1 /******************************************************************************
3 * Module Name: aslpredef - support for ACPI predefined names
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.
44 #define ACPI_CREATE_PREDEFINED_TABLE
46 #include <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include "aslcompiler.y.h"
48 #include <contrib/dev/acpica/include/acpredef.h>
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("aslpredef")
55 /* Local prototypes */
58 ApCheckForUnexpectedReturnValue (
59 ACPI_PARSE_OBJECT *Op,
60 ASL_METHOD_INFO *MethodInfo);
63 ApCheckForSpecialName (
64 ACPI_PARSE_OBJECT *Op,
69 ACPI_PARSE_OBJECT *Op,
70 UINT32 ExpectedBtypes);
75 UINT32 ExpectedBtypes);
79 * Names for the types that can be returned by the predefined objects.
80 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
82 static const char *AcpiRtypeNames[] =
92 * Predefined names for use in Resource Descriptors. These names do not
93 * appear in the global Predefined Name table (since these names never
94 * appear in actual AML byte code, only in the original ASL)
96 static const ACPI_PREDEFINED_INFO ResourceNames[] = {
118 {{"_RT_", 0, 0}}, /* Acpi 3.0 */
124 {{"_TSF", 0, 0}}, /* Acpi 3.0 */
127 {{{0,0,0,0}, 0, 0}} /* Table terminator */
130 static const ACPI_PREDEFINED_INFO ScopeNames[] = {
134 {{{0,0,0,0}, 0, 0}} /* Table terminator */
138 /*******************************************************************************
140 * FUNCTION: ApCheckForPredefinedMethod
142 * PARAMETERS: Op - A parse node of type "METHOD".
143 * MethodInfo - Saved info about this method
147 * DESCRIPTION: If method is a predefined name, check that the number of
148 * arguments and the return type (returns a value or not)
151 ******************************************************************************/
154 ApCheckForPredefinedMethod (
155 ACPI_PARSE_OBJECT *Op,
156 ASL_METHOD_INFO *MethodInfo)
159 UINT32 RequiredArgsCurrent;
160 UINT32 RequiredArgsOld;
163 /* Check for a match against the predefined name list */
165 Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
169 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
170 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
171 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
173 /* Just return, nothing to do */
177 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
179 Gbl_ReservedMethods++;
181 /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
183 if (MethodInfo->NumArguments != 0)
185 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
187 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
195 * Matched a predefined method name
197 * Validate the ASL-defined argument count. Allow two different legal
200 Gbl_ReservedMethods++;
202 RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
203 RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
205 if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
206 (MethodInfo->NumArguments != RequiredArgsOld))
208 sprintf (MsgBuffer, "%4.4s requires %u",
209 PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
211 if (MethodInfo->NumArguments > RequiredArgsCurrent)
213 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
218 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
224 * Check if method returns no value, but the predefined name is
225 * required to return a value
227 if (MethodInfo->NumReturnNoValue &&
228 PredefinedNames[Index].Info.ExpectedBtypes)
230 ApGetExpectedTypes (StringBuffer,
231 PredefinedNames[Index].Info.ExpectedBtypes);
233 sprintf (MsgBuffer, "%s required for %4.4s",
234 StringBuffer, PredefinedNames[Index].Info.Name);
236 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
246 /*******************************************************************************
248 * FUNCTION: ApCheckForUnexpectedReturnValue
250 * PARAMETERS: Op - A parse node of type "RETURN".
251 * MethodInfo - Saved info about this method
255 * DESCRIPTION: Check for an unexpected return value from a predefined method.
256 * Invoked for predefined methods that are defined to not return
257 * any value. If there is a return value, issue a remark, since
258 * the ASL writer may be confused as to the method definition
259 * and/or functionality.
261 * Note: We ignore all return values of "Zero", since this is what a standalone
262 * Return() statement will always generate -- so we ignore it here --
263 * i.e., there is no difference between Return() and Return(Zero).
264 * Also, a null Return() will be disassembled to return(Zero) -- so, we
265 * don't want to generate extraneous remarks/warnings for a disassembled
268 ******************************************************************************/
271 ApCheckForUnexpectedReturnValue (
272 ACPI_PARSE_OBJECT *Op,
273 ASL_METHOD_INFO *MethodInfo)
275 ACPI_PARSE_OBJECT *ReturnValueOp;
278 /* Ignore Return() and Return(Zero) (they are the same) */
280 ReturnValueOp = Op->Asl.Child;
281 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
286 /* We have a valid return value, but the reserved name did not expect it */
288 AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
289 Op, MethodInfo->Op->Asl.ExternalName);
293 /*******************************************************************************
295 * FUNCTION: ApCheckPredefinedReturnValue
297 * PARAMETERS: Op - A parse node of type "RETURN".
298 * MethodInfo - Saved info about this method
302 * DESCRIPTION: If method is a predefined name, attempt to validate the return
303 * value. Only "static" types can be validated - a simple return
304 * of an integer/string/buffer/package or a named reference to
305 * a static object. Values such as a Localx or Argx or a control
306 * method invocation are not checked. Issue a warning if there is
307 * a valid return value, but the reserved method defines no
310 ******************************************************************************/
313 ApCheckPredefinedReturnValue (
314 ACPI_PARSE_OBJECT *Op,
315 ASL_METHOD_INFO *MethodInfo)
318 ACPI_PARSE_OBJECT *ReturnValueOp;
321 /* Check parent method for a match against the predefined name list */
323 Index = ApCheckForPredefinedName (MethodInfo->Op,
324 MethodInfo->Op->Asl.NameSeg);
328 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
330 /* No return value expected, warn if there is one */
332 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
335 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
336 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
337 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
339 /* Just return, nothing to do */
342 default: /* A standard predefined ACPI name */
344 if (!PredefinedNames[Index].Info.ExpectedBtypes)
346 /* No return value expected, warn if there is one */
348 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
352 /* Get the object returned, it is the next argument */
354 ReturnValueOp = Op->Asl.Child;
355 switch (ReturnValueOp->Asl.ParseOpcode)
360 case PARSEOP_INTEGER:
361 case PARSEOP_STRING_LITERAL:
363 case PARSEOP_PACKAGE:
365 /* Static data return object - check against expected type */
367 ApCheckObjectType (ReturnValueOp,
368 PredefinedNames[Index].Info.ExpectedBtypes);
374 * All other ops are very difficult or impossible to typecheck at
375 * compile time. These include all Localx, Argx, and method
376 * invocations. Also, NAMESEG and NAMESTRING because the type of
377 * any named object can be changed at runtime (for example,
378 * CopyObject will change the type of the target object.)
386 /*******************************************************************************
388 * FUNCTION: ApCheckForPredefinedObject
390 * PARAMETERS: Op - A parse node
391 * Name - The ACPI name to be checked
395 * DESCRIPTION: Check for a predefined name for a static object (created via
396 * the ASL Name operator). If it is a predefined ACPI name, ensure
397 * that the name does not require any arguments (which would
398 * require a control method implemenation of the name), and that
399 * the type of the object is one of the expected types for the
402 ******************************************************************************/
405 ApCheckForPredefinedObject (
406 ACPI_PARSE_OBJECT *Op,
413 * Check for a real predefined name -- not a resource descriptor name
414 * or a predefined scope name
416 Index = ApCheckForPredefinedName (Op, Name);
420 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
421 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
422 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
427 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
430 * These names must be control methods, by definition in ACPI spec.
431 * Also because they are defined to return no value. None of them
432 * require any arguments.
434 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
435 "with zero arguments");
438 default: /* A standard predefined ACPI name */
441 * If this predefined name requires input arguments, then
442 * it must be implemented as a control method
444 if (PredefinedNames[Index].Info.ParamCount > 0)
446 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
452 * If no return value is expected from this predefined name, then
453 * it follows that it must be implemented as a control method
454 * (with zero args, because the args > 0 case was handled above)
455 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
457 if (!PredefinedNames[Index].Info.ExpectedBtypes)
459 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
460 "with zero arguments");
464 /* Typecheck the actual object, it is the next argument */
466 ApCheckObjectType (Op->Asl.Child->Asl.Next,
467 PredefinedNames[Index].Info.ExpectedBtypes);
473 /*******************************************************************************
475 * FUNCTION: ApCheckForPredefinedName
477 * PARAMETERS: Op - A parse node
478 * Name - NameSeg to check
482 * DESCRIPTION: Check a NameSeg against the reserved list.
484 ******************************************************************************/
487 ApCheckForPredefinedName (
488 ACPI_PARSE_OBJECT *Op,
496 AcpiOsPrintf ("Found a null name, external = %s\n",
497 Op->Asl.ExternalName);
500 /* All reserved names are prefixed with a single underscore */
504 return (ACPI_NOT_RESERVED_NAME);
507 /* Check for a standard predefined method name */
509 for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
511 if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
513 /* Return index into predefined array */
518 /* Check for resource names and predefined scope names */
520 for (i = 0; ResourceNames[i].Info.Name[0]; i++)
522 if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
524 return (ACPI_PREDEFINED_NAME);
528 for (i = 0; ScopeNames[i].Info.Name[0]; i++)
530 if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
532 return (ACPI_PREDEFINED_NAME);
536 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
538 return (ApCheckForSpecialName (Op, Name));
542 /*******************************************************************************
544 * FUNCTION: ApCheckForSpecialName
546 * PARAMETERS: Op - A parse node
547 * Name - NameSeg to check
551 * DESCRIPTION: Check for the "special" predefined names -
552 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
554 ******************************************************************************/
557 ApCheckForSpecialName (
558 ACPI_PARSE_OBJECT *Op,
563 * Check for the "special" predefined names. We already know that the
564 * first character is an underscore.
570 if ((Name[1] == 'L') ||
575 /* The next two characters must be hex digits */
577 if ((isxdigit ((int) Name[2])) &&
578 (isxdigit ((int) Name[3])))
580 return (ACPI_EVENT_RESERVED_NAME);
584 /* Check for the names reserved for the compiler itself: _T_x */
586 else if ((Op->Asl.ExternalName[1] == 'T') &&
587 (Op->Asl.ExternalName[2] == '_'))
589 /* Ignore if actually emitted by the compiler */
591 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
593 return (ACPI_NOT_RESERVED_NAME);
597 * Was not actually emitted by the compiler. This is a special case,
598 * however. If the ASL code being compiled was the result of a
599 * dissasembly, it may possibly contain valid compiler-emitted names
600 * of the form "_T_x". We don't want to issue an error or even a
601 * warning and force the user to manually change the names. So, we
602 * will issue a remark instead.
604 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
605 return (ACPI_COMPILER_RESERVED_NAME);
609 * The name didn't match any of the known predefined names. Flag it as a
610 * warning, since the entire namespace starting with an underscore is
611 * reserved by the ACPI spec.
613 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
614 Op->Asl.ExternalName);
616 return (ACPI_NOT_RESERVED_NAME);
620 /*******************************************************************************
622 * FUNCTION: ApCheckObjectType
624 * PARAMETERS: Op - Current parse node
625 * ExpectedBtypes - Bitmap of expected return type(s)
629 * DESCRIPTION: Check if the object type is one of the types that is expected
630 * by the predefined name. Only a limited number of object types
631 * can be returned by the predefined names.
633 ******************************************************************************/
637 ACPI_PARSE_OBJECT *Op,
638 UINT32 ExpectedBtypes)
643 switch (Op->Asl.ParseOpcode)
648 case PARSEOP_INTEGER:
649 ReturnBtype = ACPI_RTYPE_INTEGER;
653 ReturnBtype = ACPI_RTYPE_BUFFER;
656 case PARSEOP_STRING_LITERAL:
657 ReturnBtype = ACPI_RTYPE_STRING;
660 case PARSEOP_PACKAGE:
661 ReturnBtype = ACPI_RTYPE_PACKAGE;
665 /* Not one of the supported object types */
670 /* Exit if the object is one of the expected types */
672 if (ReturnBtype & ExpectedBtypes)
680 /* Format the expected types and emit an error message */
682 ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
684 sprintf (MsgBuffer, "found %s, requires %s",
685 UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
687 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
692 /*******************************************************************************
694 * FUNCTION: ApDisplayReservedNames
700 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
701 * resource descriptor names.
703 ******************************************************************************/
706 ApDisplayReservedNames (
709 const ACPI_PREDEFINED_INFO *ThisName;
710 char TypeBuffer[48]; /* Room for 5 types */
715 * Predefined names/methods
717 printf ("\nPredefined Name Information\n\n");
720 ThisName = PredefinedNames;
721 while (ThisName->Info.Name[0])
723 printf ("%4.4s Requires %u arguments, ",
724 ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
726 if (ThisName->Info.ExpectedBtypes)
728 ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
729 printf ("Must return: %s\n", TypeBuffer);
733 printf ("No return value\n");
737 * Skip next entry in the table if this name returns a Package
738 * (next entry contains the package info)
740 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
749 printf ("%u Predefined Names are recognized\n", Count);
752 * Resource Descriptor names
754 printf ("\nResource Descriptor Predefined Names\n\n");
757 ThisName = ResourceNames;
758 while (ThisName->Info.Name[0])
760 printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name);
765 printf ("%u Resource Descriptor Names are recognized\n", Count);
768 * Predefined scope names
770 printf ("\nPredefined Scope Names\n\n");
772 ThisName = ScopeNames;
773 while (ThisName->Info.Name[0])
775 printf ("%4.4s Scope\n", ThisName->Info.Name);
781 /*******************************************************************************
783 * FUNCTION: ApGetExpectedTypes
785 * PARAMETERS: Buffer - Where the formatted string is returned
786 * ExpectedBTypes - Bitfield of expected data types
788 * RETURN: None, formatted string
790 * DESCRIPTION: Format the expected object types into a printable string.
792 ******************************************************************************/
797 UINT32 ExpectedBtypes)
806 ThisRtype = ACPI_RTYPE_INTEGER;
808 for (i = 0; i < ACPI_NUM_RTYPES; i++)
810 /* If one of the expected types, concatenate the name of this type */
812 if (ExpectedBtypes & ThisRtype)
814 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
815 j = 0; /* Use name separator from now on */
817 ThisRtype <<= 1; /* Next Rtype */