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
29 #define _COMPONENT ACPI_DISPATCHER
30 MODULE_NAME ("dsutils")
33 /*******************************************************************************
35 * FUNCTION: Acpi_ds_is_result_used
43 * DESCRIPTION: Check if a result object will be used by the parent
45 ******************************************************************************/
48 acpi_ds_is_result_used (
49 ACPI_PARSE_OBJECT
*op
,
50 ACPI_WALK_STATE
*walk_state
)
52 ACPI_OPCODE_INFO
*parent_info
;
55 /* Must have both an Op and a Result Object */
63 * If there is no parent, the result can't possibly be used!
64 * (An executing method typically has no parent, since each
65 * method is parsed separately) However, a method that is
66 * invoked from another method has a parent.
74 * Get info on the parent. The root Op is AML_SCOPE
77 parent_info
= acpi_ps_get_opcode_info (op
->parent
->opcode
);
78 if (ACPI_GET_OP_TYPE (parent_info
) != ACPI_OP_TYPE_OPCODE
) {
84 * Decide what to do with the result based on the parent. If
85 * the parent opcode will not use the result, delete the object.
86 * Otherwise leave it as is, it will be deleted when it is used
87 * as an operand later.
90 switch (ACPI_GET_OP_CLASS (parent_info
)) {
92 * In these cases, the parent will never use the return object
94 case OPTYPE_CONTROL
: /* IF, ELSE, WHILE only */
96 switch (op
->parent
->opcode
) {
99 /* Never delete the return value associated with a return opcode */
108 * If we are executing the predicate AND this is the predicate op,
109 * we will use the return value!
112 if ((walk_state
->control_state
->common
.state
== CONTROL_PREDICATE_EXECUTING
) &&
113 (walk_state
->control_state
->control
.predicate_op
== op
)) {
121 /* Fall through to not used case below */
124 case OPTYPE_NAMED_OBJECT
: /* Scope, method, etc. */
127 * These opcodes allow Term_arg(s) as operands and therefore
128 * method calls. The result is used.
130 if ((op
->parent
->opcode
== AML_REGION_OP
) ||
131 (op
->parent
->opcode
== AML_CREATE_FIELD_OP
) ||
132 (op
->parent
->opcode
== AML_BIT_FIELD_OP
) ||
133 (op
->parent
->opcode
== AML_BYTE_FIELD_OP
) ||
134 (op
->parent
->opcode
== AML_WORD_FIELD_OP
) ||
135 (op
->parent
->opcode
== AML_DWORD_FIELD_OP
) ||
136 (op
->parent
->opcode
== AML_QWORD_FIELD_OP
)) {
144 * In all other cases. the parent will actually use the return
145 * object, so keep it.
155 /*******************************************************************************
157 * FUNCTION: Acpi_ds_delete_result_if_not_used
165 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
166 * result descriptor, check if the parent opcode will actually use
167 * this result. If not, delete the result now so that it will
168 * not become orphaned.
170 ******************************************************************************/
173 acpi_ds_delete_result_if_not_used (
174 ACPI_PARSE_OBJECT
*op
,
175 ACPI_OPERAND_OBJECT
*result_obj
,
176 ACPI_WALK_STATE
*walk_state
)
178 ACPI_OPERAND_OBJECT
*obj_desc
;
191 if (!acpi_ds_is_result_used (op
, walk_state
)) {
193 * Must pop the result stack (Obj_desc should be equal
197 status
= acpi_ds_result_pop (&obj_desc
, walk_state
);
198 if (ACPI_SUCCESS (status
)) {
199 acpi_cm_remove_reference (result_obj
);
207 /*******************************************************************************
209 * FUNCTION: Acpi_ds_create_operand
211 * PARAMETERS: Walk_state
216 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
217 * opcode to the equivalent interpreter object. This may include
218 * looking up a name or entering a new name into the internal
221 ******************************************************************************/
224 acpi_ds_create_operand (
225 ACPI_WALK_STATE
*walk_state
,
226 ACPI_PARSE_OBJECT
*arg
,
229 ACPI_STATUS status
= AE_OK
;
230 NATIVE_CHAR
*name_string
;
232 OBJECT_TYPE_INTERNAL data_type
;
233 ACPI_OPERAND_OBJECT
*obj_desc
;
234 ACPI_PARSE_OBJECT
*parent_op
;
237 OPERATING_MODE interpreter_mode
;
240 /* A valid name must be looked up in the namespace */
242 if ((arg
->opcode
== AML_NAMEPATH_OP
) &&
243 (arg
->value
.string
)) {
244 /* Get the entire name string from the AML stream */
246 status
= acpi_aml_get_name_string (ACPI_TYPE_ANY
,
251 if (ACPI_FAILURE (status
)) {
256 * All prefixes have been handled, and the name is
261 * Differentiate between a namespace "create" operation
262 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
263 * IMODE_EXECUTE) in order to support the creation of
264 * namespace objects during the execution of control methods.
267 parent_op
= arg
->parent
;
268 if ((acpi_ps_is_node_op (parent_op
->opcode
)) &&
269 (parent_op
->opcode
!= AML_METHODCALL_OP
) &&
270 (parent_op
->opcode
!= AML_REGION_OP
) &&
271 (parent_op
->opcode
!= AML_NAMEPATH_OP
)) {
272 /* Enter name into namespace if not found */
274 interpreter_mode
= IMODE_LOAD_PASS2
;
278 /* Return a failure if name not found */
280 interpreter_mode
= IMODE_EXECUTE
;
283 status
= acpi_ns_lookup (walk_state
->scope_info
, name_string
,
284 ACPI_TYPE_ANY
, interpreter_mode
,
285 NS_SEARCH_PARENT
| NS_DONT_OPEN_SCOPE
,
287 (ACPI_NAMESPACE_NODE
**) &obj_desc
);
289 /* Free the namestring created above */
291 acpi_cm_free (name_string
);
294 * The only case where we pass through (ignore) a NOT_FOUND
295 * error is for the Cond_ref_of opcode.
298 if (status
== AE_NOT_FOUND
) {
299 if (parent_op
->opcode
== AML_COND_REF_OF_OP
) {
301 * For the Conditional Reference op, it's OK if
302 * the name is not found; We just need a way to
303 * indicate this to the interpreter, set the
306 obj_desc
= (ACPI_OPERAND_OBJECT
*) acpi_gbl_root_node
;
312 * We just plain didn't find it -- which is a
313 * very serious error at this point
315 status
= AE_AML_NAME_NOT_FOUND
;
319 /* Check status from the lookup */
321 if (ACPI_FAILURE (status
)) {
325 /* Put the resulting object onto the current object stack */
327 status
= acpi_ds_obj_stack_push (obj_desc
, walk_state
);
328 if (ACPI_FAILURE (status
)) {
331 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc
, walk_state
));
336 /* Check for null name case */
338 if (arg
->opcode
== AML_NAMEPATH_OP
) {
340 * If the name is null, this means that this is an
341 * optional result parameter that was not specified
342 * in the original ASL. Create an Reference for a
345 opcode
= AML_ZERO_OP
; /* Has no arguments! */
348 * TBD: [Investigate] anything else needed for the
354 opcode
= arg
->opcode
;
358 /* Get the data type of the argument */
360 data_type
= acpi_ds_map_opcode_to_data_type (opcode
, &flags
);
361 if (data_type
== INTERNAL_TYPE_INVALID
) {
362 return (AE_NOT_IMPLEMENTED
);
365 if (flags
& OP_HAS_RETURN_VALUE
) {
366 DEBUGGER_EXEC (acpi_db_display_argument_object (walk_state
->operands
[walk_state
->num_operands
- 1], walk_state
));
369 * Use value that was already previously returned
370 * by the evaluation of this argument
373 status
= acpi_ds_result_pop_from_bottom (&obj_desc
, walk_state
);
374 if (ACPI_FAILURE (status
)) {
376 * Only error is underflow, and this indicates
377 * a missing or null operand!
385 /* Create an ACPI_INTERNAL_OBJECT for the argument */
387 obj_desc
= acpi_cm_create_internal_object (data_type
);
389 return (AE_NO_MEMORY
);
392 /* Initialize the new object */
394 status
= acpi_ds_init_object_from_op (walk_state
, arg
,
396 if (ACPI_FAILURE (status
)) {
397 acpi_cm_delete_object_desc (obj_desc
);
402 /* Put the operand object on the object stack */
404 status
= acpi_ds_obj_stack_push (obj_desc
, walk_state
);
405 if (ACPI_FAILURE (status
)) {
409 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc
, walk_state
));
416 /*******************************************************************************
418 * FUNCTION: Acpi_ds_create_operands
420 * PARAMETERS: First_arg - First argument of a parser argument tree
424 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
425 * namespace objects and place those argument object on the object
426 * stack in preparation for evaluation by the interpreter.
428 ******************************************************************************/
431 acpi_ds_create_operands (
432 ACPI_WALK_STATE
*walk_state
,
433 ACPI_PARSE_OBJECT
*first_arg
)
435 ACPI_STATUS status
= AE_OK
;
436 ACPI_PARSE_OBJECT
*arg
;
440 /* For all arguments in the list... */
444 status
= acpi_ds_create_operand (walk_state
, arg
, arg_count
);
445 if (ACPI_FAILURE (status
)) {
449 /* Move on to next argument, if any */
460 * We must undo everything done above; meaning that we must
461 * pop everything off of the operand stack and delete those
465 acpi_ds_obj_stack_pop_and_delete (arg_count
, walk_state
);
471 /*******************************************************************************
473 * FUNCTION: Acpi_ds_resolve_operands
475 * PARAMETERS: Walk_state - Current walk state with operands on stack
479 * DESCRIPTION: Resolve all operands to their values. Used to prepare
480 * arguments to a control method invocation (a call from one
481 * method to another.)
483 ******************************************************************************/
486 acpi_ds_resolve_operands (
487 ACPI_WALK_STATE
*walk_state
)
490 ACPI_STATUS status
= AE_OK
;
494 * Attempt to resolve each of the valid operands
495 * Method arguments are passed by value, not by reference
499 * TBD: [Investigate] Note from previous parser:
500 * Ref_of problem with Acpi_aml_resolve_to_value() conversion.
503 for (i
= 0; i
< walk_state
->num_operands
; i
++) {
504 status
= acpi_aml_resolve_to_value (&walk_state
->operands
[i
], walk_state
);
505 if (ACPI_FAILURE (status
)) {
514 /*******************************************************************************
516 * FUNCTION: Acpi_ds_map_opcode_to_data_type
518 * PARAMETERS: Opcode - AML opcode to map
519 * Out_flags - Additional info about the opcode
521 * RETURN: The ACPI type associated with the opcode
523 * DESCRIPTION: Convert a raw AML opcode to the associated ACPI data type,
524 * if any. If the opcode returns a value as part of the
525 * intepreter execution, a flag is returned in Out_flags.
527 ******************************************************************************/
530 acpi_ds_map_opcode_to_data_type (
534 OBJECT_TYPE_INTERNAL data_type
= INTERNAL_TYPE_INVALID
;
535 ACPI_OPCODE_INFO
*op_info
;
539 op_info
= acpi_ps_get_opcode_info (opcode
);
540 if (ACPI_GET_OP_TYPE (op_info
) != ACPI_OP_TYPE_OPCODE
) {
546 switch (ACPI_GET_OP_CLASS (op_info
)) {
555 data_type
= ACPI_TYPE_INTEGER
;
561 data_type
= ACPI_TYPE_STRING
;
564 case AML_NAMEPATH_OP
:
565 data_type
= INTERNAL_TYPE_REFERENCE
;
574 case OPTYPE_DATA_TERM
:
579 data_type
= ACPI_TYPE_BUFFER
;
584 data_type
= ACPI_TYPE_PACKAGE
;
593 case OPTYPE_CONSTANT
:
594 case OPTYPE_METHOD_ARGUMENT
:
595 case OPTYPE_LOCAL_VARIABLE
:
597 data_type
= INTERNAL_TYPE_REFERENCE
;
601 case OPTYPE_MONADIC2
:
602 case OPTYPE_MONADIC2_r
:
604 case OPTYPE_DYADIC2_r
:
605 case OPTYPE_DYADIC2_s
:
610 flags
= OP_HAS_RETURN_VALUE
;
611 data_type
= ACPI_TYPE_ANY
;
614 case OPTYPE_METHOD_CALL
:
616 flags
= OP_HAS_RETURN_VALUE
;
617 data_type
= ACPI_TYPE_METHOD
;
621 case OPTYPE_NAMED_OBJECT
:
623 data_type
= acpi_ds_map_named_opcode_to_data_type (opcode
);
630 /* No mapping needed at this time */
640 /* Return flags to caller if requested */
650 /*******************************************************************************
652 * FUNCTION: Acpi_ds_map_named_opcode_to_data_type
654 * PARAMETERS: Opcode - The Named AML opcode to map
656 * RETURN: The ACPI type associated with the named opcode
658 * DESCRIPTION: Convert a raw Named AML opcode to the associated data type.
659 * Named opcodes are a subsystem of the AML opcodes.
661 ******************************************************************************/
664 acpi_ds_map_named_opcode_to_data_type (
667 OBJECT_TYPE_INTERNAL data_type
;
674 data_type
= INTERNAL_TYPE_SCOPE
;
678 data_type
= ACPI_TYPE_DEVICE
;
681 case AML_THERMAL_ZONE_OP
:
682 data_type
= ACPI_TYPE_THERMAL
;
686 data_type
= ACPI_TYPE_METHOD
;
689 case AML_POWER_RES_OP
:
690 data_type
= ACPI_TYPE_POWER
;
693 case AML_PROCESSOR_OP
:
694 data_type
= ACPI_TYPE_PROCESSOR
;
697 case AML_DEF_FIELD_OP
: /* Def_field_op */
698 data_type
= INTERNAL_TYPE_DEF_FIELD_DEFN
;
701 case AML_INDEX_FIELD_OP
: /* Index_field_op */
702 data_type
= INTERNAL_TYPE_INDEX_FIELD_DEFN
;
705 case AML_BANK_FIELD_OP
: /* Bank_field_op */
706 data_type
= INTERNAL_TYPE_BANK_FIELD_DEFN
;
709 case AML_NAMEDFIELD_OP
: /* NO CASE IN ORIGINAL */
710 data_type
= ACPI_TYPE_ANY
;
713 case AML_NAME_OP
: /* Name_op - special code in original */
714 case AML_NAMEPATH_OP
:
715 data_type
= ACPI_TYPE_ANY
;
719 data_type
= INTERNAL_TYPE_ALIAS
;
723 data_type
= ACPI_TYPE_MUTEX
;
727 data_type
= ACPI_TYPE_EVENT
;
731 data_type
= ACPI_TYPE_REGION
;
736 data_type
= ACPI_TYPE_ANY
;