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