Home | History | Annotate | Line # | Download | only in compiler
aslanalyze.c revision 1.10.2.1
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.2  christos  * Module Name: aslanalyze.c - Support functions for parse tree walks
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7       1.2  christos /*
      8  1.10.2.1  christos  * Copyright (C) 2000 - 2019, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.2  christos  * Redistribution and use in source and binary forms, with or without
     12       1.2  christos  * modification, are permitted provided that the following conditions
     13       1.2  christos  * are met:
     14       1.2  christos  * 1. Redistributions of source code must retain the above copyright
     15       1.2  christos  *    notice, this list of conditions, and the following disclaimer,
     16       1.2  christos  *    without modification.
     17       1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.2  christos  *    including a substantially similar Disclaimer requirement for further
     21       1.2  christos  *    binary redistribution.
     22       1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.2  christos  *    of any contributors may be used to endorse or promote products derived
     24       1.2  christos  *    from this software without specific prior written permission.
     25       1.2  christos  *
     26       1.2  christos  * Alternatively, this software may be distributed under the terms of the
     27       1.2  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.2  christos  * Software Foundation.
     29       1.2  christos  *
     30       1.2  christos  * NO WARRANTY
     31       1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.2  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.2  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.2  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.2  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.2  christos  * POSSIBILITY OF SUCH DAMAGES.
     42       1.2  christos  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "aslcompiler.h"
     45       1.1    jruoho #include "aslcompiler.y.h"
     46       1.2  christos #include <string.h>
     47       1.2  christos 
     48       1.1    jruoho 
     49       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     50       1.1    jruoho         ACPI_MODULE_NAME    ("aslanalyze")
     51       1.1    jruoho 
     52       1.1    jruoho 
     53       1.7  christos /* Local Prototypes */
     54       1.7  christos 
     55       1.7  christos static ACPI_STATUS
     56       1.7  christos ApDeviceSubtreeWalk (
     57       1.7  christos     ACPI_PARSE_OBJECT       *Op,
     58       1.7  christos     UINT32                  Level,
     59       1.7  christos     void                    *Context);
     60       1.7  christos 
     61       1.7  christos 
     62       1.1    jruoho /*******************************************************************************
     63       1.1    jruoho  *
     64       1.1    jruoho  * FUNCTION:    AnIsInternalMethod
     65       1.1    jruoho  *
     66       1.2  christos  * PARAMETERS:  Op                  - Current op
     67       1.1    jruoho  *
     68       1.1    jruoho  * RETURN:      Boolean
     69       1.1    jruoho  *
     70       1.1    jruoho  * DESCRIPTION: Check for an internal control method.
     71       1.1    jruoho  *
     72       1.1    jruoho  ******************************************************************************/
     73       1.1    jruoho 
     74       1.2  christos BOOLEAN
     75       1.1    jruoho AnIsInternalMethod (
     76       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
     77       1.1    jruoho {
     78       1.1    jruoho 
     79       1.5  christos     if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
     80       1.5  christos         (!strcmp (Op->Asl.ExternalName, "_OSI")))
     81       1.1    jruoho     {
     82       1.1    jruoho         return (TRUE);
     83       1.1    jruoho     }
     84       1.1    jruoho 
     85       1.1    jruoho     return (FALSE);
     86       1.1    jruoho }
     87       1.1    jruoho 
     88       1.1    jruoho 
     89       1.1    jruoho /*******************************************************************************
     90       1.1    jruoho  *
     91       1.1    jruoho  * FUNCTION:    AnGetInternalMethodReturnType
     92       1.1    jruoho  *
     93       1.2  christos  * PARAMETERS:  Op                  - Current op
     94       1.1    jruoho  *
     95       1.1    jruoho  * RETURN:      Btype
     96       1.1    jruoho  *
     97       1.1    jruoho  * DESCRIPTION: Get the return type of an internal method
     98       1.1    jruoho  *
     99       1.1    jruoho  ******************************************************************************/
    100       1.1    jruoho 
    101       1.2  christos UINT32
    102       1.1    jruoho AnGetInternalMethodReturnType (
    103       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    104       1.1    jruoho {
    105       1.1    jruoho 
    106       1.5  christos     if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
    107       1.5  christos         (!strcmp (Op->Asl.ExternalName, "_OSI")))
    108       1.1    jruoho     {
    109       1.1    jruoho         return (ACPI_BTYPE_STRING);
    110       1.1    jruoho     }
    111       1.1    jruoho 
    112       1.1    jruoho     return (0);
    113       1.1    jruoho }
    114       1.1    jruoho 
    115       1.1    jruoho 
    116       1.1    jruoho /*******************************************************************************
    117       1.1    jruoho  *
    118       1.2  christos  * FUNCTION:    AnCheckId
    119       1.1    jruoho  *
    120       1.2  christos  * PARAMETERS:  Op                  - Current parse op
    121       1.2  christos  *              Type                - HID or CID
    122       1.1    jruoho  *
    123       1.2  christos  * RETURN:      None
    124       1.1    jruoho  *
    125       1.2  christos  * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
    126       1.2  christos  *              checks can be performed on _CID strings.
    127       1.1    jruoho  *
    128       1.1    jruoho  ******************************************************************************/
    129       1.1    jruoho 
    130       1.2  christos void
    131       1.2  christos AnCheckId (
    132       1.2  christos     ACPI_PARSE_OBJECT       *Op,
    133       1.2  christos     ACPI_NAME               Type)
    134       1.1    jruoho {
    135       1.2  christos     UINT32                  i;
    136       1.2  christos     ACPI_SIZE               Length;
    137       1.1    jruoho 
    138       1.1    jruoho 
    139       1.2  christos     /* Only care about string versions of _HID/_CID (integers are legal) */
    140       1.1    jruoho 
    141       1.2  christos     if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
    142       1.1    jruoho     {
    143       1.2  christos         return;
    144       1.1    jruoho     }
    145       1.1    jruoho 
    146       1.2  christos     /* For both _HID and _CID, the string must be non-null */
    147       1.1    jruoho 
    148       1.2  christos     Length = strlen (Op->Asl.Value.String);
    149       1.2  christos     if (!Length)
    150       1.1    jruoho     {
    151       1.6  christos         AslError (ASL_ERROR, ASL_MSG_NULL_STRING, Op, NULL);
    152       1.2  christos         return;
    153       1.1    jruoho     }
    154       1.1    jruoho 
    155       1.2  christos     /*
    156       1.2  christos      * One of the things we want to catch here is the use of a leading
    157       1.2  christos      * asterisk in the string -- an odd construct that certain platform
    158       1.2  christos      * manufacturers are fond of. Technically, a leading asterisk is OK
    159       1.2  christos      * for _CID, but a valid use of this has not been seen.
    160       1.2  christos      */
    161       1.2  christos     if (*Op->Asl.Value.String == '*')
    162       1.1    jruoho     {
    163       1.2  christos         AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK,
    164       1.2  christos             Op, Op->Asl.Value.String);
    165       1.2  christos         return;
    166       1.1    jruoho     }
    167       1.1    jruoho 
    168       1.2  christos     /* _CID strings are bus-specific, no more checks can be performed */
    169       1.1    jruoho 
    170       1.2  christos     if (Type == ASL_TYPE_CID)
    171       1.1    jruoho     {
    172       1.1    jruoho         return;
    173       1.1    jruoho     }
    174       1.1    jruoho 
    175       1.2  christos     /* For _HID, all characters must be alphanumeric */
    176       1.1    jruoho 
    177       1.2  christos     for (i = 0; Op->Asl.Value.String[i]; i++)
    178       1.1    jruoho     {
    179       1.2  christos         if (!isalnum ((int) Op->Asl.Value.String[i]))
    180       1.1    jruoho         {
    181       1.2  christos             AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
    182       1.2  christos                 Op, Op->Asl.Value.String);
    183       1.2  christos             return;
    184       1.1    jruoho         }
    185       1.1    jruoho     }
    186       1.1    jruoho 
    187       1.2  christos     /*
    188       1.2  christos      * _HID String must be one of these forms:
    189       1.2  christos      *
    190       1.2  christos      * "AAA####"    A is an uppercase letter and # is a hex digit
    191       1.2  christos      * "ACPI####"   # is a hex digit
    192       1.2  christos      * "NNNN####"   N is an uppercase letter or decimal digit (0-9)
    193       1.2  christos      *              # is a hex digit (ACPI 5.0)
    194       1.2  christos      */
    195       1.2  christos     if ((Length < 7) || (Length > 8))
    196       1.1    jruoho     {
    197       1.2  christos         AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
    198       1.2  christos             Op, Op->Asl.Value.String);
    199       1.2  christos         return;
    200       1.1    jruoho     }
    201       1.1    jruoho 
    202       1.6  christos     /* _HID Length is valid (7 or 8), now check prefix (first 3 or 4 chars) */
    203       1.1    jruoho 
    204       1.2  christos     if (Length == 7)
    205       1.1    jruoho     {
    206       1.2  christos         /* AAA####: Ensure the alphabetic prefix is all uppercase */
    207       1.1    jruoho 
    208       1.2  christos         for (i = 0; i < 3; i++)
    209       1.1    jruoho         {
    210       1.2  christos             if (!isupper ((int) Op->Asl.Value.String[i]))
    211       1.1    jruoho             {
    212       1.2  christos                 AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
    213       1.2  christos                     Op, &Op->Asl.Value.String[i]);
    214       1.2  christos                 return;
    215       1.1    jruoho             }
    216       1.1    jruoho         }
    217       1.1    jruoho     }
    218       1.2  christos     else /* Length == 8 */
    219       1.1    jruoho     {
    220       1.1    jruoho         /*
    221       1.2  christos          * ACPI#### or NNNN####:
    222       1.2  christos          * Ensure the prefix contains only uppercase alpha or decimal digits
    223       1.1    jruoho          */
    224       1.2  christos         for (i = 0; i < 4; i++)
    225       1.1    jruoho         {
    226       1.2  christos             if (!isupper ((int) Op->Asl.Value.String[i]) &&
    227       1.2  christos                 !isdigit ((int) Op->Asl.Value.String[i]))
    228       1.2  christos             {
    229       1.2  christos                 AslError (ASL_ERROR, ASL_MSG_HID_PREFIX,
    230       1.2  christos                     Op, &Op->Asl.Value.String[i]);
    231       1.2  christos                 return;
    232       1.2  christos             }
    233       1.1    jruoho         }
    234       1.2  christos     }
    235       1.1    jruoho 
    236       1.2  christos     /* Remaining characters (suffix) must be hex digits */
    237       1.1    jruoho 
    238       1.2  christos     for (; i < Length; i++)
    239       1.2  christos     {
    240       1.2  christos         if (!isxdigit ((int) Op->Asl.Value.String[i]))
    241       1.1    jruoho         {
    242       1.6  christos             AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX,
    243       1.6  christos                 Op, &Op->Asl.Value.String[i]);
    244       1.2  christos             break;
    245       1.1    jruoho         }
    246       1.1    jruoho     }
    247       1.1    jruoho }
    248       1.1    jruoho 
    249       1.1    jruoho 
    250       1.1    jruoho /*******************************************************************************
    251       1.1    jruoho  *
    252       1.2  christos  * FUNCTION:    AnLastStatementIsReturn
    253       1.1    jruoho  *
    254       1.2  christos  * PARAMETERS:  Op                  - A method parse node
    255       1.1    jruoho  *
    256       1.2  christos  * RETURN:      TRUE if last statement is an ASL RETURN. False otherwise
    257       1.1    jruoho  *
    258       1.2  christos  * DESCRIPTION: Walk down the list of top level statements within a method
    259       1.2  christos  *              to find the last one. Check if that last statement is in
    260       1.2  christos  *              fact a RETURN statement.
    261       1.1    jruoho  *
    262       1.1    jruoho  ******************************************************************************/
    263       1.1    jruoho 
    264       1.2  christos BOOLEAN
    265       1.2  christos AnLastStatementIsReturn (
    266       1.2  christos     ACPI_PARSE_OBJECT       *Op)
    267       1.1    jruoho {
    268       1.2  christos     ACPI_PARSE_OBJECT       *Next;
    269       1.1    jruoho 
    270       1.1    jruoho 
    271       1.2  christos     /* Check if last statement is a return */
    272       1.1    jruoho 
    273       1.2  christos     Next = ASL_GET_CHILD_NODE (Op);
    274       1.2  christos     while (Next)
    275       1.1    jruoho     {
    276       1.2  christos         if ((!Next->Asl.Next) &&
    277       1.2  christos             (Next->Asl.ParseOpcode == PARSEOP_RETURN))
    278       1.1    jruoho         {
    279       1.2  christos             return (TRUE);
    280       1.1    jruoho         }
    281       1.1    jruoho 
    282       1.2  christos         Next = ASL_GET_PEER_NODE (Next);
    283       1.1    jruoho     }
    284       1.1    jruoho 
    285       1.2  christos     return (FALSE);
    286       1.1    jruoho }
    287       1.1    jruoho 
    288       1.1    jruoho 
    289       1.1    jruoho /*******************************************************************************
    290       1.1    jruoho  *
    291       1.1    jruoho  * FUNCTION:    AnCheckMethodReturnValue
    292       1.1    jruoho  *
    293       1.1    jruoho  * PARAMETERS:  Op                  - Parent
    294       1.1    jruoho  *              OpInfo              - Parent info
    295       1.1    jruoho  *              ArgOp               - Method invocation op
    296       1.1    jruoho  *              RequiredBtypes      - What caller requires
    297       1.1    jruoho  *              ThisNodeBtype       - What this node returns (if anything)
    298       1.1    jruoho  *
    299       1.1    jruoho  * RETURN:      None
    300       1.1    jruoho  *
    301       1.1    jruoho  * DESCRIPTION: Check a method invocation for 1) A return value and if it does
    302       1.1    jruoho  *              in fact return a value, 2) check the type of the return value.
    303       1.1    jruoho  *
    304       1.1    jruoho  ******************************************************************************/
    305       1.1    jruoho 
    306       1.2  christos void
    307       1.1    jruoho AnCheckMethodReturnValue (
    308       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    309       1.1    jruoho     const ACPI_OPCODE_INFO  *OpInfo,
    310       1.1    jruoho     ACPI_PARSE_OBJECT       *ArgOp,
    311       1.1    jruoho     UINT32                  RequiredBtypes,
    312       1.1    jruoho     UINT32                  ThisNodeBtype)
    313       1.1    jruoho {
    314       1.1    jruoho     ACPI_PARSE_OBJECT       *OwningOp;
    315       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    316       1.1    jruoho 
    317       1.1    jruoho 
    318       1.1    jruoho     Node = ArgOp->Asl.Node;
    319       1.1    jruoho 
    320       1.7  christos     if (!Node)
    321       1.7  christos     {
    322       1.7  christos         /* No error message, this can happen and is OK */
    323       1.7  christos 
    324       1.7  christos         return;
    325       1.7  christos     }
    326       1.1    jruoho 
    327       1.1    jruoho     /* Examine the parent op of this method */
    328       1.1    jruoho 
    329       1.1    jruoho     OwningOp = Node->Op;
    330       1.9  christos     if (OwningOp->Asl.CompileFlags & OP_METHOD_NO_RETVAL)
    331       1.1    jruoho     {
    332       1.1    jruoho         /* Method NEVER returns a value */
    333       1.1    jruoho 
    334       1.1    jruoho         AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);
    335       1.1    jruoho     }
    336       1.9  christos     else if (OwningOp->Asl.CompileFlags & OP_METHOD_SOME_NO_RETVAL)
    337       1.1    jruoho     {
    338       1.1    jruoho         /* Method SOMETIMES returns a value, SOMETIMES not */
    339       1.1    jruoho 
    340       1.6  christos         AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL,
    341       1.6  christos             Op, Op->Asl.ExternalName);
    342       1.1    jruoho     }
    343       1.1    jruoho     else if (!(ThisNodeBtype & RequiredBtypes))
    344       1.1    jruoho     {
    345       1.1    jruoho         /* Method returns a value, but the type is wrong */
    346       1.1    jruoho 
    347  1.10.2.1  christos         AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
    348  1.10.2.1  christos         AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
    349       1.1    jruoho 
    350       1.1    jruoho         /*
    351       1.1    jruoho          * The case where the method does not return any value at all
    352       1.1    jruoho          * was already handled in the namespace cross reference
    353       1.1    jruoho          * -- Only issue an error if the method in fact returns a value,
    354       1.1    jruoho          * but it is of the wrong type
    355       1.1    jruoho          */
    356       1.1    jruoho         if (ThisNodeBtype != 0)
    357       1.1    jruoho         {
    358  1.10.2.1  christos             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer),
    359       1.1    jruoho                 "Method returns [%s], %s operator requires [%s]",
    360  1.10.2.1  christos                 AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
    361       1.1    jruoho 
    362  1.10.2.1  christos             AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, AslGbl_MsgBuffer);
    363       1.1    jruoho         }
    364       1.1    jruoho     }
    365       1.1    jruoho }
    366       1.1    jruoho 
    367       1.1    jruoho 
    368       1.1    jruoho /*******************************************************************************
    369       1.1    jruoho  *
    370       1.1    jruoho  * FUNCTION:    AnIsResultUsed
    371       1.1    jruoho  *
    372       1.2  christos  * PARAMETERS:  Op                  - Parent op for the operator
    373       1.1    jruoho  *
    374       1.1    jruoho  * RETURN:      TRUE if result from this operation is actually consumed
    375       1.1    jruoho  *
    376       1.1    jruoho  * DESCRIPTION: Determine if the function result value from an operator is
    377       1.1    jruoho  *              used.
    378       1.1    jruoho  *
    379       1.1    jruoho  ******************************************************************************/
    380       1.1    jruoho 
    381       1.1    jruoho BOOLEAN
    382       1.1    jruoho AnIsResultUsed (
    383       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    384       1.1    jruoho {
    385       1.1    jruoho     ACPI_PARSE_OBJECT       *Parent;
    386       1.1    jruoho 
    387       1.1    jruoho 
    388       1.1    jruoho     switch (Op->Asl.ParseOpcode)
    389       1.1    jruoho     {
    390       1.1    jruoho     case PARSEOP_INCREMENT:
    391       1.1    jruoho     case PARSEOP_DECREMENT:
    392       1.1    jruoho 
    393       1.1    jruoho         /* These are standalone operators, no return value */
    394       1.1    jruoho 
    395       1.1    jruoho         return (TRUE);
    396       1.1    jruoho 
    397       1.1    jruoho     default:
    398       1.2  christos 
    399       1.1    jruoho         break;
    400       1.1    jruoho     }
    401       1.1    jruoho 
    402       1.1    jruoho     /* Examine parent to determine if the return value is used */
    403       1.1    jruoho 
    404       1.1    jruoho     Parent = Op->Asl.Parent;
    405       1.1    jruoho     switch (Parent->Asl.ParseOpcode)
    406       1.1    jruoho     {
    407       1.1    jruoho     /* If/While - check if the operator is the predicate */
    408       1.1    jruoho 
    409       1.1    jruoho     case PARSEOP_IF:
    410       1.1    jruoho     case PARSEOP_WHILE:
    411       1.1    jruoho 
    412       1.1    jruoho         /* First child is the predicate */
    413       1.1    jruoho 
    414       1.1    jruoho         if (Parent->Asl.Child == Op)
    415       1.1    jruoho         {
    416       1.1    jruoho             return (TRUE);
    417       1.1    jruoho         }
    418       1.6  christos 
    419       1.1    jruoho         return (FALSE);
    420       1.1    jruoho 
    421       1.1    jruoho     /* Not used if one of these is the parent */
    422       1.1    jruoho 
    423       1.1    jruoho     case PARSEOP_METHOD:
    424       1.6  christos     case PARSEOP_DEFINITION_BLOCK:
    425       1.1    jruoho     case PARSEOP_ELSE:
    426       1.1    jruoho 
    427       1.1    jruoho         return (FALSE);
    428       1.1    jruoho 
    429       1.1    jruoho     default:
    430       1.2  christos 
    431       1.1    jruoho         /* Any other type of parent means that the result is used */
    432       1.1    jruoho 
    433       1.1    jruoho         return (TRUE);
    434       1.1    jruoho     }
    435       1.1    jruoho }
    436       1.1    jruoho 
    437       1.1    jruoho 
    438       1.1    jruoho /*******************************************************************************
    439       1.1    jruoho  *
    440       1.2  christos  * FUNCTION:    ApCheckForGpeNameConflict
    441       1.1    jruoho  *
    442       1.2  christos  * PARAMETERS:  Op                  - Current parse op
    443       1.1    jruoho  *
    444       1.2  christos  * RETURN:      None
    445       1.1    jruoho  *
    446       1.2  christos  * DESCRIPTION: Check for a conflict between GPE names within this scope.
    447       1.2  christos  *              Conflict means two GPE names with the same GPE number, but
    448       1.2  christos  *              different types -- such as _L1C and _E1C.
    449       1.1    jruoho  *
    450       1.1    jruoho  ******************************************************************************/
    451       1.1    jruoho 
    452       1.2  christos void
    453       1.2  christos ApCheckForGpeNameConflict (
    454       1.2  christos     ACPI_PARSE_OBJECT       *Op)
    455       1.1    jruoho {
    456       1.2  christos     ACPI_PARSE_OBJECT       *NextOp;
    457       1.2  christos     UINT32                  GpeNumber;
    458  1.10.2.1  christos     char                    Name[ACPI_NAMESEG_SIZE + 1];
    459  1.10.2.1  christos     char                    Target[ACPI_NAMESEG_SIZE];
    460       1.1    jruoho 
    461       1.1    jruoho 
    462       1.2  christos     /* Need a null-terminated string version of NameSeg */
    463       1.2  christos 
    464       1.2  christos     ACPI_MOVE_32_TO_32 (Name, &Op->Asl.NameSeg);
    465  1.10.2.1  christos     Name[ACPI_NAMESEG_SIZE] = 0;
    466       1.1    jruoho 
    467       1.1    jruoho     /*
    468       1.2  christos      * For a GPE method:
    469       1.2  christos      * 1st char must be underscore
    470       1.2  christos      * 2nd char must be L or E
    471       1.2  christos      * 3rd/4th chars must be a hex number
    472       1.1    jruoho      */
    473       1.2  christos     if ((Name[0] != '_') ||
    474       1.2  christos        ((Name[1] != 'L') && (Name[1] != 'E')))
    475       1.1    jruoho     {
    476       1.2  christos         return;
    477       1.2  christos     }
    478       1.1    jruoho 
    479       1.2  christos     /* Verify 3rd/4th chars are a valid hex value */
    480       1.1    jruoho 
    481       1.5  christos     GpeNumber = strtoul (&Name[2], NULL, 16);
    482       1.2  christos     if (GpeNumber == ACPI_UINT32_MAX)
    483       1.2  christos     {
    484       1.2  christos         return;
    485       1.1    jruoho     }
    486       1.1    jruoho 
    487       1.1    jruoho     /*
    488       1.2  christos      * We are now sure we have an _Lxx or _Exx.
    489       1.2  christos      * Create the target name that would cause collision (Flip E/L)
    490       1.1    jruoho      */
    491       1.2  christos     ACPI_MOVE_32_TO_32 (Target, Name);
    492       1.1    jruoho 
    493       1.2  christos     /* Inject opposite letter ("L" versus "E") */
    494       1.1    jruoho 
    495       1.2  christos     if (Name[1] == 'L')
    496       1.2  christos     {
    497       1.2  christos         Target[1] = 'E';
    498       1.2  christos     }
    499       1.2  christos     else /* Name[1] == 'E' */
    500       1.2  christos     {
    501       1.2  christos         Target[1] = 'L';
    502       1.2  christos     }
    503       1.1    jruoho 
    504       1.2  christos     /* Search all peers (objects within this scope) for target match */
    505       1.1    jruoho 
    506       1.2  christos     NextOp = Op->Asl.Next;
    507       1.2  christos     while (NextOp)
    508       1.2  christos     {
    509       1.1    jruoho         /*
    510       1.2  christos          * We mostly care about methods, but check Name() constructs also,
    511       1.2  christos          * even though they will get another error for not being a method.
    512       1.2  christos          * All GPE names must be defined as control methods.
    513       1.1    jruoho          */
    514       1.2  christos         if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) ||
    515       1.2  christos             (NextOp->Asl.ParseOpcode == PARSEOP_NAME))
    516       1.1    jruoho         {
    517  1.10.2.1  christos             if (ACPI_COMPARE_NAMESEG (Target, NextOp->Asl.NameSeg))
    518       1.2  christos             {
    519       1.2  christos                 /* Found both _Exy and _Lxy in the same scope, error */
    520       1.1    jruoho 
    521       1.2  christos                 AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp,
    522       1.2  christos                     Name);
    523       1.2  christos                 return;
    524       1.2  christos             }
    525       1.1    jruoho         }
    526       1.1    jruoho 
    527       1.2  christos         NextOp = NextOp->Asl.Next;
    528       1.1    jruoho     }
    529       1.1    jruoho 
    530       1.2  christos     /* OK, no conflict found */
    531       1.2  christos 
    532       1.2  christos     return;
    533       1.1    jruoho }
    534       1.1    jruoho 
    535       1.1    jruoho 
    536       1.1    jruoho /*******************************************************************************
    537       1.1    jruoho  *
    538       1.2  christos  * FUNCTION:    ApCheckRegMethod
    539       1.1    jruoho  *
    540       1.2  christos  * PARAMETERS:  Op                  - Current parse op
    541       1.1    jruoho  *
    542       1.2  christos  * RETURN:      None
    543       1.1    jruoho  *
    544       1.2  christos  * DESCRIPTION: Ensure that a _REG method has a corresponding Operation
    545       1.2  christos  *              Region declaration within the same scope. Note: _REG is defined
    546       1.2  christos  *              to have two arguments and must therefore be defined as a
    547       1.2  christos  *              control method.
    548       1.1    jruoho  *
    549       1.1    jruoho  ******************************************************************************/
    550       1.1    jruoho 
    551       1.2  christos void
    552       1.2  christos ApCheckRegMethod (
    553       1.2  christos     ACPI_PARSE_OBJECT       *Op)
    554       1.1    jruoho {
    555       1.2  christos     ACPI_PARSE_OBJECT       *Next;
    556       1.2  christos     ACPI_PARSE_OBJECT       *Parent;
    557       1.1    jruoho 
    558       1.1    jruoho 
    559       1.2  christos     /* We are only interested in _REG methods */
    560       1.1    jruoho 
    561  1.10.2.1  christos     if (!ACPI_COMPARE_NAMESEG (METHOD_NAME__REG, &Op->Asl.NameSeg))
    562       1.2  christos     {
    563       1.2  christos         return;
    564       1.2  christos     }
    565       1.1    jruoho 
    566       1.2  christos     /* Get the start of the current scope */
    567       1.1    jruoho 
    568       1.2  christos     Parent = Op->Asl.Parent;
    569       1.2  christos     Next = Parent->Asl.Child;
    570       1.1    jruoho 
    571       1.2  christos     /* Search entire scope for an operation region declaration */
    572       1.1    jruoho 
    573       1.2  christos     while (Next)
    574       1.1    jruoho     {
    575       1.2  christos         if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION)
    576       1.2  christos         {
    577       1.2  christos             return; /* Found region, OK */
    578       1.2  christos         }
    579       1.2  christos 
    580       1.2  christos         Next = Next->Asl.Next;
    581       1.1    jruoho     }
    582       1.1    jruoho 
    583       1.2  christos     /* No region found, issue warning */
    584       1.1    jruoho 
    585       1.2  christos     AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL);
    586       1.1    jruoho }
    587       1.3  christos 
    588       1.3  christos 
    589       1.3  christos /*******************************************************************************
    590       1.3  christos  *
    591       1.7  christos  * FUNCTION:    ApFindNameInDeviceTree
    592       1.7  christos  *
    593       1.7  christos  * PARAMETERS:  Name                - Name to search for
    594       1.7  christos  *              Op                  - Current parse op
    595       1.7  christos  *
    596       1.7  christos  * RETURN:      TRUE if name found in the same scope as Op.
    597       1.7  christos  *
    598       1.7  christos  * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
    599       1.7  christos  *              a Method() or a Name(). "Same scope" can mean under an If or
    600       1.7  christos  *              Else statement.
    601       1.7  christos  *
    602       1.7  christos  * NOTE: Detects _HID/_ADR in this type of construct (legal in ACPI 6.1+)
    603       1.7  christos  *
    604       1.7  christos  * Scope (\_SB.PCI0)
    605       1.7  christos  * {
    606       1.7  christos  *     Device (I2C0)
    607       1.7  christos  *     {
    608       1.7  christos  *         If (SMD0 != 4) {
    609       1.7  christos  *             Name (_HID, "INT3442")
    610       1.7  christos  *         } Else {
    611       1.7  christos  *             Name (_ADR, 0x400)
    612       1.7  christos  *         }
    613       1.7  christos  *     }
    614       1.7  christos  * }
    615       1.7  christos  ******************************************************************************/
    616       1.7  christos 
    617       1.7  christos BOOLEAN
    618       1.7  christos ApFindNameInDeviceTree (
    619       1.7  christos     char                    *Name,
    620       1.7  christos     ACPI_PARSE_OBJECT       *Op)
    621       1.7  christos {
    622       1.7  christos     ACPI_STATUS             Status;
    623       1.7  christos 
    624       1.7  christos 
    625       1.7  christos     Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
    626       1.7  christos         ApDeviceSubtreeWalk, NULL, Name);
    627       1.7  christos 
    628       1.7  christos     if (Status == AE_CTRL_TRUE)
    629       1.7  christos     {
    630       1.7  christos         return (TRUE);  /* Found a match */
    631       1.7  christos     }
    632       1.7  christos 
    633       1.7  christos     return (FALSE);
    634       1.7  christos }
    635       1.7  christos 
    636       1.7  christos 
    637       1.7  christos /* Callback function for interface above */
    638       1.7  christos 
    639       1.7  christos static ACPI_STATUS
    640       1.7  christos ApDeviceSubtreeWalk (
    641       1.7  christos     ACPI_PARSE_OBJECT       *Op,
    642       1.7  christos     UINT32                  Level,
    643       1.7  christos     void                    *Context)
    644       1.7  christos {
    645       1.7  christos     char                    *Name = ACPI_CAST_PTR (char, Context);
    646       1.7  christos 
    647       1.7  christos 
    648       1.7  christos     switch (Op->Asl.ParseOpcode)
    649       1.7  christos     {
    650       1.7  christos     case PARSEOP_DEVICE:
    651       1.7  christos 
    652       1.7  christos         /* Level 0 is the starting device, ignore it */
    653       1.7  christos 
    654       1.7  christos         if (Level > 0)
    655       1.7  christos         {
    656       1.7  christos             /* Ignore sub-devices */
    657       1.7  christos 
    658       1.7  christos             return (AE_CTRL_DEPTH);
    659       1.7  christos         }
    660       1.7  christos         break;
    661       1.7  christos 
    662       1.7  christos     case PARSEOP_NAME:
    663       1.7  christos     case PARSEOP_METHOD:
    664       1.7  christos 
    665       1.7  christos         /* These are what we are looking for */
    666       1.7  christos 
    667  1.10.2.1  christos         if (ACPI_COMPARE_NAMESEG (Name, Op->Asl.NameSeg))
    668       1.7  christos         {
    669       1.7  christos             return (AE_CTRL_TRUE);
    670       1.7  christos         }
    671       1.7  christos         return (AE_CTRL_DEPTH);
    672       1.7  christos 
    673       1.7  christos     case PARSEOP_SCOPE:
    674       1.7  christos     case PARSEOP_FIELD:
    675       1.7  christos     case PARSEOP_OPERATIONREGION:
    676       1.7  christos 
    677       1.7  christos         /*
    678       1.7  christos          * We want to ignore these, because either they can be large
    679       1.7  christos          * subtrees or open a scope to somewhere else.
    680       1.7  christos          */
    681       1.7  christos         return (AE_CTRL_DEPTH);
    682       1.7  christos 
    683       1.7  christos     default:
    684       1.7  christos         break;
    685       1.7  christos     }
    686       1.7  christos 
    687       1.7  christos     return (AE_OK);
    688       1.7  christos }
    689       1.7  christos 
    690       1.7  christos 
    691       1.7  christos /*******************************************************************************
    692       1.7  christos  *
    693       1.3  christos  * FUNCTION:    ApFindNameInScope
    694       1.3  christos  *
    695       1.3  christos  * PARAMETERS:  Name                - Name to search for
    696       1.3  christos  *              Op                  - Current parse op
    697       1.3  christos  *
    698       1.3  christos  * RETURN:      TRUE if name found in the same scope as Op.
    699       1.3  christos  *
    700       1.3  christos  * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
    701       1.3  christos  *              a Method() or a Name().
    702       1.3  christos  *
    703       1.3  christos  ******************************************************************************/
    704       1.3  christos 
    705       1.3  christos BOOLEAN
    706       1.3  christos ApFindNameInScope (
    707       1.3  christos     char                    *Name,
    708       1.3  christos     ACPI_PARSE_OBJECT       *Op)
    709       1.3  christos {
    710       1.3  christos     ACPI_PARSE_OBJECT       *Next;
    711       1.3  christos     ACPI_PARSE_OBJECT       *Parent;
    712       1.3  christos 
    713       1.3  christos 
    714       1.3  christos     /* Get the start of the current scope */
    715       1.3  christos 
    716       1.3  christos     Parent = Op->Asl.Parent;
    717       1.3  christos     Next = Parent->Asl.Child;
    718       1.3  christos 
    719       1.3  christos     /* Search entire scope for a match to the name */
    720       1.3  christos 
    721       1.3  christos     while (Next)
    722       1.3  christos     {
    723       1.3  christos         if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) ||
    724       1.3  christos             (Next->Asl.ParseOpcode == PARSEOP_NAME))
    725       1.3  christos         {
    726  1.10.2.1  christos             if (ACPI_COMPARE_NAMESEG (Name, Next->Asl.NameSeg))
    727       1.3  christos             {
    728       1.3  christos                 return (TRUE);
    729       1.3  christos             }
    730       1.3  christos         }
    731       1.3  christos 
    732       1.3  christos         Next = Next->Asl.Next;
    733       1.3  christos     }
    734       1.3  christos 
    735       1.3  christos     return (FALSE);
    736       1.3  christos }
    737