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 ACPI_OPCODE_INFO *parent_info;
61 /* Must have both an Op and a Result Object */
69 * If there is no parent, the result can't possibly be used!
70 * (An executing method typically has no parent, since each
71 * method is parsed separately) However, a method that is
72 * invoked from another method has a parent.
80 * Get info on the parent. The root Op is AML_SCOPE
83 parent_info = acpi_ps_get_opcode_info (op->parent->opcode);
84 if (ACPI_GET_OP_TYPE (parent_info) != ACPI_OP_TYPE_OPCODE) {
90 * Decide what to do with the result based on the parent. If
91 * the parent opcode will not use the result, delete the object.
92 * Otherwise leave it as is, it will be deleted when it is used
93 * as an operand later.
96 switch (ACPI_GET_OP_CLASS (parent_info)) {
98 * In these cases, the parent will never use the return object
100 case OPTYPE_CONTROL: /* IF, ELSE, WHILE only */
102 switch (op->parent->opcode) {
105 /* Never delete the return value associated with a return opcode */
114 * If we are executing the predicate AND this is the predicate op,
115 * we will use the return value!
118 if ((walk_state->control_state->common.state == CONTROL_PREDICATE_EXECUTING) &&
119 (walk_state->control_state->control.predicate_op == op)) {
127 /* Fall through to not used case below */
130 case OPTYPE_NAMED_OBJECT: /* Scope, method, etc. */
133 * These opcodes allow Term_arg(s) as operands and therefore
134 * method calls. The result is used.
136 if ((op->parent->opcode == AML_REGION_OP) ||
137 (op->parent->opcode == AML_CREATE_FIELD_OP) ||
138 (op->parent->opcode == AML_BIT_FIELD_OP) ||
139 (op->parent->opcode == AML_BYTE_FIELD_OP) ||
140 (op->parent->opcode == AML_WORD_FIELD_OP) ||
141 (op->parent->opcode == AML_DWORD_FIELD_OP) ||
142 (op->parent->opcode == AML_QWORD_FIELD_OP)) {
150 * In all other cases. the parent will actually use the return
151 * object, so keep it.
161 /*******************************************************************************
163 * FUNCTION: Acpi_ds_delete_result_if_not_used
171 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
172 * result descriptor, check if the parent opcode will actually use
173 * this result. If not, delete the result now so that it will
174 * not become orphaned.
176 ******************************************************************************/
179 acpi_ds_delete_result_if_not_used (
180 ACPI_PARSE_OBJECT *op,
181 ACPI_OPERAND_OBJECT *result_obj,
182 ACPI_WALK_STATE *walk_state)
184 ACPI_OPERAND_OBJECT *obj_desc;
197 if (!acpi_ds_is_result_used (op, walk_state)) {
199 * Must pop the result stack (Obj_desc should be equal
203 status = acpi_ds_result_pop (&obj_desc, walk_state);
204 if (ACPI_SUCCESS (status)) {
205 acpi_cm_remove_reference (result_obj);
213 /*******************************************************************************
215 * FUNCTION: Acpi_ds_create_operand
217 * PARAMETERS: Walk_state
222 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
223 * opcode to the equivalent interpreter object. This may include
224 * looking up a name or entering a new name into the internal
227 ******************************************************************************/
230 acpi_ds_create_operand (
231 ACPI_WALK_STATE *walk_state,
232 ACPI_PARSE_OBJECT *arg,
235 ACPI_STATUS status = AE_OK;
236 NATIVE_CHAR *name_string;
238 OBJECT_TYPE_INTERNAL data_type;
239 ACPI_OPERAND_OBJECT *obj_desc;
240 ACPI_PARSE_OBJECT *parent_op;
243 OPERATING_MODE interpreter_mode;
246 /* A valid name must be looked up in the namespace */
248 if ((arg->opcode == AML_NAMEPATH_OP) &&
249 (arg->value.string)) {
250 /* Get the entire name string from the AML stream */
252 status = acpi_aml_get_name_string (ACPI_TYPE_ANY,
257 if (ACPI_FAILURE (status)) {
262 * All prefixes have been handled, and the name is
267 * Differentiate between a namespace "create" operation
268 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
269 * IMODE_EXECUTE) in order to support the creation of
270 * namespace objects during the execution of control methods.
273 parent_op = arg->parent;
274 if ((acpi_ps_is_node_op (parent_op->opcode)) &&
275 (parent_op->opcode != AML_METHODCALL_OP) &&
276 (parent_op->opcode != AML_REGION_OP) &&
277 (parent_op->opcode != AML_NAMEPATH_OP)) {
278 /* Enter name into namespace if not found */
280 interpreter_mode = IMODE_LOAD_PASS2;
284 /* Return a failure if name not found */
286 interpreter_mode = IMODE_EXECUTE;
289 status = acpi_ns_lookup (walk_state->scope_info, name_string,
290 ACPI_TYPE_ANY, interpreter_mode,
291 NS_SEARCH_PARENT | NS_DONT_OPEN_SCOPE,
293 (ACPI_NAMESPACE_NODE **) &obj_desc);
295 /* Free the namestring created above */
297 acpi_cm_free (name_string);
300 * The only case where we pass through (ignore) a NOT_FOUND
301 * error is for the Cond_ref_of opcode.
304 if (status == AE_NOT_FOUND) {
305 if (parent_op->opcode == AML_COND_REF_OF_OP) {
307 * For the Conditional Reference op, it's OK if
308 * the name is not found; We just need a way to
309 * indicate this to the interpreter, set the
312 obj_desc = (ACPI_OPERAND_OBJECT *) acpi_gbl_root_node;
318 * We just plain didn't find it -- which is a
319 * very serious error at this point
321 status = AE_AML_NAME_NOT_FOUND;
325 /* Check status from the lookup */
327 if (ACPI_FAILURE (status)) {
331 /* Put the resulting object onto the current object stack */
333 status = acpi_ds_obj_stack_push (obj_desc, walk_state);
334 if (ACPI_FAILURE (status)) {
337 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc, walk_state));
342 /* Check for null name case */
344 if (arg->opcode == AML_NAMEPATH_OP) {
346 * If the name is null, this means that this is an
347 * optional result parameter that was not specified
348 * in the original ASL. Create an Reference for a
351 opcode = AML_ZERO_OP; /* Has no arguments! */
354 * TBD: [Investigate] anything else needed for the
360 opcode = arg->opcode;
364 /* Get the data type of the argument */
366 data_type = acpi_ds_map_opcode_to_data_type (opcode, &flags);
367 if (data_type == INTERNAL_TYPE_INVALID) {
368 return (AE_NOT_IMPLEMENTED);
371 if (flags & OP_HAS_RETURN_VALUE) {
372 DEBUGGER_EXEC (acpi_db_display_argument_object (walk_state->operands [walk_state->num_operands - 1], walk_state));
375 * Use value that was already previously returned
376 * by the evaluation of this argument
379 status = acpi_ds_result_pop_from_bottom (&obj_desc, walk_state);
380 if (ACPI_FAILURE (status)) {
382 * Only error is underflow, and this indicates
383 * a missing or null operand!
391 /* Create an ACPI_INTERNAL_OBJECT for the argument */
393 obj_desc = acpi_cm_create_internal_object (data_type);
395 return (AE_NO_MEMORY);
398 /* Initialize the new object */
400 status = acpi_ds_init_object_from_op (walk_state, arg,
402 if (ACPI_FAILURE (status)) {
403 acpi_cm_delete_object_desc (obj_desc);
408 /* Put the operand object on the object stack */
410 status = acpi_ds_obj_stack_push (obj_desc, walk_state);
411 if (ACPI_FAILURE (status)) {
415 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc, walk_state));
422 /*******************************************************************************
424 * FUNCTION: Acpi_ds_create_operands
426 * PARAMETERS: First_arg - First argument of a parser argument tree
430 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
431 * namespace objects and place those argument object on the object
432 * stack in preparation for evaluation by the interpreter.
434 ******************************************************************************/
437 acpi_ds_create_operands (
438 ACPI_WALK_STATE *walk_state,
439 ACPI_PARSE_OBJECT *first_arg)
441 ACPI_STATUS status = AE_OK;
442 ACPI_PARSE_OBJECT *arg;
446 /* For all arguments in the list... */
450 status = acpi_ds_create_operand (walk_state, arg, arg_count);
451 if (ACPI_FAILURE (status)) {
455 /* Move on to next argument, if any */
466 * We must undo everything done above; meaning that we must
467 * pop everything off of the operand stack and delete those
471 acpi_ds_obj_stack_pop_and_delete (arg_count, walk_state);
477 /*******************************************************************************
479 * FUNCTION: Acpi_ds_resolve_operands
481 * PARAMETERS: Walk_state - Current walk state with operands on stack
485 * DESCRIPTION: Resolve all operands to their values. Used to prepare
486 * arguments to a control method invocation (a call from one
487 * method to another.)
489 ******************************************************************************/
492 acpi_ds_resolve_operands (
493 ACPI_WALK_STATE *walk_state)
496 ACPI_STATUS status = AE_OK;
500 * Attempt to resolve each of the valid operands
501 * Method arguments are passed by value, not by reference
505 * TBD: [Investigate] Note from previous parser:
506 * Ref_of problem with Acpi_aml_resolve_to_value() conversion.
509 for (i = 0; i < walk_state->num_operands; i++) {
510 status = acpi_aml_resolve_to_value (&walk_state->operands[i], walk_state);
511 if (ACPI_FAILURE (status)) {
520 /*******************************************************************************
522 * FUNCTION: Acpi_ds_map_opcode_to_data_type
524 * PARAMETERS: Opcode - AML opcode to map
525 * Out_flags - Additional info about the opcode
527 * RETURN: The ACPI type associated with the opcode
529 * DESCRIPTION: Convert a raw AML opcode to the associated ACPI data type,
530 * if any. If the opcode returns a value as part of the
531 * intepreter execution, a flag is returned in Out_flags.
533 ******************************************************************************/
536 acpi_ds_map_opcode_to_data_type (
540 OBJECT_TYPE_INTERNAL data_type = INTERNAL_TYPE_INVALID;
541 ACPI_OPCODE_INFO *op_info;
545 op_info = acpi_ps_get_opcode_info (opcode);
546 if (ACPI_GET_OP_TYPE (op_info) != ACPI_OP_TYPE_OPCODE) {
552 switch (ACPI_GET_OP_CLASS (op_info)) {
561 data_type = ACPI_TYPE_INTEGER;
567 data_type = ACPI_TYPE_STRING;
570 case AML_NAMEPATH_OP:
571 data_type = INTERNAL_TYPE_REFERENCE;
580 case OPTYPE_DATA_TERM:
585 data_type = ACPI_TYPE_BUFFER;
590 data_type = ACPI_TYPE_PACKAGE;
599 case OPTYPE_CONSTANT:
600 case OPTYPE_METHOD_ARGUMENT:
601 case OPTYPE_LOCAL_VARIABLE:
603 data_type = INTERNAL_TYPE_REFERENCE;
607 case OPTYPE_MONADIC2:
608 case OPTYPE_MONADIC2_r:
610 case OPTYPE_DYADIC2_r:
611 case OPTYPE_DYADIC2_s:
616 flags = OP_HAS_RETURN_VALUE;
617 data_type = ACPI_TYPE_ANY;
620 case OPTYPE_METHOD_CALL:
622 flags = OP_HAS_RETURN_VALUE;
623 data_type = ACPI_TYPE_METHOD;
627 case OPTYPE_NAMED_OBJECT:
629 data_type = acpi_ds_map_named_opcode_to_data_type (opcode);
636 /* No mapping needed at this time */
646 /* Return flags to caller if requested */
656 /*******************************************************************************
658 * FUNCTION: Acpi_ds_map_named_opcode_to_data_type
660 * PARAMETERS: Opcode - The Named AML opcode to map
662 * RETURN: The ACPI type associated with the named opcode
664 * DESCRIPTION: Convert a raw Named AML opcode to the associated data type.
665 * Named opcodes are a subsystem of the AML opcodes.
667 ******************************************************************************/
670 acpi_ds_map_named_opcode_to_data_type (
673 OBJECT_TYPE_INTERNAL data_type;
680 data_type = INTERNAL_TYPE_SCOPE;
684 data_type = ACPI_TYPE_DEVICE;
687 case AML_THERMAL_ZONE_OP:
688 data_type = ACPI_TYPE_THERMAL;
692 data_type = ACPI_TYPE_METHOD;
695 case AML_POWER_RES_OP:
696 data_type = ACPI_TYPE_POWER;
699 case AML_PROCESSOR_OP:
700 data_type = ACPI_TYPE_PROCESSOR;
703 case AML_DEF_FIELD_OP: /* Def_field_op */
704 data_type = INTERNAL_TYPE_DEF_FIELD_DEFN;
707 case AML_INDEX_FIELD_OP: /* Index_field_op */
708 data_type = INTERNAL_TYPE_INDEX_FIELD_DEFN;
711 case AML_BANK_FIELD_OP: /* Bank_field_op */
712 data_type = INTERNAL_TYPE_BANK_FIELD_DEFN;
715 case AML_NAMEDFIELD_OP: /* NO CASE IN ORIGINAL */
716 data_type = ACPI_TYPE_ANY;
719 case AML_NAME_OP: /* Name_op - special code in original */
720 case AML_NAMEPATH_OP:
721 data_type = ACPI_TYPE_ANY;
725 data_type = INTERNAL_TYPE_ALIAS;
729 data_type = ACPI_TYPE_MUTEX;
733 data_type = ACPI_TYPE_EVENT;
737 data_type = ACPI_TYPE_REGION;
742 data_type = ACPI_TYPE_ANY;