1 /******************************************************************************
3 * Module Name: aslpredef - support for ACPI predefined names
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 const char *PredefinedName,
70 ACPI_PARSE_OBJECT *Op,
71 UINT32 ExpectedBtypes);
76 UINT32 ExpectedBtypes);
80 * Names for the types that can be returned by the predefined objects.
81 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
83 static const char *AcpiRtypeNames[] =
93 * Predefined names for use in Resource Descriptors. These names do not
94 * appear in the global Predefined Name table (since these names never
95 * appear in actual AML byte code, only in the original ASL)
97 static const ACPI_PREDEFINED_INFO ResourceNames[] = {
104 {{"_DBT", 0, 0}}, /* Acpi 5.0 */
106 {{"_DPL", 0, 0}}, /* Acpi 5.0 */
107 {{"_DRS", 0, 0}}, /* Acpi 5.0 */
108 {{"_END", 0, 0}}, /* Acpi 5.0 */
109 {{"_FLC", 0, 0}}, /* Acpi 5.0 */
113 {{"_IOR", 0, 0}}, /* Acpi 5.0 */
115 {{"_LIN", 0, 0}}, /* Acpi 5.0 */
122 {{"_MOD", 0, 0}}, /* Acpi 5.0 */
124 {{"_PAR", 0, 0}}, /* Acpi 5.0 */
125 {{"_PHA", 0, 0}}, /* Acpi 5.0 */
126 {{"_PIN", 0, 0}}, /* Acpi 5.0 */
127 {{"_PPI", 0, 0}}, /* Acpi 5.0 */
128 {{"_POL", 0, 0}}, /* Acpi 5.0 */
132 {{"_RT_", 0, 0}}, /* Acpi 3.0 */
134 {{"_RXL", 0, 0}}, /* Acpi 5.0 */
137 {{"_SLV", 0, 0}}, /* Acpi 5.0 */
138 {{"_SPE", 0, 0}}, /* Acpi 5.0 */
139 {{"_STB", 0, 0}}, /* Acpi 5.0 */
142 {{"_TSF", 0, 0}}, /* Acpi 3.0 */
144 {{"_TXL", 0, 0}}, /* Acpi 5.0 */
146 {{"_VEN", 0, 0}}, /* Acpi 5.0 */
147 {{{0,0,0,0}, 0, 0}} /* Table terminator */
150 static const ACPI_PREDEFINED_INFO ScopeNames[] = {
154 {{{0,0,0,0}, 0, 0}} /* Table terminator */
158 /*******************************************************************************
160 * FUNCTION: ApCheckForPredefinedMethod
162 * PARAMETERS: Op - A parse node of type "METHOD".
163 * MethodInfo - Saved info about this method
167 * DESCRIPTION: If method is a predefined name, check that the number of
168 * arguments and the return type (returns a value or not)
171 ******************************************************************************/
174 ApCheckForPredefinedMethod (
175 ACPI_PARSE_OBJECT *Op,
176 ASL_METHOD_INFO *MethodInfo)
179 UINT32 RequiredArgsCurrent;
180 UINT32 RequiredArgsOld;
183 /* Check for a match against the predefined name list */
185 Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
189 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
190 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
191 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
193 /* Just return, nothing to do */
197 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
199 Gbl_ReservedMethods++;
201 /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
203 if (MethodInfo->NumArguments != 0)
205 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
207 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
215 * Matched a predefined method name
217 * Validate the ASL-defined argument count. Allow two different legal
220 Gbl_ReservedMethods++;
222 RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
223 RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
225 if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
226 (MethodInfo->NumArguments != RequiredArgsOld))
228 sprintf (MsgBuffer, "%4.4s requires %u",
229 PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
231 if (MethodInfo->NumArguments > RequiredArgsCurrent)
233 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
238 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
244 * Check if method returns no value, but the predefined name is
245 * required to return a value
247 if (MethodInfo->NumReturnNoValue &&
248 PredefinedNames[Index].Info.ExpectedBtypes)
250 ApGetExpectedTypes (StringBuffer,
251 PredefinedNames[Index].Info.ExpectedBtypes);
253 sprintf (MsgBuffer, "%s required for %4.4s",
254 StringBuffer, PredefinedNames[Index].Info.Name);
256 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
266 /*******************************************************************************
268 * FUNCTION: ApCheckForUnexpectedReturnValue
270 * PARAMETERS: Op - A parse node of type "RETURN".
271 * MethodInfo - Saved info about this method
275 * DESCRIPTION: Check for an unexpected return value from a predefined method.
276 * Invoked for predefined methods that are defined to not return
277 * any value. If there is a return value, issue a remark, since
278 * the ASL writer may be confused as to the method definition
279 * and/or functionality.
281 * Note: We ignore all return values of "Zero", since this is what a standalone
282 * Return() statement will always generate -- so we ignore it here --
283 * i.e., there is no difference between Return() and Return(Zero).
284 * Also, a null Return() will be disassembled to return(Zero) -- so, we
285 * don't want to generate extraneous remarks/warnings for a disassembled
288 ******************************************************************************/
291 ApCheckForUnexpectedReturnValue (
292 ACPI_PARSE_OBJECT *Op,
293 ASL_METHOD_INFO *MethodInfo)
295 ACPI_PARSE_OBJECT *ReturnValueOp;
298 /* Ignore Return() and Return(Zero) (they are the same) */
300 ReturnValueOp = Op->Asl.Child;
301 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
306 /* We have a valid return value, but the reserved name did not expect it */
308 AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
309 Op, MethodInfo->Op->Asl.ExternalName);
313 /*******************************************************************************
315 * FUNCTION: ApCheckPredefinedReturnValue
317 * PARAMETERS: Op - A parse node of type "RETURN".
318 * MethodInfo - Saved info about this method
322 * DESCRIPTION: If method is a predefined name, attempt to validate the return
323 * value. Only "static" types can be validated - a simple return
324 * of an integer/string/buffer/package or a named reference to
325 * a static object. Values such as a Localx or Argx or a control
326 * method invocation are not checked. Issue a warning if there is
327 * a valid return value, but the reserved method defines no
330 ******************************************************************************/
333 ApCheckPredefinedReturnValue (
334 ACPI_PARSE_OBJECT *Op,
335 ASL_METHOD_INFO *MethodInfo)
338 ACPI_PARSE_OBJECT *ReturnValueOp;
341 /* Check parent method for a match against the predefined name list */
343 Index = ApCheckForPredefinedName (MethodInfo->Op,
344 MethodInfo->Op->Asl.NameSeg);
348 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
350 /* No return value expected, warn if there is one */
352 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
355 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
356 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
357 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
359 /* Just return, nothing to do */
362 default: /* A standard predefined ACPI name */
364 if (!PredefinedNames[Index].Info.ExpectedBtypes)
366 /* No return value expected, warn if there is one */
368 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
372 /* Get the object returned, it is the next argument */
374 ReturnValueOp = Op->Asl.Child;
375 switch (ReturnValueOp->Asl.ParseOpcode)
380 case PARSEOP_INTEGER:
381 case PARSEOP_STRING_LITERAL:
383 case PARSEOP_PACKAGE:
385 /* Static data return object - check against expected type */
387 ApCheckObjectType (PredefinedNames[Index].Info.Name,
389 PredefinedNames[Index].Info.ExpectedBtypes);
395 * All other ops are very difficult or impossible to typecheck at
396 * compile time. These include all Localx, Argx, and method
397 * invocations. Also, NAMESEG and NAMESTRING because the type of
398 * any named object can be changed at runtime (for example,
399 * CopyObject will change the type of the target object.)
407 /*******************************************************************************
409 * FUNCTION: ApCheckForPredefinedObject
411 * PARAMETERS: Op - A parse node
412 * Name - The ACPI name to be checked
416 * DESCRIPTION: Check for a predefined name for a static object (created via
417 * the ASL Name operator). If it is a predefined ACPI name, ensure
418 * that the name does not require any arguments (which would
419 * require a control method implemenation of the name), and that
420 * the type of the object is one of the expected types for the
423 ******************************************************************************/
426 ApCheckForPredefinedObject (
427 ACPI_PARSE_OBJECT *Op,
434 * Check for a real predefined name -- not a resource descriptor name
435 * or a predefined scope name
437 Index = ApCheckForPredefinedName (Op, Name);
441 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
442 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
443 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
448 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
451 * These names must be control methods, by definition in ACPI spec.
452 * Also because they are defined to return no value. None of them
453 * require any arguments.
455 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
456 "with zero arguments");
459 default: /* A standard predefined ACPI name */
462 * If this predefined name requires input arguments, then
463 * it must be implemented as a control method
465 if (PredefinedNames[Index].Info.ParamCount > 0)
467 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
473 * If no return value is expected from this predefined name, then
474 * it follows that it must be implemented as a control method
475 * (with zero args, because the args > 0 case was handled above)
476 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
478 if (!PredefinedNames[Index].Info.ExpectedBtypes)
480 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
481 "with zero arguments");
485 /* Typecheck the actual object, it is the next argument */
487 ApCheckObjectType (PredefinedNames[Index].Info.Name,
488 Op->Asl.Child->Asl.Next,
489 PredefinedNames[Index].Info.ExpectedBtypes);
495 /*******************************************************************************
497 * FUNCTION: ApCheckForPredefinedName
499 * PARAMETERS: Op - A parse node
500 * Name - NameSeg to check
504 * DESCRIPTION: Check a NameSeg against the reserved list.
506 ******************************************************************************/
509 ApCheckForPredefinedName (
510 ACPI_PARSE_OBJECT *Op,
518 AcpiOsPrintf ("Found a null name, external = %s\n",
519 Op->Asl.ExternalName);
522 /* All reserved names are prefixed with a single underscore */
526 return (ACPI_NOT_RESERVED_NAME);
529 /* Check for a standard predefined method name */
531 for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
533 if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
535 /* Return index into predefined array */
540 /* Check for resource names and predefined scope names */
542 for (i = 0; ResourceNames[i].Info.Name[0]; i++)
544 if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
546 return (ACPI_PREDEFINED_NAME);
550 for (i = 0; ScopeNames[i].Info.Name[0]; i++)
552 if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
554 return (ACPI_PREDEFINED_NAME);
558 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
560 return (ApCheckForSpecialName (Op, Name));
564 /*******************************************************************************
566 * FUNCTION: ApCheckForSpecialName
568 * PARAMETERS: Op - A parse node
569 * Name - NameSeg to check
573 * DESCRIPTION: Check for the "special" predefined names -
574 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
576 ******************************************************************************/
579 ApCheckForSpecialName (
580 ACPI_PARSE_OBJECT *Op,
585 * Check for the "special" predefined names. We already know that the
586 * first character is an underscore.
592 if ((Name[1] == 'L') ||
597 /* The next two characters must be hex digits */
599 if ((isxdigit ((int) Name[2])) &&
600 (isxdigit ((int) Name[3])))
602 return (ACPI_EVENT_RESERVED_NAME);
606 /* Check for the names reserved for the compiler itself: _T_x */
608 else if ((Op->Asl.ExternalName[1] == 'T') &&
609 (Op->Asl.ExternalName[2] == '_'))
611 /* Ignore if actually emitted by the compiler */
613 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
615 return (ACPI_NOT_RESERVED_NAME);
619 * Was not actually emitted by the compiler. This is a special case,
620 * however. If the ASL code being compiled was the result of a
621 * dissasembly, it may possibly contain valid compiler-emitted names
622 * of the form "_T_x". We don't want to issue an error or even a
623 * warning and force the user to manually change the names. So, we
624 * will issue a remark instead.
626 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
627 return (ACPI_COMPILER_RESERVED_NAME);
631 * The name didn't match any of the known predefined names. Flag it as a
632 * warning, since the entire namespace starting with an underscore is
633 * reserved by the ACPI spec.
635 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
636 Op->Asl.ExternalName);
638 return (ACPI_NOT_RESERVED_NAME);
642 /*******************************************************************************
644 * FUNCTION: ApCheckObjectType
646 * PARAMETERS: PredefinedName - Name of the predefined object we are checking
647 * Op - Current parse node
648 * ExpectedBtypes - Bitmap of expected return type(s)
652 * DESCRIPTION: Check if the object type is one of the types that is expected
653 * by the predefined name. Only a limited number of object types
654 * can be returned by the predefined names.
656 ******************************************************************************/
660 const char *PredefinedName,
661 ACPI_PARSE_OBJECT *Op,
662 UINT32 ExpectedBtypes)
667 switch (Op->Asl.ParseOpcode)
672 case PARSEOP_INTEGER:
673 ReturnBtype = ACPI_RTYPE_INTEGER;
677 ReturnBtype = ACPI_RTYPE_BUFFER;
680 case PARSEOP_STRING_LITERAL:
681 ReturnBtype = ACPI_RTYPE_STRING;
684 case PARSEOP_PACKAGE:
685 case PARSEOP_VAR_PACKAGE:
686 ReturnBtype = ACPI_RTYPE_PACKAGE;
690 /* Not one of the supported object types */
695 /* Exit if the object is one of the expected types */
697 if (ReturnBtype & ExpectedBtypes)
705 /* Format the expected types and emit an error message */
707 ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
709 sprintf (MsgBuffer, "%s: found %s, requires %s",
710 PredefinedName, UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
712 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
717 /*******************************************************************************
719 * FUNCTION: ApDisplayReservedNames
725 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
726 * resource descriptor names.
728 ******************************************************************************/
731 ApDisplayReservedNames (
734 const ACPI_PREDEFINED_INFO *ThisName;
735 char TypeBuffer[48]; /* Room for 5 types */
740 * Predefined names/methods
742 printf ("\nPredefined Name Information\n\n");
745 ThisName = PredefinedNames;
746 while (ThisName->Info.Name[0])
748 printf ("%4.4s Requires %u arguments, ",
749 ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
751 if (ThisName->Info.ExpectedBtypes)
753 ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
754 printf ("Must return: %s\n", TypeBuffer);
758 printf ("No return value\n");
762 * Skip next entry in the table if this name returns a Package
763 * (next entry contains the package info)
765 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
774 printf ("%u Predefined Names are recognized\n", Count);
777 * Resource Descriptor names
779 printf ("\nResource Descriptor Predefined Names\n\n");
782 ThisName = ResourceNames;
783 while (ThisName->Info.Name[0])
785 printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name);
790 printf ("%u Resource Descriptor Names are recognized\n", Count);
793 * Predefined scope names
795 printf ("\nPredefined Scope Names\n\n");
797 ThisName = ScopeNames;
798 while (ThisName->Info.Name[0])
800 printf ("%4.4s Scope\n", ThisName->Info.Name);
806 /*******************************************************************************
808 * FUNCTION: ApGetExpectedTypes
810 * PARAMETERS: Buffer - Where the formatted string is returned
811 * ExpectedBTypes - Bitfield of expected data types
813 * RETURN: None, formatted string
815 * DESCRIPTION: Format the expected object types into a printable string.
817 ******************************************************************************/
822 UINT32 ExpectedBtypes)
831 ThisRtype = ACPI_RTYPE_INTEGER;
833 for (i = 0; i < ACPI_NUM_RTYPES; i++)
835 /* If one of the expected types, concatenate the name of this type */
837 if (ExpectedBtypes & ThisRtype)
839 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
840 j = 0; /* Use name separator from now on */
842 ThisRtype <<= 1; /* Next Rtype */