Home | History | Annotate | Line # | Download | only in compiler
aslwalks.c revision 1.1.1.2.2.1
      1          1.1  jruoho /******************************************************************************
      2          1.1  jruoho  *
      3  1.1.1.2.2.1    yamt  * Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
      4          1.1  jruoho  *
      5          1.1  jruoho  *****************************************************************************/
      6          1.1  jruoho 
      7          1.1  jruoho /*
      8  1.1.1.2.2.1    yamt  * Copyright (C) 2000 - 2013, Intel Corp.
      9          1.1  jruoho  * All rights reserved.
     10          1.1  jruoho  *
     11          1.1  jruoho  * Redistribution and use in source and binary forms, with or without
     12          1.1  jruoho  * modification, are permitted provided that the following conditions
     13          1.1  jruoho  * are met:
     14          1.1  jruoho  * 1. Redistributions of source code must retain the above copyright
     15          1.1  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16          1.1  jruoho  *    without modification.
     17          1.1  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18          1.1  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19          1.1  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20          1.1  jruoho  *    including a substantially similar Disclaimer requirement for further
     21          1.1  jruoho  *    binary redistribution.
     22          1.1  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23          1.1  jruoho  *    of any contributors may be used to endorse or promote products derived
     24          1.1  jruoho  *    from this software without specific prior written permission.
     25          1.1  jruoho  *
     26          1.1  jruoho  * Alternatively, this software may be distributed under the terms of the
     27          1.1  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28          1.1  jruoho  * Software Foundation.
     29          1.1  jruoho  *
     30          1.1  jruoho  * NO WARRANTY
     31          1.1  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32          1.1  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33          1.1  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34          1.1  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35          1.1  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36          1.1  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37          1.1  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38          1.1  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39          1.1  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40          1.1  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41          1.1  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42          1.1  jruoho  */
     43          1.1  jruoho 
     44          1.1  jruoho 
     45          1.1  jruoho #include "aslcompiler.h"
     46          1.1  jruoho #include "aslcompiler.y.h"
     47          1.1  jruoho #include "acparser.h"
     48          1.1  jruoho #include "amlcode.h"
     49          1.1  jruoho 
     50          1.1  jruoho 
     51          1.1  jruoho #define _COMPONENT          ACPI_COMPILER
     52          1.1  jruoho         ACPI_MODULE_NAME    ("aslwalks")
     53          1.1  jruoho 
     54          1.1  jruoho 
     55          1.1  jruoho /*******************************************************************************
     56          1.1  jruoho  *
     57          1.1  jruoho  * FUNCTION:    AnMethodTypingWalkEnd
     58          1.1  jruoho  *
     59          1.1  jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
     60          1.1  jruoho  *
     61          1.1  jruoho  * RETURN:      Status
     62          1.1  jruoho  *
     63          1.1  jruoho  * DESCRIPTION: Ascending callback for typing walk. Complete the method
     64          1.1  jruoho  *              return analysis. Check methods for:
     65          1.1  jruoho  *              1) Initialized local variables
     66          1.1  jruoho  *              2) Valid arguments
     67          1.1  jruoho  *              3) Return types
     68          1.1  jruoho  *
     69          1.1  jruoho  ******************************************************************************/
     70          1.1  jruoho 
     71          1.1  jruoho ACPI_STATUS
     72          1.1  jruoho AnMethodTypingWalkEnd (
     73          1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
     74          1.1  jruoho     UINT32                  Level,
     75          1.1  jruoho     void                    *Context)
     76          1.1  jruoho {
     77          1.1  jruoho     UINT32                  ThisNodeBtype;
     78          1.1  jruoho 
     79          1.1  jruoho 
     80          1.1  jruoho     switch (Op->Asl.ParseOpcode)
     81          1.1  jruoho     {
     82          1.1  jruoho     case PARSEOP_METHOD:
     83          1.1  jruoho 
     84          1.1  jruoho         Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
     85          1.1  jruoho         break;
     86          1.1  jruoho 
     87          1.1  jruoho     case PARSEOP_RETURN:
     88          1.1  jruoho 
     89          1.1  jruoho         if ((Op->Asl.Child) &&
     90          1.1  jruoho             (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
     91          1.1  jruoho         {
     92          1.1  jruoho             ThisNodeBtype = AnGetBtype (Op->Asl.Child);
     93          1.1  jruoho 
     94          1.1  jruoho             if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
     95          1.1  jruoho                 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
     96          1.1  jruoho             {
     97          1.1  jruoho                 /*
     98          1.1  jruoho                  * The called method is untyped at this time (typically a
     99          1.1  jruoho                  * forward reference).
    100          1.1  jruoho                  *
    101          1.1  jruoho                  * Check for a recursive method call first.
    102          1.1  jruoho                  */
    103          1.1  jruoho                 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
    104          1.1  jruoho                 {
    105          1.1  jruoho                     /* We must type the method here */
    106          1.1  jruoho 
    107          1.1  jruoho                     TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
    108          1.1  jruoho                         ASL_WALK_VISIT_UPWARD, NULL,
    109          1.1  jruoho                         AnMethodTypingWalkEnd, NULL);
    110          1.1  jruoho 
    111          1.1  jruoho                     ThisNodeBtype = AnGetBtype (Op->Asl.Child);
    112          1.1  jruoho                 }
    113          1.1  jruoho             }
    114          1.1  jruoho 
    115          1.1  jruoho             /* Returns a value, save the value type */
    116          1.1  jruoho 
    117          1.1  jruoho             if (Op->Asl.ParentMethod)
    118          1.1  jruoho             {
    119          1.1  jruoho                 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
    120          1.1  jruoho             }
    121          1.1  jruoho         }
    122          1.1  jruoho         break;
    123          1.1  jruoho 
    124          1.1  jruoho     default:
    125  1.1.1.2.2.1    yamt 
    126          1.1  jruoho         break;
    127          1.1  jruoho     }
    128          1.1  jruoho 
    129          1.1  jruoho     return (AE_OK);
    130          1.1  jruoho }
    131          1.1  jruoho 
    132          1.1  jruoho 
    133          1.1  jruoho /*******************************************************************************
    134          1.1  jruoho  *
    135          1.1  jruoho  * FUNCTION:    AnOperandTypecheckWalkEnd
    136          1.1  jruoho  *
    137          1.1  jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    138          1.1  jruoho  *
    139          1.1  jruoho  * RETURN:      Status
    140          1.1  jruoho  *
    141          1.1  jruoho  * DESCRIPTION: Ascending callback for analysis walk. Complete method
    142          1.1  jruoho  *              return analysis.
    143          1.1  jruoho  *
    144          1.1  jruoho  ******************************************************************************/
    145          1.1  jruoho 
    146          1.1  jruoho ACPI_STATUS
    147          1.1  jruoho AnOperandTypecheckWalkEnd (
    148          1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    149          1.1  jruoho     UINT32                  Level,
    150          1.1  jruoho     void                    *Context)
    151          1.1  jruoho {
    152          1.1  jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    153          1.1  jruoho     UINT32                  RuntimeArgTypes;
    154          1.1  jruoho     UINT32                  RuntimeArgTypes2;
    155          1.1  jruoho     UINT32                  RequiredBtypes;
    156          1.1  jruoho     UINT32                  ThisNodeBtype;
    157          1.1  jruoho     UINT32                  CommonBtypes;
    158          1.1  jruoho     UINT32                  OpcodeClass;
    159          1.1  jruoho     ACPI_PARSE_OBJECT       *ArgOp;
    160          1.1  jruoho     UINT32                  ArgType;
    161          1.1  jruoho 
    162          1.1  jruoho 
    163          1.1  jruoho     switch (Op->Asl.AmlOpcode)
    164          1.1  jruoho     {
    165          1.1  jruoho     case AML_RAW_DATA_BYTE:
    166          1.1  jruoho     case AML_RAW_DATA_WORD:
    167          1.1  jruoho     case AML_RAW_DATA_DWORD:
    168          1.1  jruoho     case AML_RAW_DATA_QWORD:
    169          1.1  jruoho     case AML_RAW_DATA_BUFFER:
    170          1.1  jruoho     case AML_RAW_DATA_CHAIN:
    171          1.1  jruoho     case AML_PACKAGE_LENGTH:
    172          1.1  jruoho     case AML_UNASSIGNED_OPCODE:
    173          1.1  jruoho     case AML_DEFAULT_ARG_OP:
    174          1.1  jruoho 
    175          1.1  jruoho         /* Ignore the internal (compiler-only) AML opcodes */
    176          1.1  jruoho 
    177          1.1  jruoho         return (AE_OK);
    178          1.1  jruoho 
    179          1.1  jruoho     default:
    180  1.1.1.2.2.1    yamt 
    181          1.1  jruoho         break;
    182          1.1  jruoho     }
    183          1.1  jruoho 
    184          1.1  jruoho     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    185          1.1  jruoho     if (!OpInfo)
    186          1.1  jruoho     {
    187          1.1  jruoho         return (AE_OK);
    188          1.1  jruoho     }
    189          1.1  jruoho 
    190          1.1  jruoho     ArgOp           = Op->Asl.Child;
    191          1.1  jruoho     RuntimeArgTypes = OpInfo->RuntimeArgs;
    192          1.1  jruoho     OpcodeClass     = OpInfo->Class;
    193          1.1  jruoho 
    194          1.1  jruoho #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
    195          1.1  jruoho     /*
    196          1.1  jruoho      * Update 11/2008: In practice, we can't perform this check. A simple
    197          1.1  jruoho      * analysis is not sufficient. Also, it can cause errors when compiling
    198          1.1  jruoho      * disassembled code because of the way Switch operators are implemented
    199          1.1  jruoho      * (a While(One) loop with a named temp variable created within.)
    200          1.1  jruoho      */
    201          1.1  jruoho 
    202          1.1  jruoho     /*
    203          1.1  jruoho      * If we are creating a named object, check if we are within a while loop
    204          1.1  jruoho      * by checking if the parent is a WHILE op. This is a simple analysis, but
    205          1.1  jruoho      * probably sufficient for many cases.
    206          1.1  jruoho      *
    207          1.1  jruoho      * Allow Scope(), Buffer(), and Package().
    208          1.1  jruoho      */
    209          1.1  jruoho     if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
    210          1.1  jruoho         ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
    211          1.1  jruoho     {
    212          1.1  jruoho         if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
    213          1.1  jruoho         {
    214          1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
    215          1.1  jruoho         }
    216          1.1  jruoho     }
    217          1.1  jruoho #endif
    218          1.1  jruoho 
    219          1.1  jruoho     /*
    220          1.1  jruoho      * Special case for control opcodes IF/RETURN/WHILE since they
    221          1.1  jruoho      * have no runtime arg list (at this time)
    222          1.1  jruoho      */
    223          1.1  jruoho     switch (Op->Asl.AmlOpcode)
    224          1.1  jruoho     {
    225          1.1  jruoho     case AML_IF_OP:
    226          1.1  jruoho     case AML_WHILE_OP:
    227          1.1  jruoho     case AML_RETURN_OP:
    228          1.1  jruoho 
    229          1.1  jruoho         if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
    230          1.1  jruoho         {
    231          1.1  jruoho             /* Check for an internal method */
    232          1.1  jruoho 
    233          1.1  jruoho             if (AnIsInternalMethod (ArgOp))
    234          1.1  jruoho             {
    235          1.1  jruoho                 return (AE_OK);
    236          1.1  jruoho             }
    237          1.1  jruoho 
    238          1.1  jruoho             /* The lone arg is a method call, check it */
    239          1.1  jruoho 
    240          1.1  jruoho             RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
    241          1.1  jruoho             if (Op->Asl.AmlOpcode == AML_RETURN_OP)
    242          1.1  jruoho             {
    243          1.1  jruoho                 RequiredBtypes = 0xFFFFFFFF;
    244          1.1  jruoho             }
    245          1.1  jruoho 
    246          1.1  jruoho             ThisNodeBtype = AnGetBtype (ArgOp);
    247          1.1  jruoho             if (ThisNodeBtype == ACPI_UINT32_MAX)
    248          1.1  jruoho             {
    249          1.1  jruoho                 return (AE_OK);
    250          1.1  jruoho             }
    251          1.1  jruoho             AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
    252          1.1  jruoho                 RequiredBtypes, ThisNodeBtype);
    253          1.1  jruoho         }
    254          1.1  jruoho         return (AE_OK);
    255          1.1  jruoho 
    256          1.1  jruoho     default:
    257  1.1.1.2.2.1    yamt 
    258          1.1  jruoho         break;
    259          1.1  jruoho     }
    260          1.1  jruoho 
    261          1.1  jruoho     /* Ignore the non-executable opcodes */
    262          1.1  jruoho 
    263          1.1  jruoho     if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
    264          1.1  jruoho     {
    265          1.1  jruoho         return (AE_OK);
    266          1.1  jruoho     }
    267          1.1  jruoho 
    268          1.1  jruoho     switch (OpcodeClass)
    269          1.1  jruoho     {
    270          1.1  jruoho     case AML_CLASS_EXECUTE:
    271          1.1  jruoho     case AML_CLASS_CREATE:
    272          1.1  jruoho     case AML_CLASS_CONTROL:
    273          1.1  jruoho     case AML_CLASS_RETURN_VALUE:
    274          1.1  jruoho 
    275          1.1  jruoho         /* TBD: Change class or fix typechecking for these */
    276          1.1  jruoho 
    277          1.1  jruoho         if ((Op->Asl.AmlOpcode == AML_BUFFER_OP)        ||
    278          1.1  jruoho             (Op->Asl.AmlOpcode == AML_PACKAGE_OP)       ||
    279          1.1  jruoho             (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
    280          1.1  jruoho         {
    281          1.1  jruoho             break;
    282          1.1  jruoho         }
    283          1.1  jruoho 
    284          1.1  jruoho         /* Reverse the runtime argument list */
    285          1.1  jruoho 
    286          1.1  jruoho         RuntimeArgTypes2 = 0;
    287          1.1  jruoho         while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
    288          1.1  jruoho         {
    289          1.1  jruoho             RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
    290          1.1  jruoho             RuntimeArgTypes2 |= ArgType;
    291          1.1  jruoho             INCREMENT_ARG_LIST (RuntimeArgTypes);
    292          1.1  jruoho         }
    293          1.1  jruoho 
    294          1.1  jruoho         while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
    295          1.1  jruoho         {
    296          1.1  jruoho             RequiredBtypes = AnMapArgTypeToBtype (ArgType);
    297          1.1  jruoho 
    298          1.1  jruoho             ThisNodeBtype = AnGetBtype (ArgOp);
    299          1.1  jruoho             if (ThisNodeBtype == ACPI_UINT32_MAX)
    300          1.1  jruoho             {
    301          1.1  jruoho                 goto NextArgument;
    302          1.1  jruoho             }
    303          1.1  jruoho 
    304          1.1  jruoho             /* Examine the arg based on the required type of the arg */
    305          1.1  jruoho 
    306          1.1  jruoho             switch (ArgType)
    307          1.1  jruoho             {
    308          1.1  jruoho             case ARGI_TARGETREF:
    309          1.1  jruoho 
    310          1.1  jruoho                 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
    311          1.1  jruoho                 {
    312          1.1  jruoho                     /* ZERO is the placeholder for "don't store result" */
    313          1.1  jruoho 
    314          1.1  jruoho                     ThisNodeBtype = RequiredBtypes;
    315          1.1  jruoho                     break;
    316          1.1  jruoho                 }
    317          1.1  jruoho 
    318          1.1  jruoho                 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
    319          1.1  jruoho                 {
    320          1.1  jruoho                     /*
    321          1.1  jruoho                      * This is the case where an original reference to a resource
    322          1.1  jruoho                      * descriptor field has been replaced by an (Integer) offset.
    323          1.1  jruoho                      * These named fields are supported at compile-time only;
    324          1.1  jruoho                      * the names are not passed to the interpreter (via the AML).
    325          1.1  jruoho                      */
    326          1.1  jruoho                     if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
    327          1.1  jruoho                         (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
    328          1.1  jruoho                     {
    329          1.1  jruoho                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
    330          1.1  jruoho                     }
    331          1.1  jruoho                     else
    332          1.1  jruoho                     {
    333          1.1  jruoho                         AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
    334          1.1  jruoho                     }
    335          1.1  jruoho                     break;
    336          1.1  jruoho                 }
    337          1.1  jruoho 
    338          1.1  jruoho                 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
    339          1.1  jruoho                     (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
    340          1.1  jruoho                 {
    341          1.1  jruoho                     break;
    342          1.1  jruoho                 }
    343          1.1  jruoho 
    344          1.1  jruoho                 ThisNodeBtype = RequiredBtypes;
    345          1.1  jruoho                 break;
    346          1.1  jruoho 
    347          1.1  jruoho 
    348          1.1  jruoho             case ARGI_REFERENCE:            /* References */
    349          1.1  jruoho             case ARGI_INTEGER_REF:
    350          1.1  jruoho             case ARGI_OBJECT_REF:
    351          1.1  jruoho             case ARGI_DEVICE_REF:
    352          1.1  jruoho 
    353          1.1  jruoho                 switch (ArgOp->Asl.ParseOpcode)
    354          1.1  jruoho                 {
    355          1.1  jruoho                 case PARSEOP_LOCAL0:
    356          1.1  jruoho                 case PARSEOP_LOCAL1:
    357          1.1  jruoho                 case PARSEOP_LOCAL2:
    358          1.1  jruoho                 case PARSEOP_LOCAL3:
    359          1.1  jruoho                 case PARSEOP_LOCAL4:
    360          1.1  jruoho                 case PARSEOP_LOCAL5:
    361          1.1  jruoho                 case PARSEOP_LOCAL6:
    362          1.1  jruoho                 case PARSEOP_LOCAL7:
    363          1.1  jruoho 
    364          1.1  jruoho                     /* TBD: implement analysis of current value (type) of the local */
    365          1.1  jruoho                     /* For now, just treat any local as a typematch */
    366          1.1  jruoho 
    367          1.1  jruoho                     /*ThisNodeBtype = RequiredBtypes;*/
    368          1.1  jruoho                     break;
    369          1.1  jruoho 
    370          1.1  jruoho                 case PARSEOP_ARG0:
    371          1.1  jruoho                 case PARSEOP_ARG1:
    372          1.1  jruoho                 case PARSEOP_ARG2:
    373          1.1  jruoho                 case PARSEOP_ARG3:
    374          1.1  jruoho                 case PARSEOP_ARG4:
    375          1.1  jruoho                 case PARSEOP_ARG5:
    376          1.1  jruoho                 case PARSEOP_ARG6:
    377          1.1  jruoho 
    378          1.1  jruoho                     /* Hard to analyze argument types, sow we won't */
    379          1.1  jruoho                     /* For now, just treat any arg as a typematch */
    380          1.1  jruoho 
    381          1.1  jruoho                     /* ThisNodeBtype = RequiredBtypes; */
    382          1.1  jruoho                     break;
    383          1.1  jruoho 
    384          1.1  jruoho                 case PARSEOP_DEBUG:
    385  1.1.1.2.2.1    yamt 
    386          1.1  jruoho                     break;
    387          1.1  jruoho 
    388          1.1  jruoho                 case PARSEOP_REFOF:
    389          1.1  jruoho                 case PARSEOP_INDEX:
    390          1.1  jruoho                 default:
    391  1.1.1.2.2.1    yamt 
    392          1.1  jruoho                     break;
    393          1.1  jruoho 
    394          1.1  jruoho                 }
    395          1.1  jruoho                 break;
    396          1.1  jruoho 
    397          1.1  jruoho             case ARGI_INTEGER:
    398          1.1  jruoho             default:
    399  1.1.1.2.2.1    yamt 
    400          1.1  jruoho                 break;
    401          1.1  jruoho             }
    402          1.1  jruoho 
    403          1.1  jruoho 
    404          1.1  jruoho             CommonBtypes = ThisNodeBtype & RequiredBtypes;
    405          1.1  jruoho 
    406          1.1  jruoho             if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
    407          1.1  jruoho             {
    408          1.1  jruoho                 if (AnIsInternalMethod (ArgOp))
    409          1.1  jruoho                 {
    410          1.1  jruoho                     return (AE_OK);
    411          1.1  jruoho                 }
    412          1.1  jruoho 
    413          1.1  jruoho                 /* Check a method call for a valid return value */
    414          1.1  jruoho 
    415          1.1  jruoho                 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
    416          1.1  jruoho                     RequiredBtypes, ThisNodeBtype);
    417          1.1  jruoho             }
    418          1.1  jruoho 
    419          1.1  jruoho             /*
    420          1.1  jruoho              * Now check if the actual type(s) match at least one
    421          1.1  jruoho              * bit to the required type
    422          1.1  jruoho              */
    423          1.1  jruoho             else if (!CommonBtypes)
    424          1.1  jruoho             {
    425          1.1  jruoho                 /* No match -- this is a type mismatch error */
    426          1.1  jruoho 
    427          1.1  jruoho                 AnFormatBtype (StringBuffer, ThisNodeBtype);
    428          1.1  jruoho                 AnFormatBtype (StringBuffer2, RequiredBtypes);
    429          1.1  jruoho 
    430  1.1.1.2.2.1    yamt                 snprintf (MsgBuffer, sizeof(MsgBuffer), "[%s] found, %s operator requires [%s]",
    431          1.1  jruoho                             StringBuffer, OpInfo->Name, StringBuffer2);
    432          1.1  jruoho 
    433          1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
    434          1.1  jruoho             }
    435          1.1  jruoho 
    436          1.1  jruoho         NextArgument:
    437          1.1  jruoho             ArgOp = ArgOp->Asl.Next;
    438          1.1  jruoho             INCREMENT_ARG_LIST (RuntimeArgTypes2);
    439          1.1  jruoho         }
    440          1.1  jruoho         break;
    441          1.1  jruoho 
    442          1.1  jruoho     default:
    443  1.1.1.2.2.1    yamt 
    444          1.1  jruoho         break;
    445          1.1  jruoho     }
    446          1.1  jruoho 
    447          1.1  jruoho     return (AE_OK);
    448          1.1  jruoho }
    449          1.1  jruoho 
    450          1.1  jruoho 
    451          1.1  jruoho /*******************************************************************************
    452          1.1  jruoho  *
    453          1.1  jruoho  * FUNCTION:    AnOtherSemanticAnalysisWalkBegin
    454          1.1  jruoho  *
    455          1.1  jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    456          1.1  jruoho  *
    457          1.1  jruoho  * RETURN:      Status
    458          1.1  jruoho  *
    459          1.1  jruoho  * DESCRIPTION: Descending callback for the analysis walk. Checks for
    460          1.1  jruoho  *              miscellaneous issues in the code.
    461          1.1  jruoho  *
    462          1.1  jruoho  ******************************************************************************/
    463          1.1  jruoho 
    464          1.1  jruoho ACPI_STATUS
    465          1.1  jruoho AnOtherSemanticAnalysisWalkBegin (
    466          1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    467          1.1  jruoho     UINT32                  Level,
    468          1.1  jruoho     void                    *Context)
    469          1.1  jruoho {
    470          1.1  jruoho     ACPI_PARSE_OBJECT       *ArgNode;
    471          1.1  jruoho     ACPI_PARSE_OBJECT       *PrevArgNode = NULL;
    472          1.1  jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    473  1.1.1.2.2.1    yamt     ACPI_NAMESPACE_NODE     *Node;
    474          1.1  jruoho 
    475          1.1  jruoho 
    476          1.1  jruoho     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    477          1.1  jruoho 
    478          1.1  jruoho     /*
    479          1.1  jruoho      * Determine if an execution class operator actually does something by
    480          1.1  jruoho      * checking if it has a target and/or the function return value is used.
    481          1.1  jruoho      * (Target is optional, so a standalone statement can actually do nothing.)
    482          1.1  jruoho      */
    483          1.1  jruoho     if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
    484          1.1  jruoho         (OpInfo->Flags & AML_HAS_RETVAL) &&
    485          1.1  jruoho         (!AnIsResultUsed (Op)))
    486          1.1  jruoho     {
    487          1.1  jruoho         if (OpInfo->Flags & AML_HAS_TARGET)
    488          1.1  jruoho         {
    489          1.1  jruoho             /*
    490          1.1  jruoho              * Find the target node, it is always the last child. If the traget
    491          1.1  jruoho              * is not specified in the ASL, a default node of type Zero was
    492          1.1  jruoho              * created by the parser.
    493          1.1  jruoho              */
    494          1.1  jruoho             ArgNode = Op->Asl.Child;
    495          1.1  jruoho             while (ArgNode->Asl.Next)
    496          1.1  jruoho             {
    497          1.1  jruoho                 PrevArgNode = ArgNode;
    498          1.1  jruoho                 ArgNode = ArgNode->Asl.Next;
    499          1.1  jruoho             }
    500          1.1  jruoho 
    501          1.1  jruoho             /* Divide() is the only weird case, it has two targets */
    502          1.1  jruoho 
    503          1.1  jruoho             if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
    504          1.1  jruoho             {
    505          1.1  jruoho                 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
    506          1.1  jruoho                     (PrevArgNode) &&
    507          1.1  jruoho                     (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
    508          1.1  jruoho                 {
    509  1.1.1.2.2.1    yamt                     AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
    510          1.1  jruoho                         Op, Op->Asl.ExternalName);
    511          1.1  jruoho                 }
    512          1.1  jruoho             }
    513          1.1  jruoho             else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
    514          1.1  jruoho             {
    515  1.1.1.2.2.1    yamt                 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
    516          1.1  jruoho                     Op, Op->Asl.ExternalName);
    517          1.1  jruoho             }
    518          1.1  jruoho         }
    519          1.1  jruoho         else
    520          1.1  jruoho         {
    521          1.1  jruoho             /*
    522          1.1  jruoho              * Has no target and the result is not used. Only a couple opcodes
    523          1.1  jruoho              * can have this combination.
    524          1.1  jruoho              */
    525          1.1  jruoho             switch (Op->Asl.ParseOpcode)
    526          1.1  jruoho             {
    527          1.1  jruoho             case PARSEOP_ACQUIRE:
    528          1.1  jruoho             case PARSEOP_WAIT:
    529          1.1  jruoho             case PARSEOP_LOADTABLE:
    530  1.1.1.2.2.1    yamt 
    531          1.1  jruoho                 break;
    532          1.1  jruoho 
    533          1.1  jruoho             default:
    534  1.1.1.2.2.1    yamt 
    535  1.1.1.2.2.1    yamt                 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
    536          1.1  jruoho                     Op, Op->Asl.ExternalName);
    537          1.1  jruoho                 break;
    538          1.1  jruoho             }
    539          1.1  jruoho         }
    540          1.1  jruoho     }
    541          1.1  jruoho 
    542          1.1  jruoho 
    543          1.1  jruoho     /*
    544          1.1  jruoho      * Semantic checks for individual ASL operators
    545          1.1  jruoho      */
    546          1.1  jruoho     switch (Op->Asl.ParseOpcode)
    547          1.1  jruoho     {
    548          1.1  jruoho     case PARSEOP_ACQUIRE:
    549          1.1  jruoho     case PARSEOP_WAIT:
    550          1.1  jruoho         /*
    551          1.1  jruoho          * Emit a warning if the timeout parameter for these operators is not
    552          1.1  jruoho          * ACPI_WAIT_FOREVER, and the result value from the operator is not
    553          1.1  jruoho          * checked, meaning that a timeout could happen, but the code
    554          1.1  jruoho          * would not know about it.
    555          1.1  jruoho          */
    556          1.1  jruoho 
    557          1.1  jruoho         /* First child is the namepath, 2nd child is timeout */
    558          1.1  jruoho 
    559          1.1  jruoho         ArgNode = Op->Asl.Child;
    560          1.1  jruoho         ArgNode = ArgNode->Asl.Next;
    561          1.1  jruoho 
    562          1.1  jruoho         /*
    563          1.1  jruoho          * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
    564          1.1  jruoho          * 0xFFFF or greater
    565          1.1  jruoho          */
    566          1.1  jruoho         if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
    567          1.1  jruoho              (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER))  &&
    568          1.1  jruoho              (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
    569          1.1  jruoho         {
    570          1.1  jruoho             break;
    571          1.1  jruoho         }
    572          1.1  jruoho 
    573          1.1  jruoho         /*
    574          1.1  jruoho          * The operation could timeout. If the return value is not used
    575          1.1  jruoho          * (indicates timeout occurred), issue a warning
    576          1.1  jruoho          */
    577          1.1  jruoho         if (!AnIsResultUsed (Op))
    578          1.1  jruoho         {
    579          1.1  jruoho             AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode,
    580          1.1  jruoho                 Op->Asl.ExternalName);
    581          1.1  jruoho         }
    582          1.1  jruoho         break;
    583          1.1  jruoho 
    584          1.1  jruoho     case PARSEOP_CREATEFIELD:
    585          1.1  jruoho         /*
    586          1.1  jruoho          * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
    587          1.1  jruoho          */
    588          1.1  jruoho         ArgNode = Op->Asl.Child;
    589          1.1  jruoho         ArgNode = ArgNode->Asl.Next;
    590          1.1  jruoho         ArgNode = ArgNode->Asl.Next;
    591          1.1  jruoho 
    592          1.1  jruoho         if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
    593          1.1  jruoho            ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
    594          1.1  jruoho             (ArgNode->Asl.Value.Integer == 0)))
    595          1.1  jruoho         {
    596          1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);
    597          1.1  jruoho         }
    598          1.1  jruoho         break;
    599          1.1  jruoho 
    600  1.1.1.2.2.1    yamt     case PARSEOP_CONNECTION:
    601  1.1.1.2.2.1    yamt         /*
    602  1.1.1.2.2.1    yamt          * Ensure that the referenced operation region has the correct SPACE_ID.
    603  1.1.1.2.2.1    yamt          * From the grammar/parser, we know the parent is a FIELD definition.
    604  1.1.1.2.2.1    yamt          */
    605  1.1.1.2.2.1    yamt         ArgNode = Op->Asl.Parent;       /* Field definition */
    606  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Child;   /* First child is the OpRegion Name */
    607  1.1.1.2.2.1    yamt         Node = ArgNode->Asl.Node;       /* OpRegion namespace node */
    608  1.1.1.2.2.1    yamt 
    609  1.1.1.2.2.1    yamt         ArgNode = Node->Op;             /* OpRegion definition */
    610  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Child;   /* First child is the OpRegion Name */
    611  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Next;    /* Next peer is the SPACE_ID (what we want) */
    612  1.1.1.2.2.1    yamt 
    613  1.1.1.2.2.1    yamt         /*
    614  1.1.1.2.2.1    yamt          * The Connection() operator is only valid for the following operation
    615  1.1.1.2.2.1    yamt          * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
    616  1.1.1.2.2.1    yamt          */
    617  1.1.1.2.2.1    yamt         if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
    618  1.1.1.2.2.1    yamt             (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
    619  1.1.1.2.2.1    yamt         {
    620  1.1.1.2.2.1    yamt             AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
    621  1.1.1.2.2.1    yamt         }
    622  1.1.1.2.2.1    yamt         break;
    623  1.1.1.2.2.1    yamt 
    624  1.1.1.2.2.1    yamt     case PARSEOP_FIELD:
    625  1.1.1.2.2.1    yamt         /*
    626  1.1.1.2.2.1    yamt          * Ensure that fields for GeneralPurposeIo and GenericSerialBus
    627  1.1.1.2.2.1    yamt          * contain at least one Connection() operator
    628  1.1.1.2.2.1    yamt          */
    629  1.1.1.2.2.1    yamt         ArgNode = Op->Asl.Child;        /* 1st child is the OpRegion Name */
    630  1.1.1.2.2.1    yamt         Node = ArgNode->Asl.Node;       /* OpRegion namespace node */
    631  1.1.1.2.2.1    yamt         if (!Node)
    632  1.1.1.2.2.1    yamt         {
    633  1.1.1.2.2.1    yamt             break;
    634  1.1.1.2.2.1    yamt         }
    635  1.1.1.2.2.1    yamt 
    636  1.1.1.2.2.1    yamt         ArgNode = Node->Op;             /* OpRegion definition */
    637  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Child;   /* First child is the OpRegion Name */
    638  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Next;    /* Next peer is the SPACE_ID (what we want) */
    639  1.1.1.2.2.1    yamt 
    640  1.1.1.2.2.1    yamt         /* We are only interested in GeneralPurposeIo and GenericSerialBus */
    641  1.1.1.2.2.1    yamt 
    642  1.1.1.2.2.1    yamt         if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
    643  1.1.1.2.2.1    yamt             (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
    644  1.1.1.2.2.1    yamt         {
    645  1.1.1.2.2.1    yamt             break;
    646  1.1.1.2.2.1    yamt         }
    647  1.1.1.2.2.1    yamt 
    648  1.1.1.2.2.1    yamt         ArgNode = Op->Asl.Child;        /* 1st child is the OpRegion Name */
    649  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Next;    /* AccessType */
    650  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Next;    /* LockRule */
    651  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Next;    /* UpdateRule */
    652  1.1.1.2.2.1    yamt         ArgNode = ArgNode->Asl.Next;    /* Start of FieldUnitList */
    653  1.1.1.2.2.1    yamt 
    654  1.1.1.2.2.1    yamt         /* Walk the FieldUnitList */
    655  1.1.1.2.2.1    yamt 
    656  1.1.1.2.2.1    yamt         while (ArgNode)
    657  1.1.1.2.2.1    yamt         {
    658  1.1.1.2.2.1    yamt             if (ArgNode->Asl.ParseOpcode == PARSEOP_CONNECTION)
    659  1.1.1.2.2.1    yamt             {
    660  1.1.1.2.2.1    yamt                 break;
    661  1.1.1.2.2.1    yamt             }
    662  1.1.1.2.2.1    yamt             else if (ArgNode->Asl.ParseOpcode == PARSEOP_NAMESEG)
    663  1.1.1.2.2.1    yamt             {
    664  1.1.1.2.2.1    yamt                 AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgNode, NULL);
    665  1.1.1.2.2.1    yamt                 break;
    666  1.1.1.2.2.1    yamt             }
    667  1.1.1.2.2.1    yamt 
    668  1.1.1.2.2.1    yamt             ArgNode = ArgNode->Asl.Next;
    669  1.1.1.2.2.1    yamt         }
    670  1.1.1.2.2.1    yamt         break;
    671  1.1.1.2.2.1    yamt 
    672          1.1  jruoho     default:
    673  1.1.1.2.2.1    yamt 
    674          1.1  jruoho         break;
    675          1.1  jruoho     }
    676          1.1  jruoho 
    677          1.1  jruoho     return (AE_OK);
    678          1.1  jruoho }
    679