aslload.c revision 128212
1118611Snjl/******************************************************************************
2118611Snjl *
3118611Snjl * Module Name: dswload - Dispatcher namespace load callbacks
4128212Snjl *              $Revision: 62 $
5118611Snjl *
6118611Snjl *****************************************************************************/
7118611Snjl
8118611Snjl/******************************************************************************
9118611Snjl *
10118611Snjl * 1. Copyright Notice
11118611Snjl *
12126372Snjl * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13118611Snjl * All rights reserved.
14118611Snjl *
15118611Snjl * 2. License
16118611Snjl *
17118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property
18118611Snjl * rights.  You may have additional license terms from the party that provided
19118611Snjl * you this software, covering your right to use that party's intellectual
20118611Snjl * property rights.
21118611Snjl *
22118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23118611Snjl * copy of the source code appearing in this file ("Covered Code") an
24118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy,
26118611Snjl * make derivatives, distribute, use and display any portion of the Covered
27118611Snjl * Code in any form, with the right to sublicense such rights; and
28118611Snjl *
29118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30118611Snjl * license (with the right to sublicense), under only those claims of Intel
31118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell,
32118611Snjl * offer to sell, and import the Covered Code and derivative works thereof
33118611Snjl * solely to the minimum extent necessary to exercise the above copyright
34118611Snjl * license, and in no event shall the patent license extend to any additions
35118611Snjl * to or modifications of the Original Intel Code.  No other license or right
36118611Snjl * is granted directly or by implication, estoppel or otherwise;
37118611Snjl *
38118611Snjl * The above copyright and patent license is granted only if the following
39118611Snjl * conditions are met:
40118611Snjl *
41118611Snjl * 3. Conditions
42118611Snjl *
43118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44118611Snjl * Redistribution of source code of any substantial portion of the Covered
45118611Snjl * Code or modification with rights to further distribute source must include
46118611Snjl * the above Copyright Notice, the above License, this list of Conditions,
47118611Snjl * and the following Disclaimer and Export Compliance provision.  In addition,
48118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to
49118611Snjl * contain a file documenting the changes Licensee made to create that Covered
50118611Snjl * Code and the date of any change.  Licensee must include in that file the
51118611Snjl * documentation of any changes made by any predecessor Licensee.  Licensee
52118611Snjl * must include a prominent statement that the modification is derived,
53118611Snjl * directly or indirectly, from Original Intel Code.
54118611Snjl *
55118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56118611Snjl * Redistribution of source code of any substantial portion of the Covered
57118611Snjl * Code or modification without rights to further distribute source must
58118611Snjl * include the following Disclaimer and Export Compliance provision in the
59118611Snjl * documentation and/or other materials provided with distribution.  In
60118611Snjl * addition, Licensee may not authorize further sublicense of source of any
61118611Snjl * portion of the Covered Code, and must include terms to the effect that the
62118611Snjl * license from Licensee to its licensee is limited to the intellectual
63118611Snjl * property embodied in the software Licensee provides to its licensee, and
64118611Snjl * not to intellectual property embodied in modifications its licensee may
65118611Snjl * make.
66118611Snjl *
67118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any
68118611Snjl * substantial portion of the Covered Code or modification must reproduce the
69118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance
70118611Snjl * provision in the documentation and/or other materials provided with the
71118611Snjl * distribution.
72118611Snjl *
73118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original
74118611Snjl * Intel Code.
75118611Snjl *
76118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or
78118611Snjl * other dealings in products derived from or relating to the Covered Code
79118611Snjl * without prior written authorization from Intel.
80118611Snjl *
81118611Snjl * 4. Disclaimer and Export Compliance
82118611Snjl *
83118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84118611Snjl * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89118611Snjl * PARTICULAR PURPOSE.
90118611Snjl *
91118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98118611Snjl * LIMITED REMEDY.
99118611Snjl *
100118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this
101118611Snjl * software or system incorporating such software without first obtaining any
102118611Snjl * required license or other approval from the U. S. Department of Commerce or
103118611Snjl * any other agency or department of the United States Government.  In the
104118611Snjl * event Licensee exports any such software from the United States or
105118611Snjl * re-exports any such software from a foreign destination, Licensee shall
106118611Snjl * ensure that the distribution and export/re-export of the software is in
107118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the
108118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109118611Snjl * any of its subsidiaries will export/re-export any technical data, process,
110118611Snjl * software, or service, directly or indirectly, to any country for which the
111118611Snjl * United States government or any agency thereof requires an export license,
112118611Snjl * other governmental approval, or letter of assurance, without first obtaining
113118611Snjl * such license, approval or letter.
114118611Snjl *
115118611Snjl *****************************************************************************/
116118611Snjl
117118611Snjl#define __ASLLOAD_C__
118118611Snjl
119118611Snjl#include "aslcompiler.h"
120118611Snjl#include "amlcode.h"
121118611Snjl#include "acdispat.h"
122118611Snjl#include "acnamesp.h"
123118611Snjl
124118611Snjl#include "aslcompiler.y.h"
125118611Snjl
126118611Snjl#define _COMPONENT          ACPI_COMPILER
127118611Snjl        ACPI_MODULE_NAME    ("aslload")
128118611Snjl
129118611Snjl
130118611Snjl/*******************************************************************************
131118611Snjl *
132118611Snjl * FUNCTION:    LdLoadNamespace
133118611Snjl *
134118611Snjl * PARAMETERS:  None
135118611Snjl *
136118611Snjl * RETURN:      Status
137118611Snjl *
138118611Snjl * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
139118611Snjl *              named ASL/AML objects into the namespace.  The namespace is
140118611Snjl *              constructed in order to resolve named references and references
141118611Snjl *              to named fields within resource templates/descriptors.
142118611Snjl *
143118611Snjl ******************************************************************************/
144118611Snjl
145118611SnjlACPI_STATUS
146118611SnjlLdLoadNamespace (
147118611Snjl    ACPI_PARSE_OBJECT       *RootOp)
148118611Snjl{
149118611Snjl    ACPI_WALK_STATE         *WalkState;
150118611Snjl
151118611Snjl
152118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n");
153118611Snjl
154118611Snjl    /* Create a new walk state */
155118611Snjl
156118611Snjl    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
157118611Snjl    if (!WalkState)
158118611Snjl    {
159118611Snjl        return AE_NO_MEMORY;
160118611Snjl    }
161118611Snjl
162118611Snjl    /* Perform the walk of the parse tree */
163118611Snjl
164118611Snjl    TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
165118611Snjl                        LdNamespace1End, WalkState);
166118611Snjl
167118611Snjl    /* Dump the namespace if debug is enabled */
168118611Snjl
169118611Snjl    AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
170118611Snjl    return AE_OK;
171118611Snjl}
172118611Snjl
173118611Snjl
174118611Snjl/*******************************************************************************
175118611Snjl *
176118611Snjl * FUNCTION:    LdLoadFieldElements
177118611Snjl *
178118611Snjl * PARAMETERS:  Op          - Parent node (Field)
179118611Snjl *              WalkState       - Current walk state
180118611Snjl *
181118611Snjl * RETURN:      Status
182118611Snjl *
183118611Snjl * DESCRIPTION: Enter the named elements of the field (children of the parent)
184118611Snjl *              into the namespace.
185118611Snjl *
186118611Snjl ******************************************************************************/
187118611Snjl
188118611SnjlACPI_STATUS
189118611SnjlLdLoadFieldElements (
190118611Snjl    ACPI_PARSE_OBJECT       *Op,
191118611Snjl    ACPI_WALK_STATE         *WalkState)
192118611Snjl{
193118611Snjl    ACPI_PARSE_OBJECT       *Child = NULL;
194118611Snjl    ACPI_NAMESPACE_NODE     *Node;
195118611Snjl    ACPI_STATUS             Status;
196118611Snjl
197118611Snjl
198118611Snjl    /* Get the first named field element */
199118611Snjl
200118611Snjl    switch (Op->Asl.AmlOpcode)
201118611Snjl    {
202118611Snjl    case AML_BANK_FIELD_OP:
203118611Snjl
204118611Snjl        Child = UtGetArg (Op, 6);
205118611Snjl        break;
206118611Snjl
207118611Snjl    case AML_INDEX_FIELD_OP:
208118611Snjl
209118611Snjl        Child = UtGetArg (Op, 5);
210118611Snjl        break;
211118611Snjl
212118611Snjl    case AML_FIELD_OP:
213118611Snjl
214118611Snjl        Child = UtGetArg (Op, 4);
215118611Snjl        break;
216118611Snjl
217118611Snjl    default:
218118611Snjl        /* No other opcodes should arrive here */
219118611Snjl        return (AE_BAD_PARAMETER);
220118611Snjl    }
221118611Snjl
222118611Snjl    /* Enter all elements into the namespace */
223118611Snjl
224118611Snjl    while (Child)
225118611Snjl    {
226118611Snjl        switch (Child->Asl.AmlOpcode)
227118611Snjl        {
228118611Snjl        case AML_INT_RESERVEDFIELD_OP:
229118611Snjl        case AML_INT_ACCESSFIELD_OP:
230118611Snjl
231118611Snjl            break;
232118611Snjl
233118611Snjl        default:
234118611Snjl
235118611Snjl            Status = AcpiNsLookup (WalkState->ScopeInfo, Child->Asl.Value.String,
236118611Snjl                            ACPI_TYPE_LOCAL_REGION_FIELD, ACPI_IMODE_LOAD_PASS1,
237118611Snjl                            ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
238118611Snjl                            NULL, &Node);
239118611Snjl            if (ACPI_FAILURE (Status))
240118611Snjl            {
241118611Snjl                if (Status != AE_ALREADY_EXISTS)
242118611Snjl                {
243118611Snjl                     return (Status);
244118611Snjl                }
245118611Snjl
246118611Snjl                /*
247118611Snjl                 * The name already exists in this scope
248118611Snjl                 * But continue processing the elements
249118611Snjl                 */
250118611Snjl                AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child, Child->Asl.Value.String);
251118611Snjl            }
252118611Snjl            else
253118611Snjl            {
254118611Snjl                Child->Asl.Node = Node;
255118611Snjl                Node->Object = (ACPI_OPERAND_OBJECT *) Child;
256118611Snjl            }
257118611Snjl            break;
258118611Snjl        }
259118611Snjl        Child = Child->Asl.Next;
260118611Snjl    }
261118611Snjl    return (AE_OK);
262118611Snjl}
263118611Snjl
264118611Snjl
265118611Snjl/*******************************************************************************
266118611Snjl *
267118611Snjl * FUNCTION:    LdLoadResourceElements
268118611Snjl *
269118611Snjl * PARAMETERS:  Op          - Parent node (Resource Descriptor)
270118611Snjl *              WalkState       - Current walk state
271118611Snjl *
272118611Snjl * RETURN:      Status
273118611Snjl *
274118611Snjl * DESCRIPTION: Enter the named elements of the resource descriptor (children
275118611Snjl *              of the parent) into the namespace.
276118611Snjl *
277118611Snjl * NOTE: In the real AML namespace, these named elements never exist.  But
278118611Snjl *       we simply use the namespace here as a symbol table so we can look
279118611Snjl *       them up as they are referenced.
280118611Snjl *
281118611Snjl ******************************************************************************/
282118611Snjl
283118611SnjlACPI_STATUS
284118611SnjlLdLoadResourceElements (
285118611Snjl    ACPI_PARSE_OBJECT       *Op,
286118611Snjl    ACPI_WALK_STATE         *WalkState)
287118611Snjl{
288118611Snjl    ACPI_PARSE_OBJECT       *InitializerOp = NULL;
289118611Snjl    ACPI_NAMESPACE_NODE     *Node;
290118611Snjl    ACPI_STATUS             Status;
291118611Snjl
292118611Snjl
293118611Snjl    /*
294118611Snjl     * Enter the resouce name into the namespace
295118611Snjl     * This opens a scope
296118611Snjl     */
297118611Snjl    Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
298118611Snjl                    ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH,
299118611Snjl                    WalkState, &Node);
300118611Snjl    if (ACPI_FAILURE (Status))
301118611Snjl    {
302118611Snjl        return (Status);
303118611Snjl    }
304118611Snjl
305118611Snjl    /*
306118611Snjl     * Now enter the predefined fields, for easy lookup when referenced
307118611Snjl     * by the source ASL
308118611Snjl     */
309118611Snjl    InitializerOp = ASL_GET_CHILD_NODE (Op);
310118611Snjl    while (InitializerOp)
311118611Snjl    {
312118611Snjl
313118611Snjl        if (InitializerOp->Asl.ExternalName)
314118611Snjl        {
315118611Snjl            Status = AcpiNsLookup (WalkState->ScopeInfo,
316118611Snjl                            InitializerOp->Asl.ExternalName,
317118611Snjl                            ACPI_TYPE_LOCAL_RESOURCE_FIELD,
318118611Snjl                            ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
319118611Snjl                            NULL, &Node);
320118611Snjl            if (ACPI_FAILURE (Status))
321118611Snjl            {
322118611Snjl                return (Status);
323118611Snjl            }
324118611Snjl
325118611Snjl            /*
326118611Snjl             * Store the field offset in the namespace node so it
327118611Snjl             * can be used when the field is referenced
328118611Snjl             */
329118611Snjl            Node->OwnerId = (UINT16) InitializerOp->Asl.Value.Integer;
330118611Snjl            InitializerOp->Asl.Node = Node;
331118611Snjl            Node->Object = (ACPI_OPERAND_OBJECT *) InitializerOp;
332118611Snjl
333118611Snjl            /* Pass thru the field type (Bitfield or Bytefield) */
334118611Snjl
335118611Snjl            if (InitializerOp->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
336118611Snjl            {
337118611Snjl                Node->Flags |= ANOBJ_IS_BIT_OFFSET;
338118611Snjl            }
339118611Snjl        }
340118611Snjl        InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
341118611Snjl    }
342118611Snjl
343118611Snjl    return (AE_OK);
344118611Snjl}
345118611Snjl
346118611Snjl
347118611Snjl/*******************************************************************************
348118611Snjl *
349118611Snjl * FUNCTION:    LdNamespace1Begin
350118611Snjl *
351118611Snjl * PARAMETERS:  ASL_WALK_CALLBACK
352118611Snjl *
353118611Snjl * RETURN:      Status
354118611Snjl *
355118611Snjl * DESCRIPTION: Descending callback used during the parse tree walk.  If this
356118611Snjl *              is a named AML opcode, enter into the namespace
357118611Snjl *
358118611Snjl ******************************************************************************/
359118611Snjl
360118611SnjlACPI_STATUS
361118611SnjlLdNamespace1Begin (
362118611Snjl    ACPI_PARSE_OBJECT       *Op,
363118611Snjl    UINT32                  Level,
364118611Snjl    void                    *Context)
365118611Snjl{
366118611Snjl    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
367118611Snjl    ACPI_NAMESPACE_NODE     *Node;
368118611Snjl    ACPI_STATUS             Status;
369118611Snjl    ACPI_OBJECT_TYPE        ObjectType;
370118611Snjl    ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
371118611Snjl    char                    *Path;
372118611Snjl    UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
373118611Snjl    ACPI_PARSE_OBJECT       *Arg;
374118611Snjl    UINT32                  i;
375118611Snjl
376118611Snjl
377118611Snjl    ACPI_FUNCTION_NAME ("LdNamespace1Begin");
378118611Snjl    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
379118611Snjl        Op, Op->Asl.ParseOpName));
380118611Snjl
381118611Snjl
382118611Snjl    /*
383118611Snjl     * We are only interested in opcodes that have an associated name
384118611Snjl     * (or multiple names)
385118611Snjl     */
386118611Snjl    switch (Op->Asl.AmlOpcode)
387118611Snjl    {
388118611Snjl    case AML_BANK_FIELD_OP:
389118611Snjl    case AML_INDEX_FIELD_OP:
390118611Snjl    case AML_FIELD_OP:
391118611Snjl
392118611Snjl        Status = LdLoadFieldElements (Op, WalkState);
393118611Snjl        return (Status);
394118611Snjl
395118611Snjl    default:
396118611Snjl
397118611Snjl        /* All other opcodes go below */
398118611Snjl        break;
399118611Snjl    }
400118611Snjl
401118611Snjl    /* Check if this object has already been installed in the namespace */
402118611Snjl
403118611Snjl    if (Op->Asl.Node)
404118611Snjl    {
405118611Snjl        return (AE_OK);
406118611Snjl    }
407118611Snjl
408118611Snjl    Path = Op->Asl.Namepath;
409118611Snjl    if (!Path)
410118611Snjl    {
411118611Snjl        return (AE_OK);
412118611Snjl    }
413118611Snjl
414118611Snjl    /* Map the raw opcode into an internal object type */
415118611Snjl
416118611Snjl    switch (Op->Asl.ParseOpcode)
417118611Snjl    {
418118611Snjl    case PARSEOP_NAME:
419118611Snjl
420118611Snjl        Arg = Op->Asl.Child;        /* Get the NameSeg/NameString node */
421118611Snjl        Arg = Arg->Asl.Next;        /* First peer is the object to be associated with the name */
422118611Snjl
423118611Snjl        /* Get the data type associated with the named object, not the name itself */
424118611Snjl
425118611Snjl        /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
426118611Snjl
427118611Snjl        ObjectType = 1;
428118611Snjl        for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
429118611Snjl        {
430118611Snjl            ObjectType++;
431118611Snjl        }
432118611Snjl        break;
433118611Snjl
434118611Snjl
435118611Snjl    case PARSEOP_EXTERNAL:
436118611Snjl
437118611Snjl        /*
438118611Snjl         * "External" simply enters a name and type into the namespace.
439118611Snjl         * We must be careful to not open a new scope, however, no matter
440118611Snjl         * what type the external name refers to (e.g., a method)
441118611Snjl         *
442118611Snjl         * first child is name, next child is ObjectType
443118611Snjl         */
444118611Snjl        ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
445118611Snjl        ObjectType = ACPI_TYPE_ANY;
446118611Snjl        break;
447118611Snjl
448118611Snjl
449118611Snjl    case PARSEOP_DEFAULT_ARG:
450118611Snjl
451118611Snjl        if(Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
452118611Snjl        {
453118611Snjl            Status = LdLoadResourceElements (Op, WalkState);
454118611Snjl            goto Exit;
455118611Snjl        }
456118611Snjl
457118611Snjl        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
458118611Snjl        break;
459118611Snjl
460118611Snjl
461118611Snjl    case PARSEOP_SCOPE:
462118611Snjl
463118611Snjl        /*
464118611Snjl         * The name referenced by Scope(Name) must already exist at this point.
465118611Snjl         * In other words, forward references for Scope() are not supported.
466118611Snjl         * The only real reason for this is that the MS interpreter cannot
467118611Snjl         * handle this case.  Perhaps someday this case can go away.
468118611Snjl         */
469118611Snjl        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
470118611Snjl                        ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
471118611Snjl        if (ACPI_FAILURE (Status))
472118611Snjl        {
473118611Snjl            if (Status == AE_NOT_FOUND)
474118611Snjl            {
475118611Snjl                /* The name was not found, go ahead and create it */
476118611Snjl
477118611Snjl                Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_LOCAL_SCOPE,
478118611Snjl                                ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
479118611Snjl
480118611Snjl                /*
481118611Snjl                 * However, this is an error -- primarily because the MS
482118611Snjl                 * interpreter can't handle a forward reference from the
483118611Snjl                 * Scope() operator.
484118611Snjl                 */
485118611Snjl                AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, Op->Asl.ExternalName);
486118611Snjl                AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op, Op->Asl.ExternalName);
487118611Snjl                goto FinishNode;
488118611Snjl            }
489118611Snjl
490118611Snjl            AslCoreSubsystemError (Op, Status, "Failure from lookup\n", FALSE);
491118611Snjl            goto Exit;
492118611Snjl        }
493118611Snjl
494118611Snjl        /* We found a node with this name, now check the type */
495118611Snjl
496118611Snjl        switch (Node->Type)
497118611Snjl        {
498118611Snjl        case ACPI_TYPE_LOCAL_SCOPE:
499118611Snjl        case ACPI_TYPE_DEVICE:
500118611Snjl        case ACPI_TYPE_POWER:
501118611Snjl        case ACPI_TYPE_PROCESSOR:
502118611Snjl        case ACPI_TYPE_THERMAL:
503118611Snjl
504118611Snjl            /* These are acceptable types - they all open a new scope */
505118611Snjl            break;
506118611Snjl
507118611Snjl        case ACPI_TYPE_INTEGER:
508118611Snjl        case ACPI_TYPE_STRING:
509118611Snjl        case ACPI_TYPE_BUFFER:
510118611Snjl
511118611Snjl            /*
512118611Snjl             * These types we will allow, but we will change the type.  This
513118611Snjl             * enables some existing code of the form:
514118611Snjl             *
515118611Snjl             *  Name (DEB, 0)
516118611Snjl             *  Scope (DEB) { ... }
517118611Snjl             *
518118611Snjl             * Which is used to workaround the fact that the MS interpreter
519118611Snjl             * does not allow Scope() forward references.
520118611Snjl             */
521128212Snjl            sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
522118611Snjl                Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
523118611Snjl            AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
524118611Snjl
525118611Snjl            /*
526128212Snjl             * Switch the type to scope, open the new scope
527118611Snjl             */
528128212Snjl            Node->Type = ACPI_TYPE_LOCAL_SCOPE;
529128212Snjl            Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, WalkState);
530128212Snjl            if (ACPI_FAILURE (Status))
531128212Snjl            {
532128212Snjl                return_ACPI_STATUS (Status);
533128212Snjl            }
534118611Snjl            break;
535118611Snjl
536118611Snjl        default:
537118611Snjl
538118611Snjl            /*
539118611Snjl             * All other types are an error
540118611Snjl             */
541128212Snjl            sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
542118611Snjl            AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
543118611Snjl
544118611Snjl            /*
545118611Snjl             * However, switch the type to be an actual scope so
546118611Snjl             * that compilation can continue without generating a whole
547128212Snjl             * cascade of additional errors.  Open the new scope.
548118611Snjl             */
549128212Snjl            Node->Type = ACPI_TYPE_LOCAL_SCOPE;
550128212Snjl            Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, WalkState);
551128212Snjl            if (ACPI_FAILURE (Status))
552128212Snjl            {
553128212Snjl                return_ACPI_STATUS (Status);
554128212Snjl            }
555118611Snjl            break;
556118611Snjl        }
557118611Snjl
558118611Snjl        Status = AE_OK;
559118611Snjl        goto FinishNode;
560118611Snjl
561118611Snjl
562118611Snjl    default:
563118611Snjl
564118611Snjl        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
565118611Snjl        break;
566118611Snjl    }
567118611Snjl
568118611Snjl
569118611Snjl    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
570118611Snjl            Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
571118611Snjl
572118611Snjl    /* The name must not already exist */
573118611Snjl
574118611Snjl    Flags |= ACPI_NS_ERROR_IF_FOUND;
575118611Snjl
576118611Snjl    /*
577118611Snjl     * Enter the named type into the internal namespace.  We enter the name
578118611Snjl     * as we go downward in the parse tree.  Any necessary subobjects that involve
579118611Snjl     * arguments to the opcode must be created as we go back up the parse tree later.
580118611Snjl     */
581118611Snjl    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
582118611Snjl                    ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node));
583118611Snjl    if (ACPI_FAILURE (Status))
584118611Snjl    {
585118611Snjl        if (Status == AE_ALREADY_EXISTS)
586118611Snjl        {
587118611Snjl            /* The name already exists in this scope */
588118611Snjl
589118611Snjl            if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
590118611Snjl            {
591118611Snjl                Node->Type = (UINT8) ObjectType;
592118611Snjl                Status = AE_OK;
593118611Snjl            }
594118611Snjl            else
595118611Snjl            {
596118611Snjl                AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, Op->Asl.ExternalName);
597118611Snjl                Status = AE_OK;
598118611Snjl                goto Exit;
599118611Snjl            }
600118611Snjl        }
601118611Snjl        else
602118611Snjl        {
603118611Snjl            AslCoreSubsystemError (Op, Status, "Failure from lookup %s\n", FALSE);
604118611Snjl            goto Exit;
605118611Snjl        }
606118611Snjl    }
607118611Snjl
608118611Snjl
609118611SnjlFinishNode:
610118611Snjl    /*
611118611Snjl     * Point the parse node to the new namespace node, and point
612118611Snjl     * the Node back to the original Parse node
613118611Snjl     */
614118611Snjl    Op->Asl.Node = Node;
615118611Snjl    Node->Object = (ACPI_OPERAND_OBJECT *) Op;
616118611Snjl
617118611Snjl    /* Set the actual data type if appropriate (EXTERNAL term only) */
618118611Snjl
619118611Snjl    if (ActualObjectType != ACPI_TYPE_ANY)
620118611Snjl    {
621118611Snjl        Node->Type = (UINT8) ActualObjectType;
622118611Snjl        Node->OwnerId = ASL_EXTERNAL_METHOD;
623118611Snjl    }
624118611Snjl
625118611Snjl    if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
626118611Snjl    {
627118611Snjl        /*
628118611Snjl         * Get the method argument count from "Extra" and store
629118611Snjl         * it in the OwnerId field of the namespace node
630118611Snjl         */
631118611Snjl        Node->OwnerId = (UINT16) Op->Asl.Extra;
632118611Snjl    }
633118611Snjl
634118611SnjlExit:
635118611Snjl    return (Status);
636118611Snjl}
637118611Snjl
638118611Snjl
639118611Snjl/*******************************************************************************
640118611Snjl *
641118611Snjl * FUNCTION:    LdNamespace1End
642118611Snjl *
643118611Snjl * PARAMETERS:  ASL_WALK_CALLBACK
644118611Snjl *
645118611Snjl * RETURN:      Status
646118611Snjl *
647118611Snjl * DESCRIPTION: Ascending callback used during the loading of the namespace,
648118611Snjl *              We only need to worry about managing the scope stack here.
649118611Snjl *
650118611Snjl ******************************************************************************/
651118611Snjl
652118611SnjlACPI_STATUS
653118611SnjlLdNamespace1End (
654118611Snjl    ACPI_PARSE_OBJECT       *Op,
655118611Snjl    UINT32                  Level,
656118611Snjl    void                    *Context)
657118611Snjl{
658118611Snjl    ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
659118611Snjl    ACPI_OBJECT_TYPE        ObjectType;
660118611Snjl
661118611Snjl
662118611Snjl    ACPI_FUNCTION_NAME ("LdNamespace1End");
663118611Snjl
664118611Snjl
665118611Snjl    /* We are only interested in opcodes that have an associated name */
666118611Snjl
667118611Snjl    if (!Op->Asl.Namepath)
668118611Snjl    {
669118611Snjl        return (AE_OK);
670118611Snjl    }
671118611Snjl
672118611Snjl    /* Get the type to determine if we should pop the scope */
673118611Snjl
674118611Snjl    if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
675118611Snjl        (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
676118611Snjl    {
677118611Snjl        /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
678118611Snjl
679118611Snjl        ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
680118611Snjl    }
681118611Snjl    else
682118611Snjl    {
683118611Snjl        ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
684118611Snjl    }
685118611Snjl
686118611Snjl    /* Pop the scope stack */
687118611Snjl
688118611Snjl    if (AcpiNsOpensScope (ObjectType))
689118611Snjl    {
690118611Snjl
691118611Snjl        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
692118611Snjl            "(%s): Popping scope for Op [%s] %p\n",
693118611Snjl            AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
694118611Snjl
695118611Snjl        AcpiDsScopeStackPop (WalkState);
696118611Snjl    }
697118611Snjl
698118611Snjl    return (AE_OK);
699118611Snjl}
700118611Snjl
701118611Snjl
702