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