1 /******************************************************************************
3 * Module Name: exresop - AML Interpreter operand/object resolution
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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
&
103 AOPOBJ_AML_CONSTANT
))
109 if (TypeNeeded
!= ThisType
)
111 ACPI_ERROR ((AE_INFO
,
112 "Needed type [%s], found [%s] %p",
113 AcpiUtGetTypeName (TypeNeeded
),
114 AcpiUtGetTypeName (ThisType
), Object
));
116 return (AE_AML_OPERAND_TYPE
);
123 /*******************************************************************************
125 * FUNCTION: AcpiExResolveOperands
127 * PARAMETERS: Opcode - Opcode being interpreted
128 * StackPtr - Pointer to the operand stack to be
130 * WalkState - Current state
134 * DESCRIPTION: Convert multiple input operands to the types required by the
137 * Each 5-bit group in ArgTypes represents one required
138 * operand and indicates the required Type. The corresponding operand
139 * will be converted to the required type if possible, otherwise we
140 * abort with an exception.
142 ******************************************************************************/
145 AcpiExResolveOperands (
147 ACPI_OPERAND_OBJECT
**StackPtr
,
148 ACPI_WALK_STATE
*WalkState
)
150 ACPI_OPERAND_OBJECT
*ObjDesc
;
151 ACPI_STATUS Status
= AE_OK
;
154 const ACPI_OPCODE_INFO
*OpInfo
;
156 ACPI_OBJECT_TYPE TypeNeeded
;
160 ACPI_FUNCTION_TRACE_U32 (ExResolveOperands
, Opcode
);
163 OpInfo
= AcpiPsGetOpcodeInfo (Opcode
);
164 if (OpInfo
->Class
== AML_CLASS_UNKNOWN
)
166 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
169 ArgTypes
= OpInfo
->RuntimeArgs
;
170 if (ArgTypes
== ARGI_INVALID_OPCODE
)
172 ACPI_ERROR ((AE_INFO
, "Unknown AML opcode 0x%X",
175 return_ACPI_STATUS (AE_AML_INTERNAL
);
178 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
179 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
180 Opcode
, OpInfo
->Name
, ArgTypes
));
183 * Normal exit is with (ArgTypes == 0) at end of argument list.
184 * Function will return an exception from within the loop upon
185 * finding an entry which is not (or cannot be converted
186 * to) the required type; if stack underflows; or upon
187 * finding a NULL stack entry (which should not happen).
189 while (GET_CURRENT_ARG_TYPE (ArgTypes
))
191 if (!StackPtr
|| !*StackPtr
)
193 ACPI_ERROR ((AE_INFO
, "Null stack entry at %p",
196 return_ACPI_STATUS (AE_AML_INTERNAL
);
199 /* Extract useful items */
203 /* Decode the descriptor type */
205 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
))
207 case ACPI_DESC_TYPE_NAMED
:
211 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
214 * Resolve an alias object. The construction of these objects
215 * guarantees that there is only one level of alias indirection;
216 * thus, the attached object is always the aliased namespace node
218 if (ObjectType
== ACPI_TYPE_LOCAL_ALIAS
)
220 ObjDesc
= AcpiNsGetAttachedObject (
221 (ACPI_NAMESPACE_NODE
*) ObjDesc
);
223 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
227 case ACPI_DESC_TYPE_OPERAND
:
229 /* ACPI internal object */
231 ObjectType
= ObjDesc
->Common
.Type
;
233 /* Check for bad ACPI_OBJECT_TYPE */
235 if (!AcpiUtValidObjectType (ObjectType
))
237 ACPI_ERROR ((AE_INFO
,
238 "Bad operand object type [0x%X]", ObjectType
));
240 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
243 if (ObjectType
== (UINT8
) ACPI_TYPE_LOCAL_REFERENCE
)
245 /* Validate the Reference */
247 switch (ObjDesc
->Reference
.Class
)
249 case ACPI_REFCLASS_DEBUG
:
251 TargetOp
= AML_DEBUG_OP
;
253 /*lint -fallthrough */
255 case ACPI_REFCLASS_ARG
:
256 case ACPI_REFCLASS_LOCAL
:
257 case ACPI_REFCLASS_INDEX
:
258 case ACPI_REFCLASS_REFOF
:
259 case ACPI_REFCLASS_TABLE
: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
260 case ACPI_REFCLASS_NAME
: /* Reference to a named object */
262 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
263 "Operand is a Reference, Class [%s] %2.2X\n",
264 AcpiUtGetReferenceName (ObjDesc
),
265 ObjDesc
->Reference
.Class
));
270 ACPI_ERROR ((AE_INFO
,
271 "Unknown Reference Class 0x%2.2X in %p",
272 ObjDesc
->Reference
.Class
, ObjDesc
));
274 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
281 /* Invalid descriptor */
283 ACPI_ERROR ((AE_INFO
, "Invalid descriptor %p [%s]",
284 ObjDesc
, AcpiUtGetDescriptorName (ObjDesc
)));
286 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
289 /* Get one argument type, point to the next */
291 ThisArgType
= GET_CURRENT_ARG_TYPE (ArgTypes
);
292 INCREMENT_ARG_LIST (ArgTypes
);
295 * Handle cases where the object does not need to be
296 * resolved to a value
300 case ARGI_REF_OR_STRING
: /* Can be a String or Reference */
302 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
) ==
303 ACPI_DESC_TYPE_OPERAND
) &&
304 (ObjDesc
->Common
.Type
== ACPI_TYPE_STRING
))
307 * String found - the string references a named object and
308 * must be resolved to a node
314 * Else not a string - fall through to the normal Reference
317 /*lint -fallthrough */
319 case ARGI_REFERENCE
: /* References: */
320 case ARGI_INTEGER_REF
:
321 case ARGI_OBJECT_REF
:
322 case ARGI_DEVICE_REF
:
323 case ARGI_TARGETREF
: /* Allows implicit conversion rules before store */
324 case ARGI_FIXED_TARGET
: /* No implicit conversion before store to target */
325 case ARGI_SIMPLE_TARGET
: /* Name, Local, or Arg - no implicit conversion */
326 case ARGI_STORE_TARGET
:
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 (
338 ACPI_TYPE_LOCAL_REFERENCE
, ObjectType
, ObjDesc
);
339 if (ACPI_FAILURE (Status
))
341 return_ACPI_STATUS (Status
);
345 case ARGI_DATAREFOBJ
: /* Store operator only */
347 * We don't want to resolve IndexOp reference objects during
348 * a store because this would be an implicit DeRefOf operation.
349 * Instead, we just want to store the reference object.
350 * -- All others must be resolved below.
352 if ((Opcode
== AML_STORE_OP
) &&
353 ((*StackPtr
)->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
354 ((*StackPtr
)->Reference
.Class
== ACPI_REFCLASS_INDEX
))
362 /* 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
);
458 * Need an operand of type ACPI_TYPE_BUFFER,
459 * But we can implicitly convert from a STRING or INTEGER
460 * Aka - "Implicit Source Operand Conversion"
462 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
463 if (ACPI_FAILURE (Status
))
465 if (Status
== AE_TYPE
)
467 ACPI_ERROR ((AE_INFO
,
468 "Needed [Integer/String/Buffer], found [%s] %p",
469 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
471 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
474 return_ACPI_STATUS (Status
);
477 if (ObjDesc
!= *StackPtr
)
479 AcpiUtRemoveReference (ObjDesc
);
485 * Need an operand of type ACPI_TYPE_STRING,
486 * But we can implicitly convert from a BUFFER or INTEGER
487 * Aka - "Implicit Source Operand Conversion"
489 Status
= AcpiExConvertToString (
490 ObjDesc
, StackPtr
, ACPI_IMPLICIT_CONVERT_HEX
);
491 if (ACPI_FAILURE (Status
))
493 if (Status
== AE_TYPE
)
495 ACPI_ERROR ((AE_INFO
,
496 "Needed [Integer/String/Buffer], found [%s] %p",
497 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
499 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
502 return_ACPI_STATUS (Status
);
505 if (ObjDesc
!= *StackPtr
)
507 AcpiUtRemoveReference (ObjDesc
);
511 case ARGI_COMPUTEDATA
:
513 /* Need an operand of type INTEGER, STRING or BUFFER */
515 switch (ObjDesc
->Common
.Type
)
517 case ACPI_TYPE_INTEGER
:
518 case ACPI_TYPE_STRING
:
519 case ACPI_TYPE_BUFFER
:
525 ACPI_ERROR ((AE_INFO
,
526 "Needed [Integer/String/Buffer], found [%s] %p",
527 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
529 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
533 case ARGI_BUFFER_OR_STRING
:
535 /* Need an operand of type STRING or BUFFER */
537 switch (ObjDesc
->Common
.Type
)
539 case ACPI_TYPE_STRING
:
540 case ACPI_TYPE_BUFFER
:
545 case ACPI_TYPE_INTEGER
:
547 /* Highest priority conversion is to type Buffer */
549 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
550 if (ACPI_FAILURE (Status
))
552 return_ACPI_STATUS (Status
);
555 if (ObjDesc
!= *StackPtr
)
557 AcpiUtRemoveReference (ObjDesc
);
562 ACPI_ERROR ((AE_INFO
,
563 "Needed [Integer/String/Buffer], found [%s] %p",
564 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
566 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
570 case ARGI_DATAOBJECT
:
572 * ARGI_DATAOBJECT is only used by the SizeOf operator.
573 * Need a buffer, string, package, or RefOf reference.
575 * The only reference allowed here is a direct reference to
578 switch (ObjDesc
->Common
.Type
)
580 case ACPI_TYPE_PACKAGE
:
581 case ACPI_TYPE_STRING
:
582 case ACPI_TYPE_BUFFER
:
583 case ACPI_TYPE_LOCAL_REFERENCE
:
590 ACPI_ERROR ((AE_INFO
,
591 "Needed [Buffer/String/Package/Reference], found [%s] %p",
592 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
594 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
598 case ARGI_COMPLEXOBJ
:
600 /* Need a buffer or package or (ACPI 2.0) String */
602 switch (ObjDesc
->Common
.Type
)
604 case ACPI_TYPE_PACKAGE
:
605 case ACPI_TYPE_STRING
:
606 case ACPI_TYPE_BUFFER
:
613 ACPI_ERROR ((AE_INFO
,
614 "Needed [Buffer/String/Package], found [%s] %p",
615 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
617 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
621 case ARGI_REGION_OR_BUFFER
: /* Used by Load() only */
624 * Need an operand of type REGION or a BUFFER
625 * (which could be a resolved region field)
627 switch (ObjDesc
->Common
.Type
)
629 case ACPI_TYPE_BUFFER
:
630 case ACPI_TYPE_REGION
:
637 ACPI_ERROR ((AE_INFO
,
638 "Needed [Region/Buffer], found [%s] %p",
639 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
641 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
645 case ARGI_DATAREFOBJ
:
647 /* Used by the Store() operator only */
649 switch (ObjDesc
->Common
.Type
)
651 case ACPI_TYPE_INTEGER
:
652 case ACPI_TYPE_PACKAGE
:
653 case ACPI_TYPE_STRING
:
654 case ACPI_TYPE_BUFFER
:
655 case ACPI_TYPE_BUFFER_FIELD
:
656 case ACPI_TYPE_LOCAL_REFERENCE
:
657 case ACPI_TYPE_LOCAL_REGION_FIELD
:
658 case ACPI_TYPE_LOCAL_BANK_FIELD
:
659 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
660 case ACPI_TYPE_DDB_HANDLE
:
667 if (AcpiGbl_EnableInterpreterSlack
)
670 * Enable original behavior of Store(), allowing any
671 * and all objects as the source operand. The ACPI
672 * spec does not allow this, however.
677 if (TargetOp
== AML_DEBUG_OP
)
679 /* Allow store of any object to the Debug object */
684 ACPI_ERROR ((AE_INFO
,
685 "Needed Integer/Buffer/String/Package/Ref/Ddb]"
687 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
689 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
697 ACPI_ERROR ((AE_INFO
,
698 "Internal - Unknown ARGI (required operand) type 0x%X",
701 return_ACPI_STATUS (AE_BAD_PARAMETER
);
705 * Make sure that the original object was resolved to the
706 * required object type (Simple cases only).
708 Status
= AcpiExCheckObjectType (
709 TypeNeeded
, (*StackPtr
)->Common
.Type
, *StackPtr
);
710 if (ACPI_FAILURE (Status
))
712 return_ACPI_STATUS (Status
);
717 * If more operands needed, decrement StackPtr to point
718 * to next operand on stack
720 if (GET_CURRENT_ARG_TYPE (ArgTypes
))
726 ACPI_DUMP_OPERANDS (WalkState
->Operands
,
727 AcpiPsGetOpcodeName (Opcode
), WalkState
->NumOperands
);
729 return_ACPI_STATUS (Status
);