Home | History | Annotate | Line # | Download | only in compiler
aslmethod.c revision 1.1.1.6
      1      1.1  christos /******************************************************************************
      2      1.1  christos  *
      3      1.1  christos  * Module Name: aslmethod.c - Control method analysis walk
      4      1.1  christos  *
      5      1.1  christos  *****************************************************************************/
      6      1.1  christos 
      7      1.1  christos /*
      8  1.1.1.5  christos  * Copyright (C) 2000 - 2016, Intel Corp.
      9      1.1  christos  * All rights reserved.
     10      1.1  christos  *
     11      1.1  christos  * Redistribution and use in source and binary forms, with or without
     12      1.1  christos  * modification, are permitted provided that the following conditions
     13      1.1  christos  * are met:
     14      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15      1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16      1.1  christos  *    without modification.
     17      1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21      1.1  christos  *    binary redistribution.
     22      1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24      1.1  christos  *    from this software without specific prior written permission.
     25      1.1  christos  *
     26      1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27      1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1  christos  * Software Foundation.
     29      1.1  christos  *
     30      1.1  christos  * NO WARRANTY
     31      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1  christos  */
     43      1.1  christos 
     44      1.1  christos #include "aslcompiler.h"
     45      1.1  christos #include "aslcompiler.y.h"
     46      1.1  christos #include "acparser.h"
     47      1.1  christos #include "amlcode.h"
     48      1.1  christos 
     49      1.1  christos 
     50      1.1  christos #define _COMPONENT          ACPI_COMPILER
     51      1.1  christos         ACPI_MODULE_NAME    ("aslmethod")
     52      1.1  christos 
     53      1.1  christos 
     54      1.1  christos /* Local prototypes */
     55      1.1  christos 
     56  1.1.1.6  christos static void
     57      1.1  christos MtCheckNamedObjectInMethod (
     58      1.1  christos     ACPI_PARSE_OBJECT       *Op,
     59      1.1  christos     ASL_METHOD_INFO         *MethodInfo);
     60      1.1  christos 
     61      1.1  christos 
     62      1.1  christos /*******************************************************************************
     63      1.1  christos  *
     64      1.1  christos  * FUNCTION:    MtMethodAnalysisWalkBegin
     65      1.1  christos  *
     66      1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
     67      1.1  christos  *
     68      1.1  christos  * RETURN:      Status
     69      1.1  christos  *
     70      1.1  christos  * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
     71      1.1  christos  *              1) Initialized local variables
     72      1.1  christos  *              2) Valid arguments
     73      1.1  christos  *              3) Return types
     74      1.1  christos  *
     75      1.1  christos  ******************************************************************************/
     76      1.1  christos 
     77      1.1  christos ACPI_STATUS
     78      1.1  christos MtMethodAnalysisWalkBegin (
     79      1.1  christos     ACPI_PARSE_OBJECT       *Op,
     80      1.1  christos     UINT32                  Level,
     81      1.1  christos     void                    *Context)
     82      1.1  christos {
     83      1.1  christos     ASL_ANALYSIS_WALK_INFO  *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
     84      1.1  christos     ASL_METHOD_INFO         *MethodInfo = WalkInfo->MethodStack;
     85      1.1  christos     ACPI_PARSE_OBJECT       *Next;
     86      1.1  christos     UINT32                  RegisterNumber;
     87      1.1  christos     UINT32                  i;
     88      1.1  christos     char                    LocalName[] = "Local0";
     89      1.1  christos     char                    ArgName[] = "Arg0";
     90      1.1  christos     ACPI_PARSE_OBJECT       *ArgNode;
     91      1.1  christos     ACPI_PARSE_OBJECT       *NextType;
     92      1.1  christos     ACPI_PARSE_OBJECT       *NextParamType;
     93      1.1  christos     UINT8                   ActualArgs = 0;
     94      1.1  christos 
     95      1.1  christos 
     96  1.1.1.6  christos     /* Build cross-reference output file if requested */
     97  1.1.1.6  christos 
     98  1.1.1.6  christos     if (Gbl_CrossReferenceOutput)
     99  1.1.1.6  christos     {
    100  1.1.1.6  christos         OtXrefWalkPart1 (Op, Level, MethodInfo);
    101  1.1.1.6  christos     }
    102  1.1.1.6  christos 
    103      1.1  christos     switch (Op->Asl.ParseOpcode)
    104      1.1  christos     {
    105      1.1  christos     case PARSEOP_METHOD:
    106      1.1  christos 
    107      1.1  christos         TotalMethods++;
    108      1.1  christos 
    109      1.1  christos         /* Create and init method info */
    110      1.1  christos 
    111  1.1.1.5  christos         MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
    112      1.1  christos         MethodInfo->Next = WalkInfo->MethodStack;
    113      1.1  christos         MethodInfo->Op = Op;
    114      1.1  christos 
    115      1.1  christos         WalkInfo->MethodStack = MethodInfo;
    116      1.1  christos 
    117  1.1.1.2  christos         /*
    118  1.1.1.2  christos          * Special handling for _PSx methods. Dependency rules (same scope):
    119  1.1.1.2  christos          *
    120  1.1.1.2  christos          * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3
    121  1.1.1.2  christos          * 2) _PS1/_PS2/_PS3: A _PS0 must exist
    122  1.1.1.2  christos          */
    123  1.1.1.2  christos         if (ACPI_COMPARE_NAME (METHOD_NAME__PS0, Op->Asl.NameSeg))
    124  1.1.1.2  christos         {
    125  1.1.1.2  christos             /* For _PS0, one of _PS1/_PS2/_PS3 must exist */
    126  1.1.1.2  christos 
    127  1.1.1.2  christos             if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) &&
    128  1.1.1.2  christos                 (!ApFindNameInScope (METHOD_NAME__PS2, Op)) &&
    129  1.1.1.2  christos                 (!ApFindNameInScope (METHOD_NAME__PS3, Op)))
    130  1.1.1.2  christos             {
    131  1.1.1.2  christos                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    132  1.1.1.2  christos                     "_PS0 requires one of _PS1/_PS2/_PS3 in same scope");
    133  1.1.1.2  christos             }
    134  1.1.1.2  christos         }
    135  1.1.1.2  christos         else if (
    136  1.1.1.2  christos             ACPI_COMPARE_NAME (METHOD_NAME__PS1, Op->Asl.NameSeg) ||
    137  1.1.1.2  christos             ACPI_COMPARE_NAME (METHOD_NAME__PS2, Op->Asl.NameSeg) ||
    138  1.1.1.2  christos             ACPI_COMPARE_NAME (METHOD_NAME__PS3, Op->Asl.NameSeg))
    139  1.1.1.2  christos         {
    140  1.1.1.2  christos             /* For _PS1/_PS2/_PS3, a _PS0 must exist */
    141  1.1.1.2  christos 
    142  1.1.1.2  christos             if (!ApFindNameInScope (METHOD_NAME__PS0, Op))
    143  1.1.1.2  christos             {
    144  1.1.1.2  christos                 sprintf (MsgBuffer,
    145  1.1.1.2  christos                     "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg);
    146  1.1.1.2  christos 
    147  1.1.1.2  christos                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    148  1.1.1.2  christos                     MsgBuffer);
    149  1.1.1.2  christos             }
    150  1.1.1.2  christos         }
    151  1.1.1.2  christos 
    152  1.1.1.2  christos         /* Get the name node */
    153      1.1  christos 
    154      1.1  christos         Next = Op->Asl.Child;
    155      1.1  christos 
    156      1.1  christos         /* Get the NumArguments node */
    157      1.1  christos 
    158      1.1  christos         Next = Next->Asl.Next;
    159      1.1  christos         MethodInfo->NumArguments = (UINT8)
    160      1.1  christos             (((UINT8) Next->Asl.Value.Integer) & 0x07);
    161      1.1  christos 
    162      1.1  christos         /* Get the SerializeRule and SyncLevel nodes, ignored here */
    163      1.1  christos 
    164      1.1  christos         Next = Next->Asl.Next;
    165      1.1  christos         MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer;
    166      1.1  christos 
    167      1.1  christos         Next = Next->Asl.Next;
    168      1.1  christos         ArgNode = Next;
    169      1.1  christos 
    170      1.1  christos         /* Get the ReturnType node */
    171      1.1  christos 
    172      1.1  christos         Next = Next->Asl.Next;
    173      1.1  christos 
    174      1.1  christos         NextType = Next->Asl.Child;
    175      1.1  christos         while (NextType)
    176      1.1  christos         {
    177      1.1  christos             /* Get and map each of the ReturnTypes */
    178      1.1  christos 
    179      1.1  christos             MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType);
    180      1.1  christos             NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    181      1.1  christos             NextType = NextType->Asl.Next;
    182      1.1  christos         }
    183      1.1  christos 
    184      1.1  christos         /* Get the ParameterType node */
    185      1.1  christos 
    186      1.1  christos         Next = Next->Asl.Next;
    187      1.1  christos 
    188      1.1  christos         NextType = Next->Asl.Child;
    189      1.1  christos         while (NextType)
    190      1.1  christos         {
    191      1.1  christos             if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    192      1.1  christos             {
    193      1.1  christos                 NextParamType = NextType->Asl.Child;
    194      1.1  christos                 while (NextParamType)
    195      1.1  christos                 {
    196  1.1.1.5  christos                     MethodInfo->ValidArgTypes[ActualArgs] |=
    197  1.1.1.5  christos                         AnMapObjTypeToBtype (NextParamType);
    198  1.1.1.5  christos 
    199      1.1  christos                     NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    200      1.1  christos                     NextParamType = NextParamType->Asl.Next;
    201      1.1  christos                 }
    202      1.1  christos             }
    203      1.1  christos             else
    204      1.1  christos             {
    205      1.1  christos                 MethodInfo->ValidArgTypes[ActualArgs] =
    206      1.1  christos                     AnMapObjTypeToBtype (NextType);
    207  1.1.1.5  christos 
    208      1.1  christos                 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    209      1.1  christos                 ActualArgs++;
    210      1.1  christos             }
    211      1.1  christos 
    212      1.1  christos             NextType = NextType->Asl.Next;
    213      1.1  christos         }
    214      1.1  christos 
    215      1.1  christos         if ((MethodInfo->NumArguments) &&
    216      1.1  christos             (MethodInfo->NumArguments != ActualArgs))
    217      1.1  christos         {
    218      1.1  christos             /* error: Param list did not match number of args */
    219      1.1  christos         }
    220      1.1  christos 
    221      1.1  christos         /* Allow numarguments == 0 for Function() */
    222      1.1  christos 
    223      1.1  christos         if ((!MethodInfo->NumArguments) && (ActualArgs))
    224      1.1  christos         {
    225      1.1  christos             MethodInfo->NumArguments = ActualArgs;
    226      1.1  christos             ArgNode->Asl.Value.Integer |= ActualArgs;
    227      1.1  christos         }
    228      1.1  christos 
    229      1.1  christos         /*
    230      1.1  christos          * Actual arguments are initialized at method entry.
    231      1.1  christos          * All other ArgX "registers" can be used as locals, so we
    232      1.1  christos          * track their initialization.
    233      1.1  christos          */
    234      1.1  christos         for (i = 0; i < MethodInfo->NumArguments; i++)
    235      1.1  christos         {
    236      1.1  christos             MethodInfo->ArgInitialized[i] = TRUE;
    237      1.1  christos         }
    238      1.1  christos         break;
    239      1.1  christos 
    240      1.1  christos     case PARSEOP_METHODCALL:
    241      1.1  christos 
    242      1.1  christos         if (MethodInfo &&
    243      1.1  christos            (Op->Asl.Node == MethodInfo->Op->Asl.Node))
    244      1.1  christos         {
    245      1.1  christos             AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
    246      1.1  christos         }
    247      1.1  christos         break;
    248      1.1  christos 
    249      1.1  christos     case PARSEOP_LOCAL0:
    250      1.1  christos     case PARSEOP_LOCAL1:
    251      1.1  christos     case PARSEOP_LOCAL2:
    252      1.1  christos     case PARSEOP_LOCAL3:
    253      1.1  christos     case PARSEOP_LOCAL4:
    254      1.1  christos     case PARSEOP_LOCAL5:
    255      1.1  christos     case PARSEOP_LOCAL6:
    256      1.1  christos     case PARSEOP_LOCAL7:
    257      1.1  christos 
    258      1.1  christos         if (!MethodInfo)
    259      1.1  christos         {
    260      1.1  christos             /*
    261      1.1  christos              * Local was used outside a control method, or there was an error
    262      1.1  christos              * in the method declaration.
    263      1.1  christos              */
    264  1.1.1.5  christos             AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
    265  1.1.1.5  christos                 Op, Op->Asl.ExternalName);
    266      1.1  christos             return (AE_ERROR);
    267      1.1  christos         }
    268      1.1  christos 
    269  1.1.1.4  christos         RegisterNumber = (Op->Asl.AmlOpcode & 0x0007);
    270      1.1  christos 
    271      1.1  christos         /*
    272      1.1  christos          * If the local is being used as a target, mark the local
    273      1.1  christos          * initialized
    274      1.1  christos          */
    275      1.1  christos         if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    276      1.1  christos         {
    277      1.1  christos             MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
    278      1.1  christos         }
    279      1.1  christos 
    280      1.1  christos         /*
    281      1.1  christos          * Otherwise, this is a reference, check if the local
    282      1.1  christos          * has been previously initialized.
    283      1.1  christos          *
    284      1.1  christos          * The only operator that accepts an uninitialized value is ObjectType()
    285      1.1  christos          */
    286      1.1  christos         else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
    287      1.1  christos                  (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
    288      1.1  christos         {
    289      1.1  christos             LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
    290      1.1  christos             AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
    291      1.1  christos         }
    292      1.1  christos         break;
    293      1.1  christos 
    294      1.1  christos     case PARSEOP_ARG0:
    295      1.1  christos     case PARSEOP_ARG1:
    296      1.1  christos     case PARSEOP_ARG2:
    297      1.1  christos     case PARSEOP_ARG3:
    298      1.1  christos     case PARSEOP_ARG4:
    299      1.1  christos     case PARSEOP_ARG5:
    300      1.1  christos     case PARSEOP_ARG6:
    301      1.1  christos 
    302      1.1  christos         if (!MethodInfo)
    303      1.1  christos         {
    304      1.1  christos             /*
    305      1.1  christos              * Arg was used outside a control method, or there was an error
    306      1.1  christos              * in the method declaration.
    307      1.1  christos              */
    308  1.1.1.5  christos             AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
    309  1.1.1.5  christos                 Op, Op->Asl.ExternalName);
    310      1.1  christos             return (AE_ERROR);
    311      1.1  christos         }
    312      1.1  christos 
    313      1.1  christos         RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
    314      1.1  christos         ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
    315      1.1  christos 
    316      1.1  christos         /*
    317      1.1  christos          * If the Arg is being used as a target, mark the local
    318      1.1  christos          * initialized
    319      1.1  christos          */
    320      1.1  christos         if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    321      1.1  christos         {
    322      1.1  christos             MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
    323      1.1  christos         }
    324      1.1  christos 
    325      1.1  christos         /*
    326      1.1  christos          * Otherwise, this is a reference, check if the Arg
    327      1.1  christos          * has been previously initialized.
    328      1.1  christos          *
    329      1.1  christos          * The only operator that accepts an uninitialized value is ObjectType()
    330      1.1  christos          */
    331      1.1  christos         else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
    332  1.1.1.5  christos             (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
    333      1.1  christos         {
    334      1.1  christos             AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
    335      1.1  christos         }
    336      1.1  christos 
    337      1.1  christos         /* Flag this arg if it is not a "real" argument to the method */
    338      1.1  christos 
    339      1.1  christos         if (RegisterNumber >= MethodInfo->NumArguments)
    340      1.1  christos         {
    341      1.1  christos             AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
    342      1.1  christos         }
    343      1.1  christos         break;
    344      1.1  christos 
    345      1.1  christos     case PARSEOP_RETURN:
    346      1.1  christos 
    347      1.1  christos         if (!MethodInfo)
    348      1.1  christos         {
    349      1.1  christos             /*
    350      1.1  christos              * Probably was an error in the method declaration,
    351      1.1  christos              * no additional error here
    352      1.1  christos              */
    353      1.1  christos             ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
    354      1.1  christos             return (AE_ERROR);
    355      1.1  christos         }
    356      1.1  christos 
    357      1.1  christos         /*
    358      1.1  christos          * A child indicates a possible return value. A simple Return or
    359      1.1  christos          * Return() is marked with NODE_IS_NULL_RETURN by the parser so
    360      1.1  christos          * that it is not counted as a "real" return-with-value, although
    361      1.1  christos          * the AML code that is actually emitted is Return(0). The AML
    362      1.1  christos          * definition of Return has a required parameter, so we are
    363      1.1  christos          * forced to convert a null return to Return(0).
    364      1.1  christos          */
    365      1.1  christos         if ((Op->Asl.Child) &&
    366      1.1  christos             (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
    367      1.1  christos             (!(Op->Asl.Child->Asl.CompileFlags & NODE_IS_NULL_RETURN)))
    368      1.1  christos         {
    369      1.1  christos             MethodInfo->NumReturnWithValue++;
    370      1.1  christos         }
    371      1.1  christos         else
    372      1.1  christos         {
    373      1.1  christos             MethodInfo->NumReturnNoValue++;
    374      1.1  christos         }
    375      1.1  christos         break;
    376      1.1  christos 
    377      1.1  christos     case PARSEOP_BREAK:
    378      1.1  christos     case PARSEOP_CONTINUE:
    379      1.1  christos 
    380      1.1  christos         Next = Op->Asl.Parent;
    381      1.1  christos         while (Next)
    382      1.1  christos         {
    383      1.1  christos             if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
    384      1.1  christos             {
    385      1.1  christos                 break;
    386      1.1  christos             }
    387      1.1  christos             Next = Next->Asl.Parent;
    388      1.1  christos         }
    389      1.1  christos 
    390      1.1  christos         if (!Next)
    391      1.1  christos         {
    392      1.1  christos             AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
    393      1.1  christos         }
    394      1.1  christos         break;
    395      1.1  christos 
    396      1.1  christos     case PARSEOP_STALL:
    397      1.1  christos 
    398      1.1  christos         /* We can range check if the argument is an integer */
    399      1.1  christos 
    400      1.1  christos         if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
    401      1.1  christos             (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
    402      1.1  christos         {
    403      1.1  christos             AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
    404      1.1  christos         }
    405      1.1  christos         break;
    406      1.1  christos 
    407      1.1  christos     case PARSEOP_DEVICE:
    408  1.1.1.2  christos 
    409  1.1.1.6  christos         if (!ApFindNameInDeviceTree (METHOD_NAME__HID, Op) &&
    410  1.1.1.6  christos             !ApFindNameInDeviceTree (METHOD_NAME__ADR, Op))
    411  1.1.1.2  christos         {
    412  1.1.1.2  christos             AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    413  1.1.1.2  christos                 "Device object requires a _HID or _ADR in same scope");
    414  1.1.1.2  christos         }
    415  1.1.1.2  christos         break;
    416  1.1.1.2  christos 
    417      1.1  christos     case PARSEOP_EVENT:
    418      1.1  christos     case PARSEOP_MUTEX:
    419      1.1  christos     case PARSEOP_OPERATIONREGION:
    420      1.1  christos     case PARSEOP_POWERRESOURCE:
    421      1.1  christos     case PARSEOP_PROCESSOR:
    422      1.1  christos     case PARSEOP_THERMALZONE:
    423      1.1  christos 
    424      1.1  christos         /*
    425      1.1  christos          * The first operand is a name to be created in the namespace.
    426      1.1  christos          * Check against the reserved list.
    427      1.1  christos          */
    428      1.1  christos         i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
    429      1.1  christos         if (i < ACPI_VALID_RESERVED_NAME_MAX)
    430      1.1  christos         {
    431  1.1.1.5  christos             AslError (ASL_ERROR, ASL_MSG_RESERVED_USE,
    432  1.1.1.5  christos                 Op, Op->Asl.ExternalName);
    433      1.1  christos         }
    434      1.1  christos         break;
    435      1.1  christos 
    436      1.1  christos     case PARSEOP_NAME:
    437      1.1  christos 
    438      1.1  christos         /* Typecheck any predefined names statically defined with Name() */
    439      1.1  christos 
    440      1.1  christos         ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
    441      1.1  christos 
    442      1.1  christos         /* Special typechecking for _HID */
    443      1.1  christos 
    444  1.1.1.4  christos         if (!strcmp (METHOD_NAME__HID, Op->Asl.NameSeg))
    445      1.1  christos         {
    446      1.1  christos             Next = Op->Asl.Child->Asl.Next;
    447      1.1  christos             AnCheckId (Next, ASL_TYPE_HID);
    448      1.1  christos         }
    449      1.1  christos 
    450      1.1  christos         /* Special typechecking for _CID */
    451      1.1  christos 
    452  1.1.1.4  christos         else if (!strcmp (METHOD_NAME__CID, Op->Asl.NameSeg))
    453      1.1  christos         {
    454      1.1  christos             Next = Op->Asl.Child->Asl.Next;
    455      1.1  christos 
    456      1.1  christos             if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
    457      1.1  christos                 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
    458      1.1  christos             {
    459      1.1  christos                 Next = Next->Asl.Child;
    460      1.1  christos                 while (Next)
    461      1.1  christos                 {
    462      1.1  christos                     AnCheckId (Next, ASL_TYPE_CID);
    463      1.1  christos                     Next = Next->Asl.Next;
    464      1.1  christos                 }
    465      1.1  christos             }
    466      1.1  christos             else
    467      1.1  christos             {
    468      1.1  christos                 AnCheckId (Next, ASL_TYPE_CID);
    469      1.1  christos             }
    470      1.1  christos         }
    471  1.1.1.2  christos 
    472      1.1  christos         break;
    473      1.1  christos 
    474      1.1  christos     default:
    475      1.1  christos 
    476      1.1  christos         break;
    477      1.1  christos     }
    478      1.1  christos 
    479      1.1  christos     /* Check for named object creation within a non-serialized method */
    480      1.1  christos 
    481      1.1  christos     MtCheckNamedObjectInMethod (Op, MethodInfo);
    482      1.1  christos     return (AE_OK);
    483      1.1  christos }
    484      1.1  christos 
    485      1.1  christos 
    486      1.1  christos /*******************************************************************************
    487      1.1  christos  *
    488      1.1  christos  * FUNCTION:    MtCheckNamedObjectInMethod
    489      1.1  christos  *
    490      1.1  christos  * PARAMETERS:  Op                  - Current parser op
    491      1.1  christos  *              MethodInfo          - Info for method being parsed
    492      1.1  christos  *
    493      1.1  christos  * RETURN:      None
    494      1.1  christos  *
    495      1.1  christos  * DESCRIPTION: Detect if a non-serialized method is creating a named object,
    496      1.1  christos  *              which could possibly cause problems if two threads execute
    497      1.1  christos  *              the method concurrently. Emit a remark in this case.
    498      1.1  christos  *
    499      1.1  christos  ******************************************************************************/
    500      1.1  christos 
    501  1.1.1.6  christos static void
    502      1.1  christos MtCheckNamedObjectInMethod (
    503      1.1  christos     ACPI_PARSE_OBJECT       *Op,
    504      1.1  christos     ASL_METHOD_INFO         *MethodInfo)
    505      1.1  christos {
    506      1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    507      1.1  christos 
    508      1.1  christos 
    509  1.1.1.5  christos     /* We don't care about actual method declarations or scopes */
    510      1.1  christos 
    511  1.1.1.5  christos     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) ||
    512  1.1.1.5  christos         (Op->Asl.AmlOpcode == AML_SCOPE_OP))
    513      1.1  christos     {
    514      1.1  christos         return;
    515      1.1  christos     }
    516      1.1  christos 
    517      1.1  christos     /* Determine if we are creating a named object */
    518      1.1  christos 
    519      1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    520      1.1  christos     if (OpInfo->Class == AML_CLASS_NAMED_OBJECT)
    521      1.1  christos     {
    522      1.1  christos         /*
    523      1.1  christos          * If we have a named object created within a non-serialized method,
    524      1.1  christos          * emit a remark that the method should be serialized.
    525      1.1  christos          *
    526      1.1  christos          * Reason: If a thread blocks within the method for any reason, and
    527      1.1  christos          * another thread enters the method, the method will fail because an
    528      1.1  christos          * attempt will be made to create the same object twice.
    529      1.1  christos          */
    530      1.1  christos         if (MethodInfo && !MethodInfo->ShouldBeSerialized)
    531      1.1  christos         {
    532      1.1  christos             AslError (ASL_REMARK, ASL_MSG_SERIALIZED_REQUIRED, MethodInfo->Op,
    533      1.1  christos                 "due to creation of named objects within");
    534      1.1  christos 
    535      1.1  christos             /* Emit message only ONCE per method */
    536      1.1  christos 
    537      1.1  christos             MethodInfo->ShouldBeSerialized = TRUE;
    538      1.1  christos         }
    539      1.1  christos     }
    540      1.1  christos }
    541      1.1  christos 
    542      1.1  christos 
    543      1.1  christos /*******************************************************************************
    544      1.1  christos  *
    545      1.1  christos  * FUNCTION:    MtMethodAnalysisWalkEnd
    546      1.1  christos  *
    547      1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
    548      1.1  christos  *
    549      1.1  christos  * RETURN:      Status
    550      1.1  christos  *
    551      1.1  christos  * DESCRIPTION: Ascending callback for analysis walk. Complete method
    552      1.1  christos  *              return analysis.
    553      1.1  christos  *
    554      1.1  christos  ******************************************************************************/
    555      1.1  christos 
    556      1.1  christos ACPI_STATUS
    557      1.1  christos MtMethodAnalysisWalkEnd (
    558      1.1  christos     ACPI_PARSE_OBJECT       *Op,
    559      1.1  christos     UINT32                  Level,
    560      1.1  christos     void                    *Context)
    561      1.1  christos {
    562      1.1  christos     ASL_ANALYSIS_WALK_INFO  *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
    563      1.1  christos     ASL_METHOD_INFO         *MethodInfo = WalkInfo->MethodStack;
    564      1.1  christos 
    565      1.1  christos 
    566      1.1  christos     switch (Op->Asl.ParseOpcode)
    567      1.1  christos     {
    568      1.1  christos     case PARSEOP_METHOD:
    569      1.1  christos     case PARSEOP_RETURN:
    570      1.1  christos 
    571      1.1  christos         if (!MethodInfo)
    572      1.1  christos         {
    573      1.1  christos             printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
    574      1.1  christos             AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
    575      1.1  christos                 "No method info for this method");
    576      1.1  christos 
    577      1.1  christos             CmCleanupAndExit ();
    578      1.1  christos             return (AE_AML_INTERNAL);
    579      1.1  christos         }
    580      1.1  christos         break;
    581      1.1  christos 
    582      1.1  christos     default:
    583      1.1  christos 
    584      1.1  christos         break;
    585      1.1  christos     }
    586      1.1  christos 
    587      1.1  christos     switch (Op->Asl.ParseOpcode)
    588      1.1  christos     {
    589      1.1  christos     case PARSEOP_METHOD:
    590      1.1  christos 
    591      1.1  christos         WalkInfo->MethodStack = MethodInfo->Next;
    592      1.1  christos 
    593      1.1  christos         /*
    594      1.1  christos          * Check if there is no return statement at the end of the
    595      1.1  christos          * method AND we can actually get there -- i.e., the execution
    596      1.1  christos          * of the method can possibly terminate without a return statement.
    597      1.1  christos          */
    598      1.1  christos         if ((!AnLastStatementIsReturn (Op)) &&
    599      1.1  christos             (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT)))
    600      1.1  christos         {
    601      1.1  christos             /*
    602      1.1  christos              * No return statement, and execution can possibly exit
    603      1.1  christos              * via this path. This is equivalent to Return ()
    604      1.1  christos              */
    605      1.1  christos             MethodInfo->NumReturnNoValue++;
    606      1.1  christos         }
    607      1.1  christos 
    608      1.1  christos         /*
    609      1.1  christos          * Check for case where some return statements have a return value
    610      1.1  christos          * and some do not. Exit without a return statement is a return with
    611      1.1  christos          * no value
    612      1.1  christos          */
    613      1.1  christos         if (MethodInfo->NumReturnNoValue &&
    614      1.1  christos             MethodInfo->NumReturnWithValue)
    615      1.1  christos         {
    616      1.1  christos             AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
    617      1.1  christos                 Op->Asl.ExternalName);
    618      1.1  christos         }
    619      1.1  christos 
    620      1.1  christos         /*
    621      1.1  christos          * If there are any RETURN() statements with no value, or there is a
    622      1.1  christos          * control path that allows the method to exit without a return value,
    623      1.1  christos          * we mark the method as a method that does not return a value. This
    624      1.1  christos          * knowledge can be used to check method invocations that expect a
    625      1.1  christos          * returned value.
    626      1.1  christos          */
    627      1.1  christos         if (MethodInfo->NumReturnNoValue)
    628      1.1  christos         {
    629      1.1  christos             if (MethodInfo->NumReturnWithValue)
    630      1.1  christos             {
    631      1.1  christos                 Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL;
    632      1.1  christos             }
    633      1.1  christos             else
    634      1.1  christos             {
    635      1.1  christos                 Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL;
    636      1.1  christos             }
    637      1.1  christos         }
    638      1.1  christos 
    639      1.1  christos         /*
    640      1.1  christos          * Check predefined method names for correct return behavior
    641      1.1  christos          * and correct number of arguments. Also, some special checks
    642      1.1  christos          * For GPE and _REG methods.
    643      1.1  christos          */
    644      1.1  christos         if (ApCheckForPredefinedMethod (Op, MethodInfo))
    645      1.1  christos         {
    646      1.1  christos             /* Special check for two names like _L01 and _E01 in same scope */
    647      1.1  christos 
    648      1.1  christos             ApCheckForGpeNameConflict (Op);
    649      1.1  christos 
    650      1.1  christos             /*
    651      1.1  christos              * Special check for _REG: Must have an operation region definition
    652      1.1  christos              * within the same scope!
    653      1.1  christos              */
    654      1.1  christos             ApCheckRegMethod (Op);
    655      1.1  christos         }
    656      1.1  christos 
    657      1.1  christos         ACPI_FREE (MethodInfo);
    658      1.1  christos         break;
    659      1.1  christos 
    660      1.1  christos     case PARSEOP_NAME:
    661      1.1  christos 
    662      1.1  christos          /* Special check for two names like _L01 and _E01 in same scope */
    663      1.1  christos 
    664      1.1  christos         ApCheckForGpeNameConflict (Op);
    665      1.1  christos         break;
    666      1.1  christos 
    667      1.1  christos     case PARSEOP_RETURN:
    668      1.1  christos 
    669      1.1  christos         /*
    670      1.1  christos          * If the parent is a predefined method name, attempt to typecheck
    671      1.1  christos          * the return value. Only static types can be validated.
    672      1.1  christos          */
    673      1.1  christos         ApCheckPredefinedReturnValue (Op, MethodInfo);
    674      1.1  christos 
    675      1.1  christos         /*
    676      1.1  christos          * The parent block does not "exit" and continue execution -- the
    677      1.1  christos          * method is terminated here with the Return() statement.
    678      1.1  christos          */
    679      1.1  christos         Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
    680      1.1  christos 
    681      1.1  christos         /* Used in the "typing" pass later */
    682      1.1  christos 
    683      1.1  christos         Op->Asl.ParentMethod = MethodInfo->Op;
    684      1.1  christos 
    685      1.1  christos         /*
    686      1.1  christos          * If there is a peer node after the return statement, then this
    687      1.1  christos          * node is unreachable code -- i.e., it won't be executed because of
    688      1.1  christos          * the preceding Return() statement.
    689      1.1  christos          */
    690      1.1  christos         if (Op->Asl.Next)
    691      1.1  christos         {
    692  1.1.1.5  christos             AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE,
    693  1.1.1.5  christos                 Op->Asl.Next, NULL);
    694      1.1  christos         }
    695      1.1  christos         break;
    696      1.1  christos 
    697      1.1  christos     case PARSEOP_IF:
    698      1.1  christos 
    699      1.1  christos         if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
    700      1.1  christos             (Op->Asl.Next) &&
    701      1.1  christos             (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
    702      1.1  christos         {
    703      1.1  christos             /*
    704      1.1  christos              * This IF has a corresponding ELSE. The IF block has no exit,
    705      1.1  christos              * (it contains an unconditional Return)
    706      1.1  christos              * mark the ELSE block to remember this fact.
    707      1.1  christos              */
    708      1.1  christos             Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT;
    709      1.1  christos         }
    710      1.1  christos         break;
    711      1.1  christos 
    712      1.1  christos     case PARSEOP_ELSE:
    713      1.1  christos 
    714      1.1  christos         if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
    715      1.1  christos             (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT))
    716      1.1  christos         {
    717      1.1  christos             /*
    718      1.1  christos              * This ELSE block has no exit and the corresponding IF block
    719      1.1  christos              * has no exit either. Therefore, the parent node has no exit.
    720      1.1  christos              */
    721      1.1  christos             Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
    722      1.1  christos         }
    723      1.1  christos         break;
    724      1.1  christos 
    725      1.1  christos 
    726      1.1  christos     default:
    727      1.1  christos 
    728      1.1  christos         if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
    729      1.1  christos             (Op->Asl.Parent))
    730      1.1  christos         {
    731      1.1  christos             /* If this node has no exit, then the parent has no exit either */
    732      1.1  christos 
    733      1.1  christos             Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
    734      1.1  christos         }
    735      1.1  christos         break;
    736      1.1  christos     }
    737      1.1  christos 
    738      1.1  christos     return (AE_OK);
    739      1.1  christos }
    740