Back to home page

Quest Cross Reference

 
 

    


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

0001 /******************************************************************************
0002  *
0003  * Module Name: dswload - Dispatcher namespace load callbacks
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __DSWLOAD_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "acparser.h"
0121 #include "amlcode.h"
0122 #include "acdispat.h"
0123 #include "acinterp.h"
0124 #include "acnamesp.h"
0125 #include "acevents.h"
0126 
0127 #ifdef ACPI_ASL_COMPILER
0128 #include "acdisasm.h"
0129 #endif
0130 
0131 #define _COMPONENT          ACPI_DISPATCHER
0132         ACPI_MODULE_NAME    ("dswload")
0133 
0134 
0135 /*******************************************************************************
0136  *
0137  * FUNCTION:    AcpiDsInitCallbacks
0138  *
0139  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0140  *              PassNumber      - 1, 2, or 3
0141  *
0142  * RETURN:      Status
0143  *
0144  * DESCRIPTION: Init walk state callbacks
0145  *
0146  ******************************************************************************/
0147 
0148 ACPI_STATUS
0149 AcpiDsInitCallbacks (
0150     ACPI_WALK_STATE         *WalkState,
0151     UINT32                  PassNumber)
0152 {
0153 
0154     switch (PassNumber)
0155     {
0156     case 1:
0157         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
0158                                         ACPI_PARSE_DELETE_TREE;
0159         WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
0160         WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
0161         break;
0162 
0163     case 2:
0164         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
0165                                         ACPI_PARSE_DELETE_TREE;
0166         WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
0167         WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
0168         break;
0169 
0170     case 3:
0171 #ifndef ACPI_NO_METHOD_EXECUTION
0172         WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
0173                                         ACPI_PARSE_DELETE_TREE;
0174         WalkState->DescendingCallback = AcpiDsExecBeginOp;
0175         WalkState->AscendingCallback  = AcpiDsExecEndOp;
0176 #endif
0177         break;
0178 
0179     default:
0180         return (AE_BAD_PARAMETER);
0181     }
0182 
0183     return (AE_OK);
0184 }
0185 
0186 
0187 /*******************************************************************************
0188  *
0189  * FUNCTION:    AcpiDsLoad1BeginOp
0190  *
0191  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0192  *              OutOp           - Where to return op if a new one is created
0193  *
0194  * RETURN:      Status
0195  *
0196  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
0197  *
0198  ******************************************************************************/
0199 
0200 ACPI_STATUS
0201 AcpiDsLoad1BeginOp (
0202     ACPI_WALK_STATE         *WalkState,
0203     ACPI_PARSE_OBJECT       **OutOp)
0204 {
0205     ACPI_PARSE_OBJECT       *Op;
0206     ACPI_NAMESPACE_NODE     *Node;
0207     ACPI_STATUS             Status;
0208     ACPI_OBJECT_TYPE        ObjectType;
0209     char                    *Path;
0210     UINT32                  Flags;
0211 
0212 
0213     ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
0214 
0215 
0216     Op = WalkState->Op;
0217     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
0218 
0219     /* We are only interested in opcodes that have an associated name */
0220 
0221     if (Op)
0222     {
0223         if (!(WalkState->OpInfo->Flags & AML_NAMED))
0224         {
0225             *OutOp = Op;
0226             return_ACPI_STATUS (AE_OK);
0227         }
0228 
0229         /* Check if this object has already been installed in the namespace */
0230 
0231         if (Op->Common.Node)
0232         {
0233             *OutOp = Op;
0234             return_ACPI_STATUS (AE_OK);
0235         }
0236     }
0237 
0238     Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
0239 
0240     /* Map the raw opcode into an internal object type */
0241 
0242     ObjectType = WalkState->OpInfo->ObjectType;
0243 
0244     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0245         "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
0246 
0247     switch (WalkState->Opcode)
0248     {
0249     case AML_SCOPE_OP:
0250 
0251         /*
0252          * The target name of the Scope() operator must exist at this point so
0253          * that we can actually open the scope to enter new names underneath it.
0254          * Allow search-to-root for single namesegs.
0255          */
0256         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
0257                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
0258 #ifdef ACPI_ASL_COMPILER
0259         if (Status == AE_NOT_FOUND)
0260         {
0261             /*
0262              * Table disassembly:
0263              * Target of Scope() not found. Generate an External for it, and
0264              * insert the name into the namespace.
0265              */
0266             AcpiDmAddToExternalList (Path, ACPI_TYPE_DEVICE, 0);
0267             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
0268                        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
0269                        WalkState, &Node);
0270         }
0271 #endif
0272         if (ACPI_FAILURE (Status))
0273         {
0274             ACPI_ERROR_NAMESPACE (Path, Status);
0275             return_ACPI_STATUS (Status);
0276         }
0277 
0278         /*
0279          * Check to make sure that the target is
0280          * one of the opcodes that actually opens a scope
0281          */
0282         switch (Node->Type)
0283         {
0284         case ACPI_TYPE_ANY:
0285         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
0286         case ACPI_TYPE_DEVICE:
0287         case ACPI_TYPE_POWER:
0288         case ACPI_TYPE_PROCESSOR:
0289         case ACPI_TYPE_THERMAL:
0290 
0291             /* These are acceptable types */
0292             break;
0293 
0294         case ACPI_TYPE_INTEGER:
0295         case ACPI_TYPE_STRING:
0296         case ACPI_TYPE_BUFFER:
0297 
0298             /*
0299              * These types we will allow, but we will change the type. This
0300              * enables some existing code of the form:
0301              *
0302              *  Name (DEB, 0)
0303              *  Scope (DEB) { ... }
0304              *
0305              * Note: silently change the type here. On the second pass, we will report
0306              * a warning
0307              */
0308             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0309                 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
0310                 Path, AcpiUtGetTypeName (Node->Type)));
0311 
0312             Node->Type = ACPI_TYPE_ANY;
0313             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
0314             break;
0315 
0316         default:
0317 
0318             /* All other types are an error */
0319 
0320             ACPI_ERROR ((AE_INFO,
0321                 "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)",
0322                 AcpiUtGetTypeName (Node->Type), Path));
0323 
0324             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
0325         }
0326         break;
0327 
0328 
0329     default:
0330         /*
0331          * For all other named opcodes, we will enter the name into
0332          * the namespace.
0333          *
0334          * Setup the search flags.
0335          * Since we are entering a name into the namespace, we do not want to
0336          * enable the search-to-root upsearch.
0337          *
0338          * There are only two conditions where it is acceptable that the name
0339          * already exists:
0340          *    1) the Scope() operator can reopen a scoping object that was
0341          *       previously defined (Scope, Method, Device, etc.)
0342          *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
0343          *       BufferField, or Package), the name of the object is already
0344          *       in the namespace.
0345          */
0346         if (WalkState->DeferredNode)
0347         {
0348             /* This name is already in the namespace, get the node */
0349 
0350             Node = WalkState->DeferredNode;
0351             Status = AE_OK;
0352             break;
0353         }
0354 
0355         /*
0356          * If we are executing a method, do not create any namespace objects
0357          * during the load phase, only during execution.
0358          */
0359         if (WalkState->MethodNode)
0360         {
0361             Node = NULL;
0362             Status = AE_OK;
0363             break;
0364         }
0365 
0366         Flags = ACPI_NS_NO_UPSEARCH;
0367         if ((WalkState->Opcode != AML_SCOPE_OP) &&
0368             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
0369         {
0370             Flags |= ACPI_NS_ERROR_IF_FOUND;
0371             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
0372                     AcpiUtGetTypeName (ObjectType)));
0373         }
0374         else
0375         {
0376             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0377                 "[%s] Both Find or Create allowed\n",
0378                     AcpiUtGetTypeName (ObjectType)));
0379         }
0380 
0381         /*
0382          * Enter the named type into the internal namespace. We enter the name
0383          * as we go downward in the parse tree. Any necessary subobjects that
0384          * involve arguments to the opcode must be created as we go back up the
0385          * parse tree later.
0386          */
0387         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
0388                         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
0389         if (ACPI_FAILURE (Status))
0390         {
0391             if (Status == AE_ALREADY_EXISTS)
0392             {
0393                 /* The name already exists in this scope */
0394 
0395                 if (Node->Flags & ANOBJ_IS_EXTERNAL)
0396                 {
0397                     /*
0398                      * Allow one create on an object or segment that was
0399                      * previously declared External
0400                      */
0401                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
0402                     Node->Type = (UINT8) ObjectType;
0403 
0404                     /* Just retyped a node, probably will need to open a scope */
0405 
0406                     if (AcpiNsOpensScope (ObjectType))
0407                     {
0408                         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
0409                         if (ACPI_FAILURE (Status))
0410                         {
0411                             return_ACPI_STATUS (Status);
0412                         }
0413                     }
0414 
0415                     Status = AE_OK;
0416                 }
0417             }
0418 
0419             if (ACPI_FAILURE (Status))
0420             {
0421                 ACPI_ERROR_NAMESPACE (Path, Status);
0422                 return_ACPI_STATUS (Status);
0423             }
0424         }
0425         break;
0426     }
0427 
0428     /* Common exit */
0429 
0430     if (!Op)
0431     {
0432         /* Create a new op */
0433 
0434         Op = AcpiPsAllocOp (WalkState->Opcode);
0435         if (!Op)
0436         {
0437             return_ACPI_STATUS (AE_NO_MEMORY);
0438         }
0439     }
0440 
0441     /* Initialize the op */
0442 
0443 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
0444     Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
0445 #endif
0446 
0447     if (Node)
0448     {
0449         /*
0450          * Put the Node in the "op" object that the parser uses, so we
0451          * can get it again quickly when this scope is closed
0452          */
0453         Op->Common.Node = Node;
0454         Op->Named.Name = Node->Name.Integer;
0455     }
0456 
0457     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
0458     *OutOp = Op;
0459     return_ACPI_STATUS (Status);
0460 }
0461 
0462 
0463 /*******************************************************************************
0464  *
0465  * FUNCTION:    AcpiDsLoad1EndOp
0466  *
0467  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0468  *
0469  * RETURN:      Status
0470  *
0471  * DESCRIPTION: Ascending callback used during the loading of the namespace,
0472  *              both control methods and everything else.
0473  *
0474  ******************************************************************************/
0475 
0476 ACPI_STATUS
0477 AcpiDsLoad1EndOp (
0478     ACPI_WALK_STATE         *WalkState)
0479 {
0480     ACPI_PARSE_OBJECT       *Op;
0481     ACPI_OBJECT_TYPE        ObjectType;
0482     ACPI_STATUS             Status = AE_OK;
0483 
0484 
0485     ACPI_FUNCTION_TRACE (DsLoad1EndOp);
0486 
0487 
0488     Op = WalkState->Op;
0489     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
0490 
0491     /* We are only interested in opcodes that have an associated name */
0492 
0493     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
0494     {
0495         return_ACPI_STATUS (AE_OK);
0496     }
0497 
0498     /* Get the object type to determine if we should pop the scope */
0499 
0500     ObjectType = WalkState->OpInfo->ObjectType;
0501 
0502 #ifndef ACPI_NO_METHOD_EXECUTION
0503     if (WalkState->OpInfo->Flags & AML_FIELD)
0504     {
0505         /*
0506          * If we are executing a method, do not create any namespace objects
0507          * during the load phase, only during execution.
0508          */
0509         if (!WalkState->MethodNode)
0510         {
0511             if (WalkState->Opcode == AML_FIELD_OP          ||
0512                 WalkState->Opcode == AML_BANK_FIELD_OP     ||
0513                 WalkState->Opcode == AML_INDEX_FIELD_OP)
0514             {
0515                 Status = AcpiDsInitFieldObjects (Op, WalkState);
0516             }
0517         }
0518         return_ACPI_STATUS (Status);
0519     }
0520 
0521     /*
0522      * If we are executing a method, do not create any namespace objects
0523      * during the load phase, only during execution.
0524      */
0525     if (!WalkState->MethodNode)
0526     {
0527         if (Op->Common.AmlOpcode == AML_REGION_OP)
0528         {
0529             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
0530                         (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
0531                         WalkState);
0532             if (ACPI_FAILURE (Status))
0533             {
0534                 return_ACPI_STATUS (Status);
0535             }
0536         }
0537         else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
0538         {
0539             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
0540                         REGION_DATA_TABLE, WalkState);
0541             if (ACPI_FAILURE (Status))
0542             {
0543                 return_ACPI_STATUS (Status);
0544             }
0545         }
0546     }
0547 #endif
0548 
0549     if (Op->Common.AmlOpcode == AML_NAME_OP)
0550     {
0551         /* For Name opcode, get the object type from the argument */
0552 
0553         if (Op->Common.Value.Arg)
0554         {
0555             ObjectType = (AcpiPsGetOpcodeInfo (
0556                 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
0557 
0558             /* Set node type if we have a namespace node */
0559 
0560             if (Op->Common.Node)
0561             {
0562                 Op->Common.Node->Type = (UINT8) ObjectType;
0563             }
0564         }
0565     }
0566 
0567     /*
0568      * If we are executing a method, do not create any namespace objects
0569      * during the load phase, only during execution.
0570      */
0571     if (!WalkState->MethodNode)
0572     {
0573         if (Op->Common.AmlOpcode == AML_METHOD_OP)
0574         {
0575             /*
0576              * MethodOp PkgLength NameString MethodFlags TermList
0577              *
0578              * Note: We must create the method node/object pair as soon as we
0579              * see the method declaration. This allows later pass1 parsing
0580              * of invocations of the method (need to know the number of
0581              * arguments.)
0582              */
0583             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0584                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
0585                 WalkState, Op, Op->Named.Node));
0586 
0587             if (!AcpiNsGetAttachedObject (Op->Named.Node))
0588             {
0589                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
0590                 WalkState->NumOperands = 1;
0591 
0592                 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
0593                 if (ACPI_SUCCESS (Status))
0594                 {
0595                     Status = AcpiExCreateMethod (Op->Named.Data,
0596                                         Op->Named.Length, WalkState);
0597                 }
0598 
0599                 WalkState->Operands[0] = NULL;
0600                 WalkState->NumOperands = 0;
0601 
0602                 if (ACPI_FAILURE (Status))
0603                 {
0604                     return_ACPI_STATUS (Status);
0605                 }
0606             }
0607         }
0608     }
0609 
0610     /* Pop the scope stack (only if loading a table) */
0611 
0612     if (!WalkState->MethodNode &&
0613         AcpiNsOpensScope (ObjectType))
0614     {
0615         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
0616             AcpiUtGetTypeName (ObjectType), Op));
0617 
0618         Status = AcpiDsScopeStackPop (WalkState);
0619     }
0620 
0621     return_ACPI_STATUS (Status);
0622 }
0623 
0624 
0625 /*******************************************************************************
0626  *
0627  * FUNCTION:    AcpiDsLoad2BeginOp
0628  *
0629  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0630  *              OutOp           - Wher to return op if a new one is created
0631  *
0632  * RETURN:      Status
0633  *
0634  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
0635  *
0636  ******************************************************************************/
0637 
0638 ACPI_STATUS
0639 AcpiDsLoad2BeginOp (
0640     ACPI_WALK_STATE         *WalkState,
0641     ACPI_PARSE_OBJECT       **OutOp)
0642 {
0643     ACPI_PARSE_OBJECT       *Op;
0644     ACPI_NAMESPACE_NODE     *Node;
0645     ACPI_STATUS             Status;
0646     ACPI_OBJECT_TYPE        ObjectType;
0647     char                    *BufferPtr;
0648     UINT32                  Flags;
0649 
0650 
0651     ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
0652 
0653 
0654     Op = WalkState->Op;
0655     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
0656 
0657     if (Op)
0658     {
0659         if ((WalkState->ControlState) &&
0660             (WalkState->ControlState->Common.State ==
0661                 ACPI_CONTROL_CONDITIONAL_EXECUTING))
0662         {
0663             /* We are executing a while loop outside of a method */
0664 
0665             Status = AcpiDsExecBeginOp (WalkState, OutOp);
0666             return_ACPI_STATUS (Status);
0667         }
0668 
0669         /* We only care about Namespace opcodes here */
0670 
0671         if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
0672               (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
0673             (!(WalkState->OpInfo->Flags & AML_NAMED)))
0674         {
0675 #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
0676             if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
0677                 (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
0678             {
0679                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0680                     "Begin/EXEC: %s (fl %8.8X)\n", WalkState->OpInfo->Name,
0681                     WalkState->OpInfo->Flags));
0682 
0683                 /* Executing a type1 or type2 opcode outside of a method */
0684 
0685                 Status = AcpiDsExecBeginOp (WalkState, OutOp);
0686                 return_ACPI_STATUS (Status);
0687             }
0688 #endif
0689             return_ACPI_STATUS (AE_OK);
0690         }
0691 
0692         /* Get the name we are going to enter or lookup in the namespace */
0693 
0694         if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
0695         {
0696             /* For Namepath op, get the path string */
0697 
0698             BufferPtr = Op->Common.Value.String;
0699             if (!BufferPtr)
0700             {
0701                 /* No name, just exit */
0702 
0703                 return_ACPI_STATUS (AE_OK);
0704             }
0705         }
0706         else
0707         {
0708             /* Get name from the op */
0709 
0710             BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
0711         }
0712     }
0713     else
0714     {
0715         /* Get the namestring from the raw AML */
0716 
0717         BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
0718     }
0719 
0720     /* Map the opcode into an internal object type */
0721 
0722     ObjectType = WalkState->OpInfo->ObjectType;
0723 
0724     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0725         "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
0726 
0727     switch (WalkState->Opcode)
0728     {
0729     case AML_FIELD_OP:
0730     case AML_BANK_FIELD_OP:
0731     case AML_INDEX_FIELD_OP:
0732 
0733         Node = NULL;
0734         Status = AE_OK;
0735         break;
0736 
0737     case AML_INT_NAMEPATH_OP:
0738         /*
0739          * The NamePath is an object reference to an existing object.
0740          * Don't enter the name into the namespace, but look it up
0741          * for use later.
0742          */
0743         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
0744                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
0745                         WalkState, &(Node));
0746         break;
0747 
0748     case AML_SCOPE_OP:
0749         /*
0750          * The Path is an object reference to an existing object.
0751          * Don't enter the name into the namespace, but look it up
0752          * for use later.
0753          */
0754         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
0755                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
0756                         WalkState, &(Node));
0757         if (ACPI_FAILURE (Status))
0758         {
0759 #ifdef ACPI_ASL_COMPILER
0760             if (Status == AE_NOT_FOUND)
0761             {
0762                 Status = AE_OK;
0763             }
0764             else
0765             {
0766                 ACPI_ERROR_NAMESPACE (BufferPtr, Status);
0767             }
0768 #else
0769             ACPI_ERROR_NAMESPACE (BufferPtr, Status);
0770 #endif
0771             return_ACPI_STATUS (Status);
0772         }
0773 
0774         /*
0775          * We must check to make sure that the target is
0776          * one of the opcodes that actually opens a scope
0777          */
0778         switch (Node->Type)
0779         {
0780         case ACPI_TYPE_ANY:
0781         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
0782         case ACPI_TYPE_DEVICE:
0783         case ACPI_TYPE_POWER:
0784         case ACPI_TYPE_PROCESSOR:
0785         case ACPI_TYPE_THERMAL:
0786 
0787             /* These are acceptable types */
0788             break;
0789 
0790         case ACPI_TYPE_INTEGER:
0791         case ACPI_TYPE_STRING:
0792         case ACPI_TYPE_BUFFER:
0793 
0794             /*
0795              * These types we will allow, but we will change the type. This
0796              * enables some existing code of the form:
0797              *
0798              *  Name (DEB, 0)
0799              *  Scope (DEB) { ... }
0800              */
0801             ACPI_WARNING ((AE_INFO,
0802                 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)",
0803                 BufferPtr, AcpiUtGetTypeName (Node->Type)));
0804 
0805             Node->Type = ACPI_TYPE_ANY;
0806             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
0807             break;
0808 
0809         default:
0810 
0811             /* All other types are an error */
0812 
0813             ACPI_ERROR ((AE_INFO,
0814                 "Invalid type (%s) for target of Scope operator [%4.4s]",
0815                 AcpiUtGetTypeName (Node->Type), BufferPtr));
0816 
0817             return (AE_AML_OPERAND_TYPE);
0818         }
0819         break;
0820 
0821     default:
0822 
0823         /* All other opcodes */
0824 
0825         if (Op && Op->Common.Node)
0826         {
0827             /* This op/node was previously entered into the namespace */
0828 
0829             Node = Op->Common.Node;
0830 
0831             if (AcpiNsOpensScope (ObjectType))
0832             {
0833                 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
0834                 if (ACPI_FAILURE (Status))
0835                 {
0836                     return_ACPI_STATUS (Status);
0837                 }
0838             }
0839 
0840             return_ACPI_STATUS (AE_OK);
0841         }
0842 
0843         /*
0844          * Enter the named type into the internal namespace. We enter the name
0845          * as we go downward in the parse tree. Any necessary subobjects that
0846          * involve arguments to the opcode must be created as we go back up the
0847          * parse tree later.
0848          *
0849          * Note: Name may already exist if we are executing a deferred opcode.
0850          */
0851         if (WalkState->DeferredNode)
0852         {
0853             /* This name is already in the namespace, get the node */
0854 
0855             Node = WalkState->DeferredNode;
0856             Status = AE_OK;
0857             break;
0858         }
0859 
0860         Flags = ACPI_NS_NO_UPSEARCH;
0861         if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
0862         {
0863             /* Execution mode, node cannot already exist, node is temporary */
0864 
0865             Flags |= (ACPI_NS_ERROR_IF_FOUND | ACPI_NS_TEMPORARY);
0866         }
0867 
0868         /* Add new entry or lookup existing entry */
0869 
0870         Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
0871                     ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
0872 
0873         if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
0874         {
0875             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0876                 "***New Node [%4.4s] %p is temporary\n",
0877                 AcpiUtGetNodeName (Node), Node));
0878         }
0879         break;
0880     }
0881 
0882     if (ACPI_FAILURE (Status))
0883     {
0884         ACPI_ERROR_NAMESPACE (BufferPtr, Status);
0885         return_ACPI_STATUS (Status);
0886     }
0887 
0888     if (!Op)
0889     {
0890         /* Create a new op */
0891 
0892         Op = AcpiPsAllocOp (WalkState->Opcode);
0893         if (!Op)
0894         {
0895             return_ACPI_STATUS (AE_NO_MEMORY);
0896         }
0897 
0898         /* Initialize the new op */
0899 
0900         if (Node)
0901         {
0902             Op->Named.Name = Node->Name.Integer;
0903         }
0904         *OutOp = Op;
0905     }
0906 
0907     /*
0908      * Put the Node in the "op" object that the parser uses, so we
0909      * can get it again quickly when this scope is closed
0910      */
0911     Op->Common.Node = Node;
0912     return_ACPI_STATUS (Status);
0913 }
0914 
0915 
0916 /*******************************************************************************
0917  *
0918  * FUNCTION:    AcpiDsLoad2EndOp
0919  *
0920  * PARAMETERS:  WalkState       - Current state of the parse tree walk
0921  *
0922  * RETURN:      Status
0923  *
0924  * DESCRIPTION: Ascending callback used during the loading of the namespace,
0925  *              both control methods and everything else.
0926  *
0927  ******************************************************************************/
0928 
0929 ACPI_STATUS
0930 AcpiDsLoad2EndOp (
0931     ACPI_WALK_STATE         *WalkState)
0932 {
0933     ACPI_PARSE_OBJECT       *Op;
0934     ACPI_STATUS             Status = AE_OK;
0935     ACPI_OBJECT_TYPE        ObjectType;
0936     ACPI_NAMESPACE_NODE     *Node;
0937     ACPI_PARSE_OBJECT       *Arg;
0938     ACPI_NAMESPACE_NODE     *NewNode;
0939 #ifndef ACPI_NO_METHOD_EXECUTION
0940     UINT32                  i;
0941     UINT8                   RegionSpace;
0942 #endif
0943 
0944 
0945     ACPI_FUNCTION_TRACE (DsLoad2EndOp);
0946 
0947     Op = WalkState->Op;
0948     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
0949             WalkState->OpInfo->Name, Op, WalkState));
0950 
0951     /* Check if opcode had an associated namespace object */
0952 
0953     if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
0954     {
0955 #ifndef ACPI_NO_METHOD_EXECUTION
0956 #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
0957         /* No namespace object. Executable opcode? */
0958 
0959         if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) ||
0960             (WalkState->OpInfo->Class == AML_CLASS_CONTROL))
0961         {
0962             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0963                 "End/EXEC:   %s (fl %8.8X)\n", WalkState->OpInfo->Name,
0964                 WalkState->OpInfo->Flags));
0965 
0966             /* Executing a type1 or type2 opcode outside of a method */
0967 
0968             Status = AcpiDsExecEndOp (WalkState);
0969             return_ACPI_STATUS (Status);
0970         }
0971 #endif
0972 #endif
0973         return_ACPI_STATUS (AE_OK);
0974     }
0975 
0976     if (Op->Common.AmlOpcode == AML_SCOPE_OP)
0977     {
0978         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
0979             "Ending scope Op=%p State=%p\n", Op, WalkState));
0980     }
0981 
0982     ObjectType = WalkState->OpInfo->ObjectType;
0983 
0984     /*
0985      * Get the Node/name from the earlier lookup
0986      * (It was saved in the *op structure)
0987      */
0988     Node = Op->Common.Node;
0989 
0990     /*
0991      * Put the Node on the object stack (Contains the ACPI Name of
0992      * this object)
0993      */
0994     WalkState->Operands[0] = (void *) Node;
0995     WalkState->NumOperands = 1;
0996 
0997     /* Pop the scope stack */
0998 
0999     if (AcpiNsOpensScope (ObjectType) &&
1000        (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
1001     {
1002         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
1003             AcpiUtGetTypeName (ObjectType), Op));
1004 
1005         Status = AcpiDsScopeStackPop (WalkState);
1006         if (ACPI_FAILURE (Status))
1007         {
1008             goto Cleanup;
1009         }
1010     }
1011 
1012     /*
1013      * Named operations are as follows:
1014      *
1015      * AML_ALIAS
1016      * AML_BANKFIELD
1017      * AML_CREATEBITFIELD
1018      * AML_CREATEBYTEFIELD
1019      * AML_CREATEDWORDFIELD
1020      * AML_CREATEFIELD
1021      * AML_CREATEQWORDFIELD
1022      * AML_CREATEWORDFIELD
1023      * AML_DATA_REGION
1024      * AML_DEVICE
1025      * AML_EVENT
1026      * AML_FIELD
1027      * AML_INDEXFIELD
1028      * AML_METHOD
1029      * AML_METHODCALL
1030      * AML_MUTEX
1031      * AML_NAME
1032      * AML_NAMEDFIELD
1033      * AML_OPREGION
1034      * AML_POWERRES
1035      * AML_PROCESSOR
1036      * AML_SCOPE
1037      * AML_THERMALZONE
1038      */
1039 
1040     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1041         "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
1042         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
1043 
1044     /* Decode the opcode */
1045 
1046     Arg = Op->Common.Value.Arg;
1047 
1048     switch (WalkState->OpInfo->Type)
1049     {
1050 #ifndef ACPI_NO_METHOD_EXECUTION
1051 
1052     case AML_TYPE_CREATE_FIELD:
1053         /*
1054          * Create the field object, but the field buffer and index must
1055          * be evaluated later during the execution phase
1056          */
1057         Status = AcpiDsCreateBufferField (Op, WalkState);
1058         break;
1059 
1060 
1061      case AML_TYPE_NAMED_FIELD:
1062         /*
1063          * If we are executing a method, initialize the field
1064          */
1065         if (WalkState->MethodNode)
1066         {
1067             Status = AcpiDsInitFieldObjects (Op, WalkState);
1068         }
1069 
1070         switch (Op->Common.AmlOpcode)
1071         {
1072         case AML_INDEX_FIELD_OP:
1073 
1074             Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node,
1075                         WalkState);
1076             break;
1077 
1078         case AML_BANK_FIELD_OP:
1079 
1080             Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
1081             break;
1082 
1083         case AML_FIELD_OP:
1084 
1085             Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
1086             break;
1087 
1088         default:
1089             /* All NAMED_FIELD opcodes must be handled above */
1090             break;
1091         }
1092         break;
1093 
1094 
1095      case AML_TYPE_NAMED_SIMPLE:
1096 
1097         Status = AcpiDsCreateOperands (WalkState, Arg);
1098         if (ACPI_FAILURE (Status))
1099         {
1100             goto Cleanup;
1101         }
1102 
1103         switch (Op->Common.AmlOpcode)
1104         {
1105         case AML_PROCESSOR_OP:
1106 
1107             Status = AcpiExCreateProcessor (WalkState);
1108             break;
1109 
1110         case AML_POWER_RES_OP:
1111 
1112             Status = AcpiExCreatePowerResource (WalkState);
1113             break;
1114 
1115         case AML_MUTEX_OP:
1116 
1117             Status = AcpiExCreateMutex (WalkState);
1118             break;
1119 
1120         case AML_EVENT_OP:
1121 
1122             Status = AcpiExCreateEvent (WalkState);
1123             break;
1124 
1125 
1126         case AML_ALIAS_OP:
1127 
1128             Status = AcpiExCreateAlias (WalkState);
1129             break;
1130 
1131         default:
1132             /* Unknown opcode */
1133 
1134             Status = AE_OK;
1135             goto Cleanup;
1136         }
1137 
1138         /* Delete operands */
1139 
1140         for (i = 1; i < WalkState->NumOperands; i++)
1141         {
1142             AcpiUtRemoveReference (WalkState->Operands[i]);
1143             WalkState->Operands[i] = NULL;
1144         }
1145 
1146         break;
1147 #endif /* ACPI_NO_METHOD_EXECUTION */
1148 
1149     case AML_TYPE_NAMED_COMPLEX:
1150 
1151         switch (Op->Common.AmlOpcode)
1152         {
1153 #ifndef ACPI_NO_METHOD_EXECUTION
1154         case AML_REGION_OP:
1155         case AML_DATA_REGION_OP:
1156 
1157             if (Op->Common.AmlOpcode == AML_REGION_OP)
1158             {
1159                 RegionSpace = (ACPI_ADR_SPACE_TYPE)
1160                       ((Op->Common.Value.Arg)->Common.Value.Integer);
1161             }
1162             else
1163             {
1164                 RegionSpace = REGION_DATA_TABLE;
1165             }
1166 
1167             /*
1168              * If we are executing a method, initialize the region
1169              */
1170             if (WalkState->MethodNode)
1171             {
1172                 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
1173                             RegionSpace, WalkState);
1174                 if (ACPI_FAILURE (Status))
1175                 {
1176                     return (Status);
1177                 }
1178             }
1179 
1180             /*
1181              * The OpRegion is not fully parsed at this time. Only valid
1182              * argument is the SpaceId. (We must save the address of the
1183              * AML of the address and length operands)
1184              */
1185 
1186             /*
1187              * If we have a valid region, initialize it
1188              * Namespace is NOT locked at this point.
1189              *
1190              * TBD: need to unlock interpreter if it is locked, in order
1191              * to allow _REG methods to be run.
1192              */
1193             Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node),
1194                         FALSE);
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