xref: /freebsd-src/sys/contrib/dev/acpica/components/dispatcher/dspkginit.c (revision f1db5ef7aae243376018ad851813ca3b3ae73945)
15f9b24faSJung-uk Kim /******************************************************************************
25f9b24faSJung-uk Kim  *
35f9b24faSJung-uk Kim  * Module Name: dspkginit - Completion of deferred package initialization
45f9b24faSJung-uk Kim  *
55f9b24faSJung-uk Kim  *****************************************************************************/
65f9b24faSJung-uk Kim 
75f9b24faSJung-uk Kim /******************************************************************************
85f9b24faSJung-uk Kim  *
95f9b24faSJung-uk Kim  * 1. Copyright Notice
105f9b24faSJung-uk Kim  *
115f9b24faSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
125f9b24faSJung-uk Kim  * All rights reserved.
135f9b24faSJung-uk Kim  *
145f9b24faSJung-uk Kim  * 2. License
155f9b24faSJung-uk Kim  *
165f9b24faSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
175f9b24faSJung-uk Kim  * rights. You may have additional license terms from the party that provided
185f9b24faSJung-uk Kim  * you this software, covering your right to use that party's intellectual
195f9b24faSJung-uk Kim  * property rights.
205f9b24faSJung-uk Kim  *
215f9b24faSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
225f9b24faSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
235f9b24faSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
245f9b24faSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
255f9b24faSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
265f9b24faSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
275f9b24faSJung-uk Kim  *
285f9b24faSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
295f9b24faSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
305f9b24faSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
315f9b24faSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
325f9b24faSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
335f9b24faSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
345f9b24faSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
355f9b24faSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
365f9b24faSJung-uk Kim  *
375f9b24faSJung-uk Kim  * The above copyright and patent license is granted only if the following
385f9b24faSJung-uk Kim  * conditions are met:
395f9b24faSJung-uk Kim  *
405f9b24faSJung-uk Kim  * 3. Conditions
415f9b24faSJung-uk Kim  *
425f9b24faSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
435f9b24faSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
445f9b24faSJung-uk Kim  * Code or modification with rights to further distribute source must include
455f9b24faSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
465f9b24faSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
475f9b24faSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
485f9b24faSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
495f9b24faSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
505f9b24faSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
515f9b24faSJung-uk Kim  * must include a prominent statement that the modification is derived,
525f9b24faSJung-uk Kim  * directly or indirectly, from Original Intel Code.
535f9b24faSJung-uk Kim  *
545f9b24faSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
555f9b24faSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
565f9b24faSJung-uk Kim  * Code or modification without rights to further distribute source must
575f9b24faSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
585f9b24faSJung-uk Kim  * documentation and/or other materials provided with distribution. In
595f9b24faSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
605f9b24faSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
615f9b24faSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
625f9b24faSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
635f9b24faSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
645f9b24faSJung-uk Kim  * make.
655f9b24faSJung-uk Kim  *
665f9b24faSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
675f9b24faSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
685f9b24faSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
695f9b24faSJung-uk Kim  * provision in the documentation and/or other materials provided with the
705f9b24faSJung-uk Kim  * distribution.
715f9b24faSJung-uk Kim  *
725f9b24faSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
735f9b24faSJung-uk Kim  * Intel Code.
745f9b24faSJung-uk Kim  *
755f9b24faSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
765f9b24faSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
775f9b24faSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
785f9b24faSJung-uk Kim  * without prior written authorization from Intel.
795f9b24faSJung-uk Kim  *
805f9b24faSJung-uk Kim  * 4. Disclaimer and Export Compliance
815f9b24faSJung-uk Kim  *
825f9b24faSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
835f9b24faSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
845f9b24faSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
855f9b24faSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
865f9b24faSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
875f9b24faSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
885f9b24faSJung-uk Kim  * PARTICULAR PURPOSE.
895f9b24faSJung-uk Kim  *
905f9b24faSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
915f9b24faSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
925f9b24faSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
935f9b24faSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
945f9b24faSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
955f9b24faSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
965f9b24faSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
975f9b24faSJung-uk Kim  * LIMITED REMEDY.
985f9b24faSJung-uk Kim  *
995f9b24faSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1005f9b24faSJung-uk Kim  * software or system incorporating such software without first obtaining any
1015f9b24faSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1025f9b24faSJung-uk Kim  * any other agency or department of the United States Government. In the
1035f9b24faSJung-uk Kim  * event Licensee exports any such software from the United States or
1045f9b24faSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1055f9b24faSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1065f9b24faSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1075f9b24faSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1085f9b24faSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1095f9b24faSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1105f9b24faSJung-uk Kim  * United States government or any agency thereof requires an export license,
1115f9b24faSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1125f9b24faSJung-uk Kim  * such license, approval or letter.
1135f9b24faSJung-uk Kim  *
1145f9b24faSJung-uk Kim  *****************************************************************************
1155f9b24faSJung-uk Kim  *
1165f9b24faSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1175f9b24faSJung-uk Kim  * following license:
1185f9b24faSJung-uk Kim  *
1195f9b24faSJung-uk Kim  * Redistribution and use in source and binary forms, with or without
1205f9b24faSJung-uk Kim  * modification, are permitted provided that the following conditions
1215f9b24faSJung-uk Kim  * are met:
1225f9b24faSJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
1235f9b24faSJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
1245f9b24faSJung-uk Kim  *    without modification.
1255f9b24faSJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1265f9b24faSJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
1275f9b24faSJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
1285f9b24faSJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
1295f9b24faSJung-uk Kim  *    binary redistribution.
1305f9b24faSJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
1315f9b24faSJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
1325f9b24faSJung-uk Kim  *    from this software without specific prior written permission.
1335f9b24faSJung-uk Kim  *
1345f9b24faSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1355f9b24faSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1365f9b24faSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1375f9b24faSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1385f9b24faSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1395f9b24faSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1405f9b24faSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1415f9b24faSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1425f9b24faSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1435f9b24faSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1445f9b24faSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1455f9b24faSJung-uk Kim  *
1465f9b24faSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1475f9b24faSJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
1485f9b24faSJung-uk Kim  * Software Foundation.
1495f9b24faSJung-uk Kim  *
1505f9b24faSJung-uk Kim  *****************************************************************************/
1515f9b24faSJung-uk Kim 
1525f9b24faSJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
1535f9b24faSJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
1545f9b24faSJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
1555f9b24faSJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
1565f9b24faSJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
1575f9b24faSJung-uk Kim #include <contrib/dev/acpica/include/acinterp.h>
1585f9b24faSJung-uk Kim 
1595f9b24faSJung-uk Kim 
1605f9b24faSJung-uk Kim #define _COMPONENT          ACPI_NAMESPACE
1615f9b24faSJung-uk Kim         ACPI_MODULE_NAME    ("dspkginit")
1625f9b24faSJung-uk Kim 
1635f9b24faSJung-uk Kim 
1645f9b24faSJung-uk Kim /* Local prototypes */
1655f9b24faSJung-uk Kim 
1665f9b24faSJung-uk Kim static void
1675f9b24faSJung-uk Kim AcpiDsResolvePackageElement (
1685f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     **Element);
1695f9b24faSJung-uk Kim 
1705f9b24faSJung-uk Kim 
1715f9b24faSJung-uk Kim /*******************************************************************************
1725f9b24faSJung-uk Kim  *
1735f9b24faSJung-uk Kim  * FUNCTION:    AcpiDsBuildInternalPackageObj
1745f9b24faSJung-uk Kim  *
1755f9b24faSJung-uk Kim  * PARAMETERS:  WalkState       - Current walk state
1765f9b24faSJung-uk Kim  *              Op              - Parser object to be translated
1775f9b24faSJung-uk Kim  *              ElementCount    - Number of elements in the package - this is
1785f9b24faSJung-uk Kim  *                                the NumElements argument to Package()
1795f9b24faSJung-uk Kim  *              ObjDescPtr      - Where the ACPI internal object is returned
1805f9b24faSJung-uk Kim  *
1815f9b24faSJung-uk Kim  * RETURN:      Status
1825f9b24faSJung-uk Kim  *
1835f9b24faSJung-uk Kim  * DESCRIPTION: Translate a parser Op package object to the equivalent
1845f9b24faSJung-uk Kim  *              namespace object
1855f9b24faSJung-uk Kim  *
1865f9b24faSJung-uk Kim  * NOTE: The number of elements in the package will be always be the NumElements
1875f9b24faSJung-uk Kim  * count, regardless of the number of elements in the package list. If
1885f9b24faSJung-uk Kim  * NumElements is smaller, only that many package list elements are used.
1895f9b24faSJung-uk Kim  * if NumElements is larger, the Package object is padded out with
1905f9b24faSJung-uk Kim  * objects of type Uninitialized (as per ACPI spec.)
1915f9b24faSJung-uk Kim  *
1925f9b24faSJung-uk Kim  * Even though the ASL compilers do not allow NumElements to be smaller
1935f9b24faSJung-uk Kim  * than the Package list length (for the fixed length package opcode), some
1945f9b24faSJung-uk Kim  * BIOS code modifies the AML on the fly to adjust the NumElements, and
1955f9b24faSJung-uk Kim  * this code compensates for that. This also provides compatibility with
1965f9b24faSJung-uk Kim  * other AML interpreters.
1975f9b24faSJung-uk Kim  *
1985f9b24faSJung-uk Kim  ******************************************************************************/
1995f9b24faSJung-uk Kim 
2005f9b24faSJung-uk Kim ACPI_STATUS
2015f9b24faSJung-uk Kim AcpiDsBuildInternalPackageObj (
2025f9b24faSJung-uk Kim     ACPI_WALK_STATE         *WalkState,
2035f9b24faSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
2045f9b24faSJung-uk Kim     UINT32                  ElementCount,
2055f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     **ObjDescPtr)
2065f9b24faSJung-uk Kim {
2075f9b24faSJung-uk Kim     ACPI_PARSE_OBJECT       *Arg;
2085f9b24faSJung-uk Kim     ACPI_PARSE_OBJECT       *Parent;
2095f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
2105f9b24faSJung-uk Kim     ACPI_STATUS             Status = AE_OK;
2115f9b24faSJung-uk Kim     UINT16                  ReferenceCount;
2125f9b24faSJung-uk Kim     UINT32                  Index;
2135f9b24faSJung-uk Kim     UINT32                  i;
2145f9b24faSJung-uk Kim 
2155f9b24faSJung-uk Kim 
2165f9b24faSJung-uk Kim     ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
2175f9b24faSJung-uk Kim 
2185f9b24faSJung-uk Kim 
2195f9b24faSJung-uk Kim     /* Find the parent of a possibly nested package */
2205f9b24faSJung-uk Kim 
2215f9b24faSJung-uk Kim     Parent = Op->Common.Parent;
2225f9b24faSJung-uk Kim     while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
2235f9b24faSJung-uk Kim            (Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
2245f9b24faSJung-uk Kim     {
2255f9b24faSJung-uk Kim         Parent = Parent->Common.Parent;
2265f9b24faSJung-uk Kim     }
2275f9b24faSJung-uk Kim 
2285f9b24faSJung-uk Kim     /*
2295f9b24faSJung-uk Kim      * If we are evaluating a Named package object of the form:
2305f9b24faSJung-uk Kim      *      Name (xxxx, Package)
2315f9b24faSJung-uk Kim      * the package object already exists, otherwise it must be created.
2325f9b24faSJung-uk Kim      */
2335f9b24faSJung-uk Kim     ObjDesc = *ObjDescPtr;
2345f9b24faSJung-uk Kim     if (!ObjDesc)
2355f9b24faSJung-uk Kim     {
2365f9b24faSJung-uk Kim         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
2375f9b24faSJung-uk Kim         *ObjDescPtr = ObjDesc;
2385f9b24faSJung-uk Kim         if (!ObjDesc)
2395f9b24faSJung-uk Kim         {
2405f9b24faSJung-uk Kim             return_ACPI_STATUS (AE_NO_MEMORY);
2415f9b24faSJung-uk Kim         }
2425f9b24faSJung-uk Kim 
2435f9b24faSJung-uk Kim         ObjDesc->Package.Node = Parent->Common.Node;
2445f9b24faSJung-uk Kim     }
2455f9b24faSJung-uk Kim 
2465f9b24faSJung-uk Kim     if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID) /* Just in case */
2475f9b24faSJung-uk Kim     {
2485f9b24faSJung-uk Kim         return_ACPI_STATUS (AE_OK);
2495f9b24faSJung-uk Kim     }
2505f9b24faSJung-uk Kim 
2515f9b24faSJung-uk Kim     /*
2525f9b24faSJung-uk Kim      * Allocate the element array (array of pointers to the individual
2535f9b24faSJung-uk Kim      * objects) based on the NumElements parameter. Add an extra pointer slot
2545f9b24faSJung-uk Kim      * so that the list is always null terminated.
2555f9b24faSJung-uk Kim      */
2565f9b24faSJung-uk Kim     ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
2575f9b24faSJung-uk Kim         ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
2585f9b24faSJung-uk Kim 
2595f9b24faSJung-uk Kim     if (!ObjDesc->Package.Elements)
2605f9b24faSJung-uk Kim     {
2615f9b24faSJung-uk Kim         AcpiUtDeleteObjectDesc (ObjDesc);
2625f9b24faSJung-uk Kim         return_ACPI_STATUS (AE_NO_MEMORY);
2635f9b24faSJung-uk Kim     }
2645f9b24faSJung-uk Kim 
2655f9b24faSJung-uk Kim     ObjDesc->Package.Count = ElementCount;
2665f9b24faSJung-uk Kim     Arg = Op->Common.Value.Arg;
2675f9b24faSJung-uk Kim     Arg = Arg->Common.Next;
2685f9b24faSJung-uk Kim 
2695f9b24faSJung-uk Kim     if (Arg)
2705f9b24faSJung-uk Kim     {
2715f9b24faSJung-uk Kim         ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
2725f9b24faSJung-uk Kim     }
2735f9b24faSJung-uk Kim 
2745f9b24faSJung-uk Kim     /*
2755f9b24faSJung-uk Kim      * Initialize the elements of the package, up to the NumElements count.
2765f9b24faSJung-uk Kim      * Package is automatically padded with uninitialized (NULL) elements
2775f9b24faSJung-uk Kim      * if NumElements is greater than the package list length. Likewise,
2785f9b24faSJung-uk Kim      * Package is truncated if NumElements is less than the list length.
2795f9b24faSJung-uk Kim      */
2805f9b24faSJung-uk Kim     for (i = 0; Arg && (i < ElementCount); i++)
2815f9b24faSJung-uk Kim     {
2825f9b24faSJung-uk Kim         if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
2835f9b24faSJung-uk Kim         {
2845f9b24faSJung-uk Kim             if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
2855f9b24faSJung-uk Kim             {
2865f9b24faSJung-uk Kim                 /*
2875f9b24faSJung-uk Kim                  * A method reference "looks" to the parser to be a method
2885f9b24faSJung-uk Kim                  * invocation, so we special case it here
2895f9b24faSJung-uk Kim                  */
2905f9b24faSJung-uk Kim                 Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
2915f9b24faSJung-uk Kim                 Status = AcpiDsBuildInternalObject (
2925f9b24faSJung-uk Kim                     WalkState, Arg, &ObjDesc->Package.Elements[i]);
2935f9b24faSJung-uk Kim             }
2945f9b24faSJung-uk Kim             else
2955f9b24faSJung-uk Kim             {
2965f9b24faSJung-uk Kim                 /* This package element is already built, just get it */
2975f9b24faSJung-uk Kim 
2985f9b24faSJung-uk Kim                 ObjDesc->Package.Elements[i] =
2995f9b24faSJung-uk Kim                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
3005f9b24faSJung-uk Kim             }
3015f9b24faSJung-uk Kim         }
3025f9b24faSJung-uk Kim         else
3035f9b24faSJung-uk Kim         {
3045f9b24faSJung-uk Kim             Status = AcpiDsBuildInternalObject (
3055f9b24faSJung-uk Kim                 WalkState, Arg, &ObjDesc->Package.Elements[i]);
3065f9b24faSJung-uk Kim             if (Status == AE_NOT_FOUND)
3075f9b24faSJung-uk Kim             {
3085f9b24faSJung-uk Kim                 ACPI_ERROR ((AE_INFO, "%-48s", "****DS namepath not found"));
3095f9b24faSJung-uk Kim             }
3105f9b24faSJung-uk Kim 
3115f9b24faSJung-uk Kim             /*
3125f9b24faSJung-uk Kim              * Initialize this package element. This function handles the
3135f9b24faSJung-uk Kim              * resolution of named references within the package.
3145f9b24faSJung-uk Kim              */
3155f9b24faSJung-uk Kim             AcpiDsInitPackageElement (0, ObjDesc->Package.Elements[i],
3165f9b24faSJung-uk Kim                 NULL, &ObjDesc->Package.Elements[i]);
3175f9b24faSJung-uk Kim         }
3185f9b24faSJung-uk Kim 
3195f9b24faSJung-uk Kim         if (*ObjDescPtr)
3205f9b24faSJung-uk Kim         {
3215f9b24faSJung-uk Kim             /* Existing package, get existing reference count */
3225f9b24faSJung-uk Kim 
3235f9b24faSJung-uk Kim             ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
3245f9b24faSJung-uk Kim             if (ReferenceCount > 1)
3255f9b24faSJung-uk Kim             {
3265f9b24faSJung-uk Kim                 /* Make new element ref count match original ref count */
3275f9b24faSJung-uk Kim                 /* TBD: Probably need an AcpiUtAddReferences function */
3285f9b24faSJung-uk Kim 
3295f9b24faSJung-uk Kim                 for (Index = 0; Index < ((UINT32) ReferenceCount - 1); Index++)
3305f9b24faSJung-uk Kim                 {
3315f9b24faSJung-uk Kim                     AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
3325f9b24faSJung-uk Kim                 }
3335f9b24faSJung-uk Kim             }
3345f9b24faSJung-uk Kim         }
3355f9b24faSJung-uk Kim 
3365f9b24faSJung-uk Kim         Arg = Arg->Common.Next;
3375f9b24faSJung-uk Kim     }
3385f9b24faSJung-uk Kim 
3395f9b24faSJung-uk Kim     /* Check for match between NumElements and actual length of PackageList */
3405f9b24faSJung-uk Kim 
3415f9b24faSJung-uk Kim     if (Arg)
3425f9b24faSJung-uk Kim     {
3435f9b24faSJung-uk Kim         /*
3445f9b24faSJung-uk Kim          * NumElements was exhausted, but there are remaining elements in
3455f9b24faSJung-uk Kim          * the PackageList. Truncate the package to NumElements.
3465f9b24faSJung-uk Kim          *
3475f9b24faSJung-uk Kim          * Note: technically, this is an error, from ACPI spec: "It is an
3485f9b24faSJung-uk Kim          * error for NumElements to be less than the number of elements in
3495f9b24faSJung-uk Kim          * the PackageList". However, we just print a message and no
3505f9b24faSJung-uk Kim          * exception is returned. This provides compatibility with other
3515f9b24faSJung-uk Kim          * ACPI implementations. Some firmware implementations will alter
3525f9b24faSJung-uk Kim          * the NumElements on the fly, possibly creating this type of
3535f9b24faSJung-uk Kim          * ill-formed package object.
3545f9b24faSJung-uk Kim          */
3555f9b24faSJung-uk Kim         while (Arg)
3565f9b24faSJung-uk Kim         {
3575f9b24faSJung-uk Kim             /*
3585f9b24faSJung-uk Kim              * We must delete any package elements that were created earlier
3595f9b24faSJung-uk Kim              * and are not going to be used because of the package truncation.
3605f9b24faSJung-uk Kim              */
3615f9b24faSJung-uk Kim             if (Arg->Common.Node)
3625f9b24faSJung-uk Kim             {
3635f9b24faSJung-uk Kim                 AcpiUtRemoveReference (
3645f9b24faSJung-uk Kim                     ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
3655f9b24faSJung-uk Kim                 Arg->Common.Node = NULL;
3665f9b24faSJung-uk Kim             }
3675f9b24faSJung-uk Kim 
3685f9b24faSJung-uk Kim             /* Find out how many elements there really are */
3695f9b24faSJung-uk Kim 
3705f9b24faSJung-uk Kim             i++;
3715f9b24faSJung-uk Kim             Arg = Arg->Common.Next;
3725f9b24faSJung-uk Kim         }
3735f9b24faSJung-uk Kim 
3745f9b24faSJung-uk Kim         ACPI_INFO ((
3755f9b24faSJung-uk Kim             "Actual Package length (%u) is larger than "
3765f9b24faSJung-uk Kim             "NumElements field (%u), truncated",
3775f9b24faSJung-uk Kim             i, ElementCount));
3785f9b24faSJung-uk Kim     }
3795f9b24faSJung-uk Kim     else if (i < ElementCount)
3805f9b24faSJung-uk Kim     {
3815f9b24faSJung-uk Kim         /*
3825f9b24faSJung-uk Kim          * Arg list (elements) was exhausted, but we did not reach
3835f9b24faSJung-uk Kim          * NumElements count.
3845f9b24faSJung-uk Kim          *
3855f9b24faSJung-uk Kim          * Note: this is not an error, the package is padded out
3865f9b24faSJung-uk Kim          * with NULLs.
3875f9b24faSJung-uk Kim          */
3885f9b24faSJung-uk Kim         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
3895f9b24faSJung-uk Kim             "Package List length (%u) smaller than NumElements "
3905f9b24faSJung-uk Kim             "count (%u), padded with null elements\n",
3915f9b24faSJung-uk Kim             i, ElementCount));
3925f9b24faSJung-uk Kim     }
3935f9b24faSJung-uk Kim 
3945f9b24faSJung-uk Kim     ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
3955f9b24faSJung-uk Kim     Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
3965f9b24faSJung-uk Kim     return_ACPI_STATUS (Status);
3975f9b24faSJung-uk Kim }
3985f9b24faSJung-uk Kim 
3995f9b24faSJung-uk Kim 
4005f9b24faSJung-uk Kim /*******************************************************************************
4015f9b24faSJung-uk Kim  *
4025f9b24faSJung-uk Kim  * FUNCTION:    AcpiDsInitPackageElement
4035f9b24faSJung-uk Kim  *
4045f9b24faSJung-uk Kim  * PARAMETERS:  ACPI_PKG_CALLBACK
4055f9b24faSJung-uk Kim  *
4065f9b24faSJung-uk Kim  * RETURN:      Status
4075f9b24faSJung-uk Kim  *
4085f9b24faSJung-uk Kim  * DESCRIPTION: Resolve a named reference element within a package object
4095f9b24faSJung-uk Kim  *
4105f9b24faSJung-uk Kim  ******************************************************************************/
4115f9b24faSJung-uk Kim 
4125f9b24faSJung-uk Kim ACPI_STATUS
4135f9b24faSJung-uk Kim AcpiDsInitPackageElement (
4145f9b24faSJung-uk Kim     UINT8                   ObjectType,
4155f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     *SourceObject,
4165f9b24faSJung-uk Kim     ACPI_GENERIC_STATE      *State,
4175f9b24faSJung-uk Kim     void                    *Context)
4185f9b24faSJung-uk Kim {
4195f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     **ElementPtr;
4205f9b24faSJung-uk Kim 
4215f9b24faSJung-uk Kim 
422*f1db5ef7SJung-uk Kim     ACPI_FUNCTION_TRACE (DsInitPackageElement);
423*f1db5ef7SJung-uk Kim 
424*f1db5ef7SJung-uk Kim 
4255f9b24faSJung-uk Kim     if (!SourceObject)
4265f9b24faSJung-uk Kim     {
427*f1db5ef7SJung-uk Kim         return_ACPI_STATUS (AE_OK);
4285f9b24faSJung-uk Kim     }
4295f9b24faSJung-uk Kim 
4305f9b24faSJung-uk Kim     /*
4315f9b24faSJung-uk Kim      * The following code is a bit of a hack to workaround a (current)
4325f9b24faSJung-uk Kim      * limitation of the ACPI_PKG_CALLBACK interface. We need a pointer
4335f9b24faSJung-uk Kim      * to the location within the element array because a new object
4345f9b24faSJung-uk Kim      * may be created and stored there.
4355f9b24faSJung-uk Kim      */
4365f9b24faSJung-uk Kim     if (Context)
4375f9b24faSJung-uk Kim     {
4385f9b24faSJung-uk Kim         /* A direct call was made to this function */
4395f9b24faSJung-uk Kim 
4405f9b24faSJung-uk Kim         ElementPtr = (ACPI_OPERAND_OBJECT **) Context;
4415f9b24faSJung-uk Kim     }
4425f9b24faSJung-uk Kim     else
4435f9b24faSJung-uk Kim     {
4445f9b24faSJung-uk Kim         /* Call came from AcpiUtWalkPackageTree */
4455f9b24faSJung-uk Kim 
4465f9b24faSJung-uk Kim         ElementPtr = State->Pkg.ThisTargetObj;
4475f9b24faSJung-uk Kim     }
4485f9b24faSJung-uk Kim 
4495f9b24faSJung-uk Kim     /* We are only interested in reference objects/elements */
4505f9b24faSJung-uk Kim 
4515f9b24faSJung-uk Kim     if (SourceObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
4525f9b24faSJung-uk Kim     {
4535f9b24faSJung-uk Kim         /* Attempt to resolve the (named) reference to a namespace node */
4545f9b24faSJung-uk Kim 
4555f9b24faSJung-uk Kim         AcpiDsResolvePackageElement (ElementPtr);
4565f9b24faSJung-uk Kim     }
4575f9b24faSJung-uk Kim     else if (SourceObject->Common.Type == ACPI_TYPE_PACKAGE)
4585f9b24faSJung-uk Kim     {
4595f9b24faSJung-uk Kim         SourceObject->Package.Flags |= AOPOBJ_DATA_VALID;
4605f9b24faSJung-uk Kim     }
4615f9b24faSJung-uk Kim 
462*f1db5ef7SJung-uk Kim     return_ACPI_STATUS (AE_OK);
4635f9b24faSJung-uk Kim }
4645f9b24faSJung-uk Kim 
4655f9b24faSJung-uk Kim 
4665f9b24faSJung-uk Kim /*******************************************************************************
4675f9b24faSJung-uk Kim  *
4685f9b24faSJung-uk Kim  * FUNCTION:    AcpiDsResolvePackageElement
4695f9b24faSJung-uk Kim  *
4705f9b24faSJung-uk Kim  * PARAMETERS:  ElementPtr          - Pointer to a reference object
4715f9b24faSJung-uk Kim  *
4725f9b24faSJung-uk Kim  * RETURN:      Possible new element is stored to the indirect ElementPtr
4735f9b24faSJung-uk Kim  *
4745f9b24faSJung-uk Kim  * DESCRIPTION: Resolve a package element that is a reference to a named
4755f9b24faSJung-uk Kim  *              object.
4765f9b24faSJung-uk Kim  *
4775f9b24faSJung-uk Kim  ******************************************************************************/
4785f9b24faSJung-uk Kim 
4795f9b24faSJung-uk Kim static void
4805f9b24faSJung-uk Kim AcpiDsResolvePackageElement (
4815f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     **ElementPtr)
4825f9b24faSJung-uk Kim {
4835f9b24faSJung-uk Kim     ACPI_STATUS             Status;
4845f9b24faSJung-uk Kim     ACPI_GENERIC_STATE      ScopeInfo;
4855f9b24faSJung-uk Kim     ACPI_OPERAND_OBJECT     *Element = *ElementPtr;
4865f9b24faSJung-uk Kim     ACPI_NAMESPACE_NODE     *ResolvedNode;
487*f1db5ef7SJung-uk Kim     ACPI_NAMESPACE_NODE     *OriginalNode;
4885f9b24faSJung-uk Kim     char                    *ExternalPath = NULL;
4895f9b24faSJung-uk Kim     ACPI_OBJECT_TYPE        Type;
4905f9b24faSJung-uk Kim 
4915f9b24faSJung-uk Kim 
4925f9b24faSJung-uk Kim     ACPI_FUNCTION_TRACE (DsResolvePackageElement);
4935f9b24faSJung-uk Kim 
4945f9b24faSJung-uk Kim 
4955f9b24faSJung-uk Kim     /* Check if reference element is already resolved */
4965f9b24faSJung-uk Kim 
4975f9b24faSJung-uk Kim     if (Element->Reference.Resolved)
4985f9b24faSJung-uk Kim     {
4995f9b24faSJung-uk Kim         return_VOID;
5005f9b24faSJung-uk Kim     }
5015f9b24faSJung-uk Kim 
5025f9b24faSJung-uk Kim     /* Element must be a reference object of correct type */
5035f9b24faSJung-uk Kim 
5045f9b24faSJung-uk Kim     ScopeInfo.Scope.Node = Element->Reference.Node; /* Prefix node */
5055f9b24faSJung-uk Kim 
5065f9b24faSJung-uk Kim     Status = AcpiNsLookup (&ScopeInfo,
5075f9b24faSJung-uk Kim         (char *) Element->Reference.Aml,            /* Pointer to AML path */
5085f9b24faSJung-uk Kim         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
5095f9b24faSJung-uk Kim         ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
5105f9b24faSJung-uk Kim         NULL, &ResolvedNode);
5115f9b24faSJung-uk Kim     if (ACPI_FAILURE (Status))
5125f9b24faSJung-uk Kim     {
5135f9b24faSJung-uk Kim         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
5145f9b24faSJung-uk Kim             (char *) Element->Reference.Aml,
5155f9b24faSJung-uk Kim             NULL, &ExternalPath);
5165f9b24faSJung-uk Kim 
5175f9b24faSJung-uk Kim         ACPI_EXCEPTION ((AE_INFO, Status,
5185f9b24faSJung-uk Kim             "Could not find/resolve named package element: %s", ExternalPath));
5195f9b24faSJung-uk Kim 
5205f9b24faSJung-uk Kim         ACPI_FREE (ExternalPath);
5215f9b24faSJung-uk Kim         *ElementPtr = NULL;
5225f9b24faSJung-uk Kim         return_VOID;
5235f9b24faSJung-uk Kim     }
5245f9b24faSJung-uk Kim     else if (ResolvedNode->Type == ACPI_TYPE_ANY)
5255f9b24faSJung-uk Kim     {
5265f9b24faSJung-uk Kim         /* Named reference not resolved, return a NULL package element */
5275f9b24faSJung-uk Kim 
5285f9b24faSJung-uk Kim         ACPI_ERROR ((AE_INFO,
5295f9b24faSJung-uk Kim             "Could not resolve named package element [%4.4s] in [%4.4s]",
5305f9b24faSJung-uk Kim             ResolvedNode->Name.Ascii, ScopeInfo.Scope.Node->Name.Ascii));
5315f9b24faSJung-uk Kim         *ElementPtr = NULL;
5325f9b24faSJung-uk Kim         return_VOID;
5335f9b24faSJung-uk Kim     }
5345f9b24faSJung-uk Kim #if 0
5355f9b24faSJung-uk Kim     else if (ResolvedNode->Flags & ANOBJ_TEMPORARY)
5365f9b24faSJung-uk Kim     {
5375f9b24faSJung-uk Kim         /*
5385f9b24faSJung-uk Kim          * A temporary node found here indicates that the reference is
5395f9b24faSJung-uk Kim          * to a node that was created within this method. We are not
5405f9b24faSJung-uk Kim          * going to allow it (especially if the package is returned
5415f9b24faSJung-uk Kim          * from the method) -- the temporary node will be deleted out
5425f9b24faSJung-uk Kim          * from under the method. (05/2017).
5435f9b24faSJung-uk Kim          */
5445f9b24faSJung-uk Kim         ACPI_ERROR ((AE_INFO,
5455f9b24faSJung-uk Kim             "Package element refers to a temporary name [%4.4s], "
5465f9b24faSJung-uk Kim             "inserting a NULL element",
5475f9b24faSJung-uk Kim             ResolvedNode->Name.Ascii));
5485f9b24faSJung-uk Kim         *ElementPtr = NULL;
5495f9b24faSJung-uk Kim         return_VOID;
5505f9b24faSJung-uk Kim     }
5515f9b24faSJung-uk Kim #endif
5525f9b24faSJung-uk Kim 
5535f9b24faSJung-uk Kim     /*
5545f9b24faSJung-uk Kim      * Special handling for Alias objects. We need ResolvedNode to point
5555f9b24faSJung-uk Kim      * to the Alias target. This effectively "resolves" the alias.
5565f9b24faSJung-uk Kim      */
5575f9b24faSJung-uk Kim     if (ResolvedNode->Type == ACPI_TYPE_LOCAL_ALIAS)
5585f9b24faSJung-uk Kim     {
5595f9b24faSJung-uk Kim         ResolvedNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
5605f9b24faSJung-uk Kim             ResolvedNode->Object);
5615f9b24faSJung-uk Kim     }
5625f9b24faSJung-uk Kim 
5635f9b24faSJung-uk Kim     /* Update the reference object */
5645f9b24faSJung-uk Kim 
5655f9b24faSJung-uk Kim     Element->Reference.Resolved = TRUE;
5665f9b24faSJung-uk Kim     Element->Reference.Node = ResolvedNode;
5675f9b24faSJung-uk Kim     Type = Element->Reference.Node->Type;
5685f9b24faSJung-uk Kim 
5695f9b24faSJung-uk Kim     /*
5705f9b24faSJung-uk Kim      * Attempt to resolve the node to a value before we insert it into
5715f9b24faSJung-uk Kim      * the package. If this is a reference to a common data type,
5725f9b24faSJung-uk Kim      * resolve it immediately. According to the ACPI spec, package
5735f9b24faSJung-uk Kim      * elements can only be "data objects" or method references.
5745f9b24faSJung-uk Kim      * Attempt to resolve to an Integer, Buffer, String or Package.
5755f9b24faSJung-uk Kim      * If cannot, return the named reference (for things like Devices,
5765f9b24faSJung-uk Kim      * Methods, etc.) Buffer Fields and Fields will resolve to simple
5775f9b24faSJung-uk Kim      * objects (int/buf/str/pkg).
5785f9b24faSJung-uk Kim      *
5795f9b24faSJung-uk Kim      * NOTE: References to things like Devices, Methods, Mutexes, etc.
5805f9b24faSJung-uk Kim      * will remain as named references. This behavior is not described
5815f9b24faSJung-uk Kim      * in the ACPI spec, but it appears to be an oversight.
5825f9b24faSJung-uk Kim      */
583*f1db5ef7SJung-uk Kim     OriginalNode = ResolvedNode;
5845f9b24faSJung-uk Kim     Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
5855f9b24faSJung-uk Kim     if (ACPI_FAILURE (Status))
5865f9b24faSJung-uk Kim     {
5875f9b24faSJung-uk Kim         return_VOID;
5885f9b24faSJung-uk Kim     }
5895f9b24faSJung-uk Kim 
5905f9b24faSJung-uk Kim #if 0
5915f9b24faSJung-uk Kim /* TBD - alias support */
5925f9b24faSJung-uk Kim     /*
5935f9b24faSJung-uk Kim      * Special handling for Alias objects. We need to setup the type
5945f9b24faSJung-uk Kim      * and the Op->Common.Node to point to the Alias target. Note,
5955f9b24faSJung-uk Kim      * Alias has at most one level of indirection internally.
5965f9b24faSJung-uk Kim      */
5975f9b24faSJung-uk Kim     Type = Op->Common.Node->Type;
5985f9b24faSJung-uk Kim     if (Type == ACPI_TYPE_LOCAL_ALIAS)
5995f9b24faSJung-uk Kim     {
6005f9b24faSJung-uk Kim         Type = ObjDesc->Common.Type;
6015f9b24faSJung-uk Kim         Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
6025f9b24faSJung-uk Kim             Op->Common.Node->Object);
6035f9b24faSJung-uk Kim     }
6045f9b24faSJung-uk Kim #endif
6055f9b24faSJung-uk Kim 
6065f9b24faSJung-uk Kim     switch (Type)
6075f9b24faSJung-uk Kim     {
6085f9b24faSJung-uk Kim     /*
6095f9b24faSJung-uk Kim      * These object types are a result of named references, so we will
6105f9b24faSJung-uk Kim      * leave them as reference objects. In other words, these types
6115f9b24faSJung-uk Kim      * have no intrinsic "value".
6125f9b24faSJung-uk Kim      */
6135f9b24faSJung-uk Kim     case ACPI_TYPE_DEVICE:
6145f9b24faSJung-uk Kim     case ACPI_TYPE_THERMAL:
615*f1db5ef7SJung-uk Kim     case ACPI_TYPE_METHOD:
6165f9b24faSJung-uk Kim         break;
6175f9b24faSJung-uk Kim 
6185f9b24faSJung-uk Kim     case ACPI_TYPE_MUTEX:
6195f9b24faSJung-uk Kim     case ACPI_TYPE_POWER:
6205f9b24faSJung-uk Kim     case ACPI_TYPE_PROCESSOR:
6215f9b24faSJung-uk Kim     case ACPI_TYPE_EVENT:
6225f9b24faSJung-uk Kim     case ACPI_TYPE_REGION:
6235f9b24faSJung-uk Kim 
624*f1db5ef7SJung-uk Kim         /* AcpiExResolveNodeToValue gave these an extra reference */
625*f1db5ef7SJung-uk Kim 
626*f1db5ef7SJung-uk Kim         AcpiUtRemoveReference (OriginalNode->Object);
6275f9b24faSJung-uk Kim         break;
6285f9b24faSJung-uk Kim 
6295f9b24faSJung-uk Kim     default:
6305f9b24faSJung-uk Kim         /*
6315f9b24faSJung-uk Kim          * For all other types - the node was resolved to an actual
632*f1db5ef7SJung-uk Kim          * operand object with a value, return the object. Remove
633*f1db5ef7SJung-uk Kim          * a reference on the existing object.
6345f9b24faSJung-uk Kim          */
635*f1db5ef7SJung-uk Kim         AcpiUtRemoveReference (Element);
6365f9b24faSJung-uk Kim         *ElementPtr = (ACPI_OPERAND_OBJECT *) ResolvedNode;
6375f9b24faSJung-uk Kim         break;
6385f9b24faSJung-uk Kim     }
6395f9b24faSJung-uk Kim 
6405f9b24faSJung-uk Kim     return_VOID;
6415f9b24faSJung-uk Kim }
642