1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2006, 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
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/amlcode.h>
48 #include <acpi/acdispat.h>
49 #include <acpi/acinterp.h>
50 #include <acpi/acnamesp.h>
51 #include <acpi/acevents.h>
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME("dsopcode")
56 /* Local prototypes */
58 acpi_ds_execute_arguments(struct acpi_namespace_node *node,
59 struct acpi_namespace_node *scope_node,
60 u32 aml_length, u8 * aml_start);
63 acpi_ds_init_buffer_field(u16 aml_opcode,
64 union acpi_operand_object *obj_desc,
65 union acpi_operand_object *buffer_desc,
66 union acpi_operand_object *offset_desc,
67 union acpi_operand_object *length_desc,
68 union acpi_operand_object *result_desc);
70 /*******************************************************************************
72 * FUNCTION: acpi_ds_execute_arguments
74 * PARAMETERS: Node - Object NS node
75 * scope_node - Parent NS node
76 * aml_length - Length of executable AML
77 * aml_start - Pointer to the AML
81 * DESCRIPTION: Late (deferred) execution of region or field arguments
83 ******************************************************************************/
86 acpi_ds_execute_arguments(struct acpi_namespace_node *node,
87 struct acpi_namespace_node *scope_node,
88 u32 aml_length, u8 * aml_start)
91 union acpi_parse_object *op;
92 struct acpi_walk_state *walk_state;
94 ACPI_FUNCTION_TRACE("ds_execute_arguments");
97 * Allocate a new parser op to be the root of the parsed tree
99 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
101 return_ACPI_STATUS(AE_NO_MEMORY);
104 /* Save the Node for use in acpi_ps_parse_aml */
106 op->common.node = scope_node;
108 /* Create and initialize a new parser state */
110 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
112 status = AE_NO_MEMORY;
116 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
117 aml_length, NULL, 1);
118 if (ACPI_FAILURE(status)) {
119 acpi_ds_delete_walk_state(walk_state);
123 /* Mark this parse as a deferred opcode */
125 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
126 walk_state->deferred_node = node;
128 /* Pass1: Parse the entire declaration */
130 status = acpi_ps_parse_aml(walk_state);
131 if (ACPI_FAILURE(status)) {
135 /* Get and init the Op created above */
137 op->common.node = node;
138 acpi_ps_delete_parse_tree(op);
140 /* Evaluate the deferred arguments */
142 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
144 return_ACPI_STATUS(AE_NO_MEMORY);
147 op->common.node = scope_node;
149 /* Create and initialize a new parser state */
151 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
153 status = AE_NO_MEMORY;
157 /* Execute the opcode and arguments */
159 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
160 aml_length, NULL, 3);
161 if (ACPI_FAILURE(status)) {
162 acpi_ds_delete_walk_state(walk_state);
166 /* Mark this execution as a deferred opcode */
168 walk_state->deferred_node = node;
169 status = acpi_ps_parse_aml(walk_state);
172 acpi_ps_delete_parse_tree(op);
173 return_ACPI_STATUS(status);
176 /*******************************************************************************
178 * FUNCTION: acpi_ds_get_buffer_field_arguments
180 * PARAMETERS: obj_desc - A valid buffer_field object
184 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
185 * evaluation of these field attributes.
187 ******************************************************************************/
190 acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
192 union acpi_operand_object *extra_desc;
193 struct acpi_namespace_node *node;
196 ACPI_FUNCTION_TRACE_PTR("ds_get_buffer_field_arguments", obj_desc);
198 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
199 return_ACPI_STATUS(AE_OK);
202 /* Get the AML pointer (method object) and buffer_field node */
204 extra_desc = acpi_ns_get_secondary_object(obj_desc);
205 node = obj_desc->buffer_field.node;
207 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
208 (ACPI_TYPE_BUFFER_FIELD, node, NULL));
209 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n",
210 acpi_ut_get_node_name(node)));
212 /* Execute the AML code for the term_arg arguments */
214 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
215 extra_desc->extra.aml_length,
216 extra_desc->extra.aml_start);
217 return_ACPI_STATUS(status);
220 /*******************************************************************************
222 * FUNCTION: acpi_ds_get_buffer_arguments
224 * PARAMETERS: obj_desc - A valid Buffer object
228 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
229 * the late evaluation of these attributes.
231 ******************************************************************************/
233 acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
235 struct acpi_namespace_node *node;
238 ACPI_FUNCTION_TRACE_PTR("ds_get_buffer_arguments", obj_desc);
240 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
241 return_ACPI_STATUS(AE_OK);
244 /* Get the Buffer node */
246 node = obj_desc->buffer.node;
249 "No pointer back to NS node in buffer obj %p",
251 return_ACPI_STATUS(AE_AML_INTERNAL);
254 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
256 /* Execute the AML code for the term_arg arguments */
258 status = acpi_ds_execute_arguments(node, node,
259 obj_desc->buffer.aml_length,
260 obj_desc->buffer.aml_start);
261 return_ACPI_STATUS(status);
264 /*******************************************************************************
266 * FUNCTION: acpi_ds_get_package_arguments
268 * PARAMETERS: obj_desc - A valid Package object
272 * DESCRIPTION: Get Package length and initializer byte list. This implements
273 * the late evaluation of these attributes.
275 ******************************************************************************/
277 acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
279 struct acpi_namespace_node *node;
282 ACPI_FUNCTION_TRACE_PTR("ds_get_package_arguments", obj_desc);
284 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
285 return_ACPI_STATUS(AE_OK);
288 /* Get the Package node */
290 node = obj_desc->package.node;
293 "No pointer back to NS node in package %p",
295 return_ACPI_STATUS(AE_AML_INTERNAL);
298 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
300 /* Execute the AML code for the term_arg arguments */
302 status = acpi_ds_execute_arguments(node, node,
303 obj_desc->package.aml_length,
304 obj_desc->package.aml_start);
305 return_ACPI_STATUS(status);
308 /*****************************************************************************
310 * FUNCTION: acpi_ds_get_region_arguments
312 * PARAMETERS: obj_desc - A valid region object
316 * DESCRIPTION: Get region address and length. This implements the late
317 * evaluation of these region attributes.
319 ****************************************************************************/
321 acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
323 struct acpi_namespace_node *node;
325 union acpi_operand_object *extra_desc;
327 ACPI_FUNCTION_TRACE_PTR("ds_get_region_arguments", obj_desc);
329 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
330 return_ACPI_STATUS(AE_OK);
333 extra_desc = acpi_ns_get_secondary_object(obj_desc);
335 return_ACPI_STATUS(AE_NOT_EXIST);
338 /* Get the Region node */
340 node = obj_desc->region.node;
342 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
343 (ACPI_TYPE_REGION, node, NULL));
345 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
346 "[%4.4s] op_region Arg Init at AML %p\n",
347 acpi_ut_get_node_name(node),
348 extra_desc->extra.aml_start));
350 /* Execute the argument AML */
352 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
353 extra_desc->extra.aml_length,
354 extra_desc->extra.aml_start);
355 return_ACPI_STATUS(status);
358 /*******************************************************************************
360 * FUNCTION: acpi_ds_initialize_region
362 * PARAMETERS: obj_handle - Region namespace node
366 * DESCRIPTION: Front end to ev_initialize_region
368 ******************************************************************************/
370 acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
372 union acpi_operand_object *obj_desc;
375 obj_desc = acpi_ns_get_attached_object(obj_handle);
377 /* Namespace is NOT locked */
379 status = acpi_ev_initialize_region(obj_desc, FALSE);
383 /*******************************************************************************
385 * FUNCTION: acpi_ds_init_buffer_field
387 * PARAMETERS: aml_opcode - create_xxx_field
388 * obj_desc - buffer_field object
389 * buffer_desc - Host Buffer
390 * offset_desc - Offset into buffer
391 * length_desc - Length of field (CREATE_FIELD_OP only)
392 * result_desc - Where to store the result
396 * DESCRIPTION: Perform actual initialization of a buffer field
398 ******************************************************************************/
401 acpi_ds_init_buffer_field(u16 aml_opcode,
402 union acpi_operand_object *obj_desc,
403 union acpi_operand_object *buffer_desc,
404 union acpi_operand_object *offset_desc,
405 union acpi_operand_object *length_desc,
406 union acpi_operand_object *result_desc)
414 ACPI_FUNCTION_TRACE_PTR("ds_init_buffer_field", obj_desc);
416 /* Host object must be a Buffer */
418 if (ACPI_GET_OBJECT_TYPE(buffer_desc) != ACPI_TYPE_BUFFER) {
420 "Target of Create Field is not a Buffer object - %s",
421 acpi_ut_get_object_type_name(buffer_desc)));
423 status = AE_AML_OPERAND_TYPE;
428 * The last parameter to all of these opcodes (result_desc) started
429 * out as a name_string, and should therefore now be a NS node
430 * after resolution in acpi_ex_resolve_operands().
432 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
434 "(%s) destination not a NS Node [%s]",
435 acpi_ps_get_opcode_name(aml_opcode),
436 acpi_ut_get_descriptor_name(result_desc)));
438 status = AE_AML_OPERAND_TYPE;
442 offset = (u32) offset_desc->integer.value;
445 * Setup the Bit offsets and counts, according to the opcode
447 switch (aml_opcode) {
448 case AML_CREATE_FIELD_OP:
450 /* Offset is in bits, count is in bits */
452 field_flags = AML_FIELD_ACCESS_BYTE;
454 bit_count = (u32) length_desc->integer.value;
456 /* Must have a valid (>0) bit count */
458 if (bit_count == 0) {
460 "Attempt to create_field of length zero"));
461 status = AE_AML_OPERAND_VALUE;
466 case AML_CREATE_BIT_FIELD_OP:
468 /* Offset is in bits, Field is one bit */
472 field_flags = AML_FIELD_ACCESS_BYTE;
475 case AML_CREATE_BYTE_FIELD_OP:
477 /* Offset is in bytes, field is one byte */
479 bit_offset = 8 * offset;
481 field_flags = AML_FIELD_ACCESS_BYTE;
484 case AML_CREATE_WORD_FIELD_OP:
486 /* Offset is in bytes, field is one word */
488 bit_offset = 8 * offset;
490 field_flags = AML_FIELD_ACCESS_WORD;
493 case AML_CREATE_DWORD_FIELD_OP:
495 /* Offset is in bytes, field is one dword */
497 bit_offset = 8 * offset;
499 field_flags = AML_FIELD_ACCESS_DWORD;
502 case AML_CREATE_QWORD_FIELD_OP:
504 /* Offset is in bytes, field is one qword */
506 bit_offset = 8 * offset;
508 field_flags = AML_FIELD_ACCESS_QWORD;
514 "Unknown field creation opcode %02x", aml_opcode));
515 status = AE_AML_BAD_OPCODE;
519 /* Entire field must fit within the current length of the buffer */
521 if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
523 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
524 acpi_ut_get_node_name(result_desc),
525 bit_offset + bit_count,
526 acpi_ut_get_node_name(buffer_desc->buffer.node),
527 8 * (u32) buffer_desc->buffer.length));
528 status = AE_AML_BUFFER_LIMIT;
533 * Initialize areas of the field object that are common to all fields
534 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
535 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
537 status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
538 bit_offset, bit_count);
539 if (ACPI_FAILURE(status)) {
543 obj_desc->buffer_field.buffer_obj = buffer_desc;
545 /* Reference count for buffer_desc inherits obj_desc count */
547 buffer_desc->common.reference_count = (u16)
548 (buffer_desc->common.reference_count +
549 obj_desc->common.reference_count);
553 /* Always delete the operands */
555 acpi_ut_remove_reference(offset_desc);
556 acpi_ut_remove_reference(buffer_desc);
558 if (aml_opcode == AML_CREATE_FIELD_OP) {
559 acpi_ut_remove_reference(length_desc);
562 /* On failure, delete the result descriptor */
564 if (ACPI_FAILURE(status)) {
565 acpi_ut_remove_reference(result_desc); /* Result descriptor */
567 /* Now the address and length are valid for this buffer_field */
569 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
572 return_ACPI_STATUS(status);
575 /*******************************************************************************
577 * FUNCTION: acpi_ds_eval_buffer_field_operands
579 * PARAMETERS: walk_state - Current walk
580 * Op - A valid buffer_field Op object
584 * DESCRIPTION: Get buffer_field Buffer and Index
585 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
587 ******************************************************************************/
590 acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
591 union acpi_parse_object *op)
594 union acpi_operand_object *obj_desc;
595 struct acpi_namespace_node *node;
596 union acpi_parse_object *next_op;
598 ACPI_FUNCTION_TRACE_PTR("ds_eval_buffer_field_operands", op);
601 * This is where we evaluate the address and length fields of the
602 * create_xxx_field declaration
604 node = op->common.node;
606 /* next_op points to the op that holds the Buffer */
608 next_op = op->common.value.arg;
610 /* Evaluate/create the address and length operands */
612 status = acpi_ds_create_operands(walk_state, next_op);
613 if (ACPI_FAILURE(status)) {
614 return_ACPI_STATUS(status);
617 obj_desc = acpi_ns_get_attached_object(node);
619 return_ACPI_STATUS(AE_NOT_EXIST);
622 /* Resolve the operands */
624 status = acpi_ex_resolve_operands(op->common.aml_opcode,
625 ACPI_WALK_OPERANDS, walk_state);
627 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
628 acpi_ps_get_opcode_name(op->common.aml_opcode),
629 walk_state->num_operands,
630 "after acpi_ex_resolve_operands");
632 if (ACPI_FAILURE(status)) {
633 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
634 acpi_ps_get_opcode_name(op->common.aml_opcode),
637 return_ACPI_STATUS(status);
640 /* Initialize the Buffer Field */
642 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
644 /* NOTE: Slightly different operands for this opcode */
647 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
648 walk_state->operands[0],
649 walk_state->operands[1],
650 walk_state->operands[2],
651 walk_state->operands[3]);
653 /* All other, create_xxx_field opcodes */
656 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
657 walk_state->operands[0],
658 walk_state->operands[1], NULL,
659 walk_state->operands[2]);
662 return_ACPI_STATUS(status);
665 /*******************************************************************************
667 * FUNCTION: acpi_ds_eval_region_operands
669 * PARAMETERS: walk_state - Current walk
670 * Op - A valid region Op object
674 * DESCRIPTION: Get region address and length
675 * Called from acpi_ds_exec_end_op during op_region parse tree walk
677 ******************************************************************************/
680 acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
681 union acpi_parse_object *op)
684 union acpi_operand_object *obj_desc;
685 union acpi_operand_object *operand_desc;
686 struct acpi_namespace_node *node;
687 union acpi_parse_object *next_op;
689 ACPI_FUNCTION_TRACE_PTR("ds_eval_region_operands", op);
692 * This is where we evaluate the address and length fields of the
693 * op_region declaration
695 node = op->common.node;
697 /* next_op points to the op that holds the space_iD */
699 next_op = op->common.value.arg;
701 /* next_op points to address op */
703 next_op = next_op->common.next;
705 /* Evaluate/create the address and length operands */
707 status = acpi_ds_create_operands(walk_state, next_op);
708 if (ACPI_FAILURE(status)) {
709 return_ACPI_STATUS(status);
712 /* Resolve the length and address operands to numbers */
714 status = acpi_ex_resolve_operands(op->common.aml_opcode,
715 ACPI_WALK_OPERANDS, walk_state);
716 if (ACPI_FAILURE(status)) {
717 return_ACPI_STATUS(status);
720 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
721 acpi_ps_get_opcode_name(op->common.aml_opcode),
722 1, "after acpi_ex_resolve_operands");
724 obj_desc = acpi_ns_get_attached_object(node);
726 return_ACPI_STATUS(AE_NOT_EXIST);
730 * Get the length operand and save it
733 operand_desc = walk_state->operands[walk_state->num_operands - 1];
735 obj_desc->region.length = (u32) operand_desc->integer.value;
736 acpi_ut_remove_reference(operand_desc);
739 * Get the address and save it
740 * (at top of stack - 1)
742 operand_desc = walk_state->operands[walk_state->num_operands - 2];
744 obj_desc->region.address = (acpi_physical_address)
745 operand_desc->integer.value;
746 acpi_ut_remove_reference(operand_desc);
748 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
750 ACPI_FORMAT_UINT64(obj_desc->region.address),
751 obj_desc->region.length));
753 /* Now the address and length are valid for this opregion */
755 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
757 return_ACPI_STATUS(status);
760 /*******************************************************************************
762 * FUNCTION: acpi_ds_eval_data_object_operands
764 * PARAMETERS: walk_state - Current walk
765 * Op - A valid data_object Op object
766 * obj_desc - data_object
770 * DESCRIPTION: Get the operands and complete the following data object types:
773 ******************************************************************************/
776 acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
777 union acpi_parse_object *op,
778 union acpi_operand_object *obj_desc)
781 union acpi_operand_object *arg_desc;
784 ACPI_FUNCTION_TRACE("ds_eval_data_object_operands");
786 /* The first operand (for all of these data objects) is the length */
788 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
789 if (ACPI_FAILURE(status)) {
790 return_ACPI_STATUS(status);
793 status = acpi_ex_resolve_operands(walk_state->opcode,
795 operands[walk_state->num_operands -
797 if (ACPI_FAILURE(status)) {
798 return_ACPI_STATUS(status);
801 /* Extract length operand */
803 arg_desc = walk_state->operands[walk_state->num_operands - 1];
804 length = (u32) arg_desc->integer.value;
806 /* Cleanup for length operand */
808 status = acpi_ds_obj_stack_pop(1, walk_state);
809 if (ACPI_FAILURE(status)) {
810 return_ACPI_STATUS(status);
813 acpi_ut_remove_reference(arg_desc);
816 * Create the actual data object
818 switch (op->common.aml_opcode) {
822 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
827 case AML_VAR_PACKAGE_OP:
830 acpi_ds_build_internal_package_obj(walk_state, op, length,
835 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
838 if (ACPI_SUCCESS(status)) {
840 * Return the object in the walk_state, unless the parent is a package -
841 * in this case, the return object will be stored in the parse tree
844 if ((!op->common.parent) ||
845 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
846 (op->common.parent->common.aml_opcode !=
848 && (op->common.parent->common.aml_opcode !=
850 walk_state->result_obj = obj_desc;
854 return_ACPI_STATUS(status);
857 /*******************************************************************************
859 * FUNCTION: acpi_ds_exec_begin_control_op
861 * PARAMETERS: walk_list - The list that owns the walk stack
862 * Op - The control Op
866 * DESCRIPTION: Handles all control ops encountered during control method
869 ******************************************************************************/
872 acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
873 union acpi_parse_object *op)
875 acpi_status status = AE_OK;
876 union acpi_generic_state *control_state;
878 ACPI_FUNCTION_NAME("ds_exec_begin_control_op");
880 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
881 op->common.aml_opcode, walk_state));
883 switch (op->common.aml_opcode) {
888 * IF/WHILE: Create a new control state to manage these
889 * constructs. We need to manage these as a stack, in order
892 control_state = acpi_ut_create_control_state();
893 if (!control_state) {
894 status = AE_NO_MEMORY;
898 * Save a pointer to the predicate for multiple executions
901 control_state->control.aml_predicate_start =
902 walk_state->parser_state.aml - 1;
903 control_state->control.package_end =
904 walk_state->parser_state.pkg_end;
905 control_state->control.opcode = op->common.aml_opcode;
907 /* Push the control state on this walk's control stack */
909 acpi_ut_push_generic_state(&walk_state->control_state,
915 /* Predicate is in the state object */
916 /* If predicate is true, the IF was executed, ignore ELSE part */
918 if (walk_state->last_predicate) {
919 status = AE_CTRL_TRUE;
935 /*******************************************************************************
937 * FUNCTION: acpi_ds_exec_end_control_op
939 * PARAMETERS: walk_list - The list that owns the walk stack
940 * Op - The control Op
944 * DESCRIPTION: Handles all control ops encountered during control method
947 ******************************************************************************/
950 acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
951 union acpi_parse_object * op)
953 acpi_status status = AE_OK;
954 union acpi_generic_state *control_state;
956 ACPI_FUNCTION_NAME("ds_exec_end_control_op");
958 switch (op->common.aml_opcode) {
961 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
964 * Save the result of the predicate in case there is an
967 walk_state->last_predicate =
968 (u8) walk_state->control_state->common.value;
971 * Pop the control state that was created at the start
972 * of the IF and free it
975 acpi_ut_pop_generic_state(&walk_state->control_state);
976 acpi_ut_delete_generic_state(control_state);
985 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
987 if (walk_state->control_state->common.value) {
989 /* Predicate was true, go back and evaluate it again! */
991 status = AE_CTRL_PENDING;
994 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
995 "[WHILE_OP] termination! Op=%p\n", op));
997 /* Pop this control state and free it */
1000 acpi_ut_pop_generic_state(&walk_state->control_state);
1002 walk_state->aml_last_while =
1003 control_state->control.aml_predicate_start;
1004 acpi_ut_delete_generic_state(control_state);
1009 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1010 "[RETURN_OP] Op=%p Arg=%p\n", op,
1011 op->common.value.arg));
1014 * One optional operand -- the return value
1015 * It can be either an immediate operand or a result that
1016 * has been bubbled up the tree
1018 if (op->common.value.arg) {
1020 /* Since we have a real Return(), delete any implicit return */
1022 acpi_ds_clear_implicit_return(walk_state);
1024 /* Return statement has an immediate operand */
1027 acpi_ds_create_operands(walk_state,
1028 op->common.value.arg);
1029 if (ACPI_FAILURE(status)) {
1034 * If value being returned is a Reference (such as
1035 * an arg or local), resolve it now because it may
1036 * cease to exist at the end of the method.
1039 acpi_ex_resolve_to_value(&walk_state->operands[0],
1041 if (ACPI_FAILURE(status)) {
1046 * Get the return value and save as the last result
1047 * value. This is the only place where walk_state->return_desc
1048 * is set to anything other than zero!
1050 walk_state->return_desc = walk_state->operands[0];
1051 } else if ((walk_state->results) &&
1052 (walk_state->results->results.num_results > 0)) {
1054 /* Since we have a real Return(), delete any implicit return */
1056 acpi_ds_clear_implicit_return(walk_state);
1059 * The return value has come from a previous calculation.
1061 * If value being returned is a Reference (such as
1062 * an arg or local), resolve it now because it may
1063 * cease to exist at the end of the method.
1065 * Allow references created by the Index operator to return unchanged.
1067 if ((ACPI_GET_DESCRIPTOR_TYPE
1068 (walk_state->results->results.obj_desc[0]) ==
1069 ACPI_DESC_TYPE_OPERAND)
1071 (ACPI_GET_OBJECT_TYPE
1072 (walk_state->results->results.obj_desc[0]) ==
1073 ACPI_TYPE_LOCAL_REFERENCE)
1074 && ((walk_state->results->results.obj_desc[0])->
1075 reference.opcode != AML_INDEX_OP)) {
1077 acpi_ex_resolve_to_value(&walk_state->
1081 if (ACPI_FAILURE(status)) {
1086 walk_state->return_desc =
1087 walk_state->results->results.obj_desc[0];
1089 /* No return operand */
1091 if (walk_state->num_operands) {
1092 acpi_ut_remove_reference(walk_state->
1096 walk_state->operands[0] = NULL;
1097 walk_state->num_operands = 0;
1098 walk_state->return_desc = NULL;
1101 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1102 "Completed RETURN_OP State=%p, ret_val=%p\n",
1103 walk_state, walk_state->return_desc));
1105 /* End the control method execution right now */
1107 status = AE_CTRL_TERMINATE;
1112 /* Just do nothing! */
1115 case AML_BREAK_POINT_OP:
1117 /* Call up to the OS service layer to handle this */
1120 acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
1121 "Executed AML Breakpoint opcode");
1123 /* If and when it returns, all done. */
1128 case AML_CONTINUE_OP: /* ACPI 2.0 */
1130 /* Pop and delete control states until we find a while */
1132 while (walk_state->control_state &&
1133 (walk_state->control_state->control.opcode !=
1136 acpi_ut_pop_generic_state(&walk_state->
1138 acpi_ut_delete_generic_state(control_state);
1141 /* No while found? */
1143 if (!walk_state->control_state) {
1144 return (AE_AML_NO_WHILE);
1147 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1149 walk_state->aml_last_while =
1150 walk_state->control_state->control.package_end;
1152 /* Return status depending on opcode */
1154 if (op->common.aml_opcode == AML_BREAK_OP) {
1155 status = AE_CTRL_BREAK;
1157 status = AE_CTRL_CONTINUE;
1163 ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
1164 op->common.aml_opcode, op));
1166 status = AE_AML_BAD_OPCODE;