xref: /freebsd-src/sys/contrib/dev/acpica/compiler/aslload.c (revision ab6f3bf9cb8ad195aecd9165d8d4b1a93aed3c8d)
153289f6aSNate Lawson /******************************************************************************
253289f6aSNate Lawson  *
353289f6aSNate Lawson  * Module Name: dswload - Dispatcher namespace load callbacks
453289f6aSNate Lawson  *
553289f6aSNate Lawson  *****************************************************************************/
653289f6aSNate Lawson 
753289f6aSNate Lawson /******************************************************************************
853289f6aSNate Lawson  *
953289f6aSNate Lawson  * 1. Copyright Notice
1053289f6aSNate Lawson  *
11a9f12690SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
1253289f6aSNate Lawson  * All rights reserved.
1353289f6aSNate Lawson  *
1453289f6aSNate Lawson  * 2. License
1553289f6aSNate Lawson  *
1653289f6aSNate Lawson  * 2.1. This is your license from Intel Corp. under its intellectual property
1753289f6aSNate Lawson  * rights.  You may have additional license terms from the party that provided
1853289f6aSNate Lawson  * you this software, covering your right to use that party's intellectual
1953289f6aSNate Lawson  * property rights.
2053289f6aSNate Lawson  *
2153289f6aSNate Lawson  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2253289f6aSNate Lawson  * copy of the source code appearing in this file ("Covered Code") an
2353289f6aSNate Lawson  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2453289f6aSNate Lawson  * base code distributed originally by Intel ("Original Intel Code") to copy,
2553289f6aSNate Lawson  * make derivatives, distribute, use and display any portion of the Covered
2653289f6aSNate Lawson  * Code in any form, with the right to sublicense such rights; and
2753289f6aSNate Lawson  *
2853289f6aSNate Lawson  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
2953289f6aSNate Lawson  * license (with the right to sublicense), under only those claims of Intel
3053289f6aSNate Lawson  * patents that are infringed by the Original Intel Code, to make, use, sell,
3153289f6aSNate Lawson  * offer to sell, and import the Covered Code and derivative works thereof
3253289f6aSNate Lawson  * solely to the minimum extent necessary to exercise the above copyright
3353289f6aSNate Lawson  * license, and in no event shall the patent license extend to any additions
3453289f6aSNate Lawson  * to or modifications of the Original Intel Code.  No other license or right
3553289f6aSNate Lawson  * is granted directly or by implication, estoppel or otherwise;
3653289f6aSNate Lawson  *
3753289f6aSNate Lawson  * The above copyright and patent license is granted only if the following
3853289f6aSNate Lawson  * conditions are met:
3953289f6aSNate Lawson  *
4053289f6aSNate Lawson  * 3. Conditions
4153289f6aSNate Lawson  *
4253289f6aSNate Lawson  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4353289f6aSNate Lawson  * Redistribution of source code of any substantial portion of the Covered
4453289f6aSNate Lawson  * Code or modification with rights to further distribute source must include
4553289f6aSNate Lawson  * the above Copyright Notice, the above License, this list of Conditions,
4653289f6aSNate Lawson  * and the following Disclaimer and Export Compliance provision.  In addition,
4753289f6aSNate Lawson  * Licensee must cause all Covered Code to which Licensee contributes to
4853289f6aSNate Lawson  * contain a file documenting the changes Licensee made to create that Covered
4953289f6aSNate Lawson  * Code and the date of any change.  Licensee must include in that file the
5053289f6aSNate Lawson  * documentation of any changes made by any predecessor Licensee.  Licensee
5153289f6aSNate Lawson  * must include a prominent statement that the modification is derived,
5253289f6aSNate Lawson  * directly or indirectly, from Original Intel Code.
5353289f6aSNate Lawson  *
5453289f6aSNate Lawson  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5553289f6aSNate Lawson  * Redistribution of source code of any substantial portion of the Covered
5653289f6aSNate Lawson  * Code or modification without rights to further distribute source must
5753289f6aSNate Lawson  * include the following Disclaimer and Export Compliance provision in the
5853289f6aSNate Lawson  * documentation and/or other materials provided with distribution.  In
5953289f6aSNate Lawson  * addition, Licensee may not authorize further sublicense of source of any
6053289f6aSNate Lawson  * portion of the Covered Code, and must include terms to the effect that the
6153289f6aSNate Lawson  * license from Licensee to its licensee is limited to the intellectual
6253289f6aSNate Lawson  * property embodied in the software Licensee provides to its licensee, and
6353289f6aSNate Lawson  * not to intellectual property embodied in modifications its licensee may
6453289f6aSNate Lawson  * make.
6553289f6aSNate Lawson  *
6653289f6aSNate Lawson  * 3.3. Redistribution of Executable. Redistribution in executable form of any
6753289f6aSNate Lawson  * substantial portion of the Covered Code or modification must reproduce the
6853289f6aSNate Lawson  * above Copyright Notice, and the following Disclaimer and Export Compliance
6953289f6aSNate Lawson  * provision in the documentation and/or other materials provided with the
7053289f6aSNate Lawson  * distribution.
7153289f6aSNate Lawson  *
7253289f6aSNate Lawson  * 3.4. Intel retains all right, title, and interest in and to the Original
7353289f6aSNate Lawson  * Intel Code.
7453289f6aSNate Lawson  *
7553289f6aSNate Lawson  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7653289f6aSNate Lawson  * Intel shall be used in advertising or otherwise to promote the sale, use or
7753289f6aSNate Lawson  * other dealings in products derived from or relating to the Covered Code
7853289f6aSNate Lawson  * without prior written authorization from Intel.
7953289f6aSNate Lawson  *
8053289f6aSNate Lawson  * 4. Disclaimer and Export Compliance
8153289f6aSNate Lawson  *
8253289f6aSNate Lawson  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8353289f6aSNate Lawson  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8453289f6aSNate Lawson  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8553289f6aSNate Lawson  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8653289f6aSNate Lawson  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8753289f6aSNate Lawson  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8853289f6aSNate Lawson  * PARTICULAR PURPOSE.
8953289f6aSNate Lawson  *
9053289f6aSNate Lawson  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9153289f6aSNate Lawson  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9253289f6aSNate Lawson  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9353289f6aSNate Lawson  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9453289f6aSNate Lawson  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9553289f6aSNate Lawson  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9653289f6aSNate Lawson  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9753289f6aSNate Lawson  * LIMITED REMEDY.
9853289f6aSNate Lawson  *
9953289f6aSNate Lawson  * 4.3. Licensee shall not export, either directly or indirectly, any of this
10053289f6aSNate Lawson  * software or system incorporating such software without first obtaining any
10153289f6aSNate Lawson  * required license or other approval from the U. S. Department of Commerce or
10253289f6aSNate Lawson  * any other agency or department of the United States Government.  In the
10353289f6aSNate Lawson  * event Licensee exports any such software from the United States or
10453289f6aSNate Lawson  * re-exports any such software from a foreign destination, Licensee shall
10553289f6aSNate Lawson  * ensure that the distribution and export/re-export of the software is in
10653289f6aSNate Lawson  * compliance with all laws, regulations, orders, or other restrictions of the
10753289f6aSNate Lawson  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10853289f6aSNate Lawson  * any of its subsidiaries will export/re-export any technical data, process,
10953289f6aSNate Lawson  * software, or service, directly or indirectly, to any country for which the
11053289f6aSNate Lawson  * United States government or any agency thereof requires an export license,
11153289f6aSNate Lawson  * other governmental approval, or letter of assurance, without first obtaining
11253289f6aSNate Lawson  * such license, approval or letter.
11353289f6aSNate Lawson  *
11453289f6aSNate Lawson  *****************************************************************************/
11553289f6aSNate Lawson 
11653289f6aSNate Lawson #define __ASLLOAD_C__
11753289f6aSNate Lawson 
118*ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
119*ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
120*ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
121*ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
12253289f6aSNate Lawson 
12353289f6aSNate Lawson #include "aslcompiler.y.h"
12453289f6aSNate Lawson 
12553289f6aSNate Lawson #define _COMPONENT          ACPI_COMPILER
12653289f6aSNate Lawson         ACPI_MODULE_NAME    ("aslload")
12753289f6aSNate Lawson 
128fba7fc7eSJung-uk Kim /* Local prototypes */
129fba7fc7eSJung-uk Kim 
130fba7fc7eSJung-uk Kim static ACPI_STATUS
131fba7fc7eSJung-uk Kim LdLoadFieldElements (
132fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
133fba7fc7eSJung-uk Kim     ACPI_WALK_STATE         *WalkState);
134fba7fc7eSJung-uk Kim 
135fba7fc7eSJung-uk Kim static ACPI_STATUS
136fba7fc7eSJung-uk Kim LdLoadResourceElements (
137fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
138fba7fc7eSJung-uk Kim     ACPI_WALK_STATE         *WalkState);
139fba7fc7eSJung-uk Kim 
140fba7fc7eSJung-uk Kim static ACPI_STATUS
141fba7fc7eSJung-uk Kim LdNamespace1Begin (
142fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
143fba7fc7eSJung-uk Kim     UINT32                  Level,
144fba7fc7eSJung-uk Kim     void                    *Context);
145fba7fc7eSJung-uk Kim 
146fba7fc7eSJung-uk Kim static ACPI_STATUS
147a9f12690SJung-uk Kim LdNamespace2Begin (
148a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
149a9f12690SJung-uk Kim     UINT32                  Level,
150a9f12690SJung-uk Kim     void                    *Context);
151a9f12690SJung-uk Kim 
152a9f12690SJung-uk Kim static ACPI_STATUS
153a9f12690SJung-uk Kim LdCommonNamespaceEnd (
154fba7fc7eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
155fba7fc7eSJung-uk Kim     UINT32                  Level,
156fba7fc7eSJung-uk Kim     void                    *Context);
157fba7fc7eSJung-uk Kim 
15853289f6aSNate Lawson 
15953289f6aSNate Lawson /*******************************************************************************
16053289f6aSNate Lawson  *
16153289f6aSNate Lawson  * FUNCTION:    LdLoadNamespace
16253289f6aSNate Lawson  *
163fba7fc7eSJung-uk Kim  * PARAMETERS:  RootOp      - Root of the parse tree
16453289f6aSNate Lawson  *
16553289f6aSNate Lawson  * RETURN:      Status
16653289f6aSNate Lawson  *
16753289f6aSNate Lawson  * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
16853289f6aSNate Lawson  *              named ASL/AML objects into the namespace. The namespace is
16953289f6aSNate Lawson  *              constructed in order to resolve named references and references
17053289f6aSNate Lawson  *              to named fields within resource templates/descriptors.
17153289f6aSNate Lawson  *
17253289f6aSNate Lawson  ******************************************************************************/
17353289f6aSNate Lawson 
17453289f6aSNate Lawson ACPI_STATUS
17553289f6aSNate Lawson LdLoadNamespace (
17653289f6aSNate Lawson     ACPI_PARSE_OBJECT       *RootOp)
17753289f6aSNate Lawson {
17853289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState;
17953289f6aSNate Lawson 
18053289f6aSNate Lawson 
18153289f6aSNate Lawson     DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n");
18253289f6aSNate Lawson 
18353289f6aSNate Lawson     /* Create a new walk state */
18453289f6aSNate Lawson 
18553289f6aSNate Lawson     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
18653289f6aSNate Lawson     if (!WalkState)
18753289f6aSNate Lawson     {
18853289f6aSNate Lawson         return AE_NO_MEMORY;
18953289f6aSNate Lawson     }
19053289f6aSNate Lawson 
191a9f12690SJung-uk Kim     /* Walk the entire parse tree, first pass */
19253289f6aSNate Lawson 
19353289f6aSNate Lawson     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
194a9f12690SJung-uk Kim         LdCommonNamespaceEnd, WalkState);
195a9f12690SJung-uk Kim 
196a9f12690SJung-uk Kim     /* Second pass to handle forward references */
197a9f12690SJung-uk Kim 
198a9f12690SJung-uk Kim     TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
199a9f12690SJung-uk Kim         LdCommonNamespaceEnd, WalkState);
20053289f6aSNate Lawson 
20153289f6aSNate Lawson     /* Dump the namespace if debug is enabled */
20253289f6aSNate Lawson 
20353289f6aSNate Lawson     AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
20453289f6aSNate Lawson     return AE_OK;
20553289f6aSNate Lawson }
20653289f6aSNate Lawson 
20753289f6aSNate Lawson 
20853289f6aSNate Lawson /*******************************************************************************
20953289f6aSNate Lawson  *
21053289f6aSNate Lawson  * FUNCTION:    LdLoadFieldElements
21153289f6aSNate Lawson  *
21253289f6aSNate Lawson  * PARAMETERS:  Op              - Parent node (Field)
21353289f6aSNate Lawson  *              WalkState       - Current walk state
21453289f6aSNate Lawson  *
21553289f6aSNate Lawson  * RETURN:      Status
21653289f6aSNate Lawson  *
21753289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the field (children of the parent)
21853289f6aSNate Lawson  *              into the namespace.
21953289f6aSNate Lawson  *
22053289f6aSNate Lawson  ******************************************************************************/
22153289f6aSNate Lawson 
222fba7fc7eSJung-uk Kim static ACPI_STATUS
22353289f6aSNate Lawson LdLoadFieldElements (
22453289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
22553289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
22653289f6aSNate Lawson {
22753289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Child = NULL;
22853289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
22953289f6aSNate Lawson     ACPI_STATUS             Status;
23053289f6aSNate Lawson 
23153289f6aSNate Lawson 
23253289f6aSNate Lawson     /* Get the first named field element */
23353289f6aSNate Lawson 
23453289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
23553289f6aSNate Lawson     {
23653289f6aSNate Lawson     case AML_BANK_FIELD_OP:
23753289f6aSNate Lawson 
23853289f6aSNate Lawson         Child = UtGetArg (Op, 6);
23953289f6aSNate Lawson         break;
24053289f6aSNate Lawson 
24153289f6aSNate Lawson     case AML_INDEX_FIELD_OP:
24253289f6aSNate Lawson 
24353289f6aSNate Lawson         Child = UtGetArg (Op, 5);
24453289f6aSNate Lawson         break;
24553289f6aSNate Lawson 
24653289f6aSNate Lawson     case AML_FIELD_OP:
24753289f6aSNate Lawson 
24853289f6aSNate Lawson         Child = UtGetArg (Op, 4);
24953289f6aSNate Lawson         break;
25053289f6aSNate Lawson 
25153289f6aSNate Lawson     default:
25253289f6aSNate Lawson         /* No other opcodes should arrive here */
25353289f6aSNate Lawson         return (AE_BAD_PARAMETER);
25453289f6aSNate Lawson     }
25553289f6aSNate Lawson 
25653289f6aSNate Lawson     /* Enter all elements into the namespace */
25753289f6aSNate Lawson 
25853289f6aSNate Lawson     while (Child)
25953289f6aSNate Lawson     {
26053289f6aSNate Lawson         switch (Child->Asl.AmlOpcode)
26153289f6aSNate Lawson         {
26253289f6aSNate Lawson         case AML_INT_RESERVEDFIELD_OP:
26353289f6aSNate Lawson         case AML_INT_ACCESSFIELD_OP:
26453289f6aSNate Lawson 
26553289f6aSNate Lawson             break;
26653289f6aSNate Lawson 
26753289f6aSNate Lawson         default:
26853289f6aSNate Lawson 
269fba7fc7eSJung-uk Kim             Status = AcpiNsLookup (WalkState->ScopeInfo,
270fba7fc7eSJung-uk Kim                         Child->Asl.Value.String,
271fba7fc7eSJung-uk Kim                         ACPI_TYPE_LOCAL_REGION_FIELD,
272fba7fc7eSJung-uk Kim                         ACPI_IMODE_LOAD_PASS1,
273fba7fc7eSJung-uk Kim                         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
274fba7fc7eSJung-uk Kim                             ACPI_NS_ERROR_IF_FOUND,
27553289f6aSNate Lawson                         NULL, &Node);
27653289f6aSNate Lawson             if (ACPI_FAILURE (Status))
27753289f6aSNate Lawson             {
27853289f6aSNate Lawson                 if (Status != AE_ALREADY_EXISTS)
27953289f6aSNate Lawson                 {
280fba7fc7eSJung-uk Kim                     AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
281fba7fc7eSJung-uk Kim                         Child->Asl.Value.String);
28253289f6aSNate Lawson                     return (Status);
28353289f6aSNate Lawson                 }
28453289f6aSNate Lawson 
28553289f6aSNate Lawson                 /*
28653289f6aSNate Lawson                  * The name already exists in this scope
28753289f6aSNate Lawson                  * But continue processing the elements
28853289f6aSNate Lawson                  */
289fba7fc7eSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
290fba7fc7eSJung-uk Kim                     Child->Asl.Value.String);
29153289f6aSNate Lawson             }
29253289f6aSNate Lawson             else
29353289f6aSNate Lawson             {
29453289f6aSNate Lawson                 Child->Asl.Node = Node;
295fba7fc7eSJung-uk Kim                 Node->Op = Child;
29653289f6aSNate Lawson             }
29753289f6aSNate Lawson             break;
29853289f6aSNate Lawson         }
29953289f6aSNate Lawson         Child = Child->Asl.Next;
30053289f6aSNate Lawson     }
30153289f6aSNate Lawson     return (AE_OK);
30253289f6aSNate Lawson }
30353289f6aSNate Lawson 
30453289f6aSNate Lawson 
30553289f6aSNate Lawson /*******************************************************************************
30653289f6aSNate Lawson  *
30753289f6aSNate Lawson  * FUNCTION:    LdLoadResourceElements
30853289f6aSNate Lawson  *
30953289f6aSNate Lawson  * PARAMETERS:  Op              - Parent node (Resource Descriptor)
31053289f6aSNate Lawson  *              WalkState       - Current walk state
31153289f6aSNate Lawson  *
31253289f6aSNate Lawson  * RETURN:      Status
31353289f6aSNate Lawson  *
31453289f6aSNate Lawson  * DESCRIPTION: Enter the named elements of the resource descriptor (children
31553289f6aSNate Lawson  *              of the parent) into the namespace.
31653289f6aSNate Lawson  *
31753289f6aSNate Lawson  * NOTE: In the real AML namespace, these named elements never exist. But
31853289f6aSNate Lawson  *       we simply use the namespace here as a symbol table so we can look
31953289f6aSNate Lawson  *       them up as they are referenced.
32053289f6aSNate Lawson  *
32153289f6aSNate Lawson  ******************************************************************************/
32253289f6aSNate Lawson 
323fba7fc7eSJung-uk Kim static ACPI_STATUS
32453289f6aSNate Lawson LdLoadResourceElements (
32553289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
32653289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState)
32753289f6aSNate Lawson {
32853289f6aSNate Lawson     ACPI_PARSE_OBJECT       *InitializerOp = NULL;
32953289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
33053289f6aSNate Lawson     ACPI_STATUS             Status;
33153289f6aSNate Lawson 
33253289f6aSNate Lawson 
33353289f6aSNate Lawson     /*
334fba7fc7eSJung-uk Kim      * Enter the resource name into the namespace. Name must not already exist.
335fba7fc7eSJung-uk Kim      * This opens a scope, so later field names are guaranteed to be new/unique.
33653289f6aSNate Lawson      */
33753289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
338fba7fc7eSJung-uk Kim                 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
339fba7fc7eSJung-uk Kim                 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
34053289f6aSNate Lawson                 WalkState, &Node);
34153289f6aSNate Lawson     if (ACPI_FAILURE (Status))
34253289f6aSNate Lawson     {
343fba7fc7eSJung-uk Kim         if (Status == AE_ALREADY_EXISTS)
344fba7fc7eSJung-uk Kim         {
345fba7fc7eSJung-uk Kim             /* Actual node causing the error was saved in ParentMethod */
346fba7fc7eSJung-uk Kim 
347fba7fc7eSJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
348fba7fc7eSJung-uk Kim                 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath);
349fba7fc7eSJung-uk Kim             return (AE_OK);
350fba7fc7eSJung-uk Kim         }
35153289f6aSNate Lawson         return (Status);
35253289f6aSNate Lawson     }
35353289f6aSNate Lawson 
3541a39cfb0SJung-uk Kim     Node->Value = (UINT32) Op->Asl.Value.Integer;
3551a39cfb0SJung-uk Kim     Node->Op = Op;
3561a39cfb0SJung-uk Kim 
35753289f6aSNate Lawson     /*
35853289f6aSNate Lawson      * Now enter the predefined fields, for easy lookup when referenced
35953289f6aSNate Lawson      * by the source ASL
36053289f6aSNate Lawson      */
36153289f6aSNate Lawson     InitializerOp = ASL_GET_CHILD_NODE (Op);
36253289f6aSNate Lawson     while (InitializerOp)
36353289f6aSNate Lawson     {
36453289f6aSNate Lawson 
36553289f6aSNate Lawson         if (InitializerOp->Asl.ExternalName)
36653289f6aSNate Lawson         {
36753289f6aSNate Lawson             Status = AcpiNsLookup (WalkState->ScopeInfo,
36853289f6aSNate Lawson                         InitializerOp->Asl.ExternalName,
36953289f6aSNate Lawson                         ACPI_TYPE_LOCAL_RESOURCE_FIELD,
370fba7fc7eSJung-uk Kim                         ACPI_IMODE_LOAD_PASS1,
371fba7fc7eSJung-uk Kim                         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
37253289f6aSNate Lawson                         NULL, &Node);
37353289f6aSNate Lawson             if (ACPI_FAILURE (Status))
37453289f6aSNate Lawson             {
37553289f6aSNate Lawson                 return (Status);
37653289f6aSNate Lawson             }
37753289f6aSNate Lawson 
37853289f6aSNate Lawson             /*
37953289f6aSNate Lawson              * Store the field offset in the namespace node so it
38053289f6aSNate Lawson              * can be used when the field is referenced
38153289f6aSNate Lawson              */
382fba7fc7eSJung-uk Kim             Node->Value = (UINT32) InitializerOp->Asl.Value.Integer;
38353289f6aSNate Lawson             InitializerOp->Asl.Node = Node;
384fba7fc7eSJung-uk Kim             Node->Op = InitializerOp;
38553289f6aSNate Lawson 
38653289f6aSNate Lawson             /* Pass thru the field type (Bitfield or Bytefield) */
38753289f6aSNate Lawson 
38853289f6aSNate Lawson             if (InitializerOp->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
38953289f6aSNate Lawson             {
39053289f6aSNate Lawson                 Node->Flags |= ANOBJ_IS_BIT_OFFSET;
39153289f6aSNate Lawson             }
39253289f6aSNate Lawson         }
39353289f6aSNate Lawson         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
39453289f6aSNate Lawson     }
39553289f6aSNate Lawson 
39653289f6aSNate Lawson     return (AE_OK);
39753289f6aSNate Lawson }
39853289f6aSNate Lawson 
39953289f6aSNate Lawson 
40053289f6aSNate Lawson /*******************************************************************************
40153289f6aSNate Lawson  *
40253289f6aSNate Lawson  * FUNCTION:    LdNamespace1Begin
40353289f6aSNate Lawson  *
40453289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
40553289f6aSNate Lawson  *
40653289f6aSNate Lawson  * RETURN:      Status
40753289f6aSNate Lawson  *
40853289f6aSNate Lawson  * DESCRIPTION: Descending callback used during the parse tree walk. If this
40953289f6aSNate Lawson  *              is a named AML opcode, enter into the namespace
41053289f6aSNate Lawson  *
41153289f6aSNate Lawson  ******************************************************************************/
41253289f6aSNate Lawson 
413fba7fc7eSJung-uk Kim static ACPI_STATUS
41453289f6aSNate Lawson LdNamespace1Begin (
41553289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
41653289f6aSNate Lawson     UINT32                  Level,
41753289f6aSNate Lawson     void                    *Context)
41853289f6aSNate Lawson {
41953289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
42053289f6aSNate Lawson     ACPI_NAMESPACE_NODE     *Node;
42153289f6aSNate Lawson     ACPI_STATUS             Status;
42253289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
42353289f6aSNate Lawson     ACPI_OBJECT_TYPE        ActualObjectType = ACPI_TYPE_ANY;
42453289f6aSNate Lawson     char                    *Path;
42553289f6aSNate Lawson     UINT32                  Flags = ACPI_NS_NO_UPSEARCH;
42653289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Arg;
42753289f6aSNate Lawson     UINT32                  i;
4281a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
42953289f6aSNate Lawson 
43053289f6aSNate Lawson 
4311a39cfb0SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace1Begin);
43253289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
43353289f6aSNate Lawson         Op, Op->Asl.ParseOpName));
43453289f6aSNate Lawson 
43553289f6aSNate Lawson 
43653289f6aSNate Lawson     /*
43753289f6aSNate Lawson      * We are only interested in opcodes that have an associated name
43853289f6aSNate Lawson      * (or multiple names)
43953289f6aSNate Lawson      */
44053289f6aSNate Lawson     switch (Op->Asl.AmlOpcode)
44153289f6aSNate Lawson     {
44253289f6aSNate Lawson     case AML_BANK_FIELD_OP:
44353289f6aSNate Lawson     case AML_INDEX_FIELD_OP:
44453289f6aSNate Lawson     case AML_FIELD_OP:
44553289f6aSNate Lawson 
44653289f6aSNate Lawson         Status = LdLoadFieldElements (Op, WalkState);
44753289f6aSNate Lawson         return (Status);
44853289f6aSNate Lawson 
44953289f6aSNate Lawson     default:
45053289f6aSNate Lawson 
45153289f6aSNate Lawson         /* All other opcodes go below */
45253289f6aSNate Lawson         break;
45353289f6aSNate Lawson     }
45453289f6aSNate Lawson 
45553289f6aSNate Lawson     /* Check if this object has already been installed in the namespace */
45653289f6aSNate Lawson 
45753289f6aSNate Lawson     if (Op->Asl.Node)
45853289f6aSNate Lawson     {
45953289f6aSNate Lawson         return (AE_OK);
46053289f6aSNate Lawson     }
46153289f6aSNate Lawson 
46253289f6aSNate Lawson     Path = Op->Asl.Namepath;
46353289f6aSNate Lawson     if (!Path)
46453289f6aSNate Lawson     {
46553289f6aSNate Lawson         return (AE_OK);
46653289f6aSNate Lawson     }
46753289f6aSNate Lawson 
46853289f6aSNate Lawson     /* Map the raw opcode into an internal object type */
46953289f6aSNate Lawson 
47053289f6aSNate Lawson     switch (Op->Asl.ParseOpcode)
47153289f6aSNate Lawson     {
47253289f6aSNate Lawson     case PARSEOP_NAME:
47353289f6aSNate Lawson 
47453289f6aSNate Lawson         Arg = Op->Asl.Child;  /* Get the NameSeg/NameString node */
47553289f6aSNate Lawson         Arg = Arg->Asl.Next;  /* First peer is the object to be associated with the name */
47653289f6aSNate Lawson 
4771a39cfb0SJung-uk Kim         /*
4781a39cfb0SJung-uk Kim          * If this name refers to a ResourceTemplate, we will need to open
4791a39cfb0SJung-uk Kim          * a new scope so that the resource subfield names can be entered into
4801a39cfb0SJung-uk Kim          * the namespace underneath this name
4811a39cfb0SJung-uk Kim          */
4821a39cfb0SJung-uk Kim         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
4831a39cfb0SJung-uk Kim         {
4841a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
4851a39cfb0SJung-uk Kim         }
4861a39cfb0SJung-uk Kim 
48753289f6aSNate Lawson         /* Get the data type associated with the named object, not the name itself */
48853289f6aSNate Lawson 
48953289f6aSNate Lawson         /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
49053289f6aSNate Lawson 
49153289f6aSNate Lawson         ObjectType = 1;
49253289f6aSNate Lawson         for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
49353289f6aSNate Lawson         {
49453289f6aSNate Lawson             ObjectType++;
49553289f6aSNate Lawson         }
49653289f6aSNate Lawson         break;
49753289f6aSNate Lawson 
49853289f6aSNate Lawson 
49953289f6aSNate Lawson     case PARSEOP_EXTERNAL:
50053289f6aSNate Lawson 
50153289f6aSNate Lawson         /*
50253289f6aSNate Lawson          * "External" simply enters a name and type into the namespace.
50353289f6aSNate Lawson          * We must be careful to not open a new scope, however, no matter
50453289f6aSNate Lawson          * what type the external name refers to (e.g., a method)
50553289f6aSNate Lawson          *
50653289f6aSNate Lawson          * first child is name, next child is ObjectType
50753289f6aSNate Lawson          */
50853289f6aSNate Lawson         ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
50953289f6aSNate Lawson         ObjectType = ACPI_TYPE_ANY;
51053289f6aSNate Lawson 
5111a39cfb0SJung-uk Kim         /*
5121a39cfb0SJung-uk Kim          * We will mark every new node along the path as "External". This
5131a39cfb0SJung-uk Kim          * allows some or all of the nodes to be created later in the ASL
5141a39cfb0SJung-uk Kim          * code. Handles cases like this:
5151a39cfb0SJung-uk Kim          *
5161a39cfb0SJung-uk Kim          *   External (\_SB_.PCI0.ABCD, IntObj)
5171a39cfb0SJung-uk Kim          *   Scope (_SB_)
5181a39cfb0SJung-uk Kim          *   {
5191a39cfb0SJung-uk Kim          *       Device (PCI0)
5201a39cfb0SJung-uk Kim          *       {
5211a39cfb0SJung-uk Kim          *       }
5221a39cfb0SJung-uk Kim          *   }
5231a39cfb0SJung-uk Kim          *   Method (X)
5241a39cfb0SJung-uk Kim          *   {
5251a39cfb0SJung-uk Kim          *       Store (\_SB_.PCI0.ABCD, Local0)
5261a39cfb0SJung-uk Kim          *   }
5271a39cfb0SJung-uk Kim          */
5281a39cfb0SJung-uk Kim         Flags |= ACPI_NS_EXTERNAL;
5291a39cfb0SJung-uk Kim         break;
53053289f6aSNate Lawson 
53153289f6aSNate Lawson     case PARSEOP_DEFAULT_ARG:
53253289f6aSNate Lawson 
53353289f6aSNate Lawson         if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
53453289f6aSNate Lawson         {
53553289f6aSNate Lawson             Status = LdLoadResourceElements (Op, WalkState);
53653289f6aSNate Lawson             goto Exit;
53753289f6aSNate Lawson         }
53853289f6aSNate Lawson 
53953289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
54053289f6aSNate Lawson         break;
54153289f6aSNate Lawson 
54253289f6aSNate Lawson 
54353289f6aSNate Lawson     case PARSEOP_SCOPE:
54453289f6aSNate Lawson 
54553289f6aSNate Lawson         /*
54653289f6aSNate Lawson          * The name referenced by Scope(Name) must already exist at this point.
54753289f6aSNate Lawson          * In other words, forward references for Scope() are not supported.
54853289f6aSNate Lawson          * The only real reason for this is that the MS interpreter cannot
54953289f6aSNate Lawson          * handle this case. Perhaps someday this case can go away.
55053289f6aSNate Lawson          */
55153289f6aSNate Lawson         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
552fba7fc7eSJung-uk Kim                     ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
553fba7fc7eSJung-uk Kim                     WalkState, &(Node));
55453289f6aSNate Lawson         if (ACPI_FAILURE (Status))
55553289f6aSNate Lawson         {
55653289f6aSNate Lawson             if (Status == AE_NOT_FOUND)
55753289f6aSNate Lawson             {
55853289f6aSNate Lawson                 /* The name was not found, go ahead and create it */
55953289f6aSNate Lawson 
560fba7fc7eSJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
561fba7fc7eSJung-uk Kim                             ACPI_TYPE_LOCAL_SCOPE,
562fba7fc7eSJung-uk Kim                             ACPI_IMODE_LOAD_PASS1, Flags,
563fba7fc7eSJung-uk Kim                             WalkState, &(Node));
56453289f6aSNate Lawson 
56553289f6aSNate Lawson                 /*
56653289f6aSNate Lawson                  * However, this is an error -- primarily because the MS
56753289f6aSNate Lawson                  * interpreter can't handle a forward reference from the
56853289f6aSNate Lawson                  * Scope() operator.
56953289f6aSNate Lawson                  */
570fba7fc7eSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
571fba7fc7eSJung-uk Kim                     Op->Asl.ExternalName);
572fba7fc7eSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op,
573fba7fc7eSJung-uk Kim                     Op->Asl.ExternalName);
57453289f6aSNate Lawson                 goto FinishNode;
57553289f6aSNate Lawson             }
57653289f6aSNate Lawson 
57753289f6aSNate Lawson             AslCoreSubsystemError (Op, Status, "Failure from lookup\n", FALSE);
57853289f6aSNate Lawson             goto Exit;
57953289f6aSNate Lawson         }
58053289f6aSNate Lawson 
58153289f6aSNate Lawson         /* We found a node with this name, now check the type */
58253289f6aSNate Lawson 
58353289f6aSNate Lawson         switch (Node->Type)
58453289f6aSNate Lawson         {
58553289f6aSNate Lawson         case ACPI_TYPE_LOCAL_SCOPE:
58653289f6aSNate Lawson         case ACPI_TYPE_DEVICE:
58753289f6aSNate Lawson         case ACPI_TYPE_POWER:
58853289f6aSNate Lawson         case ACPI_TYPE_PROCESSOR:
58953289f6aSNate Lawson         case ACPI_TYPE_THERMAL:
59053289f6aSNate Lawson 
59153289f6aSNate Lawson             /* These are acceptable types - they all open a new scope */
59253289f6aSNate Lawson             break;
59353289f6aSNate Lawson 
59453289f6aSNate Lawson         case ACPI_TYPE_INTEGER:
59553289f6aSNate Lawson         case ACPI_TYPE_STRING:
59653289f6aSNate Lawson         case ACPI_TYPE_BUFFER:
59753289f6aSNate Lawson 
59853289f6aSNate Lawson             /*
599fba7fc7eSJung-uk Kim              * These types we will allow, but we will change the type.
600fba7fc7eSJung-uk Kim              * This enables some existing code of the form:
60153289f6aSNate Lawson              *
60253289f6aSNate Lawson              *  Name (DEB, 0)
60353289f6aSNate Lawson              *  Scope (DEB) { ... }
60453289f6aSNate Lawson              *
60553289f6aSNate Lawson              * Which is used to workaround the fact that the MS interpreter
60653289f6aSNate Lawson              * does not allow Scope() forward references.
60753289f6aSNate Lawson              */
608e0ef747bSNate Lawson             sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
60953289f6aSNate Lawson                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
61053289f6aSNate Lawson             AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
61153289f6aSNate Lawson 
612fba7fc7eSJung-uk Kim             /* Switch the type to scope, open the new scope */
613fba7fc7eSJung-uk Kim 
614e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
615fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
616fba7fc7eSJung-uk Kim                         WalkState);
617e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
618e0ef747bSNate Lawson             {
619e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
620e0ef747bSNate Lawson             }
62153289f6aSNate Lawson             break;
62253289f6aSNate Lawson 
62353289f6aSNate Lawson         default:
62453289f6aSNate Lawson 
625fba7fc7eSJung-uk Kim             /* All other types are an error */
626fba7fc7eSJung-uk Kim 
627fba7fc7eSJung-uk Kim             sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
628fba7fc7eSJung-uk Kim                 AcpiUtGetTypeName (Node->Type));
62953289f6aSNate Lawson             AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
63053289f6aSNate Lawson 
63153289f6aSNate Lawson             /*
63253289f6aSNate Lawson              * However, switch the type to be an actual scope so
63353289f6aSNate Lawson              * that compilation can continue without generating a whole
634e0ef747bSNate Lawson              * cascade of additional errors. Open the new scope.
63553289f6aSNate Lawson              */
636e0ef747bSNate Lawson             Node->Type = ACPI_TYPE_LOCAL_SCOPE;
637fba7fc7eSJung-uk Kim             Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
638fba7fc7eSJung-uk Kim                         WalkState);
639e0ef747bSNate Lawson             if (ACPI_FAILURE (Status))
640e0ef747bSNate Lawson             {
641e0ef747bSNate Lawson                 return_ACPI_STATUS (Status);
642e0ef747bSNate Lawson             }
64353289f6aSNate Lawson             break;
64453289f6aSNate Lawson         }
64553289f6aSNate Lawson 
64653289f6aSNate Lawson         Status = AE_OK;
64753289f6aSNate Lawson         goto FinishNode;
64853289f6aSNate Lawson 
64953289f6aSNate Lawson 
65053289f6aSNate Lawson     default:
65153289f6aSNate Lawson 
65253289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
65353289f6aSNate Lawson         break;
65453289f6aSNate Lawson     }
65553289f6aSNate Lawson 
65653289f6aSNate Lawson 
65753289f6aSNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
65853289f6aSNate Lawson             Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
65953289f6aSNate Lawson 
66053289f6aSNate Lawson     /* The name must not already exist */
66153289f6aSNate Lawson 
66253289f6aSNate Lawson     Flags |= ACPI_NS_ERROR_IF_FOUND;
66353289f6aSNate Lawson 
66453289f6aSNate Lawson     /*
66553289f6aSNate Lawson      * Enter the named type into the internal namespace. We enter the name
666fba7fc7eSJung-uk Kim      * as we go downward in the parse tree. Any necessary subobjects that
667fba7fc7eSJung-uk Kim      * involve arguments to the opcode must be created as we go back up the
668fba7fc7eSJung-uk Kim      * parse tree later.
66953289f6aSNate Lawson      */
67053289f6aSNate Lawson     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
6711a39cfb0SJung-uk Kim                     ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
67253289f6aSNate Lawson     if (ACPI_FAILURE (Status))
67353289f6aSNate Lawson     {
67453289f6aSNate Lawson         if (Status == AE_ALREADY_EXISTS)
67553289f6aSNate Lawson         {
67653289f6aSNate Lawson             /* The name already exists in this scope */
67753289f6aSNate Lawson 
67853289f6aSNate Lawson             if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
67953289f6aSNate Lawson             {
6801a39cfb0SJung-uk Kim                 /* Allow multiple references to the same scope */
6811a39cfb0SJung-uk Kim 
68253289f6aSNate Lawson                 Node->Type = (UINT8) ObjectType;
68353289f6aSNate Lawson                 Status = AE_OK;
68453289f6aSNate Lawson             }
685a9f12690SJung-uk Kim             else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
686a9f12690SJung-uk Kim                      (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
6871a39cfb0SJung-uk Kim             {
6881a39cfb0SJung-uk Kim                 /*
6891a39cfb0SJung-uk Kim                  * Allow one create on an object or segment that was
6901a39cfb0SJung-uk Kim                  * previously declared External
6911a39cfb0SJung-uk Kim                  */
6921a39cfb0SJung-uk Kim                 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
6931a39cfb0SJung-uk Kim                 Node->Type = (UINT8) ObjectType;
6941a39cfb0SJung-uk Kim 
6951a39cfb0SJung-uk Kim                 /* Just retyped a node, probably will need to open a scope */
6961a39cfb0SJung-uk Kim 
6971a39cfb0SJung-uk Kim                 if (AcpiNsOpensScope (ObjectType))
6981a39cfb0SJung-uk Kim                 {
6991a39cfb0SJung-uk Kim                     Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
7001a39cfb0SJung-uk Kim                     if (ACPI_FAILURE (Status))
7011a39cfb0SJung-uk Kim                     {
7021a39cfb0SJung-uk Kim                         return_ACPI_STATUS (Status);
7031a39cfb0SJung-uk Kim                     }
7041a39cfb0SJung-uk Kim                 }
7051a39cfb0SJung-uk Kim                 Status = AE_OK;
7061a39cfb0SJung-uk Kim             }
70753289f6aSNate Lawson             else
70853289f6aSNate Lawson             {
7091a39cfb0SJung-uk Kim                 /* Valid error, object already exists */
7101a39cfb0SJung-uk Kim 
711fba7fc7eSJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
712fba7fc7eSJung-uk Kim                     Op->Asl.ExternalName);
71353289f6aSNate Lawson                 Status = AE_OK;
71453289f6aSNate Lawson                 goto Exit;
71553289f6aSNate Lawson             }
71653289f6aSNate Lawson         }
71753289f6aSNate Lawson         else
71853289f6aSNate Lawson         {
719fba7fc7eSJung-uk Kim             AslCoreSubsystemError (Op, Status,
720fba7fc7eSJung-uk Kim                 "Failure from lookup %s\n", FALSE);
72153289f6aSNate Lawson             goto Exit;
72253289f6aSNate Lawson         }
72353289f6aSNate Lawson     }
72453289f6aSNate Lawson 
7251a39cfb0SJung-uk Kim     if (ForceNewScope)
7261a39cfb0SJung-uk Kim     {
7271a39cfb0SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
7281a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
7291a39cfb0SJung-uk Kim         {
7301a39cfb0SJung-uk Kim             return_ACPI_STATUS (Status);
7311a39cfb0SJung-uk Kim         }
7321a39cfb0SJung-uk Kim     }
73353289f6aSNate Lawson 
73453289f6aSNate Lawson FinishNode:
73553289f6aSNate Lawson     /*
73653289f6aSNate Lawson      * Point the parse node to the new namespace node, and point
73753289f6aSNate Lawson      * the Node back to the original Parse node
73853289f6aSNate Lawson      */
73953289f6aSNate Lawson     Op->Asl.Node = Node;
740fba7fc7eSJung-uk Kim     Node->Op = Op;
74153289f6aSNate Lawson 
74253289f6aSNate Lawson     /* Set the actual data type if appropriate (EXTERNAL term only) */
74353289f6aSNate Lawson 
74453289f6aSNate Lawson     if (ActualObjectType != ACPI_TYPE_ANY)
74553289f6aSNate Lawson     {
74653289f6aSNate Lawson         Node->Type = (UINT8) ActualObjectType;
747fba7fc7eSJung-uk Kim         Node->Value = ASL_EXTERNAL_METHOD;
74853289f6aSNate Lawson     }
74953289f6aSNate Lawson 
75053289f6aSNate Lawson     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
75153289f6aSNate Lawson     {
75253289f6aSNate Lawson         /*
753fba7fc7eSJung-uk Kim          * Get the method argument count from "Extra" and save
754fba7fc7eSJung-uk Kim          * it in the namespace node
75553289f6aSNate Lawson          */
756fba7fc7eSJung-uk Kim         Node->Value = (UINT32) Op->Asl.Extra;
75753289f6aSNate Lawson     }
75853289f6aSNate Lawson 
75953289f6aSNate Lawson Exit:
76053289f6aSNate Lawson     return (Status);
76153289f6aSNate Lawson }
76253289f6aSNate Lawson 
76353289f6aSNate Lawson 
76453289f6aSNate Lawson /*******************************************************************************
76553289f6aSNate Lawson  *
766a9f12690SJung-uk Kim  * FUNCTION:    LdNamespace2Begin
767a9f12690SJung-uk Kim  *
768a9f12690SJung-uk Kim  * PARAMETERS:  ASL_WALK_CALLBACK
769a9f12690SJung-uk Kim  *
770a9f12690SJung-uk Kim  * RETURN:      Status
771a9f12690SJung-uk Kim  *
772a9f12690SJung-uk Kim  * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
773a9f12690SJung-uk Kim  *              Second pass resolves some forward references.
774a9f12690SJung-uk Kim  *
775a9f12690SJung-uk Kim  * Notes:
776a9f12690SJung-uk Kim  * Currently only needs to handle the Alias operator.
777a9f12690SJung-uk Kim  * Could be used to allow forward references from the Scope() operator, but
778a9f12690SJung-uk Kim  * the MS interpreter does not allow this, so this compiler does not either.
779a9f12690SJung-uk Kim  *
780a9f12690SJung-uk Kim  ******************************************************************************/
781a9f12690SJung-uk Kim 
782a9f12690SJung-uk Kim static ACPI_STATUS
783a9f12690SJung-uk Kim LdNamespace2Begin (
784a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
785a9f12690SJung-uk Kim     UINT32                  Level,
786a9f12690SJung-uk Kim     void                    *Context)
787a9f12690SJung-uk Kim {
788a9f12690SJung-uk Kim     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
789a9f12690SJung-uk Kim     ACPI_STATUS             Status;
790a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
791a9f12690SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType;
792a9f12690SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
793a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Arg;
794a9f12690SJung-uk Kim     char                    *Path;
795a9f12690SJung-uk Kim     ACPI_NAMESPACE_NODE     *TargetNode;
796a9f12690SJung-uk Kim 
797a9f12690SJung-uk Kim 
798a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdNamespace2Begin);
799a9f12690SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
800a9f12690SJung-uk Kim         Op, Op->Asl.ParseOpName));
801a9f12690SJung-uk Kim 
802a9f12690SJung-uk Kim 
803a9f12690SJung-uk Kim     /* Ignore Ops with no namespace node */
804a9f12690SJung-uk Kim 
805a9f12690SJung-uk Kim     Node = Op->Asl.Node;
806a9f12690SJung-uk Kim     if (!Node)
807a9f12690SJung-uk Kim     {
808a9f12690SJung-uk Kim         return (AE_OK);
809a9f12690SJung-uk Kim     }
810a9f12690SJung-uk Kim 
811a9f12690SJung-uk Kim     /* Get the type to determine if we should push the scope */
812a9f12690SJung-uk Kim 
813a9f12690SJung-uk Kim     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
814a9f12690SJung-uk Kim         (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
815a9f12690SJung-uk Kim     {
816a9f12690SJung-uk Kim         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
817a9f12690SJung-uk Kim     }
818a9f12690SJung-uk Kim     else
819a9f12690SJung-uk Kim     {
820a9f12690SJung-uk Kim         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
821a9f12690SJung-uk Kim     }
822a9f12690SJung-uk Kim 
823a9f12690SJung-uk Kim     /* Push scope for Resource Templates */
824a9f12690SJung-uk Kim 
825a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
826a9f12690SJung-uk Kim     {
827a9f12690SJung-uk Kim         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
828a9f12690SJung-uk Kim         {
829a9f12690SJung-uk Kim             ForceNewScope = TRUE;
830a9f12690SJung-uk Kim         }
831a9f12690SJung-uk Kim     }
832a9f12690SJung-uk Kim 
833a9f12690SJung-uk Kim     /* Push the scope stack */
834a9f12690SJung-uk Kim 
835a9f12690SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
836a9f12690SJung-uk Kim     {
837a9f12690SJung-uk Kim         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
838a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
839a9f12690SJung-uk Kim         {
840a9f12690SJung-uk Kim             return_ACPI_STATUS (Status);
841a9f12690SJung-uk Kim         }
842a9f12690SJung-uk Kim     }
843a9f12690SJung-uk Kim 
844a9f12690SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
845a9f12690SJung-uk Kim     {
846a9f12690SJung-uk Kim         /* Complete the alias node by getting and saving the target node */
847a9f12690SJung-uk Kim 
848a9f12690SJung-uk Kim         /* First child is the alias target */
849a9f12690SJung-uk Kim 
850a9f12690SJung-uk Kim         Arg = Op->Asl.Child;
851a9f12690SJung-uk Kim 
852a9f12690SJung-uk Kim         /* Get the target pathname */
853a9f12690SJung-uk Kim 
854a9f12690SJung-uk Kim         Path = Arg->Asl.Namepath;
855a9f12690SJung-uk Kim         if (!Path)
856a9f12690SJung-uk Kim         {
857a9f12690SJung-uk Kim             Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
858a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
859a9f12690SJung-uk Kim             {
860a9f12690SJung-uk Kim                 return (Status);
861a9f12690SJung-uk Kim             }
862a9f12690SJung-uk Kim         }
863a9f12690SJung-uk Kim 
864a9f12690SJung-uk Kim         /* Get the NS node associated with the target. It must exist. */
865a9f12690SJung-uk Kim 
866a9f12690SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
867a9f12690SJung-uk Kim                     ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
868a9f12690SJung-uk Kim                     WalkState, &TargetNode);
869a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
870a9f12690SJung-uk Kim         {
871a9f12690SJung-uk Kim             if (Status == AE_NOT_FOUND)
872a9f12690SJung-uk Kim             {
873a9f12690SJung-uk Kim                 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
874a9f12690SJung-uk Kim                     Op->Asl.ExternalName);
875a9f12690SJung-uk Kim 
876a9f12690SJung-uk Kim                 /*
877a9f12690SJung-uk Kim                  * The name was not found, go ahead and create it.
878a9f12690SJung-uk Kim                  * This prevents more errors later.
879a9f12690SJung-uk Kim                  */
880a9f12690SJung-uk Kim                 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
881a9f12690SJung-uk Kim                             ACPI_TYPE_ANY,
882a9f12690SJung-uk Kim                             ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH,
883a9f12690SJung-uk Kim                             WalkState, &(Node));
884a9f12690SJung-uk Kim                 return (AE_OK);
885a9f12690SJung-uk Kim             }
886a9f12690SJung-uk Kim 
887a9f12690SJung-uk Kim             AslCoreSubsystemError (Op, Status, "Failure from lookup\n", FALSE);
888a9f12690SJung-uk Kim             return (AE_OK);
889a9f12690SJung-uk Kim         }
890a9f12690SJung-uk Kim 
891a9f12690SJung-uk Kim         /* Save the target node within the alias node */
892a9f12690SJung-uk Kim 
893a9f12690SJung-uk Kim         Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
894a9f12690SJung-uk Kim     }
895a9f12690SJung-uk Kim 
896a9f12690SJung-uk Kim     return (AE_OK);
897a9f12690SJung-uk Kim }
898a9f12690SJung-uk Kim 
899a9f12690SJung-uk Kim 
900a9f12690SJung-uk Kim /*******************************************************************************
901a9f12690SJung-uk Kim  *
902a9f12690SJung-uk Kim  * FUNCTION:    LdCommonNamespaceEnd
90353289f6aSNate Lawson  *
90453289f6aSNate Lawson  * PARAMETERS:  ASL_WALK_CALLBACK
90553289f6aSNate Lawson  *
90653289f6aSNate Lawson  * RETURN:      Status
90753289f6aSNate Lawson  *
90853289f6aSNate Lawson  * DESCRIPTION: Ascending callback used during the loading of the namespace,
90953289f6aSNate Lawson  *              We only need to worry about managing the scope stack here.
91053289f6aSNate Lawson  *
91153289f6aSNate Lawson  ******************************************************************************/
91253289f6aSNate Lawson 
913fba7fc7eSJung-uk Kim static ACPI_STATUS
914a9f12690SJung-uk Kim LdCommonNamespaceEnd (
91553289f6aSNate Lawson     ACPI_PARSE_OBJECT       *Op,
91653289f6aSNate Lawson     UINT32                  Level,
91753289f6aSNate Lawson     void                    *Context)
91853289f6aSNate Lawson {
91953289f6aSNate Lawson     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
92053289f6aSNate Lawson     ACPI_OBJECT_TYPE        ObjectType;
9211a39cfb0SJung-uk Kim     BOOLEAN                 ForceNewScope = FALSE;
92253289f6aSNate Lawson 
92353289f6aSNate Lawson 
924a9f12690SJung-uk Kim     ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
92553289f6aSNate Lawson 
92653289f6aSNate Lawson 
92753289f6aSNate Lawson     /* We are only interested in opcodes that have an associated name */
92853289f6aSNate Lawson 
92953289f6aSNate Lawson     if (!Op->Asl.Namepath)
93053289f6aSNate Lawson     {
93153289f6aSNate Lawson         return (AE_OK);
93253289f6aSNate Lawson     }
93353289f6aSNate Lawson 
93453289f6aSNate Lawson     /* Get the type to determine if we should pop the scope */
93553289f6aSNate Lawson 
93653289f6aSNate Lawson     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
93753289f6aSNate Lawson         (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
93853289f6aSNate Lawson     {
93953289f6aSNate Lawson         /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
94053289f6aSNate Lawson 
94153289f6aSNate Lawson         ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
94253289f6aSNate Lawson     }
94353289f6aSNate Lawson     else
94453289f6aSNate Lawson     {
94553289f6aSNate Lawson         ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
94653289f6aSNate Lawson     }
94753289f6aSNate Lawson 
9481a39cfb0SJung-uk Kim     /* Pop scope that was pushed for Resource Templates */
9491a39cfb0SJung-uk Kim 
9501a39cfb0SJung-uk Kim     if (Op->Asl.ParseOpcode == PARSEOP_NAME)
9511a39cfb0SJung-uk Kim     {
9521a39cfb0SJung-uk Kim         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
9531a39cfb0SJung-uk Kim         {
9541a39cfb0SJung-uk Kim             ForceNewScope = TRUE;
9551a39cfb0SJung-uk Kim         }
9561a39cfb0SJung-uk Kim     }
9571a39cfb0SJung-uk Kim 
95853289f6aSNate Lawson     /* Pop the scope stack */
95953289f6aSNate Lawson 
9601a39cfb0SJung-uk Kim     if (ForceNewScope || AcpiNsOpensScope (ObjectType))
96153289f6aSNate Lawson     {
96253289f6aSNate Lawson         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
96353289f6aSNate Lawson             "(%s): Popping scope for Op [%s] %p\n",
96453289f6aSNate Lawson             AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
96553289f6aSNate Lawson 
966fba7fc7eSJung-uk Kim         (void) AcpiDsScopeStackPop (WalkState);
96753289f6aSNate Lawson     }
96853289f6aSNate Lawson 
96953289f6aSNate Lawson     return (AE_OK);
97053289f6aSNate Lawson }
97153289f6aSNate Lawson 
97253289f6aSNate Lawson 
973