1 /******************************************************************************
3 * Module Name: dswload - Dispatcher namespace load callbacks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, 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 "aslcompiler.h"
154 #include "acdispat.h"
155 #include "acnamesp.h"
156 #include "acparser.h"
157 #include "aslcompiler.y.h"
160 #define _COMPONENT ACPI_COMPILER
161 ACPI_MODULE_NAME ("aslload")
163 /* Local prototypes */
166 LdLoadFieldElements (
167 ACPI_PARSE_OBJECT *Op,
168 ACPI_WALK_STATE *WalkState);
171 LdLoadResourceElements (
172 ACPI_PARSE_OBJECT *Op,
173 ACPI_WALK_STATE *WalkState);
177 ACPI_PARSE_OBJECT *Op,
183 ACPI_PARSE_OBJECT *Op,
188 LdCommonNamespaceEnd (
189 ACPI_PARSE_OBJECT *Op,
194 /*******************************************************************************
196 * FUNCTION: LdLoadNamespace
198 * PARAMETERS: RootOp - Root of the parse tree
202 * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
203 * named ASL/AML objects into the namespace. The namespace is
204 * constructed in order to resolve named references and references
205 * to named fields within resource templates/descriptors.
207 ******************************************************************************/
211 ACPI_PARSE_OBJECT *RootOp)
213 ACPI_WALK_STATE *WalkState;
216 /* Create a new walk state */
218 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
221 return (AE_NO_MEMORY);
224 /* Walk the entire parse tree, first pass */
226 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
227 LdCommonNamespaceEnd, WalkState);
229 /* Second pass to handle forward references */
231 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
232 LdCommonNamespaceEnd, WalkState);
234 /* Dump the namespace if debug is enabled */
236 if (AcpiDbgLevel & ACPI_LV_TABLES)
238 AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
241 ACPI_FREE (WalkState);
246 /*******************************************************************************
248 * FUNCTION: LdLoadFieldElements
250 * PARAMETERS: Op - Parent node (Field)
251 * WalkState - Current walk state
255 * DESCRIPTION: Enter the named elements of the field (children of the parent)
256 * into the namespace.
258 ******************************************************************************/
261 LdLoadFieldElements (
262 ACPI_PARSE_OBJECT *Op,
263 ACPI_WALK_STATE *WalkState)
265 ACPI_PARSE_OBJECT *Child = NULL;
266 ACPI_NAMESPACE_NODE *Node;
270 /* Get the first named field element */
272 switch (Op->Asl.AmlOpcode)
274 case AML_BANK_FIELD_OP:
276 Child = UtGetArg (Op, 6);
279 case AML_INDEX_FIELD_OP:
281 Child = UtGetArg (Op, 5);
286 Child = UtGetArg (Op, 4);
291 /* No other opcodes should arrive here */
293 return (AE_BAD_PARAMETER);
296 /* Enter all elements into the namespace */
300 switch (Child->Asl.AmlOpcode)
302 case AML_INT_RESERVEDFIELD_OP:
303 case AML_INT_ACCESSFIELD_OP:
304 case AML_INT_CONNECTION_OP:
309 Status = AcpiNsLookup (WalkState->ScopeInfo,
310 Child->Asl.Value.String,
311 ACPI_TYPE_LOCAL_REGION_FIELD,
312 ACPI_IMODE_LOAD_PASS1,
313 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
314 ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
315 if (ACPI_FAILURE (Status))
317 if (Status != AE_ALREADY_EXISTS)
319 AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
320 Child->Asl.Value.String);
323 else if (Status == AE_ALREADY_EXISTS &&
324 (Node->Flags & ANOBJ_IS_EXTERNAL))
326 Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
327 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
332 * The name already exists in this scope
333 * But continue processing the elements
335 AslDualParseOpError (ASL_WARNING, ASL_MSG_NAME_EXISTS, Child,
336 Child->Asl.Value.String, ASL_MSG_FOUND_HERE, Node->Op,
337 Node->Op->Asl.ExternalName);
342 Child->Asl.Node = Node;
348 Child = Child->Asl.Next;
355 /*******************************************************************************
357 * FUNCTION: LdLoadResourceElements
359 * PARAMETERS: Op - Parent node (Resource Descriptor)
360 * WalkState - Current walk state
364 * DESCRIPTION: Enter the named elements of the resource descriptor (children
365 * of the parent) into the namespace.
367 * NOTE: In the real AML namespace, these named elements never exist. But
368 * we simply use the namespace here as a symbol table so we can look
369 * them up as they are referenced.
371 ******************************************************************************/
374 LdLoadResourceElements (
375 ACPI_PARSE_OBJECT *Op,
376 ACPI_WALK_STATE *WalkState)
378 ACPI_PARSE_OBJECT *InitializerOp = NULL;
379 ACPI_NAMESPACE_NODE *Node;
384 * Enter the resource name into the namespace. Name must not already exist.
385 * This opens a scope, so later field names are guaranteed to be new/unique.
387 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
388 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
389 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
391 if (ACPI_FAILURE (Status))
393 if (Status == AE_ALREADY_EXISTS)
395 /* Actual node causing the error was saved in ParentMethod */
397 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
398 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
399 Op->Asl.Namepath, ASL_MSG_FOUND_HERE, Node->Op,
400 Node->Op->Asl.ExternalName);
406 Node->Value = (UINT32) Op->Asl.Value.Integer;
411 * Now enter the predefined fields, for easy lookup when referenced
414 InitializerOp = ASL_GET_CHILD_NODE (Op);
415 while (InitializerOp)
417 if (InitializerOp->Asl.ExternalName)
419 Status = AcpiNsLookup (WalkState->ScopeInfo,
420 InitializerOp->Asl.ExternalName,
421 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
422 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
423 if (ACPI_FAILURE (Status))
429 * Store the field offset and length in the namespace node
430 * so it can be used when the field is referenced
432 Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
433 Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
434 InitializerOp->Asl.Node = Node;
435 Node->Op = InitializerOp;
438 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
445 /*******************************************************************************
447 * FUNCTION: LdNamespace1Begin
449 * PARAMETERS: ASL_WALK_CALLBACK
453 * DESCRIPTION: Descending callback used during the parse tree walk. If this
454 * is a named AML opcode, enter into the namespace
456 ******************************************************************************/
460 ACPI_PARSE_OBJECT *Op,
464 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
465 ACPI_NAMESPACE_NODE *Node;
466 ACPI_PARSE_OBJECT *MethodOp;
468 ACPI_OBJECT_TYPE ObjectType;
469 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY;
471 UINT32 Flags = ACPI_NS_NO_UPSEARCH;
472 ACPI_PARSE_OBJECT *Arg;
474 BOOLEAN ForceNewScope = FALSE;
475 const ACPI_OPCODE_INFO *OpInfo;
476 ACPI_PARSE_OBJECT *ParentOp;
479 ACPI_FUNCTION_NAME (LdNamespace1Begin);
482 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
483 Op, Op->Asl.ParseOpName));
486 * We are only interested in opcodes that have an associated name
487 * (or multiple names)
489 switch (Op->Asl.AmlOpcode)
491 case AML_BANK_FIELD_OP:
492 case AML_INDEX_FIELD_OP:
495 Status = LdLoadFieldElements (Op, WalkState);
498 case AML_INT_CONNECTION_OP:
501 if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
507 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
508 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
510 if (ACPI_FAILURE (Status))
515 if (Node->Type == ACPI_TYPE_BUFFER)
517 Arg->Asl.Node = Node;
519 Arg = Node->Op->Asl.Child; /* Get namepath */
520 Arg = Arg->Asl.Next; /* Get actual buffer */
521 Arg = Arg->Asl.Child; /* Buffer length */
522 Arg = Arg->Asl.Next; /* RAW_DATA buffer */
528 /* All other opcodes go below */
533 /* Check if this object has already been installed in the namespace */
540 /* Check for a possible illegal forward reference */
542 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
543 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
546 * Op->Asl.Namepath will be NULL for these opcodes.
547 * These opcodes are guaranteed to have a parent.
548 * Examine the parent opcode.
551 ParentOp = Op->Asl.Parent;
552 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
555 * Exclude all operators that actually declare a new name:
556 * Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
557 * We only want references to named objects:
558 * Store (2, WXYZ) -> Attempt to resolve the name
560 if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) &&
561 (OpInfo->Type != AML_TYPE_NAMED_FIELD))
567 * Check if the referenced object exists at this point during
569 * 1) If it exists, then this cannot be a forward reference.
570 * 2) If it does not exist, it could be a forward reference or
571 * it truly does not exist (and no external declaration).
573 Status = AcpiNsLookup (WalkState->ScopeInfo,
574 Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
575 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
577 if (Status == AE_NOT_FOUND)
580 * This is either a forward reference or the object truly
581 * does not exist. The two cases can only be differentiated
582 * during the cross-reference stage later. Mark the Op/Name
583 * as not-found for now to indicate the need for further
586 * Special case: Allow forward references from elements of
587 * Package objects. This provides compatibility with other
588 * ACPI implementations. To correctly implement this, the
589 * ACPICA table load defers package resolution until the entire
590 * namespace has been loaded.
592 if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
593 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
595 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
604 Path = Op->Asl.Namepath;
610 /* Map the raw opcode into an internal object type */
612 switch (Op->Asl.ParseOpcode)
616 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */
617 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */
620 * If this name refers to a ResourceTemplate, we will need to open
621 * a new scope so that the resource subfield names can be entered into
622 * the namespace underneath this name
624 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
626 ForceNewScope = TRUE;
629 /* Get the data type associated with the named object, not the name itself */
631 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
634 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
640 case PARSEOP_EXTERNAL:
642 * "External" simply enters a name and type into the namespace.
643 * We must be careful to not open a new scope, however, no matter
644 * what type the external name refers to (e.g., a method)
646 * first child is name, next child is ObjectType
648 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
649 ObjectType = ACPI_TYPE_ANY;
652 * We will mark every new node along the path as "External". This
653 * allows some or all of the nodes to be created later in the ASL
654 * code. Handles cases like this:
656 * External (\_SB_.PCI0.ABCD, IntObj)
665 * Store (\_SB_.PCI0.ABCD, Local0)
668 Flags |= ACPI_NS_EXTERNAL;
671 case PARSEOP_DEFAULT_ARG:
673 if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
675 Status = LdLoadResourceElements (Op, WalkState);
676 return_ACPI_STATUS (Status);
679 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
684 * The name referenced by Scope(Name) must already exist at this point.
685 * In other words, forward references for Scope() are not supported.
686 * The only real reason for this is that the MS interpreter cannot
687 * handle this case. Perhaps someday this case can go away.
689 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
690 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
691 if (ACPI_FAILURE (Status))
693 if (Status == AE_NOT_FOUND)
695 /* The name was not found, go ahead and create it */
697 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
698 ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
699 Flags, WalkState, &Node);
700 if (ACPI_FAILURE (Status))
702 return_ACPI_STATUS (Status);
705 /* However, this is an error -- operand to Scope must exist */
707 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
709 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
710 Op->Asl.ExternalName);
714 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
715 Op->Asl.ExternalName);
721 AslCoreSubsystemError (Op, Status,
722 "Failure from namespace lookup", FALSE);
724 return_ACPI_STATUS (Status);
726 else /* Status AE_OK */
729 * Do not allow references to external scopes from the DSDT.
730 * This is because the DSDT is always loaded first, and the
731 * external reference cannot be resolved -- causing a runtime
732 * error because Scope() must be resolved immediately.
735 if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
736 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
738 /* However, allowed if the reference is within a method */
740 MethodOp = Op->Asl.Parent;
742 (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
744 MethodOp = MethodOp->Asl.Parent;
749 /* Not in a control method, error */
751 AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
756 /* We found a node with this name, now check the type */
760 case ACPI_TYPE_LOCAL_SCOPE:
761 case ACPI_TYPE_DEVICE:
762 case ACPI_TYPE_POWER:
763 case ACPI_TYPE_PROCESSOR:
764 case ACPI_TYPE_THERMAL:
766 /* These are acceptable types - they all open a new scope */
769 case ACPI_TYPE_INTEGER:
770 case ACPI_TYPE_STRING:
771 case ACPI_TYPE_BUFFER:
773 * These types we will allow, but we will change the type.
774 * This enables some existing code of the form:
777 * Scope (DEB) { ... }
779 * Which is used to workaround the fact that the MS interpreter
780 * does not allow Scope() forward references.
782 sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
783 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
784 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
786 /* Switch the type to scope, open the new scope */
788 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
789 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
791 if (ACPI_FAILURE (Status))
793 return_ACPI_STATUS (Status);
799 /* All other types are an error */
801 sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
802 AcpiUtGetTypeName (Node->Type));
803 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
806 * However, switch the type to be an actual scope so
807 * that compilation can continue without generating a whole
808 * cascade of additional errors. Open the new scope.
810 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
811 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
813 if (ACPI_FAILURE (Status))
815 return_ACPI_STATUS (Status);
825 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
829 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
830 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
832 /* The name must not already exist */
834 Flags |= ACPI_NS_ERROR_IF_FOUND;
837 * For opcodes that enter new names into the namespace,
838 * all prefix NameSegs must exist.
840 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
841 if (((WalkState->OpInfo->Flags & AML_NAMED) ||
842 (WalkState->OpInfo->Flags & AML_CREATE)) &&
843 (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
845 Flags |= ACPI_NS_PREFIX_MUST_EXIST;
849 * Enter the named type into the internal namespace. We enter the name
850 * as we go downward in the parse tree. Any necessary subobjects that
851 * involve arguments to the opcode must be created as we go back up the
854 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
855 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
856 if (ACPI_FAILURE (Status))
858 if (Status == AE_ALREADY_EXISTS)
860 /* The name already exists in this scope */
862 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
864 /* Allow multiple references to the same scope */
866 Node->Type = (UINT8) ObjectType;
869 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
870 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
873 * Allow one create on an object or segment that was
874 * previously declared External
876 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
877 Node->Type = (UINT8) ObjectType;
879 /* Just retyped a node, probably will need to open a scope */
881 if (AcpiNsOpensScope (ObjectType))
883 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
884 if (ACPI_FAILURE (Status))
886 return_ACPI_STATUS (Status);
892 else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
893 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
896 * Allow externals in same scope as the definition of the
897 * actual object. Similar to C. Allows multiple definition
898 * blocks that refer to each other in the same file.
902 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
903 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
904 (ObjectType == ACPI_TYPE_ANY))
906 /* Allow update of externals of unknown type. */
908 if (AcpiNsOpensScope (ActualObjectType))
910 Node->Type = (UINT8) ActualObjectType;
915 sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
916 AcpiUtGetTypeName (Node->Type));
917 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
918 return_ACPI_STATUS (AE_OK);
923 /* Valid error, object already exists */
925 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
926 Op->Asl.ExternalName, ASL_MSG_FOUND_HERE, Node->Op,
927 Node->Op->Asl.ExternalName);
928 return_ACPI_STATUS (AE_OK);
931 else if (AE_NOT_FOUND)
934 * One or more prefix NameSegs of the NamePath do not exist
935 * (all of them must exist). Attempt to continue compilation
936 * by setting the current scope to the root.
938 Node = AcpiGbl_RootNode;
943 /* Flag all other errors as coming from the ACPICA core */
945 AslCoreSubsystemError (Op, Status,
946 "Failure from namespace lookup", FALSE);
947 return_ACPI_STATUS (Status);
953 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
954 if (ACPI_FAILURE (Status))
956 return_ACPI_STATUS (Status);
962 * Point the parse node to the new namespace node, and point
963 * the Node back to the original Parse node
968 /* Set the actual data type if appropriate (EXTERNAL term only) */
970 if (ActualObjectType != ACPI_TYPE_ANY)
972 Node->Type = (UINT8) ActualObjectType;
973 Node->Value = ASL_EXTERNAL_METHOD;
976 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
979 * Get the method argument count from "Extra" and save
980 * it in the namespace node
982 Node->Value = (UINT32) Op->Asl.Extra;
985 return_ACPI_STATUS (Status);
989 /*******************************************************************************
991 * FUNCTION: LdNamespace2Begin
993 * PARAMETERS: ASL_WALK_CALLBACK
997 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
998 * Second pass resolves some forward references.
1001 * Currently only needs to handle the Alias operator.
1002 * Could be used to allow forward references from the Scope() operator, but
1003 * the MS interpreter does not allow this, so this compiler does not either.
1005 ******************************************************************************/
1009 ACPI_PARSE_OBJECT *Op,
1013 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1015 ACPI_NAMESPACE_NODE *Node;
1016 ACPI_OBJECT_TYPE ObjectType;
1017 BOOLEAN ForceNewScope = FALSE;
1018 ACPI_PARSE_OBJECT *Arg;
1020 ACPI_NAMESPACE_NODE *TargetNode;
1023 ACPI_FUNCTION_NAME (LdNamespace2Begin);
1024 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1025 Op, Op->Asl.ParseOpName));
1028 /* Ignore Ops with no namespace node */
1030 Node = Op->Asl.Node;
1036 /* Get the type to determine if we should push the scope */
1038 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1039 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1041 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1045 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1048 /* Push scope for Resource Templates */
1050 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1052 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1054 ForceNewScope = TRUE;
1058 /* Push the scope stack */
1060 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1062 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1063 if (ACPI_FAILURE (Status))
1065 return_ACPI_STATUS (Status);
1069 if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1072 * Complete the alias node by getting and saving the target node.
1073 * First child is the alias target
1075 Arg = Op->Asl.Child;
1077 /* Get the target pathname */
1079 Path = Arg->Asl.Namepath;
1082 Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1083 if (ACPI_FAILURE (Status))
1089 /* Get the NS node associated with the target. It must exist. */
1091 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1092 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1093 WalkState, &TargetNode);
1094 if (ACPI_FAILURE (Status))
1096 if (Status == AE_NOT_FOUND)
1098 /* Standalone NameSeg vs. NamePath */
1100 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
1102 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1103 Arg->Asl.ExternalName);
1107 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
1108 Arg->Asl.ExternalName);
1113 * NOTE: Removed 10/2018 to enhance compiler error reporting. No
1117 * The name was not found, go ahead and create it.
1118 * This prevents more errors later.
1120 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1121 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
1122 ACPI_NS_NO_UPSEARCH, WalkState, &Node);
1125 /* Removed: return (AE_OK)*/
1128 AslCoreSubsystemError (Op, Status,
1129 "Failure from namespace lookup", FALSE);
1133 /* Save the target node within the alias node */
1135 Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1142 /*******************************************************************************
1144 * FUNCTION: LdCommonNamespaceEnd
1146 * PARAMETERS: ASL_WALK_CALLBACK
1150 * DESCRIPTION: Ascending callback used during the loading of the namespace,
1151 * We only need to worry about managing the scope stack here.
1153 ******************************************************************************/
1156 LdCommonNamespaceEnd (
1157 ACPI_PARSE_OBJECT *Op,
1161 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1162 ACPI_OBJECT_TYPE ObjectType;
1163 BOOLEAN ForceNewScope = FALSE;
1166 ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1169 /* We are only interested in opcodes that have an associated name */
1171 if (!Op->Asl.Namepath)
1176 /* Get the type to determine if we should pop the scope */
1178 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1179 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1181 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1183 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1187 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1190 /* Pop scope that was pushed for Resource Templates */
1192 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1194 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1196 ForceNewScope = TRUE;
1200 /* Pop the scope stack */
1202 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1204 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1205 "(%s): Popping scope for Op [%s] %p\n",
1206 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1208 (void) AcpiDsScopeStackPop (WalkState);