xref: /freebsd-src/sys/contrib/dev/acpica/compiler/aslload.c (revision 3ee58df503b601febeef11f23c4a7e2adf425b96)
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  *
11f425b8beSJung-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 
199ec0234b4SJung-uk Kim static ACPI_STATUS
200ec0234b4SJung-uk Kim LdAnalyzeExternals (
201ec0234b4SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node,
202ec0234b4SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
203ec0234b4SJung-uk Kim     ACPI_OBJECT_TYPE        ExternalOpType,
204ec0234b4SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType,
205ec0234b4SJung-uk Kim     ACPI_WALK_STATE         *WalkState);
206ec0234b4SJung-uk Kim 
207ec0234b4SJung-uk Kim 
20853289f6aSNate Lawson /*******************************************************************************
20953289f6aSNate Lawson  *
21053289f6aSNate Lawson  * FUNCTION:    LdLoadNamespace
21153289f6aSNate Lawson  *
212fba7fc7eSJung-uk Kim  * PARAMETERS:  RootOp      - Root of the parse tree
21353289f6aSNate Lawson  *
21453289f6aSNate Lawson  * RETURN:      Status
21553289f6aSNate Lawson  *
21653289f6aSNate Lawson  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
21753289f6aSNate Lawson  *              named ASL/AML objects into the namespace. The namespace is
21853289f6aSNate Lawson  *              constructed in order to resolve named references and references
21953289f6aSNate Lawson  *              to named fields within resource templates/descriptors.
22053289f6aSNate Lawson  *
22153289f6aSNate Lawson  ******************************************************************************/
22253289f6aSNate Lawson 
22353289f6aSNate Lawson ACPI_STATUS
22453289f6aSNate Lawson LdLoadNamespace (
22553289f6aSNate Lawson     ACPI_PARSE_OBJECT       *RootOp)
22653289f6aSNate Lawson {
22753289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState;
22853289f6aSNate Lawson 
22953289f6aSNate Lawson 
23053289f6aSNate Lawson     /* Create a new walk state */
23153289f6aSNate Lawson 
23253289f6aSNate Lawson     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
23353289f6aSNate Lawson     if (!WalkState)
23453289f6aSNate Lawson     {
2358ef1a331SJung-uk Kim         return (AE_NO_MEMORY);
23653289f6aSNate Lawson     }
23753289f6aSNate Lawson 
238a9f12690SJung-uk Kim     /* Walk the entire parse tree, first pass */
23953289f6aSNate Lawson 
24053289f6aSNate Lawson     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
241a9f12690SJung-uk Kim         LdCommonNamespaceEnd, WalkState);
242a9f12690SJung-uk Kim 
243a9f12690SJung-uk Kim     /* Second pass to handle forward references */
244a9f12690SJung-uk Kim 
245a9f12690SJung-uk Kim     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
246a9f12690SJung-uk Kim         LdCommonNamespaceEnd, WalkState);
24753289f6aSNate Lawson 
24853289f6aSNate Lawson     /* Dump the namespace if debug is enabled */
24953289f6aSNate Lawson 
2503d90091dSJung-uk Kim     if (AcpiDbgLevel & ACPI_LV_TABLES)
2513d90091dSJung-uk Kim     {
25253289f6aSNate Lawson         AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
2533d90091dSJung-uk Kim     }
2543d90091dSJung-uk Kim 
255313a0c13SJung-uk Kim     ACPI_FREE (WalkState);
2568ef1a331SJung-uk Kim     return (AE_OK);
25753289f6aSNate Lawson }
25853289f6aSNate Lawson 
25953289f6aSNate Lawson 
26053289f6aSNate Lawson /*******************************************************************************
26153289f6aSNate Lawson  *
26253289f6aSNate Lawson  * FUNCTION:    LdLoadFieldElements
26353289f6aSNate Lawson  *
26437d7a5bcSJung-uk Kim  * PARAMETERS:  AmlType         - Type to search
26537d7a5bcSJung-uk Kim  *              Op              - Parent node (Field)
26653289f6aSNate Lawson  *              WalkState       - Current walk state
26753289f6aSNate Lawson  *
26853289f6aSNate Lawson  * RETURN:      Status
26953289f6aSNate Lawson  *
27053289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the field (children of the parent)
27153289f6aSNate Lawson  *              into the namespace.
27253289f6aSNate Lawson  *
27353289f6aSNate Lawson  ******************************************************************************/
27453289f6aSNate Lawson 
275fba7fc7eSJung-uk Kim static ACPI_STATUS
27653289f6aSNate Lawson LdLoadFieldElements (
27737d7a5bcSJung-uk Kim     UINT32                  AmlType,
27853289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
27953289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
28053289f6aSNate Lawson {
28153289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Child = NULL;
2829ad8b64eSJung-uk Kim     ACPI_PARSE_OBJECT       *SourceRegion;
28353289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
28453289f6aSNate Lawson     ACPI_STATUS             Status;
285f425b8beSJung-uk Kim     char                    *ExternalPath;
28653289f6aSNate Lawson 
28753289f6aSNate Lawson 
2889ad8b64eSJung-uk Kim     SourceRegion = UtGetArg (Op, 0);
2899ad8b64eSJung-uk Kim     if (SourceRegion)
2909ad8b64eSJung-uk Kim     {
2919ad8b64eSJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo,
292f425b8beSJung-uk Kim             SourceRegion->Asl.Value.String, AmlType, ACPI_IMODE_EXECUTE,
293f425b8beSJung-uk Kim             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
2949ad8b64eSJung-uk Kim         if (Status == AE_NOT_FOUND)
2959ad8b64eSJung-uk Kim         {
2969ad8b64eSJung-uk Kim             /*
2979ad8b64eSJung-uk Kim              * If the named object is not found, it means that it is either a
2989ad8b64eSJung-uk Kim              * forward reference or the named object does not exist.
2999ad8b64eSJung-uk Kim              */
3009ad8b64eSJung-uk Kim             SourceRegion->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
3019ad8b64eSJung-uk Kim         }
3029ad8b64eSJung-uk Kim     }
3039ad8b64eSJung-uk Kim 
30453289f6aSNate Lawson     /* Get the first named field element */
30553289f6aSNate Lawson 
30653289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
30753289f6aSNate Lawson     {
30853289f6aSNate Lawson     case AML_BANK_FIELD_OP:
30953289f6aSNate Lawson 
31053289f6aSNate Lawson         Child = UtGetArg (Op, 6);
31153289f6aSNate Lawson         break;
31253289f6aSNate Lawson 
31353289f6aSNate Lawson     case AML_INDEX_FIELD_OP:
31453289f6aSNate Lawson 
31553289f6aSNate Lawson         Child = UtGetArg (Op, 5);
31653289f6aSNate Lawson         break;
31753289f6aSNate Lawson 
31853289f6aSNate Lawson     case AML_FIELD_OP:
31953289f6aSNate Lawson 
32053289f6aSNate Lawson         Child = UtGetArg (Op, 4);
32153289f6aSNate Lawson         break;
32253289f6aSNate Lawson 
32353289f6aSNate Lawson     default:
324a9d8d09cSJung-uk Kim 
32553289f6aSNate Lawson         /* No other opcodes should arrive here */
326a9d8d09cSJung-uk Kim 
32753289f6aSNate Lawson         return (AE_BAD_PARAMETER);
32853289f6aSNate Lawson     }
32953289f6aSNate Lawson 
33053289f6aSNate Lawson     /* Enter all elements into the namespace */
33153289f6aSNate Lawson 
33253289f6aSNate Lawson     while (Child)
33353289f6aSNate Lawson     {
33453289f6aSNate Lawson         switch (Child->Asl.AmlOpcode)
33553289f6aSNate Lawson         {
33653289f6aSNate Lawson         case AML_INT_RESERVEDFIELD_OP:
33753289f6aSNate Lawson         case AML_INT_ACCESSFIELD_OP:
3383f0275a0SJung-uk Kim         case AML_INT_CONNECTION_OP:
33953289f6aSNate Lawson             break;
34053289f6aSNate Lawson 
34153289f6aSNate Lawson         default:
34253289f6aSNate Lawson 
343fba7fc7eSJung-uk Kim             Status = AcpiNsLookup (WalkState->ScopeInfo,
344fba7fc7eSJung-uk Kim                 Child->Asl.Value.String,
345fba7fc7eSJung-uk Kim                 ACPI_TYPE_LOCAL_REGION_FIELD,
346fba7fc7eSJung-uk Kim                 ACPI_IMODE_LOAD_PASS1,
347fba7fc7eSJung-uk Kim                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
348f8146b88SJung-uk Kim                     ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
34953289f6aSNate Lawson             if (ACPI_FAILURE (Status))
35053289f6aSNate Lawson             {
35153289f6aSNate Lawson                 if (Status != AE_ALREADY_EXISTS)
35253289f6aSNate Lawson                 {
353fba7fc7eSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
354fba7fc7eSJung-uk Kim                         Child->Asl.Value.String);
35553289f6aSNate Lawson                     return (Status);
35653289f6aSNate Lawson                 }
357af051161SJung-uk Kim                 else if (Status == AE_ALREADY_EXISTS &&
358da9b0901SJung-uk Kim                     (Node->Flags & ANOBJ_IS_EXTERNAL))
359af051161SJung-uk Kim                 {
360af051161SJung-uk Kim                     Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
36144b0f624SJung-uk Kim                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
362af051161SJung-uk Kim                 }
363af051161SJung-uk Kim                 else
364af051161SJung-uk Kim                 {
36553289f6aSNate Lawson                     /*
36653289f6aSNate Lawson                      * The name already exists in this scope
36753289f6aSNate Lawson                      * But continue processing the elements
36853289f6aSNate Lawson                      */
369f425b8beSJung-uk Kim                     ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
370f425b8beSJung-uk Kim 
371f9a6772eSJung-uk Kim                     AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
372f425b8beSJung-uk Kim                         ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
373f425b8beSJung-uk Kim                         ExternalPath);
374f425b8beSJung-uk Kim 
375f425b8beSJung-uk Kim                     if (ExternalPath)
376f425b8beSJung-uk Kim                     {
377f425b8beSJung-uk Kim                         ACPI_FREE (ExternalPath);
378f425b8beSJung-uk Kim                     }
37953289f6aSNate Lawson                 }
380af051161SJung-uk Kim             }
38153289f6aSNate Lawson             else
38253289f6aSNate Lawson             {
38353289f6aSNate Lawson                 Child->Asl.Node = Node;
384fba7fc7eSJung-uk Kim                 Node->Op = Child;
38553289f6aSNate Lawson             }
38653289f6aSNate Lawson             break;
38753289f6aSNate Lawson         }
3883f0275a0SJung-uk Kim 
38953289f6aSNate Lawson         Child = Child->Asl.Next;
39053289f6aSNate Lawson     }
3913f0275a0SJung-uk Kim 
39253289f6aSNate Lawson     return (AE_OK);
39353289f6aSNate Lawson }
39453289f6aSNate Lawson 
39553289f6aSNate Lawson 
39653289f6aSNate Lawson /*******************************************************************************
39753289f6aSNate Lawson  *
39853289f6aSNate Lawson  * FUNCTION:    LdLoadResourceElements
39953289f6aSNate Lawson  *
40053289f6aSNate Lawson  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
40153289f6aSNate Lawson  *              WalkState       - Current walk state
40253289f6aSNate Lawson  *
40353289f6aSNate Lawson  * RETURN:      Status
40453289f6aSNate Lawson  *
40553289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the resource descriptor (children
40653289f6aSNate Lawson  *              of the parent) into the namespace.
40753289f6aSNate Lawson  *
40853289f6aSNate Lawson  * NOTE: In the real AML namespace, these named elements never exist. But
40953289f6aSNate Lawson  *       we simply use the namespace here as a symbol table so we can look
41053289f6aSNate Lawson  *       them up as they are referenced.
41153289f6aSNate Lawson  *
41253289f6aSNate Lawson  ******************************************************************************/
41353289f6aSNate Lawson 
414fba7fc7eSJung-uk Kim static ACPI_STATUS
41553289f6aSNate Lawson LdLoadResourceElements (
41653289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
41753289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
41853289f6aSNate Lawson {
41953289f6aSNate Lawson     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
42053289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
42153289f6aSNate Lawson     ACPI_STATUS             Status;
422f425b8beSJung-uk Kim     char                    *ExternalPath;
42353289f6aSNate Lawson 
42453289f6aSNate Lawson 
42553289f6aSNate Lawson     /*
426fba7fc7eSJung-uk Kim      * Enter the resource name into the namespace. Name must not already exist.
427fba7fc7eSJung-uk Kim      * This opens a scope, so later field names are guaranteed to be new/unique.
42853289f6aSNate Lawson      */
42953289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
430fba7fc7eSJung-uk Kim         ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
431fba7fc7eSJung-uk Kim         ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
43253289f6aSNate Lawson         WalkState, &Node);
43353289f6aSNate Lawson     if (ACPI_FAILURE (Status))
43453289f6aSNate Lawson     {
435fba7fc7eSJung-uk Kim         if (Status == AE_ALREADY_EXISTS)
436fba7fc7eSJung-uk Kim         {
437fba7fc7eSJung-uk Kim             /* Actual node causing the error was saved in ParentMethod */
438fba7fc7eSJung-uk Kim 
439f425b8beSJung-uk Kim             ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
440f425b8beSJung-uk Kim 
44167d9aa44SJung-uk Kim             AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
44267d9aa44SJung-uk Kim                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
443f425b8beSJung-uk Kim                 ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
444f425b8beSJung-uk Kim                 ExternalPath);
445f425b8beSJung-uk Kim 
446f425b8beSJung-uk Kim             if (ExternalPath)
447f425b8beSJung-uk Kim             {
448f425b8beSJung-uk Kim                 ACPI_FREE (ExternalPath);
449f425b8beSJung-uk Kim             }
450fba7fc7eSJung-uk Kim             return (AE_OK);
451fba7fc7eSJung-uk Kim         }
45253289f6aSNate Lawson         return (Status);
45353289f6aSNate Lawson     }
45453289f6aSNate Lawson 
4551a39cfb0SJung-uk Kim     Node->Value = (UINT32) Op->Asl.Value.Integer;
4561a39cfb0SJung-uk Kim     Node->Op = Op;
457d6dd1baeSJung-uk Kim     Op->Asl.Node = Node;
4581a39cfb0SJung-uk Kim 
45953289f6aSNate Lawson     /*
46053289f6aSNate Lawson      * Now enter the predefined fields, for easy lookup when referenced
46153289f6aSNate Lawson      * by the source ASL
46253289f6aSNate Lawson      */
46353289f6aSNate Lawson     InitializerOp = ASL_GET_CHILD_NODE (Op);
46453289f6aSNate Lawson     while (InitializerOp)
46553289f6aSNate Lawson     {
46653289f6aSNate Lawson         if (InitializerOp->Asl.ExternalName)
46753289f6aSNate Lawson         {
46853289f6aSNate Lawson             Status = AcpiNsLookup (WalkState->ScopeInfo,
46953289f6aSNate Lawson                 InitializerOp->Asl.ExternalName,
4704a38ee6dSJung-uk Kim                 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
4714a38ee6dSJung-uk Kim                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
47253289f6aSNate Lawson             if (ACPI_FAILURE (Status))
47353289f6aSNate Lawson             {
47453289f6aSNate Lawson                 return (Status);
47553289f6aSNate Lawson             }
47653289f6aSNate Lawson 
47753289f6aSNate Lawson             /*
4783f0275a0SJung-uk Kim              * Store the field offset and length in the namespace node
4793f0275a0SJung-uk Kim              * so it can be used when the field is referenced
48053289f6aSNate Lawson              */
4813f0275a0SJung-uk Kim             Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
4823f0275a0SJung-uk Kim             Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
48353289f6aSNate Lawson             InitializerOp->Asl.Node = Node;
484fba7fc7eSJung-uk Kim             Node->Op = InitializerOp;
48553289f6aSNate Lawson         }
4863f0275a0SJung-uk Kim 
48753289f6aSNate Lawson         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
48853289f6aSNate Lawson     }
48953289f6aSNate Lawson 
49053289f6aSNate Lawson     return (AE_OK);
49153289f6aSNate Lawson }
49253289f6aSNate Lawson 
49353289f6aSNate Lawson 
49453289f6aSNate Lawson /*******************************************************************************
49553289f6aSNate Lawson  *
49653289f6aSNate Lawson  * FUNCTION:    LdNamespace1Begin
49753289f6aSNate Lawson  *
49853289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
49953289f6aSNate Lawson  *
50053289f6aSNate Lawson  * RETURN:      Status
50153289f6aSNate Lawson  *
50253289f6aSNate Lawson  * DESCRIPTION: Descending callback used during the parse tree walk. If this
50353289f6aSNate Lawson  *              is a named AML opcode, enter into the namespace
50453289f6aSNate Lawson  *
50553289f6aSNate Lawson  ******************************************************************************/
50653289f6aSNate Lawson 
507fba7fc7eSJung-uk Kim static ACPI_STATUS
50853289f6aSNate Lawson LdNamespace1Begin (
50953289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
51053289f6aSNate Lawson     UINT32                  Level,
51153289f6aSNate Lawson     void                    *Context)
51253289f6aSNate Lawson {
51353289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
51453289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
515f8146b88SJung-uk Kim     ACPI_PARSE_OBJECT       *MethodOp;
51653289f6aSNate Lawson     ACPI_STATUS             Status;
51753289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
51853289f6aSNate Lawson     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
51953289f6aSNate Lawson     char                    *Path;
52053289f6aSNate Lawson     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
52153289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Arg;
52253289f6aSNate Lawson     UINT32                  i;
5231a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
524835b56bfSJung-uk Kim     const ACPI_OPCODE_INFO  *OpInfo;
525835b56bfSJung-uk Kim     ACPI_PARSE_OBJECT       *ParentOp;
526f425b8beSJung-uk Kim     char                    *ExternalPath;
52753289f6aSNate Lawson 
52853289f6aSNate Lawson 
5291a39cfb0SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace1Begin);
530835b56bfSJung-uk Kim 
531835b56bfSJung-uk Kim 
53253289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
53353289f6aSNate Lawson         Op, Op->Asl.ParseOpName));
53453289f6aSNate Lawson 
53553289f6aSNate Lawson     /*
53653289f6aSNate Lawson      * We are only interested in opcodes that have an associated name
53753289f6aSNate Lawson      * (or multiple names)
53853289f6aSNate Lawson      */
53953289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
54053289f6aSNate Lawson     {
5412e578044SJung-uk Kim     case AML_INDEX_FIELD_OP:
54237d7a5bcSJung-uk Kim 
54337d7a5bcSJung-uk Kim         Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
54437d7a5bcSJung-uk Kim         return (Status);
54537d7a5bcSJung-uk Kim 
54637d7a5bcSJung-uk Kim     case AML_BANK_FIELD_OP:
54753289f6aSNate Lawson     case AML_FIELD_OP:
54853289f6aSNate Lawson 
54937d7a5bcSJung-uk Kim         Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
5509ad8b64eSJung-uk Kim         return (Status);
55153289f6aSNate Lawson 
552313a0c13SJung-uk Kim     case AML_INT_CONNECTION_OP:
553313a0c13SJung-uk Kim 
554313a0c13SJung-uk Kim         if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
555313a0c13SJung-uk Kim         {
556313a0c13SJung-uk Kim             break;
557313a0c13SJung-uk Kim         }
558313a0c13SJung-uk Kim 
559a009b7dcSJung-uk Kim         Arg = Op->Asl.Child;
560313a0c13SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
561313a0c13SJung-uk Kim             ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
562313a0c13SJung-uk Kim             WalkState, &Node);
563313a0c13SJung-uk Kim         if (ACPI_FAILURE (Status))
564313a0c13SJung-uk Kim         {
565313a0c13SJung-uk Kim             break;
566313a0c13SJung-uk Kim         }
567313a0c13SJung-uk Kim 
568313a0c13SJung-uk Kim         break;
569313a0c13SJung-uk Kim 
57053289f6aSNate Lawson     default:
57153289f6aSNate Lawson 
57253289f6aSNate Lawson         /* All other opcodes go below */
573a9d8d09cSJung-uk Kim 
57453289f6aSNate Lawson         break;
57553289f6aSNate Lawson     }
57653289f6aSNate Lawson 
57753289f6aSNate Lawson     /* Check if this object has already been installed in the namespace */
57853289f6aSNate Lawson 
57953289f6aSNate Lawson     if (Op->Asl.Node)
58053289f6aSNate Lawson     {
58153289f6aSNate Lawson         return (AE_OK);
58253289f6aSNate Lawson     }
58353289f6aSNate Lawson 
584835b56bfSJung-uk Kim     /* Check for a possible illegal forward reference */
585835b56bfSJung-uk Kim 
586835b56bfSJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
587ec0234b4SJung-uk Kim         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
588ec0234b4SJung-uk Kim         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
589835b56bfSJung-uk Kim     {
590835b56bfSJung-uk Kim         /*
591835b56bfSJung-uk Kim          * Op->Asl.Namepath will be NULL for these opcodes.
592835b56bfSJung-uk Kim          * These opcodes are guaranteed to have a parent.
593835b56bfSJung-uk Kim          * Examine the parent opcode.
594835b56bfSJung-uk Kim          */
595835b56bfSJung-uk Kim         ParentOp = Op->Asl.Parent;
596835b56bfSJung-uk Kim         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
597835b56bfSJung-uk Kim 
598835b56bfSJung-uk Kim         /*
599835b56bfSJung-uk Kim          * Exclude all operators that actually declare a new name:
600835b56bfSJung-uk Kim          *      Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
601835b56bfSJung-uk Kim          * We only want references to named objects:
602835b56bfSJung-uk Kim          *      Store (2, WXYZ) -> Attempt to resolve the name
603835b56bfSJung-uk Kim          */
604ec0234b4SJung-uk Kim         if ((Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
605ec0234b4SJung-uk Kim             (OpInfo->Class == AML_CLASS_NAMED_OBJECT))
606835b56bfSJung-uk Kim         {
607835b56bfSJung-uk Kim             return (AE_OK);
608835b56bfSJung-uk Kim         }
609835b56bfSJung-uk Kim 
610835b56bfSJung-uk Kim         /*
611835b56bfSJung-uk Kim          * Check if the referenced object exists at this point during
612835b56bfSJung-uk Kim          * the load:
613835b56bfSJung-uk Kim          * 1) If it exists, then this cannot be a forward reference.
614835b56bfSJung-uk Kim          * 2) If it does not exist, it could be a forward reference or
615835b56bfSJung-uk Kim          * it truly does not exist (and no external declaration).
616835b56bfSJung-uk Kim          */
617835b56bfSJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo,
618835b56bfSJung-uk Kim             Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
619835b56bfSJung-uk Kim             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
620835b56bfSJung-uk Kim             WalkState, &Node);
621835b56bfSJung-uk Kim         if (Status == AE_NOT_FOUND)
622835b56bfSJung-uk Kim         {
623835b56bfSJung-uk Kim             /*
624cd6518c7SJung-uk Kim              * This is either a forward reference or the object truly
625835b56bfSJung-uk Kim              * does not exist. The two cases can only be differentiated
626835b56bfSJung-uk Kim              * during the cross-reference stage later. Mark the Op/Name
627835b56bfSJung-uk Kim              * as not-found for now to indicate the need for further
628835b56bfSJung-uk Kim              * processing.
629835b56bfSJung-uk Kim              *
630835b56bfSJung-uk Kim              * Special case: Allow forward references from elements of
631835b56bfSJung-uk Kim              * Package objects. This provides compatibility with other
632835b56bfSJung-uk Kim              * ACPI implementations. To correctly implement this, the
633835b56bfSJung-uk Kim              * ACPICA table load defers package resolution until the entire
634835b56bfSJung-uk Kim              * namespace has been loaded.
635835b56bfSJung-uk Kim              */
636835b56bfSJung-uk Kim             if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
637835b56bfSJung-uk Kim                 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
638835b56bfSJung-uk Kim             {
639835b56bfSJung-uk Kim                 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
640835b56bfSJung-uk Kim             }
641835b56bfSJung-uk Kim 
642835b56bfSJung-uk Kim             return (AE_OK);
643835b56bfSJung-uk Kim         }
644835b56bfSJung-uk Kim 
645835b56bfSJung-uk Kim         return (Status);
646835b56bfSJung-uk Kim     }
647835b56bfSJung-uk Kim 
64853289f6aSNate Lawson     Path = Op->Asl.Namepath;
64953289f6aSNate Lawson     if (!Path)
65053289f6aSNate Lawson     {
65153289f6aSNate Lawson         return (AE_OK);
65253289f6aSNate Lawson     }
65353289f6aSNate Lawson 
65453289f6aSNate Lawson     /* Map the raw opcode into an internal object type */
65553289f6aSNate Lawson 
65653289f6aSNate Lawson     switch (Op->Asl.ParseOpcode)
65753289f6aSNate Lawson     {
65853289f6aSNate Lawson     case PARSEOP_NAME:
65953289f6aSNate Lawson 
66053289f6aSNate Lawson         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
66153289f6aSNate Lawson         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
66253289f6aSNate Lawson 
6631a39cfb0SJung-uk Kim         /*
6641a39cfb0SJung-uk Kim          * If this name refers to a ResourceTemplate, we will need to open
6651a39cfb0SJung-uk Kim          * a new scope so that the resource subfield names can be entered into
6661a39cfb0SJung-uk Kim          * the namespace underneath this name
6671a39cfb0SJung-uk Kim          */
6685f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
6691a39cfb0SJung-uk Kim         {
6701a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
6711a39cfb0SJung-uk Kim         }
6721a39cfb0SJung-uk Kim 
67353289f6aSNate Lawson         /* Get the data type associated with the named object, not the name itself */
67453289f6aSNate Lawson 
67553289f6aSNate Lawson         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
67653289f6aSNate Lawson 
67753289f6aSNate Lawson         ObjectType = 1;
67853289f6aSNate Lawson         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
67953289f6aSNate Lawson         {
68053289f6aSNate Lawson             ObjectType++;
68153289f6aSNate Lawson         }
68253289f6aSNate Lawson         break;
68353289f6aSNate Lawson 
68453289f6aSNate Lawson     case PARSEOP_EXTERNAL:
68553289f6aSNate Lawson         /*
68653289f6aSNate Lawson          * "External" simply enters a name and type into the namespace.
68753289f6aSNate Lawson          * We must be careful to not open a new scope, however, no matter
68853289f6aSNate Lawson          * what type the external name refers to (e.g., a method)
68953289f6aSNate Lawson          *
69053289f6aSNate Lawson          * first child is name, next child is ObjectType
69153289f6aSNate Lawson          */
69253289f6aSNate Lawson         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
69353289f6aSNate Lawson         ObjectType = ACPI_TYPE_ANY;
69453289f6aSNate Lawson 
6951a39cfb0SJung-uk Kim         /*
6961a39cfb0SJung-uk Kim          * We will mark every new node along the path as "External". This
6971a39cfb0SJung-uk Kim          * allows some or all of the nodes to be created later in the ASL
6981a39cfb0SJung-uk Kim          * code. Handles cases like this:
6991a39cfb0SJung-uk Kim          *
7001a39cfb0SJung-uk Kim          *   External (\_SB_.PCI0.ABCD, IntObj)
7011a39cfb0SJung-uk Kim          *   Scope (_SB_)
7021a39cfb0SJung-uk Kim          *   {
7031a39cfb0SJung-uk Kim          *       Device (PCI0)
7041a39cfb0SJung-uk Kim          *       {
7051a39cfb0SJung-uk Kim          *       }
7061a39cfb0SJung-uk Kim          *   }
7071a39cfb0SJung-uk Kim          *   Method (X)
7081a39cfb0SJung-uk Kim          *   {
7091a39cfb0SJung-uk Kim          *       Store (\_SB_.PCI0.ABCD, Local0)
7101a39cfb0SJung-uk Kim          *   }
7111a39cfb0SJung-uk Kim          */
7121a39cfb0SJung-uk Kim         Flags |= ACPI_NS_EXTERNAL;
7131a39cfb0SJung-uk Kim         break;
71453289f6aSNate Lawson 
71553289f6aSNate Lawson     case PARSEOP_DEFAULT_ARG:
71653289f6aSNate Lawson 
7175f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
71853289f6aSNate Lawson         {
71953289f6aSNate Lawson             Status = LdLoadResourceElements (Op, WalkState);
7209a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
72153289f6aSNate Lawson         }
72253289f6aSNate Lawson 
72353289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
72453289f6aSNate Lawson         break;
72553289f6aSNate Lawson 
72653289f6aSNate Lawson     case PARSEOP_SCOPE:
72753289f6aSNate Lawson         /*
72853289f6aSNate Lawson          * The name referenced by Scope(Name) must already exist at this point.
72953289f6aSNate Lawson          * In other words, forward references for Scope() are not supported.
73053289f6aSNate Lawson          * The only real reason for this is that the MS interpreter cannot
73153289f6aSNate Lawson          * handle this case. Perhaps someday this case can go away.
73253289f6aSNate Lawson          */
73353289f6aSNate Lawson         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
7344a38ee6dSJung-uk Kim             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
73553289f6aSNate Lawson         if (ACPI_FAILURE (Status))
73653289f6aSNate Lawson         {
73753289f6aSNate Lawson             if (Status == AE_NOT_FOUND)
73853289f6aSNate Lawson             {
73953289f6aSNate Lawson                 /* The name was not found, go ahead and create it */
74053289f6aSNate Lawson 
741fba7fc7eSJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
7424a38ee6dSJung-uk Kim                     ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
7434a38ee6dSJung-uk Kim                     Flags, WalkState, &Node);
74479c6d946SJung-uk Kim                 if (ACPI_FAILURE (Status))
74579c6d946SJung-uk Kim                 {
74679c6d946SJung-uk Kim                     return_ACPI_STATUS (Status);
74779c6d946SJung-uk Kim                 }
74853289f6aSNate Lawson 
7494a38ee6dSJung-uk Kim                 /* However, this is an error -- operand to Scope must exist */
7504a38ee6dSJung-uk Kim 
751278f0de6SJung-uk Kim                 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
7524a38ee6dSJung-uk Kim                 {
753fba7fc7eSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
754fba7fc7eSJung-uk Kim                         Op->Asl.ExternalName);
7554a38ee6dSJung-uk Kim                 }
7564a38ee6dSJung-uk Kim                 else
7574a38ee6dSJung-uk Kim                 {
7584a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
759fba7fc7eSJung-uk Kim                         Op->Asl.ExternalName);
7604a38ee6dSJung-uk Kim                 }
7614a38ee6dSJung-uk Kim 
76253289f6aSNate Lawson                 goto FinishNode;
76353289f6aSNate Lawson             }
76453289f6aSNate Lawson 
765f556842eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
766f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
767f556842eSJung-uk Kim 
7689a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
76953289f6aSNate Lawson         }
770f8146b88SJung-uk Kim         else /* Status AE_OK */
771f8146b88SJung-uk Kim         {
772f8146b88SJung-uk Kim             /*
773f8146b88SJung-uk Kim              * Do not allow references to external scopes from the DSDT.
774f8146b88SJung-uk Kim              * This is because the DSDT is always loaded first, and the
775f8146b88SJung-uk Kim              * external reference cannot be resolved -- causing a runtime
776f8146b88SJung-uk Kim              * error because Scope() must be resolved immediately.
777f8146b88SJung-uk Kim              * 10/2015.
778f8146b88SJung-uk Kim              */
779f8146b88SJung-uk Kim             if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
780278f0de6SJung-uk Kim                 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
781f8146b88SJung-uk Kim             {
782f8146b88SJung-uk Kim                 /* However, allowed if the reference is within a method */
783f8146b88SJung-uk Kim 
784f8146b88SJung-uk Kim                 MethodOp = Op->Asl.Parent;
785f8146b88SJung-uk Kim                 while (MethodOp &&
786f8146b88SJung-uk Kim                       (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
787f8146b88SJung-uk Kim                 {
788f8146b88SJung-uk Kim                     MethodOp = MethodOp->Asl.Parent;
789f8146b88SJung-uk Kim                 }
790f8146b88SJung-uk Kim 
791f8146b88SJung-uk Kim                 if (!MethodOp)
792f8146b88SJung-uk Kim                 {
793f8146b88SJung-uk Kim                     /* Not in a control method, error */
794f8146b88SJung-uk Kim 
795f8146b88SJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
796f8146b88SJung-uk Kim                 }
797f8146b88SJung-uk Kim             }
798f8146b88SJung-uk Kim         }
79953289f6aSNate Lawson 
80053289f6aSNate Lawson         /* We found a node with this name, now check the type */
80153289f6aSNate Lawson 
80253289f6aSNate Lawson         switch (Node->Type)
80353289f6aSNate Lawson         {
80453289f6aSNate Lawson         case ACPI_TYPE_LOCAL_SCOPE:
80553289f6aSNate Lawson         case ACPI_TYPE_DEVICE:
80653289f6aSNate Lawson         case ACPI_TYPE_POWER:
80753289f6aSNate Lawson         case ACPI_TYPE_PROCESSOR:
80853289f6aSNate Lawson         case ACPI_TYPE_THERMAL:
80953289f6aSNate Lawson 
81053289f6aSNate Lawson             /* These are acceptable types - they all open a new scope */
81153289f6aSNate Lawson             break;
81253289f6aSNate Lawson 
81353289f6aSNate Lawson         case ACPI_TYPE_INTEGER:
81453289f6aSNate Lawson         case ACPI_TYPE_STRING:
81553289f6aSNate Lawson         case ACPI_TYPE_BUFFER:
81653289f6aSNate Lawson             /*
817fba7fc7eSJung-uk Kim              * These types we will allow, but we will change the type.
818fba7fc7eSJung-uk Kim              * This enables some existing code of the form:
81953289f6aSNate Lawson              *
82053289f6aSNate Lawson              *  Name (DEB, 0)
82153289f6aSNate Lawson              *  Scope (DEB) { ... }
82253289f6aSNate Lawson              *
82353289f6aSNate Lawson              * Which is used to workaround the fact that the MS interpreter
82453289f6aSNate Lawson              * does not allow Scope() forward references.
82553289f6aSNate Lawson              */
8266f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
82753289f6aSNate Lawson                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
8286f1f1a63SJung-uk Kim             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
82953289f6aSNate Lawson 
830fba7fc7eSJung-uk Kim             /* Switch the type to scope, open the new scope */
831fba7fc7eSJung-uk Kim 
832e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
833fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
834fba7fc7eSJung-uk Kim                 WalkState);
835e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
836e0ef747bSNate Lawson             {
837e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
838e0ef747bSNate Lawson             }
83953289f6aSNate Lawson             break;
84053289f6aSNate Lawson 
84153289f6aSNate Lawson         default:
84253289f6aSNate Lawson 
843fba7fc7eSJung-uk Kim             /* All other types are an error */
844fba7fc7eSJung-uk Kim 
8456f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
846fba7fc7eSJung-uk Kim                 AcpiUtGetTypeName (Node->Type));
8476f1f1a63SJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
84853289f6aSNate Lawson 
84953289f6aSNate Lawson             /*
85053289f6aSNate Lawson              * However, switch the type to be an actual scope so
85153289f6aSNate Lawson              * that compilation can continue without generating a whole
852e0ef747bSNate Lawson              * cascade of additional errors. Open the new scope.
85353289f6aSNate Lawson              */
854e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
855fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
856fba7fc7eSJung-uk Kim                 WalkState);
857e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
858e0ef747bSNate Lawson             {
859e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
860e0ef747bSNate Lawson             }
86153289f6aSNate Lawson             break;
86253289f6aSNate Lawson         }
86353289f6aSNate Lawson 
86453289f6aSNate Lawson         Status = AE_OK;
86553289f6aSNate Lawson         goto FinishNode;
86653289f6aSNate Lawson 
86753289f6aSNate Lawson     default:
86853289f6aSNate Lawson 
86953289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
87053289f6aSNate Lawson         break;
87153289f6aSNate Lawson     }
87253289f6aSNate Lawson 
87353289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
87453289f6aSNate Lawson         Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
87553289f6aSNate Lawson 
87653289f6aSNate Lawson     /* The name must not already exist */
87753289f6aSNate Lawson 
87853289f6aSNate Lawson     Flags |= ACPI_NS_ERROR_IF_FOUND;
87953289f6aSNate Lawson 
88053289f6aSNate Lawson     /*
8814a38ee6dSJung-uk Kim      * For opcodes that enter new names into the namespace,
8824a38ee6dSJung-uk Kim      * all prefix NameSegs must exist.
8834a38ee6dSJung-uk Kim      */
8844a38ee6dSJung-uk Kim     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
8854a38ee6dSJung-uk Kim     if (((WalkState->OpInfo->Flags & AML_NAMED) ||
8864a38ee6dSJung-uk Kim         (WalkState->OpInfo->Flags & AML_CREATE)) &&
8874a38ee6dSJung-uk Kim         (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
8884a38ee6dSJung-uk Kim     {
8894a38ee6dSJung-uk Kim         Flags |= ACPI_NS_PREFIX_MUST_EXIST;
8904a38ee6dSJung-uk Kim     }
8914a38ee6dSJung-uk Kim 
8924a38ee6dSJung-uk Kim     /*
89353289f6aSNate Lawson      * Enter the named type into the internal namespace. We enter the name
894fba7fc7eSJung-uk Kim      * as we go downward in the parse tree. Any necessary subobjects that
895fba7fc7eSJung-uk Kim      * involve arguments to the opcode must be created as we go back up the
896fba7fc7eSJung-uk Kim      * parse tree later.
89753289f6aSNate Lawson      */
89853289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
8991a39cfb0SJung-uk Kim         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
90053289f6aSNate Lawson     if (ACPI_FAILURE (Status))
90153289f6aSNate Lawson     {
90253289f6aSNate Lawson         if (Status == AE_ALREADY_EXISTS)
90353289f6aSNate Lawson         {
90453289f6aSNate Lawson             /* The name already exists in this scope */
90553289f6aSNate Lawson 
90653289f6aSNate Lawson             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
90753289f6aSNate Lawson             {
9081a39cfb0SJung-uk Kim                 /* Allow multiple references to the same scope */
9091a39cfb0SJung-uk Kim 
91053289f6aSNate Lawson                 Node->Type = (UINT8) ObjectType;
91153289f6aSNate Lawson                 Status = AE_OK;
91253289f6aSNate Lawson             }
913ec0234b4SJung-uk Kim             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) ||
914f8146b88SJung-uk Kim                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
915f8146b88SJung-uk Kim             {
916ec0234b4SJung-uk Kim                 Status = LdAnalyzeExternals (Node, Op, ActualObjectType,
917ec0234b4SJung-uk Kim                     ObjectType, WalkState);
918ec0234b4SJung-uk Kim                 if (ACPI_FAILURE (Status))
919ec0234b4SJung-uk Kim                 {
920ec0234b4SJung-uk Kim                     if (Status == AE_ERROR)
921ec0234b4SJung-uk Kim                     {
922f8146b88SJung-uk Kim                         /*
923ec0234b4SJung-uk Kim                          * The use of AE_ERROR here indicates that there was a
924ec0234b4SJung-uk Kim                          * compiler error emitted in LdAnalyzeExternals which
925ec0234b4SJung-uk Kim                          * means that the caller should proceed to the next Op
926ec0234b4SJung-uk Kim                          * for analysis of subsequent parse objects.
927f8146b88SJung-uk Kim                          */
928f8146b88SJung-uk Kim                         Status = AE_OK;
929f8146b88SJung-uk Kim                     }
930ec0234b4SJung-uk Kim                     return_ACPI_STATUS (Status);
931f8146b88SJung-uk Kim                 }
932f8146b88SJung-uk Kim             }
93353289f6aSNate Lawson             else
93453289f6aSNate Lawson             {
9351a39cfb0SJung-uk Kim                 /* Valid error, object already exists */
9361a39cfb0SJung-uk Kim 
937f425b8beSJung-uk Kim                 ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
938f425b8beSJung-uk Kim 
93967d9aa44SJung-uk Kim                 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
940f425b8beSJung-uk Kim                     ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
941f425b8beSJung-uk Kim                     ExternalPath);
942f425b8beSJung-uk Kim 
943f425b8beSJung-uk Kim                 if (ExternalPath)
944f425b8beSJung-uk Kim                 {
945f425b8beSJung-uk Kim                     ACPI_FREE (ExternalPath);
946f425b8beSJung-uk Kim                 }
9479a179dd8SJung-uk Kim                 return_ACPI_STATUS (AE_OK);
94853289f6aSNate Lawson             }
94953289f6aSNate Lawson         }
9504a38ee6dSJung-uk Kim         else if (AE_NOT_FOUND)
9514a38ee6dSJung-uk Kim         {
9524a38ee6dSJung-uk Kim             /*
9534a38ee6dSJung-uk Kim              * One or more prefix NameSegs of the NamePath do not exist
9544a38ee6dSJung-uk Kim              * (all of them must exist). Attempt to continue compilation
9554a38ee6dSJung-uk Kim              * by setting the current scope to the root.
9564a38ee6dSJung-uk Kim              */
9574a38ee6dSJung-uk Kim             Node = AcpiGbl_RootNode;
9584a38ee6dSJung-uk Kim             Status = AE_OK;
9594a38ee6dSJung-uk Kim         }
96053289f6aSNate Lawson         else
96153289f6aSNate Lawson         {
9624a38ee6dSJung-uk Kim             /* Flag all other errors as coming from the ACPICA core */
9634a38ee6dSJung-uk Kim 
964fba7fc7eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
965f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
9669a179dd8SJung-uk Kim             return_ACPI_STATUS (Status);
96753289f6aSNate Lawson         }
96853289f6aSNate Lawson     }
96953289f6aSNate Lawson 
97037d7a5bcSJung-uk Kim     /* Check special names like _WAK and _PTS */
97137d7a5bcSJung-uk Kim 
97237d7a5bcSJung-uk Kim     LdCheckSpecialNames (Node, Op);
97337d7a5bcSJung-uk Kim 
9741a39cfb0SJung-uk Kim     if (ForceNewScope)
9751a39cfb0SJung-uk Kim     {
9761a39cfb0SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
9771a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
9781a39cfb0SJung-uk Kim         {
9791a39cfb0SJung-uk Kim             return_ACPI_STATUS (Status);
9801a39cfb0SJung-uk Kim         }
9811a39cfb0SJung-uk Kim     }
98253289f6aSNate Lawson 
98353289f6aSNate Lawson FinishNode:
98453289f6aSNate Lawson     /*
98553289f6aSNate Lawson      * Point the parse node to the new namespace node, and point
98653289f6aSNate Lawson      * the Node back to the original Parse node
98753289f6aSNate Lawson      */
98853289f6aSNate Lawson     Op->Asl.Node = Node;
989fba7fc7eSJung-uk Kim     Node->Op = Op;
99053289f6aSNate Lawson 
991f9a6772eSJung-uk Kim     /*
992f9a6772eSJung-uk Kim      * Set the actual data type if appropriate (EXTERNAL term only)
993f9a6772eSJung-uk Kim      * As of 11/19/2019, ASL External() does not support parameter
994f9a6772eSJung-uk Kim      * counts. When an External method is loaded, the parameter count is
995ec0234b4SJung-uk Kim      * recorded in the external's arg count parameter. The parameter count may
996ec0234b4SJung-uk Kim      * or may not be known in the declaration. If the value of this node turns
997ec0234b4SJung-uk Kim      * out to be ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS, it indicates that
998ec0234b4SJung-uk Kim      * we do not know the parameter count and that we must look at the usage of
999ec0234b4SJung-uk Kim      * the External method call to get this information.
1000f9a6772eSJung-uk Kim      */
100153289f6aSNate Lawson     if (ActualObjectType != ACPI_TYPE_ANY)
100253289f6aSNate Lawson     {
100353289f6aSNate Lawson         Node->Type = (UINT8) ActualObjectType;
1004ec0234b4SJung-uk Kim         Node->Value = (UINT32)
1005ec0234b4SJung-uk Kim             Op->Asl.Child->Asl.Next->Asl.Next->Asl.Value.Integer;
100653289f6aSNate Lawson     }
100753289f6aSNate Lawson 
100853289f6aSNate Lawson     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
100953289f6aSNate Lawson     {
101053289f6aSNate Lawson         /*
1011fba7fc7eSJung-uk Kim          * Get the method argument count from "Extra" and save
1012fba7fc7eSJung-uk Kim          * it in the namespace node
101353289f6aSNate Lawson          */
1014fba7fc7eSJung-uk Kim         Node->Value = (UINT32) Op->Asl.Extra;
101553289f6aSNate Lawson     }
101653289f6aSNate Lawson 
10179a179dd8SJung-uk Kim     return_ACPI_STATUS (Status);
101853289f6aSNate Lawson }
101953289f6aSNate Lawson 
102053289f6aSNate Lawson 
102153289f6aSNate Lawson /*******************************************************************************
102253289f6aSNate Lawson  *
1023ec0234b4SJung-uk Kim  * FUNCTION:    LdAnalyzeExternals
1024ec0234b4SJung-uk Kim  *
1025*3ee58df5SJung-uk Kim  * PARAMETERS:  Type1
1026*3ee58df5SJung-uk Kim  *              Type2
1027*3ee58df5SJung-uk Kim  *
1028*3ee58df5SJung-uk Kim  * RETURN:      BOOLEAN
1029*3ee58df5SJung-uk Kim  *
1030*3ee58df5SJung-uk Kim  * DESCRIPTION: Match Type1 and Type2 with the assumption that one might be
1031*3ee58df5SJung-uk Kim  *              using external types and another might be using local types.
1032*3ee58df5SJung-uk Kim  *              This should be used to compare the types found in external
1033*3ee58df5SJung-uk Kim  *              declarations with types found in other external declarations or
1034*3ee58df5SJung-uk Kim  *              named object declaration. This should not be used to match two
1035*3ee58df5SJung-uk Kim  *              object type declarations.
1036*3ee58df5SJung-uk Kim  *
1037*3ee58df5SJung-uk Kim  ******************************************************************************/
1038*3ee58df5SJung-uk Kim 
1039*3ee58df5SJung-uk Kim static BOOLEAN
1040*3ee58df5SJung-uk Kim LdTypesMatchExternType (
1041*3ee58df5SJung-uk Kim     ACPI_OBJECT_TYPE        Type1,
1042*3ee58df5SJung-uk Kim     ACPI_OBJECT_TYPE        Type2)
1043*3ee58df5SJung-uk Kim {
1044*3ee58df5SJung-uk Kim     BOOLEAN                 Type1IsLocal = Type1 > ACPI_TYPE_EXTERNAL_MAX;
1045*3ee58df5SJung-uk Kim     BOOLEAN                 Type2IsLocal = Type2 > ACPI_TYPE_EXTERNAL_MAX;
1046*3ee58df5SJung-uk Kim     ACPI_OBJECT_TYPE        ExternalType;
1047*3ee58df5SJung-uk Kim     ACPI_OBJECT_TYPE        LocalType;
1048*3ee58df5SJung-uk Kim 
1049*3ee58df5SJung-uk Kim 
1050*3ee58df5SJung-uk Kim     /*
1051*3ee58df5SJung-uk Kim      * The inputs could represent types that are local to ACPICA or types that
1052*3ee58df5SJung-uk Kim      * are known externally. Some local types, such as the OperationRegion
1053*3ee58df5SJung-uk Kim      * field units, are defined with more granularity than ACPICA local types.
1054*3ee58df5SJung-uk Kim      *
1055*3ee58df5SJung-uk Kim      * Therefore, map the local types to the external types before matching.
1056*3ee58df5SJung-uk Kim      */
1057*3ee58df5SJung-uk Kim     if (Type1IsLocal && !Type2IsLocal)
1058*3ee58df5SJung-uk Kim     {
1059*3ee58df5SJung-uk Kim         LocalType = Type1;
1060*3ee58df5SJung-uk Kim         ExternalType = Type2;
1061*3ee58df5SJung-uk Kim     }
1062*3ee58df5SJung-uk Kim     else if (!Type1IsLocal && Type2IsLocal)
1063*3ee58df5SJung-uk Kim     {
1064*3ee58df5SJung-uk Kim         LocalType = Type2;
1065*3ee58df5SJung-uk Kim         ExternalType = Type1;
1066*3ee58df5SJung-uk Kim     }
1067*3ee58df5SJung-uk Kim     else
1068*3ee58df5SJung-uk Kim     {
1069*3ee58df5SJung-uk Kim         return (Type1 == Type2);
1070*3ee58df5SJung-uk Kim     }
1071*3ee58df5SJung-uk Kim 
1072*3ee58df5SJung-uk Kim     switch (LocalType)
1073*3ee58df5SJung-uk Kim     {
1074*3ee58df5SJung-uk Kim         case ACPI_TYPE_LOCAL_REGION_FIELD:
1075*3ee58df5SJung-uk Kim         case ACPI_TYPE_LOCAL_BANK_FIELD:
1076*3ee58df5SJung-uk Kim         case ACPI_TYPE_LOCAL_INDEX_FIELD:
1077*3ee58df5SJung-uk Kim 
1078*3ee58df5SJung-uk Kim             LocalType = ACPI_TYPE_FIELD_UNIT;
1079*3ee58df5SJung-uk Kim             break;
1080*3ee58df5SJung-uk Kim 
1081*3ee58df5SJung-uk Kim         default:
1082*3ee58df5SJung-uk Kim             break;
1083*3ee58df5SJung-uk Kim     }
1084*3ee58df5SJung-uk Kim 
1085*3ee58df5SJung-uk Kim     return (LocalType == ExternalType);
1086*3ee58df5SJung-uk Kim }
1087*3ee58df5SJung-uk Kim 
1088*3ee58df5SJung-uk Kim 
1089*3ee58df5SJung-uk Kim /*******************************************************************************
1090*3ee58df5SJung-uk Kim  *
1091*3ee58df5SJung-uk Kim  * FUNCTION:    LdAnalyzeExternals
1092*3ee58df5SJung-uk Kim  *
1093ec0234b4SJung-uk Kim  * PARAMETERS:  Node            - Node that represents the named object
1094ec0234b4SJung-uk Kim  *              Op              - Named object declaring this named object
1095ec0234b4SJung-uk Kim  *              ExternalOpType  - Type of ExternalOp
1096ec0234b4SJung-uk Kim  *              ObjectType      - Type of Declared object
1097ec0234b4SJung-uk Kim  *              WalkState       - Current WalkState
1098ec0234b4SJung-uk Kim  *
1099ec0234b4SJung-uk Kim  * RETURN:      Status
1100ec0234b4SJung-uk Kim  *
1101ec0234b4SJung-uk Kim  * DESCRIPTION: Node and Op represents an identically named object declaration
1102ec0234b4SJung-uk Kim  *              that is either declared by the ASL external keyword or declared
1103ec0234b4SJung-uk Kim  *              by operators that declare named objects (i.e. Name, Device,
1104ec0234b4SJung-uk Kim  *              OperationRegion, and etc.). This function ensures that the
1105ec0234b4SJung-uk Kim  *              declarations do not contradict each other.
1106ec0234b4SJung-uk Kim  *
1107ec0234b4SJung-uk Kim  ******************************************************************************/
1108ec0234b4SJung-uk Kim 
1109ec0234b4SJung-uk Kim static ACPI_STATUS
1110ec0234b4SJung-uk Kim LdAnalyzeExternals (
1111ec0234b4SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node,
1112ec0234b4SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
1113ec0234b4SJung-uk Kim     ACPI_OBJECT_TYPE        ExternalOpType,
1114ec0234b4SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType,
1115ec0234b4SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
1116ec0234b4SJung-uk Kim {
1117ec0234b4SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
1118ec0234b4SJung-uk Kim     ACPI_OBJECT_TYPE        ActualExternalOpType;
1119ec0234b4SJung-uk Kim     ACPI_OBJECT_TYPE        ActualOpType;
1120ec0234b4SJung-uk Kim     ACPI_PARSE_OBJECT       *ExternalOp;
1121ec0234b4SJung-uk Kim     ACPI_PARSE_OBJECT       *ActualOp;
1122ec0234b4SJung-uk Kim 
1123ec0234b4SJung-uk Kim 
1124ec0234b4SJung-uk Kim     /*
1125ec0234b4SJung-uk Kim      * The declaration represented by Node and Op must have the same type.
1126ec0234b4SJung-uk Kim      * The type of the external Op is represented by ExternalOpType. However,
1127ec0234b4SJung-uk Kim      * the type of the pre-existing declaration depends on whether if Op
1128ec0234b4SJung-uk Kim      * is an external declaration or an actual declaration.
1129ec0234b4SJung-uk Kim      */
1130ec0234b4SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1131ec0234b4SJung-uk Kim     {
1132ec0234b4SJung-uk Kim         ActualExternalOpType = ExternalOpType;
1133ec0234b4SJung-uk Kim         ActualOpType = Node->Type;
1134ec0234b4SJung-uk Kim     }
1135ec0234b4SJung-uk Kim     else
1136ec0234b4SJung-uk Kim     {
1137ec0234b4SJung-uk Kim         ActualExternalOpType = Node->Type;
1138ec0234b4SJung-uk Kim         ActualOpType = ObjectType;
1139ec0234b4SJung-uk Kim     }
1140ec0234b4SJung-uk Kim 
1141ec0234b4SJung-uk Kim     if ((ActualOpType != ACPI_TYPE_ANY) &&
1142ec0234b4SJung-uk Kim         (ActualExternalOpType != ACPI_TYPE_ANY) &&
1143*3ee58df5SJung-uk Kim         !LdTypesMatchExternType (ActualExternalOpType, ActualOpType))
1144ec0234b4SJung-uk Kim     {
1145ec0234b4SJung-uk Kim         if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1146ec0234b4SJung-uk Kim             Node->Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1147ec0234b4SJung-uk Kim         {
1148*3ee58df5SJung-uk Kim             AslDualParseOpError (ASL_WARNING,
1149ec0234b4SJung-uk Kim                 ASL_MSG_DUPLICATE_EXTERN_MISMATCH, Op, NULL,
1150ec0234b4SJung-uk Kim                 ASL_MSG_DUPLICATE_EXTERN_FOUND_HERE, Node->Op, NULL);
1151ec0234b4SJung-uk Kim         }
1152ec0234b4SJung-uk Kim         else
1153ec0234b4SJung-uk Kim         {
1154ec0234b4SJung-uk Kim             if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1155ec0234b4SJung-uk Kim                 Node->Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1156ec0234b4SJung-uk Kim             {
1157ec0234b4SJung-uk Kim                 ExternalOp = Op;
1158ec0234b4SJung-uk Kim                 ActualOp = Node->Op;
1159ec0234b4SJung-uk Kim             }
1160ec0234b4SJung-uk Kim             else
1161ec0234b4SJung-uk Kim             {
1162ec0234b4SJung-uk Kim                 ExternalOp = Node->Op;
1163ec0234b4SJung-uk Kim                 ActualOp = Op;
1164ec0234b4SJung-uk Kim             }
1165*3ee58df5SJung-uk Kim             AslDualParseOpError (ASL_WARNING,
1166ec0234b4SJung-uk Kim                 ASL_MSG_DECLARATION_TYPE_MISMATCH, ExternalOp, NULL,
1167ec0234b4SJung-uk Kim                 ASL_MSG_TYPE_MISMATCH_FOUND_HERE, ActualOp, NULL);
1168ec0234b4SJung-uk Kim         }
1169ec0234b4SJung-uk Kim     }
1170ec0234b4SJung-uk Kim 
1171ec0234b4SJung-uk Kim     if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1172ec0234b4SJung-uk Kim         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
1173ec0234b4SJung-uk Kim     {
1174ec0234b4SJung-uk Kim         /*
1175ec0234b4SJung-uk Kim          * Allow one create on an object or segment that was
1176ec0234b4SJung-uk Kim          * previously declared External
1177ec0234b4SJung-uk Kim          */
1178ec0234b4SJung-uk Kim         Node->Flags &= ~ANOBJ_IS_EXTERNAL;
1179ec0234b4SJung-uk Kim         Node->Type = (UINT8) ObjectType;
1180ec0234b4SJung-uk Kim 
1181ec0234b4SJung-uk Kim         /* Just retyped a node, probably will need to open a scope */
1182ec0234b4SJung-uk Kim 
1183ec0234b4SJung-uk Kim         if (AcpiNsOpensScope (ObjectType))
1184ec0234b4SJung-uk Kim         {
1185ec0234b4SJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1186ec0234b4SJung-uk Kim             if (ACPI_FAILURE (Status))
1187ec0234b4SJung-uk Kim             {
1188ec0234b4SJung-uk Kim                 return (Status);
1189ec0234b4SJung-uk Kim             }
1190ec0234b4SJung-uk Kim         }
1191ec0234b4SJung-uk Kim 
1192ec0234b4SJung-uk Kim         Status = AE_OK;
1193ec0234b4SJung-uk Kim     }
1194ec0234b4SJung-uk Kim     else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
1195ec0234b4SJung-uk Kim              (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1196ec0234b4SJung-uk Kim     {
1197ec0234b4SJung-uk Kim         /*
1198ec0234b4SJung-uk Kim          * Allow externals in same scope as the definition of the
1199ec0234b4SJung-uk Kim          * actual object. Similar to C. Allows multiple definition
1200ec0234b4SJung-uk Kim          * blocks that refer to each other in the same file.
1201ec0234b4SJung-uk Kim          */
1202ec0234b4SJung-uk Kim         Status = AE_OK;
1203ec0234b4SJung-uk Kim     }
1204ec0234b4SJung-uk Kim     else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1205ec0234b4SJung-uk Kim              (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
1206ec0234b4SJung-uk Kim              (ObjectType == ACPI_TYPE_ANY))
1207ec0234b4SJung-uk Kim     {
1208ec0234b4SJung-uk Kim         /* Allow update of externals of unknown type. */
1209ec0234b4SJung-uk Kim 
1210ec0234b4SJung-uk Kim         Node->Type = (UINT8) ExternalOpType;
1211ec0234b4SJung-uk Kim         Status = AE_OK;
1212ec0234b4SJung-uk Kim     }
1213ec0234b4SJung-uk Kim 
1214ec0234b4SJung-uk Kim     return (Status);
1215ec0234b4SJung-uk Kim }
1216ec0234b4SJung-uk Kim 
1217ec0234b4SJung-uk Kim 
1218ec0234b4SJung-uk Kim /*******************************************************************************
1219ec0234b4SJung-uk Kim  *
122037d7a5bcSJung-uk Kim  * FUNCTION:    LdCheckSpecialNames
122137d7a5bcSJung-uk Kim  *
122237d7a5bcSJung-uk Kim  * PARAMETERS:  Node        - Node that represents the named object
122337d7a5bcSJung-uk Kim  *              Op          - Named object declaring this named object
122437d7a5bcSJung-uk Kim  *
122537d7a5bcSJung-uk Kim  * RETURN:      None
122637d7a5bcSJung-uk Kim  *
122737d7a5bcSJung-uk Kim  * DESCRIPTION: Check if certain named objects are declared in the incorrect
122837d7a5bcSJung-uk Kim  *              scope. Special named objects are listed in
122937d7a5bcSJung-uk Kim  *              AslGbl_SpecialNamedObjects and can only be declared at the root
1230a009b7dcSJung-uk Kim  *              scope. _UID inside of a processor declaration must not be a
1231a009b7dcSJung-uk Kim  *              string.
123237d7a5bcSJung-uk Kim  *
123337d7a5bcSJung-uk Kim  ******************************************************************************/
123437d7a5bcSJung-uk Kim 
123537d7a5bcSJung-uk Kim static void
123637d7a5bcSJung-uk Kim LdCheckSpecialNames (
123737d7a5bcSJung-uk Kim     ACPI_NAMESPACE_NODE     *Node,
123837d7a5bcSJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
123937d7a5bcSJung-uk Kim {
124037d7a5bcSJung-uk Kim     UINT32                  i;
124137d7a5bcSJung-uk Kim 
124237d7a5bcSJung-uk Kim 
124337d7a5bcSJung-uk Kim     for (i = 0; i < MAX_SPECIAL_NAMES; i++)
124437d7a5bcSJung-uk Kim     {
124537d7a5bcSJung-uk Kim         if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
124637d7a5bcSJung-uk Kim             Node->Parent != AcpiGbl_RootNode)
124737d7a5bcSJung-uk Kim         {
124837d7a5bcSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
124937d7a5bcSJung-uk Kim             return;
125037d7a5bcSJung-uk Kim         }
125137d7a5bcSJung-uk Kim     }
1252a009b7dcSJung-uk Kim 
1253a009b7dcSJung-uk Kim     if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1254a009b7dcSJung-uk Kim         Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1255a009b7dcSJung-uk Kim         Node->Type == ACPI_TYPE_STRING)
1256a009b7dcSJung-uk Kim     {
1257a009b7dcSJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1258a009b7dcSJung-uk Kim     }
125937d7a5bcSJung-uk Kim }
126037d7a5bcSJung-uk Kim 
126137d7a5bcSJung-uk Kim 
126237d7a5bcSJung-uk Kim /*******************************************************************************
126337d7a5bcSJung-uk Kim  *
1264a9f12690SJung-uk Kim  * FUNCTION:    LdNamespace2Begin
1265a9f12690SJung-uk Kim  *
1266a9f12690SJung-uk Kim  * PARAMETERS:  ASL_WALK_CALLBACK
1267a9f12690SJung-uk Kim  *
1268a9f12690SJung-uk Kim  * RETURN:      Status
1269a9f12690SJung-uk Kim  *
1270a9f12690SJung-uk Kim  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1271a9f12690SJung-uk Kim  *              Second pass resolves some forward references.
1272a9f12690SJung-uk Kim  *
1273a9f12690SJung-uk Kim  * Notes:
1274a9f12690SJung-uk Kim  * Currently only needs to handle the Alias operator.
1275a9f12690SJung-uk Kim  * Could be used to allow forward references from the Scope() operator, but
1276a9f12690SJung-uk Kim  * the MS interpreter does not allow this, so this compiler does not either.
1277a9f12690SJung-uk Kim  *
1278a9f12690SJung-uk Kim  ******************************************************************************/
1279a9f12690SJung-uk Kim 
1280a9f12690SJung-uk Kim static ACPI_STATUS
1281a9f12690SJung-uk Kim LdNamespace2Begin (
1282a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
1283a9f12690SJung-uk Kim     UINT32                  Level,
1284a9f12690SJung-uk Kim     void                    *Context)
1285a9f12690SJung-uk Kim {
1286a9f12690SJung-uk Kim     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1287a9f12690SJung-uk Kim     ACPI_STATUS             Status;
1288a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
1289a9f12690SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType;
1290a9f12690SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
1291a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Arg;
1292a9f12690SJung-uk Kim     char                    *Path;
1293a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *TargetNode;
1294a9f12690SJung-uk Kim 
1295a9f12690SJung-uk Kim 
1296a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace2Begin);
1297a9f12690SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1298a9f12690SJung-uk Kim         Op, Op->Asl.ParseOpName));
1299a9f12690SJung-uk Kim 
1300a9f12690SJung-uk Kim 
1301a9f12690SJung-uk Kim     /* Ignore Ops with no namespace node */
1302a9f12690SJung-uk Kim 
1303a9f12690SJung-uk Kim     Node = Op->Asl.Node;
1304a9f12690SJung-uk Kim     if (!Node)
1305a9f12690SJung-uk Kim     {
1306a9f12690SJung-uk Kim         return (AE_OK);
1307a9f12690SJung-uk Kim     }
1308a9f12690SJung-uk Kim 
1309a9f12690SJung-uk Kim     /* Get the type to determine if we should push the scope */
1310a9f12690SJung-uk Kim 
1311a9f12690SJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
13125f9b24faSJung-uk Kim         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1313a9f12690SJung-uk Kim     {
1314a9f12690SJung-uk Kim         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1315a9f12690SJung-uk Kim     }
1316a9f12690SJung-uk Kim     else
1317a9f12690SJung-uk Kim     {
1318a9f12690SJung-uk Kim         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1319a9f12690SJung-uk Kim     }
1320a9f12690SJung-uk Kim 
1321a9f12690SJung-uk Kim     /* Push scope for Resource Templates */
1322a9f12690SJung-uk Kim 
1323a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1324a9f12690SJung-uk Kim     {
13255f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1326a9f12690SJung-uk Kim         {
1327a9f12690SJung-uk Kim             ForceNewScope = TRUE;
1328a9f12690SJung-uk Kim         }
1329a9f12690SJung-uk Kim     }
1330a9f12690SJung-uk Kim 
1331a9f12690SJung-uk Kim     /* Push the scope stack */
1332a9f12690SJung-uk Kim 
1333a9f12690SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1334a9f12690SJung-uk Kim     {
1335a9f12690SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1336a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1337a9f12690SJung-uk Kim         {
1338a9f12690SJung-uk Kim             return_ACPI_STATUS (Status);
1339a9f12690SJung-uk Kim         }
1340a9f12690SJung-uk Kim     }
1341a9f12690SJung-uk Kim 
1342a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1343a9f12690SJung-uk Kim     {
13444a38ee6dSJung-uk Kim         /*
13454a38ee6dSJung-uk Kim          * Complete the alias node by getting and saving the target node.
13464a38ee6dSJung-uk Kim          * First child is the alias target
13474a38ee6dSJung-uk Kim          */
1348a9f12690SJung-uk Kim         Arg = Op->Asl.Child;
1349a9f12690SJung-uk Kim 
1350a9f12690SJung-uk Kim         /* Get the target pathname */
1351a9f12690SJung-uk Kim 
1352a9f12690SJung-uk Kim         Path = Arg->Asl.Namepath;
1353a9f12690SJung-uk Kim         if (!Path)
1354a9f12690SJung-uk Kim         {
1355a9f12690SJung-uk Kim             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1356a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
1357a9f12690SJung-uk Kim             {
1358a9f12690SJung-uk Kim                 return (Status);
1359a9f12690SJung-uk Kim             }
1360a9f12690SJung-uk Kim         }
1361a9f12690SJung-uk Kim 
1362a9f12690SJung-uk Kim         /* Get the NS node associated with the target. It must exist. */
1363a9f12690SJung-uk Kim 
1364a9f12690SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1365a9f12690SJung-uk Kim             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1366a9f12690SJung-uk Kim             WalkState, &TargetNode);
1367a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1368a9f12690SJung-uk Kim         {
1369a9f12690SJung-uk Kim             if (Status == AE_NOT_FOUND)
1370a9f12690SJung-uk Kim             {
13714a38ee6dSJung-uk Kim                 /* Standalone NameSeg vs. NamePath */
1372a9f12690SJung-uk Kim 
1373278f0de6SJung-uk Kim                 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
13744a38ee6dSJung-uk Kim                 {
13754a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
13764a38ee6dSJung-uk Kim                         Arg->Asl.ExternalName);
13774a38ee6dSJung-uk Kim                 }
13784a38ee6dSJung-uk Kim                 else
13794a38ee6dSJung-uk Kim                 {
13804a38ee6dSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
13814a38ee6dSJung-uk Kim                         Arg->Asl.ExternalName);
13824a38ee6dSJung-uk Kim                 }
13834a38ee6dSJung-uk Kim 
13844a38ee6dSJung-uk Kim #if 0
13854a38ee6dSJung-uk Kim /*
13864a38ee6dSJung-uk Kim  * NOTE: Removed 10/2018 to enhance compiler error reporting. No
13874a38ee6dSJung-uk Kim  * regressions seen.
13884a38ee6dSJung-uk Kim  */
1389a9f12690SJung-uk Kim                 /*
1390a9f12690SJung-uk Kim                  * The name was not found, go ahead and create it.
1391a9f12690SJung-uk Kim                  * This prevents more errors later.
1392a9f12690SJung-uk Kim                  */
1393a9f12690SJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
13944a38ee6dSJung-uk Kim                     ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
13954a38ee6dSJung-uk Kim                     ACPI_NS_NO_UPSEARCH, WalkState, &Node);
13964a38ee6dSJung-uk Kim #endif
13974a38ee6dSJung-uk Kim                 return (Status);
13984a38ee6dSJung-uk Kim /* Removed: return (AE_OK)*/
1399a9f12690SJung-uk Kim             }
1400a9f12690SJung-uk Kim 
1401f556842eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
1402f556842eSJung-uk Kim                 "Failure from namespace lookup", FALSE);
1403a9f12690SJung-uk Kim             return (AE_OK);
1404a9f12690SJung-uk Kim         }
1405a9f12690SJung-uk Kim 
1406a9f12690SJung-uk Kim         /* Save the target node within the alias node */
1407a9f12690SJung-uk Kim 
1408a9f12690SJung-uk Kim         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1409a9f12690SJung-uk Kim     }
1410a9f12690SJung-uk Kim 
1411a9f12690SJung-uk Kim     return (AE_OK);
1412a9f12690SJung-uk Kim }
1413a9f12690SJung-uk Kim 
1414a9f12690SJung-uk Kim 
1415a9f12690SJung-uk Kim /*******************************************************************************
1416a9f12690SJung-uk Kim  *
1417a9f12690SJung-uk Kim  * FUNCTION:    LdCommonNamespaceEnd
141853289f6aSNate Lawson  *
141953289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
142053289f6aSNate Lawson  *
142153289f6aSNate Lawson  * RETURN:      Status
142253289f6aSNate Lawson  *
142353289f6aSNate Lawson  * DESCRIPTION: Ascending callback used during the loading of the namespace,
142453289f6aSNate Lawson  *              We only need to worry about managing the scope stack here.
142553289f6aSNate Lawson  *
142653289f6aSNate Lawson  ******************************************************************************/
142753289f6aSNate Lawson 
1428fba7fc7eSJung-uk Kim static ACPI_STATUS
1429a9f12690SJung-uk Kim LdCommonNamespaceEnd (
143053289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
143153289f6aSNate Lawson     UINT32                  Level,
143253289f6aSNate Lawson     void                    *Context)
143353289f6aSNate Lawson {
143453289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
143553289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
14361a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
143753289f6aSNate Lawson 
143853289f6aSNate Lawson 
1439a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
144053289f6aSNate Lawson 
144153289f6aSNate Lawson 
144253289f6aSNate Lawson     /* We are only interested in opcodes that have an associated name */
144353289f6aSNate Lawson 
144453289f6aSNate Lawson     if (!Op->Asl.Namepath)
144553289f6aSNate Lawson     {
144653289f6aSNate Lawson         return (AE_OK);
144753289f6aSNate Lawson     }
144853289f6aSNate Lawson 
144953289f6aSNate Lawson     /* Get the type to determine if we should pop the scope */
145053289f6aSNate Lawson 
145153289f6aSNate Lawson     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
14525f9b24faSJung-uk Kim         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
145353289f6aSNate Lawson     {
145453289f6aSNate Lawson         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
145553289f6aSNate Lawson 
145653289f6aSNate Lawson         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
145753289f6aSNate Lawson     }
145853289f6aSNate Lawson     else
145953289f6aSNate Lawson     {
146053289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
146153289f6aSNate Lawson     }
146253289f6aSNate Lawson 
14631a39cfb0SJung-uk Kim     /* Pop scope that was pushed for Resource Templates */
14641a39cfb0SJung-uk Kim 
14651a39cfb0SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
14661a39cfb0SJung-uk Kim     {
14675f9b24faSJung-uk Kim         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
14681a39cfb0SJung-uk Kim         {
14691a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
14701a39cfb0SJung-uk Kim         }
14711a39cfb0SJung-uk Kim     }
14721a39cfb0SJung-uk Kim 
147353289f6aSNate Lawson     /* Pop the scope stack */
147453289f6aSNate Lawson 
14751a39cfb0SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
147653289f6aSNate Lawson     {
147753289f6aSNate Lawson         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
147853289f6aSNate Lawson             "(%s): Popping scope for Op [%s] %p\n",
147953289f6aSNate Lawson             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
148053289f6aSNate Lawson 
1481fba7fc7eSJung-uk Kim         (void) AcpiDsScopeStackPop (WalkState);
148253289f6aSNate Lawson     }
148353289f6aSNate Lawson 
148453289f6aSNate Lawson     return (AE_OK);
148553289f6aSNate Lawson }
1486