1 /******************************************************************************
3 * Module Name: exresop - AML Interpreter operand/object resolution
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/amlcode.h>
49 #include <contrib/dev/acpica/include/acparser.h>
50 #include <contrib/dev/acpica/include/acinterp.h>
51 #include <contrib/dev/acpica/include/acnamesp.h>
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exresop")
57 /* Local prototypes */
60 AcpiExCheckObjectType (
61 ACPI_OBJECT_TYPE TypeNeeded,
62 ACPI_OBJECT_TYPE ThisType,
66 /*******************************************************************************
68 * FUNCTION: AcpiExCheckObjectType
70 * PARAMETERS: TypeNeeded Object type needed
71 * ThisType Actual object type
72 * Object Object pointer
76 * DESCRIPTION: Check required type against actual type
78 ******************************************************************************/
81 AcpiExCheckObjectType (
82 ACPI_OBJECT_TYPE TypeNeeded,
83 ACPI_OBJECT_TYPE ThisType,
86 ACPI_FUNCTION_ENTRY ();
89 if (TypeNeeded == ACPI_TYPE_ANY)
91 /* All types OK, so we don't perform any typechecks */
96 if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
99 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
100 * objects and thus allow them to be targets. (As per the ACPI
101 * specification, a store to a constant is a noop.)
103 if ((ThisType == ACPI_TYPE_INTEGER) &&
104 (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags & AOPOBJ_AML_CONSTANT))
110 if (TypeNeeded != ThisType)
112 ACPI_ERROR ((AE_INFO,
113 "Needed type [%s], found [%s] %p",
114 AcpiUtGetTypeName (TypeNeeded),
115 AcpiUtGetTypeName (ThisType), Object));
117 return (AE_AML_OPERAND_TYPE);
124 /*******************************************************************************
126 * FUNCTION: AcpiExResolveOperands
128 * PARAMETERS: Opcode - Opcode being interpreted
129 * StackPtr - Pointer to the operand stack to be
131 * WalkState - Current state
135 * DESCRIPTION: Convert multiple input operands to the types required by the
138 * Each 5-bit group in ArgTypes represents one required
139 * operand and indicates the required Type. The corresponding operand
140 * will be converted to the required type if possible, otherwise we
141 * abort with an exception.
143 ******************************************************************************/
146 AcpiExResolveOperands (
148 ACPI_OPERAND_OBJECT **StackPtr,
149 ACPI_WALK_STATE *WalkState)
151 ACPI_OPERAND_OBJECT *ObjDesc;
152 ACPI_STATUS Status = AE_OK;
155 const ACPI_OPCODE_INFO *OpInfo;
157 ACPI_OBJECT_TYPE TypeNeeded;
161 ACPI_FUNCTION_TRACE_U32 (ExResolveOperands, Opcode);
164 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
165 if (OpInfo->Class == AML_CLASS_UNKNOWN)
167 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
170 ArgTypes = OpInfo->RuntimeArgs;
171 if (ArgTypes == ARGI_INVALID_OPCODE)
173 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
176 return_ACPI_STATUS (AE_AML_INTERNAL);
179 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
180 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
181 Opcode, OpInfo->Name, ArgTypes));
184 * Normal exit is with (ArgTypes == 0) at end of argument list.
185 * Function will return an exception from within the loop upon
186 * finding an entry which is not (or cannot be converted
187 * to) the required type; if stack underflows; or upon
188 * finding a NULL stack entry (which should not happen).
190 while (GET_CURRENT_ARG_TYPE (ArgTypes))
192 if (!StackPtr || !*StackPtr)
194 ACPI_ERROR ((AE_INFO, "Null stack entry at %p",
197 return_ACPI_STATUS (AE_AML_INTERNAL);
200 /* Extract useful items */
204 /* Decode the descriptor type */
206 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
208 case ACPI_DESC_TYPE_NAMED:
212 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
215 * Resolve an alias object. The construction of these objects
216 * guarantees that there is only one level of alias indirection;
217 * thus, the attached object is always the aliased namespace node
219 if (ObjectType == ACPI_TYPE_LOCAL_ALIAS)
221 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
223 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
228 case ACPI_DESC_TYPE_OPERAND:
230 /* ACPI internal object */
232 ObjectType = ObjDesc->Common.Type;
234 /* Check for bad ACPI_OBJECT_TYPE */
236 if (!AcpiUtValidObjectType (ObjectType))
238 ACPI_ERROR ((AE_INFO,
239 "Bad operand object type [0x%X]", ObjectType));
241 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
244 if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
246 /* Validate the Reference */
248 switch (ObjDesc->Reference.Class)
250 case ACPI_REFCLASS_DEBUG:
252 TargetOp = AML_DEBUG_OP;
254 /*lint -fallthrough */
256 case ACPI_REFCLASS_ARG:
257 case ACPI_REFCLASS_LOCAL:
258 case ACPI_REFCLASS_INDEX:
259 case ACPI_REFCLASS_REFOF:
260 case ACPI_REFCLASS_TABLE: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
261 case ACPI_REFCLASS_NAME: /* Reference to a named object */
263 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
264 "Operand is a Reference, Class [%s] %2.2X\n",
265 AcpiUtGetReferenceName (ObjDesc),
266 ObjDesc->Reference.Class));
271 ACPI_ERROR ((AE_INFO,
272 "Unknown Reference Class 0x%2.2X in %p",
273 ObjDesc->Reference.Class, ObjDesc));
275 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
283 /* Invalid descriptor */
285 ACPI_ERROR ((AE_INFO, "Invalid descriptor %p [%s]",
286 ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
288 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
291 /* Get one argument type, point to the next */
293 ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
294 INCREMENT_ARG_LIST (ArgTypes);
297 * Handle cases where the object does not need to be
298 * resolved to a value
302 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
304 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
305 (ObjDesc->Common.Type == ACPI_TYPE_STRING))
308 * String found - the string references a named object and
309 * must be resolved to a node
315 * Else not a string - fall through to the normal Reference
318 /*lint -fallthrough */
320 case ARGI_REFERENCE: /* References: */
321 case ARGI_INTEGER_REF:
322 case ARGI_OBJECT_REF:
323 case ARGI_DEVICE_REF:
324 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
325 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
326 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
329 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
330 * A Namespace Node is OK as-is
332 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
337 Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE,
338 ObjectType, ObjDesc);
339 if (ACPI_FAILURE (Status))
341 return_ACPI_STATUS (Status);
346 case ARGI_DATAREFOBJ: /* Store operator only */
349 * We don't want to resolve IndexOp reference objects during
350 * a store because this would be an implicit DeRefOf operation.
351 * Instead, we just want to store the reference object.
352 * -- All others must be resolved below.
354 if ((Opcode == AML_STORE_OP) &&
355 ((*StackPtr)->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
356 ((*StackPtr)->Reference.Class == ACPI_REFCLASS_INDEX))
363 /* All cases covered above */
368 * Resolve this object to a value
370 Status = AcpiExResolveToValue (StackPtr, WalkState);
371 if (ACPI_FAILURE (Status))
373 return_ACPI_STATUS (Status);
376 /* Get the resolved object */
381 * Check the resulting object (value) type
386 * For the simple cases, only one type of resolved object
391 /* Need an operand of type ACPI_TYPE_MUTEX */
393 TypeNeeded = ACPI_TYPE_MUTEX;
398 /* Need an operand of type ACPI_TYPE_EVENT */
400 TypeNeeded = ACPI_TYPE_EVENT;
403 case ARGI_PACKAGE: /* Package */
405 /* Need an operand of type ACPI_TYPE_PACKAGE */
407 TypeNeeded = ACPI_TYPE_PACKAGE;
412 /* Any operand type will do */
414 TypeNeeded = ACPI_TYPE_ANY;
419 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
421 TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE;
426 * The more complex cases allow multiple resolved object types
431 * Need an operand of type ACPI_TYPE_INTEGER,
432 * But we can implicitly convert from a STRING or BUFFER
433 * Aka - "Implicit Source Operand Conversion"
435 Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16);
436 if (ACPI_FAILURE (Status))
438 if (Status == AE_TYPE)
440 ACPI_ERROR ((AE_INFO,
441 "Needed [Integer/String/Buffer], found [%s] %p",
442 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
444 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
447 return_ACPI_STATUS (Status);
450 if (ObjDesc != *StackPtr)
452 AcpiUtRemoveReference (ObjDesc);
460 * Need an operand of type ACPI_TYPE_BUFFER,
461 * But we can implicitly convert from a STRING or INTEGER
462 * Aka - "Implicit Source Operand Conversion"
464 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
465 if (ACPI_FAILURE (Status))
467 if (Status == AE_TYPE)
469 ACPI_ERROR ((AE_INFO,
470 "Needed [Integer/String/Buffer], found [%s] %p",
471 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
473 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
476 return_ACPI_STATUS (Status);
479 if (ObjDesc != *StackPtr)
481 AcpiUtRemoveReference (ObjDesc);
489 * Need an operand of type ACPI_TYPE_STRING,
490 * But we can implicitly convert from a BUFFER or INTEGER
491 * Aka - "Implicit Source Operand Conversion"
493 Status = AcpiExConvertToString (ObjDesc, StackPtr,
494 ACPI_IMPLICIT_CONVERT_HEX);
495 if (ACPI_FAILURE (Status))
497 if (Status == AE_TYPE)
499 ACPI_ERROR ((AE_INFO,
500 "Needed [Integer/String/Buffer], found [%s] %p",
501 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
503 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
506 return_ACPI_STATUS (Status);
509 if (ObjDesc != *StackPtr)
511 AcpiUtRemoveReference (ObjDesc);
516 case ARGI_COMPUTEDATA:
518 /* Need an operand of type INTEGER, STRING or BUFFER */
520 switch (ObjDesc->Common.Type)
522 case ACPI_TYPE_INTEGER:
523 case ACPI_TYPE_STRING:
524 case ACPI_TYPE_BUFFER:
530 ACPI_ERROR ((AE_INFO,
531 "Needed [Integer/String/Buffer], found [%s] %p",
532 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
534 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
539 case ARGI_BUFFER_OR_STRING:
541 /* Need an operand of type STRING or BUFFER */
543 switch (ObjDesc->Common.Type)
545 case ACPI_TYPE_STRING:
546 case ACPI_TYPE_BUFFER:
551 case ACPI_TYPE_INTEGER:
553 /* Highest priority conversion is to type Buffer */
555 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
556 if (ACPI_FAILURE (Status))
558 return_ACPI_STATUS (Status);
561 if (ObjDesc != *StackPtr)
563 AcpiUtRemoveReference (ObjDesc);
568 ACPI_ERROR ((AE_INFO,
569 "Needed [Integer/String/Buffer], found [%s] %p",
570 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
572 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
577 case ARGI_DATAOBJECT:
579 * ARGI_DATAOBJECT is only used by the SizeOf operator.
580 * Need a buffer, string, package, or RefOf reference.
582 * The only reference allowed here is a direct reference to
585 switch (ObjDesc->Common.Type)
587 case ACPI_TYPE_PACKAGE:
588 case ACPI_TYPE_STRING:
589 case ACPI_TYPE_BUFFER:
590 case ACPI_TYPE_LOCAL_REFERENCE:
596 ACPI_ERROR ((AE_INFO,
597 "Needed [Buffer/String/Package/Reference], found [%s] %p",
598 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
600 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
605 case ARGI_COMPLEXOBJ:
607 /* Need a buffer or package or (ACPI 2.0) String */
609 switch (ObjDesc->Common.Type)
611 case ACPI_TYPE_PACKAGE:
612 case ACPI_TYPE_STRING:
613 case ACPI_TYPE_BUFFER:
619 ACPI_ERROR ((AE_INFO,
620 "Needed [Buffer/String/Package], found [%s] %p",
621 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
623 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
628 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
630 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
632 switch (ObjDesc->Common.Type)
634 case ACPI_TYPE_BUFFER:
635 case ACPI_TYPE_REGION:
641 ACPI_ERROR ((AE_INFO,
642 "Needed [Region/Buffer], found [%s] %p",
643 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
645 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
650 case ARGI_DATAREFOBJ:
652 /* Used by the Store() operator only */
654 switch (ObjDesc->Common.Type)
656 case ACPI_TYPE_INTEGER:
657 case ACPI_TYPE_PACKAGE:
658 case ACPI_TYPE_STRING:
659 case ACPI_TYPE_BUFFER:
660 case ACPI_TYPE_BUFFER_FIELD:
661 case ACPI_TYPE_LOCAL_REFERENCE:
662 case ACPI_TYPE_LOCAL_REGION_FIELD:
663 case ACPI_TYPE_LOCAL_BANK_FIELD:
664 case ACPI_TYPE_LOCAL_INDEX_FIELD:
665 case ACPI_TYPE_DDB_HANDLE:
672 if (AcpiGbl_EnableInterpreterSlack)
675 * Enable original behavior of Store(), allowing any and all
676 * objects as the source operand. The ACPI spec does not
677 * allow this, however.
682 if (TargetOp == AML_DEBUG_OP)
684 /* Allow store of any object to the Debug object */
689 ACPI_ERROR ((AE_INFO,
690 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
691 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
693 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
702 ACPI_ERROR ((AE_INFO,
703 "Internal - Unknown ARGI (required operand) type 0x%X",
706 return_ACPI_STATUS (AE_BAD_PARAMETER);
710 * Make sure that the original object was resolved to the
711 * required object type (Simple cases only).
713 Status = AcpiExCheckObjectType (TypeNeeded,
714 (*StackPtr)->Common.Type, *StackPtr);
715 if (ACPI_FAILURE (Status))
717 return_ACPI_STATUS (Status);
722 * If more operands needed, decrement StackPtr to point
723 * to next operand on stack
725 if (GET_CURRENT_ARG_TYPE (ArgTypes))
731 ACPI_DUMP_OPERANDS (WalkState->Operands,
732 AcpiPsGetOpcodeName (Opcode), WalkState->NumOperands);
734 return_ACPI_STATUS (Status);