Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / aslpredef.c
blob60b5269587b4b5b253fb510f21ef731cde90968b
1 /******************************************************************************
3 * Module Name: aslpredef - support for ACPI predefined names
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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
45 #define ACPI_CREATE_RESOURCE_TABLE
47 #include "aslcompiler.h"
48 #include "aslcompiler.y.h"
49 #include "acpredef.h"
50 #include "acnamesp.h"
53 #define _COMPONENT ACPI_COMPILER
54 ACPI_MODULE_NAME ("aslpredef")
57 /* Local prototypes */
59 static void
60 ApCheckForUnexpectedReturnValue (
61 ACPI_PARSE_OBJECT *Op,
62 ASL_METHOD_INFO *MethodInfo);
64 static UINT32
65 ApCheckForSpecialName (
66 ACPI_PARSE_OBJECT *Op,
67 char *Name);
70 /*******************************************************************************
72 * FUNCTION: ApCheckForPredefinedMethod
74 * PARAMETERS: Op - A parse node of type "METHOD".
75 * MethodInfo - Saved info about this method
77 * RETURN: None
79 * DESCRIPTION: If method is a predefined name, check that the number of
80 * arguments and the return type (returns a value or not)
81 * is correct.
83 ******************************************************************************/
85 BOOLEAN
86 ApCheckForPredefinedMethod (
87 ACPI_PARSE_OBJECT *Op,
88 ASL_METHOD_INFO *MethodInfo)
90 UINT32 Index;
91 UINT32 RequiredArgCount;
92 const ACPI_PREDEFINED_INFO *ThisName;
95 /* Check for a match against the predefined name list */
97 Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
99 switch (Index)
101 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
102 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
103 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
105 /* Just return, nothing to do */
106 return (FALSE);
109 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
111 Gbl_ReservedMethods++;
113 /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
115 if (MethodInfo->NumArguments != 0)
117 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
119 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
120 MsgBuffer);
122 break;
125 default:
127 * Matched a predefined method name - validate the ASL-defined
128 * argument count against the ACPI specification.
130 * Some methods are allowed to have a "minimum" number of args
131 * (_SCP) because their definition in ACPI has changed over time.
133 Gbl_ReservedMethods++;
134 ThisName = &AcpiGbl_PredefinedMethods[Index];
135 RequiredArgCount = METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList);
137 if (MethodInfo->NumArguments != RequiredArgCount)
139 sprintf (MsgBuffer, "%4.4s requires %u",
140 ThisName->Info.Name, RequiredArgCount);
142 if (MethodInfo->NumArguments < RequiredArgCount)
144 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
145 MsgBuffer);
147 else if ((MethodInfo->NumArguments > RequiredArgCount) &&
148 !(ThisName->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
150 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
151 MsgBuffer);
156 * Check if method returns no value, but the predefined name is
157 * required to return a value
159 if (MethodInfo->NumReturnNoValue &&
160 ThisName->Info.ExpectedBtypes)
162 AcpiUtGetExpectedReturnTypes (StringBuffer,
163 ThisName->Info.ExpectedBtypes);
165 sprintf (MsgBuffer, "%s required for %4.4s",
166 StringBuffer, ThisName->Info.Name);
168 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
169 MsgBuffer);
171 break;
174 return (TRUE);
178 /*******************************************************************************
180 * FUNCTION: ApCheckForUnexpectedReturnValue
182 * PARAMETERS: Op - A parse node of type "RETURN".
183 * MethodInfo - Saved info about this method
185 * RETURN: None
187 * DESCRIPTION: Check for an unexpected return value from a predefined method.
188 * Invoked for predefined methods that are defined to not return
189 * any value. If there is a return value, issue a remark, since
190 * the ASL writer may be confused as to the method definition
191 * and/or functionality.
193 * Note: We ignore all return values of "Zero", since this is what a standalone
194 * Return() statement will always generate -- so we ignore it here --
195 * i.e., there is no difference between Return() and Return(Zero).
196 * Also, a null Return() will be disassembled to return(Zero) -- so, we
197 * don't want to generate extraneous remarks/warnings for a disassembled
198 * ASL file.
200 ******************************************************************************/
202 static void
203 ApCheckForUnexpectedReturnValue (
204 ACPI_PARSE_OBJECT *Op,
205 ASL_METHOD_INFO *MethodInfo)
207 ACPI_PARSE_OBJECT *ReturnValueOp;
210 /* Ignore Return() and Return(Zero) (they are the same) */
212 ReturnValueOp = Op->Asl.Child;
213 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
215 return;
218 /* We have a valid return value, but the reserved name did not expect it */
220 AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
221 Op, MethodInfo->Op->Asl.ExternalName);
225 /*******************************************************************************
227 * FUNCTION: ApCheckPredefinedReturnValue
229 * PARAMETERS: Op - A parse node of type "RETURN".
230 * MethodInfo - Saved info about this method
232 * RETURN: None
234 * DESCRIPTION: If method is a predefined name, attempt to validate the return
235 * value. Only "static" types can be validated - a simple return
236 * of an integer/string/buffer/package or a named reference to
237 * a static object. Values such as a Localx or Argx or a control
238 * method invocation are not checked. Issue a warning if there is
239 * a valid return value, but the reserved method defines no
240 * return value.
242 ******************************************************************************/
244 void
245 ApCheckPredefinedReturnValue (
246 ACPI_PARSE_OBJECT *Op,
247 ASL_METHOD_INFO *MethodInfo)
249 UINT32 Index;
250 ACPI_PARSE_OBJECT *ReturnValueOp;
251 const ACPI_PREDEFINED_INFO *ThisName;
254 /* Check parent method for a match against the predefined name list */
256 Index = ApCheckForPredefinedName (MethodInfo->Op,
257 MethodInfo->Op->Asl.NameSeg);
259 switch (Index)
261 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
263 /* No return value expected, warn if there is one */
265 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
266 return;
268 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
269 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
270 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
272 /* Just return, nothing to do */
273 return;
275 default: /* A standard predefined ACPI name */
277 ThisName = &AcpiGbl_PredefinedMethods[Index];
278 if (!ThisName->Info.ExpectedBtypes)
280 /* No return value expected, warn if there is one */
282 ApCheckForUnexpectedReturnValue (Op, MethodInfo);
283 return;
286 /* Get the object returned, it is the next argument */
288 ReturnValueOp = Op->Asl.Child;
289 switch (ReturnValueOp->Asl.ParseOpcode)
291 case PARSEOP_ZERO:
292 case PARSEOP_ONE:
293 case PARSEOP_ONES:
294 case PARSEOP_INTEGER:
295 case PARSEOP_STRING_LITERAL:
296 case PARSEOP_BUFFER:
297 case PARSEOP_PACKAGE:
299 /* Static data return object - check against expected type */
301 ApCheckObjectType (ThisName->Info.Name, ReturnValueOp,
302 ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
304 /* For packages, check the individual package elements */
306 if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_PACKAGE)
308 ApCheckPackage (ReturnValueOp, ThisName);
310 break;
312 default:
314 * All other ops are very difficult or impossible to typecheck at
315 * compile time. These include all Localx, Argx, and method
316 * invocations. Also, NAMESEG and NAMESTRING because the type of
317 * any named object can be changed at runtime (for example,
318 * CopyObject will change the type of the target object.)
320 break;
326 /*******************************************************************************
328 * FUNCTION: ApCheckForPredefinedObject
330 * PARAMETERS: Op - A parse node
331 * Name - The ACPI name to be checked
333 * RETURN: None
335 * DESCRIPTION: Check for a predefined name for a static object (created via
336 * the ASL Name operator). If it is a predefined ACPI name, ensure
337 * that the name does not require any arguments (which would
338 * require a control method implemenation of the name), and that
339 * the type of the object is one of the expected types for the
340 * predefined name.
342 ******************************************************************************/
344 void
345 ApCheckForPredefinedObject (
346 ACPI_PARSE_OBJECT *Op,
347 char *Name)
349 UINT32 Index;
350 ACPI_PARSE_OBJECT *ObjectOp;
351 const ACPI_PREDEFINED_INFO *ThisName;
355 * Check for a real predefined name -- not a resource descriptor name
356 * or a predefined scope name
358 Index = ApCheckForPredefinedName (Op, Name);
360 switch (Index)
362 case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
363 case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
364 case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
366 /* Nothing to do */
367 return;
369 case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
372 * These names must be control methods, by definition in ACPI spec.
373 * Also because they are defined to return no value. None of them
374 * require any arguments.
376 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
377 "with zero arguments");
378 return;
380 default:
382 break;
385 /* A standard predefined ACPI name */
388 * If this predefined name requires input arguments, then
389 * it must be implemented as a control method
391 ThisName = &AcpiGbl_PredefinedMethods[Index];
392 if (METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList) > 0)
394 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
395 "with arguments");
396 return;
400 * If no return value is expected from this predefined name, then
401 * it follows that it must be implemented as a control method
402 * (with zero args, because the args > 0 case was handled above)
403 * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
405 if (!ThisName->Info.ExpectedBtypes)
407 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
408 "with zero arguments");
409 return;
412 /* Typecheck the actual object, it is the next argument */
414 ObjectOp = Op->Asl.Child->Asl.Next;
415 ApCheckObjectType (ThisName->Info.Name, Op->Asl.Child->Asl.Next,
416 ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
418 /* For packages, check the individual package elements */
420 if (ObjectOp->Asl.ParseOpcode == PARSEOP_PACKAGE)
422 ApCheckPackage (ObjectOp, ThisName);
427 /*******************************************************************************
429 * FUNCTION: ApCheckForPredefinedName
431 * PARAMETERS: Op - A parse node
432 * Name - NameSeg to check
434 * RETURN: None
436 * DESCRIPTION: Check a NameSeg against the reserved list.
438 ******************************************************************************/
440 UINT32
441 ApCheckForPredefinedName (
442 ACPI_PARSE_OBJECT *Op,
443 char *Name)
445 UINT32 i;
446 const ACPI_PREDEFINED_INFO *ThisName;
449 if (Name[0] == 0)
451 AcpiOsPrintf ("Found a null name, external = %s\n",
452 Op->Asl.ExternalName);
455 /* All reserved names are prefixed with a single underscore */
457 if (Name[0] != '_')
459 return (ACPI_NOT_RESERVED_NAME);
462 /* Check for a standard predefined method name */
464 ThisName = AcpiGbl_PredefinedMethods;
465 for (i = 0; ThisName->Info.Name[0]; i++)
467 if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
469 /* Return index into predefined array */
470 return (i);
473 ThisName++; /* Does not account for extra package data, but is OK */
476 /* Check for resource names and predefined scope names */
478 ThisName = AcpiGbl_ResourceNames;
479 while (ThisName->Info.Name[0])
481 if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
483 return (ACPI_PREDEFINED_NAME);
486 ThisName++;
489 ThisName = AcpiGbl_ScopeNames;
490 while (ThisName->Info.Name[0])
492 if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
494 return (ACPI_PREDEFINED_NAME);
497 ThisName++;
500 /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
502 return (ApCheckForSpecialName (Op, Name));
506 /*******************************************************************************
508 * FUNCTION: ApCheckForSpecialName
510 * PARAMETERS: Op - A parse node
511 * Name - NameSeg to check
513 * RETURN: None
515 * DESCRIPTION: Check for the "special" predefined names -
516 * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
518 ******************************************************************************/
520 static UINT32
521 ApCheckForSpecialName (
522 ACPI_PARSE_OBJECT *Op,
523 char *Name)
527 * Check for the "special" predefined names. We already know that the
528 * first character is an underscore.
529 * GPE: _Lxx
530 * GPE: _Exx
531 * GPE: _Wxx
532 * EC: _Qxx
534 if ((Name[1] == 'L') ||
535 (Name[1] == 'E') ||
536 (Name[1] == 'W') ||
537 (Name[1] == 'Q'))
539 /* The next two characters must be hex digits */
541 if ((isxdigit ((int) Name[2])) &&
542 (isxdigit ((int) Name[3])))
544 return (ACPI_EVENT_RESERVED_NAME);
548 /* Check for the names reserved for the compiler itself: _T_x */
550 else if ((Op->Asl.ExternalName[1] == 'T') &&
551 (Op->Asl.ExternalName[2] == '_'))
553 /* Ignore if actually emitted by the compiler */
555 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
557 return (ACPI_NOT_RESERVED_NAME);
561 * Was not actually emitted by the compiler. This is a special case,
562 * however. If the ASL code being compiled was the result of a
563 * dissasembly, it may possibly contain valid compiler-emitted names
564 * of the form "_T_x". We don't want to issue an error or even a
565 * warning and force the user to manually change the names. So, we
566 * will issue a remark instead.
568 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
569 return (ACPI_COMPILER_RESERVED_NAME);
573 * The name didn't match any of the known predefined names. Flag it as a
574 * warning, since the entire namespace starting with an underscore is
575 * reserved by the ACPI spec.
577 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
578 Op->Asl.ExternalName);
580 return (ACPI_NOT_RESERVED_NAME);
584 /*******************************************************************************
586 * FUNCTION: ApCheckObjectType
588 * PARAMETERS: PredefinedName - Name of the predefined object we are checking
589 * Op - Current parse node
590 * ExpectedBtypes - Bitmap of expected return type(s)
591 * PackageIndex - Index of object within parent package (if
592 * applicable - ACPI_NOT_PACKAGE_ELEMENT
593 * otherwise)
595 * RETURN: None
597 * DESCRIPTION: Check if the object type is one of the types that is expected
598 * by the predefined name. Only a limited number of object types
599 * can be returned by the predefined names.
601 ******************************************************************************/
603 ACPI_STATUS
604 ApCheckObjectType (
605 const char *PredefinedName,
606 ACPI_PARSE_OBJECT *Op,
607 UINT32 ExpectedBtypes,
608 UINT32 PackageIndex)
610 UINT32 ReturnBtype;
611 char *TypeName;
614 if (!Op)
616 return (AE_TYPE);
619 /* Map the parse opcode to a bitmapped return type (RTYPE) */
621 switch (Op->Asl.ParseOpcode)
623 case PARSEOP_ZERO:
624 case PARSEOP_ONE:
625 case PARSEOP_ONES:
626 case PARSEOP_INTEGER:
628 ReturnBtype = ACPI_RTYPE_INTEGER;
629 TypeName = "Integer";
630 break;
632 case PARSEOP_STRING_LITERAL:
634 ReturnBtype = ACPI_RTYPE_STRING;
635 TypeName = "String";
636 break;
638 case PARSEOP_BUFFER:
640 ReturnBtype = ACPI_RTYPE_BUFFER;
641 TypeName = "Buffer";
642 break;
644 case PARSEOP_PACKAGE:
645 case PARSEOP_VAR_PACKAGE:
647 ReturnBtype = ACPI_RTYPE_PACKAGE;
648 TypeName = "Package";
649 break;
651 case PARSEOP_NAMESEG:
652 case PARSEOP_NAMESTRING:
654 * Ignore any named references within a package object.
656 * For Package objects, references are allowed instead of any of the
657 * standard data types (Integer/String/Buffer/Package). These
658 * references are resolved at runtime. NAMESEG and NAMESTRING are
659 * impossible to typecheck at compile time because the type of
660 * any named object can be changed at runtime (for example,
661 * CopyObject will change the type of the target object).
663 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
665 return (AE_OK);
668 ReturnBtype = ACPI_RTYPE_REFERENCE;
669 TypeName = "Reference";
670 break;
672 default:
674 /* Not one of the supported object types */
676 TypeName = UtGetOpName (Op->Asl.ParseOpcode);
677 goto TypeErrorExit;
680 /* Exit if the object is one of the expected types */
682 if (ReturnBtype & ExpectedBtypes)
684 return (AE_OK);
688 TypeErrorExit:
690 /* Format the expected types and emit an error message */
692 AcpiUtGetExpectedReturnTypes (StringBuffer, ExpectedBtypes);
694 if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
696 sprintf (MsgBuffer, "%4.4s: found %s, %s required",
697 PredefinedName, TypeName, StringBuffer);
699 else
701 sprintf (MsgBuffer, "%4.4s: found %s at index %u, %s required",
702 PredefinedName, TypeName, PackageIndex, StringBuffer);
705 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, MsgBuffer);
706 return (AE_TYPE);
710 /*******************************************************************************
712 * FUNCTION: ApDisplayReservedNames
714 * PARAMETERS: None
716 * RETURN: None
718 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
719 * resource descriptor names.
721 ******************************************************************************/
723 void
724 ApDisplayReservedNames (
725 void)
727 const ACPI_PREDEFINED_INFO *ThisName;
728 UINT32 Count;
729 UINT32 NumTypes;
733 * Predefined names/methods
735 printf ("\nPredefined Name Information\n\n");
737 Count = 0;
738 ThisName = AcpiGbl_PredefinedMethods;
739 while (ThisName->Info.Name[0])
741 AcpiUtDisplayPredefinedMethod (MsgBuffer, ThisName, FALSE);
742 Count++;
743 ThisName = AcpiUtGetNextPredefinedMethod (ThisName);
746 printf ("%u Predefined Names are recognized\n", Count);
749 * Resource Descriptor names
751 printf ("\nPredefined Names for Resource Descriptor Fields\n\n");
753 Count = 0;
754 ThisName = AcpiGbl_ResourceNames;
755 while (ThisName->Info.Name[0])
757 NumTypes = AcpiUtGetResourceBitWidth (MsgBuffer,
758 ThisName->Info.ArgumentList);
760 printf ("%4.4s Field is %s bits wide%s\n",
761 ThisName->Info.Name, MsgBuffer,
762 (NumTypes > 1) ? " (depending on descriptor type)" : "");
764 Count++;
765 ThisName++;
768 printf ("%u Resource Descriptor Field Names are recognized\n", Count);
771 * Predefined scope names
773 printf ("\nPredefined Scope/Device Names (automatically created at root)\n\n");
775 ThisName = AcpiGbl_ScopeNames;
776 while (ThisName->Info.Name[0])
778 printf ("%4.4s Scope/Device\n", ThisName->Info.Name);
779 ThisName++;