xref: /freebsd-src/sys/contrib/dev/acpica/compiler/aslload.c (revision a009b7dcabdc27aa3fdde1f2c6dd08d4fe5a3170)
153289f6aSNate Lawson /******************************************************************************
253289f6aSNate Lawson  *
353289f6aSNate Lawson  * Module Name: dswload - Dispatcher namespace load callbacks
453289f6aSNate Lawson  *
553289f6aSNate Lawson  *****************************************************************************/
653289f6aSNate Lawson 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
11e5e1f58aSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp.
1253289f6aSNate Lawson  * All rights reserved.
1353289f6aSNate Lawson  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
119d244b227SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120d244b227SJung-uk Kim  * modification, are permitted provided that the following conditions
121d244b227SJung-uk Kim  * are met:
122d244b227SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123d244b227SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124d244b227SJung-uk Kim  *    without modification.
125d244b227SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126d244b227SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127d244b227SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128d244b227SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129d244b227SJung-uk Kim  *    binary redistribution.
130d244b227SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131d244b227SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132d244b227SJung-uk Kim  *    from this software without specific prior written permission.
13353289f6aSNate Lawson  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147d244b227SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148d244b227SJung-uk Kim  * Software Foundation.
14953289f6aSNate Lawson  *
1500d84335fSJung-uk Kim  *****************************************************************************/
15153289f6aSNate Lawson 
152ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
153ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
154ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
155ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
156835b56bfSJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
15753289f6aSNate Lawson #include "aslcompiler.y.h"
15853289f6aSNate Lawson 
159835b56bfSJung-uk Kim 
16053289f6aSNate Lawson #define _COMPONENT          ACPI_COMPILER
16153289f6aSNate Lawson         ACPI_MODULE_NAME    ("aslload")
16253289f6aSNate Lawson 
163fba7fc7eSJung-uk Kim /* Local prototypes */
164fba7fc7eSJung-uk Kim 
165fba7fc7eSJung-uk Kim static ACPI_STATUS
166fba7fc7eSJung-uk Kim LdLoadFieldElements (
16737d7a5bcSJung-uk Kim     UINT32                  AmlType,
168fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
169fba7fc7eSJung-uk Kim     ACPI_WALK_STATE         *WalkState);
170fba7fc7eSJung-uk Kim 
171fba7fc7eSJung-uk Kim static ACPI_STATUS
172fba7fc7eSJung-uk Kim LdLoadResourceElements (
173fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
174fba7fc7eSJung-uk Kim     ACPI_WALK_STATE         *WalkState);
175fba7fc7eSJung-uk Kim 
176fba7fc7eSJung-uk Kim static ACPI_STATUS
177fba7fc7eSJung-uk Kim LdNamespace1Begin (
178fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
179fba7fc7eSJung-uk Kim     UINT32                  Level,
180fba7fc7eSJung-uk Kim     void                    *Context);
181fba7fc7eSJung-uk Kim 
182fba7fc7eSJung-uk Kim static ACPI_STATUS
183a9f12690SJung-uk Kim LdNamespace2Begin (
184a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
185a9f12690SJung-uk Kim     UINT32                  Level,
186a9f12690SJung-uk Kim     void                    *Context);
187a9f12690SJung-uk Kim 
188a9f12690SJung-uk Kim static ACPI_STATUS
189a9f12690SJung-uk Kim LdCommonNamespaceEnd (
190fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
191fba7fc7eSJung-uk Kim     UINT32                  Level,
192fba7fc7eSJung-uk Kim     void                    *Context);
193fba7fc7eSJung-uk Kim 
19437d7a5bcSJung-uk Kim static void
19537d7a5bcSJung-uk Kim LdCheckSpecialNames (
19637d7a5bcSJung-uk Kim     ACPI_NAMESPACE_NODE     *Node,
19737d7a5bcSJung-uk Kim     ACPI_PARSE_OBJECT       *Op);
19853289f6aSNate Lawson 
19953289f6aSNate Lawson /*******************************************************************************
20053289f6aSNate Lawson  *
20153289f6aSNate Lawson  * FUNCTION:    LdLoadNamespace
20253289f6aSNate Lawson  *
203fba7fc7eSJung-uk Kim  * PARAMETERS:  RootOp      - Root of the parse tree
20453289f6aSNate Lawson  *
20553289f6aSNate Lawson  * RETURN:      Status
20653289f6aSNate Lawson  *
20753289f6aSNate Lawson  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
20853289f6aSNate Lawson  *              named ASL/AML objects into the namespace. The namespace is
20953289f6aSNate Lawson  *              constructed in order to resolve named references and references
21053289f6aSNate Lawson  *              to named fields within resource templates/descriptors.
21153289f6aSNate Lawson  *
21253289f6aSNate Lawson  ******************************************************************************/
21353289f6aSNate Lawson 
21453289f6aSNate Lawson ACPI_STATUS
21553289f6aSNate Lawson LdLoadNamespace (
21653289f6aSNate Lawson     ACPI_PARSE_OBJECT       *RootOp)
21753289f6aSNate Lawson {
21853289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState;
21953289f6aSNate Lawson 
22053289f6aSNate Lawson 
22153289f6aSNate Lawson     /* Create a new walk state */
22253289f6aSNate Lawson 
22353289f6aSNate Lawson     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
22453289f6aSNate Lawson     if (!WalkState)
22553289f6aSNate Lawson     {
2268ef1a331SJung-uk Kim         return (AE_NO_MEMORY);
22753289f6aSNate Lawson     }
22853289f6aSNate Lawson 
229a9f12690SJung-uk Kim     /* Walk the entire parse tree, first pass */
23053289f6aSNate Lawson 
23153289f6aSNate Lawson     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
232a9f12690SJung-uk Kim         LdCommonNamespaceEnd, WalkState);
233a9f12690SJung-uk Kim 
234a9f12690SJung-uk Kim     /* Second pass to handle forward references */
235a9f12690SJung-uk Kim 
236a9f12690SJung-uk Kim     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
237a9f12690SJung-uk Kim         LdCommonNamespaceEnd, WalkState);
23853289f6aSNate Lawson 
23953289f6aSNate Lawson     /* Dump the namespace if debug is enabled */
24053289f6aSNate Lawson 
2413d90091dSJung-uk Kim     if (AcpiDbgLevel & ACPI_LV_TABLES)
2423d90091dSJung-uk Kim     {
24353289f6aSNate Lawson         AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
2443d90091dSJung-uk Kim     }
2453d90091dSJung-uk Kim 
246313a0c13SJung-uk Kim     ACPI_FREE (WalkState);
2478ef1a331SJung-uk Kim     return (AE_OK);
24853289f6aSNate Lawson }
24953289f6aSNate Lawson 
25053289f6aSNate Lawson 
25153289f6aSNate Lawson /*******************************************************************************
25253289f6aSNate Lawson  *
25353289f6aSNate Lawson  * FUNCTION:    LdLoadFieldElements
25453289f6aSNate Lawson  *
25537d7a5bcSJung-uk Kim  * PARAMETERS:  AmlType         - Type to search
25637d7a5bcSJung-uk Kim  *              Op              - Parent node (Field)
25753289f6aSNate Lawson  *              WalkState       - Current walk state
25853289f6aSNate Lawson  *
25953289f6aSNate Lawson  * RETURN:      Status
26053289f6aSNate Lawson  *
26153289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the field (children of the parent)
26253289f6aSNate Lawson  *              into the namespace.
26353289f6aSNate Lawson  *
26453289f6aSNate Lawson  ******************************************************************************/
26553289f6aSNate Lawson 
266fba7fc7eSJung-uk Kim static ACPI_STATUS
26753289f6aSNate Lawson LdLoadFieldElements (
26837d7a5bcSJung-uk Kim     UINT32                  AmlType,
26953289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
27053289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
27153289f6aSNate Lawson {
27253289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Child = NULL;
2739ad8b64eSJung-uk Kim     ACPI_PARSE_OBJECT       *SourceRegion;
27453289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
27553289f6aSNate Lawson     ACPI_STATUS             Status;
27653289f6aSNate Lawson 
27753289f6aSNate Lawson 
2789ad8b64eSJung-uk Kim     SourceRegion = UtGetArg (Op, 0);
2799ad8b64eSJung-uk Kim     if (SourceRegion)
2809ad8b64eSJung-uk Kim     {
2819ad8b64eSJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo,
2829ad8b64eSJung-uk Kim             SourceRegion->Asl.Value.String,
28337d7a5bcSJung-uk Kim             AmlType, ACPI_IMODE_EXECUTE,
2849ad8b64eSJung-uk Kim             ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
2859ad8b64eSJung-uk Kim         if (Status == AE_NOT_FOUND)
2869ad8b64eSJung-uk Kim         {
2879ad8b64eSJung-uk Kim             /*
2889ad8b64eSJung-uk Kim              * If the named object is not found, it means that it is either a
2899ad8b64eSJung-uk Kim              * forward reference or the named object does not exist.
2909ad8b64eSJung-uk Kim              */
2919ad8b64eSJung-uk Kim             SourceRegion->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
2929ad8b64eSJung-uk Kim         }
2939ad8b64eSJung-uk Kim     }
2949ad8b64eSJung-uk Kim 
29553289f6aSNate Lawson     /* Get the first named field element */
29653289f6aSNate Lawson 
29753289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
29853289f6aSNate Lawson     {
29953289f6aSNate Lawson     case AML_BANK_FIELD_OP:
30053289f6aSNate Lawson 
30153289f6aSNate Lawson         Child = UtGetArg (Op, 6);
30253289f6aSNate Lawson         break;
30353289f6aSNate Lawson 
30453289f6aSNate Lawson     case AML_INDEX_FIELD_OP:
30553289f6aSNate Lawson 
30653289f6aSNate Lawson         Child = UtGetArg (Op, 5);
30753289f6aSNate Lawson         break;
30853289f6aSNate Lawson 
30953289f6aSNate Lawson     case AML_FIELD_OP:
31053289f6aSNate Lawson 
31153289f6aSNate Lawson         Child = UtGetArg (Op, 4);
31253289f6aSNate Lawson         break;
31353289f6aSNate Lawson 
31453289f6aSNate Lawson     default:
315a9d8d09cSJung-uk Kim 
31653289f6aSNate Lawson         /* No other opcodes should arrive here */
317a9d8d09cSJung-uk Kim 
31853289f6aSNate Lawson         return (AE_BAD_PARAMETER);
31953289f6aSNate Lawson     }
32053289f6aSNate Lawson 
32153289f6aSNate Lawson     /* Enter all elements into the namespace */
32253289f6aSNate Lawson 
32353289f6aSNate Lawson     while (Child)
32453289f6aSNate Lawson     {
32553289f6aSNate Lawson         switch (Child->Asl.AmlOpcode)
32653289f6aSNate Lawson         {
32753289f6aSNate Lawson         case AML_INT_RESERVEDFIELD_OP:
32853289f6aSNate Lawson         case AML_INT_ACCESSFIELD_OP:
3293f0275a0SJung-uk Kim         case AML_INT_CONNECTION_OP:
33053289f6aSNate Lawson             break;
33153289f6aSNate Lawson 
33253289f6aSNate Lawson         default:
33353289f6aSNate Lawson 
334fba7fc7eSJung-uk Kim             Status = AcpiNsLookup (WalkState->ScopeInfo,
335fba7fc7eSJung-uk Kim                 Child->Asl.Value.String,
336fba7fc7eSJung-uk Kim                 ACPI_TYPE_LOCAL_REGION_FIELD,
337fba7fc7eSJung-uk Kim                 ACPI_IMODE_LOAD_PASS1,
338fba7fc7eSJung-uk Kim                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
339f8146b88SJung-uk Kim                     ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
34053289f6aSNate Lawson             if (ACPI_FAILURE (Status))
34153289f6aSNate Lawson             {
34253289f6aSNate Lawson                 if (Status != AE_ALREADY_EXISTS)
34353289f6aSNate Lawson                 {
344fba7fc7eSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
345fba7fc7eSJung-uk Kim                         Child->Asl.Value.String);
34653289f6aSNate Lawson                     return (Status);
34753289f6aSNate Lawson                 }
348af051161SJung-uk Kim                 else if (Status == AE_ALREADY_EXISTS &&
349da9b0901SJung-uk Kim                     (Node->Flags & ANOBJ_IS_EXTERNAL))
350af051161SJung-uk Kim                 {
351af051161SJung-uk Kim                     Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
35244b0f624SJung-uk Kim                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
353af051161SJung-uk Kim                 }
354af051161SJung-uk Kim                 else
355af051161SJung-uk Kim                 {
35653289f6aSNate Lawson                     /*
35753289f6aSNate Lawson                      * The name already exists in this scope
35853289f6aSNate Lawson                      * But continue processing the elements
35953289f6aSNate Lawson                      */
360cd6518c7SJung-uk Kim                     AslDualParseOpError (ASL_WARNING, ASL_MSG_NAME_EXISTS, Child,
361cd6518c7SJung-uk Kim                         Child->Asl.Value.String, ASL_MSG_FOUND_HERE, Node->Op,
36267d9aa44SJung-uk Kim                         Node->Op->Asl.ExternalName);
36353289f6aSNate Lawson                 }
364af051161SJung-uk Kim             }
36553289f6aSNate Lawson             else
36653289f6aSNate Lawson             {
36753289f6aSNate Lawson                 Child->Asl.Node = Node;
368fba7fc7eSJung-uk Kim                 Node->Op = Child;
36953289f6aSNate Lawson             }
37053289f6aSNate Lawson             break;
37153289f6aSNate Lawson         }
3723f0275a0SJung-uk Kim 
37353289f6aSNate Lawson         Child = Child->Asl.Next;
37453289f6aSNate Lawson     }
3753f0275a0SJung-uk Kim 
37653289f6aSNate Lawson     return (AE_OK);
37753289f6aSNate Lawson }
37853289f6aSNate Lawson 
37953289f6aSNate Lawson 
38053289f6aSNate Lawson /*******************************************************************************
38153289f6aSNate Lawson  *
38253289f6aSNate Lawson  * FUNCTION:    LdLoadResourceElements
38353289f6aSNate Lawson  *
38453289f6aSNate Lawson  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
38553289f6aSNate Lawson  *              WalkState       - Current walk state
38653289f6aSNate Lawson  *
38753289f6aSNate Lawson  * RETURN:      Status
38853289f6aSNate Lawson  *
38953289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the resource descriptor (children
39053289f6aSNate Lawson  *              of the parent) into the namespace.
39153289f6aSNate Lawson  *
39253289f6aSNate Lawson  * NOTE: In the real AML namespace, these named elements never exist. But
39353289f6aSNate Lawson  *       we simply use the namespace here as a symbol table so we can look
39453289f6aSNate Lawson  *       them up as they are referenced.
39553289f6aSNate Lawson  *
39653289f6aSNate Lawson  ******************************************************************************/
39753289f6aSNate Lawson 
398fba7fc7eSJung-uk Kim static ACPI_STATUS
39953289f6aSNate Lawson LdLoadResourceElements (
40053289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
40153289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
40253289f6aSNate Lawson {
40353289f6aSNate Lawson     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
40453289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
40553289f6aSNate Lawson     ACPI_STATUS             Status;
40653289f6aSNate Lawson 
40753289f6aSNate Lawson 
40853289f6aSNate Lawson     /*
409fba7fc7eSJung-uk Kim      * Enter the resource name into the namespace. Name must not already exist.
410fba7fc7eSJung-uk Kim      * This opens a scope, so later field names are guaranteed to be new/unique.
41153289f6aSNate Lawson      */
41253289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
413fba7fc7eSJung-uk Kim         ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
414fba7fc7eSJung-uk Kim         ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
41553289f6aSNate Lawson         WalkState, &Node);
41653289f6aSNate Lawson     if (ACPI_FAILURE (Status))
41753289f6aSNate Lawson     {
418fba7fc7eSJung-uk Kim         if (Status == AE_ALREADY_EXISTS)
419fba7fc7eSJung-uk Kim         {
420fba7fc7eSJung-uk Kim             /* Actual node causing the error was saved in ParentMethod */
421fba7fc7eSJung-uk Kim 
42267d9aa44SJung-uk Kim             AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
42367d9aa44SJung-uk Kim                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
42467d9aa44SJung-uk Kim                 Op->Asl.Namepath, ASL_MSG_FOUND_HERE, Node->Op,
42567d9aa44SJung-uk Kim                 Node->Op->Asl.ExternalName);
426fba7fc7eSJung-uk Kim             return (AE_OK);
427fba7fc7eSJung-uk Kim         }
42853289f6aSNate Lawson         return (Status);
42953289f6aSNate Lawson     }
43053289f6aSNate Lawson 
4311a39cfb0SJung-uk Kim     Node->Value = (UINT32) Op->Asl.Value.Integer;
4321a39cfb0SJung-uk Kim     Node->Op = Op;
433d6dd1baeSJung-uk Kim     Op->Asl.Node = Node;
4341a39cfb0SJung-uk Kim 
43553289f6aSNate Lawson     /*
43653289f6aSNate Lawson      * Now enter the predefined fields, for easy lookup when referenced
43753289f6aSNate Lawson      * by the source ASL
43853289f6aSNate Lawson      */
43953289f6aSNate Lawson     InitializerOp = ASL_GET_CHILD_NODE (Op);
44053289f6aSNate Lawson     while (InitializerOp)
44153289f6aSNate Lawson     {
44253289f6aSNate Lawson         if (InitializerOp->Asl.ExternalName)
44353289f6aSNate Lawson         {
44453289f6aSNate Lawson             Status = AcpiNsLookup (WalkState->ScopeInfo,
44553289f6aSNate Lawson                 InitializerOp->Asl.ExternalName,
4464a38ee6dSJung-uk Kim                 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
4474a38ee6dSJung-uk Kim                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
44853289f6aSNate Lawson             if (ACPI_FAILURE (Status))
44953289f6aSNate Lawson             {
45053289f6aSNate Lawson                 return (Status);
45153289f6aSNate Lawson             }
45253289f6aSNate Lawson 
45353289f6aSNate Lawson             /*
4543f0275a0SJung-uk Kim              * Store the field offset and length in the namespace node
4553f0275a0SJung-uk Kim              * so it can be used when the field is referenced
45653289f6aSNate Lawson              */
4573f0275a0SJung-uk Kim             Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
4583f0275a0SJung-uk Kim             Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
45953289f6aSNate Lawson             InitializerOp->Asl.Node = Node;
460fba7fc7eSJung-uk Kim             Node->Op = InitializerOp;
46153289f6aSNate Lawson         }
4623f0275a0SJung-uk Kim 
46353289f6aSNate Lawson         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
46453289f6aSNate Lawson     }
46553289f6aSNate Lawson 
46653289f6aSNate Lawson     return (AE_OK);
46753289f6aSNate Lawson }
46853289f6aSNate Lawson 
46953289f6aSNate Lawson 
47053289f6aSNate Lawson /*******************************************************************************
47153289f6aSNate Lawson  *
47253289f6aSNate Lawson  * FUNCTION:    LdNamespace1Begin
47353289f6aSNate Lawson  *
47453289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
47553289f6aSNate Lawson  *
47653289f6aSNate Lawson  * RETURN:      Status
47753289f6aSNate Lawson  *
47853289f6aSNate Lawson  * DESCRIPTION: Descending callback used during the parse tree walk. If this
47953289f6aSNate Lawson  *              is a named AML opcode, enter into the namespace
48053289f6aSNate Lawson  *
48153289f6aSNate Lawson  ******************************************************************************/
48253289f6aSNate Lawson 
483fba7fc7eSJung-uk Kim static ACPI_STATUS
48453289f6aSNate Lawson LdNamespace1Begin (
48553289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
48653289f6aSNate Lawson     UINT32                  Level,
48753289f6aSNate Lawson     void                    *Context)
48853289f6aSNate Lawson {
48953289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
49053289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
491f8146b88SJung-uk Kim     ACPI_PARSE_OBJECT       *MethodOp;
49253289f6aSNate Lawson     ACPI_STATUS             Status;
49353289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
49453289f6aSNate Lawson     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
49553289f6aSNate Lawson     char                    *Path;
49653289f6aSNate Lawson     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
49753289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Arg;
49853289f6aSNate Lawson     UINT32                  i;
4991a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
500835b56bfSJung-uk Kim     const ACPI_OPCODE_INFO  *OpInfo;
501835b56bfSJung-uk Kim     ACPI_PARSE_OBJECT       *ParentOp;
50253289f6aSNate Lawson 
50353289f6aSNate Lawson 
5041a39cfb0SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace1Begin);
505835b56bfSJung-uk Kim 
506835b56bfSJung-uk Kim 
50753289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
50853289f6aSNate Lawson         Op, Op->Asl.ParseOpName));
50953289f6aSNate Lawson 
51053289f6aSNate Lawson     /*
51153289f6aSNate Lawson      * We are only interested in opcodes that have an associated name
51253289f6aSNate Lawson      * (or multiple names)
51353289f6aSNate Lawson      */
51453289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
51553289f6aSNate Lawson     {
5162e578044SJung-uk Kim     case AML_INDEX_FIELD_OP:
51737d7a5bcSJung-uk Kim 
51837d7a5bcSJung-uk Kim         Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
51937d7a5bcSJung-uk Kim         return (Status);
52037d7a5bcSJung-uk Kim 
52137d7a5bcSJung-uk Kim     case AML_BANK_FIELD_OP:
52253289f6aSNate Lawson     case AML_FIELD_OP:
52353289f6aSNate Lawson 
52437d7a5bcSJung-uk Kim         Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
5259ad8b64eSJung-uk Kim         return (Status);
52653289f6aSNate Lawson 
527313a0c13SJung-uk Kim     case AML_INT_CONNECTION_OP:
528313a0c13SJung-uk Kim 
529313a0c13SJung-uk Kim         if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
530313a0c13SJung-uk Kim         {
531313a0c13SJung-uk Kim             break;
532313a0c13SJung-uk Kim         }
533313a0c13SJung-uk Kim 
534*a009b7dcSJung-uk Kim         Arg = Op->Asl.Child;
535313a0c13SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
536313a0c13SJung-uk Kim             ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
537313a0c13SJung-uk Kim             WalkState, &Node);
538313a0c13SJung-uk Kim         if (ACPI_FAILURE (Status))
539313a0c13SJung-uk Kim         {
540313a0c13SJung-uk Kim             break;
541313a0c13SJung-uk Kim         }
542313a0c13SJung-uk Kim 
543313a0c13SJung-uk Kim         break;
544313a0c13SJung-uk Kim 
54553289f6aSNate Lawson     default:
54653289f6aSNate Lawson 
54753289f6aSNate Lawson         /* All other opcodes go below */
548a9d8d09cSJung-uk Kim 
54953289f6aSNate Lawson         break;
55053289f6aSNate Lawson     }
55153289f6aSNate Lawson 
55253289f6aSNate Lawson     /* Check if this object has already been installed in the namespace */
55353289f6aSNate Lawson 
55453289f6aSNate Lawson     if (Op->Asl.Node)
55553289f6aSNate Lawson     {
55653289f6aSNate Lawson         return (AE_OK);
55753289f6aSNate Lawson     }
55853289f6aSNate Lawson 
559835b56bfSJung-uk Kim     /* Check for a possible illegal forward reference */
560835b56bfSJung-uk Kim 
561835b56bfSJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
562835b56bfSJung-uk Kim         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
563835b56bfSJung-uk Kim     {
564835b56bfSJung-uk Kim         /*
565835b56bfSJung-uk Kim          * Op->Asl.Namepath will be NULL for these opcodes.
566835b56bfSJung-uk Kim          * These opcodes are guaranteed to have a parent.
567835b56bfSJung-uk Kim          * Examine the parent opcode.
568835b56bfSJung-uk Kim          */
569835b56bfSJung-uk Kim         ParentOp = Op->Asl.Parent;
570835b56bfSJung-uk Kim         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
571835b56bfSJung-uk Kim 
572835b56bfSJung-uk Kim         /*
573835b56bfSJung-uk Kim          * Exclude all operators that actually declare a new name:
574835b56bfSJung-uk Kim          *      Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
575835b56bfSJung-uk Kim          * We only want references to named objects:
576835b56bfSJung-uk Kim          *      Store (2, WXYZ) -> Attempt to resolve the name
577835b56bfSJung-uk Kim          */
5789ad8b64eSJung-uk Kim         if (OpInfo->Class == AML_CLASS_NAMED_OBJECT)
579835b56bfSJung-uk Kim         {
580835b56bfSJung-uk Kim             return (AE_OK);
581835b56bfSJung-uk Kim         }
582835b56bfSJung-uk Kim 
583835b56bfSJung-uk Kim         /*
584835b56bfSJung-uk Kim          * Check if the referenced object exists at this point during
585835b56bfSJung-uk Kim          * the load:
586835b56bfSJung-uk Kim          * 1) If it exists, then this cannot be a forward reference.
587835b56bfSJung-uk Kim          * 2) If it does not exist, it could be a forward reference or
588835b56bfSJung-uk Kim          * it truly does not exist (and no external declaration).
589835b56bfSJung-uk Kim          */
590835b56bfSJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo,
591835b56bfSJung-uk Kim             Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
592835b56bfSJung-uk Kim             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
593835b56bfSJung-uk Kim             WalkState, &Node);
594835b56bfSJung-uk Kim         if (Status == AE_NOT_FOUND)
595835b56bfSJung-uk Kim         {
596835b56bfSJung-uk Kim             /*
597cd6518c7SJung-uk Kim              * This is either a forward reference or the object truly
598835b56bfSJung-uk Kim              * does not exist. The two cases can only be differentiated
599835b56bfSJung-uk Kim              * during the cross-reference stage later. Mark the Op/Name
600835b56bfSJung-uk Kim              * as not-found for now to indicate the need for further
601835b56bfSJung-uk Kim              * processing.
602835b56bfSJung-uk Kim              *
603835b56bfSJung-uk Kim              * Special case: Allow forward references from elements of
604835b56bfSJung-uk Kim              * Package objects. This provides compatibility with other
605835b56bfSJung-uk Kim              * ACPI implementations. To correctly implement this, the
606835b56bfSJung-uk Kim              * ACPICA table load defers package resolution until the entire
607835b56bfSJung-uk Kim              * namespace has been loaded.
608835b56bfSJung-uk Kim              */
609835b56bfSJung-uk Kim             if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
610835b56bfSJung-uk Kim                 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
611835b56bfSJung-uk Kim             {
612835b56bfSJung-uk Kim                 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
613835b56bfSJung-uk Kim             }
614835b56bfSJung-uk Kim 
615835b56bfSJung-uk Kim             return (AE_OK);
616835b56bfSJung-uk Kim         }
617835b56bfSJung-uk Kim 
618835b56bfSJung-uk Kim         return (Status);
619835b56bfSJung-uk Kim     }
620835b56bfSJung-uk Kim 
62153289f6aSNate Lawson     Path = Op->Asl.Namepath;
62253289f6aSNate Lawson     if (!Path)
62353289f6aSNate Lawson     {
62453289f6aSNate Lawson         return (AE_OK);
62553289f6aSNate Lawson     }
62653289f6aSNate Lawson 
62753289f6aSNate Lawson     /* Map the raw opcode into an internal object type */
62853289f6aSNate Lawson 
62953289f6aSNate Lawson     switch (Op->Asl.ParseOpcode)
63053289f6aSNate Lawson     {
63153289f6aSNate Lawson     case PARSEOP_NAME:
63253289f6aSNate Lawson 
63353289f6aSNate Lawson         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
63453289f6aSNate Lawson         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
63553289f6aSNate Lawson 
6361a39cfb0SJung-uk Kim         /*
6371a39cfb0SJung-uk Kim          * If this name refers to a ResourceTemplate, we will need to open
6381a39cfb0SJung-uk Kim          * a new scope so that the resource subfield names can be entered into
6391a39cfb0SJung-uk Kim          * the namespace underneath this name
6401a39cfb0SJung-uk Kim          */
6415f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
6421a39cfb0SJung-uk Kim         {
6431a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
6441a39cfb0SJung-uk Kim         }
6451a39cfb0SJung-uk Kim 
64653289f6aSNate Lawson         /* Get the data type associated with the named object, not the name itself */
64753289f6aSNate Lawson 
64853289f6aSNate Lawson         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
64953289f6aSNate Lawson 
65053289f6aSNate Lawson         ObjectType = 1;
65153289f6aSNate Lawson         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
65253289f6aSNate Lawson         {
65353289f6aSNate Lawson             ObjectType++;
65453289f6aSNate Lawson         }
65553289f6aSNate Lawson         break;
65653289f6aSNate Lawson 
65753289f6aSNate Lawson     case PARSEOP_EXTERNAL:
65853289f6aSNate Lawson         /*
65953289f6aSNate Lawson          * "External" simply enters a name and type into the namespace.
66053289f6aSNate Lawson          * We must be careful to not open a new scope, however, no matter
66153289f6aSNate Lawson          * what type the external name refers to (e.g., a method)
66253289f6aSNate Lawson          *
66353289f6aSNate Lawson          * first child is name, next child is ObjectType
66453289f6aSNate Lawson          */
66553289f6aSNate Lawson         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
66653289f6aSNate Lawson         ObjectType = ACPI_TYPE_ANY;
66753289f6aSNate Lawson 
6681a39cfb0SJung-uk Kim         /*
6691a39cfb0SJung-uk Kim          * We will mark every new node along the path as "External". This
6701a39cfb0SJung-uk Kim          * allows some or all of the nodes to be created later in the ASL
6711a39cfb0SJung-uk Kim          * code. Handles cases like this:
6721a39cfb0SJung-uk Kim          *
6731a39cfb0SJung-uk Kim          *   External (\_SB_.PCI0.ABCD, IntObj)
6741a39cfb0SJung-uk Kim          *   Scope (_SB_)
6751a39cfb0SJung-uk Kim          *   {
6761a39cfb0SJung-uk Kim          *       Device (PCI0)
6771a39cfb0SJung-uk Kim          *       {
6781a39cfb0SJung-uk Kim          *       }
6791a39cfb0SJung-uk Kim          *   }
6801a39cfb0SJung-uk Kim          *   Method (X)
6811a39cfb0SJung-uk Kim          *   {
6821a39cfb0SJung-uk Kim          *       Store (\_SB_.PCI0.ABCD, Local0)
6831a39cfb0SJung-uk Kim          *   }
6841a39cfb0SJung-uk Kim          */
6851a39cfb0SJung-uk Kim         Flags |= ACPI_NS_EXTERNAL;
6861a39cfb0SJung-uk Kim         break;
68753289f6aSNate Lawson 
68853289f6aSNate Lawson     case PARSEOP_DEFAULT_ARG:
68953289f6aSNate Lawson 
6905f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
69153289f6aSNate Lawson         {
69253289f6aSNate Lawson             Status = LdLoadResourceElements (Op, WalkState);
6939a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
69453289f6aSNate Lawson         }
69553289f6aSNate Lawson 
69653289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
69753289f6aSNate Lawson         break;
69853289f6aSNate Lawson 
69953289f6aSNate Lawson     case PARSEOP_SCOPE:
70053289f6aSNate Lawson         /*
70153289f6aSNate Lawson          * The name referenced by Scope(Name) must already exist at this point.
70253289f6aSNate Lawson          * In other words, forward references for Scope() are not supported.
70353289f6aSNate Lawson          * The only real reason for this is that the MS interpreter cannot
70453289f6aSNate Lawson          * handle this case. Perhaps someday this case can go away.
70553289f6aSNate Lawson          */
70653289f6aSNate Lawson         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
7074a38ee6dSJung-uk Kim             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
70853289f6aSNate Lawson         if (ACPI_FAILURE (Status))
70953289f6aSNate Lawson         {
71053289f6aSNate Lawson             if (Status == AE_NOT_FOUND)
71153289f6aSNate Lawson             {
71253289f6aSNate Lawson                 /* The name was not found, go ahead and create it */
71353289f6aSNate Lawson 
714fba7fc7eSJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
7154a38ee6dSJung-uk Kim                     ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
7164a38ee6dSJung-uk Kim                     Flags, WalkState, &Node);
71779c6d946SJung-uk Kim                 if (ACPI_FAILURE (Status))
71879c6d946SJung-uk Kim                 {
71979c6d946SJung-uk Kim                     return_ACPI_STATUS (Status);
72079c6d946SJung-uk Kim                 }
72153289f6aSNate Lawson 
7224a38ee6dSJung-uk Kim                 /* However, this is an error -- operand to Scope must exist */
7234a38ee6dSJung-uk Kim 
724278f0de6SJung-uk Kim                 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
7254a38ee6dSJung-uk Kim                 {
726fba7fc7eSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
727fba7fc7eSJung-uk Kim                         Op->Asl.ExternalName);
7284a38ee6dSJung-uk Kim                 }
7294a38ee6dSJung-uk Kim                 else
7304a38ee6dSJung-uk Kim                 {
7314a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
732fba7fc7eSJung-uk Kim                         Op->Asl.ExternalName);
7334a38ee6dSJung-uk Kim                 }
7344a38ee6dSJung-uk Kim 
73553289f6aSNate Lawson                 goto FinishNode;
73653289f6aSNate Lawson             }
73753289f6aSNate Lawson 
738f556842eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
739f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
740f556842eSJung-uk Kim 
7419a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
74253289f6aSNate Lawson         }
743f8146b88SJung-uk Kim         else /* Status AE_OK */
744f8146b88SJung-uk Kim         {
745f8146b88SJung-uk Kim             /*
746f8146b88SJung-uk Kim              * Do not allow references to external scopes from the DSDT.
747f8146b88SJung-uk Kim              * This is because the DSDT is always loaded first, and the
748f8146b88SJung-uk Kim              * external reference cannot be resolved -- causing a runtime
749f8146b88SJung-uk Kim              * error because Scope() must be resolved immediately.
750f8146b88SJung-uk Kim              * 10/2015.
751f8146b88SJung-uk Kim              */
752f8146b88SJung-uk Kim             if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
753278f0de6SJung-uk Kim                 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
754f8146b88SJung-uk Kim             {
755f8146b88SJung-uk Kim                 /* However, allowed if the reference is within a method */
756f8146b88SJung-uk Kim 
757f8146b88SJung-uk Kim                 MethodOp = Op->Asl.Parent;
758f8146b88SJung-uk Kim                 while (MethodOp &&
759f8146b88SJung-uk Kim                       (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
760f8146b88SJung-uk Kim                 {
761f8146b88SJung-uk Kim                     MethodOp = MethodOp->Asl.Parent;
762f8146b88SJung-uk Kim                 }
763f8146b88SJung-uk Kim 
764f8146b88SJung-uk Kim                 if (!MethodOp)
765f8146b88SJung-uk Kim                 {
766f8146b88SJung-uk Kim                     /* Not in a control method, error */
767f8146b88SJung-uk Kim 
768f8146b88SJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
769f8146b88SJung-uk Kim                 }
770f8146b88SJung-uk Kim             }
771f8146b88SJung-uk Kim         }
77253289f6aSNate Lawson 
77353289f6aSNate Lawson         /* We found a node with this name, now check the type */
77453289f6aSNate Lawson 
77553289f6aSNate Lawson         switch (Node->Type)
77653289f6aSNate Lawson         {
77753289f6aSNate Lawson         case ACPI_TYPE_LOCAL_SCOPE:
77853289f6aSNate Lawson         case ACPI_TYPE_DEVICE:
77953289f6aSNate Lawson         case ACPI_TYPE_POWER:
78053289f6aSNate Lawson         case ACPI_TYPE_PROCESSOR:
78153289f6aSNate Lawson         case ACPI_TYPE_THERMAL:
78253289f6aSNate Lawson 
78353289f6aSNate Lawson             /* These are acceptable types - they all open a new scope */
78453289f6aSNate Lawson             break;
78553289f6aSNate Lawson 
78653289f6aSNate Lawson         case ACPI_TYPE_INTEGER:
78753289f6aSNate Lawson         case ACPI_TYPE_STRING:
78853289f6aSNate Lawson         case ACPI_TYPE_BUFFER:
78953289f6aSNate Lawson             /*
790fba7fc7eSJung-uk Kim              * These types we will allow, but we will change the type.
791fba7fc7eSJung-uk Kim              * This enables some existing code of the form:
79253289f6aSNate Lawson              *
79353289f6aSNate Lawson              *  Name (DEB, 0)
79453289f6aSNate Lawson              *  Scope (DEB) { ... }
79553289f6aSNate Lawson              *
79653289f6aSNate Lawson              * Which is used to workaround the fact that the MS interpreter
79753289f6aSNate Lawson              * does not allow Scope() forward references.
79853289f6aSNate Lawson              */
7996f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
80053289f6aSNate Lawson                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
8016f1f1a63SJung-uk Kim             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
80253289f6aSNate Lawson 
803fba7fc7eSJung-uk Kim             /* Switch the type to scope, open the new scope */
804fba7fc7eSJung-uk Kim 
805e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
806fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
807fba7fc7eSJung-uk Kim                 WalkState);
808e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
809e0ef747bSNate Lawson             {
810e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
811e0ef747bSNate Lawson             }
81253289f6aSNate Lawson             break;
81353289f6aSNate Lawson 
81453289f6aSNate Lawson         default:
81553289f6aSNate Lawson 
816fba7fc7eSJung-uk Kim             /* All other types are an error */
817fba7fc7eSJung-uk Kim 
8186f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
819fba7fc7eSJung-uk Kim                 AcpiUtGetTypeName (Node->Type));
8206f1f1a63SJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
82153289f6aSNate Lawson 
82253289f6aSNate Lawson             /*
82353289f6aSNate Lawson              * However, switch the type to be an actual scope so
82453289f6aSNate Lawson              * that compilation can continue without generating a whole
825e0ef747bSNate Lawson              * cascade of additional errors. Open the new scope.
82653289f6aSNate Lawson              */
827e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
828fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
829fba7fc7eSJung-uk Kim                 WalkState);
830e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
831e0ef747bSNate Lawson             {
832e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
833e0ef747bSNate Lawson             }
83453289f6aSNate Lawson             break;
83553289f6aSNate Lawson         }
83653289f6aSNate Lawson 
83753289f6aSNate Lawson         Status = AE_OK;
83853289f6aSNate Lawson         goto FinishNode;
83953289f6aSNate Lawson 
84053289f6aSNate Lawson     default:
84153289f6aSNate Lawson 
84253289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
84353289f6aSNate Lawson         break;
84453289f6aSNate Lawson     }
84553289f6aSNate Lawson 
84653289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
84753289f6aSNate Lawson         Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
84853289f6aSNate Lawson 
84953289f6aSNate Lawson     /* The name must not already exist */
85053289f6aSNate Lawson 
85153289f6aSNate Lawson     Flags |= ACPI_NS_ERROR_IF_FOUND;
85253289f6aSNate Lawson 
85353289f6aSNate Lawson     /*
8544a38ee6dSJung-uk Kim      * For opcodes that enter new names into the namespace,
8554a38ee6dSJung-uk Kim      * all prefix NameSegs must exist.
8564a38ee6dSJung-uk Kim      */
8574a38ee6dSJung-uk Kim     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
8584a38ee6dSJung-uk Kim     if (((WalkState->OpInfo->Flags & AML_NAMED) ||
8594a38ee6dSJung-uk Kim         (WalkState->OpInfo->Flags & AML_CREATE)) &&
8604a38ee6dSJung-uk Kim         (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
8614a38ee6dSJung-uk Kim     {
8624a38ee6dSJung-uk Kim         Flags |= ACPI_NS_PREFIX_MUST_EXIST;
8634a38ee6dSJung-uk Kim     }
8644a38ee6dSJung-uk Kim 
8654a38ee6dSJung-uk Kim     /*
86653289f6aSNate Lawson      * Enter the named type into the internal namespace. We enter the name
867fba7fc7eSJung-uk Kim      * as we go downward in the parse tree. Any necessary subobjects that
868fba7fc7eSJung-uk Kim      * involve arguments to the opcode must be created as we go back up the
869fba7fc7eSJung-uk Kim      * parse tree later.
87053289f6aSNate Lawson      */
87153289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
8721a39cfb0SJung-uk Kim         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
87353289f6aSNate Lawson     if (ACPI_FAILURE (Status))
87453289f6aSNate Lawson     {
87553289f6aSNate Lawson         if (Status == AE_ALREADY_EXISTS)
87653289f6aSNate Lawson         {
87753289f6aSNate Lawson             /* The name already exists in this scope */
87853289f6aSNate Lawson 
87953289f6aSNate Lawson             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
88053289f6aSNate Lawson             {
8811a39cfb0SJung-uk Kim                 /* Allow multiple references to the same scope */
8821a39cfb0SJung-uk Kim 
88353289f6aSNate Lawson                 Node->Type = (UINT8) ObjectType;
88453289f6aSNate Lawson                 Status = AE_OK;
88553289f6aSNate Lawson             }
886a9f12690SJung-uk Kim             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
887a9f12690SJung-uk Kim                      (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
8881a39cfb0SJung-uk Kim             {
8891a39cfb0SJung-uk Kim                 /*
8901a39cfb0SJung-uk Kim                  * Allow one create on an object or segment that was
891da9b0901SJung-uk Kim                  * previously declared External
8921a39cfb0SJung-uk Kim                  */
8931a39cfb0SJung-uk Kim                 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
8941a39cfb0SJung-uk Kim                 Node->Type = (UINT8) ObjectType;
8951a39cfb0SJung-uk Kim 
8961a39cfb0SJung-uk Kim                 /* Just retyped a node, probably will need to open a scope */
8971a39cfb0SJung-uk Kim 
8981a39cfb0SJung-uk Kim                 if (AcpiNsOpensScope (ObjectType))
8991a39cfb0SJung-uk Kim                 {
9001a39cfb0SJung-uk Kim                     Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
9011a39cfb0SJung-uk Kim                     if (ACPI_FAILURE (Status))
9021a39cfb0SJung-uk Kim                     {
9031a39cfb0SJung-uk Kim                         return_ACPI_STATUS (Status);
9041a39cfb0SJung-uk Kim                     }
9051a39cfb0SJung-uk Kim                 }
906f8146b88SJung-uk Kim 
9071a39cfb0SJung-uk Kim                 Status = AE_OK;
9081a39cfb0SJung-uk Kim             }
909f8146b88SJung-uk Kim             else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
910f8146b88SJung-uk Kim                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
911f8146b88SJung-uk Kim             {
912f8146b88SJung-uk Kim                 /*
913f8146b88SJung-uk Kim                  * Allow externals in same scope as the definition of the
914f8146b88SJung-uk Kim                  * actual object. Similar to C. Allows multiple definition
915da9b0901SJung-uk Kim                  * blocks that refer to each other in the same file.
916f8146b88SJung-uk Kim                  */
917f8146b88SJung-uk Kim                 Status = AE_OK;
918f8146b88SJung-uk Kim             }
919f8146b88SJung-uk Kim             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
920f8146b88SJung-uk Kim                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
921f8146b88SJung-uk Kim                      (ObjectType == ACPI_TYPE_ANY))
922f8146b88SJung-uk Kim             {
923da9b0901SJung-uk Kim                 /* Allow update of externals of unknown type. */
924f8146b88SJung-uk Kim 
925f8146b88SJung-uk Kim                 if (AcpiNsOpensScope (ActualObjectType))
926f8146b88SJung-uk Kim                 {
927f8146b88SJung-uk Kim                     Node->Type = (UINT8) ActualObjectType;
928f8146b88SJung-uk Kim                     Status = AE_OK;
929f8146b88SJung-uk Kim                 }
930f8146b88SJung-uk Kim                 else
931f8146b88SJung-uk Kim                 {
9326f1f1a63SJung-uk Kim                     sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
933f8146b88SJung-uk Kim                         AcpiUtGetTypeName (Node->Type));
9346f1f1a63SJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
935f8146b88SJung-uk Kim                     return_ACPI_STATUS (AE_OK);
936f8146b88SJung-uk Kim                 }
937f8146b88SJung-uk Kim             }
93853289f6aSNate Lawson             else
93953289f6aSNate Lawson             {
9401a39cfb0SJung-uk Kim                 /* Valid error, object already exists */
9411a39cfb0SJung-uk Kim 
94267d9aa44SJung-uk Kim                 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
94367d9aa44SJung-uk Kim                     Op->Asl.ExternalName, ASL_MSG_FOUND_HERE, Node->Op,
94467d9aa44SJung-uk Kim                     Node->Op->Asl.ExternalName);
9459a179dd8SJung-uk Kim                 return_ACPI_STATUS (AE_OK);
94653289f6aSNate Lawson             }
94753289f6aSNate Lawson         }
9484a38ee6dSJung-uk Kim         else if (AE_NOT_FOUND)
9494a38ee6dSJung-uk Kim         {
9504a38ee6dSJung-uk Kim             /*
9514a38ee6dSJung-uk Kim              * One or more prefix NameSegs of the NamePath do not exist
9524a38ee6dSJung-uk Kim              * (all of them must exist). Attempt to continue compilation
9534a38ee6dSJung-uk Kim              * by setting the current scope to the root.
9544a38ee6dSJung-uk Kim              */
9554a38ee6dSJung-uk Kim             Node = AcpiGbl_RootNode;
9564a38ee6dSJung-uk Kim             Status = AE_OK;
9574a38ee6dSJung-uk Kim         }
95853289f6aSNate Lawson         else
95953289f6aSNate Lawson         {
9604a38ee6dSJung-uk Kim             /* Flag all other errors as coming from the ACPICA core */
9614a38ee6dSJung-uk Kim 
962fba7fc7eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
963f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
9649a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
96553289f6aSNate Lawson         }
96653289f6aSNate Lawson     }
96753289f6aSNate Lawson 
96837d7a5bcSJung-uk Kim     /* Check special names like _WAK and _PTS */
96937d7a5bcSJung-uk Kim 
97037d7a5bcSJung-uk Kim     LdCheckSpecialNames (Node, Op);
97137d7a5bcSJung-uk Kim 
9721a39cfb0SJung-uk Kim     if (ForceNewScope)
9731a39cfb0SJung-uk Kim     {
9741a39cfb0SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
9751a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
9761a39cfb0SJung-uk Kim         {
9771a39cfb0SJung-uk Kim             return_ACPI_STATUS (Status);
9781a39cfb0SJung-uk Kim         }
9791a39cfb0SJung-uk Kim     }
98053289f6aSNate Lawson 
98153289f6aSNate Lawson FinishNode:
98253289f6aSNate Lawson     /*
98353289f6aSNate Lawson      * Point the parse node to the new namespace node, and point
98453289f6aSNate Lawson      * the Node back to the original Parse node
98553289f6aSNate Lawson      */
98653289f6aSNate Lawson     Op->Asl.Node = Node;
987fba7fc7eSJung-uk Kim     Node->Op = Op;
98853289f6aSNate Lawson 
98953289f6aSNate Lawson     /* Set the actual data type if appropriate (EXTERNAL term only) */
99053289f6aSNate Lawson 
99153289f6aSNate Lawson     if (ActualObjectType != ACPI_TYPE_ANY)
99253289f6aSNate Lawson     {
99353289f6aSNate Lawson         Node->Type = (UINT8) ActualObjectType;
994fba7fc7eSJung-uk Kim         Node->Value = ASL_EXTERNAL_METHOD;
99553289f6aSNate Lawson     }
99653289f6aSNate Lawson 
99753289f6aSNate Lawson     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
99853289f6aSNate Lawson     {
99953289f6aSNate Lawson         /*
1000fba7fc7eSJung-uk Kim          * Get the method argument count from "Extra" and save
1001fba7fc7eSJung-uk Kim          * it in the namespace node
100253289f6aSNate Lawson          */
1003fba7fc7eSJung-uk Kim         Node->Value = (UINT32) Op->Asl.Extra;
100453289f6aSNate Lawson     }
100553289f6aSNate Lawson 
10069a179dd8SJung-uk Kim     return_ACPI_STATUS (Status);
100753289f6aSNate Lawson }
100853289f6aSNate Lawson 
100953289f6aSNate Lawson 
101053289f6aSNate Lawson /*******************************************************************************
101153289f6aSNate Lawson  *
101237d7a5bcSJung-uk Kim  * FUNCTION:    LdCheckSpecialNames
101337d7a5bcSJung-uk Kim  *
101437d7a5bcSJung-uk Kim  * PARAMETERS:  Node        - Node that represents the named object
101537d7a5bcSJung-uk Kim  *              Op          - Named object declaring this named object
101637d7a5bcSJung-uk Kim  *
101737d7a5bcSJung-uk Kim  * RETURN:      None
101837d7a5bcSJung-uk Kim  *
101937d7a5bcSJung-uk Kim  * DESCRIPTION: Check if certain named objects are declared in the incorrect
102037d7a5bcSJung-uk Kim  *              scope. Special named objects are listed in
102137d7a5bcSJung-uk Kim  *              AslGbl_SpecialNamedObjects and can only be declared at the root
1022*a009b7dcSJung-uk Kim  *              scope. _UID inside of a processor declaration must not be a
1023*a009b7dcSJung-uk Kim  *              string.
102437d7a5bcSJung-uk Kim  *
102537d7a5bcSJung-uk Kim  ******************************************************************************/
102637d7a5bcSJung-uk Kim 
102737d7a5bcSJung-uk Kim static void
102837d7a5bcSJung-uk Kim LdCheckSpecialNames (
102937d7a5bcSJung-uk Kim     ACPI_NAMESPACE_NODE     *Node,
103037d7a5bcSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
103137d7a5bcSJung-uk Kim {
103237d7a5bcSJung-uk Kim     UINT32                  i;
103337d7a5bcSJung-uk Kim 
103437d7a5bcSJung-uk Kim 
103537d7a5bcSJung-uk Kim     for (i = 0; i < MAX_SPECIAL_NAMES; i++)
103637d7a5bcSJung-uk Kim     {
103737d7a5bcSJung-uk Kim         if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
103837d7a5bcSJung-uk Kim             Node->Parent != AcpiGbl_RootNode)
103937d7a5bcSJung-uk Kim         {
104037d7a5bcSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
104137d7a5bcSJung-uk Kim             return;
104237d7a5bcSJung-uk Kim         }
104337d7a5bcSJung-uk Kim     }
1044*a009b7dcSJung-uk Kim 
1045*a009b7dcSJung-uk Kim     if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1046*a009b7dcSJung-uk Kim         Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1047*a009b7dcSJung-uk Kim         Node->Type == ACPI_TYPE_STRING)
1048*a009b7dcSJung-uk Kim     {
1049*a009b7dcSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1050*a009b7dcSJung-uk Kim     }
105137d7a5bcSJung-uk Kim }
105237d7a5bcSJung-uk Kim 
105337d7a5bcSJung-uk Kim 
105437d7a5bcSJung-uk Kim /*******************************************************************************
105537d7a5bcSJung-uk Kim  *
1056a9f12690SJung-uk Kim  * FUNCTION:    LdNamespace2Begin
1057a9f12690SJung-uk Kim  *
1058a9f12690SJung-uk Kim  * PARAMETERS:  ASL_WALK_CALLBACK
1059a9f12690SJung-uk Kim  *
1060a9f12690SJung-uk Kim  * RETURN:      Status
1061a9f12690SJung-uk Kim  *
1062a9f12690SJung-uk Kim  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1063a9f12690SJung-uk Kim  *              Second pass resolves some forward references.
1064a9f12690SJung-uk Kim  *
1065a9f12690SJung-uk Kim  * Notes:
1066a9f12690SJung-uk Kim  * Currently only needs to handle the Alias operator.
1067a9f12690SJung-uk Kim  * Could be used to allow forward references from the Scope() operator, but
1068a9f12690SJung-uk Kim  * the MS interpreter does not allow this, so this compiler does not either.
1069a9f12690SJung-uk Kim  *
1070a9f12690SJung-uk Kim  ******************************************************************************/
1071a9f12690SJung-uk Kim 
1072a9f12690SJung-uk Kim static ACPI_STATUS
1073a9f12690SJung-uk Kim LdNamespace2Begin (
1074a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
1075a9f12690SJung-uk Kim     UINT32                  Level,
1076a9f12690SJung-uk Kim     void                    *Context)
1077a9f12690SJung-uk Kim {
1078a9f12690SJung-uk Kim     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1079a9f12690SJung-uk Kim     ACPI_STATUS             Status;
1080a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
1081a9f12690SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType;
1082a9f12690SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
1083a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Arg;
1084a9f12690SJung-uk Kim     char                    *Path;
1085a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *TargetNode;
1086a9f12690SJung-uk Kim 
1087a9f12690SJung-uk Kim 
1088a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace2Begin);
1089a9f12690SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1090a9f12690SJung-uk Kim         Op, Op->Asl.ParseOpName));
1091a9f12690SJung-uk Kim 
1092a9f12690SJung-uk Kim 
1093a9f12690SJung-uk Kim     /* Ignore Ops with no namespace node */
1094a9f12690SJung-uk Kim 
1095a9f12690SJung-uk Kim     Node = Op->Asl.Node;
1096a9f12690SJung-uk Kim     if (!Node)
1097a9f12690SJung-uk Kim     {
1098a9f12690SJung-uk Kim         return (AE_OK);
1099a9f12690SJung-uk Kim     }
1100a9f12690SJung-uk Kim 
1101a9f12690SJung-uk Kim     /* Get the type to determine if we should push the scope */
1102a9f12690SJung-uk Kim 
1103a9f12690SJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
11045f9b24faSJung-uk Kim         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1105a9f12690SJung-uk Kim     {
1106a9f12690SJung-uk Kim         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1107a9f12690SJung-uk Kim     }
1108a9f12690SJung-uk Kim     else
1109a9f12690SJung-uk Kim     {
1110a9f12690SJung-uk Kim         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1111a9f12690SJung-uk Kim     }
1112a9f12690SJung-uk Kim 
1113a9f12690SJung-uk Kim     /* Push scope for Resource Templates */
1114a9f12690SJung-uk Kim 
1115a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1116a9f12690SJung-uk Kim     {
11175f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1118a9f12690SJung-uk Kim         {
1119a9f12690SJung-uk Kim             ForceNewScope = TRUE;
1120a9f12690SJung-uk Kim         }
1121a9f12690SJung-uk Kim     }
1122a9f12690SJung-uk Kim 
1123a9f12690SJung-uk Kim     /* Push the scope stack */
1124a9f12690SJung-uk Kim 
1125a9f12690SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1126a9f12690SJung-uk Kim     {
1127a9f12690SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1128a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1129a9f12690SJung-uk Kim         {
1130a9f12690SJung-uk Kim             return_ACPI_STATUS (Status);
1131a9f12690SJung-uk Kim         }
1132a9f12690SJung-uk Kim     }
1133a9f12690SJung-uk Kim 
1134a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1135a9f12690SJung-uk Kim     {
11364a38ee6dSJung-uk Kim         /*
11374a38ee6dSJung-uk Kim          * Complete the alias node by getting and saving the target node.
11384a38ee6dSJung-uk Kim          * First child is the alias target
11394a38ee6dSJung-uk Kim          */
1140a9f12690SJung-uk Kim         Arg = Op->Asl.Child;
1141a9f12690SJung-uk Kim 
1142a9f12690SJung-uk Kim         /* Get the target pathname */
1143a9f12690SJung-uk Kim 
1144a9f12690SJung-uk Kim         Path = Arg->Asl.Namepath;
1145a9f12690SJung-uk Kim         if (!Path)
1146a9f12690SJung-uk Kim         {
1147a9f12690SJung-uk Kim             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1148a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
1149a9f12690SJung-uk Kim             {
1150a9f12690SJung-uk Kim                 return (Status);
1151a9f12690SJung-uk Kim             }
1152a9f12690SJung-uk Kim         }
1153a9f12690SJung-uk Kim 
1154a9f12690SJung-uk Kim         /* Get the NS node associated with the target. It must exist. */
1155a9f12690SJung-uk Kim 
1156a9f12690SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1157a9f12690SJung-uk Kim             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1158a9f12690SJung-uk Kim             WalkState, &TargetNode);
1159a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1160a9f12690SJung-uk Kim         {
1161a9f12690SJung-uk Kim             if (Status == AE_NOT_FOUND)
1162a9f12690SJung-uk Kim             {
11634a38ee6dSJung-uk Kim                 /* Standalone NameSeg vs. NamePath */
1164a9f12690SJung-uk Kim 
1165278f0de6SJung-uk Kim                 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
11664a38ee6dSJung-uk Kim                 {
11674a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
11684a38ee6dSJung-uk Kim                         Arg->Asl.ExternalName);
11694a38ee6dSJung-uk Kim                 }
11704a38ee6dSJung-uk Kim                 else
11714a38ee6dSJung-uk Kim                 {
11724a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
11734a38ee6dSJung-uk Kim                         Arg->Asl.ExternalName);
11744a38ee6dSJung-uk Kim                 }
11754a38ee6dSJung-uk Kim 
11764a38ee6dSJung-uk Kim #if 0
11774a38ee6dSJung-uk Kim /*
11784a38ee6dSJung-uk Kim  * NOTE: Removed 10/2018 to enhance compiler error reporting. No
11794a38ee6dSJung-uk Kim  * regressions seen.
11804a38ee6dSJung-uk Kim  */
1181a9f12690SJung-uk Kim                 /*
1182a9f12690SJung-uk Kim                  * The name was not found, go ahead and create it.
1183a9f12690SJung-uk Kim                  * This prevents more errors later.
1184a9f12690SJung-uk Kim                  */
1185a9f12690SJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
11864a38ee6dSJung-uk Kim                     ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
11874a38ee6dSJung-uk Kim                     ACPI_NS_NO_UPSEARCH, WalkState, &Node);
11884a38ee6dSJung-uk Kim #endif
11894a38ee6dSJung-uk Kim                 return (Status);
11904a38ee6dSJung-uk Kim /* Removed: return (AE_OK)*/
1191a9f12690SJung-uk Kim             }
1192a9f12690SJung-uk Kim 
1193f556842eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
1194f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
1195a9f12690SJung-uk Kim             return (AE_OK);
1196a9f12690SJung-uk Kim         }
1197a9f12690SJung-uk Kim 
1198a9f12690SJung-uk Kim         /* Save the target node within the alias node */
1199a9f12690SJung-uk Kim 
1200a9f12690SJung-uk Kim         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1201a9f12690SJung-uk Kim     }
1202a9f12690SJung-uk Kim 
1203a9f12690SJung-uk Kim     return (AE_OK);
1204a9f12690SJung-uk Kim }
1205a9f12690SJung-uk Kim 
1206a9f12690SJung-uk Kim 
1207a9f12690SJung-uk Kim /*******************************************************************************
1208a9f12690SJung-uk Kim  *
1209a9f12690SJung-uk Kim  * FUNCTION:    LdCommonNamespaceEnd
121053289f6aSNate Lawson  *
121153289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
121253289f6aSNate Lawson  *
121353289f6aSNate Lawson  * RETURN:      Status
121453289f6aSNate Lawson  *
121553289f6aSNate Lawson  * DESCRIPTION: Ascending callback used during the loading of the namespace,
121653289f6aSNate Lawson  *              We only need to worry about managing the scope stack here.
121753289f6aSNate Lawson  *
121853289f6aSNate Lawson  ******************************************************************************/
121953289f6aSNate Lawson 
1220fba7fc7eSJung-uk Kim static ACPI_STATUS
1221a9f12690SJung-uk Kim LdCommonNamespaceEnd (
122253289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
122353289f6aSNate Lawson     UINT32                  Level,
122453289f6aSNate Lawson     void                    *Context)
122553289f6aSNate Lawson {
122653289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
122753289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
12281a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
122953289f6aSNate Lawson 
123053289f6aSNate Lawson 
1231a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
123253289f6aSNate Lawson 
123353289f6aSNate Lawson 
123453289f6aSNate Lawson     /* We are only interested in opcodes that have an associated name */
123553289f6aSNate Lawson 
123653289f6aSNate Lawson     if (!Op->Asl.Namepath)
123753289f6aSNate Lawson     {
123853289f6aSNate Lawson         return (AE_OK);
123953289f6aSNate Lawson     }
124053289f6aSNate Lawson 
124153289f6aSNate Lawson     /* Get the type to determine if we should pop the scope */
124253289f6aSNate Lawson 
124353289f6aSNate Lawson     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
12445f9b24faSJung-uk Kim         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
124553289f6aSNate Lawson     {
124653289f6aSNate Lawson         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
124753289f6aSNate Lawson 
124853289f6aSNate Lawson         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
124953289f6aSNate Lawson     }
125053289f6aSNate Lawson     else
125153289f6aSNate Lawson     {
125253289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
125353289f6aSNate Lawson     }
125453289f6aSNate Lawson 
12551a39cfb0SJung-uk Kim     /* Pop scope that was pushed for Resource Templates */
12561a39cfb0SJung-uk Kim 
12571a39cfb0SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
12581a39cfb0SJung-uk Kim     {
12595f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
12601a39cfb0SJung-uk Kim         {
12611a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
12621a39cfb0SJung-uk Kim         }
12631a39cfb0SJung-uk Kim     }
12641a39cfb0SJung-uk Kim 
126553289f6aSNate Lawson     /* Pop the scope stack */
126653289f6aSNate Lawson 
12671a39cfb0SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
126853289f6aSNate Lawson     {
126953289f6aSNate Lawson         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
127053289f6aSNate Lawson             "(%s): Popping scope for Op [%s] %p\n",
127153289f6aSNate Lawson             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
127253289f6aSNate Lawson 
1273fba7fc7eSJung-uk Kim         (void) AcpiDsScopeStackPop (WalkState);
127453289f6aSNate Lawson     }
127553289f6aSNate Lawson 
127653289f6aSNate Lawson     return (AE_OK);
127753289f6aSNate Lawson }
1278