xref: /illumos-gate/usr/src/cmd/acpi/iasl/aslpredef.c (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
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 - 2018, 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  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #define ACPI_CREATE_PREDEFINED_TABLE
153 #define ACPI_CREATE_RESOURCE_TABLE
154 
155 #include "aslcompiler.h"
156 #include "aslcompiler.y.h"
157 #include "acpredef.h"
158 #include "acnamesp.h"
159 
160 
161 #define _COMPONENT          ACPI_COMPILER
162         ACPI_MODULE_NAME    ("aslpredef")
163 
164 
165 /* Local prototypes */
166 
167 static void
168 ApCheckForUnexpectedReturnValue (
169     ACPI_PARSE_OBJECT       *Op,
170     ASL_METHOD_INFO         *MethodInfo);
171 
172 static UINT32
173 ApCheckForSpecialName (
174     ACPI_PARSE_OBJECT       *Op,
175     char                    *Name);
176 
177 
178 /*******************************************************************************
179  *
180  * FUNCTION:    ApCheckForPredefinedMethod
181  *
182  * PARAMETERS:  Op              - A parse node of type "METHOD".
183  *              MethodInfo      - Saved info about this method
184  *
185  * RETURN:      None
186  *
187  * DESCRIPTION: If method is a predefined name, check that the number of
188  *              arguments and the return type (returns a value or not)
189  *              is correct.
190  *
191  ******************************************************************************/
192 
193 BOOLEAN
194 ApCheckForPredefinedMethod (
195     ACPI_PARSE_OBJECT       *Op,
196     ASL_METHOD_INFO         *MethodInfo)
197 {
198     UINT32                      Index;
199     UINT32                      RequiredArgCount;
200     const ACPI_PREDEFINED_INFO  *ThisName;
201 
202 
203     /* Check for a match against the predefined name list */
204 
205     Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
206 
207     switch (Index)
208     {
209     case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
210     case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
211     case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
212 
213         /* Just return, nothing to do */
214         return (FALSE);
215 
216 
217     case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
218 
219         Gbl_ReservedMethods++;
220 
221         /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
222 
223         if (MethodInfo->NumArguments != 0)
224         {
225             sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
226 
227             AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
228                 MsgBuffer);
229         }
230         break;
231 
232 
233     default:
234         /*
235          * Matched a predefined method name - validate the ASL-defined
236          * argument count against the ACPI specification.
237          *
238          * Some methods are allowed to have a "minimum" number of args
239          * (_SCP) because their definition in ACPI has changed over time.
240          */
241         Gbl_ReservedMethods++;
242         ThisName = &AcpiGbl_PredefinedMethods[Index];
243         RequiredArgCount = METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList);
244 
245         if (MethodInfo->NumArguments != RequiredArgCount)
246         {
247             sprintf (MsgBuffer, "%4.4s requires %u",
248                 ThisName->Info.Name, RequiredArgCount);
249 
250             if (MethodInfo->NumArguments < RequiredArgCount)
251             {
252                 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
253                     MsgBuffer);
254             }
255             else if ((MethodInfo->NumArguments > RequiredArgCount) &&
256                 !(ThisName->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
257             {
258                 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
259                     MsgBuffer);
260             }
261         }
262 
263         /*
264          * Check if method returns no value, but the predefined name is
265          * required to return a value
266          */
267         if (MethodInfo->NumReturnNoValue &&
268             ThisName->Info.ExpectedBtypes)
269         {
270             AcpiUtGetExpectedReturnTypes (StringBuffer,
271                 ThisName->Info.ExpectedBtypes);
272 
273             sprintf (MsgBuffer, "%s required for %4.4s",
274                 StringBuffer, ThisName->Info.Name);
275 
276             AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
277                 MsgBuffer);
278         }
279         break;
280     }
281 
282     return (TRUE);
283 }
284 
285 
286 /*******************************************************************************
287  *
288  * FUNCTION:    ApCheckForUnexpectedReturnValue
289  *
290  * PARAMETERS:  Op              - A parse node of type "RETURN".
291  *              MethodInfo      - Saved info about this method
292  *
293  * RETURN:      None
294  *
295  * DESCRIPTION: Check for an unexpected return value from a predefined method.
296  *              Invoked for predefined methods that are defined to not return
297  *              any value. If there is a return value, issue a remark, since
298  *              the ASL writer may be confused as to the method definition
299  *              and/or functionality.
300  *
301  * Note: We ignore all return values of "Zero", since this is what a standalone
302  *       Return() statement will always generate -- so we ignore it here --
303  *       i.e., there is no difference between Return() and Return(Zero).
304  *       Also, a null Return() will be disassembled to return(Zero) -- so, we
305  *       don't want to generate extraneous remarks/warnings for a disassembled
306  *       ASL file.
307  *
308  ******************************************************************************/
309 
310 static void
311 ApCheckForUnexpectedReturnValue (
312     ACPI_PARSE_OBJECT       *Op,
313     ASL_METHOD_INFO         *MethodInfo)
314 {
315     ACPI_PARSE_OBJECT       *ReturnValueOp;
316 
317 
318     /* Ignore Return() and Return(Zero) (they are the same) */
319 
320     ReturnValueOp = Op->Asl.Child;
321     if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
322     {
323         return;
324     }
325 
326     /* We have a valid return value, but the reserved name did not expect it */
327 
328     AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
329         Op, MethodInfo->Op->Asl.ExternalName);
330 }
331 
332 
333 /*******************************************************************************
334  *
335  * FUNCTION:    ApCheckPredefinedReturnValue
336  *
337  * PARAMETERS:  Op              - A parse node of type "RETURN".
338  *              MethodInfo      - Saved info about this method
339  *
340  * RETURN:      None
341  *
342  * DESCRIPTION: If method is a predefined name, attempt to validate the return
343  *              value. Only "static" types can be validated - a simple return
344  *              of an integer/string/buffer/package or a named reference to
345  *              a static object. Values such as a Localx or Argx or a control
346  *              method invocation are not checked. Issue a warning if there is
347  *              a valid return value, but the reserved method defines no
348  *              return value.
349  *
350  ******************************************************************************/
351 
352 void
353 ApCheckPredefinedReturnValue (
354     ACPI_PARSE_OBJECT       *Op,
355     ASL_METHOD_INFO         *MethodInfo)
356 {
357     UINT32                      Index;
358     ACPI_PARSE_OBJECT           *ReturnValueOp;
359     const ACPI_PREDEFINED_INFO  *ThisName;
360 
361 
362     /*
363      * Check parent method for a match against the predefined name list.
364      *
365      * Note: Disable compiler errors/warnings because any errors will be
366      * caught when analyzing the parent method. Eliminates duplicate errors.
367      */
368     Gbl_AllExceptionsDisabled = TRUE;
369     Index = ApCheckForPredefinedName (MethodInfo->Op,
370         MethodInfo->Op->Asl.NameSeg);
371     Gbl_AllExceptionsDisabled = FALSE;
372 
373     switch (Index)
374     {
375     case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
376 
377         /* No return value expected, warn if there is one */
378 
379         ApCheckForUnexpectedReturnValue (Op, MethodInfo);
380         return;
381 
382     case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
383     case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
384     case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
385 
386         /* Just return, nothing to do */
387         return;
388 
389     default: /* A standard predefined ACPI name */
390 
391         ThisName = &AcpiGbl_PredefinedMethods[Index];
392         if (!ThisName->Info.ExpectedBtypes)
393         {
394             /* No return value expected, warn if there is one */
395 
396             ApCheckForUnexpectedReturnValue (Op, MethodInfo);
397             return;
398         }
399 
400         /* Get the object returned, it is the next argument */
401 
402         ReturnValueOp = Op->Asl.Child;
403         switch (ReturnValueOp->Asl.ParseOpcode)
404         {
405         case PARSEOP_ZERO:
406         case PARSEOP_ONE:
407         case PARSEOP_ONES:
408         case PARSEOP_INTEGER:
409         case PARSEOP_STRING_LITERAL:
410         case PARSEOP_BUFFER:
411         case PARSEOP_PACKAGE:
412 
413             /* Static data return object - check against expected type */
414 
415             ApCheckObjectType (ThisName->Info.Name, ReturnValueOp,
416                 ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
417 
418             /* For packages, check the individual package elements */
419 
420             if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_PACKAGE)
421             {
422                 ApCheckPackage (ReturnValueOp, ThisName);
423             }
424             break;
425 
426         default:
427             /*
428              * All other ops are very difficult or impossible to typecheck at
429              * compile time. These include all Localx, Argx, and method
430              * invocations. Also, NAMESEG and NAMESTRING because the type of
431              * any named object can be changed at runtime (for example,
432              * CopyObject will change the type of the target object.)
433              */
434             break;
435         }
436     }
437 }
438 
439 
440 /*******************************************************************************
441  *
442  * FUNCTION:    ApCheckForPredefinedObject
443  *
444  * PARAMETERS:  Op              - A parse node
445  *              Name            - The ACPI name to be checked
446  *
447  * RETURN:      None
448  *
449  * DESCRIPTION: Check for a predefined name for a static object (created via
450  *              the ASL Name operator). If it is a predefined ACPI name, ensure
451  *              that the name does not require any arguments (which would
452  *              require a control method implemenation of the name), and that
453  *              the type of the object is one of the expected types for the
454  *              predefined name.
455  *
456  ******************************************************************************/
457 
458 void
459 ApCheckForPredefinedObject (
460     ACPI_PARSE_OBJECT       *Op,
461     char                    *Name)
462 {
463     UINT32                      Index;
464     ACPI_PARSE_OBJECT           *ObjectOp;
465     const ACPI_PREDEFINED_INFO  *ThisName;
466 
467 
468     /*
469      * Check for a real predefined name -- not a resource descriptor name
470      * or a predefined scope name
471      */
472     Index = ApCheckForPredefinedName (Op, Name);
473 
474     switch (Index)
475     {
476     case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
477     case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
478     case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
479 
480         /* Nothing to do */
481         return;
482 
483     case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
484 
485         /*
486          * These names must be control methods, by definition in ACPI spec.
487          * Also because they are defined to return no value. None of them
488          * require any arguments.
489          */
490         AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
491             "with zero arguments");
492         return;
493 
494     default:
495 
496         break;
497     }
498 
499     /* A standard predefined ACPI name */
500 
501     /*
502      * If this predefined name requires input arguments, then
503      * it must be implemented as a control method
504      */
505     ThisName = &AcpiGbl_PredefinedMethods[Index];
506     if (METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList) > 0)
507     {
508         AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
509             "with arguments");
510         return;
511     }
512 
513     /*
514      * If no return value is expected from this predefined name, then
515      * it follows that it must be implemented as a control method
516      * (with zero args, because the args > 0 case was handled above)
517      * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
518      */
519     if (!ThisName->Info.ExpectedBtypes)
520     {
521         AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
522             "with zero arguments");
523         return;
524     }
525 
526     /* Typecheck the actual object, it is the next argument */
527 
528     ObjectOp = Op->Asl.Child->Asl.Next;
529     ApCheckObjectType (ThisName->Info.Name, Op->Asl.Child->Asl.Next,
530         ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
531 
532     /* For packages, check the individual package elements */
533 
534     if (ObjectOp->Asl.ParseOpcode == PARSEOP_PACKAGE)
535     {
536         ApCheckPackage (ObjectOp, ThisName);
537     }
538 }
539 
540 
541 /*******************************************************************************
542  *
543  * FUNCTION:    ApCheckForPredefinedName
544  *
545  * PARAMETERS:  Op              - A parse node
546  *              Name            - NameSeg to check
547  *
548  * RETURN:      None
549  *
550  * DESCRIPTION: Check a NameSeg against the reserved list.
551  *
552  ******************************************************************************/
553 
554 UINT32
555 ApCheckForPredefinedName (
556     ACPI_PARSE_OBJECT       *Op,
557     char                    *Name)
558 {
559     UINT32                      i;
560     const ACPI_PREDEFINED_INFO  *ThisName;
561 
562 
563     if (Name[0] == 0)
564     {
565         AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
566             "zero length name found");
567     }
568 
569     /* All reserved names are prefixed with a single underscore */
570 
571     if (Name[0] != '_')
572     {
573         return (ACPI_NOT_RESERVED_NAME);
574     }
575 
576     /* Check for a standard predefined method name */
577 
578     ThisName = AcpiGbl_PredefinedMethods;
579     for (i = 0; ThisName->Info.Name[0]; i++)
580     {
581         if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
582         {
583             /* Return index into predefined array */
584             return (i);
585         }
586 
587         ThisName++; /* Does not account for extra package data, but is OK */
588     }
589 
590     /* Check for resource names and predefined scope names */
591 
592     ThisName = AcpiGbl_ResourceNames;
593     while (ThisName->Info.Name[0])
594     {
595         if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
596         {
597             return (ACPI_PREDEFINED_NAME);
598         }
599 
600         ThisName++;
601     }
602 
603     ThisName = AcpiGbl_ScopeNames;
604     while (ThisName->Info.Name[0])
605     {
606         if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
607         {
608             return (ACPI_PREDEFINED_NAME);
609         }
610 
611         ThisName++;
612     }
613 
614     /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
615 
616     return (ApCheckForSpecialName (Op, Name));
617 }
618 
619 
620 /*******************************************************************************
621  *
622  * FUNCTION:    ApCheckForSpecialName
623  *
624  * PARAMETERS:  Op              - A parse node
625  *              Name            - NameSeg to check
626  *
627  * RETURN:      None
628  *
629  * DESCRIPTION: Check for the "special" predefined names -
630  *              _Lxx, _Exx, _Qxx, _Wxx, and _T_x
631  *
632  ******************************************************************************/
633 
634 static UINT32
635 ApCheckForSpecialName (
636     ACPI_PARSE_OBJECT       *Op,
637     char                    *Name)
638 {
639 
640     /*
641      * Check for the "special" predefined names. We already know that the
642      * first character is an underscore.
643      *   GPE:  _Lxx
644      *   GPE:  _Exx
645      *   GPE:  _Wxx
646      *   EC:   _Qxx
647      */
648     if ((Name[1] == 'L') ||
649         (Name[1] == 'E') ||
650         (Name[1] == 'W') ||
651         (Name[1] == 'Q'))
652     {
653         /* The next two characters must be hex digits */
654 
655         if ((isxdigit ((int) Name[2])) &&
656             (isxdigit ((int) Name[3])))
657         {
658             return (ACPI_EVENT_RESERVED_NAME);
659         }
660     }
661 
662     /* Check for the names reserved for the compiler itself: _T_x */
663 
664     else if ((Op->Asl.ExternalName[1] == 'T') &&
665              (Op->Asl.ExternalName[2] == '_'))
666     {
667         /* Ignore if actually emitted by the compiler */
668 
669         if (Op->Asl.CompileFlags & OP_COMPILER_EMITTED)
670         {
671             return (ACPI_NOT_RESERVED_NAME);
672         }
673 
674         /*
675          * Was not actually emitted by the compiler. This is a special case,
676          * however. If the ASL code being compiled was the result of a
677          * dissasembly, it may possibly contain valid compiler-emitted names
678          * of the form "_T_x". We don't want to issue an error or even a
679          * warning and force the user to manually change the names. So, we
680          * will issue a remark instead.
681          */
682         AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED,
683             Op, Op->Asl.ExternalName);
684         return (ACPI_COMPILER_RESERVED_NAME);
685     }
686 
687     /*
688      * The name didn't match any of the known predefined names. Flag it as a
689      * warning, since the entire namespace starting with an underscore is
690      * reserved by the ACPI spec.
691      */
692     AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME,
693         Op, Op->Asl.ExternalName);
694 
695     return (ACPI_NOT_RESERVED_NAME);
696 }
697 
698 
699 /*******************************************************************************
700  *
701  * FUNCTION:    ApCheckObjectType
702  *
703  * PARAMETERS:  PredefinedName  - Name of the predefined object we are checking
704  *              Op              - Current parse node
705  *              ExpectedBtypes  - Bitmap of expected return type(s)
706  *              PackageIndex    - Index of object within parent package (if
707  *                                applicable - ACPI_NOT_PACKAGE_ELEMENT
708  *                                otherwise)
709  *
710  * RETURN:      None
711  *
712  * DESCRIPTION: Check if the object type is one of the types that is expected
713  *              by the predefined name. Only a limited number of object types
714  *              can be returned by the predefined names.
715  *
716  ******************************************************************************/
717 
718 ACPI_STATUS
719 ApCheckObjectType (
720     const char              *PredefinedName,
721     ACPI_PARSE_OBJECT       *Op,
722     UINT32                  ExpectedBtypes,
723     UINT32                  PackageIndex)
724 {
725     UINT32                  ReturnBtype;
726     char                    *TypeName;
727 
728 
729     if (!Op)
730     {
731         return (AE_TYPE);
732     }
733 
734     /* Map the parse opcode to a bitmapped return type (RTYPE) */
735 
736     switch (Op->Asl.ParseOpcode)
737     {
738     case PARSEOP_ZERO:
739     case PARSEOP_ONE:
740     case PARSEOP_ONES:
741     case PARSEOP_INTEGER:
742 
743         ReturnBtype = ACPI_RTYPE_INTEGER;
744         TypeName = "Integer";
745         break;
746 
747     case PARSEOP_STRING_LITERAL:
748 
749         ReturnBtype = ACPI_RTYPE_STRING;
750         TypeName = "String";
751         break;
752 
753     case PARSEOP_BUFFER:
754 
755         ReturnBtype = ACPI_RTYPE_BUFFER;
756         TypeName = "Buffer";
757         break;
758 
759     case PARSEOP_PACKAGE:
760     case PARSEOP_VAR_PACKAGE:
761 
762         ReturnBtype = ACPI_RTYPE_PACKAGE;
763         TypeName = "Package";
764         break;
765 
766     case PARSEOP_NAMESEG:
767     case PARSEOP_NAMESTRING:
768         /*
769          * Ignore any named references within a package object.
770          *
771          * For Package objects, references are allowed instead of any of the
772          * standard data types (Integer/String/Buffer/Package). These
773          * references are resolved at runtime. NAMESEG and NAMESTRING are
774          * impossible to typecheck at compile time because the type of
775          * any named object can be changed at runtime (for example,
776          * CopyObject will change the type of the target object).
777          */
778         if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
779         {
780             return (AE_OK);
781         }
782 
783         ReturnBtype = ACPI_RTYPE_REFERENCE;
784         TypeName = "Reference";
785         break;
786 
787     default:
788 
789         /* Not one of the supported object types */
790 
791         TypeName = UtGetOpName (Op->Asl.ParseOpcode);
792         goto TypeErrorExit;
793     }
794 
795     /* Exit if the object is one of the expected types */
796 
797     if (ReturnBtype & ExpectedBtypes)
798     {
799         return (AE_OK);
800     }
801 
802 
803 TypeErrorExit:
804 
805     /* Format the expected types and emit an error message */
806 
807     AcpiUtGetExpectedReturnTypes (StringBuffer, ExpectedBtypes);
808 
809     if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
810     {
811         sprintf (MsgBuffer, "%4.4s: found %s, %s required",
812             PredefinedName, TypeName, StringBuffer);
813     }
814     else
815     {
816         sprintf (MsgBuffer, "%4.4s: found %s at index %u, %s required",
817             PredefinedName, TypeName, PackageIndex, StringBuffer);
818     }
819 
820     AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, MsgBuffer);
821     return (AE_TYPE);
822 }
823 
824 
825 /*******************************************************************************
826  *
827  * FUNCTION:    ApDisplayReservedNames
828  *
829  * PARAMETERS:  None
830  *
831  * RETURN:      None
832  *
833  * DESCRIPTION: Dump information about the ACPI predefined names and predefined
834  *              resource descriptor names.
835  *
836  ******************************************************************************/
837 
838 void
839 ApDisplayReservedNames (
840     void)
841 {
842     const ACPI_PREDEFINED_INFO  *ThisName;
843     UINT32                      Count;
844     UINT32                      NumTypes;
845 
846 
847     /*
848      * Predefined names/methods
849      */
850     printf ("\nPredefined Name Information\n\n");
851 
852     Count = 0;
853     ThisName = AcpiGbl_PredefinedMethods;
854     while (ThisName->Info.Name[0])
855     {
856         AcpiUtDisplayPredefinedMethod (MsgBuffer, ThisName, FALSE);
857         Count++;
858         ThisName = AcpiUtGetNextPredefinedMethod (ThisName);
859     }
860 
861     printf ("%u Predefined Names are recognized\n", Count);
862 
863     /*
864      * Resource Descriptor names
865      */
866     printf ("\nPredefined Names for Resource Descriptor Fields\n\n");
867 
868     Count = 0;
869     ThisName = AcpiGbl_ResourceNames;
870     while (ThisName->Info.Name[0])
871     {
872         NumTypes = AcpiUtGetResourceBitWidth (MsgBuffer,
873             ThisName->Info.ArgumentList);
874 
875         printf ("%4.4s    Field is %s bits wide%s\n",
876             ThisName->Info.Name, MsgBuffer,
877             (NumTypes > 1) ? " (depending on descriptor type)" : "");
878 
879         Count++;
880         ThisName++;
881     }
882 
883     printf ("%u Resource Descriptor Field Names are recognized\n", Count);
884 
885     /*
886      * Predefined scope names
887      */
888     printf ("\nPredefined Scope/Device Names (automatically created at root)\n\n");
889 
890     ThisName = AcpiGbl_ScopeNames;
891     while (ThisName->Info.Name[0])
892     {
893         printf ("%4.4s    Scope/Device\n", ThisName->Info.Name);
894         ThisName++;
895     }
896 }
897