1 /******************************************************************************
3 * Module Name: dswscope - Scope stack manipulation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __DSWSCOPE_C__
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acdispat.h>
51 #define _COMPONENT ACPI_DISPATCHER
52 ACPI_MODULE_NAME ("dswscope")
55 /****************************************************************************
57 * FUNCTION: AcpiDsScopeStackClear
59 * PARAMETERS: WalkState - Current state
63 * DESCRIPTION: Pop (and free) everything on the scope stack except the
64 * root scope object (which remains at the stack top.)
66 ***************************************************************************/
69 AcpiDsScopeStackClear (
70 ACPI_WALK_STATE *WalkState)
72 ACPI_GENERIC_STATE *ScopeInfo;
74 ACPI_FUNCTION_NAME (DsScopeStackClear);
77 while (WalkState->ScopeInfo)
79 /* Pop a scope off the stack */
81 ScopeInfo = WalkState->ScopeInfo;
82 WalkState->ScopeInfo = ScopeInfo->Scope.Next;
84 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
85 "Popped object type (%s)\n",
86 AcpiUtGetTypeName (ScopeInfo->Common.Value)));
87 AcpiUtDeleteGenericState (ScopeInfo);
92 /****************************************************************************
94 * FUNCTION: AcpiDsScopeStackPush
96 * PARAMETERS: Node - Name to be made current
97 * Type - Type of frame being pushed
98 * WalkState - Current state
102 * DESCRIPTION: Push the current scope on the scope stack, and make the
103 * passed Node current.
105 ***************************************************************************/
108 AcpiDsScopeStackPush (
109 ACPI_NAMESPACE_NODE *Node,
110 ACPI_OBJECT_TYPE Type,
111 ACPI_WALK_STATE *WalkState)
113 ACPI_GENERIC_STATE *ScopeInfo;
114 ACPI_GENERIC_STATE *OldScopeInfo;
117 ACPI_FUNCTION_TRACE (DsScopeStackPush);
124 ACPI_ERROR ((AE_INFO, "Null scope parameter"));
125 return_ACPI_STATUS (AE_BAD_PARAMETER);
128 /* Make sure object type is valid */
130 if (!AcpiUtValidObjectType (Type))
132 ACPI_WARNING ((AE_INFO,
133 "Invalid object type: 0x%X", Type));
136 /* Allocate a new scope object */
138 ScopeInfo = AcpiUtCreateGenericState ();
141 return_ACPI_STATUS (AE_NO_MEMORY);
144 /* Init new scope object */
146 ScopeInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_WSCOPE;
147 ScopeInfo->Scope.Node = Node;
148 ScopeInfo->Common.Value = (UINT16) Type;
150 WalkState->ScopeDepth++;
152 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
153 "[%.2d] Pushed scope ", (UINT32) WalkState->ScopeDepth));
155 OldScopeInfo = WalkState->ScopeInfo;
158 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
160 AcpiUtGetNodeName (OldScopeInfo->Scope.Node),
161 AcpiUtGetTypeName (OldScopeInfo->Common.Value)));
165 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
166 "[\\___] (%s)", "ROOT"));
169 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
170 ", New scope -> [%4.4s] (%s)\n",
171 AcpiUtGetNodeName (ScopeInfo->Scope.Node),
172 AcpiUtGetTypeName (ScopeInfo->Common.Value)));
174 /* Push new scope object onto stack */
176 AcpiUtPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
177 return_ACPI_STATUS (AE_OK);
181 /****************************************************************************
183 * FUNCTION: AcpiDsScopeStackPop
185 * PARAMETERS: WalkState - Current state
189 * DESCRIPTION: Pop the scope stack once.
191 ***************************************************************************/
194 AcpiDsScopeStackPop (
195 ACPI_WALK_STATE *WalkState)
197 ACPI_GENERIC_STATE *ScopeInfo;
198 ACPI_GENERIC_STATE *NewScopeInfo;
201 ACPI_FUNCTION_TRACE (DsScopeStackPop);
205 * Pop scope info object off the stack.
207 ScopeInfo = AcpiUtPopGenericState (&WalkState->ScopeInfo);
210 return_ACPI_STATUS (AE_STACK_UNDERFLOW);
213 WalkState->ScopeDepth--;
215 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
216 "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
217 (UINT32) WalkState->ScopeDepth,
218 AcpiUtGetNodeName (ScopeInfo->Scope.Node),
219 AcpiUtGetTypeName (ScopeInfo->Common.Value)));
221 NewScopeInfo = WalkState->ScopeInfo;
224 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
226 AcpiUtGetNodeName (NewScopeInfo->Scope.Node),
227 AcpiUtGetTypeName (NewScopeInfo->Common.Value)));
231 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
232 "[\\___] (ROOT)\n"));
235 AcpiUtDeleteGenericState (ScopeInfo);
236 return_ACPI_STATUS (AE_OK);