1 /*******************************************************************************
3 * Module Name: dsutils - Dispatcher utilities
6 ******************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #define _COMPONENT ACPI_DISPATCHER
36 MODULE_NAME ("dsutils")
39 /*******************************************************************************
41 * FUNCTION: Acpi_ds_is_result_used
49 * DESCRIPTION: Check if a result object will be used by the parent
51 ******************************************************************************/
54 acpi_ds_is_result_used (
55 acpi_parse_object *op,
56 acpi_walk_state *walk_state)
58 const acpi_opcode_info *parent_info;
61 FUNCTION_TRACE_PTR ("Ds_is_result_used", op);
64 /* Must have both an Op and a Result Object */
67 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
73 * If there is no parent, the result can't possibly be used!
74 * (An executing method typically has no parent, since each
75 * method is parsed separately) However, a method that is
76 * invoked from another method has a parent.
84 * Get info on the parent. The root Op is AML_SCOPE
87 parent_info = acpi_ps_get_opcode_info (op->parent->opcode);
88 if (parent_info->class == AML_CLASS_UNKNOWN) {
89 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown parent opcode. Op=%p\n", op));
95 * Decide what to do with the result based on the parent. If
96 * the parent opcode will not use the result, delete the object.
97 * Otherwise leave it as is, it will be deleted when it is used
98 * as an operand later.
100 switch (parent_info->class) {
102 * In these cases, the parent will never use the return object
104 case AML_CLASS_CONTROL: /* IF, ELSE, WHILE only */
106 switch (op->parent->opcode) {
109 /* Never delete the return value associated with a return opcode */
111 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
112 "Result used, [RETURN] opcode=%X Op=%p\n", op->opcode, op));
120 * If we are executing the predicate AND this is the predicate op,
121 * we will use the return value!
123 if ((walk_state->control_state->common.state == CONTROL_PREDICATE_EXECUTING) &&
124 (walk_state->control_state->control.predicate_op == op)) {
125 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
126 "Result used as a predicate, [IF/WHILE] opcode=%X Op=%p\n",
135 /* Fall through to not used case below */
138 case AML_CLASS_NAMED_OBJECT: /* Scope, method, etc. */
139 case AML_CLASS_CREATE:
142 * These opcodes allow Term_arg(s) as operands and therefore
143 * method calls. The result is used.
145 if ((op->parent->opcode == AML_REGION_OP) ||
146 (op->parent->opcode == AML_CREATE_FIELD_OP) ||
147 (op->parent->opcode == AML_CREATE_BIT_FIELD_OP) ||
148 (op->parent->opcode == AML_CREATE_BYTE_FIELD_OP) ||
149 (op->parent->opcode == AML_CREATE_WORD_FIELD_OP) ||
150 (op->parent->opcode == AML_CREATE_DWORD_FIELD_OP) ||
151 (op->parent->opcode == AML_CREATE_QWORD_FIELD_OP)) {
152 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
153 "Result used, [Region or Create_field] opcode=%X Op=%p\n",
158 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
159 "Result not used, Parent opcode=%X Op=%p\n", op->opcode, op));
161 return_VALUE (FALSE);
165 * In all other cases. the parent will actually use the return
166 * object, so keep it.
176 /*******************************************************************************
178 * FUNCTION: Acpi_ds_delete_result_if_not_used
186 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
187 * result descriptor, check if the parent opcode will actually use
188 * this result. If not, delete the result now so that it will
189 * not become orphaned.
191 ******************************************************************************/
194 acpi_ds_delete_result_if_not_used (
195 acpi_parse_object *op,
196 acpi_operand_object *result_obj,
197 acpi_walk_state *walk_state)
199 acpi_operand_object *obj_desc;
203 FUNCTION_TRACE_PTR ("Ds_delete_result_if_not_used", result_obj);
207 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
216 if (!acpi_ds_is_result_used (op, walk_state)) {
218 * Must pop the result stack (Obj_desc should be equal to Result_obj)
220 status = acpi_ds_result_pop (&obj_desc, walk_state);
221 if (ACPI_SUCCESS (status)) {
222 acpi_ut_remove_reference (result_obj);
230 /*******************************************************************************
232 * FUNCTION: Acpi_ds_create_operand
234 * PARAMETERS: Walk_state
239 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
240 * opcode to the equivalent interpreter object. This may include
241 * looking up a name or entering a new name into the internal
244 ******************************************************************************/
247 acpi_ds_create_operand (
248 acpi_walk_state *walk_state,
249 acpi_parse_object *arg,
252 acpi_status status = AE_OK;
253 NATIVE_CHAR *name_string;
255 acpi_object_type8 data_type;
256 acpi_operand_object *obj_desc;
257 acpi_parse_object *parent_op;
260 operating_mode interpreter_mode;
261 const acpi_opcode_info *op_info;
264 FUNCTION_TRACE_PTR ("Ds_create_operand", arg);
267 /* A valid name must be looked up in the namespace */
269 if ((arg->opcode == AML_INT_NAMEPATH_OP) &&
270 (arg->value.string)) {
271 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", arg));
273 /* Get the entire name string from the AML stream */
275 status = acpi_ex_get_name_string (ACPI_TYPE_ANY, arg->value.buffer,
276 &name_string, &name_length);
278 if (ACPI_FAILURE (status)) {
279 return_ACPI_STATUS (status);
283 * All prefixes have been handled, and the name is
288 * Differentiate between a namespace "create" operation
289 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
290 * IMODE_EXECUTE) in order to support the creation of
291 * namespace objects during the execution of control methods.
293 parent_op = arg->parent;
294 op_info = acpi_ps_get_opcode_info (parent_op->opcode);
295 if ((op_info->flags & AML_NSNODE) &&
296 (parent_op->opcode != AML_INT_METHODCALL_OP) &&
297 (parent_op->opcode != AML_REGION_OP) &&
298 (parent_op->opcode != AML_INT_NAMEPATH_OP)) {
299 /* Enter name into namespace if not found */
301 interpreter_mode = IMODE_LOAD_PASS2;
305 /* Return a failure if name not found */
307 interpreter_mode = IMODE_EXECUTE;
310 status = acpi_ns_lookup (walk_state->scope_info, name_string,
311 ACPI_TYPE_ANY, interpreter_mode,
312 NS_SEARCH_PARENT | NS_DONT_OPEN_SCOPE,
314 (acpi_namespace_node **) &obj_desc);
316 /* Free the namestring created above */
318 ACPI_MEM_FREE (name_string);
321 * The only case where we pass through (ignore) a NOT_FOUND
322 * error is for the Cond_ref_of opcode.
324 if (status == AE_NOT_FOUND) {
325 if (parent_op->opcode == AML_COND_REF_OF_OP) {
327 * For the Conditional Reference op, it's OK if
328 * the name is not found; We just need a way to
329 * indicate this to the interpreter, set the
332 obj_desc = (acpi_operand_object *) acpi_gbl_root_node;
338 * We just plain didn't find it -- which is a
339 * very serious error at this point
341 status = AE_AML_NAME_NOT_FOUND;
343 /* TBD: Externalize Name_string and print */
345 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
346 "Object name was not found in namespace\n"));
350 /* Check status from the lookup */
352 if (ACPI_FAILURE (status)) {
353 return_ACPI_STATUS (status);
356 /* Put the resulting object onto the current object stack */
358 status = acpi_ds_obj_stack_push (obj_desc, walk_state);
359 if (ACPI_FAILURE (status)) {
360 return_ACPI_STATUS (status);
362 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc, walk_state));
367 /* Check for null name case */
369 if (arg->opcode == AML_INT_NAMEPATH_OP) {
371 * If the name is null, this means that this is an
372 * optional result parameter that was not specified
373 * in the original ASL. Create an Reference for a
376 opcode = AML_ZERO_OP; /* Has no arguments! */
378 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", arg));
381 * TBD: [Investigate] anything else needed for the
387 opcode = arg->opcode;
391 /* Get the data type of the argument */
393 data_type = acpi_ds_map_opcode_to_data_type (opcode, &flags);
394 if (data_type == INTERNAL_TYPE_INVALID) {
395 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
398 if (flags & OP_HAS_RETURN_VALUE) {
399 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
400 "Argument previously created, already stacked \n"));
402 DEBUGGER_EXEC (acpi_db_display_argument_object (walk_state->operands [walk_state->num_operands - 1], walk_state));
405 * Use value that was already previously returned
406 * by the evaluation of this argument
408 status = acpi_ds_result_pop_from_bottom (&obj_desc, walk_state);
409 if (ACPI_FAILURE (status)) {
411 * Only error is underflow, and this indicates
412 * a missing or null operand!
414 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Missing or null operand, %s\n",
415 acpi_format_exception (status)));
416 return_ACPI_STATUS (status);
422 /* Create an ACPI_INTERNAL_OBJECT for the argument */
424 obj_desc = acpi_ut_create_internal_object (data_type);
426 return_ACPI_STATUS (AE_NO_MEMORY);
429 /* Initialize the new object */
431 status = acpi_ds_init_object_from_op (walk_state, arg,
433 if (ACPI_FAILURE (status)) {
434 acpi_ut_delete_object_desc (obj_desc);
435 return_ACPI_STATUS (status);
439 /* Put the operand object on the object stack */
441 status = acpi_ds_obj_stack_push (obj_desc, walk_state);
442 if (ACPI_FAILURE (status)) {
443 return_ACPI_STATUS (status);
446 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc, walk_state));
449 return_ACPI_STATUS (AE_OK);
453 /*******************************************************************************
455 * FUNCTION: Acpi_ds_create_operands
457 * PARAMETERS: First_arg - First argument of a parser argument tree
461 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
462 * namespace objects and place those argument object on the object
463 * stack in preparation for evaluation by the interpreter.
465 ******************************************************************************/
468 acpi_ds_create_operands (
469 acpi_walk_state *walk_state,
470 acpi_parse_object *first_arg)
472 acpi_status status = AE_OK;
473 acpi_parse_object *arg;
477 FUNCTION_TRACE_PTR ("Ds_create_operands", first_arg);
480 /* For all arguments in the list... */
484 status = acpi_ds_create_operand (walk_state, arg, arg_count);
485 if (ACPI_FAILURE (status)) {
489 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Arg #%d (%p) done, Arg1=%p\n",
490 arg_count, arg, first_arg));
492 /* Move on to next argument, if any */
498 return_ACPI_STATUS (status);
503 * We must undo everything done above; meaning that we must
504 * pop everything off of the operand stack and delete those
507 acpi_ds_obj_stack_pop_and_delete (arg_count, walk_state);
509 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While creating Arg %d - %s\n",
510 (arg_count + 1), acpi_format_exception (status)));
511 return_ACPI_STATUS (status);
515 /*******************************************************************************
517 * FUNCTION: Acpi_ds_resolve_operands
519 * PARAMETERS: Walk_state - Current walk state with operands on stack
523 * DESCRIPTION: Resolve all operands to their values. Used to prepare
524 * arguments to a control method invocation (a call from one
525 * method to another.)
527 ******************************************************************************/
530 acpi_ds_resolve_operands (
531 acpi_walk_state *walk_state)
534 acpi_status status = AE_OK;
537 FUNCTION_TRACE_PTR ("Ds_resolve_operands", walk_state);
541 * Attempt to resolve each of the valid operands
542 * Method arguments are passed by value, not by reference
546 * TBD: [Investigate] Note from previous parser:
547 * Ref_of problem with Acpi_ex_resolve_to_value() conversion.
549 for (i = 0; i < walk_state->num_operands; i++) {
550 status = acpi_ex_resolve_to_value (&walk_state->operands[i], walk_state);
551 if (ACPI_FAILURE (status)) {
556 return_ACPI_STATUS (status);
560 /*******************************************************************************
562 * FUNCTION: Acpi_ds_map_opcode_to_data_type
564 * PARAMETERS: Opcode - AML opcode to map
565 * Out_flags - Additional info about the opcode
567 * RETURN: The ACPI type associated with the opcode
569 * DESCRIPTION: Convert a raw AML opcode to the associated ACPI data type,
570 * if any. If the opcode returns a value as part of the
571 * intepreter execution, a flag is returned in Out_flags.
573 ******************************************************************************/
576 acpi_ds_map_opcode_to_data_type (
580 acpi_object_type8 data_type = INTERNAL_TYPE_INVALID;
581 const acpi_opcode_info *op_info;
585 PROC_NAME ("Ds_map_opcode_to_data_type");
588 op_info = acpi_ps_get_opcode_info (opcode);
589 if (op_info->class == AML_CLASS_UNKNOWN) {
592 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown AML opcode: %x\n", opcode));
601 switch (op_info->type) {
603 case AML_TYPE_LITERAL:
611 data_type = ACPI_TYPE_INTEGER;
617 data_type = ACPI_TYPE_STRING;
620 case AML_INT_NAMEPATH_OP:
621 data_type = INTERNAL_TYPE_REFERENCE;
625 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
626 "Unknown (type LITERAL) AML opcode: %x\n", opcode));
632 case AML_TYPE_DATA_TERM:
637 data_type = ACPI_TYPE_BUFFER;
641 case AML_VAR_PACKAGE_OP:
643 data_type = ACPI_TYPE_PACKAGE;
647 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
648 "Unknown (type DATA_TERM) AML opcode: %x\n", opcode));
654 case AML_TYPE_CONSTANT:
655 case AML_TYPE_METHOD_ARGUMENT:
656 case AML_TYPE_LOCAL_VARIABLE:
658 data_type = INTERNAL_TYPE_REFERENCE;
662 case AML_TYPE_EXEC_1A_0T_1R:
663 case AML_TYPE_EXEC_1A_1T_1R:
664 case AML_TYPE_EXEC_2A_0T_1R:
665 case AML_TYPE_EXEC_2A_1T_1R:
666 case AML_TYPE_EXEC_2A_2T_1R:
667 case AML_TYPE_EXEC_3A_1T_1R:
668 case AML_TYPE_EXEC_6A_0T_1R:
669 case AML_TYPE_RETURN:
671 flags = OP_HAS_RETURN_VALUE;
672 data_type = ACPI_TYPE_ANY;
676 case AML_TYPE_METHOD_CALL:
678 flags = OP_HAS_RETURN_VALUE;
679 data_type = ACPI_TYPE_METHOD;
683 case AML_TYPE_NAMED_FIELD:
684 case AML_TYPE_NAMED_SIMPLE:
685 case AML_TYPE_NAMED_COMPLEX:
686 case AML_TYPE_NAMED_NO_OBJ:
688 data_type = acpi_ds_map_named_opcode_to_data_type (opcode);
692 case AML_TYPE_EXEC_1A_0T_0R:
693 case AML_TYPE_EXEC_2A_0T_0R:
694 case AML_TYPE_EXEC_3A_0T_0R:
695 case AML_TYPE_EXEC_1A_1T_0R:
696 case AML_TYPE_CONTROL:
698 /* No mapping needed at this time */
705 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
706 "Unimplemented data type opcode: %x\n", opcode));
710 /* Return flags to caller if requested */
720 /*******************************************************************************
722 * FUNCTION: Acpi_ds_map_named_opcode_to_data_type
724 * PARAMETERS: Opcode - The Named AML opcode to map
726 * RETURN: The ACPI type associated with the named opcode
728 * DESCRIPTION: Convert a raw Named AML opcode to the associated data type.
729 * Named opcodes are a subsystem of the AML opcodes.
731 ******************************************************************************/
734 acpi_ds_map_named_opcode_to_data_type (
737 acpi_object_type8 data_type;
747 data_type = INTERNAL_TYPE_SCOPE;
751 data_type = ACPI_TYPE_DEVICE;
754 case AML_THERMAL_ZONE_OP:
755 data_type = ACPI_TYPE_THERMAL;
759 data_type = ACPI_TYPE_METHOD;
762 case AML_POWER_RES_OP:
763 data_type = ACPI_TYPE_POWER;
766 case AML_PROCESSOR_OP:
767 data_type = ACPI_TYPE_PROCESSOR;
770 case AML_FIELD_OP: /* Field_op */
771 data_type = INTERNAL_TYPE_FIELD_DEFN;
774 case AML_INDEX_FIELD_OP: /* Index_field_op */
775 data_type = INTERNAL_TYPE_INDEX_FIELD_DEFN;
778 case AML_BANK_FIELD_OP: /* Bank_field_op */
779 data_type = INTERNAL_TYPE_BANK_FIELD_DEFN;
782 case AML_INT_NAMEDFIELD_OP: /* NO CASE IN ORIGINAL */
783 data_type = ACPI_TYPE_ANY;
786 case AML_NAME_OP: /* Name_op - special code in original */
787 case AML_INT_NAMEPATH_OP:
788 data_type = ACPI_TYPE_ANY;
792 data_type = INTERNAL_TYPE_ALIAS;
796 data_type = ACPI_TYPE_MUTEX;
800 data_type = ACPI_TYPE_EVENT;
803 case AML_DATA_REGION_OP:
805 data_type = ACPI_TYPE_REGION;
810 data_type = ACPI_TYPE_ANY;