exresop.c revision 114237
11556Srgrimes
21556Srgrimes/******************************************************************************
31556Srgrimes *
41556Srgrimes * Module Name: exresop - AML Interpreter operand/object resolution
51556Srgrimes *              $Revision: 62 $
61556Srgrimes *
71556Srgrimes *****************************************************************************/
81556Srgrimes
91556Srgrimes/******************************************************************************
101556Srgrimes *
111556Srgrimes * 1. Copyright Notice
121556Srgrimes *
131556Srgrimes * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
141556Srgrimes * All rights reserved.
151556Srgrimes *
161556Srgrimes * 2. License
171556Srgrimes *
181556Srgrimes * 2.1. This is your license from Intel Corp. under its intellectual property
191556Srgrimes * rights.  You may have additional license terms from the party that provided
201556Srgrimes * you this software, covering your right to use that party's intellectual
211556Srgrimes * property rights.
221556Srgrimes *
231556Srgrimes * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
241556Srgrimes * copy of the source code appearing in this file ("Covered Code") an
251556Srgrimes * irrevocable, perpetual, worldwide license under Intel's copyrights in the
261556Srgrimes * base code distributed originally by Intel ("Original Intel Code") to copy,
271556Srgrimes * make derivatives, distribute, use and display any portion of the Covered
281556Srgrimes * Code in any form, with the right to sublicense such rights; and
291556Srgrimes *
301556Srgrimes * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
311556Srgrimes * license (with the right to sublicense), under only those claims of Intel
321556Srgrimes * patents that are infringed by the Original Intel Code, to make, use, sell,
331556Srgrimes * offer to sell, and import the Covered Code and derivative works thereof
341556Srgrimes * solely to the minimum extent necessary to exercise the above copyright
351556Srgrimes * license, and in no event shall the patent license extend to any additions
361556Srgrimes * to or modifications of the Original Intel Code.  No other license or right
371556Srgrimes * is granted directly or by implication, estoppel or otherwise;
3827967Ssteve *
3927967Ssteve * The above copyright and patent license is granted only if the following
4027967Ssteve * conditions are met:
4127958Ssteve *
4250471Speter * 3. Conditions
4327967Ssteve *
441556Srgrimes * 3.1. Redistribution of Source with Rights to Further Distribute Source.
451556Srgrimes * Redistribution of source code of any substantial portion of the Covered
461556Srgrimes * Code or modification with rights to further distribute source must include
471556Srgrimes * the above Copyright Notice, the above License, this list of Conditions,
481556Srgrimes * and the following Disclaimer and Export Compliance provision.  In addition,
491556Srgrimes * Licensee must cause all Covered Code to which Licensee contributes to
501556Srgrimes * contain a file documenting the changes Licensee made to create that Covered
511556Srgrimes * Code and the date of any change.  Licensee must include in that file the
521556Srgrimes * documentation of any changes made by any predecessor Licensee.  Licensee
531556Srgrimes * must include a prominent statement that the modification is derived,
541556Srgrimes * directly or indirectly, from Original Intel Code.
551556Srgrimes *
561556Srgrimes * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
571556Srgrimes * Redistribution of source code of any substantial portion of the Covered
581556Srgrimes * Code or modification without rights to further distribute source must
5961294Sache * include the following Disclaimer and Export Compliance provision in the
6061294Sache * documentation and/or other materials provided with distribution.  In
6161294Sache * addition, Licensee may not authorize further sublicense of source of any
6261294Sache * portion of the Covered Code, and must include terms to the effect that the
6361294Sache * license from Licensee to its licensee is limited to the intellectual
6461294Sache * property embodied in the software Licensee provides to its licensee, and
651556Srgrimes * not to intellectual property embodied in modifications its licensee may
661556Srgrimes * make.
671556Srgrimes *
681556Srgrimes * 3.3. Redistribution of Executable. Redistribution in executable form of any
691556Srgrimes * substantial portion of the Covered Code or modification must reproduce the
701556Srgrimes * above Copyright Notice, and the following Disclaimer and Export Compliance
711556Srgrimes * provision in the documentation and/or other materials provided with the
721556Srgrimes * distribution.
731556Srgrimes *
741556Srgrimes * 3.4. Intel retains all right, title, and interest in and to the Original
751556Srgrimes * Intel Code.
7661268Sjoe *
7761178Sjoe * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7861178Sjoe * Intel shall be used in advertising or otherwise to promote the sale, use or
7961178Sjoe * other dealings in products derived from or relating to the Covered Code
8061178Sjoe * without prior written authorization from Intel.
8161178Sjoe *
8261178Sjoe * 4. Disclaimer and Export Compliance
8361178Sjoe *
8461178Sjoe * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8561178Sjoe * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8661178Sjoe * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8761178Sjoe * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8861178Sjoe * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8961178Sjoe * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9061178Sjoe * PARTICULAR PURPOSE.
9161178Sjoe *
9261178Sjoe * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9361178Sjoe * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9461178Sjoe * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9561178Sjoe * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9661268Sjoe * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9761178Sjoe * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
981556Srgrimes * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
991556Srgrimes * LIMITED REMEDY.
1001556Srgrimes *
1011556Srgrimes * 4.3. Licensee shall not export, either directly or indirectly, any of this
1021556Srgrimes * software or system incorporating such software without first obtaining any
1031556Srgrimes * required license or other approval from the U. S. Department of Commerce or
1041556Srgrimes * any other agency or department of the United States Government.  In the
1051556Srgrimes * event Licensee exports any such software from the United States or
1061556Srgrimes * re-exports any such software from a foreign destination, Licensee shall
1071556Srgrimes * ensure that the distribution and export/re-export of the software is in
1081556Srgrimes * compliance with all laws, regulations, orders, or other restrictions of the
1091556Srgrimes * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1101556Srgrimes * any of its subsidiaries will export/re-export any technical data, process,
1111556Srgrimes * software, or service, directly or indirectly, to any country for which the
1121556Srgrimes * United States government or any agency thereof requires an export license,
1131556Srgrimes * other governmental approval, or letter of assurance, without first obtaining
1141556Srgrimes * such license, approval or letter.
1151556Srgrimes *
1161556Srgrimes *****************************************************************************/
1171556Srgrimes
1181556Srgrimes#define __EXRESOP_C__
1191556Srgrimes
12061292Sache#include "acpi.h"
12161292Sache#include "amlcode.h"
12261292Sache#include "acparser.h"
1231556Srgrimes#include "acinterp.h"
1241556Srgrimes
1251556Srgrimes
1261556Srgrimes#define _COMPONENT          ACPI_EXECUTER
1271556Srgrimes        ACPI_MODULE_NAME    ("exresop")
1281556Srgrimes
1291556Srgrimes
1301556Srgrimes/*******************************************************************************
1311556Srgrimes *
13220417Ssteve * FUNCTION:    AcpiExCheckObjectType
1331556Srgrimes *
1341556Srgrimes * PARAMETERS:  TypeNeeded          Object type needed
1351556Srgrimes *              ThisType            Actual object type
1361556Srgrimes *              Object              Object pointer
1371556Srgrimes *
1381556Srgrimes * RETURN:      Status
1391556Srgrimes *
1401556Srgrimes * DESCRIPTION: Check required type against actual type
1411556Srgrimes *
1421556Srgrimes ******************************************************************************/
1431556Srgrimes
14455514SbdeACPI_STATUS
14513120SjoergAcpiExCheckObjectType (
14655514Sbde    ACPI_OBJECT_TYPE        TypeNeeded,
14755514Sbde    ACPI_OBJECT_TYPE        ThisType,
14813120Sjoerg    void                    *Object)
14913120Sjoerg{
15013120Sjoerg    ACPI_FUNCTION_NAME ("ExCheckObjectType");
1511556Srgrimes
1521556Srgrimes
1531556Srgrimes    if (TypeNeeded == ACPI_TYPE_ANY)
1541556Srgrimes    {
1551556Srgrimes        /* All types OK, so we don't perform any typechecks */
1561556Srgrimes
1571556Srgrimes        return (AE_OK);
1581556Srgrimes    }
1591556Srgrimes
1601556Srgrimes    if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
1611556Srgrimes    {
16261268Sjoe        /*
16361178Sjoe         * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
16461291Sache         * objects and thus allow them to be targets.  (As per the ACPI
16561268Sjoe         * specification, a store to a constant is a noop.)
16635417Sdes         */
16735373Sdes        if ((ThisType == ACPI_TYPE_INTEGER) &&
16861268Sjoe            (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags & AOPOBJ_AML_CONSTANT))
16961291Sache        {
17061268Sjoe            return (AE_OK);
17161268Sjoe        }
1721556Srgrimes    }
1731556Srgrimes
1741556Srgrimes    if (TypeNeeded != ThisType)
1751556Srgrimes    {
1761556Srgrimes        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1771556Srgrimes            "Needed [%s], found [%s] %p\n",
1781556Srgrimes            AcpiUtGetTypeName (TypeNeeded),
1791556Srgrimes            AcpiUtGetTypeName (ThisType), Object));
1801556Srgrimes
1811556Srgrimes        return (AE_AML_OPERAND_TYPE);
1821556Srgrimes    }
1831556Srgrimes
1841556Srgrimes    return (AE_OK);
1851556Srgrimes}
1861556Srgrimes
1871556Srgrimes
1881556Srgrimes/*******************************************************************************
1891556Srgrimes *
19037932Shoek * FUNCTION:    AcpiExResolveOperands
1911556Srgrimes *
19237932Shoek * PARAMETERS:  Opcode              - Opcode being interpreted
19337932Shoek *              StackPtr            - Pointer to the operand stack to be
19437932Shoek *                                    resolved
19537932Shoek *              WalkState           - Current state
19637932Shoek *
1971556Srgrimes * RETURN:      Status
1981556Srgrimes *
1991556Srgrimes * DESCRIPTION: Convert multiple input operands to the types required by the
2001556Srgrimes *              target operator.
2011556Srgrimes *
2021556Srgrimes *      Each 5-bit group in ArgTypes represents one required
2031556Srgrimes *      operand and indicates the required Type. The corresponding operand
2041556Srgrimes *      will be converted to the required type if possible, otherwise we
2051556Srgrimes *      abort with an exception.
2061556Srgrimes *
2071556Srgrimes ******************************************************************************/
2081556Srgrimes
2091556SrgrimesACPI_STATUS
2101556SrgrimesAcpiExResolveOperands (
2111556Srgrimes    UINT16                  Opcode,
2121556Srgrimes    ACPI_OPERAND_OBJECT     **StackPtr,
2131556Srgrimes    ACPI_WALK_STATE         *WalkState)
2141556Srgrimes{
2151556Srgrimes    ACPI_OPERAND_OBJECT     *ObjDesc;
2161556Srgrimes    ACPI_STATUS             Status = AE_OK;
2171556Srgrimes    UINT8                   ObjectType;
2181556Srgrimes    void                    *TempNode;
2191556Srgrimes    UINT32                  ArgTypes;
2201556Srgrimes    const ACPI_OPCODE_INFO  *OpInfo;
22137932Shoek    UINT32                  ThisArgType;
2221556Srgrimes    ACPI_OBJECT_TYPE        TypeNeeded;
2231556Srgrimes
2241556Srgrimes
2251556Srgrimes    ACPI_FUNCTION_TRACE_U32 ("ExResolveOperands", Opcode);
2261556Srgrimes
2271556Srgrimes
2281556Srgrimes    OpInfo = AcpiPsGetOpcodeInfo (Opcode);
2291556Srgrimes    if (OpInfo->Class == AML_CLASS_UNKNOWN)
2301556Srgrimes    {
2311556Srgrimes        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
2321556Srgrimes    }
2331556Srgrimes
2341556Srgrimes    ArgTypes = OpInfo->RuntimeArgs;
2351556Srgrimes    if (ArgTypes == ARGI_INVALID_OPCODE)
2361556Srgrimes    {
2371556Srgrimes        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - %X is not a valid AML opcode\n",
2381556Srgrimes            Opcode));
2391556Srgrimes
2401556Srgrimes        return_ACPI_STATUS (AE_AML_INTERNAL);
24161268Sjoe    }
24261178Sjoe
24361178Sjoe    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] OperandTypes=%X \n",
24461178Sjoe        Opcode, OpInfo->Name, ArgTypes));
24561178Sjoe
24661178Sjoe    /*
24761178Sjoe     * Normal exit is with (ArgTypes == 0) at end of argument list.
24861178Sjoe     * Function will return an exception from within the loop upon
24961178Sjoe     * finding an entry which is not (or cannot be converted
25061178Sjoe     * to) the required type; if stack underflows; or upon
25161178Sjoe     * finding a NULL stack entry (which should not happen).
25261268Sjoe     */
25337932Shoek    while (GET_CURRENT_ARG_TYPE (ArgTypes))
25437932Shoek    {
25537932Shoek        if (!StackPtr || !*StackPtr)
2561556Srgrimes        {
2571556Srgrimes            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - null stack entry at %p\n",
2581556Srgrimes                StackPtr));
2591556Srgrimes
2601556Srgrimes            return_ACPI_STATUS (AE_AML_INTERNAL);
2611556Srgrimes        }
2621556Srgrimes
2631556Srgrimes        /* Extract useful items */
2641556Srgrimes
2651556Srgrimes        ObjDesc = *StackPtr;
2661556Srgrimes
2671556Srgrimes        /* Decode the descriptor type */
2681556Srgrimes
2691556Srgrimes        switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
2701556Srgrimes        {
2711556Srgrimes        case ACPI_DESC_TYPE_NAMED:
2721556Srgrimes
2731556Srgrimes            /* Node */
2741556Srgrimes
27561292Sache            ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
27661292Sache            break;
27761292Sache
2781556Srgrimes
2791556Srgrimes        case ACPI_DESC_TYPE_OPERAND:
2801556Srgrimes
2811556Srgrimes            /* ACPI internal object */
28220417Ssteve
2831556Srgrimes            ObjectType = ACPI_GET_OBJECT_TYPE (ObjDesc);
2841556Srgrimes
2851556Srgrimes            /* Check for bad ACPI_OBJECT_TYPE */
28661268Sjoe
28761178Sjoe            if (!AcpiUtValidObjectType (ObjectType))
28861291Sache            {
28961268Sjoe                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad operand object type [%X]\n",
29035417Sdes                    ObjectType));
29135417Sdes
29261268Sjoe                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
29361291Sache            }
29461268Sjoe
29561268Sjoe            if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
2961556Srgrimes            {
2971556Srgrimes                /*
2981556Srgrimes                 * Decode the Reference
2991556Srgrimes                 */
3001556Srgrimes                OpInfo = AcpiPsGetOpcodeInfo (Opcode);
3011556Srgrimes                if (OpInfo->Class == AML_CLASS_UNKNOWN)
3021556Srgrimes                {
3031556Srgrimes                    return_ACPI_STATUS (AE_AML_BAD_OPCODE);
3041556Srgrimes                }
3051556Srgrimes
3069991Sache                switch (ObjDesc->Reference.Opcode)
30721545Smpp                {
3081556Srgrimes                case AML_DEBUG_OP:
30921545Smpp                case AML_NAME_OP:
31021545Smpp                case AML_INDEX_OP:
31121545Smpp                case AML_REF_OF_OP:
3129991Sache                case AML_ARG_OP:
3131556Srgrimes                case AML_LOCAL_OP:
3141556Srgrimes
3151556Srgrimes                    ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
3169987Swollman                        "Reference Opcode: %s\n", OpInfo->Name)));
3171556Srgrimes                    break;
3181556Srgrimes
3191556Srgrimes                default:
32021545Smpp                    ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
3211556Srgrimes                        "Unknown Reference Opcode %X\n",
3221556Srgrimes                        ObjDesc->Reference.Opcode));
3231556Srgrimes
3241556Srgrimes                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
3251556Srgrimes                }
3261556Srgrimes            }
3271556Srgrimes            break;
3281556Srgrimes
3291556Srgrimes
3301556Srgrimes        default:
3311556Srgrimes
3321556Srgrimes            /* Invalid descriptor */
3331556Srgrimes
3341556Srgrimes            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
3351556Srgrimes                "Bad descriptor type %X in Obj %p\n",
3361556Srgrimes                ACPI_GET_DESCRIPTOR_TYPE (ObjDesc), ObjDesc));
3371556Srgrimes
3381556Srgrimes            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
3391556Srgrimes        }
3401556Srgrimes
3411556Srgrimes
3421556Srgrimes        /*
3431556Srgrimes         * Get one argument type, point to the next
3441556Srgrimes         */
3451556Srgrimes        ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
3461556Srgrimes        INCREMENT_ARG_LIST (ArgTypes);
3471556Srgrimes
34820417Ssteve        /*
34920417Ssteve         * Handle cases where the object does not need to be
35020417Ssteve         * resolved to a value
3511556Srgrimes         */
3521556Srgrimes        switch (ThisArgType)
3531556Srgrimes        {
3541556Srgrimes        case ARGI_REF_OR_STRING:        /* Can be a String or Reference */
3551556Srgrimes
3561556Srgrimes            if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
3571556Srgrimes                (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_STRING))
3581556Srgrimes            {
35961268Sjoe                /*
36061291Sache                 * String found - the string references a named object and must be
36161291Sache                 * resolved to a node
36261291Sache                 */
36361291Sache                goto NextOperand;
36461291Sache            }
36561291Sache
36661291Sache            /* Else not a string - fall through to the normal Reference case below */
36761178Sjoe            /*lint -fallthrough */
36861178Sjoe
36961178Sjoe        case ARGI_REFERENCE:            /* References: */
37061178Sjoe        case ARGI_INTEGER_REF:
37161268Sjoe        case ARGI_OBJECT_REF:
37261268Sjoe        case ARGI_DEVICE_REF:
37361178Sjoe        case ARGI_TARGETREF:            /* Allows implicit conversion rules before store */
37461271Sjoe        case ARGI_FIXED_TARGET:         /* No implicit conversion before store to target */
37561268Sjoe        case ARGI_SIMPLE_TARGET:        /* Name, Local, or Arg - no implicit conversion  */
37661291Sache
37761178Sjoe            /* Need an operand of type ACPI_TYPE_LOCAL_REFERENCE */
37861268Sjoe
37961268Sjoe            if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED) /* Node (name) ptr OK as-is */
38061271Sjoe            {
38161268Sjoe                goto NextOperand;
38261291Sache            }
38361268Sjoe
38461178Sjoe            Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE,
38561178Sjoe                            ObjectType, ObjDesc);
38661268Sjoe            if (ACPI_FAILURE (Status))
38761268Sjoe            {
38861268Sjoe                return_ACPI_STATUS (Status);
38961291Sache            }
39061268Sjoe
39161268Sjoe            if (AML_NAME_OP == ObjDesc->Reference.Opcode)
39261178Sjoe            {
39361178Sjoe                /*
39461178Sjoe                 * Convert an indirect name ptr to direct name ptr and put
39561178Sjoe                 * it on the stack
39661178Sjoe                 */
39761178Sjoe                TempNode = ObjDesc->Reference.Object;
39861178Sjoe                AcpiUtRemoveReference (ObjDesc);
39961178Sjoe                (*StackPtr) = TempNode;
40061178Sjoe            }
40161178Sjoe            goto NextOperand;
40261178Sjoe
40361178Sjoe
40461178Sjoe        case ARGI_ANYTYPE:
40561178Sjoe
40661178Sjoe            /*
40761178Sjoe             * We don't want to resolve IndexOp reference objects during
40861178Sjoe             * a store because this would be an implicit DeRefOf operation.
40961178Sjoe             * Instead, we just want to store the reference object.
41061178Sjoe             * -- All others must be resolved below.
41161178Sjoe             */
41261178Sjoe            if ((Opcode == AML_STORE_OP) &&
41361178Sjoe                (ACPI_GET_OBJECT_TYPE (*StackPtr) == ACPI_TYPE_LOCAL_REFERENCE) &&
41461178Sjoe                ((*StackPtr)->Reference.Opcode == AML_INDEX_OP))
41561178Sjoe            {
41661178Sjoe                goto NextOperand;
41761178Sjoe            }
41861178Sjoe            break;
41961178Sjoe
42061178Sjoe        default:
42161178Sjoe            /* All cases covered above */
42261178Sjoe            break;
42361178Sjoe        }
42461178Sjoe
42561178Sjoe
42661178Sjoe        /*
42761178Sjoe         * Resolve this object to a value
42861178Sjoe         */
42961178Sjoe        Status = AcpiExResolveToValue (StackPtr, WalkState);
43061178Sjoe        if (ACPI_FAILURE (Status))
43161178Sjoe        {
43261178Sjoe            return_ACPI_STATUS (Status);
43361178Sjoe        }
43461178Sjoe
43561178Sjoe        /* Get the resolved object */
43661178Sjoe
43761178Sjoe        ObjDesc = *StackPtr;
43861178Sjoe
43961178Sjoe        /*
44061178Sjoe         * Check the resulting object (value) type
44161178Sjoe         */
44261178Sjoe        switch (ThisArgType)
44361178Sjoe        {
44461178Sjoe        /*
44561178Sjoe         * For the simple cases, only one type of resolved object
44661178Sjoe         * is allowed
44761178Sjoe         */
44861178Sjoe        case ARGI_MUTEX:
44961178Sjoe
45061178Sjoe            /* Need an operand of type ACPI_TYPE_MUTEX */
45161178Sjoe
45261178Sjoe            TypeNeeded = ACPI_TYPE_MUTEX;
45361291Sache            break;
45461178Sjoe
45561178Sjoe        case ARGI_EVENT:
45661178Sjoe
45761178Sjoe            /* Need an operand of type ACPI_TYPE_EVENT */
45861178Sjoe
45961178Sjoe            TypeNeeded = ACPI_TYPE_EVENT;
46061178Sjoe            break;
46161178Sjoe
46261178Sjoe        case ARGI_PACKAGE:   /* Package */
46361178Sjoe
46461178Sjoe            /* Need an operand of type ACPI_TYPE_PACKAGE */
46561178Sjoe
46661291Sache            TypeNeeded = ACPI_TYPE_PACKAGE;
46761291Sache            break;
46861291Sache
46961291Sache        case ARGI_ANYTYPE:
47061291Sache
47161294Sache            /* Any operand type will do */
47261294Sache
47361294Sache            TypeNeeded = ACPI_TYPE_ANY;
47461294Sache            break;
47561291Sache
47661268Sjoe
47761178Sjoe        /*
4781556Srgrimes         * The more complex cases allow multiple resolved object types
4791556Srgrimes         */
4801556Srgrimes        case ARGI_INTEGER:   /* Number */
4811556Srgrimes
4821556Srgrimes            /*
4831556Srgrimes             * Need an operand of type ACPI_TYPE_INTEGER,
4841556Srgrimes             * But we can implicitly convert from a STRING or BUFFER
4851556Srgrimes             * Aka - "Implicit Source Operand Conversion"
4861556Srgrimes             */
4878855Srgrimes            Status = AcpiExConvertToInteger (ObjDesc, StackPtr, WalkState);
4881556Srgrimes            if (ACPI_FAILURE (Status))
4891556Srgrimes            {
4901556Srgrimes                if (Status == AE_TYPE)
4911556Srgrimes                {
4921556Srgrimes                    ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
4931556Srgrimes                        "Needed [Integer/String/Buffer], found [%s] %p\n",
4941556Srgrimes                        AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
49535417Sdes
49635417Sdes                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
49735417Sdes                }
49835373Sdes
49935373Sdes                return_ACPI_STATUS (Status);
5001556Srgrimes            }
501            goto NextOperand;
502
503
504        case ARGI_BUFFER:
505
506            /*
507             * Need an operand of type ACPI_TYPE_BUFFER,
508             * But we can implicitly convert from a STRING or INTEGER
509             * Aka - "Implicit Source Operand Conversion"
510             */
511            Status = AcpiExConvertToBuffer (ObjDesc, StackPtr, WalkState);
512            if (ACPI_FAILURE (Status))
513            {
514                if (Status == AE_TYPE)
515                {
516                    ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
517                        "Needed [Integer/String/Buffer], found [%s] %p\n",
518                        AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
519
520                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
521                }
522
523                return_ACPI_STATUS (Status);
524            }
525            goto NextOperand;
526
527
528        case ARGI_STRING:
529
530            /*
531             * Need an operand of type ACPI_TYPE_STRING,
532             * But we can implicitly convert from a BUFFER or INTEGER
533             * Aka - "Implicit Source Operand Conversion"
534             */
535            Status = AcpiExConvertToString (ObjDesc, StackPtr, 16, ACPI_UINT32_MAX, WalkState);
536            if (ACPI_FAILURE (Status))
537            {
538                if (Status == AE_TYPE)
539                {
540                    ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
541                        "Needed [Integer/String/Buffer], found [%s] %p\n",
542                        AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
543
544                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
545                }
546
547                return_ACPI_STATUS (Status);
548            }
549            goto NextOperand;
550
551
552        case ARGI_COMPUTEDATA:
553
554            /* Need an operand of type INTEGER, STRING or BUFFER */
555
556            switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
557            {
558            case ACPI_TYPE_INTEGER:
559            case ACPI_TYPE_STRING:
560            case ACPI_TYPE_BUFFER:
561
562                /* Valid operand */
563               break;
564
565            default:
566                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
567                    "Needed [Integer/String/Buffer], found [%s] %p\n",
568                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
569
570                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
571            }
572            goto NextOperand;
573
574
575        case ARGI_BUFFER_OR_STRING:
576
577            /* Need an operand of type STRING or BUFFER */
578
579            switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
580            {
581            case ACPI_TYPE_STRING:
582            case ACPI_TYPE_BUFFER:
583
584                /* Valid operand */
585               break;
586
587            case ACPI_TYPE_INTEGER:
588
589                /* Highest priority conversion is to type Buffer */
590
591                Status = AcpiExConvertToBuffer (ObjDesc, StackPtr, WalkState);
592                if (ACPI_FAILURE (Status))
593                {
594                    return_ACPI_STATUS (Status);
595                }
596                break;
597
598            default:
599                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
600                    "Needed [Integer/String/Buffer], found [%s] %p\n",
601                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
602
603                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
604            }
605            goto NextOperand;
606
607
608        case ARGI_DATAOBJECT:
609            /*
610             * ARGI_DATAOBJECT is only used by the SizeOf operator.
611             * Need a buffer, string, package, or RefOf reference.
612             *
613             * The only reference allowed here is a direct reference to
614             * a namespace node.
615             */
616            switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
617            {
618            case ACPI_TYPE_PACKAGE:
619            case ACPI_TYPE_STRING:
620            case ACPI_TYPE_BUFFER:
621            case ACPI_TYPE_LOCAL_REFERENCE:
622
623                /* Valid operand */
624                break;
625
626            default:
627                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
628                    "Needed [Buffer/String/Package/Reference], found [%s] %p\n",
629                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
630
631                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
632            }
633            goto NextOperand;
634
635
636        case ARGI_COMPLEXOBJ:
637
638            /* Need a buffer or package or (ACPI 2.0) String */
639
640            switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
641            {
642            case ACPI_TYPE_PACKAGE:
643            case ACPI_TYPE_STRING:
644            case ACPI_TYPE_BUFFER:
645
646                /* Valid operand */
647                break;
648
649            default:
650                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
651                    "Needed [Buffer/String/Package], found [%s] %p\n",
652                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
653
654                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
655            }
656            goto NextOperand;
657
658
659        case ARGI_REGION_OR_FIELD:
660
661            /* Need an operand of type ACPI_TYPE_REGION or a FIELD in a region */
662
663            switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
664            {
665            case ACPI_TYPE_REGION:
666            case ACPI_TYPE_LOCAL_REGION_FIELD:
667            case ACPI_TYPE_LOCAL_BANK_FIELD:
668            case ACPI_TYPE_LOCAL_INDEX_FIELD:
669
670                /* Valid operand */
671                break;
672
673            default:
674                ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
675                    "Needed [Region/RegionField], found [%s] %p\n",
676                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
677
678                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
679            }
680            goto NextOperand;
681
682
683        default:
684
685            /* Unknown type */
686
687            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
688                "Internal - Unknown ARGI (required operand) type %X\n",
689                ThisArgType));
690
691            return_ACPI_STATUS (AE_BAD_PARAMETER);
692        }
693
694        /*
695         * Make sure that the original object was resolved to the
696         * required object type (Simple cases only).
697         */
698        Status = AcpiExCheckObjectType (TypeNeeded,
699                        ACPI_GET_OBJECT_TYPE (*StackPtr), *StackPtr);
700        if (ACPI_FAILURE (Status))
701        {
702            return_ACPI_STATUS (Status);
703        }
704
705NextOperand:
706        /*
707         * If more operands needed, decrement StackPtr to point
708         * to next operand on stack
709         */
710        if (GET_CURRENT_ARG_TYPE (ArgTypes))
711        {
712            StackPtr--;
713        }
714
715    }   /* while (*Types) */
716
717    return_ACPI_STATUS (Status);
718}
719
720
721