aslpredef.c revision 204766
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 - 2010, 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 "amlcode.h"
121#include "acparser.h"
122#include "acpredef.h"
123
124
125#define _COMPONENT          ACPI_COMPILER
126        ACPI_MODULE_NAME    ("aslpredef")
127
128
129/* Local prototypes */
130
131static UINT32
132ApCheckForSpecialName (
133    ACPI_PARSE_OBJECT       *Op,
134    char                    *Name);
135
136static void
137ApCheckObjectType (
138    ACPI_PARSE_OBJECT       *Op,
139    UINT32                  ExpectedBtypes);
140
141static void
142ApGetExpectedTypes (
143    char                    *Buffer,
144    UINT32                  ExpectedBtypes);
145
146
147/*
148 * Names for the types that can be returned by the predefined objects.
149 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
150 */
151static const char   *AcpiRtypeNames[] =
152{
153    "/Integer",
154    "/String",
155    "/Buffer",
156    "/Package",
157    "/Reference",
158};
159
160/*
161 * Predefined names for use in Resource Descriptors. These names do not
162 * appear in the global Predefined Name table (since these names never
163 * appear in actual AML byte code, only in the original ASL)
164 */
165static const ACPI_PREDEFINED_INFO      ResourceNames[] = {
166    {{"_ALN",     0,      0}},
167    {{"_ASI",     0,      0}},
168    {{"_ASZ",     0,      0}},
169    {{"_ATT",     0,      0}},
170    {{"_BAS",     0,      0}},
171    {{"_BM_",     0,      0}},
172    {{"_DEC",     0,      0}},
173    {{"_GRA",     0,      0}},
174    {{"_HE_",     0,      0}},
175    {{"_INT",     0,      0}},
176    {{"_LEN",     0,      0}},
177    {{"_LL_",     0,      0}},
178    {{"_MAF",     0,      0}},
179    {{"_MAX",     0,      0}},
180    {{"_MEM",     0,      0}},
181    {{"_MIF",     0,      0}},
182    {{"_MIN",     0,      0}},
183    {{"_MTP",     0,      0}},
184    {{"_RBO",     0,      0}},
185    {{"_RBW",     0,      0}},
186    {{"_RNG",     0,      0}},
187    {{"_RT_",     0,      0}},  /* Acpi 3.0 */
188    {{"_RW_",     0,      0}},
189    {{"_SHR",     0,      0}},
190    {{"_SIZ",     0,      0}},
191    {{"_TRA",     0,      0}},
192    {{"_TRS",     0,      0}},
193    {{"_TSF",     0,      0}},  /* Acpi 3.0 */
194    {{"_TTP",     0,      0}},
195    {{"_TYP",     0,      0}},
196    {{{0,0,0,0},  0,      0}}   /* Table terminator */
197};
198
199static const ACPI_PREDEFINED_INFO      ScopeNames[] = {
200    {{"_SB_",     0,      0}},
201    {{"_SI_",     0,      0}},
202    {{"_TZ_",     0,      0}},
203    {{{0,0,0,0},  0,      0}}   /* Table terminator */
204};
205
206
207/*******************************************************************************
208 *
209 * FUNCTION:    ApCheckForPredefinedMethod
210 *
211 * PARAMETERS:  Op              - A parse node of type "METHOD".
212 *              MethodInfo      - Saved info about this method
213 *
214 * RETURN:      None
215 *
216 * DESCRIPTION: If method is a predefined name, check that the number of
217 *              arguments and the return type (returns a value or not)
218 *              is correct.
219 *
220 ******************************************************************************/
221
222void
223ApCheckForPredefinedMethod (
224    ACPI_PARSE_OBJECT       *Op,
225    ASL_METHOD_INFO         *MethodInfo)
226{
227    UINT32                  Index;
228    UINT32                  RequiredArgsCurrent;
229    UINT32                  RequiredArgsOld;
230
231
232    /* Check for a match against the predefined name list */
233
234    Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
235
236    switch (Index)
237    {
238    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
239    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
240    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
241
242        /* Just return, nothing to do */
243        break;
244
245
246    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx, _Exx, and _Qxx methods */
247
248        Gbl_ReservedMethods++;
249
250        /* NumArguments must be zero for all _Lxx, _Exx, and _Qxx methods */
251
252        if (MethodInfo->NumArguments != 0)
253        {
254            sprintf (MsgBuffer, "%s requires %d", Op->Asl.ExternalName, 0);
255
256            AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
257                MsgBuffer);
258        }
259        break;
260
261
262    default:
263        /*
264         * Matched a predefined method name
265         *
266         * Validate the ASL-defined argument count. Allow two different legal
267         * arg counts.
268         */
269        Gbl_ReservedMethods++;
270
271        RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
272        RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
273
274        if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
275            (MethodInfo->NumArguments != RequiredArgsOld))
276        {
277            sprintf (MsgBuffer, "%4.4s requires %d",
278                PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
279
280            if (MethodInfo->NumArguments > RequiredArgsCurrent)
281            {
282                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
283                    MsgBuffer);
284            }
285            else
286            {
287                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
288                    MsgBuffer);
289            }
290        }
291
292        /*
293         * Check if method returns no value, but the predefined name is
294         * required to return a value
295         */
296        if (MethodInfo->NumReturnNoValue &&
297            PredefinedNames[Index].Info.ExpectedBtypes)
298        {
299            sprintf (MsgBuffer, "%4.4s", PredefinedNames[Index].Info.Name);
300
301            AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
302                MsgBuffer);
303        }
304        break;
305    }
306}
307
308
309/*******************************************************************************
310 *
311 * FUNCTION:    ApCheckForPredefinedObject
312 *
313 * PARAMETERS:  Op              - A parse node
314 *              Name            - The ACPI name to be checked
315 *
316 * RETURN:      None
317 *
318 * DESCRIPTION: Check for a predefined name for a static object (created via
319 *              the ASL Name operator). If it is a predefined ACPI name, ensure
320 *              that the name does not require any arguments (which would
321 *              require a control method implemenation of the name), and that
322 *              the type of the object is one of the expected types for the
323 *              predefined name.
324 *
325 ******************************************************************************/
326
327void
328ApCheckForPredefinedObject (
329    ACPI_PARSE_OBJECT       *Op,
330    char                    *Name)
331{
332    UINT32                  Index;
333
334
335    /*
336     * Check for a real predefined name -- not a resource descriptor name
337     * or a predefined scope name
338     */
339    Index = ApCheckForPredefinedName (Op, Name);
340    if (Index > ACPI_VALID_RESERVED_NAME_MAX)
341    {
342        return;
343    }
344
345    /*
346     * We found a matching predefind name.
347     * Check if this predefined name requires input arguments
348     */
349    if (PredefinedNames[Index].Info.ParamCount > 0)
350    {
351        /*
352         * This predefined name must always be defined as a control
353         * method because it is required to have input arguments.
354         */
355        AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
356            "with arguments");
357    }
358
359    /* Typecheck the actual object, it is the next argument */
360
361    ApCheckObjectType (Op->Asl.Child->Asl.Next,
362        PredefinedNames[Index].Info.ExpectedBtypes);
363}
364
365
366/*******************************************************************************
367 *
368 * FUNCTION:    ApCheckForPredefinedName
369 *
370 * PARAMETERS:  Op              - A parse node
371 *              Name            - NameSeg to check
372 *
373 * RETURN:      None
374 *
375 * DESCRIPTION: Check a NameSeg against the reserved list.
376 *
377 ******************************************************************************/
378
379UINT32
380ApCheckForPredefinedName (
381    ACPI_PARSE_OBJECT       *Op,
382    char                    *Name)
383{
384    UINT32                  i;
385
386
387    if (Name[0] == 0)
388    {
389        AcpiOsPrintf ("Found a null name, external = %s\n",
390            Op->Asl.ExternalName);
391    }
392
393    /* All reserved names are prefixed with a single underscore */
394
395    if (Name[0] != '_')
396    {
397        return (ACPI_NOT_RESERVED_NAME);
398    }
399
400    /* Check for a standard predefined method name */
401
402    for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
403    {
404        if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
405        {
406            /* Return index into predefined array */
407            return (i);
408        }
409    }
410
411    /* Check for resource names and predefined scope names */
412
413    for (i = 0; ResourceNames[i].Info.Name[0]; i++)
414    {
415        if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
416        {
417            return (ACPI_PREDEFINED_NAME);
418        }
419    }
420
421    for (i = 0; ScopeNames[i].Info.Name[0]; i++)
422    {
423        if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
424        {
425            return (ACPI_PREDEFINED_NAME);
426        }
427    }
428
429    /* Check for _Lxx, _Exx, _Qxx, _T_x. Warning if unknown predefined name */
430
431    return (ApCheckForSpecialName (Op, Name));
432}
433
434
435/*******************************************************************************
436 *
437 * FUNCTION:    ApCheckForSpecialName
438 *
439 * PARAMETERS:  Op              - A parse node
440 *              Name            - NameSeg to check
441 *
442 * RETURN:      None
443 *
444 * DESCRIPTION: Check for the "special" predefined names -
445 *              _Lxx, _Exx, _Qxx, and _T_x
446 *
447 ******************************************************************************/
448
449static UINT32
450ApCheckForSpecialName (
451    ACPI_PARSE_OBJECT       *Op,
452    char                    *Name)
453{
454
455    /*
456     * Check for the "special" predefined names. We know the first char is an
457     * underscore already.
458     *   GPE:  _Lxx
459     *   GPE:  _Exx
460     *   EC:   _Qxx
461     */
462    if ((Name[1] == 'L') ||
463        (Name[1] == 'E') ||
464        (Name[1] == 'Q'))
465    {
466        /* The next two characters must be hex digits */
467
468        if ((isxdigit ((int) Name[2])) &&
469            (isxdigit ((int) Name[3])))
470        {
471            return (ACPI_EVENT_RESERVED_NAME);
472        }
473    }
474
475    /* Check for the names reserved for the compiler itself: _T_x */
476
477    else if ((Op->Asl.ExternalName[1] == 'T') &&
478             (Op->Asl.ExternalName[2] == '_'))
479    {
480        /* Ignore if actually emitted by the compiler */
481
482        if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
483        {
484            return (ACPI_NOT_RESERVED_NAME);
485        }
486
487        /*
488         * Was not actually emitted by the compiler. This is a special case,
489         * however. If the ASL code being compiled was the result of a
490         * dissasembly, it may possibly contain valid compiler-emitted names
491         * of the form "_T_x". We don't want to issue an error or even a
492         * warning and force the user to manually change the names. So, we
493         * will issue a remark instead.
494         */
495        AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
496        return (ACPI_COMPILER_RESERVED_NAME);
497    }
498
499    /*
500     * The name didn't match any of the known predefined names. Flag it as a
501     * warning, since the entire namespace starting with an underscore is
502     * reserved by the ACPI spec.
503     */
504    AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
505        Op->Asl.ExternalName);
506
507    return (ACPI_NOT_RESERVED_NAME);
508}
509
510
511/*******************************************************************************
512 *
513 * FUNCTION:    ApCheckObjectType
514 *
515 * PARAMETERS:  Op              - A parse node
516 *              ExpectedBtypes  - Bitmap of expected return type(s)
517 *
518 * RETURN:      None
519 *
520 * DESCRIPTION: Check if the object type is one of the types that is expected
521 *              by the predefined name. Only a limited number of object types
522 *              can be returned by the predefined names.
523 *
524 ******************************************************************************/
525
526static void
527ApCheckObjectType (
528    ACPI_PARSE_OBJECT       *Op,
529    UINT32                  ExpectedBtypes)
530{
531    UINT32                  ReturnBtype;
532    char                    TypeBuffer[48]; /* Room for 5 types */
533
534
535    switch (Op->Asl.ParseOpcode)
536    {
537    case PARSEOP_INTEGER:
538        ReturnBtype = ACPI_RTYPE_INTEGER;
539        break;
540
541    case PARSEOP_BUFFER:
542        ReturnBtype = ACPI_RTYPE_BUFFER;
543        break;
544
545    case PARSEOP_STRING_LITERAL:
546        ReturnBtype = ACPI_RTYPE_STRING;
547        break;
548
549    case PARSEOP_PACKAGE:
550        ReturnBtype = ACPI_RTYPE_PACKAGE;
551        break;
552
553    default:
554        /* Not one of the supported object types */
555
556        goto TypeErrorExit;
557    }
558
559    /* Is the object one of the expected types? */
560
561    if (ReturnBtype & ExpectedBtypes)
562    {
563        return;
564    }
565
566
567TypeErrorExit:
568
569    /* Format the expected types and emit an error message */
570
571    ApGetExpectedTypes (TypeBuffer, ExpectedBtypes);
572
573    AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
574        TypeBuffer);
575}
576
577
578/*******************************************************************************
579 *
580 * FUNCTION:    ApDisplayReservedNames
581 *
582 * PARAMETERS:  None
583 *
584 * RETURN:      None
585 *
586 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
587 *              resource descriptor names.
588 *
589 ******************************************************************************/
590
591void
592ApDisplayReservedNames (
593    void)
594{
595    const ACPI_PREDEFINED_INFO  *ThisName;
596    char                        TypeBuffer[48]; /* Room for 5 types */
597    UINT32                      Count;
598
599
600    /*
601     * Predefined names/methods
602     */
603    printf ("\nPredefined Name Information\n\n");
604
605    Count = 0;
606    ThisName = PredefinedNames;
607    while (ThisName->Info.Name[0])
608    {
609        printf ("%4.4s    Requires %d arguments, ",
610            ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
611
612        if (ThisName->Info.ExpectedBtypes)
613        {
614            ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
615            printf ("Must return: %s\n", TypeBuffer);
616        }
617        else
618        {
619            printf ("No return value\n");
620        }
621
622        /*
623         * Skip next entry in the table if this name returns a Package
624         * (next entry contains the package info)
625         */
626        if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
627        {
628            ThisName++;
629        }
630
631        Count++;
632        ThisName++;
633    }
634
635    printf ("%u Predefined Names are recognized\n", Count);
636
637    /*
638     * Resource Descriptor names
639     */
640    printf ("\nResource Descriptor Predefined Names\n\n");
641
642    Count = 0;
643    ThisName = ResourceNames;
644    while (ThisName->Info.Name[0])
645    {
646        printf ("%4.4s    Resource Descriptor\n", ThisName->Info.Name);
647        Count++;
648        ThisName++;
649    }
650
651    printf ("%u Resource Descriptor Names are recognized\n", Count);
652
653    /*
654     * Predefined scope names
655     */
656    printf ("\nPredefined Scope Names\n\n");
657
658    ThisName = ScopeNames;
659    while (ThisName->Info.Name[0])
660    {
661        printf ("%4.4s    Scope\n", ThisName->Info.Name);
662        ThisName++;
663    }
664}
665
666
667/*******************************************************************************
668 *
669 * FUNCTION:    ApGetExpectedTypes
670 *
671 * PARAMETERS:  Buffer              - Where the formatted string is returned
672 *              ExpectedBTypes      - Bitfield of expected data types
673 *
674 * RETURN:      None, formatted string
675 *
676 * DESCRIPTION: Format the expected object types into a printable string.
677 *
678 ******************************************************************************/
679
680static void
681ApGetExpectedTypes (
682    char                        *Buffer,
683    UINT32                      ExpectedBtypes)
684{
685    UINT32                      ThisRtype;
686    UINT32                      i;
687    UINT32                      j;
688
689
690    j = 1;
691    Buffer[0] = 0;
692    ThisRtype = ACPI_RTYPE_INTEGER;
693
694    for (i = 0; i < ACPI_NUM_RTYPES; i++)
695    {
696        /* If one of the expected types, concatenate the name of this type */
697
698        if (ExpectedBtypes & ThisRtype)
699        {
700            ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
701            j = 0;              /* Use name separator from now on */
702        }
703        ThisRtype <<= 1;    /* Next Rtype */
704    }
705}
706
707