xref: /freebsd-src/sys/contrib/dev/acpica/compiler/aslload.c (revision f425b8be7e7a38e47677d7bd68819dccbdcc3134)
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  *
11*f425b8beSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2020, 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;
276*f425b8beSJung-uk Kim     char                    *ExternalPath;
27753289f6aSNate Lawson 
27853289f6aSNate Lawson 
2799ad8b64eSJung-uk Kim     SourceRegion = UtGetArg (Op, 0);
2809ad8b64eSJung-uk Kim     if (SourceRegion)
2819ad8b64eSJung-uk Kim     {
2829ad8b64eSJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo,
283*f425b8beSJung-uk Kim             SourceRegion->Asl.Value.String, AmlType, ACPI_IMODE_EXECUTE,
284*f425b8beSJung-uk Kim             ACPI_NS_SEARCH_PARENT | 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                      */
360*f425b8beSJung-uk Kim                     ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
361*f425b8beSJung-uk Kim 
362f9a6772eSJung-uk Kim                     AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
363*f425b8beSJung-uk Kim                         ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
364*f425b8beSJung-uk Kim                         ExternalPath);
365*f425b8beSJung-uk Kim 
366*f425b8beSJung-uk Kim                     if (ExternalPath)
367*f425b8beSJung-uk Kim                     {
368*f425b8beSJung-uk Kim                         ACPI_FREE (ExternalPath);
369*f425b8beSJung-uk Kim                     }
37053289f6aSNate Lawson                 }
371af051161SJung-uk Kim             }
37253289f6aSNate Lawson             else
37353289f6aSNate Lawson             {
37453289f6aSNate Lawson                 Child->Asl.Node = Node;
375fba7fc7eSJung-uk Kim                 Node->Op = Child;
37653289f6aSNate Lawson             }
37753289f6aSNate Lawson             break;
37853289f6aSNate Lawson         }
3793f0275a0SJung-uk Kim 
38053289f6aSNate Lawson         Child = Child->Asl.Next;
38153289f6aSNate Lawson     }
3823f0275a0SJung-uk Kim 
38353289f6aSNate Lawson     return (AE_OK);
38453289f6aSNate Lawson }
38553289f6aSNate Lawson 
38653289f6aSNate Lawson 
38753289f6aSNate Lawson /*******************************************************************************
38853289f6aSNate Lawson  *
38953289f6aSNate Lawson  * FUNCTION:    LdLoadResourceElements
39053289f6aSNate Lawson  *
39153289f6aSNate Lawson  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
39253289f6aSNate Lawson  *              WalkState       - Current walk state
39353289f6aSNate Lawson  *
39453289f6aSNate Lawson  * RETURN:      Status
39553289f6aSNate Lawson  *
39653289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the resource descriptor (children
39753289f6aSNate Lawson  *              of the parent) into the namespace.
39853289f6aSNate Lawson  *
39953289f6aSNate Lawson  * NOTE: In the real AML namespace, these named elements never exist. But
40053289f6aSNate Lawson  *       we simply use the namespace here as a symbol table so we can look
40153289f6aSNate Lawson  *       them up as they are referenced.
40253289f6aSNate Lawson  *
40353289f6aSNate Lawson  ******************************************************************************/
40453289f6aSNate Lawson 
405fba7fc7eSJung-uk Kim static ACPI_STATUS
40653289f6aSNate Lawson LdLoadResourceElements (
40753289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
40853289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
40953289f6aSNate Lawson {
41053289f6aSNate Lawson     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
41153289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
41253289f6aSNate Lawson     ACPI_STATUS             Status;
413*f425b8beSJung-uk Kim     char                    *ExternalPath;
41453289f6aSNate Lawson 
41553289f6aSNate Lawson 
41653289f6aSNate Lawson     /*
417fba7fc7eSJung-uk Kim      * Enter the resource name into the namespace. Name must not already exist.
418fba7fc7eSJung-uk Kim      * This opens a scope, so later field names are guaranteed to be new/unique.
41953289f6aSNate Lawson      */
42053289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
421fba7fc7eSJung-uk Kim         ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
422fba7fc7eSJung-uk Kim         ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
42353289f6aSNate Lawson         WalkState, &Node);
42453289f6aSNate Lawson     if (ACPI_FAILURE (Status))
42553289f6aSNate Lawson     {
426fba7fc7eSJung-uk Kim         if (Status == AE_ALREADY_EXISTS)
427fba7fc7eSJung-uk Kim         {
428fba7fc7eSJung-uk Kim             /* Actual node causing the error was saved in ParentMethod */
429fba7fc7eSJung-uk Kim 
430*f425b8beSJung-uk Kim             ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
431*f425b8beSJung-uk Kim 
43267d9aa44SJung-uk Kim             AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
43367d9aa44SJung-uk Kim                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
434*f425b8beSJung-uk Kim                 ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
435*f425b8beSJung-uk Kim                 ExternalPath);
436*f425b8beSJung-uk Kim 
437*f425b8beSJung-uk Kim             if (ExternalPath)
438*f425b8beSJung-uk Kim             {
439*f425b8beSJung-uk Kim                 ACPI_FREE (ExternalPath);
440*f425b8beSJung-uk Kim             }
441fba7fc7eSJung-uk Kim             return (AE_OK);
442fba7fc7eSJung-uk Kim         }
44353289f6aSNate Lawson         return (Status);
44453289f6aSNate Lawson     }
44553289f6aSNate Lawson 
4461a39cfb0SJung-uk Kim     Node->Value = (UINT32) Op->Asl.Value.Integer;
4471a39cfb0SJung-uk Kim     Node->Op = Op;
448d6dd1baeSJung-uk Kim     Op->Asl.Node = Node;
4491a39cfb0SJung-uk Kim 
45053289f6aSNate Lawson     /*
45153289f6aSNate Lawson      * Now enter the predefined fields, for easy lookup when referenced
45253289f6aSNate Lawson      * by the source ASL
45353289f6aSNate Lawson      */
45453289f6aSNate Lawson     InitializerOp = ASL_GET_CHILD_NODE (Op);
45553289f6aSNate Lawson     while (InitializerOp)
45653289f6aSNate Lawson     {
45753289f6aSNate Lawson         if (InitializerOp->Asl.ExternalName)
45853289f6aSNate Lawson         {
45953289f6aSNate Lawson             Status = AcpiNsLookup (WalkState->ScopeInfo,
46053289f6aSNate Lawson                 InitializerOp->Asl.ExternalName,
4614a38ee6dSJung-uk Kim                 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
4624a38ee6dSJung-uk Kim                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
46353289f6aSNate Lawson             if (ACPI_FAILURE (Status))
46453289f6aSNate Lawson             {
46553289f6aSNate Lawson                 return (Status);
46653289f6aSNate Lawson             }
46753289f6aSNate Lawson 
46853289f6aSNate Lawson             /*
4693f0275a0SJung-uk Kim              * Store the field offset and length in the namespace node
4703f0275a0SJung-uk Kim              * so it can be used when the field is referenced
47153289f6aSNate Lawson              */
4723f0275a0SJung-uk Kim             Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
4733f0275a0SJung-uk Kim             Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
47453289f6aSNate Lawson             InitializerOp->Asl.Node = Node;
475fba7fc7eSJung-uk Kim             Node->Op = InitializerOp;
47653289f6aSNate Lawson         }
4773f0275a0SJung-uk Kim 
47853289f6aSNate Lawson         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
47953289f6aSNate Lawson     }
48053289f6aSNate Lawson 
48153289f6aSNate Lawson     return (AE_OK);
48253289f6aSNate Lawson }
48353289f6aSNate Lawson 
48453289f6aSNate Lawson 
48553289f6aSNate Lawson /*******************************************************************************
48653289f6aSNate Lawson  *
48753289f6aSNate Lawson  * FUNCTION:    LdNamespace1Begin
48853289f6aSNate Lawson  *
48953289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
49053289f6aSNate Lawson  *
49153289f6aSNate Lawson  * RETURN:      Status
49253289f6aSNate Lawson  *
49353289f6aSNate Lawson  * DESCRIPTION: Descending callback used during the parse tree walk. If this
49453289f6aSNate Lawson  *              is a named AML opcode, enter into the namespace
49553289f6aSNate Lawson  *
49653289f6aSNate Lawson  ******************************************************************************/
49753289f6aSNate Lawson 
498fba7fc7eSJung-uk Kim static ACPI_STATUS
49953289f6aSNate Lawson LdNamespace1Begin (
50053289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
50153289f6aSNate Lawson     UINT32                  Level,
50253289f6aSNate Lawson     void                    *Context)
50353289f6aSNate Lawson {
50453289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
50553289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
506f8146b88SJung-uk Kim     ACPI_PARSE_OBJECT       *MethodOp;
50753289f6aSNate Lawson     ACPI_STATUS             Status;
50853289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
50953289f6aSNate Lawson     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
51053289f6aSNate Lawson     char                    *Path;
51153289f6aSNate Lawson     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
51253289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Arg;
51353289f6aSNate Lawson     UINT32                  i;
5141a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
515835b56bfSJung-uk Kim     const ACPI_OPCODE_INFO  *OpInfo;
516835b56bfSJung-uk Kim     ACPI_PARSE_OBJECT       *ParentOp;
517*f425b8beSJung-uk Kim     char                    *ExternalPath;
51853289f6aSNate Lawson 
51953289f6aSNate Lawson 
5201a39cfb0SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace1Begin);
521835b56bfSJung-uk Kim 
522835b56bfSJung-uk Kim 
52353289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
52453289f6aSNate Lawson         Op, Op->Asl.ParseOpName));
52553289f6aSNate Lawson 
52653289f6aSNate Lawson     /*
52753289f6aSNate Lawson      * We are only interested in opcodes that have an associated name
52853289f6aSNate Lawson      * (or multiple names)
52953289f6aSNate Lawson      */
53053289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
53153289f6aSNate Lawson     {
5322e578044SJung-uk Kim     case AML_INDEX_FIELD_OP:
53337d7a5bcSJung-uk Kim 
53437d7a5bcSJung-uk Kim         Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
53537d7a5bcSJung-uk Kim         return (Status);
53637d7a5bcSJung-uk Kim 
53737d7a5bcSJung-uk Kim     case AML_BANK_FIELD_OP:
53853289f6aSNate Lawson     case AML_FIELD_OP:
53953289f6aSNate Lawson 
54037d7a5bcSJung-uk Kim         Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
5419ad8b64eSJung-uk Kim         return (Status);
54253289f6aSNate Lawson 
543313a0c13SJung-uk Kim     case AML_INT_CONNECTION_OP:
544313a0c13SJung-uk Kim 
545313a0c13SJung-uk Kim         if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
546313a0c13SJung-uk Kim         {
547313a0c13SJung-uk Kim             break;
548313a0c13SJung-uk Kim         }
549313a0c13SJung-uk Kim 
550a009b7dcSJung-uk Kim         Arg = Op->Asl.Child;
551313a0c13SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
552313a0c13SJung-uk Kim             ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
553313a0c13SJung-uk Kim             WalkState, &Node);
554313a0c13SJung-uk Kim         if (ACPI_FAILURE (Status))
555313a0c13SJung-uk Kim         {
556313a0c13SJung-uk Kim             break;
557313a0c13SJung-uk Kim         }
558313a0c13SJung-uk Kim 
559313a0c13SJung-uk Kim         break;
560313a0c13SJung-uk Kim 
56153289f6aSNate Lawson     default:
56253289f6aSNate Lawson 
56353289f6aSNate Lawson         /* All other opcodes go below */
564a9d8d09cSJung-uk Kim 
56553289f6aSNate Lawson         break;
56653289f6aSNate Lawson     }
56753289f6aSNate Lawson 
56853289f6aSNate Lawson     /* Check if this object has already been installed in the namespace */
56953289f6aSNate Lawson 
57053289f6aSNate Lawson     if (Op->Asl.Node)
57153289f6aSNate Lawson     {
57253289f6aSNate Lawson         return (AE_OK);
57353289f6aSNate Lawson     }
57453289f6aSNate Lawson 
575835b56bfSJung-uk Kim     /* Check for a possible illegal forward reference */
576835b56bfSJung-uk Kim 
577835b56bfSJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
578835b56bfSJung-uk Kim         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
579835b56bfSJung-uk Kim     {
580835b56bfSJung-uk Kim         /*
581835b56bfSJung-uk Kim          * Op->Asl.Namepath will be NULL for these opcodes.
582835b56bfSJung-uk Kim          * These opcodes are guaranteed to have a parent.
583835b56bfSJung-uk Kim          * Examine the parent opcode.
584835b56bfSJung-uk Kim          */
585835b56bfSJung-uk Kim         ParentOp = Op->Asl.Parent;
586835b56bfSJung-uk Kim         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
587835b56bfSJung-uk Kim 
588835b56bfSJung-uk Kim         /*
589835b56bfSJung-uk Kim          * Exclude all operators that actually declare a new name:
590835b56bfSJung-uk Kim          *      Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
591835b56bfSJung-uk Kim          * We only want references to named objects:
592835b56bfSJung-uk Kim          *      Store (2, WXYZ) -> Attempt to resolve the name
593835b56bfSJung-uk Kim          */
5949ad8b64eSJung-uk Kim         if (OpInfo->Class == AML_CLASS_NAMED_OBJECT)
595835b56bfSJung-uk Kim         {
596835b56bfSJung-uk Kim             return (AE_OK);
597835b56bfSJung-uk Kim         }
598835b56bfSJung-uk Kim 
599835b56bfSJung-uk Kim         /*
600835b56bfSJung-uk Kim          * Check if the referenced object exists at this point during
601835b56bfSJung-uk Kim          * the load:
602835b56bfSJung-uk Kim          * 1) If it exists, then this cannot be a forward reference.
603835b56bfSJung-uk Kim          * 2) If it does not exist, it could be a forward reference or
604835b56bfSJung-uk Kim          * it truly does not exist (and no external declaration).
605835b56bfSJung-uk Kim          */
606835b56bfSJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo,
607835b56bfSJung-uk Kim             Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
608835b56bfSJung-uk Kim             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
609835b56bfSJung-uk Kim             WalkState, &Node);
610835b56bfSJung-uk Kim         if (Status == AE_NOT_FOUND)
611835b56bfSJung-uk Kim         {
612835b56bfSJung-uk Kim             /*
613cd6518c7SJung-uk Kim              * This is either a forward reference or the object truly
614835b56bfSJung-uk Kim              * does not exist. The two cases can only be differentiated
615835b56bfSJung-uk Kim              * during the cross-reference stage later. Mark the Op/Name
616835b56bfSJung-uk Kim              * as not-found for now to indicate the need for further
617835b56bfSJung-uk Kim              * processing.
618835b56bfSJung-uk Kim              *
619835b56bfSJung-uk Kim              * Special case: Allow forward references from elements of
620835b56bfSJung-uk Kim              * Package objects. This provides compatibility with other
621835b56bfSJung-uk Kim              * ACPI implementations. To correctly implement this, the
622835b56bfSJung-uk Kim              * ACPICA table load defers package resolution until the entire
623835b56bfSJung-uk Kim              * namespace has been loaded.
624835b56bfSJung-uk Kim              */
625835b56bfSJung-uk Kim             if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
626835b56bfSJung-uk Kim                 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
627835b56bfSJung-uk Kim             {
628835b56bfSJung-uk Kim                 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
629835b56bfSJung-uk Kim             }
630835b56bfSJung-uk Kim 
631835b56bfSJung-uk Kim             return (AE_OK);
632835b56bfSJung-uk Kim         }
633835b56bfSJung-uk Kim 
634835b56bfSJung-uk Kim         return (Status);
635835b56bfSJung-uk Kim     }
636835b56bfSJung-uk Kim 
63753289f6aSNate Lawson     Path = Op->Asl.Namepath;
63853289f6aSNate Lawson     if (!Path)
63953289f6aSNate Lawson     {
64053289f6aSNate Lawson         return (AE_OK);
64153289f6aSNate Lawson     }
64253289f6aSNate Lawson 
64353289f6aSNate Lawson     /* Map the raw opcode into an internal object type */
64453289f6aSNate Lawson 
64553289f6aSNate Lawson     switch (Op->Asl.ParseOpcode)
64653289f6aSNate Lawson     {
64753289f6aSNate Lawson     case PARSEOP_NAME:
64853289f6aSNate Lawson 
64953289f6aSNate Lawson         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
65053289f6aSNate Lawson         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
65153289f6aSNate Lawson 
6521a39cfb0SJung-uk Kim         /*
6531a39cfb0SJung-uk Kim          * If this name refers to a ResourceTemplate, we will need to open
6541a39cfb0SJung-uk Kim          * a new scope so that the resource subfield names can be entered into
6551a39cfb0SJung-uk Kim          * the namespace underneath this name
6561a39cfb0SJung-uk Kim          */
6575f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
6581a39cfb0SJung-uk Kim         {
6591a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
6601a39cfb0SJung-uk Kim         }
6611a39cfb0SJung-uk Kim 
66253289f6aSNate Lawson         /* Get the data type associated with the named object, not the name itself */
66353289f6aSNate Lawson 
66453289f6aSNate Lawson         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
66553289f6aSNate Lawson 
66653289f6aSNate Lawson         ObjectType = 1;
66753289f6aSNate Lawson         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
66853289f6aSNate Lawson         {
66953289f6aSNate Lawson             ObjectType++;
67053289f6aSNate Lawson         }
67153289f6aSNate Lawson         break;
67253289f6aSNate Lawson 
67353289f6aSNate Lawson     case PARSEOP_EXTERNAL:
67453289f6aSNate Lawson         /*
67553289f6aSNate Lawson          * "External" simply enters a name and type into the namespace.
67653289f6aSNate Lawson          * We must be careful to not open a new scope, however, no matter
67753289f6aSNate Lawson          * what type the external name refers to (e.g., a method)
67853289f6aSNate Lawson          *
67953289f6aSNate Lawson          * first child is name, next child is ObjectType
68053289f6aSNate Lawson          */
68153289f6aSNate Lawson         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
68253289f6aSNate Lawson         ObjectType = ACPI_TYPE_ANY;
68353289f6aSNate Lawson 
6841a39cfb0SJung-uk Kim         /*
6851a39cfb0SJung-uk Kim          * We will mark every new node along the path as "External". This
6861a39cfb0SJung-uk Kim          * allows some or all of the nodes to be created later in the ASL
6871a39cfb0SJung-uk Kim          * code. Handles cases like this:
6881a39cfb0SJung-uk Kim          *
6891a39cfb0SJung-uk Kim          *   External (\_SB_.PCI0.ABCD, IntObj)
6901a39cfb0SJung-uk Kim          *   Scope (_SB_)
6911a39cfb0SJung-uk Kim          *   {
6921a39cfb0SJung-uk Kim          *       Device (PCI0)
6931a39cfb0SJung-uk Kim          *       {
6941a39cfb0SJung-uk Kim          *       }
6951a39cfb0SJung-uk Kim          *   }
6961a39cfb0SJung-uk Kim          *   Method (X)
6971a39cfb0SJung-uk Kim          *   {
6981a39cfb0SJung-uk Kim          *       Store (\_SB_.PCI0.ABCD, Local0)
6991a39cfb0SJung-uk Kim          *   }
7001a39cfb0SJung-uk Kim          */
7011a39cfb0SJung-uk Kim         Flags |= ACPI_NS_EXTERNAL;
7021a39cfb0SJung-uk Kim         break;
70353289f6aSNate Lawson 
70453289f6aSNate Lawson     case PARSEOP_DEFAULT_ARG:
70553289f6aSNate Lawson 
7065f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
70753289f6aSNate Lawson         {
70853289f6aSNate Lawson             Status = LdLoadResourceElements (Op, WalkState);
7099a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
71053289f6aSNate Lawson         }
71153289f6aSNate Lawson 
71253289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
71353289f6aSNate Lawson         break;
71453289f6aSNate Lawson 
71553289f6aSNate Lawson     case PARSEOP_SCOPE:
71653289f6aSNate Lawson         /*
71753289f6aSNate Lawson          * The name referenced by Scope(Name) must already exist at this point.
71853289f6aSNate Lawson          * In other words, forward references for Scope() are not supported.
71953289f6aSNate Lawson          * The only real reason for this is that the MS interpreter cannot
72053289f6aSNate Lawson          * handle this case. Perhaps someday this case can go away.
72153289f6aSNate Lawson          */
72253289f6aSNate Lawson         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
7234a38ee6dSJung-uk Kim             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
72453289f6aSNate Lawson         if (ACPI_FAILURE (Status))
72553289f6aSNate Lawson         {
72653289f6aSNate Lawson             if (Status == AE_NOT_FOUND)
72753289f6aSNate Lawson             {
72853289f6aSNate Lawson                 /* The name was not found, go ahead and create it */
72953289f6aSNate Lawson 
730fba7fc7eSJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
7314a38ee6dSJung-uk Kim                     ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
7324a38ee6dSJung-uk Kim                     Flags, WalkState, &Node);
73379c6d946SJung-uk Kim                 if (ACPI_FAILURE (Status))
73479c6d946SJung-uk Kim                 {
73579c6d946SJung-uk Kim                     return_ACPI_STATUS (Status);
73679c6d946SJung-uk Kim                 }
73753289f6aSNate Lawson 
7384a38ee6dSJung-uk Kim                 /* However, this is an error -- operand to Scope must exist */
7394a38ee6dSJung-uk Kim 
740278f0de6SJung-uk Kim                 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
7414a38ee6dSJung-uk Kim                 {
742fba7fc7eSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
743fba7fc7eSJung-uk Kim                         Op->Asl.ExternalName);
7444a38ee6dSJung-uk Kim                 }
7454a38ee6dSJung-uk Kim                 else
7464a38ee6dSJung-uk Kim                 {
7474a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
748fba7fc7eSJung-uk Kim                         Op->Asl.ExternalName);
7494a38ee6dSJung-uk Kim                 }
7504a38ee6dSJung-uk Kim 
75153289f6aSNate Lawson                 goto FinishNode;
75253289f6aSNate Lawson             }
75353289f6aSNate Lawson 
754f556842eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
755f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
756f556842eSJung-uk Kim 
7579a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
75853289f6aSNate Lawson         }
759f8146b88SJung-uk Kim         else /* Status AE_OK */
760f8146b88SJung-uk Kim         {
761f8146b88SJung-uk Kim             /*
762f8146b88SJung-uk Kim              * Do not allow references to external scopes from the DSDT.
763f8146b88SJung-uk Kim              * This is because the DSDT is always loaded first, and the
764f8146b88SJung-uk Kim              * external reference cannot be resolved -- causing a runtime
765f8146b88SJung-uk Kim              * error because Scope() must be resolved immediately.
766f8146b88SJung-uk Kim              * 10/2015.
767f8146b88SJung-uk Kim              */
768f8146b88SJung-uk Kim             if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
769278f0de6SJung-uk Kim                 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
770f8146b88SJung-uk Kim             {
771f8146b88SJung-uk Kim                 /* However, allowed if the reference is within a method */
772f8146b88SJung-uk Kim 
773f8146b88SJung-uk Kim                 MethodOp = Op->Asl.Parent;
774f8146b88SJung-uk Kim                 while (MethodOp &&
775f8146b88SJung-uk Kim                       (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
776f8146b88SJung-uk Kim                 {
777f8146b88SJung-uk Kim                     MethodOp = MethodOp->Asl.Parent;
778f8146b88SJung-uk Kim                 }
779f8146b88SJung-uk Kim 
780f8146b88SJung-uk Kim                 if (!MethodOp)
781f8146b88SJung-uk Kim                 {
782f8146b88SJung-uk Kim                     /* Not in a control method, error */
783f8146b88SJung-uk Kim 
784f8146b88SJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
785f8146b88SJung-uk Kim                 }
786f8146b88SJung-uk Kim             }
787f8146b88SJung-uk Kim         }
78853289f6aSNate Lawson 
78953289f6aSNate Lawson         /* We found a node with this name, now check the type */
79053289f6aSNate Lawson 
79153289f6aSNate Lawson         switch (Node->Type)
79253289f6aSNate Lawson         {
79353289f6aSNate Lawson         case ACPI_TYPE_LOCAL_SCOPE:
79453289f6aSNate Lawson         case ACPI_TYPE_DEVICE:
79553289f6aSNate Lawson         case ACPI_TYPE_POWER:
79653289f6aSNate Lawson         case ACPI_TYPE_PROCESSOR:
79753289f6aSNate Lawson         case ACPI_TYPE_THERMAL:
79853289f6aSNate Lawson 
79953289f6aSNate Lawson             /* These are acceptable types - they all open a new scope */
80053289f6aSNate Lawson             break;
80153289f6aSNate Lawson 
80253289f6aSNate Lawson         case ACPI_TYPE_INTEGER:
80353289f6aSNate Lawson         case ACPI_TYPE_STRING:
80453289f6aSNate Lawson         case ACPI_TYPE_BUFFER:
80553289f6aSNate Lawson             /*
806fba7fc7eSJung-uk Kim              * These types we will allow, but we will change the type.
807fba7fc7eSJung-uk Kim              * This enables some existing code of the form:
80853289f6aSNate Lawson              *
80953289f6aSNate Lawson              *  Name (DEB, 0)
81053289f6aSNate Lawson              *  Scope (DEB) { ... }
81153289f6aSNate Lawson              *
81253289f6aSNate Lawson              * Which is used to workaround the fact that the MS interpreter
81353289f6aSNate Lawson              * does not allow Scope() forward references.
81453289f6aSNate Lawson              */
8156f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
81653289f6aSNate Lawson                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
8176f1f1a63SJung-uk Kim             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
81853289f6aSNate Lawson 
819fba7fc7eSJung-uk Kim             /* Switch the type to scope, open the new scope */
820fba7fc7eSJung-uk Kim 
821e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
822fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
823fba7fc7eSJung-uk Kim                 WalkState);
824e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
825e0ef747bSNate Lawson             {
826e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
827e0ef747bSNate Lawson             }
82853289f6aSNate Lawson             break;
82953289f6aSNate Lawson 
83053289f6aSNate Lawson         default:
83153289f6aSNate Lawson 
832fba7fc7eSJung-uk Kim             /* All other types are an error */
833fba7fc7eSJung-uk Kim 
8346f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
835fba7fc7eSJung-uk Kim                 AcpiUtGetTypeName (Node->Type));
8366f1f1a63SJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
83753289f6aSNate Lawson 
83853289f6aSNate Lawson             /*
83953289f6aSNate Lawson              * However, switch the type to be an actual scope so
84053289f6aSNate Lawson              * that compilation can continue without generating a whole
841e0ef747bSNate Lawson              * cascade of additional errors. Open the new scope.
84253289f6aSNate Lawson              */
843e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
844fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
845fba7fc7eSJung-uk Kim                 WalkState);
846e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
847e0ef747bSNate Lawson             {
848e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
849e0ef747bSNate Lawson             }
85053289f6aSNate Lawson             break;
85153289f6aSNate Lawson         }
85253289f6aSNate Lawson 
85353289f6aSNate Lawson         Status = AE_OK;
85453289f6aSNate Lawson         goto FinishNode;
85553289f6aSNate Lawson 
85653289f6aSNate Lawson     default:
85753289f6aSNate Lawson 
85853289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
85953289f6aSNate Lawson         break;
86053289f6aSNate Lawson     }
86153289f6aSNate Lawson 
86253289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
86353289f6aSNate Lawson         Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
86453289f6aSNate Lawson 
86553289f6aSNate Lawson     /* The name must not already exist */
86653289f6aSNate Lawson 
86753289f6aSNate Lawson     Flags |= ACPI_NS_ERROR_IF_FOUND;
86853289f6aSNate Lawson 
86953289f6aSNate Lawson     /*
8704a38ee6dSJung-uk Kim      * For opcodes that enter new names into the namespace,
8714a38ee6dSJung-uk Kim      * all prefix NameSegs must exist.
8724a38ee6dSJung-uk Kim      */
8734a38ee6dSJung-uk Kim     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
8744a38ee6dSJung-uk Kim     if (((WalkState->OpInfo->Flags & AML_NAMED) ||
8754a38ee6dSJung-uk Kim         (WalkState->OpInfo->Flags & AML_CREATE)) &&
8764a38ee6dSJung-uk Kim         (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
8774a38ee6dSJung-uk Kim     {
8784a38ee6dSJung-uk Kim         Flags |= ACPI_NS_PREFIX_MUST_EXIST;
8794a38ee6dSJung-uk Kim     }
8804a38ee6dSJung-uk Kim 
8814a38ee6dSJung-uk Kim     /*
88253289f6aSNate Lawson      * Enter the named type into the internal namespace. We enter the name
883fba7fc7eSJung-uk Kim      * as we go downward in the parse tree. Any necessary subobjects that
884fba7fc7eSJung-uk Kim      * involve arguments to the opcode must be created as we go back up the
885fba7fc7eSJung-uk Kim      * parse tree later.
88653289f6aSNate Lawson      */
88753289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
8881a39cfb0SJung-uk Kim         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
88953289f6aSNate Lawson     if (ACPI_FAILURE (Status))
89053289f6aSNate Lawson     {
89153289f6aSNate Lawson         if (Status == AE_ALREADY_EXISTS)
89253289f6aSNate Lawson         {
89353289f6aSNate Lawson             /* The name already exists in this scope */
89453289f6aSNate Lawson 
89553289f6aSNate Lawson             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
89653289f6aSNate Lawson             {
8971a39cfb0SJung-uk Kim                 /* Allow multiple references to the same scope */
8981a39cfb0SJung-uk Kim 
89953289f6aSNate Lawson                 Node->Type = (UINT8) ObjectType;
90053289f6aSNate Lawson                 Status = AE_OK;
90153289f6aSNate Lawson             }
902a9f12690SJung-uk Kim             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
903a9f12690SJung-uk Kim                      (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
9041a39cfb0SJung-uk Kim             {
9051a39cfb0SJung-uk Kim                 /*
9061a39cfb0SJung-uk Kim                  * Allow one create on an object or segment that was
907da9b0901SJung-uk Kim                  * previously declared External
9081a39cfb0SJung-uk Kim                  */
9091a39cfb0SJung-uk Kim                 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
9101a39cfb0SJung-uk Kim                 Node->Type = (UINT8) ObjectType;
9111a39cfb0SJung-uk Kim 
9121a39cfb0SJung-uk Kim                 /* Just retyped a node, probably will need to open a scope */
9131a39cfb0SJung-uk Kim 
9141a39cfb0SJung-uk Kim                 if (AcpiNsOpensScope (ObjectType))
9151a39cfb0SJung-uk Kim                 {
9161a39cfb0SJung-uk Kim                     Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
9171a39cfb0SJung-uk Kim                     if (ACPI_FAILURE (Status))
9181a39cfb0SJung-uk Kim                     {
9191a39cfb0SJung-uk Kim                         return_ACPI_STATUS (Status);
9201a39cfb0SJung-uk Kim                     }
9211a39cfb0SJung-uk Kim                 }
922f8146b88SJung-uk Kim 
9231a39cfb0SJung-uk Kim                 Status = AE_OK;
9241a39cfb0SJung-uk Kim             }
925f8146b88SJung-uk Kim             else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
926f8146b88SJung-uk Kim                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
927f8146b88SJung-uk Kim             {
928f8146b88SJung-uk Kim                 /*
929f8146b88SJung-uk Kim                  * Allow externals in same scope as the definition of the
930f8146b88SJung-uk Kim                  * actual object. Similar to C. Allows multiple definition
931da9b0901SJung-uk Kim                  * blocks that refer to each other in the same file.
932f8146b88SJung-uk Kim                  */
933f8146b88SJung-uk Kim                 Status = AE_OK;
934f8146b88SJung-uk Kim             }
935f8146b88SJung-uk Kim             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
936f8146b88SJung-uk Kim                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
937f8146b88SJung-uk Kim                      (ObjectType == ACPI_TYPE_ANY))
938f8146b88SJung-uk Kim             {
939da9b0901SJung-uk Kim                 /* Allow update of externals of unknown type. */
940f8146b88SJung-uk Kim 
941f8146b88SJung-uk Kim                 if (AcpiNsOpensScope (ActualObjectType))
942f8146b88SJung-uk Kim                 {
943f8146b88SJung-uk Kim                     Node->Type = (UINT8) ActualObjectType;
944f8146b88SJung-uk Kim                     Status = AE_OK;
945f8146b88SJung-uk Kim                 }
946f8146b88SJung-uk Kim                 else
947f8146b88SJung-uk Kim                 {
9486f1f1a63SJung-uk Kim                     sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
949f8146b88SJung-uk Kim                         AcpiUtGetTypeName (Node->Type));
9506f1f1a63SJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
951f8146b88SJung-uk Kim                     return_ACPI_STATUS (AE_OK);
952f8146b88SJung-uk Kim                 }
953f8146b88SJung-uk Kim             }
95453289f6aSNate Lawson             else
95553289f6aSNate Lawson             {
9561a39cfb0SJung-uk Kim                 /* Valid error, object already exists */
9571a39cfb0SJung-uk Kim 
958*f425b8beSJung-uk Kim                 ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
959*f425b8beSJung-uk Kim 
96067d9aa44SJung-uk Kim                 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
961*f425b8beSJung-uk Kim                     ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
962*f425b8beSJung-uk Kim                     ExternalPath);
963*f425b8beSJung-uk Kim 
964*f425b8beSJung-uk Kim                 if (ExternalPath)
965*f425b8beSJung-uk Kim                 {
966*f425b8beSJung-uk Kim                     ACPI_FREE (ExternalPath);
967*f425b8beSJung-uk Kim                 }
9689a179dd8SJung-uk Kim                 return_ACPI_STATUS (AE_OK);
96953289f6aSNate Lawson             }
97053289f6aSNate Lawson         }
9714a38ee6dSJung-uk Kim         else if (AE_NOT_FOUND)
9724a38ee6dSJung-uk Kim         {
9734a38ee6dSJung-uk Kim             /*
9744a38ee6dSJung-uk Kim              * One or more prefix NameSegs of the NamePath do not exist
9754a38ee6dSJung-uk Kim              * (all of them must exist). Attempt to continue compilation
9764a38ee6dSJung-uk Kim              * by setting the current scope to the root.
9774a38ee6dSJung-uk Kim              */
9784a38ee6dSJung-uk Kim             Node = AcpiGbl_RootNode;
9794a38ee6dSJung-uk Kim             Status = AE_OK;
9804a38ee6dSJung-uk Kim         }
98153289f6aSNate Lawson         else
98253289f6aSNate Lawson         {
9834a38ee6dSJung-uk Kim             /* Flag all other errors as coming from the ACPICA core */
9844a38ee6dSJung-uk Kim 
985fba7fc7eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
986f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
9879a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
98853289f6aSNate Lawson         }
98953289f6aSNate Lawson     }
99053289f6aSNate Lawson 
99137d7a5bcSJung-uk Kim     /* Check special names like _WAK and _PTS */
99237d7a5bcSJung-uk Kim 
99337d7a5bcSJung-uk Kim     LdCheckSpecialNames (Node, Op);
99437d7a5bcSJung-uk Kim 
9951a39cfb0SJung-uk Kim     if (ForceNewScope)
9961a39cfb0SJung-uk Kim     {
9971a39cfb0SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
9981a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
9991a39cfb0SJung-uk Kim         {
10001a39cfb0SJung-uk Kim             return_ACPI_STATUS (Status);
10011a39cfb0SJung-uk Kim         }
10021a39cfb0SJung-uk Kim     }
100353289f6aSNate Lawson 
100453289f6aSNate Lawson FinishNode:
100553289f6aSNate Lawson     /*
100653289f6aSNate Lawson      * Point the parse node to the new namespace node, and point
100753289f6aSNate Lawson      * the Node back to the original Parse node
100853289f6aSNate Lawson      */
100953289f6aSNate Lawson     Op->Asl.Node = Node;
1010fba7fc7eSJung-uk Kim     Node->Op = Op;
101153289f6aSNate Lawson 
1012f9a6772eSJung-uk Kim     /*
1013f9a6772eSJung-uk Kim      * Set the actual data type if appropriate (EXTERNAL term only)
1014f9a6772eSJung-uk Kim      * As of 11/19/2019, ASL External() does not support parameter
1015f9a6772eSJung-uk Kim      * counts. When an External method is loaded, the parameter count is
1016f9a6772eSJung-uk Kim      * unknown setting Node->Value to ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS
1017f9a6772eSJung-uk Kim      * indicates that the parameter count for this method is unknown.
1018f9a6772eSJung-uk Kim      * This information is used in ASL cross reference to help determine the
1019f9a6772eSJung-uk Kim      * parameter count through method calls.
1020f9a6772eSJung-uk Kim      */
102153289f6aSNate Lawson     if (ActualObjectType != ACPI_TYPE_ANY)
102253289f6aSNate Lawson     {
102353289f6aSNate Lawson         Node->Type = (UINT8) ActualObjectType;
1024f9a6772eSJung-uk Kim         Node->Value = ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS;
102553289f6aSNate Lawson     }
102653289f6aSNate Lawson 
102753289f6aSNate Lawson     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
102853289f6aSNate Lawson     {
102953289f6aSNate Lawson         /*
1030fba7fc7eSJung-uk Kim          * Get the method argument count from "Extra" and save
1031fba7fc7eSJung-uk Kim          * it in the namespace node
103253289f6aSNate Lawson          */
1033fba7fc7eSJung-uk Kim         Node->Value = (UINT32) Op->Asl.Extra;
103453289f6aSNate Lawson     }
103553289f6aSNate Lawson 
10369a179dd8SJung-uk Kim     return_ACPI_STATUS (Status);
103753289f6aSNate Lawson }
103853289f6aSNate Lawson 
103953289f6aSNate Lawson 
104053289f6aSNate Lawson /*******************************************************************************
104153289f6aSNate Lawson  *
104237d7a5bcSJung-uk Kim  * FUNCTION:    LdCheckSpecialNames
104337d7a5bcSJung-uk Kim  *
104437d7a5bcSJung-uk Kim  * PARAMETERS:  Node        - Node that represents the named object
104537d7a5bcSJung-uk Kim  *              Op          - Named object declaring this named object
104637d7a5bcSJung-uk Kim  *
104737d7a5bcSJung-uk Kim  * RETURN:      None
104837d7a5bcSJung-uk Kim  *
104937d7a5bcSJung-uk Kim  * DESCRIPTION: Check if certain named objects are declared in the incorrect
105037d7a5bcSJung-uk Kim  *              scope. Special named objects are listed in
105137d7a5bcSJung-uk Kim  *              AslGbl_SpecialNamedObjects and can only be declared at the root
1052a009b7dcSJung-uk Kim  *              scope. _UID inside of a processor declaration must not be a
1053a009b7dcSJung-uk Kim  *              string.
105437d7a5bcSJung-uk Kim  *
105537d7a5bcSJung-uk Kim  ******************************************************************************/
105637d7a5bcSJung-uk Kim 
105737d7a5bcSJung-uk Kim static void
105837d7a5bcSJung-uk Kim LdCheckSpecialNames (
105937d7a5bcSJung-uk Kim     ACPI_NAMESPACE_NODE     *Node,
106037d7a5bcSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
106137d7a5bcSJung-uk Kim {
106237d7a5bcSJung-uk Kim     UINT32                  i;
106337d7a5bcSJung-uk Kim 
106437d7a5bcSJung-uk Kim 
106537d7a5bcSJung-uk Kim     for (i = 0; i < MAX_SPECIAL_NAMES; i++)
106637d7a5bcSJung-uk Kim     {
106737d7a5bcSJung-uk Kim         if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
106837d7a5bcSJung-uk Kim             Node->Parent != AcpiGbl_RootNode)
106937d7a5bcSJung-uk Kim         {
107037d7a5bcSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
107137d7a5bcSJung-uk Kim             return;
107237d7a5bcSJung-uk Kim         }
107337d7a5bcSJung-uk Kim     }
1074a009b7dcSJung-uk Kim 
1075a009b7dcSJung-uk Kim     if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1076a009b7dcSJung-uk Kim         Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1077a009b7dcSJung-uk Kim         Node->Type == ACPI_TYPE_STRING)
1078a009b7dcSJung-uk Kim     {
1079a009b7dcSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1080a009b7dcSJung-uk Kim     }
108137d7a5bcSJung-uk Kim }
108237d7a5bcSJung-uk Kim 
108337d7a5bcSJung-uk Kim 
108437d7a5bcSJung-uk Kim /*******************************************************************************
108537d7a5bcSJung-uk Kim  *
1086a9f12690SJung-uk Kim  * FUNCTION:    LdNamespace2Begin
1087a9f12690SJung-uk Kim  *
1088a9f12690SJung-uk Kim  * PARAMETERS:  ASL_WALK_CALLBACK
1089a9f12690SJung-uk Kim  *
1090a9f12690SJung-uk Kim  * RETURN:      Status
1091a9f12690SJung-uk Kim  *
1092a9f12690SJung-uk Kim  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1093a9f12690SJung-uk Kim  *              Second pass resolves some forward references.
1094a9f12690SJung-uk Kim  *
1095a9f12690SJung-uk Kim  * Notes:
1096a9f12690SJung-uk Kim  * Currently only needs to handle the Alias operator.
1097a9f12690SJung-uk Kim  * Could be used to allow forward references from the Scope() operator, but
1098a9f12690SJung-uk Kim  * the MS interpreter does not allow this, so this compiler does not either.
1099a9f12690SJung-uk Kim  *
1100a9f12690SJung-uk Kim  ******************************************************************************/
1101a9f12690SJung-uk Kim 
1102a9f12690SJung-uk Kim static ACPI_STATUS
1103a9f12690SJung-uk Kim LdNamespace2Begin (
1104a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
1105a9f12690SJung-uk Kim     UINT32                  Level,
1106a9f12690SJung-uk Kim     void                    *Context)
1107a9f12690SJung-uk Kim {
1108a9f12690SJung-uk Kim     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1109a9f12690SJung-uk Kim     ACPI_STATUS             Status;
1110a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
1111a9f12690SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType;
1112a9f12690SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
1113a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Arg;
1114a9f12690SJung-uk Kim     char                    *Path;
1115a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *TargetNode;
1116a9f12690SJung-uk Kim 
1117a9f12690SJung-uk Kim 
1118a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace2Begin);
1119a9f12690SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1120a9f12690SJung-uk Kim         Op, Op->Asl.ParseOpName));
1121a9f12690SJung-uk Kim 
1122a9f12690SJung-uk Kim 
1123a9f12690SJung-uk Kim     /* Ignore Ops with no namespace node */
1124a9f12690SJung-uk Kim 
1125a9f12690SJung-uk Kim     Node = Op->Asl.Node;
1126a9f12690SJung-uk Kim     if (!Node)
1127a9f12690SJung-uk Kim     {
1128a9f12690SJung-uk Kim         return (AE_OK);
1129a9f12690SJung-uk Kim     }
1130a9f12690SJung-uk Kim 
1131a9f12690SJung-uk Kim     /* Get the type to determine if we should push the scope */
1132a9f12690SJung-uk Kim 
1133a9f12690SJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
11345f9b24faSJung-uk Kim         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1135a9f12690SJung-uk Kim     {
1136a9f12690SJung-uk Kim         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1137a9f12690SJung-uk Kim     }
1138a9f12690SJung-uk Kim     else
1139a9f12690SJung-uk Kim     {
1140a9f12690SJung-uk Kim         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1141a9f12690SJung-uk Kim     }
1142a9f12690SJung-uk Kim 
1143a9f12690SJung-uk Kim     /* Push scope for Resource Templates */
1144a9f12690SJung-uk Kim 
1145a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1146a9f12690SJung-uk Kim     {
11475f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1148a9f12690SJung-uk Kim         {
1149a9f12690SJung-uk Kim             ForceNewScope = TRUE;
1150a9f12690SJung-uk Kim         }
1151a9f12690SJung-uk Kim     }
1152a9f12690SJung-uk Kim 
1153a9f12690SJung-uk Kim     /* Push the scope stack */
1154a9f12690SJung-uk Kim 
1155a9f12690SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1156a9f12690SJung-uk Kim     {
1157a9f12690SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1158a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1159a9f12690SJung-uk Kim         {
1160a9f12690SJung-uk Kim             return_ACPI_STATUS (Status);
1161a9f12690SJung-uk Kim         }
1162a9f12690SJung-uk Kim     }
1163a9f12690SJung-uk Kim 
1164a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1165a9f12690SJung-uk Kim     {
11664a38ee6dSJung-uk Kim         /*
11674a38ee6dSJung-uk Kim          * Complete the alias node by getting and saving the target node.
11684a38ee6dSJung-uk Kim          * First child is the alias target
11694a38ee6dSJung-uk Kim          */
1170a9f12690SJung-uk Kim         Arg = Op->Asl.Child;
1171a9f12690SJung-uk Kim 
1172a9f12690SJung-uk Kim         /* Get the target pathname */
1173a9f12690SJung-uk Kim 
1174a9f12690SJung-uk Kim         Path = Arg->Asl.Namepath;
1175a9f12690SJung-uk Kim         if (!Path)
1176a9f12690SJung-uk Kim         {
1177a9f12690SJung-uk Kim             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1178a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
1179a9f12690SJung-uk Kim             {
1180a9f12690SJung-uk Kim                 return (Status);
1181a9f12690SJung-uk Kim             }
1182a9f12690SJung-uk Kim         }
1183a9f12690SJung-uk Kim 
1184a9f12690SJung-uk Kim         /* Get the NS node associated with the target. It must exist. */
1185a9f12690SJung-uk Kim 
1186a9f12690SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1187a9f12690SJung-uk Kim             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1188a9f12690SJung-uk Kim             WalkState, &TargetNode);
1189a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1190a9f12690SJung-uk Kim         {
1191a9f12690SJung-uk Kim             if (Status == AE_NOT_FOUND)
1192a9f12690SJung-uk Kim             {
11934a38ee6dSJung-uk Kim                 /* Standalone NameSeg vs. NamePath */
1194a9f12690SJung-uk Kim 
1195278f0de6SJung-uk Kim                 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
11964a38ee6dSJung-uk Kim                 {
11974a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
11984a38ee6dSJung-uk Kim                         Arg->Asl.ExternalName);
11994a38ee6dSJung-uk Kim                 }
12004a38ee6dSJung-uk Kim                 else
12014a38ee6dSJung-uk Kim                 {
12024a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
12034a38ee6dSJung-uk Kim                         Arg->Asl.ExternalName);
12044a38ee6dSJung-uk Kim                 }
12054a38ee6dSJung-uk Kim 
12064a38ee6dSJung-uk Kim #if 0
12074a38ee6dSJung-uk Kim /*
12084a38ee6dSJung-uk Kim  * NOTE: Removed 10/2018 to enhance compiler error reporting. No
12094a38ee6dSJung-uk Kim  * regressions seen.
12104a38ee6dSJung-uk Kim  */
1211a9f12690SJung-uk Kim                 /*
1212a9f12690SJung-uk Kim                  * The name was not found, go ahead and create it.
1213a9f12690SJung-uk Kim                  * This prevents more errors later.
1214a9f12690SJung-uk Kim                  */
1215a9f12690SJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
12164a38ee6dSJung-uk Kim                     ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
12174a38ee6dSJung-uk Kim                     ACPI_NS_NO_UPSEARCH, WalkState, &Node);
12184a38ee6dSJung-uk Kim #endif
12194a38ee6dSJung-uk Kim                 return (Status);
12204a38ee6dSJung-uk Kim /* Removed: return (AE_OK)*/
1221a9f12690SJung-uk Kim             }
1222a9f12690SJung-uk Kim 
1223f556842eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
1224f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
1225a9f12690SJung-uk Kim             return (AE_OK);
1226a9f12690SJung-uk Kim         }
1227a9f12690SJung-uk Kim 
1228a9f12690SJung-uk Kim         /* Save the target node within the alias node */
1229a9f12690SJung-uk Kim 
1230a9f12690SJung-uk Kim         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1231a9f12690SJung-uk Kim     }
1232a9f12690SJung-uk Kim 
1233a9f12690SJung-uk Kim     return (AE_OK);
1234a9f12690SJung-uk Kim }
1235a9f12690SJung-uk Kim 
1236a9f12690SJung-uk Kim 
1237a9f12690SJung-uk Kim /*******************************************************************************
1238a9f12690SJung-uk Kim  *
1239a9f12690SJung-uk Kim  * FUNCTION:    LdCommonNamespaceEnd
124053289f6aSNate Lawson  *
124153289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
124253289f6aSNate Lawson  *
124353289f6aSNate Lawson  * RETURN:      Status
124453289f6aSNate Lawson  *
124553289f6aSNate Lawson  * DESCRIPTION: Ascending callback used during the loading of the namespace,
124653289f6aSNate Lawson  *              We only need to worry about managing the scope stack here.
124753289f6aSNate Lawson  *
124853289f6aSNate Lawson  ******************************************************************************/
124953289f6aSNate Lawson 
1250fba7fc7eSJung-uk Kim static ACPI_STATUS
1251a9f12690SJung-uk Kim LdCommonNamespaceEnd (
125253289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
125353289f6aSNate Lawson     UINT32                  Level,
125453289f6aSNate Lawson     void                    *Context)
125553289f6aSNate Lawson {
125653289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
125753289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
12581a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
125953289f6aSNate Lawson 
126053289f6aSNate Lawson 
1261a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
126253289f6aSNate Lawson 
126353289f6aSNate Lawson 
126453289f6aSNate Lawson     /* We are only interested in opcodes that have an associated name */
126553289f6aSNate Lawson 
126653289f6aSNate Lawson     if (!Op->Asl.Namepath)
126753289f6aSNate Lawson     {
126853289f6aSNate Lawson         return (AE_OK);
126953289f6aSNate Lawson     }
127053289f6aSNate Lawson 
127153289f6aSNate Lawson     /* Get the type to determine if we should pop the scope */
127253289f6aSNate Lawson 
127353289f6aSNate Lawson     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
12745f9b24faSJung-uk Kim         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
127553289f6aSNate Lawson     {
127653289f6aSNate Lawson         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
127753289f6aSNate Lawson 
127853289f6aSNate Lawson         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
127953289f6aSNate Lawson     }
128053289f6aSNate Lawson     else
128153289f6aSNate Lawson     {
128253289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
128353289f6aSNate Lawson     }
128453289f6aSNate Lawson 
12851a39cfb0SJung-uk Kim     /* Pop scope that was pushed for Resource Templates */
12861a39cfb0SJung-uk Kim 
12871a39cfb0SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
12881a39cfb0SJung-uk Kim     {
12895f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
12901a39cfb0SJung-uk Kim         {
12911a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
12921a39cfb0SJung-uk Kim         }
12931a39cfb0SJung-uk Kim     }
12941a39cfb0SJung-uk Kim 
129553289f6aSNate Lawson     /* Pop the scope stack */
129653289f6aSNate Lawson 
12971a39cfb0SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
129853289f6aSNate Lawson     {
129953289f6aSNate Lawson         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
130053289f6aSNate Lawson             "(%s): Popping scope for Op [%s] %p\n",
130153289f6aSNate Lawson             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
130253289f6aSNate Lawson 
1303fba7fc7eSJung-uk Kim         (void) AcpiDsScopeStackPop (WalkState);
130453289f6aSNate Lawson     }
130553289f6aSNate Lawson 
130653289f6aSNate Lawson     return (AE_OK);
130753289f6aSNate Lawson }
1308