1 /******************************************************************************
3 * Module Name: asllookup- Namespace lookup
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include "aslcompiler.y.h"
48 #include <contrib/dev/acpica/include/acparser.h>
49 #include <contrib/dev/acpica/include/amlcode.h>
50 #include <contrib/dev/acpica/include/acnamesp.h>
51 #include <contrib/dev/acpica/include/acdispat.h>
54 #define _COMPONENT ACPI_COMPILER
55 ACPI_MODULE_NAME ("asllookup")
57 /* Local prototypes */
60 LsCompareOneNamespaceObject (
61 ACPI_HANDLE ObjHandle,
67 LsDoOneNamespaceObject (
68 ACPI_HANDLE ObjHandle,
79 ACPI_PARSE_OBJECT *Op,
80 UINT32 RegionBitLength,
81 UINT32 FieldBitOffset,
82 UINT32 FieldBitLength,
83 UINT32 AccessBitWidth);
86 LkNamespaceLocateBegin (
87 ACPI_PARSE_OBJECT *Op,
92 LkNamespaceLocateEnd (
93 ACPI_PARSE_OBJECT *Op,
99 ACPI_HANDLE ObjHandle,
106 ACPI_HANDLE ObjHandle,
111 static ACPI_PARSE_OBJECT *
113 ACPI_PARSE_OBJECT *Op);
116 /*******************************************************************************
118 * FUNCTION: LsDoOneNamespaceObject
120 * PARAMETERS: ACPI_WALK_CALLBACK
124 * DESCRIPTION: Dump a namespace object to the namespace output file.
125 * Called during the walk of the namespace to dump all objects.
127 ******************************************************************************/
130 LsDoOneNamespaceObject (
131 ACPI_HANDLE ObjHandle,
136 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
137 ACPI_OPERAND_OBJECT *ObjDesc;
138 ACPI_PARSE_OBJECT *Op;
141 Gbl_NumNamespaceObjects++;
143 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s",
144 Gbl_NumNamespaceObjects, Level, (Level * 3), " ",
146 AcpiUtGetTypeName (Node->Type));
149 ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
153 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
159 (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
163 case ACPI_TYPE_INTEGER:
165 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
166 " [Initial Value 0x%8.8X%8.8X]",
167 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
171 case ACPI_TYPE_STRING:
173 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
174 " [Initial Value \"%s\"]",
175 ObjDesc->String.Pointer);
179 /* Nothing to do for other types */
188 case ACPI_TYPE_INTEGER:
190 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
194 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
195 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
199 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
200 " [Initial Value 0x%8.8X%8.8X]",
201 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
205 case ACPI_TYPE_STRING:
207 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
211 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
212 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
216 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
217 " [Initial Value \"%s\"]",
218 Op->Asl.Value.String);
222 case ACPI_TYPE_LOCAL_REGION_FIELD:
224 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
225 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
229 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
230 " [Offset 0x%04X Length 0x%04X bits]",
231 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
235 case ACPI_TYPE_BUFFER_FIELD:
237 switch (Op->Asl.ParseOpcode)
239 case PARSEOP_CREATEBYTEFIELD:
240 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BYTE ( 8 bit)]");
243 case PARSEOP_CREATEDWORDFIELD:
244 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [DWORD (32 bit)]");
247 case PARSEOP_CREATEQWORDFIELD:
248 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [QWORD (64 bit)]");
251 case PARSEOP_CREATEWORDFIELD:
252 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [WORD (16 bit)]");
255 case PARSEOP_CREATEBITFIELD:
256 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BIT ( 1 bit)]");
259 case PARSEOP_CREATEFIELD:
260 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [Arbitrary Bit Field]");
270 case ACPI_TYPE_PACKAGE:
272 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
276 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
277 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
283 if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
284 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
286 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
287 " [Initial Length 0x%.2X elements]",
288 Op->Asl.Value.Integer);
293 case ACPI_TYPE_BUFFER:
295 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
299 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
300 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
306 if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
308 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
309 " [Initial Length 0x%.2X bytes]",
310 Op->Asl.Value.Integer);
315 case ACPI_TYPE_METHOD:
317 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
318 " [Code Length 0x%.4X bytes]",
319 Op->Asl.AmlSubtreeLength);
323 case ACPI_TYPE_LOCAL_RESOURCE:
325 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
326 " [Desc Offset 0x%.4X Bytes]", Node->Value);
330 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
332 if (Node->Flags & 0x80)
334 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
335 " [Field Offset 0x%.4X Bits 0x%.4X Bytes]",
336 Node->Value, Node->Value / 8);
340 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
341 " [Field Offset 0x%.4X Bytes]", Node->Value);
347 /* Nothing to do for other types */
352 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
357 /*******************************************************************************
359 * FUNCTION: LsSetupNsList
361 * PARAMETERS: Handle - local file handle
365 * DESCRIPTION: Set the namespace output file to the input handle
367 ******************************************************************************/
374 Gbl_NsOutputFlag = TRUE;
375 Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
379 /*******************************************************************************
381 * FUNCTION: LsDoOnePathname
383 * PARAMETERS: ACPI_WALK_CALLBACK
387 * DESCRIPTION: Print the full pathname for a namespace node.
389 ******************************************************************************/
393 ACPI_HANDLE ObjHandle,
398 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
400 ACPI_BUFFER TargetPath;
403 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
404 Status = AcpiNsHandleToPathname (Node, &TargetPath);
405 if (ACPI_FAILURE (Status))
410 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer);
411 ACPI_FREE (TargetPath.Pointer);
417 /*******************************************************************************
419 * FUNCTION: LsDisplayNamespace
425 * DESCRIPTION: Walk the namespace an display information about each node
426 * in the tree. Information is written to the optional
427 * namespace output file.
429 ******************************************************************************/
438 if (!Gbl_NsOutputFlag)
443 Gbl_NumNamespaceObjects = 0;
447 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
448 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count Depth Name - Type\n\n");
450 /* Walk entire namespace from the root */
452 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
453 ACPI_UINT32_MAX, FALSE, LsDoOneNamespaceObject, NULL,
456 /* Print the full pathname for each namespace node */
458 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
460 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
461 ACPI_UINT32_MAX, FALSE, LsDoOnePathname, NULL,
468 /*******************************************************************************
470 * FUNCTION: LsCompareOneNamespaceObject
472 * PARAMETERS: ACPI_WALK_CALLBACK
476 * DESCRIPTION: Compare name of one object.
478 ******************************************************************************/
481 LsCompareOneNamespaceObject (
482 ACPI_HANDLE ObjHandle,
487 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
490 /* Simply check the name */
492 if (*((UINT32 *) (Context)) == Node->Name.Integer)
494 /* Abort walk if we found one instance */
496 return (AE_CTRL_TRUE);
503 /*******************************************************************************
505 * FUNCTION: LkObjectExists
507 * PARAMETERS: Name - 4 char ACPI name
509 * RETURN: TRUE if name exists in namespace
511 * DESCRIPTION: Walk the namespace to find an object
513 ******************************************************************************/
522 /* Walk entire namespace from the supplied root */
524 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
525 ACPI_UINT32_MAX, FALSE, LsCompareOneNamespaceObject, NULL,
527 if (Status == AE_CTRL_TRUE)
529 /* At least one instance of the name was found */
538 /*******************************************************************************
540 * FUNCTION: LkGetNameOp
542 * PARAMETERS: Op - Current Op
544 * RETURN: NameOp associated with the input op
546 * DESCRIPTION: Find the name declaration op associated with the operator
548 ******************************************************************************/
550 static ACPI_PARSE_OBJECT *
552 ACPI_PARSE_OBJECT *Op)
554 const ACPI_OPCODE_INFO *OpInfo;
555 ACPI_PARSE_OBJECT *NameOp = Op;
558 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
561 /* Get the NamePath from the appropriate place */
563 if (OpInfo->Flags & AML_NAMED)
565 /* For nearly all NAMED operators, the name reference is the first child */
567 NameOp = Op->Asl.Child;
568 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
571 * ALIAS is the only oddball opcode, the name declaration
572 * (alias name) is the second operand
574 NameOp = Op->Asl.Child->Asl.Next;
577 else if (OpInfo->Flags & AML_CREATE)
579 /* Name must appear as the last parameter */
581 NameOp = Op->Asl.Child;
582 while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
584 NameOp = NameOp->Asl.Next;
592 /*******************************************************************************
594 * FUNCTION: LkIsObjectUsed
596 * PARAMETERS: ACPI_WALK_CALLBACK
600 * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
601 * We have to be careful, because some types and names are
602 * typically or always unreferenced, we don't want to issue
603 * excessive warnings.
605 ******************************************************************************/
609 ACPI_HANDLE ObjHandle,
614 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
617 /* Referenced flag is set during the namespace xref */
619 if (Node->Flags & ANOBJ_IS_REFERENCED)
625 * Ignore names that start with an underscore,
626 * these are the reserved ACPI names and are typically not referenced,
627 * they are called by the host OS.
629 if (Node->Name.Ascii[0] == '_')
634 /* There are some types that are typically not referenced, ignore them */
638 case ACPI_TYPE_DEVICE:
639 case ACPI_TYPE_PROCESSOR:
640 case ACPI_TYPE_POWER:
641 case ACPI_TYPE_LOCAL_RESOURCE:
648 /* All others are valid unreferenced namespace objects */
652 AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, LkGetNameOp (Node->Op), NULL);
658 /*******************************************************************************
660 * FUNCTION: LkFindUnreferencedObjects
666 * DESCRIPTION: Namespace walk to find objects that are not referenced in any
667 * way. Must be called after the namespace has been cross
670 ******************************************************************************/
673 LkFindUnreferencedObjects (
677 /* Walk entire namespace from the supplied root */
679 (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
680 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
685 /*******************************************************************************
687 * FUNCTION: LkCrossReferenceNamespace
693 * DESCRIPTION: Perform a cross reference check of the parse tree against the
694 * namespace. Every named referenced within the parse tree
695 * should be get resolved with a namespace lookup. If not, the
696 * original reference in the ASL code is invalid -- i.e., refers
697 * to a non-existent object.
699 * NOTE: The ASL "External" operator causes the name to be inserted into the
700 * namespace so that references to the external name will be resolved
703 ******************************************************************************/
706 LkCrossReferenceNamespace (
709 ACPI_WALK_STATE *WalkState;
712 DbgPrint (ASL_DEBUG_OUTPUT, "\nCross referencing namespace\n\n");
715 * Create a new walk state for use when looking up names
716 * within the namespace (Passed as context to the callbacks)
718 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
724 /* Walk the entire parse tree */
726 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, LkNamespaceLocateBegin,
727 LkNamespaceLocateEnd, WalkState);
732 /*******************************************************************************
734 * FUNCTION: LkCheckFieldRange
736 * PARAMETERS: RegionBitLength - Length of entire parent region
737 * FieldBitOffset - Start of the field unit (within region)
738 * FieldBitLength - Entire length of field unit
739 * AccessBitWidth - Access width of the field unit
743 * DESCRIPTION: Check one field unit to make sure it fits in the parent
746 * Note: AccessBitWidth must be either 8,16,32, or 64
748 ******************************************************************************/
752 ACPI_PARSE_OBJECT *Op,
753 UINT32 RegionBitLength,
754 UINT32 FieldBitOffset,
755 UINT32 FieldBitLength,
756 UINT32 AccessBitWidth)
758 UINT32 FieldEndBitOffset;
762 * Check each field unit against the region size. The entire
763 * field unit (start offset plus length) must fit within the
766 FieldEndBitOffset = FieldBitOffset + FieldBitLength;
768 if (FieldEndBitOffset > RegionBitLength)
770 /* Field definition itself is beyond the end-of-region */
772 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
777 * Now check that the field plus AccessWidth doesn't go beyond
778 * the end-of-region. Assumes AccessBitWidth is a power of 2
780 FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
782 if (FieldEndBitOffset > RegionBitLength)
784 /* Field definition combined with the access is beyond EOR */
786 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
790 /*******************************************************************************
792 * FUNCTION: LkNamespaceLocateBegin
794 * PARAMETERS: ASL_WALK_CALLBACK
798 * DESCRIPTION: Descending callback used during cross-reference. For named
799 * object references, attempt to locate the name in the
802 * NOTE: ASL references to named fields within resource descriptors are
803 * resolved to integer values here. Therefore, this step is an
804 * important part of the code generation. We don't know that the
805 * name refers to a resource descriptor until now.
807 ******************************************************************************/
810 LkNamespaceLocateBegin (
811 ACPI_PARSE_OBJECT *Op,
815 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
816 ACPI_NAMESPACE_NODE *Node;
818 ACPI_OBJECT_TYPE ObjectType;
821 ACPI_PARSE_OBJECT *NextOp;
822 ACPI_PARSE_OBJECT *OwningOp;
823 ACPI_PARSE_OBJECT *SpaceIdOp;
824 UINT32 MinimumLength;
826 const ACPI_OPCODE_INFO *OpInfo;
830 ACPI_FUNCTION_TRACE_PTR (LkNamespaceLocateBegin, Op);
833 * If this node is the actual declaration of a name
834 * [such as the XXXX name in "Method (XXXX)"],
835 * we are not interested in it here. We only care about names that are
836 * references to other objects within the namespace and the parent objects
837 * of name declarations
839 if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
844 /* We are only interested in opcodes that have an associated name */
846 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
848 if ((!(OpInfo->Flags & AML_NAMED)) &&
849 (!(OpInfo->Flags & AML_CREATE)) &&
850 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
851 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
852 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
858 * One special case: CondRefOf operator - we don't care if the name exists
859 * or not at this point, just ignore it, the point of the operator is to
860 * determine if the name exists at runtime.
862 if ((Op->Asl.Parent) &&
863 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
869 * We must enable the "search-to-root" for single NameSegs, but
870 * we have to be very careful about opening up scopes
872 Flags = ACPI_NS_SEARCH_PARENT;
873 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
874 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
875 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
878 * These are name references, do not push the scope stack
881 Flags |= ACPI_NS_DONT_OPEN_SCOPE;
884 /* Get the NamePath from the appropriate place */
886 if (OpInfo->Flags & AML_NAMED)
888 /* For nearly all NAMED operators, the name reference is the first child */
890 Path = Op->Asl.Child->Asl.Value.String;
891 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
894 * ALIAS is the only oddball opcode, the name declaration
895 * (alias name) is the second operand
897 Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
900 else if (OpInfo->Flags & AML_CREATE)
902 /* Name must appear as the last parameter */
904 NextOp = Op->Asl.Child;
905 while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
907 NextOp = NextOp->Asl.Next;
909 Path = NextOp->Asl.Value.String;
913 Path = Op->Asl.Value.String;
916 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
917 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
918 "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
921 * Lookup the name in the namespace. Name must exist at this point, or it
922 * is an invalid reference.
924 * The namespace is also used as a lookup table for references to resource
925 * descriptors and the fields within them.
929 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
930 ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
931 if (ACPI_FAILURE (Status))
933 if (Status == AE_NOT_FOUND)
936 * We didn't find the name reference by path -- we can qualify this
937 * a little better before we print an error message
939 if (strlen (Path) == ACPI_NAME_SIZE)
941 /* A simple, one-segment ACPI name */
943 if (LkObjectExists (Path))
946 * There exists such a name, but we couldn't get to it
949 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
950 Op->Asl.ExternalName);
954 /* The name doesn't exist, period */
956 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
957 Op, Op->Asl.ExternalName);
962 /* Check for a fully qualified path */
964 if (Path[0] == AML_ROOT_PREFIX)
966 /* Gave full path, the object does not exist */
968 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
969 Op->Asl.ExternalName);
974 * We can't tell whether it doesn't exist or just
977 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
978 Op->Asl.ExternalName);
987 /* Check for a reference vs. name declaration */
989 if (!(OpInfo->Flags & AML_NAMED) &&
990 !(OpInfo->Flags & AML_CREATE))
992 /* This node has been referenced, mark it for reference check */
994 Node->Flags |= ANOBJ_IS_REFERENCED;
997 /* Attempt to optimize the NamePath */
999 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
1002 * 1) Dereference an alias (A name reference that is an alias)
1003 * Aliases are not nested, the alias always points to the final object
1005 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
1006 (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
1008 /* This node points back to the original PARSEOP_ALIAS */
1012 /* The first child is the alias target op */
1014 NextOp = NextOp->Asl.Child;
1016 /* That in turn points back to original target alias node */
1018 if (NextOp->Asl.Node)
1020 Node = NextOp->Asl.Node;
1023 /* Else - forward reference to alias, will be resolved later */
1026 /* 2) Check for a reference to a resource descriptor */
1028 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
1029 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
1032 * This was a reference to a field within a resource descriptor. Extract
1033 * the associated field offset (either a bit or byte offset depending on
1034 * the field type) and change the named reference into an integer for
1035 * AML code generation
1038 if (Node->Flags & ANOBJ_IS_BIT_OFFSET)
1040 Op->Asl.CompileFlags |= NODE_IS_BIT_OFFSET;
1043 /* Perform BitOffset <--> ByteOffset conversion if necessary */
1045 switch (Op->Asl.Parent->Asl.AmlOpcode)
1047 case AML_CREATE_FIELD_OP:
1049 /* We allow a Byte offset to Bit Offset conversion for this op */
1051 if (!(Op->Asl.CompileFlags & NODE_IS_BIT_OFFSET))
1053 /* Simply multiply byte offset times 8 to get bit offset */
1055 Temp = ACPI_MUL_8 (Temp);
1060 case AML_CREATE_BIT_FIELD_OP:
1062 /* This op requires a Bit Offset */
1064 if (!(Op->Asl.CompileFlags & NODE_IS_BIT_OFFSET))
1066 AslError (ASL_ERROR, ASL_MSG_BYTES_TO_BITS, Op, NULL);
1071 case AML_CREATE_BYTE_FIELD_OP:
1072 case AML_CREATE_WORD_FIELD_OP:
1073 case AML_CREATE_DWORD_FIELD_OP:
1074 case AML_CREATE_QWORD_FIELD_OP:
1077 /* These Ops require Byte offsets */
1079 if (Op->Asl.CompileFlags & NODE_IS_BIT_OFFSET)
1081 AslError (ASL_ERROR, ASL_MSG_BITS_TO_BYTES, Op, NULL);
1087 /* Nothing to do for other opcodes */
1091 /* Now convert this node to an integer whose value is the field offset */
1093 Op->Asl.AmlLength = 0;
1094 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
1095 Op->Asl.Value.Integer = (UINT64) Temp;
1096 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
1098 OpcGenerateAmlOpcode (Op);
1101 /* 3) Check for a method invocation */
1103 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
1104 (Node->Type == ACPI_TYPE_METHOD) &&
1106 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
1108 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1112 * A reference to a method within one of these opcodes is not an
1113 * invocation of the method, it is simply a reference to the method.
1115 if ((Op->Asl.Parent) &&
1116 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
1117 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF) ||
1118 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
1123 * There are two types of method invocation:
1124 * 1) Invocation with arguments -- the parser recognizes this
1126 * 2) Invocation with no arguments --the parser cannot determine that
1127 * this is a method invocation, therefore we have to figure it out
1130 if (Node->Type != ACPI_TYPE_METHOD)
1132 sprintf (MsgBuffer, "%s is a %s",
1133 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
1135 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
1139 /* Save the method node in the caller's op */
1141 Op->Asl.Node = Node;
1142 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
1148 * This is a method invocation, with or without arguments.
1149 * Count the number of arguments, each appears as a child
1150 * under the parent node
1152 Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
1153 UtSetParseOpName (Op);
1156 NextOp = Op->Asl.Child;
1161 NextOp = NextOp->Asl.Next;
1164 if (Node->Value != ASL_EXTERNAL_METHOD)
1167 * Check the parsed arguments with the number expected by the
1168 * method declaration itself
1170 if (PassedArgs != Node->Value)
1172 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1175 if (PassedArgs < Node->Value)
1177 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
1181 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
1187 /* 4) Check for an ASL Field definition */
1189 else if ((Op->Asl.Parent) &&
1190 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
1191 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1194 * Offset checking for fields. If the parent operation region has a
1195 * constant length (known at compile time), we can check fields
1196 * defined in that region against the region length. This will catch
1197 * fields and field units that cannot possibly fit within the region.
1199 * Note: Index fields do not directly reference an operation region,
1200 * thus they are not included in this check.
1202 if (Op == Op->Asl.Parent->Asl.Child)
1205 * This is the first child of the field node, which is
1206 * the name of the region. Get the parse node for the
1207 * region -- which contains the length of the region.
1209 OwningOp = Node->Op;
1210 Op->Asl.Parent->Asl.ExtraValue =
1211 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1213 /* Examine the field access width */
1215 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1217 case AML_FIELD_ACCESS_ANY:
1218 case AML_FIELD_ACCESS_BYTE:
1219 case AML_FIELD_ACCESS_BUFFER:
1224 case AML_FIELD_ACCESS_WORD:
1228 case AML_FIELD_ACCESS_DWORD:
1232 case AML_FIELD_ACCESS_QWORD:
1238 * Is the region at least as big as the access width?
1239 * Note: DataTableRegions have 0 length
1241 if (((UINT32) OwningOp->Asl.Value.Integer) &&
1242 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1244 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1248 * Check EC/CMOS/SMBUS fields to make sure that the correct
1249 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1251 SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1252 switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1254 case ACPI_ADR_SPACE_EC:
1255 case ACPI_ADR_SPACE_CMOS:
1257 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE)
1259 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1263 case ACPI_ADR_SPACE_SMBUS:
1264 case ACPI_ADR_SPACE_IPMI:
1266 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER)
1268 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1274 /* Nothing to do for other address spaces */
1281 * This is one element of the field list. Check to make sure
1282 * that it does not go beyond the end of the parent operation region.
1284 * In the code below:
1285 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1286 * Op->Asl.ExtraValue - Field start offset (bits)
1287 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1288 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1290 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1292 LkCheckFieldRange (Op,
1293 Op->Asl.Parent->Asl.ExtraValue,
1295 (UINT32) Op->Asl.Child->Asl.Value.Integer,
1296 Op->Asl.Child->Asl.ExtraValue);
1301 Op->Asl.Node = Node;
1306 /*******************************************************************************
1308 * FUNCTION: LkNamespaceLocateEnd
1310 * PARAMETERS: ASL_WALK_CALLBACK
1314 * DESCRIPTION: Ascending callback used during cross reference. We only
1315 * need to worry about scope management here.
1317 ******************************************************************************/
1320 LkNamespaceLocateEnd (
1321 ACPI_PARSE_OBJECT *Op,
1325 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1326 const ACPI_OPCODE_INFO *OpInfo;
1329 ACPI_FUNCTION_TRACE (LkNamespaceLocateEnd);
1332 /* We are only interested in opcodes that have an associated name */
1334 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1335 if (!(OpInfo->Flags & AML_NAMED))
1340 /* Not interested in name references, we did not open a scope for them */
1342 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1343 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1344 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1349 /* Pop the scope stack if necessary */
1351 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1354 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1355 "%s: Popping scope for Op %p\n",
1356 AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1358 (void) AcpiDsScopeStackPop (WalkState);