1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2004, 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.
46 #include <acpi/acpi.h>
47 #include <acpi/acparser.h>
48 #include <acpi/amlcode.h>
49 #include <acpi/acdispat.h>
50 #include <acpi/acinterp.h>
51 #include <acpi/acnamesp.h>
52 #include <acpi/acevents.h>
54 #define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME ("dsopcode")
58 /*****************************************************************************
60 * FUNCTION: acpi_ds_execute_arguments
62 * PARAMETERS: Node - Parent NS node
63 * aml_length - Length of executable AML
64 * aml_start - Pointer to the AML
68 * DESCRIPTION: Late (deferred) execution of region or field arguments
70 ****************************************************************************/
73 acpi_ds_execute_arguments (
74 struct acpi_namespace_node *node,
75 struct acpi_namespace_node *scope_node,
80 union acpi_parse_object *op;
81 struct acpi_walk_state *walk_state;
82 union acpi_parse_object *arg;
85 ACPI_FUNCTION_TRACE ("ds_execute_arguments");
89 * Allocate a new parser op to be the root of the parsed tree
91 op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
93 return_ACPI_STATUS (AE_NO_MEMORY);
96 /* Save the Node for use in acpi_ps_parse_aml */
98 op->common.node = scope_node;
100 /* Create and initialize a new parser state */
102 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
104 return_ACPI_STATUS (AE_NO_MEMORY);
107 status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
108 aml_length, NULL, NULL, 1);
109 if (ACPI_FAILURE (status)) {
110 acpi_ds_delete_walk_state (walk_state);
111 return_ACPI_STATUS (status);
114 /* Mark this parse as a deferred opcode */
116 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
117 walk_state->deferred_node = node;
119 /* Pass1: Parse the entire declaration */
121 status = acpi_ps_parse_aml (walk_state);
122 if (ACPI_FAILURE (status)) {
123 acpi_ps_delete_parse_tree (op);
124 return_ACPI_STATUS (status);
127 /* Get and init the Op created above */
129 arg = op->common.value.arg;
130 op->common.node = node;
131 arg->common.node = node;
132 acpi_ps_delete_parse_tree (op);
134 /* Evaluate the deferred arguments */
136 op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
138 return_ACPI_STATUS (AE_NO_MEMORY);
141 op->common.node = scope_node;
143 /* Create and initialize a new parser state */
145 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
147 return_ACPI_STATUS (AE_NO_MEMORY);
150 /* Execute the opcode and arguments */
152 status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
153 aml_length, NULL, NULL, 3);
154 if (ACPI_FAILURE (status)) {
155 acpi_ds_delete_walk_state (walk_state);
156 return_ACPI_STATUS (status);
159 /* Mark this execution as a deferred opcode */
161 walk_state->deferred_node = node;
162 status = acpi_ps_parse_aml (walk_state);
163 acpi_ps_delete_parse_tree (op);
164 return_ACPI_STATUS (status);
168 /*****************************************************************************
170 * FUNCTION: acpi_ds_get_buffer_field_arguments
172 * PARAMETERS: obj_desc - A valid buffer_field object
176 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
177 * evaluation of these field attributes.
179 ****************************************************************************/
182 acpi_ds_get_buffer_field_arguments (
183 union acpi_operand_object *obj_desc)
185 union acpi_operand_object *extra_desc;
186 struct acpi_namespace_node *node;
190 ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_field_arguments", obj_desc);
193 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
194 return_ACPI_STATUS (AE_OK);
197 /* Get the AML pointer (method object) and buffer_field node */
199 extra_desc = acpi_ns_get_secondary_object (obj_desc);
200 node = obj_desc->buffer_field.node;
202 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL));
203 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n",
204 acpi_ut_get_node_name (node)));
206 /* Execute the AML code for the term_arg arguments */
208 status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
209 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
210 return_ACPI_STATUS (status);
214 /*****************************************************************************
216 * FUNCTION: acpi_ds_get_buffer_arguments
218 * PARAMETERS: obj_desc - A valid Buffer object
222 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
223 * the late evaluation of these attributes.
225 ****************************************************************************/
228 acpi_ds_get_buffer_arguments (
229 union acpi_operand_object *obj_desc)
231 struct acpi_namespace_node *node;
235 ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_arguments", obj_desc);
238 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
239 return_ACPI_STATUS (AE_OK);
242 /* Get the Buffer node */
244 node = obj_desc->buffer.node;
247 "No pointer back to NS node in buffer obj %p\n", obj_desc));
248 return_ACPI_STATUS (AE_AML_INTERNAL);
251 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
253 /* Execute the AML code for the term_arg arguments */
255 status = acpi_ds_execute_arguments (node, node,
256 obj_desc->buffer.aml_length, obj_desc->buffer.aml_start);
257 return_ACPI_STATUS (status);
261 /*****************************************************************************
263 * FUNCTION: acpi_ds_get_package_arguments
265 * PARAMETERS: obj_desc - A valid Package object
269 * DESCRIPTION: Get Package length and initializer byte list. This implements
270 * the late evaluation of these attributes.
272 ****************************************************************************/
275 acpi_ds_get_package_arguments (
276 union acpi_operand_object *obj_desc)
278 struct acpi_namespace_node *node;
282 ACPI_FUNCTION_TRACE_PTR ("ds_get_package_arguments", obj_desc);
285 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
286 return_ACPI_STATUS (AE_OK);
289 /* Get the Package node */
291 node = obj_desc->package.node;
294 "No pointer back to NS node in package %p\n", obj_desc));
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, obj_desc->package.aml_start);
304 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 ****************************************************************************/
322 acpi_ds_get_region_arguments (
323 union acpi_operand_object *obj_desc)
325 struct acpi_namespace_node *node;
327 union acpi_operand_object *extra_desc;
330 ACPI_FUNCTION_TRACE_PTR ("ds_get_region_arguments", obj_desc);
333 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
334 return_ACPI_STATUS (AE_OK);
337 extra_desc = acpi_ns_get_secondary_object (obj_desc);
339 return_ACPI_STATUS (AE_NOT_EXIST);
342 /* Get the Region node */
344 node = obj_desc->region.node;
346 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL));
348 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] op_region Arg Init at AML %p\n",
349 acpi_ut_get_node_name (node), extra_desc->extra.aml_start));
351 /* Execute the argument AML */
353 status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
354 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
355 return_ACPI_STATUS (status);
359 /*****************************************************************************
361 * FUNCTION: acpi_ds_initialize_region
363 * PARAMETERS: Op - A valid region Op object
367 * DESCRIPTION: Front end to ev_initialize_region
369 ****************************************************************************/
372 acpi_ds_initialize_region (
373 acpi_handle obj_handle)
375 union acpi_operand_object *obj_desc;
379 obj_desc = acpi_ns_get_attached_object (obj_handle);
381 /* Namespace is NOT locked */
383 status = acpi_ev_initialize_region (obj_desc, FALSE);
388 /*****************************************************************************
390 * FUNCTION: acpi_ds_init_buffer_field
392 * PARAMETERS: aml_opcode - create_xxx_field
393 * obj_desc - buffer_field object
394 * buffer_desc - Host Buffer
395 * offset_desc - Offset into buffer
396 * Length - Length of field (CREATE_FIELD_OP only)
397 * Result - Where to store the result
401 * DESCRIPTION: Perform actual initialization of a buffer field
403 ****************************************************************************/
406 acpi_ds_init_buffer_field (
408 union acpi_operand_object *obj_desc,
409 union acpi_operand_object *buffer_desc,
410 union acpi_operand_object *offset_desc,
411 union acpi_operand_object *length_desc,
412 union acpi_operand_object *result_desc)
421 ACPI_FUNCTION_TRACE_PTR ("ds_init_buffer_field", obj_desc);
424 /* Host object must be a Buffer */
426 if (ACPI_GET_OBJECT_TYPE (buffer_desc) != ACPI_TYPE_BUFFER) {
427 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
428 "Target of Create Field is not a Buffer object - %s\n",
429 acpi_ut_get_object_type_name (buffer_desc)));
431 status = AE_AML_OPERAND_TYPE;
436 * The last parameter to all of these opcodes (result_desc) started
437 * out as a name_string, and should therefore now be a NS node
438 * after resolution in acpi_ex_resolve_operands().
440 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
441 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n",
442 acpi_ps_get_opcode_name (aml_opcode), acpi_ut_get_descriptor_name (result_desc)));
444 status = AE_AML_OPERAND_TYPE;
448 offset = (u32) offset_desc->integer.value;
451 * Setup the Bit offsets and counts, according to the opcode
453 switch (aml_opcode) {
454 case AML_CREATE_FIELD_OP:
456 /* Offset is in bits, count is in bits */
459 bit_count = (u32) length_desc->integer.value;
460 field_flags = AML_FIELD_ACCESS_BYTE;
463 case AML_CREATE_BIT_FIELD_OP:
465 /* Offset is in bits, Field is one bit */
469 field_flags = AML_FIELD_ACCESS_BYTE;
472 case AML_CREATE_BYTE_FIELD_OP:
474 /* Offset is in bytes, field is one byte */
476 bit_offset = 8 * offset;
478 field_flags = AML_FIELD_ACCESS_BYTE;
481 case AML_CREATE_WORD_FIELD_OP:
483 /* Offset is in bytes, field is one word */
485 bit_offset = 8 * offset;
487 field_flags = AML_FIELD_ACCESS_WORD;
490 case AML_CREATE_DWORD_FIELD_OP:
492 /* Offset is in bytes, field is one dword */
494 bit_offset = 8 * offset;
496 field_flags = AML_FIELD_ACCESS_DWORD;
499 case AML_CREATE_QWORD_FIELD_OP:
501 /* Offset is in bytes, field is one qword */
503 bit_offset = 8 * offset;
505 field_flags = AML_FIELD_ACCESS_QWORD;
510 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
511 "Unknown field creation opcode %02x\n",
513 status = AE_AML_BAD_OPCODE;
517 /* Entire field must fit within the current length of the buffer */
519 if ((bit_offset + bit_count) >
520 (8 * (u32) buffer_desc->buffer.length)) {
521 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
522 "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
523 acpi_ut_get_node_name (result_desc),
524 bit_offset + bit_count,
525 acpi_ut_get_node_name (buffer_desc->buffer.node),
526 8 * (u32) buffer_desc->buffer.length));
527 status = AE_AML_BUFFER_LIMIT;
532 * Initialize areas of the field object that are common to all fields
533 * For field_flags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
535 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
536 bit_offset, bit_count);
537 if (ACPI_FAILURE (status)) {
541 obj_desc->buffer_field.buffer_obj = buffer_desc;
543 /* Reference count for buffer_desc inherits obj_desc count */
545 buffer_desc->common.reference_count = (u16) (buffer_desc->common.reference_count +
546 obj_desc->common.reference_count);
551 /* Always delete the operands */
553 acpi_ut_remove_reference (offset_desc);
554 acpi_ut_remove_reference (buffer_desc);
556 if (aml_opcode == AML_CREATE_FIELD_OP) {
557 acpi_ut_remove_reference (length_desc);
560 /* On failure, delete the result descriptor */
562 if (ACPI_FAILURE (status)) {
563 acpi_ut_remove_reference (result_desc); /* Result descriptor */
566 /* Now the address and length are valid for this buffer_field */
568 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
571 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 (
591 struct acpi_walk_state *walk_state,
592 union acpi_parse_object *op)
595 union acpi_operand_object *obj_desc;
596 struct acpi_namespace_node *node;
597 union acpi_parse_object *next_op;
600 ACPI_FUNCTION_TRACE_PTR ("ds_eval_buffer_field_operands", op);
604 * This is where we evaluate the address and length fields of the
605 * create_xxx_field declaration
607 node = op->common.node;
609 /* next_op points to the op that holds the Buffer */
611 next_op = op->common.value.arg;
613 /* Evaluate/create the address and length operands */
615 status = acpi_ds_create_operands (walk_state, next_op);
616 if (ACPI_FAILURE (status)) {
617 return_ACPI_STATUS (status);
620 obj_desc = acpi_ns_get_attached_object (node);
622 return_ACPI_STATUS (AE_NOT_EXIST);
625 /* Resolve the operands */
627 status = acpi_ex_resolve_operands (op->common.aml_opcode,
628 ACPI_WALK_OPERANDS, walk_state);
630 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
631 acpi_ps_get_opcode_name (op->common.aml_opcode),
632 walk_state->num_operands, "after acpi_ex_resolve_operands");
634 if (ACPI_FAILURE (status)) {
635 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
636 acpi_ps_get_opcode_name (op->common.aml_opcode), status));
638 return_ACPI_STATUS (status);
641 /* Initialize the Buffer Field */
643 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
644 /* NOTE: Slightly different operands for this opcode */
646 status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
647 walk_state->operands[0], walk_state->operands[1],
648 walk_state->operands[2], walk_state->operands[3]);
651 /* All other, create_xxx_field opcodes */
653 status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
654 walk_state->operands[0], walk_state->operands[1],
655 NULL, walk_state->operands[2]);
658 return_ACPI_STATUS (status);
662 /*****************************************************************************
664 * FUNCTION: acpi_ds_eval_region_operands
666 * PARAMETERS: walk_state - Current walk
667 * Op - A valid region Op object
671 * DESCRIPTION: Get region address and length
672 * Called from acpi_ds_exec_end_op during op_region parse tree walk
674 ****************************************************************************/
677 acpi_ds_eval_region_operands (
678 struct acpi_walk_state *walk_state,
679 union acpi_parse_object *op)
682 union acpi_operand_object *obj_desc;
683 union acpi_operand_object *operand_desc;
684 struct acpi_namespace_node *node;
685 union acpi_parse_object *next_op;
688 ACPI_FUNCTION_TRACE_PTR ("ds_eval_region_operands", op);
692 * This is where we evaluate the address and length fields of the op_region declaration
694 node = op->common.node;
696 /* next_op points to the op that holds the space_iD */
698 next_op = op->common.value.arg;
700 /* next_op points to address op */
702 next_op = next_op->common.next;
704 /* Evaluate/create the address and length operands */
706 status = acpi_ds_create_operands (walk_state, next_op);
707 if (ACPI_FAILURE (status)) {
708 return_ACPI_STATUS (status);
711 /* Resolve the length and address operands to numbers */
713 status = acpi_ex_resolve_operands (op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state);
714 if (ACPI_FAILURE (status)) {
715 return_ACPI_STATUS (status);
718 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
719 acpi_ps_get_opcode_name (op->common.aml_opcode),
720 1, "after acpi_ex_resolve_operands");
722 obj_desc = acpi_ns_get_attached_object (node);
724 return_ACPI_STATUS (AE_NOT_EXIST);
728 * Get the length operand and save it
731 operand_desc = walk_state->operands[walk_state->num_operands - 1];
733 obj_desc->region.length = (u32) operand_desc->integer.value;
734 acpi_ut_remove_reference (operand_desc);
737 * Get the address and save it
738 * (at top of stack - 1)
740 operand_desc = walk_state->operands[walk_state->num_operands - 2];
742 obj_desc->region.address = (acpi_physical_address) operand_desc->integer.value;
743 acpi_ut_remove_reference (operand_desc);
745 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
747 ACPI_FORMAT_UINT64 (obj_desc->region.address),
748 obj_desc->region.length));
750 /* Now the address and length are valid for this opregion */
752 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
754 return_ACPI_STATUS (status);
758 /*****************************************************************************
760 * FUNCTION: acpi_ds_eval_data_object_operands
762 * PARAMETERS: walk_state - Current walk
763 * Op - A valid data_object Op object
764 * obj_desc - data_object
768 * DESCRIPTION: Get the operands and complete the following data objec types:
772 ****************************************************************************/
775 acpi_ds_eval_data_object_operands (
776 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;
785 ACPI_FUNCTION_TRACE ("ds_eval_data_object_operands");
788 /* The first operand (for all of these data objects) is the length */
790 status = acpi_ds_create_operand (walk_state, op->common.value.arg, 1);
791 if (ACPI_FAILURE (status)) {
792 return_ACPI_STATUS (status);
795 status = acpi_ex_resolve_operands (walk_state->opcode,
796 &(walk_state->operands [walk_state->num_operands -1]),
798 if (ACPI_FAILURE (status)) {
799 return_ACPI_STATUS (status);
802 /* Extract length operand */
804 arg_desc = walk_state->operands [walk_state->num_operands - 1];
805 length = (u32) arg_desc->integer.value;
807 /* Cleanup for length operand */
809 status = acpi_ds_obj_stack_pop (1, walk_state);
810 if (ACPI_FAILURE (status)) {
811 return_ACPI_STATUS (status);
814 acpi_ut_remove_reference (arg_desc);
817 * Create the actual data object
819 switch (op->common.aml_opcode) {
822 status = acpi_ds_build_internal_buffer_obj (walk_state, op, length, &obj_desc);
826 case AML_VAR_PACKAGE_OP:
828 status = acpi_ds_build_internal_package_obj (walk_state, op, length, &obj_desc);
832 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
835 if (ACPI_SUCCESS (status)) {
837 * Return the object in the walk_state, unless the parent is a package --
838 * in this case, the return object will be stored in the parse tree
841 if ((!op->common.parent) ||
842 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
843 (op->common.parent->common.aml_opcode != AML_VAR_PACKAGE_OP) &&
844 (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
845 walk_state->result_obj = obj_desc;
849 return_ACPI_STATUS (status);
853 /*******************************************************************************
855 * FUNCTION: acpi_ds_exec_begin_control_op
857 * PARAMETERS: walk_list - The list that owns the walk stack
858 * Op - The control Op
862 * DESCRIPTION: Handles all control ops encountered during control method
865 ******************************************************************************/
868 acpi_ds_exec_begin_control_op (
869 struct acpi_walk_state *walk_state,
870 union acpi_parse_object *op)
872 acpi_status status = AE_OK;
873 union acpi_generic_state *control_state;
876 ACPI_FUNCTION_NAME ("ds_exec_begin_control_op");
879 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
880 op->common.aml_opcode, walk_state));
882 switch (op->common.aml_opcode) {
887 * IF/WHILE: Create a new control state to manage these
888 * constructs. We need to manage these as a stack, in order
891 control_state = acpi_ut_create_control_state ();
892 if (!control_state) {
893 status = AE_NO_MEMORY;
897 * Save a pointer to the predicate for multiple executions
900 control_state->control.aml_predicate_start = walk_state->parser_state.aml - 1;
901 control_state->control.package_end = walk_state->parser_state.pkg_end;
902 control_state->control.opcode = op->common.aml_opcode;
905 /* Push the control state on this walk's control stack */
907 acpi_ut_push_generic_state (&walk_state->control_state, control_state);
912 /* Predicate is in the state object */
913 /* If predicate is true, the IF was executed, ignore ELSE part */
915 if (walk_state->last_predicate) {
916 status = AE_CTRL_TRUE;
933 /*******************************************************************************
935 * FUNCTION: acpi_ds_exec_end_control_op
937 * PARAMETERS: walk_list - The list that owns the walk stack
938 * Op - The control Op
942 * DESCRIPTION: Handles all control ops encountered during control method
945 ******************************************************************************/
948 acpi_ds_exec_end_control_op (
949 struct acpi_walk_state *walk_state,
950 union acpi_parse_object *op)
952 acpi_status status = AE_OK;
953 union acpi_generic_state *control_state;
956 ACPI_FUNCTION_NAME ("ds_exec_end_control_op");
959 switch (op->common.aml_opcode) {
962 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
965 * Save the result of the predicate in case there is an
968 walk_state->last_predicate =
969 (u8) walk_state->control_state->common.value;
972 * Pop the control state that was created at the start
973 * of the IF and free it
975 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
976 acpi_ut_delete_generic_state (control_state);
987 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
989 if (walk_state->control_state->common.value) {
990 /* Predicate was true, go back and evaluate it again! */
992 status = AE_CTRL_PENDING;
995 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", op));
997 /* Pop this control state and free it */
999 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
1001 walk_state->aml_last_while = control_state->control.aml_predicate_start;
1002 acpi_ut_delete_generic_state (control_state);
1008 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1009 "[RETURN_OP] Op=%p Arg=%p\n",op, op->common.value.arg));
1012 * One optional operand -- the return value
1013 * It can be either an immediate operand or a result that
1014 * has been bubbled up the tree
1016 if (op->common.value.arg) {
1017 /* Return statement has an immediate operand */
1019 status = acpi_ds_create_operands (walk_state, op->common.value.arg);
1020 if (ACPI_FAILURE (status)) {
1025 * If value being returned is a Reference (such as
1026 * an arg or local), resolve it now because it may
1027 * cease to exist at the end of the method.
1029 status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state);
1030 if (ACPI_FAILURE (status)) {
1035 * Get the return value and save as the last result
1036 * value. This is the only place where walk_state->return_desc
1037 * is set to anything other than zero!
1039 walk_state->return_desc = walk_state->operands[0];
1041 else if ((walk_state->results) &&
1042 (walk_state->results->results.num_results > 0)) {
1044 * The return value has come from a previous calculation.
1046 * If value being returned is a Reference (such as
1047 * an arg or local), resolve it now because it may
1048 * cease to exist at the end of the method.
1050 * Allow references created by the Index operator to return unchanged.
1052 if ((ACPI_GET_DESCRIPTOR_TYPE (walk_state->results->results.obj_desc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1053 (ACPI_GET_OBJECT_TYPE (walk_state->results->results.obj_desc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1054 ((walk_state->results->results.obj_desc [0])->reference.opcode != AML_INDEX_OP)) {
1055 status = acpi_ex_resolve_to_value (&walk_state->results->results.obj_desc [0], walk_state);
1056 if (ACPI_FAILURE (status)) {
1061 walk_state->return_desc = walk_state->results->results.obj_desc [0];
1064 /* No return operand */
1066 if (walk_state->num_operands) {
1067 acpi_ut_remove_reference (walk_state->operands [0]);
1070 walk_state->operands [0] = NULL;
1071 walk_state->num_operands = 0;
1072 walk_state->return_desc = NULL;
1076 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1077 "Completed RETURN_OP State=%p, ret_val=%p\n",
1078 walk_state, walk_state->return_desc));
1080 /* End the control method execution right now */
1082 status = AE_CTRL_TERMINATE;
1088 /* Just do nothing! */
1092 case AML_BREAK_POINT_OP:
1094 /* Call up to the OS service layer to handle this */
1096 status = acpi_os_signal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1098 /* If and when it returns, all done. */
1104 case AML_CONTINUE_OP: /* ACPI 2.0 */
1107 /* Pop and delete control states until we find a while */
1109 while (walk_state->control_state &&
1110 (walk_state->control_state->control.opcode != AML_WHILE_OP)) {
1111 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
1112 acpi_ut_delete_generic_state (control_state);
1115 /* No while found? */
1117 if (!walk_state->control_state) {
1118 return (AE_AML_NO_WHILE);
1121 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1123 walk_state->aml_last_while = walk_state->control_state->control.package_end;
1125 /* Return status depending on opcode */
1127 if (op->common.aml_opcode == AML_BREAK_OP) {
1128 status = AE_CTRL_BREAK;
1131 status = AE_CTRL_CONTINUE;
1138 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
1139 op->common.aml_opcode, op));
1141 status = AE_AML_BAD_OPCODE;