1 /*******************************************************************************
3 * Module Name: dsutils - Dispatcher utilities
6 ******************************************************************************/
9 * Copyright (C) 2000 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 PARSER
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
))
99 * In these cases, the parent will never use the return object
101 case OPTYPE_CONTROL
: /* IF, ELSE, WHILE only */
103 switch (op
->parent
->opcode
)
107 /* Never delete the return value associated with a return opcode */
116 * If we are executing the predicate AND this is the predicate op,
117 * we will use the return value!
120 if ((walk_state
->control_state
->common
.state
== CONTROL_PREDICATE_EXECUTING
) &&
121 (walk_state
->control_state
->control
.predicate_op
== op
))
130 /* Fall through to not used case below */
133 case OPTYPE_NAMED_OBJECT
: /* Scope, method, etc. */
136 * These opcodes allow Term_arg(s) as operands and therefore
137 * method calls. The result is used.
139 if ((op
->parent
->opcode
== AML_REGION_OP
) ||
140 (op
->parent
->opcode
== AML_CREATE_FIELD_OP
) ||
141 (op
->parent
->opcode
== AML_BIT_FIELD_OP
) ||
142 (op
->parent
->opcode
== AML_BYTE_FIELD_OP
) ||
143 (op
->parent
->opcode
== AML_WORD_FIELD_OP
) ||
144 (op
->parent
->opcode
== AML_DWORD_FIELD_OP
) ||
145 (op
->parent
->opcode
== AML_QWORD_FIELD_OP
))
154 * In all other cases. the parent will actually use the return
155 * object, so keep it.
165 /*******************************************************************************
167 * FUNCTION: Acpi_ds_delete_result_if_not_used
175 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
176 * result descriptor, check if the parent opcode will actually use
177 * this result. If not, delete the result now so that it will
178 * not become orphaned.
180 ******************************************************************************/
183 acpi_ds_delete_result_if_not_used (
184 ACPI_PARSE_OBJECT
*op
,
185 ACPI_OPERAND_OBJECT
*result_obj
,
186 ACPI_WALK_STATE
*walk_state
)
188 ACPI_OPERAND_OBJECT
*obj_desc
;
201 if (!acpi_ds_is_result_used (op
, walk_state
)) {
203 * Must pop the result stack (Obj_desc should be equal
207 status
= acpi_ds_result_pop (&obj_desc
, walk_state
);
208 if (ACPI_SUCCESS (status
)) {
209 acpi_cm_remove_reference (result_obj
);
217 /*******************************************************************************
219 * FUNCTION: Acpi_ds_create_operand
221 * PARAMETERS: Walk_state
226 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
227 * opcode to the equivalent interpreter object. This may include
228 * looking up a name or entering a new name into the internal
231 ******************************************************************************/
234 acpi_ds_create_operand (
235 ACPI_WALK_STATE
*walk_state
,
236 ACPI_PARSE_OBJECT
*arg
,
239 ACPI_STATUS status
= AE_OK
;
240 NATIVE_CHAR
*name_string
;
242 OBJECT_TYPE_INTERNAL data_type
;
243 ACPI_OPERAND_OBJECT
*obj_desc
;
244 ACPI_PARSE_OBJECT
*parent_op
;
247 OPERATING_MODE interpreter_mode
;
250 /* A valid name must be looked up in the namespace */
252 if ((arg
->opcode
== AML_NAMEPATH_OP
) &&
255 /* Get the entire name string from the AML stream */
257 status
= acpi_aml_get_name_string (ACPI_TYPE_ANY
,
262 if (ACPI_FAILURE (status
)) {
267 * All prefixes have been handled, and the name is
272 * Differentiate between a namespace "create" operation
273 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
274 * IMODE_EXECUTE) in order to support the creation of
275 * namespace objects during the execution of control methods.
278 parent_op
= arg
->parent
;
279 if ((acpi_ps_is_node_op (parent_op
->opcode
)) &&
280 (parent_op
->opcode
!= AML_METHODCALL_OP
) &&
281 (parent_op
->opcode
!= AML_REGION_OP
) &&
282 (parent_op
->opcode
!= AML_NAMEPATH_OP
))
284 /* Enter name into namespace if not found */
286 interpreter_mode
= IMODE_LOAD_PASS2
;
290 /* Return a failure if name not found */
292 interpreter_mode
= IMODE_EXECUTE
;
295 status
= acpi_ns_lookup (walk_state
->scope_info
, name_string
,
296 ACPI_TYPE_ANY
, interpreter_mode
,
297 NS_SEARCH_PARENT
| NS_DONT_OPEN_SCOPE
,
299 (ACPI_NAMESPACE_NODE
**) &obj_desc
);
301 /* Free the namestring created above */
303 acpi_cm_free (name_string
);
306 * The only case where we pass through (ignore) a NOT_FOUND
307 * error is for the Cond_ref_of opcode.
310 if (status
== AE_NOT_FOUND
) {
311 if (parent_op
->opcode
== AML_COND_REF_OF_OP
) {
313 * For the Conditional Reference op, it's OK if
314 * the name is not found; We just need a way to
315 * indicate this to the interpreter, set the
318 obj_desc
= (ACPI_OPERAND_OBJECT
*) acpi_gbl_root_node
;
324 * We just plain didn't find it -- which is a
325 * very serious error at this point
327 status
= AE_AML_NAME_NOT_FOUND
;
331 /* Check status from the lookup */
333 if (ACPI_FAILURE (status
)) {
337 /* Put the resulting object onto the current object stack */
339 status
= acpi_ds_obj_stack_push (obj_desc
, walk_state
);
340 if (ACPI_FAILURE (status
)) {
343 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc
, walk_state
));
348 /* Check for null name case */
350 if (arg
->opcode
== AML_NAMEPATH_OP
) {
352 * If the name is null, this means that this is an
353 * optional result parameter that was not specified
354 * in the original ASL. Create an Reference for a
357 opcode
= AML_ZERO_OP
; /* Has no arguments! */
360 * TBD: [Investigate] anything else needed for the
366 opcode
= arg
->opcode
;
370 /* Get the data type of the argument */
372 data_type
= acpi_ds_map_opcode_to_data_type (opcode
, &flags
);
373 if (data_type
== INTERNAL_TYPE_INVALID
) {
374 return (AE_NOT_IMPLEMENTED
);
377 if (flags
& OP_HAS_RETURN_VALUE
) {
378 DEBUGGER_EXEC (acpi_db_display_argument_object (walk_state
->operands
[walk_state
->num_operands
- 1], walk_state
));
381 * Use value that was already previously returned
382 * by the evaluation of this argument
385 status
= acpi_ds_result_pop_from_bottom (&obj_desc
, walk_state
);
386 if (ACPI_FAILURE (status
)) {
388 * Only error is underflow, and this indicates
389 * a missing or null operand!
397 /* Create an ACPI_INTERNAL_OBJECT for the argument */
399 obj_desc
= acpi_cm_create_internal_object (data_type
);
401 return (AE_NO_MEMORY
);
404 /* Initialize the new object */
406 status
= acpi_ds_init_object_from_op (walk_state
, arg
,
408 if (ACPI_FAILURE (status
)) {
409 acpi_cm_delete_object_desc (obj_desc
);
414 /* Put the operand object on the object stack */
416 status
= acpi_ds_obj_stack_push (obj_desc
, walk_state
);
417 if (ACPI_FAILURE (status
)) {
421 DEBUGGER_EXEC (acpi_db_display_argument_object (obj_desc
, walk_state
));
428 /*******************************************************************************
430 * FUNCTION: Acpi_ds_create_operands
432 * PARAMETERS: First_arg - First argument of a parser argument tree
436 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
437 * namespace objects and place those argument object on the object
438 * stack in preparation for evaluation by the interpreter.
440 ******************************************************************************/
443 acpi_ds_create_operands (
444 ACPI_WALK_STATE
*walk_state
,
445 ACPI_PARSE_OBJECT
*first_arg
)
447 ACPI_STATUS status
= AE_OK
;
448 ACPI_PARSE_OBJECT
*arg
;
452 /* For all arguments in the list... */
456 status
= acpi_ds_create_operand (walk_state
, arg
, arg_count
);
457 if (ACPI_FAILURE (status
)) {
461 /* Move on to next argument, if any */
472 * We must undo everything done above; meaning that we must
473 * pop everything off of the operand stack and delete those
477 acpi_ds_obj_stack_pop_and_delete (arg_count
, walk_state
);
483 /*******************************************************************************
485 * FUNCTION: Acpi_ds_resolve_operands
487 * PARAMETERS: Walk_state - Current walk state with operands on stack
491 * DESCRIPTION: Resolve all operands to their values. Used to prepare
492 * arguments to a control method invocation (a call from one
493 * method to another.)
495 ******************************************************************************/
498 acpi_ds_resolve_operands (
499 ACPI_WALK_STATE
*walk_state
)
502 ACPI_STATUS status
= AE_OK
;
506 * Attempt to resolve each of the valid operands
507 * Method arguments are passed by value, not by reference
511 * TBD: [Investigate] Note from previous parser:
512 * Ref_of problem with Acpi_aml_resolve_to_value() conversion.
515 for (i
= 0; i
< walk_state
->num_operands
; i
++) {
516 status
= acpi_aml_resolve_to_value (&walk_state
->operands
[i
], walk_state
);
517 if (ACPI_FAILURE (status
)) {
526 /*******************************************************************************
528 * FUNCTION: Acpi_ds_map_opcode_to_data_type
530 * PARAMETERS: Opcode - AML opcode to map
531 * Out_flags - Additional info about the opcode
533 * RETURN: The ACPI type associated with the opcode
535 * DESCRIPTION: Convert a raw AML opcode to the associated ACPI data type,
536 * if any. If the opcode returns a value as part of the
537 * intepreter execution, a flag is returned in Out_flags.
539 ******************************************************************************/
542 acpi_ds_map_opcode_to_data_type (
546 OBJECT_TYPE_INTERNAL data_type
= INTERNAL_TYPE_INVALID
;
547 ACPI_OPCODE_INFO
*op_info
;
551 op_info
= acpi_ps_get_opcode_info (opcode
);
552 if (ACPI_GET_OP_TYPE (op_info
) != ACPI_OP_TYPE_OPCODE
) {
558 switch (ACPI_GET_OP_CLASS (op_info
))
569 data_type
= ACPI_TYPE_NUMBER
;
575 data_type
= ACPI_TYPE_STRING
;
578 case AML_NAMEPATH_OP
:
579 data_type
= INTERNAL_TYPE_REFERENCE
;
588 case OPTYPE_DATA_TERM
:
594 data_type
= ACPI_TYPE_BUFFER
;
599 data_type
= ACPI_TYPE_PACKAGE
;
608 case OPTYPE_CONSTANT
:
609 case OPTYPE_METHOD_ARGUMENT
:
610 case OPTYPE_LOCAL_VARIABLE
:
612 data_type
= INTERNAL_TYPE_REFERENCE
;
616 case OPTYPE_MONADIC2
:
617 case OPTYPE_MONADIC2_r
:
619 case OPTYPE_DYADIC2_r
:
620 case OPTYPE_DYADIC2_s
:
625 flags
= OP_HAS_RETURN_VALUE
;
626 data_type
= ACPI_TYPE_ANY
;
629 case OPTYPE_METHOD_CALL
:
631 flags
= OP_HAS_RETURN_VALUE
;
632 data_type
= ACPI_TYPE_METHOD
;
636 case OPTYPE_NAMED_OBJECT
:
638 data_type
= acpi_ds_map_named_opcode_to_data_type (opcode
);
645 /* No mapping needed at this time */
655 /* Return flags to caller if requested */
665 /*******************************************************************************
667 * FUNCTION: Acpi_ds_map_named_opcode_to_data_type
669 * PARAMETERS: Opcode - The Named AML opcode to map
671 * RETURN: The ACPI type associated with the named opcode
673 * DESCRIPTION: Convert a raw Named AML opcode to the associated data type.
674 * Named opcodes are a subsystem of the AML opcodes.
676 ******************************************************************************/
679 acpi_ds_map_named_opcode_to_data_type (
682 OBJECT_TYPE_INTERNAL data_type
;
690 data_type
= INTERNAL_TYPE_SCOPE
;
694 data_type
= ACPI_TYPE_DEVICE
;
697 case AML_THERMAL_ZONE_OP
:
698 data_type
= ACPI_TYPE_THERMAL
;
702 data_type
= ACPI_TYPE_METHOD
;
705 case AML_POWER_RES_OP
:
706 data_type
= ACPI_TYPE_POWER
;
709 case AML_PROCESSOR_OP
:
710 data_type
= ACPI_TYPE_PROCESSOR
;
713 case AML_DEF_FIELD_OP
: /* Def_field_op */
714 data_type
= INTERNAL_TYPE_DEF_FIELD_DEFN
;
717 case AML_INDEX_FIELD_OP
: /* Index_field_op */
718 data_type
= INTERNAL_TYPE_INDEX_FIELD_DEFN
;
721 case AML_BANK_FIELD_OP
: /* Bank_field_op */
722 data_type
= INTERNAL_TYPE_BANK_FIELD_DEFN
;
725 case AML_NAMEDFIELD_OP
: /* NO CASE IN ORIGINAL */
726 data_type
= ACPI_TYPE_ANY
;
729 case AML_NAME_OP
: /* Name_op - special code in original */
730 case AML_NAMEPATH_OP
:
731 data_type
= ACPI_TYPE_ANY
;
735 data_type
= INTERNAL_TYPE_ALIAS
;
739 data_type
= ACPI_TYPE_MUTEX
;
743 data_type
= ACPI_TYPE_EVENT
;
747 data_type
= ACPI_TYPE_REGION
;
752 data_type
= ACPI_TYPE_ANY
;