Home | History | Annotate | Line # | Download | only in dispatcher
dswload.c revision 1.1
      1 /******************************************************************************
      2  *
      3  * Module Name: dswload - Dispatcher namespace load callbacks
      4  *
      5  *****************************************************************************/
      6 
      7 /******************************************************************************
      8  *
      9  * 1. Copyright Notice
     10  *
     11  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     12  * All rights reserved.
     13  *
     14  * 2. License
     15  *
     16  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  * rights.  You may have additional license terms from the party that provided
     18  * you this software, covering your right to use that party's intellectual
     19  * property rights.
     20  *
     21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  * copy of the source code appearing in this file ("Covered Code") an
     23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  * make derivatives, distribute, use and display any portion of the Covered
     26  * Code in any form, with the right to sublicense such rights; and
     27  *
     28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  * license (with the right to sublicense), under only those claims of Intel
     30  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  * offer to sell, and import the Covered Code and derivative works thereof
     32  * solely to the minimum extent necessary to exercise the above copyright
     33  * license, and in no event shall the patent license extend to any additions
     34  * to or modifications of the Original Intel Code.  No other license or right
     35  * is granted directly or by implication, estoppel or otherwise;
     36  *
     37  * The above copyright and patent license is granted only if the following
     38  * conditions are met:
     39  *
     40  * 3. Conditions
     41  *
     42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  * Redistribution of source code of any substantial portion of the Covered
     44  * Code or modification with rights to further distribute source must include
     45  * the above Copyright Notice, the above License, this list of Conditions,
     46  * and the following Disclaimer and Export Compliance provision.  In addition,
     47  * Licensee must cause all Covered Code to which Licensee contributes to
     48  * contain a file documenting the changes Licensee made to create that Covered
     49  * Code and the date of any change.  Licensee must include in that file the
     50  * documentation of any changes made by any predecessor Licensee.  Licensee
     51  * must include a prominent statement that the modification is derived,
     52  * directly or indirectly, from Original Intel Code.
     53  *
     54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  * Redistribution of source code of any substantial portion of the Covered
     56  * Code or modification without rights to further distribute source must
     57  * include the following Disclaimer and Export Compliance provision in the
     58  * documentation and/or other materials provided with distribution.  In
     59  * addition, Licensee may not authorize further sublicense of source of any
     60  * portion of the Covered Code, and must include terms to the effect that the
     61  * license from Licensee to its licensee is limited to the intellectual
     62  * property embodied in the software Licensee provides to its licensee, and
     63  * not to intellectual property embodied in modifications its licensee may
     64  * make.
     65  *
     66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  * substantial portion of the Covered Code or modification must reproduce the
     68  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  * provision in the documentation and/or other materials provided with the
     70  * distribution.
     71  *
     72  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  * Intel Code.
     74  *
     75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  * other dealings in products derived from or relating to the Covered Code
     78  * without prior written authorization from Intel.
     79  *
     80  * 4. Disclaimer and Export Compliance
     81  *
     82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     85  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     86  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  * PARTICULAR PURPOSE.
     89  *
     90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  * LIMITED REMEDY.
     98  *
     99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  * software or system incorporating such software without first obtaining any
    101  * required license or other approval from the U. S. Department of Commerce or
    102  * any other agency or department of the United States Government.  In the
    103  * event Licensee exports any such software from the United States or
    104  * re-exports any such software from a foreign destination, Licensee shall
    105  * ensure that the distribution and export/re-export of the software is in
    106  * compliance with all laws, regulations, orders, or other restrictions of the
    107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  * any of its subsidiaries will export/re-export any technical data, process,
    109  * software, or service, directly or indirectly, to any country for which the
    110  * United States government or any agency thereof requires an export license,
    111  * other governmental approval, or letter of assurance, without first obtaining
    112  * such license, approval or letter.
    113  *
    114  *****************************************************************************/
    115 
    116 #define __DSWLOAD_C__
    117 
    118 #include "acpi.h"
    119 #include "accommon.h"
    120 #include "acparser.h"
    121 #include "amlcode.h"
    122 #include "acdispat.h"
    123 #include "acinterp.h"
    124 #include "acnamesp.h"
    125 #include "acevents.h"
    126 
    127 #ifdef ACPI_ASL_COMPILER
    128 #include "acdisasm.h"
    129 #endif
    130 
    131 #define _COMPONENT          ACPI_DISPATCHER
    132         ACPI_MODULE_NAME    ("dswload")
    133 
    134 
    135 /*******************************************************************************
    136  *
    137  * FUNCTION:    AcpiDsInitCallbacks
    138  *
    139  * PARAMETERS:  WalkState       - Current state of the parse tree walk
    140  *              PassNumber      - 1, 2, or 3
    141  *
    142  * RETURN:      Status
    143  *
    144  * DESCRIPTION: Init walk state callbacks
    145  *
    146  ******************************************************************************/
    147 
    148 ACPI_STATUS
    149 AcpiDsInitCallbacks (
    150     ACPI_WALK_STATE         *WalkState,
    151     UINT32                  PassNumber)
    152 {
    153 
    154     switch (PassNumber)
    155     {
    156     case 1:
    157         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
    158                                         ACPI_PARSE_DELETE_TREE;
    159         WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
    160         WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
    161         break;
    162 
    163     case 2:
    164         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
    165                                         ACPI_PARSE_DELETE_TREE;
    166         WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
    167         WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
    168         break;
    169 
    170     case 3:
    171 #ifndef ACPI_NO_METHOD_EXECUTION
    172         WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
    173                                         ACPI_PARSE_DELETE_TREE;
    174         WalkState->DescendingCallback = AcpiDsExecBeginOp;
    175         WalkState->AscendingCallback  = AcpiDsExecEndOp;
    176 #endif
    177         break;
    178 
    179     default:
    180         return (AE_BAD_PARAMETER);
    181     }
    182 
    183     return (AE_OK);
    184 }
    185 
    186 
    187 /*******************************************************************************
    188  *
    189  * FUNCTION:    AcpiDsLoad1BeginOp
    190  *
    191  * PARAMETERS:  WalkState       - Current state of the parse tree walk
    192  *              OutOp           - Where to return op if a new one is created
    193  *
    194  * RETURN:      Status
    195  *
    196  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
    197  *
    198  ******************************************************************************/
    199 
    200 ACPI_STATUS
    201 AcpiDsLoad1BeginOp (
    202     ACPI_WALK_STATE         *WalkState,
    203     ACPI_PARSE_OBJECT       **OutOp)
    204 {
    205     ACPI_PARSE_OBJECT       *Op;
    206     ACPI_NAMESPACE_NODE     *Node;
    207     ACPI_STATUS             Status;
    208     ACPI_OBJECT_TYPE        ObjectType;
    209     char                    *Path;
    210     UINT32                  Flags;
    211 
    212 
    213     ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
    214 
    215 
    216     Op = WalkState->Op;
    217     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
    218 
    219     /* We are only interested in opcodes that have an associated name */
    220 
    221     if (Op)
    222     {
    223         if (!(WalkState->OpInfo->Flags & AML_NAMED))
    224         {
    225             *OutOp = Op;
    226             return_ACPI_STATUS (AE_OK);
    227         }
    228 
    229         /* Check if this object has already been installed in the namespace */
    230 
    231         if (Op->Common.Node)
    232         {
    233             *OutOp = Op;
    234             return_ACPI_STATUS (AE_OK);
    235         }
    236     }
    237 
    238     Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
    239 
    240     /* Map the raw opcode into an internal object type */
    241 
    242     ObjectType = WalkState->OpInfo->ObjectType;
    243 
    244     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    245         "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
    246 
    247     switch (WalkState->Opcode)
    248     {
    249     case AML_SCOPE_OP:
    250 
    251         /*
    252          * The target name of the Scope() operator must exist at this point so
    253          * that we can actually open the scope to enter new names underneath it.
    254          * Allow search-to-root for single namesegs.
    255          */
    256         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
    257                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
    258 #ifdef ACPI_ASL_COMPILER
    259         if (Status == AE_NOT_FOUND)
    260         {
    261             /*
    262              * Table disassembly:
    263              * Target of Scope() not found. Generate an External for it, and
    264              * insert the name into the namespace.
    265              */
    266             AcpiDmAddToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0);
    267             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
    268                        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
    269                        WalkState, &Node);
    270         }
    271 #endif
    272         if (ACPI_FAILURE (Status))
    273         {
    274             ACPI_ERROR_NAMESPACE (Path, Status);
    275             return_ACPI_STATUS (Status);
    276         }
    277 
    278         /*
    279          * Check to make sure that the target is
    280          * one of the opcodes that actually opens a scope
    281          */
    282         switch (Node->Type)
    283         {
    284         case ACPI_TYPE_ANY:
    285         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
    286         case ACPI_TYPE_DEVICE:
    287         case ACPI_TYPE_POWER:
    288         case ACPI_TYPE_PROCESSOR:
    289         case ACPI_TYPE_THERMAL:
    290 
    291             /* These are acceptable types */
    292             break;
    293 
    294         case ACPI_TYPE_INTEGER:
    295         case ACPI_TYPE_STRING:
    296         case ACPI_TYPE_BUFFER:
    297 
    298             /*
    299              * These types we will allow, but we will change the type.
    300              * This enables some existing code of the form:
    301              *
    302              *  Name (DEB, 0)
    303              *  Scope (DEB) { ... }
    304              *
    305              * Note: silently change the type here. On the second pass,
    306              * we will report a warning
    307              */
    308             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    309                 "Type override - [%4.4s] had invalid type (%s) "
    310                 "for Scope operator, changed to type ANY\n",
    311                 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
    312 
    313             Node->Type = ACPI_TYPE_ANY;
    314             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
    315             break;
    316 
    317         default:
    318 
    319             /* All other types are an error */
    320 
    321             ACPI_ERROR ((AE_INFO,
    322                 "Invalid type (%s) for target of "
    323                 "Scope operator [%4.4s] (Cannot override)",
    324                 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
    325 
    326             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    327         }
    328         break;
    329 
    330 
    331     default:
    332         /*
    333          * For all other named opcodes, we will enter the name into
    334          * the namespace.
    335          *
    336          * Setup the search flags.
    337          * Since we are entering a name into the namespace, we do not want to
    338          * enable the search-to-root upsearch.
    339          *
    340          * There are only two conditions where it is acceptable that the name
    341          * already exists:
    342          *    1) the Scope() operator can reopen a scoping object that was
    343          *       previously defined (Scope, Method, Device, etc.)
    344          *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
    345          *       BufferField, or Package), the name of the object is already
    346          *       in the namespace.
    347          */
    348         if (WalkState->DeferredNode)
    349         {
    350             /* This name is already in the namespace, get the node */
    351 
    352             Node = WalkState->DeferredNode;
    353             Status = AE_OK;
    354             break;
    355         }
    356 
    357         /*
    358          * If we are executing a method, do not create any namespace objects
    359          * during the load phase, only during execution.
    360          */
    361         if (WalkState->MethodNode)
    362         {
    363             Node = NULL;
    364             Status = AE_OK;
    365             break;
    366         }
    367 
    368         Flags = ACPI_NS_NO_UPSEARCH;
    369         if ((WalkState->Opcode != AML_SCOPE_OP) &&
    370             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
    371         {
    372             Flags |= ACPI_NS_ERROR_IF_FOUND;
    373             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
    374                     AcpiUtGetTypeName (ObjectType)));
    375         }
    376         else
    377         {
    378             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    379                 "[%s] Both Find or Create allowed\n",
    380                     AcpiUtGetTypeName (ObjectType)));
    381         }
    382 
    383         /*
    384          * Enter the named type into the internal namespace. We enter the name
    385          * as we go downward in the parse tree. Any necessary subobjects that
    386          * involve arguments to the opcode must be created as we go back up the
    387          * parse tree later.
    388          */
    389         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
    390                         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
    391         if (ACPI_FAILURE (Status))
    392         {
    393             if (Status == AE_ALREADY_EXISTS)
    394             {
    395                 /* The name already exists in this scope */
    396 
    397                 if (Node->Flags & ANOBJ_IS_EXTERNAL)
    398                 {
    399                     /*
    400                      * Allow one create on an object or segment that was
    401                      * previously declared External
    402                      */
    403                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
    404                     Node->Type = (UINT8) ObjectType;
    405 
    406                     /* Just retyped a node, probably will need to open a scope */
    407 
    408                     if (AcpiNsOpensScope (ObjectType))
    409                     {
    410                         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
    411                         if (ACPI_FAILURE (Status))
    412                         {
    413                             return_ACPI_STATUS (Status);
    414                         }
    415                     }
    416 
    417                     Status = AE_OK;
    418                 }
    419             }
    420 
    421             if (ACPI_FAILURE (Status))
    422             {
    423                 ACPI_ERROR_NAMESPACE (Path, Status);
    424                 return_ACPI_STATUS (Status);
    425             }
    426         }
    427         break;
    428     }
    429 
    430     /* Common exit */
    431 
    432     if (!Op)
    433     {
    434         /* Create a new op */
    435 
    436         Op = AcpiPsAllocOp (WalkState->Opcode);
    437         if (!Op)
    438         {
    439             return_ACPI_STATUS (AE_NO_MEMORY);
    440         }
    441     }
    442 
    443     /* Initialize the op */
    444 
    445 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
    446     Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
    447 #endif
    448 
    449     if (Node)
    450     {
    451         /*
    452          * Put the Node in the "op" object that the parser uses, so we
    453          * can get it again quickly when this scope is closed
    454          */
    455         Op->Common.Node = Node;
    456         Op->Named.Name = Node->Name.Integer;
    457     }
    458 
    459     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
    460     *OutOp = Op;
    461     return_ACPI_STATUS (Status);
    462 }
    463 
    464 
    465 /*******************************************************************************
    466  *
    467  * FUNCTION:    AcpiDsLoad1EndOp
    468  *
    469  * PARAMETERS:  WalkState       - Current state of the parse tree walk
    470  *
    471  * RETURN:      Status
    472  *
    473  * DESCRIPTION: Ascending callback used during the loading of the namespace,
    474  *              both control methods and everything else.
    475  *
    476  ******************************************************************************/
    477 
    478 ACPI_STATUS
    479 AcpiDsLoad1EndOp (
    480     ACPI_WALK_STATE         *WalkState)
    481 {
    482     ACPI_PARSE_OBJECT       *Op;
    483     ACPI_OBJECT_TYPE        ObjectType;
    484     ACPI_STATUS             Status = AE_OK;
    485 
    486 
    487     ACPI_FUNCTION_TRACE (DsLoad1EndOp);
    488 
    489 
    490     Op = WalkState->Op;
    491     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
    492 
    493     /* We are only interested in opcodes that have an associated name */
    494 
    495     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
    496     {
    497         return_ACPI_STATUS (AE_OK);
    498     }
    499 
    500     /* Get the object type to determine if we should pop the scope */
    501 
    502     ObjectType = WalkState->OpInfo->ObjectType;
    503 
    504 #ifndef ACPI_NO_METHOD_EXECUTION
    505     if (WalkState->OpInfo->Flags & AML_FIELD)
    506     {
    507         /*
    508          * If we are executing a method, do not create any namespace objects
    509          * during the load phase, only during execution.
    510          */
    511         if (!WalkState->MethodNode)
    512         {
    513             if (WalkState->Opcode == AML_FIELD_OP          ||
    514                 WalkState->Opcode == AML_BANK_FIELD_OP     ||
    515                 WalkState->Opcode == AML_INDEX_FIELD_OP)
    516             {
    517                 Status = AcpiDsInitFieldObjects (Op, WalkState);
    518             }
    519         }
    520         return_ACPI_STATUS (Status);
    521     }
    522 
    523     /*
    524      * If we are executing a method, do not create any namespace objects
    525      * during the load phase, only during execution.
    526      */
    527     if (!WalkState->MethodNode)
    528     {
    529         if (Op->Common.AmlOpcode == AML_REGION_OP)
    530         {
    531             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
    532                         (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
    533                         WalkState);
    534             if (ACPI_FAILURE (Status))
    535             {
    536                 return_ACPI_STATUS (Status);
    537             }
    538         }
    539         else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
    540         {
    541             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
    542                         REGION_DATA_TABLE, WalkState);
    543             if (ACPI_FAILURE (Status))
    544             {
    545                 return_ACPI_STATUS (Status);
    546             }
    547         }
    548     }
    549 #endif
    550 
    551     if (Op->Common.AmlOpcode == AML_NAME_OP)
    552     {
    553         /* For Name opcode, get the object type from the argument */
    554 
    555         if (Op->Common.Value.Arg)
    556         {
    557             ObjectType = (AcpiPsGetOpcodeInfo (
    558                 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
    559 
    560             /* Set node type if we have a namespace node */
    561 
    562             if (Op->Common.Node)
    563             {
    564                 Op->Common.Node->Type = (UINT8) ObjectType;
    565             }
    566         }
    567     }
    568 
    569     /*
    570      * If we are executing a method, do not create any namespace objects
    571      * during the load phase, only during execution.
    572      */
    573     if (!WalkState->MethodNode)
    574     {
    575         if (Op->Common.AmlOpcode == AML_METHOD_OP)
    576         {
    577             /*
    578              * MethodOp PkgLength NameString MethodFlags TermList
    579              *
    580              * Note: We must create the method node/object pair as soon as we
    581              * see the method declaration. This allows later pass1 parsing
    582              * of invocations of the method (need to know the number of
    583              * arguments.)
    584              */
    585             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    586                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
    587                 WalkState, Op, Op->Named.Node));
    588 
    589             if (!AcpiNsGetAttachedObject (Op->Named.Node))
    590             {
    591                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
    592                 WalkState->NumOperands = 1;
    593 
    594                 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
    595                 if (ACPI_SUCCESS (Status))
    596                 {
    597                     Status = AcpiExCreateMethod (Op->Named.Data,
    598                                         Op->Named.Length, WalkState);
    599                 }
    600 
    601                 WalkState->Operands[0] = NULL;
    602                 WalkState->NumOperands = 0;
    603 
    604                 if (ACPI_FAILURE (Status))
    605                 {
    606                     return_ACPI_STATUS (Status);
    607                 }
    608             }
    609         }
    610     }
    611 
    612     /* Pop the scope stack (only if loading a table) */
    613 
    614     if (!WalkState->MethodNode &&
    615         AcpiNsOpensScope (ObjectType))
    616     {
    617         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
    618             AcpiUtGetTypeName (ObjectType), Op));
    619 
    620         Status = AcpiDsScopeStackPop (WalkState);
    621     }
    622 
    623     return_ACPI_STATUS (Status);
    624 }
    625 
    626 
    627 /*******************************************************************************
    628  *
    629  * FUNCTION:    AcpiDsLoad2BeginOp
    630  *
    631  * PARAMETERS:  WalkState       - Current state of the parse tree walk
    632  *              OutOp           - Wher to return op if a new one is created
    633  *
    634  * RETURN:      Status
    635  *
    636  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
    637  *
    638  ******************************************************************************/
    639 
    640 ACPI_STATUS
    641 AcpiDsLoad2BeginOp (
    642     ACPI_WALK_STATE         *WalkState,
    643     ACPI_PARSE_OBJECT       **OutOp)
    644 {
    645     ACPI_PARSE_OBJECT       *Op;
    646     ACPI_NAMESPACE_NODE     *Node;
    647     ACPI_STATUS             Status;
    648     ACPI_OBJECT_TYPE        ObjectType;
    649     char                    *BufferPtr;
    650     UINT32                  Flags;
    651 
    652 
    653     ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
    654 
    655 
    656     Op = WalkState->Op;
    657     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
    658 
    659     if (Op)
    660     {
    661         if ((WalkState->ControlState) &&
    662             (WalkState->ControlState->Common.State ==
    663                 ACPI_CONTROL_CONDITIONAL_EXECUTING))
    664         {
    665             /* We are executing a while loop outside of a method */
    666 
    667             Status = AcpiDsExecBeginOp (WalkState, OutOp);
    668             return_ACPI_STATUS (Status);
    669         }
    670 
    671         /* We only care about Namespace opcodes here */
    672 
    673         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
    674               (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
    675             (!(WalkState->OpInfo->Flags & AML_NAMED)))
    676         {
    677             return_ACPI_STATUS (AE_OK);
    678         }
    679 
    680         /* Get the name we are going to enter or lookup in the namespace */
    681 
    682         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
    683         {
    684             /* For Namepath op, get the path string */
    685 
    686             BufferPtr = Op->Common.Value.String;
    687             if (!BufferPtr)
    688             {
    689                 /* No name, just exit */
    690 
    691                 return_ACPI_STATUS (AE_OK);
    692             }
    693         }
    694         else
    695         {
    696             /* Get name from the op */
    697 
    698             BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
    699         }
    700     }
    701     else
    702     {
    703         /* Get the namestring from the raw AML */
    704 
    705         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
    706     }
    707 
    708     /* Map the opcode into an internal object type */
    709 
    710     ObjectType = WalkState->OpInfo->ObjectType;
    711 
    712     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    713         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
    714 
    715     switch (WalkState->Opcode)
    716     {
    717     case AML_FIELD_OP:
    718     case AML_BANK_FIELD_OP:
    719     case AML_INDEX_FIELD_OP:
    720 
    721         Node = NULL;
    722         Status = AE_OK;
    723         break;
    724 
    725     case AML_INT_NAMEPATH_OP:
    726         /*
    727          * The NamePath is an object reference to an existing object.
    728          * Don't enter the name into the namespace, but look it up
    729          * for use later.
    730          */
    731         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
    732                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
    733                         WalkState, &(Node));
    734         break;
    735 
    736     case AML_SCOPE_OP:
    737 
    738         /* Special case for Scope(\) -> refers to the Root node */
    739 
    740         if (Op && (Op->Named.Node == AcpiGbl_RootNode))
    741         {
    742             Node = Op->Named.Node;
    743 
    744             Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
    745             if (ACPI_FAILURE (Status))
    746             {
    747                 return_ACPI_STATUS (Status);
    748             }
    749         }
    750         else
    751         {
    752             /*
    753              * The Path is an object reference to an existing object.
    754              * Don't enter the name into the namespace, but look it up
    755              * for use later.
    756              */
    757             Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
    758                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
    759                         WalkState, &(Node));
    760             if (ACPI_FAILURE (Status))
    761             {
    762 #ifdef ACPI_ASL_COMPILER
    763                 if (Status == AE_NOT_FOUND)
    764                 {
    765                     Status = AE_OK;
    766                 }
    767                 else
    768                 {
    769                     ACPI_ERROR_NAMESPACE (BufferPtr, Status);
    770                 }
    771 #else
    772                 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
    773 #endif
    774                 return_ACPI_STATUS (Status);
    775             }
    776         }
    777 
    778         /*
    779          * We must check to make sure that the target is
    780          * one of the opcodes that actually opens a scope
    781          */
    782         switch (Node->Type)
    783         {
    784         case ACPI_TYPE_ANY:
    785         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
    786         case ACPI_TYPE_DEVICE:
    787         case ACPI_TYPE_POWER:
    788         case ACPI_TYPE_PROCESSOR:
    789         case ACPI_TYPE_THERMAL:
    790 
    791             /* These are acceptable types */
    792             break;
    793 
    794         case ACPI_TYPE_INTEGER:
    795         case ACPI_TYPE_STRING:
    796         case ACPI_TYPE_BUFFER:
    797 
    798             /*
    799              * These types we will allow, but we will change the type.
    800              * This enables some existing code of the form:
    801              *
    802              *  Name (DEB, 0)
    803              *  Scope (DEB) { ... }
    804              */
    805             ACPI_WARNING ((AE_INFO,
    806                 "Type override - [%4.4s] had invalid type (%s) "
    807                 "for Scope operator, changed to type ANY\n",
    808                 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
    809 
    810             Node->Type = ACPI_TYPE_ANY;
    811             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
    812             break;
    813 
    814         default:
    815 
    816             /* All other types are an error */
    817 
    818             ACPI_ERROR ((AE_INFO,
    819                 "Invalid type (%s) for target of "
    820                 "Scope operator [%4.4s] (Cannot override)",
    821                 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
    822 
    823             return (AE_AML_OPERAND_TYPE);
    824         }
    825         break;
    826 
    827     default:
    828 
    829         /* All other opcodes */
    830 
    831         if (Op && Op->Common.Node)
    832         {
    833             /* This op/node was previously entered into the namespace */
    834 
    835             Node = Op->Common.Node;
    836 
    837             if (AcpiNsOpensScope (ObjectType))
    838             {
    839                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
    840                 if (ACPI_FAILURE (Status))
    841                 {
    842                     return_ACPI_STATUS (Status);
    843                 }
    844             }
    845 
    846             return_ACPI_STATUS (AE_OK);
    847         }
    848 
    849         /*
    850          * Enter the named type into the internal namespace. We enter the name
    851          * as we go downward in the parse tree. Any necessary subobjects that
    852          * involve arguments to the opcode must be created as we go back up the
    853          * parse tree later.
    854          *
    855          * Note: Name may already exist if we are executing a deferred opcode.
    856          */
    857         if (WalkState->DeferredNode)
    858         {
    859             /* This name is already in the namespace, get the node */
    860 
    861             Node = WalkState->DeferredNode;
    862             Status = AE_OK;
    863             break;
    864         }
    865 
    866         Flags = ACPI_NS_NO_UPSEARCH;
    867         if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
    868         {
    869             /* Execution mode, node cannot already exist, node is temporary */
    870 
    871             Flags |= ACPI_NS_ERROR_IF_FOUND;
    872 
    873             if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
    874             {
    875                 Flags |= ACPI_NS_TEMPORARY;
    876             }
    877         }
    878 
    879         /* Add new entry or lookup existing entry */
    880 
    881         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
    882                     ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
    883 
    884         if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
    885         {
    886             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    887                 "***New Node [%4.4s] %p is temporary\n",
    888                 AcpiUtGetNodeName (Node), Node));
    889         }
    890         break;
    891     }
    892 
    893     if (ACPI_FAILURE (Status))
    894     {
    895         ACPI_ERROR_NAMESPACE (BufferPtr, Status);
    896         return_ACPI_STATUS (Status);
    897     }
    898 
    899     if (!Op)
    900     {
    901         /* Create a new op */
    902 
    903         Op = AcpiPsAllocOp (WalkState->Opcode);
    904         if (!Op)
    905         {
    906             return_ACPI_STATUS (AE_NO_MEMORY);
    907         }
    908 
    909         /* Initialize the new op */
    910 
    911         if (Node)
    912         {
    913             Op->Named.Name = Node->Name.Integer;
    914         }
    915         *OutOp = Op;
    916     }
    917 
    918     /*
    919      * Put the Node in the "op" object that the parser uses, so we
    920      * can get it again quickly when this scope is closed
    921      */
    922     Op->Common.Node = Node;
    923     return_ACPI_STATUS (Status);
    924 }
    925 
    926 
    927 /*******************************************************************************
    928  *
    929  * FUNCTION:    AcpiDsLoad2EndOp
    930  *
    931  * PARAMETERS:  WalkState       - Current state of the parse tree walk
    932  *
    933  * RETURN:      Status
    934  *
    935  * DESCRIPTION: Ascending callback used during the loading of the namespace,
    936  *              both control methods and everything else.
    937  *
    938  ******************************************************************************/
    939 
    940 ACPI_STATUS
    941 AcpiDsLoad2EndOp (
    942     ACPI_WALK_STATE         *WalkState)
    943 {
    944     ACPI_PARSE_OBJECT       *Op;
    945     ACPI_STATUS             Status = AE_OK;
    946     ACPI_OBJECT_TYPE        ObjectType;
    947     ACPI_NAMESPACE_NODE     *Node;
    948     ACPI_PARSE_OBJECT       *Arg;
    949     ACPI_NAMESPACE_NODE     *NewNode;
    950 #ifndef ACPI_NO_METHOD_EXECUTION
    951     UINT32                  i;
    952     UINT8                   RegionSpace;
    953 #endif
    954 
    955 
    956     ACPI_FUNCTION_TRACE (DsLoad2EndOp);
    957 
    958     Op = WalkState->Op;
    959     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
    960             WalkState->OpInfo->Name, Op, WalkState));
    961 
    962     /* Check if opcode had an associated namespace object */
    963 
    964     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
    965     {
    966         return_ACPI_STATUS (AE_OK);
    967     }
    968 
    969     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
    970     {
    971         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    972             "Ending scope Op=%p State=%p\n", Op, WalkState));
    973     }
    974 
    975     ObjectType = WalkState->OpInfo->ObjectType;
    976 
    977     /*
    978      * Get the Node/name from the earlier lookup
    979      * (It was saved in the *op structure)
    980      */
    981     Node = Op->Common.Node;
    982 
    983     /*
    984      * Put the Node on the object stack (Contains the ACPI Name of
    985      * this object)
    986      */
    987     WalkState->Operands[0] = (void *) Node;
    988     WalkState->NumOperands = 1;
    989 
    990     /* Pop the scope stack */
    991 
    992     if (AcpiNsOpensScope (ObjectType) &&
    993        (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
    994     {
    995         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
    996             AcpiUtGetTypeName (ObjectType), Op));
    997 
    998         Status = AcpiDsScopeStackPop (WalkState);
    999         if (ACPI_FAILURE (Status))
   1000         {
   1001             goto Cleanup;
   1002         }
   1003     }
   1004 
   1005     /*
   1006      * Named operations are as follows:
   1007      *
   1008      * AML_ALIAS
   1009      * AML_BANKFIELD
   1010      * AML_CREATEBITFIELD
   1011      * AML_CREATEBYTEFIELD
   1012      * AML_CREATEDWORDFIELD
   1013      * AML_CREATEFIELD
   1014      * AML_CREATEQWORDFIELD
   1015      * AML_CREATEWORDFIELD
   1016      * AML_DATA_REGION
   1017      * AML_DEVICE
   1018      * AML_EVENT
   1019      * AML_FIELD
   1020      * AML_INDEXFIELD
   1021      * AML_METHOD
   1022      * AML_METHODCALL
   1023      * AML_MUTEX
   1024      * AML_NAME
   1025      * AML_NAMEDFIELD
   1026      * AML_OPREGION
   1027      * AML_POWERRES
   1028      * AML_PROCESSOR
   1029      * AML_SCOPE
   1030      * AML_THERMALZONE
   1031      */
   1032 
   1033     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
   1034         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
   1035         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
   1036 
   1037     /* Decode the opcode */
   1038 
   1039     Arg = Op->Common.Value.Arg;
   1040 
   1041     switch (WalkState->OpInfo->Type)
   1042     {
   1043 #ifndef ACPI_NO_METHOD_EXECUTION
   1044 
   1045     case AML_TYPE_CREATE_FIELD:
   1046         /*
   1047          * Create the field object, but the field buffer and index must
   1048          * be evaluated later during the execution phase
   1049          */
   1050         Status = AcpiDsCreateBufferField (Op, WalkState);
   1051         break;
   1052 
   1053 
   1054      case AML_TYPE_NAMED_FIELD:
   1055         /*
   1056          * If we are executing a method, initialize the field
   1057          */
   1058         if (WalkState->MethodNode)
   1059         {
   1060             Status = AcpiDsInitFieldObjects (Op, WalkState);
   1061         }
   1062 
   1063         switch (Op->Common.AmlOpcode)
   1064         {
   1065         case AML_INDEX_FIELD_OP:
   1066 
   1067             Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
   1068                         WalkState);
   1069             break;
   1070 
   1071         case AML_BANK_FIELD_OP:
   1072 
   1073             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
   1074             break;
   1075 
   1076         case AML_FIELD_OP:
   1077 
   1078             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
   1079             break;
   1080 
   1081         default:
   1082             /* All NAMED_FIELD opcodes must be handled above */
   1083             break;
   1084         }
   1085         break;
   1086 
   1087 
   1088      case AML_TYPE_NAMED_SIMPLE:
   1089 
   1090         Status = AcpiDsCreateOperands (WalkState, Arg);
   1091         if (ACPI_FAILURE (Status))
   1092         {
   1093             goto Cleanup;
   1094         }
   1095 
   1096         switch (Op->Common.AmlOpcode)
   1097         {
   1098         case AML_PROCESSOR_OP:
   1099 
   1100             Status = AcpiExCreateProcessor (WalkState);
   1101             break;
   1102 
   1103         case AML_POWER_RES_OP:
   1104 
   1105             Status = AcpiExCreatePowerResource (WalkState);
   1106             break;
   1107 
   1108         case AML_MUTEX_OP:
   1109 
   1110             Status = AcpiExCreateMutex (WalkState);
   1111             break;
   1112 
   1113         case AML_EVENT_OP:
   1114 
   1115             Status = AcpiExCreateEvent (WalkState);
   1116             break;
   1117 
   1118 
   1119         case AML_ALIAS_OP:
   1120 
   1121             Status = AcpiExCreateAlias (WalkState);
   1122             break;
   1123 
   1124         default:
   1125             /* Unknown opcode */
   1126 
   1127             Status = AE_OK;
   1128             goto Cleanup;
   1129         }
   1130 
   1131         /* Delete operands */
   1132 
   1133         for (i = 1; i < WalkState->NumOperands; i++)
   1134         {
   1135             AcpiUtRemoveReference (WalkState->Operands[i]);
   1136             WalkState->Operands[i] = NULL;
   1137         }
   1138 
   1139         break;
   1140 #endif /* ACPI_NO_METHOD_EXECUTION */
   1141 
   1142     case AML_TYPE_NAMED_COMPLEX:
   1143 
   1144         switch (Op->Common.AmlOpcode)
   1145         {
   1146 #ifndef ACPI_NO_METHOD_EXECUTION
   1147         case AML_REGION_OP:
   1148         case AML_DATA_REGION_OP:
   1149 
   1150             if (Op->Common.AmlOpcode == AML_REGION_OP)
   1151             {
   1152                 RegionSpace = (ACPI_ADR_SPACE_TYPE)
   1153                       ((Op->Common.Value.Arg)->Common.Value.Integer);
   1154             }
   1155             else
   1156             {
   1157                 RegionSpace = REGION_DATA_TABLE;
   1158             }
   1159 
   1160             /*
   1161              * The OpRegion is not fully parsed at this time. The only valid
   1162              * argument is the SpaceId. (We must save the address of the
   1163              * AML of the address and length operands)
   1164              *
   1165              * If we have a valid region, initialize it. The namespace is
   1166              * unlocked at this point.
   1167              *
   1168              * Need to unlock interpreter if it is locked (if we are running
   1169              * a control method), in order to allow _REG methods to be run
   1170              * during AcpiEvInitializeRegion.
   1171              */
   1172             if (WalkState->MethodNode)
   1173             {
   1174                 /*
   1175                  * Executing a method: initialize the region and unlock
   1176                  * the interpreter
   1177                  */
   1178                 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
   1179                             RegionSpace, WalkState);
   1180                 if (ACPI_FAILURE (Status))
   1181                 {
   1182                     return (Status);
   1183                 }
   1184 
   1185                 AcpiExExitInterpreter ();
   1186             }
   1187 
   1188             Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
   1189                         FALSE);
   1190             if (WalkState->MethodNode)
   1191             {
   1192                 AcpiExEnterInterpreter ();
   1193             }
   1194 
   1195             if (ACPI_FAILURE (Status))
   1196             {
   1197                 /*
   1198                  *  If AE_NOT_EXIST is returned, it is not fatal
   1199                  *  because many regions get created before a handler
   1200                  *  is installed for said region.
   1201                  */
   1202                 if (AE_NOT_EXIST == Status)
   1203                 {
   1204                     Status = AE_OK;
   1205                 }
   1206             }
   1207             break;
   1208 
   1209 
   1210         case AML_NAME_OP:
   1211 
   1212             Status = AcpiDsCreateNode (WalkState, Node, Op);
   1213             break;
   1214 
   1215 
   1216         case AML_METHOD_OP:
   1217             /*
   1218              * MethodOp PkgLength NameString MethodFlags TermList
   1219              *
   1220              * Note: We must create the method node/object pair as soon as we
   1221              * see the method declaration. This allows later pass1 parsing
   1222              * of invocations of the method (need to know the number of
   1223              * arguments.)
   1224              */
   1225             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
   1226                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
   1227                 WalkState, Op, Op->Named.Node));
   1228 
   1229             if (!AcpiNsGetAttachedObject (Op->Named.Node))
   1230             {
   1231                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
   1232                 WalkState->NumOperands = 1;
   1233 
   1234                 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
   1235                 if (ACPI_SUCCESS (Status))
   1236                 {
   1237                     Status = AcpiExCreateMethod (Op->Named.Data,
   1238                                         Op->Named.Length, WalkState);
   1239                 }
   1240                 WalkState->Operands[0] = NULL;
   1241                 WalkState->NumOperands = 0;
   1242 
   1243                 if (ACPI_FAILURE (Status))
   1244                 {
   1245                     return_ACPI_STATUS (Status);
   1246                 }
   1247             }
   1248             break;
   1249 
   1250 #endif /* ACPI_NO_METHOD_EXECUTION */
   1251 
   1252         default:
   1253             /* All NAMED_COMPLEX opcodes must be handled above */
   1254             break;
   1255         }
   1256         break;
   1257 
   1258 
   1259     case AML_CLASS_INTERNAL:
   1260 
   1261         /* case AML_INT_NAMEPATH_OP: */
   1262         break;
   1263 
   1264 
   1265     case AML_CLASS_METHOD_CALL:
   1266 
   1267         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
   1268             "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
   1269             WalkState, Op, Node));
   1270 
   1271         /*
   1272          * Lookup the method name and save the Node
   1273          */
   1274         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
   1275                         ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
   1276                         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
   1277                         WalkState, &(NewNode));
   1278         if (ACPI_SUCCESS (Status))
   1279         {
   1280             /*
   1281              * Make sure that what we found is indeed a method
   1282              * We didn't search for a method on purpose, to see if the name
   1283              * would resolve
   1284              */
   1285             if (NewNode->Type != ACPI_TYPE_METHOD)
   1286             {
   1287                 Status = AE_AML_OPERAND_TYPE;
   1288             }
   1289 
   1290             /* We could put the returned object (Node) on the object stack for
   1291              * later, but for now, we will put it in the "op" object that the
   1292              * parser uses, so we can get it again at the end of this scope
   1293              */
   1294             Op->Common.Node = NewNode;
   1295         }
   1296         else
   1297         {
   1298             ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
   1299         }
   1300         break;
   1301 
   1302 
   1303     default:
   1304         break;
   1305     }
   1306 
   1307 Cleanup:
   1308 
   1309     /* Remove the Node pushed at the very beginning */
   1310 
   1311     WalkState->Operands[0] = NULL;
   1312     WalkState->NumOperands = 0;
   1313     return_ACPI_STATUS (Status);
   1314 }
   1315 
   1316 
   1317