1 /******************************************************************************
3 * Module Name: dswload - Dispatcher namespace load callbacks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include <contrib/dev/acpica/include/amlcode.h>
154 #include <contrib/dev/acpica/include/acdispat.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
157 #include "aslcompiler.y.h"
159 #define _COMPONENT ACPI_COMPILER
160 ACPI_MODULE_NAME ("aslload")
162 /* Local prototypes */
165 LdLoadFieldElements (
166 ACPI_PARSE_OBJECT *Op,
167 ACPI_WALK_STATE *WalkState);
170 LdLoadResourceElements (
171 ACPI_PARSE_OBJECT *Op,
172 ACPI_WALK_STATE *WalkState);
176 ACPI_PARSE_OBJECT *Op,
182 ACPI_PARSE_OBJECT *Op,
187 LdCommonNamespaceEnd (
188 ACPI_PARSE_OBJECT *Op,
193 /*******************************************************************************
195 * FUNCTION: LdLoadNamespace
197 * PARAMETERS: RootOp - Root of the parse tree
201 * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
202 * named ASL/AML objects into the namespace. The namespace is
203 * constructed in order to resolve named references and references
204 * to named fields within resource templates/descriptors.
206 ******************************************************************************/
210 ACPI_PARSE_OBJECT *RootOp)
212 ACPI_WALK_STATE *WalkState;
215 /* Create a new walk state */
217 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
220 return (AE_NO_MEMORY);
223 /* Walk the entire parse tree, first pass */
225 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
226 LdCommonNamespaceEnd, WalkState);
228 /* Second pass to handle forward references */
230 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
231 LdCommonNamespaceEnd, WalkState);
233 /* Dump the namespace if debug is enabled */
235 AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
236 ACPI_FREE (WalkState);
241 /*******************************************************************************
243 * FUNCTION: LdLoadFieldElements
245 * PARAMETERS: Op - Parent node (Field)
246 * WalkState - Current walk state
250 * DESCRIPTION: Enter the named elements of the field (children of the parent)
251 * into the namespace.
253 ******************************************************************************/
256 LdLoadFieldElements (
257 ACPI_PARSE_OBJECT *Op,
258 ACPI_WALK_STATE *WalkState)
260 ACPI_PARSE_OBJECT *Child = NULL;
261 ACPI_NAMESPACE_NODE *Node;
265 /* Get the first named field element */
267 switch (Op->Asl.AmlOpcode)
269 case AML_BANK_FIELD_OP:
271 Child = UtGetArg (Op, 6);
274 case AML_INDEX_FIELD_OP:
276 Child = UtGetArg (Op, 5);
281 Child = UtGetArg (Op, 4);
286 /* No other opcodes should arrive here */
288 return (AE_BAD_PARAMETER);
291 /* Enter all elements into the namespace */
295 switch (Child->Asl.AmlOpcode)
297 case AML_INT_RESERVEDFIELD_OP:
298 case AML_INT_ACCESSFIELD_OP:
299 case AML_INT_CONNECTION_OP:
304 Status = AcpiNsLookup (WalkState->ScopeInfo,
305 Child->Asl.Value.String,
306 ACPI_TYPE_LOCAL_REGION_FIELD,
307 ACPI_IMODE_LOAD_PASS1,
308 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
309 ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
310 if (ACPI_FAILURE (Status))
312 if (Status != AE_ALREADY_EXISTS)
314 AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
315 Child->Asl.Value.String);
318 else if (Status == AE_ALREADY_EXISTS &&
319 (Node->Flags & ANOBJ_IS_EXTERNAL) &&
320 Node->OwnerId != WalkState->OwnerId)
322 Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
327 * The name already exists in this scope
328 * But continue processing the elements
330 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
331 Child->Asl.Value.String);
336 Child->Asl.Node = Node;
342 Child = Child->Asl.Next;
349 /*******************************************************************************
351 * FUNCTION: LdLoadResourceElements
353 * PARAMETERS: Op - Parent node (Resource Descriptor)
354 * WalkState - Current walk state
358 * DESCRIPTION: Enter the named elements of the resource descriptor (children
359 * of the parent) into the namespace.
361 * NOTE: In the real AML namespace, these named elements never exist. But
362 * we simply use the namespace here as a symbol table so we can look
363 * them up as they are referenced.
365 ******************************************************************************/
368 LdLoadResourceElements (
369 ACPI_PARSE_OBJECT *Op,
370 ACPI_WALK_STATE *WalkState)
372 ACPI_PARSE_OBJECT *InitializerOp = NULL;
373 ACPI_NAMESPACE_NODE *Node;
378 * Enter the resource name into the namespace. Name must not already exist.
379 * This opens a scope, so later field names are guaranteed to be new/unique.
381 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
382 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
383 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
385 if (ACPI_FAILURE (Status))
387 if (Status == AE_ALREADY_EXISTS)
389 /* Actual node causing the error was saved in ParentMethod */
391 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
392 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath);
398 Node->Value = (UINT32) Op->Asl.Value.Integer;
403 * Now enter the predefined fields, for easy lookup when referenced
406 InitializerOp = ASL_GET_CHILD_NODE (Op);
407 while (InitializerOp)
409 if (InitializerOp->Asl.ExternalName)
411 Status = AcpiNsLookup (WalkState->ScopeInfo,
412 InitializerOp->Asl.ExternalName,
413 ACPI_TYPE_LOCAL_RESOURCE_FIELD,
414 ACPI_IMODE_LOAD_PASS1,
415 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
417 if (ACPI_FAILURE (Status))
423 * Store the field offset and length in the namespace node
424 * so it can be used when the field is referenced
426 Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
427 Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
428 InitializerOp->Asl.Node = Node;
429 Node->Op = InitializerOp;
432 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
439 /*******************************************************************************
441 * FUNCTION: LdNamespace1Begin
443 * PARAMETERS: ASL_WALK_CALLBACK
447 * DESCRIPTION: Descending callback used during the parse tree walk. If this
448 * is a named AML opcode, enter into the namespace
450 ******************************************************************************/
454 ACPI_PARSE_OBJECT *Op,
458 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
459 ACPI_NAMESPACE_NODE *Node;
460 ACPI_PARSE_OBJECT *MethodOp;
462 ACPI_OBJECT_TYPE ObjectType;
463 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY;
465 UINT32 Flags = ACPI_NS_NO_UPSEARCH;
466 ACPI_PARSE_OBJECT *Arg;
468 BOOLEAN ForceNewScope = FALSE;
469 ACPI_OWNER_ID OwnerId = 0;
472 ACPI_FUNCTION_NAME (LdNamespace1Begin);
473 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
474 Op, Op->Asl.ParseOpName));
476 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)
479 * Allocate an OwnerId for this block. This helps identify the owners
480 * of each namespace node. This is used in determining whether if
481 * certain external declarations cause redefinition errors.
483 Status = AcpiUtAllocateOwnerId (&OwnerId);
484 WalkState->OwnerId = OwnerId;
485 if (ACPI_FAILURE (Status))
487 AslCoreSubsystemError (Op, Status,
488 "Failure to allocate owner ID to this definition block.", FALSE);
489 return_ACPI_STATUS (Status);
494 * We are only interested in opcodes that have an associated name
495 * (or multiple names)
497 switch (Op->Asl.AmlOpcode)
499 case AML_BANK_FIELD_OP:
500 case AML_INDEX_FIELD_OP:
503 Status = LdLoadFieldElements (Op, WalkState);
506 case AML_INT_CONNECTION_OP:
509 if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
515 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
516 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
518 if (ACPI_FAILURE (Status))
523 if (Node->Type == ACPI_TYPE_BUFFER)
525 Arg->Asl.Node = Node;
527 Arg = Node->Op->Asl.Child; /* Get namepath */
528 Arg = Arg->Asl.Next; /* Get actual buffer */
529 Arg = Arg->Asl.Child; /* Buffer length */
530 Arg = Arg->Asl.Next; /* RAW_DATA buffer */
536 /* All other opcodes go below */
541 /* Check if this object has already been installed in the namespace */
548 Path = Op->Asl.Namepath;
554 /* Map the raw opcode into an internal object type */
556 switch (Op->Asl.ParseOpcode)
560 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */
561 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */
564 * If this name refers to a ResourceTemplate, we will need to open
565 * a new scope so that the resource subfield names can be entered into
566 * the namespace underneath this name
568 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
570 ForceNewScope = TRUE;
573 /* Get the data type associated with the named object, not the name itself */
575 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
578 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
585 case PARSEOP_EXTERNAL:
587 * "External" simply enters a name and type into the namespace.
588 * We must be careful to not open a new scope, however, no matter
589 * what type the external name refers to (e.g., a method)
591 * first child is name, next child is ObjectType
593 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
594 ObjectType = ACPI_TYPE_ANY;
597 * We will mark every new node along the path as "External". This
598 * allows some or all of the nodes to be created later in the ASL
599 * code. Handles cases like this:
601 * External (\_SB_.PCI0.ABCD, IntObj)
610 * Store (\_SB_.PCI0.ABCD, Local0)
613 Flags |= ACPI_NS_EXTERNAL;
616 case PARSEOP_DEFAULT_ARG:
618 if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
620 Status = LdLoadResourceElements (Op, WalkState);
621 return_ACPI_STATUS (Status);
624 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
629 * The name referenced by Scope(Name) must already exist at this point.
630 * In other words, forward references for Scope() are not supported.
631 * The only real reason for this is that the MS interpreter cannot
632 * handle this case. Perhaps someday this case can go away.
634 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
635 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
637 if (ACPI_FAILURE (Status))
639 if (Status == AE_NOT_FOUND)
641 /* The name was not found, go ahead and create it */
643 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
644 ACPI_TYPE_LOCAL_SCOPE,
645 ACPI_IMODE_LOAD_PASS1, Flags,
647 if (ACPI_FAILURE (Status))
649 return_ACPI_STATUS (Status);
653 * However, this is an error -- primarily because the MS
654 * interpreter can't handle a forward reference from the
657 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
658 Op->Asl.ExternalName);
659 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op,
660 Op->Asl.ExternalName);
664 AslCoreSubsystemError (Op, Status,
665 "Failure from namespace lookup", FALSE);
667 return_ACPI_STATUS (Status);
669 else /* Status AE_OK */
672 * Do not allow references to external scopes from the DSDT.
673 * This is because the DSDT is always loaded first, and the
674 * external reference cannot be resolved -- causing a runtime
675 * error because Scope() must be resolved immediately.
678 if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
679 (ACPI_COMPARE_NAME (Gbl_TableSignature, "DSDT")))
681 /* However, allowed if the reference is within a method */
683 MethodOp = Op->Asl.Parent;
685 (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
687 MethodOp = MethodOp->Asl.Parent;
692 /* Not in a control method, error */
694 AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
699 /* We found a node with this name, now check the type */
703 case ACPI_TYPE_LOCAL_SCOPE:
704 case ACPI_TYPE_DEVICE:
705 case ACPI_TYPE_POWER:
706 case ACPI_TYPE_PROCESSOR:
707 case ACPI_TYPE_THERMAL:
709 /* These are acceptable types - they all open a new scope */
712 case ACPI_TYPE_INTEGER:
713 case ACPI_TYPE_STRING:
714 case ACPI_TYPE_BUFFER:
716 * These types we will allow, but we will change the type.
717 * This enables some existing code of the form:
720 * Scope (DEB) { ... }
722 * Which is used to workaround the fact that the MS interpreter
723 * does not allow Scope() forward references.
725 sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
726 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
727 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
729 /* Switch the type to scope, open the new scope */
731 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
732 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
734 if (ACPI_FAILURE (Status))
736 return_ACPI_STATUS (Status);
742 /* All other types are an error */
744 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
745 AcpiUtGetTypeName (Node->Type));
746 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
749 * However, switch the type to be an actual scope so
750 * that compilation can continue without generating a whole
751 * cascade of additional errors. Open the new scope.
753 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
754 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
756 if (ACPI_FAILURE (Status))
758 return_ACPI_STATUS (Status);
769 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
774 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
775 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
777 /* The name must not already exist */
779 Flags |= ACPI_NS_ERROR_IF_FOUND;
782 * Enter the named type into the internal namespace. We enter the name
783 * as we go downward in the parse tree. Any necessary subobjects that
784 * involve arguments to the opcode must be created as we go back up the
787 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
788 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
789 if (ACPI_FAILURE (Status))
791 if (Status == AE_ALREADY_EXISTS)
793 /* The name already exists in this scope */
795 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
797 /* Allow multiple references to the same scope */
799 Node->Type = (UINT8) ObjectType;
802 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
803 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
806 * Allow one create on an object or segment that was
807 * previously declared External only if WalkState->OwnerId and
808 * Node->OwnerId are found in different tables (meaning that
809 * they have differnt OwnerIds).
811 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
812 Node->Type = (UINT8) ObjectType;
814 /* Just retyped a node, probably will need to open a scope */
816 if (AcpiNsOpensScope (ObjectType))
818 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
819 if (ACPI_FAILURE (Status))
821 return_ACPI_STATUS (Status);
827 if (Node->OwnerId == WalkState->OwnerId &&
828 !(Node->Flags & IMPLICIT_EXTERNAL))
830 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
831 Op->Asl.ExternalName);
833 if (Node->Flags & IMPLICIT_EXTERNAL)
835 Node->Flags &= ~IMPLICIT_EXTERNAL;
838 else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
839 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
842 * Allow externals in same scope as the definition of the
843 * actual object. Similar to C. Allows multiple definition
844 * blocks that refer to each other in the same file. However,
845 * do not allow name declaration and an external declaration
846 * within the same table. This is considered a re-declaration.
850 if (Node->OwnerId == WalkState->OwnerId)
852 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
853 Op->Asl.ExternalName);
856 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
857 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
858 (ObjectType == ACPI_TYPE_ANY))
861 * Allow update of externals of unknown type.
862 * In the case that multiple definition blocks are being
863 * parsed, updating the OwnerId allows enables subsequent calls
864 * of this method to understand which table the most recent
865 * external declaration was seen. Without this OwnerId update,
866 * code like the following is allowed to compile:
868 * DefinitionBlock("externtest.aml", "DSDT", 0x02, "Intel", "Many", 0x00000001)
870 * External(ERRS,methodobj)
878 * DefinitionBlock("externtest.aml", "SSDT", 0x02, "Intel", "Many", 0x00000001)
882 * External(ERRS,methodobj)
889 Node->OwnerId = WalkState->OwnerId;
891 if (AcpiNsOpensScope (ActualObjectType))
893 Node->Type = (UINT8) ActualObjectType;
898 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
899 AcpiUtGetTypeName (Node->Type));
900 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
901 return_ACPI_STATUS (AE_OK);
906 /* Valid error, object already exists */
908 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
909 Op->Asl.ExternalName);
910 return_ACPI_STATUS (AE_OK);
915 AslCoreSubsystemError (Op, Status,
916 "Failure from namespace lookup", FALSE);
917 return_ACPI_STATUS (Status);
923 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
924 if (ACPI_FAILURE (Status))
926 return_ACPI_STATUS (Status);
932 * Point the parse node to the new namespace node, and point
933 * the Node back to the original Parse node
938 /* Set the actual data type if appropriate (EXTERNAL term only) */
940 if (ActualObjectType != ACPI_TYPE_ANY)
942 Node->Type = (UINT8) ActualObjectType;
943 Node->Value = ASL_EXTERNAL_METHOD;
946 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
949 * Get the method argument count from "Extra" and save
950 * it in the namespace node
952 Node->Value = (UINT32) Op->Asl.Extra;
955 return_ACPI_STATUS (Status);
959 /*******************************************************************************
961 * FUNCTION: LdNamespace2Begin
963 * PARAMETERS: ASL_WALK_CALLBACK
967 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
968 * Second pass resolves some forward references.
971 * Currently only needs to handle the Alias operator.
972 * Could be used to allow forward references from the Scope() operator, but
973 * the MS interpreter does not allow this, so this compiler does not either.
975 ******************************************************************************/
979 ACPI_PARSE_OBJECT *Op,
983 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
985 ACPI_NAMESPACE_NODE *Node;
986 ACPI_OBJECT_TYPE ObjectType;
987 BOOLEAN ForceNewScope = FALSE;
988 ACPI_PARSE_OBJECT *Arg;
990 ACPI_NAMESPACE_NODE *TargetNode;
993 ACPI_FUNCTION_NAME (LdNamespace2Begin);
994 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
995 Op, Op->Asl.ParseOpName));
998 /* Ignore Ops with no namespace node */
1000 Node = Op->Asl.Node;
1006 /* Get the type to determine if we should push the scope */
1008 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1009 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1011 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1015 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1018 /* Push scope for Resource Templates */
1020 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1022 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1024 ForceNewScope = TRUE;
1028 /* Push the scope stack */
1030 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1032 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1033 if (ACPI_FAILURE (Status))
1035 return_ACPI_STATUS (Status);
1039 if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1041 /* Complete the alias node by getting and saving the target node */
1043 /* First child is the alias target */
1045 Arg = Op->Asl.Child;
1047 /* Get the target pathname */
1049 Path = Arg->Asl.Namepath;
1052 Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1053 if (ACPI_FAILURE (Status))
1059 /* Get the NS node associated with the target. It must exist. */
1061 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1062 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1063 WalkState, &TargetNode);
1064 if (ACPI_FAILURE (Status))
1066 if (Status == AE_NOT_FOUND)
1068 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1069 Op->Asl.ExternalName);
1072 * The name was not found, go ahead and create it.
1073 * This prevents more errors later.
1075 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1077 ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH,
1078 WalkState, &(Node));
1082 AslCoreSubsystemError (Op, Status,
1083 "Failure from namespace lookup", FALSE);
1087 /* Save the target node within the alias node */
1089 Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1096 /*******************************************************************************
1098 * FUNCTION: LdCommonNamespaceEnd
1100 * PARAMETERS: ASL_WALK_CALLBACK
1104 * DESCRIPTION: Ascending callback used during the loading of the namespace,
1105 * We only need to worry about managing the scope stack here.
1107 ******************************************************************************/
1110 LdCommonNamespaceEnd (
1111 ACPI_PARSE_OBJECT *Op,
1115 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1116 ACPI_OBJECT_TYPE ObjectType;
1117 BOOLEAN ForceNewScope = FALSE;
1120 ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1123 /* We are only interested in opcodes that have an associated name */
1125 if (!Op->Asl.Namepath)
1130 /* Get the type to determine if we should pop the scope */
1132 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1133 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1135 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1137 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1141 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1144 /* Pop scope that was pushed for Resource Templates */
1146 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1148 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1150 ForceNewScope = TRUE;
1154 /* Pop the scope stack */
1156 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1158 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1159 "(%s): Popping scope for Op [%s] %p\n",
1160 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1162 (void) AcpiDsScopeStackPop (WalkState);