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 <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>
156 #include <contrib/dev/acpica/include/acparser.h>
157 #include "aslcompiler.y.h"
160 #define _COMPONENT ACPI_COMPILER
161 ACPI_MODULE_NAME ("aslload")
163 /* Local prototypes */
166 LdLoadFieldElements (
168 ACPI_PARSE_OBJECT *Op,
169 ACPI_WALK_STATE *WalkState);
172 LdLoadResourceElements (
173 ACPI_PARSE_OBJECT *Op,
174 ACPI_WALK_STATE *WalkState);
178 ACPI_PARSE_OBJECT *Op,
184 ACPI_PARSE_OBJECT *Op,
189 LdCommonNamespaceEnd (
190 ACPI_PARSE_OBJECT *Op,
195 LdCheckSpecialNames (
196 ACPI_NAMESPACE_NODE *Node,
197 ACPI_PARSE_OBJECT *Op);
199 /*******************************************************************************
201 * FUNCTION: LdLoadNamespace
203 * PARAMETERS: RootOp - Root of the parse tree
207 * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the
208 * named ASL/AML objects into the namespace. The namespace is
209 * constructed in order to resolve named references and references
210 * to named fields within resource templates/descriptors.
212 ******************************************************************************/
216 ACPI_PARSE_OBJECT *RootOp)
218 ACPI_WALK_STATE *WalkState;
221 /* Create a new walk state */
223 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
226 return (AE_NO_MEMORY);
229 /* Walk the entire parse tree, first pass */
231 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin,
232 LdCommonNamespaceEnd, WalkState);
234 /* Second pass to handle forward references */
236 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin,
237 LdCommonNamespaceEnd, WalkState);
239 /* Dump the namespace if debug is enabled */
241 if (AcpiDbgLevel & ACPI_LV_TABLES)
243 AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX);
246 ACPI_FREE (WalkState);
251 /*******************************************************************************
253 * FUNCTION: LdLoadFieldElements
255 * PARAMETERS: AmlType - Type to search
256 * Op - Parent node (Field)
257 * WalkState - Current walk state
261 * DESCRIPTION: Enter the named elements of the field (children of the parent)
262 * into the namespace.
264 ******************************************************************************/
267 LdLoadFieldElements (
269 ACPI_PARSE_OBJECT *Op,
270 ACPI_WALK_STATE *WalkState)
272 ACPI_PARSE_OBJECT *Child = NULL;
273 ACPI_PARSE_OBJECT *SourceRegion;
274 ACPI_NAMESPACE_NODE *Node;
278 SourceRegion = UtGetArg (Op, 0);
281 Status = AcpiNsLookup (WalkState->ScopeInfo,
282 SourceRegion->Asl.Value.String,
283 AmlType, ACPI_IMODE_EXECUTE,
284 ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
285 if (Status == AE_NOT_FOUND)
288 * If the named object is not found, it means that it is either a
289 * forward reference or the named object does not exist.
291 SourceRegion->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
295 /* Get the first named field element */
297 switch (Op->Asl.AmlOpcode)
299 case AML_BANK_FIELD_OP:
301 Child = UtGetArg (Op, 6);
304 case AML_INDEX_FIELD_OP:
306 Child = UtGetArg (Op, 5);
311 Child = UtGetArg (Op, 4);
316 /* No other opcodes should arrive here */
318 return (AE_BAD_PARAMETER);
321 /* Enter all elements into the namespace */
325 switch (Child->Asl.AmlOpcode)
327 case AML_INT_RESERVEDFIELD_OP:
328 case AML_INT_ACCESSFIELD_OP:
329 case AML_INT_CONNECTION_OP:
334 Status = AcpiNsLookup (WalkState->ScopeInfo,
335 Child->Asl.Value.String,
336 ACPI_TYPE_LOCAL_REGION_FIELD,
337 ACPI_IMODE_LOAD_PASS1,
338 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
339 ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
340 if (ACPI_FAILURE (Status))
342 if (Status != AE_ALREADY_EXISTS)
344 AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child,
345 Child->Asl.Value.String);
348 else if (Status == AE_ALREADY_EXISTS &&
349 (Node->Flags & ANOBJ_IS_EXTERNAL))
351 Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD;
352 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
357 * The name already exists in this scope
358 * But continue processing the elements
360 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
361 Child->Asl.Value.String, ASL_MSG_FOUND_HERE, Node->Op,
362 Node->Op->Asl.ExternalName);
367 Child->Asl.Node = Node;
373 Child = Child->Asl.Next;
380 /*******************************************************************************
382 * FUNCTION: LdLoadResourceElements
384 * PARAMETERS: Op - Parent node (Resource Descriptor)
385 * WalkState - Current walk state
389 * DESCRIPTION: Enter the named elements of the resource descriptor (children
390 * of the parent) into the namespace.
392 * NOTE: In the real AML namespace, these named elements never exist. But
393 * we simply use the namespace here as a symbol table so we can look
394 * them up as they are referenced.
396 ******************************************************************************/
399 LdLoadResourceElements (
400 ACPI_PARSE_OBJECT *Op,
401 ACPI_WALK_STATE *WalkState)
403 ACPI_PARSE_OBJECT *InitializerOp = NULL;
404 ACPI_NAMESPACE_NODE *Node;
409 * Enter the resource name into the namespace. Name must not already exist.
410 * This opens a scope, so later field names are guaranteed to be new/unique.
412 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
413 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
414 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
416 if (ACPI_FAILURE (Status))
418 if (Status == AE_ALREADY_EXISTS)
420 /* Actual node causing the error was saved in ParentMethod */
422 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
423 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod,
424 Op->Asl.Namepath, ASL_MSG_FOUND_HERE, Node->Op,
425 Node->Op->Asl.ExternalName);
431 Node->Value = (UINT32) Op->Asl.Value.Integer;
436 * Now enter the predefined fields, for easy lookup when referenced
439 InitializerOp = ASL_GET_CHILD_NODE (Op);
440 while (InitializerOp)
442 if (InitializerOp->Asl.ExternalName)
444 Status = AcpiNsLookup (WalkState->ScopeInfo,
445 InitializerOp->Asl.ExternalName,
446 ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1,
447 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
448 if (ACPI_FAILURE (Status))
454 * Store the field offset and length in the namespace node
455 * so it can be used when the field is referenced
457 Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
458 Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
459 InitializerOp->Asl.Node = Node;
460 Node->Op = InitializerOp;
463 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
470 /*******************************************************************************
472 * FUNCTION: LdNamespace1Begin
474 * PARAMETERS: ASL_WALK_CALLBACK
478 * DESCRIPTION: Descending callback used during the parse tree walk. If this
479 * is a named AML opcode, enter into the namespace
481 ******************************************************************************/
485 ACPI_PARSE_OBJECT *Op,
489 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
490 ACPI_NAMESPACE_NODE *Node;
491 ACPI_PARSE_OBJECT *MethodOp;
493 ACPI_OBJECT_TYPE ObjectType;
494 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY;
496 UINT32 Flags = ACPI_NS_NO_UPSEARCH;
497 ACPI_PARSE_OBJECT *Arg;
499 BOOLEAN ForceNewScope = FALSE;
500 const ACPI_OPCODE_INFO *OpInfo;
501 ACPI_PARSE_OBJECT *ParentOp;
504 ACPI_FUNCTION_NAME (LdNamespace1Begin);
507 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
508 Op, Op->Asl.ParseOpName));
511 * We are only interested in opcodes that have an associated name
512 * (or multiple names)
514 switch (Op->Asl.AmlOpcode)
516 case AML_INDEX_FIELD_OP:
518 Status = LdLoadFieldElements (ACPI_TYPE_LOCAL_REGION_FIELD, Op, WalkState);
521 case AML_BANK_FIELD_OP:
524 Status = LdLoadFieldElements (ACPI_TYPE_REGION, Op, WalkState);
527 case AML_INT_CONNECTION_OP:
529 if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
535 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
536 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
538 if (ACPI_FAILURE (Status))
547 /* All other opcodes go below */
552 /* Check if this object has already been installed in the namespace */
559 /* Check for a possible illegal forward reference */
561 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
562 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
565 * Op->Asl.Namepath will be NULL for these opcodes.
566 * These opcodes are guaranteed to have a parent.
567 * Examine the parent opcode.
569 ParentOp = Op->Asl.Parent;
570 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode);
573 * Exclude all operators that actually declare a new name:
574 * Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT)
575 * We only want references to named objects:
576 * Store (2, WXYZ) -> Attempt to resolve the name
578 if (OpInfo->Class == AML_CLASS_NAMED_OBJECT)
584 * Check if the referenced object exists at this point during
586 * 1) If it exists, then this cannot be a forward reference.
587 * 2) If it does not exist, it could be a forward reference or
588 * it truly does not exist (and no external declaration).
590 Status = AcpiNsLookup (WalkState->ScopeInfo,
591 Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
592 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
594 if (Status == AE_NOT_FOUND)
597 * This is either a forward reference or the object truly
598 * does not exist. The two cases can only be differentiated
599 * during the cross-reference stage later. Mark the Op/Name
600 * as not-found for now to indicate the need for further
603 * Special case: Allow forward references from elements of
604 * Package objects. This provides compatibility with other
605 * ACPI implementations. To correctly implement this, the
606 * ACPICA table load defers package resolution until the entire
607 * namespace has been loaded.
609 if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) &&
610 (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE))
612 Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD;
621 Path = Op->Asl.Namepath;
627 /* Map the raw opcode into an internal object type */
629 switch (Op->Asl.ParseOpcode)
633 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */
634 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */
637 * If this name refers to a ResourceTemplate, we will need to open
638 * a new scope so that the resource subfield names can be entered into
639 * the namespace underneath this name
641 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
643 ForceNewScope = TRUE;
646 /* Get the data type associated with the named object, not the name itself */
648 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
651 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
657 case PARSEOP_EXTERNAL:
659 * "External" simply enters a name and type into the namespace.
660 * We must be careful to not open a new scope, however, no matter
661 * what type the external name refers to (e.g., a method)
663 * first child is name, next child is ObjectType
665 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
666 ObjectType = ACPI_TYPE_ANY;
669 * We will mark every new node along the path as "External". This
670 * allows some or all of the nodes to be created later in the ASL
671 * code. Handles cases like this:
673 * External (\_SB_.PCI0.ABCD, IntObj)
682 * Store (\_SB_.PCI0.ABCD, Local0)
685 Flags |= ACPI_NS_EXTERNAL;
688 case PARSEOP_DEFAULT_ARG:
690 if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)
692 Status = LdLoadResourceElements (Op, WalkState);
693 return_ACPI_STATUS (Status);
696 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
701 * The name referenced by Scope(Name) must already exist at this point.
702 * In other words, forward references for Scope() are not supported.
703 * The only real reason for this is that the MS interpreter cannot
704 * handle this case. Perhaps someday this case can go away.
706 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
707 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &Node);
708 if (ACPI_FAILURE (Status))
710 if (Status == AE_NOT_FOUND)
712 /* The name was not found, go ahead and create it */
714 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
715 ACPI_TYPE_LOCAL_SCOPE, ACPI_IMODE_LOAD_PASS1,
716 Flags, WalkState, &Node);
717 if (ACPI_FAILURE (Status))
719 return_ACPI_STATUS (Status);
722 /* However, this is an error -- operand to Scope must exist */
724 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
726 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
727 Op->Asl.ExternalName);
731 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
732 Op->Asl.ExternalName);
738 AslCoreSubsystemError (Op, Status,
739 "Failure from namespace lookup", FALSE);
741 return_ACPI_STATUS (Status);
743 else /* Status AE_OK */
746 * Do not allow references to external scopes from the DSDT.
747 * This is because the DSDT is always loaded first, and the
748 * external reference cannot be resolved -- causing a runtime
749 * error because Scope() must be resolved immediately.
752 if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
753 (ACPI_COMPARE_NAMESEG (AslGbl_TableSignature, "DSDT")))
755 /* However, allowed if the reference is within a method */
757 MethodOp = Op->Asl.Parent;
759 (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
761 MethodOp = MethodOp->Asl.Parent;
766 /* Not in a control method, error */
768 AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
773 /* We found a node with this name, now check the type */
777 case ACPI_TYPE_LOCAL_SCOPE:
778 case ACPI_TYPE_DEVICE:
779 case ACPI_TYPE_POWER:
780 case ACPI_TYPE_PROCESSOR:
781 case ACPI_TYPE_THERMAL:
783 /* These are acceptable types - they all open a new scope */
786 case ACPI_TYPE_INTEGER:
787 case ACPI_TYPE_STRING:
788 case ACPI_TYPE_BUFFER:
790 * These types we will allow, but we will change the type.
791 * This enables some existing code of the form:
794 * Scope (DEB) { ... }
796 * Which is used to workaround the fact that the MS interpreter
797 * does not allow Scope() forward references.
799 sprintf (AslGbl_MsgBuffer, "%s [%s], changing type to [Scope]",
800 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
801 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
803 /* Switch the type to scope, open the new scope */
805 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
806 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
808 if (ACPI_FAILURE (Status))
810 return_ACPI_STATUS (Status);
816 /* All other types are an error */
818 sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
819 AcpiUtGetTypeName (Node->Type));
820 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
823 * However, switch the type to be an actual scope so
824 * that compilation can continue without generating a whole
825 * cascade of additional errors. Open the new scope.
827 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
828 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
830 if (ACPI_FAILURE (Status))
832 return_ACPI_STATUS (Status);
842 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
846 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
847 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
849 /* The name must not already exist */
851 Flags |= ACPI_NS_ERROR_IF_FOUND;
854 * For opcodes that enter new names into the namespace,
855 * all prefix NameSegs must exist.
857 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
858 if (((WalkState->OpInfo->Flags & AML_NAMED) ||
859 (WalkState->OpInfo->Flags & AML_CREATE)) &&
860 (Op->Asl.AmlOpcode != AML_EXTERNAL_OP))
862 Flags |= ACPI_NS_PREFIX_MUST_EXIST;
866 * Enter the named type into the internal namespace. We enter the name
867 * as we go downward in the parse tree. Any necessary subobjects that
868 * involve arguments to the opcode must be created as we go back up the
871 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
872 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
873 if (ACPI_FAILURE (Status))
875 if (Status == AE_ALREADY_EXISTS)
877 /* The name already exists in this scope */
879 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
881 /* Allow multiple references to the same scope */
883 Node->Type = (UINT8) ObjectType;
886 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
887 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
890 * Allow one create on an object or segment that was
891 * previously declared External
893 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
894 Node->Type = (UINT8) ObjectType;
896 /* Just retyped a node, probably will need to open a scope */
898 if (AcpiNsOpensScope (ObjectType))
900 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
901 if (ACPI_FAILURE (Status))
903 return_ACPI_STATUS (Status);
909 else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
910 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
913 * Allow externals in same scope as the definition of the
914 * actual object. Similar to C. Allows multiple definition
915 * blocks that refer to each other in the same file.
919 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
920 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
921 (ObjectType == ACPI_TYPE_ANY))
923 /* Allow update of externals of unknown type. */
925 if (AcpiNsOpensScope (ActualObjectType))
927 Node->Type = (UINT8) ActualObjectType;
932 sprintf (AslGbl_MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
933 AcpiUtGetTypeName (Node->Type));
934 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, AslGbl_MsgBuffer);
935 return_ACPI_STATUS (AE_OK);
940 /* Valid error, object already exists */
942 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
943 Op->Asl.ExternalName, ASL_MSG_FOUND_HERE, Node->Op,
944 Node->Op->Asl.ExternalName);
945 return_ACPI_STATUS (AE_OK);
948 else if (AE_NOT_FOUND)
951 * One or more prefix NameSegs of the NamePath do not exist
952 * (all of them must exist). Attempt to continue compilation
953 * by setting the current scope to the root.
955 Node = AcpiGbl_RootNode;
960 /* Flag all other errors as coming from the ACPICA core */
962 AslCoreSubsystemError (Op, Status,
963 "Failure from namespace lookup", FALSE);
964 return_ACPI_STATUS (Status);
968 /* Check special names like _WAK and _PTS */
970 LdCheckSpecialNames (Node, Op);
974 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
975 if (ACPI_FAILURE (Status))
977 return_ACPI_STATUS (Status);
983 * Point the parse node to the new namespace node, and point
984 * the Node back to the original Parse node
990 * Set the actual data type if appropriate (EXTERNAL term only)
991 * As of 11/19/2019, ASL External() does not support parameter
992 * counts. When an External method is loaded, the parameter count is
993 * unknown setting Node->Value to ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS
994 * indicates that the parameter count for this method is unknown.
995 * This information is used in ASL cross reference to help determine the
996 * parameter count through method calls.
998 if (ActualObjectType != ACPI_TYPE_ANY)
1000 Node->Type = (UINT8) ActualObjectType;
1001 Node->Value = ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS;
1004 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
1007 * Get the method argument count from "Extra" and save
1008 * it in the namespace node
1010 Node->Value = (UINT32) Op->Asl.Extra;
1013 return_ACPI_STATUS (Status);
1017 /*******************************************************************************
1019 * FUNCTION: LdCheckSpecialNames
1021 * PARAMETERS: Node - Node that represents the named object
1022 * Op - Named object declaring this named object
1026 * DESCRIPTION: Check if certain named objects are declared in the incorrect
1027 * scope. Special named objects are listed in
1028 * AslGbl_SpecialNamedObjects and can only be declared at the root
1029 * scope. _UID inside of a processor declaration must not be a
1032 ******************************************************************************/
1035 LdCheckSpecialNames (
1036 ACPI_NAMESPACE_NODE *Node,
1037 ACPI_PARSE_OBJECT *Op)
1042 for (i = 0; i < MAX_SPECIAL_NAMES; i++)
1044 if (ACPI_COMPARE_NAMESEG(Node->Name.Ascii, AslGbl_SpecialNamedObjects[i]) &&
1045 Node->Parent != AcpiGbl_RootNode)
1047 AslError (ASL_ERROR, ASL_MSG_INVALID_SPECIAL_NAME, Op, Op->Asl.ExternalName);
1052 if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, "_UID") &&
1053 Node->Parent->Type == ACPI_TYPE_PROCESSOR &&
1054 Node->Type == ACPI_TYPE_STRING)
1056 AslError (ASL_ERROR, ASL_MSG_INVALID_PROCESSOR_UID , Op, "found a string");
1061 /*******************************************************************************
1063 * FUNCTION: LdNamespace2Begin
1065 * PARAMETERS: ASL_WALK_CALLBACK
1069 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
1070 * Second pass resolves some forward references.
1073 * Currently only needs to handle the Alias operator.
1074 * Could be used to allow forward references from the Scope() operator, but
1075 * the MS interpreter does not allow this, so this compiler does not either.
1077 ******************************************************************************/
1081 ACPI_PARSE_OBJECT *Op,
1085 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1087 ACPI_NAMESPACE_NODE *Node;
1088 ACPI_OBJECT_TYPE ObjectType;
1089 BOOLEAN ForceNewScope = FALSE;
1090 ACPI_PARSE_OBJECT *Arg;
1092 ACPI_NAMESPACE_NODE *TargetNode;
1095 ACPI_FUNCTION_NAME (LdNamespace2Begin);
1096 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
1097 Op, Op->Asl.ParseOpName));
1100 /* Ignore Ops with no namespace node */
1102 Node = Op->Asl.Node;
1108 /* Get the type to determine if we should push the scope */
1110 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1111 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1113 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1117 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1120 /* Push scope for Resource Templates */
1122 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1124 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1126 ForceNewScope = TRUE;
1130 /* Push the scope stack */
1132 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1134 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
1135 if (ACPI_FAILURE (Status))
1137 return_ACPI_STATUS (Status);
1141 if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
1144 * Complete the alias node by getting and saving the target node.
1145 * First child is the alias target
1147 Arg = Op->Asl.Child;
1149 /* Get the target pathname */
1151 Path = Arg->Asl.Namepath;
1154 Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
1155 if (ACPI_FAILURE (Status))
1161 /* Get the NS node associated with the target. It must exist. */
1163 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
1164 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
1165 WalkState, &TargetNode);
1166 if (ACPI_FAILURE (Status))
1168 if (Status == AE_NOT_FOUND)
1170 /* Standalone NameSeg vs. NamePath */
1172 if (strlen (Arg->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
1174 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1175 Arg->Asl.ExternalName);
1179 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
1180 Arg->Asl.ExternalName);
1185 * NOTE: Removed 10/2018 to enhance compiler error reporting. No
1189 * The name was not found, go ahead and create it.
1190 * This prevents more errors later.
1192 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1193 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
1194 ACPI_NS_NO_UPSEARCH, WalkState, &Node);
1197 /* Removed: return (AE_OK)*/
1200 AslCoreSubsystemError (Op, Status,
1201 "Failure from namespace lookup", FALSE);
1205 /* Save the target node within the alias node */
1207 Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1214 /*******************************************************************************
1216 * FUNCTION: LdCommonNamespaceEnd
1218 * PARAMETERS: ASL_WALK_CALLBACK
1222 * DESCRIPTION: Ascending callback used during the loading of the namespace,
1223 * We only need to worry about managing the scope stack here.
1225 ******************************************************************************/
1228 LdCommonNamespaceEnd (
1229 ACPI_PARSE_OBJECT *Op,
1233 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1234 ACPI_OBJECT_TYPE ObjectType;
1235 BOOLEAN ForceNewScope = FALSE;
1238 ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1241 /* We are only interested in opcodes that have an associated name */
1243 if (!Op->Asl.Namepath)
1248 /* Get the type to determine if we should pop the scope */
1250 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1251 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC))
1253 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1255 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1259 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1262 /* Pop scope that was pushed for Resource Templates */
1264 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1266 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC)
1268 ForceNewScope = TRUE;
1272 /* Pop the scope stack */
1274 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1276 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1277 "(%s): Popping scope for Op [%s] %p\n",
1278 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1280 (void) AcpiDsScopeStackPop (WalkState);