2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2006, R. Byron Moore
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
46 #include <acpi/amlcode.h>
47 #include <acpi/acparser.h>
48 #include <acpi/acinterp.h>
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME("exresop")
53 /* Local prototypes */
55 acpi_ex_check_object_type(acpi_object_type type_needed,
56 acpi_object_type this_type, void *object);
58 /*******************************************************************************
60 * FUNCTION: acpi_ex_check_object_type
62 * PARAMETERS: type_needed Object type needed
63 * this_type Actual object type
64 * Object Object pointer
68 * DESCRIPTION: Check required type against actual type
70 ******************************************************************************/
73 acpi_ex_check_object_type(acpi_object_type type_needed,
74 acpi_object_type this_type, void *object)
76 ACPI_FUNCTION_ENTRY();
78 if (type_needed == ACPI_TYPE_ANY) {
79 /* All types OK, so we don't perform any typechecks */
84 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
86 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
87 * objects and thus allow them to be targets. (As per the ACPI
88 * specification, a store to a constant is a noop.)
90 if ((this_type == ACPI_TYPE_INTEGER) &&
91 (((union acpi_operand_object *)object)->common.
92 flags & AOPOBJ_AML_CONSTANT)) {
97 if (type_needed != this_type) {
98 ACPI_REPORT_ERROR(("Needed type [%s], found [%s] %p\n",
99 acpi_ut_get_type_name(type_needed),
100 acpi_ut_get_type_name(this_type), object));
102 return (AE_AML_OPERAND_TYPE);
108 /*******************************************************************************
110 * FUNCTION: acpi_ex_resolve_operands
112 * PARAMETERS: Opcode - Opcode being interpreted
113 * stack_ptr - Pointer to the operand stack to be
115 * walk_state - Current state
119 * DESCRIPTION: Convert multiple input operands to the types required by the
122 * Each 5-bit group in arg_types represents one required
123 * operand and indicates the required Type. The corresponding operand
124 * will be converted to the required type if possible, otherwise we
125 * abort with an exception.
127 ******************************************************************************/
130 acpi_ex_resolve_operands(u16 opcode,
131 union acpi_operand_object ** stack_ptr,
132 struct acpi_walk_state * walk_state)
134 union acpi_operand_object *obj_desc;
135 acpi_status status = AE_OK;
139 const struct acpi_opcode_info *op_info;
141 acpi_object_type type_needed;
144 ACPI_FUNCTION_TRACE_U32("ex_resolve_operands", opcode);
146 op_info = acpi_ps_get_opcode_info(opcode);
147 if (op_info->class == AML_CLASS_UNKNOWN) {
148 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
151 arg_types = op_info->runtime_args;
152 if (arg_types == ARGI_INVALID_OPCODE) {
153 ACPI_REPORT_ERROR(("Unknown AML opcode %X\n", opcode));
155 return_ACPI_STATUS(AE_AML_INTERNAL);
158 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
159 "Opcode %X [%s] required_operand_types=%8.8X\n",
160 opcode, op_info->name, arg_types));
163 * Normal exit is with (arg_types == 0) at end of argument list.
164 * Function will return an exception from within the loop upon
165 * finding an entry which is not (or cannot be converted
166 * to) the required type; if stack underflows; or upon
167 * finding a NULL stack entry (which should not happen).
169 while (GET_CURRENT_ARG_TYPE(arg_types)) {
170 if (!stack_ptr || !*stack_ptr) {
171 ACPI_REPORT_ERROR(("Null stack entry at %p\n",
174 return_ACPI_STATUS(AE_AML_INTERNAL);
177 /* Extract useful items */
179 obj_desc = *stack_ptr;
181 /* Decode the descriptor type */
183 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
184 case ACPI_DESC_TYPE_NAMED:
189 ((struct acpi_namespace_node *)obj_desc)->type;
192 case ACPI_DESC_TYPE_OPERAND:
194 /* ACPI internal object */
196 object_type = ACPI_GET_OBJECT_TYPE(obj_desc);
198 /* Check for bad acpi_object_type */
200 if (!acpi_ut_valid_object_type(object_type)) {
201 ACPI_REPORT_ERROR(("Bad operand object type [%X]\n", object_type));
203 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
206 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
207 /* Decode the Reference */
209 op_info = acpi_ps_get_opcode_info(opcode);
210 if (op_info->class == AML_CLASS_UNKNOWN) {
211 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
214 switch (obj_desc->reference.opcode) {
216 target_op = AML_DEBUG_OP;
218 /*lint -fallthrough */
225 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
226 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
228 ACPI_DEBUG_ONLY_MEMBERS(ACPI_DEBUG_PRINT
230 "Operand is a Reference, ref_opcode [%s]\n",
231 (acpi_ps_get_opcode_info
239 ACPI_REPORT_ERROR(("Operand is a Reference, Unknown Reference Opcode: %X\n", obj_desc->reference.opcode));
241 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
248 /* Invalid descriptor */
250 ACPI_REPORT_ERROR(("Invalid descriptor %p [%s]\n",
252 acpi_ut_get_descriptor_name
255 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
258 /* Get one argument type, point to the next */
260 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
261 INCREMENT_ARG_LIST(arg_types);
264 * Handle cases where the object does not need to be
265 * resolved to a value
267 switch (this_arg_type) {
268 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
270 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
271 ACPI_DESC_TYPE_OPERAND)
272 && (ACPI_GET_OBJECT_TYPE(obj_desc) ==
275 * String found - the string references a named object and
276 * must be resolved to a node
282 * Else not a string - fall through to the normal Reference
285 /*lint -fallthrough */
287 case ARGI_REFERENCE: /* References: */
288 case ARGI_INTEGER_REF:
289 case ARGI_OBJECT_REF:
290 case ARGI_DEVICE_REF:
291 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
292 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
293 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
296 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
297 * A Namespace Node is OK as-is
299 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
300 ACPI_DESC_TYPE_NAMED) {
305 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
306 object_type, obj_desc);
307 if (ACPI_FAILURE(status)) {
308 return_ACPI_STATUS(status);
311 if (obj_desc->reference.opcode == AML_NAME_OP) {
312 /* Convert a named reference to the actual named object */
314 temp_node = obj_desc->reference.object;
315 acpi_ut_remove_reference(obj_desc);
316 (*stack_ptr) = temp_node;
320 case ARGI_DATAREFOBJ: /* Store operator only */
323 * We don't want to resolve index_op reference objects during
324 * a store because this would be an implicit de_ref_of operation.
325 * Instead, we just want to store the reference object.
326 * -- All others must be resolved below.
328 if ((opcode == AML_STORE_OP) &&
329 (ACPI_GET_OBJECT_TYPE(*stack_ptr) ==
330 ACPI_TYPE_LOCAL_REFERENCE)
331 && ((*stack_ptr)->reference.opcode ==
338 /* All cases covered above */
343 * Resolve this object to a value
345 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
346 if (ACPI_FAILURE(status)) {
347 return_ACPI_STATUS(status);
350 /* Get the resolved object */
352 obj_desc = *stack_ptr;
355 * Check the resulting object (value) type
357 switch (this_arg_type) {
359 * For the simple cases, only one type of resolved object
364 /* Need an operand of type ACPI_TYPE_MUTEX */
366 type_needed = ACPI_TYPE_MUTEX;
371 /* Need an operand of type ACPI_TYPE_EVENT */
373 type_needed = ACPI_TYPE_EVENT;
376 case ARGI_PACKAGE: /* Package */
378 /* Need an operand of type ACPI_TYPE_PACKAGE */
380 type_needed = ACPI_TYPE_PACKAGE;
385 /* Any operand type will do */
387 type_needed = ACPI_TYPE_ANY;
392 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
394 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
398 * The more complex cases allow multiple resolved object types
403 * Need an operand of type ACPI_TYPE_INTEGER,
404 * But we can implicitly convert from a STRING or BUFFER
405 * Aka - "Implicit Source Operand Conversion"
408 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
409 if (ACPI_FAILURE(status)) {
410 if (status == AE_TYPE) {
411 ACPI_REPORT_ERROR(("Needed [Integer/String/Buffer], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
413 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
416 return_ACPI_STATUS(status);
419 if (obj_desc != *stack_ptr) {
420 acpi_ut_remove_reference(obj_desc);
427 * Need an operand of type ACPI_TYPE_BUFFER,
428 * But we can implicitly convert from a STRING or INTEGER
429 * Aka - "Implicit Source Operand Conversion"
431 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
432 if (ACPI_FAILURE(status)) {
433 if (status == AE_TYPE) {
434 ACPI_REPORT_ERROR(("Needed [Integer/String/Buffer], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
436 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
439 return_ACPI_STATUS(status);
442 if (obj_desc != *stack_ptr) {
443 acpi_ut_remove_reference(obj_desc);
450 * Need an operand of type ACPI_TYPE_STRING,
451 * But we can implicitly convert from a BUFFER or INTEGER
452 * Aka - "Implicit Source Operand Conversion"
454 status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
455 ACPI_IMPLICIT_CONVERT_HEX);
456 if (ACPI_FAILURE(status)) {
457 if (status == AE_TYPE) {
458 ACPI_REPORT_ERROR(("Needed [Integer/String/Buffer], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
460 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
463 return_ACPI_STATUS(status);
466 if (obj_desc != *stack_ptr) {
467 acpi_ut_remove_reference(obj_desc);
471 case ARGI_COMPUTEDATA:
473 /* Need an operand of type INTEGER, STRING or BUFFER */
475 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
476 case ACPI_TYPE_INTEGER:
477 case ACPI_TYPE_STRING:
478 case ACPI_TYPE_BUFFER:
484 ACPI_REPORT_ERROR(("Needed [Integer/String/Buffer], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
486 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
490 case ARGI_BUFFER_OR_STRING:
492 /* Need an operand of type STRING or BUFFER */
494 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
495 case ACPI_TYPE_STRING:
496 case ACPI_TYPE_BUFFER:
501 case ACPI_TYPE_INTEGER:
503 /* Highest priority conversion is to type Buffer */
506 acpi_ex_convert_to_buffer(obj_desc,
508 if (ACPI_FAILURE(status)) {
509 return_ACPI_STATUS(status);
512 if (obj_desc != *stack_ptr) {
513 acpi_ut_remove_reference(obj_desc);
518 ACPI_REPORT_ERROR(("Needed [Integer/String/Buffer], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
520 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
524 case ARGI_DATAOBJECT:
526 * ARGI_DATAOBJECT is only used by the size_of operator.
527 * Need a buffer, string, package, or ref_of reference.
529 * The only reference allowed here is a direct reference to
532 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
533 case ACPI_TYPE_PACKAGE:
534 case ACPI_TYPE_STRING:
535 case ACPI_TYPE_BUFFER:
536 case ACPI_TYPE_LOCAL_REFERENCE:
542 ACPI_REPORT_ERROR(("Needed [Buffer/String/Package/Reference], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
544 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
548 case ARGI_COMPLEXOBJ:
550 /* Need a buffer or package or (ACPI 2.0) String */
552 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
553 case ACPI_TYPE_PACKAGE:
554 case ACPI_TYPE_STRING:
555 case ACPI_TYPE_BUFFER:
561 ACPI_REPORT_ERROR(("Needed [Buffer/String/Package], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
563 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
567 case ARGI_REGION_OR_FIELD:
569 /* Need an operand of type REGION or a FIELD in a region */
571 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
572 case ACPI_TYPE_REGION:
573 case ACPI_TYPE_LOCAL_REGION_FIELD:
574 case ACPI_TYPE_LOCAL_BANK_FIELD:
575 case ACPI_TYPE_LOCAL_INDEX_FIELD:
581 ACPI_REPORT_ERROR(("Needed [Region/region_field], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
583 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
587 case ARGI_DATAREFOBJ:
589 /* Used by the Store() operator only */
591 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
592 case ACPI_TYPE_INTEGER:
593 case ACPI_TYPE_PACKAGE:
594 case ACPI_TYPE_STRING:
595 case ACPI_TYPE_BUFFER:
596 case ACPI_TYPE_BUFFER_FIELD:
597 case ACPI_TYPE_LOCAL_REFERENCE:
598 case ACPI_TYPE_LOCAL_REGION_FIELD:
599 case ACPI_TYPE_LOCAL_BANK_FIELD:
600 case ACPI_TYPE_LOCAL_INDEX_FIELD:
601 case ACPI_TYPE_DDB_HANDLE:
608 if (acpi_gbl_enable_interpreter_slack) {
610 * Enable original behavior of Store(), allowing any and all
611 * objects as the source operand. The ACPI spec does not
612 * allow this, however.
617 if (target_op == AML_DEBUG_OP) {
618 /* Allow store of any object to the Debug object */
623 ACPI_REPORT_ERROR(("Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n", acpi_ut_get_object_type_name(obj_desc), obj_desc));
625 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
633 ACPI_REPORT_ERROR(("Internal - Unknown ARGI (required operand) type %X\n", this_arg_type));
635 return_ACPI_STATUS(AE_BAD_PARAMETER);
639 * Make sure that the original object was resolved to the
640 * required object type (Simple cases only).
642 status = acpi_ex_check_object_type(type_needed,
644 (*stack_ptr), *stack_ptr);
645 if (ACPI_FAILURE(status)) {
646 return_ACPI_STATUS(status);
651 * If more operands needed, decrement stack_ptr to point
652 * to next operand on stack
654 if (GET_CURRENT_ARG_TYPE(arg_types)) {
659 return_ACPI_STATUS(status);