Home | History | Annotate | Line # | Download | only in compiler
asllookup.c revision 1.1.1.3.2.1
      1          1.1  jruoho /******************************************************************************
      2          1.1  jruoho  *
      3  1.1.1.3.2.1    yamt  * 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.2.1    yamt  * Copyright (C) 2000 - 2013, 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 
     45          1.1  jruoho #include "aslcompiler.h"
     46          1.1  jruoho #include "aslcompiler.y.h"
     47          1.1  jruoho #include "acparser.h"
     48          1.1  jruoho #include "amlcode.h"
     49          1.1  jruoho #include "acnamesp.h"
     50          1.1  jruoho #include "acdispat.h"
     51          1.1  jruoho 
     52          1.1  jruoho 
     53          1.1  jruoho #define _COMPONENT          ACPI_COMPILER
     54          1.1  jruoho         ACPI_MODULE_NAME    ("asllookup")
     55          1.1  jruoho 
     56          1.1  jruoho /* Local prototypes */
     57          1.1  jruoho 
     58          1.1  jruoho static ACPI_STATUS
     59          1.1  jruoho LkIsObjectUsed (
     60          1.1  jruoho     ACPI_HANDLE             ObjHandle,
     61          1.1  jruoho     UINT32                  Level,
     62          1.1  jruoho     void                    *Context,
     63          1.1  jruoho     void                    **ReturnValue);
     64          1.1  jruoho 
     65      1.1.1.2  jruoho static ACPI_PARSE_OBJECT *
     66          1.1  jruoho LkGetNameOp (
     67          1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
     68          1.1  jruoho 
     69          1.1  jruoho 
     70          1.1  jruoho /*******************************************************************************
     71          1.1  jruoho  *
     72  1.1.1.3.2.1    yamt  * FUNCTION:    LkFindUnreferencedObjects
     73          1.1  jruoho  *
     74  1.1.1.3.2.1    yamt  * PARAMETERS:  None
     75          1.1  jruoho  *
     76          1.1  jruoho  * RETURN:      None
     77          1.1  jruoho  *
     78  1.1.1.3.2.1    yamt  * DESCRIPTION: Namespace walk to find objects that are not referenced in any
     79  1.1.1.3.2.1    yamt  *              way. Must be called after the namespace has been cross
     80  1.1.1.3.2.1    yamt  *              referenced.
     81          1.1  jruoho  *
     82          1.1  jruoho  ******************************************************************************/
     83          1.1  jruoho 
     84          1.1  jruoho void
     85  1.1.1.3.2.1    yamt LkFindUnreferencedObjects (
     86          1.1  jruoho     void)
     87          1.1  jruoho {
     88          1.1  jruoho 
     89          1.1  jruoho     /* Walk entire namespace from the supplied root */
     90          1.1  jruoho 
     91  1.1.1.3.2.1    yamt     (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
     92  1.1.1.3.2.1    yamt                 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
     93  1.1.1.3.2.1    yamt                 NULL, NULL);
     94          1.1  jruoho }
     95          1.1  jruoho 
     96          1.1  jruoho 
     97          1.1  jruoho /*******************************************************************************
     98          1.1  jruoho  *
     99          1.1  jruoho  * FUNCTION:    LkIsObjectUsed
    100          1.1  jruoho  *
    101          1.1  jruoho  * PARAMETERS:  ACPI_WALK_CALLBACK
    102          1.1  jruoho  *
    103          1.1  jruoho  * RETURN:      Status
    104          1.1  jruoho  *
    105          1.1  jruoho  * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
    106          1.1  jruoho  *              We have to be careful, because some types and names are
    107          1.1  jruoho  *              typically or always unreferenced, we don't want to issue
    108  1.1.1.3.2.1    yamt  *              excessive warnings. Note: Names that are declared within a
    109  1.1.1.3.2.1    yamt  *              control method are temporary, so we always issue a remark
    110  1.1.1.3.2.1    yamt  *              if they are not referenced.
    111          1.1  jruoho  *
    112          1.1  jruoho  ******************************************************************************/
    113          1.1  jruoho 
    114          1.1  jruoho static ACPI_STATUS
    115          1.1  jruoho LkIsObjectUsed (
    116          1.1  jruoho     ACPI_HANDLE             ObjHandle,
    117          1.1  jruoho     UINT32                  Level,
    118          1.1  jruoho     void                    *Context,
    119          1.1  jruoho     void                    **ReturnValue)
    120          1.1  jruoho {
    121          1.1  jruoho     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    122  1.1.1.3.2.1    yamt     ACPI_NAMESPACE_NODE     *Next;
    123          1.1  jruoho 
    124          1.1  jruoho 
    125          1.1  jruoho     /* Referenced flag is set during the namespace xref */
    126          1.1  jruoho 
    127          1.1  jruoho     if (Node->Flags & ANOBJ_IS_REFERENCED)
    128          1.1  jruoho     {
    129          1.1  jruoho         return (AE_OK);
    130          1.1  jruoho     }
    131          1.1  jruoho 
    132  1.1.1.3.2.1    yamt     if (!Node->Op)
    133          1.1  jruoho     {
    134          1.1  jruoho         return (AE_OK);
    135          1.1  jruoho     }
    136          1.1  jruoho 
    137  1.1.1.3.2.1    yamt     /* These types are typically never directly referenced, ignore them */
    138          1.1  jruoho 
    139          1.1  jruoho     switch (Node->Type)
    140          1.1  jruoho     {
    141          1.1  jruoho     case ACPI_TYPE_DEVICE:
    142          1.1  jruoho     case ACPI_TYPE_PROCESSOR:
    143          1.1  jruoho     case ACPI_TYPE_POWER:
    144  1.1.1.3.2.1    yamt     case ACPI_TYPE_THERMAL:
    145          1.1  jruoho     case ACPI_TYPE_LOCAL_RESOURCE:
    146  1.1.1.3.2.1    yamt 
    147          1.1  jruoho         return (AE_OK);
    148          1.1  jruoho 
    149          1.1  jruoho     default:
    150  1.1.1.3.2.1    yamt 
    151          1.1  jruoho         break;
    152          1.1  jruoho     }
    153          1.1  jruoho 
    154  1.1.1.3.2.1    yamt     /* Determine if the name is within a control method */
    155          1.1  jruoho 
    156  1.1.1.3.2.1    yamt     Next = Node->Parent;
    157  1.1.1.3.2.1    yamt     while (Next)
    158          1.1  jruoho     {
    159  1.1.1.3.2.1    yamt         if (Next->Type == ACPI_TYPE_METHOD)
    160  1.1.1.3.2.1    yamt         {
    161  1.1.1.3.2.1    yamt             /*
    162  1.1.1.3.2.1    yamt              * Name is within a method, therefore it is temporary.
    163  1.1.1.3.2.1    yamt              * Issue a remark even if it is a reserved name (starts
    164  1.1.1.3.2.1    yamt              * with an underscore).
    165  1.1.1.3.2.1    yamt              */
    166  1.1.1.3.2.1    yamt             snprintf (MsgBuffer, sizeof(MsgBuffer), "Name is within method [%4.4s]",
    167  1.1.1.3.2.1    yamt                 Next->Name.Ascii);
    168  1.1.1.3.2.1    yamt             AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED,
    169  1.1.1.3.2.1    yamt                 LkGetNameOp (Node->Op), MsgBuffer);
    170  1.1.1.3.2.1    yamt             return (AE_OK);
    171  1.1.1.3.2.1    yamt         }
    172          1.1  jruoho 
    173  1.1.1.3.2.1    yamt         Next = Next->Parent;
    174          1.1  jruoho     }
    175          1.1  jruoho 
    176  1.1.1.3.2.1    yamt     /* The name is not within a control method */
    177          1.1  jruoho 
    178          1.1  jruoho     /*
    179  1.1.1.3.2.1    yamt      * Ignore names that start with an underscore. These are the reserved
    180  1.1.1.3.2.1    yamt      * ACPI names and are typically not referenced since they are meant
    181  1.1.1.3.2.1    yamt      * to be called by the host OS.
    182          1.1  jruoho      */
    183  1.1.1.3.2.1    yamt     if (Node->Name.Ascii[0] == '_')
    184          1.1  jruoho     {
    185  1.1.1.3.2.1    yamt         return (AE_OK);
    186          1.1  jruoho     }
    187          1.1  jruoho 
    188          1.1  jruoho     /*
    189  1.1.1.3.2.1    yamt      * What remains is an unresolved user name that is not within a method.
    190  1.1.1.3.2.1    yamt      * However, the object could be referenced via another table, so issue
    191  1.1.1.3.2.1    yamt      * the warning at level 2.
    192          1.1  jruoho      */
    193  1.1.1.3.2.1    yamt     AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED,
    194  1.1.1.3.2.1    yamt         LkGetNameOp (Node->Op), NULL);
    195  1.1.1.3.2.1    yamt     return (AE_OK);
    196          1.1  jruoho }
    197          1.1  jruoho 
    198  1.1.1.3.2.1    yamt 
    199          1.1  jruoho /*******************************************************************************
    200          1.1  jruoho  *
    201  1.1.1.3.2.1    yamt  * FUNCTION:    LkGetNameOp
    202          1.1  jruoho  *
    203  1.1.1.3.2.1    yamt  * PARAMETERS:  Op              - Current Op
    204          1.1  jruoho  *
    205  1.1.1.3.2.1    yamt  * RETURN:      NameOp associated with the input op
    206          1.1  jruoho  *
    207  1.1.1.3.2.1    yamt  * DESCRIPTION: Find the name declaration op associated with the operator
    208          1.1  jruoho  *
    209          1.1  jruoho  ******************************************************************************/
    210          1.1  jruoho 
    211  1.1.1.3.2.1    yamt static ACPI_PARSE_OBJECT *
    212  1.1.1.3.2.1    yamt LkGetNameOp (
    213  1.1.1.3.2.1    yamt     ACPI_PARSE_OBJECT       *Op)
    214          1.1  jruoho {
    215          1.1  jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    216  1.1.1.3.2.1    yamt     ACPI_PARSE_OBJECT       *NameOp = Op;
    217          1.1  jruoho 
    218          1.1  jruoho 
    219          1.1  jruoho     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    220          1.1  jruoho 
    221          1.1  jruoho 
    222          1.1  jruoho     /* Get the NamePath from the appropriate place */
    223          1.1  jruoho 
    224          1.1  jruoho     if (OpInfo->Flags & AML_NAMED)
    225          1.1  jruoho     {
    226          1.1  jruoho         /* For nearly all NAMED operators, the name reference is the first child */
    227          1.1  jruoho 
    228  1.1.1.3.2.1    yamt         NameOp = Op->Asl.Child;
    229          1.1  jruoho         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
    230          1.1  jruoho         {
    231          1.1  jruoho             /*
    232          1.1  jruoho              * ALIAS is the only oddball opcode, the name declaration
    233          1.1  jruoho              * (alias name) is the second operand
    234          1.1  jruoho              */
    235  1.1.1.3.2.1    yamt             NameOp = Op->Asl.Child->Asl.Next;
    236          1.1  jruoho         }
    237          1.1  jruoho     }
    238          1.1  jruoho     else if (OpInfo->Flags & AML_CREATE)
    239          1.1  jruoho     {
    240          1.1  jruoho         /* Name must appear as the last parameter */
    241          1.1  jruoho 
    242  1.1.1.3.2.1    yamt         NameOp = Op->Asl.Child;
    243  1.1.1.3.2.1    yamt         while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
    244          1.1  jruoho         {
    245  1.1.1.3.2.1    yamt             NameOp = NameOp->Asl.Next;
    246          1.1  jruoho         }
    247          1.1  jruoho     }
    248          1.1  jruoho 
    249  1.1.1.3.2.1    yamt     return (NameOp);
    250          1.1  jruoho }
    251