1/******************************************************************************
2 *
3 * Module Name: aslload - compiler 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 <contrib/dev/acpica/compiler/aslcompiler.h>
153#include <contrib/dev/acpica/include/amlcode.h>
154#include <contrib/dev/acpica/include/acdispat.h>
155#include <contrib/dev/acpica/include/acnamesp.h>
156#include <contrib/dev/acpica/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
165static ACPI_STATUS
166LdLoadFieldElements (
167    UINT32                  AmlType,
168    ACPI_PARSE_OBJECT       *Op,
169    ACPI_WALK_STATE         *WalkState);
170
171static ACPI_STATUS
172LdLoadResourceElements (
173    ACPI_PARSE_OBJECT       *Op,
174    ACPI_WALK_STATE         *WalkState);
175
176static ACPI_STATUS
177LdNamespace1Begin (
178    ACPI_PARSE_OBJECT       *Op,
179    UINT32                  Level,
180    void                    *Context);
181
182static ACPI_STATUS
183LdNamespace2Begin (
184    ACPI_PARSE_OBJECT       *Op,
185    UINT32                  Level,
186    void                    *Context);
187
188static ACPI_STATUS
189LdCommonNamespaceEnd (
190    ACPI_PARSE_OBJECT       *Op,
191    UINT32                  Level,
192    void                    *Context);
193
194static void
195LdCheckSpecialNames (
196    ACPI_NAMESPACE_NODE     *Node,
197    ACPI_PARSE_OBJECT       *Op);
198
199static ACPI_STATUS
200LdAnalyzeExternals (
201    ACPI_NAMESPACE_NODE     *Node,
202    ACPI_PARSE_OBJECT       *Op,
203    ACPI_OBJECT_TYPE        ExternalOpType,
204    ACPI_WALK_STATE         *WalkState);
205
206
207/*******************************************************************************
208 *
209 * FUNCTION:    LdLoadNamespace
210 *
211 * PARAMETERS:  RootOp      - Root of the parse tree
212 *
213 * RETURN:      Status
214 *
215 * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
216 *              named ASL/AML objects into the namespace. The namespace is
217 *              constructed in order to resolve named references and references
218 *              to named fields within resource templates/descriptors.
219 *
220 ******************************************************************************/
221
222ACPI_STATUS
223LdLoadNamespace (
224    ACPI_PARSE_OBJECT       *RootOp)
225{
226    ACPI_WALK_STATE         *WalkState;
227
228
229    /* Create a new walk state */
230
231    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
232    if (!WalkState)
233    {
234        return (AE_NO_MEMORY);
235    }
236
237    /* Walk the entire parse tree, first pass */
238
239    TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
240        LdCommonNamespaceEnd, WalkState);
241
242    /* Second pass to handle forward references */
243
244    TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
245        LdCommonNamespaceEnd, WalkState);
246
247    /* Dump the namespace if debug is enabled */
248
249    if (AcpiDbgLevel & ACPI_LV_TABLES)
250    {
251        AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
252    }
253
254    ACPI_FREE (WalkState);
255    return (AE_OK);
256}
257
258
259/*******************************************************************************
260 *
261 * FUNCTION:    LdLoadFieldElements
262 *
263 * PARAMETERS:  AmlType         - Type to search
264 *              Op              - Parent node (Field)
265 *              WalkState       - Current walk state
266 *
267 * RETURN:      Status
268 *
269 * DESCRIPTION: Enter the named elements of the field (children of the parent)
270 *              into the namespace.
271 *
272 ******************************************************************************/
273
274static ACPI_STATUS
275LdLoadFieldElements (
276    UINT32                  AmlType,
277    ACPI_PARSE_OBJECT       *Op,
278    ACPI_WALK_STATE         *WalkState)
279{
280    ACPI_PARSE_OBJECT       *Child = NULL;
281    ACPI_PARSE_OBJECT       *SourceRegion;
282    ACPI_NAMESPACE_NODE     *Node;
283    ACPI_STATUS             Status;
284    char                    *ExternalPath;
285
286
287    SourceRegion = UtGetArg (Op, 0);
288    if (SourceRegion)
289    {
290        Status = AcpiNsLookup (WalkState->ScopeInfo,
291            SourceRegion->Asl.Value.String, AmlType, ACPI_IMODE_EXECUTE,
292            ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
293        if (Status == AE_NOT_FOUND)
294        {
295            /*
296             * If the named object is not found, it means that it is either a
297             * forward reference or the named object does not exist.
298             */
299            SourceRegion->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
300        }
301    }
302
303    /* Get the first named field element */
304
305    switch (Op->Asl.AmlOpcode)
306    {
307    case AML_BANK_FIELD_OP:
308
309        Child = UtGetArg (Op, 6);
310        break;
311
312    case AML_INDEX_FIELD_OP:
313
314        Child = UtGetArg (Op, 5);
315        break;
316
317    case AML_FIELD_OP:
318
319        Child = UtGetArg (Op, 4);
320        break;
321
322    default:
323
324        /* No other opcodes should arrive here */
325
326        return (AE_BAD_PARAMETER);
327    }
328
329    /* Enter all elements into the namespace */
330
331    while (Child)
332    {
333        switch (Child->Asl.AmlOpcode)
334        {
335        case AML_INT_RESERVEDFIELD_OP:
336        case AML_INT_ACCESSFIELD_OP:
337        case AML_INT_CONNECTION_OP:
338            break;
339
340        default:
341
342            Status = AcpiNsLookup (WalkState->ScopeInfo,
343                Child->Asl.Value.String,
344                ACPI_TYPE_LOCAL_REGION_FIELD,
345                ACPI_IMODE_LOAD_PASS1,
346                ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
347                    ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
348            if (ACPI_FAILURE (Status))
349            {
350                if (Status != AE_ALREADY_EXISTS)
351                {
352                    AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
353                        Child->Asl.Value.String);
354                    return (Status);
355                }
356                else if (Status == AE_ALREADY_EXISTS &&
357                    (Node->Flags & ANOBJ_IS_EXTERNAL))
358                {
359                    Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
360                    Node->Flags &= ~ANOBJ_IS_EXTERNAL;
361                }
362                else
363                {
364                    /*
365                     * The name already exists in this scope
366                     * But continue processing the elements
367                     */
368                    ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
369
370                    AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
371                        ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
372                        ExternalPath);
373
374                    if (ExternalPath)
375                    {
376                        ACPI_FREE (ExternalPath);
377                    }
378                }
379            }
380            else
381            {
382                Child->Asl.Node = Node;
383                Node->Op = Child;
384            }
385            break;
386        }
387
388        Child = Child->Asl.Next;
389    }
390
391    return (AE_OK);
392}
393
394
395/*******************************************************************************
396 *
397 * FUNCTION:    LdLoadResourceElements
398 *
399 * PARAMETERS:  Op              - Parent node (Resource Descriptor)
400 *              WalkState       - Current walk state
401 *
402 * RETURN:      Status
403 *
404 * DESCRIPTION: Enter the named elements of the resource descriptor (children
405 *              of the parent) into the namespace.
406 *
407 * NOTE: In the real AML namespace, these named elements never exist. But
408 *       we simply use the namespace here as a symbol table so we can look
409 *       them up as they are referenced.
410 *
411 ******************************************************************************/
412
413static ACPI_STATUS
414LdLoadResourceElements (
415    ACPI_PARSE_OBJECT       *Op,
416    ACPI_WALK_STATE         *WalkState)
417{
418    ACPI_PARSE_OBJECT       *InitializerOp = NULL;
419    ACPI_NAMESPACE_NODE     *Node;
420    ACPI_STATUS             Status;
421    char                    *ExternalPath;
422
423
424    /*
425     * Enter the resource name into the namespace. Name must not already exist.
426     * This opens a scope, so later field names are guaranteed to be new/unique.
427     */
428    Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
429        ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
430        ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
431        WalkState, &Node);
432    if (ACPI_FAILURE (Status))
433    {
434        if (Status == AE_ALREADY_EXISTS)
435        {
436            /* Actual node causing the error was saved in ParentMethod */
437
438            ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
439
440            AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
441                (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
442                ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
443                ExternalPath);
444
445            if (ExternalPath)
446            {
447                ACPI_FREE (ExternalPath);
448            }
449            return (AE_OK);
450        }
451        return (Status);
452    }
453
454    Node->Value = (UINT32) Op->Asl.Value.Integer;
455    Node->Op = Op;
456    Op->Asl.Node = Node;
457
458    /*
459     * Now enter the predefined fields, for easy lookup when referenced
460     * by the source ASL
461     */
462    InitializerOp = ASL_GET_CHILD_NODE (Op);
463    while (InitializerOp)
464    {
465        if (InitializerOp->Asl.ExternalName)
466        {
467            Status = AcpiNsLookup (WalkState->ScopeInfo,
468                InitializerOp->Asl.ExternalName,
469                ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
470                ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
471            if (ACPI_FAILURE (Status))
472            {
473                return (Status);
474            }
475
476            /*
477             * Store the field offset and length in the namespace node
478             * so it can be used when the field is referenced
479             */
480            Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
481            Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
482            InitializerOp->Asl.Node = Node;
483            Node->Op = InitializerOp;
484        }
485
486        InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
487    }
488
489    return (AE_OK);
490}
491
492
493/*******************************************************************************
494 *
495 * FUNCTION:    LdNamespace1Begin
496 *
497 * PARAMETERS:  ASL_WALK_CALLBACK
498 *
499 * RETURN:      Status
500 *
501 * DESCRIPTION: Descending callback used during the parse tree walk. If this
502 *              is a named AML opcode, enter into the namespace
503 *
504 ******************************************************************************/
505
506static ACPI_STATUS
507LdNamespace1Begin (
508    ACPI_PARSE_OBJECT       *Op,
509    UINT32                  Level,
510    void                    *Context)
511{
512    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
513    ACPI_NAMESPACE_NODE     *Node;
514    ACPI_PARSE_OBJECT       *MethodOp;
515    ACPI_STATUS             Status;
516    ACPI_OBJECT_TYPE        ObjectType;
517    char                    *Path;
518    UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
519    ACPI_PARSE_OBJECT       *Arg;
520    UINT32                  i;
521    BOOLEAN                 ForceNewScope = FALSE;
522    const ACPI_OPCODE_INFO  *OpInfo;
523    ACPI_PARSE_OBJECT       *ParentOp;
524    char                    *ExternalPath;
525
526
527    ACPI_FUNCTION_NAME (LdNamespace1Begin);
528
529
530    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
531        Op, Op->Asl.ParseOpName));
532
533    /*
534     * We are only interested in opcodes that have an associated name
535     * (or multiple names)
536     */
537    switch (Op->Asl.AmlOpcode)
538    {
539    case AML_INDEX_FIELD_OP:
540
541        Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
542        return (Status);
543
544    case AML_BANK_FIELD_OP:
545    case AML_FIELD_OP:
546
547        Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
548        return (Status);
549
550    case AML_INT_CONNECTION_OP:
551
552        if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
553        {
554            break;
555        }
556
557        Arg = Op->Asl.Child;
558        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
559            ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
560            WalkState, &Node);
561        if (ACPI_FAILURE (Status))
562        {
563            break;
564        }
565
566        break;
567
568    default:
569
570        /* All other opcodes go below */
571
572        break;
573    }
574
575    /* Check if this object has already been installed in the namespace */
576
577    if (Op->Asl.Node)
578    {
579        return (AE_OK);
580    }
581
582    /* Check for a possible illegal forward reference */
583
584    if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
585        (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
586        (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
587    {
588        /*
589         * Op->Asl.Namepath will be NULL for these opcodes.
590         * These opcodes are guaranteed to have a parent.
591         * Examine the parent opcode.
592         */
593        ParentOp = Op->Asl.Parent;
594        OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
595
596        /*
597         * Exclude all operators that actually declare a new name:
598         *      Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
599         * We only want references to named objects:
600         *      Store (2, WXYZ) -> Attempt to resolve the name
601         */
602        if ((Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
603            (OpInfo->Class == AML_CLASS_NAMED_OBJECT))
604        {
605            return (AE_OK);
606        }
607
608        /*
609         * Check if the referenced object exists at this point during
610         * the load:
611         * 1) If it exists, then this cannot be a forward reference.
612         * 2) If it does not exist, it could be a forward reference or
613         * it truly does not exist (and no external declaration).
614         */
615        Status = AcpiNsLookup (WalkState->ScopeInfo,
616            Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
617            ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
618            WalkState, &Node);
619        if (Status == AE_NOT_FOUND)
620        {
621            /*
622             * This is either a forward reference or the object truly
623             * does not exist. The two cases can only be differentiated
624             * during the cross-reference stage later. Mark the Op/Name
625             * as not-found for now to indicate the need for further
626             * processing.
627             *
628             * Special case: Allow forward references from elements of
629             * Package objects. This provides compatibility with other
630             * ACPI implementations. To correctly implement this, the
631             * ACPICA table load defers package resolution until the entire
632             * namespace has been loaded.
633             */
634            if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
635                (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
636            {
637                Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
638            }
639
640            return (AE_OK);
641        }
642
643        return (Status);
644    }
645
646    Path = Op->Asl.Namepath;
647    if (!Path)
648    {
649        return (AE_OK);
650    }
651
652    /* Map the raw opcode into an internal object type */
653
654    switch (Op->Asl.ParseOpcode)
655    {
656    case PARSEOP_NAME:
657
658        Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
659        Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
660
661        /*
662         * If this name refers to a ResourceTemplate, we will need to open
663         * a new scope so that the resource subfield names can be entered into
664         * the namespace underneath this name
665         */
666        if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
667        {
668            ForceNewScope = TRUE;
669        }
670
671        /* Get the data type associated with the named object, not the name itself */
672
673        /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
674
675        ObjectType = 1;
676        for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
677        {
678            ObjectType++;
679        }
680        break;
681
682    case PARSEOP_EXTERNAL:
683        /*
684         * "External" simply enters a name and type into the namespace.
685         * We must be careful to not open a new scope, however, no matter
686         * what type the external name refers to (e.g., a method)
687         *
688         * first child is name, next child is ObjectType
689         */
690        ObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
691
692        /*
693         * We will mark every new node along the path as "External". This
694         * allows some or all of the nodes to be created later in the ASL
695         * code. Handles cases like this:
696         *
697         *   External (\_SB_.PCI0.ABCD, IntObj)
698         *   Scope (_SB_)
699         *   {
700         *       Device (PCI0)
701         *       {
702         *       }
703         *   }
704         *   Method (X)
705         *   {
706         *       Store (\_SB_.PCI0.ABCD, Local0)
707         *   }
708         */
709        Flags |= ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE;
710        break;
711
712    case PARSEOP_DEFAULT_ARG:
713
714        if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
715        {
716            Status = LdLoadResourceElements (Op, WalkState);
717            return_ACPI_STATUS (Status);
718        }
719
720        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
721        break;
722
723    case PARSEOP_SCOPE:
724        /*
725         * The name referenced by Scope(Name) must already exist at this point.
726         * In other words, forward references for Scope() are not supported.
727         * The only real reason for this is that the MS interpreter cannot
728         * handle this case. Perhaps someday this case can go away.
729         */
730        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
731            ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
732        if (ACPI_FAILURE (Status))
733        {
734            if (Status == AE_NOT_FOUND)
735            {
736                /* The name was not found, go ahead and create it */
737
738                Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
739                    ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
740                    Flags, WalkState, &Node);
741                if (ACPI_FAILURE (Status))
742                {
743                    return_ACPI_STATUS (Status);
744                }
745
746                /* However, this is an error -- operand to Scope must exist */
747
748                if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
749                {
750                    AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
751                        Op->Asl.ExternalName);
752                }
753                else
754                {
755                    AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
756                        Op->Asl.ExternalName);
757                }
758
759                goto FinishNode;
760            }
761
762            AslCoreSubsystemError (Op, Status,
763                "Failure from namespace lookup", FALSE);
764
765            return_ACPI_STATUS (Status);
766        }
767        else /* Status AE_OK */
768        {
769            /*
770             * Do not allow references to external scopes from the DSDT.
771             * This is because the DSDT is always loaded first, and the
772             * external reference cannot be resolved -- causing a runtime
773             * error because Scope() must be resolved immediately.
774             * 10/2015.
775             */
776            if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
777                (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
778            {
779                /* However, allowed if the reference is within a method */
780
781                MethodOp = Op->Asl.Parent;
782                while (MethodOp &&
783                      (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
784                {
785                    MethodOp = MethodOp->Asl.Parent;
786                }
787
788                if (!MethodOp)
789                {
790                    /* Not in a control method, error */
791
792                    AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
793                }
794            }
795        }
796
797        /* We found a node with this name, now check the type */
798
799        switch (Node->Type)
800        {
801        case ACPI_TYPE_LOCAL_SCOPE:
802        case ACPI_TYPE_DEVICE:
803        case ACPI_TYPE_POWER:
804        case ACPI_TYPE_PROCESSOR:
805        case ACPI_TYPE_THERMAL:
806
807            /* These are acceptable types - they all open a new scope */
808            break;
809
810        case ACPI_TYPE_INTEGER:
811        case ACPI_TYPE_STRING:
812        case ACPI_TYPE_BUFFER:
813            /*
814             * These types we will allow, but we will change the type.
815             * This enables some existing code of the form:
816             *
817             *  Name (DEB, 0)
818             *  Scope (DEB) { ... }
819             *
820             * Which is used to workaround the fact that the MS interpreter
821             * does not allow Scope() forward references.
822             */
823            sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
824                Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
825            AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
826
827            /* Switch the type to scope, open the new scope */
828
829            Node->Type = ACPI_TYPE_LOCAL_SCOPE;
830            Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
831                WalkState);
832            if (ACPI_FAILURE (Status))
833            {
834                return_ACPI_STATUS (Status);
835            }
836            break;
837
838        default:
839
840            /* All other types are an error */
841
842            sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
843                AcpiUtGetTypeName (Node->Type));
844            AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
845
846            /*
847             * However, switch the type to be an actual scope so
848             * that compilation can continue without generating a whole
849             * cascade of additional errors. Open the new scope.
850             */
851            Node->Type = ACPI_TYPE_LOCAL_SCOPE;
852            Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
853                WalkState);
854            if (ACPI_FAILURE (Status))
855            {
856                return_ACPI_STATUS (Status);
857            }
858            break;
859        }
860
861        Status = AE_OK;
862        goto FinishNode;
863
864    default:
865
866        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
867        break;
868    }
869
870    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
871        Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
872
873    /* The name must not already exist */
874
875    Flags |= ACPI_NS_ERROR_IF_FOUND;
876
877    /*
878     * For opcodes that enter new names into the namespace,
879     * all prefix NameSegs must exist.
880     */
881    WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
882    if (((WalkState->OpInfo->Flags & AML_NAMED) ||
883        (WalkState->OpInfo->Flags & AML_CREATE)) &&
884        (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
885    {
886        Flags |= ACPI_NS_PREFIX_MUST_EXIST;
887    }
888
889    /*
890     * Enter the named type into the internal namespace. We enter the name
891     * as we go downward in the parse tree. Any necessary subobjects that
892     * involve arguments to the opcode must be created as we go back up the
893     * parse tree later.
894     */
895    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
896        ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
897    if (ACPI_FAILURE (Status))
898    {
899        if (Status == AE_ALREADY_EXISTS)
900        {
901            /* The name already exists in this scope */
902
903            if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
904            {
905                /* Allow multiple references to the same scope */
906
907                Node->Type = (UINT8) ObjectType;
908                Status = AE_OK;
909            }
910            else if ((Node->Flags & ANOBJ_IS_EXTERNAL) ||
911                     (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
912            {
913                Status = LdAnalyzeExternals (Node, Op, ObjectType, WalkState);
914                if (ACPI_FAILURE (Status))
915                {
916                    if (Status == AE_ERROR)
917                    {
918                        /*
919                         * The use of AE_ERROR here indicates that there was a
920                         * compiler error emitted in LdAnalyzeExternals which
921                         * means that the caller should proceed to the next Op
922                         * for analysis of subsequent parse objects.
923                         */
924                        Status = AE_OK;
925                    }
926                    return_ACPI_STATUS (Status);
927                }
928
929                if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
930                     (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
931                {
932                    /*
933                     * If we get to here, it means that an actual definition of
934                     * the object declared external exists. Meaning that Op
935                     * loading this this Op should have no change to the ACPI
936                     * namespace. By going to FinishNode, we skip the
937                     * assignment of Node->Op = Op.
938                     */
939                    goto FinishNode;
940                }
941            }
942            else
943            {
944                /* Valid error, object already exists */
945
946                ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
947
948                AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
949                    ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
950                    ExternalPath);
951
952                if (ExternalPath)
953                {
954                    ACPI_FREE (ExternalPath);
955                }
956                return_ACPI_STATUS (AE_OK);
957            }
958        }
959        else if (AE_NOT_FOUND)
960        {
961            /*
962             * One or more prefix NameSegs of the NamePath do not exist
963             * (all of them must exist). Attempt to continue compilation
964             * by setting the current scope to the root.
965             */
966            Node = AcpiGbl_RootNode;
967            Status = AE_OK;
968        }
969        else
970        {
971            /* Flag all other errors as coming from the ACPICA core */
972
973            AslCoreSubsystemError (Op, Status,
974                "Failure from namespace lookup", FALSE);
975            return_ACPI_STATUS (Status);
976        }
977    }
978
979    /* Check special names like _WAK and _PTS */
980
981    LdCheckSpecialNames (Node, Op);
982
983    if (ForceNewScope)
984    {
985        Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
986        if (ACPI_FAILURE (Status))
987        {
988            return_ACPI_STATUS (Status);
989        }
990    }
991
992    /* Point the Node back to the original Parse node */
993
994    Node->Op = Op;
995
996FinishNode:
997
998    /* Point the parse node to the new namespace node */
999
1000    Op->Asl.Node = Node;
1001
1002    if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
1003    {
1004        /*
1005         * Get the method argument count from "Extra" and save
1006         * it in the namespace node
1007         */
1008        Node->Value = (UINT32) Op->Asl.Extra;
1009    }
1010    else if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1011        Node->Type == ACPI_TYPE_METHOD &&
1012        (Node->Flags & ANOBJ_IS_EXTERNAL))
1013    {
1014        Node->Value =
1015            (UINT32) Op->Asl.Child->Asl.Next->Asl.Next->Asl.Value.Integer;
1016    }
1017
1018    return_ACPI_STATUS (Status);
1019}
1020
1021
1022/*******************************************************************************
1023 *
1024 * FUNCTION:    LdMatchExternType
1025 *
1026 * PARAMETERS:  Type1
1027 *              Type2
1028 *
1029 * RETURN:      BOOLEAN
1030 *
1031 * DESCRIPTION: Match Type1 and Type2 with the assumption that one might be
1032 *              using external types and another might be using local types.
1033 *              This should be used to compare the types found in external
1034 *              declarations with types found in other external declarations or
1035 *              named object declaration. This should not be used to match two
1036 *              object type declarations.
1037 *
1038 ******************************************************************************/
1039
1040static BOOLEAN
1041LdMatchExternType (
1042    ACPI_OBJECT_TYPE        Type1,
1043    ACPI_OBJECT_TYPE        Type2)
1044{
1045    BOOLEAN                 Type1IsLocal = Type1 > ACPI_TYPE_EXTERNAL_MAX;
1046    BOOLEAN                 Type2IsLocal = Type2 > ACPI_TYPE_EXTERNAL_MAX;
1047    ACPI_OBJECT_TYPE        ExternalType;
1048    ACPI_OBJECT_TYPE        LocalType;
1049
1050
1051    /*
1052     * The inputs could represent types that are local to ACPICA or types that
1053     * are known externally. Some local types, such as the OperationRegion
1054     * field units, are defined with more granularity than ACPICA local types.
1055     *
1056     * Therefore, map the local types to the external types before matching.
1057     */
1058    if (Type1IsLocal && !Type2IsLocal)
1059    {
1060        LocalType = Type1;
1061        ExternalType = Type2;
1062    }
1063    else if (!Type1IsLocal && Type2IsLocal)
1064    {
1065        LocalType = Type2;
1066        ExternalType = Type1;
1067    }
1068    else
1069    {
1070        return (Type1 == Type2);
1071    }
1072
1073    switch (LocalType)
1074    {
1075        case ACPI_TYPE_LOCAL_REGION_FIELD:
1076        case ACPI_TYPE_LOCAL_BANK_FIELD:
1077        case ACPI_TYPE_LOCAL_INDEX_FIELD:
1078
1079            LocalType = ACPI_TYPE_FIELD_UNIT;
1080            break;
1081
1082        default:
1083            break;
1084    }
1085
1086    return (LocalType == ExternalType);
1087}
1088
1089
1090/*******************************************************************************
1091 *
1092 * FUNCTION:    LdAnalyzeExternals
1093 *
1094 * PARAMETERS:  Node            - Node that represents the named object
1095 *              Op              - Named object declaring this named object
1096 *              ExternalOpType  - Type of ExternalOp
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
1109static ACPI_STATUS
1110LdAnalyzeExternals (
1111    ACPI_NAMESPACE_NODE     *Node,
1112    ACPI_PARSE_OBJECT       *Op,
1113    ACPI_OBJECT_TYPE        ExternalOpType,
1114    ACPI_WALK_STATE         *WalkState)
1115{
1116    ACPI_STATUS             Status = AE_OK;
1117    ACPI_OBJECT_TYPE        ActualExternalOpType;
1118    ACPI_OBJECT_TYPE        ActualOpType;
1119    ACPI_PARSE_OBJECT       *ExternalOp;
1120    ACPI_PARSE_OBJECT       *ActualOp;
1121
1122
1123    /*
1124     * The declaration represented by Node and Op must have the same type.
1125     * The type of the external Op is represented by ExternalOpType. However,
1126     * the type of the pre-existing declaration depends on whether if Op
1127     * is an external declaration or an actual declaration.
1128     */
1129    if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1130    {
1131        ActualExternalOpType = ExternalOpType;
1132        ActualOpType = Node->Type;
1133    }
1134    else
1135    {
1136        ActualExternalOpType = Node->Type;
1137        ActualOpType = ExternalOpType;
1138    }
1139
1140    if ((ActualOpType != ACPI_TYPE_ANY) &&
1141        (ActualExternalOpType != ACPI_TYPE_ANY) &&
1142        !LdMatchExternType (ActualExternalOpType, ActualOpType))
1143    {
1144        if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1145            Node->Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1146        {
1147            AslDualParseOpError (ASL_WARNING,
1148                ASL_MSG_DUPLICATE_EXTERN_MISMATCH, Op, NULL,
1149                ASL_MSG_DUPLICATE_EXTERN_FOUND_HERE, Node->Op, NULL);
1150        }
1151        else
1152        {
1153            if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1154                Node->Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1155            {
1156                ExternalOp = Op;
1157                ActualOp = Node->Op;
1158            }
1159            else
1160            {
1161                ExternalOp = Node->Op;
1162                ActualOp = Op;
1163            }
1164            AslDualParseOpError (ASL_WARNING,
1165                ASL_MSG_DECLARATION_TYPE_MISMATCH, ExternalOp, NULL,
1166                ASL_MSG_TYPE_MISMATCH_FOUND_HERE, ActualOp, NULL);
1167        }
1168    }
1169
1170    /* Set the object type of the external */
1171
1172    if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1173        (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
1174    {
1175        /*
1176         * Allow one create on an object or segment that was
1177         * previously declared External
1178         */
1179        Node->Flags &= ~ANOBJ_IS_EXTERNAL;
1180        Node->Type = (UINT8) ActualOpType;
1181
1182        /* Just retyped a node, probably will need to open a scope */
1183
1184        if (AcpiNsOpensScope (ActualOpType))
1185        {
1186            Status = AcpiDsScopeStackPush (Node, ActualOpType, WalkState);
1187            if (ACPI_FAILURE (Status))
1188            {
1189                return (Status);
1190            }
1191        }
1192
1193        Status = AE_OK;
1194    }
1195    else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
1196             (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1197    {
1198        /*
1199         * Allow externals in same scope as the definition of the
1200         * actual object. Similar to C. Allows multiple definition
1201         * blocks that refer to each other in the same file.
1202         */
1203        Status = AE_OK;
1204    }
1205    else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1206             (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
1207             (ActualOpType == ACPI_TYPE_ANY))
1208    {
1209        /* Allow update of externals of unknown type. */
1210
1211        Node->Type = (UINT8) ActualExternalOpType;
1212        Status = AE_OK;
1213    }
1214
1215    return (Status);
1216}
1217
1218
1219/*******************************************************************************
1220 *
1221 * FUNCTION:    LdCheckSpecialNames
1222 *
1223 * PARAMETERS:  Node        - Node that represents the named object
1224 *              Op          - Named object declaring this named object
1225 *
1226 * RETURN:      None
1227 *
1228 * DESCRIPTION: Check if certain named objects are declared in the incorrect
1229 *              scope. Special named objects are listed in
1230 *              AslGbl_SpecialNamedObjects and can only be declared at the root
1231 *              scope. _UID inside of a processor declaration must not be a
1232 *              string.
1233 *
1234 ******************************************************************************/
1235
1236static void
1237LdCheckSpecialNames (
1238    ACPI_NAMESPACE_NODE     *Node,
1239    ACPI_PARSE_OBJECT       *Op)
1240{
1241    UINT32                  i;
1242
1243
1244    for (i = 0; i < MAX_SPECIAL_NAMES; i++)
1245    {
1246        if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
1247            Node->Parent != AcpiGbl_RootNode)
1248        {
1249            AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
1250            return;
1251        }
1252    }
1253
1254    if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1255        Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1256        Node->Type == ACPI_TYPE_STRING)
1257    {
1258        AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1259    }
1260}
1261
1262
1263/*******************************************************************************
1264 *
1265 * FUNCTION:    LdNamespace2Begin
1266 *
1267 * PARAMETERS:  ASL_WALK_CALLBACK
1268 *
1269 * RETURN:      Status
1270 *
1271 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1272 *              Second pass resolves some forward references.
1273 *
1274 * Notes:
1275 * Currently only needs to handle the Alias operator.
1276 * Could be used to allow forward references from the Scope() operator, but
1277 * the MS interpreter does not allow this, so this compiler does not either.
1278 *
1279 ******************************************************************************/
1280
1281static ACPI_STATUS
1282LdNamespace2Begin (
1283    ACPI_PARSE_OBJECT       *Op,
1284    UINT32                  Level,
1285    void                    *Context)
1286{
1287    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1288    ACPI_STATUS             Status;
1289    ACPI_NAMESPACE_NODE     *Node;
1290    ACPI_OBJECT_TYPE        ObjectType;
1291    BOOLEAN                 ForceNewScope = FALSE;
1292    ACPI_PARSE_OBJECT       *Arg;
1293    char                    *Path;
1294    ACPI_NAMESPACE_NODE     *TargetNode;
1295
1296
1297    ACPI_FUNCTION_NAME (LdNamespace2Begin);
1298    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1299        Op, Op->Asl.ParseOpName));
1300
1301
1302    /* Ignore Ops with no namespace node */
1303
1304    Node = Op->Asl.Node;
1305    if (!Node)
1306    {
1307        return (AE_OK);
1308    }
1309
1310    /* Get the type to determine if we should push the scope */
1311
1312    if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1313        (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1314    {
1315        ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1316    }
1317    else
1318    {
1319        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1320    }
1321
1322    /* Push scope for Resource Templates */
1323
1324    if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1325    {
1326        if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1327        {
1328            ForceNewScope = TRUE;
1329        }
1330    }
1331
1332    /* Push the scope stack */
1333
1334    if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1335    {
1336        Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1337        if (ACPI_FAILURE (Status))
1338        {
1339            return_ACPI_STATUS (Status);
1340        }
1341    }
1342
1343    if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1344    {
1345        /*
1346         * Complete the alias node by getting and saving the target node.
1347         * First child is the alias target
1348         */
1349        Arg = Op->Asl.Child;
1350
1351        /* Get the target pathname */
1352
1353        Path = Arg->Asl.Namepath;
1354        if (!Path)
1355        {
1356            Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1357            if (ACPI_FAILURE (Status))
1358            {
1359                return (Status);
1360            }
1361        }
1362
1363        /* Get the NS node associated with the target. It must exist. */
1364
1365        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1366            ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1367            WalkState, &TargetNode);
1368        if (ACPI_FAILURE (Status))
1369        {
1370            if (Status == AE_NOT_FOUND)
1371            {
1372                /* Standalone NameSeg vs. NamePath */
1373
1374                if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
1375                {
1376                    AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1377                        Arg->Asl.ExternalName);
1378                }
1379                else
1380                {
1381                    AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
1382                        Arg->Asl.ExternalName);
1383                }
1384
1385#if 0
1386/*
1387 * NOTE: Removed 10/2018 to enhance compiler error reporting. No
1388 * regressions seen.
1389 */
1390                /*
1391                 * The name was not found, go ahead and create it.
1392                 * This prevents more errors later.
1393                 */
1394                Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1395                    ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
1396                    ACPI_NS_NO_UPSEARCH, WalkState, &Node);
1397#endif
1398                return (Status);
1399/* Removed: return (AE_OK)*/
1400            }
1401
1402            AslCoreSubsystemError (Op, Status,
1403                "Failure from namespace lookup", FALSE);
1404            return (AE_OK);
1405        }
1406
1407        /* Save the target node within the alias node as well as type information */
1408
1409        Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1410        Node->Type = TargetNode->Type;
1411        if (Node->Type == ACPI_TYPE_METHOD)
1412        {
1413            /* Save the parameter count for methods */
1414
1415            Node->Value = TargetNode->Value;
1416        }
1417    }
1418
1419    return (AE_OK);
1420}
1421
1422
1423/*******************************************************************************
1424 *
1425 * FUNCTION:    LdCommonNamespaceEnd
1426 *
1427 * PARAMETERS:  ASL_WALK_CALLBACK
1428 *
1429 * RETURN:      Status
1430 *
1431 * DESCRIPTION: Ascending callback used during the loading of the namespace,
1432 *              We only need to worry about managing the scope stack here.
1433 *
1434 ******************************************************************************/
1435
1436static ACPI_STATUS
1437LdCommonNamespaceEnd (
1438    ACPI_PARSE_OBJECT       *Op,
1439    UINT32                  Level,
1440    void                    *Context)
1441{
1442    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1443    ACPI_OBJECT_TYPE        ObjectType;
1444    BOOLEAN                 ForceNewScope = FALSE;
1445
1446
1447    ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1448
1449
1450    /* We are only interested in opcodes that have an associated name */
1451
1452    if (!Op->Asl.Namepath)
1453    {
1454        return (AE_OK);
1455    }
1456
1457    /* Get the type to determine if we should pop the scope */
1458
1459    if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1460        (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1461    {
1462        /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1463
1464        ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1465    }
1466    else
1467    {
1468        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1469    }
1470
1471    /* Pop scope that was pushed for Resource Templates */
1472
1473    if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1474    {
1475        if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1476        {
1477            ForceNewScope = TRUE;
1478        }
1479    }
1480
1481    /* Pop the scope stack */
1482
1483    if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1484    {
1485        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1486            "(%s): Popping scope for Op [%s] %p\n",
1487            AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1488
1489        (void) AcpiDsScopeStackPop (WalkState);
1490    }
1491
1492    return (AE_OK);
1493}
1494