Back to home page

Quest Cross Reference

 
 

    


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

0001 /******************************************************************************
0002  *
0003  * Module Name: dsobject - Dispatcher object management routines
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __DSOBJECT_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "acparser.h"
0121 #include "amlcode.h"
0122 #include "acdispat.h"
0123 #include "acnamesp.h"
0124 #include "acinterp.h"
0125 
0126 #define _COMPONENT          ACPI_DISPATCHER
0127         ACPI_MODULE_NAME    ("dsobject")
0128 
0129 /* Local prototypes */
0130 
0131 static ACPI_STATUS
0132 AcpiDsBuildInternalObject (
0133     ACPI_WALK_STATE         *WalkState,
0134     ACPI_PARSE_OBJECT       *Op,
0135     ACPI_OPERAND_OBJECT     **ObjDescPtr);
0136 
0137 
0138 #ifndef ACPI_NO_METHOD_EXECUTION
0139 /*******************************************************************************
0140  *
0141  * FUNCTION:    AcpiDsBuildInternalObject
0142  *
0143  * PARAMETERS:  WalkState       - Current walk state
0144  *              Op              - Parser object to be translated
0145  *              ObjDescPtr      - Where the ACPI internal object is returned
0146  *
0147  * RETURN:      Status
0148  *
0149  * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
0150  *              Simple objects are any objects other than a package object!
0151  *
0152  ******************************************************************************/
0153 
0154 static ACPI_STATUS
0155 AcpiDsBuildInternalObject (
0156     ACPI_WALK_STATE         *WalkState,
0157     ACPI_PARSE_OBJECT       *Op,
0158     ACPI_OPERAND_OBJECT     **ObjDescPtr)
0159 {
0160     ACPI_OPERAND_OBJECT     *ObjDesc;
0161     ACPI_STATUS             Status;
0162 
0163 
0164     ACPI_FUNCTION_TRACE (DsBuildInternalObject);
0165 
0166 
0167     *ObjDescPtr = NULL;
0168     if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
0169     {
0170         /*
0171          * This is a named object reference. If this name was
0172          * previously looked up in the namespace, it was stored in this op.
0173          * Otherwise, go ahead and look it up now
0174          */
0175         if (!Op->Common.Node)
0176         {
0177             Status = AcpiNsLookup (WalkState->ScopeInfo,
0178                         Op->Common.Value.String,
0179                         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0180                         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
0181                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
0182             if (ACPI_FAILURE (Status))
0183             {
0184                 /* Check if we are resolving a named reference within a package */
0185 
0186                 if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
0187 
0188                     ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
0189                      (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
0190                 {
0191                     /*
0192                      * We didn't find the target and we are populating elements
0193                      * of a package - ignore if slack enabled. Some ASL code
0194                      * contains dangling invalid references in packages and
0195                      * expects that no exception will be issued. Leave the
0196                      * element as a null element. It cannot be used, but it
0197                      * can be overwritten by subsequent ASL code - this is
0198                      * typically the case.
0199                      */
0200                     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0201                         "Ignoring unresolved reference in package [%4.4s]\n",
0202                         WalkState->ScopeInfo->Scope.Node->Name.Ascii));
0203 
0204                     return_ACPI_STATUS (AE_OK);
0205                 }
0206                 else
0207                 {
0208                     ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
0209                 }
0210 
0211                 return_ACPI_STATUS (Status);
0212             }
0213         }
0214 
0215         /* Special object resolution for elements of a package */
0216 
0217         if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
0218             (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
0219         {
0220             /*
0221              * Attempt to resolve the node to a value before we insert it into
0222              * the package. If this is a reference to a common data type,
0223              * resolve it immediately. According to the ACPI spec, package
0224              * elements can only be "data objects" or method references.
0225              * Attempt to resolve to an Integer, Buffer, String or Package.
0226              * If cannot, return the named reference (for things like Devices,
0227              * Methods, etc.) Buffer Fields and Fields will resolve to simple
0228              * objects (int/buf/str/pkg).
0229              *
0230              * NOTE: References to things like Devices, Methods, Mutexes, etc.
0231              * will remain as named references. This behavior is not described
0232              * in the ACPI spec, but it appears to be an oversight.
0233              */
0234             ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
0235 
0236             Status = AcpiExResolveNodeToValue (
0237                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
0238                         WalkState);
0239             if (ACPI_FAILURE (Status))
0240             {
0241                 return_ACPI_STATUS (Status);
0242             }
0243 
0244             switch (Op->Common.Node->Type)
0245             {
0246             /*
0247              * For these types, we need the actual node, not the subobject.
0248              * However, the subobject did not get an extra reference count above.
0249              *
0250              * TBD: should ExResolveNodeToValue be changed to fix this?
0251              */
0252             case ACPI_TYPE_DEVICE:
0253             case ACPI_TYPE_THERMAL:
0254 
0255                 AcpiUtAddReference (Op->Common.Node->Object);
0256 
0257                 /*lint -fallthrough */
0258             /*
0259              * For these types, we need the actual node, not the subobject.
0260              * The subobject got an extra reference count in ExResolveNodeToValue.
0261              */
0262             case ACPI_TYPE_MUTEX:
0263             case ACPI_TYPE_METHOD:
0264             case ACPI_TYPE_POWER:
0265             case ACPI_TYPE_PROCESSOR:
0266             case ACPI_TYPE_EVENT:
0267             case ACPI_TYPE_REGION:
0268 
0269                 /* We will create a reference object for these types below */
0270                 break;
0271 
0272             default:
0273                 /*
0274                  * All other types - the node was resolved to an actual
0275                  * object, we are done.
0276                  */
0277                 goto Exit;
0278             }
0279         }
0280     }
0281 
0282     /* Create and init a new internal ACPI object */
0283 
0284     ObjDesc = AcpiUtCreateInternalObject (
0285                 (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
0286     if (!ObjDesc)
0287     {
0288         return_ACPI_STATUS (AE_NO_MEMORY);
0289     }
0290 
0291     Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode,
0292                 &ObjDesc);
0293     if (ACPI_FAILURE (Status))
0294     {
0295         AcpiUtRemoveReference (ObjDesc);
0296         return_ACPI_STATUS (Status);
0297     }
0298 
0299 Exit:
0300     *ObjDescPtr = ObjDesc;
0301     return_ACPI_STATUS (Status);
0302 }
0303 
0304 
0305 /*******************************************************************************
0306  *
0307  * FUNCTION:    AcpiDsBuildInternalBufferObj
0308  *
0309  * PARAMETERS:  WalkState       - Current walk state
0310  *              Op              - Parser object to be translated
0311  *              BufferLength    - Length of the buffer
0312  *              ObjDescPtr      - Where the ACPI internal object is returned
0313  *
0314  * RETURN:      Status
0315  *
0316  * DESCRIPTION: Translate a parser Op package object to the equivalent
0317  *              namespace object
0318  *
0319  ******************************************************************************/
0320 
0321 ACPI_STATUS
0322 AcpiDsBuildInternalBufferObj (
0323     ACPI_WALK_STATE         *WalkState,
0324     ACPI_PARSE_OBJECT       *Op,
0325     UINT32                  BufferLength,
0326     ACPI_OPERAND_OBJECT     **ObjDescPtr)
0327 {
0328     ACPI_PARSE_OBJECT       *Arg;
0329     ACPI_OPERAND_OBJECT     *ObjDesc;
0330     ACPI_PARSE_OBJECT       *ByteList;
0331     UINT32                  ByteListLength = 0;
0332 
0333 
0334     ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
0335 
0336 
0337     /*
0338      * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
0339      * The buffer object already exists (from the NS node), otherwise it must
0340      * be created.
0341      */
0342     ObjDesc = *ObjDescPtr;
0343     if (!ObjDesc)
0344     {
0345         /* Create a new buffer object */
0346 
0347         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
0348         *ObjDescPtr = ObjDesc;
0349         if (!ObjDesc)
0350         {
0351             return_ACPI_STATUS (AE_NO_MEMORY);
0352         }
0353     }
0354 
0355     /*
0356      * Second arg is the buffer data (optional) ByteList can be either
0357      * individual bytes or a string initializer.  In either case, a
0358      * ByteList appears in the AML.
0359      */
0360     Arg = Op->Common.Value.Arg;         /* skip first arg */
0361 
0362     ByteList = Arg->Named.Next;
0363     if (ByteList)
0364     {
0365         if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
0366         {
0367             ACPI_ERROR ((AE_INFO,
0368                 "Expecting bytelist, got AML opcode %X in op %p",
0369                 ByteList->Common.AmlOpcode, ByteList));
0370 
0371             AcpiUtRemoveReference (ObjDesc);
0372             return (AE_TYPE);
0373         }
0374 
0375         ByteListLength = (UINT32) ByteList->Common.Value.Integer;
0376     }
0377 
0378     /*
0379      * The buffer length (number of bytes) will be the larger of:
0380      * 1) The specified buffer length and
0381      * 2) The length of the initializer byte list
0382      */
0383     ObjDesc->Buffer.Length = BufferLength;
0384     if (ByteListLength > BufferLength)
0385     {
0386         ObjDesc->Buffer.Length = ByteListLength;
0387     }
0388 
0389     /* Allocate the buffer */
0390 
0391     if (ObjDesc->Buffer.Length == 0)
0392     {
0393         ObjDesc->Buffer.Pointer = NULL;
0394         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0395             "Buffer defined with zero length in AML, creating\n"));
0396     }
0397     else
0398     {
0399         ObjDesc->Buffer.Pointer = ACPI_ALLOCATE_ZEROED (
0400                                         ObjDesc->Buffer.Length);
0401         if (!ObjDesc->Buffer.Pointer)
0402         {
0403             AcpiUtDeleteObjectDesc (ObjDesc);
0404             return_ACPI_STATUS (AE_NO_MEMORY);
0405         }
0406 
0407         /* Initialize buffer from the ByteList (if present) */
0408 
0409         if (ByteList)
0410         {
0411             ACPI_MEMCPY (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
0412                          ByteListLength);
0413         }
0414     }
0415 
0416     ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
0417     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
0418     return_ACPI_STATUS (AE_OK);
0419 }
0420 
0421 
0422 /*******************************************************************************
0423  *
0424  * FUNCTION:    AcpiDsBuildInternalPackageObj
0425  *
0426  * PARAMETERS:  WalkState       - Current walk state
0427  *              Op              - Parser object to be translated
0428  *              ElementCount    - Number of elements in the package - this is
0429  *                                the NumElements argument to Package()
0430  *              ObjDescPtr      - Where the ACPI internal object is returned
0431  *
0432  * RETURN:      Status
0433  *
0434  * DESCRIPTION: Translate a parser Op package object to the equivalent
0435  *              namespace object
0436  *
0437  * NOTE: The number of elements in the package will be always be the NumElements
0438  * count, regardless of the number of elements in the package list. If
0439  * NumElements is smaller, only that many package list elements are used.
0440  * if NumElements is larger, the Package object is padded out with
0441  * objects of type Uninitialized (as per ACPI spec.)
0442  *
0443  * Even though the ASL compilers do not allow NumElements to be smaller
0444  * than the Package list length (for the fixed length package opcode), some
0445  * BIOS code modifies the AML on the fly to adjust the NumElements, and
0446  * this code compensates for that. This also provides compatibility with
0447  * other AML interpreters.
0448  *
0449  ******************************************************************************/
0450 
0451 ACPI_STATUS
0452 AcpiDsBuildInternalPackageObj (
0453     ACPI_WALK_STATE         *WalkState,
0454     ACPI_PARSE_OBJECT       *Op,
0455     UINT32                  ElementCount,
0456     ACPI_OPERAND_OBJECT     **ObjDescPtr)
0457 {
0458     ACPI_PARSE_OBJECT       *Arg;
0459     ACPI_PARSE_OBJECT       *Parent;
0460     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
0461     ACPI_STATUS             Status = AE_OK;
0462     UINT32                  i;
0463     UINT16                  Index;
0464     UINT16                  ReferenceCount;
0465 
0466 
0467     ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
0468 
0469 
0470     /* Find the parent of a possibly nested package */
0471 
0472     Parent = Op->Common.Parent;
0473     while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
0474            (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
0475     {
0476         Parent = Parent->Common.Parent;
0477     }
0478 
0479     /*
0480      * If we are evaluating a Named package object "Name (xxxx, Package)",
0481      * the package object already exists, otherwise it must be created.
0482      */
0483     ObjDesc = *ObjDescPtr;
0484     if (!ObjDesc)
0485     {
0486         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
0487         *ObjDescPtr = ObjDesc;
0488         if (!ObjDesc)
0489         {
0490             return_ACPI_STATUS (AE_NO_MEMORY);
0491         }
0492 
0493         ObjDesc->Package.Node = Parent->Common.Node;
0494     }
0495 
0496     /*
0497      * Allocate the element array (array of pointers to the individual
0498      * objects) based on the NumElements parameter. Add an extra pointer slot
0499      * so that the list is always null terminated.
0500      */
0501     ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
0502         ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
0503 
0504     if (!ObjDesc->Package.Elements)
0505     {
0506         AcpiUtDeleteObjectDesc (ObjDesc);
0507         return_ACPI_STATUS (AE_NO_MEMORY);
0508     }
0509 
0510     ObjDesc->Package.Count = ElementCount;
0511 
0512     /*
0513      * Initialize the elements of the package, up to the NumElements count.
0514      * Package is automatically padded with uninitialized (NULL) elements
0515      * if NumElements is greater than the package list length. Likewise,
0516      * Package is truncated if NumElements is less than the list length.
0517      */
0518     Arg = Op->Common.Value.Arg;
0519     Arg = Arg->Common.Next;
0520     for (i = 0; Arg && (i < ElementCount); i++)
0521     {
0522         if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
0523         {
0524             if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
0525             {
0526                 /*
0527                  * A method reference "looks" to the parser to be a method
0528                  * invocation, so we special case it here
0529                  */
0530                 Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
0531                 Status = AcpiDsBuildInternalObject (WalkState, Arg,
0532                             &ObjDesc->Package.Elements[i]);
0533             }
0534             else
0535             {
0536                 /* This package element is already built, just get it */
0537 
0538                 ObjDesc->Package.Elements[i] =
0539                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
0540             }
0541         }
0542         else
0543         {
0544             Status = AcpiDsBuildInternalObject (WalkState, Arg,
0545                         &ObjDesc->Package.Elements[i]);
0546         }
0547 
0548         if (*ObjDescPtr)
0549         {
0550             /* Existing package, get existing reference count */
0551 
0552             ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
0553             if (ReferenceCount > 1)
0554             {
0555                 /* Make new element ref count match original ref count */
0556 
0557                 for (Index = 0; Index < (ReferenceCount - 1); Index++)
0558                 {
0559                     AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
0560                 }
0561             }
0562         }
0563 
0564         Arg = Arg->Common.Next;
0565     }
0566 
0567     /* Check for match between NumElements and actual length of PackageList */
0568 
0569     if (Arg)
0570     {
0571         /*
0572          * NumElements was exhausted, but there are remaining elements in the
0573          * PackageList.
0574          *
0575          * Note: technically, this is an error, from ACPI spec: "It is an error
0576          * for NumElements to be less than the number of elements in the
0577          * PackageList". However, for now, we just print an error message and
0578          * no exception is returned.
0579          */
0580         while (Arg)
0581         {
0582             /* Find out how many elements there really are */
0583 
0584             i++;
0585             Arg = Arg->Common.Next;
0586         }
0587 
0588         ACPI_ERROR ((AE_INFO,
0589             "Package List length (%X) larger than NumElements count (%X), truncated\n",
0590             i, ElementCount));
0591     }
0592     else if (i < ElementCount)
0593     {
0594         /*
0595          * Arg list (elements) was exhausted, but we did not reach NumElements count.
0596          * Note: this is not an error, the package is padded out with NULLs.
0597          */
0598         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0599             "Package List length (%X) smaller than NumElements count (%X), padded with null elements\n",
0600             i, ElementCount));
0601     }
0602 
0603     ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
0604     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
0605     return_ACPI_STATUS (Status);
0606 }
0607 
0608 
0609 /*******************************************************************************
0610  *
0611  * FUNCTION:    AcpiDsCreateNode
0612  *
0613  * PARAMETERS:  WalkState       - Current walk state
0614  *              Node            - NS Node to be initialized
0615  *              Op              - Parser object to be translated
0616  *
0617  * RETURN:      Status
0618  *
0619  * DESCRIPTION: Create the object to be associated with a namespace node
0620  *
0621  ******************************************************************************/
0622 
0623 ACPI_STATUS
0624 AcpiDsCreateNode (
0625     ACPI_WALK_STATE         *WalkState,
0626     ACPI_NAMESPACE_NODE     *Node,
0627     ACPI_PARSE_OBJECT       *Op)
0628 {
0629     ACPI_STATUS             Status;
0630     ACPI_OPERAND_OBJECT     *ObjDesc;
0631 
0632 
0633     ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
0634 
0635 
0636     /*
0637      * Because of the execution pass through the non-control-method
0638      * parts of the table, we can arrive here twice.  Only init
0639      * the named object node the first time through
0640      */
0641     if (AcpiNsGetAttachedObject (Node))
0642     {
0643         return_ACPI_STATUS (AE_OK);
0644     }
0645 
0646     if (!Op->Common.Value.Arg)
0647     {
0648         /* No arguments, there is nothing to do */
0649 
0650         return_ACPI_STATUS (AE_OK);
0651     }
0652 
0653     /* Build an internal object for the argument(s) */
0654 
0655     Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg,
0656                 &ObjDesc);
0657     if (ACPI_FAILURE (Status))
0658     {
0659         return_ACPI_STATUS (Status);
0660     }
0661 
0662     /* Re-type the object according to its argument */
0663 
0664     Node->Type = ObjDesc->Common.Type;
0665 
0666     /* Attach obj to node */
0667 
0668     Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
0669 
0670     /* Remove local reference to the object */
0671 
0672     AcpiUtRemoveReference (ObjDesc);
0673     return_ACPI_STATUS (Status);
0674 }
0675 
0676 #endif /* ACPI_NO_METHOD_EXECUTION */
0677 
0678 
0679 /*******************************************************************************
0680  *
0681  * FUNCTION:    AcpiDsInitObjectFromOp
0682  *
0683  * PARAMETERS:  WalkState       - Current walk state
0684  *              Op              - Parser op used to init the internal object
0685  *              Opcode          - AML opcode associated with the object
0686  *              RetObjDesc      - Namespace object to be initialized
0687  *
0688  * RETURN:      Status
0689  *
0690  * DESCRIPTION: Initialize a namespace object from a parser Op and its
0691  *              associated arguments.  The namespace object is a more compact
0692  *              representation of the Op and its arguments.
0693  *
0694  ******************************************************************************/
0695 
0696 ACPI_STATUS
0697 AcpiDsInitObjectFromOp (
0698     ACPI_WALK_STATE         *WalkState,
0699     ACPI_PARSE_OBJECT       *Op,
0700     UINT16                  Opcode,
0701     ACPI_OPERAND_OBJECT     **RetObjDesc)
0702 {
0703     const ACPI_OPCODE_INFO  *OpInfo;
0704     ACPI_OPERAND_OBJECT     *ObjDesc;
0705     ACPI_STATUS             Status = AE_OK;
0706 
0707 
0708     ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
0709 
0710 
0711     ObjDesc = *RetObjDesc;
0712     OpInfo = AcpiPsGetOpcodeInfo (Opcode);
0713     if (OpInfo->Class == AML_CLASS_UNKNOWN)
0714     {
0715         /* Unknown opcode */
0716 
0717         return_ACPI_STATUS (AE_TYPE);
0718     }
0719 
0720     /* Perform per-object initialization */
0721 
0722     switch (ObjDesc->Common.Type)
0723     {
0724     case ACPI_TYPE_BUFFER:
0725 
0726         /*
0727          * Defer evaluation of Buffer TermArg operand
0728          */
0729         ObjDesc->Buffer.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
0730                                         WalkState->Operands[0]);
0731         ObjDesc->Buffer.AmlStart  = Op->Named.Data;
0732         ObjDesc->Buffer.AmlLength = Op->Named.Length;
0733         break;
0734 
0735 
0736     case ACPI_TYPE_PACKAGE:
0737 
0738         /*
0739          * Defer evaluation of Package TermArg operand
0740          */
0741         ObjDesc->Package.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
0742                                         WalkState->Operands[0]);
0743         ObjDesc->Package.AmlStart  = Op->Named.Data;
0744         ObjDesc->Package.AmlLength = Op->Named.Length;
0745         break;
0746 
0747 
0748     case ACPI_TYPE_INTEGER:
0749 
0750         switch (OpInfo->Type)
0751         {
0752         case AML_TYPE_CONSTANT:
0753             /*
0754              * Resolve AML Constants here - AND ONLY HERE!
0755              * All constants are integers.
0756              * We mark the integer with a flag that indicates that it started
0757              * life as a constant -- so that stores to constants will perform
0758              * as expected (noop). ZeroOp is used as a placeholder for optional
0759              * target operands.
0760              */
0761             ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
0762 
0763             switch (Opcode)
0764             {
0765             case AML_ZERO_OP:
0766 
0767                 ObjDesc->Integer.Value = 0;
0768                 break;
0769 
0770             case AML_ONE_OP:
0771 
0772                 ObjDesc->Integer.Value = 1;
0773                 break;
0774 
0775             case AML_ONES_OP:
0776 
0777                 ObjDesc->Integer.Value = ACPI_INTEGER_MAX;
0778 
0779                 /* Truncate value if we are executing from a 32-bit ACPI table */
0780 
0781 #ifndef ACPI_NO_METHOD_EXECUTION
0782                 AcpiExTruncateFor32bitTable (ObjDesc);
0783 #endif
0784                 break;
0785 
0786             case AML_REVISION_OP:
0787 
0788                 ObjDesc->Integer.Value = ACPI_CA_VERSION;
0789                 break;
0790 
0791             default:
0792 
0793                 ACPI_ERROR ((AE_INFO,
0794                     "Unknown constant opcode %X", Opcode));
0795                 Status = AE_AML_OPERAND_TYPE;
0796                 break;
0797             }
0798             break;
0799 
0800 
0801         case AML_TYPE_LITERAL:
0802 
0803             ObjDesc->Integer.Value = Op->Common.Value.Integer;
0804 #ifndef ACPI_NO_METHOD_EXECUTION
0805             AcpiExTruncateFor32bitTable (ObjDesc);
0806 #endif
0807             break;
0808 
0809 
0810         default:
0811             ACPI_ERROR ((AE_INFO, "Unknown Integer type %X",
0812                 OpInfo->Type));
0813             Status = AE_AML_OPERAND_TYPE;
0814             break;
0815         }
0816         break;
0817 
0818 
0819     case ACPI_TYPE_STRING:
0820 
0821         ObjDesc->String.Pointer = Op->Common.Value.String;
0822         ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Op->Common.Value.String);
0823 
0824         /*
0825          * The string is contained in the ACPI table, don't ever try
0826          * to delete it
0827          */
0828         ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
0829         break;
0830 
0831 
0832     case ACPI_TYPE_METHOD:
0833         break;
0834 
0835 
0836     case ACPI_TYPE_LOCAL_REFERENCE:
0837 
0838         switch (OpInfo->Type)
0839         {
0840         case AML_TYPE_LOCAL_VARIABLE:
0841 
0842             /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
0843 
0844             ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
0845             ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
0846 
0847 #ifndef ACPI_NO_METHOD_EXECUTION
0848             Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
0849                         ObjDesc->Reference.Value, WalkState,
0850                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
0851                             &ObjDesc->Reference.Object));
0852 #endif
0853             break;
0854 
0855 
0856         case AML_TYPE_METHOD_ARGUMENT:
0857 
0858             /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
0859 
0860             ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
0861             ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
0862 
0863 #ifndef ACPI_NO_METHOD_EXECUTION
0864             Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
0865                         ObjDesc->Reference.Value, WalkState,
0866                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
0867                             &ObjDesc->Reference.Object));
0868 #endif
0869             break;
0870 
0871         default: /* Object name or Debug object */
0872 
0873             switch (Op->Common.AmlOpcode)
0874             {
0875             case AML_INT_NAMEPATH_OP:
0876 
0877                 /* Node was saved in Op */
0878 
0879                 ObjDesc->Reference.Node = Op->Common.Node;
0880                 ObjDesc->Reference.Object = Op->Common.Node->Object;
0881                 ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
0882                 break;
0883 
0884             case AML_DEBUG_OP:
0885 
0886                 ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
0887                 break;
0888 
0889             default:
0890 
0891                 ACPI_ERROR ((AE_INFO,
0892                     "Unimplemented reference type for AML opcode: %4.4X", Opcode));
0893                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
0894             }
0895             break;
0896         }
0897         break;
0898 
0899 
0900     default:
0901 
0902         ACPI_ERROR ((AE_INFO, "Unimplemented data type: %X",
0903             ObjDesc->Common.Type));
0904 
0905         Status = AE_AML_OPERAND_TYPE;
0906         break;
0907     }
0908 
0909     return_ACPI_STATUS (Status);
0910 }
0911 
0912