1 /******************************************************************************
3 * Module Name: aslanalyze.c - Support functions for parse tree walks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
157 #define _COMPONENT ACPI_COMPILER
158 ACPI_MODULE_NAME ("aslanalyze")
161 /* Local Prototypes */
164 ApDeviceSubtreeWalk (
165 ACPI_PARSE_OBJECT *Op,
170 /*******************************************************************************
172 * FUNCTION: AnIsInternalMethod
174 * PARAMETERS: Op - Current op
178 * DESCRIPTION: Check for an internal control method.
180 ******************************************************************************/
184 ACPI_PARSE_OBJECT *Op)
187 if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
188 (!strcmp (Op->Asl.ExternalName, "_OSI")))
197 /*******************************************************************************
199 * FUNCTION: AnGetInternalMethodReturnType
201 * PARAMETERS: Op - Current op
205 * DESCRIPTION: Get the return type of an internal method
207 ******************************************************************************/
210 AnGetInternalMethodReturnType (
211 ACPI_PARSE_OBJECT *Op)
214 if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
215 (!strcmp (Op->Asl.ExternalName, "_OSI")))
217 return (ACPI_BTYPE_STRING);
224 /*******************************************************************************
226 * FUNCTION: AnCheckId
228 * PARAMETERS: Op - Current parse op
233 * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
234 * checks can be performed on _CID strings.
236 ******************************************************************************/
240 ACPI_PARSE_OBJECT *Op,
247 /* Only care about string versions of _HID/_CID (integers are legal) */
249 if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
254 /* For both _HID and _CID, the string must be non-null */
256 Length = strlen (Op->Asl.Value.String);
259 AslError (ASL_ERROR, ASL_MSG_NULL_STRING, Op, NULL);
264 * One of the things we want to catch here is the use of a leading
265 * asterisk in the string -- an odd construct that certain platform
266 * manufacturers are fond of. Technically, a leading asterisk is OK
267 * for _CID, but a valid use of this has not been seen.
269 if (*Op->Asl.Value.String == '*')
271 AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK,
272 Op, Op->Asl.Value.String);
276 /* _CID strings are bus-specific, no more checks can be performed */
278 if (Type == ASL_TYPE_CID)
283 /* For _HID, all characters must be alphanumeric */
285 for (i = 0; Op->Asl.Value.String[i]; i++)
287 if (!isalnum ((int) Op->Asl.Value.String[i]))
289 AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
290 Op, Op->Asl.Value.String);
296 * _HID String must be one of these forms:
298 * "AAA####" A is an uppercase letter and # is a hex digit
299 * "ACPI####" # is a hex digit
300 * "NNNN####" N is an uppercase letter or decimal digit (0-9)
301 * # is a hex digit (ACPI 5.0)
303 if ((Length < 7) || (Length > 8))
305 AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
306 Op, Op->Asl.Value.String);
310 /* _HID Length is valid (7 or 8), now check prefix (first 3 or 4 chars) */
314 /* AAA####: Ensure the alphabetic prefix is all uppercase */
316 for (i = 0; i < 3; i++)
318 if (!isupper ((int) Op->Asl.Value.String[i]))
320 AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
321 Op, &Op->Asl.Value.String[i]);
326 else /* Length == 8 */
329 * ACPI#### or NNNN####:
330 * Ensure the prefix contains only uppercase alpha or decimal digits
332 for (i = 0; i < 4; i++)
334 if (!isupper ((int) Op->Asl.Value.String[i]) &&
335 !isdigit ((int) Op->Asl.Value.String[i]))
337 AslError (ASL_ERROR, ASL_MSG_HID_PREFIX,
338 Op, &Op->Asl.Value.String[i]);
344 /* Remaining characters (suffix) must be hex digits */
346 for (; i < Length; i++)
348 if (!isxdigit ((int) Op->Asl.Value.String[i]))
350 AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX,
351 Op, &Op->Asl.Value.String[i]);
358 /*******************************************************************************
360 * FUNCTION: AnLastStatementIsReturn
362 * PARAMETERS: Op - A method parse node
364 * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
366 * DESCRIPTION: Walk down the list of top level statements within a method
367 * to find the last one. Check if that last statement is in
368 * fact a RETURN statement.
370 ******************************************************************************/
373 AnLastStatementIsReturn (
374 ACPI_PARSE_OBJECT *Op)
376 ACPI_PARSE_OBJECT *Next;
379 /* Check if last statement is a return */
381 Next = ASL_GET_CHILD_NODE (Op);
384 if ((!Next->Asl.Next) &&
385 (Next->Asl.ParseOpcode == PARSEOP_RETURN))
390 Next = ASL_GET_PEER_NODE (Next);
397 /*******************************************************************************
399 * FUNCTION: AnCheckMethodReturnValue
401 * PARAMETERS: Op - Parent
402 * OpInfo - Parent info
403 * ArgOp - Method invocation op
404 * RequiredBtypes - What caller requires
405 * ThisNodeBtype - What this node returns (if anything)
409 * DESCRIPTION: Check a method invocation for 1) A return value and if it does
410 * in fact return a value, 2) check the type of the return value.
412 ******************************************************************************/
415 AnCheckMethodReturnValue (
416 ACPI_PARSE_OBJECT *Op,
417 const ACPI_OPCODE_INFO *OpInfo,
418 ACPI_PARSE_OBJECT *ArgOp,
419 UINT32 RequiredBtypes,
420 UINT32 ThisNodeBtype)
422 ACPI_PARSE_OBJECT *OwningOp;
423 ACPI_NAMESPACE_NODE *Node;
426 Node = ArgOp->Asl.Node;
430 /* No error message, this can happen and is OK */
435 /* Examine the parent op of this method */
438 if (OwningOp->Asl.CompileFlags & OP_METHOD_NO_RETVAL)
440 /* Method NEVER returns a value */
442 AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);
444 else if (OwningOp->Asl.CompileFlags & OP_METHOD_SOME_NO_RETVAL)
446 /* Method SOMETIMES returns a value, SOMETIMES not */
448 AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL,
449 Op, Op->Asl.ExternalName);
451 else if (!(ThisNodeBtype & RequiredBtypes))
453 /* Method returns a value, but the type is wrong */
455 AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
456 AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
459 * The case where the method does not return any value at all
460 * was already handled in the namespace cross reference
461 * -- Only issue an error if the method in fact returns a value,
462 * but it is of the wrong type
464 if (ThisNodeBtype != 0)
466 sprintf (AslGbl_MsgBuffer,
467 "Method returns [%s], %s operator requires [%s]",
468 AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
470 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, AslGbl_MsgBuffer);
476 /*******************************************************************************
478 * FUNCTION: AnIsResultUsed
480 * PARAMETERS: Op - Parent op for the operator
482 * RETURN: TRUE if result from this operation is actually consumed
484 * DESCRIPTION: Determine if the function result value from an operator is
487 ******************************************************************************/
491 ACPI_PARSE_OBJECT *Op)
493 ACPI_PARSE_OBJECT *Parent;
496 switch (Op->Asl.ParseOpcode)
498 case PARSEOP_INCREMENT:
499 case PARSEOP_DECREMENT:
501 /* These are standalone operators, no return value */
510 /* Examine parent to determine if the return value is used */
512 Parent = Op->Asl.Parent;
513 switch (Parent->Asl.ParseOpcode)
515 /* If/While - check if the operator is the predicate */
520 /* First child is the predicate */
522 if (Parent->Asl.Child == Op)
529 /* Not used if one of these is the parent */
532 case PARSEOP_DEFINITION_BLOCK:
539 /* Any other type of parent means that the result is used */
546 /*******************************************************************************
548 * FUNCTION: ApCheckForGpeNameConflict
550 * PARAMETERS: Op - Current parse op
554 * DESCRIPTION: Check for a conflict between GPE names within this scope.
555 * Conflict means two GPE names with the same GPE number, but
556 * different types -- such as _L1C and _E1C.
558 ******************************************************************************/
561 ApCheckForGpeNameConflict (
562 ACPI_PARSE_OBJECT *Op)
564 ACPI_PARSE_OBJECT *NextOp;
566 char Name[ACPI_NAME_SIZE + 1];
567 char Target[ACPI_NAME_SIZE];
570 /* Need a null-terminated string version of NameSeg */
572 ACPI_MOVE_32_TO_32 (Name, &Op->Asl.NameSeg);
573 Name[ACPI_NAME_SIZE] = 0;
577 * 1st char must be underscore
578 * 2nd char must be L or E
579 * 3rd/4th chars must be a hex number
581 if ((Name[0] != '_') ||
582 ((Name[1] != 'L') && (Name[1] != 'E')))
587 /* Verify 3rd/4th chars are a valid hex value */
589 GpeNumber = strtoul (&Name[2], NULL, 16);
590 if (GpeNumber == ACPI_UINT32_MAX)
596 * We are now sure we have an _Lxx or _Exx.
597 * Create the target name that would cause collision (Flip E/L)
599 ACPI_MOVE_32_TO_32 (Target, Name);
601 /* Inject opposite letter ("L" versus "E") */
607 else /* Name[1] == 'E' */
612 /* Search all peers (objects within this scope) for target match */
614 NextOp = Op->Asl.Next;
618 * We mostly care about methods, but check Name() constructs also,
619 * even though they will get another error for not being a method.
620 * All GPE names must be defined as control methods.
622 if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) ||
623 (NextOp->Asl.ParseOpcode == PARSEOP_NAME))
625 if (ACPI_COMPARE_NAME (Target, NextOp->Asl.NameSeg))
627 /* Found both _Exy and _Lxy in the same scope, error */
629 AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp,
635 NextOp = NextOp->Asl.Next;
638 /* OK, no conflict found */
644 /*******************************************************************************
646 * FUNCTION: ApCheckRegMethod
648 * PARAMETERS: Op - Current parse op
652 * DESCRIPTION: Ensure that a _REG method has a corresponding Operation
653 * Region declaration within the same scope. Note: _REG is defined
654 * to have two arguments and must therefore be defined as a
657 ******************************************************************************/
661 ACPI_PARSE_OBJECT *Op)
663 ACPI_PARSE_OBJECT *Next;
664 ACPI_PARSE_OBJECT *Parent;
667 /* We are only interested in _REG methods */
669 if (!ACPI_COMPARE_NAME (METHOD_NAME__REG, &Op->Asl.NameSeg))
674 /* Get the start of the current scope */
676 Parent = Op->Asl.Parent;
677 Next = Parent->Asl.Child;
679 /* Search entire scope for an operation region declaration */
683 if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION)
685 return; /* Found region, OK */
688 Next = Next->Asl.Next;
691 /* No region found, issue warning */
693 AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL);
697 /*******************************************************************************
699 * FUNCTION: ApFindNameInDeviceTree
701 * PARAMETERS: Name - Name to search for
702 * Op - Current parse op
704 * RETURN: TRUE if name found in the same scope as Op.
706 * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
707 * a Method() or a Name(). "Same scope" can mean under an If or
710 * NOTE: Detects _HID/_ADR in this type of construct (legal in ACPI 6.1+)
717 * Name (_HID, "INT3442")
723 ******************************************************************************/
726 ApFindNameInDeviceTree (
728 ACPI_PARSE_OBJECT *Op)
733 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
734 ApDeviceSubtreeWalk, NULL, Name);
736 if (Status == AE_CTRL_TRUE)
738 return (TRUE); /* Found a match */
745 /* Callback function for interface above */
748 ApDeviceSubtreeWalk (
749 ACPI_PARSE_OBJECT *Op,
753 char *Name = ACPI_CAST_PTR (char, Context);
756 switch (Op->Asl.ParseOpcode)
760 /* Level 0 is the starting device, ignore it */
764 /* Ignore sub-devices */
766 return (AE_CTRL_DEPTH);
773 /* These are what we are looking for */
775 if (ACPI_COMPARE_NAME (Name, Op->Asl.NameSeg))
777 return (AE_CTRL_TRUE);
779 return (AE_CTRL_DEPTH);
783 case PARSEOP_OPERATIONREGION:
786 * We want to ignore these, because either they can be large
787 * subtrees or open a scope to somewhere else.
789 return (AE_CTRL_DEPTH);
799 /*******************************************************************************
801 * FUNCTION: ApFindNameInScope
803 * PARAMETERS: Name - Name to search for
804 * Op - Current parse op
806 * RETURN: TRUE if name found in the same scope as Op.
808 * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
809 * a Method() or a Name().
811 ******************************************************************************/
816 ACPI_PARSE_OBJECT *Op)
818 ACPI_PARSE_OBJECT *Next;
819 ACPI_PARSE_OBJECT *Parent;
822 /* Get the start of the current scope */
824 Parent = Op->Asl.Parent;
825 Next = Parent->Asl.Child;
827 /* Search entire scope for a match to the name */
831 if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) ||
832 (Next->Asl.ParseOpcode == PARSEOP_NAME))
834 if (ACPI_COMPARE_NAME (Name, Next->Asl.NameSeg))
840 Next = Next->Asl.Next;