Home | History | Annotate | Line # | Download | only in executer
exresnte.c revision 1.1.1.6
      1 /******************************************************************************
      2  *
      3  * Module Name: exresnte - AML Interpreter object resolution
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2016, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acdispat.h"
     47 #include "acinterp.h"
     48 #include "acnamesp.h"
     49 
     50 
     51 #define _COMPONENT          ACPI_EXECUTER
     52         ACPI_MODULE_NAME    ("exresnte")
     53 
     54 
     55 /*******************************************************************************
     56  *
     57  * FUNCTION:    AcpiExResolveNodeToValue
     58  *
     59  * PARAMETERS:  ObjectPtr       - Pointer to a location that contains
     60  *                                a pointer to a NS node, and will receive a
     61  *                                pointer to the resolved object.
     62  *              WalkState       - Current state. Valid only if executing AML
     63  *                                code. NULL if simply resolving an object
     64  *
     65  * RETURN:      Status
     66  *
     67  * DESCRIPTION: Resolve a Namespace node to a valued object
     68  *
     69  * Note: for some of the data types, the pointer attached to the Node
     70  * can be either a pointer to an actual internal object or a pointer into the
     71  * AML stream itself. These types are currently:
     72  *
     73  *      ACPI_TYPE_INTEGER
     74  *      ACPI_TYPE_STRING
     75  *      ACPI_TYPE_BUFFER
     76  *      ACPI_TYPE_MUTEX
     77  *      ACPI_TYPE_PACKAGE
     78  *
     79  ******************************************************************************/
     80 
     81 ACPI_STATUS
     82 AcpiExResolveNodeToValue (
     83     ACPI_NAMESPACE_NODE     **ObjectPtr,
     84     ACPI_WALK_STATE         *WalkState)
     85 
     86 {
     87     ACPI_STATUS             Status = AE_OK;
     88     ACPI_OPERAND_OBJECT     *SourceDesc;
     89     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
     90     ACPI_NAMESPACE_NODE     *Node;
     91     ACPI_OBJECT_TYPE        EntryType;
     92 
     93 
     94     ACPI_FUNCTION_TRACE (ExResolveNodeToValue);
     95 
     96 
     97     /*
     98      * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the
     99      * object that is attached to the Node.
    100      */
    101     Node = *ObjectPtr;
    102     SourceDesc = AcpiNsGetAttachedObject (Node);
    103     EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
    104 
    105     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
    106          Node, SourceDesc, AcpiUtGetTypeName (EntryType)));
    107 
    108     if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) ||
    109         (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS))
    110     {
    111         /* There is always exactly one level of indirection */
    112 
    113         Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
    114         SourceDesc = AcpiNsGetAttachedObject (Node);
    115         EntryType = AcpiNsGetType ((ACPI_HANDLE) Node);
    116         *ObjectPtr = Node;
    117     }
    118 
    119     /*
    120      * Several object types require no further processing:
    121      * 1) Device/Thermal objects don't have a "real" subobject, return Node
    122      * 2) Method locals and arguments have a pseudo-Node
    123      * 3) 10/2007: Added method type to assist with Package construction.
    124      */
    125     if ((EntryType == ACPI_TYPE_DEVICE)  ||
    126         (EntryType == ACPI_TYPE_THERMAL) ||
    127         (EntryType == ACPI_TYPE_METHOD)  ||
    128         (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL)))
    129     {
    130         return_ACPI_STATUS (AE_OK);
    131     }
    132 
    133     if (!SourceDesc)
    134     {
    135         ACPI_ERROR ((AE_INFO, "No object attached to node [%4.4s] %p",
    136             Node->Name.Ascii, Node));
    137         return_ACPI_STATUS (AE_AML_UNINITIALIZED_NODE);
    138     }
    139 
    140     /*
    141      * Action is based on the type of the Node, which indicates the type
    142      * of the attached object or pointer
    143      */
    144     switch (EntryType)
    145     {
    146     case ACPI_TYPE_PACKAGE:
    147 
    148         if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE)
    149         {
    150             ACPI_ERROR ((AE_INFO, "Object not a Package, type %s",
    151                 AcpiUtGetObjectTypeName (SourceDesc)));
    152             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    153         }
    154 
    155         Status = AcpiDsGetPackageArguments (SourceDesc);
    156         if (ACPI_SUCCESS (Status))
    157         {
    158             /* Return an additional reference to the object */
    159 
    160             ObjDesc = SourceDesc;
    161             AcpiUtAddReference (ObjDesc);
    162         }
    163         break;
    164 
    165     case ACPI_TYPE_BUFFER:
    166 
    167         if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
    168         {
    169             ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s",
    170                 AcpiUtGetObjectTypeName (SourceDesc)));
    171             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    172         }
    173 
    174         Status = AcpiDsGetBufferArguments (SourceDesc);
    175         if (ACPI_SUCCESS (Status))
    176         {
    177             /* Return an additional reference to the object */
    178 
    179             ObjDesc = SourceDesc;
    180             AcpiUtAddReference (ObjDesc);
    181         }
    182         break;
    183 
    184     case ACPI_TYPE_STRING:
    185 
    186         if (SourceDesc->Common.Type != ACPI_TYPE_STRING)
    187         {
    188             ACPI_ERROR ((AE_INFO, "Object not a String, type %s",
    189                 AcpiUtGetObjectTypeName (SourceDesc)));
    190             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    191         }
    192 
    193         /* Return an additional reference to the object */
    194 
    195         ObjDesc = SourceDesc;
    196         AcpiUtAddReference (ObjDesc);
    197         break;
    198 
    199     case ACPI_TYPE_INTEGER:
    200 
    201         if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER)
    202         {
    203             ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s",
    204                 AcpiUtGetObjectTypeName (SourceDesc)));
    205             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    206         }
    207 
    208         /* Return an additional reference to the object */
    209 
    210         ObjDesc = SourceDesc;
    211         AcpiUtAddReference (ObjDesc);
    212         break;
    213 
    214     case ACPI_TYPE_BUFFER_FIELD:
    215     case ACPI_TYPE_LOCAL_REGION_FIELD:
    216     case ACPI_TYPE_LOCAL_BANK_FIELD:
    217     case ACPI_TYPE_LOCAL_INDEX_FIELD:
    218 
    219         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    220             "FieldRead Node=%p SourceDesc=%p Type=%X\n",
    221             Node, SourceDesc, EntryType));
    222 
    223         Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc);
    224         break;
    225 
    226     /* For these objects, just return the object attached to the Node */
    227 
    228     case ACPI_TYPE_MUTEX:
    229     case ACPI_TYPE_POWER:
    230     case ACPI_TYPE_PROCESSOR:
    231     case ACPI_TYPE_EVENT:
    232     case ACPI_TYPE_REGION:
    233 
    234         /* Return an additional reference to the object */
    235 
    236         ObjDesc = SourceDesc;
    237         AcpiUtAddReference (ObjDesc);
    238         break;
    239 
    240     /* TYPE_ANY is untyped, and thus there is no object associated with it */
    241 
    242     case ACPI_TYPE_ANY:
    243 
    244         ACPI_ERROR ((AE_INFO,
    245             "Untyped entry %p, no attached object!", Node));
    246 
    247         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);  /* Cannot be AE_TYPE */
    248 
    249     case ACPI_TYPE_LOCAL_REFERENCE:
    250 
    251         switch (SourceDesc->Reference.Class)
    252         {
    253         case ACPI_REFCLASS_TABLE:   /* This is a DdbHandle */
    254         case ACPI_REFCLASS_REFOF:
    255         case ACPI_REFCLASS_INDEX:
    256 
    257             /* Return an additional reference to the object */
    258 
    259             ObjDesc = SourceDesc;
    260             AcpiUtAddReference (ObjDesc);
    261             break;
    262 
    263         default:
    264 
    265             /* No named references are allowed here */
    266 
    267             ACPI_ERROR ((AE_INFO,
    268                 "Unsupported Reference type 0x%X",
    269                 SourceDesc->Reference.Class));
    270 
    271             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    272         }
    273         break;
    274 
    275     default:
    276 
    277         /* Default case is for unknown types */
    278 
    279         ACPI_ERROR ((AE_INFO,
    280             "Node %p - Unknown object type 0x%X",
    281             Node, EntryType));
    282 
    283         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    284 
    285     } /* switch (EntryType) */
    286 
    287 
    288     /* Return the object descriptor */
    289 
    290     *ObjectPtr = (void *) ObjDesc;
    291     return_ACPI_STATUS (Status);
    292 }
    293