MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / acpi / executer / exresop.c
blobd410bd7f1fe3b2e2be8c238f1ccc06a0ca49ee35
2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2004, 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
14 * are met:
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.
31 * NO WARRANTY
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.
46 #include <acpi/acpi.h>
47 #include <acpi/amlcode.h>
48 #include <acpi/acparser.h>
49 #include <acpi/acinterp.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exresop")
56 /*******************************************************************************
58 * FUNCTION: acpi_ex_check_object_type
60 * PARAMETERS: type_needed Object type needed
61 * this_type Actual object type
62 * Object Object pointer
64 * RETURN: Status
66 * DESCRIPTION: Check required type against actual type
68 ******************************************************************************/
70 acpi_status
71 acpi_ex_check_object_type (
72 acpi_object_type type_needed,
73 acpi_object_type this_type,
74 void *object)
76 ACPI_FUNCTION_NAME ("ex_check_object_type");
79 if (type_needed == ACPI_TYPE_ANY) {
80 /* All types OK, so we don't perform any typechecks */
82 return (AE_OK);
85 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
87 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
88 * objects and thus allow them to be targets. (As per the ACPI
89 * specification, a store to a constant is a noop.)
91 if ((this_type == ACPI_TYPE_INTEGER) &&
92 (((union acpi_operand_object *) object)->common.flags & AOPOBJ_AML_CONSTANT)) {
93 return (AE_OK);
97 if (type_needed != this_type) {
98 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
99 "Needed [%s], found [%s] %p\n",
100 acpi_ut_get_type_name (type_needed),
101 acpi_ut_get_type_name (this_type), object));
103 return (AE_AML_OPERAND_TYPE);
106 return (AE_OK);
110 /*******************************************************************************
112 * FUNCTION: acpi_ex_resolve_operands
114 * PARAMETERS: Opcode - Opcode being interpreted
115 * stack_ptr - Pointer to the operand stack to be
116 * resolved
117 * walk_state - Current state
119 * RETURN: Status
121 * DESCRIPTION: Convert multiple input operands to the types required by the
122 * target operator.
124 * Each 5-bit group in arg_types represents one required
125 * operand and indicates the required Type. The corresponding operand
126 * will be converted to the required type if possible, otherwise we
127 * abort with an exception.
129 ******************************************************************************/
131 acpi_status
132 acpi_ex_resolve_operands (
133 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;
139 u8 object_type;
140 void *temp_node;
141 u32 arg_types;
142 const struct acpi_opcode_info *op_info;
143 u32 this_arg_type;
144 acpi_object_type type_needed;
147 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode);
150 op_info = acpi_ps_get_opcode_info (opcode);
151 if (op_info->class == AML_CLASS_UNKNOWN) {
152 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
155 arg_types = op_info->runtime_args;
156 if (arg_types == ARGI_INVALID_OPCODE) {
157 ACPI_REPORT_ERROR (("resolve_operands: %X is not a valid AML opcode\n",
158 opcode));
160 return_ACPI_STATUS (AE_AML_INTERNAL);
163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] operand_types=%X \n",
164 opcode, op_info->name, arg_types));
167 * Normal exit is with (arg_types == 0) at end of argument list.
168 * Function will return an exception from within the loop upon
169 * finding an entry which is not (or cannot be converted
170 * to) the required type; if stack underflows; or upon
171 * finding a NULL stack entry (which should not happen).
173 while (GET_CURRENT_ARG_TYPE (arg_types)) {
174 if (!stack_ptr || !*stack_ptr) {
175 ACPI_REPORT_ERROR (("resolve_operands: Null stack entry at %p\n",
176 stack_ptr));
178 return_ACPI_STATUS (AE_AML_INTERNAL);
181 /* Extract useful items */
183 obj_desc = *stack_ptr;
185 /* Decode the descriptor type */
187 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
188 case ACPI_DESC_TYPE_NAMED:
190 /* Node */
192 object_type = ((struct acpi_namespace_node *) obj_desc)->type;
193 break;
196 case ACPI_DESC_TYPE_OPERAND:
198 /* ACPI internal object */
200 object_type = ACPI_GET_OBJECT_TYPE (obj_desc);
202 /* Check for bad acpi_object_type */
204 if (!acpi_ut_valid_object_type (object_type)) {
205 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad operand object type [%X]\n",
206 object_type));
208 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
211 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
213 * Decode the Reference
215 op_info = acpi_ps_get_opcode_info (opcode);
216 if (op_info->class == AML_CLASS_UNKNOWN) {
217 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
220 switch (obj_desc->reference.opcode) {
221 case AML_DEBUG_OP:
222 case AML_NAME_OP:
223 case AML_INDEX_OP:
224 case AML_REF_OF_OP:
225 case AML_ARG_OP:
226 case AML_LOCAL_OP:
227 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
229 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
230 "Reference Opcode: %s\n", op_info->name)));
231 break;
233 default:
234 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
235 "Unknown Reference Opcode %X [%s]\n",
236 obj_desc->reference.opcode,
237 (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name));
239 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
242 break;
245 default:
247 /* Invalid descriptor */
249 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
250 "Invalid descriptor %p [%s]\n",
251 obj_desc, acpi_ut_get_descriptor_name (obj_desc)));
253 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) == ACPI_DESC_TYPE_OPERAND) &&
271 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) {
273 * String found - the string references a named object and must be
274 * resolved to a node
276 goto next_operand;
279 /* Else not a string - fall through to the normal Reference case below */
280 /*lint -fallthrough */
282 case ARGI_REFERENCE: /* References: */
283 case ARGI_INTEGER_REF:
284 case ARGI_OBJECT_REF:
285 case ARGI_DEVICE_REF:
286 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
287 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
288 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
290 /* Need an operand of type ACPI_TYPE_LOCAL_REFERENCE */
292 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) /* Node (name) ptr OK as-is */ {
293 goto next_operand;
296 status = acpi_ex_check_object_type (ACPI_TYPE_LOCAL_REFERENCE,
297 object_type, obj_desc);
298 if (ACPI_FAILURE (status)) {
299 return_ACPI_STATUS (status);
302 if (AML_NAME_OP == obj_desc->reference.opcode) {
304 * Convert an indirect name ptr to direct name ptr and put
305 * it on the stack
307 temp_node = obj_desc->reference.object;
308 acpi_ut_remove_reference (obj_desc);
309 (*stack_ptr) = temp_node;
311 goto next_operand;
314 case ARGI_ANYTYPE:
317 * We don't want to resolve index_op reference objects during
318 * a store because this would be an implicit de_ref_of operation.
319 * Instead, we just want to store the reference object.
320 * -- All others must be resolved below.
322 if ((opcode == AML_STORE_OP) &&
323 (ACPI_GET_OBJECT_TYPE (*stack_ptr) == ACPI_TYPE_LOCAL_REFERENCE) &&
324 ((*stack_ptr)->reference.opcode == AML_INDEX_OP)) {
325 goto next_operand;
327 break;
329 default:
330 /* All cases covered above */
331 break;
336 * Resolve this object to a value
338 status = acpi_ex_resolve_to_value (stack_ptr, walk_state);
339 if (ACPI_FAILURE (status)) {
340 return_ACPI_STATUS (status);
343 /* Get the resolved object */
345 obj_desc = *stack_ptr;
348 * Check the resulting object (value) type
350 switch (this_arg_type) {
352 * For the simple cases, only one type of resolved object
353 * is allowed
355 case ARGI_MUTEX:
357 /* Need an operand of type ACPI_TYPE_MUTEX */
359 type_needed = ACPI_TYPE_MUTEX;
360 break;
362 case ARGI_EVENT:
364 /* Need an operand of type ACPI_TYPE_EVENT */
366 type_needed = ACPI_TYPE_EVENT;
367 break;
369 case ARGI_PACKAGE: /* Package */
371 /* Need an operand of type ACPI_TYPE_PACKAGE */
373 type_needed = ACPI_TYPE_PACKAGE;
374 break;
376 case ARGI_ANYTYPE:
378 /* Any operand type will do */
380 type_needed = ACPI_TYPE_ANY;
381 break;
383 case ARGI_DDBHANDLE:
385 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
387 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
388 break;
392 * The more complex cases allow multiple resolved object types
394 case ARGI_INTEGER: /* Number */
397 * Need an operand of type ACPI_TYPE_INTEGER,
398 * But we can implicitly convert from a STRING or BUFFER
399 * Aka - "Implicit Source Operand Conversion"
401 status = acpi_ex_convert_to_integer (obj_desc, stack_ptr, walk_state);
402 if (ACPI_FAILURE (status)) {
403 if (status == AE_TYPE) {
404 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
405 "Needed [Integer/String/Buffer], found [%s] %p\n",
406 acpi_ut_get_object_type_name (obj_desc), obj_desc));
408 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
411 return_ACPI_STATUS (status);
413 goto next_operand;
416 case ARGI_BUFFER:
419 * Need an operand of type ACPI_TYPE_BUFFER,
420 * But we can implicitly convert from a STRING or INTEGER
421 * Aka - "Implicit Source Operand Conversion"
423 status = acpi_ex_convert_to_buffer (obj_desc, stack_ptr, walk_state);
424 if (ACPI_FAILURE (status)) {
425 if (status == AE_TYPE) {
426 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
427 "Needed [Integer/String/Buffer], found [%s] %p\n",
428 acpi_ut_get_object_type_name (obj_desc), obj_desc));
430 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
433 return_ACPI_STATUS (status);
435 goto next_operand;
438 case ARGI_STRING:
441 * Need an operand of type ACPI_TYPE_STRING,
442 * But we can implicitly convert from a BUFFER or INTEGER
443 * Aka - "Implicit Source Operand Conversion"
445 status = acpi_ex_convert_to_string (obj_desc, stack_ptr, 16, ACPI_UINT32_MAX, walk_state);
446 if (ACPI_FAILURE (status)) {
447 if (status == AE_TYPE) {
448 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
449 "Needed [Integer/String/Buffer], found [%s] %p\n",
450 acpi_ut_get_object_type_name (obj_desc), obj_desc));
452 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
455 return_ACPI_STATUS (status);
457 goto next_operand;
460 case ARGI_COMPUTEDATA:
462 /* Need an operand of type INTEGER, STRING or BUFFER */
464 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
465 case ACPI_TYPE_INTEGER:
466 case ACPI_TYPE_STRING:
467 case ACPI_TYPE_BUFFER:
469 /* Valid operand */
470 break;
472 default:
473 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
474 "Needed [Integer/String/Buffer], found [%s] %p\n",
475 acpi_ut_get_object_type_name (obj_desc), obj_desc));
477 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
479 goto next_operand;
482 case ARGI_BUFFER_OR_STRING:
484 /* Need an operand of type STRING or BUFFER */
486 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
487 case ACPI_TYPE_STRING:
488 case ACPI_TYPE_BUFFER:
490 /* Valid operand */
491 break;
493 case ACPI_TYPE_INTEGER:
495 /* Highest priority conversion is to type Buffer */
497 status = acpi_ex_convert_to_buffer (obj_desc, stack_ptr, walk_state);
498 if (ACPI_FAILURE (status)) {
499 return_ACPI_STATUS (status);
501 break;
503 default:
504 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
505 "Needed [Integer/String/Buffer], found [%s] %p\n",
506 acpi_ut_get_object_type_name (obj_desc), obj_desc));
508 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
510 goto next_operand;
513 case ARGI_DATAOBJECT:
515 * ARGI_DATAOBJECT is only used by the size_of operator.
516 * Need a buffer, string, package, or ref_of reference.
518 * The only reference allowed here is a direct reference to
519 * a namespace node.
521 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
522 case ACPI_TYPE_PACKAGE:
523 case ACPI_TYPE_STRING:
524 case ACPI_TYPE_BUFFER:
525 case ACPI_TYPE_LOCAL_REFERENCE:
527 /* Valid operand */
528 break;
530 default:
531 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
532 "Needed [Buffer/String/Package/Reference], found [%s] %p\n",
533 acpi_ut_get_object_type_name (obj_desc), obj_desc));
535 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
537 goto next_operand;
540 case ARGI_COMPLEXOBJ:
542 /* Need a buffer or package or (ACPI 2.0) String */
544 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
545 case ACPI_TYPE_PACKAGE:
546 case ACPI_TYPE_STRING:
547 case ACPI_TYPE_BUFFER:
549 /* Valid operand */
550 break;
552 default:
553 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
554 "Needed [Buffer/String/Package], found [%s] %p\n",
555 acpi_ut_get_object_type_name (obj_desc), obj_desc));
557 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
559 goto next_operand;
562 case ARGI_REGION_OR_FIELD:
564 /* Need an operand of type ACPI_TYPE_REGION or a FIELD in a region */
566 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
567 case ACPI_TYPE_REGION:
568 case ACPI_TYPE_LOCAL_REGION_FIELD:
569 case ACPI_TYPE_LOCAL_BANK_FIELD:
570 case ACPI_TYPE_LOCAL_INDEX_FIELD:
572 /* Valid operand */
573 break;
575 default:
576 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
577 "Needed [Region/region_field], found [%s] %p\n",
578 acpi_ut_get_object_type_name (obj_desc), obj_desc));
580 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
582 goto next_operand;
585 default:
587 /* Unknown type */
589 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
590 "Internal - Unknown ARGI (required operand) type %X\n",
591 this_arg_type));
593 return_ACPI_STATUS (AE_BAD_PARAMETER);
597 * Make sure that the original object was resolved to the
598 * required object type (Simple cases only).
600 status = acpi_ex_check_object_type (type_needed,
601 ACPI_GET_OBJECT_TYPE (*stack_ptr), *stack_ptr);
602 if (ACPI_FAILURE (status)) {
603 return_ACPI_STATUS (status);
606 next_operand:
608 * If more operands needed, decrement stack_ptr to point
609 * to next operand on stack
611 if (GET_CURRENT_ARG_TYPE (arg_types)) {
612 stack_ptr--;
615 } /* while (*Types) */
617 return_ACPI_STATUS (status);