]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/acpica/lib-acpi/src/acpica/compiler/aslpredef.c
update
[l4.git] / l4 / pkg / acpica / lib-acpi / src / acpica / compiler / aslpredef.c
1 /******************************************************************************
2  *
3  * Module Name: aslpredef - support for ACPI predefined names
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2012, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116 #define ACPI_CREATE_PREDEFINED_TABLE
117
118 #include "aslcompiler.h"
119 #include "aslcompiler.y.h"
120 #include "acpredef.h"
121
122
123 #define _COMPONENT          ACPI_COMPILER
124         ACPI_MODULE_NAME    ("aslpredef")
125
126
127 /* Local prototypes */
128
129 static void
130 ApCheckForUnexpectedReturnValue (
131     ACPI_PARSE_OBJECT       *Op,
132     ASL_METHOD_INFO         *MethodInfo);
133
134 static UINT32
135 ApCheckForSpecialName (
136     ACPI_PARSE_OBJECT       *Op,
137     char                    *Name);
138
139 static void
140 ApCheckObjectType (
141     ACPI_PARSE_OBJECT       *Op,
142     UINT32                  ExpectedBtypes);
143
144 static void
145 ApGetExpectedTypes (
146     char                    *Buffer,
147     UINT32                  ExpectedBtypes);
148
149
150 /*
151  * Names for the types that can be returned by the predefined objects.
152  * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
153  */
154 static const char   *AcpiRtypeNames[] =
155 {
156     "/Integer",
157     "/String",
158     "/Buffer",
159     "/Package",
160     "/Reference",
161 };
162
163 /*
164  * Predefined names for use in Resource Descriptors. These names do not
165  * appear in the global Predefined Name table (since these names never
166  * appear in actual AML byte code, only in the original ASL)
167  */
168 static const ACPI_PREDEFINED_INFO      ResourceNames[] = {
169     {{"_ALN",     0,      0}},
170     {{"_ASI",     0,      0}},
171     {{"_ASZ",     0,      0}},
172     {{"_ATT",     0,      0}},
173     {{"_BAS",     0,      0}},
174     {{"_BM_",     0,      0}},
175     {{"_DBT",     0,      0}},  /* Acpi 5.0 */
176     {{"_DEC",     0,      0}},
177     {{"_DPL",     0,      0}},  /* Acpi 5.0 */
178     {{"_DRS",     0,      0}},  /* Acpi 5.0 */
179     {{"_END",     0,      0}},  /* Acpi 5.0 */
180     {{"_FLC",     0,      0}},  /* Acpi 5.0 */
181     {{"_GRA",     0,      0}},
182     {{"_HE_",     0,      0}},
183     {{"_INT",     0,      0}},
184     {{"_IOR",     0,      0}},  /* Acpi 5.0 */
185     {{"_LEN",     0,      0}},
186     {{"_LIN",     0,      0}},  /* Acpi 5.0 */
187     {{"_LL_",     0,      0}},
188     {{"_MAF",     0,      0}},
189     {{"_MAX",     0,      0}},
190     {{"_MEM",     0,      0}},
191     {{"_MIF",     0,      0}},
192     {{"_MIN",     0,      0}},
193     {{"_MOD",     0,      0}},  /* Acpi 5.0 */
194     {{"_MTP",     0,      0}},
195     {{"_PAR",     0,      0}},  /* Acpi 5.0 */
196     {{"_PHA",     0,      0}},  /* Acpi 5.0 */
197     {{"_PIN",     0,      0}},  /* Acpi 5.0 */
198     {{"_PPI",     0,      0}},  /* Acpi 5.0 */
199     {{"_POL",     0,      0}},  /* Acpi 5.0 */
200     {{"_RBO",     0,      0}},
201     {{"_RBW",     0,      0}},
202     {{"_RNG",     0,      0}},
203     {{"_RT_",     0,      0}},  /* Acpi 3.0 */
204     {{"_RW_",     0,      0}},
205     {{"_RXL",     0,      0}},  /* Acpi 5.0 */
206     {{"_SHR",     0,      0}},
207     {{"_SIZ",     0,      0}},
208     {{"_SLV",     0,      0}},  /* Acpi 5.0 */
209     {{"_SPE",     0,      0}},  /* Acpi 5.0 */
210     {{"_STB",     0,      0}},  /* Acpi 5.0 */
211     {{"_TRA",     0,      0}},
212     {{"_TRS",     0,      0}},
213     {{"_TSF",     0,      0}},  /* Acpi 3.0 */
214     {{"_TTP",     0,      0}},
215     {{"_TXL",     0,      0}},  /* Acpi 5.0 */
216     {{"_TYP",     0,      0}},
217     {{"_VEN",     0,      0}},  /* Acpi 5.0 */
218     {{{0,0,0,0},  0,      0}}   /* Table terminator */
219 };
220
221 static const ACPI_PREDEFINED_INFO      ScopeNames[] = {
222     {{"_SB_",     0,      0}},
223     {{"_SI_",     0,      0}},
224     {{"_TZ_",     0,      0}},
225     {{{0,0,0,0},  0,      0}}   /* Table terminator */
226 };
227
228
229 /*******************************************************************************
230  *
231  * FUNCTION:    ApCheckForPredefinedMethod
232  *
233  * PARAMETERS:  Op              - A parse node of type "METHOD".
234  *              MethodInfo      - Saved info about this method
235  *
236  * RETURN:      None
237  *
238  * DESCRIPTION: If method is a predefined name, check that the number of
239  *              arguments and the return type (returns a value or not)
240  *              is correct.
241  *
242  ******************************************************************************/
243
244 BOOLEAN
245 ApCheckForPredefinedMethod (
246     ACPI_PARSE_OBJECT       *Op,
247     ASL_METHOD_INFO         *MethodInfo)
248 {
249     UINT32                  Index;
250     UINT32                  RequiredArgsCurrent;
251     UINT32                  RequiredArgsOld;
252
253
254     /* Check for a match against the predefined name list */
255
256     Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
257
258     switch (Index)
259     {
260     case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
261     case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
262     case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
263
264         /* Just return, nothing to do */
265         return (FALSE);
266
267
268     case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
269
270         Gbl_ReservedMethods++;
271
272         /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
273
274         if (MethodInfo->NumArguments != 0)
275         {
276             sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
277
278             AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
279                 MsgBuffer);
280         }
281         break;
282
283
284     default:
285         /*
286          * Matched a predefined method name
287          *
288          * Validate the ASL-defined argument count. Allow two different legal
289          * arg counts.
290          */
291         Gbl_ReservedMethods++;
292
293         RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
294         RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
295
296         if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
297             (MethodInfo->NumArguments != RequiredArgsOld))
298         {
299             sprintf (MsgBuffer, "%4.4s requires %u",
300                 PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
301
302             if (MethodInfo->NumArguments > RequiredArgsCurrent)
303             {
304                 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
305                     MsgBuffer);
306             }
307             else
308             {
309                 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
310                     MsgBuffer);
311             }
312         }
313
314         /*
315          * Check if method returns no value, but the predefined name is
316          * required to return a value
317          */
318         if (MethodInfo->NumReturnNoValue &&
319             PredefinedNames[Index].Info.ExpectedBtypes)
320         {
321             ApGetExpectedTypes (StringBuffer,
322                 PredefinedNames[Index].Info.ExpectedBtypes);
323
324             sprintf (MsgBuffer, "%s required for %4.4s",
325                 StringBuffer, PredefinedNames[Index].Info.Name);
326
327             AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
328                 MsgBuffer);
329         }
330         break;
331     }
332
333     return (TRUE);
334 }
335
336
337 /*******************************************************************************
338  *
339  * FUNCTION:    ApCheckForUnexpectedReturnValue
340  *
341  * PARAMETERS:  Op              - A parse node of type "RETURN".
342  *              MethodInfo      - Saved info about this method
343  *
344  * RETURN:      None
345  *
346  * DESCRIPTION: Check for an unexpected return value from a predefined method.
347  *              Invoked for predefined methods that are defined to not return
348  *              any value. If there is a return value, issue a remark, since
349  *              the ASL writer may be confused as to the method definition
350  *              and/or functionality.
351  *
352  * Note: We ignore all return values of "Zero", since this is what a standalone
353  *       Return() statement will always generate -- so we ignore it here --
354  *       i.e., there is no difference between Return() and Return(Zero).
355  *       Also, a null Return() will be disassembled to return(Zero) -- so, we
356  *       don't want to generate extraneous remarks/warnings for a disassembled
357  *       ASL file.
358  *
359  ******************************************************************************/
360
361 static void
362 ApCheckForUnexpectedReturnValue (
363     ACPI_PARSE_OBJECT       *Op,
364     ASL_METHOD_INFO         *MethodInfo)
365 {
366     ACPI_PARSE_OBJECT       *ReturnValueOp;
367
368
369     /* Ignore Return() and Return(Zero) (they are the same) */
370
371     ReturnValueOp = Op->Asl.Child;
372     if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
373     {
374         return;
375     }
376
377     /* We have a valid return value, but the reserved name did not expect it */
378
379     AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
380         Op, MethodInfo->Op->Asl.ExternalName);
381 }
382
383
384 /*******************************************************************************
385  *
386  * FUNCTION:    ApCheckPredefinedReturnValue
387  *
388  * PARAMETERS:  Op              - A parse node of type "RETURN".
389  *              MethodInfo      - Saved info about this method
390  *
391  * RETURN:      None
392  *
393  * DESCRIPTION: If method is a predefined name, attempt to validate the return
394  *              value. Only "static" types can be validated - a simple return
395  *              of an integer/string/buffer/package or a named reference to
396  *              a static object. Values such as a Localx or Argx or a control
397  *              method invocation are not checked. Issue a warning if there is
398  *              a valid return value, but the reserved method defines no
399  *              return value.
400  *
401  ******************************************************************************/
402
403 void
404 ApCheckPredefinedReturnValue (
405     ACPI_PARSE_OBJECT       *Op,
406     ASL_METHOD_INFO         *MethodInfo)
407 {
408     UINT32                  Index;
409     ACPI_PARSE_OBJECT       *ReturnValueOp;
410
411
412     /* Check parent method for a match against the predefined name list */
413
414     Index = ApCheckForPredefinedName (MethodInfo->Op,
415                 MethodInfo->Op->Asl.NameSeg);
416
417     switch (Index)
418     {
419     case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
420
421         /* No return value expected, warn if there is one */
422
423         ApCheckForUnexpectedReturnValue (Op, MethodInfo);
424         return;
425
426     case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
427     case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
428     case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
429
430         /* Just return, nothing to do */
431         return;
432
433     default: /* A standard predefined ACPI name */
434
435         if (!PredefinedNames[Index].Info.ExpectedBtypes)
436         {
437             /* No return value expected, warn if there is one */
438
439             ApCheckForUnexpectedReturnValue (Op, MethodInfo);
440             return;
441         }
442
443         /* Get the object returned, it is the next argument */
444
445         ReturnValueOp = Op->Asl.Child;
446         switch (ReturnValueOp->Asl.ParseOpcode)
447         {
448         case PARSEOP_ZERO:
449         case PARSEOP_ONE:
450         case PARSEOP_ONES:
451         case PARSEOP_INTEGER:
452         case PARSEOP_STRING_LITERAL:
453         case PARSEOP_BUFFER:
454         case PARSEOP_PACKAGE:
455
456             /* Static data return object - check against expected type */
457
458             ApCheckObjectType (ReturnValueOp,
459                 PredefinedNames[Index].Info.ExpectedBtypes);
460             break;
461
462         default:
463
464             /*
465              * All other ops are very difficult or impossible to typecheck at
466              * compile time. These include all Localx, Argx, and method
467              * invocations. Also, NAMESEG and NAMESTRING because the type of
468              * any named object can be changed at runtime (for example,
469              * CopyObject will change the type of the target object.)
470              */
471             break;
472         }
473     }
474 }
475
476
477 /*******************************************************************************
478  *
479  * FUNCTION:    ApCheckForPredefinedObject
480  *
481  * PARAMETERS:  Op              - A parse node
482  *              Name            - The ACPI name to be checked
483  *
484  * RETURN:      None
485  *
486  * DESCRIPTION: Check for a predefined name for a static object (created via
487  *              the ASL Name operator). If it is a predefined ACPI name, ensure
488  *              that the name does not require any arguments (which would
489  *              require a control method implemenation of the name), and that
490  *              the type of the object is one of the expected types for the
491  *              predefined name.
492  *
493  ******************************************************************************/
494
495 void
496 ApCheckForPredefinedObject (
497     ACPI_PARSE_OBJECT       *Op,
498     char                    *Name)
499 {
500     UINT32                  Index;
501
502
503     /*
504      * Check for a real predefined name -- not a resource descriptor name
505      * or a predefined scope name
506      */
507     Index = ApCheckForPredefinedName (Op, Name);
508
509     switch (Index)
510     {
511     case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
512     case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
513     case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
514
515         /* Nothing to do */
516         return;
517
518     case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
519
520         /*
521          * These names must be control methods, by definition in ACPI spec.
522          * Also because they are defined to return no value. None of them
523          * require any arguments.
524          */
525         AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
526             "with zero arguments");
527         return;
528
529     default: /* A standard predefined ACPI name */
530
531         /*
532          * If this predefined name requires input arguments, then
533          * it must be implemented as a control method
534          */
535         if (PredefinedNames[Index].Info.ParamCount > 0)
536         {
537             AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
538                 "with arguments");
539             return;
540         }
541
542         /*
543          * If no return value is expected from this predefined name, then
544          * it follows that it must be implemented as a control method
545          * (with zero args, because the args > 0 case was handled above)
546          * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
547          */
548         if (!PredefinedNames[Index].Info.ExpectedBtypes)
549         {
550             AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
551                 "with zero arguments");
552             return;
553         }
554
555         /* Typecheck the actual object, it is the next argument */
556
557         ApCheckObjectType (Op->Asl.Child->Asl.Next,
558             PredefinedNames[Index].Info.ExpectedBtypes);
559         return;
560     }
561 }
562
563
564 /*******************************************************************************
565  *
566  * FUNCTION:    ApCheckForPredefinedName
567  *
568  * PARAMETERS:  Op              - A parse node
569  *              Name            - NameSeg to check
570  *
571  * RETURN:      None
572  *
573  * DESCRIPTION: Check a NameSeg against the reserved list.
574  *
575  ******************************************************************************/
576
577 UINT32
578 ApCheckForPredefinedName (
579     ACPI_PARSE_OBJECT       *Op,
580     char                    *Name)
581 {
582     UINT32                  i;
583
584
585     if (Name[0] == 0)
586     {
587         AcpiOsPrintf ("Found a null name, external = %s\n",
588             Op->Asl.ExternalName);
589     }
590
591     /* All reserved names are prefixed with a single underscore */
592
593     if (Name[0] != '_')
594     {
595         return (ACPI_NOT_RESERVED_NAME);
596     }
597
598     /* Check for a standard predefined method name */
599
600     for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
601     {
602         if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
603         {
604             /* Return index into predefined array */
605             return (i);
606         }
607     }
608
609     /* Check for resource names and predefined scope names */
610
611     for (i = 0; ResourceNames[i].Info.Name[0]; i++)
612     {
613         if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
614         {
615             return (ACPI_PREDEFINED_NAME);
616         }
617     }
618
619     for (i = 0; ScopeNames[i].Info.Name[0]; i++)
620     {
621         if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
622         {
623             return (ACPI_PREDEFINED_NAME);
624         }
625     }
626
627     /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
628
629     return (ApCheckForSpecialName (Op, Name));
630 }
631
632
633 /*******************************************************************************
634  *
635  * FUNCTION:    ApCheckForSpecialName
636  *
637  * PARAMETERS:  Op              - A parse node
638  *              Name            - NameSeg to check
639  *
640  * RETURN:      None
641  *
642  * DESCRIPTION: Check for the "special" predefined names -
643  *              _Lxx, _Exx, _Qxx, _Wxx, and _T_x
644  *
645  ******************************************************************************/
646
647 static UINT32
648 ApCheckForSpecialName (
649     ACPI_PARSE_OBJECT       *Op,
650     char                    *Name)
651 {
652
653     /*
654      * Check for the "special" predefined names. We already know that the
655      * first character is an underscore.
656      *   GPE:  _Lxx
657      *   GPE:  _Exx
658      *   GPE:  _Wxx
659      *   EC:   _Qxx
660      */
661     if ((Name[1] == 'L') ||
662         (Name[1] == 'E') ||
663         (Name[1] == 'W') ||
664         (Name[1] == 'Q'))
665     {
666         /* The next two characters must be hex digits */
667
668         if ((isxdigit ((int) Name[2])) &&
669             (isxdigit ((int) Name[3])))
670         {
671             return (ACPI_EVENT_RESERVED_NAME);
672         }
673     }
674
675     /* Check for the names reserved for the compiler itself: _T_x */
676
677     else if ((Op->Asl.ExternalName[1] == 'T') &&
678              (Op->Asl.ExternalName[2] == '_'))
679     {
680         /* Ignore if actually emitted by the compiler */
681
682         if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
683         {
684             return (ACPI_NOT_RESERVED_NAME);
685         }
686
687         /*
688          * Was not actually emitted by the compiler. This is a special case,
689          * however. If the ASL code being compiled was the result of a
690          * dissasembly, it may possibly contain valid compiler-emitted names
691          * of the form "_T_x". We don't want to issue an error or even a
692          * warning and force the user to manually change the names. So, we
693          * will issue a remark instead.
694          */
695         AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
696         return (ACPI_COMPILER_RESERVED_NAME);
697     }
698
699     /*
700      * The name didn't match any of the known predefined names. Flag it as a
701      * warning, since the entire namespace starting with an underscore is
702      * reserved by the ACPI spec.
703      */
704     AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
705         Op->Asl.ExternalName);
706
707     return (ACPI_NOT_RESERVED_NAME);
708 }
709
710
711 /*******************************************************************************
712  *
713  * FUNCTION:    ApCheckObjectType
714  *
715  * PARAMETERS:  Op              - Current parse node
716  *              ExpectedBtypes  - Bitmap of expected return type(s)
717  *
718  * RETURN:      None
719  *
720  * DESCRIPTION: Check if the object type is one of the types that is expected
721  *              by the predefined name. Only a limited number of object types
722  *              can be returned by the predefined names.
723  *
724  ******************************************************************************/
725
726 static void
727 ApCheckObjectType (
728     ACPI_PARSE_OBJECT       *Op,
729     UINT32                  ExpectedBtypes)
730 {
731     UINT32                  ReturnBtype;
732
733
734     switch (Op->Asl.ParseOpcode)
735     {
736     case PARSEOP_ZERO:
737     case PARSEOP_ONE:
738     case PARSEOP_ONES:
739     case PARSEOP_INTEGER:
740         ReturnBtype = ACPI_RTYPE_INTEGER;
741         break;
742
743     case PARSEOP_BUFFER:
744         ReturnBtype = ACPI_RTYPE_BUFFER;
745         break;
746
747     case PARSEOP_STRING_LITERAL:
748         ReturnBtype = ACPI_RTYPE_STRING;
749         break;
750
751     case PARSEOP_PACKAGE:
752     case PARSEOP_VAR_PACKAGE:
753         ReturnBtype = ACPI_RTYPE_PACKAGE;
754         break;
755
756     default:
757         /* Not one of the supported object types */
758
759         goto TypeErrorExit;
760     }
761
762     /* Exit if the object is one of the expected types */
763
764     if (ReturnBtype & ExpectedBtypes)
765     {
766         return;
767     }
768
769
770 TypeErrorExit:
771
772     /* Format the expected types and emit an error message */
773
774     ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
775
776     sprintf (MsgBuffer, "found %s, requires %s",
777         UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
778
779     AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
780         MsgBuffer);
781 }
782
783
784 /*******************************************************************************
785  *
786  * FUNCTION:    ApDisplayReservedNames
787  *
788  * PARAMETERS:  None
789  *
790  * RETURN:      None
791  *
792  * DESCRIPTION: Dump information about the ACPI predefined names and predefined
793  *              resource descriptor names.
794  *
795  ******************************************************************************/
796
797 void
798 ApDisplayReservedNames (
799     void)
800 {
801     const ACPI_PREDEFINED_INFO  *ThisName;
802     char                        TypeBuffer[48]; /* Room for 5 types */
803     UINT32                      Count;
804
805
806     /*
807      * Predefined names/methods
808      */
809     printf ("\nPredefined Name Information\n\n");
810
811     Count = 0;
812     ThisName = PredefinedNames;
813     while (ThisName->Info.Name[0])
814     {
815         printf ("%4.4s    Requires %u arguments, ",
816             ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
817
818         if (ThisName->Info.ExpectedBtypes)
819         {
820             ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
821             printf ("Must return: %s\n", TypeBuffer);
822         }
823         else
824         {
825             printf ("No return value\n");
826         }
827
828         /*
829          * Skip next entry in the table if this name returns a Package
830          * (next entry contains the package info)
831          */
832         if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
833         {
834             ThisName++;
835         }
836
837         Count++;
838         ThisName++;
839     }
840
841     printf ("%u Predefined Names are recognized\n", Count);
842
843     /*
844      * Resource Descriptor names
845      */
846     printf ("\nResource Descriptor Predefined Names\n\n");
847
848     Count = 0;
849     ThisName = ResourceNames;
850     while (ThisName->Info.Name[0])
851     {
852         printf ("%4.4s    Resource Descriptor\n", ThisName->Info.Name);
853         Count++;
854         ThisName++;
855     }
856
857     printf ("%u Resource Descriptor Names are recognized\n", Count);
858
859     /*
860      * Predefined scope names
861      */
862     printf ("\nPredefined Scope Names\n\n");
863
864     ThisName = ScopeNames;
865     while (ThisName->Info.Name[0])
866     {
867         printf ("%4.4s    Scope\n", ThisName->Info.Name);
868         ThisName++;
869     }
870 }
871
872
873 /*******************************************************************************
874  *
875  * FUNCTION:    ApGetExpectedTypes
876  *
877  * PARAMETERS:  Buffer              - Where the formatted string is returned
878  *              ExpectedBTypes      - Bitfield of expected data types
879  *
880  * RETURN:      None, formatted string
881  *
882  * DESCRIPTION: Format the expected object types into a printable string.
883  *
884  ******************************************************************************/
885
886 static void
887 ApGetExpectedTypes (
888     char                        *Buffer,
889     UINT32                      ExpectedBtypes)
890 {
891     UINT32                      ThisRtype;
892     UINT32                      i;
893     UINT32                      j;
894
895
896     j = 1;
897     Buffer[0] = 0;
898     ThisRtype = ACPI_RTYPE_INTEGER;
899
900     for (i = 0; i < ACPI_NUM_RTYPES; i++)
901     {
902         /* If one of the expected types, concatenate the name of this type */
903
904         if (ExpectedBtypes & ThisRtype)
905         {
906             ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
907             j = 0;              /* Use name separator from now on */
908         }
909         ThisRtype <<= 1;    /* Next Rtype */
910     }
911 }