Back to home page

Quest Cross Reference

 
 

    


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

0001 /******************************************************************************
0002  *
0003  * Module Name: dsopcode - Dispatcher Op Region support and handling of
0004  *                         "control" opcodes
0005  *
0006  *****************************************************************************/
0007 
0008 /******************************************************************************
0009  *
0010  * 1. Copyright Notice
0011  *
0012  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0013  * All rights reserved.
0014  *
0015  * 2. License
0016  *
0017  * 2.1. This is your license from Intel Corp. under its intellectual property
0018  * rights.  You may have additional license terms from the party that provided
0019  * you this software, covering your right to use that party's intellectual
0020  * property rights.
0021  *
0022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0023  * copy of the source code appearing in this file ("Covered Code") an
0024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0025  * base code distributed originally by Intel ("Original Intel Code") to copy,
0026  * make derivatives, distribute, use and display any portion of the Covered
0027  * Code in any form, with the right to sublicense such rights; and
0028  *
0029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0030  * license (with the right to sublicense), under only those claims of Intel
0031  * patents that are infringed by the Original Intel Code, to make, use, sell,
0032  * offer to sell, and import the Covered Code and derivative works thereof
0033  * solely to the minimum extent necessary to exercise the above copyright
0034  * license, and in no event shall the patent license extend to any additions
0035  * to or modifications of the Original Intel Code.  No other license or right
0036  * is granted directly or by implication, estoppel or otherwise;
0037  *
0038  * The above copyright and patent license is granted only if the following
0039  * conditions are met:
0040  *
0041  * 3. Conditions
0042  *
0043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0044  * Redistribution of source code of any substantial portion of the Covered
0045  * Code or modification with rights to further distribute source must include
0046  * the above Copyright Notice, the above License, this list of Conditions,
0047  * and the following Disclaimer and Export Compliance provision.  In addition,
0048  * Licensee must cause all Covered Code to which Licensee contributes to
0049  * contain a file documenting the changes Licensee made to create that Covered
0050  * Code and the date of any change.  Licensee must include in that file the
0051  * documentation of any changes made by any predecessor Licensee.  Licensee
0052  * must include a prominent statement that the modification is derived,
0053  * directly or indirectly, from Original Intel Code.
0054  *
0055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0056  * Redistribution of source code of any substantial portion of the Covered
0057  * Code or modification without rights to further distribute source must
0058  * include the following Disclaimer and Export Compliance provision in the
0059  * documentation and/or other materials provided with distribution.  In
0060  * addition, Licensee may not authorize further sublicense of source of any
0061  * portion of the Covered Code, and must include terms to the effect that the
0062  * license from Licensee to its licensee is limited to the intellectual
0063  * property embodied in the software Licensee provides to its licensee, and
0064  * not to intellectual property embodied in modifications its licensee may
0065  * make.
0066  *
0067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0068  * substantial portion of the Covered Code or modification must reproduce the
0069  * above Copyright Notice, and the following Disclaimer and Export Compliance
0070  * provision in the documentation and/or other materials provided with the
0071  * distribution.
0072  *
0073  * 3.4. Intel retains all right, title, and interest in and to the Original
0074  * Intel Code.
0075  *
0076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0077  * Intel shall be used in advertising or otherwise to promote the sale, use or
0078  * other dealings in products derived from or relating to the Covered Code
0079  * without prior written authorization from Intel.
0080  *
0081  * 4. Disclaimer and Export Compliance
0082  *
0083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0089  * PARTICULAR PURPOSE.
0090  *
0091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0098  * LIMITED REMEDY.
0099  *
0100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0101  * software or system incorporating such software without first obtaining any
0102  * required license or other approval from the U. S. Department of Commerce or
0103  * any other agency or department of the United States Government.  In the
0104  * event Licensee exports any such software from the United States or
0105  * re-exports any such software from a foreign destination, Licensee shall
0106  * ensure that the distribution and export/re-export of the software is in
0107  * compliance with all laws, regulations, orders, or other restrictions of the
0108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0109  * any of its subsidiaries will export/re-export any technical data, process,
0110  * software, or service, directly or indirectly, to any country for which the
0111  * United States government or any agency thereof requires an export license,
0112  * other governmental approval, or letter of assurance, without first obtaining
0113  * such license, approval or letter.
0114  *
0115  *****************************************************************************/
0116 
0117 #define __DSOPCODE_C__
0118 
0119 #include "acpi.h"
0120 #include "accommon.h"
0121 #include "acparser.h"
0122 #include "amlcode.h"
0123 #include "acdispat.h"
0124 #include "acinterp.h"
0125 #include "acnamesp.h"
0126 #include "acevents.h"
0127 #include "actables.h"
0128 
0129 #define _COMPONENT          ACPI_DISPATCHER
0130         ACPI_MODULE_NAME    ("dsopcode")
0131 
0132 /* Local prototypes */
0133 
0134 static ACPI_STATUS
0135 AcpiDsExecuteArguments (
0136     ACPI_NAMESPACE_NODE     *Node,
0137     ACPI_NAMESPACE_NODE     *ScopeNode,
0138     UINT32                  AmlLength,
0139     UINT8                   *AmlStart);
0140 
0141 static ACPI_STATUS
0142 AcpiDsInitBufferField (
0143     UINT16                  AmlOpcode,
0144     ACPI_OPERAND_OBJECT     *ObjDesc,
0145     ACPI_OPERAND_OBJECT     *BufferDesc,
0146     ACPI_OPERAND_OBJECT     *OffsetDesc,
0147     ACPI_OPERAND_OBJECT     *LengthDesc,
0148     ACPI_OPERAND_OBJECT     *ResultDesc);
0149 
0150 
0151 /*******************************************************************************
0152  *
0153  * FUNCTION:    AcpiDsExecuteArguments
0154  *
0155  * PARAMETERS:  Node                - Object NS node
0156  *              ScopeNode           - Parent NS node
0157  *              AmlLength           - Length of executable AML
0158  *              AmlStart            - Pointer to the AML
0159  *
0160  * RETURN:      Status.
0161  *
0162  * DESCRIPTION: Late (deferred) execution of region or field arguments
0163  *
0164  ******************************************************************************/
0165 
0166 static ACPI_STATUS
0167 AcpiDsExecuteArguments (
0168     ACPI_NAMESPACE_NODE     *Node,
0169     ACPI_NAMESPACE_NODE     *ScopeNode,
0170     UINT32                  AmlLength,
0171     UINT8                   *AmlStart)
0172 {
0173     ACPI_STATUS             Status;
0174     ACPI_PARSE_OBJECT       *Op;
0175     ACPI_WALK_STATE         *WalkState;
0176 
0177 
0178     ACPI_FUNCTION_TRACE (DsExecuteArguments);
0179 
0180 
0181     /*
0182      * Allocate a new parser op to be the root of the parsed tree
0183      */
0184     Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
0185     if (!Op)
0186     {
0187         return_ACPI_STATUS (AE_NO_MEMORY);
0188     }
0189 
0190     /* Save the Node for use in AcpiPsParseAml */
0191 
0192     Op->Common.Node = ScopeNode;
0193 
0194     /* Create and initialize a new parser state */
0195 
0196     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
0197     if (!WalkState)
0198     {
0199         Status = AE_NO_MEMORY;
0200         goto Cleanup;
0201     }
0202 
0203     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
0204                     AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
0205     if (ACPI_FAILURE (Status))
0206     {
0207         AcpiDsDeleteWalkState (WalkState);
0208         goto Cleanup;
0209     }
0210 
0211     /* Mark this parse as a deferred opcode */
0212 
0213     WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
0214     WalkState->DeferredNode = Node;
0215 
0216     /* Pass1: Parse the entire declaration */
0217 
0218     Status = AcpiPsParseAml (WalkState);
0219     if (ACPI_FAILURE (Status))
0220     {
0221         goto Cleanup;
0222     }
0223 
0224     /* Get and init the Op created above */
0225 
0226     Op->Common.Node = Node;
0227     AcpiPsDeleteParseTree (Op);
0228 
0229     /* Evaluate the deferred arguments */
0230 
0231     Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP);
0232     if (!Op)
0233     {
0234         return_ACPI_STATUS (AE_NO_MEMORY);
0235     }
0236 
0237     Op->Common.Node = ScopeNode;
0238 
0239     /* Create and initialize a new parser state */
0240 
0241     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
0242     if (!WalkState)
0243     {
0244         Status = AE_NO_MEMORY;
0245         goto Cleanup;
0246     }
0247 
0248     /* Execute the opcode and arguments */
0249 
0250     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
0251                     AmlLength, NULL, ACPI_IMODE_EXECUTE);
0252     if (ACPI_FAILURE (Status))
0253     {
0254         AcpiDsDeleteWalkState (WalkState);
0255         goto Cleanup;
0256     }
0257 
0258     /* Mark this execution as a deferred opcode */
0259 
0260     WalkState->DeferredNode = Node;
0261     Status = AcpiPsParseAml (WalkState);
0262 
0263 Cleanup:
0264     AcpiPsDeleteParseTree (Op);
0265     return_ACPI_STATUS (Status);
0266 }
0267 
0268 
0269 /*******************************************************************************
0270  *
0271  * FUNCTION:    AcpiDsGetBufferFieldArguments
0272  *
0273  * PARAMETERS:  ObjDesc         - A valid BufferField object
0274  *
0275  * RETURN:      Status.
0276  *
0277  * DESCRIPTION: Get BufferField Buffer and Index.  This implements the late
0278  *              evaluation of these field attributes.
0279  *
0280  ******************************************************************************/
0281 
0282 ACPI_STATUS
0283 AcpiDsGetBufferFieldArguments (
0284     ACPI_OPERAND_OBJECT     *ObjDesc)
0285 {
0286     ACPI_OPERAND_OBJECT     *ExtraDesc;
0287     ACPI_NAMESPACE_NODE     *Node;
0288     ACPI_STATUS             Status;
0289 
0290 
0291     ACPI_FUNCTION_TRACE_PTR (DsGetBufferFieldArguments, ObjDesc);
0292 
0293 
0294     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
0295     {
0296         return_ACPI_STATUS (AE_OK);
0297     }
0298 
0299     /* Get the AML pointer (method object) and BufferField node */
0300 
0301     ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
0302     Node = ObjDesc->BufferField.Node;
0303 
0304     ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_BUFFER_FIELD, Node, NULL));
0305     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
0306         AcpiUtGetNodeName (Node)));
0307 
0308     /* Execute the AML code for the TermArg arguments */
0309 
0310     Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
0311                 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
0312     return_ACPI_STATUS (Status);
0313 }
0314 
0315 
0316 /*******************************************************************************
0317  *
0318  * FUNCTION:    AcpiDsGetBankFieldArguments
0319  *
0320  * PARAMETERS:  ObjDesc         - A valid BankField object
0321  *
0322  * RETURN:      Status.
0323  *
0324  * DESCRIPTION: Get BankField BankValue.  This implements the late
0325  *              evaluation of these field attributes.
0326  *
0327  ******************************************************************************/
0328 
0329 ACPI_STATUS
0330 AcpiDsGetBankFieldArguments (
0331     ACPI_OPERAND_OBJECT     *ObjDesc)
0332 {
0333     ACPI_OPERAND_OBJECT     *ExtraDesc;
0334     ACPI_NAMESPACE_NODE     *Node;
0335     ACPI_STATUS             Status;
0336 
0337 
0338     ACPI_FUNCTION_TRACE_PTR (DsGetBankFieldArguments, ObjDesc);
0339 
0340 
0341     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
0342     {
0343         return_ACPI_STATUS (AE_OK);
0344     }
0345 
0346     /* Get the AML pointer (method object) and BankField node */
0347 
0348     ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
0349     Node = ObjDesc->BankField.Node;
0350 
0351     ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_LOCAL_BANK_FIELD, Node, NULL));
0352     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
0353         AcpiUtGetNodeName (Node)));
0354 
0355     /* Execute the AML code for the TermArg arguments */
0356 
0357     Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
0358                 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
0359     return_ACPI_STATUS (Status);
0360 }
0361 
0362 
0363 /*******************************************************************************
0364  *
0365  * FUNCTION:    AcpiDsGetBufferArguments
0366  *
0367  * PARAMETERS:  ObjDesc         - A valid Buffer object
0368  *
0369  * RETURN:      Status.
0370  *
0371  * DESCRIPTION: Get Buffer length and initializer byte list.  This implements
0372  *              the late evaluation of these attributes.
0373  *
0374  ******************************************************************************/
0375 
0376 ACPI_STATUS
0377 AcpiDsGetBufferArguments (
0378     ACPI_OPERAND_OBJECT     *ObjDesc)
0379 {
0380     ACPI_NAMESPACE_NODE     *Node;
0381     ACPI_STATUS             Status;
0382 
0383 
0384     ACPI_FUNCTION_TRACE_PTR (DsGetBufferArguments, ObjDesc);
0385 
0386 
0387     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
0388     {
0389         return_ACPI_STATUS (AE_OK);
0390     }
0391 
0392     /* Get the Buffer node */
0393 
0394     Node = ObjDesc->Buffer.Node;
0395     if (!Node)
0396     {
0397         ACPI_ERROR ((AE_INFO,
0398             "No pointer back to NS node in buffer obj %p", ObjDesc));
0399         return_ACPI_STATUS (AE_AML_INTERNAL);
0400     }
0401 
0402     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
0403 
0404     /* Execute the AML code for the TermArg arguments */
0405 
0406     Status = AcpiDsExecuteArguments (Node, Node,
0407                 ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
0408     return_ACPI_STATUS (Status);
0409 }
0410 
0411 
0412 /*******************************************************************************
0413  *
0414  * FUNCTION:    AcpiDsGetPackageArguments
0415  *
0416  * PARAMETERS:  ObjDesc         - A valid Package object
0417  *
0418  * RETURN:      Status.
0419  *
0420  * DESCRIPTION: Get Package length and initializer byte list.  This implements
0421  *              the late evaluation of these attributes.
0422  *
0423  ******************************************************************************/
0424 
0425 ACPI_STATUS
0426 AcpiDsGetPackageArguments (
0427     ACPI_OPERAND_OBJECT     *ObjDesc)
0428 {
0429     ACPI_NAMESPACE_NODE     *Node;
0430     ACPI_STATUS             Status;
0431 
0432 
0433     ACPI_FUNCTION_TRACE_PTR (DsGetPackageArguments, ObjDesc);
0434 
0435 
0436     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
0437     {
0438         return_ACPI_STATUS (AE_OK);
0439     }
0440 
0441     /* Get the Package node */
0442 
0443     Node = ObjDesc->Package.Node;
0444     if (!Node)
0445     {
0446         ACPI_ERROR ((AE_INFO,
0447             "No pointer back to NS node in package %p", ObjDesc));
0448         return_ACPI_STATUS (AE_AML_INTERNAL);
0449     }
0450 
0451     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
0452 
0453     /* Execute the AML code for the TermArg arguments */
0454 
0455     Status = AcpiDsExecuteArguments (Node, Node,
0456                 ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
0457     return_ACPI_STATUS (Status);
0458 }
0459 
0460 
0461 /*****************************************************************************
0462  *
0463  * FUNCTION:    AcpiDsGetRegionArguments
0464  *
0465  * PARAMETERS:  ObjDesc         - A valid region object
0466  *
0467  * RETURN:      Status.
0468  *
0469  * DESCRIPTION: Get region address and length.  This implements the late
0470  *              evaluation of these region attributes.
0471  *
0472  ****************************************************************************/
0473 
0474 ACPI_STATUS
0475 AcpiDsGetRegionArguments (
0476     ACPI_OPERAND_OBJECT     *ObjDesc)
0477 {
0478     ACPI_NAMESPACE_NODE     *Node;
0479     ACPI_STATUS             Status;
0480     ACPI_OPERAND_OBJECT     *ExtraDesc;
0481 
0482 
0483     ACPI_FUNCTION_TRACE_PTR (DsGetRegionArguments, ObjDesc);
0484 
0485 
0486     if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
0487     {
0488         return_ACPI_STATUS (AE_OK);
0489     }
0490 
0491     ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
0492     if (!ExtraDesc)
0493     {
0494         return_ACPI_STATUS (AE_NOT_EXIST);
0495     }
0496 
0497     /* Get the Region node */
0498 
0499     Node = ObjDesc->Region.Node;
0500 
0501     ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (ACPI_TYPE_REGION, Node, NULL));
0502 
0503     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
0504         AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
0505 
0506     /* Execute the argument AML */
0507 
0508     Status = AcpiDsExecuteArguments (Node, AcpiNsGetParentNode (Node),
0509                 ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
0510     return_ACPI_STATUS (Status);
0511 }
0512 
0513 
0514 /*******************************************************************************
0515  *
0516  * FUNCTION:    AcpiDsInitializeRegion
0517  *
0518  * PARAMETERS:  ObjHandle       - Region namespace node
0519  *
0520  * RETURN:      Status
0521  *
0522  * DESCRIPTION: Front end to EvInitializeRegion
0523  *
0524  ******************************************************************************/
0525 
0526 ACPI_STATUS
0527 AcpiDsInitializeRegion (
0528     ACPI_HANDLE             ObjHandle)
0529 {
0530     ACPI_OPERAND_OBJECT     *ObjDesc;
0531     ACPI_STATUS             Status;
0532 
0533 
0534     ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
0535 
0536     /* Namespace is NOT locked */
0537 
0538     Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
0539     return (Status);
0540 }
0541 
0542 
0543 /*******************************************************************************
0544  *
0545  * FUNCTION:    AcpiDsInitBufferField
0546  *
0547  * PARAMETERS:  AmlOpcode       - CreateXxxField
0548  *              ObjDesc         - BufferField object
0549  *              BufferDesc      - Host Buffer
0550  *              OffsetDesc      - Offset into buffer
0551  *              LengthDesc      - Length of field (CREATE_FIELD_OP only)
0552  *              ResultDesc      - Where to store the result
0553  *
0554  * RETURN:      Status
0555  *
0556  * DESCRIPTION: Perform actual initialization of a buffer field
0557  *
0558  ******************************************************************************/
0559 
0560 static ACPI_STATUS
0561 AcpiDsInitBufferField (
0562     UINT16                  AmlOpcode,
0563     ACPI_OPERAND_OBJECT     *ObjDesc,
0564     ACPI_OPERAND_OBJECT     *BufferDesc,
0565     ACPI_OPERAND_OBJECT     *OffsetDesc,
0566     ACPI_OPERAND_OBJECT     *LengthDesc,
0567     ACPI_OPERAND_OBJECT     *ResultDesc)
0568 {
0569     UINT32                  Offset;
0570     UINT32                  BitOffset;
0571     UINT32                  BitCount;
0572     UINT8                   FieldFlags;
0573     ACPI_STATUS             Status;
0574 
0575 
0576     ACPI_FUNCTION_TRACE_PTR (DsInitBufferField, ObjDesc);
0577 
0578 
0579     /* Host object must be a Buffer */
0580 
0581     if (BufferDesc->Common.Type != ACPI_TYPE_BUFFER)
0582     {
0583         ACPI_ERROR ((AE_INFO,
0584             "Target of Create Field is not a Buffer object - %s",
0585             AcpiUtGetObjectTypeName (BufferDesc)));
0586 
0587         Status = AE_AML_OPERAND_TYPE;
0588         goto Cleanup;
0589     }
0590 
0591     /*
0592      * The last parameter to all of these opcodes (ResultDesc) started
0593      * out as a NameString, and should therefore now be a NS node
0594      * after resolution in AcpiExResolveOperands().
0595      */
0596     if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
0597     {
0598         ACPI_ERROR ((AE_INFO,
0599             "(%s) destination not a NS Node [%s]",
0600             AcpiPsGetOpcodeName (AmlOpcode),
0601             AcpiUtGetDescriptorName (ResultDesc)));
0602 
0603         Status = AE_AML_OPERAND_TYPE;
0604         goto Cleanup;
0605     }
0606 
0607     Offset = (UINT32) OffsetDesc->Integer.Value;
0608 
0609     /*
0610      * Setup the Bit offsets and counts, according to the opcode
0611      */
0612     switch (AmlOpcode)
0613     {
0614     case AML_CREATE_FIELD_OP:
0615 
0616         /* Offset is in bits, count is in bits */
0617 
0618         FieldFlags = AML_FIELD_ACCESS_BYTE;
0619         BitOffset  = Offset;
0620         BitCount   = (UINT32) LengthDesc->Integer.Value;
0621 
0622         /* Must have a valid (>0) bit count */
0623 
0624         if (BitCount == 0)
0625         {
0626             ACPI_ERROR ((AE_INFO,
0627                 "Attempt to CreateField of length zero"));
0628             Status = AE_AML_OPERAND_VALUE;
0629             goto Cleanup;
0630         }
0631         break;
0632 
0633     case AML_CREATE_BIT_FIELD_OP:
0634 
0635         /* Offset is in bits, Field is one bit */
0636 
0637         BitOffset  = Offset;
0638         BitCount   = 1;
0639         FieldFlags = AML_FIELD_ACCESS_BYTE;
0640         break;
0641 
0642     case AML_CREATE_BYTE_FIELD_OP:
0643 
0644         /* Offset is in bytes, field is one byte */
0645 
0646         BitOffset  = 8 * Offset;
0647         BitCount   = 8;
0648         FieldFlags = AML_FIELD_ACCESS_BYTE;
0649         break;
0650 
0651     case AML_CREATE_WORD_FIELD_OP:
0652 
0653         /* Offset is in bytes, field is one word */
0654 
0655         BitOffset  = 8 * Offset;
0656         BitCount   = 16;
0657         FieldFlags = AML_FIELD_ACCESS_WORD;
0658         break;
0659 
0660     case AML_CREATE_DWORD_FIELD_OP:
0661 
0662         /* Offset is in bytes, field is one dword */
0663 
0664         BitOffset  = 8 * Offset;
0665         BitCount   = 32;
0666         FieldFlags = AML_FIELD_ACCESS_DWORD;
0667         break;
0668 
0669     case AML_CREATE_QWORD_FIELD_OP:
0670 
0671         /* Offset is in bytes, field is one qword */
0672 
0673         BitOffset  = 8 * Offset;
0674         BitCount   = 64;
0675         FieldFlags = AML_FIELD_ACCESS_QWORD;
0676         break;
0677 
0678     default:
0679 
0680         ACPI_ERROR ((AE_INFO,
0681             "Unknown field creation opcode %02x",
0682             AmlOpcode));
0683         Status = AE_AML_BAD_OPCODE;
0684         goto Cleanup;
0685     }
0686 
0687     /* Entire field must fit within the current length of the buffer */
0688 
0689     if ((BitOffset + BitCount) >
0690         (8 * (UINT32) BufferDesc->Buffer.Length))
0691     {
0692         ACPI_ERROR ((AE_INFO,
0693             "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
0694             AcpiUtGetNodeName (ResultDesc),
0695             BitOffset + BitCount,
0696             AcpiUtGetNodeName (BufferDesc->Buffer.Node),
0697             8 * (UINT32) BufferDesc->Buffer.Length));
0698         Status = AE_AML_BUFFER_LIMIT;
0699         goto Cleanup;
0700     }
0701 
0702     /*
0703      * Initialize areas of the field object that are common to all fields
0704      * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
0705      * UPDATE_RULE = 0 (UPDATE_PRESERVE)
0706      */
0707     Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags, 0,
0708                                             BitOffset, BitCount);
0709     if (ACPI_FAILURE (Status))
0710     {
0711         goto Cleanup;
0712     }
0713 
0714     ObjDesc->BufferField.BufferObj = BufferDesc;
0715 
0716     /* Reference count for BufferDesc inherits ObjDesc count */
0717 
0718     BufferDesc->Common.ReferenceCount = (UINT16)
0719         (BufferDesc->Common.ReferenceCount + ObjDesc->Common.ReferenceCount);
0720 
0721 
0722 Cleanup:
0723 
0724     /* Always delete the operands */
0725 
0726     AcpiUtRemoveReference (OffsetDesc);
0727     AcpiUtRemoveReference (BufferDesc);
0728 
0729     if (AmlOpcode == AML_CREATE_FIELD_OP)
0730     {
0731         AcpiUtRemoveReference (LengthDesc);
0732     }
0733 
0734     /* On failure, delete the result descriptor */
0735 
0736     if (ACPI_FAILURE (Status))
0737     {
0738         AcpiUtRemoveReference (ResultDesc);     /* Result descriptor */
0739     }
0740     else
0741     {
0742         /* Now the address and length are valid for this BufferField */
0743 
0744         ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
0745     }
0746 
0747     return_ACPI_STATUS (Status);
0748 }
0749 
0750 
0751 /*******************************************************************************
0752  *
0753  * FUNCTION:    AcpiDsEvalBufferFieldOperands
0754  *
0755  * PARAMETERS:  WalkState       - Current walk
0756  *              Op              - A valid BufferField Op object
0757  *
0758  * RETURN:      Status
0759  *
0760  * DESCRIPTION: Get BufferField Buffer and Index
0761  *              Called from AcpiDsExecEndOp during BufferField parse tree walk
0762  *
0763  ******************************************************************************/
0764 
0765 ACPI_STATUS
0766 AcpiDsEvalBufferFieldOperands (
0767     ACPI_WALK_STATE         *WalkState,
0768     ACPI_PARSE_OBJECT       *Op)
0769 {
0770     ACPI_STATUS             Status;
0771     ACPI_OPERAND_OBJECT     *ObjDesc;
0772     ACPI_NAMESPACE_NODE     *Node;
0773     ACPI_PARSE_OBJECT       *NextOp;
0774 
0775 
0776     ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands, Op);
0777 
0778 
0779     /*
0780      * This is where we evaluate the address and length fields of the
0781      * CreateXxxField declaration
0782      */
0783     Node =  Op->Common.Node;
0784 
0785     /* NextOp points to the op that holds the Buffer */
0786 
0787     NextOp = Op->Common.Value.Arg;
0788 
0789     /* Evaluate/create the address and length operands */
0790 
0791     Status = AcpiDsCreateOperands (WalkState, NextOp);
0792     if (ACPI_FAILURE (Status))
0793     {
0794         return_ACPI_STATUS (Status);
0795     }
0796 
0797     ObjDesc = AcpiNsGetAttachedObject (Node);
0798     if (!ObjDesc)
0799     {
0800         return_ACPI_STATUS (AE_NOT_EXIST);
0801     }
0802 
0803     /* Resolve the operands */
0804 
0805     Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
0806                     ACPI_WALK_OPERANDS, WalkState);
0807     if (ACPI_FAILURE (Status))
0808     {
0809         ACPI_ERROR ((AE_INFO, "(%s) bad operand(s) (%X)",
0810             AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
0811 
0812         return_ACPI_STATUS (Status);
0813     }
0814 
0815     /* Initialize the Buffer Field */
0816 
0817     if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
0818     {
0819         /* NOTE: Slightly different operands for this opcode */
0820 
0821         Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
0822                     WalkState->Operands[0], WalkState->Operands[1],
0823                     WalkState->Operands[2], WalkState->Operands[3]);
0824     }
0825     else
0826     {
0827         /* All other, CreateXxxField opcodes */
0828 
0829         Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
0830                     WalkState->Operands[0], WalkState->Operands[1],
0831                                       NULL, WalkState->Operands[2]);
0832     }
0833 
0834     return_ACPI_STATUS (Status);
0835 }
0836 
0837 
0838 /*******************************************************************************
0839  *
0840  * FUNCTION:    AcpiDsEvalRegionOperands
0841  *
0842  * PARAMETERS:  WalkState       - Current walk
0843  *              Op              - A valid region Op object
0844  *
0845  * RETURN:      Status
0846  *
0847  * DESCRIPTION: Get region address and length
0848  *              Called from AcpiDsExecEndOp during OpRegion parse tree walk
0849  *
0850  ******************************************************************************/
0851 
0852 ACPI_STATUS
0853 AcpiDsEvalRegionOperands (
0854     ACPI_WALK_STATE         *WalkState,
0855     ACPI_PARSE_OBJECT       *Op)
0856 {
0857     ACPI_STATUS             Status;
0858     ACPI_OPERAND_OBJECT     *ObjDesc;
0859     ACPI_OPERAND_OBJECT     *OperandDesc;
0860     ACPI_NAMESPACE_NODE     *Node;
0861     ACPI_PARSE_OBJECT       *NextOp;
0862 
0863 
0864     ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands, Op);
0865 
0866 
0867     /*
0868      * This is where we evaluate the address and length fields of the
0869      * OpRegion declaration
0870      */
0871     Node =  Op->Common.Node;
0872 
0873     /* NextOp points to the op that holds the SpaceID */
0874 
0875     NextOp = Op->Common.Value.Arg;
0876 
0877     /* NextOp points to address op */
0878 
0879     NextOp = NextOp->Common.Next;
0880 
0881     /* Evaluate/create the address and length operands */
0882 
0883     Status = AcpiDsCreateOperands (WalkState, NextOp);
0884     if (ACPI_FAILURE (Status))
0885     {
0886         return_ACPI_STATUS (Status);
0887     }
0888 
0889     /* Resolve the length and address operands to numbers */
0890 
0891     Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
0892                 ACPI_WALK_OPERANDS, WalkState);
0893     if (ACPI_FAILURE (Status))
0894     {
0895         return_ACPI_STATUS (Status);
0896     }
0897 
0898     ObjDesc = AcpiNsGetAttachedObject (Node);
0899     if (!ObjDesc)
0900     {
0901         return_ACPI_STATUS (AE_NOT_EXIST);
0902     }
0903 
0904     /*
0905      * Get the length operand and save it
0906      * (at Top of stack)
0907      */
0908     OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
0909 
0910     ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
0911     AcpiUtRemoveReference (OperandDesc);
0912 
0913     /*
0914      * Get the address and save it
0915      * (at top of stack - 1)
0916      */
0917     OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
0918 
0919     ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS)
0920                                 OperandDesc->Integer.Value;
0921     AcpiUtRemoveReference (OperandDesc);
0922 
0923     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
0924         ObjDesc,
0925         ACPI_FORMAT_NATIVE_UINT (ObjDesc->Region.Address),
0926         ObjDesc->Region.Length));
0927 
0928     /* Now the address and length are valid for this opregion */
0929 
0930     ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
0931 
0932     return_ACPI_STATUS (Status);
0933 }
0934 
0935 
0936 /*******************************************************************************
0937  *
0938  * FUNCTION:    AcpiDsEvalTableRegionOperands
0939  *
0940  * PARAMETERS:  WalkState       - Current walk
0941  *              Op              - A valid region Op object
0942  *
0943  * RETURN:      Status
0944  *
0945  * DESCRIPTION: Get region address and length
0946  *              Called from AcpiDsExecEndOp during DataTableRegion parse tree walk
0947  *
0948  ******************************************************************************/
0949 
0950 ACPI_STATUS
0951 AcpiDsEvalTableRegionOperands (
0952     ACPI_WALK_STATE         *WalkState,
0953     ACPI_PARSE_OBJECT       *Op)
0954 {
0955     ACPI_STATUS             Status;
0956     ACPI_OPERAND_OBJECT     *ObjDesc;
0957     ACPI_OPERAND_OBJECT     **Operand;
0958     ACPI_NAMESPACE_NODE     *Node;
0959     ACPI_PARSE_OBJECT       *NextOp;
0960     UINT32                  TableIndex;
0961     ACPI_TABLE_HEADER       *Table;
0962 
0963 
0964     ACPI_FUNCTION_TRACE_PTR (DsEvalTableRegionOperands, Op);
0965 
0966 
0967     /*
0968      * This is where we evaluate the SignatureString and OemIDString
0969      * and OemTableIDString of the DataTableRegion declaration
0970      */
0971     Node =  Op->Common.Node;
0972 
0973     /* NextOp points to SignatureString op */
0974 
0975     NextOp = Op->Common.Value.Arg;
0976 
0977     /*
0978      * Evaluate/create the SignatureString and OemIDString
0979      * and OemTableIDString operands
0980      */
0981     Status = AcpiDsCreateOperands (WalkState, NextOp);
0982     if (ACPI_FAILURE (Status))
0983     {
0984         return_ACPI_STATUS (Status);
0985     }
0986 
0987     /*
0988      * Resolve the SignatureString and OemIDString
0989      * and OemTableIDString operands
0990      */
0991     Status = AcpiExResolveOperands (Op->Common.AmlOpcode,
0992                 ACPI_WALK_OPERANDS, WalkState);
0993     if (ACPI_FAILURE (Status))
0994     {
0995         return_ACPI_STATUS (Status);
0996     }
0997 
0998     Operand = &WalkState->Operands[0];
0999 
1000     /* Find the ACPI table */
1001 
1002     Status = AcpiTbFindTable (Operand[0]->String.Pointer,
1003                 Operand[1]->String.Pointer, Operand[2]->String.Pointer,
1004                 &TableIndex);
1005     if (ACPI_FAILURE (Status))
1006     {
1007         return_ACPI_STATUS (Status);
1008     }
1009 
1010     AcpiUtRemoveReference (Operand[0]);
1011     AcpiUtRemoveReference (Operand[1]);
1012     AcpiUtRemoveReference (Operand[2]);
1013 
1014     Status = AcpiGetTableByIndex (TableIndex, &Table);
1015     if (ACPI_FAILURE (Status))
1016     {
1017         return_ACPI_STATUS (Status);
1018     }
1019 
1020     ObjDesc = AcpiNsGetAttachedObject (Node);
1021     if (!ObjDesc)
1022     {
1023         return_ACPI_STATUS (AE_NOT_EXIST);
1024     }
1025 
1026     ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS) ACPI_TO_INTEGER (Table);
1027     ObjDesc->Region.Length = Table->Length;
1028 
1029     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
1030         ObjDesc,
1031         ACPI_FORMAT_NATIVE_UINT (ObjDesc->Region.Address),
1032         ObjDesc->Region.Length));
1033 
1034     /* Now the address and length are valid for this opregion */
1035 
1036     ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
1037 
1038     return_ACPI_STATUS (Status);
1039 }
1040 
1041 
1042 /*******************************************************************************
1043  *
1044  * FUNCTION:    AcpiDsEvalDataObjectOperands
1045  *
1046  * PARAMETERS:  WalkState       - Current walk
1047  *              Op              - A valid DataObject Op object
1048  *              ObjDesc         - DataObject
1049  *
1050  * RETURN:      Status
1051  *
1052  * DESCRIPTION: Get the operands and complete the following data object types:
1053  *              Buffer, Package.
1054  *
1055  ******************************************************************************/
1056 
1057 ACPI_STATUS
1058 AcpiDsEvalDataObjectOperands (
1059     ACPI_WALK_STATE         *WalkState,
1060     ACPI_PARSE_OBJECT       *Op,
1061     ACPI_OPERAND_OBJECT     *ObjDesc)
1062 {
1063     ACPI_STATUS             Status;
1064     ACPI_OPERAND_OBJECT     *ArgDesc;
1065     UINT32                  Length;
1066 
1067 
1068     ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands);
1069 
1070 
1071     /* The first operand (for all of these data objects) is the length */
1072 
1073     /*
1074      * Set proper index into operand stack for AcpiDsObjStackPush
1075      * invoked inside AcpiDsCreateOperand.
1076      */
1077     WalkState->OperandIndex = WalkState->NumOperands;
1078 
1079     Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
1080     if (ACPI_FAILURE (Status))
1081     {
1082         return_ACPI_STATUS (Status);
1083     }
1084 
1085     Status = AcpiExResolveOperands (WalkState->Opcode,
1086                     &(WalkState->Operands [WalkState->NumOperands -1]),
1087                     WalkState);
1088     if (ACPI_FAILURE (Status))
1089     {
1090         return_ACPI_STATUS (Status);
1091     }
1092 
1093     /* Extract length operand */
1094 
1095     ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
1096     Length = (UINT32) ArgDesc->Integer.Value;
1097 
1098     /* Cleanup for length operand */
1099 
1100     Status = AcpiDsObjStackPop (1, WalkState);
1101     if (ACPI_FAILURE (Status))
1102     {
1103         return_ACPI_STATUS (Status);
1104     }
1105 
1106     AcpiUtRemoveReference (ArgDesc);
1107 
1108     /*
1109      * Create the actual data object
1110      */
1111     switch (Op->Common.AmlOpcode)
1112     {
1113     case AML_BUFFER_OP:
1114 
1115         Status = AcpiDsBuildInternalBufferObj (WalkState, Op, Length, &ObjDesc);
1116         break;
1117 
1118     case AML_PACKAGE_OP:
1119     case AML_VAR_PACKAGE_OP:
1120 
1121         Status = AcpiDsBuildInternalPackageObj (WalkState, Op, Length, &ObjDesc);
1122         break;
1123 
1124     default:
1125         return_ACPI_STATUS (AE_AML_BAD_OPCODE);
1126     }
1127 
1128     if (ACPI_SUCCESS (Status))
1129     {
1130         /*
1131          * Return the object in the WalkState, unless the parent is a package -
1132          * in this case, the return object will be stored in the parse tree
1133          * for the package.
1134          */
1135         if ((!Op->Common.Parent) ||
1136             ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
1137              (Op->Common.Parent->Common.AmlOpcode != AML_VAR_PACKAGE_OP) &&
1138              (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
1139         {
1140             WalkState->ResultObj = ObjDesc;
1141         }
1142     }
1143 
1144     return_ACPI_STATUS (Status);
1145 }
1146 
1147 
1148 /*******************************************************************************
1149  *
1150  * FUNCTION:    AcpiDsEvalBankFieldOperands
1151  *
1152  * PARAMETERS:  WalkState       - Current walk
1153  *              Op              - A valid BankField Op object
1154  *
1155  * RETURN:      Status
1156  *
1157  * DESCRIPTION: Get BankField BankValue
1158  *              Called from AcpiDsExecEndOp during BankField parse tree walk
1159  *
1160  ******************************************************************************/
1161 
1162 ACPI_STATUS
1163 AcpiDsEvalBankFieldOperands (
1164     ACPI_WALK_STATE         *WalkState,
1165     ACPI_PARSE_OBJECT       *Op)
1166 {
1167     ACPI_STATUS             Status;
1168     ACPI_OPERAND_OBJECT     *ObjDesc;
1169     ACPI_OPERAND_OBJECT     *OperandDesc;
1170     ACPI_NAMESPACE_NODE     *Node;
1171     ACPI_PARSE_OBJECT       *NextOp;
1172     ACPI_PARSE_OBJECT       *Arg;
1173 
1174 
1175     ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands, Op);
1176 
1177 
1178     /*
1179      * This is where we evaluate the BankValue field of the
1180      * BankField declaration
1181      */
1182 
1183     /* NextOp points to the op that holds the Region */
1184 
1185     NextOp = Op->Common.Value.Arg;
1186 
1187     /* NextOp points to the op that holds the Bank Register */
1188 
1189     NextOp = NextOp->Common.Next;
1190 
1191     /* NextOp points to the op that holds the Bank Value */
1192 
1193     NextOp = NextOp->Common.Next;
1194 
1195     /*
1196      * Set proper index into operand stack for AcpiDsObjStackPush
1197      * invoked inside AcpiDsCreateOperand.
1198      *
1199      * We use WalkState->Operands[0] to store the evaluated BankValue
1200      */
1201     WalkState->OperandIndex = 0;
1202 
1203     Status = AcpiDsCreateOperand (WalkState, NextOp, 0);
1204     if (ACPI_FAILURE (Status))
1205     {
1206         return_ACPI_STATUS (Status);
1207     }
1208 
1209     Status = AcpiExResolveToValue (&WalkState->Operands[0], WalkState);
1210     if (ACPI_FAILURE (Status))
1211     {
1212         return_ACPI_STATUS (Status);
1213     }
1214 
1215     ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS,
1216         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 1);
1217     /*
1218      * Get the BankValue operand and save it
1219      * (at Top of stack)
1220      */
1221     OperandDesc = WalkState->Operands[0];
1222 
1223     /* Arg points to the start Bank Field */
1224 
1225     Arg = AcpiPsGetArg (Op, 4);
1226     while (Arg)
1227     {
1228         /* Ignore OFFSET and ACCESSAS terms here */
1229 
1230         if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
1231         {
1232             Node = Arg->Common.Node;
1233 
1234             ObjDesc = AcpiNsGetAttachedObject (Node);
1235             if (!ObjDesc)
1236             {
1237                 return_ACPI_STATUS (AE_NOT_EXIST);
1238             }
1239 
1240             ObjDesc->BankField.Value = (UINT32) OperandDesc->Integer.Value;
1241         }
1242 
1243         /* Move to next field in the list */
1244 
1245         Arg = Arg->Common.Next;
1246     }
1247 
1248     AcpiUtRemoveReference (OperandDesc);
1249     return_ACPI_STATUS (Status);
1250 }
1251 
1252 
1253 /*******************************************************************************
1254  *
1255  * FUNCTION:    AcpiDsExecBeginControlOp
1256  *
1257  * PARAMETERS:  WalkList        - The list that owns the walk stack
1258  *              Op              - The control Op
1259  *
1260  * RETURN:      Status
1261  *
1262  * DESCRIPTION: Handles all control ops encountered during control method
1263  *              execution.
1264  *
1265  ******************************************************************************/
1266 
1267 ACPI_STATUS
1268 AcpiDsExecBeginControlOp (
1269     ACPI_WALK_STATE         *WalkState,
1270     ACPI_PARSE_OBJECT       *Op)
1271 {
1272     ACPI_STATUS             Status = AE_OK;
1273     ACPI_GENERIC_STATE      *ControlState;
1274 
1275 
1276     ACPI_FUNCTION_NAME (DsExecBeginControlOp);
1277 
1278 
1279     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", Op,
1280         Op->Common.AmlOpcode, WalkState));
1281 
1282     switch (Op->Common.AmlOpcode)
1283     {
1284     case AML_WHILE_OP:
1285 
1286         /*
1287          * If this is an additional iteration of a while loop, continue.
1288          * There is no need to allocate a new control state.
1289          */
1290         if (WalkState->ControlState)
1291         {
1292             if (WalkState->ControlState->Control.AmlPredicateStart ==
1293                 (WalkState->ParserState.Aml - 1))
1294             {
1295                 /* Reset the state to start-of-loop */
1296 
1297                 WalkState->ControlState->Common.State = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1298                 break;
1299             }
1300         }
1301 
1302         /*lint -fallthrough */
1303 
1304     case AML_IF_OP:
1305 
1306         /*
1307          * IF/WHILE: Create a new control state to manage these
1308          * constructs. We need to manage these as a stack, in order
1309          * to handle nesting.
1310          */
1311         ControlState = AcpiUtCreateControlState ();
1312         if (!ControlState)
1313         {
1314             Status = AE_NO_MEMORY;
1315             break;
1316         }
1317         /*
1318          * Save a pointer to the predicate for multiple executions
1319          * of a loop
1320          */
1321         ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
1322         ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
1323         ControlState->Control.Opcode = Op->Common.AmlOpcode;
1324 
1325 
1326         /* Push the control state on this walk's control stack */
1327 
1328         AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
1329         break;
1330 
1331     case AML_ELSE_OP:
1332 
1333         /* Predicate is in the state object */
1334         /* If predicate is true, the IF was executed, ignore ELSE part */
1335 
1336         if (WalkState->LastPredicate)
1337         {
1338             Status = AE_CTRL_TRUE;
1339         }
1340 
1341         break;
1342 
1343     case AML_RETURN_OP:
1344 
1345         break;
1346 
1347     default:
1348         break;
1349     }
1350 
1351     return (Status);
1352 }
1353 
1354 
1355 /*******************************************************************************
1356  *
1357  * FUNCTION:    AcpiDsExecEndControlOp
1358  *
1359  * PARAMETERS:  WalkList        - The list that owns the walk stack
1360  *              Op              - The control Op
1361  *
1362  * RETURN:      Status
1363  *
1364  * DESCRIPTION: Handles all control ops encountered during control method
1365  *              execution.
1366  *
1367  ******************************************************************************/
1368 
1369 ACPI_STATUS
1370 AcpiDsExecEndControlOp (
1371     ACPI_WALK_STATE         *WalkState,
1372     ACPI_PARSE_OBJECT       *Op)
1373 {
1374     ACPI_STATUS             Status = AE_OK;
1375     ACPI_GENERIC_STATE      *ControlState;
1376 
1377 
1378     ACPI_FUNCTION_NAME (DsExecEndControlOp);
1379 
1380 
1381     switch (Op->Common.AmlOpcode)
1382     {
1383     case AML_IF_OP:
1384 
1385         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
1386 
1387         /*
1388          * Save the result of the predicate in case there is an
1389          * ELSE to come
1390          */
1391         WalkState->LastPredicate =
1392             (BOOLEAN) WalkState->ControlState->Common.Value;
1393 
1394         /*
1395          * Pop the control state that was created at the start
1396          * of the IF and free it
1397          */
1398         ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1399         AcpiUtDeleteGenericState (ControlState);
1400         break;
1401 
1402 
1403     case AML_ELSE_OP:
1404 
1405         break;
1406 
1407 
1408     case AML_WHILE_OP:
1409 
1410         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
1411 
1412         ControlState = WalkState->ControlState;
1413         if (ControlState->Common.Value)
1414         {
1415             /* Predicate was true, the body of the loop was just executed */
1416 
1417             /*
1418              * This loop counter mechanism allows the interpreter to escape
1419              * possibly infinite loops. This can occur in poorly written AML
1420              * when the hardware does not respond within a while loop and the
1421              * loop does not implement a timeout.
1422              */
1423             ControlState->Control.LoopCount++;
1424             if (ControlState->Control.LoopCount > ACPI_MAX_LOOP_ITERATIONS)
1425             {
1426                 Status = AE_AML_INFINITE_LOOP;
1427                 break;
1428             }
1429 
1430             /*
1431              * Go back and evaluate the predicate and maybe execute the loop
1432              * another time
1433              */
1434             Status = AE_CTRL_PENDING;
1435             WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
1436             break;
1437         }
1438 
1439         /* Predicate was false, terminate this while loop */
1440 
1441         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1442             "[WHILE_OP] termination! Op=%p\n",Op));
1443 
1444         /* Pop this control state and free it */
1445 
1446         ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1447         AcpiUtDeleteGenericState (ControlState);
1448         break;
1449 
1450 
1451     case AML_RETURN_OP:
1452 
1453         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1454             "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
1455 
1456         /*
1457          * One optional operand -- the return value
1458          * It can be either an immediate operand or a result that
1459          * has been bubbled up the tree
1460          */
1461         if (Op->Common.Value.Arg)
1462         {
1463             /* Since we have a real Return(), delete any implicit return */
1464 
1465             AcpiDsClearImplicitReturn (WalkState);
1466 
1467             /* Return statement has an immediate operand */
1468 
1469             Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
1470             if (ACPI_FAILURE (Status))
1471             {
1472                 return (Status);
1473             }
1474 
1475             /*
1476              * If value being returned is a Reference (such as
1477              * an arg or local), resolve it now because it may
1478              * cease to exist at the end of the method.
1479              */
1480             Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
1481             if (ACPI_FAILURE (Status))
1482             {
1483                 return (Status);
1484             }
1485 
1486             /*
1487              * Get the return value and save as the last result
1488              * value.  This is the only place where WalkState->ReturnDesc
1489              * is set to anything other than zero!
1490              */
1491             WalkState->ReturnDesc = WalkState->Operands[0];
1492         }
1493         else if (WalkState->ResultCount)
1494         {
1495             /* Since we have a real Return(), delete any implicit return */
1496 
1497             AcpiDsClearImplicitReturn (WalkState);
1498 
1499             /*
1500              * The return value has come from a previous calculation.
1501              *
1502              * If value being returned is a Reference (such as
1503              * an arg or local), resolve it now because it may
1504              * cease to exist at the end of the method.
1505              *
1506              * Allow references created by the Index operator to return unchanged.
1507              */
1508             if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1509                 ((WalkState->Results->Results.ObjDesc [0])->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
1510                 ((WalkState->Results->Results.ObjDesc [0])->Reference.Class != ACPI_REFCLASS_INDEX))
1511             {
1512                 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
1513                 if (ACPI_FAILURE (Status))
1514                 {
1515                     return (Status);
1516                 }
1517             }
1518 
1519             WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
1520         }
1521         else
1522         {
1523             /* No return operand */
1524 
1525             if (WalkState->NumOperands)
1526             {
1527                 AcpiUtRemoveReference (WalkState->Operands [0]);
1528             }
1529 
1530             WalkState->Operands [0]     = NULL;
1531             WalkState->NumOperands      = 0;
1532             WalkState->ReturnDesc       = NULL;
1533         }
1534 
1535 
1536         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1537             "Completed RETURN_OP State=%p, RetVal=%p\n",
1538             WalkState, WalkState->ReturnDesc));
1539 
1540         /* End the control method execution right now */
1541 
1542         Status = AE_CTRL_TERMINATE;
1543         break;
1544 
1545 
1546     case AML_NOOP_OP:
1547 
1548         /* Just do nothing! */
1549         break;
1550 
1551 
1552     case AML_BREAK_POINT_OP:
1553 
1554         /*
1555          * Set the single-step flag. This will cause the debugger (if present)
1556          * to break to the console within the AML debugger at the start of the
1557          * next AML instruction.
1558          */
1559         ACPI_DEBUGGER_EXEC (
1560             AcpiGbl_CmSingleStep = TRUE);
1561         ACPI_DEBUGGER_EXEC (
1562             AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n"));
1563 
1564         /* Call to the OSL in case OS wants a piece of the action */
1565 
1566         Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
1567                     "Executed AML Breakpoint opcode");
1568         break;
1569 
1570 
1571     case AML_BREAK_OP:
1572     case AML_CONTINUE_OP: /* ACPI 2.0 */
1573 
1574 
1575         /* Pop and delete control states until we find a while */
1576 
1577         while (WalkState->ControlState &&
1578                 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
1579         {
1580             ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
1581             AcpiUtDeleteGenericState (ControlState);
1582         }
1583 
1584         /* No while found? */
1585 
1586         if (!WalkState->ControlState)
1587         {
1588             return (AE_AML_NO_WHILE);
1589         }
1590 
1591         /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
1592 
1593         WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
1594 
1595         /* Return status depending on opcode */
1596 
1597         if (Op->Common.AmlOpcode == AML_BREAK_OP)
1598         {
1599             Status = AE_CTRL_BREAK;
1600         }
1601         else
1602         {
1603             Status = AE_CTRL_CONTINUE;
1604         }
1605         break;
1606 
1607 
1608     default:
1609 
1610         ACPI_ERROR ((AE_INFO, "Unknown control opcode=%X Op=%p",
1611             Op->Common.AmlOpcode, Op));
1612 
1613         Status = AE_AML_BAD_OPCODE;
1614         break;
1615     }
1616 
1617     return (Status);
1618 }
1619