Subversion Repositories Kolibri OS

Rev

Rev 1498 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /******************************************************************************
  2.  *
  3.  * Module Name: dsobject - Dispatcher object management routines
  4.  *
  5.  *****************************************************************************/
  6.  
  7. /******************************************************************************
  8.  *
  9.  * 1. Copyright Notice
  10.  *
  11.  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
  12.  * All rights reserved.
  13.  *
  14.  * 2. License
  15.  *
  16.  * 2.1. This is your license from Intel Corp. under its intellectual property
  17.  * rights.  You may have additional license terms from the party that provided
  18.  * you this software, covering your right to use that party's intellectual
  19.  * property rights.
  20.  *
  21.  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  22.  * copy of the source code appearing in this file ("Covered Code") an
  23.  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  24.  * base code distributed originally by Intel ("Original Intel Code") to copy,
  25.  * make derivatives, distribute, use and display any portion of the Covered
  26.  * Code in any form, with the right to sublicense such rights; and
  27.  *
  28.  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  29.  * license (with the right to sublicense), under only those claims of Intel
  30.  * patents that are infringed by the Original Intel Code, to make, use, sell,
  31.  * offer to sell, and import the Covered Code and derivative works thereof
  32.  * solely to the minimum extent necessary to exercise the above copyright
  33.  * license, and in no event shall the patent license extend to any additions
  34.  * to or modifications of the Original Intel Code.  No other license or right
  35.  * is granted directly or by implication, estoppel or otherwise;
  36.  *
  37.  * The above copyright and patent license is granted only if the following
  38.  * conditions are met:
  39.  *
  40.  * 3. Conditions
  41.  *
  42.  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  43.  * Redistribution of source code of any substantial portion of the Covered
  44.  * Code or modification with rights to further distribute source must include
  45.  * the above Copyright Notice, the above License, this list of Conditions,
  46.  * and the following Disclaimer and Export Compliance provision.  In addition,
  47.  * Licensee must cause all Covered Code to which Licensee contributes to
  48.  * contain a file documenting the changes Licensee made to create that Covered
  49.  * Code and the date of any change.  Licensee must include in that file the
  50.  * documentation of any changes made by any predecessor Licensee.  Licensee
  51.  * must include a prominent statement that the modification is derived,
  52.  * directly or indirectly, from Original Intel Code.
  53.  *
  54.  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  55.  * Redistribution of source code of any substantial portion of the Covered
  56.  * Code or modification without rights to further distribute source must
  57.  * include the following Disclaimer and Export Compliance provision in the
  58.  * documentation and/or other materials provided with distribution.  In
  59.  * addition, Licensee may not authorize further sublicense of source of any
  60.  * portion of the Covered Code, and must include terms to the effect that the
  61.  * license from Licensee to its licensee is limited to the intellectual
  62.  * property embodied in the software Licensee provides to its licensee, and
  63.  * not to intellectual property embodied in modifications its licensee may
  64.  * make.
  65.  *
  66.  * 3.3. Redistribution of Executable. Redistribution in executable form of any
  67.  * substantial portion of the Covered Code or modification must reproduce the
  68.  * above Copyright Notice, and the following Disclaimer and Export Compliance
  69.  * provision in the documentation and/or other materials provided with the
  70.  * distribution.
  71.  *
  72.  * 3.4. Intel retains all right, title, and interest in and to the Original
  73.  * Intel Code.
  74.  *
  75.  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  76.  * Intel shall be used in advertising or otherwise to promote the sale, use or
  77.  * other dealings in products derived from or relating to the Covered Code
  78.  * without prior written authorization from Intel.
  79.  *
  80.  * 4. Disclaimer and Export Compliance
  81.  *
  82.  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  83.  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  84.  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
  85.  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
  86.  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
  87.  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  88.  * PARTICULAR PURPOSE.
  89.  *
  90.  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  91.  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  92.  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  93.  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  94.  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  95.  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
  96.  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  97.  * LIMITED REMEDY.
  98.  *
  99.  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  100.  * software or system incorporating such software without first obtaining any
  101.  * required license or other approval from the U. S. Department of Commerce or
  102.  * any other agency or department of the United States Government.  In the
  103.  * event Licensee exports any such software from the United States or
  104.  * re-exports any such software from a foreign destination, Licensee shall
  105.  * ensure that the distribution and export/re-export of the software is in
  106.  * compliance with all laws, regulations, orders, or other restrictions of the
  107.  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  108.  * any of its subsidiaries will export/re-export any technical data, process,
  109.  * software, or service, directly or indirectly, to any country for which the
  110.  * United States government or any agency thereof requires an export license,
  111.  * other governmental approval, or letter of assurance, without first obtaining
  112.  * such license, approval or letter.
  113.  *
  114.  *****************************************************************************/
  115.  
  116. #define __DSOBJECT_C__
  117.  
  118. #include "acpi.h"
  119. #include "accommon.h"
  120. #include "acparser.h"
  121. #include "amlcode.h"
  122. #include "acdispat.h"
  123. #include "acnamesp.h"
  124. #include "acinterp.h"
  125.  
  126. #define _COMPONENT          ACPI_DISPATCHER
  127.         ACPI_MODULE_NAME    ("dsobject")
  128.  
  129. /* Local prototypes */
  130.  
  131. static ACPI_STATUS
  132. AcpiDsBuildInternalObject (
  133.     ACPI_WALK_STATE         *WalkState,
  134.     ACPI_PARSE_OBJECT       *Op,
  135.     ACPI_OPERAND_OBJECT     **ObjDescPtr);
  136.  
  137.  
  138. #ifndef ACPI_NO_METHOD_EXECUTION
  139. /*******************************************************************************
  140.  *
  141.  * FUNCTION:    AcpiDsBuildInternalObject
  142.  *
  143.  * PARAMETERS:  WalkState       - Current walk state
  144.  *              Op              - Parser object to be translated
  145.  *              ObjDescPtr      - Where the ACPI internal object is returned
  146.  *
  147.  * RETURN:      Status
  148.  *
  149.  * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
  150.  *              Simple objects are any objects other than a package object!
  151.  *
  152.  ******************************************************************************/
  153.  
  154. static ACPI_STATUS
  155. AcpiDsBuildInternalObject (
  156.     ACPI_WALK_STATE         *WalkState,
  157.     ACPI_PARSE_OBJECT       *Op,
  158.     ACPI_OPERAND_OBJECT     **ObjDescPtr)
  159. {
  160.     ACPI_OPERAND_OBJECT     *ObjDesc;
  161.     ACPI_STATUS             Status;
  162.     ACPI_OBJECT_TYPE        Type;
  163.  
  164.  
  165.     ACPI_FUNCTION_TRACE (DsBuildInternalObject);
  166.  
  167.  
  168.     *ObjDescPtr = NULL;
  169.     if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
  170.     {
  171.         /*
  172.          * This is a named object reference. If this name was
  173.          * previously looked up in the namespace, it was stored in this op.
  174.          * Otherwise, go ahead and look it up now
  175.          */
  176.         if (!Op->Common.Node)
  177.         {
  178.             Status = AcpiNsLookup (WalkState->ScopeInfo,
  179.                         Op->Common.Value.String,
  180.                         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  181.                         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
  182.                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
  183.             if (ACPI_FAILURE (Status))
  184.             {
  185.                 /* Check if we are resolving a named reference within a package */
  186.  
  187.                 if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
  188.  
  189.                     ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  190.                      (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
  191.                 {
  192.                     /*
  193.                      * We didn't find the target and we are populating elements
  194.                      * of a package - ignore if slack enabled. Some ASL code
  195.                      * contains dangling invalid references in packages and
  196.                      * expects that no exception will be issued. Leave the
  197.                      * element as a null element. It cannot be used, but it
  198.                      * can be overwritten by subsequent ASL code - this is
  199.                      * typically the case.
  200.                      */
  201.                     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  202.                         "Ignoring unresolved reference in package [%4.4s]\n",
  203.                         WalkState->ScopeInfo->Scope.Node->Name.Ascii));
  204.  
  205.                     return_ACPI_STATUS (AE_OK);
  206.                 }
  207.                 else
  208.                 {
  209.                     ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
  210.                 }
  211.  
  212.                 return_ACPI_STATUS (Status);
  213.             }
  214.         }
  215.  
  216.         /* Special object resolution for elements of a package */
  217.  
  218.         if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  219.             (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
  220.         {
  221.             /*
  222.              * Attempt to resolve the node to a value before we insert it into
  223.              * the package. If this is a reference to a common data type,
  224.              * resolve it immediately. According to the ACPI spec, package
  225.              * elements can only be "data objects" or method references.
  226.              * Attempt to resolve to an Integer, Buffer, String or Package.
  227.              * If cannot, return the named reference (for things like Devices,
  228.              * Methods, etc.) Buffer Fields and Fields will resolve to simple
  229.              * objects (int/buf/str/pkg).
  230.              *
  231.              * NOTE: References to things like Devices, Methods, Mutexes, etc.
  232.              * will remain as named references. This behavior is not described
  233.              * in the ACPI spec, but it appears to be an oversight.
  234.              */
  235.             ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
  236.  
  237.             Status = AcpiExResolveNodeToValue (
  238.                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
  239.                         WalkState);
  240.             if (ACPI_FAILURE (Status))
  241.             {
  242.                 return_ACPI_STATUS (Status);
  243.             }
  244.  
  245.             /*
  246.              * Special handling for Alias objects. We need to setup the type
  247.              * and the Op->Common.Node to point to the Alias target. Note,
  248.              * Alias has at most one level of indirection internally.
  249.              */
  250.             Type = Op->Common.Node->Type;
  251.             if (Type == ACPI_TYPE_LOCAL_ALIAS)
  252.             {
  253.                 Type = ObjDesc->Common.Type;
  254.                 Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
  255.                     Op->Common.Node->Object);
  256.             }
  257.  
  258.             switch (Type)
  259.             {
  260.             /*
  261.              * For these types, we need the actual node, not the subobject.
  262.              * However, the subobject did not get an extra reference count above.
  263.              *
  264.              * TBD: should ExResolveNodeToValue be changed to fix this?
  265.              */
  266.             case ACPI_TYPE_DEVICE:
  267.             case ACPI_TYPE_THERMAL:
  268.  
  269.                 AcpiUtAddReference (Op->Common.Node->Object);
  270.  
  271.                 /*lint -fallthrough */
  272.             /*
  273.              * For these types, we need the actual node, not the subobject.
  274.              * The subobject got an extra reference count in ExResolveNodeToValue.
  275.              */
  276.             case ACPI_TYPE_MUTEX:
  277.             case ACPI_TYPE_METHOD:
  278.             case ACPI_TYPE_POWER:
  279.             case ACPI_TYPE_PROCESSOR:
  280.             case ACPI_TYPE_EVENT:
  281.             case ACPI_TYPE_REGION:
  282.  
  283.                 /* We will create a reference object for these types below */
  284.                 break;
  285.  
  286.             default:
  287.                 /*
  288.                  * All other types - the node was resolved to an actual
  289.                  * object, we are done.
  290.                  */
  291.                 goto Exit;
  292.             }
  293.         }
  294.     }
  295.  
  296.     /* Create and init a new internal ACPI object */
  297.  
  298.     ObjDesc = AcpiUtCreateInternalObject (
  299.                 (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
  300.     if (!ObjDesc)
  301.     {
  302.         return_ACPI_STATUS (AE_NO_MEMORY);
  303.     }
  304.  
  305.     Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode,
  306.                 &ObjDesc);
  307.     if (ACPI_FAILURE (Status))
  308.     {
  309.         AcpiUtRemoveReference (ObjDesc);
  310.         return_ACPI_STATUS (Status);
  311.     }
  312.  
  313. Exit:
  314.     *ObjDescPtr = ObjDesc;
  315.     return_ACPI_STATUS (Status);
  316. }
  317.  
  318.  
  319. /*******************************************************************************
  320.  *
  321.  * FUNCTION:    AcpiDsBuildInternalBufferObj
  322.  *
  323.  * PARAMETERS:  WalkState       - Current walk state
  324.  *              Op              - Parser object to be translated
  325.  *              BufferLength    - Length of the buffer
  326.  *              ObjDescPtr      - Where the ACPI internal object is returned
  327.  *
  328.  * RETURN:      Status
  329.  *
  330.  * DESCRIPTION: Translate a parser Op package object to the equivalent
  331.  *              namespace object
  332.  *
  333.  ******************************************************************************/
  334.  
  335. ACPI_STATUS
  336. AcpiDsBuildInternalBufferObj (
  337.     ACPI_WALK_STATE         *WalkState,
  338.     ACPI_PARSE_OBJECT       *Op,
  339.     UINT32                  BufferLength,
  340.     ACPI_OPERAND_OBJECT     **ObjDescPtr)
  341. {
  342.     ACPI_PARSE_OBJECT       *Arg;
  343.     ACPI_OPERAND_OBJECT     *ObjDesc;
  344.     ACPI_PARSE_OBJECT       *ByteList;
  345.     UINT32                  ByteListLength = 0;
  346.  
  347.  
  348.     ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
  349.  
  350.  
  351.     /*
  352.      * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
  353.      * The buffer object already exists (from the NS node), otherwise it must
  354.      * be created.
  355.      */
  356.     ObjDesc = *ObjDescPtr;
  357.     if (!ObjDesc)
  358.     {
  359.         /* Create a new buffer object */
  360.  
  361.         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
  362.         *ObjDescPtr = ObjDesc;
  363.         if (!ObjDesc)
  364.         {
  365.             return_ACPI_STATUS (AE_NO_MEMORY);
  366.         }
  367.     }
  368.  
  369.     /*
  370.      * Second arg is the buffer data (optional) ByteList can be either
  371.      * individual bytes or a string initializer.  In either case, a
  372.      * ByteList appears in the AML.
  373.      */
  374.     Arg = Op->Common.Value.Arg;         /* skip first arg */
  375.  
  376.     ByteList = Arg->Named.Next;
  377.     if (ByteList)
  378.     {
  379.         if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
  380.         {
  381.             ACPI_ERROR ((AE_INFO,
  382.                 "Expecting bytelist, found AML opcode 0x%X in op %p",
  383.                 ByteList->Common.AmlOpcode, ByteList));
  384.  
  385.             AcpiUtRemoveReference (ObjDesc);
  386.             return (AE_TYPE);
  387.         }
  388.  
  389.         ByteListLength = (UINT32) ByteList->Common.Value.Integer;
  390.     }
  391.  
  392.     /*
  393.      * The buffer length (number of bytes) will be the larger of:
  394.      * 1) The specified buffer length and
  395.      * 2) The length of the initializer byte list
  396.      */
  397.     ObjDesc->Buffer.Length = BufferLength;
  398.     if (ByteListLength > BufferLength)
  399.     {
  400.         ObjDesc->Buffer.Length = ByteListLength;
  401.     }
  402.  
  403.     /* Allocate the buffer */
  404.  
  405.     if (ObjDesc->Buffer.Length == 0)
  406.     {
  407.         ObjDesc->Buffer.Pointer = NULL;
  408.         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  409.             "Buffer defined with zero length in AML, creating\n"));
  410.     }
  411.     else
  412.     {
  413.         ObjDesc->Buffer.Pointer = ACPI_ALLOCATE_ZEROED (
  414.                                         ObjDesc->Buffer.Length);
  415.         if (!ObjDesc->Buffer.Pointer)
  416.         {
  417.             AcpiUtDeleteObjectDesc (ObjDesc);
  418.             return_ACPI_STATUS (AE_NO_MEMORY);
  419.         }
  420.  
  421.         /* Initialize buffer from the ByteList (if present) */
  422.  
  423.         if (ByteList)
  424.         {
  425.             ACPI_MEMCPY (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
  426.                          ByteListLength);
  427.         }
  428.     }
  429.  
  430.     ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
  431.     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
  432.     return_ACPI_STATUS (AE_OK);
  433. }
  434.  
  435.  
  436. /*******************************************************************************
  437.  *
  438.  * FUNCTION:    AcpiDsBuildInternalPackageObj
  439.  *
  440.  * PARAMETERS:  WalkState       - Current walk state
  441.  *              Op              - Parser object to be translated
  442.  *              ElementCount    - Number of elements in the package - this is
  443.  *                                the NumElements argument to Package()
  444.  *              ObjDescPtr      - Where the ACPI internal object is returned
  445.  *
  446.  * RETURN:      Status
  447.  *
  448.  * DESCRIPTION: Translate a parser Op package object to the equivalent
  449.  *              namespace object
  450.  *
  451.  * NOTE: The number of elements in the package will be always be the NumElements
  452.  * count, regardless of the number of elements in the package list. If
  453.  * NumElements is smaller, only that many package list elements are used.
  454.  * if NumElements is larger, the Package object is padded out with
  455.  * objects of type Uninitialized (as per ACPI spec.)
  456.  *
  457.  * Even though the ASL compilers do not allow NumElements to be smaller
  458.  * than the Package list length (for the fixed length package opcode), some
  459.  * BIOS code modifies the AML on the fly to adjust the NumElements, and
  460.  * this code compensates for that. This also provides compatibility with
  461.  * other AML interpreters.
  462.  *
  463.  ******************************************************************************/
  464.  
  465. ACPI_STATUS
  466. AcpiDsBuildInternalPackageObj (
  467.     ACPI_WALK_STATE         *WalkState,
  468.     ACPI_PARSE_OBJECT       *Op,
  469.     UINT32                  ElementCount,
  470.     ACPI_OPERAND_OBJECT     **ObjDescPtr)
  471. {
  472.     ACPI_PARSE_OBJECT       *Arg;
  473.     ACPI_PARSE_OBJECT       *Parent;
  474.     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
  475.     ACPI_STATUS             Status = AE_OK;
  476.     UINT32                  i;
  477.     UINT16                  Index;
  478.     UINT16                  ReferenceCount;
  479.  
  480.  
  481.     ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
  482.  
  483.  
  484.     /* Find the parent of a possibly nested package */
  485.  
  486.     Parent = Op->Common.Parent;
  487.     while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  488.            (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
  489.     {
  490.         Parent = Parent->Common.Parent;
  491.     }
  492.  
  493.     /*
  494.      * If we are evaluating a Named package object "Name (xxxx, Package)",
  495.      * the package object already exists, otherwise it must be created.
  496.      */
  497.     ObjDesc = *ObjDescPtr;
  498.     if (!ObjDesc)
  499.     {
  500.         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
  501.         *ObjDescPtr = ObjDesc;
  502.         if (!ObjDesc)
  503.         {
  504.             return_ACPI_STATUS (AE_NO_MEMORY);
  505.         }
  506.  
  507.         ObjDesc->Package.Node = Parent->Common.Node;
  508.     }
  509.  
  510.     /*
  511.      * Allocate the element array (array of pointers to the individual
  512.      * objects) based on the NumElements parameter. Add an extra pointer slot
  513.      * so that the list is always null terminated.
  514.      */
  515.     ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
  516.         ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
  517.  
  518.     if (!ObjDesc->Package.Elements)
  519.     {
  520.         AcpiUtDeleteObjectDesc (ObjDesc);
  521.         return_ACPI_STATUS (AE_NO_MEMORY);
  522.     }
  523.  
  524.     ObjDesc->Package.Count = ElementCount;
  525.  
  526.     /*
  527.      * Initialize the elements of the package, up to the NumElements count.
  528.      * Package is automatically padded with uninitialized (NULL) elements
  529.      * if NumElements is greater than the package list length. Likewise,
  530.      * Package is truncated if NumElements is less than the list length.
  531.      */
  532.     Arg = Op->Common.Value.Arg;
  533.     Arg = Arg->Common.Next;
  534.     for (i = 0; Arg && (i < ElementCount); i++)
  535.     {
  536.         if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
  537.         {
  538.             if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
  539.             {
  540.                 /*
  541.                  * A method reference "looks" to the parser to be a method
  542.                  * invocation, so we special case it here
  543.                  */
  544.                 Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
  545.                 Status = AcpiDsBuildInternalObject (WalkState, Arg,
  546.                             &ObjDesc->Package.Elements[i]);
  547.             }
  548.             else
  549.             {
  550.                 /* This package element is already built, just get it */
  551.  
  552.                 ObjDesc->Package.Elements[i] =
  553.                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
  554.             }
  555.         }
  556.         else
  557.         {
  558.             Status = AcpiDsBuildInternalObject (WalkState, Arg,
  559.                         &ObjDesc->Package.Elements[i]);
  560.         }
  561.  
  562.         if (*ObjDescPtr)
  563.         {
  564.             /* Existing package, get existing reference count */
  565.  
  566.             ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
  567.             if (ReferenceCount > 1)
  568.             {
  569.                 /* Make new element ref count match original ref count */
  570.  
  571.                 for (Index = 0; Index < (ReferenceCount - 1); Index++)
  572.                 {
  573.                     AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
  574.                 }
  575.             }
  576.         }
  577.  
  578.         Arg = Arg->Common.Next;
  579.     }
  580.  
  581.     /* Check for match between NumElements and actual length of PackageList */
  582.  
  583.     if (Arg)
  584.     {
  585.         /*
  586.          * NumElements was exhausted, but there are remaining elements in the
  587.          * PackageList. Truncate the package to NumElements.
  588.          *
  589.          * Note: technically, this is an error, from ACPI spec: "It is an error
  590.          * for NumElements to be less than the number of elements in the
  591.          * PackageList". However, we just print a message and
  592.          * no exception is returned. This provides Windows compatibility. Some
  593.          * BIOSs will alter the NumElements on the fly, creating this type
  594.          * of ill-formed package object.
  595.          */
  596.         while (Arg)
  597.         {
  598.             /*
  599.              * We must delete any package elements that were created earlier
  600.              * and are not going to be used because of the package truncation.
  601.              */
  602.             if (Arg->Common.Node)
  603.             {
  604.                 AcpiUtRemoveReference (
  605.                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
  606.                 Arg->Common.Node = NULL;
  607.             }
  608.  
  609.             /* Find out how many elements there really are */
  610.  
  611.             i++;
  612.             Arg = Arg->Common.Next;
  613.         }
  614.  
  615.         ACPI_INFO ((AE_INFO,
  616.             "Actual Package length (%u) is larger than NumElements field (%u), truncated\n",
  617.             i, ElementCount));
  618.     }
  619.     else if (i < ElementCount)
  620.     {
  621.         /*
  622.          * Arg list (elements) was exhausted, but we did not reach NumElements count.
  623.          * Note: this is not an error, the package is padded out with NULLs.
  624.          */
  625.         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  626.             "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
  627.             i, ElementCount));
  628.     }
  629.  
  630.     ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
  631.     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
  632.     return_ACPI_STATUS (Status);
  633. }
  634.  
  635.  
  636. /*******************************************************************************
  637.  *
  638.  * FUNCTION:    AcpiDsCreateNode
  639.  *
  640.  * PARAMETERS:  WalkState       - Current walk state
  641.  *              Node            - NS Node to be initialized
  642.  *              Op              - Parser object to be translated
  643.  *
  644.  * RETURN:      Status
  645.  *
  646.  * DESCRIPTION: Create the object to be associated with a namespace node
  647.  *
  648.  ******************************************************************************/
  649.  
  650. ACPI_STATUS
  651. AcpiDsCreateNode (
  652.     ACPI_WALK_STATE         *WalkState,
  653.     ACPI_NAMESPACE_NODE     *Node,
  654.     ACPI_PARSE_OBJECT       *Op)
  655. {
  656.     ACPI_STATUS             Status;
  657.     ACPI_OPERAND_OBJECT     *ObjDesc;
  658.  
  659.  
  660.     ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
  661.  
  662.  
  663.     /*
  664.      * Because of the execution pass through the non-control-method
  665.      * parts of the table, we can arrive here twice.  Only init
  666.      * the named object node the first time through
  667.      */
  668.     if (AcpiNsGetAttachedObject (Node))
  669.     {
  670.         return_ACPI_STATUS (AE_OK);
  671.     }
  672.  
  673.     if (!Op->Common.Value.Arg)
  674.     {
  675.         /* No arguments, there is nothing to do */
  676.  
  677.         return_ACPI_STATUS (AE_OK);
  678.     }
  679.  
  680.     /* Build an internal object for the argument(s) */
  681.  
  682.     Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg,
  683.                 &ObjDesc);
  684.     if (ACPI_FAILURE (Status))
  685.     {
  686.         return_ACPI_STATUS (Status);
  687.     }
  688.  
  689.     /* Re-type the object according to its argument */
  690.  
  691.     Node->Type = ObjDesc->Common.Type;
  692.  
  693.     /* Attach obj to node */
  694.  
  695.     Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
  696.  
  697.     /* Remove local reference to the object */
  698.  
  699.     AcpiUtRemoveReference (ObjDesc);
  700.     return_ACPI_STATUS (Status);
  701. }
  702.  
  703. #endif /* ACPI_NO_METHOD_EXECUTION */
  704.  
  705.  
  706. /*******************************************************************************
  707.  *
  708.  * FUNCTION:    AcpiDsInitObjectFromOp
  709.  *
  710.  * PARAMETERS:  WalkState       - Current walk state
  711.  *              Op              - Parser op used to init the internal object
  712.  *              Opcode          - AML opcode associated with the object
  713.  *              RetObjDesc      - Namespace object to be initialized
  714.  *
  715.  * RETURN:      Status
  716.  *
  717.  * DESCRIPTION: Initialize a namespace object from a parser Op and its
  718.  *              associated arguments.  The namespace object is a more compact
  719.  *              representation of the Op and its arguments.
  720.  *
  721.  ******************************************************************************/
  722.  
  723. ACPI_STATUS
  724. AcpiDsInitObjectFromOp (
  725.     ACPI_WALK_STATE         *WalkState,
  726.     ACPI_PARSE_OBJECT       *Op,
  727.     UINT16                  Opcode,
  728.     ACPI_OPERAND_OBJECT     **RetObjDesc)
  729. {
  730.     const ACPI_OPCODE_INFO  *OpInfo;
  731.     ACPI_OPERAND_OBJECT     *ObjDesc;
  732.     ACPI_STATUS             Status = AE_OK;
  733.  
  734.  
  735.     ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
  736.  
  737.  
  738.     ObjDesc = *RetObjDesc;
  739.     OpInfo = AcpiPsGetOpcodeInfo (Opcode);
  740.     if (OpInfo->Class == AML_CLASS_UNKNOWN)
  741.     {
  742.         /* Unknown opcode */
  743.  
  744.         return_ACPI_STATUS (AE_TYPE);
  745.     }
  746.  
  747.     /* Perform per-object initialization */
  748.  
  749.     switch (ObjDesc->Common.Type)
  750.     {
  751.     case ACPI_TYPE_BUFFER:
  752.  
  753.         /*
  754.          * Defer evaluation of Buffer TermArg operand
  755.          */
  756.         ObjDesc->Buffer.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
  757.                                         WalkState->Operands[0]);
  758.         ObjDesc->Buffer.AmlStart  = Op->Named.Data;
  759.         ObjDesc->Buffer.AmlLength = Op->Named.Length;
  760.         break;
  761.  
  762.  
  763.     case ACPI_TYPE_PACKAGE:
  764.  
  765.         /*
  766.          * Defer evaluation of Package TermArg operand
  767.          */
  768.         ObjDesc->Package.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
  769.                                         WalkState->Operands[0]);
  770.         ObjDesc->Package.AmlStart  = Op->Named.Data;
  771.         ObjDesc->Package.AmlLength = Op->Named.Length;
  772.         break;
  773.  
  774.  
  775.     case ACPI_TYPE_INTEGER:
  776.  
  777.         switch (OpInfo->Type)
  778.         {
  779.         case AML_TYPE_CONSTANT:
  780.             /*
  781.              * Resolve AML Constants here - AND ONLY HERE!
  782.              * All constants are integers.
  783.              * We mark the integer with a flag that indicates that it started
  784.              * life as a constant -- so that stores to constants will perform
  785.              * as expected (noop). ZeroOp is used as a placeholder for optional
  786.              * target operands.
  787.              */
  788.             ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
  789.  
  790.             switch (Opcode)
  791.             {
  792.             case AML_ZERO_OP:
  793.  
  794.                 ObjDesc->Integer.Value = 0;
  795.                 break;
  796.  
  797.             case AML_ONE_OP:
  798.  
  799.                 ObjDesc->Integer.Value = 1;
  800.                 break;
  801.  
  802.             case AML_ONES_OP:
  803.  
  804.                 ObjDesc->Integer.Value = ACPI_UINT64_MAX;
  805.  
  806.                 /* Truncate value if we are executing from a 32-bit ACPI table */
  807.  
  808. #ifndef ACPI_NO_METHOD_EXECUTION
  809.                 AcpiExTruncateFor32bitTable (ObjDesc);
  810. #endif
  811.                 break;
  812.  
  813.             case AML_REVISION_OP:
  814.  
  815.                 ObjDesc->Integer.Value = ACPI_CA_VERSION;
  816.                 break;
  817.  
  818.             default:
  819.  
  820.                 ACPI_ERROR ((AE_INFO,
  821.                     "Unknown constant opcode 0x%X", Opcode));
  822.                 Status = AE_AML_OPERAND_TYPE;
  823.                 break;
  824.             }
  825.             break;
  826.  
  827.  
  828.         case AML_TYPE_LITERAL:
  829.  
  830.             ObjDesc->Integer.Value = Op->Common.Value.Integer;
  831. #ifndef ACPI_NO_METHOD_EXECUTION
  832.             AcpiExTruncateFor32bitTable (ObjDesc);
  833. #endif
  834.             break;
  835.  
  836.  
  837.         default:
  838.             ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
  839.                 OpInfo->Type));
  840.             Status = AE_AML_OPERAND_TYPE;
  841.             break;
  842.         }
  843.         break;
  844.  
  845.  
  846.     case ACPI_TYPE_STRING:
  847.  
  848.         ObjDesc->String.Pointer = Op->Common.Value.String;
  849.         ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Op->Common.Value.String);
  850.  
  851.         /*
  852.          * The string is contained in the ACPI table, don't ever try
  853.          * to delete it
  854.          */
  855.         ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
  856.         break;
  857.  
  858.  
  859.     case ACPI_TYPE_METHOD:
  860.         break;
  861.  
  862.  
  863.     case ACPI_TYPE_LOCAL_REFERENCE:
  864.  
  865.         switch (OpInfo->Type)
  866.         {
  867.         case AML_TYPE_LOCAL_VARIABLE:
  868.  
  869.             /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
  870.  
  871.             ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
  872.             ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
  873.  
  874. #ifndef ACPI_NO_METHOD_EXECUTION
  875.             Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
  876.                         ObjDesc->Reference.Value, WalkState,
  877.                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
  878.                             &ObjDesc->Reference.Object));
  879. #endif
  880.             break;
  881.  
  882.  
  883.         case AML_TYPE_METHOD_ARGUMENT:
  884.  
  885.             /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
  886.  
  887.             ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
  888.             ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
  889.  
  890. #ifndef ACPI_NO_METHOD_EXECUTION
  891.             Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
  892.                         ObjDesc->Reference.Value, WalkState,
  893.                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
  894.                             &ObjDesc->Reference.Object));
  895. #endif
  896.             break;
  897.  
  898.         default: /* Object name or Debug object */
  899.  
  900.             switch (Op->Common.AmlOpcode)
  901.             {
  902.             case AML_INT_NAMEPATH_OP:
  903.  
  904.                 /* Node was saved in Op */
  905.  
  906.                 ObjDesc->Reference.Node = Op->Common.Node;
  907.                 ObjDesc->Reference.Object = Op->Common.Node->Object;
  908.                 ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
  909.                 break;
  910.  
  911.             case AML_DEBUG_OP:
  912.  
  913.                 ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
  914.                 break;
  915.  
  916.             default:
  917.  
  918.                 ACPI_ERROR ((AE_INFO,
  919.                     "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
  920.                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  921.             }
  922.             break;
  923.         }
  924.         break;
  925.  
  926.  
  927.     default:
  928.  
  929.         ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
  930.             ObjDesc->Common.Type));
  931.  
  932.         Status = AE_AML_OPERAND_TYPE;
  933.         break;
  934.     }
  935.  
  936.     return_ACPI_STATUS (Status);
  937. }
  938.  
  939.  
  940.