Home | History | Annotate | Line # | Download | only in dispatcher
dsutils.c revision 1.1.1.2.20.2
      1           1.1    jruoho /*******************************************************************************
      2           1.1    jruoho  *
      3           1.1    jruoho  * Module Name: dsutils - Dispatcher utilities
      4           1.1    jruoho  *
      5           1.1    jruoho  ******************************************************************************/
      6           1.1    jruoho 
      7       1.1.1.2    jruoho /*
      8  1.1.1.2.20.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 "acpi.h"
     45           1.1    jruoho #include "accommon.h"
     46           1.1    jruoho #include "acparser.h"
     47           1.1    jruoho #include "amlcode.h"
     48           1.1    jruoho #include "acdispat.h"
     49           1.1    jruoho #include "acinterp.h"
     50           1.1    jruoho #include "acnamesp.h"
     51           1.1    jruoho #include "acdebug.h"
     52           1.1    jruoho 
     53           1.1    jruoho #define _COMPONENT          ACPI_DISPATCHER
     54           1.1    jruoho         ACPI_MODULE_NAME    ("dsutils")
     55           1.1    jruoho 
     56           1.1    jruoho 
     57           1.1    jruoho /*******************************************************************************
     58           1.1    jruoho  *
     59           1.1    jruoho  * FUNCTION:    AcpiDsClearImplicitReturn
     60           1.1    jruoho  *
     61           1.1    jruoho  * PARAMETERS:  WalkState           - Current State
     62           1.1    jruoho  *
     63           1.1    jruoho  * RETURN:      None.
     64           1.1    jruoho  *
     65  1.1.1.2.20.1       tls  * DESCRIPTION: Clear and remove a reference on an implicit return value. Used
     66           1.1    jruoho  *              to delete "stale" return values (if enabled, the return value
     67           1.1    jruoho  *              from every operator is saved at least momentarily, in case the
     68           1.1    jruoho  *              parent method exits.)
     69           1.1    jruoho  *
     70           1.1    jruoho  ******************************************************************************/
     71           1.1    jruoho 
     72           1.1    jruoho void
     73           1.1    jruoho AcpiDsClearImplicitReturn (
     74           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     75           1.1    jruoho {
     76           1.1    jruoho     ACPI_FUNCTION_NAME (DsClearImplicitReturn);
     77           1.1    jruoho 
     78           1.1    jruoho 
     79           1.1    jruoho     /*
     80           1.1    jruoho      * Slack must be enabled for this feature
     81           1.1    jruoho      */
     82           1.1    jruoho     if (!AcpiGbl_EnableInterpreterSlack)
     83           1.1    jruoho     {
     84           1.1    jruoho         return;
     85           1.1    jruoho     }
     86           1.1    jruoho 
     87           1.1    jruoho     if (WalkState->ImplicitReturnObj)
     88           1.1    jruoho     {
     89           1.1    jruoho         /*
     90           1.1    jruoho          * Delete any "stale" implicit return. However, in
     91           1.1    jruoho          * complex statements, the implicit return value can be
     92           1.1    jruoho          * bubbled up several levels.
     93           1.1    jruoho          */
     94           1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
     95           1.1    jruoho             "Removing reference on stale implicit return obj %p\n",
     96           1.1    jruoho             WalkState->ImplicitReturnObj));
     97           1.1    jruoho 
     98           1.1    jruoho         AcpiUtRemoveReference (WalkState->ImplicitReturnObj);
     99           1.1    jruoho         WalkState->ImplicitReturnObj = NULL;
    100           1.1    jruoho     }
    101           1.1    jruoho }
    102           1.1    jruoho 
    103           1.1    jruoho 
    104           1.1    jruoho #ifndef ACPI_NO_METHOD_EXECUTION
    105           1.1    jruoho /*******************************************************************************
    106           1.1    jruoho  *
    107           1.1    jruoho  * FUNCTION:    AcpiDsDoImplicitReturn
    108           1.1    jruoho  *
    109           1.1    jruoho  * PARAMETERS:  ReturnDesc          - The return value
    110           1.1    jruoho  *              WalkState           - Current State
    111           1.1    jruoho  *              AddReference        - True if a reference should be added to the
    112           1.1    jruoho  *                                    return object
    113           1.1    jruoho  *
    114           1.1    jruoho  * RETURN:      TRUE if implicit return enabled, FALSE otherwise
    115           1.1    jruoho  *
    116           1.1    jruoho  * DESCRIPTION: Implements the optional "implicit return".  We save the result
    117           1.1    jruoho  *              of every ASL operator and control method invocation in case the
    118  1.1.1.2.20.1       tls  *              parent method exit. Before storing a new return value, we
    119           1.1    jruoho  *              delete the previous return value.
    120           1.1    jruoho  *
    121           1.1    jruoho  ******************************************************************************/
    122           1.1    jruoho 
    123           1.1    jruoho BOOLEAN
    124           1.1    jruoho AcpiDsDoImplicitReturn (
    125           1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc,
    126           1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    127           1.1    jruoho     BOOLEAN                 AddReference)
    128           1.1    jruoho {
    129           1.1    jruoho     ACPI_FUNCTION_NAME (DsDoImplicitReturn);
    130           1.1    jruoho 
    131           1.1    jruoho 
    132           1.1    jruoho     /*
    133           1.1    jruoho      * Slack must be enabled for this feature, and we must
    134           1.1    jruoho      * have a valid return object
    135           1.1    jruoho      */
    136           1.1    jruoho     if ((!AcpiGbl_EnableInterpreterSlack) ||
    137           1.1    jruoho         (!ReturnDesc))
    138           1.1    jruoho     {
    139           1.1    jruoho         return (FALSE);
    140           1.1    jruoho     }
    141           1.1    jruoho 
    142           1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    143  1.1.1.2.20.2  jdolecek         "Result %p will be implicitly returned; Prev=%p\n",
    144  1.1.1.2.20.2  jdolecek         ReturnDesc,
    145  1.1.1.2.20.2  jdolecek         WalkState->ImplicitReturnObj));
    146           1.1    jruoho 
    147           1.1    jruoho     /*
    148           1.1    jruoho      * Delete any "stale" implicit return value first. However, in
    149           1.1    jruoho      * complex statements, the implicit return value can be
    150           1.1    jruoho      * bubbled up several levels, so we don't clear the value if it
    151           1.1    jruoho      * is the same as the ReturnDesc.
    152           1.1    jruoho      */
    153           1.1    jruoho     if (WalkState->ImplicitReturnObj)
    154           1.1    jruoho     {
    155           1.1    jruoho         if (WalkState->ImplicitReturnObj == ReturnDesc)
    156           1.1    jruoho         {
    157           1.1    jruoho             return (TRUE);
    158           1.1    jruoho         }
    159           1.1    jruoho         AcpiDsClearImplicitReturn (WalkState);
    160           1.1    jruoho     }
    161           1.1    jruoho 
    162           1.1    jruoho     /* Save the implicit return value, add a reference if requested */
    163           1.1    jruoho 
    164           1.1    jruoho     WalkState->ImplicitReturnObj = ReturnDesc;
    165           1.1    jruoho     if (AddReference)
    166           1.1    jruoho     {
    167           1.1    jruoho         AcpiUtAddReference (ReturnDesc);
    168           1.1    jruoho     }
    169           1.1    jruoho 
    170           1.1    jruoho     return (TRUE);
    171           1.1    jruoho }
    172           1.1    jruoho 
    173           1.1    jruoho 
    174           1.1    jruoho /*******************************************************************************
    175           1.1    jruoho  *
    176           1.1    jruoho  * FUNCTION:    AcpiDsIsResultUsed
    177           1.1    jruoho  *
    178           1.1    jruoho  * PARAMETERS:  Op                  - Current Op
    179           1.1    jruoho  *              WalkState           - Current State
    180           1.1    jruoho  *
    181           1.1    jruoho  * RETURN:      TRUE if result is used, FALSE otherwise
    182           1.1    jruoho  *
    183           1.1    jruoho  * DESCRIPTION: Check if a result object will be used by the parent
    184           1.1    jruoho  *
    185           1.1    jruoho  ******************************************************************************/
    186           1.1    jruoho 
    187           1.1    jruoho BOOLEAN
    188           1.1    jruoho AcpiDsIsResultUsed (
    189           1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    190           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    191           1.1    jruoho {
    192           1.1    jruoho     const ACPI_OPCODE_INFO  *ParentInfo;
    193           1.1    jruoho 
    194           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsIsResultUsed, Op);
    195           1.1    jruoho 
    196           1.1    jruoho 
    197           1.1    jruoho     /* Must have both an Op and a Result Object */
    198           1.1    jruoho 
    199           1.1    jruoho     if (!Op)
    200           1.1    jruoho     {
    201           1.1    jruoho         ACPI_ERROR ((AE_INFO, "Null Op"));
    202           1.1    jruoho         return_UINT8 (TRUE);
    203           1.1    jruoho     }
    204           1.1    jruoho 
    205           1.1    jruoho     /*
    206           1.1    jruoho      * We know that this operator is not a
    207           1.1    jruoho      * Return() operator (would not come here.) The following code is the
    208           1.1    jruoho      * optional support for a so-called "implicit return". Some AML code
    209           1.1    jruoho      * assumes that the last value of the method is "implicitly" returned
    210           1.1    jruoho      * to the caller. Just save the last result as the return value.
    211           1.1    jruoho      * NOTE: this is optional because the ASL language does not actually
    212           1.1    jruoho      * support this behavior.
    213           1.1    jruoho      */
    214           1.1    jruoho     (void) AcpiDsDoImplicitReturn (WalkState->ResultObj, WalkState, TRUE);
    215           1.1    jruoho 
    216           1.1    jruoho     /*
    217           1.1    jruoho      * Now determine if the parent will use the result
    218           1.1    jruoho      *
    219           1.1    jruoho      * If there is no parent, or the parent is a ScopeOp, we are executing
    220           1.1    jruoho      * at the method level. An executing method typically has no parent,
    221  1.1.1.2.20.1       tls      * since each method is parsed separately. A method invoked externally
    222           1.1    jruoho      * via ExecuteControlMethod has a ScopeOp as the parent.
    223           1.1    jruoho      */
    224           1.1    jruoho     if ((!Op->Common.Parent) ||
    225           1.1    jruoho         (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
    226           1.1    jruoho     {
    227           1.1    jruoho         /* No parent, the return value cannot possibly be used */
    228           1.1    jruoho 
    229           1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    230           1.1    jruoho             "At Method level, result of [%s] not used\n",
    231           1.1    jruoho             AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
    232           1.1    jruoho         return_UINT8 (FALSE);
    233           1.1    jruoho     }
    234           1.1    jruoho 
    235           1.1    jruoho     /* Get info on the parent. The RootOp is AML_SCOPE */
    236           1.1    jruoho 
    237           1.1    jruoho     ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
    238           1.1    jruoho     if (ParentInfo->Class == AML_CLASS_UNKNOWN)
    239           1.1    jruoho     {
    240           1.1    jruoho         ACPI_ERROR ((AE_INFO,
    241           1.1    jruoho             "Unknown parent opcode Op=%p", Op));
    242           1.1    jruoho         return_UINT8 (FALSE);
    243           1.1    jruoho     }
    244           1.1    jruoho 
    245           1.1    jruoho     /*
    246  1.1.1.2.20.1       tls      * Decide what to do with the result based on the parent. If
    247           1.1    jruoho      * the parent opcode will not use the result, delete the object.
    248           1.1    jruoho      * Otherwise leave it as is, it will be deleted when it is used
    249           1.1    jruoho      * as an operand later.
    250           1.1    jruoho      */
    251           1.1    jruoho     switch (ParentInfo->Class)
    252           1.1    jruoho     {
    253           1.1    jruoho     case AML_CLASS_CONTROL:
    254           1.1    jruoho 
    255           1.1    jruoho         switch (Op->Common.Parent->Common.AmlOpcode)
    256           1.1    jruoho         {
    257           1.1    jruoho         case AML_RETURN_OP:
    258           1.1    jruoho 
    259           1.1    jruoho             /* Never delete the return value associated with a return opcode */
    260           1.1    jruoho 
    261           1.1    jruoho             goto ResultUsed;
    262           1.1    jruoho 
    263           1.1    jruoho         case AML_IF_OP:
    264           1.1    jruoho         case AML_WHILE_OP:
    265           1.1    jruoho             /*
    266           1.1    jruoho              * If we are executing the predicate AND this is the predicate op,
    267           1.1    jruoho              * we will use the return value
    268           1.1    jruoho              */
    269  1.1.1.2.20.2  jdolecek             if ((WalkState->ControlState->Common.State ==
    270  1.1.1.2.20.2  jdolecek                     ACPI_CONTROL_PREDICATE_EXECUTING) &&
    271           1.1    jruoho                 (WalkState->ControlState->Control.PredicateOp == Op))
    272           1.1    jruoho             {
    273           1.1    jruoho                 goto ResultUsed;
    274           1.1    jruoho             }
    275           1.1    jruoho             break;
    276           1.1    jruoho 
    277           1.1    jruoho         default:
    278  1.1.1.2.20.1       tls 
    279           1.1    jruoho             /* Ignore other control opcodes */
    280  1.1.1.2.20.1       tls 
    281           1.1    jruoho             break;
    282           1.1    jruoho         }
    283           1.1    jruoho 
    284           1.1    jruoho         /* The general control opcode returns no result */
    285           1.1    jruoho 
    286           1.1    jruoho         goto ResultNotUsed;
    287           1.1    jruoho 
    288           1.1    jruoho     case AML_CLASS_CREATE:
    289           1.1    jruoho         /*
    290           1.1    jruoho          * These opcodes allow TermArg(s) as operands and therefore
    291  1.1.1.2.20.1       tls          * the operands can be method calls. The result is used.
    292           1.1    jruoho          */
    293           1.1    jruoho         goto ResultUsed;
    294           1.1    jruoho 
    295           1.1    jruoho     case AML_CLASS_NAMED_OBJECT:
    296           1.1    jruoho 
    297           1.1    jruoho         if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
    298           1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
    299           1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
    300           1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
    301  1.1.1.2.20.2  jdolecek             (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP) ||
    302           1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_INT_EVAL_SUBTREE_OP) ||
    303           1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP))
    304           1.1    jruoho         {
    305           1.1    jruoho             /*
    306           1.1    jruoho              * These opcodes allow TermArg(s) as operands and therefore
    307  1.1.1.2.20.1       tls              * the operands can be method calls. The result is used.
    308           1.1    jruoho              */
    309           1.1    jruoho             goto ResultUsed;
    310           1.1    jruoho         }
    311           1.1    jruoho 
    312           1.1    jruoho         goto ResultNotUsed;
    313           1.1    jruoho 
    314           1.1    jruoho     default:
    315           1.1    jruoho         /*
    316           1.1    jruoho          * In all other cases. the parent will actually use the return
    317           1.1    jruoho          * object, so keep it.
    318           1.1    jruoho          */
    319           1.1    jruoho         goto ResultUsed;
    320           1.1    jruoho     }
    321           1.1    jruoho 
    322           1.1    jruoho 
    323           1.1    jruoho ResultUsed:
    324           1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    325           1.1    jruoho         "Result of [%s] used by Parent [%s] Op=%p\n",
    326           1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
    327           1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
    328           1.1    jruoho 
    329           1.1    jruoho     return_UINT8 (TRUE);
    330           1.1    jruoho 
    331           1.1    jruoho 
    332           1.1    jruoho ResultNotUsed:
    333           1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    334           1.1    jruoho         "Result of [%s] not used by Parent [%s] Op=%p\n",
    335           1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
    336           1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
    337           1.1    jruoho 
    338           1.1    jruoho     return_UINT8 (FALSE);
    339           1.1    jruoho }
    340           1.1    jruoho 
    341           1.1    jruoho 
    342           1.1    jruoho /*******************************************************************************
    343           1.1    jruoho  *
    344           1.1    jruoho  * FUNCTION:    AcpiDsDeleteResultIfNotUsed
    345           1.1    jruoho  *
    346           1.1    jruoho  * PARAMETERS:  Op              - Current parse Op
    347           1.1    jruoho  *              ResultObj       - Result of the operation
    348           1.1    jruoho  *              WalkState       - Current state
    349           1.1    jruoho  *
    350           1.1    jruoho  * RETURN:      Status
    351           1.1    jruoho  *
    352  1.1.1.2.20.1       tls  * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
    353           1.1    jruoho  *              result descriptor, check if the parent opcode will actually use
    354  1.1.1.2.20.1       tls  *              this result. If not, delete the result now so that it will
    355           1.1    jruoho  *              not become orphaned.
    356           1.1    jruoho  *
    357           1.1    jruoho  ******************************************************************************/
    358           1.1    jruoho 
    359           1.1    jruoho void
    360           1.1    jruoho AcpiDsDeleteResultIfNotUsed (
    361           1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    362           1.1    jruoho     ACPI_OPERAND_OBJECT     *ResultObj,
    363           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    364           1.1    jruoho {
    365           1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    366           1.1    jruoho     ACPI_STATUS             Status;
    367           1.1    jruoho 
    368           1.1    jruoho 
    369           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsDeleteResultIfNotUsed, ResultObj);
    370           1.1    jruoho 
    371           1.1    jruoho 
    372           1.1    jruoho     if (!Op)
    373           1.1    jruoho     {
    374           1.1    jruoho         ACPI_ERROR ((AE_INFO, "Null Op"));
    375           1.1    jruoho         return_VOID;
    376           1.1    jruoho     }
    377           1.1    jruoho 
    378           1.1    jruoho     if (!ResultObj)
    379           1.1    jruoho     {
    380           1.1    jruoho         return_VOID;
    381           1.1    jruoho     }
    382           1.1    jruoho 
    383           1.1    jruoho     if (!AcpiDsIsResultUsed (Op, WalkState))
    384           1.1    jruoho     {
    385           1.1    jruoho         /* Must pop the result stack (ObjDesc should be equal to ResultObj) */
    386           1.1    jruoho 
    387           1.1    jruoho         Status = AcpiDsResultPop (&ObjDesc, WalkState);
    388           1.1    jruoho         if (ACPI_SUCCESS (Status))
    389           1.1    jruoho         {
    390           1.1    jruoho             AcpiUtRemoveReference (ResultObj);
    391           1.1    jruoho         }
    392           1.1    jruoho     }
    393           1.1    jruoho 
    394           1.1    jruoho     return_VOID;
    395           1.1    jruoho }
    396           1.1    jruoho 
    397           1.1    jruoho 
    398           1.1    jruoho /*******************************************************************************
    399           1.1    jruoho  *
    400           1.1    jruoho  * FUNCTION:    AcpiDsResolveOperands
    401           1.1    jruoho  *
    402           1.1    jruoho  * PARAMETERS:  WalkState           - Current walk state with operands on stack
    403           1.1    jruoho  *
    404           1.1    jruoho  * RETURN:      Status
    405           1.1    jruoho  *
    406  1.1.1.2.20.1       tls  * DESCRIPTION: Resolve all operands to their values. Used to prepare
    407           1.1    jruoho  *              arguments to a control method invocation (a call from one
    408           1.1    jruoho  *              method to another.)
    409           1.1    jruoho  *
    410           1.1    jruoho  ******************************************************************************/
    411           1.1    jruoho 
    412           1.1    jruoho ACPI_STATUS
    413           1.1    jruoho AcpiDsResolveOperands (
    414           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    415           1.1    jruoho {
    416           1.1    jruoho     UINT32                  i;
    417           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    418           1.1    jruoho 
    419           1.1    jruoho 
    420           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsResolveOperands, WalkState);
    421           1.1    jruoho 
    422           1.1    jruoho 
    423           1.1    jruoho     /*
    424           1.1    jruoho      * Attempt to resolve each of the valid operands
    425  1.1.1.2.20.1       tls      * Method arguments are passed by reference, not by value. This means
    426           1.1    jruoho      * that the actual objects are passed, not copies of the objects.
    427           1.1    jruoho      */
    428           1.1    jruoho     for (i = 0; i < WalkState->NumOperands; i++)
    429           1.1    jruoho     {
    430           1.1    jruoho         Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
    431           1.1    jruoho         if (ACPI_FAILURE (Status))
    432           1.1    jruoho         {
    433           1.1    jruoho             break;
    434           1.1    jruoho         }
    435           1.1    jruoho     }
    436           1.1    jruoho 
    437           1.1    jruoho     return_ACPI_STATUS (Status);
    438           1.1    jruoho }
    439           1.1    jruoho 
    440           1.1    jruoho 
    441           1.1    jruoho /*******************************************************************************
    442           1.1    jruoho  *
    443           1.1    jruoho  * FUNCTION:    AcpiDsClearOperands
    444           1.1    jruoho  *
    445           1.1    jruoho  * PARAMETERS:  WalkState           - Current walk state with operands on stack
    446           1.1    jruoho  *
    447           1.1    jruoho  * RETURN:      None
    448           1.1    jruoho  *
    449           1.1    jruoho  * DESCRIPTION: Clear all operands on the current walk state operand stack.
    450           1.1    jruoho  *
    451           1.1    jruoho  ******************************************************************************/
    452           1.1    jruoho 
    453           1.1    jruoho void
    454           1.1    jruoho AcpiDsClearOperands (
    455           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    456           1.1    jruoho {
    457           1.1    jruoho     UINT32                  i;
    458           1.1    jruoho 
    459           1.1    jruoho 
    460           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsClearOperands, WalkState);
    461           1.1    jruoho 
    462           1.1    jruoho 
    463           1.1    jruoho     /* Remove a reference on each operand on the stack */
    464           1.1    jruoho 
    465           1.1    jruoho     for (i = 0; i < WalkState->NumOperands; i++)
    466           1.1    jruoho     {
    467           1.1    jruoho         /*
    468           1.1    jruoho          * Remove a reference to all operands, including both
    469           1.1    jruoho          * "Arguments" and "Targets".
    470           1.1    jruoho          */
    471           1.1    jruoho         AcpiUtRemoveReference (WalkState->Operands[i]);
    472           1.1    jruoho         WalkState->Operands[i] = NULL;
    473           1.1    jruoho     }
    474           1.1    jruoho 
    475           1.1    jruoho     WalkState->NumOperands = 0;
    476           1.1    jruoho     return_VOID;
    477           1.1    jruoho }
    478           1.1    jruoho #endif
    479           1.1    jruoho 
    480           1.1    jruoho 
    481           1.1    jruoho /*******************************************************************************
    482           1.1    jruoho  *
    483           1.1    jruoho  * FUNCTION:    AcpiDsCreateOperand
    484           1.1    jruoho  *
    485           1.1    jruoho  * PARAMETERS:  WalkState       - Current walk state
    486           1.1    jruoho  *              Arg             - Parse object for the argument
    487           1.1    jruoho  *              ArgIndex        - Which argument (zero based)
    488           1.1    jruoho  *
    489           1.1    jruoho  * RETURN:      Status
    490           1.1    jruoho  *
    491           1.1    jruoho  * DESCRIPTION: Translate a parse tree object that is an argument to an AML
    492  1.1.1.2.20.1       tls  *              opcode to the equivalent interpreter object. This may include
    493           1.1    jruoho  *              looking up a name or entering a new name into the internal
    494           1.1    jruoho  *              namespace.
    495           1.1    jruoho  *
    496           1.1    jruoho  ******************************************************************************/
    497           1.1    jruoho 
    498           1.1    jruoho ACPI_STATUS
    499           1.1    jruoho AcpiDsCreateOperand (
    500           1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    501           1.1    jruoho     ACPI_PARSE_OBJECT       *Arg,
    502           1.1    jruoho     UINT32                  ArgIndex)
    503           1.1    jruoho {
    504           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    505           1.1    jruoho     char                    *NameString;
    506           1.1    jruoho     UINT32                  NameLength;
    507           1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    508           1.1    jruoho     ACPI_PARSE_OBJECT       *ParentOp;
    509           1.1    jruoho     UINT16                  Opcode;
    510           1.1    jruoho     ACPI_INTERPRETER_MODE   InterpreterMode;
    511           1.1    jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    512           1.1    jruoho 
    513           1.1    jruoho 
    514           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsCreateOperand, Arg);
    515           1.1    jruoho 
    516           1.1    jruoho 
    517           1.1    jruoho     /* A valid name must be looked up in the namespace */
    518           1.1    jruoho 
    519           1.1    jruoho     if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
    520           1.1    jruoho         (Arg->Common.Value.String) &&
    521           1.1    jruoho         !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
    522           1.1    jruoho     {
    523           1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
    524           1.1    jruoho 
    525           1.1    jruoho         /* Get the entire name string from the AML stream */
    526           1.1    jruoho 
    527  1.1.1.2.20.2  jdolecek         Status = AcpiExGetNameString (ACPI_TYPE_ANY,
    528  1.1.1.2.20.2  jdolecek             Arg->Common.Value.Buffer, &NameString, &NameLength);
    529           1.1    jruoho 
    530           1.1    jruoho         if (ACPI_FAILURE (Status))
    531           1.1    jruoho         {
    532           1.1    jruoho             return_ACPI_STATUS (Status);
    533           1.1    jruoho         }
    534           1.1    jruoho 
    535           1.1    jruoho         /* All prefixes have been handled, and the name is in NameString */
    536           1.1    jruoho 
    537           1.1    jruoho         /*
    538  1.1.1.2.20.1       tls          * Special handling for BufferField declarations. This is a deferred
    539           1.1    jruoho          * opcode that unfortunately defines the field name as the last
    540  1.1.1.2.20.1       tls          * parameter instead of the first. We get here when we are performing
    541           1.1    jruoho          * the deferred execution, so the actual name of the field is already
    542  1.1.1.2.20.1       tls          * in the namespace. We don't want to attempt to look it up again
    543           1.1    jruoho          * because we may be executing in a different scope than where the
    544           1.1    jruoho          * actual opcode exists.
    545           1.1    jruoho          */
    546           1.1    jruoho         if ((WalkState->DeferredNode) &&
    547           1.1    jruoho             (WalkState->DeferredNode->Type == ACPI_TYPE_BUFFER_FIELD) &&
    548  1.1.1.2.20.2  jdolecek             (ArgIndex == (UINT32)
    549  1.1.1.2.20.2  jdolecek                 ((WalkState->Opcode == AML_CREATE_FIELD_OP) ? 3 : 2)))
    550           1.1    jruoho         {
    551           1.1    jruoho             ObjDesc = ACPI_CAST_PTR (
    552  1.1.1.2.20.2  jdolecek                 ACPI_OPERAND_OBJECT, WalkState->DeferredNode);
    553           1.1    jruoho             Status = AE_OK;
    554           1.1    jruoho         }
    555           1.1    jruoho         else    /* All other opcodes */
    556           1.1    jruoho         {
    557           1.1    jruoho             /*
    558           1.1    jruoho              * Differentiate between a namespace "create" operation
    559           1.1    jruoho              * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
    560           1.1    jruoho              * IMODE_EXECUTE) in order to support the creation of
    561           1.1    jruoho              * namespace objects during the execution of control methods.
    562           1.1    jruoho              */
    563           1.1    jruoho             ParentOp = Arg->Common.Parent;
    564           1.1    jruoho             OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
    565  1.1.1.2.20.2  jdolecek 
    566           1.1    jruoho             if ((OpInfo->Flags & AML_NSNODE) &&
    567           1.1    jruoho                 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
    568           1.1    jruoho                 (ParentOp->Common.AmlOpcode != AML_REGION_OP) &&
    569           1.1    jruoho                 (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
    570           1.1    jruoho             {
    571           1.1    jruoho                 /* Enter name into namespace if not found */
    572           1.1    jruoho 
    573           1.1    jruoho                 InterpreterMode = ACPI_IMODE_LOAD_PASS2;
    574           1.1    jruoho             }
    575           1.1    jruoho             else
    576           1.1    jruoho             {
    577           1.1    jruoho                 /* Return a failure if name not found */
    578           1.1    jruoho 
    579           1.1    jruoho                 InterpreterMode = ACPI_IMODE_EXECUTE;
    580           1.1    jruoho             }
    581           1.1    jruoho 
    582           1.1    jruoho             Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
    583  1.1.1.2.20.2  jdolecek                 ACPI_TYPE_ANY, InterpreterMode,
    584  1.1.1.2.20.2  jdolecek                 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, WalkState,
    585  1.1.1.2.20.2  jdolecek                 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc));
    586           1.1    jruoho             /*
    587           1.1    jruoho              * The only case where we pass through (ignore) a NOT_FOUND
    588           1.1    jruoho              * error is for the CondRefOf opcode.
    589           1.1    jruoho              */
    590           1.1    jruoho             if (Status == AE_NOT_FOUND)
    591           1.1    jruoho             {
    592  1.1.1.2.20.2  jdolecek                 if (ParentOp->Common.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)
    593           1.1    jruoho                 {
    594           1.1    jruoho                     /*
    595           1.1    jruoho                      * For the Conditional Reference op, it's OK if
    596           1.1    jruoho                      * the name is not found;  We just need a way to
    597           1.1    jruoho                      * indicate this to the interpreter, set the
    598           1.1    jruoho                      * object to the root
    599           1.1    jruoho                      */
    600           1.1    jruoho                     ObjDesc = ACPI_CAST_PTR (
    601  1.1.1.2.20.2  jdolecek                         ACPI_OPERAND_OBJECT, AcpiGbl_RootNode);
    602           1.1    jruoho                     Status = AE_OK;
    603           1.1    jruoho                 }
    604  1.1.1.2.20.2  jdolecek                 else if (ParentOp->Common.AmlOpcode == AML_EXTERNAL_OP)
    605  1.1.1.2.20.2  jdolecek                 {
    606  1.1.1.2.20.2  jdolecek                     /*
    607  1.1.1.2.20.2  jdolecek                      * This opcode should never appear here. It is used only
    608  1.1.1.2.20.2  jdolecek                      * by AML disassemblers and is surrounded by an If(0)
    609  1.1.1.2.20.2  jdolecek                      * by the ASL compiler.
    610  1.1.1.2.20.2  jdolecek                      *
    611  1.1.1.2.20.2  jdolecek                      * Therefore, if we see it here, it is a serious error.
    612  1.1.1.2.20.2  jdolecek                      */
    613  1.1.1.2.20.2  jdolecek                     Status = AE_AML_BAD_OPCODE;
    614  1.1.1.2.20.2  jdolecek                 }
    615           1.1    jruoho                 else
    616           1.1    jruoho                 {
    617           1.1    jruoho                     /*
    618           1.1    jruoho                      * We just plain didn't find it -- which is a
    619           1.1    jruoho                      * very serious error at this point
    620           1.1    jruoho                      */
    621           1.1    jruoho                     Status = AE_AML_NAME_NOT_FOUND;
    622           1.1    jruoho                 }
    623           1.1    jruoho             }
    624           1.1    jruoho 
    625           1.1    jruoho             if (ACPI_FAILURE (Status))
    626           1.1    jruoho             {
    627  1.1.1.2.20.2  jdolecek                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
    628  1.1.1.2.20.2  jdolecek                     NameString, Status);
    629           1.1    jruoho             }
    630           1.1    jruoho         }
    631           1.1    jruoho 
    632           1.1    jruoho         /* Free the namestring created above */
    633           1.1    jruoho 
    634           1.1    jruoho         ACPI_FREE (NameString);
    635           1.1    jruoho 
    636           1.1    jruoho         /* Check status from the lookup */
    637           1.1    jruoho 
    638           1.1    jruoho         if (ACPI_FAILURE (Status))
    639           1.1    jruoho         {
    640           1.1    jruoho             return_ACPI_STATUS (Status);
    641           1.1    jruoho         }
    642           1.1    jruoho 
    643           1.1    jruoho         /* Put the resulting object onto the current object stack */
    644           1.1    jruoho 
    645           1.1    jruoho         Status = AcpiDsObjStackPush (ObjDesc, WalkState);
    646           1.1    jruoho         if (ACPI_FAILURE (Status))
    647           1.1    jruoho         {
    648           1.1    jruoho             return_ACPI_STATUS (Status);
    649           1.1    jruoho         }
    650  1.1.1.2.20.2  jdolecek 
    651  1.1.1.2.20.2  jdolecek         AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
    652           1.1    jruoho     }
    653           1.1    jruoho     else
    654           1.1    jruoho     {
    655           1.1    jruoho         /* Check for null name case */
    656           1.1    jruoho 
    657           1.1    jruoho         if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
    658           1.1    jruoho             !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
    659           1.1    jruoho         {
    660           1.1    jruoho             /*
    661           1.1    jruoho              * If the name is null, this means that this is an
    662           1.1    jruoho              * optional result parameter that was not specified
    663  1.1.1.2.20.1       tls              * in the original ASL. Create a Zero Constant for a
    664  1.1.1.2.20.1       tls              * placeholder. (Store to a constant is a Noop.)
    665           1.1    jruoho              */
    666           1.1    jruoho             Opcode = AML_ZERO_OP;       /* Has no arguments! */
    667           1.1    jruoho 
    668           1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    669           1.1    jruoho                 "Null namepath: Arg=%p\n", Arg));
    670           1.1    jruoho         }
    671           1.1    jruoho         else
    672           1.1    jruoho         {
    673           1.1    jruoho             Opcode = Arg->Common.AmlOpcode;
    674           1.1    jruoho         }
    675           1.1    jruoho 
    676           1.1    jruoho         /* Get the object type of the argument */
    677           1.1    jruoho 
    678           1.1    jruoho         OpInfo = AcpiPsGetOpcodeInfo (Opcode);
    679           1.1    jruoho         if (OpInfo->ObjectType == ACPI_TYPE_INVALID)
    680           1.1    jruoho         {
    681           1.1    jruoho             return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
    682           1.1    jruoho         }
    683           1.1    jruoho 
    684  1.1.1.2.20.2  jdolecek         if ((OpInfo->Flags & AML_HAS_RETVAL) ||
    685  1.1.1.2.20.2  jdolecek             (Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
    686           1.1    jruoho         {
    687           1.1    jruoho             /*
    688           1.1    jruoho              * Use value that was already previously returned
    689           1.1    jruoho              * by the evaluation of this argument
    690           1.1    jruoho              */
    691           1.1    jruoho             Status = AcpiDsResultPop (&ObjDesc, WalkState);
    692           1.1    jruoho             if (ACPI_FAILURE (Status))
    693           1.1    jruoho             {
    694           1.1    jruoho                 /*
    695           1.1    jruoho                  * Only error is underflow, and this indicates
    696           1.1    jruoho                  * a missing or null operand!
    697           1.1    jruoho                  */
    698           1.1    jruoho                 ACPI_EXCEPTION ((AE_INFO, Status,
    699           1.1    jruoho                     "Missing or null operand"));
    700           1.1    jruoho                 return_ACPI_STATUS (Status);
    701           1.1    jruoho             }
    702           1.1    jruoho         }
    703           1.1    jruoho         else
    704           1.1    jruoho         {
    705           1.1    jruoho             /* Create an ACPI_INTERNAL_OBJECT for the argument */
    706           1.1    jruoho 
    707           1.1    jruoho             ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType);
    708           1.1    jruoho             if (!ObjDesc)
    709           1.1    jruoho             {
    710           1.1    jruoho                 return_ACPI_STATUS (AE_NO_MEMORY);
    711           1.1    jruoho             }
    712           1.1    jruoho 
    713           1.1    jruoho             /* Initialize the new object */
    714           1.1    jruoho 
    715           1.1    jruoho             Status = AcpiDsInitObjectFromOp (
    716  1.1.1.2.20.2  jdolecek                 WalkState, Arg, Opcode, &ObjDesc);
    717           1.1    jruoho             if (ACPI_FAILURE (Status))
    718           1.1    jruoho             {
    719           1.1    jruoho                 AcpiUtDeleteObjectDesc (ObjDesc);
    720           1.1    jruoho                 return_ACPI_STATUS (Status);
    721           1.1    jruoho             }
    722           1.1    jruoho         }
    723           1.1    jruoho 
    724           1.1    jruoho         /* Put the operand object on the object stack */
    725           1.1    jruoho 
    726           1.1    jruoho         Status = AcpiDsObjStackPush (ObjDesc, WalkState);
    727           1.1    jruoho         if (ACPI_FAILURE (Status))
    728           1.1    jruoho         {
    729           1.1    jruoho             return_ACPI_STATUS (Status);
    730           1.1    jruoho         }
    731           1.1    jruoho 
    732  1.1.1.2.20.2  jdolecek         AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
    733           1.1    jruoho     }
    734           1.1    jruoho 
    735           1.1    jruoho     return_ACPI_STATUS (AE_OK);
    736           1.1    jruoho }
    737           1.1    jruoho 
    738           1.1    jruoho 
    739           1.1    jruoho /*******************************************************************************
    740           1.1    jruoho  *
    741           1.1    jruoho  * FUNCTION:    AcpiDsCreateOperands
    742           1.1    jruoho  *
    743           1.1    jruoho  * PARAMETERS:  WalkState           - Current state
    744           1.1    jruoho  *              FirstArg            - First argument of a parser argument tree
    745           1.1    jruoho  *
    746           1.1    jruoho  * RETURN:      Status
    747           1.1    jruoho  *
    748           1.1    jruoho  * DESCRIPTION: Convert an operator's arguments from a parse tree format to
    749           1.1    jruoho  *              namespace objects and place those argument object on the object
    750           1.1    jruoho  *              stack in preparation for evaluation by the interpreter.
    751           1.1    jruoho  *
    752           1.1    jruoho  ******************************************************************************/
    753           1.1    jruoho 
    754           1.1    jruoho ACPI_STATUS
    755           1.1    jruoho AcpiDsCreateOperands (
    756           1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    757           1.1    jruoho     ACPI_PARSE_OBJECT       *FirstArg)
    758           1.1    jruoho {
    759           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    760           1.1    jruoho     ACPI_PARSE_OBJECT       *Arg;
    761           1.1    jruoho     ACPI_PARSE_OBJECT       *Arguments[ACPI_OBJ_NUM_OPERANDS];
    762           1.1    jruoho     UINT32                  ArgCount = 0;
    763           1.1    jruoho     UINT32                  Index = WalkState->NumOperands;
    764           1.1    jruoho     UINT32                  i;
    765           1.1    jruoho 
    766           1.1    jruoho 
    767           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsCreateOperands, FirstArg);
    768           1.1    jruoho 
    769           1.1    jruoho 
    770           1.1    jruoho     /* Get all arguments in the list */
    771           1.1    jruoho 
    772           1.1    jruoho     Arg = FirstArg;
    773           1.1    jruoho     while (Arg)
    774           1.1    jruoho     {
    775           1.1    jruoho         if (Index >= ACPI_OBJ_NUM_OPERANDS)
    776           1.1    jruoho         {
    777           1.1    jruoho             return_ACPI_STATUS (AE_BAD_DATA);
    778           1.1    jruoho         }
    779           1.1    jruoho 
    780           1.1    jruoho         Arguments[Index] = Arg;
    781           1.1    jruoho         WalkState->Operands [Index] = NULL;
    782           1.1    jruoho 
    783           1.1    jruoho         /* Move on to next argument, if any */
    784           1.1    jruoho 
    785           1.1    jruoho         Arg = Arg->Common.Next;
    786           1.1    jruoho         ArgCount++;
    787           1.1    jruoho         Index++;
    788           1.1    jruoho     }
    789           1.1    jruoho 
    790  1.1.1.2.20.1       tls     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    791  1.1.1.2.20.1       tls         "NumOperands %d, ArgCount %d, Index %d\n",
    792  1.1.1.2.20.1       tls         WalkState->NumOperands, ArgCount, Index));
    793           1.1    jruoho 
    794  1.1.1.2.20.1       tls     /* Create the interpreter arguments, in reverse order */
    795           1.1    jruoho 
    796  1.1.1.2.20.1       tls     Index--;
    797           1.1    jruoho     for (i = 0; i < ArgCount; i++)
    798           1.1    jruoho     {
    799           1.1    jruoho         Arg = Arguments[Index];
    800           1.1    jruoho         WalkState->OperandIndex = (UINT8) Index;
    801           1.1    jruoho 
    802           1.1    jruoho         Status = AcpiDsCreateOperand (WalkState, Arg, Index);
    803           1.1    jruoho         if (ACPI_FAILURE (Status))
    804           1.1    jruoho         {
    805           1.1    jruoho             goto Cleanup;
    806           1.1    jruoho         }
    807           1.1    jruoho 
    808  1.1.1.2.20.1       tls         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    809  1.1.1.2.20.1       tls             "Created Arg #%u (%p) %u args total\n",
    810  1.1.1.2.20.1       tls             Index, Arg, ArgCount));
    811           1.1    jruoho         Index--;
    812           1.1    jruoho     }
    813           1.1    jruoho 
    814           1.1    jruoho     return_ACPI_STATUS (Status);
    815           1.1    jruoho 
    816           1.1    jruoho 
    817           1.1    jruoho Cleanup:
    818           1.1    jruoho     /*
    819           1.1    jruoho      * We must undo everything done above; meaning that we must
    820           1.1    jruoho      * pop everything off of the operand stack and delete those
    821           1.1    jruoho      * objects
    822           1.1    jruoho      */
    823           1.1    jruoho     AcpiDsObjStackPopAndDelete (ArgCount, WalkState);
    824           1.1    jruoho 
    825           1.1    jruoho     ACPI_EXCEPTION ((AE_INFO, Status, "While creating Arg %u", Index));
    826           1.1    jruoho     return_ACPI_STATUS (Status);
    827           1.1    jruoho }
    828           1.1    jruoho 
    829           1.1    jruoho 
    830           1.1    jruoho /*****************************************************************************
    831           1.1    jruoho  *
    832           1.1    jruoho  * FUNCTION:    AcpiDsEvaluateNamePath
    833           1.1    jruoho  *
    834           1.1    jruoho  * PARAMETERS:  WalkState       - Current state of the parse tree walk,
    835           1.1    jruoho  *                                the opcode of current operation should be
    836           1.1    jruoho  *                                AML_INT_NAMEPATH_OP
    837           1.1    jruoho  *
    838           1.1    jruoho  * RETURN:      Status
    839           1.1    jruoho  *
    840           1.1    jruoho  * DESCRIPTION: Translate the -NamePath- parse tree object to the equivalent
    841           1.1    jruoho  *              interpreter object, convert it to value, if needed, duplicate
    842           1.1    jruoho  *              it, if needed, and push it onto the current result stack.
    843           1.1    jruoho  *
    844           1.1    jruoho  ****************************************************************************/
    845           1.1    jruoho 
    846           1.1    jruoho ACPI_STATUS
    847           1.1    jruoho AcpiDsEvaluateNamePath (
    848           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    849           1.1    jruoho {
    850           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    851           1.1    jruoho     ACPI_PARSE_OBJECT       *Op = WalkState->Op;
    852           1.1    jruoho     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
    853           1.1    jruoho     ACPI_OPERAND_OBJECT     *NewObjDesc;
    854           1.1    jruoho     UINT8                   Type;
    855           1.1    jruoho 
    856           1.1    jruoho 
    857           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsEvaluateNamePath, WalkState);
    858           1.1    jruoho 
    859           1.1    jruoho 
    860           1.1    jruoho     if (!Op->Common.Parent)
    861           1.1    jruoho     {
    862           1.1    jruoho         /* This happens after certain exception processing */
    863           1.1    jruoho 
    864           1.1    jruoho         goto Exit;
    865           1.1    jruoho     }
    866           1.1    jruoho 
    867           1.1    jruoho     if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
    868  1.1.1.2.20.2  jdolecek         (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP) ||
    869           1.1    jruoho         (Op->Common.Parent->Common.AmlOpcode == AML_REF_OF_OP))
    870           1.1    jruoho     {
    871           1.1    jruoho         /* TBD: Should we specify this feature as a bit of OpInfo->Flags of these opcodes? */
    872           1.1    jruoho 
    873           1.1    jruoho         goto Exit;
    874           1.1    jruoho     }
    875           1.1    jruoho 
    876           1.1    jruoho     Status = AcpiDsCreateOperand (WalkState, Op, 0);
    877           1.1    jruoho     if (ACPI_FAILURE (Status))
    878           1.1    jruoho     {
    879           1.1    jruoho         goto Exit;
    880           1.1    jruoho     }
    881           1.1    jruoho 
    882           1.1    jruoho     if (Op->Common.Flags & ACPI_PARSEOP_TARGET)
    883           1.1    jruoho     {
    884           1.1    jruoho         NewObjDesc = *Operand;
    885           1.1    jruoho         goto PushResult;
    886           1.1    jruoho     }
    887           1.1    jruoho 
    888           1.1    jruoho     Type = (*Operand)->Common.Type;
    889           1.1    jruoho 
    890           1.1    jruoho     Status = AcpiExResolveToValue (Operand, WalkState);
    891           1.1    jruoho     if (ACPI_FAILURE (Status))
    892           1.1    jruoho     {
    893           1.1    jruoho         goto Exit;
    894           1.1    jruoho     }
    895           1.1    jruoho 
    896           1.1    jruoho     if (Type == ACPI_TYPE_INTEGER)
    897           1.1    jruoho     {
    898           1.1    jruoho         /* It was incremented by AcpiExResolveToValue */
    899           1.1    jruoho 
    900           1.1    jruoho         AcpiUtRemoveReference (*Operand);
    901           1.1    jruoho 
    902  1.1.1.2.20.2  jdolecek         Status = AcpiUtCopyIobjectToIobject (
    903  1.1.1.2.20.2  jdolecek             *Operand, &NewObjDesc, WalkState);
    904           1.1    jruoho         if (ACPI_FAILURE (Status))
    905           1.1    jruoho         {
    906           1.1    jruoho             goto Exit;
    907           1.1    jruoho         }
    908           1.1    jruoho     }
    909           1.1    jruoho     else
    910           1.1    jruoho     {
    911           1.1    jruoho         /*
    912           1.1    jruoho          * The object either was anew created or is
    913           1.1    jruoho          * a Namespace node - don't decrement it.
    914           1.1    jruoho          */
    915           1.1    jruoho         NewObjDesc = *Operand;
    916           1.1    jruoho     }
    917           1.1    jruoho 
    918           1.1    jruoho     /* Cleanup for name-path operand */
    919           1.1    jruoho 
    920           1.1    jruoho     Status = AcpiDsObjStackPop (1, WalkState);
    921           1.1    jruoho     if (ACPI_FAILURE (Status))
    922           1.1    jruoho     {
    923           1.1    jruoho         WalkState->ResultObj = NewObjDesc;
    924           1.1    jruoho         goto Exit;
    925           1.1    jruoho     }
    926           1.1    jruoho 
    927           1.1    jruoho PushResult:
    928           1.1    jruoho 
    929           1.1    jruoho     WalkState->ResultObj = NewObjDesc;
    930           1.1    jruoho 
    931           1.1    jruoho     Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
    932           1.1    jruoho     if (ACPI_SUCCESS (Status))
    933           1.1    jruoho     {
    934           1.1    jruoho         /* Force to take it from stack */
    935           1.1    jruoho 
    936           1.1    jruoho         Op->Common.Flags |= ACPI_PARSEOP_IN_STACK;
    937           1.1    jruoho     }
    938           1.1    jruoho 
    939           1.1    jruoho Exit:
    940           1.1    jruoho 
    941           1.1    jruoho     return_ACPI_STATUS (Status);
    942           1.1    jruoho }
    943