[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / acpi / dispatcher / dswexec.c
blob2071a0d2bbbb9545751242a75125fad89723b817
1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2005, 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/acparser.h>
48 #include <acpi/amlcode.h>
49 #include <acpi/acdispat.h>
50 #include <acpi/acinterp.h>
51 #include <acpi/acnamesp.h>
52 #include <acpi/acdebug.h>
53 #include <acpi/acdisasm.h>
56 #define _COMPONENT ACPI_DISPATCHER
57 ACPI_MODULE_NAME ("dswexec")
60 * Dispatch table for opcode classes
62 static ACPI_EXECUTE_OP acpi_gbl_op_type_dispatch [] = {
63 acpi_ex_opcode_0A_0T_1R,
64 acpi_ex_opcode_1A_0T_0R,
65 acpi_ex_opcode_1A_0T_1R,
66 acpi_ex_opcode_1A_1T_0R,
67 acpi_ex_opcode_1A_1T_1R,
68 acpi_ex_opcode_2A_0T_0R,
69 acpi_ex_opcode_2A_0T_1R,
70 acpi_ex_opcode_2A_1T_1R,
71 acpi_ex_opcode_2A_2T_1R,
72 acpi_ex_opcode_3A_0T_0R,
73 acpi_ex_opcode_3A_1T_1R,
74 acpi_ex_opcode_6A_0T_1R};
76 /*****************************************************************************
78 * FUNCTION: acpi_ds_get_predicate_value
80 * PARAMETERS: walk_state - Current state of the parse tree walk
82 * RETURN: Status
84 * DESCRIPTION: Get the result of a predicate evaluation
86 ****************************************************************************/
88 acpi_status
89 acpi_ds_get_predicate_value (
90 struct acpi_walk_state *walk_state,
91 union acpi_operand_object *result_obj) {
92 acpi_status status = AE_OK;
93 union acpi_operand_object *obj_desc;
94 union acpi_operand_object *local_obj_desc = NULL;
97 ACPI_FUNCTION_TRACE_PTR ("ds_get_predicate_value", walk_state);
100 walk_state->control_state->common.state = 0;
102 if (result_obj) {
103 status = acpi_ds_result_pop (&obj_desc, walk_state);
104 if (ACPI_FAILURE (status)) {
105 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
106 "Could not get result from predicate evaluation, %s\n",
107 acpi_format_exception (status)));
109 return_ACPI_STATUS (status);
112 else {
113 status = acpi_ds_create_operand (walk_state, walk_state->op, 0);
114 if (ACPI_FAILURE (status)) {
115 return_ACPI_STATUS (status);
118 status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state);
119 if (ACPI_FAILURE (status)) {
120 return_ACPI_STATUS (status);
123 obj_desc = walk_state->operands [0];
126 if (!obj_desc) {
127 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate obj_desc=%p State=%p\n",
128 obj_desc, walk_state));
130 return_ACPI_STATUS (AE_AML_NO_OPERAND);
134 * Result of predicate evaluation must be an Integer
135 * object. Implicitly convert the argument if necessary.
137 status = acpi_ex_convert_to_integer (obj_desc, &local_obj_desc, 16);
138 if (ACPI_FAILURE (status)) {
139 goto cleanup;
142 if (ACPI_GET_OBJECT_TYPE (local_obj_desc) != ACPI_TYPE_INTEGER) {
143 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
144 "Bad predicate (not an integer) obj_desc=%p State=%p Type=%X\n",
145 obj_desc, walk_state, ACPI_GET_OBJECT_TYPE (obj_desc)));
147 status = AE_AML_OPERAND_TYPE;
148 goto cleanup;
151 /* Truncate the predicate to 32-bits if necessary */
153 acpi_ex_truncate_for32bit_table (local_obj_desc);
156 * Save the result of the predicate evaluation on
157 * the control stack
159 if (local_obj_desc->integer.value) {
160 walk_state->control_state->common.value = TRUE;
162 else {
164 * Predicate is FALSE, we will just toss the
165 * rest of the package
167 walk_state->control_state->common.value = FALSE;
168 status = AE_CTRL_FALSE;
172 cleanup:
174 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
175 walk_state->control_state->common.value, walk_state->op));
177 /* Break to debugger to display result */
179 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (local_obj_desc, walk_state));
182 * Delete the predicate result object (we know that
183 * we don't need it anymore)
185 if (local_obj_desc != obj_desc) {
186 acpi_ut_remove_reference (local_obj_desc);
188 acpi_ut_remove_reference (obj_desc);
190 walk_state->control_state->common.state = ACPI_CONTROL_NORMAL;
191 return_ACPI_STATUS (status);
195 /*****************************************************************************
197 * FUNCTION: acpi_ds_exec_begin_op
199 * PARAMETERS: walk_state - Current state of the parse tree walk
200 * out_op - Return op if a new one is created
202 * RETURN: Status
204 * DESCRIPTION: Descending callback used during the execution of control
205 * methods. This is where most operators and operands are
206 * dispatched to the interpreter.
208 ****************************************************************************/
210 acpi_status
211 acpi_ds_exec_begin_op (
212 struct acpi_walk_state *walk_state,
213 union acpi_parse_object **out_op)
215 union acpi_parse_object *op;
216 acpi_status status = AE_OK;
217 u32 opcode_class;
220 ACPI_FUNCTION_TRACE_PTR ("ds_exec_begin_op", walk_state);
223 op = walk_state->op;
224 if (!op) {
225 status = acpi_ds_load2_begin_op (walk_state, out_op);
226 if (ACPI_FAILURE (status)) {
227 return_ACPI_STATUS (status);
230 op = *out_op;
231 walk_state->op = op;
232 walk_state->opcode = op->common.aml_opcode;
233 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
235 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) {
236 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
237 acpi_ut_get_type_name (walk_state->op_info->object_type), op));
239 status = acpi_ds_scope_stack_pop (walk_state);
240 if (ACPI_FAILURE (status)) {
241 return_ACPI_STATUS (status);
246 if (op == walk_state->origin) {
247 if (out_op) {
248 *out_op = op;
251 return_ACPI_STATUS (AE_OK);
255 * If the previous opcode was a conditional, this opcode
256 * must be the beginning of the associated predicate.
257 * Save this knowledge in the current scope descriptor
259 if ((walk_state->control_state) &&
260 (walk_state->control_state->common.state ==
261 ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
262 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n",
263 op, walk_state));
265 walk_state->control_state->common.state = ACPI_CONTROL_PREDICATE_EXECUTING;
267 /* Save start of predicate */
269 walk_state->control_state->control.predicate_op = op;
273 opcode_class = walk_state->op_info->class;
275 /* We want to send namepaths to the load code */
277 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
278 opcode_class = AML_CLASS_NAMED_OBJECT;
282 * Handle the opcode based upon the opcode type
284 switch (opcode_class) {
285 case AML_CLASS_CONTROL:
287 status = acpi_ds_result_stack_push (walk_state);
288 if (ACPI_FAILURE (status)) {
289 return_ACPI_STATUS (status);
292 status = acpi_ds_exec_begin_control_op (walk_state, op);
293 break;
296 case AML_CLASS_NAMED_OBJECT:
298 if (walk_state->walk_type == ACPI_WALK_METHOD) {
300 * Found a named object declaration during method
301 * execution; we must enter this object into the
302 * namespace. The created object is temporary and
303 * will be deleted upon completion of the execution
304 * of this method.
306 status = acpi_ds_load2_begin_op (walk_state, NULL);
309 if (op->common.aml_opcode == AML_REGION_OP) {
310 status = acpi_ds_result_stack_push (walk_state);
312 break;
315 case AML_CLASS_EXECUTE:
316 case AML_CLASS_CREATE:
319 * Most operators with arguments.
320 * Start a new result/operand state
322 status = acpi_ds_result_stack_push (walk_state);
323 break;
326 default:
327 break;
330 /* Nothing to do here during method execution */
332 return_ACPI_STATUS (status);
336 /*****************************************************************************
338 * FUNCTION: acpi_ds_exec_end_op
340 * PARAMETERS: walk_state - Current state of the parse tree walk
341 * Op - Op that has been just been completed in the
342 * walk; Arguments have now been evaluated.
344 * RETURN: Status
346 * DESCRIPTION: Ascending callback used during the execution of control
347 * methods. The only thing we really need to do here is to
348 * notice the beginning of IF, ELSE, and WHILE blocks.
350 ****************************************************************************/
352 acpi_status
353 acpi_ds_exec_end_op (
354 struct acpi_walk_state *walk_state)
356 union acpi_parse_object *op;
357 acpi_status status = AE_OK;
358 u32 op_type;
359 u32 op_class;
360 union acpi_parse_object *next_op;
361 union acpi_parse_object *first_arg;
364 ACPI_FUNCTION_TRACE_PTR ("ds_exec_end_op", walk_state);
367 op = walk_state->op;
368 op_type = walk_state->op_info->type;
369 op_class = walk_state->op_info->class;
371 if (op_class == AML_CLASS_UNKNOWN) {
372 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode %X\n", op->common.aml_opcode));
373 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
376 first_arg = op->common.value.arg;
378 /* Init the walk state */
380 walk_state->num_operands = 0;
381 walk_state->return_desc = NULL;
382 walk_state->result_obj = NULL;
384 /* Call debugger for single step support (DEBUG build only) */
386 ACPI_DEBUGGER_EXEC (status = acpi_db_single_step (walk_state, op, op_class));
387 ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (status)) {return_ACPI_STATUS (status);});
389 /* Decode the Opcode Class */
391 switch (op_class) {
392 case AML_CLASS_ARGUMENT: /* constants, literals, etc. -- do nothing */
393 break;
396 case AML_CLASS_EXECUTE: /* most operators with arguments */
398 /* Build resolved operand stack */
400 status = acpi_ds_create_operands (walk_state, first_arg);
401 if (ACPI_FAILURE (status)) {
402 goto cleanup;
405 /* Done with this result state (Now that operand stack is built) */
407 status = acpi_ds_result_stack_pop (walk_state);
408 if (ACPI_FAILURE (status)) {
409 goto cleanup;
413 * All opcodes require operand resolution, with the only exceptions
414 * being the object_type and size_of operators.
416 if (!(walk_state->op_info->flags & AML_NO_OPERAND_RESOLVE)) {
417 /* Resolve all operands */
419 status = acpi_ex_resolve_operands (walk_state->opcode,
420 &(walk_state->operands [walk_state->num_operands -1]),
421 walk_state);
422 if (ACPI_SUCCESS (status)) {
423 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
424 acpi_ps_get_opcode_name (walk_state->opcode),
425 walk_state->num_operands, "after ex_resolve_operands");
429 if (ACPI_SUCCESS (status)) {
431 * Dispatch the request to the appropriate interpreter handler
432 * routine. There is one routine per opcode "type" based upon the
433 * number of opcode arguments and return type.
435 status = acpi_gbl_op_type_dispatch[op_type] (walk_state);
437 else {
439 * Treat constructs of the form "Store(local_x,local_x)" as noops when the
440 * Local is uninitialized.
442 if ((status == AE_AML_UNINITIALIZED_LOCAL) &&
443 (walk_state->opcode == AML_STORE_OP) &&
444 (walk_state->operands[0]->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
445 (walk_state->operands[1]->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
446 (walk_state->operands[0]->reference.opcode ==
447 walk_state->operands[1]->reference.opcode) &&
448 (walk_state->operands[0]->reference.offset ==
449 walk_state->operands[1]->reference.offset)) {
450 status = AE_OK;
452 else {
453 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
454 "[%s]: Could not resolve operands, %s\n",
455 acpi_ps_get_opcode_name (walk_state->opcode),
456 acpi_format_exception (status)));
460 /* Always delete the argument objects and clear the operand stack */
462 acpi_ds_clear_operands (walk_state);
465 * If a result object was returned from above, push it on the
466 * current result stack
468 if (ACPI_SUCCESS (status) &&
469 walk_state->result_obj) {
470 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
473 break;
476 default:
478 switch (op_type) {
479 case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
481 /* 1 Operand, 0 external_result, 0 internal_result */
483 status = acpi_ds_exec_end_control_op (walk_state, op);
485 /* Make sure to properly pop the result stack */
487 if (ACPI_SUCCESS (status)) {
488 status = acpi_ds_result_stack_pop (walk_state);
490 else if (status == AE_CTRL_PENDING) {
491 status = acpi_ds_result_stack_pop (walk_state);
492 if (ACPI_SUCCESS (status)) {
493 status = AE_CTRL_PENDING;
496 break;
499 case AML_TYPE_METHOD_CALL:
502 * If the method is referenced from within a package
503 * declaration, it is not a invocation of the method, just
504 * a reference to it.
506 if ((op->asl.parent) &&
507 ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) ||
508 (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) {
509 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method Reference in a Package, Op=%p\n", op));
510 op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object;
511 acpi_ut_add_reference (op->asl.value.arg->asl.node->object);
512 return_ACPI_STATUS (AE_OK);
515 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method invocation, Op=%p\n", op));
518 * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
519 * the method Node pointer
521 /* next_op points to the op that holds the method name */
523 next_op = first_arg;
525 /* next_op points to first argument op */
527 next_op = next_op->common.next;
530 * Get the method's arguments and put them on the operand stack
532 status = acpi_ds_create_operands (walk_state, next_op);
533 if (ACPI_FAILURE (status)) {
534 break;
538 * Since the operands will be passed to another control method,
539 * we must resolve all local references here (Local variables,
540 * arguments to *this* method, etc.)
542 status = acpi_ds_resolve_operands (walk_state);
543 if (ACPI_FAILURE (status)) {
544 /* On error, clear all resolved operands */
546 acpi_ds_clear_operands (walk_state);
547 break;
551 * Tell the walk loop to preempt this running method and
552 * execute the new method
554 status = AE_CTRL_TRANSFER;
557 * Return now; we don't want to disturb anything,
558 * especially the operand count!
560 return_ACPI_STATUS (status);
563 case AML_TYPE_CREATE_FIELD:
565 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
566 "Executing create_field Buffer/Index Op=%p\n", op));
568 status = acpi_ds_load2_end_op (walk_state);
569 if (ACPI_FAILURE (status)) {
570 break;
573 status = acpi_ds_eval_buffer_field_operands (walk_state, op);
574 break;
577 case AML_TYPE_CREATE_OBJECT:
579 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
580 "Executing create_object (Buffer/Package) Op=%p\n", op));
582 switch (op->common.parent->common.aml_opcode) {
583 case AML_NAME_OP:
586 * Put the Node on the object stack (Contains the ACPI Name of
587 * this object)
589 walk_state->operands[0] = (void *) op->common.parent->common.node;
590 walk_state->num_operands = 1;
592 status = acpi_ds_create_node (walk_state, op->common.parent->common.node, op->common.parent);
593 if (ACPI_FAILURE (status)) {
594 break;
597 /* Fall through */
598 /*lint -fallthrough */
600 case AML_INT_EVAL_SUBTREE_OP:
602 status = acpi_ds_eval_data_object_operands (walk_state, op,
603 acpi_ns_get_attached_object (op->common.parent->common.node));
604 break;
606 default:
608 status = acpi_ds_eval_data_object_operands (walk_state, op, NULL);
609 break;
612 /* Done with this result state (Now that operand stack is built) */
614 status = acpi_ds_result_stack_pop (walk_state);
615 if (ACPI_FAILURE (status)) {
616 goto cleanup;
620 * If a result object was returned from above, push it on the
621 * current result stack
623 if (ACPI_SUCCESS (status) &&
624 walk_state->result_obj) {
625 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
627 break;
630 case AML_TYPE_NAMED_FIELD:
631 case AML_TYPE_NAMED_COMPLEX:
632 case AML_TYPE_NAMED_SIMPLE:
633 case AML_TYPE_NAMED_NO_OBJ:
635 status = acpi_ds_load2_end_op (walk_state);
636 if (ACPI_FAILURE (status)) {
637 break;
640 if (op->common.aml_opcode == AML_REGION_OP) {
641 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
642 "Executing op_region Address/Length Op=%p\n", op));
644 status = acpi_ds_eval_region_operands (walk_state, op);
645 if (ACPI_FAILURE (status)) {
646 break;
649 status = acpi_ds_result_stack_pop (walk_state);
652 break;
655 case AML_TYPE_UNDEFINED:
657 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Undefined opcode type Op=%p\n", op));
658 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
661 case AML_TYPE_BOGUS:
663 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
664 "Internal opcode=%X type Op=%p\n",
665 walk_state->opcode, op));
666 break;
669 default:
671 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
672 "Unimplemented opcode, class=%X type=%X Opcode=%X Op=%p\n",
673 op_class, op_type, op->common.aml_opcode, op));
675 status = AE_NOT_IMPLEMENTED;
676 break;
681 * ACPI 2.0 support for 64-bit integers: Truncate numeric
682 * result value if we are executing from a 32-bit ACPI table
684 acpi_ex_truncate_for32bit_table (walk_state->result_obj);
687 * Check if we just completed the evaluation of a
688 * conditional predicate
691 if ((ACPI_SUCCESS (status)) &&
692 (walk_state->control_state) &&
693 (walk_state->control_state->common.state ==
694 ACPI_CONTROL_PREDICATE_EXECUTING) &&
695 (walk_state->control_state->control.predicate_op == op)) {
696 status = acpi_ds_get_predicate_value (walk_state, walk_state->result_obj);
697 walk_state->result_obj = NULL;
701 cleanup:
703 /* Invoke exception handler on error */
705 if (ACPI_FAILURE (status) &&
706 acpi_gbl_exception_handler &&
707 !(status & AE_CODE_CONTROL)) {
708 acpi_ex_exit_interpreter ();
709 status = acpi_gbl_exception_handler (status,
710 walk_state->method_node->name.integer, walk_state->opcode,
711 walk_state->aml_offset, NULL);
712 acpi_ex_enter_interpreter ();
715 if (walk_state->result_obj) {
716 /* Break to debugger to display result */
718 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj, walk_state));
721 * Delete the result op if and only if:
722 * Parent will not use the result -- such as any
723 * non-nested type2 op in a method (parent will be method)
725 acpi_ds_delete_result_if_not_used (op, walk_state->result_obj, walk_state);
728 #ifdef _UNDER_DEVELOPMENT
730 if (walk_state->parser_state.aml == walk_state->parser_state.aml_end) {
731 acpi_db_method_end (walk_state);
733 #endif
735 /* Always clear the object stack */
737 walk_state->num_operands = 0;
739 #ifdef ACPI_DISASSEMBLER
741 /* On error, display method locals/args */
743 if (ACPI_FAILURE (status)) {
744 acpi_dm_dump_method_info (status, walk_state, op);
746 #endif
748 return_ACPI_STATUS (status);