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);
320 * The name already exists in this scope
321 * But continue processing the elements
323 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child,
324 Child->Asl.Value.String);
328 Child->Asl.Node = Node;
334 Child = Child->Asl.Next;
341 /*******************************************************************************
343 * FUNCTION: LdLoadResourceElements
345 * PARAMETERS: Op - Parent node (Resource Descriptor)
346 * WalkState - Current walk state
350 * DESCRIPTION: Enter the named elements of the resource descriptor (children
351 * of the parent) into the namespace.
353 * NOTE: In the real AML namespace, these named elements never exist. But
354 * we simply use the namespace here as a symbol table so we can look
355 * them up as they are referenced.
357 ******************************************************************************/
360 LdLoadResourceElements (
361 ACPI_PARSE_OBJECT *Op,
362 ACPI_WALK_STATE *WalkState)
364 ACPI_PARSE_OBJECT *InitializerOp = NULL;
365 ACPI_NAMESPACE_NODE *Node;
370 * Enter the resource name into the namespace. Name must not already exist.
371 * This opens a scope, so later field names are guaranteed to be new/unique.
373 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath,
374 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1,
375 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND,
377 if (ACPI_FAILURE (Status))
379 if (Status == AE_ALREADY_EXISTS)
381 /* Actual node causing the error was saved in ParentMethod */
383 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS,
384 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath);
390 Node->Value = (UINT32) Op->Asl.Value.Integer;
395 * Now enter the predefined fields, for easy lookup when referenced
398 InitializerOp = ASL_GET_CHILD_NODE (Op);
399 while (InitializerOp)
401 if (InitializerOp->Asl.ExternalName)
403 Status = AcpiNsLookup (WalkState->ScopeInfo,
404 InitializerOp->Asl.ExternalName,
405 ACPI_TYPE_LOCAL_RESOURCE_FIELD,
406 ACPI_IMODE_LOAD_PASS1,
407 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
409 if (ACPI_FAILURE (Status))
415 * Store the field offset and length in the namespace node
416 * so it can be used when the field is referenced
418 Node->Value = InitializerOp->Asl.Value.Tag.BitOffset;
419 Node->Length = InitializerOp->Asl.Value.Tag.BitLength;
420 InitializerOp->Asl.Node = Node;
421 Node->Op = InitializerOp;
424 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
431 /*******************************************************************************
433 * FUNCTION: LdNamespace1Begin
435 * PARAMETERS: ASL_WALK_CALLBACK
439 * DESCRIPTION: Descending callback used during the parse tree walk. If this
440 * is a named AML opcode, enter into the namespace
442 ******************************************************************************/
446 ACPI_PARSE_OBJECT *Op,
450 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
451 ACPI_NAMESPACE_NODE *Node;
452 ACPI_PARSE_OBJECT *MethodOp;
454 ACPI_OBJECT_TYPE ObjectType;
455 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY;
457 UINT32 Flags = ACPI_NS_NO_UPSEARCH;
458 ACPI_PARSE_OBJECT *Arg;
460 BOOLEAN ForceNewScope = FALSE;
463 ACPI_FUNCTION_NAME (LdNamespace1Begin);
464 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
465 Op, Op->Asl.ParseOpName));
468 * We are only interested in opcodes that have an associated name
469 * (or multiple names)
471 switch (Op->Asl.AmlOpcode)
473 case AML_BANK_FIELD_OP:
474 case AML_INDEX_FIELD_OP:
477 Status = LdLoadFieldElements (Op, WalkState);
480 case AML_INT_CONNECTION_OP:
483 if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP)
489 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName,
490 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
492 if (ACPI_FAILURE (Status))
497 if (Node->Type == ACPI_TYPE_BUFFER)
499 Arg->Asl.Node = Node;
501 Arg = Node->Op->Asl.Child; /* Get namepath */
502 Arg = Arg->Asl.Next; /* Get actual buffer */
503 Arg = Arg->Asl.Child; /* Buffer length */
504 Arg = Arg->Asl.Next; /* RAW_DATA buffer */
510 /* All other opcodes go below */
515 /* Check if this object has already been installed in the namespace */
522 Path = Op->Asl.Namepath;
528 /* Map the raw opcode into an internal object type */
530 switch (Op->Asl.ParseOpcode)
534 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */
535 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */
538 * If this name refers to a ResourceTemplate, we will need to open
539 * a new scope so that the resource subfield names can be entered into
540 * the namespace underneath this name
542 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
544 ForceNewScope = TRUE;
547 /* Get the data type associated with the named object, not the name itself */
549 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */
552 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2)
559 case PARSEOP_EXTERNAL:
561 * "External" simply enters a name and type into the namespace.
562 * We must be careful to not open a new scope, however, no matter
563 * what type the external name refers to (e.g., a method)
565 * first child is name, next child is ObjectType
567 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer;
568 ObjectType = ACPI_TYPE_ANY;
571 * We will mark every new node along the path as "External". This
572 * allows some or all of the nodes to be created later in the ASL
573 * code. Handles cases like this:
575 * External (\_SB_.PCI0.ABCD, IntObj)
584 * Store (\_SB_.PCI0.ABCD, Local0)
587 Flags |= ACPI_NS_EXTERNAL;
590 case PARSEOP_DEFAULT_ARG:
592 if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)
594 Status = LdLoadResourceElements (Op, WalkState);
595 return_ACPI_STATUS (Status);
598 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
603 * The name referenced by Scope(Name) must already exist at this point.
604 * In other words, forward references for Scope() are not supported.
605 * The only real reason for this is that the MS interpreter cannot
606 * handle this case. Perhaps someday this case can go away.
608 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
609 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
611 if (ACPI_FAILURE (Status))
613 if (Status == AE_NOT_FOUND)
615 /* The name was not found, go ahead and create it */
617 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
618 ACPI_TYPE_LOCAL_SCOPE,
619 ACPI_IMODE_LOAD_PASS1, Flags,
621 if (ACPI_FAILURE (Status))
623 return_ACPI_STATUS (Status);
627 * However, this is an error -- primarily because the MS
628 * interpreter can't handle a forward reference from the
631 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
632 Op->Asl.ExternalName);
633 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op,
634 Op->Asl.ExternalName);
638 AslCoreSubsystemError (Op, Status,
639 "Failure from namespace lookup", FALSE);
641 return_ACPI_STATUS (Status);
643 else /* Status AE_OK */
646 * Do not allow references to external scopes from the DSDT.
647 * This is because the DSDT is always loaded first, and the
648 * external reference cannot be resolved -- causing a runtime
649 * error because Scope() must be resolved immediately.
652 if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
653 (ACPI_COMPARE_NAME (Gbl_TableSignature, "DSDT")))
655 /* However, allowed if the reference is within a method */
657 MethodOp = Op->Asl.Parent;
659 (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD))
661 MethodOp = MethodOp->Asl.Parent;
666 /* Not in a control method, error */
668 AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL);
673 /* We found a node with this name, now check the type */
677 case ACPI_TYPE_LOCAL_SCOPE:
678 case ACPI_TYPE_DEVICE:
679 case ACPI_TYPE_POWER:
680 case ACPI_TYPE_PROCESSOR:
681 case ACPI_TYPE_THERMAL:
683 /* These are acceptable types - they all open a new scope */
686 case ACPI_TYPE_INTEGER:
687 case ACPI_TYPE_STRING:
688 case ACPI_TYPE_BUFFER:
690 * These types we will allow, but we will change the type.
691 * This enables some existing code of the form:
694 * Scope (DEB) { ... }
696 * Which is used to workaround the fact that the MS interpreter
697 * does not allow Scope() forward references.
699 sprintf (MsgBuffer, "%s [%s], changing type to [Scope]",
700 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
701 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
703 /* Switch the type to scope, open the new scope */
705 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
706 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
708 if (ACPI_FAILURE (Status))
710 return_ACPI_STATUS (Status);
716 /* All other types are an error */
718 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
719 AcpiUtGetTypeName (Node->Type));
720 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
723 * However, switch the type to be an actual scope so
724 * that compilation can continue without generating a whole
725 * cascade of additional errors. Open the new scope.
727 Node->Type = ACPI_TYPE_LOCAL_SCOPE;
728 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE,
730 if (ACPI_FAILURE (Status))
732 return_ACPI_STATUS (Status);
743 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
748 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n",
749 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType)));
751 /* The name must not already exist */
753 Flags |= ACPI_NS_ERROR_IF_FOUND;
756 * Enter the named type into the internal namespace. We enter the name
757 * as we go downward in the parse tree. Any necessary subobjects that
758 * involve arguments to the opcode must be created as we go back up the
761 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
762 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
763 if (ACPI_FAILURE (Status))
765 if (Status == AE_ALREADY_EXISTS)
767 /* The name already exists in this scope */
769 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
771 /* Allow multiple references to the same scope */
773 Node->Type = (UINT8) ObjectType;
776 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
777 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
780 * Allow one create on an object or segment that was
781 * previously declared External
783 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
784 Node->Type = (UINT8) ObjectType;
786 /* Just retyped a node, probably will need to open a scope */
788 if (AcpiNsOpensScope (ObjectType))
790 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
791 if (ACPI_FAILURE (Status))
793 return_ACPI_STATUS (Status);
799 else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) &&
800 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
803 * Allow externals in same scope as the definition of the
804 * actual object. Similar to C. Allows multiple definition
805 * blocks that refer to each other in the same file.
809 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) &&
810 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) &&
811 (ObjectType == ACPI_TYPE_ANY))
813 /* Allow update of externals of unknown type. */
815 if (AcpiNsOpensScope (ActualObjectType))
817 Node->Type = (UINT8) ActualObjectType;
822 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName,
823 AcpiUtGetTypeName (Node->Type));
824 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer);
825 return_ACPI_STATUS (AE_OK);
830 /* Valid error, object already exists */
832 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op,
833 Op->Asl.ExternalName);
834 return_ACPI_STATUS (AE_OK);
839 AslCoreSubsystemError (Op, Status,
840 "Failure from namespace lookup", FALSE);
841 return_ACPI_STATUS (Status);
847 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
848 if (ACPI_FAILURE (Status))
850 return_ACPI_STATUS (Status);
856 * Point the parse node to the new namespace node, and point
857 * the Node back to the original Parse node
862 /* Set the actual data type if appropriate (EXTERNAL term only) */
864 if (ActualObjectType != ACPI_TYPE_ANY)
866 Node->Type = (UINT8) ActualObjectType;
867 Node->Value = ASL_EXTERNAL_METHOD;
870 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
873 * Get the method argument count from "Extra" and save
874 * it in the namespace node
876 Node->Value = (UINT32) Op->Asl.Extra;
879 return_ACPI_STATUS (Status);
883 /*******************************************************************************
885 * FUNCTION: LdNamespace2Begin
887 * PARAMETERS: ASL_WALK_CALLBACK
891 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk.
892 * Second pass resolves some forward references.
895 * Currently only needs to handle the Alias operator.
896 * Could be used to allow forward references from the Scope() operator, but
897 * the MS interpreter does not allow this, so this compiler does not either.
899 ******************************************************************************/
903 ACPI_PARSE_OBJECT *Op,
907 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
909 ACPI_NAMESPACE_NODE *Node;
910 ACPI_OBJECT_TYPE ObjectType;
911 BOOLEAN ForceNewScope = FALSE;
912 ACPI_PARSE_OBJECT *Arg;
914 ACPI_NAMESPACE_NODE *TargetNode;
917 ACPI_FUNCTION_NAME (LdNamespace2Begin);
918 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n",
919 Op, Op->Asl.ParseOpName));
922 /* Ignore Ops with no namespace node */
930 /* Get the type to determine if we should push the scope */
932 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
933 (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
935 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
939 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
942 /* Push scope for Resource Templates */
944 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
946 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
948 ForceNewScope = TRUE;
952 /* Push the scope stack */
954 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
956 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
957 if (ACPI_FAILURE (Status))
959 return_ACPI_STATUS (Status);
963 if (Op->Asl.ParseOpcode == PARSEOP_ALIAS)
965 /* Complete the alias node by getting and saving the target node */
967 /* First child is the alias target */
971 /* Get the target pathname */
973 Path = Arg->Asl.Namepath;
976 Status = UtInternalizeName (Arg->Asl.ExternalName, &Path);
977 if (ACPI_FAILURE (Status))
983 /* Get the NS node associated with the target. It must exist. */
985 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
986 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
987 WalkState, &TargetNode);
988 if (ACPI_FAILURE (Status))
990 if (Status == AE_NOT_FOUND)
992 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
993 Op->Asl.ExternalName);
996 * The name was not found, go ahead and create it.
997 * This prevents more errors later.
999 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
1001 ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH,
1002 WalkState, &(Node));
1006 AslCoreSubsystemError (Op, Status,
1007 "Failure from namespace lookup", FALSE);
1011 /* Save the target node within the alias node */
1013 Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode);
1020 /*******************************************************************************
1022 * FUNCTION: LdCommonNamespaceEnd
1024 * PARAMETERS: ASL_WALK_CALLBACK
1028 * DESCRIPTION: Ascending callback used during the loading of the namespace,
1029 * We only need to worry about managing the scope stack here.
1031 ******************************************************************************/
1034 LdCommonNamespaceEnd (
1035 ACPI_PARSE_OBJECT *Op,
1039 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1040 ACPI_OBJECT_TYPE ObjectType;
1041 BOOLEAN ForceNewScope = FALSE;
1044 ACPI_FUNCTION_NAME (LdCommonNamespaceEnd);
1047 /* We are only interested in opcodes that have an associated name */
1049 if (!Op->Asl.Namepath)
1054 /* Get the type to determine if we should pop the scope */
1056 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) &&
1057 (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC))
1059 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */
1061 ObjectType = ACPI_TYPE_LOCAL_RESOURCE;
1065 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1068 /* Pop scope that was pushed for Resource Templates */
1070 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
1072 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1074 ForceNewScope = TRUE;
1078 /* Pop the scope stack */
1080 if (ForceNewScope || AcpiNsOpensScope (ObjectType))
1082 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1083 "(%s): Popping scope for Op [%s] %p\n",
1084 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op));
1086 (void) AcpiDsScopeStackPop (WalkState);