2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define __EXRESOP_C__
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/amlcode.h>
122 #include <contrib/dev/acpica/acparser.h>
123 #include <contrib/dev/acpica/acinterp.h>
126 #define _COMPONENT ACPI_EXECUTER
127 ACPI_MODULE_NAME ("exresop")
129 /* Local prototypes */
132 AcpiExCheckObjectType (
133 ACPI_OBJECT_TYPE TypeNeeded,
134 ACPI_OBJECT_TYPE ThisType,
138 /*******************************************************************************
140 * FUNCTION: AcpiExCheckObjectType
142 * PARAMETERS: TypeNeeded Object type needed
143 * ThisType Actual object type
144 * Object Object pointer
148 * DESCRIPTION: Check required type against actual type
150 ******************************************************************************/
153 AcpiExCheckObjectType (
154 ACPI_OBJECT_TYPE TypeNeeded,
155 ACPI_OBJECT_TYPE ThisType,
158 ACPI_FUNCTION_NAME ("ExCheckObjectType");
161 if (TypeNeeded == ACPI_TYPE_ANY)
163 /* All types OK, so we don't perform any typechecks */
168 if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
171 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
172 * objects and thus allow them to be targets. (As per the ACPI
173 * specification, a store to a constant is a noop.)
175 if ((ThisType == ACPI_TYPE_INTEGER) &&
176 (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags & AOPOBJ_AML_CONSTANT))
182 if (TypeNeeded != ThisType)
184 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
185 "Needed [%s], found [%s] %p\n",
186 AcpiUtGetTypeName (TypeNeeded),
187 AcpiUtGetTypeName (ThisType), Object));
189 return (AE_AML_OPERAND_TYPE);
196 /*******************************************************************************
198 * FUNCTION: AcpiExResolveOperands
200 * PARAMETERS: Opcode - Opcode being interpreted
201 * StackPtr - Pointer to the operand stack to be
203 * WalkState - Current state
207 * DESCRIPTION: Convert multiple input operands to the types required by the
210 * Each 5-bit group in ArgTypes represents one required
211 * operand and indicates the required Type. The corresponding operand
212 * will be converted to the required type if possible, otherwise we
213 * abort with an exception.
215 ******************************************************************************/
218 AcpiExResolveOperands (
220 ACPI_OPERAND_OBJECT **StackPtr,
221 ACPI_WALK_STATE *WalkState)
223 ACPI_OPERAND_OBJECT *ObjDesc;
224 ACPI_STATUS Status = AE_OK;
228 const ACPI_OPCODE_INFO *OpInfo;
230 ACPI_OBJECT_TYPE TypeNeeded;
234 ACPI_FUNCTION_TRACE_U32 ("ExResolveOperands", Opcode);
237 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
238 if (OpInfo->Class == AML_CLASS_UNKNOWN)
240 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
243 ArgTypes = OpInfo->RuntimeArgs;
244 if (ArgTypes == ARGI_INVALID_OPCODE)
246 ACPI_REPORT_ERROR (("ResolveOperands: %X is not a valid AML opcode\n",
249 return_ACPI_STATUS (AE_AML_INTERNAL);
252 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
253 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
254 Opcode, OpInfo->Name, ArgTypes));
257 * Normal exit is with (ArgTypes == 0) at end of argument list.
258 * Function will return an exception from within the loop upon
259 * finding an entry which is not (or cannot be converted
260 * to) the required type; if stack underflows; or upon
261 * finding a NULL stack entry (which should not happen).
263 while (GET_CURRENT_ARG_TYPE (ArgTypes))
265 if (!StackPtr || !*StackPtr)
267 ACPI_REPORT_ERROR (("ResolveOperands: Null stack entry at %p\n",
270 return_ACPI_STATUS (AE_AML_INTERNAL);
273 /* Extract useful items */
277 /* Decode the descriptor type */
279 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
281 case ACPI_DESC_TYPE_NAMED:
285 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
289 case ACPI_DESC_TYPE_OPERAND:
291 /* ACPI internal object */
293 ObjectType = ACPI_GET_OBJECT_TYPE (ObjDesc);
295 /* Check for bad ACPI_OBJECT_TYPE */
297 if (!AcpiUtValidObjectType (ObjectType))
299 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
300 "Bad operand object type [%X]\n",
303 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
306 if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
308 /* Decode the Reference */
310 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
311 if (OpInfo->Class == AML_CLASS_UNKNOWN)
313 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
316 switch (ObjDesc->Reference.Opcode)
319 TargetOp = AML_DEBUG_OP;
321 /*lint -fallthrough */
328 case AML_LOAD_OP: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
329 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
331 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
332 "Operand is a Reference, RefOpcode [%s]\n",
333 (AcpiPsGetOpcodeInfo (ObjDesc->Reference.Opcode))->Name)));
337 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
338 "Operand is a Reference, Unknown Reference Opcode %X [%s]\n",
339 ObjDesc->Reference.Opcode,
340 (AcpiPsGetOpcodeInfo (ObjDesc->Reference.Opcode))->Name));
342 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
350 /* Invalid descriptor */
352 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
353 "Invalid descriptor %p [%s]\n",
354 ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
356 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
359 /* Get one argument type, point to the next */
361 ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
362 INCREMENT_ARG_LIST (ArgTypes);
365 * Handle cases where the object does not need to be
366 * resolved to a value
370 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
372 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
373 (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_STRING))
376 * String found - the string references a named object and
377 * must be resolved to a node
383 * Else not a string - fall through to the normal Reference
386 /*lint -fallthrough */
388 case ARGI_REFERENCE: /* References: */
389 case ARGI_INTEGER_REF:
390 case ARGI_OBJECT_REF:
391 case ARGI_DEVICE_REF:
392 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
393 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
394 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
397 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
398 * A Namespace Node is OK as-is
400 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
405 Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE,
406 ObjectType, ObjDesc);
407 if (ACPI_FAILURE (Status))
409 return_ACPI_STATUS (Status);
412 if (ObjDesc->Reference.Opcode == AML_NAME_OP)
414 /* Convert a named reference to the actual named object */
416 TempNode = ObjDesc->Reference.Object;
417 AcpiUtRemoveReference (ObjDesc);
418 (*StackPtr) = TempNode;
423 case ARGI_DATAREFOBJ: /* Store operator only */
426 * We don't want to resolve IndexOp reference objects during
427 * a store because this would be an implicit DeRefOf operation.
428 * Instead, we just want to store the reference object.
429 * -- All others must be resolved below.
431 if ((Opcode == AML_STORE_OP) &&
432 (ACPI_GET_OBJECT_TYPE (*StackPtr) == ACPI_TYPE_LOCAL_REFERENCE) &&
433 ((*StackPtr)->Reference.Opcode == AML_INDEX_OP))
440 /* All cases covered above */
445 * Resolve this object to a value
447 Status = AcpiExResolveToValue (StackPtr, WalkState);
448 if (ACPI_FAILURE (Status))
450 return_ACPI_STATUS (Status);
453 /* Get the resolved object */
458 * Check the resulting object (value) type
463 * For the simple cases, only one type of resolved object
468 /* Need an operand of type ACPI_TYPE_MUTEX */
470 TypeNeeded = ACPI_TYPE_MUTEX;
475 /* Need an operand of type ACPI_TYPE_EVENT */
477 TypeNeeded = ACPI_TYPE_EVENT;
480 case ARGI_PACKAGE: /* Package */
482 /* Need an operand of type ACPI_TYPE_PACKAGE */
484 TypeNeeded = ACPI_TYPE_PACKAGE;
489 /* Any operand type will do */
491 TypeNeeded = ACPI_TYPE_ANY;
496 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
498 TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE;
503 * The more complex cases allow multiple resolved object types
508 * Need an operand of type ACPI_TYPE_INTEGER,
509 * But we can implicitly convert from a STRING or BUFFER
510 * Aka - "Implicit Source Operand Conversion"
512 Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16);
513 if (ACPI_FAILURE (Status))
515 if (Status == AE_TYPE)
517 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
518 "Needed [Integer/String/Buffer], found [%s] %p\n",
519 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
521 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
524 return_ACPI_STATUS (Status);
527 if (ObjDesc != *StackPtr)
529 AcpiUtRemoveReference (ObjDesc);
537 * Need an operand of type ACPI_TYPE_BUFFER,
538 * But we can implicitly convert from a STRING or INTEGER
539 * Aka - "Implicit Source Operand Conversion"
541 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
542 if (ACPI_FAILURE (Status))
544 if (Status == AE_TYPE)
546 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
547 "Needed [Integer/String/Buffer], found [%s] %p\n",
548 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
550 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
553 return_ACPI_STATUS (Status);
556 if (ObjDesc != *StackPtr)
558 AcpiUtRemoveReference (ObjDesc);
566 * Need an operand of type ACPI_TYPE_STRING,
567 * But we can implicitly convert from a BUFFER or INTEGER
568 * Aka - "Implicit Source Operand Conversion"
570 Status = AcpiExConvertToString (ObjDesc, StackPtr,
571 ACPI_IMPLICIT_CONVERT_HEX);
572 if (ACPI_FAILURE (Status))
574 if (Status == AE_TYPE)
576 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
577 "Needed [Integer/String/Buffer], found [%s] %p\n",
578 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
580 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
583 return_ACPI_STATUS (Status);
586 if (ObjDesc != *StackPtr)
588 AcpiUtRemoveReference (ObjDesc);
593 case ARGI_COMPUTEDATA:
595 /* Need an operand of type INTEGER, STRING or BUFFER */
597 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
599 case ACPI_TYPE_INTEGER:
600 case ACPI_TYPE_STRING:
601 case ACPI_TYPE_BUFFER:
607 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
608 "Needed [Integer/String/Buffer], found [%s] %p\n",
609 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
611 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
616 case ARGI_BUFFER_OR_STRING:
618 /* Need an operand of type STRING or BUFFER */
620 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
622 case ACPI_TYPE_STRING:
623 case ACPI_TYPE_BUFFER:
628 case ACPI_TYPE_INTEGER:
630 /* Highest priority conversion is to type Buffer */
632 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
633 if (ACPI_FAILURE (Status))
635 return_ACPI_STATUS (Status);
638 if (ObjDesc != *StackPtr)
640 AcpiUtRemoveReference (ObjDesc);
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
646 "Needed [Integer/String/Buffer], found [%s] %p\n",
647 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
649 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
654 case ARGI_DATAOBJECT:
656 * ARGI_DATAOBJECT is only used by the SizeOf operator.
657 * Need a buffer, string, package, or RefOf reference.
659 * The only reference allowed here is a direct reference to
662 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
664 case ACPI_TYPE_PACKAGE:
665 case ACPI_TYPE_STRING:
666 case ACPI_TYPE_BUFFER:
667 case ACPI_TYPE_LOCAL_REFERENCE:
673 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
674 "Needed [Buffer/String/Package/Reference], found [%s] %p\n",
675 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
677 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
682 case ARGI_COMPLEXOBJ:
684 /* Need a buffer or package or (ACPI 2.0) String */
686 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
688 case ACPI_TYPE_PACKAGE:
689 case ACPI_TYPE_STRING:
690 case ACPI_TYPE_BUFFER:
696 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
697 "Needed [Buffer/String/Package], found [%s] %p\n",
698 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
700 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
705 case ARGI_REGION_OR_FIELD:
707 /* Need an operand of type REGION or a FIELD in a region */
709 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
711 case ACPI_TYPE_REGION:
712 case ACPI_TYPE_LOCAL_REGION_FIELD:
713 case ACPI_TYPE_LOCAL_BANK_FIELD:
714 case ACPI_TYPE_LOCAL_INDEX_FIELD:
720 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
721 "Needed [Region/RegionField], found [%s] %p\n",
722 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
724 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
729 case ARGI_DATAREFOBJ:
731 /* Used by the Store() operator only */
733 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
735 case ACPI_TYPE_INTEGER:
736 case ACPI_TYPE_PACKAGE:
737 case ACPI_TYPE_STRING:
738 case ACPI_TYPE_BUFFER:
739 case ACPI_TYPE_BUFFER_FIELD:
740 case ACPI_TYPE_LOCAL_REFERENCE:
741 case ACPI_TYPE_LOCAL_REGION_FIELD:
742 case ACPI_TYPE_LOCAL_BANK_FIELD:
743 case ACPI_TYPE_LOCAL_INDEX_FIELD:
744 case ACPI_TYPE_DDB_HANDLE:
751 if (AcpiGbl_EnableInterpreterSlack)
754 * Enable original behavior of Store(), allowing any and all
755 * objects as the source operand. The ACPI spec does not
756 * allow this, however.
761 if (TargetOp == AML_DEBUG_OP)
763 /* Allow store of any object to the Debug object */
768 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
769 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n",
770 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
772 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
781 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
782 "Internal - Unknown ARGI (required operand) type %X\n",
785 return_ACPI_STATUS (AE_BAD_PARAMETER);
789 * Make sure that the original object was resolved to the
790 * required object type (Simple cases only).
792 Status = AcpiExCheckObjectType (TypeNeeded,
793 ACPI_GET_OBJECT_TYPE (*StackPtr), *StackPtr);
794 if (ACPI_FAILURE (Status))
796 return_ACPI_STATUS (Status);
801 * If more operands needed, decrement StackPtr to point
802 * to next operand on stack
804 if (GET_CURRENT_ARG_TYPE (ArgTypes))
810 return_ACPI_STATUS (Status);