dswstate.c revision 99679
155071Sache/******************************************************************************
229726Swosch *
386796Sache * Module Name: dswstate - Dispatcher parse tree walk management routines
486796Sache *              $Revision: 65 $
586796Sache *
686796Sache *****************************************************************************/
786796Sache
886796Sache/******************************************************************************
986796Sache *
1086796Sache * 1. Copyright Notice
1186796Sache *
1286796Sache * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
1386796Sache * All rights reserved.
1486796Sache *
1555071Sache * 2. License
1655071Sache *
1729726Swosch * 2.1. This is your license from Intel Corp. under its intellectual property
1829726Swosch * rights.  You may have additional license terms from the party that provided
1929726Swosch * you this software, covering your right to use that party's intellectual
2029726Swosch * property rights.
2129726Swosch *
2229726Swosch * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2329726Swosch * copy of the source code appearing in this file ("Covered Code") an
2429726Swosch * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2529726Swosch * base code distributed originally by Intel ("Original Intel Code") to copy,
2629726Swosch * make derivatives, distribute, use and display any portion of the Covered
2729726Swosch * Code in any form, with the right to sublicense such rights; and
2829726Swosch *
2929726Swosch * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3029726Swosch * license (with the right to sublicense), under only those claims of Intel
3129726Swosch * patents that are infringed by the Original Intel Code, to make, use, sell,
3255071Sache * offer to sell, and import the Covered Code and derivative works thereof
3329726Swosch * solely to the minimum extent necessary to exercise the above copyright
3429726Swosch * license, and in no event shall the patent license extend to any additions
3529726Swosch * to or modifications of the Original Intel Code.  No other license or right
3629726Swosch * is granted directly or by implication, estoppel or otherwise;
3729726Swosch *
3829726Swosch * The above copyright and patent license is granted only if the following
3929726Swosch * conditions are met:
4029726Swosch *
4129726Swosch * 3. Conditions
4229726Swosch *
4329726Swosch * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4429726Swosch * Redistribution of source code of any substantial portion of the Covered
4529726Swosch * Code or modification with rights to further distribute source must include
4629726Swosch * the above Copyright Notice, the above License, this list of Conditions,
4729726Swosch * and the following Disclaimer and Export Compliance provision.  In addition,
4886796Sache * Licensee must cause all Covered Code to which Licensee contributes to
4986796Sache * contain a file documenting the changes Licensee made to create that Covered
5086796Sache * Code and the date of any change.  Licensee must include in that file the
5186796Sache * documentation of any changes made by any predecessor Licensee.  Licensee
5286796Sache * must include a prominent statement that the modification is derived,
5386796Sache * directly or indirectly, from Original Intel Code.
5486796Sache *
5586796Sache * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5686796Sache * Redistribution of source code of any substantial portion of the Covered
5786796Sache * Code or modification without rights to further distribute source must
5886796Sache * include the following Disclaimer and Export Compliance provision in the
5986796Sache * documentation and/or other materials provided with distribution.  In
6029726Swosch * addition, Licensee may not authorize further sublicense of source of any
6155071Sache * portion of the Covered Code, and must include terms to the effect that the
6255071Sache * license from Licensee to its licensee is limited to the intellectual
6355071Sache * property embodied in the software Licensee provides to its licensee, and
6455071Sache * not to intellectual property embodied in modifications its licensee may
6555071Sache * make.
6629726Swosch *
6755071Sache * 3.3. Redistribution of Executable. Redistribution in executable form of any
6829726Swosch * substantial portion of the Covered Code or modification must reproduce the
6929726Swosch * above Copyright Notice, and the following Disclaimer and Export Compliance
7029726Swosch * provision in the documentation and/or other materials provided with the
7155071Sache * distribution.
7255071Sache *
7329726Swosch * 3.4. Intel retains all right, title, and interest in and to the Original
7455071Sache * Intel Code.
7555071Sache *
7655071Sache * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7729726Swosch * Intel shall be used in advertising or otherwise to promote the sale, use or
7829726Swosch * other dealings in products derived from or relating to the Covered Code
7955071Sache * without prior written authorization from Intel.
8055071Sache *
8129726Swosch * 4. Disclaimer and Export Compliance
8229726Swosch *
8355071Sache * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8429726Swosch * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8529726Swosch * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8655071Sache * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8755071Sache * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8829726Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8955071Sache * PARTICULAR PURPOSE.
9029726Swosch *
9155071Sache * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9229726Swosch * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9329726Swosch * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9486796Sache * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9529726Swosch * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9629726Swosch * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define __DSWSTATE_C__
119
120#include "acpi.h"
121#include "acparser.h"
122#include "acdispat.h"
123#include "acnamesp.h"
124
125#define _COMPONENT          ACPI_DISPATCHER
126        ACPI_MODULE_NAME    ("dswstate")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION:    AcpiDsResultInsert
132 *
133 * PARAMETERS:  Object              - Object to push
134 *              WalkState           - Current Walk state
135 *
136 * RETURN:      Status
137 *
138 * DESCRIPTION: Push an object onto this walk's result stack
139 *
140 ******************************************************************************/
141
142ACPI_STATUS
143AcpiDsResultInsert (
144    void                    *Object,
145    UINT32                  Index,
146    ACPI_WALK_STATE         *WalkState)
147{
148    ACPI_GENERIC_STATE      *State;
149
150
151    ACPI_FUNCTION_NAME ("DsResultInsert");
152
153
154    State = WalkState->Results;
155    if (!State)
156    {
157        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
158            WalkState));
159        return (AE_NOT_EXIST);
160    }
161
162    if (Index >= OBJ_NUM_OPERANDS)
163    {
164        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
165            "Index out of range: %X Obj=%p State=%p Num=%X\n",
166            Index, Object, WalkState, State->Results.NumResults));
167        return (AE_BAD_PARAMETER);
168    }
169
170    if (!Object)
171    {
172        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
173            "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
174            Index, Object, WalkState, State->Results.NumResults));
175        return (AE_BAD_PARAMETER);
176    }
177
178    State->Results.ObjDesc [Index] = Object;
179    State->Results.NumResults++;
180
181    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
182        "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
183        Object, Object ? AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object) : "NULL",
184        WalkState, State->Results.NumResults, WalkState->CurrentResult));
185
186    return (AE_OK);
187}
188
189
190/*******************************************************************************
191 *
192 * FUNCTION:    AcpiDsResultRemove
193 *
194 * PARAMETERS:  Object              - Where to return the popped object
195 *              WalkState           - Current Walk state
196 *
197 * RETURN:      Status
198 *
199 * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
200 *              other words, this is a FIFO.
201 *
202 ******************************************************************************/
203
204ACPI_STATUS
205AcpiDsResultRemove (
206    ACPI_OPERAND_OBJECT     **Object,
207    UINT32                  Index,
208    ACPI_WALK_STATE         *WalkState)
209{
210    ACPI_GENERIC_STATE      *State;
211
212
213    ACPI_FUNCTION_NAME ("DsResultRemove");
214
215
216    State = WalkState->Results;
217    if (!State)
218    {
219        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
220            WalkState));
221        return (AE_NOT_EXIST);
222    }
223
224    if (Index >= OBJ_MAX_OPERAND)
225    {
226        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
227            "Index out of range: %X State=%p Num=%X\n",
228            Index, WalkState, State->Results.NumResults));
229    }
230
231    /* Check for a valid result object */
232
233    if (!State->Results.ObjDesc [Index])
234    {
235        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
236            "Null operand! State=%p #Ops=%X, Index=%X\n",
237            WalkState, State->Results.NumResults, Index));
238        return (AE_AML_NO_RETURN_VALUE);
239    }
240
241    /* Remove the object */
242
243    State->Results.NumResults--;
244
245    *Object = State->Results.ObjDesc [Index];
246    State->Results.ObjDesc [Index] = NULL;
247
248    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
249        "Obj=%p [%s] Index=%X State=%p Num=%X\n",
250        *Object, (*Object) ? AcpiUtGetObjectTypeName (*Object) : "NULL",
251        Index, WalkState, State->Results.NumResults));
252
253    return (AE_OK);
254}
255
256
257/*******************************************************************************
258 *
259 * FUNCTION:    AcpiDsResultPop
260 *
261 * PARAMETERS:  Object              - Where to return the popped object
262 *              WalkState           - Current Walk state
263 *
264 * RETURN:      Status
265 *
266 * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
267 *              other words, this is a FIFO.
268 *
269 ******************************************************************************/
270
271ACPI_STATUS
272AcpiDsResultPop (
273    ACPI_OPERAND_OBJECT     **Object,
274    ACPI_WALK_STATE         *WalkState)
275{
276    UINT32                  Index;
277    ACPI_GENERIC_STATE      *State;
278
279
280    ACPI_FUNCTION_NAME ("DsResultPop");
281
282
283    State = WalkState->Results;
284    if (!State)
285    {
286        return (AE_OK);
287    }
288
289    if (!State->Results.NumResults)
290    {
291        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Result stack is empty! State=%p\n",
292            WalkState));
293        return (AE_AML_NO_RETURN_VALUE);
294    }
295
296    /* Remove top element */
297
298    State->Results.NumResults--;
299
300    for (Index = OBJ_NUM_OPERANDS; Index; Index--)
301    {
302        /* Check for a valid result object */
303
304        if (State->Results.ObjDesc [Index -1])
305        {
306            *Object = State->Results.ObjDesc [Index -1];
307            State->Results.ObjDesc [Index -1] = NULL;
308
309            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n",
310                *Object, (*Object) ? AcpiUtGetObjectTypeName (*Object) : "NULL",
311                Index -1, WalkState, State->Results.NumResults));
312
313            return (AE_OK);
314        }
315    }
316
317    ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", WalkState));
318    return (AE_AML_NO_RETURN_VALUE);
319}
320
321/*******************************************************************************
322 *
323 * FUNCTION:    AcpiDsResultPopFromBottom
324 *
325 * PARAMETERS:  Object              - Where to return the popped object
326 *              WalkState           - Current Walk state
327 *
328 * RETURN:      Status
329 *
330 * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
331 *              other words, this is a FIFO.
332 *
333 ******************************************************************************/
334
335ACPI_STATUS
336AcpiDsResultPopFromBottom (
337    ACPI_OPERAND_OBJECT     **Object,
338    ACPI_WALK_STATE         *WalkState)
339{
340    NATIVE_UINT             Index;
341    ACPI_GENERIC_STATE      *State;
342
343
344    ACPI_FUNCTION_NAME ("DsResultPopFromBottom");
345
346
347    State = WalkState->Results;
348    if (!State)
349    {
350        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
351            "Warning: No result object pushed! State=%p\n", WalkState));
352        return (AE_NOT_EXIST);
353    }
354
355    if (!State->Results.NumResults)
356    {
357        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", WalkState));
358        return (AE_AML_NO_RETURN_VALUE);
359    }
360
361    /* Remove Bottom element */
362
363    *Object = State->Results.ObjDesc [0];
364
365    /* Push entire stack down one element */
366
367    for (Index = 0; Index < State->Results.NumResults; Index++)
368    {
369        State->Results.ObjDesc [Index] = State->Results.ObjDesc [Index + 1];
370    }
371
372    State->Results.NumResults--;
373
374    /* Check for a valid result object */
375
376    if (!*Object)
377    {
378        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null operand! State=%p #Ops=%X, Index=%X\n",
379            WalkState, State->Results.NumResults, (UINT32) Index));
380        return (AE_AML_NO_RETURN_VALUE);
381    }
382
383    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s], Results=%p State=%p\n",
384        *Object, (*Object) ? AcpiUtGetObjectTypeName (*Object) : "NULL",
385        State, WalkState));
386
387
388    return (AE_OK);
389}
390
391
392/*******************************************************************************
393 *
394 * FUNCTION:    AcpiDsResultPush
395 *
396 * PARAMETERS:  Object              - Where to return the popped object
397 *              WalkState           - Current Walk state
398 *
399 * RETURN:      Status
400 *
401 * DESCRIPTION: Push an object onto the current result stack
402 *
403 ******************************************************************************/
404
405ACPI_STATUS
406AcpiDsResultPush (
407    ACPI_OPERAND_OBJECT     *Object,
408    ACPI_WALK_STATE         *WalkState)
409{
410    ACPI_GENERIC_STATE      *State;
411
412
413    ACPI_FUNCTION_NAME ("DsResultPush");
414
415
416    State = WalkState->Results;
417    if (!State)
418    {
419        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result stack frame\n"));
420        return (AE_AML_INTERNAL);
421    }
422
423    if (State->Results.NumResults == OBJ_NUM_OPERANDS)
424    {
425        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
426            "Result stack overflow: Obj=%p State=%p Num=%X\n",
427            Object, WalkState, State->Results.NumResults));
428        return (AE_STACK_OVERFLOW);
429    }
430
431    if (!Object)
432    {
433        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Object! Obj=%p State=%p Num=%X\n",
434            Object, WalkState, State->Results.NumResults));
435        return (AE_BAD_PARAMETER);
436    }
437
438    State->Results.ObjDesc [State->Results.NumResults] = Object;
439    State->Results.NumResults++;
440
441    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
442        Object, Object ? AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object) : "NULL",
443        WalkState, State->Results.NumResults, WalkState->CurrentResult));
444
445    return (AE_OK);
446}
447
448
449/*******************************************************************************
450 *
451 * FUNCTION:    AcpiDsResultStackPush
452 *
453 * PARAMETERS:  Object              - Object to push
454 *              WalkState           - Current Walk state
455 *
456 * RETURN:      Status
457 *
458 * DESCRIPTION:
459 *
460 ******************************************************************************/
461
462ACPI_STATUS
463AcpiDsResultStackPush (
464    ACPI_WALK_STATE         *WalkState)
465{
466    ACPI_GENERIC_STATE      *State;
467
468    ACPI_FUNCTION_NAME ("DsResultStackPush");
469
470
471    State = AcpiUtCreateGenericState ();
472    if (!State)
473    {
474        return (AE_NO_MEMORY);
475    }
476
477    State->Common.DataType  = ACPI_DESC_TYPE_STATE_RESULT;
478    AcpiUtPushGenericState (&WalkState->Results, State);
479
480    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
481        State, WalkState));
482
483    return (AE_OK);
484}
485
486
487/*******************************************************************************
488 *
489 * FUNCTION:    AcpiDsResultStackPop
490 *
491 * PARAMETERS:  WalkState           - Current Walk state
492 *
493 * RETURN:      Status
494 *
495 * DESCRIPTION:
496 *
497 ******************************************************************************/
498
499ACPI_STATUS
500AcpiDsResultStackPop (
501    ACPI_WALK_STATE         *WalkState)
502{
503    ACPI_GENERIC_STATE      *State;
504
505    ACPI_FUNCTION_NAME ("DsResultStackPop");
506
507
508    /* Check for stack underflow */
509
510    if (WalkState->Results == NULL)
511    {
512        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Underflow - State=%p\n",
513            WalkState));
514        return (AE_AML_NO_OPERAND);
515    }
516
517
518    State = AcpiUtPopGenericState (&WalkState->Results);
519
520    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
521        "Result=%p RemainingResults=%X State=%p\n",
522        State, State->Results.NumResults, WalkState));
523
524    AcpiUtDeleteGenericState (State);
525
526    return (AE_OK);
527}
528
529
530/*******************************************************************************
531 *
532 * FUNCTION:    AcpiDsObjStackDeleteAll
533 *
534 * PARAMETERS:  WalkState           - Current Walk state
535 *
536 * RETURN:      Status
537 *
538 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
539 *              Should be used with great care, if at all!
540 *
541 ******************************************************************************/
542
543ACPI_STATUS
544AcpiDsObjStackDeleteAll (
545    ACPI_WALK_STATE         *WalkState)
546{
547    UINT32                  i;
548
549
550    ACPI_FUNCTION_TRACE_PTR ("DsObjStackDeleteAll", WalkState);
551
552
553    /* The stack size is configurable, but fixed */
554
555    for (i = 0; i < OBJ_NUM_OPERANDS; i++)
556    {
557        if (WalkState->Operands[i])
558        {
559            AcpiUtRemoveReference (WalkState->Operands[i]);
560            WalkState->Operands[i] = NULL;
561        }
562    }
563
564    return_ACPI_STATUS (AE_OK);
565}
566
567
568/*******************************************************************************
569 *
570 * FUNCTION:    AcpiDsObjStackPush
571 *
572 * PARAMETERS:  Object              - Object to push
573 *              WalkState           - Current Walk state
574 *
575 * RETURN:      Status
576 *
577 * DESCRIPTION: Push an object onto this walk's object/operand stack
578 *
579 ******************************************************************************/
580
581ACPI_STATUS
582AcpiDsObjStackPush (
583    void                    *Object,
584    ACPI_WALK_STATE         *WalkState)
585{
586    ACPI_FUNCTION_NAME ("DsObjStackPush");
587
588
589    /* Check for stack overflow */
590
591    if (WalkState->NumOperands >= OBJ_NUM_OPERANDS)
592    {
593        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
594            "overflow! Obj=%p State=%p #Ops=%X\n",
595            Object, WalkState, WalkState->NumOperands));
596        return (AE_STACK_OVERFLOW);
597    }
598
599    /* Put the object onto the stack */
600
601    WalkState->Operands [WalkState->NumOperands] = Object;
602    WalkState->NumOperands++;
603
604    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
605                    Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
606                    WalkState, WalkState->NumOperands));
607
608    return (AE_OK);
609}
610
611
612#if 0
613/*******************************************************************************
614 *
615 * FUNCTION:    AcpiDsObjStackPopObject
616 *
617 * PARAMETERS:  PopCount            - Number of objects/entries to pop
618 *              WalkState           - Current Walk state
619 *
620 * RETURN:      Status
621 *
622 * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
623 *              deleted by this routine.
624 *
625 ******************************************************************************/
626
627ACPI_STATUS
628AcpiDsObjStackPopObject (
629    ACPI_OPERAND_OBJECT     **Object,
630    ACPI_WALK_STATE         *WalkState)
631{
632    ACPI_FUNCTION_NAME ("DsObjStackPopObject");
633
634
635    /* Check for stack underflow */
636
637    if (WalkState->NumOperands == 0)
638    {
639        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
640            "Missing operand/stack empty! State=%p #Ops=%X\n",
641            WalkState, WalkState->NumOperands));
642        *Object = NULL;
643        return (AE_AML_NO_OPERAND);
644    }
645
646    /* Pop the stack */
647
648    WalkState->NumOperands--;
649
650    /* Check for a valid operand */
651
652    if (!WalkState->Operands [WalkState->NumOperands])
653    {
654        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
655            "Null operand! State=%p #Ops=%X\n",
656            WalkState, WalkState->NumOperands));
657        *Object = NULL;
658        return (AE_AML_NO_OPERAND);
659    }
660
661    /* Get operand and set stack entry to null */
662
663    *Object = WalkState->Operands [WalkState->NumOperands];
664    WalkState->Operands [WalkState->NumOperands] = NULL;
665
666    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
667                    *Object, AcpiUtGetObjectTypeName (*Object),
668                    WalkState, WalkState->NumOperands));
669
670    return (AE_OK);
671}
672#endif
673
674/*******************************************************************************
675 *
676 * FUNCTION:    AcpiDsObjStackPop
677 *
678 * PARAMETERS:  PopCount            - Number of objects/entries to pop
679 *              WalkState           - Current Walk state
680 *
681 * RETURN:      Status
682 *
683 * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
684 *              deleted by this routine.
685 *
686 ******************************************************************************/
687
688ACPI_STATUS
689AcpiDsObjStackPop (
690    UINT32                  PopCount,
691    ACPI_WALK_STATE         *WalkState)
692{
693    UINT32                  i;
694
695    ACPI_FUNCTION_NAME ("DsObjStackPop");
696
697
698    for (i = 0; i < PopCount; i++)
699    {
700        /* Check for stack underflow */
701
702        if (WalkState->NumOperands == 0)
703        {
704            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
705                "Underflow! Count=%X State=%p #Ops=%X\n",
706                PopCount, WalkState, WalkState->NumOperands));
707            return (AE_STACK_UNDERFLOW);
708        }
709
710        /* Just set the stack entry to null */
711
712        WalkState->NumOperands--;
713        WalkState->Operands [WalkState->NumOperands] = NULL;
714    }
715
716    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
717                    PopCount, WalkState, WalkState->NumOperands));
718
719    return (AE_OK);
720}
721
722
723/*******************************************************************************
724 *
725 * FUNCTION:    AcpiDsObjStackPopAndDelete
726 *
727 * PARAMETERS:  PopCount            - Number of objects/entries to pop
728 *              WalkState           - Current Walk state
729 *
730 * RETURN:      Status
731 *
732 * DESCRIPTION: Pop this walk's object stack and delete each object that is
733 *              popped off.
734 *
735 ******************************************************************************/
736
737ACPI_STATUS
738AcpiDsObjStackPopAndDelete (
739    UINT32                  PopCount,
740    ACPI_WALK_STATE         *WalkState)
741{
742    UINT32                  i;
743    ACPI_OPERAND_OBJECT     *ObjDesc;
744
745    ACPI_FUNCTION_NAME ("DsObjStackPopAndDelete");
746
747
748    for (i = 0; i < PopCount; i++)
749    {
750        /* Check for stack underflow */
751
752        if (WalkState->NumOperands == 0)
753        {
754            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
755                "Underflow! Count=%X State=%p #Ops=%X\n",
756                PopCount, WalkState, WalkState->NumOperands));
757            return (AE_STACK_UNDERFLOW);
758        }
759
760        /* Pop the stack and delete an object if present in this stack entry */
761
762        WalkState->NumOperands--;
763        ObjDesc = WalkState->Operands [WalkState->NumOperands];
764        if (ObjDesc)
765        {
766            AcpiUtRemoveReference (WalkState->Operands [WalkState->NumOperands]);
767            WalkState->Operands [WalkState->NumOperands] = NULL;
768        }
769    }
770
771    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
772                    PopCount, WalkState, WalkState->NumOperands));
773
774    return (AE_OK);
775}
776
777
778/*******************************************************************************
779 *
780 * FUNCTION:    AcpiDsObjStackGetValue
781 *
782 * PARAMETERS:  Index               - Stack index whose value is desired.  Based
783 *                                    on the top of the stack (index=0 == top)
784 *              WalkState           - Current Walk state
785 *
786 * RETURN:      Status
787 *
788 * DESCRIPTION: Retrieve an object from this walk's object stack.  Index must
789 *              be within the range of the current stack pointer.
790 *
791 ******************************************************************************/
792
793void *
794AcpiDsObjStackGetValue (
795    UINT32                  Index,
796    ACPI_WALK_STATE         *WalkState)
797{
798
799    ACPI_FUNCTION_TRACE_PTR ("DsObjStackGetValue", WalkState);
800
801
802    /* Can't do it if the stack is empty */
803
804    if (WalkState->NumOperands == 0)
805    {
806        return_PTR (NULL);
807    }
808
809    /* or if the index is past the top of the stack */
810
811    if (Index > (WalkState->NumOperands - (UINT32) 1))
812    {
813        return_PTR (NULL);
814    }
815
816    return_PTR (WalkState->Operands[(NATIVE_UINT)(WalkState->NumOperands - 1) -
817                    Index]);
818}
819
820
821/*******************************************************************************
822 *
823 * FUNCTION:    AcpiDsGetCurrentWalkState
824 *
825 * PARAMETERS:  Thread          - Get current active state for this Thread
826 *
827 * RETURN:      Pointer to the current walk state
828 *
829 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
830 *              walk state.)
831 *
832 ******************************************************************************/
833
834ACPI_WALK_STATE *
835AcpiDsGetCurrentWalkState (
836    ACPI_THREAD_STATE       *Thread)
837
838{
839    ACPI_FUNCTION_NAME ("DsGetCurrentWalkState");
840
841
842    if (!Thread)
843    {
844        return (NULL);
845    }
846
847    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "DsGetCurrentWalkState, =%p\n",
848        Thread->WalkStateList));
849
850    return (Thread->WalkStateList);
851}
852
853
854/*******************************************************************************
855 *
856 * FUNCTION:    AcpiDsPushWalkState
857 *
858 * PARAMETERS:  WalkState       - State to push
859 *              WalkList        - The list that owns the walk stack
860 *
861 * RETURN:      None
862 *
863 * DESCRIPTION: Place the WalkState at the head of the state list.
864 *
865 ******************************************************************************/
866
867void
868AcpiDsPushWalkState (
869    ACPI_WALK_STATE         *WalkState,
870    ACPI_THREAD_STATE       *Thread)
871{
872    ACPI_FUNCTION_TRACE ("DsPushWalkState");
873
874
875    WalkState->Next       = Thread->WalkStateList;
876    Thread->WalkStateList = WalkState;
877
878    return_VOID;
879}
880
881
882/*******************************************************************************
883 *
884 * FUNCTION:    AcpiDsPopWalkState
885 *
886 * PARAMETERS:  WalkList        - The list that owns the walk stack
887 *
888 * RETURN:      A WalkState object popped from the stack
889 *
890 * DESCRIPTION: Remove and return the walkstate object that is at the head of
891 *              the walk stack for the given walk list.  NULL indicates that
892 *              the list is empty.
893 *
894 ******************************************************************************/
895
896ACPI_WALK_STATE *
897AcpiDsPopWalkState (
898    ACPI_THREAD_STATE       *Thread)
899{
900    ACPI_WALK_STATE         *WalkState;
901
902
903    ACPI_FUNCTION_TRACE ("DsPopWalkState");
904
905
906    WalkState = Thread->WalkStateList;
907
908    if (WalkState)
909    {
910        /* Next walk state becomes the current walk state */
911
912        Thread->WalkStateList = WalkState->Next;
913
914        /*
915         * Don't clear the NEXT field, this serves as an indicator
916         * that there is a parent WALK STATE
917         *     NO: WalkState->Next = NULL;
918         */
919    }
920
921    return_PTR (WalkState);
922}
923
924
925/*******************************************************************************
926 *
927 * FUNCTION:    AcpiDsCreateWalkState
928 *
929 * PARAMETERS:  Origin          - Starting point for this walk
930 *              Thread          - Current thread state
931 *
932 * RETURN:      Pointer to the new walk state.
933 *
934 * DESCRIPTION: Allocate and initialize a new walk state.  The current walk
935 *              state is set to this new state.
936 *
937 ******************************************************************************/
938
939ACPI_WALK_STATE *
940AcpiDsCreateWalkState (
941    ACPI_OWNER_ID           OwnerId,
942    ACPI_PARSE_OBJECT       *Origin,
943    ACPI_OPERAND_OBJECT     *MthDesc,
944    ACPI_THREAD_STATE       *Thread)
945{
946    ACPI_WALK_STATE         *WalkState;
947    ACPI_STATUS             Status;
948
949
950    ACPI_FUNCTION_TRACE ("DsCreateWalkState");
951
952
953    WalkState = AcpiUtAcquireFromCache (ACPI_MEM_LIST_WALK);
954    if (!WalkState)
955    {
956        return_PTR (NULL);
957    }
958
959    WalkState->DataType         = ACPI_DESC_TYPE_WALK;
960    WalkState->OwnerId          = OwnerId;
961    WalkState->Origin           = Origin;
962    WalkState->MethodDesc       = MthDesc;
963    WalkState->Thread           = Thread;
964
965    /* Init the method args/local */
966
967#ifndef _ACPI_ASL_COMPILER
968    AcpiDsMethodDataInit (WalkState);
969#endif
970
971    /* Create an initial result stack entry */
972
973    Status = AcpiDsResultStackPush (WalkState);
974    if (ACPI_FAILURE (Status))
975    {
976        return_PTR (NULL);
977    }
978
979    /* Put the new state at the head of the walk list */
980
981    if (Thread)
982    {
983        AcpiDsPushWalkState (WalkState, Thread);
984    }
985
986    return_PTR (WalkState);
987}
988
989
990#ifndef _ACPI_ASL_COMPILER
991/*******************************************************************************
992 *
993 * FUNCTION:    AcpiDsInitAmlWalk
994 *
995 * PARAMETERS:  WalkState       - New state to be initialized
996 *
997 * RETURN:      None
998 *
999 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
1000 *
1001 ******************************************************************************/
1002
1003ACPI_STATUS
1004AcpiDsInitAmlWalk (
1005    ACPI_WALK_STATE         *WalkState,
1006    ACPI_PARSE_OBJECT       *Op,
1007    ACPI_NAMESPACE_NODE     *MethodNode,
1008    UINT8                   *AmlStart,
1009    UINT32                  AmlLength,
1010    ACPI_OPERAND_OBJECT     **Params,
1011    ACPI_OPERAND_OBJECT     **ReturnObjDesc,
1012    UINT32                  PassNumber)
1013{
1014    ACPI_STATUS             Status;
1015    ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
1016
1017
1018    ACPI_FUNCTION_TRACE ("DsInitAmlWalk");
1019
1020
1021    WalkState->ParserState.Aml      =
1022    WalkState->ParserState.AmlStart = AmlStart;
1023    WalkState->ParserState.AmlEnd   =
1024    WalkState->ParserState.PkgEnd   = AmlStart + AmlLength;
1025
1026    /* The NextOp of the NextWalk will be the beginning of the method */
1027
1028    WalkState->NextOp               = NULL;
1029    WalkState->Params               = Params;
1030    WalkState->CallerReturnDesc     = ReturnObjDesc;
1031
1032    Status = AcpiPsInitScope (&WalkState->ParserState, Op);
1033    if (ACPI_FAILURE (Status))
1034    {
1035        return_ACPI_STATUS (Status);
1036    }
1037
1038    if (MethodNode)
1039    {
1040        WalkState->ParserState.StartNode    = MethodNode;
1041        WalkState->WalkType                 = ACPI_WALK_METHOD;
1042        WalkState->MethodNode               = MethodNode;
1043        WalkState->MethodDesc               = AcpiNsGetAttachedObject (MethodNode);
1044
1045        /* Push start scope on scope stack and make it current  */
1046
1047        Status = AcpiDsScopeStackPush (MethodNode, ACPI_TYPE_METHOD, WalkState);
1048        if (ACPI_FAILURE (Status))
1049        {
1050            return_ACPI_STATUS (Status);
1051        }
1052
1053        /* Init the method arguments */
1054
1055        Status = AcpiDsMethodDataInitArgs (Params, MTH_NUM_ARGS, WalkState);
1056        if (ACPI_FAILURE (Status))
1057        {
1058            return_ACPI_STATUS (Status);
1059        }
1060    }
1061    else
1062    {
1063        /* Setup the current scope */
1064
1065        ParserState->StartNode = ParserState->StartOp->Common.Node;
1066        if (ParserState->StartNode)
1067        {
1068            /* Push start scope on scope stack and make it current  */
1069
1070            Status = AcpiDsScopeStackPush (ParserState->StartNode,
1071                            ParserState->StartNode->Type, WalkState);
1072            if (ACPI_FAILURE (Status))
1073            {
1074                return_ACPI_STATUS (Status);
1075            }
1076        }
1077    }
1078
1079    Status = AcpiDsInitCallbacks (WalkState, PassNumber);
1080    return_ACPI_STATUS (Status);
1081}
1082#endif
1083
1084
1085/*******************************************************************************
1086 *
1087 * FUNCTION:    AcpiDsDeleteWalkState
1088 *
1089 * PARAMETERS:  WalkState       - State to delete
1090 *
1091 * RETURN:      Status
1092 *
1093 * DESCRIPTION: Delete a walk state including all internal data structures
1094 *
1095 ******************************************************************************/
1096
1097void
1098AcpiDsDeleteWalkState (
1099    ACPI_WALK_STATE         *WalkState)
1100{
1101    ACPI_GENERIC_STATE      *State;
1102
1103
1104    ACPI_FUNCTION_TRACE_PTR ("DsDeleteWalkState", WalkState);
1105
1106
1107    if (!WalkState)
1108    {
1109        return;
1110    }
1111
1112    if (WalkState->DataType != ACPI_DESC_TYPE_WALK)
1113    {
1114        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n", WalkState));
1115        return;
1116    }
1117
1118    if (WalkState->ParserState.Scope)
1119    {
1120        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n", WalkState));
1121    }
1122
1123   /* Always must free any linked control states */
1124
1125    while (WalkState->ControlState)
1126    {
1127        State = WalkState->ControlState;
1128        WalkState->ControlState = State->Common.Next;
1129
1130        AcpiUtDeleteGenericState (State);
1131    }
1132
1133    /* Always must free any linked parse states */
1134
1135    while (WalkState->ScopeInfo)
1136    {
1137        State = WalkState->ScopeInfo;
1138        WalkState->ScopeInfo = State->Common.Next;
1139
1140        AcpiUtDeleteGenericState (State);
1141    }
1142
1143    /* Always must free any stacked result states */
1144
1145    while (WalkState->Results)
1146    {
1147        State = WalkState->Results;
1148        WalkState->Results = State->Common.Next;
1149
1150        AcpiUtDeleteGenericState (State);
1151    }
1152
1153    AcpiUtReleaseToCache (ACPI_MEM_LIST_WALK, WalkState);
1154    return_VOID;
1155}
1156
1157
1158/******************************************************************************
1159 *
1160 * FUNCTION:    AcpiDsDeleteWalkStateCache
1161 *
1162 * PARAMETERS:  None
1163 *
1164 * RETURN:      Status
1165 *
1166 * DESCRIPTION: Purge the global state object cache.  Used during subsystem
1167 *              termination.
1168 *
1169 ******************************************************************************/
1170
1171void
1172AcpiDsDeleteWalkStateCache (
1173    void)
1174{
1175    ACPI_FUNCTION_TRACE ("DsDeleteWalkStateCache");
1176
1177
1178    AcpiUtDeleteGenericCache (ACPI_MEM_LIST_WALK);
1179    return_VOID;
1180}
1181
1182
1183