Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:02

0001 /******************************************************************************
0002  *
0003  * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acparser.h"
0155 #include "amlcode.h"
0156 #include "acdispat.h"
0157 #include "acinterp.h"
0158 #include "acnamesp.h"
0159 #include "acevents.h"
0160 #ifdef ACPI_EXEC_APP
0161 #include "aecommon.h"
0162 #endif
0163 
0164 #define _COMPONENT          ACPI_DISPATCHER
0165         ACPI_MODULE_NAME    ("dswload2")
0166 
0167 
0168 /*******************************************************************************
0169  *
0170  * FUNCTION:    AcpiDsLoad2BeginOp
0171  *
0172  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0173  *              OutOp           - Where to return op if a new one is created
0174  *
0175  * RETURN:      Status
0176  *
0177  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
0178  *
0179  ******************************************************************************/
0180 
0181 ACPI_STATUS
0182 AcpiDsLoad2BeginOp (
0183     ACPI_WALK_STATE         *WalkState,
0184     ACPI_PARSE_OBJECT       **OutOp)
0185 {
0186     ACPI_PARSE_OBJECT       *Op;
0187     ACPI_NAMESPACE_NODE     *Node;
0188     ACPI_STATUS             Status;
0189     ACPI_OBJECT_TYPE        ObjectType;
0190     char                    *BufferPtr;
0191     UINT32                  Flags;
0192 
0193 
0194     ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
0195 
0196 
0197     Op = WalkState->Op;
0198     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
0199 
0200     if (Op)
0201     {
0202         if ((WalkState->ControlState) &&
0203             (WalkState->ControlState->Common.State ==
0204                 ACPI_CONTROL_CONDITIONAL_EXECUTING))
0205         {
0206             /* We are executing a while loop outside of a method */
0207 
0208             Status = AcpiDsExecBeginOp (WalkState, OutOp);
0209             return_ACPI_STATUS (Status);
0210         }
0211 
0212         /* We only care about Namespace opcodes here */
0213 
0214         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
0215               (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
0216             (!(WalkState->OpInfo->Flags & AML_NAMED)))
0217         {
0218             return_ACPI_STATUS (AE_OK);
0219         }
0220 
0221         /* Get the name we are going to enter or lookup in the namespace */
0222 
0223         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
0224         {
0225             /* For Namepath op, get the path string */
0226 
0227             BufferPtr = Op->Common.Value.String;
0228             if (!BufferPtr)
0229             {
0230                 /* No name, just exit */
0231 
0232                 return_ACPI_STATUS (AE_OK);
0233             }
0234         }
0235         else
0236         {
0237             /* Get name from the op */
0238 
0239             BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
0240         }
0241     }
0242     else
0243     {
0244         /* Get the namestring from the raw AML */
0245 
0246         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
0247     }
0248 
0249     /* Map the opcode into an internal object type */
0250 
0251     ObjectType = WalkState->OpInfo->ObjectType;
0252 
0253     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0254         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
0255 
0256     switch (WalkState->Opcode)
0257     {
0258     case AML_FIELD_OP:
0259     case AML_BANK_FIELD_OP:
0260     case AML_INDEX_FIELD_OP:
0261 
0262         Node = NULL;
0263         Status = AE_OK;
0264         break;
0265 
0266     case AML_INT_NAMEPATH_OP:
0267         /*
0268          * The NamePath is an object reference to an existing object.
0269          * Don't enter the name into the namespace, but look it up
0270          * for use later.
0271          */
0272         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
0273             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
0274             WalkState, &(Node));
0275         break;
0276 
0277     case AML_SCOPE_OP:
0278 
0279         /* Special case for Scope(\) -> refers to the Root node */
0280 
0281         if (Op && (Op->Named.Node == AcpiGbl_RootNode))
0282         {
0283             Node = Op->Named.Node;
0284 
0285             Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
0286             if (ACPI_FAILURE (Status))
0287             {
0288                 return_ACPI_STATUS (Status);
0289             }
0290         }
0291         else
0292         {
0293             /*
0294              * The Path is an object reference to an existing object.
0295              * Don't enter the name into the namespace, but look it up
0296              * for use later.
0297              */
0298             Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
0299                 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
0300                 WalkState, &(Node));
0301             if (ACPI_FAILURE (Status))
0302             {
0303 #ifdef ACPI_ASL_COMPILER
0304                 if (Status == AE_NOT_FOUND)
0305                 {
0306                     Status = AE_OK;
0307                 }
0308                 else
0309                 {
0310                     ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0311                         BufferPtr, Status);
0312                 }
0313 #else
0314                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0315                     BufferPtr, Status);
0316 #endif
0317                 return_ACPI_STATUS (Status);
0318             }
0319         }
0320 
0321         /*
0322          * We must check to make sure that the target is
0323          * one of the opcodes that actually opens a scope
0324          */
0325         switch (Node->Type)
0326         {
0327         case ACPI_TYPE_ANY:
0328         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
0329         case ACPI_TYPE_DEVICE:
0330         case ACPI_TYPE_POWER:
0331         case ACPI_TYPE_PROCESSOR:
0332         case ACPI_TYPE_THERMAL:
0333 
0334             /* These are acceptable types */
0335             break;
0336 
0337         case ACPI_TYPE_INTEGER:
0338         case ACPI_TYPE_STRING:
0339         case ACPI_TYPE_BUFFER:
0340 
0341             /*
0342              * These types we will allow, but we will change the type.
0343              * This enables some existing code of the form:
0344              *
0345              *  Name (DEB, 0)
0346              *  Scope (DEB) { ... }
0347              */
0348             ACPI_WARNING ((AE_INFO,
0349                 "Type override - [%4.4s] had invalid type (%s) "
0350                 "for Scope operator, changed to type ANY",
0351                 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
0352 
0353             Node->Type = ACPI_TYPE_ANY;
0354             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
0355             break;
0356 
0357         case ACPI_TYPE_METHOD:
0358 
0359             /*
0360              * Allow scope change to root during execution of module-level
0361              * code. Root is typed METHOD during this time.
0362              */
0363             if ((Node == AcpiGbl_RootNode) &&
0364                 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
0365             {
0366                 break;
0367             }
0368 
0369             ACPI_FALLTHROUGH;
0370 
0371         default:
0372 
0373             /* All other types are an error */
0374 
0375             ACPI_ERROR ((AE_INFO,
0376                 "Invalid type (%s) for target of "
0377                 "Scope operator [%4.4s] (Cannot override)",
0378                 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
0379 
0380             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
0381         }
0382         break;
0383 
0384     default:
0385 
0386         /* All other opcodes */
0387 
0388         if (Op && Op->Common.Node)
0389         {
0390             /* This op/node was previously entered into the namespace */
0391 
0392             Node = Op->Common.Node;
0393 
0394             if (AcpiNsOpensScope (ObjectType))
0395             {
0396                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
0397                 if (ACPI_FAILURE (Status))
0398                 {
0399                     return_ACPI_STATUS (Status);
0400                 }
0401             }
0402 
0403             return_ACPI_STATUS (AE_OK);
0404         }
0405 
0406         /*
0407          * Enter the named type into the internal namespace. We enter the name
0408          * as we go downward in the parse tree. Any necessary subobjects that
0409          * involve arguments to the opcode must be created as we go back up the
0410          * parse tree later.
0411          *
0412          * Note: Name may already exist if we are executing a deferred opcode.
0413          */
0414         if (WalkState->DeferredNode)
0415         {
0416             /* This name is already in the namespace, get the node */
0417 
0418             Node = WalkState->DeferredNode;
0419             Status = AE_OK;
0420             break;
0421         }
0422 
0423         Flags = ACPI_NS_NO_UPSEARCH;
0424         if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
0425         {
0426             /* Execution mode, node cannot already exist, node is temporary */
0427 
0428             Flags |= ACPI_NS_ERROR_IF_FOUND;
0429 
0430             if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
0431             {
0432                 Flags |= ACPI_NS_TEMPORARY;
0433             }
0434         }
0435 
0436 #ifdef ACPI_ASL_COMPILER
0437 
0438         /*
0439          * Do not open a scope for AML_EXTERNAL_OP
0440          * AcpiNsLookup can open a new scope based on the object type
0441          * of this op. AML_EXTERNAL_OP is a declaration rather than a
0442          * definition. In the case that this external is a method object,
0443          * AcpiNsLookup will open a new scope. However, an AML_EXTERNAL_OP
0444          * associated with the ACPI_TYPE_METHOD is a declaration, rather than
0445          * a definition. Flags is set to avoid opening a scope for any
0446          * AML_EXTERNAL_OP.
0447          */
0448         if (WalkState->Opcode == AML_EXTERNAL_OP)
0449         {
0450             Flags |= ACPI_NS_DONT_OPEN_SCOPE;
0451         }
0452 #endif
0453 
0454         /*
0455          * For name creation opcodes, the full namepath prefix must
0456          * exist, except for the final (new) nameseg.
0457          */
0458         if (WalkState->OpInfo->Flags & AML_NAMED)
0459         {
0460             Flags |= ACPI_NS_PREFIX_MUST_EXIST;
0461         }
0462 
0463         /* Add new entry or lookup existing entry */
0464 
0465         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
0466             ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
0467 
0468         if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
0469         {
0470             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0471                 "***New Node [%4.4s] %p is temporary\n",
0472                 AcpiUtGetNodeName (Node), Node));
0473         }
0474         break;
0475     }
0476 
0477     if (ACPI_FAILURE (Status))
0478     {
0479         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0480             BufferPtr, Status);
0481         return_ACPI_STATUS (Status);
0482     }
0483 
0484     if (!Op)
0485     {
0486         /* Create a new op */
0487 
0488         Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
0489         if (!Op)
0490         {
0491             return_ACPI_STATUS (AE_NO_MEMORY);
0492         }
0493 
0494         /* Initialize the new op */
0495 
0496         if (Node)
0497         {
0498             Op->Named.Name = Node->Name.Integer;
0499         }
0500         *OutOp = Op;
0501     }
0502 
0503     /*
0504      * Put the Node in the "op" object that the parser uses, so we
0505      * can get it again quickly when this scope is closed
0506      */
0507     Op->Common.Node = Node;
0508     return_ACPI_STATUS (Status);
0509 }
0510 
0511 
0512 /*******************************************************************************
0513  *
0514  * FUNCTION:    AcpiDsLoad2EndOp
0515  *
0516  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0517  *
0518  * RETURN:      Status
0519  *
0520  * DESCRIPTION: Ascending callback used during the loading of the namespace,
0521  *              both control methods and everything else.
0522  *
0523  ******************************************************************************/
0524 
0525 ACPI_STATUS
0526 AcpiDsLoad2EndOp (
0527     ACPI_WALK_STATE         *WalkState)
0528 {
0529     ACPI_PARSE_OBJECT       *Op;
0530     ACPI_STATUS             Status = AE_OK;
0531     ACPI_OBJECT_TYPE        ObjectType;
0532     ACPI_NAMESPACE_NODE     *Node;
0533     ACPI_PARSE_OBJECT       *Arg;
0534     ACPI_NAMESPACE_NODE     *NewNode;
0535     UINT32                  i;
0536     UINT8                   RegionSpace;
0537 #ifdef ACPI_EXEC_APP
0538     ACPI_OPERAND_OBJECT     *ObjDesc;
0539     char                    *Namepath;
0540 #endif
0541 
0542 
0543     ACPI_FUNCTION_TRACE (DsLoad2EndOp);
0544 
0545     Op = WalkState->Op;
0546     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
0547         WalkState->OpInfo->Name, Op, WalkState));
0548 
0549     /* Check if opcode had an associated namespace object */
0550 
0551     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
0552     {
0553         return_ACPI_STATUS (AE_OK);
0554     }
0555 
0556     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
0557     {
0558         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0559             "Ending scope Op=%p State=%p\n", Op, WalkState));
0560     }
0561 
0562     ObjectType = WalkState->OpInfo->ObjectType;
0563 
0564     /*
0565      * Get the Node/name from the earlier lookup
0566      * (It was saved in the *op structure)
0567      */
0568     Node = Op->Common.Node;
0569 
0570     /*
0571      * Put the Node on the object stack (Contains the ACPI Name of
0572      * this object)
0573      */
0574     WalkState->Operands[0] = (void *) Node;
0575     WalkState->NumOperands = 1;
0576 
0577     /* Pop the scope stack */
0578 
0579     if (AcpiNsOpensScope (ObjectType) &&
0580        (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
0581     {
0582         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
0583             AcpiUtGetTypeName (ObjectType), Op));
0584 
0585         Status = AcpiDsScopeStackPop (WalkState);
0586         if (ACPI_FAILURE (Status))
0587         {
0588             goto Cleanup;
0589         }
0590     }
0591 
0592     /*
0593      * Named operations are as follows:
0594      *
0595      * AML_ALIAS
0596      * AML_BANKFIELD
0597      * AML_CREATEBITFIELD
0598      * AML_CREATEBYTEFIELD
0599      * AML_CREATEDWORDFIELD
0600      * AML_CREATEFIELD
0601      * AML_CREATEQWORDFIELD
0602      * AML_CREATEWORDFIELD
0603      * AML_DATA_REGION
0604      * AML_DEVICE
0605      * AML_EVENT
0606      * AML_FIELD
0607      * AML_INDEXFIELD
0608      * AML_METHOD
0609      * AML_METHODCALL
0610      * AML_MUTEX
0611      * AML_NAME
0612      * AML_NAMEDFIELD
0613      * AML_OPREGION
0614      * AML_POWERRES
0615      * AML_PROCESSOR
0616      * AML_SCOPE
0617      * AML_THERMALZONE
0618      */
0619 
0620     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0621         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
0622         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
0623 
0624     /* Decode the opcode */
0625 
0626     Arg = Op->Common.Value.Arg;
0627 
0628     switch (WalkState->OpInfo->Type)
0629     {
0630 
0631     case AML_TYPE_CREATE_FIELD:
0632         /*
0633          * Create the field object, but the field buffer and index must
0634          * be evaluated later during the execution phase
0635          */
0636         Status = AcpiDsCreateBufferField (Op, WalkState);
0637         if ACPI_FAILURE (Status)
0638         {
0639             ACPI_EXCEPTION ((AE_INFO, Status, "CreateBufferField failure"));
0640             goto Cleanup;
0641         }
0642         break;
0643 
0644      case AML_TYPE_NAMED_FIELD:
0645         /*
0646          * If we are executing a method, initialize the field
0647          */
0648         if (WalkState->MethodNode)
0649         {
0650             Status = AcpiDsInitFieldObjects (Op, WalkState);
0651         }
0652 
0653         switch (Op->Common.AmlOpcode)
0654         {
0655         case AML_INDEX_FIELD_OP:
0656 
0657             Status = AcpiDsCreateIndexField (
0658                 Op, (ACPI_HANDLE) Arg->Common.Node, WalkState);
0659             break;
0660 
0661         case AML_BANK_FIELD_OP:
0662 
0663             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
0664             break;
0665 
0666         case AML_FIELD_OP:
0667 
0668             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
0669             break;
0670 
0671         default:
0672 
0673             /* All NAMED_FIELD opcodes must be handled above */
0674             break;
0675         }
0676         break;
0677 
0678      case AML_TYPE_NAMED_SIMPLE:
0679 
0680         Status = AcpiDsCreateOperands (WalkState, Arg);
0681         if (ACPI_FAILURE (Status))
0682         {
0683             goto Cleanup;
0684         }
0685 
0686         switch (Op->Common.AmlOpcode)
0687         {
0688         case AML_PROCESSOR_OP:
0689 
0690             Status = AcpiExCreateProcessor (WalkState);
0691             break;
0692 
0693         case AML_POWER_RESOURCE_OP:
0694 
0695             Status = AcpiExCreatePowerResource (WalkState);
0696             break;
0697 
0698         case AML_MUTEX_OP:
0699 
0700             Status = AcpiExCreateMutex (WalkState);
0701             break;
0702 
0703         case AML_EVENT_OP:
0704 
0705             Status = AcpiExCreateEvent (WalkState);
0706             break;
0707 
0708         case AML_ALIAS_OP:
0709 
0710             Status = AcpiExCreateAlias (WalkState);
0711             break;
0712 
0713         default:
0714 
0715             /* Unknown opcode */
0716 
0717             Status = AE_OK;
0718             goto Cleanup;
0719         }
0720 
0721         /* Delete operands */
0722 
0723         for (i = 1; i < WalkState->NumOperands; i++)
0724         {
0725             AcpiUtRemoveReference (WalkState->Operands[i]);
0726             WalkState->Operands[i] = NULL;
0727         }
0728 
0729         break;
0730 
0731     case AML_TYPE_NAMED_COMPLEX:
0732 
0733         switch (Op->Common.AmlOpcode)
0734         {
0735         case AML_REGION_OP:
0736         case AML_DATA_REGION_OP:
0737 
0738             if (Op->Common.AmlOpcode == AML_REGION_OP)
0739             {
0740                 RegionSpace = (ACPI_ADR_SPACE_TYPE)
0741                     ((Op->Common.Value.Arg)->Common.Value.Integer);
0742             }
0743             else
0744             {
0745                 RegionSpace = ACPI_ADR_SPACE_DATA_TABLE;
0746             }
0747 
0748             /*
0749              * The OpRegion is not fully parsed at this time. The only valid
0750              * argument is the SpaceId. (We must save the address of the
0751              * AML of the address and length operands)
0752              *
0753              * If we have a valid region, initialize it. The namespace is
0754              * unlocked at this point.
0755              *
0756              * Need to unlock interpreter if it is locked (if we are running
0757              * a control method), in order to allow _REG methods to be run
0758              * during AcpiEvInitializeRegion.
0759              */
0760             if (WalkState->MethodNode)
0761             {
0762                 /*
0763                  * Executing a method: initialize the region and unlock
0764                  * the interpreter
0765                  */
0766                 Status = AcpiExCreateRegion (Op->Named.Data,
0767                     Op->Named.Length, RegionSpace, WalkState);
0768                 if (ACPI_FAILURE (Status))
0769                 {
0770                     return_ACPI_STATUS (Status);
0771                 }
0772             }
0773 
0774             Status = AcpiEvInitializeRegion (
0775                 AcpiNsGetAttachedObject (Node));
0776             break;
0777 
0778         case AML_NAME_OP:
0779 
0780             Status = AcpiDsCreateNode (WalkState, Node, Op);
0781             if (ACPI_FAILURE (Status))
0782             {
0783                 goto Cleanup;
0784             }
0785 
0786 #ifdef ACPI_EXEC_APP
0787             /*
0788              * AcpiExec support for namespace initialization file (initialize
0789              * Name opcodes in this code.)
0790              */
0791             Namepath = AcpiNsGetExternalPathname (Node);
0792             Status = AeLookupInitFileEntry (Namepath, &ObjDesc);
0793             if (ACPI_SUCCESS (Status))
0794             {
0795                 /* Detach any existing object, attach new object */
0796 
0797                 if (Node->Object)
0798                 {
0799                     AcpiNsDetachObject (Node);
0800                 }
0801                 AcpiNsAttachObject (Node, ObjDesc, ObjDesc->Common.Type);
0802             }
0803             ACPI_FREE (Namepath);
0804             Status = AE_OK;
0805 #endif
0806             break;
0807 
0808         case AML_METHOD_OP:
0809             /*
0810              * MethodOp PkgLength NameString MethodFlags TermList
0811              *
0812              * Note: We must create the method node/object pair as soon as we
0813              * see the method declaration. This allows later pass1 parsing
0814              * of invocations of the method (need to know the number of
0815              * arguments.)
0816              */
0817             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0818                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
0819                 WalkState, Op, Op->Named.Node));
0820 
0821             if (!AcpiNsGetAttachedObject (Op->Named.Node))
0822             {
0823                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
0824                 WalkState->NumOperands = 1;
0825 
0826                 Status = AcpiDsCreateOperands (
0827                     WalkState, Op->Common.Value.Arg);
0828                 if (ACPI_SUCCESS (Status))
0829                 {
0830                     Status = AcpiExCreateMethod (
0831                         Op->Named.Data, Op->Named.Length, WalkState);
0832                 }
0833 
0834                 WalkState->Operands[0] = NULL;
0835                 WalkState->NumOperands = 0;
0836 
0837                 if (ACPI_FAILURE (Status))
0838                 {
0839                     return_ACPI_STATUS (Status);
0840                 }
0841             }
0842             break;
0843 
0844 
0845         default:
0846 
0847             /* All NAMED_COMPLEX opcodes must be handled above */
0848             break;
0849         }
0850         break;
0851 
0852     case AML_CLASS_INTERNAL:
0853 
0854         /* case AML_INT_NAMEPATH_OP: */
0855         break;
0856 
0857     case AML_CLASS_METHOD_CALL:
0858 
0859         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0860             "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
0861             WalkState, Op, Node));
0862 
0863         /*
0864          * Lookup the method name and save the Node
0865          */
0866         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
0867             ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
0868             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
0869             WalkState, &(NewNode));
0870         if (ACPI_SUCCESS (Status))
0871         {
0872             /*
0873              * Make sure that what we found is indeed a method
0874              * We didn't search for a method on purpose, to see if the name
0875              * would resolve
0876              */
0877             if (NewNode->Type != ACPI_TYPE_METHOD)
0878             {
0879                 Status = AE_AML_OPERAND_TYPE;
0880             }
0881 
0882             /* We could put the returned object (Node) on the object stack for
0883              * later, but for now, we will put it in the "op" object that the
0884              * parser uses, so we can get it again at the end of this scope
0885              */
0886             Op->Common.Node = NewNode;
0887         }
0888         else
0889         {
0890             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0891                 Arg->Common.Value.String, Status);
0892         }
0893         break;
0894 
0895 
0896     default:
0897 
0898         break;
0899     }
0900 
0901 Cleanup:
0902 
0903     /* Remove the Node pushed at the very beginning */
0904 
0905     WalkState->Operands[0] = NULL;
0906     WalkState->NumOperands = 0;
0907     return_ACPI_STATUS (Status);
0908 }