1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
6 * Copyright (C) 2000 - 2022, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
17 #define _COMPONENT ACPI_EXECUTER
18 ACPI_MODULE_NAME("exresop")
20 /* Local prototypes */
22 acpi_ex_check_object_type(acpi_object_type type_needed,
23 acpi_object_type this_type, void *object);
25 /*******************************************************************************
27 * FUNCTION: acpi_ex_check_object_type
29 * PARAMETERS: type_needed Object type needed
30 * this_type Actual object type
31 * Object Object pointer
35 * DESCRIPTION: Check required type against actual type
37 ******************************************************************************/
40 acpi_ex_check_object_type(acpi_object_type type_needed,
41 acpi_object_type this_type, void *object)
43 ACPI_FUNCTION_ENTRY();
45 if (type_needed == ACPI_TYPE_ANY) {
47 /* All types OK, so we don't perform any typechecks */
52 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
54 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
55 * objects and thus allow them to be targets. (As per the ACPI
56 * specification, a store to a constant is a noop.)
58 if ((this_type == ACPI_TYPE_INTEGER) &&
59 (((union acpi_operand_object *)object)->common.flags &
60 AOPOBJ_AML_CONSTANT)) {
65 if (type_needed != this_type) {
67 "Needed type [%s], found [%s] %p",
68 acpi_ut_get_type_name(type_needed),
69 acpi_ut_get_type_name(this_type), object));
71 return (AE_AML_OPERAND_TYPE);
77 /*******************************************************************************
79 * FUNCTION: acpi_ex_resolve_operands
81 * PARAMETERS: opcode - Opcode being interpreted
82 * stack_ptr - Pointer to the operand stack to be
84 * walk_state - Current state
88 * DESCRIPTION: Convert multiple input operands to the types required by the
91 * Each 5-bit group in arg_types represents one required
92 * operand and indicates the required Type. The corresponding operand
93 * will be converted to the required type if possible, otherwise we
94 * abort with an exception.
96 ******************************************************************************/
99 acpi_ex_resolve_operands(u16 opcode,
100 union acpi_operand_object **stack_ptr,
101 struct acpi_walk_state *walk_state)
103 union acpi_operand_object *obj_desc;
104 acpi_status status = AE_OK;
107 const struct acpi_opcode_info *op_info;
109 acpi_object_type type_needed;
112 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
114 op_info = acpi_ps_get_opcode_info(opcode);
115 if (op_info->class == AML_CLASS_UNKNOWN) {
116 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
119 arg_types = op_info->runtime_args;
120 if (arg_types == ARGI_INVALID_OPCODE) {
121 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode));
123 return_ACPI_STATUS(AE_AML_INTERNAL);
126 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
127 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
128 opcode, op_info->name, arg_types));
131 * Normal exit is with (arg_types == 0) at end of argument list.
132 * Function will return an exception from within the loop upon
133 * finding an entry which is not (or cannot be converted
134 * to) the required type; if stack underflows; or upon
135 * finding a NULL stack entry (which should not happen).
137 while (GET_CURRENT_ARG_TYPE(arg_types)) {
138 if (!stack_ptr || !*stack_ptr) {
139 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
142 return_ACPI_STATUS(AE_AML_INTERNAL);
145 /* Extract useful items */
147 obj_desc = *stack_ptr;
149 /* Decode the descriptor type */
151 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
152 case ACPI_DESC_TYPE_NAMED:
157 ((struct acpi_namespace_node *)obj_desc)->type;
160 * Resolve an alias object. The construction of these objects
161 * guarantees that there is only one level of alias indirection;
162 * thus, the attached object is always the aliased namespace node
164 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
165 obj_desc = acpi_ns_get_attached_object((struct
169 *stack_ptr = obj_desc;
171 ((struct acpi_namespace_node *)obj_desc)->
176 case ACPI_DESC_TYPE_OPERAND:
178 /* ACPI internal object */
180 object_type = obj_desc->common.type;
182 /* Check for bad acpi_object_type */
184 if (!acpi_ut_valid_object_type(object_type)) {
186 "Bad operand object type [0x%X]",
189 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
192 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
194 /* Validate the Reference */
196 switch (obj_desc->reference.class) {
197 case ACPI_REFCLASS_DEBUG:
199 target_op = AML_DEBUG_OP;
203 case ACPI_REFCLASS_ARG:
204 case ACPI_REFCLASS_LOCAL:
205 case ACPI_REFCLASS_INDEX:
206 case ACPI_REFCLASS_REFOF:
207 case ACPI_REFCLASS_TABLE: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
208 case ACPI_REFCLASS_NAME: /* Reference to a named object */
210 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
211 "Operand is a Reference, Class [%s] %2.2X\n",
212 acpi_ut_get_reference_name
221 "Unknown Reference Class 0x%2.2X in %p",
222 obj_desc->reference.class,
225 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
232 /* Invalid descriptor */
234 ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
236 acpi_ut_get_descriptor_name(obj_desc)));
238 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
241 /* Get one argument type, point to the next */
243 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
244 INCREMENT_ARG_LIST(arg_types);
247 * Handle cases where the object does not need to be
248 * resolved to a value
250 switch (this_arg_type) {
251 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
253 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
254 ACPI_DESC_TYPE_OPERAND) &&
255 (obj_desc->common.type == ACPI_TYPE_STRING)) {
257 * String found - the string references a named object and
258 * must be resolved to a node
264 * Else not a string - fall through to the normal Reference
269 case ARGI_REFERENCE: /* References: */
270 case ARGI_INTEGER_REF:
271 case ARGI_OBJECT_REF:
272 case ARGI_DEVICE_REF:
273 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
274 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
275 case ARGI_SIMPLE_TARGET: /* Name, Local, or arg - no implicit conversion */
276 case ARGI_STORE_TARGET:
279 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
280 * A Namespace Node is OK as-is
282 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
283 ACPI_DESC_TYPE_NAMED) {
288 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
289 object_type, obj_desc);
290 if (ACPI_FAILURE(status)) {
291 return_ACPI_STATUS(status);
295 case ARGI_DATAREFOBJ: /* Store operator only */
297 * We don't want to resolve index_op reference objects during
298 * a store because this would be an implicit de_ref_of operation.
299 * Instead, we just want to store the reference object.
300 * -- All others must be resolved below.
302 if ((opcode == AML_STORE_OP) &&
303 ((*stack_ptr)->common.type ==
304 ACPI_TYPE_LOCAL_REFERENCE)
305 && ((*stack_ptr)->reference.class ==
306 ACPI_REFCLASS_INDEX)) {
313 /* All cases covered above */
319 * Resolve this object to a value
321 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
322 if (ACPI_FAILURE(status)) {
323 return_ACPI_STATUS(status);
326 /* Get the resolved object */
328 obj_desc = *stack_ptr;
331 * Check the resulting object (value) type
333 switch (this_arg_type) {
335 * For the simple cases, only one type of resolved object
340 /* Need an operand of type ACPI_TYPE_MUTEX */
342 type_needed = ACPI_TYPE_MUTEX;
347 /* Need an operand of type ACPI_TYPE_EVENT */
349 type_needed = ACPI_TYPE_EVENT;
352 case ARGI_PACKAGE: /* Package */
354 /* Need an operand of type ACPI_TYPE_PACKAGE */
356 type_needed = ACPI_TYPE_PACKAGE;
361 /* Any operand type will do */
363 type_needed = ACPI_TYPE_ANY;
368 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
370 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
374 * The more complex cases allow multiple resolved object types
379 * Need an operand of type ACPI_TYPE_INTEGER, but we can
380 * implicitly convert from a STRING or BUFFER.
382 * Known as "Implicit Source Operand Conversion"
384 status = acpi_ex_convert_to_integer(obj_desc, stack_ptr,
385 ACPI_IMPLICIT_CONVERSION);
386 if (ACPI_FAILURE(status)) {
387 if (status == AE_TYPE) {
389 "Needed [Integer/String/Buffer], found [%s] %p",
390 acpi_ut_get_object_type_name
391 (obj_desc), obj_desc));
393 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
396 return_ACPI_STATUS(status);
399 if (obj_desc != *stack_ptr) {
400 acpi_ut_remove_reference(obj_desc);
406 * Need an operand of type ACPI_TYPE_BUFFER,
407 * But we can implicitly convert from a STRING or INTEGER
408 * aka - "Implicit Source Operand Conversion"
410 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
411 if (ACPI_FAILURE(status)) {
412 if (status == AE_TYPE) {
414 "Needed [Integer/String/Buffer], found [%s] %p",
415 acpi_ut_get_object_type_name
416 (obj_desc), obj_desc));
418 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
421 return_ACPI_STATUS(status);
424 if (obj_desc != *stack_ptr) {
425 acpi_ut_remove_reference(obj_desc);
431 * Need an operand of type ACPI_TYPE_STRING,
432 * But we can implicitly convert from a BUFFER or INTEGER
433 * aka - "Implicit Source Operand Conversion"
436 acpi_ex_convert_to_string(obj_desc, stack_ptr,
437 ACPI_IMPLICIT_CONVERT_HEX);
438 if (ACPI_FAILURE(status)) {
439 if (status == AE_TYPE) {
441 "Needed [Integer/String/Buffer], found [%s] %p",
442 acpi_ut_get_object_type_name
443 (obj_desc), obj_desc));
445 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
448 return_ACPI_STATUS(status);
451 if (obj_desc != *stack_ptr) {
452 acpi_ut_remove_reference(obj_desc);
456 case ARGI_COMPUTEDATA:
458 /* Need an operand of type INTEGER, STRING or BUFFER */
460 switch (obj_desc->common.type) {
461 case ACPI_TYPE_INTEGER:
462 case ACPI_TYPE_STRING:
463 case ACPI_TYPE_BUFFER:
470 "Needed [Integer/String/Buffer], found [%s] %p",
471 acpi_ut_get_object_type_name
472 (obj_desc), obj_desc));
474 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
478 case ARGI_BUFFER_OR_STRING:
480 /* Need an operand of type STRING or BUFFER */
482 switch (obj_desc->common.type) {
483 case ACPI_TYPE_STRING:
484 case ACPI_TYPE_BUFFER:
489 case ACPI_TYPE_INTEGER:
491 /* Highest priority conversion is to type Buffer */
494 acpi_ex_convert_to_buffer(obj_desc,
496 if (ACPI_FAILURE(status)) {
497 return_ACPI_STATUS(status);
500 if (obj_desc != *stack_ptr) {
501 acpi_ut_remove_reference(obj_desc);
507 "Needed [Integer/String/Buffer], found [%s] %p",
508 acpi_ut_get_object_type_name
509 (obj_desc), obj_desc));
511 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
515 case ARGI_DATAOBJECT:
517 * ARGI_DATAOBJECT is only used by the size_of operator.
518 * Need a buffer, string, package, or ref_of reference.
520 * The only reference allowed here is a direct reference to
523 switch (obj_desc->common.type) {
524 case ACPI_TYPE_PACKAGE:
525 case ACPI_TYPE_STRING:
526 case ACPI_TYPE_BUFFER:
527 case ACPI_TYPE_LOCAL_REFERENCE:
535 "Needed [Buffer/String/Package/Reference], found [%s] %p",
536 acpi_ut_get_object_type_name
537 (obj_desc), obj_desc));
539 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
543 case ARGI_COMPLEXOBJ:
545 /* Need a buffer or package or (ACPI 2.0) String */
547 switch (obj_desc->common.type) {
548 case ACPI_TYPE_PACKAGE:
549 case ACPI_TYPE_STRING:
550 case ACPI_TYPE_BUFFER:
558 "Needed [Buffer/String/Package], found [%s] %p",
559 acpi_ut_get_object_type_name
560 (obj_desc), obj_desc));
562 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
566 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
569 * Need an operand of type REGION or a BUFFER
570 * (which could be a resolved region field)
572 switch (obj_desc->common.type) {
573 case ACPI_TYPE_BUFFER:
574 case ACPI_TYPE_REGION:
582 "Needed [Region/Buffer], found [%s] %p",
583 acpi_ut_get_object_type_name
584 (obj_desc), obj_desc));
586 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
590 case ARGI_DATAREFOBJ:
592 /* Used by the Store() operator only */
594 switch (obj_desc->common.type) {
595 case ACPI_TYPE_INTEGER:
596 case ACPI_TYPE_PACKAGE:
597 case ACPI_TYPE_STRING:
598 case ACPI_TYPE_BUFFER:
599 case ACPI_TYPE_BUFFER_FIELD:
600 case ACPI_TYPE_LOCAL_REFERENCE:
601 case ACPI_TYPE_LOCAL_REGION_FIELD:
602 case ACPI_TYPE_LOCAL_BANK_FIELD:
603 case ACPI_TYPE_LOCAL_INDEX_FIELD:
604 case ACPI_TYPE_DDB_HANDLE:
611 if (acpi_gbl_enable_interpreter_slack) {
613 * Enable original behavior of Store(), allowing any
614 * and all objects as the source operand. The ACPI
615 * spec does not allow this, however.
620 if (target_op == AML_DEBUG_OP) {
622 /* Allow store of any object to the Debug object */
628 "Needed Integer/Buffer/String/Package/Ref/Ddb]"
630 acpi_ut_get_object_type_name
631 (obj_desc), obj_desc));
633 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
642 "Internal - Unknown ARGI (required operand) type 0x%X",
645 return_ACPI_STATUS(AE_BAD_PARAMETER);
649 * Make sure that the original object was resolved to the
650 * required object type (Simple cases only).
653 acpi_ex_check_object_type(type_needed,
654 (*stack_ptr)->common.type,
656 if (ACPI_FAILURE(status)) {
657 return_ACPI_STATUS(status);
662 * If more operands needed, decrement stack_ptr to point
663 * to next operand on stack
665 if (GET_CURRENT_ARG_TYPE(arg_types)) {
670 ACPI_DUMP_OPERANDS(walk_state->operands,
671 acpi_ps_get_opcode_name(opcode),
672 walk_state->num_operands);
674 return_ACPI_STATUS(status);