xref: /minix3/minix/drivers/power/acpi/dispatcher/dswstate.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /******************************************************************************
2*433d6423SLionel Sambuc  *
3*433d6423SLionel Sambuc  * Module Name: dswstate - Dispatcher parse tree walk management routines
4*433d6423SLionel Sambuc  *
5*433d6423SLionel Sambuc  *****************************************************************************/
6*433d6423SLionel Sambuc 
7*433d6423SLionel Sambuc /******************************************************************************
8*433d6423SLionel Sambuc  *
9*433d6423SLionel Sambuc  * 1. Copyright Notice
10*433d6423SLionel Sambuc  *
11*433d6423SLionel Sambuc  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12*433d6423SLionel Sambuc  * All rights reserved.
13*433d6423SLionel Sambuc  *
14*433d6423SLionel Sambuc  * 2. License
15*433d6423SLionel Sambuc  *
16*433d6423SLionel Sambuc  * 2.1. This is your license from Intel Corp. under its intellectual property
17*433d6423SLionel Sambuc  * rights.  You may have additional license terms from the party that provided
18*433d6423SLionel Sambuc  * you this software, covering your right to use that party's intellectual
19*433d6423SLionel Sambuc  * property rights.
20*433d6423SLionel Sambuc  *
21*433d6423SLionel Sambuc  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*433d6423SLionel Sambuc  * copy of the source code appearing in this file ("Covered Code") an
23*433d6423SLionel Sambuc  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*433d6423SLionel Sambuc  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*433d6423SLionel Sambuc  * make derivatives, distribute, use and display any portion of the Covered
26*433d6423SLionel Sambuc  * Code in any form, with the right to sublicense such rights; and
27*433d6423SLionel Sambuc  *
28*433d6423SLionel Sambuc  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*433d6423SLionel Sambuc  * license (with the right to sublicense), under only those claims of Intel
30*433d6423SLionel Sambuc  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*433d6423SLionel Sambuc  * offer to sell, and import the Covered Code and derivative works thereof
32*433d6423SLionel Sambuc  * solely to the minimum extent necessary to exercise the above copyright
33*433d6423SLionel Sambuc  * license, and in no event shall the patent license extend to any additions
34*433d6423SLionel Sambuc  * to or modifications of the Original Intel Code.  No other license or right
35*433d6423SLionel Sambuc  * is granted directly or by implication, estoppel or otherwise;
36*433d6423SLionel Sambuc  *
37*433d6423SLionel Sambuc  * The above copyright and patent license is granted only if the following
38*433d6423SLionel Sambuc  * conditions are met:
39*433d6423SLionel Sambuc  *
40*433d6423SLionel Sambuc  * 3. Conditions
41*433d6423SLionel Sambuc  *
42*433d6423SLionel Sambuc  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*433d6423SLionel Sambuc  * Redistribution of source code of any substantial portion of the Covered
44*433d6423SLionel Sambuc  * Code or modification with rights to further distribute source must include
45*433d6423SLionel Sambuc  * the above Copyright Notice, the above License, this list of Conditions,
46*433d6423SLionel Sambuc  * and the following Disclaimer and Export Compliance provision.  In addition,
47*433d6423SLionel Sambuc  * Licensee must cause all Covered Code to which Licensee contributes to
48*433d6423SLionel Sambuc  * contain a file documenting the changes Licensee made to create that Covered
49*433d6423SLionel Sambuc  * Code and the date of any change.  Licensee must include in that file the
50*433d6423SLionel Sambuc  * documentation of any changes made by any predecessor Licensee.  Licensee
51*433d6423SLionel Sambuc  * must include a prominent statement that the modification is derived,
52*433d6423SLionel Sambuc  * directly or indirectly, from Original Intel Code.
53*433d6423SLionel Sambuc  *
54*433d6423SLionel Sambuc  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*433d6423SLionel Sambuc  * Redistribution of source code of any substantial portion of the Covered
56*433d6423SLionel Sambuc  * Code or modification without rights to further distribute source must
57*433d6423SLionel Sambuc  * include the following Disclaimer and Export Compliance provision in the
58*433d6423SLionel Sambuc  * documentation and/or other materials provided with distribution.  In
59*433d6423SLionel Sambuc  * addition, Licensee may not authorize further sublicense of source of any
60*433d6423SLionel Sambuc  * portion of the Covered Code, and must include terms to the effect that the
61*433d6423SLionel Sambuc  * license from Licensee to its licensee is limited to the intellectual
62*433d6423SLionel Sambuc  * property embodied in the software Licensee provides to its licensee, and
63*433d6423SLionel Sambuc  * not to intellectual property embodied in modifications its licensee may
64*433d6423SLionel Sambuc  * make.
65*433d6423SLionel Sambuc  *
66*433d6423SLionel Sambuc  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*433d6423SLionel Sambuc  * substantial portion of the Covered Code or modification must reproduce the
68*433d6423SLionel Sambuc  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*433d6423SLionel Sambuc  * provision in the documentation and/or other materials provided with the
70*433d6423SLionel Sambuc  * distribution.
71*433d6423SLionel Sambuc  *
72*433d6423SLionel Sambuc  * 3.4. Intel retains all right, title, and interest in and to the Original
73*433d6423SLionel Sambuc  * Intel Code.
74*433d6423SLionel Sambuc  *
75*433d6423SLionel Sambuc  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*433d6423SLionel Sambuc  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*433d6423SLionel Sambuc  * other dealings in products derived from or relating to the Covered Code
78*433d6423SLionel Sambuc  * without prior written authorization from Intel.
79*433d6423SLionel Sambuc  *
80*433d6423SLionel Sambuc  * 4. Disclaimer and Export Compliance
81*433d6423SLionel Sambuc  *
82*433d6423SLionel Sambuc  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*433d6423SLionel Sambuc  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*433d6423SLionel Sambuc  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85*433d6423SLionel Sambuc  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86*433d6423SLionel Sambuc  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87*433d6423SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*433d6423SLionel Sambuc  * PARTICULAR PURPOSE.
89*433d6423SLionel Sambuc  *
90*433d6423SLionel Sambuc  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*433d6423SLionel Sambuc  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*433d6423SLionel Sambuc  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*433d6423SLionel Sambuc  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*433d6423SLionel Sambuc  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*433d6423SLionel Sambuc  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96*433d6423SLionel Sambuc  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*433d6423SLionel Sambuc  * LIMITED REMEDY.
98*433d6423SLionel Sambuc  *
99*433d6423SLionel Sambuc  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*433d6423SLionel Sambuc  * software or system incorporating such software without first obtaining any
101*433d6423SLionel Sambuc  * required license or other approval from the U. S. Department of Commerce or
102*433d6423SLionel Sambuc  * any other agency or department of the United States Government.  In the
103*433d6423SLionel Sambuc  * event Licensee exports any such software from the United States or
104*433d6423SLionel Sambuc  * re-exports any such software from a foreign destination, Licensee shall
105*433d6423SLionel Sambuc  * ensure that the distribution and export/re-export of the software is in
106*433d6423SLionel Sambuc  * compliance with all laws, regulations, orders, or other restrictions of the
107*433d6423SLionel Sambuc  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*433d6423SLionel Sambuc  * any of its subsidiaries will export/re-export any technical data, process,
109*433d6423SLionel Sambuc  * software, or service, directly or indirectly, to any country for which the
110*433d6423SLionel Sambuc  * United States government or any agency thereof requires an export license,
111*433d6423SLionel Sambuc  * other governmental approval, or letter of assurance, without first obtaining
112*433d6423SLionel Sambuc  * such license, approval or letter.
113*433d6423SLionel Sambuc  *
114*433d6423SLionel Sambuc  *****************************************************************************/
115*433d6423SLionel Sambuc 
116*433d6423SLionel Sambuc 
117*433d6423SLionel Sambuc #define __DSWSTATE_C__
118*433d6423SLionel Sambuc 
119*433d6423SLionel Sambuc #include "acpi.h"
120*433d6423SLionel Sambuc #include "accommon.h"
121*433d6423SLionel Sambuc #include "acparser.h"
122*433d6423SLionel Sambuc #include "acdispat.h"
123*433d6423SLionel Sambuc #include "acnamesp.h"
124*433d6423SLionel Sambuc 
125*433d6423SLionel Sambuc #define _COMPONENT          ACPI_DISPATCHER
126*433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("dswstate")
127*433d6423SLionel Sambuc 
128*433d6423SLionel Sambuc /* Local prototypes */
129*433d6423SLionel Sambuc 
130*433d6423SLionel Sambuc static ACPI_STATUS
131*433d6423SLionel Sambuc AcpiDsResultStackPush (
132*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState);
133*433d6423SLionel Sambuc 
134*433d6423SLionel Sambuc static ACPI_STATUS
135*433d6423SLionel Sambuc AcpiDsResultStackPop (
136*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState);
137*433d6423SLionel Sambuc 
138*433d6423SLionel Sambuc 
139*433d6423SLionel Sambuc /*******************************************************************************
140*433d6423SLionel Sambuc  *
141*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsResultPop
142*433d6423SLionel Sambuc  *
143*433d6423SLionel Sambuc  * PARAMETERS:  Object              - Where to return the popped object
144*433d6423SLionel Sambuc  *              WalkState           - Current Walk state
145*433d6423SLionel Sambuc  *
146*433d6423SLionel Sambuc  * RETURN:      Status
147*433d6423SLionel Sambuc  *
148*433d6423SLionel Sambuc  * DESCRIPTION: Pop an object off the top of this walk's result stack
149*433d6423SLionel Sambuc  *
150*433d6423SLionel Sambuc  ******************************************************************************/
151*433d6423SLionel Sambuc 
152*433d6423SLionel Sambuc ACPI_STATUS
153*433d6423SLionel Sambuc AcpiDsResultPop (
154*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **Object,
155*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
156*433d6423SLionel Sambuc {
157*433d6423SLionel Sambuc     UINT32                  Index;
158*433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State;
159*433d6423SLionel Sambuc     ACPI_STATUS             Status;
160*433d6423SLionel Sambuc 
161*433d6423SLionel Sambuc 
162*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsResultPop);
163*433d6423SLionel Sambuc 
164*433d6423SLionel Sambuc 
165*433d6423SLionel Sambuc     State = WalkState->Results;
166*433d6423SLionel Sambuc 
167*433d6423SLionel Sambuc     /* Incorrect state of result stack */
168*433d6423SLionel Sambuc 
169*433d6423SLionel Sambuc     if (State && !WalkState->ResultCount)
170*433d6423SLionel Sambuc     {
171*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "No results on result stack"));
172*433d6423SLionel Sambuc         return (AE_AML_INTERNAL);
173*433d6423SLionel Sambuc     }
174*433d6423SLionel Sambuc 
175*433d6423SLionel Sambuc     if (!State && WalkState->ResultCount)
176*433d6423SLionel Sambuc     {
177*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "No result state for result stack"));
178*433d6423SLionel Sambuc         return (AE_AML_INTERNAL);
179*433d6423SLionel Sambuc     }
180*433d6423SLionel Sambuc 
181*433d6423SLionel Sambuc     /* Empty result stack */
182*433d6423SLionel Sambuc 
183*433d6423SLionel Sambuc     if (!State)
184*433d6423SLionel Sambuc     {
185*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));
186*433d6423SLionel Sambuc         return (AE_AML_NO_RETURN_VALUE);
187*433d6423SLionel Sambuc     }
188*433d6423SLionel Sambuc 
189*433d6423SLionel Sambuc     /* Return object of the top element and clean that top element result stack */
190*433d6423SLionel Sambuc 
191*433d6423SLionel Sambuc     WalkState->ResultCount--;
192*433d6423SLionel Sambuc     Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
193*433d6423SLionel Sambuc 
194*433d6423SLionel Sambuc     *Object = State->Results.ObjDesc [Index];
195*433d6423SLionel Sambuc     if (!*Object)
196*433d6423SLionel Sambuc     {
197*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",
198*433d6423SLionel Sambuc             WalkState));
199*433d6423SLionel Sambuc         return (AE_AML_NO_RETURN_VALUE);
200*433d6423SLionel Sambuc     }
201*433d6423SLionel Sambuc 
202*433d6423SLionel Sambuc     State->Results.ObjDesc [Index] = NULL;
203*433d6423SLionel Sambuc     if (Index == 0)
204*433d6423SLionel Sambuc     {
205*433d6423SLionel Sambuc         Status = AcpiDsResultStackPop (WalkState);
206*433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
207*433d6423SLionel Sambuc         {
208*433d6423SLionel Sambuc             return (Status);
209*433d6423SLionel Sambuc         }
210*433d6423SLionel Sambuc     }
211*433d6423SLionel Sambuc 
212*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
213*433d6423SLionel Sambuc         "Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,
214*433d6423SLionel Sambuc         AcpiUtGetObjectTypeName (*Object),
215*433d6423SLionel Sambuc         Index, WalkState, WalkState->ResultCount));
216*433d6423SLionel Sambuc 
217*433d6423SLionel Sambuc     return (AE_OK);
218*433d6423SLionel Sambuc }
219*433d6423SLionel Sambuc 
220*433d6423SLionel Sambuc 
221*433d6423SLionel Sambuc /*******************************************************************************
222*433d6423SLionel Sambuc  *
223*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsResultPush
224*433d6423SLionel Sambuc  *
225*433d6423SLionel Sambuc  * PARAMETERS:  Object              - Where to return the popped object
226*433d6423SLionel Sambuc  *              WalkState           - Current Walk state
227*433d6423SLionel Sambuc  *
228*433d6423SLionel Sambuc  * RETURN:      Status
229*433d6423SLionel Sambuc  *
230*433d6423SLionel Sambuc  * DESCRIPTION: Push an object onto the current result stack
231*433d6423SLionel Sambuc  *
232*433d6423SLionel Sambuc  ******************************************************************************/
233*433d6423SLionel Sambuc 
234*433d6423SLionel Sambuc ACPI_STATUS
235*433d6423SLionel Sambuc AcpiDsResultPush (
236*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Object,
237*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
238*433d6423SLionel Sambuc {
239*433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State;
240*433d6423SLionel Sambuc     ACPI_STATUS             Status;
241*433d6423SLionel Sambuc     UINT32                  Index;
242*433d6423SLionel Sambuc 
243*433d6423SLionel Sambuc 
244*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsResultPush);
245*433d6423SLionel Sambuc 
246*433d6423SLionel Sambuc 
247*433d6423SLionel Sambuc     if (WalkState->ResultCount > WalkState->ResultSize)
248*433d6423SLionel Sambuc     {
249*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Result stack is full"));
250*433d6423SLionel Sambuc         return (AE_AML_INTERNAL);
251*433d6423SLionel Sambuc     }
252*433d6423SLionel Sambuc     else if (WalkState->ResultCount == WalkState->ResultSize)
253*433d6423SLionel Sambuc     {
254*433d6423SLionel Sambuc         /* Extend the result stack */
255*433d6423SLionel Sambuc 
256*433d6423SLionel Sambuc         Status = AcpiDsResultStackPush (WalkState);
257*433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
258*433d6423SLionel Sambuc         {
259*433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));
260*433d6423SLionel Sambuc             return (Status);
261*433d6423SLionel Sambuc         }
262*433d6423SLionel Sambuc     }
263*433d6423SLionel Sambuc 
264*433d6423SLionel Sambuc     if (!(WalkState->ResultCount < WalkState->ResultSize))
265*433d6423SLionel Sambuc     {
266*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "No free elements in result stack"));
267*433d6423SLionel Sambuc         return (AE_AML_INTERNAL);
268*433d6423SLionel Sambuc     }
269*433d6423SLionel Sambuc 
270*433d6423SLionel Sambuc     State = WalkState->Results;
271*433d6423SLionel Sambuc     if (!State)
272*433d6423SLionel Sambuc     {
273*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "No result stack frame during push"));
274*433d6423SLionel Sambuc         return (AE_AML_INTERNAL);
275*433d6423SLionel Sambuc     }
276*433d6423SLionel Sambuc 
277*433d6423SLionel Sambuc     if (!Object)
278*433d6423SLionel Sambuc     {
279*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
280*433d6423SLionel Sambuc             "Null Object! Obj=%p State=%p Num=%u",
281*433d6423SLionel Sambuc             Object, WalkState, WalkState->ResultCount));
282*433d6423SLionel Sambuc         return (AE_BAD_PARAMETER);
283*433d6423SLionel Sambuc     }
284*433d6423SLionel Sambuc 
285*433d6423SLionel Sambuc     /* Assign the address of object to the top free element of result stack */
286*433d6423SLionel Sambuc 
287*433d6423SLionel Sambuc     Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
288*433d6423SLionel Sambuc     State->Results.ObjDesc [Index] = Object;
289*433d6423SLionel Sambuc     WalkState->ResultCount++;
290*433d6423SLionel Sambuc 
291*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
292*433d6423SLionel Sambuc         Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
293*433d6423SLionel Sambuc         WalkState, WalkState->ResultCount, WalkState->CurrentResult));
294*433d6423SLionel Sambuc 
295*433d6423SLionel Sambuc     return (AE_OK);
296*433d6423SLionel Sambuc }
297*433d6423SLionel Sambuc 
298*433d6423SLionel Sambuc 
299*433d6423SLionel Sambuc /*******************************************************************************
300*433d6423SLionel Sambuc  *
301*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsResultStackPush
302*433d6423SLionel Sambuc  *
303*433d6423SLionel Sambuc  * PARAMETERS:  WalkState           - Current Walk state
304*433d6423SLionel Sambuc  *
305*433d6423SLionel Sambuc  * RETURN:      Status
306*433d6423SLionel Sambuc  *
307*433d6423SLionel Sambuc  * DESCRIPTION: Push an object onto the WalkState result stack
308*433d6423SLionel Sambuc  *
309*433d6423SLionel Sambuc  ******************************************************************************/
310*433d6423SLionel Sambuc 
311*433d6423SLionel Sambuc static ACPI_STATUS
312*433d6423SLionel Sambuc AcpiDsResultStackPush (
313*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
314*433d6423SLionel Sambuc {
315*433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State;
316*433d6423SLionel Sambuc 
317*433d6423SLionel Sambuc 
318*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsResultStackPush);
319*433d6423SLionel Sambuc 
320*433d6423SLionel Sambuc 
321*433d6423SLionel Sambuc     /* Check for stack overflow */
322*433d6423SLionel Sambuc 
323*433d6423SLionel Sambuc     if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >
324*433d6423SLionel Sambuc         ACPI_RESULTS_OBJ_NUM_MAX)
325*433d6423SLionel Sambuc     {
326*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%u",
327*433d6423SLionel Sambuc             WalkState, WalkState->ResultSize));
328*433d6423SLionel Sambuc         return (AE_STACK_OVERFLOW);
329*433d6423SLionel Sambuc     }
330*433d6423SLionel Sambuc 
331*433d6423SLionel Sambuc     State = AcpiUtCreateGenericState ();
332*433d6423SLionel Sambuc     if (!State)
333*433d6423SLionel Sambuc     {
334*433d6423SLionel Sambuc         return (AE_NO_MEMORY);
335*433d6423SLionel Sambuc     }
336*433d6423SLionel Sambuc 
337*433d6423SLionel Sambuc     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;
338*433d6423SLionel Sambuc     AcpiUtPushGenericState (&WalkState->Results, State);
339*433d6423SLionel Sambuc 
340*433d6423SLionel Sambuc     /* Increase the length of the result stack by the length of frame */
341*433d6423SLionel Sambuc 
342*433d6423SLionel Sambuc     WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;
343*433d6423SLionel Sambuc 
344*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
345*433d6423SLionel Sambuc         State, WalkState));
346*433d6423SLionel Sambuc 
347*433d6423SLionel Sambuc     return (AE_OK);
348*433d6423SLionel Sambuc }
349*433d6423SLionel Sambuc 
350*433d6423SLionel Sambuc 
351*433d6423SLionel Sambuc /*******************************************************************************
352*433d6423SLionel Sambuc  *
353*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsResultStackPop
354*433d6423SLionel Sambuc  *
355*433d6423SLionel Sambuc  * PARAMETERS:  WalkState           - Current Walk state
356*433d6423SLionel Sambuc  *
357*433d6423SLionel Sambuc  * RETURN:      Status
358*433d6423SLionel Sambuc  *
359*433d6423SLionel Sambuc  * DESCRIPTION: Pop an object off of the WalkState result stack
360*433d6423SLionel Sambuc  *
361*433d6423SLionel Sambuc  ******************************************************************************/
362*433d6423SLionel Sambuc 
363*433d6423SLionel Sambuc static ACPI_STATUS
364*433d6423SLionel Sambuc AcpiDsResultStackPop (
365*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
366*433d6423SLionel Sambuc {
367*433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State;
368*433d6423SLionel Sambuc 
369*433d6423SLionel Sambuc 
370*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsResultStackPop);
371*433d6423SLionel Sambuc 
372*433d6423SLionel Sambuc 
373*433d6423SLionel Sambuc     /* Check for stack underflow */
374*433d6423SLionel Sambuc 
375*433d6423SLionel Sambuc     if (WalkState->Results == NULL)
376*433d6423SLionel Sambuc     {
377*433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Result stack underflow - State=%p\n",
378*433d6423SLionel Sambuc             WalkState));
379*433d6423SLionel Sambuc         return (AE_AML_NO_OPERAND);
380*433d6423SLionel Sambuc     }
381*433d6423SLionel Sambuc 
382*433d6423SLionel Sambuc     if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)
383*433d6423SLionel Sambuc     {
384*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));
385*433d6423SLionel Sambuc         return (AE_AML_INTERNAL);
386*433d6423SLionel Sambuc     }
387*433d6423SLionel Sambuc 
388*433d6423SLionel Sambuc     State = AcpiUtPopGenericState (&WalkState->Results);
389*433d6423SLionel Sambuc     AcpiUtDeleteGenericState (State);
390*433d6423SLionel Sambuc 
391*433d6423SLionel Sambuc     /* Decrease the length of result stack by the length of frame */
392*433d6423SLionel Sambuc 
393*433d6423SLionel Sambuc     WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;
394*433d6423SLionel Sambuc 
395*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
396*433d6423SLionel Sambuc         "Result=%p RemainingResults=%X State=%p\n",
397*433d6423SLionel Sambuc         State, WalkState->ResultCount, WalkState));
398*433d6423SLionel Sambuc 
399*433d6423SLionel Sambuc     return (AE_OK);
400*433d6423SLionel Sambuc }
401*433d6423SLionel Sambuc 
402*433d6423SLionel Sambuc 
403*433d6423SLionel Sambuc /*******************************************************************************
404*433d6423SLionel Sambuc  *
405*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsObjStackPush
406*433d6423SLionel Sambuc  *
407*433d6423SLionel Sambuc  * PARAMETERS:  Object              - Object to push
408*433d6423SLionel Sambuc  *              WalkState           - Current Walk state
409*433d6423SLionel Sambuc  *
410*433d6423SLionel Sambuc  * RETURN:      Status
411*433d6423SLionel Sambuc  *
412*433d6423SLionel Sambuc  * DESCRIPTION: Push an object onto this walk's object/operand stack
413*433d6423SLionel Sambuc  *
414*433d6423SLionel Sambuc  ******************************************************************************/
415*433d6423SLionel Sambuc 
416*433d6423SLionel Sambuc ACPI_STATUS
417*433d6423SLionel Sambuc AcpiDsObjStackPush (
418*433d6423SLionel Sambuc     void                    *Object,
419*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
420*433d6423SLionel Sambuc {
421*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsObjStackPush);
422*433d6423SLionel Sambuc 
423*433d6423SLionel Sambuc 
424*433d6423SLionel Sambuc     /* Check for stack overflow */
425*433d6423SLionel Sambuc 
426*433d6423SLionel Sambuc     if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)
427*433d6423SLionel Sambuc     {
428*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
429*433d6423SLionel Sambuc             "Object stack overflow! Obj=%p State=%p #Ops=%u",
430*433d6423SLionel Sambuc             Object, WalkState, WalkState->NumOperands));
431*433d6423SLionel Sambuc         return (AE_STACK_OVERFLOW);
432*433d6423SLionel Sambuc     }
433*433d6423SLionel Sambuc 
434*433d6423SLionel Sambuc     /* Put the object onto the stack */
435*433d6423SLionel Sambuc 
436*433d6423SLionel Sambuc     WalkState->Operands [WalkState->OperandIndex] = Object;
437*433d6423SLionel Sambuc     WalkState->NumOperands++;
438*433d6423SLionel Sambuc 
439*433d6423SLionel Sambuc     /* For the usual order of filling the operand stack */
440*433d6423SLionel Sambuc 
441*433d6423SLionel Sambuc     WalkState->OperandIndex++;
442*433d6423SLionel Sambuc 
443*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
444*433d6423SLionel Sambuc         Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
445*433d6423SLionel Sambuc         WalkState, WalkState->NumOperands));
446*433d6423SLionel Sambuc 
447*433d6423SLionel Sambuc     return (AE_OK);
448*433d6423SLionel Sambuc }
449*433d6423SLionel Sambuc 
450*433d6423SLionel Sambuc 
451*433d6423SLionel Sambuc /*******************************************************************************
452*433d6423SLionel Sambuc  *
453*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsObjStackPop
454*433d6423SLionel Sambuc  *
455*433d6423SLionel Sambuc  * PARAMETERS:  PopCount            - Number of objects/entries to pop
456*433d6423SLionel Sambuc  *              WalkState           - Current Walk state
457*433d6423SLionel Sambuc  *
458*433d6423SLionel Sambuc  * RETURN:      Status
459*433d6423SLionel Sambuc  *
460*433d6423SLionel Sambuc  * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
461*433d6423SLionel Sambuc  *              deleted by this routine.
462*433d6423SLionel Sambuc  *
463*433d6423SLionel Sambuc  ******************************************************************************/
464*433d6423SLionel Sambuc 
465*433d6423SLionel Sambuc ACPI_STATUS
466*433d6423SLionel Sambuc AcpiDsObjStackPop (
467*433d6423SLionel Sambuc     UINT32                  PopCount,
468*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
469*433d6423SLionel Sambuc {
470*433d6423SLionel Sambuc     UINT32                  i;
471*433d6423SLionel Sambuc 
472*433d6423SLionel Sambuc 
473*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsObjStackPop);
474*433d6423SLionel Sambuc 
475*433d6423SLionel Sambuc 
476*433d6423SLionel Sambuc     for (i = 0; i < PopCount; i++)
477*433d6423SLionel Sambuc     {
478*433d6423SLionel Sambuc         /* Check for stack underflow */
479*433d6423SLionel Sambuc 
480*433d6423SLionel Sambuc         if (WalkState->NumOperands == 0)
481*433d6423SLionel Sambuc         {
482*433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
483*433d6423SLionel Sambuc                 "Object stack underflow! Count=%X State=%p #Ops=%u",
484*433d6423SLionel Sambuc                 PopCount, WalkState, WalkState->NumOperands));
485*433d6423SLionel Sambuc             return (AE_STACK_UNDERFLOW);
486*433d6423SLionel Sambuc         }
487*433d6423SLionel Sambuc 
488*433d6423SLionel Sambuc         /* Just set the stack entry to null */
489*433d6423SLionel Sambuc 
490*433d6423SLionel Sambuc         WalkState->NumOperands--;
491*433d6423SLionel Sambuc         WalkState->Operands [WalkState->NumOperands] = NULL;
492*433d6423SLionel Sambuc     }
493*433d6423SLionel Sambuc 
494*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
495*433d6423SLionel Sambuc         PopCount, WalkState, WalkState->NumOperands));
496*433d6423SLionel Sambuc 
497*433d6423SLionel Sambuc     return (AE_OK);
498*433d6423SLionel Sambuc }
499*433d6423SLionel Sambuc 
500*433d6423SLionel Sambuc 
501*433d6423SLionel Sambuc /*******************************************************************************
502*433d6423SLionel Sambuc  *
503*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsObjStackPopAndDelete
504*433d6423SLionel Sambuc  *
505*433d6423SLionel Sambuc  * PARAMETERS:  PopCount            - Number of objects/entries to pop
506*433d6423SLionel Sambuc  *              WalkState           - Current Walk state
507*433d6423SLionel Sambuc  *
508*433d6423SLionel Sambuc  * RETURN:      Status
509*433d6423SLionel Sambuc  *
510*433d6423SLionel Sambuc  * DESCRIPTION: Pop this walk's object stack and delete each object that is
511*433d6423SLionel Sambuc  *              popped off.
512*433d6423SLionel Sambuc  *
513*433d6423SLionel Sambuc  ******************************************************************************/
514*433d6423SLionel Sambuc 
515*433d6423SLionel Sambuc void
516*433d6423SLionel Sambuc AcpiDsObjStackPopAndDelete (
517*433d6423SLionel Sambuc     UINT32                  PopCount,
518*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
519*433d6423SLionel Sambuc {
520*433d6423SLionel Sambuc     INT32                   i;
521*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
522*433d6423SLionel Sambuc 
523*433d6423SLionel Sambuc 
524*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);
525*433d6423SLionel Sambuc 
526*433d6423SLionel Sambuc 
527*433d6423SLionel Sambuc     if (PopCount == 0)
528*433d6423SLionel Sambuc     {
529*433d6423SLionel Sambuc         return;
530*433d6423SLionel Sambuc     }
531*433d6423SLionel Sambuc 
532*433d6423SLionel Sambuc     for (i = (INT32) PopCount - 1; i >= 0; i--)
533*433d6423SLionel Sambuc     {
534*433d6423SLionel Sambuc         if (WalkState->NumOperands == 0)
535*433d6423SLionel Sambuc         {
536*433d6423SLionel Sambuc             return;
537*433d6423SLionel Sambuc         }
538*433d6423SLionel Sambuc 
539*433d6423SLionel Sambuc         /* Pop the stack and delete an object if present in this stack entry */
540*433d6423SLionel Sambuc 
541*433d6423SLionel Sambuc         WalkState->NumOperands--;
542*433d6423SLionel Sambuc         ObjDesc = WalkState->Operands [i];
543*433d6423SLionel Sambuc         if (ObjDesc)
544*433d6423SLionel Sambuc         {
545*433d6423SLionel Sambuc             AcpiUtRemoveReference (WalkState->Operands [i]);
546*433d6423SLionel Sambuc             WalkState->Operands [i] = NULL;
547*433d6423SLionel Sambuc         }
548*433d6423SLionel Sambuc     }
549*433d6423SLionel Sambuc 
550*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
551*433d6423SLionel Sambuc         PopCount, WalkState, WalkState->NumOperands));
552*433d6423SLionel Sambuc }
553*433d6423SLionel Sambuc 
554*433d6423SLionel Sambuc 
555*433d6423SLionel Sambuc /*******************************************************************************
556*433d6423SLionel Sambuc  *
557*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsGetCurrentWalkState
558*433d6423SLionel Sambuc  *
559*433d6423SLionel Sambuc  * PARAMETERS:  Thread          - Get current active state for this Thread
560*433d6423SLionel Sambuc  *
561*433d6423SLionel Sambuc  * RETURN:      Pointer to the current walk state
562*433d6423SLionel Sambuc  *
563*433d6423SLionel Sambuc  * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
564*433d6423SLionel Sambuc  *              walk state.)
565*433d6423SLionel Sambuc  *
566*433d6423SLionel Sambuc  ******************************************************************************/
567*433d6423SLionel Sambuc 
568*433d6423SLionel Sambuc ACPI_WALK_STATE *
569*433d6423SLionel Sambuc AcpiDsGetCurrentWalkState (
570*433d6423SLionel Sambuc     ACPI_THREAD_STATE       *Thread)
571*433d6423SLionel Sambuc {
572*433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (DsGetCurrentWalkState);
573*433d6423SLionel Sambuc 
574*433d6423SLionel Sambuc 
575*433d6423SLionel Sambuc     if (!Thread)
576*433d6423SLionel Sambuc     {
577*433d6423SLionel Sambuc         return (NULL);
578*433d6423SLionel Sambuc     }
579*433d6423SLionel Sambuc 
580*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",
581*433d6423SLionel Sambuc         Thread->WalkStateList));
582*433d6423SLionel Sambuc 
583*433d6423SLionel Sambuc     return (Thread->WalkStateList);
584*433d6423SLionel Sambuc }
585*433d6423SLionel Sambuc 
586*433d6423SLionel Sambuc 
587*433d6423SLionel Sambuc /*******************************************************************************
588*433d6423SLionel Sambuc  *
589*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsPushWalkState
590*433d6423SLionel Sambuc  *
591*433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - State to push
592*433d6423SLionel Sambuc  *              Thread          - Thread state object
593*433d6423SLionel Sambuc  *
594*433d6423SLionel Sambuc  * RETURN:      None
595*433d6423SLionel Sambuc  *
596*433d6423SLionel Sambuc  * DESCRIPTION: Place the Thread state at the head of the state list
597*433d6423SLionel Sambuc  *
598*433d6423SLionel Sambuc  ******************************************************************************/
599*433d6423SLionel Sambuc 
600*433d6423SLionel Sambuc void
601*433d6423SLionel Sambuc AcpiDsPushWalkState (
602*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
603*433d6423SLionel Sambuc     ACPI_THREAD_STATE       *Thread)
604*433d6423SLionel Sambuc {
605*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsPushWalkState);
606*433d6423SLionel Sambuc 
607*433d6423SLionel Sambuc 
608*433d6423SLionel Sambuc     WalkState->Next = Thread->WalkStateList;
609*433d6423SLionel Sambuc     Thread->WalkStateList = WalkState;
610*433d6423SLionel Sambuc 
611*433d6423SLionel Sambuc     return_VOID;
612*433d6423SLionel Sambuc }
613*433d6423SLionel Sambuc 
614*433d6423SLionel Sambuc 
615*433d6423SLionel Sambuc /*******************************************************************************
616*433d6423SLionel Sambuc  *
617*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsPopWalkState
618*433d6423SLionel Sambuc  *
619*433d6423SLionel Sambuc  * PARAMETERS:  Thread      - Current thread state
620*433d6423SLionel Sambuc  *
621*433d6423SLionel Sambuc  * RETURN:      A WalkState object popped from the thread's stack
622*433d6423SLionel Sambuc  *
623*433d6423SLionel Sambuc  * DESCRIPTION: Remove and return the walkstate object that is at the head of
624*433d6423SLionel Sambuc  *              the walk stack for the given walk list.  NULL indicates that
625*433d6423SLionel Sambuc  *              the list is empty.
626*433d6423SLionel Sambuc  *
627*433d6423SLionel Sambuc  ******************************************************************************/
628*433d6423SLionel Sambuc 
629*433d6423SLionel Sambuc ACPI_WALK_STATE *
630*433d6423SLionel Sambuc AcpiDsPopWalkState (
631*433d6423SLionel Sambuc     ACPI_THREAD_STATE       *Thread)
632*433d6423SLionel Sambuc {
633*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState;
634*433d6423SLionel Sambuc 
635*433d6423SLionel Sambuc 
636*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsPopWalkState);
637*433d6423SLionel Sambuc 
638*433d6423SLionel Sambuc 
639*433d6423SLionel Sambuc     WalkState = Thread->WalkStateList;
640*433d6423SLionel Sambuc 
641*433d6423SLionel Sambuc     if (WalkState)
642*433d6423SLionel Sambuc     {
643*433d6423SLionel Sambuc         /* Next walk state becomes the current walk state */
644*433d6423SLionel Sambuc 
645*433d6423SLionel Sambuc         Thread->WalkStateList = WalkState->Next;
646*433d6423SLionel Sambuc 
647*433d6423SLionel Sambuc         /*
648*433d6423SLionel Sambuc          * Don't clear the NEXT field, this serves as an indicator
649*433d6423SLionel Sambuc          * that there is a parent WALK STATE
650*433d6423SLionel Sambuc          * Do Not: WalkState->Next = NULL;
651*433d6423SLionel Sambuc          */
652*433d6423SLionel Sambuc     }
653*433d6423SLionel Sambuc 
654*433d6423SLionel Sambuc     return_PTR (WalkState);
655*433d6423SLionel Sambuc }
656*433d6423SLionel Sambuc 
657*433d6423SLionel Sambuc 
658*433d6423SLionel Sambuc /*******************************************************************************
659*433d6423SLionel Sambuc  *
660*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsCreateWalkState
661*433d6423SLionel Sambuc  *
662*433d6423SLionel Sambuc  * PARAMETERS:  OwnerId         - ID for object creation
663*433d6423SLionel Sambuc  *              Origin          - Starting point for this walk
664*433d6423SLionel Sambuc  *              MethodDesc      - Method object
665*433d6423SLionel Sambuc  *              Thread          - Current thread state
666*433d6423SLionel Sambuc  *
667*433d6423SLionel Sambuc  * RETURN:      Pointer to the new walk state.
668*433d6423SLionel Sambuc  *
669*433d6423SLionel Sambuc  * DESCRIPTION: Allocate and initialize a new walk state.  The current walk
670*433d6423SLionel Sambuc  *              state is set to this new state.
671*433d6423SLionel Sambuc  *
672*433d6423SLionel Sambuc  ******************************************************************************/
673*433d6423SLionel Sambuc 
674*433d6423SLionel Sambuc ACPI_WALK_STATE *
675*433d6423SLionel Sambuc AcpiDsCreateWalkState (
676*433d6423SLionel Sambuc     ACPI_OWNER_ID           OwnerId,
677*433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Origin,
678*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *MethodDesc,
679*433d6423SLionel Sambuc     ACPI_THREAD_STATE       *Thread)
680*433d6423SLionel Sambuc {
681*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState;
682*433d6423SLionel Sambuc 
683*433d6423SLionel Sambuc 
684*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsCreateWalkState);
685*433d6423SLionel Sambuc 
686*433d6423SLionel Sambuc 
687*433d6423SLionel Sambuc     WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));
688*433d6423SLionel Sambuc     if (!WalkState)
689*433d6423SLionel Sambuc     {
690*433d6423SLionel Sambuc         return_PTR (NULL);
691*433d6423SLionel Sambuc     }
692*433d6423SLionel Sambuc 
693*433d6423SLionel Sambuc     WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;
694*433d6423SLionel Sambuc     WalkState->MethodDesc = MethodDesc;
695*433d6423SLionel Sambuc     WalkState->OwnerId = OwnerId;
696*433d6423SLionel Sambuc     WalkState->Origin = Origin;
697*433d6423SLionel Sambuc     WalkState->Thread = Thread;
698*433d6423SLionel Sambuc 
699*433d6423SLionel Sambuc     WalkState->ParserState.StartOp = Origin;
700*433d6423SLionel Sambuc 
701*433d6423SLionel Sambuc     /* Init the method args/local */
702*433d6423SLionel Sambuc 
703*433d6423SLionel Sambuc #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
704*433d6423SLionel Sambuc     AcpiDsMethodDataInit (WalkState);
705*433d6423SLionel Sambuc #endif
706*433d6423SLionel Sambuc 
707*433d6423SLionel Sambuc     /* Put the new state at the head of the walk list */
708*433d6423SLionel Sambuc 
709*433d6423SLionel Sambuc     if (Thread)
710*433d6423SLionel Sambuc     {
711*433d6423SLionel Sambuc         AcpiDsPushWalkState (WalkState, Thread);
712*433d6423SLionel Sambuc     }
713*433d6423SLionel Sambuc 
714*433d6423SLionel Sambuc     return_PTR (WalkState);
715*433d6423SLionel Sambuc }
716*433d6423SLionel Sambuc 
717*433d6423SLionel Sambuc 
718*433d6423SLionel Sambuc /*******************************************************************************
719*433d6423SLionel Sambuc  *
720*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsInitAmlWalk
721*433d6423SLionel Sambuc  *
722*433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - New state to be initialized
723*433d6423SLionel Sambuc  *              Op              - Current parse op
724*433d6423SLionel Sambuc  *              MethodNode      - Control method NS node, if any
725*433d6423SLionel Sambuc  *              AmlStart        - Start of AML
726*433d6423SLionel Sambuc  *              AmlLength       - Length of AML
727*433d6423SLionel Sambuc  *              Info            - Method info block (params, etc.)
728*433d6423SLionel Sambuc  *              PassNumber      - 1, 2, or 3
729*433d6423SLionel Sambuc  *
730*433d6423SLionel Sambuc  * RETURN:      Status
731*433d6423SLionel Sambuc  *
732*433d6423SLionel Sambuc  * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
733*433d6423SLionel Sambuc  *
734*433d6423SLionel Sambuc  ******************************************************************************/
735*433d6423SLionel Sambuc 
736*433d6423SLionel Sambuc ACPI_STATUS
737*433d6423SLionel Sambuc AcpiDsInitAmlWalk (
738*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
739*433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *Op,
740*433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *MethodNode,
741*433d6423SLionel Sambuc     UINT8                   *AmlStart,
742*433d6423SLionel Sambuc     UINT32                  AmlLength,
743*433d6423SLionel Sambuc     ACPI_EVALUATE_INFO      *Info,
744*433d6423SLionel Sambuc     UINT8                   PassNumber)
745*433d6423SLionel Sambuc {
746*433d6423SLionel Sambuc     ACPI_STATUS             Status;
747*433d6423SLionel Sambuc     ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
748*433d6423SLionel Sambuc     ACPI_PARSE_OBJECT       *ExtraOp;
749*433d6423SLionel Sambuc 
750*433d6423SLionel Sambuc 
751*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (DsInitAmlWalk);
752*433d6423SLionel Sambuc 
753*433d6423SLionel Sambuc 
754*433d6423SLionel Sambuc     WalkState->ParserState.Aml =
755*433d6423SLionel Sambuc     WalkState->ParserState.AmlStart = AmlStart;
756*433d6423SLionel Sambuc     WalkState->ParserState.AmlEnd =
757*433d6423SLionel Sambuc     WalkState->ParserState.PkgEnd = AmlStart + AmlLength;
758*433d6423SLionel Sambuc 
759*433d6423SLionel Sambuc     /* The NextOp of the NextWalk will be the beginning of the method */
760*433d6423SLionel Sambuc 
761*433d6423SLionel Sambuc     WalkState->NextOp = NULL;
762*433d6423SLionel Sambuc     WalkState->PassNumber = PassNumber;
763*433d6423SLionel Sambuc 
764*433d6423SLionel Sambuc     if (Info)
765*433d6423SLionel Sambuc     {
766*433d6423SLionel Sambuc         WalkState->Params = Info->Parameters;
767*433d6423SLionel Sambuc         WalkState->CallerReturnDesc = &Info->ReturnObject;
768*433d6423SLionel Sambuc     }
769*433d6423SLionel Sambuc 
770*433d6423SLionel Sambuc     Status = AcpiPsInitScope (&WalkState->ParserState, Op);
771*433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
772*433d6423SLionel Sambuc     {
773*433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
774*433d6423SLionel Sambuc     }
775*433d6423SLionel Sambuc 
776*433d6423SLionel Sambuc     if (MethodNode)
777*433d6423SLionel Sambuc     {
778*433d6423SLionel Sambuc         WalkState->ParserState.StartNode = MethodNode;
779*433d6423SLionel Sambuc         WalkState->WalkType = ACPI_WALK_METHOD;
780*433d6423SLionel Sambuc         WalkState->MethodNode = MethodNode;
781*433d6423SLionel Sambuc         WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);
782*433d6423SLionel Sambuc 
783*433d6423SLionel Sambuc         /* Push start scope on scope stack and make it current  */
784*433d6423SLionel Sambuc 
785*433d6423SLionel Sambuc         Status = AcpiDsScopeStackPush (MethodNode, ACPI_TYPE_METHOD, WalkState);
786*433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
787*433d6423SLionel Sambuc         {
788*433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
789*433d6423SLionel Sambuc         }
790*433d6423SLionel Sambuc 
791*433d6423SLionel Sambuc         /* Init the method arguments */
792*433d6423SLionel Sambuc 
793*433d6423SLionel Sambuc         Status = AcpiDsMethodDataInitArgs (WalkState->Params,
794*433d6423SLionel Sambuc                     ACPI_METHOD_NUM_ARGS, WalkState);
795*433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
796*433d6423SLionel Sambuc         {
797*433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
798*433d6423SLionel Sambuc         }
799*433d6423SLionel Sambuc     }
800*433d6423SLionel Sambuc     else
801*433d6423SLionel Sambuc     {
802*433d6423SLionel Sambuc         /*
803*433d6423SLionel Sambuc          * Setup the current scope.
804*433d6423SLionel Sambuc          * Find a Named Op that has a namespace node associated with it.
805*433d6423SLionel Sambuc          * search upwards from this Op.  Current scope is the first
806*433d6423SLionel Sambuc          * Op with a namespace node.
807*433d6423SLionel Sambuc          */
808*433d6423SLionel Sambuc         ExtraOp = ParserState->StartOp;
809*433d6423SLionel Sambuc         while (ExtraOp && !ExtraOp->Common.Node)
810*433d6423SLionel Sambuc         {
811*433d6423SLionel Sambuc             ExtraOp = ExtraOp->Common.Parent;
812*433d6423SLionel Sambuc         }
813*433d6423SLionel Sambuc 
814*433d6423SLionel Sambuc         if (!ExtraOp)
815*433d6423SLionel Sambuc         {
816*433d6423SLionel Sambuc             ParserState->StartNode = NULL;
817*433d6423SLionel Sambuc         }
818*433d6423SLionel Sambuc         else
819*433d6423SLionel Sambuc         {
820*433d6423SLionel Sambuc             ParserState->StartNode = ExtraOp->Common.Node;
821*433d6423SLionel Sambuc         }
822*433d6423SLionel Sambuc 
823*433d6423SLionel Sambuc         if (ParserState->StartNode)
824*433d6423SLionel Sambuc         {
825*433d6423SLionel Sambuc             /* Push start scope on scope stack and make it current  */
826*433d6423SLionel Sambuc 
827*433d6423SLionel Sambuc             Status = AcpiDsScopeStackPush (ParserState->StartNode,
828*433d6423SLionel Sambuc                             ParserState->StartNode->Type, WalkState);
829*433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
830*433d6423SLionel Sambuc             {
831*433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
832*433d6423SLionel Sambuc             }
833*433d6423SLionel Sambuc         }
834*433d6423SLionel Sambuc     }
835*433d6423SLionel Sambuc 
836*433d6423SLionel Sambuc     Status = AcpiDsInitCallbacks (WalkState, PassNumber);
837*433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
838*433d6423SLionel Sambuc }
839*433d6423SLionel Sambuc 
840*433d6423SLionel Sambuc 
841*433d6423SLionel Sambuc /*******************************************************************************
842*433d6423SLionel Sambuc  *
843*433d6423SLionel Sambuc  * FUNCTION:    AcpiDsDeleteWalkState
844*433d6423SLionel Sambuc  *
845*433d6423SLionel Sambuc  * PARAMETERS:  WalkState       - State to delete
846*433d6423SLionel Sambuc  *
847*433d6423SLionel Sambuc  * RETURN:      Status
848*433d6423SLionel Sambuc  *
849*433d6423SLionel Sambuc  * DESCRIPTION: Delete a walk state including all internal data structures
850*433d6423SLionel Sambuc  *
851*433d6423SLionel Sambuc  ******************************************************************************/
852*433d6423SLionel Sambuc 
853*433d6423SLionel Sambuc void
854*433d6423SLionel Sambuc AcpiDsDeleteWalkState (
855*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
856*433d6423SLionel Sambuc {
857*433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State;
858*433d6423SLionel Sambuc 
859*433d6423SLionel Sambuc 
860*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);
861*433d6423SLionel Sambuc 
862*433d6423SLionel Sambuc 
863*433d6423SLionel Sambuc     if (!WalkState)
864*433d6423SLionel Sambuc     {
865*433d6423SLionel Sambuc         return;
866*433d6423SLionel Sambuc     }
867*433d6423SLionel Sambuc 
868*433d6423SLionel Sambuc     if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)
869*433d6423SLionel Sambuc     {
870*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",
871*433d6423SLionel Sambuc             WalkState));
872*433d6423SLionel Sambuc         return;
873*433d6423SLionel Sambuc     }
874*433d6423SLionel Sambuc 
875*433d6423SLionel Sambuc     /* There should not be any open scopes */
876*433d6423SLionel Sambuc 
877*433d6423SLionel Sambuc     if (WalkState->ParserState.Scope)
878*433d6423SLionel Sambuc     {
879*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",
880*433d6423SLionel Sambuc             WalkState));
881*433d6423SLionel Sambuc         AcpiPsCleanupScope (&WalkState->ParserState);
882*433d6423SLionel Sambuc     }
883*433d6423SLionel Sambuc 
884*433d6423SLionel Sambuc     /* Always must free any linked control states */
885*433d6423SLionel Sambuc 
886*433d6423SLionel Sambuc     while (WalkState->ControlState)
887*433d6423SLionel Sambuc     {
888*433d6423SLionel Sambuc         State = WalkState->ControlState;
889*433d6423SLionel Sambuc         WalkState->ControlState = State->Common.Next;
890*433d6423SLionel Sambuc 
891*433d6423SLionel Sambuc         AcpiUtDeleteGenericState (State);
892*433d6423SLionel Sambuc     }
893*433d6423SLionel Sambuc 
894*433d6423SLionel Sambuc     /* Always must free any linked parse states */
895*433d6423SLionel Sambuc 
896*433d6423SLionel Sambuc     while (WalkState->ScopeInfo)
897*433d6423SLionel Sambuc     {
898*433d6423SLionel Sambuc         State = WalkState->ScopeInfo;
899*433d6423SLionel Sambuc         WalkState->ScopeInfo = State->Common.Next;
900*433d6423SLionel Sambuc 
901*433d6423SLionel Sambuc         AcpiUtDeleteGenericState (State);
902*433d6423SLionel Sambuc     }
903*433d6423SLionel Sambuc 
904*433d6423SLionel Sambuc     /* Always must free any stacked result states */
905*433d6423SLionel Sambuc 
906*433d6423SLionel Sambuc     while (WalkState->Results)
907*433d6423SLionel Sambuc     {
908*433d6423SLionel Sambuc         State = WalkState->Results;
909*433d6423SLionel Sambuc         WalkState->Results = State->Common.Next;
910*433d6423SLionel Sambuc 
911*433d6423SLionel Sambuc         AcpiUtDeleteGenericState (State);
912*433d6423SLionel Sambuc     }
913*433d6423SLionel Sambuc 
914*433d6423SLionel Sambuc     ACPI_FREE (WalkState);
915*433d6423SLionel Sambuc     return_VOID;
916*433d6423SLionel Sambuc }
917*433d6423SLionel Sambuc 
918*433d6423SLionel Sambuc 
919