1 /******************************************************************************
3 * Module Name: aslxref - Namespace cross-reference
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/acparser.h>
47 #include <contrib/dev/acpica/include/amlcode.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 #include <contrib/dev/acpica/include/acdispat.h>
52 #define _COMPONENT ACPI_COMPILER
53 ACPI_MODULE_NAME ("aslxref")
55 /* Local prototypes */
58 XfNamespaceLocateBegin (
59 ACPI_PARSE_OBJECT *Op,
64 XfNamespaceLocateEnd (
65 ACPI_PARSE_OBJECT *Op,
69 static ACPI_PARSE_OBJECT *
71 ACPI_PARSE_OBJECT *Op);
78 XfCompareOneNamespaceObject (
79 ACPI_HANDLE ObjHandle,
86 ACPI_PARSE_OBJECT *Op,
87 UINT32 RegionBitLength,
88 UINT32 FieldBitOffset,
89 UINT32 FieldBitLength,
90 UINT32 AccessBitWidth);
92 #ifdef __UNDER_DEVELOPMENT
93 static ACPI_PARSE_OBJECT *
95 ACPI_PARSE_OBJECT *Op);
98 XfCheckIllegalReference (
99 ACPI_PARSE_OBJECT *Op,
100 ACPI_NAMESPACE_NODE *Node);
104 ACPI_PARSE_OBJECT *MethodOp1,
105 ACPI_PARSE_OBJECT *MethodOp2);
109 /*******************************************************************************
111 * FUNCTION: XfCrossReferenceNamespace
117 * DESCRIPTION: Perform a cross reference check of the parse tree against the
118 * namespace. Every named referenced within the parse tree
119 * should be get resolved with a namespace lookup. If not, the
120 * original reference in the ASL code is invalid -- i.e., refers
121 * to a non-existent object.
123 * NOTE: The ASL "External" operator causes the name to be inserted into the
124 * namespace so that references to the external name will be resolved
127 ******************************************************************************/
130 XfCrossReferenceNamespace (
133 ACPI_WALK_STATE *WalkState;
136 DbgPrint (ASL_DEBUG_OUTPUT, "\nCross referencing namespace\n\n");
139 * Create a new walk state for use when looking up names
140 * within the namespace (Passed as context to the callbacks)
142 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
145 return (AE_NO_MEMORY);
148 /* Walk the entire parse tree */
150 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, XfNamespaceLocateBegin,
151 XfNamespaceLocateEnd, WalkState);
153 ACPI_FREE (WalkState);
158 /*******************************************************************************
160 * FUNCTION: XfObjectExists
162 * PARAMETERS: Name - 4 char ACPI name
164 * RETURN: TRUE if name exists in namespace
166 * DESCRIPTION: Walk the namespace to find an object
168 ******************************************************************************/
177 /* Walk entire namespace from the supplied root */
179 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
180 ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
182 if (Status == AE_CTRL_TRUE)
184 /* At least one instance of the name was found */
193 /*******************************************************************************
195 * FUNCTION: XfCompareOneNamespaceObject
197 * PARAMETERS: ACPI_WALK_CALLBACK
201 * DESCRIPTION: Compare name of one object.
203 ******************************************************************************/
206 XfCompareOneNamespaceObject (
207 ACPI_HANDLE ObjHandle,
212 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
215 /* Simply check the name */
217 if (*((UINT32 *) (Context)) == Node->Name.Integer)
219 /* Abort walk if we found one instance */
221 return (AE_CTRL_TRUE);
228 /*******************************************************************************
230 * FUNCTION: XfCheckFieldRange
232 * PARAMETERS: RegionBitLength - Length of entire parent region
233 * FieldBitOffset - Start of the field unit (within region)
234 * FieldBitLength - Entire length of field unit
235 * AccessBitWidth - Access width of the field unit
239 * DESCRIPTION: Check one field unit to make sure it fits in the parent
242 * Note: AccessBitWidth must be either 8,16,32, or 64
244 ******************************************************************************/
248 ACPI_PARSE_OBJECT *Op,
249 UINT32 RegionBitLength,
250 UINT32 FieldBitOffset,
251 UINT32 FieldBitLength,
252 UINT32 AccessBitWidth)
254 UINT32 FieldEndBitOffset;
258 * Check each field unit against the region size. The entire
259 * field unit (start offset plus length) must fit within the
262 FieldEndBitOffset = FieldBitOffset + FieldBitLength;
264 if (FieldEndBitOffset > RegionBitLength)
266 /* Field definition itself is beyond the end-of-region */
268 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
273 * Now check that the field plus AccessWidth doesn't go beyond
274 * the end-of-region. Assumes AccessBitWidth is a power of 2
276 FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
278 if (FieldEndBitOffset > RegionBitLength)
280 /* Field definition combined with the access is beyond EOR */
282 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
287 /*******************************************************************************
289 * FUNCTION: XfGetParentMethod
291 * PARAMETERS: Op - Parse Op to be checked
293 * RETURN: Control method Op if found. NULL otherwise
295 * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if
296 * the input Op is not within a control method.
298 ******************************************************************************/
300 static ACPI_PARSE_OBJECT *
302 ACPI_PARSE_OBJECT *Op)
304 ACPI_PARSE_OBJECT *NextOp;
307 NextOp = Op->Asl.Parent;
310 if (NextOp->Asl.AmlOpcode == AML_METHOD_OP)
315 NextOp = NextOp->Asl.Parent;
318 return (NULL); /* No parent method found */
321 /*******************************************************************************
323 * FUNCTION: XfNamespaceLocateBegin
325 * PARAMETERS: ASL_WALK_CALLBACK
329 * DESCRIPTION: Descending callback used during cross-reference. For named
330 * object references, attempt to locate the name in the
333 * NOTE: ASL references to named fields within resource descriptors are
334 * resolved to integer values here. Therefore, this step is an
335 * important part of the code generation. We don't know that the
336 * name refers to a resource descriptor until now.
338 ******************************************************************************/
341 XfNamespaceLocateBegin (
342 ACPI_PARSE_OBJECT *Op,
346 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
347 ACPI_NAMESPACE_NODE *Node;
349 ACPI_OBJECT_TYPE ObjectType;
352 ACPI_PARSE_OBJECT *NextOp;
353 ACPI_PARSE_OBJECT *OwningOp;
354 ACPI_PARSE_OBJECT *SpaceIdOp;
355 UINT32 MinimumLength;
357 UINT32 FieldBitLength;
360 const ACPI_OPCODE_INFO *OpInfo;
362 ASL_METHOD_LOCAL *MethodLocals = NULL;
363 ASL_METHOD_LOCAL *MethodArgs = NULL;
368 ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
371 if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
375 /* Support for method LocalX/ArgX analysis */
377 if (!Node->MethodLocals)
379 /* Create local/arg info blocks */
381 MethodLocals = UtLocalCalloc (
382 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
383 Node->MethodLocals = MethodLocals;
385 MethodArgs = UtLocalCalloc (
386 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
387 Node->MethodArgs = MethodArgs;
390 * Get the method argument count
391 * First, get the name node
393 NextOp = Op->Asl.Child;
395 /* Get the NumArguments node */
397 NextOp = NextOp->Asl.Next;
398 Node->ArgCount = (UINT8)
399 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
401 /* We will track all posible ArgXs */
403 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
405 if (i < Node->ArgCount)
407 /* Real Args are always "initialized" */
409 MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
413 /* Other ArgXs can be used as locals */
415 MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
418 MethodArgs[i].Op = Op;
424 * If this node is the actual declaration of a name
425 * [such as the XXXX name in "Method (XXXX)"],
426 * we are not interested in it here. We only care about names that are
427 * references to other objects within the namespace and the parent objects
428 * of name declarations
430 if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
432 return_ACPI_STATUS (AE_OK);
435 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
437 /* Check method LocalX variables */
439 if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
441 /* Find parent method Op */
443 NextOp = XfGetParentMethod (Op);
446 return_ACPI_STATUS (AE_OK);
449 /* Get method node */
451 Node = NextOp->Asl.Node;
453 RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
454 MethodLocals = Node->MethodLocals;
456 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
458 /* Local is being initialized */
460 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
461 MethodLocals[RegisterNumber].Op = Op;
463 return_ACPI_STATUS (AE_OK);
466 /* Mark this Local as referenced */
468 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
469 MethodLocals[RegisterNumber].Op = Op;
471 return_ACPI_STATUS (AE_OK);
474 /* Check method ArgX variables */
476 if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
478 /* Find parent method Op */
480 NextOp = XfGetParentMethod (Op);
483 return_ACPI_STATUS (AE_OK);
486 /* Get method node */
488 Node = NextOp->Asl.Node;
492 RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
493 MethodArgs = Node->MethodArgs;
495 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
497 /* Arg is being initialized */
499 MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
500 MethodArgs[RegisterNumber].Op = Op;
502 return_ACPI_STATUS (AE_OK);
505 /* Mark this Arg as referenced */
507 MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
508 MethodArgs[RegisterNumber].Op = Op;
510 return_ACPI_STATUS (AE_OK);
514 * After method ArgX and LocalX, we are only interested in opcodes
515 * that have an associated name
517 if ((!(OpInfo->Flags & AML_NAMED)) &&
518 (!(OpInfo->Flags & AML_CREATE)) &&
519 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
520 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
521 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
523 return_ACPI_STATUS (AE_OK);
527 * One special case: CondRefOf operator - we don't care if the name exists
528 * or not at this point, just ignore it, the point of the operator is to
529 * determine if the name exists at runtime.
531 if ((Op->Asl.Parent) &&
532 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
534 return_ACPI_STATUS (AE_OK);
538 * We must enable the "search-to-root" for single NameSegs, but
539 * we have to be very careful about opening up scopes
541 Flags = ACPI_NS_SEARCH_PARENT;
542 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
543 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
544 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
547 * These are name references, do not push the scope stack
550 Flags |= ACPI_NS_DONT_OPEN_SCOPE;
553 /* Get the NamePath from the appropriate place */
555 if (OpInfo->Flags & AML_NAMED)
557 /* For nearly all NAMED operators, the name reference is the first child */
559 Path = Op->Asl.Child->Asl.Value.String;
560 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
563 * ALIAS is the only oddball opcode, the name declaration
564 * (alias name) is the second operand
566 Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
569 else if (OpInfo->Flags & AML_CREATE)
571 /* Name must appear as the last parameter */
573 NextOp = Op->Asl.Child;
574 while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
576 NextOp = NextOp->Asl.Next;
578 Path = NextOp->Asl.Value.String;
582 Path = Op->Asl.Value.String;
585 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
586 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
587 "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
590 * Lookup the name in the namespace. Name must exist at this point, or it
591 * is an invalid reference.
593 * The namespace is also used as a lookup table for references to resource
594 * descriptors and the fields within them.
598 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
599 ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
600 if (ACPI_FAILURE (Status))
602 if (Status == AE_NOT_FOUND)
605 * We didn't find the name reference by path -- we can qualify this
606 * a little better before we print an error message
608 if (strlen (Path) == ACPI_NAME_SIZE)
610 /* A simple, one-segment ACPI name */
612 if (XfObjectExists (Path))
615 * There exists such a name, but we couldn't get to it
618 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
619 Op->Asl.ExternalName);
623 /* The name doesn't exist, period */
625 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
626 Op, Op->Asl.ExternalName);
631 /* Check for a fully qualified path */
633 if (Path[0] == AML_ROOT_PREFIX)
635 /* Gave full path, the object does not exist */
637 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
638 Op->Asl.ExternalName);
643 * We can't tell whether it doesn't exist or just
646 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
647 Op->Asl.ExternalName);
654 return_ACPI_STATUS (Status);
657 /* Check for a reference vs. name declaration */
659 if (!(OpInfo->Flags & AML_NAMED) &&
660 !(OpInfo->Flags & AML_CREATE))
662 /* This node has been referenced, mark it for reference check */
664 Node->Flags |= ANOBJ_IS_REFERENCED;
666 #ifdef __UNDER_DEVELOPMENT
668 /* Check for an illegal reference */
670 XfCheckIllegalReference (Op, Node);
674 /* Attempt to optimize the NamePath */
676 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
679 * 1) Dereference an alias (A name reference that is an alias)
680 * Aliases are not nested, the alias always points to the final object
682 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
683 (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
685 /* This node points back to the original PARSEOP_ALIAS */
689 /* The first child is the alias target op */
691 NextOp = NextOp->Asl.Child;
693 /* That in turn points back to original target alias node */
695 if (NextOp->Asl.Node)
697 Node = NextOp->Asl.Node;
700 /* Else - forward reference to alias, will be resolved later */
703 /* 2) Check for a reference to a resource descriptor */
705 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
706 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
709 * This was a reference to a field within a resource descriptor.
710 * Extract the associated field offset (either a bit or byte
711 * offset depending on the field type) and change the named
712 * reference into an integer for AML code generation
714 Offset = Node->Value;
715 TagBitLength = Node->Length;
718 * If a field is being created, generate the length (in bits) of
719 * the field. Note: Opcodes other than CreateXxxField and Index
720 * can come through here. For other opcodes, we just need to
721 * convert the resource tag reference to an integer offset.
723 switch (Op->Asl.Parent->Asl.AmlOpcode)
725 case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
727 * We know the length operand is an integer constant because
728 * we know that it contains a reference to a resource
731 FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
734 case AML_CREATE_BIT_FIELD_OP:
739 case AML_CREATE_BYTE_FIELD_OP:
745 case AML_CREATE_WORD_FIELD_OP:
750 case AML_CREATE_DWORD_FIELD_OP:
755 case AML_CREATE_QWORD_FIELD_OP:
766 /* Check the field length against the length of the resource tag */
770 if (TagBitLength < FieldBitLength)
772 Message = ASL_MSG_TAG_SMALLER;
774 else if (TagBitLength > FieldBitLength)
776 Message = ASL_MSG_TAG_LARGER;
781 sprintf (MsgBuffer, "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
782 TagBitLength, (TagBitLength > 1) ? "s" : "",
783 FieldBitLength, (FieldBitLength > 1) ? "s" : "");
785 AslError (ASL_WARNING, Message, Op, MsgBuffer);
789 /* Convert the BitOffset to a ByteOffset for certain opcodes */
791 switch (Op->Asl.Parent->Asl.AmlOpcode)
793 case AML_CREATE_BYTE_FIELD_OP:
794 case AML_CREATE_WORD_FIELD_OP:
795 case AML_CREATE_DWORD_FIELD_OP:
796 case AML_CREATE_QWORD_FIELD_OP:
799 Offset = ACPI_DIV_8 (Offset);
807 /* Now convert this node to an integer whose value is the field offset */
809 Op->Asl.AmlLength = 0;
810 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
811 Op->Asl.Value.Integer = (UINT64) Offset;
812 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
814 OpcGenerateAmlOpcode (Op);
817 /* 3) Check for a method invocation */
819 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
820 (Node->Type == ACPI_TYPE_METHOD) &&
822 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
824 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
827 * A reference to a method within one of these opcodes is not an
828 * invocation of the method, it is simply a reference to the method.
830 if ((Op->Asl.Parent) &&
831 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
832 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF) ||
833 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
834 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
835 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
837 return_ACPI_STATUS (AE_OK);
840 * There are two types of method invocation:
841 * 1) Invocation with arguments -- the parser recognizes this
843 * 2) Invocation with no arguments --the parser cannot determine that
844 * this is a method invocation, therefore we have to figure it out
847 if (Node->Type != ACPI_TYPE_METHOD)
849 sprintf (MsgBuffer, "%s is a %s",
850 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
852 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
853 return_ACPI_STATUS (AE_OK);
856 /* Save the method node in the caller's op */
859 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
861 return_ACPI_STATUS (AE_OK);
865 * This is a method invocation, with or without arguments.
866 * Count the number of arguments, each appears as a child
867 * under the parent node
869 Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
870 UtSetParseOpName (Op);
873 NextOp = Op->Asl.Child;
878 NextOp = NextOp->Asl.Next;
881 if (Node->Value != ASL_EXTERNAL_METHOD)
884 * Check the parsed arguments with the number expected by the
885 * method declaration itself
887 if (PassedArgs != Node->Value)
889 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
892 if (PassedArgs < Node->Value)
894 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
898 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
904 /* 4) Check for an ASL Field definition */
906 else if ((Op->Asl.Parent) &&
907 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
908 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
911 * Offset checking for fields. If the parent operation region has a
912 * constant length (known at compile time), we can check fields
913 * defined in that region against the region length. This will catch
914 * fields and field units that cannot possibly fit within the region.
916 * Note: Index fields do not directly reference an operation region,
917 * thus they are not included in this check.
919 if (Op == Op->Asl.Parent->Asl.Child)
922 * This is the first child of the field node, which is
923 * the name of the region. Get the parse node for the
924 * region -- which contains the length of the region.
927 Op->Asl.Parent->Asl.ExtraValue =
928 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
930 /* Examine the field access width */
932 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
934 case AML_FIELD_ACCESS_ANY:
935 case AML_FIELD_ACCESS_BYTE:
936 case AML_FIELD_ACCESS_BUFFER:
942 case AML_FIELD_ACCESS_WORD:
947 case AML_FIELD_ACCESS_DWORD:
952 case AML_FIELD_ACCESS_QWORD:
959 * Is the region at least as big as the access width?
960 * Note: DataTableRegions have 0 length
962 if (((UINT32) OwningOp->Asl.Value.Integer) &&
963 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
965 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
969 * Check EC/CMOS/SMBUS fields to make sure that the correct
970 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
972 SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
973 switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
975 case ACPI_ADR_SPACE_EC:
976 case ACPI_ADR_SPACE_CMOS:
977 case ACPI_ADR_SPACE_GPIO:
979 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE)
981 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
985 case ACPI_ADR_SPACE_SMBUS:
986 case ACPI_ADR_SPACE_IPMI:
987 case ACPI_ADR_SPACE_GSBUS:
989 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER)
991 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
997 /* Nothing to do for other address spaces */
1005 * This is one element of the field list. Check to make sure
1006 * that it does not go beyond the end of the parent operation region.
1008 * In the code below:
1009 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1010 * Op->Asl.ExtraValue - Field start offset (bits)
1011 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1012 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1014 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1016 XfCheckFieldRange (Op,
1017 Op->Asl.Parent->Asl.ExtraValue,
1019 (UINT32) Op->Asl.Child->Asl.Value.Integer,
1020 Op->Asl.Child->Asl.ExtraValue);
1025 /* 5) Check for a connection object */
1027 else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1029 return_ACPI_STATUS (Status);
1033 Op->Asl.Node = Node;
1034 return_ACPI_STATUS (Status);
1038 /*******************************************************************************
1040 * FUNCTION: XfNamespaceLocateEnd
1042 * PARAMETERS: ASL_WALK_CALLBACK
1046 * DESCRIPTION: Ascending callback used during cross reference. We only
1047 * need to worry about scope management here.
1049 ******************************************************************************/
1052 XfNamespaceLocateEnd (
1053 ACPI_PARSE_OBJECT *Op,
1057 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1058 const ACPI_OPCODE_INFO *OpInfo;
1061 ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1064 /* We are only interested in opcodes that have an associated name */
1066 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1067 if (!(OpInfo->Flags & AML_NAMED))
1069 return_ACPI_STATUS (AE_OK);
1072 /* Not interested in name references, we did not open a scope for them */
1074 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1075 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1076 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
1078 return_ACPI_STATUS (AE_OK);
1081 /* Pop the scope stack if necessary */
1083 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1086 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1087 "%s: Popping scope for Op %p\n",
1088 AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1090 (void) AcpiDsScopeStackPop (WalkState);
1093 return_ACPI_STATUS (AE_OK);
1097 #ifdef __UNDER_DEVELOPMENT
1098 /*******************************************************************************
1100 * FUNCTION: XfIsObjectParental
1102 * PARAMETERS: ChildOp - Op to be checked
1103 * PossibleParentOp - Determine if this op is in the family
1105 * RETURN: TRUE if ChildOp is a descendent of PossibleParentOp
1107 * DESCRIPTION: Determine if an Op is a descendent of another Op. Used to
1108 * detect if a method is declared within another method.
1110 ******************************************************************************/
1113 XfIsObjectParental (
1114 ACPI_PARSE_OBJECT *ChildOp,
1115 ACPI_PARSE_OBJECT *PossibleParentOp)
1117 ACPI_PARSE_OBJECT *ParentOp;
1120 /* Search upwards through the tree for possible parent */
1125 if (ParentOp == PossibleParentOp)
1130 ParentOp = ParentOp->Asl.Parent;
1137 /*******************************************************************************
1139 * FUNCTION: XfGetParentMethod
1141 * PARAMETERS: Op - Op to be checked
1143 * RETURN: Op for parent method. NULL if object is not within a method.
1145 * DESCRIPTION: Determine if an object is within a control method. Used to
1146 * implement special rules for named references from within a
1149 * NOTE: It would be better to have the parser set a flag in the Op if possible.
1151 ******************************************************************************/
1153 static ACPI_PARSE_OBJECT *
1155 ACPI_PARSE_OBJECT *Op)
1157 ACPI_PARSE_OBJECT *ParentOp;
1165 if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
1170 /* Walk upwards through the parse tree, up to the root if necessary */
1175 if (ParentOp->Asl.ParseOpcode == PARSEOP_METHOD)
1180 ParentOp = ParentOp->Asl.Parent;
1183 /* Object is not within a method */
1189 /*******************************************************************************
1191 * FUNCTION: XfCheckIllegalReference
1193 * PARAMETERS: Op - Op referring to the target
1194 * TargetNode - Target of the reference
1196 * RETURN: None. Emits error message for an illegal reference
1198 * DESCRIPTION: Determine if a named reference is legal. A "named" reference
1199 * is something like: Store(ABCD, ...), where ABCD is an AML
1200 * Nameseg or Namepath.
1202 * NOTE: Caller must ensure that the name Op is in fact a reference, and not
1203 * an actual name declaration (creation of a named object).
1205 ******************************************************************************/
1208 XfCheckIllegalReference (
1209 ACPI_PARSE_OBJECT *Op,
1210 ACPI_NAMESPACE_NODE *TargetNode)
1212 ACPI_PARSE_OBJECT *MethodOp1;
1213 ACPI_PARSE_OBJECT *MethodOp2;
1214 ACPI_PARSE_OBJECT *TargetOp;
1218 * Check for an illegal reference to a named object:
1220 * 1) References from one control method to another, non-parent
1221 * method are not allowed, they will fail at runtime.
1223 * 2) Forward references within a control method are not allowed.
1224 * AML interpreters use a one-pass parse of control methods
1225 * so these forward references will fail at runtime.
1227 TargetOp = TargetNode->Op;
1229 MethodOp1 = XfGetParentMethod (Op);
1230 MethodOp2 = XfGetParentMethod (TargetOp);
1232 /* Are both objects within control method(s)? */
1234 if (!MethodOp1 || !MethodOp2)
1239 /* Objects not in the same method? */
1241 if (MethodOp1 != MethodOp2)
1244 * 1) Cross-method named reference
1246 * This is OK if and only if the target reference is within in a
1247 * method that is a parent of current method
1249 if (!XfIsObjectParental (MethodOp1, MethodOp2))
1251 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_METHOD_REF, Op,
1252 Op->Asl.ExternalName);
1257 * 2) Both reference and target are in the same method. Check if this is
1258 * an (illegal) forward reference by examining the exact source code
1259 * location of each (the referenced object and the object declaration).
1260 * This is a bit nasty, yet effective.
1262 else if (Op->Asl.LogicalByteOffset < TargetOp->Asl.LogicalByteOffset)
1264 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
1265 Op->Asl.ExternalName);