1 /******************************************************************************
2  *
3  * Module Name: dswload - Dispatcher namespace load callbacks
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "aslcompiler.h"
153 #include "amlcode.h"
154 #include "acdispat.h"
155 #include "acnamesp.h"
156 #include "acparser.h"
157 #include "aslcompiler.y.h"
158 
159 
160 #define _COMPONENT          ACPI_COMPILER
161         ACPI_MODULE_NAME    ("aslload")
162 
163 /* Local prototypes */
164 
165 static ACPI_STATUS
166 LdLoadFieldElements (
167     UINT32                  AmlType,
168     ACPI_PARSE_OBJECT       *Op,
169     ACPI_WALK_STATE         *WalkState);
170 
171 static ACPI_STATUS
172 LdLoadResourceElements (
173     ACPI_PARSE_OBJECT       *Op,
174     ACPI_WALK_STATE         *WalkState);
175 
176 static ACPI_STATUS
177 LdNamespace1Begin (
178     ACPI_PARSE_OBJECT       *Op,
179     UINT32                  Level,
180     void                    *Context);
181 
182 static ACPI_STATUS
183 LdNamespace2Begin (
184     ACPI_PARSE_OBJECT       *Op,
185     UINT32                  Level,
186     void                    *Context);
187 
188 static ACPI_STATUS
189 LdCommonNamespaceEnd (
190     ACPI_PARSE_OBJECT       *Op,
191     UINT32                  Level,
192     void                    *Context);
193 
194 static void
195 LdCheckSpecialNames (
196     ACPI_NAMESPACE_NODE     *Node,
197     ACPI_PARSE_OBJECT       *Op);
198 
199 static ACPI_STATUS
200 LdAnalyzeExternals (
201     ACPI_NAMESPACE_NODE     *Node,
202     ACPI_PARSE_OBJECT       *Op,
203     ACPI_OBJECT_TYPE        ExternalOpType,
204     ACPI_OBJECT_TYPE        ObjectType,
205     ACPI_WALK_STATE         *WalkState);
206 
207 
208 /*******************************************************************************
209  *
210  * FUNCTION:    LdLoadNamespace
211  *
212  * PARAMETERS:  RootOp      - Root of the parse tree
213  *
214  * RETURN:      Status
215  *
216  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
217  *              named ASL/AML objects into the namespace. The namespace is
218  *              constructed in order to resolve named references and references
219  *              to named fields within resource templates/descriptors.
220  *
221  ******************************************************************************/
222 
223 ACPI_STATUS
224 LdLoadNamespace (
225     ACPI_PARSE_OBJECT       *RootOp)
226 {
227     ACPI_WALK_STATE         *WalkState;
228 
229 
230     /* Create a new walk state */
231 
232     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
233     if (!WalkState)
234     {
235         return (AE_NO_MEMORY);
236     }
237 
238     /* Walk the entire parse tree, first pass */
239 
240     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
241         LdCommonNamespaceEnd, WalkState);
242 
243     /* Second pass to handle forward references */
244 
245     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
246         LdCommonNamespaceEnd, WalkState);
247 
248     /* Dump the namespace if debug is enabled */
249 
250     if (AcpiDbgLevel & ACPI_LV_TABLES)
251     {
252         AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
253     }
254 
255     ACPI_FREE (WalkState);
256     return (AE_OK);
257 }
258 
259 
260 /*******************************************************************************
261  *
262  * FUNCTION:    LdLoadFieldElements
263  *
264  * PARAMETERS:  AmlType         - Type to search
265  *              Op              - Parent node (Field)
266  *              WalkState       - Current walk state
267  *
268  * RETURN:      Status
269  *
270  * DESCRIPTION: Enter the named elements of the field (children of the parent)
271  *              into the namespace.
272  *
273  ******************************************************************************/
274 
275 static ACPI_STATUS
276 LdLoadFieldElements (
277     UINT32                  AmlType,
278     ACPI_PARSE_OBJECT       *Op,
279     ACPI_WALK_STATE         *WalkState)
280 {
281     ACPI_PARSE_OBJECT       *Child = NULL;
282     ACPI_PARSE_OBJECT       *SourceRegion;
283     ACPI_NAMESPACE_NODE     *Node;
284     ACPI_STATUS             Status;
285     char                    *ExternalPath;
286 
287 
288     SourceRegion = UtGetArg (Op, 0);
289     if (SourceRegion)
290     {
291         Status = AcpiNsLookup (WalkState->ScopeInfo,
292             SourceRegion->Asl.Value.String, AmlType, ACPI_IMODE_EXECUTE,
293             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
294         if (Status == AE_NOT_FOUND)
295         {
296             /*
297              * If the named object is not found, it means that it is either a
298              * forward reference or the named object does not exist.
299              */
300             SourceRegion->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
301         }
302     }
303 
304     /* Get the first named field element */
305 
306     switch (Op->Asl.AmlOpcode)
307     {
308     case AML_BANK_FIELD_OP:
309 
310         Child = UtGetArg (Op, 6);
311         break;
312 
313     case AML_INDEX_FIELD_OP:
314 
315         Child = UtGetArg (Op, 5);
316         break;
317 
318     case AML_FIELD_OP:
319 
320         Child = UtGetArg (Op, 4);
321         break;
322 
323     default:
324 
325         /* No other opcodes should arrive here */
326 
327         return (AE_BAD_PARAMETER);
328     }
329 
330     /* Enter all elements into the namespace */
331 
332     while (Child)
333     {
334         switch (Child->Asl.AmlOpcode)
335         {
336         case AML_INT_RESERVEDFIELD_OP:
337         case AML_INT_ACCESSFIELD_OP:
338         case AML_INT_CONNECTION_OP:
339             break;
340 
341         default:
342 
343             Status = AcpiNsLookup (WalkState->ScopeInfo,
344                 Child->Asl.Value.String,
345                 ACPI_TYPE_LOCAL_REGION_FIELD,
346                 ACPI_IMODE_LOAD_PASS1,
347                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
348                     ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
349             if (ACPI_FAILURE (Status))
350             {
351                 if (Status != AE_ALREADY_EXISTS)
352                 {
353                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
354                         Child->Asl.Value.String);
355                     return (Status);
356                 }
357                 else if (Status == AE_ALREADY_EXISTS &&
358                     (Node->Flags & ANOBJ_IS_EXTERNAL))
359                 {
360                     Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
361                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
362                 }
363                 else
364                 {
365                     /*
366                      * The name already exists in this scope
367                      * But continue processing the elements
368                      */
369                     ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
370 
371                     AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
372                         ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
373                         ExternalPath);
374 
375                     if (ExternalPath)
376                     {
377                         ACPI_FREE (ExternalPath);
378                     }
379                 }
380             }
381             else
382             {
383                 Child->Asl.Node = Node;
384                 Node->Op = Child;
385             }
386             break;
387         }
388 
389         Child = Child->Asl.Next;
390     }
391 
392     return (AE_OK);
393 }
394 
395 
396 /*******************************************************************************
397  *
398  * FUNCTION:    LdLoadResourceElements
399  *
400  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
401  *              WalkState       - Current walk state
402  *
403  * RETURN:      Status
404  *
405  * DESCRIPTION: Enter the named elements of the resource descriptor (children
406  *              of the parent) into the namespace.
407  *
408  * NOTE: In the real AML namespace, these named elements never exist. But
409  *       we simply use the namespace here as a symbol table so we can look
410  *       them up as they are referenced.
411  *
412  ******************************************************************************/
413 
414 static ACPI_STATUS
415 LdLoadResourceElements (
416     ACPI_PARSE_OBJECT       *Op,
417     ACPI_WALK_STATE         *WalkState)
418 {
419     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
420     ACPI_NAMESPACE_NODE     *Node;
421     ACPI_STATUS             Status;
422     char                    *ExternalPath;
423 
424 
425     /*
426      * Enter the resource name into the namespace. Name must not already exist.
427      * This opens a scope, so later field names are guaranteed to be new/unique.
428      */
429     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
430         ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
431         ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
432         WalkState, &Node);
433     if (ACPI_FAILURE (Status))
434     {
435         if (Status == AE_ALREADY_EXISTS)
436         {
437             /* Actual node causing the error was saved in ParentMethod */
438 
439             ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
440 
441             AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
442                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
443                 ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
444                 ExternalPath);
445 
446             if (ExternalPath)
447             {
448                 ACPI_FREE (ExternalPath);
449             }
450             return (AE_OK);
451         }
452         return (Status);
453     }
454 
455     Node->Value = (UINT32) Op->Asl.Value.Integer;
456     Node->Op = Op;
457     Op->Asl.Node = Node;
458 
459     /*
460      * Now enter the predefined fields, for easy lookup when referenced
461      * by the source ASL
462      */
463     InitializerOp = ASL_GET_CHILD_NODE (Op);
464     while (InitializerOp)
465     {
466         if (InitializerOp->Asl.ExternalName)
467         {
468             Status = AcpiNsLookup (WalkState->ScopeInfo,
469                 InitializerOp->Asl.ExternalName,
470                 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
471                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
472             if (ACPI_FAILURE (Status))
473             {
474                 return (Status);
475             }
476 
477             /*
478              * Store the field offset and length in the namespace node
479              * so it can be used when the field is referenced
480              */
481             Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
482             Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
483             InitializerOp->Asl.Node = Node;
484             Node->Op = InitializerOp;
485         }
486 
487         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
488     }
489 
490     return (AE_OK);
491 }
492 
493 
494 /*******************************************************************************
495  *
496  * FUNCTION:    LdNamespace1Begin
497  *
498  * PARAMETERS:  ASL_WALK_CALLBACK
499  *
500  * RETURN:      Status
501  *
502  * DESCRIPTION: Descending callback used during the parse tree walk. If this
503  *              is a named AML opcode, enter into the namespace
504  *
505  ******************************************************************************/
506 
507 static ACPI_STATUS
508 LdNamespace1Begin (
509     ACPI_PARSE_OBJECT       *Op,
510     UINT32                  Level,
511     void                    *Context)
512 {
513     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
514     ACPI_NAMESPACE_NODE     *Node;
515     ACPI_PARSE_OBJECT       *MethodOp;
516     ACPI_STATUS             Status;
517     ACPI_OBJECT_TYPE        ObjectType;
518     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
519     char                    *Path;
520     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
521     ACPI_PARSE_OBJECT       *Arg;
522     UINT32                  i;
523     BOOLEAN                 ForceNewScope = FALSE;
524     const ACPI_OPCODE_INFO  *OpInfo;
525     ACPI_PARSE_OBJECT       *ParentOp;
526     char                    *ExternalPath;
527 
528 
529     ACPI_FUNCTION_NAME (LdNamespace1Begin);
530 
531 
532     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
533         Op, Op->Asl.ParseOpName));
534 
535     /*
536      * We are only interested in opcodes that have an associated name
537      * (or multiple names)
538      */
539     switch (Op->Asl.AmlOpcode)
540     {
541     case AML_INDEX_FIELD_OP:
542 
543         Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
544         return (Status);
545 
546     case AML_BANK_FIELD_OP:
547     case AML_FIELD_OP:
548 
549         Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
550         return (Status);
551 
552     case AML_INT_CONNECTION_OP:
553 
554         if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
555         {
556             break;
557         }
558 
559         Arg = Op->Asl.Child;
560         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
561             ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
562             WalkState, &Node);
563         if (ACPI_FAILURE (Status))
564         {
565             break;
566         }
567 
568         break;
569 
570     default:
571 
572         /* All other opcodes go below */
573 
574         break;
575     }
576 
577     /* Check if this object has already been installed in the namespace */
578 
579     if (Op->Asl.Node)
580     {
581         return (AE_OK);
582     }
583 
584     /* Check for a possible illegal forward reference */
585 
586     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
587         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
588         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
589     {
590         /*
591          * Op->Asl.Namepath will be NULL for these opcodes.
592          * These opcodes are guaranteed to have a parent.
593          * Examine the parent opcode.
594          */
595         ParentOp = Op->Asl.Parent;
596         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
597 
598         /*
599          * Exclude all operators that actually declare a new name:
600          *      Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
601          * We only want references to named objects:
602          *      Store (2, WXYZ) -> Attempt to resolve the name
603          */
604         if ((Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
605             (OpInfo->Class == AML_CLASS_NAMED_OBJECT))
606         {
607             return (AE_OK);
608         }
609 
610         /*
611          * Check if the referenced object exists at this point during
612          * the load:
613          * 1) If it exists, then this cannot be a forward reference.
614          * 2) If it does not exist, it could be a forward reference or
615          * it truly does not exist (and no external declaration).
616          */
617         Status = AcpiNsLookup (WalkState->ScopeInfo,
618             Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
619             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
620             WalkState, &Node);
621         if (Status == AE_NOT_FOUND)
622         {
623             /*
624              * This is either a forward reference or the object truly
625              * does not exist. The two cases can only be differentiated
626              * during the cross-reference stage later. Mark the Op/Name
627              * as not-found for now to indicate the need for further
628              * processing.
629              *
630              * Special case: Allow forward references from elements of
631              * Package objects. This provides compatibility with other
632              * ACPI implementations. To correctly implement this, the
633              * ACPICA table load defers package resolution until the entire
634              * namespace has been loaded.
635              */
636             if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
637                 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
638             {
639                 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
640             }
641 
642             return (AE_OK);
643         }
644 
645         return (Status);
646     }
647 
648     Path = Op->Asl.Namepath;
649     if (!Path)
650     {
651         return (AE_OK);
652     }
653 
654     /* Map the raw opcode into an internal object type */
655 
656     switch (Op->Asl.ParseOpcode)
657     {
658     case PARSEOP_NAME:
659 
660         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
661         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
662 
663         /*
664          * If this name refers to a ResourceTemplate, we will need to open
665          * a new scope so that the resource subfield names can be entered into
666          * the namespace underneath this name
667          */
668         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
669         {
670             ForceNewScope = TRUE;
671         }
672 
673         /* Get the data type associated with the named object, not the name itself */
674 
675         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
676 
677         ObjectType = 1;
678         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
679         {
680             ObjectType++;
681         }
682         break;
683 
684     case PARSEOP_EXTERNAL:
685         /*
686          * "External" simply enters a name and type into the namespace.
687          * We must be careful to not open a new scope, however, no matter
688          * what type the external name refers to (e.g., a method)
689          *
690          * first child is name, next child is ObjectType
691          */
692         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
693         ObjectType = ACPI_TYPE_ANY;
694 
695         /*
696          * We will mark every new node along the path as "External". This
697          * allows some or all of the nodes to be created later in the ASL
698          * code. Handles cases like this:
699          *
700          *   External (\_SB_.PCI0.ABCD, IntObj)
701          *   Scope (_SB_)
702          *   {
703          *       Device (PCI0)
704          *       {
705          *       }
706          *   }
707          *   Method (X)
708          *   {
709          *       Store (\_SB_.PCI0.ABCD, Local0)
710          *   }
711          */
712         Flags |= ACPI_NS_EXTERNAL;
713         break;
714 
715     case PARSEOP_DEFAULT_ARG:
716 
717         if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
718         {
719             Status = LdLoadResourceElements (Op, WalkState);
720             return_ACPI_STATUS (Status);
721         }
722 
723         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
724         break;
725 
726     case PARSEOP_SCOPE:
727         /*
728          * The name referenced by Scope(Name) must already exist at this point.
729          * In other words, forward references for Scope() are not supported.
730          * The only real reason for this is that the MS interpreter cannot
731          * handle this case. Perhaps someday this case can go away.
732          */
733         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
734             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
735         if (ACPI_FAILURE (Status))
736         {
737             if (Status == AE_NOT_FOUND)
738             {
739                 /* The name was not found, go ahead and create it */
740 
741                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
742                     ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
743                     Flags, WalkState, &Node);
744                 if (ACPI_FAILURE (Status))
745                 {
746                     return_ACPI_STATUS (Status);
747                 }
748 
749                 /* However, this is an error -- operand to Scope must exist */
750 
751                 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
752                 {
753                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
754                         Op->Asl.ExternalName);
755                 }
756                 else
757                 {
758                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
759                         Op->Asl.ExternalName);
760                 }
761 
762                 goto FinishNode;
763             }
764 
765             AslCoreSubsystemError (Op, Status,
766                 "Failure from namespace lookup", FALSE);
767 
768             return_ACPI_STATUS (Status);
769         }
770         else /* Status AE_OK */
771         {
772             /*
773              * Do not allow references to external scopes from the DSDT.
774              * This is because the DSDT is always loaded first, and the
775              * external reference cannot be resolved -- causing a runtime
776              * error because Scope() must be resolved immediately.
777              * 10/2015.
778              */
779             if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
780                 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
781             {
782                 /* However, allowed if the reference is within a method */
783 
784                 MethodOp = Op->Asl.Parent;
785                 while (MethodOp &&
786                       (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
787                 {
788                     MethodOp = MethodOp->Asl.Parent;
789                 }
790 
791                 if (!MethodOp)
792                 {
793                     /* Not in a control method, error */
794 
795                     AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
796                 }
797             }
798         }
799 
800         /* We found a node with this name, now check the type */
801 
802         switch (Node->Type)
803         {
804         case ACPI_TYPE_LOCAL_SCOPE:
805         case ACPI_TYPE_DEVICE:
806         case ACPI_TYPE_POWER:
807         case ACPI_TYPE_PROCESSOR:
808         case ACPI_TYPE_THERMAL:
809 
810             /* These are acceptable types - they all open a new scope */
811             break;
812 
813         case ACPI_TYPE_INTEGER:
814         case ACPI_TYPE_STRING:
815         case ACPI_TYPE_BUFFER:
816             /*
817              * These types we will allow, but we will change the type.
818              * This enables some existing code of the form:
819              *
820              *  Name (DEB, 0)
821              *  Scope (DEB) { ... }
822              *
823              * Which is used to workaround the fact that the MS interpreter
824              * does not allow Scope() forward references.
825              */
826             sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
827                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
828             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
829 
830             /* Switch the type to scope, open the new scope */
831 
832             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
833             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
834                 WalkState);
835             if (ACPI_FAILURE (Status))
836             {
837                 return_ACPI_STATUS (Status);
838             }
839             break;
840 
841         default:
842 
843             /* All other types are an error */
844 
845             sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
846                 AcpiUtGetTypeName (Node->Type));
847             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
848 
849             /*
850              * However, switch the type to be an actual scope so
851              * that compilation can continue without generating a whole
852              * cascade of additional errors. Open the new scope.
853              */
854             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
855             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
856                 WalkState);
857             if (ACPI_FAILURE (Status))
858             {
859                 return_ACPI_STATUS (Status);
860             }
861             break;
862         }
863 
864         Status = AE_OK;
865         goto FinishNode;
866 
867     default:
868 
869         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
870         break;
871     }
872 
873     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
874         Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
875 
876     /* The name must not already exist */
877 
878     Flags |= ACPI_NS_ERROR_IF_FOUND;
879 
880     /*
881      * For opcodes that enter new names into the namespace,
882      * all prefix NameSegs must exist.
883      */
884     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
885     if (((WalkState->OpInfo->Flags & AML_NAMED) ||
886         (WalkState->OpInfo->Flags & AML_CREATE)) &&
887         (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
888     {
889         Flags |= ACPI_NS_PREFIX_MUST_EXIST;
890     }
891 
892     /*
893      * Enter the named type into the internal namespace. We enter the name
894      * as we go downward in the parse tree. Any necessary subobjects that
895      * involve arguments to the opcode must be created as we go back up the
896      * parse tree later.
897      */
898     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
899         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
900     if (ACPI_FAILURE (Status))
901     {
902         if (Status == AE_ALREADY_EXISTS)
903         {
904             /* The name already exists in this scope */
905 
906             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
907             {
908                 /* Allow multiple references to the same scope */
909 
910                 Node->Type = (UINT8) ObjectType;
911                 Status = AE_OK;
912             }
913             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) ||
914                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
915             {
916                 Status = LdAnalyzeExternals (Node, Op, ActualObjectType,
917                     ObjectType, WalkState);
918                 if (ACPI_FAILURE (Status))
919                 {
920                     if (Status == AE_ERROR)
921                     {
922                         /*
923                          * The use of AE_ERROR here indicates that there was a
924                          * compiler error emitted in LdAnalyzeExternals which
925                          * means that the caller should proceed to the next Op
926                          * for analysis of subsequent parse objects.
927                          */
928                         Status = AE_OK;
929                     }
930                     return_ACPI_STATUS (Status);
931                 }
932             }
933             else
934             {
935                 /* Valid error, object already exists */
936 
937                 ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
938 
939                 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
940                     ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
941                     ExternalPath);
942 
943                 if (ExternalPath)
944                 {
945                     ACPI_FREE (ExternalPath);
946                 }
947                 return_ACPI_STATUS (AE_OK);
948             }
949         }
950         else if (AE_NOT_FOUND)
951         {
952             /*
953              * One or more prefix NameSegs of the NamePath do not exist
954              * (all of them must exist). Attempt to continue compilation
955              * by setting the current scope to the root.
956              */
957             Node = AcpiGbl_RootNode;
958             Status = AE_OK;
959         }
960         else
961         {
962             /* Flag all other errors as coming from the ACPICA core */
963 
964             AslCoreSubsystemError (Op, Status,
965                 "Failure from namespace lookup", FALSE);
966             return_ACPI_STATUS (Status);
967         }
968     }
969 
970     /* Check special names like _WAK and _PTS */
971 
972     LdCheckSpecialNames (Node, Op);
973 
974     if (ForceNewScope)
975     {
976         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
977         if (ACPI_FAILURE (Status))
978         {
979             return_ACPI_STATUS (Status);
980         }
981     }
982 
983 FinishNode:
984     /*
985      * Point the parse node to the new namespace node, and point
986      * the Node back to the original Parse node
987      */
988     Op->Asl.Node = Node;
989     Node->Op = Op;
990 
991     /*
992      * Set the actual data type if appropriate (EXTERNAL term only)
993      * As of 11/19/2019, ASL External() does not support parameter
994      * counts. When an External method is loaded, the parameter count is
995      * recorded in the external's arg count parameter. The parameter count may
996      * or may not be known in the declaration. If the value of this node turns
997      * out to be ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS, it indicates that
998      * we do not know the parameter count and that we must look at the usage of
999      * the External method call to get this information.
1000      */
1001     if (ActualObjectType != ACPI_TYPE_ANY)
1002     {
1003         Node->Type = (UINT8) ActualObjectType;
1004         Node->Value = (UINT32)
1005             Op->Asl.Child->Asl.Next->Asl.Next->Asl.Value.Integer;
1006     }
1007 
1008     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
1009     {
1010         /*
1011          * Get the method argument count from "Extra" and save
1012          * it in the namespace node
1013          */
1014         Node->Value = (UINT32) Op->Asl.Extra;
1015     }
1016 
1017     return_ACPI_STATUS (Status);
1018 }
1019 
1020 
1021 /*******************************************************************************
1022  *
1023  * FUNCTION:    LdAnalyzeExternals
1024  *
1025  * PARAMETERS:  Type1
1026  *              Type2
1027  *
1028  * RETURN:      BOOLEAN
1029  *
1030  * DESCRIPTION: Match Type1 and Type2 with the assumption that one might be
1031  *              using external types and another might be using local types.
1032  *              This should be used to compare the types found in external
1033  *              declarations with types found in other external declarations or
1034  *              named object declaration. This should not be used to match two
1035  *              object type declarations.
1036  *
1037  ******************************************************************************/
1038 
1039 static BOOLEAN
1040 LdTypesMatchExternType (
1041     ACPI_OBJECT_TYPE        Type1,
1042     ACPI_OBJECT_TYPE        Type2)
1043 {
1044     BOOLEAN                 Type1IsLocal = Type1 > ACPI_TYPE_EXTERNAL_MAX;
1045     BOOLEAN                 Type2IsLocal = Type2 > ACPI_TYPE_EXTERNAL_MAX;
1046     ACPI_OBJECT_TYPE        ExternalType;
1047     ACPI_OBJECT_TYPE        LocalType;
1048 
1049 
1050     /*
1051      * The inputs could represent types that are local to ACPICA or types that
1052      * are known externally. Some local types, such as the OperationRegion
1053      * field units, are defined with more granularity than ACPICA local types.
1054      *
1055      * Therefore, map the local types to the external types before matching.
1056      */
1057     if (Type1IsLocal && !Type2IsLocal)
1058     {
1059         LocalType = Type1;
1060         ExternalType = Type2;
1061     }
1062     else if (!Type1IsLocal && Type2IsLocal)
1063     {
1064         LocalType = Type2;
1065         ExternalType = Type1;
1066     }
1067     else
1068     {
1069         return (Type1 == Type2);
1070     }
1071 
1072     switch (LocalType)
1073     {
1074         case ACPI_TYPE_LOCAL_REGION_FIELD:
1075         case ACPI_TYPE_LOCAL_BANK_FIELD:
1076         case ACPI_TYPE_LOCAL_INDEX_FIELD:
1077 
1078             LocalType = ACPI_TYPE_FIELD_UNIT;
1079             break;
1080 
1081         default:
1082             break;
1083     }
1084 
1085     return (LocalType == ExternalType);
1086 }
1087 
1088 
1089 /*******************************************************************************
1090  *
1091  * FUNCTION:    LdAnalyzeExternals
1092  *
1093  * PARAMETERS:  Node            - Node that represents the named object
1094  *              Op              - Named object declaring this named object
1095  *              ExternalOpType  - Type of ExternalOp
1096  *              ObjectType      - Type of Declared object
1097  *              WalkState       - Current WalkState
1098  *
1099  * RETURN:      Status
1100  *
1101  * DESCRIPTION: Node and Op represents an identically named object declaration
1102  *              that is either declared by the ASL external keyword or declared
1103  *              by operators that declare named objects (i.e. Name, Device,
1104  *              OperationRegion, and etc.). This function ensures that the
1105  *              declarations do not contradict each other.
1106  *
1107  ******************************************************************************/
1108 
1109 static ACPI_STATUS
1110 LdAnalyzeExternals (
1111     ACPI_NAMESPACE_NODE     *Node,
1112     ACPI_PARSE_OBJECT       *Op,
1113     ACPI_OBJECT_TYPE        ExternalOpType,
1114     ACPI_OBJECT_TYPE        ObjectType,
1115     ACPI_WALK_STATE         *WalkState)
1116 {
1117     ACPI_STATUS             Status = AE_OK;
1118     ACPI_OBJECT_TYPE        ActualExternalOpType;
1119     ACPI_OBJECT_TYPE        ActualOpType;
1120     ACPI_PARSE_OBJECT       *ExternalOp;
1121     ACPI_PARSE_OBJECT       *ActualOp;
1122 
1123 
1124     /*
1125      * The declaration represented by Node and Op must have the same type.
1126      * The type of the external Op is represented by ExternalOpType. However,
1127      * the type of the pre-existing declaration depends on whether if Op
1128      * is an external declaration or an actual declaration.
1129      */
1130     if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1131     {
1132         ActualExternalOpType = ExternalOpType;
1133         ActualOpType = Node->Type;
1134     }
1135     else
1136     {
1137         ActualExternalOpType = Node->Type;
1138         ActualOpType = ObjectType;
1139     }
1140 
1141     if ((ActualOpType != ACPI_TYPE_ANY) &&
1142         (ActualExternalOpType != ACPI_TYPE_ANY) &&
1143         !LdTypesMatchExternType (ActualExternalOpType, ActualOpType))
1144     {
1145         if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1146             Node->Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1147         {
1148             AslDualParseOpError (ASL_WARNING,
1149                 ASL_MSG_DUPLICATE_EXTERN_MISMATCH, Op, NULL,
1150                 ASL_MSG_DUPLICATE_EXTERN_FOUND_HERE, Node->Op, NULL);
1151         }
1152         else
1153         {
1154             if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1155                 Node->Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1156             {
1157                 ExternalOp = Op;
1158                 ActualOp = Node->Op;
1159             }
1160             else
1161             {
1162                 ExternalOp = Node->Op;
1163                 ActualOp = Op;
1164             }
1165             AslDualParseOpError (ASL_WARNING,
1166                 ASL_MSG_DECLARATION_TYPE_MISMATCH, ExternalOp, NULL,
1167                 ASL_MSG_TYPE_MISMATCH_FOUND_HERE, ActualOp, NULL);
1168         }
1169     }
1170 
1171     if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1172         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
1173     {
1174         /*
1175          * Allow one create on an object or segment that was
1176          * previously declared External
1177          */
1178         Node->Flags &= ~ANOBJ_IS_EXTERNAL;
1179         Node->Type = (UINT8) ObjectType;
1180 
1181         /* Just retyped a node, probably will need to open a scope */
1182 
1183         if (AcpiNsOpensScope (ObjectType))
1184         {
1185             Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1186             if (ACPI_FAILURE (Status))
1187             {
1188                 return (Status);
1189             }
1190         }
1191 
1192         Status = AE_OK;
1193     }
1194     else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
1195              (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1196     {
1197         /*
1198          * Allow externals in same scope as the definition of the
1199          * actual object. Similar to C. Allows multiple definition
1200          * blocks that refer to each other in the same file.
1201          */
1202         Status = AE_OK;
1203     }
1204     else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1205              (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
1206              (ObjectType == ACPI_TYPE_ANY))
1207     {
1208         /* Allow update of externals of unknown type. */
1209 
1210         Node->Type = (UINT8) ExternalOpType;
1211         Status = AE_OK;
1212     }
1213 
1214     return (Status);
1215 }
1216 
1217 
1218 /*******************************************************************************
1219  *
1220  * FUNCTION:    LdCheckSpecialNames
1221  *
1222  * PARAMETERS:  Node        - Node that represents the named object
1223  *              Op          - Named object declaring this named object
1224  *
1225  * RETURN:      None
1226  *
1227  * DESCRIPTION: Check if certain named objects are declared in the incorrect
1228  *              scope. Special named objects are listed in
1229  *              AslGbl_SpecialNamedObjects and can only be declared at the root
1230  *              scope. _UID inside of a processor declaration must not be a
1231  *              string.
1232  *
1233  ******************************************************************************/
1234 
1235 static void
1236 LdCheckSpecialNames (
1237     ACPI_NAMESPACE_NODE     *Node,
1238     ACPI_PARSE_OBJECT       *Op)
1239 {
1240     UINT32                  i;
1241 
1242 
1243     for (i = 0; i < MAX_SPECIAL_NAMES; i++)
1244     {
1245         if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
1246             Node->Parent != AcpiGbl_RootNode)
1247         {
1248             AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
1249             return;
1250         }
1251     }
1252 
1253     if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1254         Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1255         Node->Type == ACPI_TYPE_STRING)
1256     {
1257         AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1258     }
1259 }
1260 
1261 
1262 /*******************************************************************************
1263  *
1264  * FUNCTION:    LdNamespace2Begin
1265  *
1266  * PARAMETERS:  ASL_WALK_CALLBACK
1267  *
1268  * RETURN:      Status
1269  *
1270  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1271  *              Second pass resolves some forward references.
1272  *
1273  * Notes:
1274  * Currently only needs to handle the Alias operator.
1275  * Could be used to allow forward references from the Scope() operator, but
1276  * the MS interpreter does not allow this, so this compiler does not either.
1277  *
1278  ******************************************************************************/
1279 
1280 static ACPI_STATUS
1281 LdNamespace2Begin (
1282     ACPI_PARSE_OBJECT       *Op,
1283     UINT32                  Level,
1284     void                    *Context)
1285 {
1286     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1287     ACPI_STATUS             Status;
1288     ACPI_NAMESPACE_NODE     *Node;
1289     ACPI_OBJECT_TYPE        ObjectType;
1290     BOOLEAN                 ForceNewScope = FALSE;
1291     ACPI_PARSE_OBJECT       *Arg;
1292     char                    *Path;
1293     ACPI_NAMESPACE_NODE     *TargetNode;
1294 
1295 
1296     ACPI_FUNCTION_NAME (LdNamespace2Begin);
1297     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1298         Op, Op->Asl.ParseOpName));
1299 
1300 
1301     /* Ignore Ops with no namespace node */
1302 
1303     Node = Op->Asl.Node;
1304     if (!Node)
1305     {
1306         return (AE_OK);
1307     }
1308 
1309     /* Get the type to determine if we should push the scope */
1310 
1311     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1312         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1313     {
1314         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1315     }
1316     else
1317     {
1318         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1319     }
1320 
1321     /* Push scope for Resource Templates */
1322 
1323     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1324     {
1325         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1326         {
1327             ForceNewScope = TRUE;
1328         }
1329     }
1330 
1331     /* Push the scope stack */
1332 
1333     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1334     {
1335         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1336         if (ACPI_FAILURE (Status))
1337         {
1338             return_ACPI_STATUS (Status);
1339         }
1340     }
1341 
1342     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1343     {
1344         /*
1345          * Complete the alias node by getting and saving the target node.
1346          * First child is the alias target
1347          */
1348         Arg = Op->Asl.Child;
1349 
1350         /* Get the target pathname */
1351 
1352         Path = Arg->Asl.Namepath;
1353         if (!Path)
1354         {
1355             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1356             if (ACPI_FAILURE (Status))
1357             {
1358                 return (Status);
1359             }
1360         }
1361 
1362         /* Get the NS node associated with the target. It must exist. */
1363 
1364         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1365             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1366             WalkState, &TargetNode);
1367         if (ACPI_FAILURE (Status))
1368         {
1369             if (Status == AE_NOT_FOUND)
1370             {
1371                 /* Standalone NameSeg vs. NamePath */
1372 
1373                 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
1374                 {
1375                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1376                         Arg->Asl.ExternalName);
1377                 }
1378                 else
1379                 {
1380                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
1381                         Arg->Asl.ExternalName);
1382                 }
1383 
1384 #if 0
1385 /*
1386  * NOTE: Removed 10/2018 to enhance compiler error reporting. No
1387  * regressions seen.
1388  */
1389                 /*
1390                  * The name was not found, go ahead and create it.
1391                  * This prevents more errors later.
1392                  */
1393                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1394                     ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
1395                     ACPI_NS_NO_UPSEARCH, WalkState, &Node);
1396 #endif
1397                 return (Status);
1398 /* Removed: return (AE_OK)*/
1399             }
1400 
1401             AslCoreSubsystemError (Op, Status,
1402                 "Failure from namespace lookup", FALSE);
1403             return (AE_OK);
1404         }
1405 
1406         /* Save the target node within the alias node */
1407 
1408         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1409     }
1410 
1411     return (AE_OK);
1412 }
1413 
1414 
1415 /*******************************************************************************
1416  *
1417  * FUNCTION:    LdCommonNamespaceEnd
1418  *
1419  * PARAMETERS:  ASL_WALK_CALLBACK
1420  *
1421  * RETURN:      Status
1422  *
1423  * DESCRIPTION: Ascending callback used during the loading of the namespace,
1424  *              We only need to worry about managing the scope stack here.
1425  *
1426  ******************************************************************************/
1427 
1428 static ACPI_STATUS
1429 LdCommonNamespaceEnd (
1430     ACPI_PARSE_OBJECT       *Op,
1431     UINT32                  Level,
1432     void                    *Context)
1433 {
1434     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1435     ACPI_OBJECT_TYPE        ObjectType;
1436     BOOLEAN                 ForceNewScope = FALSE;
1437 
1438 
1439     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1440 
1441 
1442     /* We are only interested in opcodes that have an associated name */
1443 
1444     if (!Op->Asl.Namepath)
1445     {
1446         return (AE_OK);
1447     }
1448 
1449     /* Get the type to determine if we should pop the scope */
1450 
1451     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1452         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1453     {
1454         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1455 
1456         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1457     }
1458     else
1459     {
1460         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1461     }
1462 
1463     /* Pop scope that was pushed for Resource Templates */
1464 
1465     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1466     {
1467         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1468         {
1469             ForceNewScope = TRUE;
1470         }
1471     }
1472 
1473     /* Pop the scope stack */
1474 
1475     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1476     {
1477         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1478             "(%s): Popping scope for Op [%s] %p\n",
1479             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1480 
1481         (void) AcpiDsScopeStackPop (WalkState);
1482     }
1483 
1484     return (AE_OK);
1485 }
1486