1 /******************************************************************************
3 * Module Name: aslxref - Namespace cross-reference
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2020, 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"
153 #include "aslcompiler.y.h"
154 #include "acparser.h"
156 #include "acnamesp.h"
157 #include "acdispat.h"
160 #define _COMPONENT ACPI_COMPILER
161 ACPI_MODULE_NAME ("aslxref")
163 /* Local prototypes */
166 XfNamespaceLocateBegin (
167 ACPI_PARSE_OBJECT *Op,
172 XfNamespaceLocateEnd (
173 ACPI_PARSE_OBJECT *Op,
178 XfValidateCrossReference (
179 ACPI_PARSE_OBJECT *Op,
180 const ACPI_OPCODE_INFO *OpInfo,
181 ACPI_NAMESPACE_NODE *Node);
188 XfCompareOneNamespaceObject (
189 ACPI_HANDLE ObjHandle,
196 ACPI_PARSE_OBJECT *Op,
197 UINT32 RegionBitLength,
198 UINT32 FieldBitOffset,
199 UINT32 FieldBitLength,
200 UINT32 AccessBitWidth);
203 XfFindCondRefOfName (
204 ACPI_NAMESPACE_NODE *Node,
205 ACPI_PARSE_OBJECT *Op);
208 XfRefIsGuardedByIfCondRefOf (
209 ACPI_NAMESPACE_NODE *Node,
210 ACPI_PARSE_OBJECT *Op);
213 /*******************************************************************************
215 * FUNCTION: XfCrossReferenceNamespace
221 * DESCRIPTION: Perform a cross reference check of the parse tree against the
222 * namespace. Every named referenced within the parse tree
223 * should be get resolved with a namespace lookup. If not, the
224 * original reference in the ASL code is invalid -- i.e., refers
225 * to a non-existent object.
227 * NOTE: The ASL "External" operator causes the name to be inserted into the
228 * namespace so that references to the external name will be resolved
231 ******************************************************************************/
234 XfCrossReferenceNamespace (
237 ACPI_WALK_STATE *WalkState;
241 * Create a new walk state for use when looking up names
242 * within the namespace (Passed as context to the callbacks)
244 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
247 return (AE_NO_MEMORY);
250 /* Walk the entire parse tree */
252 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
253 XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState);
255 ACPI_FREE (WalkState);
260 /*******************************************************************************
262 * FUNCTION: XfObjectExists
264 * PARAMETERS: Name - 4 char ACPI name
266 * RETURN: TRUE if name exists in namespace
268 * DESCRIPTION: Walk the namespace to find an object
270 ******************************************************************************/
279 /* Walk entire namespace from the supplied root */
281 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
282 ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
284 if (Status == AE_CTRL_TRUE)
286 /* At least one instance of the name was found */
295 /*******************************************************************************
297 * FUNCTION: XfCompareOneNamespaceObject
299 * PARAMETERS: ACPI_WALK_CALLBACK
303 * DESCRIPTION: Compare name of one object.
305 ******************************************************************************/
308 XfCompareOneNamespaceObject (
309 ACPI_HANDLE ObjHandle,
314 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
317 /* Simply check the name */
319 if (*((UINT32 *) (Context)) == Node->Name.Integer)
321 /* Abort walk if we found one instance */
323 return (AE_CTRL_TRUE);
330 /*******************************************************************************
332 * FUNCTION: XfCheckFieldRange
334 * PARAMETERS: RegionBitLength - Length of entire parent region
335 * FieldBitOffset - Start of the field unit (within region)
336 * FieldBitLength - Entire length of field unit
337 * AccessBitWidth - Access width of the field unit
341 * DESCRIPTION: Check one field unit to make sure it fits in the parent
344 * Note: AccessBitWidth must be either 8,16,32, or 64
346 ******************************************************************************/
350 ACPI_PARSE_OBJECT *Op,
351 UINT32 RegionBitLength,
352 UINT32 FieldBitOffset,
353 UINT32 FieldBitLength,
354 UINT32 AccessBitWidth)
356 UINT32 FieldEndBitOffset;
360 * Check each field unit against the region size. The entire
361 * field unit (start offset plus length) must fit within the
364 FieldEndBitOffset = FieldBitOffset + FieldBitLength;
366 if (FieldEndBitOffset > RegionBitLength)
368 /* Field definition itself is beyond the end-of-region */
370 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
375 * Now check that the field plus AccessWidth doesn't go beyond
376 * the end-of-region. Assumes AccessBitWidth is a power of 2
378 FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
380 if (FieldEndBitOffset > RegionBitLength)
382 /* Field definition combined with the access is beyond EOR */
384 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
389 /*******************************************************************************
391 * FUNCTION: XfNamespaceLocateBegin
393 * PARAMETERS: ASL_WALK_CALLBACK
397 * DESCRIPTION: Descending callback used during cross-reference. For named
398 * object references, attempt to locate the name in the
401 * NOTE: ASL references to named fields within resource descriptors are
402 * resolved to integer values here. Therefore, this step is an
403 * important part of the code generation. We don't know that the
404 * name refers to a resource descriptor until now.
406 ******************************************************************************/
409 XfNamespaceLocateBegin (
410 ACPI_PARSE_OBJECT *Op,
414 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
415 ACPI_NAMESPACE_NODE *Node;
417 ACPI_OBJECT_TYPE ObjectType;
420 ACPI_PARSE_OBJECT *NextOp;
421 ACPI_PARSE_OBJECT *OwningOp;
422 ACPI_PARSE_OBJECT *SpaceIdOp;
423 UINT32 MinimumLength;
425 UINT32 FieldBitLength;
428 const ACPI_OPCODE_INFO *OpInfo;
430 ASL_METHOD_LOCAL *MethodLocals = NULL;
431 ASL_METHOD_LOCAL *MethodArgs = NULL;
434 ACPI_NAMESPACE_NODE *DeclarationParentMethod;
435 ACPI_PARSE_OBJECT *ReferenceParentMethod;
438 ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
441 if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
445 /* Support for method LocalX/ArgX analysis */
447 if (!Node->MethodLocals)
449 /* Create local/arg info blocks */
451 MethodLocals = UtLocalCalloc (
452 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
453 Node->MethodLocals = MethodLocals;
455 MethodArgs = UtLocalCalloc (
456 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
457 Node->MethodArgs = MethodArgs;
460 * Get the method argument count
461 * First, get the name node
463 NextOp = Op->Asl.Child;
465 /* Get the NumArguments node */
467 NextOp = NextOp->Asl.Next;
468 Node->ArgCount = (UINT8)
469 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
471 /* We will track all possible ArgXs */
473 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
475 if (i < Node->ArgCount)
477 /* Real Args are always "initialized" */
479 MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
483 /* Other ArgXs can be used as locals */
485 MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
488 MethodArgs[i].Op = Op;
494 * If this node is the actual declaration of a name
495 * [such as the XXXX name in "Method (XXXX)"],
496 * we are not interested in it here. We only care about names that are
497 * references to other objects within the namespace and the parent objects
498 * of name declarations
500 if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)
502 return_ACPI_STATUS (AE_OK);
505 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
507 /* Check method LocalX variables */
509 if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
511 /* Find parent method Op */
513 NextOp = UtGetParentMethodOp (Op);
516 return_ACPI_STATUS (AE_OK);
519 /* Get method node */
521 Node = NextOp->Asl.Node;
523 RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
524 MethodLocals = Node->MethodLocals;
526 if (Op->Asl.CompileFlags & OP_IS_TARGET)
528 /* Local is being initialized */
530 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
531 MethodLocals[RegisterNumber].Op = Op;
533 return_ACPI_STATUS (AE_OK);
536 /* Mark this Local as referenced */
538 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
539 MethodLocals[RegisterNumber].Op = Op;
541 return_ACPI_STATUS (AE_OK);
544 /* Check method ArgX variables */
546 if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
548 /* Find parent method Op */
550 NextOp = UtGetParentMethodOp (Op);
553 return_ACPI_STATUS (AE_OK);
556 /* Get method node */
558 Node = NextOp->Asl.Node;
562 RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
563 MethodArgs = Node->MethodArgs;
565 /* Mark this Arg as referenced */
567 MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
568 MethodArgs[RegisterNumber].Op = Op;
570 if (Op->Asl.CompileFlags & OP_IS_TARGET)
572 /* Arg is being initialized */
574 MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
577 return_ACPI_STATUS (AE_OK);
581 * After method ArgX and LocalX, we are only interested in opcodes
582 * that have an associated name
584 if ((!(OpInfo->Flags & AML_NAMED)) &&
585 (!(OpInfo->Flags & AML_CREATE)) &&
586 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
587 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
588 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
589 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
591 return_ACPI_STATUS (AE_OK);
595 * We must enable the "search-to-root" for single NameSegs, but
596 * we have to be very careful about opening up scopes
598 Flags = ACPI_NS_SEARCH_PARENT;
599 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
600 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
601 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
602 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) ||
603 (Op->Asl.ParseOpcode == PARSEOP_CONDREFOF))
606 * These are name references, do not push the scope stack
609 Flags |= ACPI_NS_DONT_OPEN_SCOPE;
612 /* Get the NamePath from the appropriate place */
614 if (OpInfo->Flags & AML_NAMED)
616 /* For nearly all NAMED operators, the name reference is the first child */
618 Path = Op->Asl.Child->Asl.Value.String;
619 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
622 * ALIAS is the only oddball opcode, the name declaration
623 * (alias name) is the second operand
625 Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
628 else if (OpInfo->Flags & AML_CREATE)
630 /* Name must appear as the last parameter */
632 NextOp = Op->Asl.Child;
633 while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
635 NextOp = NextOp->Asl.Next;
638 Path = NextOp->Asl.Value.String;
642 Path = Op->Asl.Value.String;
645 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
646 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
647 "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
650 * Lookup the name in the namespace. Name must exist at this point, or it
651 * is an invalid reference.
653 * The namespace is also used as a lookup table for references to resource
654 * descriptors and the fields within them.
656 AslGbl_NsLookupCount++;
658 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
659 ACPI_IMODE_EXECUTE, Flags, WalkState, &Node);
660 if (ACPI_FAILURE (Status))
662 if (Status == AE_NOT_FOUND)
665 * We didn't find the name reference by path -- we can qualify this
666 * a little better before we print an error message
669 if ((Op->Asl.Parent) &&
670 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
673 * One special case: CondRefOf operator - if the name doesn't
674 * exist at this point, it means that there's no actual or
675 * external declaration. If the name is not found, just ignore
676 * it, the point of the operator is to determine if the name
677 * exists at runtime. We wanted to see if this named object
678 * exists to facilitate analysis to allow protected usage of
679 * undeclared externals.
681 return_ACPI_STATUS (AE_OK);
683 else if (strlen (Path) == ACPI_NAMESEG_SIZE)
685 /* A simple, one-segment ACPI name */
687 if (XfObjectExists (Path))
690 * There exists such a name, but we couldn't get to it
693 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
694 Op->Asl.ExternalName);
698 /* The name doesn't exist, period */
700 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
701 Op, Op->Asl.ExternalName);
706 /* The NamePath contains multiple NameSegs */
708 if ((OpInfo->Flags & AML_CREATE) ||
709 (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS))
712 * The new name is the last parameter. For the
713 * CreateXXXXField and Alias operators
715 NextOp = Op->Asl.Child;
716 while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
718 NextOp = NextOp->Asl.Next;
721 AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp,
722 NextOp->Asl.ExternalName);
724 else if (OpInfo->Flags & AML_NAMED)
726 /* The new name is the first parameter */
728 AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op,
729 Op->Asl.ExternalName);
731 else if (Path[0] == AML_ROOT_PREFIX)
733 /* Full namepath from root, the object does not exist */
735 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
736 Op->Asl.ExternalName);
741 * Generic "not found" error. Cannot determine whether it
742 * doesn't exist or just can't be reached. However, we
743 * can differentiate between a NameSeg vs. NamePath.
745 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
747 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
748 Op->Asl.ExternalName);
752 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
753 Op->Asl.ExternalName);
761 return_ACPI_STATUS (Status);
764 /* Check for an attempt to access an object in another method */
766 if (!XfValidateCrossReference (Op, OpInfo, Node))
768 AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op,
769 Op->Asl.ExternalName);
770 return_ACPI_STATUS (Status);
773 /* Object was found above, check for an illegal forward reference */
775 if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD)
778 * During the load phase, this Op was flagged as a possible
779 * illegal forward reference. In other words, Op is a name path or
780 * name segment that refers to a named object declared after the
781 * reference. In this scinario, Node refers to the actual declaration
782 * and Op is a parse node that references the named object.
786 * Object references inside of control methods are allowed to
787 * refer to objects declared outside of control methods.
789 * If the declaration and reference are both contained inside of the
790 * same method or outside of any method, this is a forward reference
791 * and should be reported as a compiler error.
793 DeclarationParentMethod = UtGetParentMethodNode (Node);
794 ReferenceParentMethod = UtGetParentMethodOp (Op);
796 /* case 1: declaration and reference are both outside of method */
798 if (!ReferenceParentMethod && !DeclarationParentMethod)
800 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
801 Op->Asl.ExternalName);
804 /* case 2: declaration and reference are both inside of the same method */
806 else if (ReferenceParentMethod && DeclarationParentMethod &&
807 ReferenceParentMethod == DeclarationParentMethod->Op)
809 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
810 Op->Asl.ExternalName);
814 /* Check for a reference vs. name declaration */
816 if (!(OpInfo->Flags & AML_NAMED) &&
817 !(OpInfo->Flags & AML_CREATE))
819 /* This node has been referenced, mark it for reference check */
821 Node->Flags |= ANOBJ_IS_REFERENCED;
825 * Attempt to optimize the NamePath
827 * One special case: CondRefOf operator - not all AML interpreter
828 * implementations expect optimized namepaths as a parameter to this
829 * operator. They require relative name paths with prefix operators or
830 * namepaths starting with the root scope.
832 * Other AML interpreter implementations do not perform the namespace
833 * search that starts at the current scope and recursively searching the
834 * parent scope until the root scope. The lack of search is only known to
835 * occur for the namestring parameter for the CondRefOf operator.
837 if ((Op->Asl.Parent) &&
838 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_CONDREFOF))
840 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
844 * 1) Dereference an alias (A name reference that is an alias)
845 * Aliases are not nested, the alias always points to the final object
847 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
848 (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
850 /* This node points back to the original PARSEOP_ALIAS */
854 /* The first child is the alias target op */
856 NextOp = NextOp->Asl.Child;
858 /* That in turn points back to original target alias node */
860 if (NextOp->Asl.Node)
862 Node = NextOp->Asl.Node;
865 /* Else - forward reference to alias, will be resolved later */
868 /* 2) Check for a reference to a resource descriptor */
870 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
871 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
874 * This was a reference to a field within a resource descriptor.
875 * Extract the associated field offset (either a bit or byte
876 * offset depending on the field type) and change the named
877 * reference into an integer for AML code generation
879 Offset = Node->Value;
880 TagBitLength = Node->Length;
883 * If a field is being created, generate the length (in bits) of
884 * the field. Note: Opcodes other than CreateXxxField and Index
885 * can come through here. For other opcodes, we just need to
886 * convert the resource tag reference to an integer offset.
888 switch (Op->Asl.Parent->Asl.AmlOpcode)
890 case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
892 * We know the length operand is an integer constant because
893 * we know that it contains a reference to a resource
896 FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
899 case AML_CREATE_BIT_FIELD_OP:
904 case AML_CREATE_BYTE_FIELD_OP:
910 case AML_CREATE_WORD_FIELD_OP:
915 case AML_CREATE_DWORD_FIELD_OP:
920 case AML_CREATE_QWORD_FIELD_OP:
931 /* Check the field length against the length of the resource tag */
935 if (TagBitLength < FieldBitLength)
937 Message = ASL_MSG_TAG_SMALLER;
939 else if (TagBitLength > FieldBitLength)
941 Message = ASL_MSG_TAG_LARGER;
946 sprintf (AslGbl_MsgBuffer,
947 "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
948 TagBitLength, (TagBitLength > 1) ? "s" : "",
949 FieldBitLength, (FieldBitLength > 1) ? "s" : "");
951 AslError (ASL_WARNING, Message, Op, AslGbl_MsgBuffer);
955 /* Convert the BitOffset to a ByteOffset for certain opcodes */
957 switch (Op->Asl.Parent->Asl.AmlOpcode)
959 case AML_CREATE_BYTE_FIELD_OP:
960 case AML_CREATE_WORD_FIELD_OP:
961 case AML_CREATE_DWORD_FIELD_OP:
962 case AML_CREATE_QWORD_FIELD_OP:
965 Offset = ACPI_DIV_8 (Offset);
973 /* Now convert this node to an integer whose value is the field offset */
975 Op->Asl.AmlLength = 0;
976 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
977 Op->Asl.Value.Integer = (UINT64) Offset;
978 Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;
980 OpcGenerateAmlOpcode (Op);
983 /* 3) Check for a method invocation */
985 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
986 (Node->Type == ACPI_TYPE_METHOD) &&
988 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
990 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
993 * A reference to a method within one of these opcodes is not an
994 * invocation of the method, it is simply a reference to the method.
996 * September 2016: Removed DeRefOf from this list
998 if ((Op->Asl.Parent) &&
999 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
1000 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
1001 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
1002 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
1004 return_ACPI_STATUS (AE_OK);
1008 * There are two types of method invocation:
1009 * 1) Invocation with arguments -- the parser recognizes this
1011 * 2) Invocation with no arguments --the parser cannot determine that
1012 * this is a method invocation, therefore we have to figure it out
1015 if (Node->Type != ACPI_TYPE_METHOD)
1017 sprintf (AslGbl_MsgBuffer, "%s is a %s",
1018 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
1020 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, AslGbl_MsgBuffer);
1021 return_ACPI_STATUS (AE_OK);
1024 /* Save the method node in the caller's op */
1026 Op->Asl.Node = Node;
1027 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
1029 return_ACPI_STATUS (AE_OK);
1033 * This is a method invocation, with or without arguments.
1034 * Count the number of arguments, each appears as a child
1035 * under the parent node
1037 Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
1038 UtSetParseOpName (Op);
1041 NextOp = Op->Asl.Child;
1046 NextOp = NextOp->Asl.Next;
1049 if (Node->Value != ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS &&
1050 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1053 * Check the parsed arguments with the number expected by the
1054 * method declaration itself
1056 if (PassedArgs != Node->Value)
1058 if (Node->Flags & ANOBJ_IS_EXTERNAL)
1060 sprintf (AslGbl_MsgBuffer,
1061 "according to previous use, %s requires %u",
1062 Op->Asl.ExternalName, Node->Value);
1066 sprintf (AslGbl_MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1070 if (PassedArgs < Node->Value)
1072 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer);
1076 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer);
1082 * At this point, a method call to an external method has been
1083 * detected. As of 11/19/2019, iASL does not support parameter counts
1084 * for methods declared as external. Therefore, save the parameter
1085 * count of the first method call and use this count check other
1086 * method calls to ensure that the methods are being called with the
1087 * same amount of parameters.
1089 else if (Node->Type == ACPI_TYPE_METHOD &&
1090 (Node->Flags & ANOBJ_IS_EXTERNAL) &&
1091 Node->Value == ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS &&
1092 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1094 Node->Value = PassedArgs;
1098 /* 4) Check for an ASL Field definition */
1100 else if ((Op->Asl.Parent) &&
1101 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
1102 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1105 * Offset checking for fields. If the parent operation region has a
1106 * constant length (known at compile time), we can check fields
1107 * defined in that region against the region length. This will catch
1108 * fields and field units that cannot possibly fit within the region.
1110 * Note: Index fields do not directly reference an operation region,
1111 * thus they are not included in this check.
1113 if (Op == Op->Asl.Parent->Asl.Child)
1116 * This is the first child of the field node, which is
1117 * the name of the region. Get the parse node for the
1118 * region -- which contains the length of the region.
1120 OwningOp = Node->Op;
1121 Op->Asl.Parent->Asl.ExtraValue =
1122 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1124 /* Examine the field access width */
1126 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1128 case AML_FIELD_ACCESS_ANY:
1129 case AML_FIELD_ACCESS_BYTE:
1130 case AML_FIELD_ACCESS_BUFFER:
1136 case AML_FIELD_ACCESS_WORD:
1141 case AML_FIELD_ACCESS_DWORD:
1146 case AML_FIELD_ACCESS_QWORD:
1153 * Is the region at least as big as the access width?
1154 * Note: DataTableRegions have 0 length
1156 if (((UINT32) OwningOp->Asl.Value.Integer) &&
1157 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1159 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1163 * Check EC/CMOS/SMBUS fields to make sure that the correct
1164 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1166 SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1167 switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1169 case ACPI_ADR_SPACE_EC:
1170 case ACPI_ADR_SPACE_CMOS:
1171 case ACPI_ADR_SPACE_GPIO:
1173 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1174 AML_FIELD_ACCESS_BYTE)
1176 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1180 case ACPI_ADR_SPACE_SMBUS:
1181 case ACPI_ADR_SPACE_IPMI:
1182 case ACPI_ADR_SPACE_GSBUS:
1184 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1185 AML_FIELD_ACCESS_BUFFER)
1187 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1193 /* Nothing to do for other address spaces */
1201 * This is one element of the field list. Check to make sure
1202 * that it does not go beyond the end of the parent operation region.
1204 * In the code below:
1205 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1206 * Op->Asl.ExtraValue - Field start offset (bits)
1207 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1208 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1210 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1212 XfCheckFieldRange (Op,
1213 Op->Asl.Parent->Asl.ExtraValue,
1215 (UINT32) Op->Asl.Child->Asl.Value.Integer,
1216 Op->Asl.Child->Asl.ExtraValue);
1222 * 5) Check for external resolution
1224 * By this point, everything should be loaded in the namespace. If a
1225 * namespace lookup results in a namespace node that is an external, it
1226 * means that this named object was not defined in the input ASL. This
1227 * causes issues because there are plenty of incidents where developers
1228 * use the external keyword to suppress compiler errors about undefined
1229 * objects. Note: this only applies when compiling multiple definition
1232 * Do not check for external resolution in the following cases:
1234 * case 1) External (ABCD)
1236 * This declares ABCD as an external so there is no requirement for
1237 * ABCD to be loaded in the namespace when analyzing the actual
1238 * External() statement.
1240 * case 2) CondRefOf (ABCD)
1242 * This operator will query the ACPI namespace on the existence of
1243 * ABCD. If ABCD does not exist, this operator will return a 0
1244 * without incurring AML runtime errors. Therefore, ABCD is allowed
1245 * to not exist when analyzing the CondRefOf operator.
1247 * case 3) External (ABCD)
1248 * if (CondRefOf (ABCD))
1253 * In this case, ABCD is accessed only if it exists due to the if
1254 * statement so there is no need to flag the ABCD nested in the
1257 if (AslGbl_ParseTreeRoot->Asl.Child && AslGbl_ParseTreeRoot->Asl.Child->Asl.Next &&
1258 (Node->Flags & ANOBJ_IS_EXTERNAL) &&
1259 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL &&
1260 Op->Asl.ParseOpcode != PARSEOP_EXTERNAL &&
1261 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_CONDREFOF &&
1262 !XfRefIsGuardedByIfCondRefOf (Node, Op))
1264 AslError (ASL_ERROR, ASL_MSG_UNDEFINED_EXTERNAL, Op, NULL);
1267 /* 5) Check for a connection object */
1269 else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1271 return_ACPI_STATUS (Status);
1275 Op->Asl.Node = Node;
1276 return_ACPI_STATUS (Status);
1280 /*******************************************************************************
1282 * FUNCTION: XfRefIsGuardedByIfCondRefOf
1284 * PARAMETERS: Node - Named object reference node
1285 * Op - Named object reference parse node
1289 * DESCRIPTION: returns true if Op checked inside if (CondRefOf (...))
1292 ******************************************************************************/
1295 XfRefIsGuardedByIfCondRefOf (
1296 ACPI_NAMESPACE_NODE *Node,
1297 ACPI_PARSE_OBJECT *Op)
1299 ACPI_PARSE_OBJECT *Parent = Op->Asl.Parent;
1304 if (Parent->Asl.ParseOpcode == PARSEOP_IF &&
1305 XfFindCondRefOfName (Node, Parent->Asl.Child))
1310 Parent = Parent->Asl.Parent;
1317 /*******************************************************************************
1319 * FUNCTION: XfRefIsGuardedByIfCondRefOf
1321 * PARAMETERS: Node - Named object reference node
1322 * Op - Named object reference parse node
1326 * DESCRIPTION: returns true if Op checked inside if (CondRefOf (...))
1329 ******************************************************************************/
1332 XfFindCondRefOfName (
1333 ACPI_NAMESPACE_NODE *Node,
1334 ACPI_PARSE_OBJECT *Op)
1336 BOOLEAN CondRefOfFound = FALSE;
1344 switch (Op->Asl.ParseOpcode)
1346 case PARSEOP_CONDREFOF:
1348 return (Op->Asl.Child->Common.Node == Node);
1353 CondRefOfFound = XfFindCondRefOfName (Node, Op->Asl.Child);
1359 return (XfFindCondRefOfName (Node, Op->Asl.Child->Asl.Next));
1370 /*******************************************************************************
1372 * FUNCTION: XfNamespaceLocateEnd
1374 * PARAMETERS: ASL_WALK_CALLBACK
1378 * DESCRIPTION: Ascending callback used during cross reference. We only
1379 * need to worry about scope management here.
1381 ******************************************************************************/
1384 XfNamespaceLocateEnd (
1385 ACPI_PARSE_OBJECT *Op,
1389 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1390 const ACPI_OPCODE_INFO *OpInfo;
1393 ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1396 /* We are only interested in opcodes that have an associated name */
1398 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1399 if (!(OpInfo->Flags & AML_NAMED))
1401 return_ACPI_STATUS (AE_OK);
1404 /* Not interested in name references, we did not open a scope for them */
1406 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1407 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1408 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1409 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1411 return_ACPI_STATUS (AE_OK);
1414 /* Pop the scope stack if necessary */
1416 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1419 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1420 "%s: Popping scope for Op %p\n",
1421 AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1423 (void) AcpiDsScopeStackPop (WalkState);
1426 return_ACPI_STATUS (AE_OK);
1430 /*******************************************************************************
1432 * FUNCTION: XfValidateCrossReference
1434 * PARAMETERS: Op - Parse Op that references the object
1435 * OpInfo - Parse Op info struct
1436 * Node - Node for the referenced object
1438 * RETURN: TRUE if the reference is legal, FALSE otherwise
1440 * DESCRIPTION: Determine if a reference to another object is allowed.
1443 * Method (A) {Name (INT1, 1)} Declaration of object INT1
1444 * Method (B) (Store (2, \A.INT1)} Illegal reference to object INT1
1445 * (INT1 is temporary, valid only during
1449 * A null pointer returned by either UtGetParentMethodOp or
1450 * UtGetParentMethodNode indicates that the parameter object is not
1451 * within a control method.
1453 * Five cases are handled: Case(Op, Node)
1454 * 1) Case(0,0): Op is not within a method, Node is not --> OK
1455 * 2) Case(0,1): Op is not within a method, but Node is --> Illegal
1456 * 3) Case(1,0): Op is within a method, Node is not --> OK
1457 * 4) Case(1,1): Both are within the same method --> OK
1458 * 5) Case(1,1): Both are in methods, but not same method --> Illegal
1460 ******************************************************************************/
1463 XfValidateCrossReference (
1464 ACPI_PARSE_OBJECT *Op,
1465 const ACPI_OPCODE_INFO *OpInfo,
1466 ACPI_NAMESPACE_NODE *Node)
1468 ACPI_PARSE_OBJECT *ReferencingMethodOp;
1469 ACPI_NAMESPACE_NODE *ReferencedMethodNode;
1472 /* Ignore actual named (and related) object declarations */
1474 if (OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_DEFER | AML_HAS_ARGS))
1480 * 1) Search upwards in parse tree for owner of the referencing object
1481 * 2) Search upwards in namespace to find the owner of the referenced object
1483 ReferencingMethodOp = UtGetParentMethodOp (Op);
1484 ReferencedMethodNode = UtGetParentMethodNode (Node);
1486 if (!ReferencingMethodOp && !ReferencedMethodNode)
1489 * 1) Case (0,0): Both Op and Node are not within methods
1495 if (!ReferencingMethodOp && ReferencedMethodNode)
1498 * 2) Case (0,1): Op is not in a method, but Node is within a
1499 * method --> illegal
1503 else if (ReferencingMethodOp && !ReferencedMethodNode)
1506 * 3) Case (1,0): Op is within a method, but Node is not
1511 else if (ReferencingMethodOp->Asl.Node == ReferencedMethodNode)
1514 * 4) Case (1,1): Both Op and Node are within the same method
1522 * 5) Case (1,1), Op and Node are in different methods