Home | History | Annotate | Line # | Download | only in compiler
aslmethod.c revision 1.1.1.17
      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.16  christos  * Copyright (C) 2000 - 2021, 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.1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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.1.14  christos #include "acnamesp.h"
     47       1.1  christos #include "acparser.h"
     48       1.1  christos #include "amlcode.h"
     49       1.1  christos 
     50       1.1  christos 
     51       1.1  christos #define _COMPONENT          ACPI_COMPILER
     52       1.1  christos         ACPI_MODULE_NAME    ("aslmethod")
     53       1.1  christos 
     54       1.1  christos 
     55       1.1  christos /* Local prototypes */
     56       1.1  christos 
     57   1.1.1.6  christos static void
     58       1.1  christos MtCheckNamedObjectInMethod (
     59       1.1  christos     ACPI_PARSE_OBJECT       *Op,
     60       1.1  christos     ASL_METHOD_INFO         *MethodInfo);
     61       1.1  christos 
     62  1.1.1.14  christos static void
     63  1.1.1.14  christos MtCheckStaticOperationRegionInMethod (
     64  1.1.1.14  christos     ACPI_PARSE_OBJECT       *Op);
     65  1.1.1.14  christos 
     66       1.1  christos 
     67       1.1  christos /*******************************************************************************
     68       1.1  christos  *
     69       1.1  christos  * FUNCTION:    MtMethodAnalysisWalkBegin
     70       1.1  christos  *
     71       1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
     72       1.1  christos  *
     73       1.1  christos  * RETURN:      Status
     74       1.1  christos  *
     75       1.1  christos  * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
     76       1.1  christos  *              1) Initialized local variables
     77       1.1  christos  *              2) Valid arguments
     78       1.1  christos  *              3) Return types
     79       1.1  christos  *
     80       1.1  christos  ******************************************************************************/
     81       1.1  christos 
     82       1.1  christos ACPI_STATUS
     83       1.1  christos MtMethodAnalysisWalkBegin (
     84       1.1  christos     ACPI_PARSE_OBJECT       *Op,
     85       1.1  christos     UINT32                  Level,
     86       1.1  christos     void                    *Context)
     87       1.1  christos {
     88       1.1  christos     ASL_ANALYSIS_WALK_INFO  *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
     89       1.1  christos     ASL_METHOD_INFO         *MethodInfo = WalkInfo->MethodStack;
     90       1.1  christos     ACPI_PARSE_OBJECT       *Next;
     91       1.1  christos     UINT32                  RegisterNumber;
     92       1.1  christos     UINT32                  i;
     93       1.1  christos     char                    LocalName[] = "Local0";
     94       1.1  christos     char                    ArgName[] = "Arg0";
     95       1.1  christos     ACPI_PARSE_OBJECT       *ArgNode;
     96       1.1  christos     ACPI_PARSE_OBJECT       *NextType;
     97       1.1  christos     UINT8                   ActualArgs = 0;
     98  1.1.1.13  christos     BOOLEAN                 HidExists;
     99  1.1.1.13  christos     BOOLEAN                 AdrExists;
    100  1.1.1.17  christos     BOOLEAN                 PrsExists;
    101  1.1.1.17  christos     BOOLEAN                 CrsExists;
    102  1.1.1.17  christos     BOOLEAN                 SrsExists;
    103  1.1.1.17  christos     BOOLEAN                 DisExists;
    104       1.1  christos 
    105       1.1  christos 
    106   1.1.1.6  christos     /* Build cross-reference output file if requested */
    107   1.1.1.6  christos 
    108  1.1.1.11  christos     if (AslGbl_CrossReferenceOutput)
    109   1.1.1.6  christos     {
    110   1.1.1.6  christos         OtXrefWalkPart1 (Op, Level, MethodInfo);
    111   1.1.1.6  christos     }
    112   1.1.1.6  christos 
    113       1.1  christos     switch (Op->Asl.ParseOpcode)
    114       1.1  christos     {
    115       1.1  christos     case PARSEOP_METHOD:
    116       1.1  christos 
    117  1.1.1.11  christos         AslGbl_TotalMethods++;
    118       1.1  christos 
    119       1.1  christos         /* Create and init method info */
    120       1.1  christos 
    121   1.1.1.5  christos         MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
    122       1.1  christos         MethodInfo->Next = WalkInfo->MethodStack;
    123       1.1  christos         MethodInfo->Op = Op;
    124       1.1  christos 
    125       1.1  christos         WalkInfo->MethodStack = MethodInfo;
    126       1.1  christos 
    127   1.1.1.2  christos         /*
    128   1.1.1.2  christos          * Special handling for _PSx methods. Dependency rules (same scope):
    129   1.1.1.2  christos          *
    130   1.1.1.2  christos          * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3
    131   1.1.1.2  christos          * 2) _PS1/_PS2/_PS3: A _PS0 must exist
    132   1.1.1.2  christos          */
    133  1.1.1.12  christos         if (ACPI_COMPARE_NAMESEG (METHOD_NAME__PS0, Op->Asl.NameSeg))
    134   1.1.1.2  christos         {
    135   1.1.1.2  christos             /* For _PS0, one of _PS1/_PS2/_PS3 must exist */
    136   1.1.1.2  christos 
    137   1.1.1.2  christos             if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) &&
    138   1.1.1.2  christos                 (!ApFindNameInScope (METHOD_NAME__PS2, Op)) &&
    139   1.1.1.2  christos                 (!ApFindNameInScope (METHOD_NAME__PS3, Op)))
    140   1.1.1.2  christos             {
    141   1.1.1.2  christos                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    142   1.1.1.2  christos                     "_PS0 requires one of _PS1/_PS2/_PS3 in same scope");
    143   1.1.1.2  christos             }
    144   1.1.1.2  christos         }
    145   1.1.1.2  christos         else if (
    146  1.1.1.12  christos             ACPI_COMPARE_NAMESEG (METHOD_NAME__PS1, Op->Asl.NameSeg) ||
    147  1.1.1.12  christos             ACPI_COMPARE_NAMESEG (METHOD_NAME__PS2, Op->Asl.NameSeg) ||
    148  1.1.1.12  christos             ACPI_COMPARE_NAMESEG (METHOD_NAME__PS3, Op->Asl.NameSeg))
    149   1.1.1.2  christos         {
    150   1.1.1.2  christos             /* For _PS1/_PS2/_PS3, a _PS0 must exist */
    151   1.1.1.2  christos 
    152   1.1.1.2  christos             if (!ApFindNameInScope (METHOD_NAME__PS0, Op))
    153   1.1.1.2  christos             {
    154  1.1.1.11  christos                 sprintf (AslGbl_MsgBuffer,
    155   1.1.1.2  christos                     "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg);
    156   1.1.1.2  christos 
    157   1.1.1.2  christos                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    158  1.1.1.11  christos                     AslGbl_MsgBuffer);
    159   1.1.1.2  christos             }
    160   1.1.1.2  christos         }
    161   1.1.1.2  christos 
    162   1.1.1.2  christos         /* Get the name node */
    163       1.1  christos 
    164       1.1  christos         Next = Op->Asl.Child;
    165       1.1  christos 
    166       1.1  christos         /* Get the NumArguments node */
    167       1.1  christos 
    168       1.1  christos         Next = Next->Asl.Next;
    169       1.1  christos         MethodInfo->NumArguments = (UINT8)
    170       1.1  christos             (((UINT8) Next->Asl.Value.Integer) & 0x07);
    171       1.1  christos 
    172       1.1  christos         /* Get the SerializeRule and SyncLevel nodes, ignored here */
    173       1.1  christos 
    174       1.1  christos         Next = Next->Asl.Next;
    175       1.1  christos         MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer;
    176       1.1  christos 
    177       1.1  christos         Next = Next->Asl.Next;
    178       1.1  christos         ArgNode = Next;
    179       1.1  christos 
    180       1.1  christos         /* Get the ReturnType node */
    181       1.1  christos 
    182       1.1  christos         Next = Next->Asl.Next;
    183       1.1  christos 
    184       1.1  christos         NextType = Next->Asl.Child;
    185       1.1  christos 
    186  1.1.1.14  christos         MethodInfo->ValidReturnTypes = MtProcessTypeOp (NextType);
    187  1.1.1.16  christos         Op->Asl.AcpiBtype |= MethodInfo->ValidReturnTypes;
    188       1.1  christos 
    189       1.1  christos         /* Get the ParameterType node */
    190       1.1  christos 
    191       1.1  christos         Next = Next->Asl.Next;
    192       1.1  christos 
    193       1.1  christos         NextType = Next->Asl.Child;
    194  1.1.1.14  christos         if (!NextType)
    195       1.1  christos         {
    196  1.1.1.14  christos             /*
    197  1.1.1.14  christos              * The optional parameter types list was omitted  at the source
    198  1.1.1.14  christos              * level. Use the Argument count parameter instead.
    199  1.1.1.14  christos              */
    200  1.1.1.14  christos             ActualArgs = MethodInfo->NumArguments;
    201  1.1.1.14  christos         }
    202  1.1.1.14  christos         else
    203  1.1.1.14  christos         {
    204  1.1.1.14  christos             ActualArgs = MtProcessParameterTypeList (NextType,
    205  1.1.1.14  christos                 MethodInfo->ValidArgTypes);
    206  1.1.1.15  christos             MethodInfo->NumArguments = ActualArgs;
    207  1.1.1.15  christos             ArgNode->Asl.Value.Integer |= ActualArgs;
    208       1.1  christos         }
    209       1.1  christos 
    210       1.1  christos         if ((MethodInfo->NumArguments) &&
    211       1.1  christos             (MethodInfo->NumArguments != ActualArgs))
    212       1.1  christos         {
    213  1.1.1.14  christos             sprintf (AslGbl_MsgBuffer,
    214  1.1.1.14  christos                 "Length = %u", ActualArgs);
    215  1.1.1.14  christos             AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_MISMATCH,
    216  1.1.1.14  christos                 Op->Asl.Child->Asl.Next, AslGbl_MsgBuffer);
    217       1.1  christos         }
    218       1.1  christos 
    219       1.1  christos         /* Allow numarguments == 0 for Function() */
    220       1.1  christos 
    221       1.1  christos         if ((!MethodInfo->NumArguments) && (ActualArgs))
    222       1.1  christos         {
    223       1.1  christos             MethodInfo->NumArguments = ActualArgs;
    224       1.1  christos             ArgNode->Asl.Value.Integer |= ActualArgs;
    225       1.1  christos         }
    226       1.1  christos 
    227       1.1  christos         /*
    228       1.1  christos          * Actual arguments are initialized at method entry.
    229       1.1  christos          * All other ArgX "registers" can be used as locals, so we
    230       1.1  christos          * track their initialization.
    231       1.1  christos          */
    232       1.1  christos         for (i = 0; i < MethodInfo->NumArguments; i++)
    233       1.1  christos         {
    234       1.1  christos             MethodInfo->ArgInitialized[i] = TRUE;
    235       1.1  christos         }
    236       1.1  christos         break;
    237       1.1  christos 
    238       1.1  christos     case PARSEOP_METHODCALL:
    239       1.1  christos 
    240   1.1.1.9  christos         /* Check for a recursive method call */
    241   1.1.1.9  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.1.9  christos             if (MethodInfo->CreatesNamedObjects)
    246   1.1.1.9  christos             {
    247   1.1.1.9  christos                 /*
    248   1.1.1.9  christos                  * This is an error, as it will fail at runtime on all ACPI
    249   1.1.1.9  christos                  * implementations. Any named object declarations will be
    250   1.1.1.9  christos                  * executed twice, causing failure the second time. Note,
    251   1.1.1.9  christos                  * this is independent of whether the method is declared
    252   1.1.1.9  christos                  * Serialized, because the same thread is attempting to
    253   1.1.1.9  christos                  * reenter the method, and this will always succeed.
    254   1.1.1.9  christos                  */
    255   1.1.1.9  christos                 AslDualParseOpError (ASL_ERROR, ASL_MSG_ILLEGAL_RECURSION, Op,
    256   1.1.1.9  christos                     Op->Asl.Value.String, ASL_MSG_FOUND_HERE, MethodInfo->Op,
    257   1.1.1.9  christos                     MethodInfo->Op->Asl.ExternalName);
    258   1.1.1.9  christos             }
    259   1.1.1.9  christos             else
    260   1.1.1.9  christos             {
    261   1.1.1.9  christos                 /* Method does not create objects, issue a remark */
    262   1.1.1.9  christos 
    263   1.1.1.9  christos                 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
    264   1.1.1.9  christos             }
    265       1.1  christos         }
    266       1.1  christos         break;
    267       1.1  christos 
    268       1.1  christos     case PARSEOP_LOCAL0:
    269       1.1  christos     case PARSEOP_LOCAL1:
    270       1.1  christos     case PARSEOP_LOCAL2:
    271       1.1  christos     case PARSEOP_LOCAL3:
    272       1.1  christos     case PARSEOP_LOCAL4:
    273       1.1  christos     case PARSEOP_LOCAL5:
    274       1.1  christos     case PARSEOP_LOCAL6:
    275       1.1  christos     case PARSEOP_LOCAL7:
    276       1.1  christos 
    277       1.1  christos         if (!MethodInfo)
    278       1.1  christos         {
    279       1.1  christos             /*
    280       1.1  christos              * Local was used outside a control method, or there was an error
    281       1.1  christos              * in the method declaration.
    282       1.1  christos              */
    283   1.1.1.5  christos             AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
    284   1.1.1.5  christos                 Op, Op->Asl.ExternalName);
    285       1.1  christos             return (AE_ERROR);
    286       1.1  christos         }
    287       1.1  christos 
    288   1.1.1.4  christos         RegisterNumber = (Op->Asl.AmlOpcode & 0x0007);
    289       1.1  christos 
    290       1.1  christos         /*
    291       1.1  christos          * If the local is being used as a target, mark the local
    292       1.1  christos          * initialized
    293       1.1  christos          */
    294   1.1.1.8  christos         if (Op->Asl.CompileFlags & OP_IS_TARGET)
    295       1.1  christos         {
    296       1.1  christos             MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
    297       1.1  christos         }
    298       1.1  christos 
    299       1.1  christos         /*
    300       1.1  christos          * Otherwise, this is a reference, check if the local
    301       1.1  christos          * has been previously initialized.
    302       1.1  christos          *
    303       1.1  christos          * The only operator that accepts an uninitialized value is ObjectType()
    304       1.1  christos          */
    305       1.1  christos         else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
    306       1.1  christos                  (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
    307       1.1  christos         {
    308       1.1  christos             LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
    309       1.1  christos             AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
    310       1.1  christos         }
    311       1.1  christos         break;
    312       1.1  christos 
    313       1.1  christos     case PARSEOP_ARG0:
    314       1.1  christos     case PARSEOP_ARG1:
    315       1.1  christos     case PARSEOP_ARG2:
    316       1.1  christos     case PARSEOP_ARG3:
    317       1.1  christos     case PARSEOP_ARG4:
    318       1.1  christos     case PARSEOP_ARG5:
    319       1.1  christos     case PARSEOP_ARG6:
    320       1.1  christos 
    321       1.1  christos         if (!MethodInfo)
    322       1.1  christos         {
    323       1.1  christos             /*
    324       1.1  christos              * Arg was used outside a control method, or there was an error
    325       1.1  christos              * in the method declaration.
    326       1.1  christos              */
    327   1.1.1.5  christos             AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
    328   1.1.1.5  christos                 Op, Op->Asl.ExternalName);
    329       1.1  christos             return (AE_ERROR);
    330       1.1  christos         }
    331       1.1  christos 
    332       1.1  christos         RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
    333       1.1  christos         ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
    334       1.1  christos 
    335       1.1  christos         /*
    336       1.1  christos          * If the Arg is being used as a target, mark the local
    337       1.1  christos          * initialized
    338       1.1  christos          */
    339   1.1.1.8  christos         if (Op->Asl.CompileFlags & OP_IS_TARGET)
    340       1.1  christos         {
    341       1.1  christos             MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
    342       1.1  christos         }
    343       1.1  christos 
    344       1.1  christos         /*
    345       1.1  christos          * Otherwise, this is a reference, check if the Arg
    346       1.1  christos          * has been previously initialized.
    347       1.1  christos          *
    348       1.1  christos          * The only operator that accepts an uninitialized value is ObjectType()
    349       1.1  christos          */
    350       1.1  christos         else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
    351   1.1.1.5  christos             (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
    352       1.1  christos         {
    353       1.1  christos             AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
    354       1.1  christos         }
    355       1.1  christos 
    356       1.1  christos         /* Flag this arg if it is not a "real" argument to the method */
    357       1.1  christos 
    358       1.1  christos         if (RegisterNumber >= MethodInfo->NumArguments)
    359       1.1  christos         {
    360       1.1  christos             AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
    361       1.1  christos         }
    362       1.1  christos         break;
    363       1.1  christos 
    364       1.1  christos     case PARSEOP_RETURN:
    365       1.1  christos 
    366       1.1  christos         if (!MethodInfo)
    367       1.1  christos         {
    368       1.1  christos             /*
    369       1.1  christos              * Probably was an error in the method declaration,
    370       1.1  christos              * no additional error here
    371       1.1  christos              */
    372       1.1  christos             ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
    373       1.1  christos             return (AE_ERROR);
    374       1.1  christos         }
    375       1.1  christos 
    376       1.1  christos         /*
    377       1.1  christos          * A child indicates a possible return value. A simple Return or
    378   1.1.1.8  christos          * Return() is marked with OP_IS_NULL_RETURN by the parser so
    379       1.1  christos          * that it is not counted as a "real" return-with-value, although
    380       1.1  christos          * the AML code that is actually emitted is Return(0). The AML
    381       1.1  christos          * definition of Return has a required parameter, so we are
    382       1.1  christos          * forced to convert a null return to Return(0).
    383       1.1  christos          */
    384       1.1  christos         if ((Op->Asl.Child) &&
    385       1.1  christos             (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
    386   1.1.1.8  christos             (!(Op->Asl.Child->Asl.CompileFlags & OP_IS_NULL_RETURN)))
    387       1.1  christos         {
    388       1.1  christos             MethodInfo->NumReturnWithValue++;
    389       1.1  christos         }
    390       1.1  christos         else
    391       1.1  christos         {
    392       1.1  christos             MethodInfo->NumReturnNoValue++;
    393       1.1  christos         }
    394       1.1  christos         break;
    395       1.1  christos 
    396       1.1  christos     case PARSEOP_BREAK:
    397       1.1  christos     case PARSEOP_CONTINUE:
    398       1.1  christos 
    399       1.1  christos         Next = Op->Asl.Parent;
    400       1.1  christos         while (Next)
    401       1.1  christos         {
    402       1.1  christos             if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
    403       1.1  christos             {
    404       1.1  christos                 break;
    405       1.1  christos             }
    406       1.1  christos             Next = Next->Asl.Parent;
    407       1.1  christos         }
    408       1.1  christos 
    409       1.1  christos         if (!Next)
    410       1.1  christos         {
    411       1.1  christos             AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
    412       1.1  christos         }
    413       1.1  christos         break;
    414       1.1  christos 
    415       1.1  christos     case PARSEOP_STALL:
    416       1.1  christos 
    417       1.1  christos         /* We can range check if the argument is an integer */
    418       1.1  christos 
    419       1.1  christos         if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
    420       1.1  christos             (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
    421       1.1  christos         {
    422       1.1  christos             AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
    423       1.1  christos         }
    424       1.1  christos         break;
    425       1.1  christos 
    426       1.1  christos     case PARSEOP_DEVICE:
    427   1.1.1.2  christos 
    428  1.1.1.13  christos         /* Check usage of _HID and _ADR objects */
    429  1.1.1.13  christos 
    430  1.1.1.13  christos         HidExists = ApFindNameInDeviceTree (METHOD_NAME__HID, Op);
    431  1.1.1.13  christos         AdrExists = ApFindNameInDeviceTree (METHOD_NAME__ADR, Op);
    432  1.1.1.13  christos 
    433  1.1.1.13  christos         if (!HidExists && !AdrExists)
    434   1.1.1.2  christos         {
    435  1.1.1.17  christos             AslError (ASL_ERROR, ASL_MSG_MISSING_DEPENDENCY, Op,
    436  1.1.1.17  christos                 "Device object requires a _HID or _ADR");
    437   1.1.1.2  christos         }
    438  1.1.1.13  christos         else if (HidExists && AdrExists)
    439  1.1.1.13  christos         {
    440  1.1.1.13  christos             /*
    441  1.1.1.13  christos              * According to the ACPI spec, "A device object must contain
    442  1.1.1.13  christos              * either an _HID object or an _ADR object, but should not contain
    443  1.1.1.13  christos              * both".
    444  1.1.1.13  christos              */
    445  1.1.1.13  christos             AslError (ASL_WARNING, ASL_MSG_MULTIPLE_TYPES, Op,
    446  1.1.1.13  christos                 "Device object requires either a _HID or _ADR, but not both");
    447  1.1.1.13  christos         }
    448  1.1.1.17  christos 
    449  1.1.1.17  christos         /*
    450  1.1.1.17  christos          * Check usage of _CRS, _DIS, _PRS, and _SRS objects (July 2021).
    451  1.1.1.17  christos          *
    452  1.1.1.17  christos          * Under the Device Object:
    453  1.1.1.17  christos          *
    454  1.1.1.17  christos          * 1) If _PRS present, must have _CRS and _SRS
    455  1.1.1.17  christos          * 2) If _SRS present, must have _PRS (_PRS requires _CRS and _SRS)
    456  1.1.1.17  christos          * 3) If _DIS present, must have _SRS (_SRS requires _PRS, _PRS requires _CRS and _SRS)
    457  1.1.1.17  christos          * 4) If _SRS present, probably should have a _DIS (Remark only)
    458  1.1.1.17  christos          */
    459  1.1.1.17  christos         CrsExists = ApFindNameInDeviceTree (METHOD_NAME__CRS, Op);
    460  1.1.1.17  christos         DisExists = ApFindNameInDeviceTree (METHOD_NAME__DIS, Op);
    461  1.1.1.17  christos         PrsExists = ApFindNameInDeviceTree (METHOD_NAME__PRS, Op);
    462  1.1.1.17  christos         SrsExists = ApFindNameInDeviceTree (METHOD_NAME__SRS, Op);
    463  1.1.1.17  christos 
    464  1.1.1.17  christos         /* 1) If _PRS is present, must have a _CRS and _SRS */
    465  1.1.1.17  christos 
    466  1.1.1.17  christos         if (PrsExists)
    467  1.1.1.17  christos         {
    468  1.1.1.17  christos             if (!CrsExists)
    469  1.1.1.17  christos             {
    470  1.1.1.17  christos                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    471  1.1.1.17  christos                     "Device has a _PRS, missing a _CRS, required");
    472  1.1.1.17  christos             }
    473  1.1.1.17  christos             if (!SrsExists)
    474  1.1.1.17  christos             {
    475  1.1.1.17  christos                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    476  1.1.1.17  christos                     "Device has a _PRS, missing a _SRS, required");
    477  1.1.1.17  christos             }
    478  1.1.1.17  christos         }
    479  1.1.1.17  christos 
    480  1.1.1.17  christos         /* 2) If _SRS is present, must have _PRS (_PRS requires _CRS and _SRS) */
    481  1.1.1.17  christos 
    482  1.1.1.17  christos         if ((SrsExists) && (!PrsExists))
    483  1.1.1.17  christos         {
    484  1.1.1.17  christos             AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    485  1.1.1.17  christos                 "Device has a _SRS, missing a _PRS, required");
    486  1.1.1.17  christos         }
    487  1.1.1.17  christos 
    488  1.1.1.17  christos         /* 3) If _DIS is present, must have a _SRS */
    489  1.1.1.17  christos 
    490  1.1.1.17  christos         if ((DisExists) && (!SrsExists))
    491  1.1.1.17  christos         {
    492  1.1.1.17  christos             AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
    493  1.1.1.17  christos                 "Device has a _DIS, missing a _SRS, required");
    494  1.1.1.17  christos         }
    495  1.1.1.17  christos 
    496  1.1.1.17  christos         /*
    497  1.1.1.17  christos          * 4) If _SRS is present, should have a _DIS (_PRS requires _CRS
    498  1.1.1.17  christos          * and _SRS)  Remark only.
    499  1.1.1.17  christos          */
    500  1.1.1.17  christos         if ((SrsExists) && (!DisExists))
    501  1.1.1.17  christos         {
    502  1.1.1.17  christos             AslError (ASL_REMARK, ASL_MSG_MISSING_DEPENDENCY, Op,
    503  1.1.1.17  christos                 "Device has a _SRS, no corresponding _DIS");
    504  1.1.1.17  christos         }
    505   1.1.1.2  christos         break;
    506   1.1.1.2  christos 
    507       1.1  christos     case PARSEOP_EVENT:
    508       1.1  christos     case PARSEOP_MUTEX:
    509       1.1  christos     case PARSEOP_OPERATIONREGION:
    510       1.1  christos     case PARSEOP_POWERRESOURCE:
    511       1.1  christos     case PARSEOP_PROCESSOR:
    512       1.1  christos     case PARSEOP_THERMALZONE:
    513       1.1  christos 
    514       1.1  christos         /*
    515       1.1  christos          * The first operand is a name to be created in the namespace.
    516       1.1  christos          * Check against the reserved list.
    517       1.1  christos          */
    518       1.1  christos         i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
    519       1.1  christos         if (i < ACPI_VALID_RESERVED_NAME_MAX)
    520       1.1  christos         {
    521   1.1.1.5  christos             AslError (ASL_ERROR, ASL_MSG_RESERVED_USE,
    522   1.1.1.5  christos                 Op, Op->Asl.ExternalName);
    523       1.1  christos         }
    524  1.1.1.14  christos 
    525  1.1.1.14  christos         MtCheckStaticOperationRegionInMethod (Op);
    526       1.1  christos         break;
    527       1.1  christos 
    528       1.1  christos     case PARSEOP_NAME:
    529       1.1  christos 
    530       1.1  christos         /* Typecheck any predefined names statically defined with Name() */
    531       1.1  christos 
    532       1.1  christos         ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
    533       1.1  christos 
    534       1.1  christos         /* Special typechecking for _HID */
    535       1.1  christos 
    536  1.1.1.13  christos         if (ACPI_COMPARE_NAMESEG (METHOD_NAME__HID, Op->Asl.NameSeg))
    537       1.1  christos         {
    538       1.1  christos             Next = Op->Asl.Child->Asl.Next;
    539       1.1  christos             AnCheckId (Next, ASL_TYPE_HID);
    540       1.1  christos         }
    541       1.1  christos 
    542       1.1  christos         /* Special typechecking for _CID */
    543       1.1  christos 
    544  1.1.1.13  christos         else if (ACPI_COMPARE_NAMESEG (METHOD_NAME__CID, Op->Asl.NameSeg))
    545       1.1  christos         {
    546       1.1  christos             Next = Op->Asl.Child->Asl.Next;
    547       1.1  christos 
    548       1.1  christos             if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
    549       1.1  christos                 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
    550       1.1  christos             {
    551       1.1  christos                 Next = Next->Asl.Child;
    552       1.1  christos                 while (Next)
    553       1.1  christos                 {
    554       1.1  christos                     AnCheckId (Next, ASL_TYPE_CID);
    555       1.1  christos                     Next = Next->Asl.Next;
    556       1.1  christos                 }
    557       1.1  christos             }
    558       1.1  christos             else
    559       1.1  christos             {
    560       1.1  christos                 AnCheckId (Next, ASL_TYPE_CID);
    561       1.1  christos             }
    562       1.1  christos         }
    563   1.1.1.2  christos 
    564       1.1  christos         break;
    565       1.1  christos 
    566       1.1  christos     default:
    567       1.1  christos 
    568       1.1  christos         break;
    569       1.1  christos     }
    570       1.1  christos 
    571       1.1  christos     /* Check for named object creation within a non-serialized method */
    572       1.1  christos 
    573       1.1  christos     MtCheckNamedObjectInMethod (Op, MethodInfo);
    574       1.1  christos     return (AE_OK);
    575       1.1  christos }
    576       1.1  christos 
    577       1.1  christos 
    578       1.1  christos /*******************************************************************************
    579       1.1  christos  *
    580  1.1.1.14  christos  * FUNCTION:    MtProcessTypeOp
    581  1.1.1.14  christos  *
    582  1.1.1.14  christos  * PARAMETERS:  Op                  - Op representing a btype
    583  1.1.1.14  christos  *
    584  1.1.1.14  christos  * RETURN:      Btype represented by Op
    585  1.1.1.14  christos  *
    586  1.1.1.14  christos  * DESCRIPTION: Process a parse object that represents single parameter type or
    587  1.1.1.14  christos  *              a return type in method, function, and external declarations.
    588  1.1.1.14  christos  *
    589  1.1.1.14  christos  ******************************************************************************/
    590  1.1.1.14  christos 
    591  1.1.1.14  christos UINT32
    592  1.1.1.14  christos MtProcessTypeOp (
    593  1.1.1.14  christos     ACPI_PARSE_OBJECT       *TypeOp)
    594  1.1.1.14  christos {
    595  1.1.1.14  christos     UINT32                  Btype = ACPI_BTYPE_ANY;
    596  1.1.1.14  christos 
    597  1.1.1.14  christos 
    598  1.1.1.14  christos     while (TypeOp)
    599  1.1.1.14  christos     {
    600  1.1.1.14  christos         Btype |= AnMapObjTypeToBtype (TypeOp);
    601  1.1.1.14  christos         TypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    602  1.1.1.14  christos         TypeOp = TypeOp->Asl.Next;
    603  1.1.1.14  christos     }
    604  1.1.1.14  christos 
    605  1.1.1.14  christos     return (Btype);
    606  1.1.1.14  christos }
    607  1.1.1.14  christos 
    608  1.1.1.14  christos 
    609  1.1.1.14  christos /*******************************************************************************
    610  1.1.1.14  christos  *
    611  1.1.1.14  christos  * FUNCTION:    MtProcessParameterTypeList
    612  1.1.1.14  christos  *
    613  1.1.1.14  christos  * PARAMETERS:  Op                  - Op representing a btype
    614  1.1.1.14  christos  *
    615  1.1.1.14  christos  * RETURN:      Btype represented by Op
    616  1.1.1.14  christos  *
    617  1.1.1.14  christos  * DESCRIPTION: Process a parse object that represents a parameter type list in
    618  1.1.1.14  christos  *              method, function, and external declarations.
    619  1.1.1.14  christos  *
    620  1.1.1.14  christos  ******************************************************************************/
    621  1.1.1.14  christos 
    622  1.1.1.14  christos UINT8
    623  1.1.1.14  christos MtProcessParameterTypeList (
    624  1.1.1.14  christos     ACPI_PARSE_OBJECT       *ParamTypeOp,
    625  1.1.1.14  christos     UINT32                  *TypeList)
    626  1.1.1.14  christos {
    627  1.1.1.14  christos     UINT8                   ParameterCount = 0;
    628  1.1.1.14  christos 
    629  1.1.1.14  christos 
    630  1.1.1.15  christos     if (ParamTypeOp && ParamTypeOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
    631  1.1.1.15  christos     {
    632  1.1.1.15  christos         /* Special case for a single parameter without braces */
    633  1.1.1.15  christos 
    634  1.1.1.15  christos         TypeList[ParameterCount] =
    635  1.1.1.15  christos             MtProcessTypeOp (ParamTypeOp);
    636  1.1.1.15  christos 
    637  1.1.1.15  christos         return (1);
    638  1.1.1.15  christos     }
    639  1.1.1.15  christos 
    640  1.1.1.14  christos     while (ParamTypeOp)
    641  1.1.1.14  christos     {
    642  1.1.1.14  christos         TypeList[ParameterCount] =
    643  1.1.1.14  christos             MtProcessTypeOp (ParamTypeOp->Asl.Child);
    644  1.1.1.14  christos 
    645  1.1.1.14  christos         ParameterCount++;
    646  1.1.1.14  christos         ParamTypeOp = ParamTypeOp->Asl.Next;
    647  1.1.1.14  christos     }
    648  1.1.1.14  christos 
    649  1.1.1.14  christos     return (ParameterCount);
    650  1.1.1.14  christos }
    651  1.1.1.14  christos 
    652  1.1.1.14  christos 
    653  1.1.1.14  christos /*******************************************************************************
    654  1.1.1.14  christos  *
    655       1.1  christos  * FUNCTION:    MtCheckNamedObjectInMethod
    656       1.1  christos  *
    657       1.1  christos  * PARAMETERS:  Op                  - Current parser op
    658       1.1  christos  *              MethodInfo          - Info for method being parsed
    659       1.1  christos  *
    660       1.1  christos  * RETURN:      None
    661       1.1  christos  *
    662       1.1  christos  * DESCRIPTION: Detect if a non-serialized method is creating a named object,
    663       1.1  christos  *              which could possibly cause problems if two threads execute
    664       1.1  christos  *              the method concurrently. Emit a remark in this case.
    665       1.1  christos  *
    666       1.1  christos  ******************************************************************************/
    667       1.1  christos 
    668   1.1.1.6  christos static void
    669       1.1  christos MtCheckNamedObjectInMethod (
    670       1.1  christos     ACPI_PARSE_OBJECT       *Op,
    671       1.1  christos     ASL_METHOD_INFO         *MethodInfo)
    672       1.1  christos {
    673       1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    674  1.1.1.14  christos     char                    *ExternalPath;
    675       1.1  christos 
    676       1.1  christos 
    677   1.1.1.5  christos     /* We don't care about actual method declarations or scopes */
    678       1.1  christos 
    679   1.1.1.5  christos     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) ||
    680   1.1.1.5  christos         (Op->Asl.AmlOpcode == AML_SCOPE_OP))
    681       1.1  christos     {
    682       1.1  christos         return;
    683       1.1  christos     }
    684       1.1  christos 
    685   1.1.1.9  christos     /* Determine if we are creating a named object within a method */
    686   1.1.1.9  christos 
    687   1.1.1.9  christos     if (!MethodInfo)
    688   1.1.1.9  christos     {
    689   1.1.1.9  christos         return;
    690   1.1.1.9  christos     }
    691       1.1  christos 
    692       1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    693  1.1.1.15  christos     if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_FIELD_OP))
    694       1.1  christos     {
    695       1.1  christos         /*
    696   1.1.1.9  christos          * 1) Mark the method as a method that creates named objects.
    697   1.1.1.9  christos          *
    698  1.1.1.14  christos          * 2) Issue a remark indicating the inefficiency of creating named
    699  1.1.1.14  christos          * objects within a method (Except for compiler-emitted temporary
    700  1.1.1.14  christos          * variables).
    701  1.1.1.14  christos          *
    702  1.1.1.14  christos          * 3) If the method is non-serialized, emit a remark that the method
    703   1.1.1.9  christos          * should be serialized.
    704       1.1  christos          *
    705       1.1  christos          * Reason: If a thread blocks within the method for any reason, and
    706   1.1.1.9  christos          * another thread enters the method, the method will fail because
    707   1.1.1.9  christos          * an attempt will be made to create the same object twice.
    708  1.1.1.15  christos          *
    709  1.1.1.15  christos          * Note: The Field opcode is disallowed here because Field() does not
    710  1.1.1.15  christos          * create a new named object.
    711       1.1  christos          */
    712  1.1.1.14  christos         ExternalPath = AcpiNsGetNormalizedPathname (MethodInfo->Op->Asl.Node, TRUE);
    713  1.1.1.14  christos 
    714  1.1.1.14  christos         /* No error for compiler temp variables (name starts with "_T_") */
    715  1.1.1.14  christos 
    716  1.1.1.14  christos         if ((Op->Asl.NameSeg[0] != '_') &&
    717  1.1.1.14  christos             (Op->Asl.NameSeg[1] != 'T') &&
    718  1.1.1.14  christos             (Op->Asl.NameSeg[2] != '_'))
    719  1.1.1.14  christos         {
    720  1.1.1.14  christos             AslError (ASL_REMARK, ASL_MSG_NAMED_OBJECT_CREATION, Op,
    721  1.1.1.14  christos                 ExternalPath);
    722  1.1.1.14  christos         }
    723  1.1.1.14  christos 
    724   1.1.1.9  christos         MethodInfo->CreatesNamedObjects = TRUE;
    725   1.1.1.9  christos         if (!MethodInfo->ShouldBeSerialized)
    726       1.1  christos         {
    727       1.1  christos             AslError (ASL_REMARK, ASL_MSG_SERIALIZED_REQUIRED, MethodInfo->Op,
    728  1.1.1.14  christos                 ExternalPath);
    729       1.1  christos 
    730       1.1  christos             /* Emit message only ONCE per method */
    731       1.1  christos 
    732       1.1  christos             MethodInfo->ShouldBeSerialized = TRUE;
    733       1.1  christos         }
    734  1.1.1.14  christos 
    735  1.1.1.14  christos         if (ExternalPath)
    736  1.1.1.14  christos         {
    737  1.1.1.14  christos             ACPI_FREE (ExternalPath);
    738  1.1.1.14  christos         }
    739       1.1  christos     }
    740       1.1  christos }
    741       1.1  christos 
    742       1.1  christos 
    743       1.1  christos /*******************************************************************************
    744       1.1  christos  *
    745  1.1.1.14  christos  * FUNCTION:    MtCheckStaticOperationRegionInMethod
    746  1.1.1.14  christos  *
    747  1.1.1.14  christos  * PARAMETERS:  Op                  - Current parser op
    748  1.1.1.14  christos  *
    749  1.1.1.14  christos  * RETURN:      None
    750  1.1.1.14  christos  *
    751  1.1.1.14  christos  * DESCRIPTION: Warns if an Operation Region with static address or length
    752  1.1.1.14  christos  *              is declared inside a control method
    753  1.1.1.14  christos  *
    754  1.1.1.14  christos  ******************************************************************************/
    755  1.1.1.14  christos 
    756  1.1.1.14  christos static void
    757  1.1.1.14  christos MtCheckStaticOperationRegionInMethod(
    758  1.1.1.14  christos     ACPI_PARSE_OBJECT*       Op)
    759  1.1.1.14  christos {
    760  1.1.1.14  christos     ACPI_PARSE_OBJECT*       AddressOp;
    761  1.1.1.14  christos     ACPI_PARSE_OBJECT*       LengthOp;
    762  1.1.1.14  christos 
    763  1.1.1.14  christos 
    764  1.1.1.14  christos     if (Op->Asl.ParseOpcode != PARSEOP_OPERATIONREGION)
    765  1.1.1.14  christos     {
    766  1.1.1.14  christos         return;
    767  1.1.1.14  christos     }
    768  1.1.1.14  christos 
    769  1.1.1.14  christos     /*
    770  1.1.1.14  christos      * OperationRegion should have 4 arguments defined. At this point, we
    771  1.1.1.14  christos      * assume that the parse tree is well-formed.
    772  1.1.1.14  christos      */
    773  1.1.1.14  christos     AddressOp = Op->Asl.Child->Asl.Next->Asl.Next;
    774  1.1.1.14  christos     LengthOp = Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next;
    775  1.1.1.14  christos 
    776  1.1.1.14  christos     if (UtGetParentMethodOp (Op) &&
    777  1.1.1.14  christos         AddressOp->Asl.ParseOpcode == PARSEOP_INTEGER &&
    778  1.1.1.14  christos         LengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)
    779  1.1.1.14  christos     {
    780  1.1.1.14  christos         /*
    781  1.1.1.14  christos          * At this point, a static operation region declared inside of a
    782  1.1.1.14  christos          * control method has been found. Throw a warning because this is
    783  1.1.1.14  christos          * highly inefficient.
    784  1.1.1.14  christos          */
    785  1.1.1.14  christos         AslError(ASL_WARNING, ASL_MSG_STATIC_OPREGION_IN_METHOD, Op, NULL);
    786  1.1.1.14  christos     }
    787  1.1.1.14  christos 
    788  1.1.1.14  christos     return;
    789  1.1.1.14  christos }
    790  1.1.1.14  christos 
    791  1.1.1.14  christos 
    792  1.1.1.14  christos /*******************************************************************************
    793  1.1.1.14  christos  *
    794       1.1  christos  * FUNCTION:    MtMethodAnalysisWalkEnd
    795       1.1  christos  *
    796       1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
    797       1.1  christos  *
    798       1.1  christos  * RETURN:      Status
    799       1.1  christos  *
    800       1.1  christos  * DESCRIPTION: Ascending callback for analysis walk. Complete method
    801       1.1  christos  *              return analysis.
    802       1.1  christos  *
    803       1.1  christos  ******************************************************************************/
    804       1.1  christos 
    805       1.1  christos ACPI_STATUS
    806       1.1  christos MtMethodAnalysisWalkEnd (
    807       1.1  christos     ACPI_PARSE_OBJECT       *Op,
    808       1.1  christos     UINT32                  Level,
    809       1.1  christos     void                    *Context)
    810       1.1  christos {
    811       1.1  christos     ASL_ANALYSIS_WALK_INFO  *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
    812       1.1  christos     ASL_METHOD_INFO         *MethodInfo = WalkInfo->MethodStack;
    813  1.1.1.14  christos     char                    *ExternalPath;
    814       1.1  christos 
    815       1.1  christos 
    816       1.1  christos     switch (Op->Asl.ParseOpcode)
    817       1.1  christos     {
    818       1.1  christos     case PARSEOP_METHOD:
    819       1.1  christos     case PARSEOP_RETURN:
    820       1.1  christos 
    821       1.1  christos         if (!MethodInfo)
    822       1.1  christos         {
    823       1.1  christos             printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
    824       1.1  christos             AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
    825       1.1  christos                 "No method info for this method");
    826       1.1  christos 
    827       1.1  christos             CmCleanupAndExit ();
    828       1.1  christos             return (AE_AML_INTERNAL);
    829       1.1  christos         }
    830       1.1  christos         break;
    831       1.1  christos 
    832       1.1  christos     default:
    833       1.1  christos 
    834       1.1  christos         break;
    835       1.1  christos     }
    836       1.1  christos 
    837       1.1  christos     switch (Op->Asl.ParseOpcode)
    838       1.1  christos     {
    839       1.1  christos     case PARSEOP_METHOD:
    840       1.1  christos 
    841       1.1  christos         WalkInfo->MethodStack = MethodInfo->Next;
    842       1.1  christos 
    843       1.1  christos         /*
    844       1.1  christos          * Check if there is no return statement at the end of the
    845       1.1  christos          * method AND we can actually get there -- i.e., the execution
    846       1.1  christos          * of the method can possibly terminate without a return statement.
    847       1.1  christos          */
    848       1.1  christos         if ((!AnLastStatementIsReturn (Op)) &&
    849   1.1.1.8  christos             (!(Op->Asl.CompileFlags & OP_HAS_NO_EXIT)))
    850       1.1  christos         {
    851       1.1  christos             /*
    852       1.1  christos              * No return statement, and execution can possibly exit
    853       1.1  christos              * via this path. This is equivalent to Return ()
    854       1.1  christos              */
    855       1.1  christos             MethodInfo->NumReturnNoValue++;
    856       1.1  christos         }
    857       1.1  christos 
    858       1.1  christos         /*
    859       1.1  christos          * Check for case where some return statements have a return value
    860       1.1  christos          * and some do not. Exit without a return statement is a return with
    861       1.1  christos          * no value
    862       1.1  christos          */
    863       1.1  christos         if (MethodInfo->NumReturnNoValue &&
    864       1.1  christos             MethodInfo->NumReturnWithValue)
    865       1.1  christos         {
    866  1.1.1.14  christos             ExternalPath = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE);
    867  1.1.1.14  christos 
    868       1.1  christos             AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
    869  1.1.1.14  christos                 ExternalPath);
    870  1.1.1.14  christos 
    871  1.1.1.14  christos             if (ExternalPath)
    872  1.1.1.14  christos             {
    873  1.1.1.14  christos                 ACPI_FREE (ExternalPath);
    874  1.1.1.14  christos             }
    875       1.1  christos         }
    876       1.1  christos 
    877       1.1  christos         /*
    878       1.1  christos          * If there are any RETURN() statements with no value, or there is a
    879       1.1  christos          * control path that allows the method to exit without a return value,
    880       1.1  christos          * we mark the method as a method that does not return a value. This
    881       1.1  christos          * knowledge can be used to check method invocations that expect a
    882       1.1  christos          * returned value.
    883       1.1  christos          */
    884       1.1  christos         if (MethodInfo->NumReturnNoValue)
    885       1.1  christos         {
    886       1.1  christos             if (MethodInfo->NumReturnWithValue)
    887       1.1  christos             {
    888   1.1.1.8  christos                 Op->Asl.CompileFlags |= OP_METHOD_SOME_NO_RETVAL;
    889       1.1  christos             }
    890       1.1  christos             else
    891       1.1  christos             {
    892   1.1.1.8  christos                 Op->Asl.CompileFlags |= OP_METHOD_NO_RETVAL;
    893       1.1  christos             }
    894       1.1  christos         }
    895       1.1  christos 
    896       1.1  christos         /*
    897       1.1  christos          * Check predefined method names for correct return behavior
    898       1.1  christos          * and correct number of arguments. Also, some special checks
    899       1.1  christos          * For GPE and _REG methods.
    900       1.1  christos          */
    901       1.1  christos         if (ApCheckForPredefinedMethod (Op, MethodInfo))
    902       1.1  christos         {
    903       1.1  christos             /* Special check for two names like _L01 and _E01 in same scope */
    904       1.1  christos 
    905       1.1  christos             ApCheckForGpeNameConflict (Op);
    906       1.1  christos 
    907       1.1  christos             /*
    908       1.1  christos              * Special check for _REG: Must have an operation region definition
    909       1.1  christos              * within the same scope!
    910       1.1  christos              */
    911       1.1  christos             ApCheckRegMethod (Op);
    912       1.1  christos         }
    913       1.1  christos 
    914       1.1  christos         ACPI_FREE (MethodInfo);
    915       1.1  christos         break;
    916       1.1  christos 
    917       1.1  christos     case PARSEOP_NAME:
    918       1.1  christos 
    919       1.1  christos          /* Special check for two names like _L01 and _E01 in same scope */
    920       1.1  christos 
    921       1.1  christos         ApCheckForGpeNameConflict (Op);
    922       1.1  christos         break;
    923       1.1  christos 
    924       1.1  christos     case PARSEOP_RETURN:
    925       1.1  christos 
    926       1.1  christos         /*
    927       1.1  christos          * If the parent is a predefined method name, attempt to typecheck
    928       1.1  christos          * the return value. Only static types can be validated.
    929       1.1  christos          */
    930       1.1  christos         ApCheckPredefinedReturnValue (Op, MethodInfo);
    931       1.1  christos 
    932       1.1  christos         /*
    933       1.1  christos          * The parent block does not "exit" and continue execution -- the
    934       1.1  christos          * method is terminated here with the Return() statement.
    935       1.1  christos          */
    936   1.1.1.8  christos         Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
    937       1.1  christos 
    938       1.1  christos         /* Used in the "typing" pass later */
    939       1.1  christos 
    940       1.1  christos         Op->Asl.ParentMethod = MethodInfo->Op;
    941       1.1  christos 
    942       1.1  christos         /*
    943       1.1  christos          * If there is a peer node after the return statement, then this
    944       1.1  christos          * node is unreachable code -- i.e., it won't be executed because of
    945       1.1  christos          * the preceding Return() statement.
    946       1.1  christos          */
    947       1.1  christos         if (Op->Asl.Next)
    948       1.1  christos         {
    949   1.1.1.5  christos             AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE,
    950   1.1.1.5  christos                 Op->Asl.Next, NULL);
    951       1.1  christos         }
    952       1.1  christos         break;
    953       1.1  christos 
    954       1.1  christos     case PARSEOP_IF:
    955       1.1  christos 
    956   1.1.1.8  christos         if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
    957       1.1  christos             (Op->Asl.Next) &&
    958       1.1  christos             (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
    959       1.1  christos         {
    960       1.1  christos             /*
    961       1.1  christos              * This IF has a corresponding ELSE. The IF block has no exit,
    962       1.1  christos              * (it contains an unconditional Return)
    963       1.1  christos              * mark the ELSE block to remember this fact.
    964       1.1  christos              */
    965   1.1.1.8  christos             Op->Asl.Next->Asl.CompileFlags |= OP_IF_HAS_NO_EXIT;
    966       1.1  christos         }
    967       1.1  christos         break;
    968       1.1  christos 
    969       1.1  christos     case PARSEOP_ELSE:
    970       1.1  christos 
    971   1.1.1.8  christos         if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
    972   1.1.1.8  christos             (Op->Asl.CompileFlags & OP_IF_HAS_NO_EXIT))
    973       1.1  christos         {
    974       1.1  christos             /*
    975       1.1  christos              * This ELSE block has no exit and the corresponding IF block
    976       1.1  christos              * has no exit either. Therefore, the parent node has no exit.
    977       1.1  christos              */
    978   1.1.1.8  christos             Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
    979       1.1  christos         }
    980       1.1  christos         break;
    981       1.1  christos 
    982       1.1  christos 
    983       1.1  christos     default:
    984       1.1  christos 
    985   1.1.1.8  christos         if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
    986       1.1  christos             (Op->Asl.Parent))
    987       1.1  christos         {
    988       1.1  christos             /* If this node has no exit, then the parent has no exit either */
    989       1.1  christos 
    990   1.1.1.8  christos             Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
    991       1.1  christos         }
    992       1.1  christos         break;
    993       1.1  christos     }
    994       1.1  christos 
    995       1.1  christos     return (AE_OK);
    996       1.1  christos }
    997