1 /******************************************************************************
3 * Module Name: aslanalyze.c - Support functions for parse tree walks
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 "aslcompiler.h"
45 #include "aslcompiler.y.h"
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslanalyze")
53 /*******************************************************************************
55 * FUNCTION: AnIsInternalMethod
57 * PARAMETERS: Op - Current op
61 * DESCRIPTION: Check for an internal control method.
63 ******************************************************************************/
67 ACPI_PARSE_OBJECT *Op)
70 if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
71 (!strcmp (Op->Asl.ExternalName, "_OSI")))
80 /*******************************************************************************
82 * FUNCTION: AnGetInternalMethodReturnType
84 * PARAMETERS: Op - Current op
88 * DESCRIPTION: Get the return type of an internal method
90 ******************************************************************************/
93 AnGetInternalMethodReturnType (
94 ACPI_PARSE_OBJECT *Op)
97 if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
98 (!strcmp (Op->Asl.ExternalName, "_OSI")))
100 return (ACPI_BTYPE_STRING);
107 /*******************************************************************************
109 * FUNCTION: AnCheckId
111 * PARAMETERS: Op - Current parse op
116 * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
117 * checks can be performed on _CID strings.
119 ******************************************************************************/
123 ACPI_PARSE_OBJECT *Op,
130 /* Only care about string versions of _HID/_CID (integers are legal) */
132 if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
137 /* For both _HID and _CID, the string must be non-null */
139 Length = strlen (Op->Asl.Value.String);
142 AslError (ASL_ERROR, ASL_MSG_NULL_STRING,
148 * One of the things we want to catch here is the use of a leading
149 * asterisk in the string -- an odd construct that certain platform
150 * manufacturers are fond of. Technically, a leading asterisk is OK
151 * for _CID, but a valid use of this has not been seen.
153 if (*Op->Asl.Value.String == '*')
155 AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK,
156 Op, Op->Asl.Value.String);
160 /* _CID strings are bus-specific, no more checks can be performed */
162 if (Type == ASL_TYPE_CID)
167 /* For _HID, all characters must be alphanumeric */
169 for (i = 0; Op->Asl.Value.String[i]; i++)
171 if (!isalnum ((int) Op->Asl.Value.String[i]))
173 AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
174 Op, Op->Asl.Value.String);
180 * _HID String must be one of these forms:
182 * "AAA####" A is an uppercase letter and # is a hex digit
183 * "ACPI####" # is a hex digit
184 * "NNNN####" N is an uppercase letter or decimal digit (0-9)
185 * # is a hex digit (ACPI 5.0)
187 if ((Length < 7) || (Length > 8))
189 AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
190 Op, Op->Asl.Value.String);
194 /* _HID Length is valid (7 or 8), now check the prefix (first 3 or 4 chars) */
198 /* AAA####: Ensure the alphabetic prefix is all uppercase */
200 for (i = 0; i < 3; i++)
202 if (!isupper ((int) Op->Asl.Value.String[i]))
204 AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
205 Op, &Op->Asl.Value.String[i]);
210 else /* Length == 8 */
213 * ACPI#### or NNNN####:
214 * Ensure the prefix contains only uppercase alpha or decimal digits
216 for (i = 0; i < 4; i++)
218 if (!isupper ((int) Op->Asl.Value.String[i]) &&
219 !isdigit ((int) Op->Asl.Value.String[i]))
221 AslError (ASL_ERROR, ASL_MSG_HID_PREFIX,
222 Op, &Op->Asl.Value.String[i]);
228 /* Remaining characters (suffix) must be hex digits */
230 for (; i < Length; i++)
232 if (!isxdigit ((int) Op->Asl.Value.String[i]))
234 AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX,
235 Op, &Op->Asl.Value.String[i]);
242 /*******************************************************************************
244 * FUNCTION: AnLastStatementIsReturn
246 * PARAMETERS: Op - A method parse node
248 * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
250 * DESCRIPTION: Walk down the list of top level statements within a method
251 * to find the last one. Check if that last statement is in
252 * fact a RETURN statement.
254 ******************************************************************************/
257 AnLastStatementIsReturn (
258 ACPI_PARSE_OBJECT *Op)
260 ACPI_PARSE_OBJECT *Next;
263 /* Check if last statement is a return */
265 Next = ASL_GET_CHILD_NODE (Op);
268 if ((!Next->Asl.Next) &&
269 (Next->Asl.ParseOpcode == PARSEOP_RETURN))
274 Next = ASL_GET_PEER_NODE (Next);
281 /*******************************************************************************
283 * FUNCTION: AnCheckMethodReturnValue
285 * PARAMETERS: Op - Parent
286 * OpInfo - Parent info
287 * ArgOp - Method invocation op
288 * RequiredBtypes - What caller requires
289 * ThisNodeBtype - What this node returns (if anything)
293 * DESCRIPTION: Check a method invocation for 1) A return value and if it does
294 * in fact return a value, 2) check the type of the return value.
296 ******************************************************************************/
299 AnCheckMethodReturnValue (
300 ACPI_PARSE_OBJECT *Op,
301 const ACPI_OPCODE_INFO *OpInfo,
302 ACPI_PARSE_OBJECT *ArgOp,
303 UINT32 RequiredBtypes,
304 UINT32 ThisNodeBtype)
306 ACPI_PARSE_OBJECT *OwningOp;
307 ACPI_NAMESPACE_NODE *Node;
310 Node = ArgOp->Asl.Node;
313 /* Examine the parent op of this method */
316 if (OwningOp->Asl.CompileFlags & NODE_METHOD_NO_RETVAL)
318 /* Method NEVER returns a value */
320 AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);
322 else if (OwningOp->Asl.CompileFlags & NODE_METHOD_SOME_NO_RETVAL)
324 /* Method SOMETIMES returns a value, SOMETIMES not */
326 AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, Op->Asl.ExternalName);
328 else if (!(ThisNodeBtype & RequiredBtypes))
330 /* Method returns a value, but the type is wrong */
332 AnFormatBtype (StringBuffer, ThisNodeBtype);
333 AnFormatBtype (StringBuffer2, RequiredBtypes);
336 * The case where the method does not return any value at all
337 * was already handled in the namespace cross reference
338 * -- Only issue an error if the method in fact returns a value,
339 * but it is of the wrong type
341 if (ThisNodeBtype != 0)
344 "Method returns [%s], %s operator requires [%s]",
345 StringBuffer, OpInfo->Name, StringBuffer2);
347 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
353 /*******************************************************************************
355 * FUNCTION: AnIsResultUsed
357 * PARAMETERS: Op - Parent op for the operator
359 * RETURN: TRUE if result from this operation is actually consumed
361 * DESCRIPTION: Determine if the function result value from an operator is
364 ******************************************************************************/
368 ACPI_PARSE_OBJECT *Op)
370 ACPI_PARSE_OBJECT *Parent;
373 switch (Op->Asl.ParseOpcode)
375 case PARSEOP_INCREMENT:
376 case PARSEOP_DECREMENT:
378 /* These are standalone operators, no return value */
387 /* Examine parent to determine if the return value is used */
389 Parent = Op->Asl.Parent;
390 switch (Parent->Asl.ParseOpcode)
392 /* If/While - check if the operator is the predicate */
397 /* First child is the predicate */
399 if (Parent->Asl.Child == Op)
405 /* Not used if one of these is the parent */
408 case PARSEOP_DEFINITIONBLOCK:
415 /* Any other type of parent means that the result is used */
422 /*******************************************************************************
424 * FUNCTION: ApCheckForGpeNameConflict
426 * PARAMETERS: Op - Current parse op
430 * DESCRIPTION: Check for a conflict between GPE names within this scope.
431 * Conflict means two GPE names with the same GPE number, but
432 * different types -- such as _L1C and _E1C.
434 ******************************************************************************/
437 ApCheckForGpeNameConflict (
438 ACPI_PARSE_OBJECT *Op)
440 ACPI_PARSE_OBJECT *NextOp;
442 char Name[ACPI_NAME_SIZE + 1];
443 char Target[ACPI_NAME_SIZE];
446 /* Need a null-terminated string version of NameSeg */
448 ACPI_MOVE_32_TO_32 (Name, &Op->Asl.NameSeg);
449 Name[ACPI_NAME_SIZE] = 0;
453 * 1st char must be underscore
454 * 2nd char must be L or E
455 * 3rd/4th chars must be a hex number
457 if ((Name[0] != '_') ||
458 ((Name[1] != 'L') && (Name[1] != 'E')))
463 /* Verify 3rd/4th chars are a valid hex value */
465 GpeNumber = strtoul (&Name[2], NULL, 16);
466 if (GpeNumber == ACPI_UINT32_MAX)
472 * We are now sure we have an _Lxx or _Exx.
473 * Create the target name that would cause collision (Flip E/L)
475 ACPI_MOVE_32_TO_32 (Target, Name);
477 /* Inject opposite letter ("L" versus "E") */
483 else /* Name[1] == 'E' */
488 /* Search all peers (objects within this scope) for target match */
490 NextOp = Op->Asl.Next;
494 * We mostly care about methods, but check Name() constructs also,
495 * even though they will get another error for not being a method.
496 * All GPE names must be defined as control methods.
498 if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) ||
499 (NextOp->Asl.ParseOpcode == PARSEOP_NAME))
501 if (ACPI_COMPARE_NAME (Target, NextOp->Asl.NameSeg))
503 /* Found both _Exy and _Lxy in the same scope, error */
505 AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp,
511 NextOp = NextOp->Asl.Next;
514 /* OK, no conflict found */
520 /*******************************************************************************
522 * FUNCTION: ApCheckRegMethod
524 * PARAMETERS: Op - Current parse op
528 * DESCRIPTION: Ensure that a _REG method has a corresponding Operation
529 * Region declaration within the same scope. Note: _REG is defined
530 * to have two arguments and must therefore be defined as a
533 ******************************************************************************/
537 ACPI_PARSE_OBJECT *Op)
539 ACPI_PARSE_OBJECT *Next;
540 ACPI_PARSE_OBJECT *Parent;
543 /* We are only interested in _REG methods */
545 if (!ACPI_COMPARE_NAME (METHOD_NAME__REG, &Op->Asl.NameSeg))
550 /* Get the start of the current scope */
552 Parent = Op->Asl.Parent;
553 Next = Parent->Asl.Child;
555 /* Search entire scope for an operation region declaration */
559 if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION)
561 return; /* Found region, OK */
564 Next = Next->Asl.Next;
567 /* No region found, issue warning */
569 AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL);
573 /*******************************************************************************
575 * FUNCTION: ApFindNameInScope
577 * PARAMETERS: Name - Name to search for
578 * Op - Current parse op
580 * RETURN: TRUE if name found in the same scope as Op.
582 * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
583 * a Method() or a Name().
585 ******************************************************************************/
590 ACPI_PARSE_OBJECT *Op)
592 ACPI_PARSE_OBJECT *Next;
593 ACPI_PARSE_OBJECT *Parent;
596 /* Get the start of the current scope */
598 Parent = Op->Asl.Parent;
599 Next = Parent->Asl.Child;
601 /* Search entire scope for a match to the name */
605 if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) ||
606 (Next->Asl.ParseOpcode == PARSEOP_NAME))
608 if (ACPI_COMPARE_NAME (Name, Next->Asl.NameSeg))
614 Next = Next->Asl.Next;