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 ApCheckForSpecialName (
59 ACPI_PARSE_OBJECT *Op,
64 ACPI_PARSE_OBJECT *Op,
65 UINT32 ExpectedBtypes);
70 UINT32 ExpectedBtypes);
74 * Names for the types that can be returned by the predefined objects.
75 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
77 static const char *AcpiRtypeNames[] =
87 * Predefined names for use in Resource Descriptors. These names do not
88 * appear in the global Predefined Name table (since these names never
89 * appear in actual AML byte code, only in the original ASL)
91 static const ACPI_PREDEFINED_INFO ResourceNames[] = {
113 {{"_RT_", 0, 0}}, /* Acpi 3.0 */
119 {{"_TSF", 0, 0}}, /* Acpi 3.0 */
122 {{{0,0,0,0}, 0, 0}} /* Table terminator */
125 static const ACPI_PREDEFINED_INFO ScopeNames[] = {
129 {{{0,0,0,0}, 0, 0}} /* Table terminator */
133 /*******************************************************************************
135 * FUNCTION: ApCheckForPredefinedMethod
137 * PARAMETERS: Op - A parse node of type "METHOD".
138 * MethodInfo - Saved info about this method
142 * DESCRIPTION: If method is a predefined name, check that the number of
143 * arguments and the return type (returns a value or not)
146 ******************************************************************************/
149 ApCheckForPredefinedMethod (
150 ACPI_PARSE_OBJECT *Op,
151 ASL_METHOD_INFO *MethodInfo)
154 UINT32 RequiredArgsCurrent;
155 UINT32 RequiredArgsOld;
158 /* Check for a match against the predefined name list */
160 Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
164 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
165 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
166 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
168 /* Just return, nothing to do */
172 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
174 Gbl_ReservedMethods++;
176 /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
178 if (MethodInfo->NumArguments != 0)
180 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
182 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
190 * Matched a predefined method name
192 * Validate the ASL-defined argument count. Allow two different legal
195 Gbl_ReservedMethods++;
197 RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
198 RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
200 if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
201 (MethodInfo->NumArguments != RequiredArgsOld))
203 sprintf (MsgBuffer, "%4.4s requires %u",
204 PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
206 if (MethodInfo->NumArguments > RequiredArgsCurrent)
208 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
213 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
219 * Check if method returns no value, but the predefined name is
220 * required to return a value
222 if (MethodInfo->NumReturnNoValue &&
223 PredefinedNames[Index].Info.ExpectedBtypes)
225 ApGetExpectedTypes (StringBuffer,
226 PredefinedNames[Index].Info.ExpectedBtypes);
228 sprintf (MsgBuffer, "%s required for %4.4s",
229 StringBuffer, PredefinedNames[Index].Info.Name);
231 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
239 /*******************************************************************************
241 * FUNCTION: ApCheckPredefinedReturnValue
243 * PARAMETERS: Op - A parse node of type "RETURN".
244 * MethodInfo - Saved info about this method
248 * DESCRIPTION: If method is a predefined name, attempt to validate the return
249 * value. Only "static" types can be validated - a simple return
250 * of an integer/string/buffer/package or a named reference to
251 * a static object. Values such as a Localx or Argx or a control
252 * method invocation are not checked.
254 ******************************************************************************/
257 ApCheckPredefinedReturnValue (
258 ACPI_PARSE_OBJECT *Op,
259 ASL_METHOD_INFO *MethodInfo)
262 ACPI_PARSE_OBJECT *ReturnValueOp;
265 /* Check parent method for a match against the predefined name list */
267 Index = ApCheckForPredefinedName (MethodInfo->Op,
268 MethodInfo->Op->Asl.NameSeg);
272 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
273 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
274 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
275 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
277 /* Just return, nothing to do */
280 default: /* A standard predefined ACPI name */
282 /* Exit if no return value expected */
284 if (!PredefinedNames[Index].Info.ExpectedBtypes)
289 /* Get the object returned, it is the next argument */
291 ReturnValueOp = Op->Asl.Child;
292 switch (ReturnValueOp->Asl.ParseOpcode)
297 case PARSEOP_INTEGER:
298 case PARSEOP_STRING_LITERAL:
300 case PARSEOP_PACKAGE:
302 /* Static data return object - check against expected type */
304 ApCheckObjectType (ReturnValueOp,
305 PredefinedNames[Index].Info.ExpectedBtypes);
311 * All other ops are very difficult or impossible to typecheck at
312 * compile time. These include all Localx, Argx, and method
313 * invocations. Also, NAMESEG and NAMESTRING because the type of
314 * any named object can be changed at runtime (for example,
315 * CopyObject will change the type of the target object.)
323 /*******************************************************************************
325 * FUNCTION: ApCheckForPredefinedObject
327 * PARAMETERS: Op - A parse node
328 * Name - The ACPI name to be checked
332 * DESCRIPTION: Check for a predefined name for a static object (created via
333 * the ASL Name operator). If it is a predefined ACPI name, ensure
334 * that the name does not require any arguments (which would
335 * require a control method implemenation of the name), and that
336 * the type of the object is one of the expected types for the
339 ******************************************************************************/
342 ApCheckForPredefinedObject (
343 ACPI_PARSE_OBJECT *Op,
350 * Check for a real predefined name -- not a resource descriptor name
351 * or a predefined scope name
353 Index = ApCheckForPredefinedName (Op, Name);
357 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
358 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
359 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
364 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
367 * These names must be control methods, by definition in ACPI spec.
368 * Also because they are defined to return no value. None of them
369 * require any arguments.
371 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
372 "with zero arguments");
375 default: /* A standard predefined ACPI name */
378 * If this predefined name requires input arguments, then
379 * it must be implemented as a control method
381 if (PredefinedNames[Index].Info.ParamCount > 0)
383 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
389 * If no return value is expected from this predefined name, then
390 * it follows that it must be implemented as a control method
391 * (with zero args, because the args > 0 case was handled above)
392 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
394 if (!PredefinedNames[Index].Info.ExpectedBtypes)
396 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
397 "with zero arguments");
401 /* Typecheck the actual object, it is the next argument */
403 ApCheckObjectType (Op->Asl.Child->Asl.Next,
404 PredefinedNames[Index].Info.ExpectedBtypes);
410 /*******************************************************************************
412 * FUNCTION: ApCheckForPredefinedName
414 * PARAMETERS: Op - A parse node
415 * Name - NameSeg to check
419 * DESCRIPTION: Check a NameSeg against the reserved list.
421 ******************************************************************************/
424 ApCheckForPredefinedName (
425 ACPI_PARSE_OBJECT *Op,
433 AcpiOsPrintf ("Found a null name, external = %s\n",
434 Op->Asl.ExternalName);
437 /* All reserved names are prefixed with a single underscore */
441 return (ACPI_NOT_RESERVED_NAME);
444 /* Check for a standard predefined method name */
446 for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
448 if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
450 /* Return index into predefined array */
455 /* Check for resource names and predefined scope names */
457 for (i = 0; ResourceNames[i].Info.Name[0]; i++)
459 if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
461 return (ACPI_PREDEFINED_NAME);
465 for (i = 0; ScopeNames[i].Info.Name[0]; i++)
467 if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
469 return (ACPI_PREDEFINED_NAME);
473 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
475 return (ApCheckForSpecialName (Op, Name));
479 /*******************************************************************************
481 * FUNCTION: ApCheckForSpecialName
483 * PARAMETERS: Op - A parse node
484 * Name - NameSeg to check
488 * DESCRIPTION: Check for the "special" predefined names -
489 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
491 ******************************************************************************/
494 ApCheckForSpecialName (
495 ACPI_PARSE_OBJECT *Op,
500 * Check for the "special" predefined names. We already know that the
501 * first character is an underscore.
507 if ((Name[1] == 'L') ||
512 /* The next two characters must be hex digits */
514 if ((isxdigit ((int) Name[2])) &&
515 (isxdigit ((int) Name[3])))
517 return (ACPI_EVENT_RESERVED_NAME);
521 /* Check for the names reserved for the compiler itself: _T_x */
523 else if ((Op->Asl.ExternalName[1] == 'T') &&
524 (Op->Asl.ExternalName[2] == '_'))
526 /* Ignore if actually emitted by the compiler */
528 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
530 return (ACPI_NOT_RESERVED_NAME);
534 * Was not actually emitted by the compiler. This is a special case,
535 * however. If the ASL code being compiled was the result of a
536 * dissasembly, it may possibly contain valid compiler-emitted names
537 * of the form "_T_x". We don't want to issue an error or even a
538 * warning and force the user to manually change the names. So, we
539 * will issue a remark instead.
541 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
542 return (ACPI_COMPILER_RESERVED_NAME);
546 * The name didn't match any of the known predefined names. Flag it as a
547 * warning, since the entire namespace starting with an underscore is
548 * reserved by the ACPI spec.
550 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
551 Op->Asl.ExternalName);
553 return (ACPI_NOT_RESERVED_NAME);
557 /*******************************************************************************
559 * FUNCTION: ApCheckObjectType
561 * PARAMETERS: Op - Current parse node
562 * ExpectedBtypes - Bitmap of expected return type(s)
566 * DESCRIPTION: Check if the object type is one of the types that is expected
567 * by the predefined name. Only a limited number of object types
568 * can be returned by the predefined names.
570 ******************************************************************************/
574 ACPI_PARSE_OBJECT *Op,
575 UINT32 ExpectedBtypes)
580 switch (Op->Asl.ParseOpcode)
585 case PARSEOP_INTEGER:
586 ReturnBtype = ACPI_RTYPE_INTEGER;
590 ReturnBtype = ACPI_RTYPE_BUFFER;
593 case PARSEOP_STRING_LITERAL:
594 ReturnBtype = ACPI_RTYPE_STRING;
597 case PARSEOP_PACKAGE:
598 ReturnBtype = ACPI_RTYPE_PACKAGE;
602 /* Not one of the supported object types */
607 /* Exit if the object is one of the expected types */
609 if (ReturnBtype & ExpectedBtypes)
617 /* Format the expected types and emit an error message */
619 ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
621 sprintf (MsgBuffer, "found %s, requires %s",
622 UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
624 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
629 /*******************************************************************************
631 * FUNCTION: ApDisplayReservedNames
637 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
638 * resource descriptor names.
640 ******************************************************************************/
643 ApDisplayReservedNames (
646 const ACPI_PREDEFINED_INFO *ThisName;
647 char TypeBuffer[48]; /* Room for 5 types */
652 * Predefined names/methods
654 printf ("\nPredefined Name Information\n\n");
657 ThisName = PredefinedNames;
658 while (ThisName->Info.Name[0])
660 printf ("%4.4s Requires %u arguments, ",
661 ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
663 if (ThisName->Info.ExpectedBtypes)
665 ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
666 printf ("Must return: %s\n", TypeBuffer);
670 printf ("No return value\n");
674 * Skip next entry in the table if this name returns a Package
675 * (next entry contains the package info)
677 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
686 printf ("%u Predefined Names are recognized\n", Count);
689 * Resource Descriptor names
691 printf ("\nResource Descriptor Predefined Names\n\n");
694 ThisName = ResourceNames;
695 while (ThisName->Info.Name[0])
697 printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name);
702 printf ("%u Resource Descriptor Names are recognized\n", Count);
705 * Predefined scope names
707 printf ("\nPredefined Scope Names\n\n");
709 ThisName = ScopeNames;
710 while (ThisName->Info.Name[0])
712 printf ("%4.4s Scope\n", ThisName->Info.Name);
718 /*******************************************************************************
720 * FUNCTION: ApGetExpectedTypes
722 * PARAMETERS: Buffer - Where the formatted string is returned
723 * ExpectedBTypes - Bitfield of expected data types
725 * RETURN: None, formatted string
727 * DESCRIPTION: Format the expected object types into a printable string.
729 ******************************************************************************/
734 UINT32 ExpectedBtypes)
743 ThisRtype = ACPI_RTYPE_INTEGER;
745 for (i = 0; i < ACPI_NUM_RTYPES; i++)
747 /* If one of the expected types, concatenate the name of this type */
749 if (ExpectedBtypes & ThisRtype)
751 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
752 j = 0; /* Use name separator from now on */
754 ThisRtype <<= 1; /* Next Rtype */