1 /******************************************************************************
3 * Module Name: aslpredef - support for ACPI predefined names
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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[] = {
103 {{"_DBT", 0, 0}}, /* Acpi 5.0 */
105 {{"_DPL", 0, 0}}, /* Acpi 5.0 */
106 {{"_DRS", 0, 0}}, /* Acpi 5.0 */
107 {{"_END", 0, 0}}, /* Acpi 5.0 */
108 {{"_FLC", 0, 0}}, /* Acpi 5.0 */
112 {{"_IOR", 0, 0}}, /* Acpi 5.0 */
114 {{"_LIN", 0, 0}}, /* Acpi 5.0 */
121 {{"_MOD", 0, 0}}, /* Acpi 5.0 */
123 {{"_PAR", 0, 0}}, /* Acpi 5.0 */
124 {{"_PHA", 0, 0}}, /* Acpi 5.0 */
125 {{"_PIN", 0, 0}}, /* Acpi 5.0 */
126 {{"_PPI", 0, 0}}, /* Acpi 5.0 */
127 {{"_POL", 0, 0}}, /* Acpi 5.0 */
131 {{"_RT_", 0, 0}}, /* Acpi 3.0 */
133 {{"_RXL", 0, 0}}, /* Acpi 5.0 */
136 {{"_SLV", 0, 0}}, /* Acpi 5.0 */
137 {{"_SPE", 0, 0}}, /* Acpi 5.0 */
138 {{"_STB", 0, 0}}, /* Acpi 5.0 */
141 {{"_TSF", 0, 0}}, /* Acpi 3.0 */
143 {{"_TXL", 0, 0}}, /* Acpi 5.0 */
145 {{"_VEN", 0, 0}}, /* Acpi 5.0 */
146 {{{0,0,0,0}, 0, 0}} /* Table terminator */
149 static const ACPI_PREDEFINED_INFO ScopeNames[] = {
153 {{{0,0,0,0}, 0, 0}} /* Table terminator */
157 /*******************************************************************************
159 * FUNCTION: ApCheckForPredefinedMethod
161 * PARAMETERS: Op - A parse node of type "METHOD".
162 * MethodInfo - Saved info about this method
166 * DESCRIPTION: If method is a predefined name, check that the number of
167 * arguments and the return type (returns a value or not)
170 ******************************************************************************/
173 ApCheckForPredefinedMethod (
174 ACPI_PARSE_OBJECT *Op,
175 ASL_METHOD_INFO *MethodInfo)
178 UINT32 RequiredArgsCurrent;
179 UINT32 RequiredArgsOld;
182 /* Check for a match against the predefined name list */
184 Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
188 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
189 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
190 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
192 /* Just return, nothing to do */
196 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
198 Gbl_ReservedMethods++;
200 /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
202 if (MethodInfo->NumArguments != 0)
204 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
206 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
214 * Matched a predefined method name
216 * Validate the ASL-defined argument count. Allow two different legal
219 Gbl_ReservedMethods++;
221 RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
222 RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
224 if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
225 (MethodInfo->NumArguments != RequiredArgsOld))
227 sprintf (MsgBuffer, "%4.4s requires %u",
228 PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
230 if (MethodInfo->NumArguments > RequiredArgsCurrent)
232 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
237 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
243 * Check if method returns no value, but the predefined name is
244 * required to return a value
246 if (MethodInfo->NumReturnNoValue &&
247 PredefinedNames[Index].Info.ExpectedBtypes)
249 ApGetExpectedTypes (StringBuffer,
250 PredefinedNames[Index].Info.ExpectedBtypes);
252 sprintf (MsgBuffer, "%s required for %4.4s",
253 StringBuffer, PredefinedNames[Index].Info.Name);
255 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
265 /*******************************************************************************
267 * FUNCTION: ApCheckForUnexpectedReturnValue
269 * PARAMETERS: Op - A parse node of type "RETURN".
270 * MethodInfo - Saved info about this method
274 * DESCRIPTION: Check for an unexpected return value from a predefined method.
275 * Invoked for predefined methods that are defined to not return
276 * any value. If there is a return value, issue a remark, since
277 * the ASL writer may be confused as to the method definition
278 * and/or functionality.
280 * Note: We ignore all return values of "Zero", since this is what a standalone
281 * Return() statement will always generate -- so we ignore it here --
282 * i.e., there is no difference between Return() and Return(Zero).
283 * Also, a null Return() will be disassembled to return(Zero) -- so, we
284 * don't want to generate extraneous remarks/warnings for a disassembled
287 ******************************************************************************/
290 ApCheckForUnexpectedReturnValue (
291 ACPI_PARSE_OBJECT *Op,
292 ASL_METHOD_INFO *MethodInfo)
294 ACPI_PARSE_OBJECT *ReturnValueOp;
297 /* Ignore Return() and Return(Zero) (they are the same) */
299 ReturnValueOp = Op->Asl.Child;
300 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
305 /* We have a valid return value, but the reserved name did not expect it */
307 AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
308 Op, MethodInfo->Op->Asl.ExternalName);
312 /*******************************************************************************
314 * FUNCTION: ApCheckPredefinedReturnValue
316 * PARAMETERS: Op - A parse node of type "RETURN".
317 * MethodInfo - Saved info about this method
321 * DESCRIPTION: If method is a predefined name, attempt to validate the return
322 * value. Only "static" types can be validated - a simple return
323 * of an integer/string/buffer/package or a named reference to
324 * a static object. Values such as a Localx or Argx or a control
325 * method invocation are not checked. Issue a warning if there is
326 * a valid return value, but the reserved method defines no
329 ******************************************************************************/
332 ApCheckPredefinedReturnValue (
333 ACPI_PARSE_OBJECT *Op,
334 ASL_METHOD_INFO *MethodInfo)
337 ACPI_PARSE_OBJECT *ReturnValueOp;
340 /* Check parent method for a match against the predefined name list */
342 Index = ApCheckForPredefinedName (MethodInfo->Op,
343 MethodInfo->Op->Asl.NameSeg);
347 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
349 /* No return value expected, warn if there is one */
351 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
354 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
355 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
356 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
358 /* Just return, nothing to do */
361 default: /* A standard predefined ACPI name */
363 if (!PredefinedNames[Index].Info.ExpectedBtypes)
365 /* No return value expected, warn if there is one */
367 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
371 /* Get the object returned, it is the next argument */
373 ReturnValueOp = Op->Asl.Child;
374 switch (ReturnValueOp->Asl.ParseOpcode)
379 case PARSEOP_INTEGER:
380 case PARSEOP_STRING_LITERAL:
382 case PARSEOP_PACKAGE:
384 /* Static data return object - check against expected type */
386 ApCheckObjectType (ReturnValueOp,
387 PredefinedNames[Index].Info.ExpectedBtypes);
393 * All other ops are very difficult or impossible to typecheck at
394 * compile time. These include all Localx, Argx, and method
395 * invocations. Also, NAMESEG and NAMESTRING because the type of
396 * any named object can be changed at runtime (for example,
397 * CopyObject will change the type of the target object.)
405 /*******************************************************************************
407 * FUNCTION: ApCheckForPredefinedObject
409 * PARAMETERS: Op - A parse node
410 * Name - The ACPI name to be checked
414 * DESCRIPTION: Check for a predefined name for a static object (created via
415 * the ASL Name operator). If it is a predefined ACPI name, ensure
416 * that the name does not require any arguments (which would
417 * require a control method implemenation of the name), and that
418 * the type of the object is one of the expected types for the
421 ******************************************************************************/
424 ApCheckForPredefinedObject (
425 ACPI_PARSE_OBJECT *Op,
432 * Check for a real predefined name -- not a resource descriptor name
433 * or a predefined scope name
435 Index = ApCheckForPredefinedName (Op, Name);
439 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
440 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
441 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
446 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
449 * These names must be control methods, by definition in ACPI spec.
450 * Also because they are defined to return no value. None of them
451 * require any arguments.
453 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
454 "with zero arguments");
457 default: /* A standard predefined ACPI name */
460 * If this predefined name requires input arguments, then
461 * it must be implemented as a control method
463 if (PredefinedNames[Index].Info.ParamCount > 0)
465 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
471 * If no return value is expected from this predefined name, then
472 * it follows that it must be implemented as a control method
473 * (with zero args, because the args > 0 case was handled above)
474 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
476 if (!PredefinedNames[Index].Info.ExpectedBtypes)
478 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
479 "with zero arguments");
483 /* Typecheck the actual object, it is the next argument */
485 ApCheckObjectType (Op->Asl.Child->Asl.Next,
486 PredefinedNames[Index].Info.ExpectedBtypes);
492 /*******************************************************************************
494 * FUNCTION: ApCheckForPredefinedName
496 * PARAMETERS: Op - A parse node
497 * Name - NameSeg to check
501 * DESCRIPTION: Check a NameSeg against the reserved list.
503 ******************************************************************************/
506 ApCheckForPredefinedName (
507 ACPI_PARSE_OBJECT *Op,
515 AcpiOsPrintf ("Found a null name, external = %s\n",
516 Op->Asl.ExternalName);
519 /* All reserved names are prefixed with a single underscore */
523 return (ACPI_NOT_RESERVED_NAME);
526 /* Check for a standard predefined method name */
528 for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
530 if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
532 /* Return index into predefined array */
537 /* Check for resource names and predefined scope names */
539 for (i = 0; ResourceNames[i].Info.Name[0]; i++)
541 if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
543 return (ACPI_PREDEFINED_NAME);
547 for (i = 0; ScopeNames[i].Info.Name[0]; i++)
549 if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
551 return (ACPI_PREDEFINED_NAME);
555 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
557 return (ApCheckForSpecialName (Op, Name));
561 /*******************************************************************************
563 * FUNCTION: ApCheckForSpecialName
565 * PARAMETERS: Op - A parse node
566 * Name - NameSeg to check
570 * DESCRIPTION: Check for the "special" predefined names -
571 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
573 ******************************************************************************/
576 ApCheckForSpecialName (
577 ACPI_PARSE_OBJECT *Op,
582 * Check for the "special" predefined names. We already know that the
583 * first character is an underscore.
589 if ((Name[1] == 'L') ||
594 /* The next two characters must be hex digits */
596 if ((isxdigit ((int) Name[2])) &&
597 (isxdigit ((int) Name[3])))
599 return (ACPI_EVENT_RESERVED_NAME);
603 /* Check for the names reserved for the compiler itself: _T_x */
605 else if ((Op->Asl.ExternalName[1] == 'T') &&
606 (Op->Asl.ExternalName[2] == '_'))
608 /* Ignore if actually emitted by the compiler */
610 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
612 return (ACPI_NOT_RESERVED_NAME);
616 * Was not actually emitted by the compiler. This is a special case,
617 * however. If the ASL code being compiled was the result of a
618 * dissasembly, it may possibly contain valid compiler-emitted names
619 * of the form "_T_x". We don't want to issue an error or even a
620 * warning and force the user to manually change the names. So, we
621 * will issue a remark instead.
623 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
624 return (ACPI_COMPILER_RESERVED_NAME);
628 * The name didn't match any of the known predefined names. Flag it as a
629 * warning, since the entire namespace starting with an underscore is
630 * reserved by the ACPI spec.
632 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
633 Op->Asl.ExternalName);
635 return (ACPI_NOT_RESERVED_NAME);
639 /*******************************************************************************
641 * FUNCTION: ApCheckObjectType
643 * PARAMETERS: Op - Current parse node
644 * ExpectedBtypes - Bitmap of expected return type(s)
648 * DESCRIPTION: Check if the object type is one of the types that is expected
649 * by the predefined name. Only a limited number of object types
650 * can be returned by the predefined names.
652 ******************************************************************************/
656 ACPI_PARSE_OBJECT *Op,
657 UINT32 ExpectedBtypes)
662 switch (Op->Asl.ParseOpcode)
667 case PARSEOP_INTEGER:
668 ReturnBtype = ACPI_RTYPE_INTEGER;
672 ReturnBtype = ACPI_RTYPE_BUFFER;
675 case PARSEOP_STRING_LITERAL:
676 ReturnBtype = ACPI_RTYPE_STRING;
679 case PARSEOP_PACKAGE:
680 case PARSEOP_VAR_PACKAGE:
681 ReturnBtype = ACPI_RTYPE_PACKAGE;
685 /* Not one of the supported object types */
690 /* Exit if the object is one of the expected types */
692 if (ReturnBtype & ExpectedBtypes)
700 /* Format the expected types and emit an error message */
702 ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
704 sprintf (MsgBuffer, "found %s, requires %s",
705 UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
707 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
712 /*******************************************************************************
714 * FUNCTION: ApDisplayReservedNames
720 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
721 * resource descriptor names.
723 ******************************************************************************/
726 ApDisplayReservedNames (
729 const ACPI_PREDEFINED_INFO *ThisName;
730 char TypeBuffer[48]; /* Room for 5 types */
735 * Predefined names/methods
737 printf ("\nPredefined Name Information\n\n");
740 ThisName = PredefinedNames;
741 while (ThisName->Info.Name[0])
743 printf ("%4.4s Requires %u arguments, ",
744 ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
746 if (ThisName->Info.ExpectedBtypes)
748 ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
749 printf ("Must return: %s\n", TypeBuffer);
753 printf ("No return value\n");
757 * Skip next entry in the table if this name returns a Package
758 * (next entry contains the package info)
760 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
769 printf ("%u Predefined Names are recognized\n", Count);
772 * Resource Descriptor names
774 printf ("\nResource Descriptor Predefined Names\n\n");
777 ThisName = ResourceNames;
778 while (ThisName->Info.Name[0])
780 printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name);
785 printf ("%u Resource Descriptor Names are recognized\n", Count);
788 * Predefined scope names
790 printf ("\nPredefined Scope Names\n\n");
792 ThisName = ScopeNames;
793 while (ThisName->Info.Name[0])
795 printf ("%4.4s Scope\n", ThisName->Info.Name);
801 /*******************************************************************************
803 * FUNCTION: ApGetExpectedTypes
805 * PARAMETERS: Buffer - Where the formatted string is returned
806 * ExpectedBTypes - Bitfield of expected data types
808 * RETURN: None, formatted string
810 * DESCRIPTION: Format the expected object types into a printable string.
812 ******************************************************************************/
817 UINT32 ExpectedBtypes)
826 ThisRtype = ACPI_RTYPE_INTEGER;
828 for (i = 0; i < ACPI_NUM_RTYPES; i++)
830 /* If one of the expected types, concatenate the name of this type */
832 if (ExpectedBtypes & ThisRtype)
834 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
835 j = 0; /* Use name separator from now on */
837 ThisRtype <<= 1; /* Next Rtype */