1 /******************************************************************************
3 * Module Name: aslxref - Namespace cross-reference
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 "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acnamesp.h>
157 #include <contrib/dev/acpica/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);
183 static ACPI_PARSE_OBJECT *
185 ACPI_PARSE_OBJECT *Op);
192 XfCompareOneNamespaceObject (
193 ACPI_HANDLE ObjHandle,
200 ACPI_PARSE_OBJECT *Op,
201 UINT32 RegionBitLength,
202 UINT32 FieldBitOffset,
203 UINT32 FieldBitLength,
204 UINT32 AccessBitWidth);
207 /*******************************************************************************
209 * FUNCTION: XfCrossReferenceNamespace
215 * DESCRIPTION: Perform a cross reference check of the parse tree against the
216 * namespace. Every named referenced within the parse tree
217 * should be get resolved with a namespace lookup. If not, the
218 * original reference in the ASL code is invalid -- i.e., refers
219 * to a non-existent object.
221 * NOTE: The ASL "External" operator causes the name to be inserted into the
222 * namespace so that references to the external name will be resolved
225 ******************************************************************************/
228 XfCrossReferenceNamespace (
231 ACPI_WALK_STATE *WalkState;
235 * Create a new walk state for use when looking up names
236 * within the namespace (Passed as context to the callbacks)
238 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
241 return (AE_NO_MEMORY);
244 /* Walk the entire parse tree */
246 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
247 XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState);
249 ACPI_FREE (WalkState);
254 /*******************************************************************************
256 * FUNCTION: XfObjectExists
258 * PARAMETERS: Name - 4 char ACPI name
260 * RETURN: TRUE if name exists in namespace
262 * DESCRIPTION: Walk the namespace to find an object
264 ******************************************************************************/
273 /* Walk entire namespace from the supplied root */
275 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
276 ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
278 if (Status == AE_CTRL_TRUE)
280 /* At least one instance of the name was found */
289 /*******************************************************************************
291 * FUNCTION: XfCompareOneNamespaceObject
293 * PARAMETERS: ACPI_WALK_CALLBACK
297 * DESCRIPTION: Compare name of one object.
299 ******************************************************************************/
302 XfCompareOneNamespaceObject (
303 ACPI_HANDLE ObjHandle,
308 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
311 /* Simply check the name */
313 if (*((UINT32 *) (Context)) == Node->Name.Integer)
315 /* Abort walk if we found one instance */
317 return (AE_CTRL_TRUE);
324 /*******************************************************************************
326 * FUNCTION: XfCheckFieldRange
328 * PARAMETERS: RegionBitLength - Length of entire parent region
329 * FieldBitOffset - Start of the field unit (within region)
330 * FieldBitLength - Entire length of field unit
331 * AccessBitWidth - Access width of the field unit
335 * DESCRIPTION: Check one field unit to make sure it fits in the parent
338 * Note: AccessBitWidth must be either 8,16,32, or 64
340 ******************************************************************************/
344 ACPI_PARSE_OBJECT *Op,
345 UINT32 RegionBitLength,
346 UINT32 FieldBitOffset,
347 UINT32 FieldBitLength,
348 UINT32 AccessBitWidth)
350 UINT32 FieldEndBitOffset;
354 * Check each field unit against the region size. The entire
355 * field unit (start offset plus length) must fit within the
358 FieldEndBitOffset = FieldBitOffset + FieldBitLength;
360 if (FieldEndBitOffset > RegionBitLength)
362 /* Field definition itself is beyond the end-of-region */
364 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
369 * Now check that the field plus AccessWidth doesn't go beyond
370 * the end-of-region. Assumes AccessBitWidth is a power of 2
372 FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
374 if (FieldEndBitOffset > RegionBitLength)
376 /* Field definition combined with the access is beyond EOR */
378 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
383 /*******************************************************************************
385 * FUNCTION: XfGetParentMethod
387 * PARAMETERS: Op - Parse Op to be checked
389 * RETURN: Control method Op if found. NULL otherwise
391 * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if
392 * the input Op is not within a control method.
394 ******************************************************************************/
396 static ACPI_PARSE_OBJECT *
398 ACPI_PARSE_OBJECT *Op)
400 ACPI_PARSE_OBJECT *NextOp;
403 NextOp = Op->Asl.Parent;
406 if (NextOp->Asl.AmlOpcode == AML_METHOD_OP)
411 NextOp = NextOp->Asl.Parent;
414 return (NULL); /* No parent method found */
418 /*******************************************************************************
420 * FUNCTION: XfNamespaceLocateBegin
422 * PARAMETERS: ASL_WALK_CALLBACK
426 * DESCRIPTION: Descending callback used during cross-reference. For named
427 * object references, attempt to locate the name in the
430 * NOTE: ASL references to named fields within resource descriptors are
431 * resolved to integer values here. Therefore, this step is an
432 * important part of the code generation. We don't know that the
433 * name refers to a resource descriptor until now.
435 ******************************************************************************/
438 XfNamespaceLocateBegin (
439 ACPI_PARSE_OBJECT *Op,
443 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
444 ACPI_NAMESPACE_NODE *Node;
446 ACPI_OBJECT_TYPE ObjectType;
449 ACPI_PARSE_OBJECT *NextOp;
450 ACPI_PARSE_OBJECT *OwningOp;
451 ACPI_PARSE_OBJECT *SpaceIdOp;
452 UINT32 MinimumLength;
454 UINT32 FieldBitLength;
457 const ACPI_OPCODE_INFO *OpInfo;
459 ASL_METHOD_LOCAL *MethodLocals = NULL;
460 ASL_METHOD_LOCAL *MethodArgs = NULL;
465 ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
468 if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
472 /* Support for method LocalX/ArgX analysis */
474 if (!Node->MethodLocals)
476 /* Create local/arg info blocks */
478 MethodLocals = UtLocalCalloc (
479 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
480 Node->MethodLocals = MethodLocals;
482 MethodArgs = UtLocalCalloc (
483 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
484 Node->MethodArgs = MethodArgs;
487 * Get the method argument count
488 * First, get the name node
490 NextOp = Op->Asl.Child;
492 /* Get the NumArguments node */
494 NextOp = NextOp->Asl.Next;
495 Node->ArgCount = (UINT8)
496 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
498 /* We will track all possible ArgXs */
500 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
502 if (i < Node->ArgCount)
504 /* Real Args are always "initialized" */
506 MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
510 /* Other ArgXs can be used as locals */
512 MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
515 MethodArgs[i].Op = Op;
521 * If this node is the actual declaration of a name
522 * [such as the XXXX name in "Method (XXXX)"],
523 * we are not interested in it here. We only care about names that are
524 * references to other objects within the namespace and the parent objects
525 * of name declarations
527 if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)
529 return_ACPI_STATUS (AE_OK);
532 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
534 /* Check method LocalX variables */
536 if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
538 /* Find parent method Op */
540 NextOp = XfGetParentMethod (Op);
543 return_ACPI_STATUS (AE_OK);
546 /* Get method node */
548 Node = NextOp->Asl.Node;
550 RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
551 MethodLocals = Node->MethodLocals;
553 if (Op->Asl.CompileFlags & OP_IS_TARGET)
555 /* Local is being initialized */
557 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
558 MethodLocals[RegisterNumber].Op = Op;
560 return_ACPI_STATUS (AE_OK);
563 /* Mark this Local as referenced */
565 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
566 MethodLocals[RegisterNumber].Op = Op;
568 return_ACPI_STATUS (AE_OK);
571 /* Check method ArgX variables */
573 if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
575 /* Find parent method Op */
577 NextOp = XfGetParentMethod (Op);
580 return_ACPI_STATUS (AE_OK);
583 /* Get method node */
585 Node = NextOp->Asl.Node;
589 RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
590 MethodArgs = Node->MethodArgs;
592 /* Mark this Arg as referenced */
594 MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
595 MethodArgs[RegisterNumber].Op = Op;
597 if (Op->Asl.CompileFlags & OP_IS_TARGET)
599 /* Arg is being initialized */
601 MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
604 return_ACPI_STATUS (AE_OK);
608 * After method ArgX and LocalX, we are only interested in opcodes
609 * that have an associated name
611 if ((!(OpInfo->Flags & AML_NAMED)) &&
612 (!(OpInfo->Flags & AML_CREATE)) &&
613 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
614 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
615 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
616 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL) &&
617 (OpInfo->Type != AML_TYPE_NAMED_FIELD))
619 return_ACPI_STATUS (AE_OK);
623 * One special case: CondRefOf operator - we don't care if the name exists
624 * or not at this point, just ignore it, the point of the operator is to
625 * determine if the name exists at runtime.
627 if ((Op->Asl.Parent) &&
628 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
630 return_ACPI_STATUS (AE_OK);
634 * We must enable the "search-to-root" for single NameSegs, but
635 * we have to be very careful about opening up scopes
637 Flags = ACPI_NS_SEARCH_PARENT;
638 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
639 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
640 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
641 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) ||
642 (OpInfo->Type == AML_TYPE_NAMED_FIELD))
645 * These are name references, do not push the scope stack
648 Flags |= ACPI_NS_DONT_OPEN_SCOPE;
651 /* Get the NamePath from the appropriate place */
653 if (OpInfo->Flags & AML_NAMED)
655 /* For nearly all NAMED operators, the name reference is the first child */
657 Path = Op->Asl.Child->Asl.Value.String;
658 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
661 * ALIAS is the only oddball opcode, the name declaration
662 * (alias name) is the second operand
664 Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
667 else if (OpInfo->Flags & AML_CREATE)
669 /* Name must appear as the last parameter */
671 NextOp = Op->Asl.Child;
672 while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
674 NextOp = NextOp->Asl.Next;
677 Path = NextOp->Asl.Value.String;
679 else if (OpInfo->Type == AML_TYPE_NAMED_FIELD)
681 Path = Op->Asl.Child->Asl.Value.String;
685 Path = Op->Asl.Value.String;
688 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
689 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
690 "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
693 * Lookup the name in the namespace. Name must exist at this point, or it
694 * is an invalid reference.
696 * The namespace is also used as a lookup table for references to resource
697 * descriptors and the fields within them.
699 AslGbl_NsLookupCount++;
701 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
702 ACPI_IMODE_EXECUTE, Flags, WalkState, &Node);
703 if (ACPI_FAILURE (Status))
705 if (Status == AE_NOT_FOUND)
708 * We didn't find the name reference by path -- we can qualify this
709 * a little better before we print an error message
711 if (strlen (Path) == ACPI_NAMESEG_SIZE)
713 /* A simple, one-segment ACPI name */
715 if (XfObjectExists (Path))
718 * There exists such a name, but we couldn't get to it
721 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
722 Op->Asl.ExternalName);
726 /* The name doesn't exist, period */
728 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
729 Op, Op->Asl.ExternalName);
734 /* The NamePath contains multiple NameSegs */
736 if ((OpInfo->Flags & AML_CREATE) ||
737 (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS))
740 * The new name is the last parameter. For the
741 * CreateXXXXField and Alias operators
743 NextOp = Op->Asl.Child;
744 while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
746 NextOp = NextOp->Asl.Next;
749 AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp,
750 NextOp->Asl.ExternalName);
752 else if (OpInfo->Flags & AML_NAMED)
754 /* The new name is the first parameter */
756 AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op,
757 Op->Asl.ExternalName);
759 else if (Path[0] == AML_ROOT_PREFIX)
761 /* Full namepath from root, the object does not exist */
763 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
764 Op->Asl.ExternalName);
769 * Generic "not found" error. Cannot determine whether it
770 * doesn't exist or just can't be reached. However, we
771 * can differentiate between a NameSeg vs. NamePath.
773 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
775 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
776 Op->Asl.ExternalName);
780 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
781 Op->Asl.ExternalName);
789 return_ACPI_STATUS (Status);
792 /* Check for an attempt to access an object in another method */
794 if (!XfValidateCrossReference (Op, OpInfo, Node))
796 AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op,
797 Op->Asl.ExternalName);
798 return_ACPI_STATUS (Status);
801 /* Object was found above, check for an illegal forward reference */
803 if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD)
806 * During the load phase, this Op was flagged as a possible
807 * illegal forward reference
809 * Note: Allow "forward references" from within a method to an
810 * object that is not within any method (module-level code)
812 if (!WalkState->ScopeInfo || (UtGetParentMethod (Node) &&
813 !UtNodeIsDescendantOf (WalkState->ScopeInfo->Scope.Node,
814 UtGetParentMethod (Node))))
816 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
817 Op->Asl.ExternalName);
821 /* Check for a reference vs. name declaration */
823 if (!(OpInfo->Flags & AML_NAMED) &&
824 !(OpInfo->Flags & AML_CREATE))
826 /* This node has been referenced, mark it for reference check */
828 Node->Flags |= ANOBJ_IS_REFERENCED;
831 /* Attempt to optimize the NamePath */
833 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
836 * 1) Dereference an alias (A name reference that is an alias)
837 * Aliases are not nested, the alias always points to the final object
839 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
840 (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
842 /* This node points back to the original PARSEOP_ALIAS */
846 /* The first child is the alias target op */
848 NextOp = NextOp->Asl.Child;
850 /* That in turn points back to original target alias node */
852 if (NextOp->Asl.Node)
854 Node = NextOp->Asl.Node;
857 /* Else - forward reference to alias, will be resolved later */
860 /* 2) Check for a reference to a resource descriptor */
862 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
863 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
866 * This was a reference to a field within a resource descriptor.
867 * Extract the associated field offset (either a bit or byte
868 * offset depending on the field type) and change the named
869 * reference into an integer for AML code generation
871 Offset = Node->Value;
872 TagBitLength = Node->Length;
875 * If a field is being created, generate the length (in bits) of
876 * the field. Note: Opcodes other than CreateXxxField and Index
877 * can come through here. For other opcodes, we just need to
878 * convert the resource tag reference to an integer offset.
880 switch (Op->Asl.Parent->Asl.AmlOpcode)
882 case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
884 * We know the length operand is an integer constant because
885 * we know that it contains a reference to a resource
888 FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
891 case AML_CREATE_BIT_FIELD_OP:
896 case AML_CREATE_BYTE_FIELD_OP:
902 case AML_CREATE_WORD_FIELD_OP:
907 case AML_CREATE_DWORD_FIELD_OP:
912 case AML_CREATE_QWORD_FIELD_OP:
923 /* Check the field length against the length of the resource tag */
927 if (TagBitLength < FieldBitLength)
929 Message = ASL_MSG_TAG_SMALLER;
931 else if (TagBitLength > FieldBitLength)
933 Message = ASL_MSG_TAG_LARGER;
938 sprintf (AslGbl_MsgBuffer,
939 "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
940 TagBitLength, (TagBitLength > 1) ? "s" : "",
941 FieldBitLength, (FieldBitLength > 1) ? "s" : "");
943 AslError (ASL_WARNING, Message, Op, AslGbl_MsgBuffer);
947 /* Convert the BitOffset to a ByteOffset for certain opcodes */
949 switch (Op->Asl.Parent->Asl.AmlOpcode)
951 case AML_CREATE_BYTE_FIELD_OP:
952 case AML_CREATE_WORD_FIELD_OP:
953 case AML_CREATE_DWORD_FIELD_OP:
954 case AML_CREATE_QWORD_FIELD_OP:
957 Offset = ACPI_DIV_8 (Offset);
965 /* Now convert this node to an integer whose value is the field offset */
967 Op->Asl.AmlLength = 0;
968 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
969 Op->Asl.Value.Integer = (UINT64) Offset;
970 Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;
972 OpcGenerateAmlOpcode (Op);
975 /* 3) Check for a method invocation */
977 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
978 (Node->Type == ACPI_TYPE_METHOD) &&
980 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
982 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
985 * A reference to a method within one of these opcodes is not an
986 * invocation of the method, it is simply a reference to the method.
988 * September 2016: Removed DeRefOf from this list
990 if ((Op->Asl.Parent) &&
991 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
992 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
993 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
994 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
996 return_ACPI_STATUS (AE_OK);
1000 * There are two types of method invocation:
1001 * 1) Invocation with arguments -- the parser recognizes this
1003 * 2) Invocation with no arguments --the parser cannot determine that
1004 * this is a method invocation, therefore we have to figure it out
1007 if (Node->Type != ACPI_TYPE_METHOD)
1009 sprintf (AslGbl_MsgBuffer, "%s is a %s",
1010 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
1012 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, AslGbl_MsgBuffer);
1013 return_ACPI_STATUS (AE_OK);
1016 /* Save the method node in the caller's op */
1018 Op->Asl.Node = Node;
1019 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
1021 return_ACPI_STATUS (AE_OK);
1025 * This is a method invocation, with or without arguments.
1026 * Count the number of arguments, each appears as a child
1027 * under the parent node
1029 Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
1030 UtSetParseOpName (Op);
1033 NextOp = Op->Asl.Child;
1038 NextOp = NextOp->Asl.Next;
1041 if (Node->Value != ASL_EXTERNAL_METHOD &&
1042 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1045 * Check the parsed arguments with the number expected by the
1046 * method declaration itself
1048 if (PassedArgs != Node->Value)
1050 sprintf (AslGbl_MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1053 if (PassedArgs < Node->Value)
1055 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer);
1059 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer);
1065 /* 4) Check for an ASL Field definition */
1067 else if ((Op->Asl.Parent) &&
1068 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
1069 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1072 * Offset checking for fields. If the parent operation region has a
1073 * constant length (known at compile time), we can check fields
1074 * defined in that region against the region length. This will catch
1075 * fields and field units that cannot possibly fit within the region.
1077 * Note: Index fields do not directly reference an operation region,
1078 * thus they are not included in this check.
1080 if (Op == Op->Asl.Parent->Asl.Child)
1083 * This is the first child of the field node, which is
1084 * the name of the region. Get the parse node for the
1085 * region -- which contains the length of the region.
1087 OwningOp = Node->Op;
1088 Op->Asl.Parent->Asl.ExtraValue =
1089 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1091 /* Examine the field access width */
1093 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1095 case AML_FIELD_ACCESS_ANY:
1096 case AML_FIELD_ACCESS_BYTE:
1097 case AML_FIELD_ACCESS_BUFFER:
1103 case AML_FIELD_ACCESS_WORD:
1108 case AML_FIELD_ACCESS_DWORD:
1113 case AML_FIELD_ACCESS_QWORD:
1120 * Is the region at least as big as the access width?
1121 * Note: DataTableRegions have 0 length
1123 if (((UINT32) OwningOp->Asl.Value.Integer) &&
1124 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1126 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1130 * Check EC/CMOS/SMBUS fields to make sure that the correct
1131 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1133 SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1134 switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1136 case ACPI_ADR_SPACE_EC:
1137 case ACPI_ADR_SPACE_CMOS:
1138 case ACPI_ADR_SPACE_GPIO:
1140 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1141 AML_FIELD_ACCESS_BYTE)
1143 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1147 case ACPI_ADR_SPACE_SMBUS:
1148 case ACPI_ADR_SPACE_IPMI:
1149 case ACPI_ADR_SPACE_GSBUS:
1151 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1152 AML_FIELD_ACCESS_BUFFER)
1154 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1160 /* Nothing to do for other address spaces */
1168 * This is one element of the field list. Check to make sure
1169 * that it does not go beyond the end of the parent operation region.
1171 * In the code below:
1172 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1173 * Op->Asl.ExtraValue - Field start offset (bits)
1174 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1175 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1177 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1179 XfCheckFieldRange (Op,
1180 Op->Asl.Parent->Asl.ExtraValue,
1182 (UINT32) Op->Asl.Child->Asl.Value.Integer,
1183 Op->Asl.Child->Asl.ExtraValue);
1188 /* 5) Check for a connection object */
1190 else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1192 return_ACPI_STATUS (Status);
1196 Op->Asl.Node = Node;
1197 return_ACPI_STATUS (Status);
1201 /*******************************************************************************
1203 * FUNCTION: XfNamespaceLocateEnd
1205 * PARAMETERS: ASL_WALK_CALLBACK
1209 * DESCRIPTION: Ascending callback used during cross reference. We only
1210 * need to worry about scope management here.
1212 ******************************************************************************/
1215 XfNamespaceLocateEnd (
1216 ACPI_PARSE_OBJECT *Op,
1220 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1221 const ACPI_OPCODE_INFO *OpInfo;
1224 ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1227 /* We are only interested in opcodes that have an associated name */
1229 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1230 if (!(OpInfo->Flags & AML_NAMED))
1232 return_ACPI_STATUS (AE_OK);
1235 /* Not interested in name references, we did not open a scope for them */
1237 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1238 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1239 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1240 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1242 return_ACPI_STATUS (AE_OK);
1245 /* Pop the scope stack if necessary */
1247 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1250 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1251 "%s: Popping scope for Op %p\n",
1252 AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1254 (void) AcpiDsScopeStackPop (WalkState);
1257 return_ACPI_STATUS (AE_OK);
1261 /*******************************************************************************
1263 * FUNCTION: XfValidateCrossReference
1265 * PARAMETERS: Op - Parse Op that references the object
1266 * OpInfo - Parse Op info struct
1267 * Node - Node for the referenced object
1269 * RETURN: TRUE if the reference is legal, FALSE otherwise
1271 * DESCRIPTION: Determine if a reference to another object is allowed.
1274 * Method (A) {Name (INT1, 1)} Declaration of object INT1
1275 * Method (B) (Store (2, \A.INT1)} Illegal reference to object INT1
1276 * (INT1 is temporary, valid only during
1280 * A null pointer returned by either XfGetParentMethod or
1281 * UtGetParentMethod indicates that the parameter object is not
1282 * within a control method.
1284 * Five cases are handled: Case(Op, Node)
1285 * 1) Case(0,0): Op is not within a method, Node is not --> OK
1286 * 2) Case(0,1): Op is not within a method, but Node is --> Illegal
1287 * 3) Case(1,0): Op is within a method, Node is not --> OK
1288 * 4) Case(1,1): Both are within the same method --> OK
1289 * 5) Case(1,1): Both are in methods, but not same method --> Illegal
1291 ******************************************************************************/
1294 XfValidateCrossReference (
1295 ACPI_PARSE_OBJECT *Op,
1296 const ACPI_OPCODE_INFO *OpInfo,
1297 ACPI_NAMESPACE_NODE *Node)
1299 ACPI_PARSE_OBJECT *ReferencingMethodOp;
1300 ACPI_NAMESPACE_NODE *ReferencedMethodNode;
1303 /* Ignore actual named (and related) object declarations */
1305 if (OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_DEFER | AML_HAS_ARGS))
1311 * 1) Search upwards in parse tree for owner of the referencing object
1312 * 2) Search upwards in namespace to find the owner of the referenced object
1314 ReferencingMethodOp = XfGetParentMethod (Op);
1315 ReferencedMethodNode = UtGetParentMethod (Node);
1317 if (!ReferencingMethodOp && !ReferencedMethodNode)
1320 * 1) Case (0,0): Both Op and Node are not within methods
1326 if (!ReferencingMethodOp && ReferencedMethodNode)
1329 * 2) Case (0,1): Op is not in a method, but Node is within a
1330 * method --> illegal
1334 else if (ReferencingMethodOp && !ReferencedMethodNode)
1337 * 3) Case (1,0): Op is within a method, but Node is not
1342 else if (ReferencingMethodOp->Asl.Node == ReferencedMethodNode)
1345 * 4) Case (1,1): Both Op and Node are within the same method
1353 * 5) Case (1,1), Op and Node are in different methods