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