xref: /titanic_51/usr/src/uts/intel/io/acpica/dispatcher/dswscope.c (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1 /******************************************************************************
2  *
3  * Module Name: dswscope - Scope stack manipulation
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2011, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43 
44 #define __DSWSCOPE_C__
45 
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acdispat.h"
49 
50 
51 #define _COMPONENT          ACPI_DISPATCHER
52         ACPI_MODULE_NAME    ("dswscope")
53 
54 
55 /****************************************************************************
56  *
57  * FUNCTION:    AcpiDsScopeStackClear
58  *
59  * PARAMETERS:  WalkState       - Current state
60  *
61  * RETURN:      None
62  *
63  * DESCRIPTION: Pop (and free) everything on the scope stack except the
64  *              root scope object (which remains at the stack top.)
65  *
66  ***************************************************************************/
67 
68 void
69 AcpiDsScopeStackClear (
70     ACPI_WALK_STATE         *WalkState)
71 {
72     ACPI_GENERIC_STATE      *ScopeInfo;
73 
74     ACPI_FUNCTION_NAME (DsScopeStackClear);
75 
76 
77     while (WalkState->ScopeInfo)
78     {
79         /* Pop a scope off the stack */
80 
81         ScopeInfo = WalkState->ScopeInfo;
82         WalkState->ScopeInfo = ScopeInfo->Scope.Next;
83 
84         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
85             "Popped object type (%s)\n",
86             AcpiUtGetTypeName (ScopeInfo->Common.Value)));
87         AcpiUtDeleteGenericState (ScopeInfo);
88     }
89 }
90 
91 
92 /****************************************************************************
93  *
94  * FUNCTION:    AcpiDsScopeStackPush
95  *
96  * PARAMETERS:  Node            - Name to be made current
97  *              Type            - Type of frame being pushed
98  *              WalkState       - Current state
99  *
100  * RETURN:      Status
101  *
102  * DESCRIPTION: Push the current scope on the scope stack, and make the
103  *              passed Node current.
104  *
105  ***************************************************************************/
106 
107 ACPI_STATUS
108 AcpiDsScopeStackPush (
109     ACPI_NAMESPACE_NODE     *Node,
110     ACPI_OBJECT_TYPE        Type,
111     ACPI_WALK_STATE         *WalkState)
112 {
113     ACPI_GENERIC_STATE      *ScopeInfo;
114     ACPI_GENERIC_STATE      *OldScopeInfo;
115 
116 
117     ACPI_FUNCTION_TRACE (DsScopeStackPush);
118 
119 
120     if (!Node)
121     {
122         /* Invalid scope   */
123 
124         ACPI_ERROR ((AE_INFO, "Null scope parameter"));
125         return_ACPI_STATUS (AE_BAD_PARAMETER);
126     }
127 
128     /* Make sure object type is valid */
129 
130     if (!AcpiUtValidObjectType (Type))
131     {
132         ACPI_WARNING ((AE_INFO,
133             "Invalid object type: 0x%X", Type));
134     }
135 
136     /* Allocate a new scope object */
137 
138     ScopeInfo = AcpiUtCreateGenericState ();
139     if (!ScopeInfo)
140     {
141         return_ACPI_STATUS (AE_NO_MEMORY);
142     }
143 
144     /* Init new scope object */
145 
146     ScopeInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_WSCOPE;
147     ScopeInfo->Scope.Node = Node;
148     ScopeInfo->Common.Value = (UINT16) Type;
149 
150     WalkState->ScopeDepth++;
151 
152     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
153         "[%.2d] Pushed scope ", (UINT32) WalkState->ScopeDepth));
154 
155     OldScopeInfo = WalkState->ScopeInfo;
156     if (OldScopeInfo)
157     {
158         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
159             "[%4.4s] (%s)",
160             AcpiUtGetNodeName (OldScopeInfo->Scope.Node),
161             AcpiUtGetTypeName (OldScopeInfo->Common.Value)));
162     }
163     else
164     {
165         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
166             "[\\___] (%s)", "ROOT"));
167     }
168 
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)));
173 
174     /* Push new scope object onto stack */
175 
176     AcpiUtPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
177     return_ACPI_STATUS (AE_OK);
178 }
179 
180 
181 /****************************************************************************
182  *
183  * FUNCTION:    AcpiDsScopeStackPop
184  *
185  * PARAMETERS:  WalkState       - Current state
186  *
187  * RETURN:      Status
188  *
189  * DESCRIPTION: Pop the scope stack once.
190  *
191  ***************************************************************************/
192 
193 ACPI_STATUS
194 AcpiDsScopeStackPop (
195     ACPI_WALK_STATE         *WalkState)
196 {
197     ACPI_GENERIC_STATE      *ScopeInfo;
198     ACPI_GENERIC_STATE      *NewScopeInfo;
199 
200 
201     ACPI_FUNCTION_TRACE (DsScopeStackPop);
202 
203 
204     /*
205      * Pop scope info object off the stack.
206      */
207     ScopeInfo = AcpiUtPopGenericState (&WalkState->ScopeInfo);
208     if (!ScopeInfo)
209     {
210         return_ACPI_STATUS (AE_STACK_UNDERFLOW);
211     }
212 
213     WalkState->ScopeDepth--;
214 
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)));
220 
221     NewScopeInfo = WalkState->ScopeInfo;
222     if (NewScopeInfo)
223     {
224         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
225             "[%4.4s] (%s)\n",
226             AcpiUtGetNodeName (NewScopeInfo->Scope.Node),
227             AcpiUtGetTypeName (NewScopeInfo->Common.Value)));
228     }
229     else
230     {
231         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
232             "[\\___] (ROOT)\n"));
233     }
234 
235     AcpiUtDeleteGenericState (ScopeInfo);
236     return_ACPI_STATUS (AE_OK);
237 }
238 
239 
240