1 /******************************************************************************
3 * Module Name: exresop - AML Interpreter operand/object resolution
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exresop")
55 /* Local prototypes */
58 AcpiExCheckObjectType (
59 ACPI_OBJECT_TYPE TypeNeeded,
60 ACPI_OBJECT_TYPE ThisType,
64 /*******************************************************************************
66 * FUNCTION: AcpiExCheckObjectType
68 * PARAMETERS: TypeNeeded Object type needed
69 * ThisType Actual object type
70 * Object Object pointer
74 * DESCRIPTION: Check required type against actual type
76 ******************************************************************************/
79 AcpiExCheckObjectType (
80 ACPI_OBJECT_TYPE TypeNeeded,
81 ACPI_OBJECT_TYPE ThisType,
84 ACPI_FUNCTION_ENTRY ();
87 if (TypeNeeded == ACPI_TYPE_ANY)
89 /* All types OK, so we don't perform any typechecks */
94 if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
97 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
98 * objects and thus allow them to be targets. (As per the ACPI
99 * specification, a store to a constant is a noop.)
101 if ((ThisType == ACPI_TYPE_INTEGER) &&
102 (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags & AOPOBJ_AML_CONSTANT))
108 if (TypeNeeded != ThisType)
110 ACPI_ERROR ((AE_INFO,
111 "Needed type [%s], found [%s] %p",
112 AcpiUtGetTypeName (TypeNeeded),
113 AcpiUtGetTypeName (ThisType), Object));
115 return (AE_AML_OPERAND_TYPE);
122 /*******************************************************************************
124 * FUNCTION: AcpiExResolveOperands
126 * PARAMETERS: Opcode - Opcode being interpreted
127 * StackPtr - Pointer to the operand stack to be
129 * WalkState - Current state
133 * DESCRIPTION: Convert multiple input operands to the types required by the
136 * Each 5-bit group in ArgTypes represents one required
137 * operand and indicates the required Type. The corresponding operand
138 * will be converted to the required type if possible, otherwise we
139 * abort with an exception.
141 ******************************************************************************/
144 AcpiExResolveOperands (
146 ACPI_OPERAND_OBJECT **StackPtr,
147 ACPI_WALK_STATE *WalkState)
149 ACPI_OPERAND_OBJECT *ObjDesc;
150 ACPI_STATUS Status = AE_OK;
153 const ACPI_OPCODE_INFO *OpInfo;
155 ACPI_OBJECT_TYPE TypeNeeded;
159 ACPI_FUNCTION_TRACE_U32 (ExResolveOperands, Opcode);
162 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
163 if (OpInfo->Class == AML_CLASS_UNKNOWN)
165 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
168 ArgTypes = OpInfo->RuntimeArgs;
169 if (ArgTypes == ARGI_INVALID_OPCODE)
171 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
174 return_ACPI_STATUS (AE_AML_INTERNAL);
177 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
178 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
179 Opcode, OpInfo->Name, ArgTypes));
182 * Normal exit is with (ArgTypes == 0) at end of argument list.
183 * Function will return an exception from within the loop upon
184 * finding an entry which is not (or cannot be converted
185 * to) the required type; if stack underflows; or upon
186 * finding a NULL stack entry (which should not happen).
188 while (GET_CURRENT_ARG_TYPE (ArgTypes))
190 if (!StackPtr || !*StackPtr)
192 ACPI_ERROR ((AE_INFO, "Null stack entry at %p",
195 return_ACPI_STATUS (AE_AML_INTERNAL);
198 /* Extract useful items */
202 /* Decode the descriptor type */
204 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
206 case ACPI_DESC_TYPE_NAMED:
210 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
213 * Resolve an alias object. The construction of these objects
214 * guarantees that there is only one level of alias indirection;
215 * thus, the attached object is always the aliased namespace node
217 if (ObjectType == ACPI_TYPE_LOCAL_ALIAS)
219 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
221 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
225 case ACPI_DESC_TYPE_OPERAND:
227 /* ACPI internal object */
229 ObjectType = ObjDesc->Common.Type;
231 /* Check for bad ACPI_OBJECT_TYPE */
233 if (!AcpiUtValidObjectType (ObjectType))
235 ACPI_ERROR ((AE_INFO,
236 "Bad operand object type [0x%X]", ObjectType));
238 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
241 if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
243 /* Validate the Reference */
245 switch (ObjDesc->Reference.Class)
247 case ACPI_REFCLASS_DEBUG:
249 TargetOp = AML_DEBUG_OP;
251 /*lint -fallthrough */
253 case ACPI_REFCLASS_ARG:
254 case ACPI_REFCLASS_LOCAL:
255 case ACPI_REFCLASS_INDEX:
256 case ACPI_REFCLASS_REFOF:
257 case ACPI_REFCLASS_TABLE: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
258 case ACPI_REFCLASS_NAME: /* Reference to a named object */
260 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
261 "Operand is a Reference, Class [%s] %2.2X\n",
262 AcpiUtGetReferenceName (ObjDesc),
263 ObjDesc->Reference.Class));
268 ACPI_ERROR ((AE_INFO,
269 "Unknown Reference Class 0x%2.2X in %p",
270 ObjDesc->Reference.Class, ObjDesc));
272 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
279 /* Invalid descriptor */
281 ACPI_ERROR ((AE_INFO, "Invalid descriptor %p [%s]",
282 ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
284 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
287 /* Get one argument type, point to the next */
289 ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
290 INCREMENT_ARG_LIST (ArgTypes);
293 * Handle cases where the object does not need to be
294 * resolved to a value
298 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
300 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
301 (ObjDesc->Common.Type == ACPI_TYPE_STRING))
304 * String found - the string references a named object and
305 * must be resolved to a node
311 * Else not a string - fall through to the normal Reference
314 /*lint -fallthrough */
316 case ARGI_REFERENCE: /* References: */
317 case ARGI_INTEGER_REF:
318 case ARGI_OBJECT_REF:
319 case ARGI_DEVICE_REF:
320 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
321 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
322 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
324 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
325 * A Namespace Node is OK as-is
327 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
332 Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE,
333 ObjectType, ObjDesc);
334 if (ACPI_FAILURE (Status))
336 return_ACPI_STATUS (Status);
340 case ARGI_DATAREFOBJ: /* Store operator only */
342 * We don't want to resolve IndexOp reference objects during
343 * a store because this would be an implicit DeRefOf operation.
344 * Instead, we just want to store the reference object.
345 * -- All others must be resolved below.
347 if ((Opcode == AML_STORE_OP) &&
348 ((*StackPtr)->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
349 ((*StackPtr)->Reference.Class == ACPI_REFCLASS_INDEX))
357 /* All cases covered above */
363 * Resolve this object to a value
365 Status = AcpiExResolveToValue (StackPtr, WalkState);
366 if (ACPI_FAILURE (Status))
368 return_ACPI_STATUS (Status);
371 /* Get the resolved object */
376 * Check the resulting object (value) type
381 * For the simple cases, only one type of resolved object
386 /* Need an operand of type ACPI_TYPE_MUTEX */
388 TypeNeeded = ACPI_TYPE_MUTEX;
393 /* Need an operand of type ACPI_TYPE_EVENT */
395 TypeNeeded = ACPI_TYPE_EVENT;
398 case ARGI_PACKAGE: /* Package */
400 /* Need an operand of type ACPI_TYPE_PACKAGE */
402 TypeNeeded = ACPI_TYPE_PACKAGE;
407 /* Any operand type will do */
409 TypeNeeded = ACPI_TYPE_ANY;
414 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
416 TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE;
421 * The more complex cases allow multiple resolved object types
426 * Need an operand of type ACPI_TYPE_INTEGER,
427 * But we can implicitly convert from a STRING or BUFFER
428 * Aka - "Implicit Source Operand Conversion"
430 Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16);
431 if (ACPI_FAILURE (Status))
433 if (Status == AE_TYPE)
435 ACPI_ERROR ((AE_INFO,
436 "Needed [Integer/String/Buffer], found [%s] %p",
437 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
439 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
442 return_ACPI_STATUS (Status);
445 if (ObjDesc != *StackPtr)
447 AcpiUtRemoveReference (ObjDesc);
453 * Need an operand of type ACPI_TYPE_BUFFER,
454 * But we can implicitly convert from a STRING or INTEGER
455 * Aka - "Implicit Source Operand Conversion"
457 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
458 if (ACPI_FAILURE (Status))
460 if (Status == AE_TYPE)
462 ACPI_ERROR ((AE_INFO,
463 "Needed [Integer/String/Buffer], found [%s] %p",
464 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
466 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
469 return_ACPI_STATUS (Status);
472 if (ObjDesc != *StackPtr)
474 AcpiUtRemoveReference (ObjDesc);
480 * Need an operand of type ACPI_TYPE_STRING,
481 * But we can implicitly convert from a BUFFER or INTEGER
482 * Aka - "Implicit Source Operand Conversion"
484 Status = AcpiExConvertToString (ObjDesc, StackPtr,
485 ACPI_IMPLICIT_CONVERT_HEX);
486 if (ACPI_FAILURE (Status))
488 if (Status == AE_TYPE)
490 ACPI_ERROR ((AE_INFO,
491 "Needed [Integer/String/Buffer], found [%s] %p",
492 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
494 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
497 return_ACPI_STATUS (Status);
500 if (ObjDesc != *StackPtr)
502 AcpiUtRemoveReference (ObjDesc);
506 case ARGI_COMPUTEDATA:
508 /* Need an operand of type INTEGER, STRING or BUFFER */
510 switch (ObjDesc->Common.Type)
512 case ACPI_TYPE_INTEGER:
513 case ACPI_TYPE_STRING:
514 case ACPI_TYPE_BUFFER:
520 ACPI_ERROR ((AE_INFO,
521 "Needed [Integer/String/Buffer], found [%s] %p",
522 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
524 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
528 case ARGI_BUFFER_OR_STRING:
530 /* Need an operand of type STRING or BUFFER */
532 switch (ObjDesc->Common.Type)
534 case ACPI_TYPE_STRING:
535 case ACPI_TYPE_BUFFER:
540 case ACPI_TYPE_INTEGER:
542 /* Highest priority conversion is to type Buffer */
544 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
545 if (ACPI_FAILURE (Status))
547 return_ACPI_STATUS (Status);
550 if (ObjDesc != *StackPtr)
552 AcpiUtRemoveReference (ObjDesc);
557 ACPI_ERROR ((AE_INFO,
558 "Needed [Integer/String/Buffer], found [%s] %p",
559 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
561 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
565 case ARGI_DATAOBJECT:
567 * ARGI_DATAOBJECT is only used by the SizeOf operator.
568 * Need a buffer, string, package, or RefOf reference.
570 * The only reference allowed here is a direct reference to
573 switch (ObjDesc->Common.Type)
575 case ACPI_TYPE_PACKAGE:
576 case ACPI_TYPE_STRING:
577 case ACPI_TYPE_BUFFER:
578 case ACPI_TYPE_LOCAL_REFERENCE:
585 ACPI_ERROR ((AE_INFO,
586 "Needed [Buffer/String/Package/Reference], found [%s] %p",
587 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
589 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
593 case ARGI_COMPLEXOBJ:
595 /* Need a buffer or package or (ACPI 2.0) String */
597 switch (ObjDesc->Common.Type)
599 case ACPI_TYPE_PACKAGE:
600 case ACPI_TYPE_STRING:
601 case ACPI_TYPE_BUFFER:
608 ACPI_ERROR ((AE_INFO,
609 "Needed [Buffer/String/Package], found [%s] %p",
610 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
612 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
616 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
618 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
620 switch (ObjDesc->Common.Type)
622 case ACPI_TYPE_BUFFER:
623 case ACPI_TYPE_REGION:
630 ACPI_ERROR ((AE_INFO,
631 "Needed [Region/Buffer], found [%s] %p",
632 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
634 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
638 case ARGI_DATAREFOBJ:
640 /* Used by the Store() operator only */
642 switch (ObjDesc->Common.Type)
644 case ACPI_TYPE_INTEGER:
645 case ACPI_TYPE_PACKAGE:
646 case ACPI_TYPE_STRING:
647 case ACPI_TYPE_BUFFER:
648 case ACPI_TYPE_BUFFER_FIELD:
649 case ACPI_TYPE_LOCAL_REFERENCE:
650 case ACPI_TYPE_LOCAL_REGION_FIELD:
651 case ACPI_TYPE_LOCAL_BANK_FIELD:
652 case ACPI_TYPE_LOCAL_INDEX_FIELD:
653 case ACPI_TYPE_DDB_HANDLE:
660 if (AcpiGbl_EnableInterpreterSlack)
663 * Enable original behavior of Store(), allowing any and all
664 * objects as the source operand. The ACPI spec does not
665 * allow this, however.
670 if (TargetOp == AML_DEBUG_OP)
672 /* Allow store of any object to the Debug object */
677 ACPI_ERROR ((AE_INFO,
678 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
679 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
681 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
689 ACPI_ERROR ((AE_INFO,
690 "Internal - Unknown ARGI (required operand) type 0x%X",
693 return_ACPI_STATUS (AE_BAD_PARAMETER);
697 * Make sure that the original object was resolved to the
698 * required object type (Simple cases only).
700 Status = AcpiExCheckObjectType (TypeNeeded,
701 (*StackPtr)->Common.Type, *StackPtr);
702 if (ACPI_FAILURE (Status))
704 return_ACPI_STATUS (Status);
709 * If more operands needed, decrement StackPtr to point
710 * to next operand on stack
712 if (GET_CURRENT_ARG_TYPE (ArgTypes))
718 ACPI_DUMP_OPERANDS (WalkState->Operands,
719 AcpiPsGetOpcodeName (Opcode), WalkState->NumOperands);
721 return_ACPI_STATUS (Status);