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,
244 /*******************************************************************************
246 * FUNCTION: ApCheckForUnexpectedReturnValue
248 * PARAMETERS: Op - A parse node of type "RETURN".
249 * MethodInfo - Saved info about this method
253 * DESCRIPTION: Check for an unexpected return value from a predefined method.
254 * Invoked for predefined methods that are defined to not return
255 * any value. If there is a return value, issue a remark, since
256 * the ASL writer may be confused as to the method definition
257 * and/or functionality.
259 * Note: We ignore all return values of "Zero", since this is what a standalone
260 * Return() statement will always generate -- so we ignore it here --
261 * i.e., there is no difference between Return() and Return(Zero).
262 * Also, a null Return() will be disassembled to return(Zero) -- so, we
263 * don't want to generate extraneous remarks/warnings for a disassembled
266 ******************************************************************************/
269 ApCheckForUnexpectedReturnValue (
270 ACPI_PARSE_OBJECT *Op,
271 ASL_METHOD_INFO *MethodInfo)
273 ACPI_PARSE_OBJECT *ReturnValueOp;
276 /* Ignore Return() and Return(Zero) (they are the same) */
278 ReturnValueOp = Op->Asl.Child;
279 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
284 /* We have a valid return value, but the reserved name did not expect it */
286 AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
287 Op, MethodInfo->Op->Asl.ExternalName);
291 /*******************************************************************************
293 * FUNCTION: ApCheckPredefinedReturnValue
295 * PARAMETERS: Op - A parse node of type "RETURN".
296 * MethodInfo - Saved info about this method
300 * DESCRIPTION: If method is a predefined name, attempt to validate the return
301 * value. Only "static" types can be validated - a simple return
302 * of an integer/string/buffer/package or a named reference to
303 * a static object. Values such as a Localx or Argx or a control
304 * method invocation are not checked. Issue a warning if there is
305 * a valid return value, but the reserved method defines no
308 ******************************************************************************/
311 ApCheckPredefinedReturnValue (
312 ACPI_PARSE_OBJECT *Op,
313 ASL_METHOD_INFO *MethodInfo)
316 ACPI_PARSE_OBJECT *ReturnValueOp;
319 /* Check parent method for a match against the predefined name list */
321 Index = ApCheckForPredefinedName (MethodInfo->Op,
322 MethodInfo->Op->Asl.NameSeg);
326 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
328 /* No return value expected, warn if there is one */
330 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
333 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
334 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
335 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
337 /* Just return, nothing to do */
340 default: /* A standard predefined ACPI name */
342 if (!PredefinedNames[Index].Info.ExpectedBtypes)
344 /* No return value expected, warn if there is one */
346 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
350 /* Get the object returned, it is the next argument */
352 ReturnValueOp = Op->Asl.Child;
353 switch (ReturnValueOp->Asl.ParseOpcode)
358 case PARSEOP_INTEGER:
359 case PARSEOP_STRING_LITERAL:
361 case PARSEOP_PACKAGE:
363 /* Static data return object - check against expected type */
365 ApCheckObjectType (ReturnValueOp,
366 PredefinedNames[Index].Info.ExpectedBtypes);
372 * All other ops are very difficult or impossible to typecheck at
373 * compile time. These include all Localx, Argx, and method
374 * invocations. Also, NAMESEG and NAMESTRING because the type of
375 * any named object can be changed at runtime (for example,
376 * CopyObject will change the type of the target object.)
384 /*******************************************************************************
386 * FUNCTION: ApCheckForPredefinedObject
388 * PARAMETERS: Op - A parse node
389 * Name - The ACPI name to be checked
393 * DESCRIPTION: Check for a predefined name for a static object (created via
394 * the ASL Name operator). If it is a predefined ACPI name, ensure
395 * that the name does not require any arguments (which would
396 * require a control method implemenation of the name), and that
397 * the type of the object is one of the expected types for the
400 ******************************************************************************/
403 ApCheckForPredefinedObject (
404 ACPI_PARSE_OBJECT *Op,
411 * Check for a real predefined name -- not a resource descriptor name
412 * or a predefined scope name
414 Index = ApCheckForPredefinedName (Op, Name);
418 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
419 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
420 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
425 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
428 * These names must be control methods, by definition in ACPI spec.
429 * Also because they are defined to return no value. None of them
430 * require any arguments.
432 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
433 "with zero arguments");
436 default: /* A standard predefined ACPI name */
439 * If this predefined name requires input arguments, then
440 * it must be implemented as a control method
442 if (PredefinedNames[Index].Info.ParamCount > 0)
444 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
450 * If no return value is expected from this predefined name, then
451 * it follows that it must be implemented as a control method
452 * (with zero args, because the args > 0 case was handled above)
453 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
455 if (!PredefinedNames[Index].Info.ExpectedBtypes)
457 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
458 "with zero arguments");
462 /* Typecheck the actual object, it is the next argument */
464 ApCheckObjectType (Op->Asl.Child->Asl.Next,
465 PredefinedNames[Index].Info.ExpectedBtypes);
471 /*******************************************************************************
473 * FUNCTION: ApCheckForPredefinedName
475 * PARAMETERS: Op - A parse node
476 * Name - NameSeg to check
480 * DESCRIPTION: Check a NameSeg against the reserved list.
482 ******************************************************************************/
485 ApCheckForPredefinedName (
486 ACPI_PARSE_OBJECT *Op,
494 AcpiOsPrintf ("Found a null name, external = %s\n",
495 Op->Asl.ExternalName);
498 /* All reserved names are prefixed with a single underscore */
502 return (ACPI_NOT_RESERVED_NAME);
505 /* Check for a standard predefined method name */
507 for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
509 if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
511 /* Return index into predefined array */
516 /* Check for resource names and predefined scope names */
518 for (i = 0; ResourceNames[i].Info.Name[0]; i++)
520 if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
522 return (ACPI_PREDEFINED_NAME);
526 for (i = 0; ScopeNames[i].Info.Name[0]; i++)
528 if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
530 return (ACPI_PREDEFINED_NAME);
534 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
536 return (ApCheckForSpecialName (Op, Name));
540 /*******************************************************************************
542 * FUNCTION: ApCheckForSpecialName
544 * PARAMETERS: Op - A parse node
545 * Name - NameSeg to check
549 * DESCRIPTION: Check for the "special" predefined names -
550 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
552 ******************************************************************************/
555 ApCheckForSpecialName (
556 ACPI_PARSE_OBJECT *Op,
561 * Check for the "special" predefined names. We already know that the
562 * first character is an underscore.
568 if ((Name[1] == 'L') ||
573 /* The next two characters must be hex digits */
575 if ((isxdigit ((int) Name[2])) &&
576 (isxdigit ((int) Name[3])))
578 return (ACPI_EVENT_RESERVED_NAME);
582 /* Check for the names reserved for the compiler itself: _T_x */
584 else if ((Op->Asl.ExternalName[1] == 'T') &&
585 (Op->Asl.ExternalName[2] == '_'))
587 /* Ignore if actually emitted by the compiler */
589 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
591 return (ACPI_NOT_RESERVED_NAME);
595 * Was not actually emitted by the compiler. This is a special case,
596 * however. If the ASL code being compiled was the result of a
597 * dissasembly, it may possibly contain valid compiler-emitted names
598 * of the form "_T_x". We don't want to issue an error or even a
599 * warning and force the user to manually change the names. So, we
600 * will issue a remark instead.
602 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
603 return (ACPI_COMPILER_RESERVED_NAME);
607 * The name didn't match any of the known predefined names. Flag it as a
608 * warning, since the entire namespace starting with an underscore is
609 * reserved by the ACPI spec.
611 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
612 Op->Asl.ExternalName);
614 return (ACPI_NOT_RESERVED_NAME);
618 /*******************************************************************************
620 * FUNCTION: ApCheckObjectType
622 * PARAMETERS: Op - Current parse node
623 * ExpectedBtypes - Bitmap of expected return type(s)
627 * DESCRIPTION: Check if the object type is one of the types that is expected
628 * by the predefined name. Only a limited number of object types
629 * can be returned by the predefined names.
631 ******************************************************************************/
635 ACPI_PARSE_OBJECT *Op,
636 UINT32 ExpectedBtypes)
641 switch (Op->Asl.ParseOpcode)
646 case PARSEOP_INTEGER:
647 ReturnBtype = ACPI_RTYPE_INTEGER;
651 ReturnBtype = ACPI_RTYPE_BUFFER;
654 case PARSEOP_STRING_LITERAL:
655 ReturnBtype = ACPI_RTYPE_STRING;
658 case PARSEOP_PACKAGE:
659 ReturnBtype = ACPI_RTYPE_PACKAGE;
663 /* Not one of the supported object types */
668 /* Exit if the object is one of the expected types */
670 if (ReturnBtype & ExpectedBtypes)
678 /* Format the expected types and emit an error message */
680 ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
682 sprintf (MsgBuffer, "found %s, requires %s",
683 UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
685 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
690 /*******************************************************************************
692 * FUNCTION: ApDisplayReservedNames
698 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
699 * resource descriptor names.
701 ******************************************************************************/
704 ApDisplayReservedNames (
707 const ACPI_PREDEFINED_INFO *ThisName;
708 char TypeBuffer[48]; /* Room for 5 types */
713 * Predefined names/methods
715 printf ("\nPredefined Name Information\n\n");
718 ThisName = PredefinedNames;
719 while (ThisName->Info.Name[0])
721 printf ("%4.4s Requires %u arguments, ",
722 ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
724 if (ThisName->Info.ExpectedBtypes)
726 ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
727 printf ("Must return: %s\n", TypeBuffer);
731 printf ("No return value\n");
735 * Skip next entry in the table if this name returns a Package
736 * (next entry contains the package info)
738 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
747 printf ("%u Predefined Names are recognized\n", Count);
750 * Resource Descriptor names
752 printf ("\nResource Descriptor Predefined Names\n\n");
755 ThisName = ResourceNames;
756 while (ThisName->Info.Name[0])
758 printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name);
763 printf ("%u Resource Descriptor Names are recognized\n", Count);
766 * Predefined scope names
768 printf ("\nPredefined Scope Names\n\n");
770 ThisName = ScopeNames;
771 while (ThisName->Info.Name[0])
773 printf ("%4.4s Scope\n", ThisName->Info.Name);
779 /*******************************************************************************
781 * FUNCTION: ApGetExpectedTypes
783 * PARAMETERS: Buffer - Where the formatted string is returned
784 * ExpectedBTypes - Bitfield of expected data types
786 * RETURN: None, formatted string
788 * DESCRIPTION: Format the expected object types into a printable string.
790 ******************************************************************************/
795 UINT32 ExpectedBtypes)
804 ThisRtype = ACPI_RTYPE_INTEGER;
806 for (i = 0; i < ACPI_NUM_RTYPES; i++)
808 /* If one of the expected types, concatenate the name of this type */
810 if (ExpectedBtypes & ThisRtype)
812 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
813 j = 0; /* Use name separator from now on */
815 ThisRtype <<= 1; /* Next Rtype */