Back to home page

Quest Cross Reference

 
 

    


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

0001 /******************************************************************************
0002  *
0003  * Module Name: psparse - Parser top level AML parse 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 /*
0118  * Parse the AML and build an operation tree as most interpreters,
0119  * like Perl, do.  Parsing is done by hand rather than with a YACC
0120  * generated parser to tightly constrain stack and dynamic memory
0121  * usage.  At the same time, parsing is kept flexible and the code
0122  * fairly compact by parsing based on a list of AML opcode
0123  * templates in AmlOpInfo[]
0124  */
0125 
0126 #include "acpi.h"
0127 #include "accommon.h"
0128 #include "acparser.h"
0129 #include "acdispat.h"
0130 #include "amlcode.h"
0131 #include "acnamesp.h"
0132 #include "acinterp.h"
0133 
0134 #define _COMPONENT          ACPI_PARSER
0135         ACPI_MODULE_NAME    ("psparse")
0136 
0137 
0138 /*******************************************************************************
0139  *
0140  * FUNCTION:    AcpiPsGetOpcodeSize
0141  *
0142  * PARAMETERS:  Opcode          - An AML opcode
0143  *
0144  * RETURN:      Size of the opcode, in bytes (1 or 2)
0145  *
0146  * DESCRIPTION: Get the size of the current opcode.
0147  *
0148  ******************************************************************************/
0149 
0150 UINT32
0151 AcpiPsGetOpcodeSize (
0152     UINT32                  Opcode)
0153 {
0154 
0155     /* Extended (2-byte) opcode if > 255 */
0156 
0157     if (Opcode > 0x00FF)
0158     {
0159         return (2);
0160     }
0161 
0162     /* Otherwise, just a single byte opcode */
0163 
0164     return (1);
0165 }
0166 
0167 
0168 /*******************************************************************************
0169  *
0170  * FUNCTION:    AcpiPsPeekOpcode
0171  *
0172  * PARAMETERS:  ParserState         - A parser state object
0173  *
0174  * RETURN:      Next AML opcode
0175  *
0176  * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
0177  *
0178  ******************************************************************************/
0179 
0180 UINT16
0181 AcpiPsPeekOpcode (
0182     ACPI_PARSE_STATE        *ParserState)
0183 {
0184     UINT8                   *Aml;
0185     UINT16                  Opcode;
0186 
0187 
0188     Aml = ParserState->Aml;
0189     Opcode = (UINT16) ACPI_GET8 (Aml);
0190 
0191     if (Opcode == AML_EXTENDED_OP_PREFIX)
0192     {
0193         /* Extended opcode, get the second opcode byte */
0194 
0195         Aml++;
0196         Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml));
0197     }
0198 
0199     return (Opcode);
0200 }
0201 
0202 
0203 /*******************************************************************************
0204  *
0205  * FUNCTION:    AcpiPsCompleteThisOp
0206  *
0207  * PARAMETERS:  WalkState       - Current State
0208  *              Op              - Op to complete
0209  *
0210  * RETURN:      Status
0211  *
0212  * DESCRIPTION: Perform any cleanup at the completion of an Op.
0213  *
0214  ******************************************************************************/
0215 
0216 ACPI_STATUS
0217 AcpiPsCompleteThisOp (
0218     ACPI_WALK_STATE         *WalkState,
0219     ACPI_PARSE_OBJECT       *Op)
0220 {
0221     ACPI_PARSE_OBJECT       *Prev;
0222     ACPI_PARSE_OBJECT       *Next;
0223     const ACPI_OPCODE_INFO  *ParentInfo;
0224     ACPI_PARSE_OBJECT       *ReplacementOp = NULL;
0225     ACPI_STATUS             Status = AE_OK;
0226 
0227 
0228     ACPI_FUNCTION_TRACE_PTR (PsCompleteThisOp, Op);
0229 
0230 
0231     /* Check for null Op, can happen if AML code is corrupt */
0232 
0233     if (!Op)
0234     {
0235         return_ACPI_STATUS (AE_OK);  /* OK for now */
0236     }
0237 
0238     /* Delete this op and the subtree below it if asked to */
0239 
0240     if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) ||
0241          (WalkState->OpInfo->Class == AML_CLASS_ARGUMENT))
0242     {
0243         return_ACPI_STATUS (AE_OK);
0244     }
0245 
0246     /* Make sure that we only delete this subtree */
0247 
0248     if (Op->Common.Parent)
0249     {
0250         Prev = Op->Common.Parent->Common.Value.Arg;
0251         if (!Prev)
0252         {
0253             /* Nothing more to do */
0254 
0255             goto Cleanup;
0256         }
0257 
0258         /*
0259          * Check if we need to replace the operator and its subtree
0260          * with a return value op (placeholder op)
0261          */
0262         ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
0263 
0264         switch (ParentInfo->Class)
0265         {
0266         case AML_CLASS_CONTROL:
0267             break;
0268 
0269         case AML_CLASS_CREATE:
0270 
0271             /*
0272              * These opcodes contain TermArg operands.  The current
0273              * op must be replaced by a placeholder return op
0274              */
0275             ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
0276             if (!ReplacementOp)
0277             {
0278                 Status = AE_NO_MEMORY;
0279             }
0280             break;
0281 
0282         case AML_CLASS_NAMED_OBJECT:
0283 
0284             /*
0285              * These opcodes contain TermArg operands.  The current
0286              * op must be replaced by a placeholder return op
0287              */
0288             if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
0289                 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
0290                 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
0291                 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
0292                 (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP)   ||
0293                 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
0294             {
0295                 ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
0296                 if (!ReplacementOp)
0297                 {
0298                     Status = AE_NO_MEMORY;
0299                 }
0300             }
0301             else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
0302                      (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
0303             {
0304                 if ((Op->Common.AmlOpcode == AML_BUFFER_OP) ||
0305                     (Op->Common.AmlOpcode == AML_PACKAGE_OP) ||
0306                     (Op->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
0307                 {
0308                     ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode);
0309                     if (!ReplacementOp)
0310                     {
0311                         Status = AE_NO_MEMORY;
0312                     }
0313                     else
0314                     {
0315                         ReplacementOp->Named.Data = Op->Named.Data;
0316                         ReplacementOp->Named.Length = Op->Named.Length;
0317                     }
0318                 }
0319             }
0320             break;
0321 
0322         default:
0323 
0324             ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
0325             if (!ReplacementOp)
0326             {
0327                 Status = AE_NO_MEMORY;
0328             }
0329         }
0330 
0331         /* We must unlink this op from the parent tree */
0332 
0333         if (Prev == Op)
0334         {
0335             /* This op is the first in the list */
0336 
0337             if (ReplacementOp)
0338             {
0339                 ReplacementOp->Common.Parent        = Op->Common.Parent;
0340                 ReplacementOp->Common.Value.Arg     = NULL;
0341                 ReplacementOp->Common.Node          = Op->Common.Node;
0342                 Op->Common.Parent->Common.Value.Arg = ReplacementOp;
0343                 ReplacementOp->Common.Next          = Op->Common.Next;
0344             }
0345             else
0346             {
0347                 Op->Common.Parent->Common.Value.Arg = Op->Common.Next;
0348             }
0349         }
0350 
0351         /* Search the parent list */
0352 
0353         else while (Prev)
0354         {
0355             /* Traverse all siblings in the parent's argument list */
0356 
0357             Next = Prev->Common.Next;
0358             if (Next == Op)
0359             {
0360                 if (ReplacementOp)
0361                 {
0362                     ReplacementOp->Common.Parent    = Op->Common.Parent;
0363                     ReplacementOp->Common.Value.Arg = NULL;
0364                     ReplacementOp->Common.Node      = Op->Common.Node;
0365                     Prev->Common.Next               = ReplacementOp;
0366                     ReplacementOp->Common.Next      = Op->Common.Next;
0367                     Next = NULL;
0368                 }
0369                 else
0370                 {
0371                     Prev->Common.Next = Op->Common.Next;
0372                     Next = NULL;
0373                 }
0374             }
0375             Prev = Next;
0376         }
0377     }
0378 
0379 
0380 Cleanup:
0381 
0382     /* Now we can actually delete the subtree rooted at Op */
0383 
0384     AcpiPsDeleteParseTree (Op);
0385     return_ACPI_STATUS (Status);
0386 }
0387 
0388 
0389 /*******************************************************************************
0390  *
0391  * FUNCTION:    AcpiPsNextParseState
0392  *
0393  * PARAMETERS:  WalkState           - Current state
0394  *              Op                  - Current parse op
0395  *              CallbackStatus      - Status from previous operation
0396  *
0397  * RETURN:      Status
0398  *
0399  * DESCRIPTION: Update the parser state based upon the return exception from
0400  *              the parser callback.
0401  *
0402  ******************************************************************************/
0403 
0404 ACPI_STATUS
0405 AcpiPsNextParseState (
0406     ACPI_WALK_STATE         *WalkState,
0407     ACPI_PARSE_OBJECT       *Op,
0408     ACPI_STATUS             CallbackStatus)
0409 {
0410     ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
0411     ACPI_STATUS             Status = AE_CTRL_PENDING;
0412 
0413 
0414     ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op);
0415 
0416 
0417     switch (CallbackStatus)
0418     {
0419     case AE_CTRL_TERMINATE:
0420         /*
0421          * A control method was terminated via a RETURN statement.
0422          * The walk of this method is complete.
0423          */
0424         ParserState->Aml = ParserState->AmlEnd;
0425         Status = AE_CTRL_TERMINATE;
0426         break;
0427 
0428 
0429     case AE_CTRL_BREAK:
0430 
0431         ParserState->Aml = WalkState->AmlLastWhile;
0432         WalkState->ControlState->Common.Value = FALSE;
0433         Status = AE_CTRL_BREAK;
0434         break;
0435 
0436 
0437     case AE_CTRL_CONTINUE:
0438 
0439         ParserState->Aml = WalkState->AmlLastWhile;
0440         Status = AE_CTRL_CONTINUE;
0441         break;
0442 
0443 
0444     case AE_CTRL_PENDING:
0445 
0446         ParserState->Aml = WalkState->AmlLastWhile;
0447         break;
0448 
0449 #if 0
0450     case AE_CTRL_SKIP:
0451 
0452         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
0453         Status = AE_OK;
0454         break;
0455 #endif
0456 
0457     case AE_CTRL_TRUE:
0458         /*
0459          * Predicate of an IF was true, and we are at the matching ELSE.
0460          * Just close out this package
0461          */
0462         ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState);
0463         Status = AE_CTRL_PENDING;
0464         break;
0465 
0466 
0467     case AE_CTRL_FALSE:
0468         /*
0469          * Either an IF/WHILE Predicate was false or we encountered a BREAK
0470          * opcode.  In both cases, we do not execute the rest of the
0471          * package;  We simply close out the parent (finishing the walk of
0472          * this branch of the tree) and continue execution at the parent
0473          * level.
0474          */
0475         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
0476 
0477         /* In the case of a BREAK, just force a predicate (if any) to FALSE */
0478 
0479         WalkState->ControlState->Common.Value = FALSE;
0480         Status = AE_CTRL_END;
0481         break;
0482 
0483 
0484     case AE_CTRL_TRANSFER:
0485 
0486         /* A method call (invocation) -- transfer control */
0487 
0488         Status = AE_CTRL_TRANSFER;
0489         WalkState->PrevOp = Op;
0490         WalkState->MethodCallOp = Op;
0491         WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node;
0492 
0493         /* Will return value (if any) be used by the caller? */
0494 
0495         WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState);
0496         break;
0497 
0498 
0499     default:
0500 
0501         Status = CallbackStatus;
0502         if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL)
0503         {
0504             Status = AE_OK;
0505         }
0506         break;
0507     }
0508 
0509     return_ACPI_STATUS (Status);
0510 }
0511 
0512 
0513 /*******************************************************************************
0514  *
0515  * FUNCTION:    AcpiPsParseAml
0516  *
0517  * PARAMETERS:  WalkState       - Current state
0518  *
0519  *
0520  * RETURN:      Status
0521  *
0522  * DESCRIPTION: Parse raw AML and return a tree of ops
0523  *
0524  ******************************************************************************/
0525 
0526 ACPI_STATUS
0527 AcpiPsParseAml (
0528     ACPI_WALK_STATE         *WalkState)
0529 {
0530     ACPI_STATUS             Status;
0531     ACPI_THREAD_STATE       *Thread;
0532     ACPI_THREAD_STATE       *PrevWalkList = AcpiGbl_CurrentWalkList;
0533     ACPI_WALK_STATE         *PreviousWalkState;
0534 
0535 
0536     ACPI_FUNCTION_TRACE (PsParseAml);
0537 
0538     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0539         "Entered with WalkState=%p Aml=%p size=%X\n",
0540         WalkState, WalkState->ParserState.Aml,
0541         WalkState->ParserState.AmlSize));
0542 
0543     if (!WalkState->ParserState.Aml)
0544     {
0545         return_ACPI_STATUS (AE_NULL_OBJECT);
0546     }
0547 
0548     /* Create and initialize a new thread state */
0549 
0550     Thread = AcpiUtCreateThreadState ();
0551     if (!Thread)
0552     {
0553         if (WalkState->MethodDesc)
0554         {
0555             /* Executing a control method - additional cleanup */
0556 
0557             AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
0558         }
0559 
0560         AcpiDsDeleteWalkState (WalkState);
0561         return_ACPI_STATUS (AE_NO_MEMORY);
0562     }
0563 
0564     WalkState->Thread = Thread;
0565 
0566     /*
0567      * If executing a method, the starting SyncLevel is this method's
0568      * SyncLevel
0569      */
0570     if (WalkState->MethodDesc)
0571     {
0572         WalkState->Thread->CurrentSyncLevel = WalkState->MethodDesc->Method.SyncLevel;
0573     }
0574 
0575     AcpiDsPushWalkState (WalkState, Thread);
0576 
0577     /*
0578      * This global allows the AML debugger to get a handle to the currently
0579      * executing control method.
0580      */
0581     AcpiGbl_CurrentWalkList = Thread;
0582 
0583     /*
0584      * Execute the walk loop as long as there is a valid Walk State.  This
0585      * handles nested control method invocations without recursion.
0586      */
0587     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState));
0588 
0589     Status = AE_OK;
0590     while (WalkState)
0591     {
0592         if (ACPI_SUCCESS (Status))
0593         {
0594             /*
0595              * The ParseLoop executes AML until the method terminates
0596              * or calls another method.
0597              */
0598             Status = AcpiPsParseLoop (WalkState);
0599         }
0600 
0601         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0602             "Completed one call to walk loop, %s State=%p\n",
0603             AcpiFormatException (Status), WalkState));
0604 
0605         if (Status == AE_CTRL_TRANSFER)
0606         {
0607             /*
0608              * A method call was detected.
0609              * Transfer control to the called control method
0610              */
0611             Status = AcpiDsCallControlMethod (Thread, WalkState, NULL);
0612             if (ACPI_FAILURE (Status))
0613             {
0614                 Status = AcpiDsMethodError (Status, WalkState);
0615             }
0616 
0617             /*
0618              * If the transfer to the new method method call worked, a new walk
0619              * state was created -- get it
0620              */
0621             WalkState = AcpiDsGetCurrentWalkState (Thread);
0622             continue;
0623         }
0624         else if (Status == AE_CTRL_TERMINATE)
0625         {
0626             Status = AE_OK;
0627         }
0628         else if ((Status != AE_OK) && (WalkState->MethodDesc))
0629         {
0630             /* Either the method parse or actual execution failed */
0631 
0632             ACPI_ERROR_METHOD ("Method parse/execution failed",
0633                 WalkState->MethodNode, NULL, Status);
0634 
0635             /* Check for possible multi-thread reentrancy problem */
0636 
0637             if ((Status == AE_ALREADY_EXISTS) &&
0638                 (!WalkState->MethodDesc->Method.Mutex))
0639             {
0640                 ACPI_INFO ((AE_INFO,
0641                     "Marking method %4.4s as Serialized because of AE_ALREADY_EXISTS error",
0642                     WalkState->MethodNode->Name.Ascii));
0643 
0644                 /*
0645                  * Method tried to create an object twice. The probable cause is
0646                  * that the method cannot handle reentrancy.
0647                  *
0648                  * The method is marked NotSerialized, but it tried to create
0649                  * a named object, causing the second thread entrance to fail.
0650                  * Workaround this problem by marking the method permanently
0651                  * as Serialized.
0652                  */
0653                 WalkState->MethodDesc->Method.MethodFlags |= AML_METHOD_SERIALIZED;
0654                 WalkState->MethodDesc->Method.SyncLevel = 0;
0655             }
0656         }
0657 
0658         /* We are done with this walk, move on to the parent if any */
0659 
0660         WalkState = AcpiDsPopWalkState (Thread);
0661 
0662         /* Reset the current scope to the beginning of scope stack */
0663 
0664         AcpiDsScopeStackClear (WalkState);
0665 
0666         /*
0667          * If we just returned from the execution of a control method or if we
0668          * encountered an error during the method parse phase, there's lots of
0669          * cleanup to do
0670          */
0671         if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) ||
0672             (ACPI_FAILURE (Status)))
0673         {
0674             AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
0675         }
0676 
0677         /* Delete this walk state and all linked control states */
0678 
0679         AcpiPsCleanupScope (&WalkState->ParserState);
0680         PreviousWalkState = WalkState;
0681 
0682         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0683             "ReturnValue=%p, ImplicitValue=%p State=%p\n",
0684             WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState));
0685 
0686         /* Check if we have restarted a preempted walk */
0687 
0688         WalkState = AcpiDsGetCurrentWalkState (Thread);
0689         if (WalkState)
0690         {
0691             if (ACPI_SUCCESS (Status))
0692             {
0693                 /*
0694                  * There is another walk state, restart it.
0695                  * If the method return value is not used by the parent,
0696                  * The object is deleted
0697                  */
0698                 if (!PreviousWalkState->ReturnDesc)
0699                 {
0700                     /*
0701                      * In slack mode execution, if there is no return value
0702                      * we should implicitly return zero (0) as a default value.
0703                      */
0704                     if (AcpiGbl_EnableInterpreterSlack &&
0705                         !PreviousWalkState->ImplicitReturnObj)
0706                     {
0707                         PreviousWalkState->ImplicitReturnObj =
0708                             AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
0709                         if (!PreviousWalkState->ImplicitReturnObj)
0710                         {
0711                             return_ACPI_STATUS (AE_NO_MEMORY);
0712                         }
0713 
0714                         PreviousWalkState->ImplicitReturnObj->Integer.Value = 0;
0715                     }
0716 
0717                     /* Restart the calling control method */
0718 
0719                     Status = AcpiDsRestartControlMethod (WalkState,
0720                                 PreviousWalkState->ImplicitReturnObj);
0721                 }
0722                 else
0723                 {
0724                     /*
0725                      * We have a valid return value, delete any implicit
0726                      * return value.
0727                      */
0728                     AcpiDsClearImplicitReturn (PreviousWalkState);
0729 
0730                     Status = AcpiDsRestartControlMethod (WalkState,
0731                                 PreviousWalkState->ReturnDesc);
0732                 }
0733                 if (ACPI_SUCCESS (Status))
0734                 {
0735                     WalkState->WalkType |= ACPI_WALK_METHOD_RESTART;
0736                 }
0737             }
0738             else
0739             {
0740                 /* On error, delete any return object or implicit return */
0741 
0742                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
0743                 AcpiDsClearImplicitReturn (PreviousWalkState);
0744             }
0745         }
0746 
0747         /*
0748          * Just completed a 1st-level method, save the final internal return
0749          * value (if any)
0750          */
0751         else if (PreviousWalkState->CallerReturnDesc)
0752         {
0753             if (PreviousWalkState->ImplicitReturnObj)
0754             {
0755                 *(PreviousWalkState->CallerReturnDesc) =
0756                     PreviousWalkState->ImplicitReturnObj;
0757             }
0758             else
0759             {
0760                  /* NULL if no return value */
0761 
0762                 *(PreviousWalkState->CallerReturnDesc) =
0763                     PreviousWalkState->ReturnDesc;
0764             }
0765         }
0766         else
0767         {
0768             if (PreviousWalkState->ReturnDesc)
0769             {
0770                 /* Caller doesn't want it, must delete it */
0771 
0772                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
0773             }
0774             if (PreviousWalkState->ImplicitReturnObj)
0775             {
0776                 /* Caller doesn't want it, must delete it */
0777 
0778                 AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj);
0779             }
0780         }
0781 
0782         AcpiDsDeleteWalkState (PreviousWalkState);
0783     }
0784 
0785     /* Normal exit */
0786 
0787     AcpiExReleaseAllMutexes (Thread);
0788     AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread));
0789     AcpiGbl_CurrentWalkList = PrevWalkList;
0790     return_ACPI_STATUS (Status);
0791 }
0792 
0793