Home | History | Annotate | Line # | Download | only in compiler
asllookup.c revision 1.1.1.3.12.2
      1           1.1    jruoho /******************************************************************************
      2           1.1    jruoho  *
      3  1.1.1.3.12.1       tls  * Module Name: asllookup- Namespace lookup functions
      4           1.1    jruoho  *
      5           1.1    jruoho  *****************************************************************************/
      6           1.1    jruoho 
      7       1.1.1.2    jruoho /*
      8  1.1.1.3.12.2  jdolecek  * Copyright (C) 2000 - 2017, Intel Corp.
      9           1.1    jruoho  * All rights reserved.
     10           1.1    jruoho  *
     11       1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13       1.1.1.2    jruoho  * are met:
     14       1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1.1.2    jruoho  *    without modification.
     17       1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1.1.2    jruoho  *    binary redistribution.
     22       1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25       1.1.1.2    jruoho  *
     26       1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1.1.2    jruoho  * Software Foundation.
     29       1.1.1.2    jruoho  *
     30       1.1.1.2    jruoho  * NO WARRANTY
     31       1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1.1.2    jruoho  */
     43           1.1    jruoho 
     44           1.1    jruoho #include "aslcompiler.h"
     45           1.1    jruoho #include "aslcompiler.y.h"
     46           1.1    jruoho #include "acparser.h"
     47           1.1    jruoho #include "amlcode.h"
     48           1.1    jruoho #include "acnamesp.h"
     49           1.1    jruoho #include "acdispat.h"
     50           1.1    jruoho 
     51           1.1    jruoho 
     52           1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     53           1.1    jruoho         ACPI_MODULE_NAME    ("asllookup")
     54           1.1    jruoho 
     55           1.1    jruoho /* Local prototypes */
     56           1.1    jruoho 
     57           1.1    jruoho static ACPI_STATUS
     58           1.1    jruoho LkIsObjectUsed (
     59           1.1    jruoho     ACPI_HANDLE             ObjHandle,
     60           1.1    jruoho     UINT32                  Level,
     61           1.1    jruoho     void                    *Context,
     62           1.1    jruoho     void                    **ReturnValue);
     63           1.1    jruoho 
     64       1.1.1.2    jruoho static ACPI_PARSE_OBJECT *
     65           1.1    jruoho LkGetNameOp (
     66           1.1    jruoho     ACPI_PARSE_OBJECT       *Op);
     67           1.1    jruoho 
     68           1.1    jruoho 
     69           1.1    jruoho /*******************************************************************************
     70           1.1    jruoho  *
     71  1.1.1.3.12.1       tls  * FUNCTION:    LkFindUnreferencedObjects
     72           1.1    jruoho  *
     73  1.1.1.3.12.1       tls  * PARAMETERS:  None
     74           1.1    jruoho  *
     75           1.1    jruoho  * RETURN:      None
     76           1.1    jruoho  *
     77  1.1.1.3.12.1       tls  * DESCRIPTION: Namespace walk to find objects that are not referenced in any
     78  1.1.1.3.12.1       tls  *              way. Must be called after the namespace has been cross
     79  1.1.1.3.12.1       tls  *              referenced.
     80           1.1    jruoho  *
     81           1.1    jruoho  ******************************************************************************/
     82           1.1    jruoho 
     83           1.1    jruoho void
     84  1.1.1.3.12.1       tls LkFindUnreferencedObjects (
     85           1.1    jruoho     void)
     86           1.1    jruoho {
     87           1.1    jruoho 
     88           1.1    jruoho     /* Walk entire namespace from the supplied root */
     89           1.1    jruoho 
     90  1.1.1.3.12.1       tls     (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
     91  1.1.1.3.12.1       tls                 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
     92  1.1.1.3.12.1       tls                 NULL, NULL);
     93           1.1    jruoho }
     94           1.1    jruoho 
     95           1.1    jruoho 
     96           1.1    jruoho /*******************************************************************************
     97           1.1    jruoho  *
     98           1.1    jruoho  * FUNCTION:    LkIsObjectUsed
     99           1.1    jruoho  *
    100           1.1    jruoho  * PARAMETERS:  ACPI_WALK_CALLBACK
    101           1.1    jruoho  *
    102           1.1    jruoho  * RETURN:      Status
    103           1.1    jruoho  *
    104           1.1    jruoho  * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
    105           1.1    jruoho  *              We have to be careful, because some types and names are
    106           1.1    jruoho  *              typically or always unreferenced, we don't want to issue
    107  1.1.1.3.12.1       tls  *              excessive warnings. Note: Names that are declared within a
    108  1.1.1.3.12.1       tls  *              control method are temporary, so we always issue a remark
    109  1.1.1.3.12.1       tls  *              if they are not referenced.
    110           1.1    jruoho  *
    111           1.1    jruoho  ******************************************************************************/
    112           1.1    jruoho 
    113           1.1    jruoho static ACPI_STATUS
    114           1.1    jruoho LkIsObjectUsed (
    115           1.1    jruoho     ACPI_HANDLE             ObjHandle,
    116           1.1    jruoho     UINT32                  Level,
    117           1.1    jruoho     void                    *Context,
    118           1.1    jruoho     void                    **ReturnValue)
    119           1.1    jruoho {
    120           1.1    jruoho     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    121  1.1.1.3.12.1       tls     ACPI_NAMESPACE_NODE     *Next;
    122  1.1.1.3.12.2  jdolecek     ASL_METHOD_LOCAL        *MethodLocals;
    123  1.1.1.3.12.2  jdolecek     ASL_METHOD_LOCAL        *MethodArgs;
    124  1.1.1.3.12.2  jdolecek     UINT32                  i;
    125  1.1.1.3.12.2  jdolecek 
    126  1.1.1.3.12.2  jdolecek 
    127  1.1.1.3.12.2  jdolecek     if (Node->Type == ACPI_TYPE_METHOD)
    128  1.1.1.3.12.2  jdolecek     {
    129  1.1.1.3.12.2  jdolecek         if (!Node->Op || !Node->MethodLocals)
    130  1.1.1.3.12.2  jdolecek         {
    131  1.1.1.3.12.2  jdolecek             return (AE_OK);
    132  1.1.1.3.12.2  jdolecek         }
    133  1.1.1.3.12.2  jdolecek 
    134  1.1.1.3.12.2  jdolecek         MethodLocals = (ASL_METHOD_LOCAL *) Node->MethodLocals;
    135  1.1.1.3.12.2  jdolecek         MethodArgs = (ASL_METHOD_LOCAL *) Node->MethodArgs;
    136           1.1    jruoho 
    137  1.1.1.3.12.2  jdolecek         /*
    138  1.1.1.3.12.2  jdolecek          * Analysis of LocalX variables
    139  1.1.1.3.12.2  jdolecek          */
    140  1.1.1.3.12.2  jdolecek         for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
    141  1.1.1.3.12.2  jdolecek         {
    142  1.1.1.3.12.2  jdolecek             /* Warn for Locals that are set but never referenced */
    143  1.1.1.3.12.2  jdolecek 
    144  1.1.1.3.12.2  jdolecek             if ((MethodLocals[i].Flags & ASL_LOCAL_INITIALIZED) &&
    145  1.1.1.3.12.2  jdolecek                 (!(MethodLocals[i].Flags & ASL_LOCAL_REFERENCED)))
    146  1.1.1.3.12.2  jdolecek             {
    147  1.1.1.3.12.2  jdolecek                 sprintf (MsgBuffer, "Local%u", i);
    148  1.1.1.3.12.2  jdolecek                 AslError (ASL_WARNING, ASL_MSG_LOCAL_NOT_USED,
    149  1.1.1.3.12.2  jdolecek                     MethodLocals[i].Op, MsgBuffer);
    150  1.1.1.3.12.2  jdolecek             }
    151  1.1.1.3.12.2  jdolecek         }
    152  1.1.1.3.12.2  jdolecek 
    153  1.1.1.3.12.2  jdolecek         /*
    154  1.1.1.3.12.2  jdolecek          * Analysis of ArgX variables (standard method arguments,
    155  1.1.1.3.12.2  jdolecek          * and remaining unused ArgX can also be used as locals)
    156  1.1.1.3.12.2  jdolecek          */
    157  1.1.1.3.12.2  jdolecek         for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
    158  1.1.1.3.12.2  jdolecek         {
    159  1.1.1.3.12.2  jdolecek             if (MethodArgs[i].Flags & ASL_ARG_IS_LOCAL)
    160  1.1.1.3.12.2  jdolecek             {
    161  1.1.1.3.12.2  jdolecek                 /* Warn if ArgX is being used as a local, but not referenced */
    162  1.1.1.3.12.2  jdolecek 
    163  1.1.1.3.12.2  jdolecek                 if ((MethodArgs[i].Flags & ASL_ARG_INITIALIZED) &&
    164  1.1.1.3.12.2  jdolecek                     (!(MethodArgs[i].Flags & ASL_ARG_REFERENCED)))
    165  1.1.1.3.12.2  jdolecek                 {
    166  1.1.1.3.12.2  jdolecek                     sprintf (MsgBuffer, "Arg%u", i);
    167  1.1.1.3.12.2  jdolecek                     AslError (ASL_WARNING, ASL_MSG_ARG_AS_LOCAL_NOT_USED,
    168  1.1.1.3.12.2  jdolecek                         MethodArgs[i].Op, MsgBuffer);
    169  1.1.1.3.12.2  jdolecek                 }
    170  1.1.1.3.12.2  jdolecek             }
    171  1.1.1.3.12.2  jdolecek             else
    172  1.1.1.3.12.2  jdolecek             {
    173  1.1.1.3.12.2  jdolecek                 /*
    174  1.1.1.3.12.2  jdolecek                  * Remark if a normal method ArgX is not referenced.
    175  1.1.1.3.12.2  jdolecek                  * We ignore the predefined methods since often, not
    176  1.1.1.3.12.2  jdolecek                  * all arguments are needed or used.
    177  1.1.1.3.12.2  jdolecek                  */
    178  1.1.1.3.12.2  jdolecek                 if ((Node->Name.Ascii[0] != '_') &&
    179  1.1.1.3.12.2  jdolecek                     (!(MethodArgs[i].Flags & ASL_ARG_REFERENCED)))
    180  1.1.1.3.12.2  jdolecek                 {
    181  1.1.1.3.12.2  jdolecek                     sprintf (MsgBuffer, "Arg%u", i);
    182  1.1.1.3.12.2  jdolecek                     AslError (ASL_REMARK, ASL_MSG_ARG_NOT_USED,
    183  1.1.1.3.12.2  jdolecek                         MethodArgs[i].Op, MsgBuffer);
    184  1.1.1.3.12.2  jdolecek                 }
    185  1.1.1.3.12.2  jdolecek             }
    186  1.1.1.3.12.2  jdolecek         }
    187  1.1.1.3.12.2  jdolecek     }
    188           1.1    jruoho 
    189           1.1    jruoho     /* Referenced flag is set during the namespace xref */
    190           1.1    jruoho 
    191           1.1    jruoho     if (Node->Flags & ANOBJ_IS_REFERENCED)
    192           1.1    jruoho     {
    193           1.1    jruoho         return (AE_OK);
    194           1.1    jruoho     }
    195           1.1    jruoho 
    196  1.1.1.3.12.1       tls     if (!Node->Op)
    197           1.1    jruoho     {
    198           1.1    jruoho         return (AE_OK);
    199           1.1    jruoho     }
    200           1.1    jruoho 
    201  1.1.1.3.12.1       tls     /* These types are typically never directly referenced, ignore them */
    202           1.1    jruoho 
    203           1.1    jruoho     switch (Node->Type)
    204           1.1    jruoho     {
    205           1.1    jruoho     case ACPI_TYPE_DEVICE:
    206           1.1    jruoho     case ACPI_TYPE_PROCESSOR:
    207           1.1    jruoho     case ACPI_TYPE_POWER:
    208  1.1.1.3.12.1       tls     case ACPI_TYPE_THERMAL:
    209           1.1    jruoho     case ACPI_TYPE_LOCAL_RESOURCE:
    210  1.1.1.3.12.2  jdolecek     case ACPI_TYPE_LOCAL_RESOURCE_FIELD: /* Names assigned to descriptor elements */
    211  1.1.1.3.12.1       tls 
    212           1.1    jruoho         return (AE_OK);
    213           1.1    jruoho 
    214           1.1    jruoho     default:
    215  1.1.1.3.12.1       tls 
    216           1.1    jruoho         break;
    217           1.1    jruoho     }
    218           1.1    jruoho 
    219  1.1.1.3.12.1       tls     /* Determine if the name is within a control method */
    220           1.1    jruoho 
    221  1.1.1.3.12.1       tls     Next = Node->Parent;
    222  1.1.1.3.12.1       tls     while (Next)
    223           1.1    jruoho     {
    224  1.1.1.3.12.1       tls         if (Next->Type == ACPI_TYPE_METHOD)
    225  1.1.1.3.12.1       tls         {
    226  1.1.1.3.12.1       tls             /*
    227  1.1.1.3.12.1       tls              * Name is within a method, therefore it is temporary.
    228  1.1.1.3.12.1       tls              * Issue a remark even if it is a reserved name (starts
    229  1.1.1.3.12.1       tls              * with an underscore).
    230  1.1.1.3.12.1       tls              */
    231  1.1.1.3.12.2  jdolecek             snprintf (MsgBuffer, sizeof(MsgBuffer), "Name [%4.4s] is within a method [%4.4s]",
    232  1.1.1.3.12.2  jdolecek                 Node->Name.Ascii, Next->Name.Ascii);
    233  1.1.1.3.12.1       tls             AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED,
    234  1.1.1.3.12.1       tls                 LkGetNameOp (Node->Op), MsgBuffer);
    235  1.1.1.3.12.1       tls             return (AE_OK);
    236  1.1.1.3.12.1       tls         }
    237           1.1    jruoho 
    238  1.1.1.3.12.1       tls         Next = Next->Parent;
    239           1.1    jruoho     }
    240           1.1    jruoho 
    241  1.1.1.3.12.1       tls     /* The name is not within a control method */
    242           1.1    jruoho 
    243           1.1    jruoho     /*
    244  1.1.1.3.12.1       tls      * Ignore names that start with an underscore. These are the reserved
    245  1.1.1.3.12.1       tls      * ACPI names and are typically not referenced since they are meant
    246  1.1.1.3.12.1       tls      * to be called by the host OS.
    247           1.1    jruoho      */
    248  1.1.1.3.12.1       tls     if (Node->Name.Ascii[0] == '_')
    249           1.1    jruoho     {
    250  1.1.1.3.12.1       tls         return (AE_OK);
    251           1.1    jruoho     }
    252           1.1    jruoho 
    253           1.1    jruoho     /*
    254  1.1.1.3.12.1       tls      * What remains is an unresolved user name that is not within a method.
    255  1.1.1.3.12.1       tls      * However, the object could be referenced via another table, so issue
    256  1.1.1.3.12.1       tls      * the warning at level 2.
    257           1.1    jruoho      */
    258  1.1.1.3.12.1       tls     AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED,
    259  1.1.1.3.12.1       tls         LkGetNameOp (Node->Op), NULL);
    260  1.1.1.3.12.1       tls     return (AE_OK);
    261           1.1    jruoho }
    262           1.1    jruoho 
    263  1.1.1.3.12.1       tls 
    264           1.1    jruoho /*******************************************************************************
    265           1.1    jruoho  *
    266  1.1.1.3.12.1       tls  * FUNCTION:    LkGetNameOp
    267           1.1    jruoho  *
    268  1.1.1.3.12.1       tls  * PARAMETERS:  Op              - Current Op
    269           1.1    jruoho  *
    270  1.1.1.3.12.1       tls  * RETURN:      NameOp associated with the input op
    271           1.1    jruoho  *
    272  1.1.1.3.12.1       tls  * DESCRIPTION: Find the name declaration op associated with the operator
    273           1.1    jruoho  *
    274           1.1    jruoho  ******************************************************************************/
    275           1.1    jruoho 
    276  1.1.1.3.12.1       tls static ACPI_PARSE_OBJECT *
    277  1.1.1.3.12.1       tls LkGetNameOp (
    278  1.1.1.3.12.1       tls     ACPI_PARSE_OBJECT       *Op)
    279           1.1    jruoho {
    280           1.1    jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    281  1.1.1.3.12.1       tls     ACPI_PARSE_OBJECT       *NameOp = Op;
    282           1.1    jruoho 
    283           1.1    jruoho 
    284           1.1    jruoho     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    285           1.1    jruoho 
    286           1.1    jruoho 
    287           1.1    jruoho     /* Get the NamePath from the appropriate place */
    288           1.1    jruoho 
    289           1.1    jruoho     if (OpInfo->Flags & AML_NAMED)
    290           1.1    jruoho     {
    291           1.1    jruoho         /* For nearly all NAMED operators, the name reference is the first child */
    292           1.1    jruoho 
    293  1.1.1.3.12.1       tls         NameOp = Op->Asl.Child;
    294           1.1    jruoho         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
    295           1.1    jruoho         {
    296           1.1    jruoho             /*
    297           1.1    jruoho              * ALIAS is the only oddball opcode, the name declaration
    298           1.1    jruoho              * (alias name) is the second operand
    299           1.1    jruoho              */
    300  1.1.1.3.12.1       tls             NameOp = Op->Asl.Child->Asl.Next;
    301           1.1    jruoho         }
    302           1.1    jruoho     }
    303           1.1    jruoho     else if (OpInfo->Flags & AML_CREATE)
    304           1.1    jruoho     {
    305           1.1    jruoho         /* Name must appear as the last parameter */
    306           1.1    jruoho 
    307  1.1.1.3.12.1       tls         NameOp = Op->Asl.Child;
    308  1.1.1.3.12.2  jdolecek         while (!(NameOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
    309           1.1    jruoho         {
    310  1.1.1.3.12.1       tls             NameOp = NameOp->Asl.Next;
    311           1.1    jruoho         }
    312           1.1    jruoho     }
    313           1.1    jruoho 
    314  1.1.1.3.12.1       tls     return (NameOp);
    315           1.1    jruoho }
    316