2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
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>
49 #include <acpi/acnamesp.h>
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME("exresop")
54 /* Local prototypes */
56 acpi_ex_check_object_type(acpi_object_type type_needed,
57 acpi_object_type this_type, void *object);
59 /*******************************************************************************
61 * FUNCTION: acpi_ex_check_object_type
63 * PARAMETERS: type_needed Object type needed
64 * this_type Actual object type
65 * Object Object pointer
69 * DESCRIPTION: Check required type against actual type
71 ******************************************************************************/
74 acpi_ex_check_object_type(acpi_object_type type_needed,
75 acpi_object_type this_type, void *object)
77 ACPI_FUNCTION_ENTRY();
79 if (type_needed == ACPI_TYPE_ANY) {
81 /* All types OK, so we don't perform any typechecks */
86 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
88 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
89 * objects and thus allow them to be targets. (As per the ACPI
90 * specification, a store to a constant is a noop.)
92 if ((this_type == ACPI_TYPE_INTEGER) &&
93 (((union acpi_operand_object *)object)->common.
94 flags & AOPOBJ_AML_CONSTANT)) {
99 if (type_needed != this_type) {
101 "Needed type [%s], found [%s] %p",
102 acpi_ut_get_type_name(type_needed),
103 acpi_ut_get_type_name(this_type), object));
105 return (AE_AML_OPERAND_TYPE);
111 /*******************************************************************************
113 * FUNCTION: acpi_ex_resolve_operands
115 * PARAMETERS: Opcode - Opcode being interpreted
116 * stack_ptr - Pointer to the operand stack to be
118 * walk_state - Current state
122 * DESCRIPTION: Convert multiple input operands to the types required by the
125 * Each 5-bit group in arg_types represents one required
126 * operand and indicates the required Type. The corresponding operand
127 * will be converted to the required type if possible, otherwise we
128 * abort with an exception.
130 ******************************************************************************/
133 acpi_ex_resolve_operands(u16 opcode,
134 union acpi_operand_object ** stack_ptr,
135 struct acpi_walk_state * walk_state)
137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK;
141 const struct acpi_opcode_info *op_info;
143 acpi_object_type type_needed;
146 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
148 op_info = acpi_ps_get_opcode_info(opcode);
149 if (op_info->class == AML_CLASS_UNKNOWN) {
150 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
153 arg_types = op_info->runtime_args;
154 if (arg_types == ARGI_INVALID_OPCODE) {
155 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", opcode));
157 return_ACPI_STATUS(AE_AML_INTERNAL);
160 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
161 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
162 opcode, op_info->name, arg_types));
165 * Normal exit is with (arg_types == 0) at end of argument list.
166 * Function will return an exception from within the loop upon
167 * finding an entry which is not (or cannot be converted
168 * to) the required type; if stack underflows; or upon
169 * finding a NULL stack entry (which should not happen).
171 while (GET_CURRENT_ARG_TYPE(arg_types)) {
172 if (!stack_ptr || !*stack_ptr) {
173 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
176 return_ACPI_STATUS(AE_AML_INTERNAL);
179 /* Extract useful items */
181 obj_desc = *stack_ptr;
183 /* Decode the descriptor type */
185 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
186 case ACPI_DESC_TYPE_NAMED:
191 ((struct acpi_namespace_node *)obj_desc)->type;
194 * Resolve an alias object. The construction of these objects
195 * guarantees that there is only one level of alias indirection;
196 * thus, the attached object is always the aliased namespace node
198 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
200 acpi_ns_get_attached_object((struct
203 *stack_ptr = obj_desc;
205 ((struct acpi_namespace_node *)obj_desc)->
210 case ACPI_DESC_TYPE_OPERAND:
212 /* ACPI internal object */
214 object_type = ACPI_GET_OBJECT_TYPE(obj_desc);
216 /* Check for bad acpi_object_type */
218 if (!acpi_ut_valid_object_type(object_type)) {
220 "Bad operand object type [%X]",
223 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
226 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
228 /* Decode the Reference */
230 op_info = acpi_ps_get_opcode_info(opcode);
231 if (op_info->class == AML_CLASS_UNKNOWN) {
232 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
235 switch (obj_desc->reference.opcode) {
237 target_op = AML_DEBUG_OP;
239 /*lint -fallthrough */
245 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
246 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
248 ACPI_DEBUG_ONLY_MEMBERS(ACPI_DEBUG_PRINT
250 "Operand is a Reference, RefOpcode [%s]\n",
251 (acpi_ps_get_opcode_info
260 "Operand is a Reference, Unknown Reference Opcode: %X",
264 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
271 /* Invalid descriptor */
274 "Invalid descriptor %p [%s]",
276 acpi_ut_get_descriptor_name(obj_desc)));
278 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
281 /* Get one argument type, point to the next */
283 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
284 INCREMENT_ARG_LIST(arg_types);
287 * Handle cases where the object does not need to be
288 * resolved to a value
290 switch (this_arg_type) {
291 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
293 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
294 ACPI_DESC_TYPE_OPERAND)
295 && (ACPI_GET_OBJECT_TYPE(obj_desc) ==
298 * String found - the string references a named object and
299 * must be resolved to a node
305 * Else not a string - fall through to the normal Reference
308 /*lint -fallthrough */
310 case ARGI_REFERENCE: /* References: */
311 case ARGI_INTEGER_REF:
312 case ARGI_OBJECT_REF:
313 case ARGI_DEVICE_REF:
314 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
315 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
316 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
319 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
320 * A Namespace Node is OK as-is
322 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
323 ACPI_DESC_TYPE_NAMED) {
328 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
329 object_type, obj_desc);
330 if (ACPI_FAILURE(status)) {
331 return_ACPI_STATUS(status);
335 case ARGI_DATAREFOBJ: /* Store operator only */
338 * We don't want to resolve index_op reference objects during
339 * a store because this would be an implicit de_ref_of operation.
340 * Instead, we just want to store the reference object.
341 * -- All others must be resolved below.
343 if ((opcode == AML_STORE_OP) &&
344 (ACPI_GET_OBJECT_TYPE(*stack_ptr) ==
345 ACPI_TYPE_LOCAL_REFERENCE)
346 && ((*stack_ptr)->reference.opcode == AML_INDEX_OP)) {
352 /* All cases covered above */
357 * Resolve this object to a value
359 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
360 if (ACPI_FAILURE(status)) {
361 return_ACPI_STATUS(status);
364 /* Get the resolved object */
366 obj_desc = *stack_ptr;
369 * Check the resulting object (value) type
371 switch (this_arg_type) {
373 * For the simple cases, only one type of resolved object
378 /* Need an operand of type ACPI_TYPE_MUTEX */
380 type_needed = ACPI_TYPE_MUTEX;
385 /* Need an operand of type ACPI_TYPE_EVENT */
387 type_needed = ACPI_TYPE_EVENT;
390 case ARGI_PACKAGE: /* Package */
392 /* Need an operand of type ACPI_TYPE_PACKAGE */
394 type_needed = ACPI_TYPE_PACKAGE;
399 /* Any operand type will do */
401 type_needed = ACPI_TYPE_ANY;
406 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
408 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
412 * The more complex cases allow multiple resolved object types
417 * Need an operand of type ACPI_TYPE_INTEGER,
418 * But we can implicitly convert from a STRING or BUFFER
419 * Aka - "Implicit Source Operand Conversion"
422 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
423 if (ACPI_FAILURE(status)) {
424 if (status == AE_TYPE) {
426 "Needed [Integer/String/Buffer], found [%s] %p",
427 acpi_ut_get_object_type_name
428 (obj_desc), obj_desc));
430 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
433 return_ACPI_STATUS(status);
436 if (obj_desc != *stack_ptr) {
437 acpi_ut_remove_reference(obj_desc);
444 * Need an operand of type ACPI_TYPE_BUFFER,
445 * But we can implicitly convert from a STRING or INTEGER
446 * Aka - "Implicit Source Operand Conversion"
448 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
449 if (ACPI_FAILURE(status)) {
450 if (status == AE_TYPE) {
452 "Needed [Integer/String/Buffer], found [%s] %p",
453 acpi_ut_get_object_type_name
454 (obj_desc), obj_desc));
456 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
459 return_ACPI_STATUS(status);
462 if (obj_desc != *stack_ptr) {
463 acpi_ut_remove_reference(obj_desc);
470 * Need an operand of type ACPI_TYPE_STRING,
471 * But we can implicitly convert from a BUFFER or INTEGER
472 * Aka - "Implicit Source Operand Conversion"
474 status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
475 ACPI_IMPLICIT_CONVERT_HEX);
476 if (ACPI_FAILURE(status)) {
477 if (status == AE_TYPE) {
479 "Needed [Integer/String/Buffer], found [%s] %p",
480 acpi_ut_get_object_type_name
481 (obj_desc), obj_desc));
483 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
486 return_ACPI_STATUS(status);
489 if (obj_desc != *stack_ptr) {
490 acpi_ut_remove_reference(obj_desc);
494 case ARGI_COMPUTEDATA:
496 /* Need an operand of type INTEGER, STRING or BUFFER */
498 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
499 case ACPI_TYPE_INTEGER:
500 case ACPI_TYPE_STRING:
501 case ACPI_TYPE_BUFFER:
508 "Needed [Integer/String/Buffer], found [%s] %p",
509 acpi_ut_get_object_type_name
510 (obj_desc), obj_desc));
512 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
516 case ARGI_BUFFER_OR_STRING:
518 /* Need an operand of type STRING or BUFFER */
520 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
521 case ACPI_TYPE_STRING:
522 case ACPI_TYPE_BUFFER:
527 case ACPI_TYPE_INTEGER:
529 /* Highest priority conversion is to type Buffer */
532 acpi_ex_convert_to_buffer(obj_desc,
534 if (ACPI_FAILURE(status)) {
535 return_ACPI_STATUS(status);
538 if (obj_desc != *stack_ptr) {
539 acpi_ut_remove_reference(obj_desc);
545 "Needed [Integer/String/Buffer], found [%s] %p",
546 acpi_ut_get_object_type_name
547 (obj_desc), obj_desc));
549 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
553 case ARGI_DATAOBJECT:
555 * ARGI_DATAOBJECT is only used by the size_of operator.
556 * Need a buffer, string, package, or ref_of reference.
558 * The only reference allowed here is a direct reference to
561 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
562 case ACPI_TYPE_PACKAGE:
563 case ACPI_TYPE_STRING:
564 case ACPI_TYPE_BUFFER:
565 case ACPI_TYPE_LOCAL_REFERENCE:
572 "Needed [Buffer/String/Package/Reference], found [%s] %p",
573 acpi_ut_get_object_type_name
574 (obj_desc), obj_desc));
576 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
580 case ARGI_COMPLEXOBJ:
582 /* Need a buffer or package or (ACPI 2.0) String */
584 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
585 case ACPI_TYPE_PACKAGE:
586 case ACPI_TYPE_STRING:
587 case ACPI_TYPE_BUFFER:
594 "Needed [Buffer/String/Package], found [%s] %p",
595 acpi_ut_get_object_type_name
596 (obj_desc), obj_desc));
598 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
602 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
604 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
606 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
607 case ACPI_TYPE_BUFFER:
608 case ACPI_TYPE_REGION:
615 "Needed [Region/Buffer], found [%s] %p",
616 acpi_ut_get_object_type_name
617 (obj_desc), obj_desc));
619 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
623 case ARGI_DATAREFOBJ:
625 /* Used by the Store() operator only */
627 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
628 case ACPI_TYPE_INTEGER:
629 case ACPI_TYPE_PACKAGE:
630 case ACPI_TYPE_STRING:
631 case ACPI_TYPE_BUFFER:
632 case ACPI_TYPE_BUFFER_FIELD:
633 case ACPI_TYPE_LOCAL_REFERENCE:
634 case ACPI_TYPE_LOCAL_REGION_FIELD:
635 case ACPI_TYPE_LOCAL_BANK_FIELD:
636 case ACPI_TYPE_LOCAL_INDEX_FIELD:
637 case ACPI_TYPE_DDB_HANDLE:
644 if (acpi_gbl_enable_interpreter_slack) {
646 * Enable original behavior of Store(), allowing any and all
647 * objects as the source operand. The ACPI spec does not
648 * allow this, however.
653 if (target_op == AML_DEBUG_OP) {
655 /* Allow store of any object to the Debug object */
661 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
662 acpi_ut_get_object_type_name
663 (obj_desc), obj_desc));
665 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
674 "Internal - Unknown ARGI (required operand) type %X",
677 return_ACPI_STATUS(AE_BAD_PARAMETER);
681 * Make sure that the original object was resolved to the
682 * required object type (Simple cases only).
684 status = acpi_ex_check_object_type(type_needed,
686 (*stack_ptr), *stack_ptr);
687 if (ACPI_FAILURE(status)) {
688 return_ACPI_STATUS(status);
693 * If more operands needed, decrement stack_ptr to point
694 * to next operand on stack
696 if (GET_CURRENT_ARG_TYPE(arg_types)) {
701 ACPI_DUMP_OPERANDS(walk_state->operands,
702 acpi_ps_get_opcode_name(opcode),
703 walk_state->num_operands);
705 return_ACPI_STATUS(status);