Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/dswstate.c need to be fixed.

0001 /******************************************************************************
0002  *
0003  * Module Name: dswstate - Dispatcher parse tree walk management routines
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 
0117 #define __DSWSTATE_C__
0118 
0119 #include "acpi.h"
0120 #include "accommon.h"
0121 #include "acparser.h"
0122 #include "acdispat.h"
0123 #include "acnamesp.h"
0124 
0125 #define _COMPONENT          ACPI_DISPATCHER
0126         ACPI_MODULE_NAME    ("dswstate")
0127 
0128 /* Local prototypes */
0129 
0130 static ACPI_STATUS
0131 AcpiDsResultStackPush (
0132     ACPI_WALK_STATE         *WalkState);
0133 
0134 static ACPI_STATUS
0135 AcpiDsResultStackPop (
0136     ACPI_WALK_STATE         *WalkState);
0137 
0138 
0139 /*******************************************************************************
0140  *
0141  * FUNCTION:    AcpiDsResultPop
0142  *
0143  * PARAMETERS:  Object              - Where to return the popped object
0144  *              WalkState           - Current Walk state
0145  *
0146  * RETURN:      Status
0147  *
0148  * DESCRIPTION: Pop an object off the top of this walk's result stack
0149  *
0150  ******************************************************************************/
0151 
0152 ACPI_STATUS
0153 AcpiDsResultPop (
0154     ACPI_OPERAND_OBJECT     **Object,
0155     ACPI_WALK_STATE         *WalkState)
0156 {
0157     UINT32                  Index;
0158     ACPI_GENERIC_STATE      *State;
0159     ACPI_STATUS             Status;
0160 
0161 
0162     ACPI_FUNCTION_NAME (DsResultPop);
0163 
0164 
0165     State = WalkState->Results;
0166 
0167     /* Incorrect state of result stack */
0168 
0169     if (State && !WalkState->ResultCount)
0170     {
0171         ACPI_ERROR ((AE_INFO, "No results on result stack"));
0172         return (AE_AML_INTERNAL);
0173     }
0174 
0175     if (!State && WalkState->ResultCount)
0176     {
0177         ACPI_ERROR ((AE_INFO, "No result state for result stack"));
0178         return (AE_AML_INTERNAL);
0179     }
0180 
0181     /* Empty result stack */
0182 
0183     if (!State)
0184     {
0185         ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));
0186         return (AE_AML_NO_RETURN_VALUE);
0187     }
0188 
0189     /* Return object of the top element and clean that top element result stack */
0190 
0191     WalkState->ResultCount--;
0192     Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
0193 
0194     *Object = State->Results.ObjDesc [Index];
0195     if (!*Object)
0196     {
0197         ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",
0198             WalkState));
0199         return (AE_AML_NO_RETURN_VALUE);
0200     }
0201 
0202     State->Results.ObjDesc [Index] = NULL;
0203     if (Index == 0)
0204     {
0205         Status = AcpiDsResultStackPop (WalkState);
0206         if (ACPI_FAILURE (Status))
0207         {
0208             return (Status);
0209         }
0210     }
0211 
0212     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0213         "Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,
0214         AcpiUtGetObjectTypeName (*Object),
0215         Index, WalkState, WalkState->ResultCount));
0216 
0217     return (AE_OK);
0218 }
0219 
0220 
0221 /*******************************************************************************
0222  *
0223  * FUNCTION:    AcpiDsResultPush
0224  *
0225  * PARAMETERS:  Object              - Where to return the popped object
0226  *              WalkState           - Current Walk state
0227  *
0228  * RETURN:      Status
0229  *
0230  * DESCRIPTION: Push an object onto the current result stack
0231  *
0232  ******************************************************************************/
0233 
0234 ACPI_STATUS
0235 AcpiDsResultPush (
0236     ACPI_OPERAND_OBJECT     *Object,
0237     ACPI_WALK_STATE         *WalkState)
0238 {
0239     ACPI_GENERIC_STATE      *State;
0240     ACPI_STATUS             Status;
0241     UINT32                  Index;
0242 
0243 
0244     ACPI_FUNCTION_NAME (DsResultPush);
0245 
0246 
0247     if (WalkState->ResultCount > WalkState->ResultSize)
0248     {
0249         ACPI_ERROR ((AE_INFO, "Result stack is full"));
0250         return (AE_AML_INTERNAL);
0251     }
0252     else if (WalkState->ResultCount == WalkState->ResultSize)
0253     {
0254         /* Extend the result stack */
0255 
0256         Status = AcpiDsResultStackPush (WalkState);
0257         if (ACPI_FAILURE (Status))
0258         {
0259             ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));
0260             return (Status);
0261         }
0262     }
0263 
0264     if (!(WalkState->ResultCount < WalkState->ResultSize))
0265     {
0266         ACPI_ERROR ((AE_INFO, "No free elements in result stack"));
0267         return (AE_AML_INTERNAL);
0268     }
0269 
0270     State = WalkState->Results;
0271     if (!State)
0272     {
0273         ACPI_ERROR ((AE_INFO, "No result stack frame during push"));
0274         return (AE_AML_INTERNAL);
0275     }
0276 
0277     if (!Object)
0278     {
0279         ACPI_ERROR ((AE_INFO,
0280             "Null Object! Obj=%p State=%p Num=%X",
0281             Object, WalkState, WalkState->ResultCount));
0282         return (AE_BAD_PARAMETER);
0283     }
0284 
0285     /* Assign the address of object to the top free element of result stack */
0286 
0287     Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
0288     State->Results.ObjDesc [Index] = Object;
0289     WalkState->ResultCount++;
0290 
0291     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
0292         Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
0293         WalkState, WalkState->ResultCount, WalkState->CurrentResult));
0294 
0295     return (AE_OK);
0296 }
0297 
0298 
0299 /*******************************************************************************
0300  *
0301  * FUNCTION:    AcpiDsResultStackPush
0302  *
0303  * PARAMETERS:  WalkState           - Current Walk state
0304  *
0305  * RETURN:      Status
0306  *
0307  * DESCRIPTION: Push an object onto the WalkState result stack
0308  *
0309  ******************************************************************************/
0310 
0311 static ACPI_STATUS
0312 AcpiDsResultStackPush (
0313     ACPI_WALK_STATE         *WalkState)
0314 {
0315     ACPI_GENERIC_STATE      *State;
0316 
0317 
0318     ACPI_FUNCTION_NAME (DsResultStackPush);
0319 
0320 
0321     /* Check for stack overflow */
0322 
0323     if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >
0324         ACPI_RESULTS_OBJ_NUM_MAX)
0325     {
0326         ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%X",
0327             WalkState, WalkState->ResultSize));
0328         return (AE_STACK_OVERFLOW);
0329     }
0330 
0331     State = AcpiUtCreateGenericState ();
0332     if (!State)
0333     {
0334         return (AE_NO_MEMORY);
0335     }
0336 
0337     State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;
0338     AcpiUtPushGenericState (&WalkState->Results, State);
0339 
0340     /* Increase the length of the result stack by the length of frame */
0341 
0342     WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;
0343 
0344     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
0345         State, WalkState));
0346 
0347     return (AE_OK);
0348 }
0349 
0350 
0351 /*******************************************************************************
0352  *
0353  * FUNCTION:    AcpiDsResultStackPop
0354  *
0355  * PARAMETERS:  WalkState           - Current Walk state
0356  *
0357  * RETURN:      Status
0358  *
0359  * DESCRIPTION: Pop an object off of the WalkState result stack
0360  *
0361  ******************************************************************************/
0362 
0363 static ACPI_STATUS
0364 AcpiDsResultStackPop (
0365     ACPI_WALK_STATE         *WalkState)
0366 {
0367     ACPI_GENERIC_STATE      *State;
0368 
0369 
0370     ACPI_FUNCTION_NAME (DsResultStackPop);
0371 
0372 
0373     /* Check for stack underflow */
0374 
0375     if (WalkState->Results == NULL)
0376     {
0377         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Result stack underflow - State=%p\n",
0378             WalkState));
0379         return (AE_AML_NO_OPERAND);
0380     }
0381 
0382     if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)
0383     {
0384         ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));
0385         return (AE_AML_INTERNAL);
0386     }
0387 
0388     State = AcpiUtPopGenericState (&WalkState->Results);
0389     AcpiUtDeleteGenericState (State);
0390 
0391     /* Decrease the length of result stack by the length of frame */
0392 
0393     WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;
0394 
0395     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0396         "Result=%p RemainingResults=%X State=%p\n",
0397         State, WalkState->ResultCount, WalkState));
0398 
0399     return (AE_OK);
0400 }
0401 
0402 
0403 /*******************************************************************************
0404  *
0405  * FUNCTION:    AcpiDsObjStackPush
0406  *
0407  * PARAMETERS:  Object              - Object to push
0408  *              WalkState           - Current Walk state
0409  *
0410  * RETURN:      Status
0411  *
0412  * DESCRIPTION: Push an object onto this walk's object/operand stack
0413  *
0414  ******************************************************************************/
0415 
0416 ACPI_STATUS
0417 AcpiDsObjStackPush (
0418     void                    *Object,
0419     ACPI_WALK_STATE         *WalkState)
0420 {
0421     ACPI_FUNCTION_NAME (DsObjStackPush);
0422 
0423 
0424     /* Check for stack overflow */
0425 
0426     if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)
0427     {
0428         ACPI_ERROR ((AE_INFO,
0429             "Object stack overflow! Obj=%p State=%p #Ops=%X",
0430             Object, WalkState, WalkState->NumOperands));
0431         return (AE_STACK_OVERFLOW);
0432     }
0433 
0434     /* Put the object onto the stack */
0435 
0436     WalkState->Operands [WalkState->OperandIndex] = Object;
0437     WalkState->NumOperands++;
0438 
0439     /* For the usual order of filling the operand stack */
0440 
0441     WalkState->OperandIndex++;
0442 
0443     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
0444         Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
0445         WalkState, WalkState->NumOperands));
0446 
0447     return (AE_OK);
0448 }
0449 
0450 
0451 /*******************************************************************************
0452  *
0453  * FUNCTION:    AcpiDsObjStackPop
0454  *
0455  * PARAMETERS:  PopCount            - Number of objects/entries to pop
0456  *              WalkState           - Current Walk state
0457  *
0458  * RETURN:      Status
0459  *
0460  * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
0461  *              deleted by this routine.
0462  *
0463  ******************************************************************************/
0464 
0465 ACPI_STATUS
0466 AcpiDsObjStackPop (
0467     UINT32                  PopCount,
0468     ACPI_WALK_STATE         *WalkState)
0469 {
0470     UINT32                  i;
0471 
0472 
0473     ACPI_FUNCTION_NAME (DsObjStackPop);
0474 
0475 
0476     for (i = 0; i < PopCount; i++)
0477     {
0478         /* Check for stack underflow */
0479 
0480         if (WalkState->NumOperands == 0)
0481         {
0482             ACPI_ERROR ((AE_INFO,
0483                 "Object stack underflow! Count=%X State=%p #Ops=%X",
0484                 PopCount, WalkState, WalkState->NumOperands));
0485             return (AE_STACK_UNDERFLOW);
0486         }
0487 
0488         /* Just set the stack entry to null */
0489 
0490         WalkState->NumOperands--;
0491         WalkState->Operands [WalkState->NumOperands] = NULL;
0492     }
0493 
0494     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
0495         PopCount, WalkState, WalkState->NumOperands));
0496 
0497     return (AE_OK);
0498 }
0499 
0500 
0501 /*******************************************************************************
0502  *
0503  * FUNCTION:    AcpiDsObjStackPopAndDelete
0504  *
0505  * PARAMETERS:  PopCount            - Number of objects/entries to pop
0506  *              WalkState           - Current Walk state
0507  *
0508  * RETURN:      Status
0509  *
0510  * DESCRIPTION: Pop this walk's object stack and delete each object that is
0511  *              popped off.
0512  *
0513  ******************************************************************************/
0514 
0515 void
0516 AcpiDsObjStackPopAndDelete (
0517     UINT32                  PopCount,
0518     ACPI_WALK_STATE         *WalkState)
0519 {
0520     INT32                   i;
0521     ACPI_OPERAND_OBJECT     *ObjDesc;
0522 
0523 
0524     ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);
0525 
0526 
0527     if (PopCount == 0)
0528     {
0529         return;
0530     }
0531 
0532     for (i = (INT32) PopCount - 1; i >= 0; i--)
0533     {
0534         if (WalkState->NumOperands == 0)
0535         {
0536             return;
0537         }
0538 
0539         /* Pop the stack and delete an object if present in this stack entry */
0540 
0541         WalkState->NumOperands--;
0542         ObjDesc = WalkState->Operands [i];
0543         if (ObjDesc)
0544         {
0545             AcpiUtRemoveReference (WalkState->Operands [i]);
0546             WalkState->Operands [i] = NULL;
0547         }
0548     }
0549 
0550     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
0551         PopCount, WalkState, WalkState->NumOperands));
0552 }
0553 
0554 
0555 /*******************************************************************************
0556  *
0557  * FUNCTION:    AcpiDsGetCurrentWalkState
0558  *
0559  * PARAMETERS:  Thread          - Get current active state for this Thread
0560  *
0561  * RETURN:      Pointer to the current walk state
0562  *
0563  * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
0564  *              walk state.)
0565  *
0566  ******************************************************************************/
0567 
0568 ACPI_WALK_STATE *
0569 AcpiDsGetCurrentWalkState (
0570     ACPI_THREAD_STATE       *Thread)
0571 {
0572     ACPI_FUNCTION_NAME (DsGetCurrentWalkState);
0573 
0574 
0575     if (!Thread)
0576     {
0577         return (NULL);
0578     }
0579 
0580     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",
0581         Thread->WalkStateList));
0582 
0583     return (Thread->WalkStateList);
0584 }
0585 
0586 
0587 /*******************************************************************************
0588  *
0589  * FUNCTION:    AcpiDsPushWalkState
0590  *
0591  * PARAMETERS:  WalkState       - State to push
0592  *              Thread          - Thread state object
0593  *
0594  * RETURN:      None
0595  *
0596  * DESCRIPTION: Place the Thread state at the head of the state list
0597  *
0598  ******************************************************************************/
0599 
0600 void
0601 AcpiDsPushWalkState (
0602     ACPI_WALK_STATE         *WalkState,
0603     ACPI_THREAD_STATE       *Thread)
0604 {
0605     ACPI_FUNCTION_TRACE (DsPushWalkState);
0606 
0607 
0608     WalkState->Next = Thread->WalkStateList;
0609     Thread->WalkStateList = WalkState;
0610 
0611     return_VOID;
0612 }
0613 
0614 
0615 /*******************************************************************************
0616  *
0617  * FUNCTION:    AcpiDsPopWalkState
0618  *
0619  * PARAMETERS:  Thread      - Current thread state
0620  *
0621  * RETURN:      A WalkState object popped from the thread's stack
0622  *
0623  * DESCRIPTION: Remove and return the walkstate object that is at the head of
0624  *              the walk stack for the given walk list.  NULL indicates that
0625  *              the list is empty.
0626  *
0627  ******************************************************************************/
0628 
0629 ACPI_WALK_STATE *
0630 AcpiDsPopWalkState (
0631     ACPI_THREAD_STATE       *Thread)
0632 {
0633     ACPI_WALK_STATE         *WalkState;
0634 
0635 
0636     ACPI_FUNCTION_TRACE (DsPopWalkState);
0637 
0638 
0639     WalkState = Thread->WalkStateList;
0640 
0641     if (WalkState)
0642     {
0643         /* Next walk state becomes the current walk state */
0644 
0645         Thread->WalkStateList = WalkState->Next;
0646 
0647         /*
0648          * Don't clear the NEXT field, this serves as an indicator
0649          * that there is a parent WALK STATE
0650          * Do Not: WalkState->Next = NULL;
0651          */
0652     }
0653 
0654     return_PTR (WalkState);
0655 }
0656 
0657 
0658 /*******************************************************************************
0659  *
0660  * FUNCTION:    AcpiDsCreateWalkState
0661  *
0662  * PARAMETERS:  OwnerId         - ID for object creation
0663  *              Origin          - Starting point for this walk
0664  *              MethodDesc      - Method object
0665  *              Thread          - Current thread state
0666  *
0667  * RETURN:      Pointer to the new walk state.
0668  *
0669  * DESCRIPTION: Allocate and initialize a new walk state.  The current walk
0670  *              state is set to this new state.
0671  *
0672  ******************************************************************************/
0673 
0674 ACPI_WALK_STATE *
0675 AcpiDsCreateWalkState (
0676     ACPI_OWNER_ID           OwnerId,
0677     ACPI_PARSE_OBJECT       *Origin,
0678     ACPI_OPERAND_OBJECT     *MethodDesc,
0679     ACPI_THREAD_STATE       *Thread)
0680 {
0681     ACPI_WALK_STATE         *WalkState;
0682 
0683 
0684     ACPI_FUNCTION_TRACE (DsCreateWalkState);
0685 
0686 
0687     WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));
0688     if (!WalkState)
0689     {
0690         return_PTR (NULL);
0691     }
0692 
0693     WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;
0694     WalkState->MethodDesc = MethodDesc;
0695     WalkState->OwnerId = OwnerId;
0696     WalkState->Origin = Origin;
0697     WalkState->Thread = Thread;
0698 
0699     WalkState->ParserState.StartOp = Origin;
0700 
0701     /* Init the method args/local */
0702 
0703 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
0704     AcpiDsMethodDataInit (WalkState);
0705 #endif
0706 
0707     /* Put the new state at the head of the walk list */
0708 
0709     if (Thread)
0710     {
0711         AcpiDsPushWalkState (WalkState, Thread);
0712     }
0713 
0714     return_PTR (WalkState);
0715 }
0716 
0717 
0718 /*******************************************************************************
0719  *
0720  * FUNCTION:    AcpiDsInitAmlWalk
0721  *
0722  * PARAMETERS:  WalkState       - New state to be initialized
0723  *              Op              - Current parse op
0724  *              MethodNode      - Control method NS node, if any
0725  *              AmlStart        - Start of AML
0726  *              AmlLength       - Length of AML
0727  *              Info            - Method info block (params, etc.)
0728  *              PassNumber      - 1, 2, or 3
0729  *
0730  * RETURN:      Status
0731  *
0732  * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
0733  *
0734  ******************************************************************************/
0735 
0736 ACPI_STATUS
0737 AcpiDsInitAmlWalk (
0738     ACPI_WALK_STATE         *WalkState,
0739     ACPI_PARSE_OBJECT       *Op,
0740     ACPI_NAMESPACE_NODE     *MethodNode,
0741     UINT8                   *AmlStart,
0742     UINT32                  AmlLength,
0743     ACPI_EVALUATE_INFO      *Info,
0744     UINT8                   PassNumber)
0745 {
0746     ACPI_STATUS             Status;
0747     ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
0748     ACPI_PARSE_OBJECT       *ExtraOp;
0749 
0750 
0751     ACPI_FUNCTION_TRACE (DsInitAmlWalk);
0752 
0753 
0754     WalkState->ParserState.Aml =
0755     WalkState->ParserState.AmlStart = AmlStart;
0756     WalkState->ParserState.AmlEnd =
0757     WalkState->ParserState.PkgEnd = AmlStart + AmlLength;
0758 
0759     /* The NextOp of the NextWalk will be the beginning of the method */
0760 
0761     WalkState->NextOp = NULL;
0762     WalkState->PassNumber = PassNumber;
0763 
0764     if (Info)
0765     {
0766         WalkState->Params = Info->Parameters;
0767         WalkState->CallerReturnDesc = &Info->ReturnObject;
0768     }
0769 
0770     Status = AcpiPsInitScope (&WalkState->ParserState, Op);
0771     if (ACPI_FAILURE (Status))
0772     {
0773         return_ACPI_STATUS (Status);
0774     }
0775 
0776     if (MethodNode)
0777     {
0778         WalkState->ParserState.StartNode = MethodNode;
0779         WalkState->WalkType = ACPI_WALK_METHOD;
0780         WalkState->MethodNode = MethodNode;
0781         WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);
0782 
0783         /* Push start scope on scope stack and make it current  */
0784 
0785         Status = AcpiDsScopeStackPush (MethodNode, ACPI_TYPE_METHOD, WalkState);
0786         if (ACPI_FAILURE (Status))
0787         {
0788             return_ACPI_STATUS (Status);
0789         }
0790 
0791         /* Init the method arguments */
0792 
0793         Status = AcpiDsMethodDataInitArgs (WalkState->Params,
0794                     ACPI_METHOD_NUM_ARGS, WalkState);
0795         if (ACPI_FAILURE (Status))
0796         {
0797             return_ACPI_STATUS (Status);
0798         }
0799     }
0800     else
0801     {
0802         /*
0803          * Setup the current scope.
0804          * Find a Named Op that has a namespace node associated with it.
0805          * search upwards from this Op.  Current scope is the first
0806          * Op with a namespace node.
0807          */
0808         ExtraOp = ParserState->StartOp;
0809         while (ExtraOp && !ExtraOp->Common.Node)
0810         {
0811             ExtraOp = ExtraOp->Common.Parent;
0812         }
0813 
0814         if (!ExtraOp)
0815         {
0816             ParserState->StartNode = NULL;
0817         }
0818         else
0819         {
0820             ParserState->StartNode = ExtraOp->Common.Node;
0821         }
0822 
0823         if (ParserState->StartNode)
0824         {
0825             /* Push start scope on scope stack and make it current  */
0826 
0827             Status = AcpiDsScopeStackPush (ParserState->StartNode,
0828                             ParserState->StartNode->Type, WalkState);
0829             if (ACPI_FAILURE (Status))
0830             {
0831                 return_ACPI_STATUS (Status);
0832             }
0833         }
0834     }
0835 
0836     Status = AcpiDsInitCallbacks (WalkState, PassNumber);
0837     return_ACPI_STATUS (Status);
0838 }
0839 
0840 
0841 /*******************************************************************************
0842  *
0843  * FUNCTION:    AcpiDsDeleteWalkState
0844  *
0845  * PARAMETERS:  WalkState       - State to delete
0846  *
0847  * RETURN:      Status
0848  *
0849  * DESCRIPTION: Delete a walk state including all internal data structures
0850  *
0851  ******************************************************************************/
0852 
0853 void
0854 AcpiDsDeleteWalkState (
0855     ACPI_WALK_STATE         *WalkState)
0856 {
0857     ACPI_GENERIC_STATE      *State;
0858 
0859 
0860     ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);
0861 
0862 
0863     if (!WalkState)
0864     {
0865         return;
0866     }
0867 
0868     if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)
0869     {
0870         ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",
0871             WalkState));
0872         return;
0873     }
0874 
0875     /* There should not be any open scopes */
0876 
0877     if (WalkState->ParserState.Scope)
0878     {
0879         ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",
0880             WalkState));
0881         AcpiPsCleanupScope (&WalkState->ParserState);
0882     }
0883 
0884     /* Always must free any linked control states */
0885 
0886     while (WalkState->ControlState)
0887     {
0888         State = WalkState->ControlState;
0889         WalkState->ControlState = State->Common.Next;
0890 
0891         AcpiUtDeleteGenericState (State);
0892     }
0893 
0894     /* Always must free any linked parse states */
0895 
0896     while (WalkState->ScopeInfo)
0897     {
0898         State = WalkState->ScopeInfo;
0899         WalkState->ScopeInfo = State->Common.Next;
0900 
0901         AcpiUtDeleteGenericState (State);
0902     }
0903 
0904     /* Always must free any stacked result states */
0905 
0906     while (WalkState->Results)
0907     {
0908         State = WalkState->Results;
0909         WalkState->Results = State->Common.Next;
0910 
0911         AcpiUtDeleteGenericState (State);
0912     }
0913 
0914     ACPI_FREE (WalkState);
0915     return_VOID;
0916 }
0917 
0918