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 UINT32 FieldBitLength;
829 const ACPI_OPCODE_INFO *OpInfo;
833 ACPI_FUNCTION_TRACE_PTR (LkNamespaceLocateBegin, Op);
836 * If this node is the actual declaration of a name
837 * [such as the XXXX name in "Method (XXXX)"],
838 * we are not interested in it here. We only care about names that are
839 * references to other objects within the namespace and the parent objects
840 * of name declarations
842 if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
847 /* We are only interested in opcodes that have an associated name */
849 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
851 if ((!(OpInfo->Flags & AML_NAMED)) &&
852 (!(OpInfo->Flags & AML_CREATE)) &&
853 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
854 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
855 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
861 * One special case: CondRefOf operator - we don't care if the name exists
862 * or not at this point, just ignore it, the point of the operator is to
863 * determine if the name exists at runtime.
865 if ((Op->Asl.Parent) &&
866 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
872 * We must enable the "search-to-root" for single NameSegs, but
873 * we have to be very careful about opening up scopes
875 Flags = ACPI_NS_SEARCH_PARENT;
876 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
877 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
878 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
881 * These are name references, do not push the scope stack
884 Flags |= ACPI_NS_DONT_OPEN_SCOPE;
887 /* Get the NamePath from the appropriate place */
889 if (OpInfo->Flags & AML_NAMED)
891 /* For nearly all NAMED operators, the name reference is the first child */
893 Path = Op->Asl.Child->Asl.Value.String;
894 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
897 * ALIAS is the only oddball opcode, the name declaration
898 * (alias name) is the second operand
900 Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
903 else if (OpInfo->Flags & AML_CREATE)
905 /* Name must appear as the last parameter */
907 NextOp = Op->Asl.Child;
908 while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
910 NextOp = NextOp->Asl.Next;
912 Path = NextOp->Asl.Value.String;
916 Path = Op->Asl.Value.String;
919 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
920 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
921 "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
924 * Lookup the name in the namespace. Name must exist at this point, or it
925 * is an invalid reference.
927 * The namespace is also used as a lookup table for references to resource
928 * descriptors and the fields within them.
932 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
933 ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
934 if (ACPI_FAILURE (Status))
936 if (Status == AE_NOT_FOUND)
939 * We didn't find the name reference by path -- we can qualify this
940 * a little better before we print an error message
942 if (strlen (Path) == ACPI_NAME_SIZE)
944 /* A simple, one-segment ACPI name */
946 if (LkObjectExists (Path))
949 * There exists such a name, but we couldn't get to it
952 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
953 Op->Asl.ExternalName);
957 /* The name doesn't exist, period */
959 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
960 Op, Op->Asl.ExternalName);
965 /* Check for a fully qualified path */
967 if (Path[0] == AML_ROOT_PREFIX)
969 /* Gave full path, the object does not exist */
971 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
972 Op->Asl.ExternalName);
977 * We can't tell whether it doesn't exist or just
980 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
981 Op->Asl.ExternalName);
990 /* Check for a reference vs. name declaration */
992 if (!(OpInfo->Flags & AML_NAMED) &&
993 !(OpInfo->Flags & AML_CREATE))
995 /* This node has been referenced, mark it for reference check */
997 Node->Flags |= ANOBJ_IS_REFERENCED;
1000 /* Attempt to optimize the NamePath */
1002 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
1005 * 1) Dereference an alias (A name reference that is an alias)
1006 * Aliases are not nested, the alias always points to the final object
1008 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
1009 (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
1011 /* This node points back to the original PARSEOP_ALIAS */
1015 /* The first child is the alias target op */
1017 NextOp = NextOp->Asl.Child;
1019 /* That in turn points back to original target alias node */
1021 if (NextOp->Asl.Node)
1023 Node = NextOp->Asl.Node;
1026 /* Else - forward reference to alias, will be resolved later */
1029 /* 2) Check for a reference to a resource descriptor */
1031 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
1032 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
1035 * This was a reference to a field within a resource descriptor.
1036 * Extract the associated field offset (either a bit or byte
1037 * offset depending on the field type) and change the named
1038 * reference into an integer for AML code generation
1040 Offset = Node->Value;
1041 TagBitLength = Node->Length;
1044 * If a field is being created, generate the length (in bits) of
1045 * the field. Note: Opcodes other than CreateXxxField and Index
1046 * can come through here. For other opcodes, we just need to
1047 * convert the resource tag reference to an integer offset.
1049 switch (Op->Asl.Parent->Asl.AmlOpcode)
1051 case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
1053 * We know the length operand is an integer constant because
1054 * we know that it contains a reference to a resource
1057 FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
1060 case AML_CREATE_BIT_FIELD_OP:
1064 case AML_CREATE_BYTE_FIELD_OP:
1069 case AML_CREATE_WORD_FIELD_OP:
1070 FieldBitLength = 16;
1073 case AML_CREATE_DWORD_FIELD_OP:
1074 FieldBitLength = 32;
1077 case AML_CREATE_QWORD_FIELD_OP:
1078 FieldBitLength = 64;
1086 /* Check the field length against the length of the resource tag */
1090 if (TagBitLength < FieldBitLength)
1092 Message = ASL_MSG_TAG_SMALLER;
1094 else if (TagBitLength > FieldBitLength)
1096 Message = ASL_MSG_TAG_LARGER;
1101 sprintf (MsgBuffer, "Tag: %u bit%s, Field: %u bit%s",
1102 TagBitLength, (TagBitLength > 1) ? "s" : "",
1103 FieldBitLength, (FieldBitLength > 1) ? "s" : "");
1105 AslError (ASL_WARNING, Message, Op, MsgBuffer);
1109 /* Convert the BitOffset to a ByteOffset for certain opcodes */
1111 switch (Op->Asl.Parent->Asl.AmlOpcode)
1113 case AML_CREATE_BYTE_FIELD_OP:
1114 case AML_CREATE_WORD_FIELD_OP:
1115 case AML_CREATE_DWORD_FIELD_OP:
1116 case AML_CREATE_QWORD_FIELD_OP:
1119 Offset = ACPI_DIV_8 (Offset);
1126 /* Now convert this node to an integer whose value is the field offset */
1128 Op->Asl.AmlLength = 0;
1129 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
1130 Op->Asl.Value.Integer = (UINT64) Offset;
1131 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
1133 OpcGenerateAmlOpcode (Op);
1136 /* 3) Check for a method invocation */
1138 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
1139 (Node->Type == ACPI_TYPE_METHOD) &&
1141 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
1143 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1147 * A reference to a method within one of these opcodes is not an
1148 * invocation of the method, it is simply a reference to the method.
1150 if ((Op->Asl.Parent) &&
1151 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
1152 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF) ||
1153 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
1158 * There are two types of method invocation:
1159 * 1) Invocation with arguments -- the parser recognizes this
1161 * 2) Invocation with no arguments --the parser cannot determine that
1162 * this is a method invocation, therefore we have to figure it out
1165 if (Node->Type != ACPI_TYPE_METHOD)
1167 sprintf (MsgBuffer, "%s is a %s",
1168 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
1170 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
1174 /* Save the method node in the caller's op */
1176 Op->Asl.Node = Node;
1177 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
1183 * This is a method invocation, with or without arguments.
1184 * Count the number of arguments, each appears as a child
1185 * under the parent node
1187 Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
1188 UtSetParseOpName (Op);
1191 NextOp = Op->Asl.Child;
1196 NextOp = NextOp->Asl.Next;
1199 if (Node->Value != ASL_EXTERNAL_METHOD)
1202 * Check the parsed arguments with the number expected by the
1203 * method declaration itself
1205 if (PassedArgs != Node->Value)
1207 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1210 if (PassedArgs < Node->Value)
1212 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
1216 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
1222 /* 4) Check for an ASL Field definition */
1224 else if ((Op->Asl.Parent) &&
1225 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
1226 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1229 * Offset checking for fields. If the parent operation region has a
1230 * constant length (known at compile time), we can check fields
1231 * defined in that region against the region length. This will catch
1232 * fields and field units that cannot possibly fit within the region.
1234 * Note: Index fields do not directly reference an operation region,
1235 * thus they are not included in this check.
1237 if (Op == Op->Asl.Parent->Asl.Child)
1240 * This is the first child of the field node, which is
1241 * the name of the region. Get the parse node for the
1242 * region -- which contains the length of the region.
1244 OwningOp = Node->Op;
1245 Op->Asl.Parent->Asl.ExtraValue =
1246 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1248 /* Examine the field access width */
1250 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1252 case AML_FIELD_ACCESS_ANY:
1253 case AML_FIELD_ACCESS_BYTE:
1254 case AML_FIELD_ACCESS_BUFFER:
1259 case AML_FIELD_ACCESS_WORD:
1263 case AML_FIELD_ACCESS_DWORD:
1267 case AML_FIELD_ACCESS_QWORD:
1273 * Is the region at least as big as the access width?
1274 * Note: DataTableRegions have 0 length
1276 if (((UINT32) OwningOp->Asl.Value.Integer) &&
1277 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1279 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1283 * Check EC/CMOS/SMBUS fields to make sure that the correct
1284 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1286 SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1287 switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1289 case ACPI_ADR_SPACE_EC:
1290 case ACPI_ADR_SPACE_CMOS:
1291 case ACPI_ADR_SPACE_GPIO:
1293 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE)
1295 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1299 case ACPI_ADR_SPACE_SMBUS:
1300 case ACPI_ADR_SPACE_IPMI:
1301 case ACPI_ADR_SPACE_GSBUS:
1303 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER)
1305 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1311 /* Nothing to do for other address spaces */
1318 * This is one element of the field list. Check to make sure
1319 * that it does not go beyond the end of the parent operation region.
1321 * In the code below:
1322 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1323 * Op->Asl.ExtraValue - Field start offset (bits)
1324 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1325 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1327 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1329 LkCheckFieldRange (Op,
1330 Op->Asl.Parent->Asl.ExtraValue,
1332 (UINT32) Op->Asl.Child->Asl.Value.Integer,
1333 Op->Asl.Child->Asl.ExtraValue);
1338 Op->Asl.Node = Node;
1343 /*******************************************************************************
1345 * FUNCTION: LkNamespaceLocateEnd
1347 * PARAMETERS: ASL_WALK_CALLBACK
1351 * DESCRIPTION: Ascending callback used during cross reference. We only
1352 * need to worry about scope management here.
1354 ******************************************************************************/
1357 LkNamespaceLocateEnd (
1358 ACPI_PARSE_OBJECT *Op,
1362 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1363 const ACPI_OPCODE_INFO *OpInfo;
1366 ACPI_FUNCTION_TRACE (LkNamespaceLocateEnd);
1369 /* We are only interested in opcodes that have an associated name */
1371 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1372 if (!(OpInfo->Flags & AML_NAMED))
1377 /* Not interested in name references, we did not open a scope for them */
1379 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1380 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1381 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1386 /* Pop the scope stack if necessary */
1388 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1391 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1392 "%s: Popping scope for Op %p\n",
1393 AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1395 (void) AcpiDsScopeStackPop (WalkState);