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>
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;
142 const struct acpi_opcode_info *op_info;
144 acpi_object_type type_needed;
147 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
149 op_info = acpi_ps_get_opcode_info(opcode);
150 if (op_info->class == AML_CLASS_UNKNOWN) {
151 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
154 arg_types = op_info->runtime_args;
155 if (arg_types == ARGI_INVALID_OPCODE) {
156 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", opcode));
158 return_ACPI_STATUS(AE_AML_INTERNAL);
161 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
162 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
163 opcode, op_info->name, arg_types));
166 * Normal exit is with (arg_types == 0) at end of argument list.
167 * Function will return an exception from within the loop upon
168 * finding an entry which is not (or cannot be converted
169 * to) the required type; if stack underflows; or upon
170 * finding a NULL stack entry (which should not happen).
172 while (GET_CURRENT_ARG_TYPE(arg_types)) {
173 if (!stack_ptr || !*stack_ptr) {
174 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
177 return_ACPI_STATUS(AE_AML_INTERNAL);
180 /* Extract useful items */
182 obj_desc = *stack_ptr;
184 /* Decode the descriptor type */
186 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
187 case ACPI_DESC_TYPE_NAMED:
192 ((struct acpi_namespace_node *)obj_desc)->type;
195 * Resolve an alias object. The construction of these objects
196 * guarantees that there is only one level of alias indirection;
197 * thus, the attached object is always the aliased namespace node
199 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
201 acpi_ns_get_attached_object((struct
204 *stack_ptr = obj_desc;
206 ((struct acpi_namespace_node *)obj_desc)->
211 case ACPI_DESC_TYPE_OPERAND:
213 /* ACPI internal object */
215 object_type = ACPI_GET_OBJECT_TYPE(obj_desc);
217 /* Check for bad acpi_object_type */
219 if (!acpi_ut_valid_object_type(object_type)) {
221 "Bad operand object type [%X]",
224 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
227 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
229 /* Decode the Reference */
231 op_info = acpi_ps_get_opcode_info(opcode);
232 if (op_info->class == AML_CLASS_UNKNOWN) {
233 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
236 switch (obj_desc->reference.opcode) {
238 target_op = AML_DEBUG_OP;
240 /*lint -fallthrough */
247 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
248 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
250 ACPI_DEBUG_ONLY_MEMBERS(ACPI_DEBUG_PRINT
252 "Operand is a Reference, RefOpcode [%s]\n",
253 (acpi_ps_get_opcode_info
262 "Operand is a Reference, Unknown Reference Opcode: %X",
266 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
273 /* Invalid descriptor */
276 "Invalid descriptor %p [%s]",
278 acpi_ut_get_descriptor_name(obj_desc)));
280 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
283 /* Get one argument type, point to the next */
285 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
286 INCREMENT_ARG_LIST(arg_types);
289 * Handle cases where the object does not need to be
290 * resolved to a value
292 switch (this_arg_type) {
293 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
295 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
296 ACPI_DESC_TYPE_OPERAND)
297 && (ACPI_GET_OBJECT_TYPE(obj_desc) ==
300 * String found - the string references a named object and
301 * must be resolved to a node
307 * Else not a string - fall through to the normal Reference
310 /*lint -fallthrough */
312 case ARGI_REFERENCE: /* References: */
313 case ARGI_INTEGER_REF:
314 case ARGI_OBJECT_REF:
315 case ARGI_DEVICE_REF:
316 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
317 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
318 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
321 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
322 * A Namespace Node is OK as-is
324 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
325 ACPI_DESC_TYPE_NAMED) {
330 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
331 object_type, obj_desc);
332 if (ACPI_FAILURE(status)) {
333 return_ACPI_STATUS(status);
336 if (obj_desc->reference.opcode == AML_NAME_OP) {
338 /* Convert a named reference to the actual named object */
340 temp_node = obj_desc->reference.object;
341 acpi_ut_remove_reference(obj_desc);
342 (*stack_ptr) = temp_node;
346 case ARGI_DATAREFOBJ: /* Store operator only */
349 * We don't want to resolve index_op reference objects during
350 * a store because this would be an implicit de_ref_of operation.
351 * Instead, we just want to store the reference object.
352 * -- All others must be resolved below.
354 if ((opcode == AML_STORE_OP) &&
355 (ACPI_GET_OBJECT_TYPE(*stack_ptr) ==
356 ACPI_TYPE_LOCAL_REFERENCE)
357 && ((*stack_ptr)->reference.opcode ==
364 /* All cases covered above */
369 * Resolve this object to a value
371 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
372 if (ACPI_FAILURE(status)) {
373 return_ACPI_STATUS(status);
376 /* Get the resolved object */
378 obj_desc = *stack_ptr;
381 * Check the resulting object (value) type
383 switch (this_arg_type) {
385 * For the simple cases, only one type of resolved object
390 /* Need an operand of type ACPI_TYPE_MUTEX */
392 type_needed = ACPI_TYPE_MUTEX;
397 /* Need an operand of type ACPI_TYPE_EVENT */
399 type_needed = ACPI_TYPE_EVENT;
402 case ARGI_PACKAGE: /* Package */
404 /* Need an operand of type ACPI_TYPE_PACKAGE */
406 type_needed = ACPI_TYPE_PACKAGE;
411 /* Any operand type will do */
413 type_needed = ACPI_TYPE_ANY;
418 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
420 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
424 * The more complex cases allow multiple resolved object types
429 * Need an operand of type ACPI_TYPE_INTEGER,
430 * But we can implicitly convert from a STRING or BUFFER
431 * Aka - "Implicit Source Operand Conversion"
434 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
435 if (ACPI_FAILURE(status)) {
436 if (status == AE_TYPE) {
438 "Needed [Integer/String/Buffer], found [%s] %p",
439 acpi_ut_get_object_type_name
440 (obj_desc), obj_desc));
442 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
445 return_ACPI_STATUS(status);
448 if (obj_desc != *stack_ptr) {
449 acpi_ut_remove_reference(obj_desc);
456 * Need an operand of type ACPI_TYPE_BUFFER,
457 * But we can implicitly convert from a STRING or INTEGER
458 * Aka - "Implicit Source Operand Conversion"
460 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
461 if (ACPI_FAILURE(status)) {
462 if (status == AE_TYPE) {
464 "Needed [Integer/String/Buffer], found [%s] %p",
465 acpi_ut_get_object_type_name
466 (obj_desc), obj_desc));
468 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
471 return_ACPI_STATUS(status);
474 if (obj_desc != *stack_ptr) {
475 acpi_ut_remove_reference(obj_desc);
482 * Need an operand of type ACPI_TYPE_STRING,
483 * But we can implicitly convert from a BUFFER or INTEGER
484 * Aka - "Implicit Source Operand Conversion"
486 status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
487 ACPI_IMPLICIT_CONVERT_HEX);
488 if (ACPI_FAILURE(status)) {
489 if (status == AE_TYPE) {
491 "Needed [Integer/String/Buffer], found [%s] %p",
492 acpi_ut_get_object_type_name
493 (obj_desc), obj_desc));
495 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
498 return_ACPI_STATUS(status);
501 if (obj_desc != *stack_ptr) {
502 acpi_ut_remove_reference(obj_desc);
506 case ARGI_COMPUTEDATA:
508 /* Need an operand of type INTEGER, STRING or BUFFER */
510 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
511 case ACPI_TYPE_INTEGER:
512 case ACPI_TYPE_STRING:
513 case ACPI_TYPE_BUFFER:
520 "Needed [Integer/String/Buffer], found [%s] %p",
521 acpi_ut_get_object_type_name
522 (obj_desc), obj_desc));
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 (ACPI_GET_OBJECT_TYPE(obj_desc)) {
533 case ACPI_TYPE_STRING:
534 case ACPI_TYPE_BUFFER:
539 case ACPI_TYPE_INTEGER:
541 /* Highest priority conversion is to type Buffer */
544 acpi_ex_convert_to_buffer(obj_desc,
546 if (ACPI_FAILURE(status)) {
547 return_ACPI_STATUS(status);
550 if (obj_desc != *stack_ptr) {
551 acpi_ut_remove_reference(obj_desc);
557 "Needed [Integer/String/Buffer], found [%s] %p",
558 acpi_ut_get_object_type_name
559 (obj_desc), obj_desc));
561 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
565 case ARGI_DATAOBJECT:
567 * ARGI_DATAOBJECT is only used by the size_of operator.
568 * Need a buffer, string, package, or ref_of reference.
570 * The only reference allowed here is a direct reference to
573 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
574 case ACPI_TYPE_PACKAGE:
575 case ACPI_TYPE_STRING:
576 case ACPI_TYPE_BUFFER:
577 case ACPI_TYPE_LOCAL_REFERENCE:
584 "Needed [Buffer/String/Package/Reference], found [%s] %p",
585 acpi_ut_get_object_type_name
586 (obj_desc), obj_desc));
588 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
592 case ARGI_COMPLEXOBJ:
594 /* Need a buffer or package or (ACPI 2.0) String */
596 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
597 case ACPI_TYPE_PACKAGE:
598 case ACPI_TYPE_STRING:
599 case ACPI_TYPE_BUFFER:
606 "Needed [Buffer/String/Package], found [%s] %p",
607 acpi_ut_get_object_type_name
608 (obj_desc), obj_desc));
610 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
614 case ARGI_REGION_OR_FIELD:
616 /* Need an operand of type REGION or a FIELD in a region */
618 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
619 case ACPI_TYPE_REGION:
620 case ACPI_TYPE_LOCAL_REGION_FIELD:
621 case ACPI_TYPE_LOCAL_BANK_FIELD:
622 case ACPI_TYPE_LOCAL_INDEX_FIELD:
629 "Needed [Region/RegionField], found [%s] %p",
630 acpi_ut_get_object_type_name
631 (obj_desc), obj_desc));
633 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
637 case ARGI_DATAREFOBJ:
639 /* Used by the Store() operator only */
641 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
642 case ACPI_TYPE_INTEGER:
643 case ACPI_TYPE_PACKAGE:
644 case ACPI_TYPE_STRING:
645 case ACPI_TYPE_BUFFER:
646 case ACPI_TYPE_BUFFER_FIELD:
647 case ACPI_TYPE_LOCAL_REFERENCE:
648 case ACPI_TYPE_LOCAL_REGION_FIELD:
649 case ACPI_TYPE_LOCAL_BANK_FIELD:
650 case ACPI_TYPE_LOCAL_INDEX_FIELD:
651 case ACPI_TYPE_DDB_HANDLE:
658 if (acpi_gbl_enable_interpreter_slack) {
660 * Enable original behavior of Store(), allowing any and all
661 * objects as the source operand. The ACPI spec does not
662 * allow this, however.
667 if (target_op == AML_DEBUG_OP) {
669 /* Allow store of any object to the Debug object */
675 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
676 acpi_ut_get_object_type_name
677 (obj_desc), obj_desc));
679 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
688 "Internal - Unknown ARGI (required operand) type %X",
691 return_ACPI_STATUS(AE_BAD_PARAMETER);
695 * Make sure that the original object was resolved to the
696 * required object type (Simple cases only).
698 status = acpi_ex_check_object_type(type_needed,
700 (*stack_ptr), *stack_ptr);
701 if (ACPI_FAILURE(status)) {
702 return_ACPI_STATUS(status);
707 * If more operands needed, decrement stack_ptr to point
708 * to next operand on stack
710 if (GET_CURRENT_ARG_TYPE(arg_types)) {
715 return_ACPI_STATUS(status);