1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: dswscope - Scope stack manipulation
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc *****************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acdispat.h"
47433d6423SLionel Sambuc
48433d6423SLionel Sambuc
49433d6423SLionel Sambuc #define _COMPONENT ACPI_DISPATCHER
50433d6423SLionel Sambuc ACPI_MODULE_NAME ("dswscope")
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc
53433d6423SLionel Sambuc /****************************************************************************
54433d6423SLionel Sambuc *
55433d6423SLionel Sambuc * FUNCTION: AcpiDsScopeStackClear
56433d6423SLionel Sambuc *
57433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state
58433d6423SLionel Sambuc *
59433d6423SLionel Sambuc * RETURN: None
60433d6423SLionel Sambuc *
61433d6423SLionel Sambuc * DESCRIPTION: Pop (and free) everything on the scope stack except the
62433d6423SLionel Sambuc * root scope object (which remains at the stack top.)
63433d6423SLionel Sambuc *
64433d6423SLionel Sambuc ***************************************************************************/
65433d6423SLionel Sambuc
66433d6423SLionel Sambuc void
AcpiDsScopeStackClear(ACPI_WALK_STATE * WalkState)67433d6423SLionel Sambuc AcpiDsScopeStackClear (
68433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
69433d6423SLionel Sambuc {
70433d6423SLionel Sambuc ACPI_GENERIC_STATE *ScopeInfo;
71433d6423SLionel Sambuc
72433d6423SLionel Sambuc ACPI_FUNCTION_NAME (DsScopeStackClear);
73433d6423SLionel Sambuc
74433d6423SLionel Sambuc
75433d6423SLionel Sambuc while (WalkState->ScopeInfo)
76433d6423SLionel Sambuc {
77433d6423SLionel Sambuc /* Pop a scope off the stack */
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc ScopeInfo = WalkState->ScopeInfo;
80433d6423SLionel Sambuc WalkState->ScopeInfo = ScopeInfo->Scope.Next;
81433d6423SLionel Sambuc
82433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
83433d6423SLionel Sambuc "Popped object type (%s)\n",
84433d6423SLionel Sambuc AcpiUtGetTypeName (ScopeInfo->Common.Value)));
85433d6423SLionel Sambuc AcpiUtDeleteGenericState (ScopeInfo);
86433d6423SLionel Sambuc }
87433d6423SLionel Sambuc }
88433d6423SLionel Sambuc
89433d6423SLionel Sambuc
90433d6423SLionel Sambuc /****************************************************************************
91433d6423SLionel Sambuc *
92433d6423SLionel Sambuc * FUNCTION: AcpiDsScopeStackPush
93433d6423SLionel Sambuc *
94433d6423SLionel Sambuc * PARAMETERS: Node - Name to be made current
95433d6423SLionel Sambuc * Type - Type of frame being pushed
96433d6423SLionel Sambuc * WalkState - Current state
97433d6423SLionel Sambuc *
98433d6423SLionel Sambuc * RETURN: Status
99433d6423SLionel Sambuc *
100433d6423SLionel Sambuc * DESCRIPTION: Push the current scope on the scope stack, and make the
101433d6423SLionel Sambuc * passed Node current.
102433d6423SLionel Sambuc *
103433d6423SLionel Sambuc ***************************************************************************/
104433d6423SLionel Sambuc
105433d6423SLionel Sambuc ACPI_STATUS
AcpiDsScopeStackPush(ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_TYPE Type,ACPI_WALK_STATE * WalkState)106433d6423SLionel Sambuc AcpiDsScopeStackPush (
107433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node,
108433d6423SLionel Sambuc ACPI_OBJECT_TYPE Type,
109433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
110433d6423SLionel Sambuc {
111433d6423SLionel Sambuc ACPI_GENERIC_STATE *ScopeInfo;
112433d6423SLionel Sambuc ACPI_GENERIC_STATE *OldScopeInfo;
113433d6423SLionel Sambuc
114433d6423SLionel Sambuc
115433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (DsScopeStackPush);
116433d6423SLionel Sambuc
117433d6423SLionel Sambuc
118433d6423SLionel Sambuc if (!Node)
119433d6423SLionel Sambuc {
120433d6423SLionel Sambuc /* Invalid scope */
121433d6423SLionel Sambuc
122433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Null scope parameter"));
123433d6423SLionel Sambuc return_ACPI_STATUS (AE_BAD_PARAMETER);
124433d6423SLionel Sambuc }
125433d6423SLionel Sambuc
126433d6423SLionel Sambuc /* Make sure object type is valid */
127433d6423SLionel Sambuc
128433d6423SLionel Sambuc if (!AcpiUtValidObjectType (Type))
129433d6423SLionel Sambuc {
130433d6423SLionel Sambuc ACPI_WARNING ((AE_INFO,
131433d6423SLionel Sambuc "Invalid object type: 0x%X", Type));
132433d6423SLionel Sambuc }
133433d6423SLionel Sambuc
134433d6423SLionel Sambuc /* Allocate a new scope object */
135433d6423SLionel Sambuc
136433d6423SLionel Sambuc ScopeInfo = AcpiUtCreateGenericState ();
137433d6423SLionel Sambuc if (!ScopeInfo)
138433d6423SLionel Sambuc {
139433d6423SLionel Sambuc return_ACPI_STATUS (AE_NO_MEMORY);
140433d6423SLionel Sambuc }
141433d6423SLionel Sambuc
142433d6423SLionel Sambuc /* Init new scope object */
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc ScopeInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_WSCOPE;
145433d6423SLionel Sambuc ScopeInfo->Scope.Node = Node;
146433d6423SLionel Sambuc ScopeInfo->Common.Value = (UINT16) Type;
147433d6423SLionel Sambuc
148433d6423SLionel Sambuc WalkState->ScopeDepth++;
149433d6423SLionel Sambuc
150433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
151433d6423SLionel Sambuc "[%.2d] Pushed scope ", (UINT32) WalkState->ScopeDepth));
152433d6423SLionel Sambuc
153433d6423SLionel Sambuc OldScopeInfo = WalkState->ScopeInfo;
154433d6423SLionel Sambuc if (OldScopeInfo)
155433d6423SLionel Sambuc {
156433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
157433d6423SLionel Sambuc "[%4.4s] (%s)",
158433d6423SLionel Sambuc AcpiUtGetNodeName (OldScopeInfo->Scope.Node),
159433d6423SLionel Sambuc AcpiUtGetTypeName (OldScopeInfo->Common.Value)));
160433d6423SLionel Sambuc }
161433d6423SLionel Sambuc else
162433d6423SLionel Sambuc {
163433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
164433d6423SLionel Sambuc "[\\___] (%s)", "ROOT"));
165433d6423SLionel Sambuc }
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
168433d6423SLionel Sambuc ", New scope -> [%4.4s] (%s)\n",
169433d6423SLionel Sambuc AcpiUtGetNodeName (ScopeInfo->Scope.Node),
170433d6423SLionel Sambuc AcpiUtGetTypeName (ScopeInfo->Common.Value)));
171433d6423SLionel Sambuc
172433d6423SLionel Sambuc /* Push new scope object onto stack */
173433d6423SLionel Sambuc
174433d6423SLionel Sambuc AcpiUtPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
175433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
176433d6423SLionel Sambuc }
177433d6423SLionel Sambuc
178433d6423SLionel Sambuc
179433d6423SLionel Sambuc /****************************************************************************
180433d6423SLionel Sambuc *
181433d6423SLionel Sambuc * FUNCTION: AcpiDsScopeStackPop
182433d6423SLionel Sambuc *
183433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state
184433d6423SLionel Sambuc *
185433d6423SLionel Sambuc * RETURN: Status
186433d6423SLionel Sambuc *
187433d6423SLionel Sambuc * DESCRIPTION: Pop the scope stack once.
188433d6423SLionel Sambuc *
189433d6423SLionel Sambuc ***************************************************************************/
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc ACPI_STATUS
AcpiDsScopeStackPop(ACPI_WALK_STATE * WalkState)192433d6423SLionel Sambuc AcpiDsScopeStackPop (
193433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
194433d6423SLionel Sambuc {
195433d6423SLionel Sambuc ACPI_GENERIC_STATE *ScopeInfo;
196433d6423SLionel Sambuc ACPI_GENERIC_STATE *NewScopeInfo;
197433d6423SLionel Sambuc
198433d6423SLionel Sambuc
199433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (DsScopeStackPop);
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc
202433d6423SLionel Sambuc /*
203433d6423SLionel Sambuc * Pop scope info object off the stack.
204433d6423SLionel Sambuc */
205433d6423SLionel Sambuc ScopeInfo = AcpiUtPopGenericState (&WalkState->ScopeInfo);
206433d6423SLionel Sambuc if (!ScopeInfo)
207433d6423SLionel Sambuc {
208433d6423SLionel Sambuc return_ACPI_STATUS (AE_STACK_UNDERFLOW);
209433d6423SLionel Sambuc }
210433d6423SLionel Sambuc
211433d6423SLionel Sambuc WalkState->ScopeDepth--;
212433d6423SLionel Sambuc
213433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
214433d6423SLionel Sambuc "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
215433d6423SLionel Sambuc (UINT32) WalkState->ScopeDepth,
216433d6423SLionel Sambuc AcpiUtGetNodeName (ScopeInfo->Scope.Node),
217433d6423SLionel Sambuc AcpiUtGetTypeName (ScopeInfo->Common.Value)));
218433d6423SLionel Sambuc
219433d6423SLionel Sambuc NewScopeInfo = WalkState->ScopeInfo;
220433d6423SLionel Sambuc if (NewScopeInfo)
221433d6423SLionel Sambuc {
222433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
223433d6423SLionel Sambuc "[%4.4s] (%s)\n",
224433d6423SLionel Sambuc AcpiUtGetNodeName (NewScopeInfo->Scope.Node),
225433d6423SLionel Sambuc AcpiUtGetTypeName (NewScopeInfo->Common.Value)));
226433d6423SLionel Sambuc }
227433d6423SLionel Sambuc else
228433d6423SLionel Sambuc {
229433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
230433d6423SLionel Sambuc "[\\___] (ROOT)\n"));
231433d6423SLionel Sambuc }
232433d6423SLionel Sambuc
233433d6423SLionel Sambuc AcpiUtDeleteGenericState (ScopeInfo);
234433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
235433d6423SLionel Sambuc }
236