1 /******************************************************************************
3 * Module Name: aslpredef - support for ACPI predefined names
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, 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 #define ACPI_CREATE_PREDEFINED_TABLE
118 #include "aslcompiler.h"
119 #include "aslcompiler.y.h"
120 #include "acpredef.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslpredef")
127 /* Local prototypes */
130 ApCheckForUnexpectedReturnValue (
131 ACPI_PARSE_OBJECT *Op,
132 ASL_METHOD_INFO *MethodInfo);
135 ApCheckForSpecialName (
136 ACPI_PARSE_OBJECT *Op,
141 ACPI_PARSE_OBJECT *Op,
142 UINT32 ExpectedBtypes);
147 UINT32 ExpectedBtypes);
151 * Names for the types that can be returned by the predefined objects.
152 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
154 static const char *AcpiRtypeNames[] =
164 * Predefined names for use in Resource Descriptors. These names do not
165 * appear in the global Predefined Name table (since these names never
166 * appear in actual AML byte code, only in the original ASL)
168 static const ACPI_PREDEFINED_INFO ResourceNames[] = {
190 {{"_RT_", 0, 0}}, /* Acpi 3.0 */
196 {{"_TSF", 0, 0}}, /* Acpi 3.0 */
199 {{{0,0,0,0}, 0, 0}} /* Table terminator */
202 static const ACPI_PREDEFINED_INFO ScopeNames[] = {
206 {{{0,0,0,0}, 0, 0}} /* Table terminator */
210 /*******************************************************************************
212 * FUNCTION: ApCheckForPredefinedMethod
214 * PARAMETERS: Op - A parse node of type "METHOD".
215 * MethodInfo - Saved info about this method
219 * DESCRIPTION: If method is a predefined name, check that the number of
220 * arguments and the return type (returns a value or not)
223 ******************************************************************************/
226 ApCheckForPredefinedMethod (
227 ACPI_PARSE_OBJECT *Op,
228 ASL_METHOD_INFO *MethodInfo)
231 UINT32 RequiredArgsCurrent;
232 UINT32 RequiredArgsOld;
235 /* Check for a match against the predefined name list */
237 Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
241 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
242 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
243 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
245 /* Just return, nothing to do */
249 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
251 Gbl_ReservedMethods++;
253 /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
255 if (MethodInfo->NumArguments != 0)
257 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
259 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
267 * Matched a predefined method name
269 * Validate the ASL-defined argument count. Allow two different legal
272 Gbl_ReservedMethods++;
274 RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
275 RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
277 if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
278 (MethodInfo->NumArguments != RequiredArgsOld))
280 sprintf (MsgBuffer, "%4.4s requires %u",
281 PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
283 if (MethodInfo->NumArguments > RequiredArgsCurrent)
285 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
290 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
296 * Check if method returns no value, but the predefined name is
297 * required to return a value
299 if (MethodInfo->NumReturnNoValue &&
300 PredefinedNames[Index].Info.ExpectedBtypes)
302 ApGetExpectedTypes (StringBuffer,
303 PredefinedNames[Index].Info.ExpectedBtypes);
305 sprintf (MsgBuffer, "%s required for %4.4s",
306 StringBuffer, PredefinedNames[Index].Info.Name);
308 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
316 /*******************************************************************************
318 * FUNCTION: ApCheckForUnexpectedReturnValue
320 * PARAMETERS: Op - A parse node of type "RETURN".
321 * MethodInfo - Saved info about this method
325 * DESCRIPTION: Check for an unexpected return value from a predefined method.
326 * Invoked for predefined methods that are defined to not return
327 * any value. If there is a return value, issue a remark, since
328 * the ASL writer may be confused as to the method definition
329 * and/or functionality.
331 * Note: We ignore all return values of "Zero", since this is what a standalone
332 * Return() statement will always generate -- so we ignore it here --
333 * i.e., there is no difference between Return() and Return(Zero).
334 * Also, a null Return() will be disassembled to return(Zero) -- so, we
335 * don't want to generate extraneous remarks/warnings for a disassembled
338 ******************************************************************************/
341 ApCheckForUnexpectedReturnValue (
342 ACPI_PARSE_OBJECT *Op,
343 ASL_METHOD_INFO *MethodInfo)
345 ACPI_PARSE_OBJECT *ReturnValueOp;
348 /* Ignore Return() and Return(Zero) (they are the same) */
350 ReturnValueOp = Op->Asl.Child;
351 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
356 /* We have a valid return value, but the reserved name did not expect it */
358 AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
359 Op, MethodInfo->Op->Asl.ExternalName);
363 /*******************************************************************************
365 * FUNCTION: ApCheckPredefinedReturnValue
367 * PARAMETERS: Op - A parse node of type "RETURN".
368 * MethodInfo - Saved info about this method
372 * DESCRIPTION: If method is a predefined name, attempt to validate the return
373 * value. Only "static" types can be validated - a simple return
374 * of an integer/string/buffer/package or a named reference to
375 * a static object. Values such as a Localx or Argx or a control
376 * method invocation are not checked. Issue a warning if there is
377 * a valid return value, but the reserved method defines no
380 ******************************************************************************/
383 ApCheckPredefinedReturnValue (
384 ACPI_PARSE_OBJECT *Op,
385 ASL_METHOD_INFO *MethodInfo)
388 ACPI_PARSE_OBJECT *ReturnValueOp;
391 /* Check parent method for a match against the predefined name list */
393 Index = ApCheckForPredefinedName (MethodInfo->Op,
394 MethodInfo->Op->Asl.NameSeg);
398 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
400 /* No return value expected, warn if there is one */
402 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
405 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
406 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
407 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
409 /* Just return, nothing to do */
412 default: /* A standard predefined ACPI name */
414 if (!PredefinedNames[Index].Info.ExpectedBtypes)
416 /* No return value expected, warn if there is one */
418 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
422 /* Get the object returned, it is the next argument */
424 ReturnValueOp = Op->Asl.Child;
425 switch (ReturnValueOp->Asl.ParseOpcode)
430 case PARSEOP_INTEGER:
431 case PARSEOP_STRING_LITERAL:
433 case PARSEOP_PACKAGE:
435 /* Static data return object - check against expected type */
437 ApCheckObjectType (ReturnValueOp,
438 PredefinedNames[Index].Info.ExpectedBtypes);
444 * All other ops are very difficult or impossible to typecheck at
445 * compile time. These include all Localx, Argx, and method
446 * invocations. Also, NAMESEG and NAMESTRING because the type of
447 * any named object can be changed at runtime (for example,
448 * CopyObject will change the type of the target object.)
456 /*******************************************************************************
458 * FUNCTION: ApCheckForPredefinedObject
460 * PARAMETERS: Op - A parse node
461 * Name - The ACPI name to be checked
465 * DESCRIPTION: Check for a predefined name for a static object (created via
466 * the ASL Name operator). If it is a predefined ACPI name, ensure
467 * that the name does not require any arguments (which would
468 * require a control method implemenation of the name), and that
469 * the type of the object is one of the expected types for the
472 ******************************************************************************/
475 ApCheckForPredefinedObject (
476 ACPI_PARSE_OBJECT *Op,
483 * Check for a real predefined name -- not a resource descriptor name
484 * or a predefined scope name
486 Index = ApCheckForPredefinedName (Op, Name);
490 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
491 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
492 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
497 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
500 * These names must be control methods, by definition in ACPI spec.
501 * Also because they are defined to return no value. None of them
502 * require any arguments.
504 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
505 "with zero arguments");
508 default: /* A standard predefined ACPI name */
511 * If this predefined name requires input arguments, then
512 * it must be implemented as a control method
514 if (PredefinedNames[Index].Info.ParamCount > 0)
516 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
522 * If no return value is expected from this predefined name, then
523 * it follows that it must be implemented as a control method
524 * (with zero args, because the args > 0 case was handled above)
525 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
527 if (!PredefinedNames[Index].Info.ExpectedBtypes)
529 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
530 "with zero arguments");
534 /* Typecheck the actual object, it is the next argument */
536 ApCheckObjectType (Op->Asl.Child->Asl.Next,
537 PredefinedNames[Index].Info.ExpectedBtypes);
543 /*******************************************************************************
545 * FUNCTION: ApCheckForPredefinedName
547 * PARAMETERS: Op - A parse node
548 * Name - NameSeg to check
552 * DESCRIPTION: Check a NameSeg against the reserved list.
554 ******************************************************************************/
557 ApCheckForPredefinedName (
558 ACPI_PARSE_OBJECT *Op,
566 AcpiOsPrintf ("Found a null name, external = %s\n",
567 Op->Asl.ExternalName);
570 /* All reserved names are prefixed with a single underscore */
574 return (ACPI_NOT_RESERVED_NAME);
577 /* Check for a standard predefined method name */
579 for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
581 if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
583 /* Return index into predefined array */
588 /* Check for resource names and predefined scope names */
590 for (i = 0; ResourceNames[i].Info.Name[0]; i++)
592 if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
594 return (ACPI_PREDEFINED_NAME);
598 for (i = 0; ScopeNames[i].Info.Name[0]; i++)
600 if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
602 return (ACPI_PREDEFINED_NAME);
606 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
608 return (ApCheckForSpecialName (Op, Name));
612 /*******************************************************************************
614 * FUNCTION: ApCheckForSpecialName
616 * PARAMETERS: Op - A parse node
617 * Name - NameSeg to check
621 * DESCRIPTION: Check for the "special" predefined names -
622 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
624 ******************************************************************************/
627 ApCheckForSpecialName (
628 ACPI_PARSE_OBJECT *Op,
633 * Check for the "special" predefined names. We already know that the
634 * first character is an underscore.
640 if ((Name[1] == 'L') ||
645 /* The next two characters must be hex digits */
647 if ((isxdigit ((int) Name[2])) &&
648 (isxdigit ((int) Name[3])))
650 return (ACPI_EVENT_RESERVED_NAME);
654 /* Check for the names reserved for the compiler itself: _T_x */
656 else if ((Op->Asl.ExternalName[1] == 'T') &&
657 (Op->Asl.ExternalName[2] == '_'))
659 /* Ignore if actually emitted by the compiler */
661 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
663 return (ACPI_NOT_RESERVED_NAME);
667 * Was not actually emitted by the compiler. This is a special case,
668 * however. If the ASL code being compiled was the result of a
669 * dissasembly, it may possibly contain valid compiler-emitted names
670 * of the form "_T_x". We don't want to issue an error or even a
671 * warning and force the user to manually change the names. So, we
672 * will issue a remark instead.
674 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
675 return (ACPI_COMPILER_RESERVED_NAME);
679 * The name didn't match any of the known predefined names. Flag it as a
680 * warning, since the entire namespace starting with an underscore is
681 * reserved by the ACPI spec.
683 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
684 Op->Asl.ExternalName);
686 return (ACPI_NOT_RESERVED_NAME);
690 /*******************************************************************************
692 * FUNCTION: ApCheckObjectType
694 * PARAMETERS: Op - Current parse node
695 * ExpectedBtypes - Bitmap of expected return type(s)
699 * DESCRIPTION: Check if the object type is one of the types that is expected
700 * by the predefined name. Only a limited number of object types
701 * can be returned by the predefined names.
703 ******************************************************************************/
707 ACPI_PARSE_OBJECT *Op,
708 UINT32 ExpectedBtypes)
713 switch (Op->Asl.ParseOpcode)
718 case PARSEOP_INTEGER:
719 ReturnBtype = ACPI_RTYPE_INTEGER;
723 ReturnBtype = ACPI_RTYPE_BUFFER;
726 case PARSEOP_STRING_LITERAL:
727 ReturnBtype = ACPI_RTYPE_STRING;
730 case PARSEOP_PACKAGE:
731 ReturnBtype = ACPI_RTYPE_PACKAGE;
735 /* Not one of the supported object types */
740 /* Exit if the object is one of the expected types */
742 if (ReturnBtype & ExpectedBtypes)
750 /* Format the expected types and emit an error message */
752 ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
754 sprintf (MsgBuffer, "found %s, requires %s",
755 UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
757 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
762 /*******************************************************************************
764 * FUNCTION: ApDisplayReservedNames
770 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
771 * resource descriptor names.
773 ******************************************************************************/
776 ApDisplayReservedNames (
779 const ACPI_PREDEFINED_INFO *ThisName;
780 char TypeBuffer[48]; /* Room for 5 types */
785 * Predefined names/methods
787 printf ("\nPredefined Name Information\n\n");
790 ThisName = PredefinedNames;
791 while (ThisName->Info.Name[0])
793 printf ("%4.4s Requires %u arguments, ",
794 ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
796 if (ThisName->Info.ExpectedBtypes)
798 ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
799 printf ("Must return: %s\n", TypeBuffer);
803 printf ("No return value\n");
807 * Skip next entry in the table if this name returns a Package
808 * (next entry contains the package info)
810 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
819 printf ("%u Predefined Names are recognized\n", Count);
822 * Resource Descriptor names
824 printf ("\nResource Descriptor Predefined Names\n\n");
827 ThisName = ResourceNames;
828 while (ThisName->Info.Name[0])
830 printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name);
835 printf ("%u Resource Descriptor Names are recognized\n", Count);
838 * Predefined scope names
840 printf ("\nPredefined Scope Names\n\n");
842 ThisName = ScopeNames;
843 while (ThisName->Info.Name[0])
845 printf ("%4.4s Scope\n", ThisName->Info.Name);
851 /*******************************************************************************
853 * FUNCTION: ApGetExpectedTypes
855 * PARAMETERS: Buffer - Where the formatted string is returned
856 * ExpectedBTypes - Bitfield of expected data types
858 * RETURN: None, formatted string
860 * DESCRIPTION: Format the expected object types into a printable string.
862 ******************************************************************************/
867 UINT32 ExpectedBtypes)
876 ThisRtype = ACPI_RTYPE_INTEGER;
878 for (i = 0; i < ACPI_NUM_RTYPES; i++)
880 /* If one of the expected types, concatenate the name of this type */
882 if (ExpectedBtypes & ThisRtype)
884 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
885 j = 0; /* Use name separator from now on */
887 ThisRtype <<= 1; /* Next Rtype */