1149703c7Sjruoho /******************************************************************************
2149703c7Sjruoho  *
3107eddacSchristos  * Module Name: aslload - compiler namespace load callbacks
4149703c7Sjruoho  *
5149703c7Sjruoho  *****************************************************************************/
6149703c7Sjruoho 
768471b32Sjruoho /*
8*ec12a2faSchristos  * Copyright (C) 2000 - 2022, Intel Corp.
9149703c7Sjruoho  * All rights reserved.
10149703c7Sjruoho  *
1168471b32Sjruoho  * Redistribution and use in source and binary forms, with or without
1268471b32Sjruoho  * modification, are permitted provided that the following conditions
1368471b32Sjruoho  * are met:
1468471b32Sjruoho  * 1. Redistributions of source code must retain the above copyright
1568471b32Sjruoho  *    notice, this list of conditions, and the following disclaimer,
1668471b32Sjruoho  *    without modification.
1768471b32Sjruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1868471b32Sjruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
1968471b32Sjruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
2068471b32Sjruoho  *    including a substantially similar Disclaimer requirement for further
2168471b32Sjruoho  *    binary redistribution.
2268471b32Sjruoho  * 3. Neither the names of the above-listed copyright holders nor the names
2368471b32Sjruoho  *    of any contributors may be used to endorse or promote products derived
2468471b32Sjruoho  *    from this software without specific prior written permission.
25149703c7Sjruoho  *
2668471b32Sjruoho  * Alternatively, this software may be distributed under the terms of the
2768471b32Sjruoho  * GNU General Public License ("GPL") version 2 as published by the Free
2868471b32Sjruoho  * Software Foundation.
29149703c7Sjruoho  *
3068471b32Sjruoho  * NO WARRANTY
3168471b32Sjruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3268471b32Sjruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33adee7055Schristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3468471b32Sjruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3568471b32Sjruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3668471b32Sjruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3768471b32Sjruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3868471b32Sjruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3968471b32Sjruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4068471b32Sjruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4168471b32Sjruoho  * POSSIBILITY OF SUCH DAMAGES.
4268471b32Sjruoho  */
43149703c7Sjruoho 
44149703c7Sjruoho #include "aslcompiler.h"
45149703c7Sjruoho #include "amlcode.h"
46149703c7Sjruoho #include "acdispat.h"
47149703c7Sjruoho #include "acnamesp.h"
488d27934cSchristos #include "acparser.h"
49149703c7Sjruoho #include "aslcompiler.y.h"
50149703c7Sjruoho 
518d27934cSchristos 
52149703c7Sjruoho #define _COMPONENT          ACPI_COMPILER
53149703c7Sjruoho         ACPI_MODULE_NAME    ("aslload")
54149703c7Sjruoho 
55149703c7Sjruoho /* Local prototypes */
56149703c7Sjruoho 
57149703c7Sjruoho static ACPI_STATUS
58149703c7Sjruoho LdLoadFieldElements (
59bd6fb9ddSchristos     UINT32                  AmlType,
60149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
61149703c7Sjruoho     ACPI_WALK_STATE         *WalkState);
62149703c7Sjruoho 
63149703c7Sjruoho static ACPI_STATUS
64149703c7Sjruoho LdLoadResourceElements (
65149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
66149703c7Sjruoho     ACPI_WALK_STATE         *WalkState);
67149703c7Sjruoho 
68149703c7Sjruoho static ACPI_STATUS
69149703c7Sjruoho LdNamespace1Begin (
70149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
71149703c7Sjruoho     UINT32                  Level,
72149703c7Sjruoho     void                    *Context);
73149703c7Sjruoho 
74149703c7Sjruoho static ACPI_STATUS
75149703c7Sjruoho LdNamespace2Begin (
76149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
77149703c7Sjruoho     UINT32                  Level,
78149703c7Sjruoho     void                    *Context);
79149703c7Sjruoho 
80149703c7Sjruoho static ACPI_STATUS
81149703c7Sjruoho LdCommonNamespaceEnd (
82149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
83149703c7Sjruoho     UINT32                  Level,
84149703c7Sjruoho     void                    *Context);
85149703c7Sjruoho 
86bd6fb9ddSchristos static void
87bd6fb9ddSchristos LdCheckSpecialNames (
88bd6fb9ddSchristos     ACPI_NAMESPACE_NODE     *Node,
89bd6fb9ddSchristos     ACPI_PARSE_OBJECT       *Op);
90149703c7Sjruoho 
91bd973ebcSchristos static ACPI_STATUS
92bd973ebcSchristos LdAnalyzeExternals (
93bd973ebcSchristos     ACPI_NAMESPACE_NODE     *Node,
94bd973ebcSchristos     ACPI_PARSE_OBJECT       *Op,
95bd973ebcSchristos     ACPI_OBJECT_TYPE        ExternalOpType,
96bd973ebcSchristos     ACPI_WALK_STATE         *WalkState);
97bd973ebcSchristos 
98bd973ebcSchristos 
99149703c7Sjruoho /*******************************************************************************
100149703c7Sjruoho  *
101149703c7Sjruoho  * FUNCTION:    LdLoadNamespace
102149703c7Sjruoho  *
103149703c7Sjruoho  * PARAMETERS:  RootOp      - Root of the parse tree
104149703c7Sjruoho  *
105149703c7Sjruoho  * RETURN:      Status
106149703c7Sjruoho  *
107149703c7Sjruoho  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
108149703c7Sjruoho  *              named ASL/AML objects into the namespace. The namespace is
109149703c7Sjruoho  *              constructed in order to resolve named references and references
110149703c7Sjruoho  *              to named fields within resource templates/descriptors.
111149703c7Sjruoho  *
112149703c7Sjruoho  ******************************************************************************/
113149703c7Sjruoho 
114149703c7Sjruoho ACPI_STATUS
LdLoadNamespace(ACPI_PARSE_OBJECT * RootOp)115149703c7Sjruoho LdLoadNamespace (
116149703c7Sjruoho     ACPI_PARSE_OBJECT       *RootOp)
117149703c7Sjruoho {
118149703c7Sjruoho     ACPI_WALK_STATE         *WalkState;
119149703c7Sjruoho 
120149703c7Sjruoho 
121149703c7Sjruoho     /* Create a new walk state */
122149703c7Sjruoho 
123149703c7Sjruoho     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
124149703c7Sjruoho     if (!WalkState)
125149703c7Sjruoho     {
12673d4e80bSchristos         return (AE_NO_MEMORY);
127149703c7Sjruoho     }
128149703c7Sjruoho 
129149703c7Sjruoho     /* Walk the entire parse tree, first pass */
130149703c7Sjruoho 
131149703c7Sjruoho     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
132149703c7Sjruoho         LdCommonNamespaceEnd, WalkState);
133149703c7Sjruoho 
134149703c7Sjruoho     /* Second pass to handle forward references */
135149703c7Sjruoho 
136149703c7Sjruoho     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
137149703c7Sjruoho         LdCommonNamespaceEnd, WalkState);
138149703c7Sjruoho 
139149703c7Sjruoho     /* Dump the namespace if debug is enabled */
140149703c7Sjruoho 
141dab10b95Schristos     if (AcpiDbgLevel & ACPI_LV_TABLES)
142dab10b95Schristos     {
143149703c7Sjruoho         AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
144dab10b95Schristos     }
145dab10b95Schristos 
146ea4d7e80Schristos     ACPI_FREE (WalkState);
14773d4e80bSchristos     return (AE_OK);
148149703c7Sjruoho }
149149703c7Sjruoho 
150149703c7Sjruoho 
151149703c7Sjruoho /*******************************************************************************
152149703c7Sjruoho  *
153149703c7Sjruoho  * FUNCTION:    LdLoadFieldElements
154149703c7Sjruoho  *
155bd6fb9ddSchristos  * PARAMETERS:  AmlType         - Type to search
156bd6fb9ddSchristos  *              Op              - Parent node (Field)
157149703c7Sjruoho  *              WalkState       - Current walk state
158149703c7Sjruoho  *
159149703c7Sjruoho  * RETURN:      Status
160149703c7Sjruoho  *
161149703c7Sjruoho  * DESCRIPTION: Enter the named elements of the field (children of the parent)
162149703c7Sjruoho  *              into the namespace.
163149703c7Sjruoho  *
164149703c7Sjruoho  ******************************************************************************/
165149703c7Sjruoho 
166149703c7Sjruoho static ACPI_STATUS
LdLoadFieldElements(UINT32 AmlType,ACPI_PARSE_OBJECT * Op,ACPI_WALK_STATE * WalkState)167149703c7Sjruoho LdLoadFieldElements (
168bd6fb9ddSchristos     UINT32                  AmlType,
169149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
170149703c7Sjruoho     ACPI_WALK_STATE         *WalkState)
171149703c7Sjruoho {
172149703c7Sjruoho     ACPI_PARSE_OBJECT       *Child = NULL;
173bd6fb9ddSchristos     ACPI_PARSE_OBJECT       *SourceRegion;
174149703c7Sjruoho     ACPI_NAMESPACE_NODE     *Node;
175149703c7Sjruoho     ACPI_STATUS             Status;
176bd973ebcSchristos     char                    *ExternalPath;
177149703c7Sjruoho 
178149703c7Sjruoho 
179bd6fb9ddSchristos     SourceRegion = UtGetArg (Op, 0);
180bd6fb9ddSchristos     if (SourceRegion)
181bd6fb9ddSchristos     {
182bd6fb9ddSchristos         Status = AcpiNsLookup (WalkState->ScopeInfo,
183bd973ebcSchristos             SourceRegion->Asl.Value.String, AmlType, ACPI_IMODE_EXECUTE,
184bd973ebcSchristos             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
185bd6fb9ddSchristos         if (Status == AE_NOT_FOUND)
186bd6fb9ddSchristos         {
187bd6fb9ddSchristos             /*
188bd6fb9ddSchristos              * If the named object is not found, it means that it is either a
189bd6fb9ddSchristos              * forward reference or the named object does not exist.
190bd6fb9ddSchristos              */
191bd6fb9ddSchristos             SourceRegion->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
192bd6fb9ddSchristos         }
193bd6fb9ddSchristos     }
194bd6fb9ddSchristos 
195149703c7Sjruoho     /* Get the first named field element */
196149703c7Sjruoho 
197149703c7Sjruoho     switch (Op->Asl.AmlOpcode)
198149703c7Sjruoho     {
199149703c7Sjruoho     case AML_BANK_FIELD_OP:
200149703c7Sjruoho 
201149703c7Sjruoho         Child = UtGetArg (Op, 6);
202149703c7Sjruoho         break;
203149703c7Sjruoho 
204149703c7Sjruoho     case AML_INDEX_FIELD_OP:
205149703c7Sjruoho 
206149703c7Sjruoho         Child = UtGetArg (Op, 5);
207149703c7Sjruoho         break;
208149703c7Sjruoho 
209149703c7Sjruoho     case AML_FIELD_OP:
210149703c7Sjruoho 
211149703c7Sjruoho         Child = UtGetArg (Op, 4);
212149703c7Sjruoho         break;
213149703c7Sjruoho 
214149703c7Sjruoho     default:
21573d4e80bSchristos 
216149703c7Sjruoho         /* No other opcodes should arrive here */
21773d4e80bSchristos 
218149703c7Sjruoho         return (AE_BAD_PARAMETER);
219149703c7Sjruoho     }
220149703c7Sjruoho 
221149703c7Sjruoho     /* Enter all elements into the namespace */
222149703c7Sjruoho 
223149703c7Sjruoho     while (Child)
224149703c7Sjruoho     {
225149703c7Sjruoho         switch (Child->Asl.AmlOpcode)
226149703c7Sjruoho         {
227149703c7Sjruoho         case AML_INT_RESERVEDFIELD_OP:
228149703c7Sjruoho         case AML_INT_ACCESSFIELD_OP:
22973d4e80bSchristos         case AML_INT_CONNECTION_OP:
230149703c7Sjruoho             break;
231149703c7Sjruoho 
232149703c7Sjruoho         default:
233149703c7Sjruoho 
234149703c7Sjruoho             Status = AcpiNsLookup (WalkState->ScopeInfo,
235149703c7Sjruoho                 Child->Asl.Value.String,
236149703c7Sjruoho                 ACPI_TYPE_LOCAL_REGION_FIELD,
237149703c7Sjruoho                 ACPI_IMODE_LOAD_PASS1,
238149703c7Sjruoho                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
23994e0d463Schristos                     ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
240149703c7Sjruoho             if (ACPI_FAILURE (Status))
241149703c7Sjruoho             {
242149703c7Sjruoho                 if (Status != AE_ALREADY_EXISTS)
243149703c7Sjruoho                 {
244149703c7Sjruoho                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
245149703c7Sjruoho                         Child->Asl.Value.String);
246149703c7Sjruoho                     return (Status);
247149703c7Sjruoho                 }
24835a687ffSchristos                 else if (Status == AE_ALREADY_EXISTS &&
249dab10b95Schristos                     (Node->Flags & ANOBJ_IS_EXTERNAL))
25035a687ffSchristos                 {
25135a687ffSchristos                     Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
252f5a85da7Schristos                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
25335a687ffSchristos                 }
25435a687ffSchristos                 else
25535a687ffSchristos                 {
256149703c7Sjruoho                     /*
257149703c7Sjruoho                      * The name already exists in this scope
258149703c7Sjruoho                      * But continue processing the elements
259149703c7Sjruoho                      */
260bd973ebcSchristos                     ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
261bd973ebcSchristos 
2625fc006f0Schristos                     AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
263bd973ebcSchristos                         ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
264bd973ebcSchristos                         ExternalPath);
265bd973ebcSchristos 
266bd973ebcSchristos                     if (ExternalPath)
267bd973ebcSchristos                     {
268bd973ebcSchristos                         ACPI_FREE (ExternalPath);
269bd973ebcSchristos                     }
270149703c7Sjruoho                 }
27135a687ffSchristos             }
272149703c7Sjruoho             else
273149703c7Sjruoho             {
274149703c7Sjruoho                 Child->Asl.Node = Node;
275149703c7Sjruoho                 Node->Op = Child;
276149703c7Sjruoho             }
277149703c7Sjruoho             break;
278149703c7Sjruoho         }
27973d4e80bSchristos 
280149703c7Sjruoho         Child = Child->Asl.Next;
281149703c7Sjruoho     }
28273d4e80bSchristos 
283149703c7Sjruoho     return (AE_OK);
284149703c7Sjruoho }
285149703c7Sjruoho 
286149703c7Sjruoho 
287149703c7Sjruoho /*******************************************************************************
288149703c7Sjruoho  *
289149703c7Sjruoho  * FUNCTION:    LdLoadResourceElements
290149703c7Sjruoho  *
291149703c7Sjruoho  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
292149703c7Sjruoho  *              WalkState       - Current walk state
293149703c7Sjruoho  *
294149703c7Sjruoho  * RETURN:      Status
295149703c7Sjruoho  *
296149703c7Sjruoho  * DESCRIPTION: Enter the named elements of the resource descriptor (children
297149703c7Sjruoho  *              of the parent) into the namespace.
298149703c7Sjruoho  *
299149703c7Sjruoho  * NOTE: In the real AML namespace, these named elements never exist. But
300149703c7Sjruoho  *       we simply use the namespace here as a symbol table so we can look
301149703c7Sjruoho  *       them up as they are referenced.
302149703c7Sjruoho  *
303149703c7Sjruoho  ******************************************************************************/
304149703c7Sjruoho 
305149703c7Sjruoho static ACPI_STATUS
LdLoadResourceElements(ACPI_PARSE_OBJECT * Op,ACPI_WALK_STATE * WalkState)306149703c7Sjruoho LdLoadResourceElements (
307149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
308149703c7Sjruoho     ACPI_WALK_STATE         *WalkState)
309149703c7Sjruoho {
310149703c7Sjruoho     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
311149703c7Sjruoho     ACPI_NAMESPACE_NODE     *Node;
312149703c7Sjruoho     ACPI_STATUS             Status;
313bd973ebcSchristos     char                    *ExternalPath;
314149703c7Sjruoho 
315149703c7Sjruoho 
316149703c7Sjruoho     /*
317149703c7Sjruoho      * Enter the resource name into the namespace. Name must not already exist.
318149703c7Sjruoho      * This opens a scope, so later field names are guaranteed to be new/unique.
319149703c7Sjruoho      */
320149703c7Sjruoho     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
321149703c7Sjruoho         ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
322149703c7Sjruoho         ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
323149703c7Sjruoho         WalkState, &Node);
324149703c7Sjruoho     if (ACPI_FAILURE (Status))
325149703c7Sjruoho     {
326149703c7Sjruoho         if (Status == AE_ALREADY_EXISTS)
327149703c7Sjruoho         {
328149703c7Sjruoho             /* Actual node causing the error was saved in ParentMethod */
329149703c7Sjruoho 
330bd973ebcSchristos             ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
331bd973ebcSchristos 
332232afe62Schristos             AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
333232afe62Schristos                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
334bd973ebcSchristos                 ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
335bd973ebcSchristos                 ExternalPath);
336bd973ebcSchristos 
337bd973ebcSchristos             if (ExternalPath)
338bd973ebcSchristos             {
339bd973ebcSchristos                 ACPI_FREE (ExternalPath);
340bd973ebcSchristos             }
341149703c7Sjruoho             return (AE_OK);
342149703c7Sjruoho         }
343149703c7Sjruoho         return (Status);
344149703c7Sjruoho     }
345149703c7Sjruoho 
346149703c7Sjruoho     Node->Value = (UINT32) Op->Asl.Value.Integer;
347149703c7Sjruoho     Node->Op = Op;
348149703c7Sjruoho     Op->Asl.Node = Node;
349149703c7Sjruoho 
350149703c7Sjruoho     /*
351149703c7Sjruoho      * Now enter the predefined fields, for easy lookup when referenced
352149703c7Sjruoho      * by the source ASL
353149703c7Sjruoho      */
354149703c7Sjruoho     InitializerOp = ASL_GET_CHILD_NODE (Op);
355149703c7Sjruoho     while (InitializerOp)
356149703c7Sjruoho     {
357149703c7Sjruoho         if (InitializerOp->Asl.ExternalName)
358149703c7Sjruoho         {
359149703c7Sjruoho             Status = AcpiNsLookup (WalkState->ScopeInfo,
360149703c7Sjruoho                 InitializerOp->Asl.ExternalName,
361aaf4f1f0Schristos                 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
362aaf4f1f0Schristos                 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
363149703c7Sjruoho             if (ACPI_FAILURE (Status))
364149703c7Sjruoho             {
365149703c7Sjruoho                 return (Status);
366149703c7Sjruoho             }
367149703c7Sjruoho 
368149703c7Sjruoho             /*
36973d4e80bSchristos              * Store the field offset and length in the namespace node
37073d4e80bSchristos              * so it can be used when the field is referenced
371149703c7Sjruoho              */
37273d4e80bSchristos             Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
37373d4e80bSchristos             Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
374149703c7Sjruoho             InitializerOp->Asl.Node = Node;
375149703c7Sjruoho             Node->Op = InitializerOp;
376149703c7Sjruoho         }
37773d4e80bSchristos 
378149703c7Sjruoho         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
379149703c7Sjruoho     }
380149703c7Sjruoho 
381149703c7Sjruoho     return (AE_OK);
382149703c7Sjruoho }
383149703c7Sjruoho 
384149703c7Sjruoho 
385149703c7Sjruoho /*******************************************************************************
386149703c7Sjruoho  *
387149703c7Sjruoho  * FUNCTION:    LdNamespace1Begin
388149703c7Sjruoho  *
389149703c7Sjruoho  * PARAMETERS:  ASL_WALK_CALLBACK
390149703c7Sjruoho  *
391149703c7Sjruoho  * RETURN:      Status
392149703c7Sjruoho  *
393149703c7Sjruoho  * DESCRIPTION: Descending callback used during the parse tree walk. If this
394149703c7Sjruoho  *              is a named AML opcode, enter into the namespace
395149703c7Sjruoho  *
396149703c7Sjruoho  ******************************************************************************/
397149703c7Sjruoho 
398149703c7Sjruoho static ACPI_STATUS
LdNamespace1Begin(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)399149703c7Sjruoho LdNamespace1Begin (
400149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
401149703c7Sjruoho     UINT32                  Level,
402149703c7Sjruoho     void                    *Context)
403149703c7Sjruoho {
404149703c7Sjruoho     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
405149703c7Sjruoho     ACPI_NAMESPACE_NODE     *Node;
40694e0d463Schristos     ACPI_PARSE_OBJECT       *MethodOp;
407149703c7Sjruoho     ACPI_STATUS             Status;
408149703c7Sjruoho     ACPI_OBJECT_TYPE        ObjectType;
409149703c7Sjruoho     char                    *Path;
410149703c7Sjruoho     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
411149703c7Sjruoho     ACPI_PARSE_OBJECT       *Arg;
412149703c7Sjruoho     UINT32                  i;
413149703c7Sjruoho     BOOLEAN                 ForceNewScope = FALSE;
4148d27934cSchristos     const ACPI_OPCODE_INFO  *OpInfo;
4158d27934cSchristos     ACPI_PARSE_OBJECT       *ParentOp;
416bd973ebcSchristos     char                    *ExternalPath;
417149703c7Sjruoho 
418149703c7Sjruoho 
419149703c7Sjruoho     ACPI_FUNCTION_NAME (LdNamespace1Begin);
4208d27934cSchristos 
4218d27934cSchristos 
422149703c7Sjruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
423149703c7Sjruoho         Op, Op->Asl.ParseOpName));
424149703c7Sjruoho 
425149703c7Sjruoho     /*
426149703c7Sjruoho      * We are only interested in opcodes that have an associated name
427149703c7Sjruoho      * (or multiple names)
428149703c7Sjruoho      */
429149703c7Sjruoho     switch (Op->Asl.AmlOpcode)
430149703c7Sjruoho     {
431149703c7Sjruoho     case AML_INDEX_FIELD_OP:
432bd6fb9ddSchristos 
433bd6fb9ddSchristos         Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
434bd6fb9ddSchristos         return (Status);
435bd6fb9ddSchristos 
436bd6fb9ddSchristos     case AML_BANK_FIELD_OP:
437149703c7Sjruoho     case AML_FIELD_OP:
438149703c7Sjruoho 
439bd6fb9ddSchristos         Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
440bd6fb9ddSchristos         return (Status);
441149703c7Sjruoho 
442ea4d7e80Schristos     case AML_INT_CONNECTION_OP:
443ea4d7e80Schristos 
444ea4d7e80Schristos         if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
445ea4d7e80Schristos         {
446ea4d7e80Schristos             break;
447ea4d7e80Schristos         }
448ea4d7e80Schristos 
4495fc006f0Schristos         Arg = Op->Asl.Child;
450ea4d7e80Schristos         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
451ea4d7e80Schristos             ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
452ea4d7e80Schristos             WalkState, &Node);
453ea4d7e80Schristos         if (ACPI_FAILURE (Status))
454ea4d7e80Schristos         {
455ea4d7e80Schristos             break;
456ea4d7e80Schristos         }
457ea4d7e80Schristos 
458ea4d7e80Schristos         break;
459ea4d7e80Schristos 
460149703c7Sjruoho     default:
461149703c7Sjruoho 
462149703c7Sjruoho         /* All other opcodes go below */
46373d4e80bSchristos 
464149703c7Sjruoho         break;
465149703c7Sjruoho     }
466149703c7Sjruoho 
467149703c7Sjruoho     /* Check if this object has already been installed in the namespace */
468149703c7Sjruoho 
469149703c7Sjruoho     if (Op->Asl.Node)
470149703c7Sjruoho     {
471149703c7Sjruoho         return (AE_OK);
472149703c7Sjruoho     }
473149703c7Sjruoho 
4748d27934cSchristos     /* Check for a possible illegal forward reference */
4758d27934cSchristos 
4768d27934cSchristos     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
477bd973ebcSchristos         (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
478bd973ebcSchristos         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
4798d27934cSchristos     {
4808d27934cSchristos         /*
4818d27934cSchristos          * Op->Asl.Namepath will be NULL for these opcodes.
4828d27934cSchristos          * These opcodes are guaranteed to have a parent.
4838d27934cSchristos          * Examine the parent opcode.
4848d27934cSchristos          */
4858d27934cSchristos         ParentOp = Op->Asl.Parent;
4868d27934cSchristos         OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
4878d27934cSchristos 
4888d27934cSchristos         /*
4898d27934cSchristos          * Exclude all operators that actually declare a new name:
4908d27934cSchristos          *      Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
4918d27934cSchristos          * We only want references to named objects:
4928d27934cSchristos          *      Store (2, WXYZ) -> Attempt to resolve the name
4938d27934cSchristos          */
494bd973ebcSchristos         if ((Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
495bd973ebcSchristos             (OpInfo->Class == AML_CLASS_NAMED_OBJECT))
4968d27934cSchristos         {
4978d27934cSchristos             return (AE_OK);
4988d27934cSchristos         }
4998d27934cSchristos 
5008d27934cSchristos         /*
5018d27934cSchristos          * Check if the referenced object exists at this point during
5028d27934cSchristos          * the load:
5038d27934cSchristos          * 1) If it exists, then this cannot be a forward reference.
5048d27934cSchristos          * 2) If it does not exist, it could be a forward reference or
5058d27934cSchristos          * it truly does not exist (and no external declaration).
5068d27934cSchristos          */
5078d27934cSchristos         Status = AcpiNsLookup (WalkState->ScopeInfo,
5088d27934cSchristos             Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
5098d27934cSchristos             ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
5108d27934cSchristos             WalkState, &Node);
5118d27934cSchristos         if (Status == AE_NOT_FOUND)
5128d27934cSchristos         {
5138d27934cSchristos             /*
514f5a85da7Schristos              * This is either a forward reference or the object truly
5158d27934cSchristos              * does not exist. The two cases can only be differentiated
5168d27934cSchristos              * during the cross-reference stage later. Mark the Op/Name
5178d27934cSchristos              * as not-found for now to indicate the need for further
5188d27934cSchristos              * processing.
5198d27934cSchristos              *
5208d27934cSchristos              * Special case: Allow forward references from elements of
5218d27934cSchristos              * Package objects. This provides compatibility with other
5228d27934cSchristos              * ACPI implementations. To correctly implement this, the
5238d27934cSchristos              * ACPICA table load defers package resolution until the entire
5248d27934cSchristos              * namespace has been loaded.
5258d27934cSchristos              */
5268d27934cSchristos             if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
5278d27934cSchristos                 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
5288d27934cSchristos             {
5298d27934cSchristos                 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
5308d27934cSchristos             }
5318d27934cSchristos 
5328d27934cSchristos             return (AE_OK);
5338d27934cSchristos         }
5348d27934cSchristos 
5358d27934cSchristos         return (Status);
5368d27934cSchristos     }
5378d27934cSchristos 
538149703c7Sjruoho     Path = Op->Asl.Namepath;
539149703c7Sjruoho     if (!Path)
540149703c7Sjruoho     {
541149703c7Sjruoho         return (AE_OK);
542149703c7Sjruoho     }
543149703c7Sjruoho 
544149703c7Sjruoho     /* Map the raw opcode into an internal object type */
545149703c7Sjruoho 
546149703c7Sjruoho     switch (Op->Asl.ParseOpcode)
547149703c7Sjruoho     {
548149703c7Sjruoho     case PARSEOP_NAME:
549149703c7Sjruoho 
550149703c7Sjruoho         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
551149703c7Sjruoho         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
552149703c7Sjruoho 
553149703c7Sjruoho         /*
554149703c7Sjruoho          * If this name refers to a ResourceTemplate, we will need to open
555149703c7Sjruoho          * a new scope so that the resource subfield names can be entered into
556149703c7Sjruoho          * the namespace underneath this name
557149703c7Sjruoho          */
55835a687ffSchristos         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
559149703c7Sjruoho         {
560149703c7Sjruoho             ForceNewScope = TRUE;
561149703c7Sjruoho         }
562149703c7Sjruoho 
563149703c7Sjruoho         /* Get the data type associated with the named object, not the name itself */
564149703c7Sjruoho 
565149703c7Sjruoho         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
566149703c7Sjruoho 
567149703c7Sjruoho         ObjectType = 1;
568149703c7Sjruoho         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
569149703c7Sjruoho         {
570149703c7Sjruoho             ObjectType++;
571149703c7Sjruoho         }
572149703c7Sjruoho         break;
573149703c7Sjruoho 
574149703c7Sjruoho     case PARSEOP_EXTERNAL:
575149703c7Sjruoho         /*
576149703c7Sjruoho          * "External" simply enters a name and type into the namespace.
577149703c7Sjruoho          * We must be careful to not open a new scope, however, no matter
578149703c7Sjruoho          * what type the external name refers to (e.g., a method)
579149703c7Sjruoho          *
580149703c7Sjruoho          * first child is name, next child is ObjectType
581149703c7Sjruoho          */
582107eddacSchristos         ObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
583149703c7Sjruoho 
584149703c7Sjruoho         /*
585149703c7Sjruoho          * We will mark every new node along the path as "External". This
586149703c7Sjruoho          * allows some or all of the nodes to be created later in the ASL
587149703c7Sjruoho          * code. Handles cases like this:
588149703c7Sjruoho          *
589149703c7Sjruoho          *   External (\_SB_.PCI0.ABCD, IntObj)
590149703c7Sjruoho          *   Scope (_SB_)
591149703c7Sjruoho          *   {
592149703c7Sjruoho          *       Device (PCI0)
593149703c7Sjruoho          *       {
594149703c7Sjruoho          *       }
595149703c7Sjruoho          *   }
596149703c7Sjruoho          *   Method (X)
597149703c7Sjruoho          *   {
598149703c7Sjruoho          *       Store (\_SB_.PCI0.ABCD, Local0)
599149703c7Sjruoho          *   }
600149703c7Sjruoho          */
601107eddacSchristos         Flags |= ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE;
602149703c7Sjruoho         break;
603149703c7Sjruoho 
604149703c7Sjruoho     case PARSEOP_DEFAULT_ARG:
605149703c7Sjruoho 
60635a687ffSchristos         if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
607149703c7Sjruoho         {
608149703c7Sjruoho             Status = LdLoadResourceElements (Op, WalkState);
609149703c7Sjruoho             return_ACPI_STATUS (Status);
610149703c7Sjruoho         }
611149703c7Sjruoho 
612149703c7Sjruoho         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
613149703c7Sjruoho         break;
614149703c7Sjruoho 
615149703c7Sjruoho     case PARSEOP_SCOPE:
616149703c7Sjruoho         /*
617149703c7Sjruoho          * The name referenced by Scope(Name) must already exist at this point.
618149703c7Sjruoho          * In other words, forward references for Scope() are not supported.
619149703c7Sjruoho          * The only real reason for this is that the MS interpreter cannot
620149703c7Sjruoho          * handle this case. Perhaps someday this case can go away.
621149703c7Sjruoho          */
622149703c7Sjruoho         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
623aaf4f1f0Schristos             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
624149703c7Sjruoho         if (ACPI_FAILURE (Status))
625149703c7Sjruoho         {
626149703c7Sjruoho             if (Status == AE_NOT_FOUND)
627149703c7Sjruoho             {
628149703c7Sjruoho                 /* The name was not found, go ahead and create it */
629149703c7Sjruoho 
630149703c7Sjruoho                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
631aaf4f1f0Schristos                     ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
632aaf4f1f0Schristos                     Flags, WalkState, &Node);
63373d4e80bSchristos                 if (ACPI_FAILURE (Status))
63473d4e80bSchristos                 {
63573d4e80bSchristos                     return_ACPI_STATUS (Status);
63673d4e80bSchristos                 }
637149703c7Sjruoho 
638aaf4f1f0Schristos                 /* However, this is an error -- operand to Scope must exist */
639aaf4f1f0Schristos 
640f5a85da7Schristos                 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
641aaf4f1f0Schristos                 {
642149703c7Sjruoho                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
643149703c7Sjruoho                         Op->Asl.ExternalName);
644aaf4f1f0Schristos                 }
645aaf4f1f0Schristos                 else
646aaf4f1f0Schristos                 {
647aaf4f1f0Schristos                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
648149703c7Sjruoho                         Op->Asl.ExternalName);
649aaf4f1f0Schristos                 }
650aaf4f1f0Schristos 
651149703c7Sjruoho                 goto FinishNode;
652149703c7Sjruoho             }
653149703c7Sjruoho 
654149703c7Sjruoho             AslCoreSubsystemError (Op, Status,
655149703c7Sjruoho                 "Failure from namespace lookup", FALSE);
656149703c7Sjruoho 
657149703c7Sjruoho             return_ACPI_STATUS (Status);
658149703c7Sjruoho         }
65994e0d463Schristos         else /* Status AE_OK */
66094e0d463Schristos         {
66194e0d463Schristos             /*
66294e0d463Schristos              * Do not allow references to external scopes from the DSDT.
66394e0d463Schristos              * This is because the DSDT is always loaded first, and the
66494e0d463Schristos              * external reference cannot be resolved -- causing a runtime
66594e0d463Schristos              * error because Scope() must be resolved immediately.
66694e0d463Schristos              * 10/2015.
66794e0d463Schristos              */
66894e0d463Schristos             if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
669f5a85da7Schristos                 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
67094e0d463Schristos             {
67194e0d463Schristos                 /* However, allowed if the reference is within a method */
67294e0d463Schristos 
67394e0d463Schristos                 MethodOp = Op->Asl.Parent;
67494e0d463Schristos                 while (MethodOp &&
67594e0d463Schristos                       (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
67694e0d463Schristos                 {
67794e0d463Schristos                     MethodOp = MethodOp->Asl.Parent;
67894e0d463Schristos                 }
67994e0d463Schristos 
68094e0d463Schristos                 if (!MethodOp)
68194e0d463Schristos                 {
68294e0d463Schristos                     /* Not in a control method, error */
68394e0d463Schristos 
68494e0d463Schristos                     AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
68594e0d463Schristos                 }
68694e0d463Schristos             }
68794e0d463Schristos         }
688149703c7Sjruoho 
689149703c7Sjruoho         /* We found a node with this name, now check the type */
690149703c7Sjruoho 
691149703c7Sjruoho         switch (Node->Type)
692149703c7Sjruoho         {
693149703c7Sjruoho         case ACPI_TYPE_LOCAL_SCOPE:
694149703c7Sjruoho         case ACPI_TYPE_DEVICE:
695149703c7Sjruoho         case ACPI_TYPE_POWER:
696149703c7Sjruoho         case ACPI_TYPE_PROCESSOR:
697149703c7Sjruoho         case ACPI_TYPE_THERMAL:
698149703c7Sjruoho 
699149703c7Sjruoho             /* These are acceptable types - they all open a new scope */
700149703c7Sjruoho             break;
701149703c7Sjruoho 
702149703c7Sjruoho         case ACPI_TYPE_INTEGER:
703149703c7Sjruoho         case ACPI_TYPE_STRING:
704149703c7Sjruoho         case ACPI_TYPE_BUFFER:
705149703c7Sjruoho             /*
706149703c7Sjruoho              * These types we will allow, but we will change the type.
707149703c7Sjruoho              * This enables some existing code of the form:
708149703c7Sjruoho              *
709149703c7Sjruoho              *  Name (DEB, 0)
710149703c7Sjruoho              *  Scope (DEB) { ... }
711149703c7Sjruoho              *
712149703c7Sjruoho              * Which is used to workaround the fact that the MS interpreter
713149703c7Sjruoho              * does not allow Scope() forward references.
714149703c7Sjruoho              */
715aaf4f1f0Schristos             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "%s [%s], changing type to [Scope]",
716149703c7Sjruoho                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
717aaf4f1f0Schristos             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
718149703c7Sjruoho 
719149703c7Sjruoho             /* Switch the type to scope, open the new scope */
720149703c7Sjruoho 
721149703c7Sjruoho             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
722149703c7Sjruoho             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
723149703c7Sjruoho                 WalkState);
724149703c7Sjruoho             if (ACPI_FAILURE (Status))
725149703c7Sjruoho             {
726149703c7Sjruoho                 return_ACPI_STATUS (Status);
727149703c7Sjruoho             }
728149703c7Sjruoho             break;
729149703c7Sjruoho 
730149703c7Sjruoho         default:
731149703c7Sjruoho 
732149703c7Sjruoho             /* All other types are an error */
733149703c7Sjruoho 
734aaf4f1f0Schristos             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "%s [%s]", Op->Asl.ExternalName,
735149703c7Sjruoho                 AcpiUtGetTypeName (Node->Type));
736aaf4f1f0Schristos             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
737149703c7Sjruoho 
738149703c7Sjruoho             /*
739149703c7Sjruoho              * However, switch the type to be an actual scope so
740149703c7Sjruoho              * that compilation can continue without generating a whole
741149703c7Sjruoho              * cascade of additional errors. Open the new scope.
742149703c7Sjruoho              */
743149703c7Sjruoho             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
744149703c7Sjruoho             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
745149703c7Sjruoho                 WalkState);
746149703c7Sjruoho             if (ACPI_FAILURE (Status))
747149703c7Sjruoho             {
748149703c7Sjruoho                 return_ACPI_STATUS (Status);
749149703c7Sjruoho             }
750149703c7Sjruoho             break;
751149703c7Sjruoho         }
752149703c7Sjruoho 
753149703c7Sjruoho         Status = AE_OK;
754149703c7Sjruoho         goto FinishNode;
755149703c7Sjruoho 
756149703c7Sjruoho     default:
757149703c7Sjruoho 
758149703c7Sjruoho         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
759149703c7Sjruoho         break;
760149703c7Sjruoho     }
761149703c7Sjruoho 
762149703c7Sjruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
763149703c7Sjruoho         Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
764149703c7Sjruoho 
765149703c7Sjruoho     /* The name must not already exist */
766149703c7Sjruoho 
767149703c7Sjruoho     Flags |= ACPI_NS_ERROR_IF_FOUND;
768149703c7Sjruoho 
769149703c7Sjruoho     /*
770aaf4f1f0Schristos      * For opcodes that enter new names into the namespace,
771aaf4f1f0Schristos      * all prefix NameSegs must exist.
772aaf4f1f0Schristos      */
773aaf4f1f0Schristos     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
774aaf4f1f0Schristos     if (((WalkState->OpInfo->Flags & AML_NAMED) ||
775aaf4f1f0Schristos         (WalkState->OpInfo->Flags & AML_CREATE)) &&
776aaf4f1f0Schristos         (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
777aaf4f1f0Schristos     {
778aaf4f1f0Schristos         Flags |= ACPI_NS_PREFIX_MUST_EXIST;
779aaf4f1f0Schristos     }
780aaf4f1f0Schristos 
781aaf4f1f0Schristos     /*
782149703c7Sjruoho      * Enter the named type into the internal namespace. We enter the name
783149703c7Sjruoho      * as we go downward in the parse tree. Any necessary subobjects that
784149703c7Sjruoho      * involve arguments to the opcode must be created as we go back up the
785149703c7Sjruoho      * parse tree later.
786149703c7Sjruoho      */
787149703c7Sjruoho     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
788149703c7Sjruoho         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
789149703c7Sjruoho     if (ACPI_FAILURE (Status))
790149703c7Sjruoho     {
791149703c7Sjruoho         if (Status == AE_ALREADY_EXISTS)
792149703c7Sjruoho         {
793149703c7Sjruoho             /* The name already exists in this scope */
794149703c7Sjruoho 
795149703c7Sjruoho             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
796149703c7Sjruoho             {
797149703c7Sjruoho                 /* Allow multiple references to the same scope */
798149703c7Sjruoho 
799149703c7Sjruoho                 Node->Type = (UINT8) ObjectType;
800149703c7Sjruoho                 Status = AE_OK;
801149703c7Sjruoho             }
802bd973ebcSchristos             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) ||
80394e0d463Schristos                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
80494e0d463Schristos             {
805107eddacSchristos                 Status = LdAnalyzeExternals (Node, Op, ObjectType, WalkState);
806bd973ebcSchristos                 if (ACPI_FAILURE (Status))
807bd973ebcSchristos                 {
808bd973ebcSchristos                     if (Status == AE_ERROR)
809bd973ebcSchristos                     {
81094e0d463Schristos                         /*
811bd973ebcSchristos                          * The use of AE_ERROR here indicates that there was a
812bd973ebcSchristos                          * compiler error emitted in LdAnalyzeExternals which
813bd973ebcSchristos                          * means that the caller should proceed to the next Op
814bd973ebcSchristos                          * for analysis of subsequent parse objects.
81594e0d463Schristos                          */
816149703c7Sjruoho                         Status = AE_OK;
817149703c7Sjruoho                     }
818bd973ebcSchristos                     return_ACPI_STATUS (Status);
819dc79220aSchristos                 }
820107eddacSchristos 
821107eddacSchristos                 if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
822107eddacSchristos                      (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
823107eddacSchristos                 {
824107eddacSchristos                     /*
825107eddacSchristos                      * If we get to here, it means that an actual definition of
826107eddacSchristos                      * the object declared external exists. Meaning that Op
827107eddacSchristos                      * loading this this Op should have no change to the ACPI
828107eddacSchristos                      * namespace. By going to FinishNode, we skip the
829107eddacSchristos                      * assignment of Node->Op = Op.
830107eddacSchristos                      */
831107eddacSchristos                     goto FinishNode;
832107eddacSchristos                 }
833dc79220aSchristos             }
834149703c7Sjruoho             else
835149703c7Sjruoho             {
836149703c7Sjruoho                 /* Valid error, object already exists */
837149703c7Sjruoho 
838bd973ebcSchristos                 ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
839bd973ebcSchristos 
840232afe62Schristos                 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
841bd973ebcSchristos                     ExternalPath, ASL_MSG_FOUND_HERE, Node->Op,
842bd973ebcSchristos                     ExternalPath);
843bd973ebcSchristos 
844bd973ebcSchristos                 if (ExternalPath)
845bd973ebcSchristos                 {
846bd973ebcSchristos                     ACPI_FREE (ExternalPath);
847bd973ebcSchristos                 }
848149703c7Sjruoho                 return_ACPI_STATUS (AE_OK);
849149703c7Sjruoho             }
850149703c7Sjruoho         }
851aaf4f1f0Schristos         else if (AE_NOT_FOUND)
852aaf4f1f0Schristos         {
853aaf4f1f0Schristos             /*
854aaf4f1f0Schristos              * One or more prefix NameSegs of the NamePath do not exist
855aaf4f1f0Schristos              * (all of them must exist). Attempt to continue compilation
856aaf4f1f0Schristos              * by setting the current scope to the root.
857aaf4f1f0Schristos              */
858aaf4f1f0Schristos             Node = AcpiGbl_RootNode;
859aaf4f1f0Schristos             Status = AE_OK;
860aaf4f1f0Schristos         }
861149703c7Sjruoho         else
862149703c7Sjruoho         {
863aaf4f1f0Schristos             /* Flag all other errors as coming from the ACPICA core */
864aaf4f1f0Schristos 
865149703c7Sjruoho             AslCoreSubsystemError (Op, Status,
866149703c7Sjruoho                 "Failure from namespace lookup", FALSE);
867149703c7Sjruoho             return_ACPI_STATUS (Status);
868149703c7Sjruoho         }
869149703c7Sjruoho     }
870149703c7Sjruoho 
871bd6fb9ddSchristos     /* Check special names like _WAK and _PTS */
872bd6fb9ddSchristos 
873bd6fb9ddSchristos     LdCheckSpecialNames (Node, Op);
874bd6fb9ddSchristos 
875149703c7Sjruoho     if (ForceNewScope)
876149703c7Sjruoho     {
877149703c7Sjruoho         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
878149703c7Sjruoho         if (ACPI_FAILURE (Status))
879149703c7Sjruoho         {
880149703c7Sjruoho             return_ACPI_STATUS (Status);
881149703c7Sjruoho         }
882149703c7Sjruoho     }
883149703c7Sjruoho 
884107eddacSchristos     /* Point the Node back to the original Parse node */
885107eddacSchristos 
886149703c7Sjruoho     Node->Op = Op;
887149703c7Sjruoho 
888107eddacSchristos FinishNode:
889107eddacSchristos 
890107eddacSchristos     /* Point the parse node to the new namespace node */
891107eddacSchristos 
892107eddacSchristos     Op->Asl.Node = Node;
893149703c7Sjruoho 
894149703c7Sjruoho     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
895149703c7Sjruoho     {
896149703c7Sjruoho         /*
897149703c7Sjruoho          * Get the method argument count from "Extra" and save
898149703c7Sjruoho          * it in the namespace node
899149703c7Sjruoho          */
900149703c7Sjruoho         Node->Value = (UINT32) Op->Asl.Extra;
901149703c7Sjruoho     }
902107eddacSchristos     else if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
903107eddacSchristos         Node->Type == ACPI_TYPE_METHOD &&
904107eddacSchristos         (Node->Flags & ANOBJ_IS_EXTERNAL))
905107eddacSchristos     {
906107eddacSchristos         Node->Value =
907107eddacSchristos             (UINT32) Op->Asl.Child->Asl.Next->Asl.Next->Asl.Value.Integer;
908107eddacSchristos     }
909149703c7Sjruoho 
910149703c7Sjruoho     return_ACPI_STATUS (Status);
911149703c7Sjruoho }
912149703c7Sjruoho 
913149703c7Sjruoho 
914149703c7Sjruoho /*******************************************************************************
915149703c7Sjruoho  *
916107eddacSchristos  * FUNCTION:    LdMatchExternType
917bd973ebcSchristos  *
918bd973ebcSchristos  * PARAMETERS:  Type1
919bd973ebcSchristos  *              Type2
920bd973ebcSchristos  *
921bd973ebcSchristos  * RETURN:      BOOLEAN
922bd973ebcSchristos  *
923bd973ebcSchristos  * DESCRIPTION: Match Type1 and Type2 with the assumption that one might be
924bd973ebcSchristos  *              using external types and another might be using local types.
925bd973ebcSchristos  *              This should be used to compare the types found in external
926bd973ebcSchristos  *              declarations with types found in other external declarations or
927bd973ebcSchristos  *              named object declaration. This should not be used to match two
928bd973ebcSchristos  *              object type declarations.
929bd973ebcSchristos  *
930bd973ebcSchristos  ******************************************************************************/
931bd973ebcSchristos 
932bd973ebcSchristos static BOOLEAN
LdMatchExternType(ACPI_OBJECT_TYPE Type1,ACPI_OBJECT_TYPE Type2)933107eddacSchristos LdMatchExternType (
934bd973ebcSchristos     ACPI_OBJECT_TYPE        Type1,
935bd973ebcSchristos     ACPI_OBJECT_TYPE        Type2)
936bd973ebcSchristos {
937bd973ebcSchristos     BOOLEAN                 Type1IsLocal = Type1 > ACPI_TYPE_EXTERNAL_MAX;
938bd973ebcSchristos     BOOLEAN                 Type2IsLocal = Type2 > ACPI_TYPE_EXTERNAL_MAX;
939bd973ebcSchristos     ACPI_OBJECT_TYPE        ExternalType;
940bd973ebcSchristos     ACPI_OBJECT_TYPE        LocalType;
941bd973ebcSchristos 
942bd973ebcSchristos 
943bd973ebcSchristos     /*
944bd973ebcSchristos      * The inputs could represent types that are local to ACPICA or types that
945bd973ebcSchristos      * are known externally. Some local types, such as the OperationRegion
946bd973ebcSchristos      * field units, are defined with more granularity than ACPICA local types.
947bd973ebcSchristos      *
948bd973ebcSchristos      * Therefore, map the local types to the external types before matching.
949bd973ebcSchristos      */
950bd973ebcSchristos     if (Type1IsLocal && !Type2IsLocal)
951bd973ebcSchristos     {
952bd973ebcSchristos         LocalType = Type1;
953bd973ebcSchristos         ExternalType = Type2;
954bd973ebcSchristos     }
955bd973ebcSchristos     else if (!Type1IsLocal && Type2IsLocal)
956bd973ebcSchristos     {
957bd973ebcSchristos         LocalType = Type2;
958bd973ebcSchristos         ExternalType = Type1;
959bd973ebcSchristos     }
960bd973ebcSchristos     else
961bd973ebcSchristos     {
962bd973ebcSchristos         return (Type1 == Type2);
963bd973ebcSchristos     }
964bd973ebcSchristos 
965bd973ebcSchristos     switch (LocalType)
966bd973ebcSchristos     {
967bd973ebcSchristos         case ACPI_TYPE_LOCAL_REGION_FIELD:
968bd973ebcSchristos         case ACPI_TYPE_LOCAL_BANK_FIELD:
969bd973ebcSchristos         case ACPI_TYPE_LOCAL_INDEX_FIELD:
970bd973ebcSchristos 
971bd973ebcSchristos             LocalType = ACPI_TYPE_FIELD_UNIT;
972bd973ebcSchristos             break;
973bd973ebcSchristos 
974bd973ebcSchristos         default:
975bd973ebcSchristos             break;
976bd973ebcSchristos     }
977bd973ebcSchristos 
978bd973ebcSchristos     return (LocalType == ExternalType);
979bd973ebcSchristos }
980bd973ebcSchristos 
981bd973ebcSchristos 
982bd973ebcSchristos /*******************************************************************************
983bd973ebcSchristos  *
984bd973ebcSchristos  * FUNCTION:    LdAnalyzeExternals
985bd973ebcSchristos  *
986bd973ebcSchristos  * PARAMETERS:  Node            - Node that represents the named object
987bd973ebcSchristos  *              Op              - Named object declaring this named object
988bd973ebcSchristos  *              ExternalOpType  - Type of ExternalOp
989bd973ebcSchristos  *              WalkState       - Current WalkState
990bd973ebcSchristos  *
991bd973ebcSchristos  * RETURN:      Status
992bd973ebcSchristos  *
993bd973ebcSchristos  * DESCRIPTION: Node and Op represents an identically named object declaration
994bd973ebcSchristos  *              that is either declared by the ASL external keyword or declared
995bd973ebcSchristos  *              by operators that declare named objects (i.e. Name, Device,
996bd973ebcSchristos  *              OperationRegion, and etc.). This function ensures that the
997bd973ebcSchristos  *              declarations do not contradict each other.
998bd973ebcSchristos  *
999bd973ebcSchristos  ******************************************************************************/
1000bd973ebcSchristos 
1001bd973ebcSchristos static ACPI_STATUS
LdAnalyzeExternals(ACPI_NAMESPACE_NODE * Node,ACPI_PARSE_OBJECT * Op,ACPI_OBJECT_TYPE ExternalOpType,ACPI_WALK_STATE * WalkState)1002bd973ebcSchristos LdAnalyzeExternals (
1003bd973ebcSchristos     ACPI_NAMESPACE_NODE     *Node,
1004bd973ebcSchristos     ACPI_PARSE_OBJECT       *Op,
1005bd973ebcSchristos     ACPI_OBJECT_TYPE        ExternalOpType,
1006bd973ebcSchristos     ACPI_WALK_STATE         *WalkState)
1007bd973ebcSchristos {
1008bd973ebcSchristos     ACPI_STATUS             Status = AE_OK;
1009bd973ebcSchristos     ACPI_OBJECT_TYPE        ActualExternalOpType;
1010bd973ebcSchristos     ACPI_OBJECT_TYPE        ActualOpType;
1011bd973ebcSchristos     ACPI_PARSE_OBJECT       *ExternalOp;
1012bd973ebcSchristos     ACPI_PARSE_OBJECT       *ActualOp;
1013bd973ebcSchristos 
1014bd973ebcSchristos 
1015bd973ebcSchristos     /*
1016bd973ebcSchristos      * The declaration represented by Node and Op must have the same type.
1017bd973ebcSchristos      * The type of the external Op is represented by ExternalOpType. However,
1018bd973ebcSchristos      * the type of the pre-existing declaration depends on whether if Op
1019bd973ebcSchristos      * is an external declaration or an actual declaration.
1020bd973ebcSchristos      */
1021bd973ebcSchristos     if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1022bd973ebcSchristos     {
1023bd973ebcSchristos         ActualExternalOpType = ExternalOpType;
1024bd973ebcSchristos         ActualOpType = Node->Type;
1025bd973ebcSchristos     }
1026bd973ebcSchristos     else
1027bd973ebcSchristos     {
1028bd973ebcSchristos         ActualExternalOpType = Node->Type;
1029107eddacSchristos         ActualOpType = ExternalOpType;
1030bd973ebcSchristos     }
1031bd973ebcSchristos 
1032bd973ebcSchristos     if ((ActualOpType != ACPI_TYPE_ANY) &&
1033bd973ebcSchristos         (ActualExternalOpType != ACPI_TYPE_ANY) &&
1034107eddacSchristos         !LdMatchExternType (ActualExternalOpType, ActualOpType))
1035bd973ebcSchristos     {
1036bd973ebcSchristos         if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1037bd973ebcSchristos             Node->Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1038bd973ebcSchristos         {
1039bd973ebcSchristos             AslDualParseOpError (ASL_WARNING,
1040bd973ebcSchristos                 ASL_MSG_DUPLICATE_EXTERN_MISMATCH, Op, NULL,
1041bd973ebcSchristos                 ASL_MSG_DUPLICATE_EXTERN_FOUND_HERE, Node->Op, NULL);
1042bd973ebcSchristos         }
1043bd973ebcSchristos         else
1044bd973ebcSchristos         {
1045bd973ebcSchristos             if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL &&
1046bd973ebcSchristos                 Node->Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1047bd973ebcSchristos             {
1048bd973ebcSchristos                 ExternalOp = Op;
1049bd973ebcSchristos                 ActualOp = Node->Op;
1050bd973ebcSchristos             }
1051bd973ebcSchristos             else
1052bd973ebcSchristos             {
1053bd973ebcSchristos                 ExternalOp = Node->Op;
1054bd973ebcSchristos                 ActualOp = Op;
1055bd973ebcSchristos             }
1056bd973ebcSchristos             AslDualParseOpError (ASL_WARNING,
1057bd973ebcSchristos                 ASL_MSG_DECLARATION_TYPE_MISMATCH, ExternalOp, NULL,
1058bd973ebcSchristos                 ASL_MSG_TYPE_MISMATCH_FOUND_HERE, ActualOp, NULL);
1059bd973ebcSchristos         }
1060bd973ebcSchristos     }
1061bd973ebcSchristos 
1062107eddacSchristos     /* Set the object type of the external */
1063107eddacSchristos 
1064bd973ebcSchristos     if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1065bd973ebcSchristos         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
1066bd973ebcSchristos     {
1067bd973ebcSchristos         /*
1068bd973ebcSchristos          * Allow one create on an object or segment that was
1069bd973ebcSchristos          * previously declared External
1070bd973ebcSchristos          */
1071bd973ebcSchristos         Node->Flags &= ~ANOBJ_IS_EXTERNAL;
1072cf9af4faSchristos         Node->Type = (UINT8) ActualOpType;
1073bd973ebcSchristos 
1074bd973ebcSchristos         /* Just retyped a node, probably will need to open a scope */
1075bd973ebcSchristos 
1076cf9af4faSchristos         if (AcpiNsOpensScope (ActualOpType))
1077bd973ebcSchristos         {
1078cf9af4faSchristos             Status = AcpiDsScopeStackPush (Node, ActualOpType, WalkState);
1079bd973ebcSchristos             if (ACPI_FAILURE (Status))
1080bd973ebcSchristos             {
1081bd973ebcSchristos                 return (Status);
1082bd973ebcSchristos             }
1083bd973ebcSchristos         }
1084bd973ebcSchristos 
1085bd973ebcSchristos         Status = AE_OK;
1086bd973ebcSchristos     }
1087bd973ebcSchristos     else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
1088bd973ebcSchristos              (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1089bd973ebcSchristos     {
1090bd973ebcSchristos         /*
1091bd973ebcSchristos          * Allow externals in same scope as the definition of the
1092bd973ebcSchristos          * actual object. Similar to C. Allows multiple definition
1093bd973ebcSchristos          * blocks that refer to each other in the same file.
1094bd973ebcSchristos          */
1095bd973ebcSchristos         Status = AE_OK;
1096bd973ebcSchristos     }
1097bd973ebcSchristos     else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
1098bd973ebcSchristos              (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
1099cf9af4faSchristos              (ActualOpType == ACPI_TYPE_ANY))
1100bd973ebcSchristos     {
1101bd973ebcSchristos         /* Allow update of externals of unknown type. */
1102bd973ebcSchristos 
1103cf9af4faSchristos         Node->Type = (UINT8) ActualExternalOpType;
1104bd973ebcSchristos         Status = AE_OK;
1105bd973ebcSchristos     }
1106bd973ebcSchristos 
1107bd973ebcSchristos     return (Status);
1108bd973ebcSchristos }
1109bd973ebcSchristos 
1110bd973ebcSchristos 
1111bd973ebcSchristos /*******************************************************************************
1112bd973ebcSchristos  *
1113bd6fb9ddSchristos  * FUNCTION:    LdCheckSpecialNames
1114bd6fb9ddSchristos  *
1115bd6fb9ddSchristos  * PARAMETERS:  Node        - Node that represents the named object
1116bd6fb9ddSchristos  *              Op          - Named object declaring this named object
1117bd6fb9ddSchristos  *
1118bd6fb9ddSchristos  * RETURN:      None
1119bd6fb9ddSchristos  *
1120bd6fb9ddSchristos  * DESCRIPTION: Check if certain named objects are declared in the incorrect
1121bd6fb9ddSchristos  *              scope. Special named objects are listed in
1122bd6fb9ddSchristos  *              AslGbl_SpecialNamedObjects and can only be declared at the root
1123bd6fb9ddSchristos  *              scope. _UID inside of a processor declaration must not be a
1124bd6fb9ddSchristos  *              string.
1125bd6fb9ddSchristos  *
1126bd6fb9ddSchristos  ******************************************************************************/
1127bd6fb9ddSchristos 
1128bd6fb9ddSchristos static void
LdCheckSpecialNames(ACPI_NAMESPACE_NODE * Node,ACPI_PARSE_OBJECT * Op)1129bd6fb9ddSchristos LdCheckSpecialNames (
1130bd6fb9ddSchristos     ACPI_NAMESPACE_NODE     *Node,
1131bd6fb9ddSchristos     ACPI_PARSE_OBJECT       *Op)
1132bd6fb9ddSchristos {
1133bd6fb9ddSchristos     UINT32                  i;
1134bd6fb9ddSchristos 
1135bd6fb9ddSchristos 
1136bd6fb9ddSchristos     for (i = 0; i < MAX_SPECIAL_NAMES; i++)
1137bd6fb9ddSchristos     {
1138bd6fb9ddSchristos         if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
1139bd6fb9ddSchristos             Node->Parent != AcpiGbl_RootNode)
1140bd6fb9ddSchristos         {
1141bd6fb9ddSchristos             AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
1142bd6fb9ddSchristos             return;
1143bd6fb9ddSchristos         }
1144bd6fb9ddSchristos     }
1145bd6fb9ddSchristos 
1146bd6fb9ddSchristos     if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1147bd6fb9ddSchristos         Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1148bd6fb9ddSchristos         Node->Type == ACPI_TYPE_STRING)
1149bd6fb9ddSchristos     {
1150bd6fb9ddSchristos         AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1151bd6fb9ddSchristos     }
1152bd6fb9ddSchristos }
1153bd6fb9ddSchristos 
1154bd6fb9ddSchristos 
1155bd6fb9ddSchristos /*******************************************************************************
1156bd6fb9ddSchristos  *
1157149703c7Sjruoho  * FUNCTION:    LdNamespace2Begin
1158149703c7Sjruoho  *
1159149703c7Sjruoho  * PARAMETERS:  ASL_WALK_CALLBACK
1160149703c7Sjruoho  *
1161149703c7Sjruoho  * RETURN:      Status
1162149703c7Sjruoho  *
1163149703c7Sjruoho  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1164149703c7Sjruoho  *              Second pass resolves some forward references.
1165149703c7Sjruoho  *
1166149703c7Sjruoho  * Notes:
1167149703c7Sjruoho  * Currently only needs to handle the Alias operator.
1168149703c7Sjruoho  * Could be used to allow forward references from the Scope() operator, but
1169149703c7Sjruoho  * the MS interpreter does not allow this, so this compiler does not either.
1170149703c7Sjruoho  *
1171149703c7Sjruoho  ******************************************************************************/
1172149703c7Sjruoho 
1173149703c7Sjruoho static ACPI_STATUS
LdNamespace2Begin(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)1174149703c7Sjruoho LdNamespace2Begin (
1175149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
1176149703c7Sjruoho     UINT32                  Level,
1177149703c7Sjruoho     void                    *Context)
1178149703c7Sjruoho {
1179149703c7Sjruoho     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1180149703c7Sjruoho     ACPI_STATUS             Status;
1181149703c7Sjruoho     ACPI_NAMESPACE_NODE     *Node;
1182149703c7Sjruoho     ACPI_OBJECT_TYPE        ObjectType;
1183149703c7Sjruoho     BOOLEAN                 ForceNewScope = FALSE;
1184149703c7Sjruoho     ACPI_PARSE_OBJECT       *Arg;
1185149703c7Sjruoho     char                    *Path;
1186149703c7Sjruoho     ACPI_NAMESPACE_NODE     *TargetNode;
1187149703c7Sjruoho 
1188149703c7Sjruoho 
1189149703c7Sjruoho     ACPI_FUNCTION_NAME (LdNamespace2Begin);
1190149703c7Sjruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1191149703c7Sjruoho         Op, Op->Asl.ParseOpName));
1192149703c7Sjruoho 
1193149703c7Sjruoho 
1194149703c7Sjruoho     /* Ignore Ops with no namespace node */
1195149703c7Sjruoho 
1196149703c7Sjruoho     Node = Op->Asl.Node;
1197149703c7Sjruoho     if (!Node)
1198149703c7Sjruoho     {
1199149703c7Sjruoho         return (AE_OK);
1200149703c7Sjruoho     }
1201149703c7Sjruoho 
1202149703c7Sjruoho     /* Get the type to determine if we should push the scope */
1203149703c7Sjruoho 
1204149703c7Sjruoho     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
120535a687ffSchristos         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1206149703c7Sjruoho     {
1207149703c7Sjruoho         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1208149703c7Sjruoho     }
1209149703c7Sjruoho     else
1210149703c7Sjruoho     {
1211149703c7Sjruoho         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1212149703c7Sjruoho     }
1213149703c7Sjruoho 
1214149703c7Sjruoho     /* Push scope for Resource Templates */
1215149703c7Sjruoho 
1216149703c7Sjruoho     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1217149703c7Sjruoho     {
121835a687ffSchristos         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1219149703c7Sjruoho         {
1220149703c7Sjruoho             ForceNewScope = TRUE;
1221149703c7Sjruoho         }
1222149703c7Sjruoho     }
1223149703c7Sjruoho 
1224149703c7Sjruoho     /* Push the scope stack */
1225149703c7Sjruoho 
1226149703c7Sjruoho     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1227149703c7Sjruoho     {
1228149703c7Sjruoho         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1229149703c7Sjruoho         if (ACPI_FAILURE (Status))
1230149703c7Sjruoho         {
1231149703c7Sjruoho             return_ACPI_STATUS (Status);
1232149703c7Sjruoho         }
1233149703c7Sjruoho     }
1234149703c7Sjruoho 
1235149703c7Sjruoho     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1236149703c7Sjruoho     {
1237aaf4f1f0Schristos         /*
1238aaf4f1f0Schristos          * Complete the alias node by getting and saving the target node.
1239aaf4f1f0Schristos          * First child is the alias target
1240aaf4f1f0Schristos          */
1241149703c7Sjruoho         Arg = Op->Asl.Child;
1242149703c7Sjruoho 
1243149703c7Sjruoho         /* Get the target pathname */
1244149703c7Sjruoho 
1245149703c7Sjruoho         Path = Arg->Asl.Namepath;
1246149703c7Sjruoho         if (!Path)
1247149703c7Sjruoho         {
1248149703c7Sjruoho             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1249149703c7Sjruoho             if (ACPI_FAILURE (Status))
1250149703c7Sjruoho             {
1251149703c7Sjruoho                 return (Status);
1252149703c7Sjruoho             }
1253149703c7Sjruoho         }
1254149703c7Sjruoho 
1255149703c7Sjruoho         /* Get the NS node associated with the target. It must exist. */
1256149703c7Sjruoho 
1257149703c7Sjruoho         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1258149703c7Sjruoho             ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1259149703c7Sjruoho             WalkState, &TargetNode);
1260149703c7Sjruoho         if (ACPI_FAILURE (Status))
1261149703c7Sjruoho         {
1262149703c7Sjruoho             if (Status == AE_NOT_FOUND)
1263149703c7Sjruoho             {
1264aaf4f1f0Schristos                 /* Standalone NameSeg vs. NamePath */
1265149703c7Sjruoho 
1266f5a85da7Schristos                 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
1267aaf4f1f0Schristos                 {
1268aaf4f1f0Schristos                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1269aaf4f1f0Schristos                         Arg->Asl.ExternalName);
1270aaf4f1f0Schristos                 }
1271aaf4f1f0Schristos                 else
1272aaf4f1f0Schristos                 {
1273aaf4f1f0Schristos                     AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
1274aaf4f1f0Schristos                         Arg->Asl.ExternalName);
1275aaf4f1f0Schristos                 }
1276aaf4f1f0Schristos 
1277aaf4f1f0Schristos #if 0
1278aaf4f1f0Schristos /*
1279aaf4f1f0Schristos  * NOTE: Removed 10/2018 to enhance compiler error reporting. No
1280aaf4f1f0Schristos  * regressions seen.
1281aaf4f1f0Schristos  */
1282149703c7Sjruoho                 /*
1283149703c7Sjruoho                  * The name was not found, go ahead and create it.
1284149703c7Sjruoho                  * This prevents more errors later.
1285149703c7Sjruoho                  */
1286149703c7Sjruoho                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1287aaf4f1f0Schristos                     ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
1288aaf4f1f0Schristos                     ACPI_NS_NO_UPSEARCH, WalkState, &Node);
1289aaf4f1f0Schristos #endif
1290aaf4f1f0Schristos                 return (Status);
1291aaf4f1f0Schristos /* Removed: return (AE_OK)*/
1292149703c7Sjruoho             }
1293149703c7Sjruoho 
1294149703c7Sjruoho             AslCoreSubsystemError (Op, Status,
1295149703c7Sjruoho                 "Failure from namespace lookup", FALSE);
1296149703c7Sjruoho             return (AE_OK);
1297149703c7Sjruoho         }
1298149703c7Sjruoho 
12998517b6f4Schristos         /* Save the target node within the alias node as well as type information */
1300149703c7Sjruoho 
1301149703c7Sjruoho         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
13028517b6f4Schristos         Node->Type = TargetNode->Type;
13038517b6f4Schristos         if (Node->Type == ACPI_TYPE_METHOD)
13048517b6f4Schristos         {
13058517b6f4Schristos             /* Save the parameter count for methods */
13068517b6f4Schristos 
13078517b6f4Schristos             Node->Value = TargetNode->Value;
13088517b6f4Schristos         }
1309149703c7Sjruoho     }
1310149703c7Sjruoho 
1311149703c7Sjruoho     return (AE_OK);
1312149703c7Sjruoho }
1313149703c7Sjruoho 
1314149703c7Sjruoho 
1315149703c7Sjruoho /*******************************************************************************
1316149703c7Sjruoho  *
1317149703c7Sjruoho  * FUNCTION:    LdCommonNamespaceEnd
1318149703c7Sjruoho  *
1319149703c7Sjruoho  * PARAMETERS:  ASL_WALK_CALLBACK
1320149703c7Sjruoho  *
1321149703c7Sjruoho  * RETURN:      Status
1322149703c7Sjruoho  *
1323149703c7Sjruoho  * DESCRIPTION: Ascending callback used during the loading of the namespace,
1324149703c7Sjruoho  *              We only need to worry about managing the scope stack here.
1325149703c7Sjruoho  *
1326149703c7Sjruoho  ******************************************************************************/
1327149703c7Sjruoho 
1328149703c7Sjruoho static ACPI_STATUS
LdCommonNamespaceEnd(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)1329149703c7Sjruoho LdCommonNamespaceEnd (
1330149703c7Sjruoho     ACPI_PARSE_OBJECT       *Op,
1331149703c7Sjruoho     UINT32                  Level,
1332149703c7Sjruoho     void                    *Context)
1333149703c7Sjruoho {
1334149703c7Sjruoho     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1335149703c7Sjruoho     ACPI_OBJECT_TYPE        ObjectType;
1336149703c7Sjruoho     BOOLEAN                 ForceNewScope = FALSE;
1337149703c7Sjruoho 
1338149703c7Sjruoho 
1339149703c7Sjruoho     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1340149703c7Sjruoho 
1341149703c7Sjruoho 
1342149703c7Sjruoho     /* We are only interested in opcodes that have an associated name */
1343149703c7Sjruoho 
1344149703c7Sjruoho     if (!Op->Asl.Namepath)
1345149703c7Sjruoho     {
1346149703c7Sjruoho         return (AE_OK);
1347149703c7Sjruoho     }
1348149703c7Sjruoho 
1349149703c7Sjruoho     /* Get the type to determine if we should pop the scope */
1350149703c7Sjruoho 
1351149703c7Sjruoho     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
135235a687ffSchristos         (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1353149703c7Sjruoho     {
1354149703c7Sjruoho         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1355149703c7Sjruoho 
1356149703c7Sjruoho         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1357149703c7Sjruoho     }
1358149703c7Sjruoho     else
1359149703c7Sjruoho     {
1360149703c7Sjruoho         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1361149703c7Sjruoho     }
1362149703c7Sjruoho 
1363149703c7Sjruoho     /* Pop scope that was pushed for Resource Templates */
1364149703c7Sjruoho 
1365149703c7Sjruoho     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1366149703c7Sjruoho     {
136735a687ffSchristos         if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1368149703c7Sjruoho         {
1369149703c7Sjruoho             ForceNewScope = TRUE;
1370149703c7Sjruoho         }
1371149703c7Sjruoho     }
1372149703c7Sjruoho 
1373149703c7Sjruoho     /* Pop the scope stack */
1374149703c7Sjruoho 
1375149703c7Sjruoho     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1376149703c7Sjruoho     {
1377149703c7Sjruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1378149703c7Sjruoho             "(%s): Popping scope for Op [%s] %p\n",
1379149703c7Sjruoho             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1380149703c7Sjruoho 
1381149703c7Sjruoho         (void) AcpiDsScopeStackPop (WalkState);
1382149703c7Sjruoho     }
1383149703c7Sjruoho 
1384149703c7Sjruoho     return (AE_OK);
1385149703c7Sjruoho }
1386