Home | History | Annotate | Line # | Download | only in dispatcher
dsutils.c revision 1.1.1.21
      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.20  christos /******************************************************************************
      8  1.1.1.20  christos  *
      9  1.1.1.20  christos  * 1. Copyright Notice
     10  1.1.1.20  christos  *
     11  1.1.1.21  christos  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.1.1.20  christos  * 2. License
     15  1.1.1.20  christos  *
     16  1.1.1.20  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.20  christos  * rights. You may have additional license terms from the party that provided
     18  1.1.1.20  christos  * you this software, covering your right to use that party's intellectual
     19  1.1.1.20  christos  * property rights.
     20  1.1.1.20  christos  *
     21  1.1.1.20  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.20  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.20  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.20  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.20  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.20  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.20  christos  *
     28  1.1.1.20  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.20  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.20  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.20  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.20  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.20  christos  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.20  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.20  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.20  christos  *
     37  1.1.1.20  christos  * The above copyright and patent license is granted only if the following
     38  1.1.1.20  christos  * conditions are met:
     39  1.1.1.20  christos  *
     40  1.1.1.20  christos  * 3. Conditions
     41  1.1.1.20  christos  *
     42  1.1.1.20  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.20  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.20  christos  * Code or modification with rights to further distribute source must include
     45  1.1.1.20  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.20  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.20  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.20  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.20  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.20  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.20  christos  * must include a prominent statement that the modification is derived,
     52  1.1.1.20  christos  * directly or indirectly, from Original Intel Code.
     53  1.1.1.20  christos  *
     54  1.1.1.20  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.20  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.20  christos  * Code or modification without rights to further distribute source must
     57  1.1.1.20  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.20  christos  * documentation and/or other materials provided with distribution. In
     59  1.1.1.20  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.20  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.20  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.20  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.20  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.20  christos  * make.
     65  1.1.1.20  christos  *
     66  1.1.1.20  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.20  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.20  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.20  christos  * provision in the documentation and/or other materials provided with the
     70  1.1.1.20  christos  * distribution.
     71  1.1.1.20  christos  *
     72  1.1.1.20  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.20  christos  * Intel Code.
     74  1.1.1.20  christos  *
     75  1.1.1.20  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.20  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.20  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.20  christos  * without prior written authorization from Intel.
     79  1.1.1.20  christos  *
     80  1.1.1.20  christos  * 4. Disclaimer and Export Compliance
     81  1.1.1.20  christos  *
     82  1.1.1.20  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.20  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.20  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.20  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.20  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.20  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.20  christos  * PARTICULAR PURPOSE.
     89  1.1.1.20  christos  *
     90  1.1.1.20  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.20  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.20  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.20  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.20  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.20  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.20  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.20  christos  * LIMITED REMEDY.
     98  1.1.1.20  christos  *
     99  1.1.1.20  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.20  christos  * software or system incorporating such software without first obtaining any
    101  1.1.1.20  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.20  christos  * any other agency or department of the United States Government. In the
    103  1.1.1.20  christos  * event Licensee exports any such software from the United States or
    104  1.1.1.20  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.20  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.20  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.20  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.20  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.20  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.20  christos  * United States government or any agency thereof requires an export license,
    111  1.1.1.20  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.20  christos  * such license, approval or letter.
    113  1.1.1.20  christos  *
    114  1.1.1.20  christos  *****************************************************************************
    115  1.1.1.20  christos  *
    116  1.1.1.20  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.20  christos  * following license:
    118  1.1.1.20  christos  *
    119   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
    120   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
    121   1.1.1.2    jruoho  * are met:
    122   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
    123   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124   1.1.1.2    jruoho  *    without modification.
    125   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
    129   1.1.1.2    jruoho  *    binary redistribution.
    130   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
    132   1.1.1.2    jruoho  *    from this software without specific prior written permission.
    133   1.1.1.2    jruoho  *
    134   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.1.1.17  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.20  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.20  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.20  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.20  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.20  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.20  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.20  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.20  christos  *
    146  1.1.1.20  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.20  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.20  christos  * Software Foundation.
    149  1.1.1.20  christos  *
    150  1.1.1.20  christos  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "acpi.h"
    153       1.1    jruoho #include "accommon.h"
    154       1.1    jruoho #include "acparser.h"
    155       1.1    jruoho #include "amlcode.h"
    156       1.1    jruoho #include "acdispat.h"
    157       1.1    jruoho #include "acinterp.h"
    158       1.1    jruoho #include "acnamesp.h"
    159       1.1    jruoho #include "acdebug.h"
    160       1.1    jruoho 
    161       1.1    jruoho #define _COMPONENT          ACPI_DISPATCHER
    162       1.1    jruoho         ACPI_MODULE_NAME    ("dsutils")
    163       1.1    jruoho 
    164       1.1    jruoho 
    165       1.1    jruoho /*******************************************************************************
    166       1.1    jruoho  *
    167       1.1    jruoho  * FUNCTION:    AcpiDsClearImplicitReturn
    168       1.1    jruoho  *
    169       1.1    jruoho  * PARAMETERS:  WalkState           - Current State
    170       1.1    jruoho  *
    171       1.1    jruoho  * RETURN:      None.
    172       1.1    jruoho  *
    173   1.1.1.3  christos  * DESCRIPTION: Clear and remove a reference on an implicit return value. Used
    174       1.1    jruoho  *              to delete "stale" return values (if enabled, the return value
    175       1.1    jruoho  *              from every operator is saved at least momentarily, in case the
    176       1.1    jruoho  *              parent method exits.)
    177       1.1    jruoho  *
    178       1.1    jruoho  ******************************************************************************/
    179       1.1    jruoho 
    180       1.1    jruoho void
    181       1.1    jruoho AcpiDsClearImplicitReturn (
    182       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    183       1.1    jruoho {
    184       1.1    jruoho     ACPI_FUNCTION_NAME (DsClearImplicitReturn);
    185       1.1    jruoho 
    186       1.1    jruoho 
    187       1.1    jruoho     /*
    188       1.1    jruoho      * Slack must be enabled for this feature
    189       1.1    jruoho      */
    190       1.1    jruoho     if (!AcpiGbl_EnableInterpreterSlack)
    191       1.1    jruoho     {
    192       1.1    jruoho         return;
    193       1.1    jruoho     }
    194       1.1    jruoho 
    195       1.1    jruoho     if (WalkState->ImplicitReturnObj)
    196       1.1    jruoho     {
    197       1.1    jruoho         /*
    198       1.1    jruoho          * Delete any "stale" implicit return. However, in
    199       1.1    jruoho          * complex statements, the implicit return value can be
    200       1.1    jruoho          * bubbled up several levels.
    201       1.1    jruoho          */
    202       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    203       1.1    jruoho             "Removing reference on stale implicit return obj %p\n",
    204       1.1    jruoho             WalkState->ImplicitReturnObj));
    205       1.1    jruoho 
    206       1.1    jruoho         AcpiUtRemoveReference (WalkState->ImplicitReturnObj);
    207       1.1    jruoho         WalkState->ImplicitReturnObj = NULL;
    208       1.1    jruoho     }
    209       1.1    jruoho }
    210       1.1    jruoho 
    211       1.1    jruoho 
    212       1.1    jruoho /*******************************************************************************
    213       1.1    jruoho  *
    214       1.1    jruoho  * FUNCTION:    AcpiDsDoImplicitReturn
    215       1.1    jruoho  *
    216       1.1    jruoho  * PARAMETERS:  ReturnDesc          - The return value
    217       1.1    jruoho  *              WalkState           - Current State
    218       1.1    jruoho  *              AddReference        - True if a reference should be added to the
    219       1.1    jruoho  *                                    return object
    220       1.1    jruoho  *
    221       1.1    jruoho  * RETURN:      TRUE if implicit return enabled, FALSE otherwise
    222       1.1    jruoho  *
    223       1.1    jruoho  * DESCRIPTION: Implements the optional "implicit return".  We save the result
    224       1.1    jruoho  *              of every ASL operator and control method invocation in case the
    225   1.1.1.3  christos  *              parent method exit. Before storing a new return value, we
    226       1.1    jruoho  *              delete the previous return value.
    227       1.1    jruoho  *
    228       1.1    jruoho  ******************************************************************************/
    229       1.1    jruoho 
    230       1.1    jruoho BOOLEAN
    231       1.1    jruoho AcpiDsDoImplicitReturn (
    232       1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc,
    233       1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    234       1.1    jruoho     BOOLEAN                 AddReference)
    235       1.1    jruoho {
    236       1.1    jruoho     ACPI_FUNCTION_NAME (DsDoImplicitReturn);
    237       1.1    jruoho 
    238       1.1    jruoho 
    239       1.1    jruoho     /*
    240       1.1    jruoho      * Slack must be enabled for this feature, and we must
    241       1.1    jruoho      * have a valid return object
    242       1.1    jruoho      */
    243       1.1    jruoho     if ((!AcpiGbl_EnableInterpreterSlack) ||
    244       1.1    jruoho         (!ReturnDesc))
    245       1.1    jruoho     {
    246       1.1    jruoho         return (FALSE);
    247       1.1    jruoho     }
    248       1.1    jruoho 
    249       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    250   1.1.1.7  christos         "Result %p will be implicitly returned; Prev=%p\n",
    251   1.1.1.7  christos         ReturnDesc,
    252   1.1.1.7  christos         WalkState->ImplicitReturnObj));
    253       1.1    jruoho 
    254       1.1    jruoho     /*
    255       1.1    jruoho      * Delete any "stale" implicit return value first. However, in
    256       1.1    jruoho      * complex statements, the implicit return value can be
    257       1.1    jruoho      * bubbled up several levels, so we don't clear the value if it
    258       1.1    jruoho      * is the same as the ReturnDesc.
    259       1.1    jruoho      */
    260       1.1    jruoho     if (WalkState->ImplicitReturnObj)
    261       1.1    jruoho     {
    262       1.1    jruoho         if (WalkState->ImplicitReturnObj == ReturnDesc)
    263       1.1    jruoho         {
    264       1.1    jruoho             return (TRUE);
    265       1.1    jruoho         }
    266       1.1    jruoho         AcpiDsClearImplicitReturn (WalkState);
    267       1.1    jruoho     }
    268       1.1    jruoho 
    269       1.1    jruoho     /* Save the implicit return value, add a reference if requested */
    270       1.1    jruoho 
    271       1.1    jruoho     WalkState->ImplicitReturnObj = ReturnDesc;
    272       1.1    jruoho     if (AddReference)
    273       1.1    jruoho     {
    274       1.1    jruoho         AcpiUtAddReference (ReturnDesc);
    275       1.1    jruoho     }
    276       1.1    jruoho 
    277       1.1    jruoho     return (TRUE);
    278       1.1    jruoho }
    279       1.1    jruoho 
    280       1.1    jruoho 
    281       1.1    jruoho /*******************************************************************************
    282       1.1    jruoho  *
    283       1.1    jruoho  * FUNCTION:    AcpiDsIsResultUsed
    284       1.1    jruoho  *
    285       1.1    jruoho  * PARAMETERS:  Op                  - Current Op
    286       1.1    jruoho  *              WalkState           - Current State
    287       1.1    jruoho  *
    288       1.1    jruoho  * RETURN:      TRUE if result is used, FALSE otherwise
    289       1.1    jruoho  *
    290       1.1    jruoho  * DESCRIPTION: Check if a result object will be used by the parent
    291       1.1    jruoho  *
    292       1.1    jruoho  ******************************************************************************/
    293       1.1    jruoho 
    294       1.1    jruoho BOOLEAN
    295       1.1    jruoho AcpiDsIsResultUsed (
    296       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    297       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    298       1.1    jruoho {
    299       1.1    jruoho     const ACPI_OPCODE_INFO  *ParentInfo;
    300       1.1    jruoho 
    301       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsIsResultUsed, Op);
    302       1.1    jruoho 
    303       1.1    jruoho 
    304       1.1    jruoho     /* Must have both an Op and a Result Object */
    305       1.1    jruoho 
    306       1.1    jruoho     if (!Op)
    307       1.1    jruoho     {
    308       1.1    jruoho         ACPI_ERROR ((AE_INFO, "Null Op"));
    309       1.1    jruoho         return_UINT8 (TRUE);
    310       1.1    jruoho     }
    311       1.1    jruoho 
    312       1.1    jruoho     /*
    313       1.1    jruoho      * We know that this operator is not a
    314       1.1    jruoho      * Return() operator (would not come here.) The following code is the
    315       1.1    jruoho      * optional support for a so-called "implicit return". Some AML code
    316       1.1    jruoho      * assumes that the last value of the method is "implicitly" returned
    317       1.1    jruoho      * to the caller. Just save the last result as the return value.
    318       1.1    jruoho      * NOTE: this is optional because the ASL language does not actually
    319       1.1    jruoho      * support this behavior.
    320       1.1    jruoho      */
    321       1.1    jruoho     (void) AcpiDsDoImplicitReturn (WalkState->ResultObj, WalkState, TRUE);
    322       1.1    jruoho 
    323       1.1    jruoho     /*
    324       1.1    jruoho      * Now determine if the parent will use the result
    325       1.1    jruoho      *
    326       1.1    jruoho      * If there is no parent, or the parent is a ScopeOp, we are executing
    327       1.1    jruoho      * at the method level. An executing method typically has no parent,
    328   1.1.1.3  christos      * since each method is parsed separately. A method invoked externally
    329       1.1    jruoho      * via ExecuteControlMethod has a ScopeOp as the parent.
    330       1.1    jruoho      */
    331       1.1    jruoho     if ((!Op->Common.Parent) ||
    332       1.1    jruoho         (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
    333       1.1    jruoho     {
    334       1.1    jruoho         /* No parent, the return value cannot possibly be used */
    335       1.1    jruoho 
    336       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    337       1.1    jruoho             "At Method level, result of [%s] not used\n",
    338       1.1    jruoho             AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
    339       1.1    jruoho         return_UINT8 (FALSE);
    340       1.1    jruoho     }
    341       1.1    jruoho 
    342       1.1    jruoho     /* Get info on the parent. The RootOp is AML_SCOPE */
    343       1.1    jruoho 
    344       1.1    jruoho     ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
    345       1.1    jruoho     if (ParentInfo->Class == AML_CLASS_UNKNOWN)
    346       1.1    jruoho     {
    347       1.1    jruoho         ACPI_ERROR ((AE_INFO,
    348       1.1    jruoho             "Unknown parent opcode Op=%p", Op));
    349       1.1    jruoho         return_UINT8 (FALSE);
    350       1.1    jruoho     }
    351       1.1    jruoho 
    352       1.1    jruoho     /*
    353   1.1.1.3  christos      * Decide what to do with the result based on the parent. If
    354       1.1    jruoho      * the parent opcode will not use the result, delete the object.
    355       1.1    jruoho      * Otherwise leave it as is, it will be deleted when it is used
    356       1.1    jruoho      * as an operand later.
    357       1.1    jruoho      */
    358       1.1    jruoho     switch (ParentInfo->Class)
    359       1.1    jruoho     {
    360       1.1    jruoho     case AML_CLASS_CONTROL:
    361       1.1    jruoho 
    362       1.1    jruoho         switch (Op->Common.Parent->Common.AmlOpcode)
    363       1.1    jruoho         {
    364       1.1    jruoho         case AML_RETURN_OP:
    365       1.1    jruoho 
    366       1.1    jruoho             /* Never delete the return value associated with a return opcode */
    367       1.1    jruoho 
    368       1.1    jruoho             goto ResultUsed;
    369       1.1    jruoho 
    370       1.1    jruoho         case AML_IF_OP:
    371       1.1    jruoho         case AML_WHILE_OP:
    372       1.1    jruoho             /*
    373       1.1    jruoho              * If we are executing the predicate AND this is the predicate op,
    374       1.1    jruoho              * we will use the return value
    375       1.1    jruoho              */
    376   1.1.1.7  christos             if ((WalkState->ControlState->Common.State ==
    377   1.1.1.7  christos                     ACPI_CONTROL_PREDICATE_EXECUTING) &&
    378       1.1    jruoho                 (WalkState->ControlState->Control.PredicateOp == Op))
    379       1.1    jruoho             {
    380       1.1    jruoho                 goto ResultUsed;
    381       1.1    jruoho             }
    382       1.1    jruoho             break;
    383       1.1    jruoho 
    384       1.1    jruoho         default:
    385   1.1.1.3  christos 
    386       1.1    jruoho             /* Ignore other control opcodes */
    387   1.1.1.3  christos 
    388       1.1    jruoho             break;
    389       1.1    jruoho         }
    390       1.1    jruoho 
    391       1.1    jruoho         /* The general control opcode returns no result */
    392       1.1    jruoho 
    393       1.1    jruoho         goto ResultNotUsed;
    394       1.1    jruoho 
    395       1.1    jruoho     case AML_CLASS_CREATE:
    396       1.1    jruoho         /*
    397       1.1    jruoho          * These opcodes allow TermArg(s) as operands and therefore
    398   1.1.1.3  christos          * the operands can be method calls. The result is used.
    399       1.1    jruoho          */
    400       1.1    jruoho         goto ResultUsed;
    401       1.1    jruoho 
    402       1.1    jruoho     case AML_CLASS_NAMED_OBJECT:
    403       1.1    jruoho 
    404       1.1    jruoho         if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
    405       1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
    406       1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
    407       1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
    408  1.1.1.10  christos             (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP) ||
    409       1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_INT_EVAL_SUBTREE_OP) ||
    410       1.1    jruoho             (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP))
    411       1.1    jruoho         {
    412       1.1    jruoho             /*
    413       1.1    jruoho              * These opcodes allow TermArg(s) as operands and therefore
    414   1.1.1.3  christos              * the operands can be method calls. The result is used.
    415       1.1    jruoho              */
    416       1.1    jruoho             goto ResultUsed;
    417       1.1    jruoho         }
    418       1.1    jruoho 
    419       1.1    jruoho         goto ResultNotUsed;
    420       1.1    jruoho 
    421       1.1    jruoho     default:
    422       1.1    jruoho         /*
    423       1.1    jruoho          * In all other cases. the parent will actually use the return
    424       1.1    jruoho          * object, so keep it.
    425       1.1    jruoho          */
    426       1.1    jruoho         goto ResultUsed;
    427       1.1    jruoho     }
    428       1.1    jruoho 
    429       1.1    jruoho 
    430       1.1    jruoho ResultUsed:
    431       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    432       1.1    jruoho         "Result of [%s] used by Parent [%s] Op=%p\n",
    433       1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
    434       1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
    435       1.1    jruoho 
    436       1.1    jruoho     return_UINT8 (TRUE);
    437       1.1    jruoho 
    438       1.1    jruoho 
    439       1.1    jruoho ResultNotUsed:
    440       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    441       1.1    jruoho         "Result of [%s] not used by Parent [%s] Op=%p\n",
    442       1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
    443       1.1    jruoho         AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
    444       1.1    jruoho 
    445       1.1    jruoho     return_UINT8 (FALSE);
    446       1.1    jruoho }
    447       1.1    jruoho 
    448       1.1    jruoho 
    449       1.1    jruoho /*******************************************************************************
    450       1.1    jruoho  *
    451       1.1    jruoho  * FUNCTION:    AcpiDsDeleteResultIfNotUsed
    452       1.1    jruoho  *
    453       1.1    jruoho  * PARAMETERS:  Op              - Current parse Op
    454       1.1    jruoho  *              ResultObj       - Result of the operation
    455       1.1    jruoho  *              WalkState       - Current state
    456       1.1    jruoho  *
    457       1.1    jruoho  * RETURN:      Status
    458       1.1    jruoho  *
    459   1.1.1.3  christos  * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
    460       1.1    jruoho  *              result descriptor, check if the parent opcode will actually use
    461   1.1.1.3  christos  *              this result. If not, delete the result now so that it will
    462       1.1    jruoho  *              not become orphaned.
    463       1.1    jruoho  *
    464       1.1    jruoho  ******************************************************************************/
    465       1.1    jruoho 
    466       1.1    jruoho void
    467       1.1    jruoho AcpiDsDeleteResultIfNotUsed (
    468       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    469       1.1    jruoho     ACPI_OPERAND_OBJECT     *ResultObj,
    470       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    471       1.1    jruoho {
    472       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    473       1.1    jruoho     ACPI_STATUS             Status;
    474       1.1    jruoho 
    475       1.1    jruoho 
    476       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsDeleteResultIfNotUsed, ResultObj);
    477       1.1    jruoho 
    478       1.1    jruoho 
    479       1.1    jruoho     if (!Op)
    480       1.1    jruoho     {
    481       1.1    jruoho         ACPI_ERROR ((AE_INFO, "Null Op"));
    482       1.1    jruoho         return_VOID;
    483       1.1    jruoho     }
    484       1.1    jruoho 
    485       1.1    jruoho     if (!ResultObj)
    486       1.1    jruoho     {
    487       1.1    jruoho         return_VOID;
    488       1.1    jruoho     }
    489       1.1    jruoho 
    490       1.1    jruoho     if (!AcpiDsIsResultUsed (Op, WalkState))
    491       1.1    jruoho     {
    492       1.1    jruoho         /* Must pop the result stack (ObjDesc should be equal to ResultObj) */
    493       1.1    jruoho 
    494       1.1    jruoho         Status = AcpiDsResultPop (&ObjDesc, WalkState);
    495       1.1    jruoho         if (ACPI_SUCCESS (Status))
    496       1.1    jruoho         {
    497       1.1    jruoho             AcpiUtRemoveReference (ResultObj);
    498       1.1    jruoho         }
    499       1.1    jruoho     }
    500       1.1    jruoho 
    501       1.1    jruoho     return_VOID;
    502       1.1    jruoho }
    503       1.1    jruoho 
    504       1.1    jruoho 
    505       1.1    jruoho /*******************************************************************************
    506       1.1    jruoho  *
    507       1.1    jruoho  * FUNCTION:    AcpiDsResolveOperands
    508       1.1    jruoho  *
    509       1.1    jruoho  * PARAMETERS:  WalkState           - Current walk state with operands on stack
    510       1.1    jruoho  *
    511       1.1    jruoho  * RETURN:      Status
    512       1.1    jruoho  *
    513   1.1.1.3  christos  * DESCRIPTION: Resolve all operands to their values. Used to prepare
    514       1.1    jruoho  *              arguments to a control method invocation (a call from one
    515       1.1    jruoho  *              method to another.)
    516       1.1    jruoho  *
    517       1.1    jruoho  ******************************************************************************/
    518       1.1    jruoho 
    519       1.1    jruoho ACPI_STATUS
    520       1.1    jruoho AcpiDsResolveOperands (
    521       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    522       1.1    jruoho {
    523       1.1    jruoho     UINT32                  i;
    524       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    525       1.1    jruoho 
    526       1.1    jruoho 
    527       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsResolveOperands, WalkState);
    528       1.1    jruoho 
    529       1.1    jruoho 
    530       1.1    jruoho     /*
    531       1.1    jruoho      * Attempt to resolve each of the valid operands
    532   1.1.1.3  christos      * Method arguments are passed by reference, not by value. This means
    533       1.1    jruoho      * that the actual objects are passed, not copies of the objects.
    534       1.1    jruoho      */
    535       1.1    jruoho     for (i = 0; i < WalkState->NumOperands; i++)
    536       1.1    jruoho     {
    537       1.1    jruoho         Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
    538       1.1    jruoho         if (ACPI_FAILURE (Status))
    539       1.1    jruoho         {
    540       1.1    jruoho             break;
    541       1.1    jruoho         }
    542       1.1    jruoho     }
    543       1.1    jruoho 
    544       1.1    jruoho     return_ACPI_STATUS (Status);
    545       1.1    jruoho }
    546       1.1    jruoho 
    547       1.1    jruoho 
    548       1.1    jruoho /*******************************************************************************
    549       1.1    jruoho  *
    550       1.1    jruoho  * FUNCTION:    AcpiDsClearOperands
    551       1.1    jruoho  *
    552       1.1    jruoho  * PARAMETERS:  WalkState           - Current walk state with operands on stack
    553       1.1    jruoho  *
    554       1.1    jruoho  * RETURN:      None
    555       1.1    jruoho  *
    556       1.1    jruoho  * DESCRIPTION: Clear all operands on the current walk state operand stack.
    557       1.1    jruoho  *
    558       1.1    jruoho  ******************************************************************************/
    559       1.1    jruoho 
    560       1.1    jruoho void
    561       1.1    jruoho AcpiDsClearOperands (
    562       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    563       1.1    jruoho {
    564       1.1    jruoho     UINT32                  i;
    565       1.1    jruoho 
    566       1.1    jruoho 
    567       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsClearOperands, WalkState);
    568       1.1    jruoho 
    569       1.1    jruoho 
    570       1.1    jruoho     /* Remove a reference on each operand on the stack */
    571       1.1    jruoho 
    572       1.1    jruoho     for (i = 0; i < WalkState->NumOperands; i++)
    573       1.1    jruoho     {
    574       1.1    jruoho         /*
    575       1.1    jruoho          * Remove a reference to all operands, including both
    576       1.1    jruoho          * "Arguments" and "Targets".
    577       1.1    jruoho          */
    578       1.1    jruoho         AcpiUtRemoveReference (WalkState->Operands[i]);
    579       1.1    jruoho         WalkState->Operands[i] = NULL;
    580       1.1    jruoho     }
    581       1.1    jruoho 
    582       1.1    jruoho     WalkState->NumOperands = 0;
    583       1.1    jruoho     return_VOID;
    584       1.1    jruoho }
    585       1.1    jruoho 
    586       1.1    jruoho 
    587       1.1    jruoho /*******************************************************************************
    588       1.1    jruoho  *
    589       1.1    jruoho  * FUNCTION:    AcpiDsCreateOperand
    590       1.1    jruoho  *
    591       1.1    jruoho  * PARAMETERS:  WalkState       - Current walk state
    592       1.1    jruoho  *              Arg             - Parse object for the argument
    593       1.1    jruoho  *              ArgIndex        - Which argument (zero based)
    594       1.1    jruoho  *
    595       1.1    jruoho  * RETURN:      Status
    596       1.1    jruoho  *
    597       1.1    jruoho  * DESCRIPTION: Translate a parse tree object that is an argument to an AML
    598   1.1.1.3  christos  *              opcode to the equivalent interpreter object. This may include
    599       1.1    jruoho  *              looking up a name or entering a new name into the internal
    600       1.1    jruoho  *              namespace.
    601       1.1    jruoho  *
    602       1.1    jruoho  ******************************************************************************/
    603       1.1    jruoho 
    604       1.1    jruoho ACPI_STATUS
    605       1.1    jruoho AcpiDsCreateOperand (
    606       1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    607       1.1    jruoho     ACPI_PARSE_OBJECT       *Arg,
    608       1.1    jruoho     UINT32                  ArgIndex)
    609       1.1    jruoho {
    610       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    611       1.1    jruoho     char                    *NameString;
    612       1.1    jruoho     UINT32                  NameLength;
    613       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    614       1.1    jruoho     ACPI_PARSE_OBJECT       *ParentOp;
    615       1.1    jruoho     UINT16                  Opcode;
    616       1.1    jruoho     ACPI_INTERPRETER_MODE   InterpreterMode;
    617       1.1    jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    618       1.1    jruoho 
    619       1.1    jruoho 
    620       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsCreateOperand, Arg);
    621       1.1    jruoho 
    622       1.1    jruoho 
    623       1.1    jruoho     /* A valid name must be looked up in the namespace */
    624       1.1    jruoho 
    625       1.1    jruoho     if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
    626       1.1    jruoho         (Arg->Common.Value.String) &&
    627       1.1    jruoho         !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
    628       1.1    jruoho     {
    629       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
    630       1.1    jruoho 
    631       1.1    jruoho         /* Get the entire name string from the AML stream */
    632       1.1    jruoho 
    633   1.1.1.7  christos         Status = AcpiExGetNameString (ACPI_TYPE_ANY,
    634   1.1.1.7  christos             Arg->Common.Value.Buffer, &NameString, &NameLength);
    635       1.1    jruoho 
    636       1.1    jruoho         if (ACPI_FAILURE (Status))
    637       1.1    jruoho         {
    638       1.1    jruoho             return_ACPI_STATUS (Status);
    639       1.1    jruoho         }
    640       1.1    jruoho 
    641       1.1    jruoho         /* All prefixes have been handled, and the name is in NameString */
    642       1.1    jruoho 
    643       1.1    jruoho         /*
    644   1.1.1.3  christos          * Special handling for BufferField declarations. This is a deferred
    645       1.1    jruoho          * opcode that unfortunately defines the field name as the last
    646   1.1.1.3  christos          * parameter instead of the first. We get here when we are performing
    647       1.1    jruoho          * the deferred execution, so the actual name of the field is already
    648   1.1.1.3  christos          * in the namespace. We don't want to attempt to look it up again
    649       1.1    jruoho          * because we may be executing in a different scope than where the
    650       1.1    jruoho          * actual opcode exists.
    651       1.1    jruoho          */
    652       1.1    jruoho         if ((WalkState->DeferredNode) &&
    653       1.1    jruoho             (WalkState->DeferredNode->Type == ACPI_TYPE_BUFFER_FIELD) &&
    654   1.1.1.7  christos             (ArgIndex == (UINT32)
    655   1.1.1.7  christos                 ((WalkState->Opcode == AML_CREATE_FIELD_OP) ? 3 : 2)))
    656       1.1    jruoho         {
    657       1.1    jruoho             ObjDesc = ACPI_CAST_PTR (
    658   1.1.1.7  christos                 ACPI_OPERAND_OBJECT, WalkState->DeferredNode);
    659       1.1    jruoho             Status = AE_OK;
    660       1.1    jruoho         }
    661       1.1    jruoho         else    /* All other opcodes */
    662       1.1    jruoho         {
    663       1.1    jruoho             /*
    664       1.1    jruoho              * Differentiate between a namespace "create" operation
    665       1.1    jruoho              * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
    666       1.1    jruoho              * IMODE_EXECUTE) in order to support the creation of
    667       1.1    jruoho              * namespace objects during the execution of control methods.
    668       1.1    jruoho              */
    669       1.1    jruoho             ParentOp = Arg->Common.Parent;
    670       1.1    jruoho             OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
    671   1.1.1.7  christos 
    672       1.1    jruoho             if ((OpInfo->Flags & AML_NSNODE) &&
    673       1.1    jruoho                 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
    674       1.1    jruoho                 (ParentOp->Common.AmlOpcode != AML_REGION_OP) &&
    675       1.1    jruoho                 (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
    676       1.1    jruoho             {
    677       1.1    jruoho                 /* Enter name into namespace if not found */
    678       1.1    jruoho 
    679       1.1    jruoho                 InterpreterMode = ACPI_IMODE_LOAD_PASS2;
    680       1.1    jruoho             }
    681       1.1    jruoho             else
    682       1.1    jruoho             {
    683       1.1    jruoho                 /* Return a failure if name not found */
    684       1.1    jruoho 
    685       1.1    jruoho                 InterpreterMode = ACPI_IMODE_EXECUTE;
    686       1.1    jruoho             }
    687       1.1    jruoho 
    688       1.1    jruoho             Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
    689   1.1.1.7  christos                 ACPI_TYPE_ANY, InterpreterMode,
    690   1.1.1.7  christos                 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, WalkState,
    691   1.1.1.7  christos                 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc));
    692       1.1    jruoho             /*
    693       1.1    jruoho              * The only case where we pass through (ignore) a NOT_FOUND
    694       1.1    jruoho              * error is for the CondRefOf opcode.
    695       1.1    jruoho              */
    696       1.1    jruoho             if (Status == AE_NOT_FOUND)
    697       1.1    jruoho             {
    698  1.1.1.10  christos                 if (ParentOp->Common.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)
    699       1.1    jruoho                 {
    700       1.1    jruoho                     /*
    701       1.1    jruoho                      * For the Conditional Reference op, it's OK if
    702       1.1    jruoho                      * the name is not found;  We just need a way to
    703       1.1    jruoho                      * indicate this to the interpreter, set the
    704       1.1    jruoho                      * object to the root
    705       1.1    jruoho                      */
    706       1.1    jruoho                     ObjDesc = ACPI_CAST_PTR (
    707   1.1.1.7  christos                         ACPI_OPERAND_OBJECT, AcpiGbl_RootNode);
    708       1.1    jruoho                     Status = AE_OK;
    709       1.1    jruoho                 }
    710   1.1.1.5  christos                 else if (ParentOp->Common.AmlOpcode == AML_EXTERNAL_OP)
    711   1.1.1.5  christos                 {
    712   1.1.1.8  christos                     /*
    713   1.1.1.8  christos                      * This opcode should never appear here. It is used only
    714   1.1.1.8  christos                      * by AML disassemblers and is surrounded by an If(0)
    715   1.1.1.8  christos                      * by the ASL compiler.
    716   1.1.1.8  christos                      *
    717   1.1.1.8  christos                      * Therefore, if we see it here, it is a serious error.
    718   1.1.1.8  christos                      */
    719   1.1.1.8  christos                     Status = AE_AML_BAD_OPCODE;
    720   1.1.1.5  christos                 }
    721       1.1    jruoho                 else
    722       1.1    jruoho                 {
    723       1.1    jruoho                     /*
    724       1.1    jruoho                      * We just plain didn't find it -- which is a
    725       1.1    jruoho                      * very serious error at this point
    726       1.1    jruoho                      */
    727       1.1    jruoho                     Status = AE_AML_NAME_NOT_FOUND;
    728       1.1    jruoho                 }
    729       1.1    jruoho             }
    730       1.1    jruoho 
    731       1.1    jruoho             if (ACPI_FAILURE (Status))
    732       1.1    jruoho             {
    733  1.1.1.12  christos                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
    734  1.1.1.12  christos                     NameString, Status);
    735       1.1    jruoho             }
    736       1.1    jruoho         }
    737       1.1    jruoho 
    738       1.1    jruoho         /* Free the namestring created above */
    739       1.1    jruoho 
    740       1.1    jruoho         ACPI_FREE (NameString);
    741       1.1    jruoho 
    742       1.1    jruoho         /* Check status from the lookup */
    743       1.1    jruoho 
    744       1.1    jruoho         if (ACPI_FAILURE (Status))
    745       1.1    jruoho         {
    746       1.1    jruoho             return_ACPI_STATUS (Status);
    747       1.1    jruoho         }
    748       1.1    jruoho 
    749       1.1    jruoho         /* Put the resulting object onto the current object stack */
    750       1.1    jruoho 
    751       1.1    jruoho         Status = AcpiDsObjStackPush (ObjDesc, WalkState);
    752       1.1    jruoho         if (ACPI_FAILURE (Status))
    753       1.1    jruoho         {
    754       1.1    jruoho             return_ACPI_STATUS (Status);
    755       1.1    jruoho         }
    756   1.1.1.7  christos 
    757   1.1.1.7  christos         AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
    758       1.1    jruoho     }
    759       1.1    jruoho     else
    760       1.1    jruoho     {
    761       1.1    jruoho         /* Check for null name case */
    762       1.1    jruoho 
    763       1.1    jruoho         if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
    764       1.1    jruoho             !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
    765       1.1    jruoho         {
    766       1.1    jruoho             /*
    767       1.1    jruoho              * If the name is null, this means that this is an
    768       1.1    jruoho              * optional result parameter that was not specified
    769   1.1.1.3  christos              * in the original ASL. Create a Zero Constant for a
    770   1.1.1.3  christos              * placeholder. (Store to a constant is a Noop.)
    771       1.1    jruoho              */
    772       1.1    jruoho             Opcode = AML_ZERO_OP;       /* Has no arguments! */
    773       1.1    jruoho 
    774       1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    775       1.1    jruoho                 "Null namepath: Arg=%p\n", Arg));
    776       1.1    jruoho         }
    777       1.1    jruoho         else
    778       1.1    jruoho         {
    779       1.1    jruoho             Opcode = Arg->Common.AmlOpcode;
    780       1.1    jruoho         }
    781       1.1    jruoho 
    782       1.1    jruoho         /* Get the object type of the argument */
    783       1.1    jruoho 
    784       1.1    jruoho         OpInfo = AcpiPsGetOpcodeInfo (Opcode);
    785       1.1    jruoho         if (OpInfo->ObjectType == ACPI_TYPE_INVALID)
    786       1.1    jruoho         {
    787       1.1    jruoho             return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
    788       1.1    jruoho         }
    789       1.1    jruoho 
    790   1.1.1.7  christos         if ((OpInfo->Flags & AML_HAS_RETVAL) ||
    791   1.1.1.7  christos             (Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
    792       1.1    jruoho         {
    793       1.1    jruoho             /*
    794       1.1    jruoho              * Use value that was already previously returned
    795       1.1    jruoho              * by the evaluation of this argument
    796       1.1    jruoho              */
    797       1.1    jruoho             Status = AcpiDsResultPop (&ObjDesc, WalkState);
    798       1.1    jruoho             if (ACPI_FAILURE (Status))
    799       1.1    jruoho             {
    800       1.1    jruoho                 /*
    801       1.1    jruoho                  * Only error is underflow, and this indicates
    802       1.1    jruoho                  * a missing or null operand!
    803       1.1    jruoho                  */
    804       1.1    jruoho                 ACPI_EXCEPTION ((AE_INFO, Status,
    805       1.1    jruoho                     "Missing or null operand"));
    806       1.1    jruoho                 return_ACPI_STATUS (Status);
    807       1.1    jruoho             }
    808       1.1    jruoho         }
    809       1.1    jruoho         else
    810       1.1    jruoho         {
    811       1.1    jruoho             /* Create an ACPI_INTERNAL_OBJECT for the argument */
    812       1.1    jruoho 
    813       1.1    jruoho             ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType);
    814       1.1    jruoho             if (!ObjDesc)
    815       1.1    jruoho             {
    816       1.1    jruoho                 return_ACPI_STATUS (AE_NO_MEMORY);
    817       1.1    jruoho             }
    818       1.1    jruoho 
    819       1.1    jruoho             /* Initialize the new object */
    820       1.1    jruoho 
    821       1.1    jruoho             Status = AcpiDsInitObjectFromOp (
    822   1.1.1.7  christos                 WalkState, Arg, Opcode, &ObjDesc);
    823       1.1    jruoho             if (ACPI_FAILURE (Status))
    824       1.1    jruoho             {
    825       1.1    jruoho                 AcpiUtDeleteObjectDesc (ObjDesc);
    826       1.1    jruoho                 return_ACPI_STATUS (Status);
    827       1.1    jruoho             }
    828       1.1    jruoho         }
    829       1.1    jruoho 
    830       1.1    jruoho         /* Put the operand object on the object stack */
    831       1.1    jruoho 
    832       1.1    jruoho         Status = AcpiDsObjStackPush (ObjDesc, WalkState);
    833       1.1    jruoho         if (ACPI_FAILURE (Status))
    834       1.1    jruoho         {
    835       1.1    jruoho             return_ACPI_STATUS (Status);
    836       1.1    jruoho         }
    837       1.1    jruoho 
    838   1.1.1.7  christos         AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
    839       1.1    jruoho     }
    840       1.1    jruoho 
    841       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    842       1.1    jruoho }
    843       1.1    jruoho 
    844       1.1    jruoho 
    845       1.1    jruoho /*******************************************************************************
    846       1.1    jruoho  *
    847       1.1    jruoho  * FUNCTION:    AcpiDsCreateOperands
    848       1.1    jruoho  *
    849       1.1    jruoho  * PARAMETERS:  WalkState           - Current state
    850       1.1    jruoho  *              FirstArg            - First argument of a parser argument tree
    851       1.1    jruoho  *
    852       1.1    jruoho  * RETURN:      Status
    853       1.1    jruoho  *
    854       1.1    jruoho  * DESCRIPTION: Convert an operator's arguments from a parse tree format to
    855       1.1    jruoho  *              namespace objects and place those argument object on the object
    856       1.1    jruoho  *              stack in preparation for evaluation by the interpreter.
    857       1.1    jruoho  *
    858       1.1    jruoho  ******************************************************************************/
    859       1.1    jruoho 
    860       1.1    jruoho ACPI_STATUS
    861       1.1    jruoho AcpiDsCreateOperands (
    862       1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    863       1.1    jruoho     ACPI_PARSE_OBJECT       *FirstArg)
    864       1.1    jruoho {
    865       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    866       1.1    jruoho     ACPI_PARSE_OBJECT       *Arg;
    867       1.1    jruoho     ACPI_PARSE_OBJECT       *Arguments[ACPI_OBJ_NUM_OPERANDS];
    868       1.1    jruoho     UINT32                  ArgCount = 0;
    869       1.1    jruoho     UINT32                  Index = WalkState->NumOperands;
    870  1.1.1.20  christos     UINT32                  PrevNumOperands = WalkState->NumOperands;
    871  1.1.1.20  christos     UINT32                  NewNumOperands;
    872       1.1    jruoho     UINT32                  i;
    873       1.1    jruoho 
    874       1.1    jruoho 
    875       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsCreateOperands, FirstArg);
    876       1.1    jruoho 
    877       1.1    jruoho 
    878       1.1    jruoho     /* Get all arguments in the list */
    879       1.1    jruoho 
    880       1.1    jruoho     Arg = FirstArg;
    881       1.1    jruoho     while (Arg)
    882       1.1    jruoho     {
    883       1.1    jruoho         if (Index >= ACPI_OBJ_NUM_OPERANDS)
    884       1.1    jruoho         {
    885       1.1    jruoho             return_ACPI_STATUS (AE_BAD_DATA);
    886       1.1    jruoho         }
    887       1.1    jruoho 
    888       1.1    jruoho         Arguments[Index] = Arg;
    889       1.1    jruoho         WalkState->Operands [Index] = NULL;
    890       1.1    jruoho 
    891       1.1    jruoho         /* Move on to next argument, if any */
    892       1.1    jruoho 
    893       1.1    jruoho         Arg = Arg->Common.Next;
    894       1.1    jruoho         ArgCount++;
    895       1.1    jruoho         Index++;
    896       1.1    jruoho     }
    897       1.1    jruoho 
    898   1.1.1.3  christos     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    899   1.1.1.3  christos         "NumOperands %d, ArgCount %d, Index %d\n",
    900   1.1.1.3  christos         WalkState->NumOperands, ArgCount, Index));
    901       1.1    jruoho 
    902   1.1.1.3  christos     /* Create the interpreter arguments, in reverse order */
    903       1.1    jruoho 
    904  1.1.1.20  christos     NewNumOperands = Index;
    905   1.1.1.3  christos     Index--;
    906       1.1    jruoho     for (i = 0; i < ArgCount; i++)
    907       1.1    jruoho     {
    908       1.1    jruoho         Arg = Arguments[Index];
    909       1.1    jruoho         WalkState->OperandIndex = (UINT8) Index;
    910       1.1    jruoho 
    911       1.1    jruoho         Status = AcpiDsCreateOperand (WalkState, Arg, Index);
    912       1.1    jruoho         if (ACPI_FAILURE (Status))
    913       1.1    jruoho         {
    914       1.1    jruoho             goto Cleanup;
    915       1.1    jruoho         }
    916       1.1    jruoho 
    917   1.1.1.3  christos         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    918   1.1.1.3  christos             "Created Arg #%u (%p) %u args total\n",
    919   1.1.1.3  christos             Index, Arg, ArgCount));
    920       1.1    jruoho         Index--;
    921       1.1    jruoho     }
    922       1.1    jruoho 
    923       1.1    jruoho     return_ACPI_STATUS (Status);
    924       1.1    jruoho 
    925       1.1    jruoho 
    926       1.1    jruoho Cleanup:
    927       1.1    jruoho     /*
    928       1.1    jruoho      * We must undo everything done above; meaning that we must
    929       1.1    jruoho      * pop everything off of the operand stack and delete those
    930       1.1    jruoho      * objects
    931       1.1    jruoho      */
    932  1.1.1.20  christos     WalkState->NumOperands = (UINT8) (i);
    933  1.1.1.20  christos     AcpiDsObjStackPopAndDelete (NewNumOperands, WalkState);
    934  1.1.1.20  christos 
    935  1.1.1.20  christos     /* Restore operand count */
    936  1.1.1.20  christos     WalkState->NumOperands = (UINT8) (PrevNumOperands);
    937       1.1    jruoho 
    938       1.1    jruoho     ACPI_EXCEPTION ((AE_INFO, Status, "While creating Arg %u", Index));
    939       1.1    jruoho     return_ACPI_STATUS (Status);
    940       1.1    jruoho }
    941       1.1    jruoho 
    942       1.1    jruoho 
    943       1.1    jruoho /*****************************************************************************
    944       1.1    jruoho  *
    945       1.1    jruoho  * FUNCTION:    AcpiDsEvaluateNamePath
    946       1.1    jruoho  *
    947       1.1    jruoho  * PARAMETERS:  WalkState       - Current state of the parse tree walk,
    948       1.1    jruoho  *                                the opcode of current operation should be
    949       1.1    jruoho  *                                AML_INT_NAMEPATH_OP
    950       1.1    jruoho  *
    951       1.1    jruoho  * RETURN:      Status
    952       1.1    jruoho  *
    953       1.1    jruoho  * DESCRIPTION: Translate the -NamePath- parse tree object to the equivalent
    954       1.1    jruoho  *              interpreter object, convert it to value, if needed, duplicate
    955       1.1    jruoho  *              it, if needed, and push it onto the current result stack.
    956       1.1    jruoho  *
    957       1.1    jruoho  ****************************************************************************/
    958       1.1    jruoho 
    959       1.1    jruoho ACPI_STATUS
    960       1.1    jruoho AcpiDsEvaluateNamePath (
    961       1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    962       1.1    jruoho {
    963       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    964       1.1    jruoho     ACPI_PARSE_OBJECT       *Op = WalkState->Op;
    965       1.1    jruoho     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
    966       1.1    jruoho     ACPI_OPERAND_OBJECT     *NewObjDesc;
    967       1.1    jruoho     UINT8                   Type;
    968       1.1    jruoho 
    969       1.1    jruoho 
    970       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (DsEvaluateNamePath, WalkState);
    971       1.1    jruoho 
    972       1.1    jruoho 
    973       1.1    jruoho     if (!Op->Common.Parent)
    974       1.1    jruoho     {
    975       1.1    jruoho         /* This happens after certain exception processing */
    976       1.1    jruoho 
    977       1.1    jruoho         goto Exit;
    978       1.1    jruoho     }
    979       1.1    jruoho 
    980       1.1    jruoho     if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
    981  1.1.1.10  christos         (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP) ||
    982       1.1    jruoho         (Op->Common.Parent->Common.AmlOpcode == AML_REF_OF_OP))
    983       1.1    jruoho     {
    984       1.1    jruoho         /* TBD: Should we specify this feature as a bit of OpInfo->Flags of these opcodes? */
    985       1.1    jruoho 
    986       1.1    jruoho         goto Exit;
    987       1.1    jruoho     }
    988       1.1    jruoho 
    989       1.1    jruoho     Status = AcpiDsCreateOperand (WalkState, Op, 0);
    990       1.1    jruoho     if (ACPI_FAILURE (Status))
    991       1.1    jruoho     {
    992       1.1    jruoho         goto Exit;
    993       1.1    jruoho     }
    994       1.1    jruoho 
    995       1.1    jruoho     if (Op->Common.Flags & ACPI_PARSEOP_TARGET)
    996       1.1    jruoho     {
    997       1.1    jruoho         NewObjDesc = *Operand;
    998       1.1    jruoho         goto PushResult;
    999       1.1    jruoho     }
   1000       1.1    jruoho 
   1001       1.1    jruoho     Type = (*Operand)->Common.Type;
   1002       1.1    jruoho 
   1003       1.1    jruoho     Status = AcpiExResolveToValue (Operand, WalkState);
   1004       1.1    jruoho     if (ACPI_FAILURE (Status))
   1005       1.1    jruoho     {
   1006       1.1    jruoho         goto Exit;
   1007       1.1    jruoho     }
   1008       1.1    jruoho 
   1009       1.1    jruoho     if (Type == ACPI_TYPE_INTEGER)
   1010       1.1    jruoho     {
   1011       1.1    jruoho         /* It was incremented by AcpiExResolveToValue */
   1012       1.1    jruoho 
   1013       1.1    jruoho         AcpiUtRemoveReference (*Operand);
   1014       1.1    jruoho 
   1015   1.1.1.7  christos         Status = AcpiUtCopyIobjectToIobject (
   1016   1.1.1.7  christos             *Operand, &NewObjDesc, WalkState);
   1017       1.1    jruoho         if (ACPI_FAILURE (Status))
   1018       1.1    jruoho         {
   1019       1.1    jruoho             goto Exit;
   1020       1.1    jruoho         }
   1021       1.1    jruoho     }
   1022       1.1    jruoho     else
   1023       1.1    jruoho     {
   1024       1.1    jruoho         /*
   1025       1.1    jruoho          * The object either was anew created or is
   1026       1.1    jruoho          * a Namespace node - don't decrement it.
   1027       1.1    jruoho          */
   1028       1.1    jruoho         NewObjDesc = *Operand;
   1029       1.1    jruoho     }
   1030       1.1    jruoho 
   1031       1.1    jruoho     /* Cleanup for name-path operand */
   1032       1.1    jruoho 
   1033       1.1    jruoho     Status = AcpiDsObjStackPop (1, WalkState);
   1034       1.1    jruoho     if (ACPI_FAILURE (Status))
   1035       1.1    jruoho     {
   1036       1.1    jruoho         WalkState->ResultObj = NewObjDesc;
   1037       1.1    jruoho         goto Exit;
   1038       1.1    jruoho     }
   1039       1.1    jruoho 
   1040       1.1    jruoho PushResult:
   1041       1.1    jruoho 
   1042       1.1    jruoho     WalkState->ResultObj = NewObjDesc;
   1043       1.1    jruoho 
   1044       1.1    jruoho     Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
   1045       1.1    jruoho     if (ACPI_SUCCESS (Status))
   1046       1.1    jruoho     {
   1047       1.1    jruoho         /* Force to take it from stack */
   1048       1.1    jruoho 
   1049       1.1    jruoho         Op->Common.Flags |= ACPI_PARSEOP_IN_STACK;
   1050       1.1    jruoho     }
   1051       1.1    jruoho 
   1052       1.1    jruoho Exit:
   1053       1.1    jruoho 
   1054       1.1    jruoho     return_ACPI_STATUS (Status);
   1055       1.1    jruoho }
   1056