Home | History | Annotate | Line # | Download | only in dispatcher
dspkginit.c revision 1.1.1.1.4.1
      1          1.1  christos /******************************************************************************
      2          1.1  christos  *
      3          1.1  christos  * Module Name: dspkginit - Completion of deferred package initialization
      4          1.1  christos  *
      5          1.1  christos  *****************************************************************************/
      6          1.1  christos 
      7          1.1  christos /*
      8  1.1.1.1.4.1  pgoyette  * Copyright (C) 2000 - 2018, Intel Corp.
      9          1.1  christos  * All rights reserved.
     10          1.1  christos  *
     11          1.1  christos  * Redistribution and use in source and binary forms, with or without
     12          1.1  christos  * modification, are permitted provided that the following conditions
     13          1.1  christos  * are met:
     14          1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15          1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16          1.1  christos  *    without modification.
     17          1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18          1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19          1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20          1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21          1.1  christos  *    binary redistribution.
     22          1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23          1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24          1.1  christos  *    from this software without specific prior written permission.
     25          1.1  christos  *
     26          1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27          1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28          1.1  christos  * Software Foundation.
     29          1.1  christos  *
     30          1.1  christos  * NO WARRANTY
     31          1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32          1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33          1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34          1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35          1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36          1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37          1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38          1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39          1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40          1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41          1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42          1.1  christos  */
     43          1.1  christos 
     44          1.1  christos #include "acpi.h"
     45          1.1  christos #include "accommon.h"
     46          1.1  christos #include "acnamesp.h"
     47          1.1  christos #include "amlcode.h"
     48          1.1  christos #include "acdispat.h"
     49          1.1  christos #include "acinterp.h"
     50  1.1.1.1.4.1  pgoyette #include "acparser.h"
     51          1.1  christos 
     52          1.1  christos 
     53          1.1  christos #define _COMPONENT          ACPI_NAMESPACE
     54          1.1  christos         ACPI_MODULE_NAME    ("dspkginit")
     55          1.1  christos 
     56          1.1  christos 
     57          1.1  christos /* Local prototypes */
     58          1.1  christos 
     59          1.1  christos static void
     60          1.1  christos AcpiDsResolvePackageElement (
     61          1.1  christos     ACPI_OPERAND_OBJECT     **Element);
     62          1.1  christos 
     63          1.1  christos 
     64          1.1  christos /*******************************************************************************
     65          1.1  christos  *
     66          1.1  christos  * FUNCTION:    AcpiDsBuildInternalPackageObj
     67          1.1  christos  *
     68          1.1  christos  * PARAMETERS:  WalkState       - Current walk state
     69          1.1  christos  *              Op              - Parser object to be translated
     70          1.1  christos  *              ElementCount    - Number of elements in the package - this is
     71          1.1  christos  *                                the NumElements argument to Package()
     72          1.1  christos  *              ObjDescPtr      - Where the ACPI internal object is returned
     73          1.1  christos  *
     74          1.1  christos  * RETURN:      Status
     75          1.1  christos  *
     76          1.1  christos  * DESCRIPTION: Translate a parser Op package object to the equivalent
     77          1.1  christos  *              namespace object
     78          1.1  christos  *
     79          1.1  christos  * NOTE: The number of elements in the package will be always be the NumElements
     80          1.1  christos  * count, regardless of the number of elements in the package list. If
     81          1.1  christos  * NumElements is smaller, only that many package list elements are used.
     82          1.1  christos  * if NumElements is larger, the Package object is padded out with
     83          1.1  christos  * objects of type Uninitialized (as per ACPI spec.)
     84          1.1  christos  *
     85          1.1  christos  * Even though the ASL compilers do not allow NumElements to be smaller
     86          1.1  christos  * than the Package list length (for the fixed length package opcode), some
     87          1.1  christos  * BIOS code modifies the AML on the fly to adjust the NumElements, and
     88          1.1  christos  * this code compensates for that. This also provides compatibility with
     89          1.1  christos  * other AML interpreters.
     90          1.1  christos  *
     91          1.1  christos  ******************************************************************************/
     92          1.1  christos 
     93          1.1  christos ACPI_STATUS
     94          1.1  christos AcpiDsBuildInternalPackageObj (
     95          1.1  christos     ACPI_WALK_STATE         *WalkState,
     96          1.1  christos     ACPI_PARSE_OBJECT       *Op,
     97          1.1  christos     UINT32                  ElementCount,
     98          1.1  christos     ACPI_OPERAND_OBJECT     **ObjDescPtr)
     99          1.1  christos {
    100          1.1  christos     ACPI_PARSE_OBJECT       *Arg;
    101          1.1  christos     ACPI_PARSE_OBJECT       *Parent;
    102          1.1  christos     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
    103          1.1  christos     ACPI_STATUS             Status = AE_OK;
    104  1.1.1.1.4.1  pgoyette     BOOLEAN                 ModuleLevelCode = FALSE;
    105          1.1  christos     UINT16                  ReferenceCount;
    106          1.1  christos     UINT32                  Index;
    107          1.1  christos     UINT32                  i;
    108          1.1  christos 
    109          1.1  christos 
    110          1.1  christos     ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
    111          1.1  christos 
    112          1.1  christos 
    113  1.1.1.1.4.1  pgoyette     /* Check if we are executing module level code */
    114  1.1.1.1.4.1  pgoyette 
    115  1.1.1.1.4.1  pgoyette     if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)
    116  1.1.1.1.4.1  pgoyette     {
    117  1.1.1.1.4.1  pgoyette         ModuleLevelCode = TRUE;
    118  1.1.1.1.4.1  pgoyette     }
    119  1.1.1.1.4.1  pgoyette 
    120          1.1  christos     /* Find the parent of a possibly nested package */
    121          1.1  christos 
    122          1.1  christos     Parent = Op->Common.Parent;
    123          1.1  christos     while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
    124          1.1  christos            (Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
    125          1.1  christos     {
    126          1.1  christos         Parent = Parent->Common.Parent;
    127          1.1  christos     }
    128          1.1  christos 
    129          1.1  christos     /*
    130          1.1  christos      * If we are evaluating a Named package object of the form:
    131          1.1  christos      *      Name (xxxx, Package)
    132          1.1  christos      * the package object already exists, otherwise it must be created.
    133          1.1  christos      */
    134          1.1  christos     ObjDesc = *ObjDescPtr;
    135          1.1  christos     if (!ObjDesc)
    136          1.1  christos     {
    137          1.1  christos         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
    138          1.1  christos         *ObjDescPtr = ObjDesc;
    139          1.1  christos         if (!ObjDesc)
    140          1.1  christos         {
    141          1.1  christos             return_ACPI_STATUS (AE_NO_MEMORY);
    142          1.1  christos         }
    143          1.1  christos 
    144          1.1  christos         ObjDesc->Package.Node = Parent->Common.Node;
    145          1.1  christos     }
    146          1.1  christos 
    147          1.1  christos     if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID) /* Just in case */
    148          1.1  christos     {
    149          1.1  christos         return_ACPI_STATUS (AE_OK);
    150          1.1  christos     }
    151          1.1  christos 
    152          1.1  christos     /*
    153          1.1  christos      * Allocate the element array (array of pointers to the individual
    154  1.1.1.1.4.1  pgoyette      * objects) if necessary. the count is based on the NumElements
    155  1.1.1.1.4.1  pgoyette      * parameter. Add an extra pointer slot so that the list is always
    156  1.1.1.1.4.1  pgoyette      * null terminated.
    157          1.1  christos      */
    158          1.1  christos     if (!ObjDesc->Package.Elements)
    159          1.1  christos     {
    160  1.1.1.1.4.1  pgoyette         ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
    161  1.1.1.1.4.1  pgoyette             ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
    162  1.1.1.1.4.1  pgoyette 
    163  1.1.1.1.4.1  pgoyette         if (!ObjDesc->Package.Elements)
    164  1.1.1.1.4.1  pgoyette         {
    165  1.1.1.1.4.1  pgoyette             AcpiUtDeleteObjectDesc (ObjDesc);
    166  1.1.1.1.4.1  pgoyette             return_ACPI_STATUS (AE_NO_MEMORY);
    167  1.1.1.1.4.1  pgoyette         }
    168  1.1.1.1.4.1  pgoyette 
    169  1.1.1.1.4.1  pgoyette         ObjDesc->Package.Count = ElementCount;
    170          1.1  christos     }
    171          1.1  christos 
    172  1.1.1.1.4.1  pgoyette     /* First arg is element count. Second arg begins the initializer list */
    173  1.1.1.1.4.1  pgoyette 
    174          1.1  christos     Arg = Op->Common.Value.Arg;
    175          1.1  christos     Arg = Arg->Common.Next;
    176          1.1  christos 
    177  1.1.1.1.4.1  pgoyette     /*
    178  1.1.1.1.4.1  pgoyette      * If we are executing module-level code, we will defer the
    179  1.1.1.1.4.1  pgoyette      * full resolution of the package elements in order to support
    180  1.1.1.1.4.1  pgoyette      * forward references from the elements. This provides
    181  1.1.1.1.4.1  pgoyette      * compatibility with other ACPI implementations.
    182  1.1.1.1.4.1  pgoyette      */
    183  1.1.1.1.4.1  pgoyette     if (ModuleLevelCode)
    184          1.1  christos     {
    185  1.1.1.1.4.1  pgoyette         ObjDesc->Package.AmlStart = WalkState->Aml;
    186  1.1.1.1.4.1  pgoyette         ObjDesc->Package.AmlLength = 0;
    187  1.1.1.1.4.1  pgoyette 
    188  1.1.1.1.4.1  pgoyette         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
    189  1.1.1.1.4.1  pgoyette             "%s: Deferring resolution of Package elements\n",
    190  1.1.1.1.4.1  pgoyette             ACPI_GET_FUNCTION_NAME));
    191          1.1  christos     }
    192          1.1  christos 
    193          1.1  christos     /*
    194          1.1  christos      * Initialize the elements of the package, up to the NumElements count.
    195          1.1  christos      * Package is automatically padded with uninitialized (NULL) elements
    196          1.1  christos      * if NumElements is greater than the package list length. Likewise,
    197          1.1  christos      * Package is truncated if NumElements is less than the list length.
    198          1.1  christos      */
    199          1.1  christos     for (i = 0; Arg && (i < ElementCount); i++)
    200          1.1  christos     {
    201          1.1  christos         if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
    202          1.1  christos         {
    203          1.1  christos             if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
    204          1.1  christos             {
    205          1.1  christos                 /*
    206          1.1  christos                  * A method reference "looks" to the parser to be a method
    207          1.1  christos                  * invocation, so we special case it here
    208          1.1  christos                  */
    209          1.1  christos                 Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
    210          1.1  christos                 Status = AcpiDsBuildInternalObject (
    211          1.1  christos                     WalkState, Arg, &ObjDesc->Package.Elements[i]);
    212          1.1  christos             }
    213          1.1  christos             else
    214          1.1  christos             {
    215          1.1  christos                 /* This package element is already built, just get it */
    216          1.1  christos 
    217          1.1  christos                 ObjDesc->Package.Elements[i] =
    218          1.1  christos                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
    219          1.1  christos             }
    220          1.1  christos         }
    221          1.1  christos         else
    222          1.1  christos         {
    223          1.1  christos             Status = AcpiDsBuildInternalObject (
    224          1.1  christos                 WalkState, Arg, &ObjDesc->Package.Elements[i]);
    225          1.1  christos             if (Status == AE_NOT_FOUND)
    226          1.1  christos             {
    227          1.1  christos                 ACPI_ERROR ((AE_INFO, "%-48s", "****DS namepath not found"));
    228          1.1  christos             }
    229          1.1  christos 
    230  1.1.1.1.4.1  pgoyette             if (!ModuleLevelCode)
    231  1.1.1.1.4.1  pgoyette             {
    232  1.1.1.1.4.1  pgoyette                 /*
    233  1.1.1.1.4.1  pgoyette                  * Initialize this package element. This function handles the
    234  1.1.1.1.4.1  pgoyette                  * resolution of named references within the package.
    235  1.1.1.1.4.1  pgoyette                  * Forward references from module-level code are deferred
    236  1.1.1.1.4.1  pgoyette                  * until all ACPI tables are loaded.
    237  1.1.1.1.4.1  pgoyette                  */
    238  1.1.1.1.4.1  pgoyette                 AcpiDsInitPackageElement (0, ObjDesc->Package.Elements[i],
    239  1.1.1.1.4.1  pgoyette                     NULL, &ObjDesc->Package.Elements[i]);
    240  1.1.1.1.4.1  pgoyette             }
    241          1.1  christos         }
    242          1.1  christos 
    243          1.1  christos         if (*ObjDescPtr)
    244          1.1  christos         {
    245          1.1  christos             /* Existing package, get existing reference count */
    246          1.1  christos 
    247          1.1  christos             ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
    248          1.1  christos             if (ReferenceCount > 1)
    249          1.1  christos             {
    250          1.1  christos                 /* Make new element ref count match original ref count */
    251          1.1  christos                 /* TBD: Probably need an AcpiUtAddReferences function */
    252          1.1  christos 
    253          1.1  christos                 for (Index = 0; Index < ((UINT32) ReferenceCount - 1); Index++)
    254          1.1  christos                 {
    255          1.1  christos                     AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
    256          1.1  christos                 }
    257          1.1  christos             }
    258          1.1  christos         }
    259          1.1  christos 
    260          1.1  christos         Arg = Arg->Common.Next;
    261          1.1  christos     }
    262          1.1  christos 
    263          1.1  christos     /* Check for match between NumElements and actual length of PackageList */
    264          1.1  christos 
    265          1.1  christos     if (Arg)
    266          1.1  christos     {
    267          1.1  christos         /*
    268          1.1  christos          * NumElements was exhausted, but there are remaining elements in
    269          1.1  christos          * the PackageList. Truncate the package to NumElements.
    270          1.1  christos          *
    271          1.1  christos          * Note: technically, this is an error, from ACPI spec: "It is an
    272          1.1  christos          * error for NumElements to be less than the number of elements in
    273          1.1  christos          * the PackageList". However, we just print a message and no
    274          1.1  christos          * exception is returned. This provides compatibility with other
    275          1.1  christos          * ACPI implementations. Some firmware implementations will alter
    276          1.1  christos          * the NumElements on the fly, possibly creating this type of
    277          1.1  christos          * ill-formed package object.
    278          1.1  christos          */
    279          1.1  christos         while (Arg)
    280          1.1  christos         {
    281          1.1  christos             /*
    282          1.1  christos              * We must delete any package elements that were created earlier
    283          1.1  christos              * and are not going to be used because of the package truncation.
    284          1.1  christos              */
    285          1.1  christos             if (Arg->Common.Node)
    286          1.1  christos             {
    287          1.1  christos                 AcpiUtRemoveReference (
    288          1.1  christos                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
    289          1.1  christos                 Arg->Common.Node = NULL;
    290          1.1  christos             }
    291          1.1  christos 
    292          1.1  christos             /* Find out how many elements there really are */
    293          1.1  christos 
    294          1.1  christos             i++;
    295          1.1  christos             Arg = Arg->Common.Next;
    296          1.1  christos         }
    297          1.1  christos 
    298          1.1  christos         ACPI_INFO ((
    299          1.1  christos             "Actual Package length (%u) is larger than "
    300          1.1  christos             "NumElements field (%u), truncated",
    301          1.1  christos             i, ElementCount));
    302          1.1  christos     }
    303          1.1  christos     else if (i < ElementCount)
    304          1.1  christos     {
    305          1.1  christos         /*
    306          1.1  christos          * Arg list (elements) was exhausted, but we did not reach
    307          1.1  christos          * NumElements count.
    308          1.1  christos          *
    309          1.1  christos          * Note: this is not an error, the package is padded out
    310  1.1.1.1.4.1  pgoyette          * with NULLs as per the ACPI specification.
    311          1.1  christos          */
    312  1.1.1.1.4.1  pgoyette         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
    313  1.1.1.1.4.1  pgoyette             "%s: Package List length (%u) smaller than NumElements "
    314          1.1  christos             "count (%u), padded with null elements\n",
    315  1.1.1.1.4.1  pgoyette             ACPI_GET_FUNCTION_NAME, i, ElementCount));
    316  1.1.1.1.4.1  pgoyette     }
    317  1.1.1.1.4.1  pgoyette 
    318  1.1.1.1.4.1  pgoyette     /* Module-level packages will be resolved later */
    319  1.1.1.1.4.1  pgoyette 
    320  1.1.1.1.4.1  pgoyette     if (!ModuleLevelCode)
    321  1.1.1.1.4.1  pgoyette     {
    322  1.1.1.1.4.1  pgoyette         ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
    323          1.1  christos     }
    324          1.1  christos 
    325          1.1  christos     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
    326          1.1  christos     return_ACPI_STATUS (Status);
    327          1.1  christos }
    328          1.1  christos 
    329          1.1  christos 
    330          1.1  christos /*******************************************************************************
    331          1.1  christos  *
    332          1.1  christos  * FUNCTION:    AcpiDsInitPackageElement
    333          1.1  christos  *
    334          1.1  christos  * PARAMETERS:  ACPI_PKG_CALLBACK
    335          1.1  christos  *
    336          1.1  christos  * RETURN:      Status
    337          1.1  christos  *
    338          1.1  christos  * DESCRIPTION: Resolve a named reference element within a package object
    339          1.1  christos  *
    340          1.1  christos  ******************************************************************************/
    341          1.1  christos 
    342          1.1  christos ACPI_STATUS
    343          1.1  christos AcpiDsInitPackageElement (
    344          1.1  christos     UINT8                   ObjectType,
    345          1.1  christos     ACPI_OPERAND_OBJECT     *SourceObject,
    346          1.1  christos     ACPI_GENERIC_STATE      *State,
    347          1.1  christos     void                    *Context)
    348          1.1  christos {
    349          1.1  christos     ACPI_OPERAND_OBJECT     **ElementPtr;
    350          1.1  christos 
    351          1.1  christos 
    352  1.1.1.1.4.1  pgoyette     ACPI_FUNCTION_TRACE (DsInitPackageElement);
    353  1.1.1.1.4.1  pgoyette 
    354  1.1.1.1.4.1  pgoyette 
    355          1.1  christos     if (!SourceObject)
    356          1.1  christos     {
    357  1.1.1.1.4.1  pgoyette         return_ACPI_STATUS (AE_OK);
    358          1.1  christos     }
    359          1.1  christos 
    360          1.1  christos     /*
    361          1.1  christos      * The following code is a bit of a hack to workaround a (current)
    362          1.1  christos      * limitation of the ACPI_PKG_CALLBACK interface. We need a pointer
    363          1.1  christos      * to the location within the element array because a new object
    364          1.1  christos      * may be created and stored there.
    365          1.1  christos      */
    366          1.1  christos     if (Context)
    367          1.1  christos     {
    368          1.1  christos         /* A direct call was made to this function */
    369          1.1  christos 
    370          1.1  christos         ElementPtr = (ACPI_OPERAND_OBJECT **) Context;
    371          1.1  christos     }
    372          1.1  christos     else
    373          1.1  christos     {
    374          1.1  christos         /* Call came from AcpiUtWalkPackageTree */
    375          1.1  christos 
    376          1.1  christos         ElementPtr = State->Pkg.ThisTargetObj;
    377          1.1  christos     }
    378          1.1  christos 
    379          1.1  christos     /* We are only interested in reference objects/elements */
    380          1.1  christos 
    381          1.1  christos     if (SourceObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
    382          1.1  christos     {
    383          1.1  christos         /* Attempt to resolve the (named) reference to a namespace node */
    384          1.1  christos 
    385          1.1  christos         AcpiDsResolvePackageElement (ElementPtr);
    386          1.1  christos     }
    387          1.1  christos     else if (SourceObject->Common.Type == ACPI_TYPE_PACKAGE)
    388          1.1  christos     {
    389          1.1  christos         SourceObject->Package.Flags |= AOPOBJ_DATA_VALID;
    390          1.1  christos     }
    391          1.1  christos 
    392  1.1.1.1.4.1  pgoyette     return_ACPI_STATUS (AE_OK);
    393          1.1  christos }
    394          1.1  christos 
    395          1.1  christos 
    396          1.1  christos /*******************************************************************************
    397          1.1  christos  *
    398          1.1  christos  * FUNCTION:    AcpiDsResolvePackageElement
    399          1.1  christos  *
    400          1.1  christos  * PARAMETERS:  ElementPtr          - Pointer to a reference object
    401          1.1  christos  *
    402          1.1  christos  * RETURN:      Possible new element is stored to the indirect ElementPtr
    403          1.1  christos  *
    404          1.1  christos  * DESCRIPTION: Resolve a package element that is a reference to a named
    405          1.1  christos  *              object.
    406          1.1  christos  *
    407          1.1  christos  ******************************************************************************/
    408          1.1  christos 
    409          1.1  christos static void
    410          1.1  christos AcpiDsResolvePackageElement (
    411          1.1  christos     ACPI_OPERAND_OBJECT     **ElementPtr)
    412          1.1  christos {
    413          1.1  christos     ACPI_STATUS             Status;
    414  1.1.1.1.4.1  pgoyette     ACPI_STATUS             Status2;
    415          1.1  christos     ACPI_GENERIC_STATE      ScopeInfo;
    416          1.1  christos     ACPI_OPERAND_OBJECT     *Element = *ElementPtr;
    417          1.1  christos     ACPI_NAMESPACE_NODE     *ResolvedNode;
    418  1.1.1.1.4.1  pgoyette     ACPI_NAMESPACE_NODE     *OriginalNode;
    419  1.1.1.1.4.1  pgoyette     char                    *ExternalPath = __UNCONST("");
    420          1.1  christos     ACPI_OBJECT_TYPE        Type;
    421          1.1  christos 
    422          1.1  christos 
    423          1.1  christos     ACPI_FUNCTION_TRACE (DsResolvePackageElement);
    424          1.1  christos 
    425          1.1  christos 
    426          1.1  christos     /* Check if reference element is already resolved */
    427          1.1  christos 
    428          1.1  christos     if (Element->Reference.Resolved)
    429          1.1  christos     {
    430  1.1.1.1.4.1  pgoyette         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
    431  1.1.1.1.4.1  pgoyette             "%s: Package element is already resolved\n",
    432  1.1.1.1.4.1  pgoyette             ACPI_GET_FUNCTION_NAME));
    433  1.1.1.1.4.1  pgoyette 
    434          1.1  christos         return_VOID;
    435          1.1  christos     }
    436          1.1  christos 
    437          1.1  christos     /* Element must be a reference object of correct type */
    438          1.1  christos 
    439          1.1  christos     ScopeInfo.Scope.Node = Element->Reference.Node; /* Prefix node */
    440          1.1  christos 
    441  1.1.1.1.4.1  pgoyette     Status = AcpiNsLookup (&ScopeInfo, (char *) Element->Reference.Aml,
    442          1.1  christos         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
    443          1.1  christos         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
    444          1.1  christos         NULL, &ResolvedNode);
    445          1.1  christos     if (ACPI_FAILURE (Status))
    446          1.1  christos     {
    447  1.1.1.1.4.1  pgoyette         if ((Status == AE_NOT_FOUND) && AcpiGbl_IgnorePackageResolutionErrors)
    448  1.1.1.1.4.1  pgoyette         {
    449  1.1.1.1.4.1  pgoyette             /*
    450  1.1.1.1.4.1  pgoyette              * Optionally be silent about the NOT_FOUND case for the referenced
    451  1.1.1.1.4.1  pgoyette              * name. Although this is potentially a serious problem,
    452  1.1.1.1.4.1  pgoyette              * it can generate a lot of noise/errors on platforms whose
    453  1.1.1.1.4.1  pgoyette              * firmware carries around a bunch of unused Package objects.
    454  1.1.1.1.4.1  pgoyette              * To disable these errors, set this global to TRUE:
    455  1.1.1.1.4.1  pgoyette              *     AcpiGbl_IgnorePackageResolutionErrors
    456  1.1.1.1.4.1  pgoyette              *
    457  1.1.1.1.4.1  pgoyette              * If the AML actually tries to use such a package, the unresolved
    458  1.1.1.1.4.1  pgoyette              * element(s) will be replaced with NULL elements.
    459  1.1.1.1.4.1  pgoyette              */
    460  1.1.1.1.4.1  pgoyette 
    461  1.1.1.1.4.1  pgoyette             /* Referenced name not found, set the element to NULL */
    462  1.1.1.1.4.1  pgoyette 
    463  1.1.1.1.4.1  pgoyette             AcpiUtRemoveReference (*ElementPtr);
    464  1.1.1.1.4.1  pgoyette             *ElementPtr = NULL;
    465  1.1.1.1.4.1  pgoyette             return_VOID;
    466  1.1.1.1.4.1  pgoyette         }
    467  1.1.1.1.4.1  pgoyette 
    468  1.1.1.1.4.1  pgoyette         Status2 = AcpiNsExternalizeName (ACPI_UINT32_MAX,
    469  1.1.1.1.4.1  pgoyette             (char *) Element->Reference.Aml, NULL, &ExternalPath);
    470          1.1  christos 
    471          1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status,
    472  1.1.1.1.4.1  pgoyette             "While resolving a named reference package element - %s",
    473  1.1.1.1.4.1  pgoyette             ExternalPath));
    474  1.1.1.1.4.1  pgoyette         if (ACPI_SUCCESS (Status2))
    475  1.1.1.1.4.1  pgoyette         {
    476  1.1.1.1.4.1  pgoyette             ACPI_FREE (ExternalPath);
    477  1.1.1.1.4.1  pgoyette         }
    478  1.1.1.1.4.1  pgoyette 
    479  1.1.1.1.4.1  pgoyette         /* Could not resolve name, set the element to NULL */
    480          1.1  christos 
    481  1.1.1.1.4.1  pgoyette         AcpiUtRemoveReference (*ElementPtr);
    482          1.1  christos         *ElementPtr = NULL;
    483          1.1  christos         return_VOID;
    484          1.1  christos     }
    485          1.1  christos     else if (ResolvedNode->Type == ACPI_TYPE_ANY)
    486          1.1  christos     {
    487          1.1  christos         /* Named reference not resolved, return a NULL package element */
    488          1.1  christos 
    489          1.1  christos         ACPI_ERROR ((AE_INFO,
    490          1.1  christos             "Could not resolve named package element [%4.4s] in [%4.4s]",
    491          1.1  christos             ResolvedNode->Name.Ascii, ScopeInfo.Scope.Node->Name.Ascii));
    492          1.1  christos         *ElementPtr = NULL;
    493          1.1  christos         return_VOID;
    494          1.1  christos     }
    495          1.1  christos 
    496          1.1  christos     /*
    497          1.1  christos      * Special handling for Alias objects. We need ResolvedNode to point
    498          1.1  christos      * to the Alias target. This effectively "resolves" the alias.
    499          1.1  christos      */
    500          1.1  christos     if (ResolvedNode->Type == ACPI_TYPE_LOCAL_ALIAS)
    501          1.1  christos     {
    502          1.1  christos         ResolvedNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
    503          1.1  christos             ResolvedNode->Object);
    504          1.1  christos     }
    505          1.1  christos 
    506          1.1  christos     /* Update the reference object */
    507          1.1  christos 
    508          1.1  christos     Element->Reference.Resolved = TRUE;
    509          1.1  christos     Element->Reference.Node = ResolvedNode;
    510          1.1  christos     Type = Element->Reference.Node->Type;
    511          1.1  christos 
    512          1.1  christos     /*
    513          1.1  christos      * Attempt to resolve the node to a value before we insert it into
    514          1.1  christos      * the package. If this is a reference to a common data type,
    515          1.1  christos      * resolve it immediately. According to the ACPI spec, package
    516          1.1  christos      * elements can only be "data objects" or method references.
    517          1.1  christos      * Attempt to resolve to an Integer, Buffer, String or Package.
    518          1.1  christos      * If cannot, return the named reference (for things like Devices,
    519          1.1  christos      * Methods, etc.) Buffer Fields and Fields will resolve to simple
    520          1.1  christos      * objects (int/buf/str/pkg).
    521          1.1  christos      *
    522          1.1  christos      * NOTE: References to things like Devices, Methods, Mutexes, etc.
    523          1.1  christos      * will remain as named references. This behavior is not described
    524          1.1  christos      * in the ACPI spec, but it appears to be an oversight.
    525          1.1  christos      */
    526  1.1.1.1.4.1  pgoyette     OriginalNode = ResolvedNode;
    527          1.1  christos     Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
    528          1.1  christos     if (ACPI_FAILURE (Status))
    529          1.1  christos     {
    530          1.1  christos         return_VOID;
    531          1.1  christos     }
    532          1.1  christos 
    533          1.1  christos     switch (Type)
    534          1.1  christos     {
    535          1.1  christos     /*
    536          1.1  christos      * These object types are a result of named references, so we will
    537          1.1  christos      * leave them as reference objects. In other words, these types
    538          1.1  christos      * have no intrinsic "value".
    539          1.1  christos      */
    540          1.1  christos     case ACPI_TYPE_DEVICE:
    541          1.1  christos     case ACPI_TYPE_THERMAL:
    542  1.1.1.1.4.1  pgoyette     case ACPI_TYPE_METHOD:
    543          1.1  christos         break;
    544          1.1  christos 
    545          1.1  christos     case ACPI_TYPE_MUTEX:
    546          1.1  christos     case ACPI_TYPE_POWER:
    547          1.1  christos     case ACPI_TYPE_PROCESSOR:
    548          1.1  christos     case ACPI_TYPE_EVENT:
    549          1.1  christos     case ACPI_TYPE_REGION:
    550          1.1  christos 
    551  1.1.1.1.4.1  pgoyette         /* AcpiExResolveNodeToValue gave these an extra reference */
    552  1.1.1.1.4.1  pgoyette 
    553  1.1.1.1.4.1  pgoyette         AcpiUtRemoveReference (OriginalNode->Object);
    554          1.1  christos         break;
    555          1.1  christos 
    556          1.1  christos     default:
    557          1.1  christos         /*
    558          1.1  christos          * For all other types - the node was resolved to an actual
    559  1.1.1.1.4.1  pgoyette          * operand object with a value, return the object. Remove
    560  1.1.1.1.4.1  pgoyette          * a reference on the existing object.
    561          1.1  christos          */
    562  1.1.1.1.4.1  pgoyette         AcpiUtRemoveReference (Element);
    563          1.1  christos         *ElementPtr = (ACPI_OPERAND_OBJECT *) ResolvedNode;
    564          1.1  christos         break;
    565          1.1  christos     }
    566          1.1  christos 
    567          1.1  christos     return_VOID;
    568          1.1  christos }
    569