1 /******************************************************************************
3 * Module Name: asllookup- Namespace lookup
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, 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 *****************************************************************************/
117 #include "aslcompiler.h"
118 #include "aslcompiler.y.h"
120 #include "acparser.h"
122 #include "acnamesp.h"
123 #include "acdispat.h"
126 #define _COMPONENT ACPI_COMPILER
127 ACPI_MODULE_NAME ("asllookup")
129 /* Local prototypes */
132 LsCompareOneNamespaceObject (
133 ACPI_HANDLE ObjHandle,
139 LsDoOneNamespaceObject (
140 ACPI_HANDLE ObjHandle,
151 ACPI_PARSE_OBJECT *Op,
152 UINT32 RegionBitLength,
153 UINT32 FieldBitOffset,
154 UINT32 FieldBitLength,
155 UINT32 AccessBitWidth);
158 LkNamespaceLocateBegin (
159 ACPI_PARSE_OBJECT *Op,
164 LkNamespaceLocateEnd (
165 ACPI_PARSE_OBJECT *Op,
171 ACPI_HANDLE ObjHandle,
178 ACPI_HANDLE ObjHandle,
183 static ACPI_PARSE_OBJECT *
185 ACPI_PARSE_OBJECT *Op);
188 /*******************************************************************************
190 * FUNCTION: LsDoOneNamespaceObject
192 * PARAMETERS: ACPI_WALK_CALLBACK
196 * DESCRIPTION: Dump a namespace object to the namespace output file.
197 * Called during the walk of the namespace to dump all objects.
199 ******************************************************************************/
202 LsDoOneNamespaceObject (
203 ACPI_HANDLE ObjHandle,
208 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
209 ACPI_OPERAND_OBJECT *ObjDesc;
210 ACPI_PARSE_OBJECT *Op;
213 Gbl_NumNamespaceObjects++;
215 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s",
216 Gbl_NumNamespaceObjects, Level, (Level * 3), " ",
218 AcpiUtGetTypeName (Node->Type));
221 ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
225 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
231 (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
235 case ACPI_TYPE_INTEGER:
237 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
238 " [Initial Value 0x%8.8X%8.8X]",
239 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
243 case ACPI_TYPE_STRING:
245 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
246 " [Initial Value \"%s\"]",
247 ObjDesc->String.Pointer);
251 /* Nothing to do for other types */
260 case ACPI_TYPE_INTEGER:
262 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
266 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
267 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
271 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
272 " [Initial Value 0x%8.8X%8.8X]",
273 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
277 case ACPI_TYPE_STRING:
279 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
283 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
284 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
288 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
289 " [Initial Value \"%s\"]",
290 Op->Asl.Value.String);
294 case ACPI_TYPE_LOCAL_REGION_FIELD:
296 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
297 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
301 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
302 " [Offset 0x%04X Length 0x%04X bits]",
303 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
307 case ACPI_TYPE_BUFFER_FIELD:
309 switch (Op->Asl.ParseOpcode)
311 case PARSEOP_CREATEBYTEFIELD:
312 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BYTE ( 8 bit)]");
315 case PARSEOP_CREATEDWORDFIELD:
316 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [DWORD (32 bit)]");
319 case PARSEOP_CREATEQWORDFIELD:
320 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [QWORD (64 bit)]");
323 case PARSEOP_CREATEWORDFIELD:
324 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [WORD (16 bit)]");
327 case PARSEOP_CREATEBITFIELD:
328 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BIT ( 1 bit)]");
331 case PARSEOP_CREATEFIELD:
332 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [Arbitrary Bit Field]");
342 case ACPI_TYPE_PACKAGE:
344 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
348 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
349 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
355 if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
356 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
358 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
359 " [Initial Length 0x%.2X elements]",
360 Op->Asl.Value.Integer);
365 case ACPI_TYPE_BUFFER:
367 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
371 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
372 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
378 if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
380 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
381 " [Initial Length 0x%.2X bytes]",
382 Op->Asl.Value.Integer);
387 case ACPI_TYPE_METHOD:
389 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
390 " [Code Length 0x%.4X bytes]",
391 Op->Asl.AmlSubtreeLength);
395 case ACPI_TYPE_LOCAL_RESOURCE:
397 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
398 " [Desc Offset 0x%.4X Bytes]", Node->Value);
402 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
404 if (Node->Flags & 0x80)
406 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
407 " [Field Offset 0x%.4X Bits 0x%.4X Bytes]",
408 Node->Value, Node->Value / 8);
412 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
413 " [Field Offset 0x%.4X Bytes]", Node->Value);
419 /* Nothing to do for other types */
424 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
429 /*******************************************************************************
431 * FUNCTION: LsSetupNsList
433 * PARAMETERS: Handle - local file handle
437 * DESCRIPTION: Set the namespace output file to the input handle
439 ******************************************************************************/
446 Gbl_NsOutputFlag = TRUE;
447 Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
451 /*******************************************************************************
453 * FUNCTION: LsDoOnePathname
455 * PARAMETERS: ACPI_WALK_CALLBACK
459 * DESCRIPTION: Print the full pathname for a namespace node.
461 ******************************************************************************/
465 ACPI_HANDLE ObjHandle,
470 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
472 ACPI_BUFFER TargetPath;
475 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
476 Status = AcpiNsHandleToPathname (Node, &TargetPath);
477 if (ACPI_FAILURE (Status))
482 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer);
483 ACPI_FREE (TargetPath.Pointer);
489 /*******************************************************************************
491 * FUNCTION: LsDisplayNamespace
497 * DESCRIPTION: Walk the namespace an display information about each node
498 * in the tree. Information is written to the optional
499 * namespace output file.
501 ******************************************************************************/
510 if (!Gbl_NsOutputFlag)
515 Gbl_NumNamespaceObjects = 0;
519 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
520 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count Depth Name - Type\n\n");
522 /* Walk entire namespace from the root */
524 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
525 ACPI_UINT32_MAX, FALSE, LsDoOneNamespaceObject, NULL,
528 /* Print the full pathname for each namespace node */
530 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
532 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
533 ACPI_UINT32_MAX, FALSE, LsDoOnePathname, NULL,
540 /*******************************************************************************
542 * FUNCTION: LsCompareOneNamespaceObject
544 * PARAMETERS: ACPI_WALK_CALLBACK
548 * DESCRIPTION: Compare name of one object.
550 ******************************************************************************/
553 LsCompareOneNamespaceObject (
554 ACPI_HANDLE ObjHandle,
559 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
562 /* Simply check the name */
564 if (*((UINT32 *) (Context)) == Node->Name.Integer)
566 /* Abort walk if we found one instance */
568 return (AE_CTRL_TRUE);
575 /*******************************************************************************
577 * FUNCTION: LkObjectExists
579 * PARAMETERS: Name - 4 char ACPI name
581 * RETURN: TRUE if name exists in namespace
583 * DESCRIPTION: Walk the namespace to find an object
585 ******************************************************************************/
594 /* Walk entire namespace from the supplied root */
596 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
597 ACPI_UINT32_MAX, FALSE, LsCompareOneNamespaceObject, NULL,
599 if (Status == AE_CTRL_TRUE)
601 /* At least one instance of the name was found */
610 /*******************************************************************************
612 * FUNCTION: LkGetNameOp
614 * PARAMETERS: Op - Current Op
616 * RETURN: NameOp associated with the input op
618 * DESCRIPTION: Find the name declaration op associated with the operator
620 ******************************************************************************/
622 static ACPI_PARSE_OBJECT *
624 ACPI_PARSE_OBJECT *Op)
626 const ACPI_OPCODE_INFO *OpInfo;
627 ACPI_PARSE_OBJECT *NameOp = Op;
630 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
633 /* Get the NamePath from the appropriate place */
635 if (OpInfo->Flags & AML_NAMED)
637 /* For nearly all NAMED operators, the name reference is the first child */
639 NameOp = Op->Asl.Child;
640 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
643 * ALIAS is the only oddball opcode, the name declaration
644 * (alias name) is the second operand
646 NameOp = Op->Asl.Child->Asl.Next;
649 else if (OpInfo->Flags & AML_CREATE)
651 /* Name must appear as the last parameter */
653 NameOp = Op->Asl.Child;
654 while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
656 NameOp = NameOp->Asl.Next;
664 /*******************************************************************************
666 * FUNCTION: LkIsObjectUsed
668 * PARAMETERS: ACPI_WALK_CALLBACK
672 * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
673 * We have to be careful, because some types and names are
674 * typically or always unreferenced, we don't want to issue
675 * excessive warnings.
677 ******************************************************************************/
681 ACPI_HANDLE ObjHandle,
686 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
689 /* Referenced flag is set during the namespace xref */
691 if (Node->Flags & ANOBJ_IS_REFERENCED)
697 * Ignore names that start with an underscore,
698 * these are the reserved ACPI names and are typically not referenced,
699 * they are called by the host OS.
701 if (Node->Name.Ascii[0] == '_')
706 /* There are some types that are typically not referenced, ignore them */
710 case ACPI_TYPE_DEVICE:
711 case ACPI_TYPE_PROCESSOR:
712 case ACPI_TYPE_POWER:
713 case ACPI_TYPE_LOCAL_RESOURCE:
720 /* All others are valid unreferenced namespace objects */
724 AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, LkGetNameOp (Node->Op), NULL);
730 /*******************************************************************************
732 * FUNCTION: LkFindUnreferencedObjects
738 * DESCRIPTION: Namespace walk to find objects that are not referenced in any
739 * way. Must be called after the namespace has been cross
742 ******************************************************************************/
745 LkFindUnreferencedObjects (
749 /* Walk entire namespace from the supplied root */
751 (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
752 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
757 /*******************************************************************************
759 * FUNCTION: LkCrossReferenceNamespace
765 * DESCRIPTION: Perform a cross reference check of the parse tree against the
766 * namespace. Every named referenced within the parse tree
767 * should be get resolved with a namespace lookup. If not, the
768 * original reference in the ASL code is invalid -- i.e., refers
769 * to a non-existent object.
771 * NOTE: The ASL "External" operator causes the name to be inserted into the
772 * namespace so that references to the external name will be resolved
775 ******************************************************************************/
778 LkCrossReferenceNamespace (
781 ACPI_WALK_STATE *WalkState;
784 DbgPrint (ASL_DEBUG_OUTPUT, "\nCross referencing namespace\n\n");
787 * Create a new walk state for use when looking up names
788 * within the namespace (Passed as context to the callbacks)
790 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
796 /* Walk the entire parse tree */
798 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, LkNamespaceLocateBegin,
799 LkNamespaceLocateEnd, WalkState);
804 /*******************************************************************************
806 * FUNCTION: LkCheckFieldRange
808 * PARAMETERS: RegionBitLength - Length of entire parent region
809 * FieldBitOffset - Start of the field unit (within region)
810 * FieldBitLength - Entire length of field unit
811 * AccessBitWidth - Access width of the field unit
815 * DESCRIPTION: Check one field unit to make sure it fits in the parent
818 * Note: AccessBitWidth must be either 8,16,32, or 64
820 ******************************************************************************/
824 ACPI_PARSE_OBJECT *Op,
825 UINT32 RegionBitLength,
826 UINT32 FieldBitOffset,
827 UINT32 FieldBitLength,
828 UINT32 AccessBitWidth)
830 UINT32 FieldEndBitOffset;
834 * Check each field unit against the region size. The entire
835 * field unit (start offset plus length) must fit within the
838 FieldEndBitOffset = FieldBitOffset + FieldBitLength;
840 if (FieldEndBitOffset > RegionBitLength)
842 /* Field definition itself is beyond the end-of-region */
844 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
849 * Now check that the field plus AccessWidth doesn't go beyond
850 * the end-of-region. Assumes AccessBitWidth is a power of 2
852 FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
854 if (FieldEndBitOffset > RegionBitLength)
856 /* Field definition combined with the access is beyond EOR */
858 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
862 /*******************************************************************************
864 * FUNCTION: LkNamespaceLocateBegin
866 * PARAMETERS: ASL_WALK_CALLBACK
870 * DESCRIPTION: Descending callback used during cross-reference. For named
871 * object references, attempt to locate the name in the
874 * NOTE: ASL references to named fields within resource descriptors are
875 * resolved to integer values here. Therefore, this step is an
876 * important part of the code generation. We don't know that the
877 * name refers to a resource descriptor until now.
879 ******************************************************************************/
882 LkNamespaceLocateBegin (
883 ACPI_PARSE_OBJECT *Op,
887 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
888 ACPI_NAMESPACE_NODE *Node;
890 ACPI_OBJECT_TYPE ObjectType;
893 ACPI_PARSE_OBJECT *NextOp;
894 ACPI_PARSE_OBJECT *OwningOp;
895 ACPI_PARSE_OBJECT *SpaceIdOp;
896 UINT32 MinimumLength;
898 const ACPI_OPCODE_INFO *OpInfo;
902 ACPI_FUNCTION_TRACE_PTR (LkNamespaceLocateBegin, Op);
905 * If this node is the actual declaration of a name
906 * [such as the XXXX name in "Method (XXXX)"],
907 * we are not interested in it here. We only care about names that are
908 * references to other objects within the namespace and the parent objects
909 * of name declarations
911 if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
916 /* We are only interested in opcodes that have an associated name */
918 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
920 if ((!(OpInfo->Flags & AML_NAMED)) &&
921 (!(OpInfo->Flags & AML_CREATE)) &&
922 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
923 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
924 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
930 * One special case: CondRefOf operator - we don't care if the name exists
931 * or not at this point, just ignore it, the point of the operator is to
932 * determine if the name exists at runtime.
934 if ((Op->Asl.Parent) &&
935 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
941 * We must enable the "search-to-root" for single NameSegs, but
942 * we have to be very careful about opening up scopes
944 Flags = ACPI_NS_SEARCH_PARENT;
945 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
946 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
947 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
950 * These are name references, do not push the scope stack
953 Flags |= ACPI_NS_DONT_OPEN_SCOPE;
956 /* Get the NamePath from the appropriate place */
958 if (OpInfo->Flags & AML_NAMED)
960 /* For nearly all NAMED operators, the name reference is the first child */
962 Path = Op->Asl.Child->Asl.Value.String;
963 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
966 * ALIAS is the only oddball opcode, the name declaration
967 * (alias name) is the second operand
969 Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
972 else if (OpInfo->Flags & AML_CREATE)
974 /* Name must appear as the last parameter */
976 NextOp = Op->Asl.Child;
977 while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
979 NextOp = NextOp->Asl.Next;
981 Path = NextOp->Asl.Value.String;
985 Path = Op->Asl.Value.String;
988 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
989 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
990 "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
993 * Lookup the name in the namespace. Name must exist at this point, or it
994 * is an invalid reference.
996 * The namespace is also used as a lookup table for references to resource
997 * descriptors and the fields within them.
1001 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
1002 ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
1003 if (ACPI_FAILURE (Status))
1005 if (Status == AE_NOT_FOUND)
1008 * We didn't find the name reference by path -- we can qualify this
1009 * a little better before we print an error message
1011 if (strlen (Path) == ACPI_NAME_SIZE)
1013 /* A simple, one-segment ACPI name */
1015 if (LkObjectExists (Path))
1018 * There exists such a name, but we couldn't get to it
1021 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
1022 Op->Asl.ExternalName);
1026 /* The name doesn't exist, period */
1028 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
1029 Op, Op->Asl.ExternalName);
1034 /* Check for a fully qualified path */
1036 if (Path[0] == AML_ROOT_PREFIX)
1038 /* Gave full path, the object does not exist */
1040 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
1041 Op->Asl.ExternalName);
1046 * We can't tell whether it doesn't exist or just
1049 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
1050 Op->Asl.ExternalName);
1059 /* Check for a reference vs. name declaration */
1061 if (!(OpInfo->Flags & AML_NAMED) &&
1062 !(OpInfo->Flags & AML_CREATE))
1064 /* This node has been referenced, mark it for reference check */
1066 Node->Flags |= ANOBJ_IS_REFERENCED;
1069 /* Attempt to optimize the NamePath */
1071 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
1074 * 1) Dereference an alias (A name reference that is an alias)
1075 * Aliases are not nested, the alias always points to the final object
1077 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
1078 (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
1080 /* This node points back to the original PARSEOP_ALIAS */
1084 /* The first child is the alias target op */
1086 NextOp = NextOp->Asl.Child;
1088 /* That in turn points back to original target alias node */
1090 if (NextOp->Asl.Node)
1092 Node = NextOp->Asl.Node;
1095 /* Else - forward reference to alias, will be resolved later */
1098 /* 2) Check for a reference to a resource descriptor */
1100 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
1101 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
1104 * This was a reference to a field within a resource descriptor. Extract
1105 * the associated field offset (either a bit or byte offset depending on
1106 * the field type) and change the named reference into an integer for
1107 * AML code generation
1110 if (Node->Flags & ANOBJ_IS_BIT_OFFSET)
1112 Op->Asl.CompileFlags |= NODE_IS_BIT_OFFSET;
1115 /* Perform BitOffset <--> ByteOffset conversion if necessary */
1117 switch (Op->Asl.Parent->Asl.AmlOpcode)
1119 case AML_CREATE_FIELD_OP:
1121 /* We allow a Byte offset to Bit Offset conversion for this op */
1123 if (!(Op->Asl.CompileFlags & NODE_IS_BIT_OFFSET))
1125 /* Simply multiply byte offset times 8 to get bit offset */
1127 Temp = ACPI_MUL_8 (Temp);
1132 case AML_CREATE_BIT_FIELD_OP:
1134 /* This op requires a Bit Offset */
1136 if (!(Op->Asl.CompileFlags & NODE_IS_BIT_OFFSET))
1138 AslError (ASL_ERROR, ASL_MSG_BYTES_TO_BITS, Op, NULL);
1143 case AML_CREATE_BYTE_FIELD_OP:
1144 case AML_CREATE_WORD_FIELD_OP:
1145 case AML_CREATE_DWORD_FIELD_OP:
1146 case AML_CREATE_QWORD_FIELD_OP:
1149 /* These Ops require Byte offsets */
1151 if (Op->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
1153 AslError (ASL_ERROR, ASL_MSG_BITS_TO_BYTES, Op, NULL);
1159 /* Nothing to do for other opcodes */
1163 /* Now convert this node to an integer whose value is the field offset */
1165 Op->Asl.AmlLength = 0;
1166 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
1167 Op->Asl.Value.Integer = (UINT64) Temp;
1168 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
1170 OpcGenerateAmlOpcode (Op);
1173 /* 3) Check for a method invocation */
1175 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
1176 (Node->Type == ACPI_TYPE_METHOD) &&
1178 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
1180 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1184 * A reference to a method within one of these opcodes is not an
1185 * invocation of the method, it is simply a reference to the method.
1187 if ((Op->Asl.Parent) &&
1188 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
1189 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF) ||
1190 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
1195 * There are two types of method invocation:
1196 * 1) Invocation with arguments -- the parser recognizes this
1198 * 2) Invocation with no arguments --the parser cannot determine that
1199 * this is a method invocation, therefore we have to figure it out
1202 if (Node->Type != ACPI_TYPE_METHOD)
1204 sprintf (MsgBuffer, "%s is a %s",
1205 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
1207 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
1211 /* Save the method node in the caller's op */
1213 Op->Asl.Node = Node;
1214 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
1220 * This is a method invocation, with or without arguments.
1221 * Count the number of arguments, each appears as a child
1222 * under the parent node
1224 Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
1225 UtSetParseOpName (Op);
1228 NextOp = Op->Asl.Child;
1233 NextOp = NextOp->Asl.Next;
1236 if (Node->Value != ASL_EXTERNAL_METHOD)
1239 * Check the parsed arguments with the number expected by the
1240 * method declaration itself
1242 if (PassedArgs != Node->Value)
1244 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1247 if (PassedArgs < Node->Value)
1249 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
1253 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
1259 /* 4) Check for an ASL Field definition */
1261 else if ((Op->Asl.Parent) &&
1262 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
1263 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1266 * Offset checking for fields. If the parent operation region has a
1267 * constant length (known at compile time), we can check fields
1268 * defined in that region against the region length. This will catch
1269 * fields and field units that cannot possibly fit within the region.
1271 * Note: Index fields do not directly reference an operation region,
1272 * thus they are not included in this check.
1274 if (Op == Op->Asl.Parent->Asl.Child)
1277 * This is the first child of the field node, which is
1278 * the name of the region. Get the parse node for the
1279 * region -- which contains the length of the region.
1281 OwningOp = Node->Op;
1282 Op->Asl.Parent->Asl.ExtraValue =
1283 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1285 /* Examine the field access width */
1287 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1289 case AML_FIELD_ACCESS_ANY:
1290 case AML_FIELD_ACCESS_BYTE:
1291 case AML_FIELD_ACCESS_BUFFER:
1296 case AML_FIELD_ACCESS_WORD:
1300 case AML_FIELD_ACCESS_DWORD:
1304 case AML_FIELD_ACCESS_QWORD:
1310 * Is the region at least as big as the access width?
1311 * Note: DataTableRegions have 0 length
1313 if (((UINT32) OwningOp->Asl.Value.Integer) &&
1314 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1316 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1320 * Check EC/CMOS/SMBUS fields to make sure that the correct
1321 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1323 SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1324 switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1329 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE)
1331 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1338 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER)
1340 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1346 /* Nothing to do for other address spaces */
1353 * This is one element of the field list. Check to make sure
1354 * that it does not go beyond the end of the parent operation region.
1356 * In the code below:
1357 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1358 * Op->Asl.ExtraValue - Field start offset (bits)
1359 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1360 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1362 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1364 LkCheckFieldRange (Op,
1365 Op->Asl.Parent->Asl.ExtraValue,
1367 (UINT32) Op->Asl.Child->Asl.Value.Integer,
1368 Op->Asl.Child->Asl.ExtraValue);
1373 Op->Asl.Node = Node;
1378 /*******************************************************************************
1380 * FUNCTION: LkNamespaceLocateEnd
1382 * PARAMETERS: ASL_WALK_CALLBACK
1386 * DESCRIPTION: Ascending callback used during cross reference. We only
1387 * need to worry about scope management here.
1389 ******************************************************************************/
1392 LkNamespaceLocateEnd (
1393 ACPI_PARSE_OBJECT *Op,
1397 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1398 const ACPI_OPCODE_INFO *OpInfo;
1401 ACPI_FUNCTION_TRACE (LkNamespaceLocateEnd);
1404 /* We are only interested in opcodes that have an associated name */
1406 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1407 if (!(OpInfo->Flags & AML_NAMED))
1412 /* Not interested in name references, we did not open a scope for them */
1414 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1415 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1416 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1421 /* Pop the scope stack if necessary */
1423 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1426 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1427 "%s: Popping scope for Op %p\n",
1428 AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1430 (void) AcpiDsScopeStackPop (WalkState);