167754Smsmith/******************************************************************************
267754Smsmith *
377424Smsmith * Module Name: exresop - AML Interpreter operand/object resolution
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7217365Sjkim/*
8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp.
970243Smsmith * All rights reserved.
1067754Smsmith *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
2567754Smsmith *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
2967754Smsmith *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
4367754Smsmith
44193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
45193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
46193341Sjkim#include <contrib/dev/acpica/include/amlcode.h>
47193341Sjkim#include <contrib/dev/acpica/include/acparser.h>
48193341Sjkim#include <contrib/dev/acpica/include/acinterp.h>
49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
5067754Smsmith
5167754Smsmith
5277424Smsmith#define _COMPONENT          ACPI_EXECUTER
5391116Smsmith        ACPI_MODULE_NAME    ("exresop")
5467754Smsmith
55151937Sjkim/* Local prototypes */
5667754Smsmith
57151937Sjkimstatic ACPI_STATUS
58151937SjkimAcpiExCheckObjectType (
59151937Sjkim    ACPI_OBJECT_TYPE        TypeNeeded,
60151937Sjkim    ACPI_OBJECT_TYPE        ThisType,
61151937Sjkim    void                    *Object);
62151937Sjkim
63151937Sjkim
6467754Smsmith/*******************************************************************************
6567754Smsmith *
6677424Smsmith * FUNCTION:    AcpiExCheckObjectType
6769746Smsmith *
6869746Smsmith * PARAMETERS:  TypeNeeded          Object type needed
6969746Smsmith *              ThisType            Actual object type
7069746Smsmith *              Object              Object pointer
7169746Smsmith *
7269746Smsmith * RETURN:      Status
7369746Smsmith *
7469746Smsmith * DESCRIPTION: Check required type against actual type
7569746Smsmith *
7669746Smsmith ******************************************************************************/
7769746Smsmith
78151937Sjkimstatic ACPI_STATUS
7977424SmsmithAcpiExCheckObjectType (
8069746Smsmith    ACPI_OBJECT_TYPE        TypeNeeded,
8169746Smsmith    ACPI_OBJECT_TYPE        ThisType,
8269746Smsmith    void                    *Object)
8369746Smsmith{
84167802Sjkim    ACPI_FUNCTION_ENTRY ();
8569746Smsmith
8683174Smsmith
8769746Smsmith    if (TypeNeeded == ACPI_TYPE_ANY)
8869746Smsmith    {
8969746Smsmith        /* All types OK, so we don't perform any typechecks */
9069746Smsmith
9169746Smsmith        return (AE_OK);
9269746Smsmith    }
9369746Smsmith
94107325Siwasaki    if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
9599679Siwasaki    {
9699679Siwasaki        /*
9799679Siwasaki         * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
98241973Sjkim         * objects and thus allow them to be targets. (As per the ACPI
9999679Siwasaki         * specification, a store to a constant is a noop.)
10099679Siwasaki         */
10199679Siwasaki        if ((ThisType == ACPI_TYPE_INTEGER) &&
102306536Sjkim            (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags &
103306536Sjkim                AOPOBJ_AML_CONSTANT))
10499679Siwasaki        {
10599679Siwasaki            return (AE_OK);
10699679Siwasaki        }
10799679Siwasaki    }
10899679Siwasaki
10969746Smsmith    if (TypeNeeded != ThisType)
11069746Smsmith    {
111167802Sjkim        ACPI_ERROR ((AE_INFO,
112167802Sjkim            "Needed type [%s], found [%s] %p",
11377424Smsmith            AcpiUtGetTypeName (TypeNeeded),
11477424Smsmith            AcpiUtGetTypeName (ThisType), Object));
11569746Smsmith
11669746Smsmith        return (AE_AML_OPERAND_TYPE);
11769746Smsmith    }
11869746Smsmith
11969746Smsmith    return (AE_OK);
12069746Smsmith}
12169746Smsmith
12269746Smsmith
12369746Smsmith/*******************************************************************************
12469746Smsmith *
12577424Smsmith * FUNCTION:    AcpiExResolveOperands
12667754Smsmith *
12791116Smsmith * PARAMETERS:  Opcode              - Opcode being interpreted
12891116Smsmith *              StackPtr            - Pointer to the operand stack to be
12991116Smsmith *                                    resolved
13099679Siwasaki *              WalkState           - Current state
13167754Smsmith *
13267754Smsmith * RETURN:      Status
13367754Smsmith *
13491116Smsmith * DESCRIPTION: Convert multiple input operands to the types required by the
13591116Smsmith *              target operator.
13667754Smsmith *
13799679Siwasaki *      Each 5-bit group in ArgTypes represents one required
138102550Siwasaki *      operand and indicates the required Type. The corresponding operand
139102550Siwasaki *      will be converted to the required type if possible, otherwise we
14099679Siwasaki *      abort with an exception.
14167754Smsmith *
14267754Smsmith ******************************************************************************/
14367754Smsmith
14467754SmsmithACPI_STATUS
14577424SmsmithAcpiExResolveOperands (
14667754Smsmith    UINT16                  Opcode,
14767754Smsmith    ACPI_OPERAND_OBJECT     **StackPtr,
14867754Smsmith    ACPI_WALK_STATE         *WalkState)
14967754Smsmith{
15067754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
15167754Smsmith    ACPI_STATUS             Status = AE_OK;
15267754Smsmith    UINT8                   ObjectType;
15367754Smsmith    UINT32                  ArgTypes;
15483174Smsmith    const ACPI_OPCODE_INFO  *OpInfo;
15567754Smsmith    UINT32                  ThisArgType;
15669746Smsmith    ACPI_OBJECT_TYPE        TypeNeeded;
157151937Sjkim    UINT16                  TargetOp = 0;
15867754Smsmith
15967754Smsmith
160167802Sjkim    ACPI_FUNCTION_TRACE_U32 (ExResolveOperands, Opcode);
16167754Smsmith
16267754Smsmith
16367754Smsmith    OpInfo = AcpiPsGetOpcodeInfo (Opcode);
16485756Smsmith    if (OpInfo->Class == AML_CLASS_UNKNOWN)
16567754Smsmith    {
16667754Smsmith        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
16767754Smsmith    }
16867754Smsmith
16967754Smsmith    ArgTypes = OpInfo->RuntimeArgs;
17067754Smsmith    if (ArgTypes == ARGI_INVALID_OPCODE)
17167754Smsmith    {
172204773Sjkim        ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
17377424Smsmith            Opcode));
17469746Smsmith
17569746Smsmith        return_ACPI_STATUS (AE_AML_INTERNAL);
17667754Smsmith    }
17767754Smsmith
178151937Sjkim    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
179151937Sjkim        "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
18099146Siwasaki        Opcode, OpInfo->Name, ArgTypes));
18167754Smsmith
18277424Smsmith    /*
18377424Smsmith     * Normal exit is with (ArgTypes == 0) at end of argument list.
18467754Smsmith     * Function will return an exception from within the loop upon
18577424Smsmith     * finding an entry which is not (or cannot be converted
18677424Smsmith     * to) the required type; if stack underflows; or upon
18777424Smsmith     * finding a NULL stack entry (which should not happen).
18867754Smsmith     */
18967754Smsmith    while (GET_CURRENT_ARG_TYPE (ArgTypes))
19067754Smsmith    {
19167754Smsmith        if (!StackPtr || !*StackPtr)
19267754Smsmith        {
193167802Sjkim            ACPI_ERROR ((AE_INFO, "Null stack entry at %p",
19477424Smsmith                StackPtr));
19569746Smsmith
19669746Smsmith            return_ACPI_STATUS (AE_AML_INTERNAL);
19767754Smsmith        }
19867754Smsmith
19967754Smsmith        /* Extract useful items */
20067754Smsmith
20167754Smsmith        ObjDesc = *StackPtr;
20267754Smsmith
20367754Smsmith        /* Decode the descriptor type */
20467754Smsmith
20591116Smsmith        switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
20667754Smsmith        {
20791116Smsmith        case ACPI_DESC_TYPE_NAMED:
20891116Smsmith
209151937Sjkim            /* Namespace Node */
21067754Smsmith
21167754Smsmith            ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
212167802Sjkim
213167802Sjkim            /*
214167802Sjkim             * Resolve an alias object. The construction of these objects
215167802Sjkim             * guarantees that there is only one level of alias indirection;
216167802Sjkim             * thus, the attached object is always the aliased namespace node
217167802Sjkim             */
218167802Sjkim            if (ObjectType == ACPI_TYPE_LOCAL_ALIAS)
219167802Sjkim            {
220306536Sjkim                ObjDesc = AcpiNsGetAttachedObject (
221306536Sjkim                    (ACPI_NAMESPACE_NODE *) ObjDesc);
222167802Sjkim                *StackPtr = ObjDesc;
223167802Sjkim                ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
224167802Sjkim            }
22591116Smsmith            break;
22667754Smsmith
22799679Siwasaki        case ACPI_DESC_TYPE_OPERAND:
22891116Smsmith
22967754Smsmith            /* ACPI internal object */
23067754Smsmith
231193267Sjkim            ObjectType = ObjDesc->Common.Type;
23267754Smsmith
23367754Smsmith            /* Check for bad ACPI_OBJECT_TYPE */
23467754Smsmith
235107325Siwasaki            if (!AcpiUtValidObjectType (ObjectType))
23667754Smsmith            {
237167802Sjkim                ACPI_ERROR ((AE_INFO,
238204773Sjkim                    "Bad operand object type [0x%X]", ObjectType));
23969746Smsmith
24069746Smsmith                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
24167754Smsmith            }
24267754Smsmith
243107325Siwasaki            if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
24467754Smsmith            {
245193267Sjkim                /* Validate the Reference */
246151937Sjkim
247193267Sjkim                switch (ObjDesc->Reference.Class)
24867754Smsmith                {
249193267Sjkim                case ACPI_REFCLASS_DEBUG:
25067754Smsmith
251151937Sjkim                    TargetOp = AML_DEBUG_OP;
252151937Sjkim
253151937Sjkim                    /*lint -fallthrough */
254151937Sjkim
255193267Sjkim                case ACPI_REFCLASS_ARG:
256193267Sjkim                case ACPI_REFCLASS_LOCAL:
257193267Sjkim                case ACPI_REFCLASS_INDEX:
258193267Sjkim                case ACPI_REFCLASS_REFOF:
259193267Sjkim                case ACPI_REFCLASS_TABLE:    /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
260193267Sjkim                case ACPI_REFCLASS_NAME:     /* Reference to a named object */
26167754Smsmith
262193267Sjkim                    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
263193267Sjkim                        "Operand is a Reference, Class [%s] %2.2X\n",
264193267Sjkim                        AcpiUtGetReferenceName (ObjDesc),
265193267Sjkim                        ObjDesc->Reference.Class));
26667754Smsmith                    break;
26767754Smsmith
26867754Smsmith                default:
269193267Sjkim
270167802Sjkim                    ACPI_ERROR ((AE_INFO,
271204773Sjkim                        "Unknown Reference Class 0x%2.2X in %p",
272193267Sjkim                        ObjDesc->Reference.Class, ObjDesc));
27367754Smsmith
27469746Smsmith                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
27567754Smsmith                }
27667754Smsmith            }
27791116Smsmith            break;
27867754Smsmith
27991116Smsmith        default:
28091116Smsmith
28167754Smsmith            /* Invalid descriptor */
28267754Smsmith
283193267Sjkim            ACPI_ERROR ((AE_INFO, "Invalid descriptor %p [%s]",
284167802Sjkim                ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
28567754Smsmith
28669746Smsmith            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
28767754Smsmith        }
28867754Smsmith
289151937Sjkim        /* Get one argument type, point to the next */
29067754Smsmith
29167754Smsmith        ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
29267754Smsmith        INCREMENT_ARG_LIST (ArgTypes);
29367754Smsmith
29469746Smsmith        /*
29570243Smsmith         * Handle cases where the object does not need to be
29670243Smsmith         * resolved to a value
29769746Smsmith         */
29867754Smsmith        switch (ThisArgType)
29967754Smsmith        {
30091116Smsmith        case ARGI_REF_OR_STRING:        /* Can be a String or Reference */
30167754Smsmith
302306536Sjkim            if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) ==
303306536Sjkim                ACPI_DESC_TYPE_OPERAND) &&
304193267Sjkim                (ObjDesc->Common.Type == ACPI_TYPE_STRING))
30591116Smsmith            {
30691116Smsmith                /*
307151937Sjkim                 * String found - the string references a named object and
308151937Sjkim                 * must be resolved to a node
30991116Smsmith                 */
31091116Smsmith                goto NextOperand;
31191116Smsmith            }
31291116Smsmith
313151937Sjkim            /*
314151937Sjkim             * Else not a string - fall through to the normal Reference
315151937Sjkim             * case below
316151937Sjkim             */
31799679Siwasaki            /*lint -fallthrough */
31891116Smsmith
31991116Smsmith        case ARGI_REFERENCE:            /* References: */
32071867Smsmith        case ARGI_INTEGER_REF:
32171867Smsmith        case ARGI_OBJECT_REF:
32271867Smsmith        case ARGI_DEVICE_REF:
323151937Sjkim        case ARGI_TARGETREF:     /* Allows implicit conversion rules before store */
324151937Sjkim        case ARGI_FIXED_TARGET:  /* No implicit conversion before store to target */
325151937Sjkim        case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion  */
326306536Sjkim        case ARGI_STORE_TARGET:
327306536Sjkim
328151937Sjkim            /*
329151937Sjkim             * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
330151937Sjkim             * A Namespace Node is OK as-is
331151937Sjkim             */
332151937Sjkim            if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
33367754Smsmith            {
33469746Smsmith                goto NextOperand;
33567754Smsmith            }
33667754Smsmith
337306536Sjkim            Status = AcpiExCheckObjectType (
338306536Sjkim                ACPI_TYPE_LOCAL_REFERENCE, ObjectType, ObjDesc);
33969746Smsmith            if (ACPI_FAILURE (Status))
34067754Smsmith            {
34169746Smsmith                return_ACPI_STATUS (Status);
34267754Smsmith            }
34369746Smsmith            goto NextOperand;
34467754Smsmith
345151937Sjkim        case ARGI_DATAREFOBJ:  /* Store operator only */
34669746Smsmith            /*
34769746Smsmith             * We don't want to resolve IndexOp reference objects during
34869746Smsmith             * a store because this would be an implicit DeRefOf operation.
34969746Smsmith             * Instead, we just want to store the reference object.
35069746Smsmith             * -- All others must be resolved below.
35169746Smsmith             */
35269746Smsmith            if ((Opcode == AML_STORE_OP) &&
353193267Sjkim                ((*StackPtr)->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
354193267Sjkim                ((*StackPtr)->Reference.Class == ACPI_REFCLASS_INDEX))
35567754Smsmith            {
35669746Smsmith                goto NextOperand;
35767754Smsmith            }
35867754Smsmith            break;
35999679Siwasaki
36099679Siwasaki        default:
361250838Sjkim
36299679Siwasaki            /* All cases covered above */
363250838Sjkim
36499679Siwasaki            break;
36569746Smsmith        }
36667754Smsmith
36769746Smsmith        /*
36869746Smsmith         * Resolve this object to a value
36969746Smsmith         */
37077424Smsmith        Status = AcpiExResolveToValue (StackPtr, WalkState);
37169746Smsmith        if (ACPI_FAILURE (Status))
37269746Smsmith        {
37369746Smsmith            return_ACPI_STATUS (Status);
37469746Smsmith        }
37567754Smsmith
376104470Siwasaki        /* Get the resolved object */
377104470Siwasaki
378104470Siwasaki        ObjDesc = *StackPtr;
379104470Siwasaki
38069746Smsmith        /*
38169746Smsmith         * Check the resulting object (value) type
38269746Smsmith         */
38369746Smsmith        switch (ThisArgType)
38469746Smsmith        {
38569746Smsmith        /*
38669746Smsmith         * For the simple cases, only one type of resolved object
38769746Smsmith         * is allowed
38869746Smsmith         */
38967754Smsmith        case ARGI_MUTEX:
39067754Smsmith
39167754Smsmith            /* Need an operand of type ACPI_TYPE_MUTEX */
39267754Smsmith
39369746Smsmith            TypeNeeded = ACPI_TYPE_MUTEX;
39467754Smsmith            break;
39567754Smsmith
39667754Smsmith        case ARGI_EVENT:
39767754Smsmith
39867754Smsmith            /* Need an operand of type ACPI_TYPE_EVENT */
39967754Smsmith
40069746Smsmith            TypeNeeded = ACPI_TYPE_EVENT;
40167754Smsmith            break;
40267754Smsmith
40367754Smsmith        case ARGI_PACKAGE:   /* Package */
40467754Smsmith
40567754Smsmith            /* Need an operand of type ACPI_TYPE_PACKAGE */
40667754Smsmith
40769746Smsmith            TypeNeeded = ACPI_TYPE_PACKAGE;
40869746Smsmith            break;
40967754Smsmith
41069746Smsmith        case ARGI_ANYTYPE:
41169746Smsmith
41269746Smsmith            /* Any operand type will do */
41369746Smsmith
41469746Smsmith            TypeNeeded = ACPI_TYPE_ANY;
41567754Smsmith            break;
41667754Smsmith
417123315Snjl        case ARGI_DDBHANDLE:
41867754Smsmith
419123315Snjl            /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
420123315Snjl
421123315Snjl            TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE;
422123315Snjl            break;
423123315Snjl
424123315Snjl
42569746Smsmith        /*
42669746Smsmith         * The more complex cases allow multiple resolved object types
42769746Smsmith         */
428151937Sjkim        case ARGI_INTEGER:
42971867Smsmith
43071867Smsmith            /*
43171867Smsmith             * Need an operand of type ACPI_TYPE_INTEGER,
43271867Smsmith             * But we can implicitly convert from a STRING or BUFFER
433104470Siwasaki             * Aka - "Implicit Source Operand Conversion"
43471867Smsmith             */
435138287Smarks            Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16);
43671867Smsmith            if (ACPI_FAILURE (Status))
43771867Smsmith            {
43871867Smsmith                if (Status == AE_TYPE)
43971867Smsmith                {
440167802Sjkim                    ACPI_ERROR ((AE_INFO,
441167802Sjkim                        "Needed [Integer/String/Buffer], found [%s] %p",
442104470Siwasaki                        AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
44371867Smsmith
44471867Smsmith                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
44571867Smsmith                }
44671867Smsmith
44771867Smsmith                return_ACPI_STATUS (Status);
44871867Smsmith            }
449151937Sjkim
450151937Sjkim            if (ObjDesc != *StackPtr)
451151937Sjkim            {
452151937Sjkim                AcpiUtRemoveReference (ObjDesc);
453151937Sjkim            }
45471867Smsmith            goto NextOperand;
45571867Smsmith
45671867Smsmith        case ARGI_BUFFER:
45771867Smsmith            /*
45871867Smsmith             * Need an operand of type ACPI_TYPE_BUFFER,
45971867Smsmith             * But we can implicitly convert from a STRING or INTEGER
460104470Siwasaki             * Aka - "Implicit Source Operand Conversion"
46171867Smsmith             */
462138287Smarks            Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
46371867Smsmith            if (ACPI_FAILURE (Status))
46471867Smsmith            {
46571867Smsmith                if (Status == AE_TYPE)
46671867Smsmith                {
467167802Sjkim                    ACPI_ERROR ((AE_INFO,
468167802Sjkim                        "Needed [Integer/String/Buffer], found [%s] %p",
469104470Siwasaki                        AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
47071867Smsmith
47171867Smsmith                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
47271867Smsmith                }
47371867Smsmith
47471867Smsmith                return_ACPI_STATUS (Status);
47571867Smsmith            }
476151937Sjkim
477151937Sjkim            if (ObjDesc != *StackPtr)
478151937Sjkim            {
479151937Sjkim                AcpiUtRemoveReference (ObjDesc);
480151937Sjkim            }
48171867Smsmith            goto NextOperand;
48271867Smsmith
48369746Smsmith        case ARGI_STRING:
48471867Smsmith            /*
48571867Smsmith             * Need an operand of type ACPI_TYPE_STRING,
48671867Smsmith             * But we can implicitly convert from a BUFFER or INTEGER
487104470Siwasaki             * Aka - "Implicit Source Operand Conversion"
48871867Smsmith             */
489306536Sjkim            Status = AcpiExConvertToString (
490306536Sjkim                ObjDesc, StackPtr, ACPI_IMPLICIT_CONVERT_HEX);
49171867Smsmith            if (ACPI_FAILURE (Status))
49271867Smsmith            {
49371867Smsmith                if (Status == AE_TYPE)
49471867Smsmith                {
495167802Sjkim                    ACPI_ERROR ((AE_INFO,
496167802Sjkim                        "Needed [Integer/String/Buffer], found [%s] %p",
497104470Siwasaki                        AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
49867754Smsmith
49971867Smsmith                    return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
50071867Smsmith                }
50171867Smsmith
50271867Smsmith                return_ACPI_STATUS (Status);
50371867Smsmith            }
504151937Sjkim
505151937Sjkim            if (ObjDesc != *StackPtr)
506151937Sjkim            {
507151937Sjkim                AcpiUtRemoveReference (ObjDesc);
508151937Sjkim            }
50971867Smsmith            goto NextOperand;
51071867Smsmith
51171867Smsmith        case ARGI_COMPUTEDATA:
51271867Smsmith
51371867Smsmith            /* Need an operand of type INTEGER, STRING or BUFFER */
51471867Smsmith
515193267Sjkim            switch (ObjDesc->Common.Type)
51667754Smsmith            {
51791116Smsmith            case ACPI_TYPE_INTEGER:
51891116Smsmith            case ACPI_TYPE_STRING:
51991116Smsmith            case ACPI_TYPE_BUFFER:
52091116Smsmith
52191116Smsmith                /* Valid operand */
52291116Smsmith               break;
52391116Smsmith
52491116Smsmith            default:
525167802Sjkim                ACPI_ERROR ((AE_INFO,
526167802Sjkim                    "Needed [Integer/String/Buffer], found [%s] %p",
527104470Siwasaki                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
52867754Smsmith
52969746Smsmith                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
53067754Smsmith            }
53169746Smsmith            goto NextOperand;
53267754Smsmith
533114237Snjl        case ARGI_BUFFER_OR_STRING:
534114237Snjl
535114237Snjl            /* Need an operand of type STRING or BUFFER */
536114237Snjl
537193267Sjkim            switch (ObjDesc->Common.Type)
538114237Snjl            {
539114237Snjl            case ACPI_TYPE_STRING:
540114237Snjl            case ACPI_TYPE_BUFFER:
541114237Snjl
542114237Snjl                /* Valid operand */
543114237Snjl               break;
544114237Snjl
545114237Snjl            case ACPI_TYPE_INTEGER:
546114237Snjl
547114237Snjl                /* Highest priority conversion is to type Buffer */
548114237Snjl
549138287Smarks                Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
550114237Snjl                if (ACPI_FAILURE (Status))
551114237Snjl                {
552114237Snjl                    return_ACPI_STATUS (Status);
553114237Snjl                }
554151937Sjkim
555151937Sjkim                if (ObjDesc != *StackPtr)
556151937Sjkim                {
557151937Sjkim                    AcpiUtRemoveReference (ObjDesc);
558151937Sjkim                }
559114237Snjl                break;
560114237Snjl
561114237Snjl            default:
562167802Sjkim                ACPI_ERROR ((AE_INFO,
563167802Sjkim                    "Needed [Integer/String/Buffer], found [%s] %p",
564114237Snjl                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
565114237Snjl
566114237Snjl                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
567114237Snjl            }
568114237Snjl            goto NextOperand;
569114237Snjl
57067754Smsmith        case ARGI_DATAOBJECT:
57167754Smsmith            /*
57267754Smsmith             * ARGI_DATAOBJECT is only used by the SizeOf operator.
573104470Siwasaki             * Need a buffer, string, package, or RefOf reference.
57467754Smsmith             *
57591116Smsmith             * The only reference allowed here is a direct reference to
57691116Smsmith             * a namespace node.
57767754Smsmith             */
578193267Sjkim            switch (ObjDesc->Common.Type)
57967754Smsmith            {
58091116Smsmith            case ACPI_TYPE_PACKAGE:
58191116Smsmith            case ACPI_TYPE_STRING:
58291116Smsmith            case ACPI_TYPE_BUFFER:
583107325Siwasaki            case ACPI_TYPE_LOCAL_REFERENCE:
58491116Smsmith
58591116Smsmith                /* Valid operand */
58691116Smsmith                break;
58791116Smsmith
58891116Smsmith            default:
589250838Sjkim
590167802Sjkim                ACPI_ERROR ((AE_INFO,
591167802Sjkim                    "Needed [Buffer/String/Package/Reference], found [%s] %p",
592104470Siwasaki                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
59391116Smsmith
59491116Smsmith                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
59591116Smsmith            }
59669746Smsmith            goto NextOperand;
59767754Smsmith
59867754Smsmith        case ARGI_COMPLEXOBJ:
59967754Smsmith
60077424Smsmith            /* Need a buffer or package or (ACPI 2.0) String */
60167754Smsmith
602193267Sjkim            switch (ObjDesc->Common.Type)
60367754Smsmith            {
60491116Smsmith            case ACPI_TYPE_PACKAGE:
60591116Smsmith            case ACPI_TYPE_STRING:
60691116Smsmith            case ACPI_TYPE_BUFFER:
60791116Smsmith
60891116Smsmith                /* Valid operand */
60991116Smsmith                break;
61091116Smsmith
61191116Smsmith            default:
612250838Sjkim
613167802Sjkim                ACPI_ERROR ((AE_INFO,
614167802Sjkim                    "Needed [Buffer/String/Package], found [%s] %p",
615104470Siwasaki                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
61669746Smsmith
61769746Smsmith                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
61867754Smsmith            }
61969746Smsmith            goto NextOperand;
62067754Smsmith
621167802Sjkim        case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
622114237Snjl
623306536Sjkim            /*
624306536Sjkim             * Need an operand of type REGION or a BUFFER
625306536Sjkim             * (which could be a resolved region field)
626306536Sjkim             */
627193267Sjkim            switch (ObjDesc->Common.Type)
628114237Snjl            {
629167802Sjkim            case ACPI_TYPE_BUFFER:
630114237Snjl            case ACPI_TYPE_REGION:
631114237Snjl
632114237Snjl                /* Valid operand */
633114237Snjl                break;
634114237Snjl
635114237Snjl            default:
636250838Sjkim
637167802Sjkim                ACPI_ERROR ((AE_INFO,
638167802Sjkim                    "Needed [Region/Buffer], found [%s] %p",
639114237Snjl                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
640114237Snjl
641114237Snjl                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
642114237Snjl            }
643114237Snjl            goto NextOperand;
644114237Snjl
645151937Sjkim        case ARGI_DATAREFOBJ:
646151937Sjkim
647151937Sjkim            /* Used by the Store() operator only */
648151937Sjkim
649193267Sjkim            switch (ObjDesc->Common.Type)
650151937Sjkim            {
651151937Sjkim            case ACPI_TYPE_INTEGER:
652151937Sjkim            case ACPI_TYPE_PACKAGE:
653151937Sjkim            case ACPI_TYPE_STRING:
654151937Sjkim            case ACPI_TYPE_BUFFER:
655151937Sjkim            case ACPI_TYPE_BUFFER_FIELD:
656151937Sjkim            case ACPI_TYPE_LOCAL_REFERENCE:
657151937Sjkim            case ACPI_TYPE_LOCAL_REGION_FIELD:
658151937Sjkim            case ACPI_TYPE_LOCAL_BANK_FIELD:
659151937Sjkim            case ACPI_TYPE_LOCAL_INDEX_FIELD:
660151937Sjkim            case ACPI_TYPE_DDB_HANDLE:
661151937Sjkim
662151937Sjkim                /* Valid operand */
663151937Sjkim                break;
664151937Sjkim
665151937Sjkim            default:
666151937Sjkim
667151937Sjkim                if (AcpiGbl_EnableInterpreterSlack)
668151937Sjkim                {
669151937Sjkim                    /*
670306536Sjkim                     * Enable original behavior of Store(), allowing any
671306536Sjkim                     * and all objects as the source operand. The ACPI
672306536Sjkim                     * spec does not allow this, however.
673151937Sjkim                     */
674151937Sjkim                    break;
675151937Sjkim                }
676151937Sjkim
677151937Sjkim                if (TargetOp == AML_DEBUG_OP)
678151937Sjkim                {
679151937Sjkim                    /* Allow store of any object to the Debug object */
680151937Sjkim
681151937Sjkim                    break;
682151937Sjkim                }
683151937Sjkim
684167802Sjkim                ACPI_ERROR ((AE_INFO,
685306536Sjkim                    "Needed Integer/Buffer/String/Package/Ref/Ddb]"
686306536Sjkim                    ", found [%s] %p",
687151937Sjkim                    AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
688151937Sjkim
689151937Sjkim                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
690151937Sjkim            }
691151937Sjkim            goto NextOperand;
692151937Sjkim
69369746Smsmith        default:
69467754Smsmith
69569746Smsmith            /* Unknown type */
69669746Smsmith
697167802Sjkim            ACPI_ERROR ((AE_INFO,
698204773Sjkim                "Internal - Unknown ARGI (required operand) type 0x%X",
69967754Smsmith                ThisArgType));
70067754Smsmith
70169746Smsmith            return_ACPI_STATUS (AE_BAD_PARAMETER);
70269746Smsmith        }
70367754Smsmith
70470243Smsmith        /*
70569746Smsmith         * Make sure that the original object was resolved to the
70669746Smsmith         * required object type (Simple cases only).
70769746Smsmith         */
708306536Sjkim        Status = AcpiExCheckObjectType (
709306536Sjkim            TypeNeeded, (*StackPtr)->Common.Type, *StackPtr);
71069746Smsmith        if (ACPI_FAILURE (Status))
71169746Smsmith        {
71269746Smsmith            return_ACPI_STATUS (Status);
71369746Smsmith        }
71469746Smsmith
71569746SmsmithNextOperand:
71667754Smsmith        /*
71767754Smsmith         * If more operands needed, decrement StackPtr to point
71869746Smsmith         * to next operand on stack
71967754Smsmith         */
72067754Smsmith        if (GET_CURRENT_ARG_TYPE (ArgTypes))
72167754Smsmith        {
72267754Smsmith            StackPtr--;
72367754Smsmith        }
724151937Sjkim    }
72567754Smsmith
726193267Sjkim    ACPI_DUMP_OPERANDS (WalkState->Operands,
727193267Sjkim        AcpiPsGetOpcodeName (Opcode), WalkState->NumOperands);
728193267Sjkim
72969746Smsmith    return_ACPI_STATUS (Status);
73067754Smsmith}
731