1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, 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")
57 /* Local prototypes */
60 acpi_ds_execute_arguments (
61 struct acpi_namespace_node *node,
62 struct acpi_namespace_node *scope_node,
67 acpi_ds_init_buffer_field (
69 union acpi_operand_object *obj_desc,
70 union acpi_operand_object *buffer_desc,
71 union acpi_operand_object *offset_desc,
72 union acpi_operand_object *length_desc,
73 union acpi_operand_object *result_desc);
76 /*******************************************************************************
78 * FUNCTION: acpi_ds_execute_arguments
80 * PARAMETERS: Node - Object NS node
81 * scope_node - Parent NS node
82 * aml_length - Length of executable AML
83 * aml_start - Pointer to the AML
87 * DESCRIPTION: Late (deferred) execution of region or field arguments
89 ******************************************************************************/
92 acpi_ds_execute_arguments (
93 struct acpi_namespace_node *node,
94 struct acpi_namespace_node *scope_node,
99 union acpi_parse_object *op;
100 struct acpi_walk_state *walk_state;
103 ACPI_FUNCTION_TRACE ("ds_execute_arguments");
107 * Allocate a new parser op to be the root of the parsed tree
109 op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
111 return_ACPI_STATUS (AE_NO_MEMORY);
114 /* Save the Node for use in acpi_ps_parse_aml */
116 op->common.node = scope_node;
118 /* Create and initialize a new parser state */
120 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
122 return_ACPI_STATUS (AE_NO_MEMORY);
125 status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
126 aml_length, NULL, 1);
127 if (ACPI_FAILURE (status)) {
128 acpi_ds_delete_walk_state (walk_state);
129 return_ACPI_STATUS (status);
132 /* Mark this parse as a deferred opcode */
134 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
135 walk_state->deferred_node = node;
137 /* Pass1: Parse the entire declaration */
139 status = acpi_ps_parse_aml (walk_state);
140 if (ACPI_FAILURE (status)) {
141 acpi_ps_delete_parse_tree (op);
142 return_ACPI_STATUS (status);
145 /* Get and init the Op created above */
147 op->common.node = node;
148 acpi_ps_delete_parse_tree (op);
150 /* Evaluate the deferred arguments */
152 op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
154 return_ACPI_STATUS (AE_NO_MEMORY);
157 op->common.node = scope_node;
159 /* Create and initialize a new parser state */
161 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
163 return_ACPI_STATUS (AE_NO_MEMORY);
166 /* Execute the opcode and arguments */
168 status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
169 aml_length, NULL, 3);
170 if (ACPI_FAILURE (status)) {
171 acpi_ds_delete_walk_state (walk_state);
172 return_ACPI_STATUS (status);
175 /* Mark this execution as a deferred opcode */
177 walk_state->deferred_node = node;
178 status = acpi_ps_parse_aml (walk_state);
179 acpi_ps_delete_parse_tree (op);
180 return_ACPI_STATUS (status);
184 /*******************************************************************************
186 * FUNCTION: acpi_ds_get_buffer_field_arguments
188 * PARAMETERS: obj_desc - A valid buffer_field object
192 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
193 * evaluation of these field attributes.
195 ******************************************************************************/
198 acpi_ds_get_buffer_field_arguments (
199 union acpi_operand_object *obj_desc)
201 union acpi_operand_object *extra_desc;
202 struct acpi_namespace_node *node;
206 ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_field_arguments", obj_desc);
209 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
210 return_ACPI_STATUS (AE_OK);
213 /* Get the AML pointer (method object) and buffer_field node */
215 extra_desc = acpi_ns_get_secondary_object (obj_desc);
216 node = obj_desc->buffer_field.node;
218 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL));
219 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n",
220 acpi_ut_get_node_name (node)));
222 /* Execute the AML code for the term_arg arguments */
224 status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
225 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
226 return_ACPI_STATUS (status);
230 /*******************************************************************************
232 * FUNCTION: acpi_ds_get_buffer_arguments
234 * PARAMETERS: obj_desc - A valid Buffer object
238 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
239 * the late evaluation of these attributes.
241 ******************************************************************************/
244 acpi_ds_get_buffer_arguments (
245 union acpi_operand_object *obj_desc)
247 struct acpi_namespace_node *node;
251 ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_arguments", obj_desc);
254 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
255 return_ACPI_STATUS (AE_OK);
258 /* Get the Buffer node */
260 node = obj_desc->buffer.node;
263 "No pointer back to NS node in buffer obj %p\n", obj_desc));
264 return_ACPI_STATUS (AE_AML_INTERNAL);
267 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
269 /* Execute the AML code for the term_arg arguments */
271 status = acpi_ds_execute_arguments (node, node,
272 obj_desc->buffer.aml_length, obj_desc->buffer.aml_start);
273 return_ACPI_STATUS (status);
277 /*******************************************************************************
279 * FUNCTION: acpi_ds_get_package_arguments
281 * PARAMETERS: obj_desc - A valid Package object
285 * DESCRIPTION: Get Package length and initializer byte list. This implements
286 * the late evaluation of these attributes.
288 ******************************************************************************/
291 acpi_ds_get_package_arguments (
292 union acpi_operand_object *obj_desc)
294 struct acpi_namespace_node *node;
298 ACPI_FUNCTION_TRACE_PTR ("ds_get_package_arguments", obj_desc);
301 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
302 return_ACPI_STATUS (AE_OK);
305 /* Get the Package node */
307 node = obj_desc->package.node;
310 "No pointer back to NS node in package %p\n", obj_desc));
311 return_ACPI_STATUS (AE_AML_INTERNAL);
314 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
316 /* Execute the AML code for the term_arg arguments */
318 status = acpi_ds_execute_arguments (node, node,
319 obj_desc->package.aml_length, obj_desc->package.aml_start);
320 return_ACPI_STATUS (status);
324 /*****************************************************************************
326 * FUNCTION: acpi_ds_get_region_arguments
328 * PARAMETERS: obj_desc - A valid region object
332 * DESCRIPTION: Get region address and length. This implements the late
333 * evaluation of these region attributes.
335 ****************************************************************************/
338 acpi_ds_get_region_arguments (
339 union acpi_operand_object *obj_desc)
341 struct acpi_namespace_node *node;
343 union acpi_operand_object *extra_desc;
346 ACPI_FUNCTION_TRACE_PTR ("ds_get_region_arguments", obj_desc);
349 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
350 return_ACPI_STATUS (AE_OK);
353 extra_desc = acpi_ns_get_secondary_object (obj_desc);
355 return_ACPI_STATUS (AE_NOT_EXIST);
358 /* Get the Region node */
360 node = obj_desc->region.node;
362 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL));
364 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] op_region Arg Init at AML %p\n",
365 acpi_ut_get_node_name (node), extra_desc->extra.aml_start));
367 /* Execute the argument AML */
369 status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
370 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
371 return_ACPI_STATUS (status);
375 /*******************************************************************************
377 * FUNCTION: acpi_ds_initialize_region
379 * PARAMETERS: obj_handle - Region namespace node
383 * DESCRIPTION: Front end to ev_initialize_region
385 ******************************************************************************/
388 acpi_ds_initialize_region (
389 acpi_handle obj_handle)
391 union acpi_operand_object *obj_desc;
395 obj_desc = acpi_ns_get_attached_object (obj_handle);
397 /* Namespace is NOT locked */
399 status = acpi_ev_initialize_region (obj_desc, FALSE);
404 /*******************************************************************************
406 * FUNCTION: acpi_ds_init_buffer_field
408 * PARAMETERS: aml_opcode - create_xxx_field
409 * obj_desc - buffer_field object
410 * buffer_desc - Host Buffer
411 * offset_desc - Offset into buffer
412 * length_desc - Length of field (CREATE_FIELD_OP only)
413 * result_desc - Where to store the result
417 * DESCRIPTION: Perform actual initialization of a buffer field
419 ******************************************************************************/
422 acpi_ds_init_buffer_field (
424 union acpi_operand_object *obj_desc,
425 union acpi_operand_object *buffer_desc,
426 union acpi_operand_object *offset_desc,
427 union acpi_operand_object *length_desc,
428 union acpi_operand_object *result_desc)
437 ACPI_FUNCTION_TRACE_PTR ("ds_init_buffer_field", obj_desc);
440 /* Host object must be a Buffer */
442 if (ACPI_GET_OBJECT_TYPE (buffer_desc) != ACPI_TYPE_BUFFER) {
443 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
444 "Target of Create Field is not a Buffer object - %s\n",
445 acpi_ut_get_object_type_name (buffer_desc)));
447 status = AE_AML_OPERAND_TYPE;
452 * The last parameter to all of these opcodes (result_desc) started
453 * out as a name_string, and should therefore now be a NS node
454 * after resolution in acpi_ex_resolve_operands().
456 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
457 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
458 "(%s) destination not a NS Node [%s]\n",
459 acpi_ps_get_opcode_name (aml_opcode),
460 acpi_ut_get_descriptor_name (result_desc)));
462 status = AE_AML_OPERAND_TYPE;
466 offset = (u32) offset_desc->integer.value;
469 * Setup the Bit offsets and counts, according to the opcode
471 switch (aml_opcode) {
472 case AML_CREATE_FIELD_OP:
474 /* Offset is in bits, count is in bits */
476 field_flags = AML_FIELD_ACCESS_BYTE;
478 bit_count = (u32) length_desc->integer.value;
480 /* Must have a valid (>0) bit count */
482 if (bit_count == 0) {
483 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
484 "Attempt to create_field of length 0\n"));
485 status = AE_AML_OPERAND_VALUE;
490 case AML_CREATE_BIT_FIELD_OP:
492 /* Offset is in bits, Field is one bit */
496 field_flags = AML_FIELD_ACCESS_BYTE;
499 case AML_CREATE_BYTE_FIELD_OP:
501 /* Offset is in bytes, field is one byte */
503 bit_offset = 8 * offset;
505 field_flags = AML_FIELD_ACCESS_BYTE;
508 case AML_CREATE_WORD_FIELD_OP:
510 /* Offset is in bytes, field is one word */
512 bit_offset = 8 * offset;
514 field_flags = AML_FIELD_ACCESS_WORD;
517 case AML_CREATE_DWORD_FIELD_OP:
519 /* Offset is in bytes, field is one dword */
521 bit_offset = 8 * offset;
523 field_flags = AML_FIELD_ACCESS_DWORD;
526 case AML_CREATE_QWORD_FIELD_OP:
528 /* Offset is in bytes, field is one qword */
530 bit_offset = 8 * offset;
532 field_flags = AML_FIELD_ACCESS_QWORD;
537 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
538 "Unknown field creation opcode %02x\n",
540 status = AE_AML_BAD_OPCODE;
544 /* Entire field must fit within the current length of the buffer */
546 if ((bit_offset + bit_count) >
547 (8 * (u32) buffer_desc->buffer.length)) {
548 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
549 "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
550 acpi_ut_get_node_name (result_desc),
551 bit_offset + bit_count,
552 acpi_ut_get_node_name (buffer_desc->buffer.node),
553 8 * (u32) buffer_desc->buffer.length));
554 status = AE_AML_BUFFER_LIMIT;
559 * Initialize areas of the field object that are common to all fields
560 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
561 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
563 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
564 bit_offset, bit_count);
565 if (ACPI_FAILURE (status)) {
569 obj_desc->buffer_field.buffer_obj = buffer_desc;
571 /* Reference count for buffer_desc inherits obj_desc count */
573 buffer_desc->common.reference_count = (u16)
574 (buffer_desc->common.reference_count + obj_desc->common.reference_count);
579 /* Always delete the operands */
581 acpi_ut_remove_reference (offset_desc);
582 acpi_ut_remove_reference (buffer_desc);
584 if (aml_opcode == AML_CREATE_FIELD_OP) {
585 acpi_ut_remove_reference (length_desc);
588 /* On failure, delete the result descriptor */
590 if (ACPI_FAILURE (status)) {
591 acpi_ut_remove_reference (result_desc); /* Result descriptor */
594 /* Now the address and length are valid for this buffer_field */
596 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
599 return_ACPI_STATUS (status);
603 /*******************************************************************************
605 * FUNCTION: acpi_ds_eval_buffer_field_operands
607 * PARAMETERS: walk_state - Current walk
608 * Op - A valid buffer_field Op object
612 * DESCRIPTION: Get buffer_field Buffer and Index
613 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
615 ******************************************************************************/
618 acpi_ds_eval_buffer_field_operands (
619 struct acpi_walk_state *walk_state,
620 union acpi_parse_object *op)
623 union acpi_operand_object *obj_desc;
624 struct acpi_namespace_node *node;
625 union acpi_parse_object *next_op;
628 ACPI_FUNCTION_TRACE_PTR ("ds_eval_buffer_field_operands", op);
632 * This is where we evaluate the address and length fields of the
633 * create_xxx_field declaration
635 node = op->common.node;
637 /* next_op points to the op that holds the Buffer */
639 next_op = op->common.value.arg;
641 /* Evaluate/create the address and length operands */
643 status = acpi_ds_create_operands (walk_state, next_op);
644 if (ACPI_FAILURE (status)) {
645 return_ACPI_STATUS (status);
648 obj_desc = acpi_ns_get_attached_object (node);
650 return_ACPI_STATUS (AE_NOT_EXIST);
653 /* Resolve the operands */
655 status = acpi_ex_resolve_operands (op->common.aml_opcode,
656 ACPI_WALK_OPERANDS, walk_state);
658 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
659 acpi_ps_get_opcode_name (op->common.aml_opcode),
660 walk_state->num_operands, "after acpi_ex_resolve_operands");
662 if (ACPI_FAILURE (status)) {
663 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
664 acpi_ps_get_opcode_name (op->common.aml_opcode), status));
666 return_ACPI_STATUS (status);
669 /* Initialize the Buffer Field */
671 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
672 /* NOTE: Slightly different operands for this opcode */
674 status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
675 walk_state->operands[0], walk_state->operands[1],
676 walk_state->operands[2], walk_state->operands[3]);
679 /* All other, create_xxx_field opcodes */
681 status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
682 walk_state->operands[0], walk_state->operands[1],
683 NULL, walk_state->operands[2]);
686 return_ACPI_STATUS (status);
690 /*******************************************************************************
692 * FUNCTION: acpi_ds_eval_region_operands
694 * PARAMETERS: walk_state - Current walk
695 * Op - A valid region Op object
699 * DESCRIPTION: Get region address and length
700 * Called from acpi_ds_exec_end_op during op_region parse tree walk
702 ******************************************************************************/
705 acpi_ds_eval_region_operands (
706 struct acpi_walk_state *walk_state,
707 union acpi_parse_object *op)
710 union acpi_operand_object *obj_desc;
711 union acpi_operand_object *operand_desc;
712 struct acpi_namespace_node *node;
713 union acpi_parse_object *next_op;
716 ACPI_FUNCTION_TRACE_PTR ("ds_eval_region_operands", op);
720 * This is where we evaluate the address and length fields of the
721 * op_region declaration
723 node = op->common.node;
725 /* next_op points to the op that holds the space_iD */
727 next_op = op->common.value.arg;
729 /* next_op points to address op */
731 next_op = next_op->common.next;
733 /* Evaluate/create the address and length operands */
735 status = acpi_ds_create_operands (walk_state, next_op);
736 if (ACPI_FAILURE (status)) {
737 return_ACPI_STATUS (status);
740 /* Resolve the length and address operands to numbers */
742 status = acpi_ex_resolve_operands (op->common.aml_opcode,
743 ACPI_WALK_OPERANDS, walk_state);
744 if (ACPI_FAILURE (status)) {
745 return_ACPI_STATUS (status);
748 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
749 acpi_ps_get_opcode_name (op->common.aml_opcode),
750 1, "after acpi_ex_resolve_operands");
752 obj_desc = acpi_ns_get_attached_object (node);
754 return_ACPI_STATUS (AE_NOT_EXIST);
758 * Get the length operand and save it
761 operand_desc = walk_state->operands[walk_state->num_operands - 1];
763 obj_desc->region.length = (u32) operand_desc->integer.value;
764 acpi_ut_remove_reference (operand_desc);
767 * Get the address and save it
768 * (at top of stack - 1)
770 operand_desc = walk_state->operands[walk_state->num_operands - 2];
772 obj_desc->region.address = (acpi_physical_address)
773 operand_desc->integer.value;
774 acpi_ut_remove_reference (operand_desc);
776 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
778 ACPI_FORMAT_UINT64 (obj_desc->region.address),
779 obj_desc->region.length));
781 /* Now the address and length are valid for this opregion */
783 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
785 return_ACPI_STATUS (status);
789 /*******************************************************************************
791 * FUNCTION: acpi_ds_eval_data_object_operands
793 * PARAMETERS: walk_state - Current walk
794 * Op - A valid data_object Op object
795 * obj_desc - data_object
799 * DESCRIPTION: Get the operands and complete the following data object types:
802 ******************************************************************************/
805 acpi_ds_eval_data_object_operands (
806 struct acpi_walk_state *walk_state,
807 union acpi_parse_object *op,
808 union acpi_operand_object *obj_desc)
811 union acpi_operand_object *arg_desc;
815 ACPI_FUNCTION_TRACE ("ds_eval_data_object_operands");
818 /* The first operand (for all of these data objects) is the length */
820 status = acpi_ds_create_operand (walk_state, op->common.value.arg, 1);
821 if (ACPI_FAILURE (status)) {
822 return_ACPI_STATUS (status);
825 status = acpi_ex_resolve_operands (walk_state->opcode,
826 &(walk_state->operands [walk_state->num_operands -1]),
828 if (ACPI_FAILURE (status)) {
829 return_ACPI_STATUS (status);
832 /* Extract length operand */
834 arg_desc = walk_state->operands [walk_state->num_operands - 1];
835 length = (u32) arg_desc->integer.value;
837 /* Cleanup for length operand */
839 status = acpi_ds_obj_stack_pop (1, walk_state);
840 if (ACPI_FAILURE (status)) {
841 return_ACPI_STATUS (status);
844 acpi_ut_remove_reference (arg_desc);
847 * Create the actual data object
849 switch (op->common.aml_opcode) {
852 status = acpi_ds_build_internal_buffer_obj (walk_state, op, length, &obj_desc);
856 case AML_VAR_PACKAGE_OP:
858 status = acpi_ds_build_internal_package_obj (walk_state, op, length, &obj_desc);
862 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
865 if (ACPI_SUCCESS (status)) {
867 * Return the object in the walk_state, unless the parent is a package -
868 * in this case, the return object will be stored in the parse tree
871 if ((!op->common.parent) ||
872 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
873 (op->common.parent->common.aml_opcode != AML_VAR_PACKAGE_OP) &&
874 (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
875 walk_state->result_obj = obj_desc;
879 return_ACPI_STATUS (status);
883 /*******************************************************************************
885 * FUNCTION: acpi_ds_exec_begin_control_op
887 * PARAMETERS: walk_list - The list that owns the walk stack
888 * Op - The control Op
892 * DESCRIPTION: Handles all control ops encountered during control method
895 ******************************************************************************/
898 acpi_ds_exec_begin_control_op (
899 struct acpi_walk_state *walk_state,
900 union acpi_parse_object *op)
902 acpi_status status = AE_OK;
903 union acpi_generic_state *control_state;
906 ACPI_FUNCTION_NAME ("ds_exec_begin_control_op");
909 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
910 op->common.aml_opcode, walk_state));
912 switch (op->common.aml_opcode) {
917 * IF/WHILE: Create a new control state to manage these
918 * constructs. We need to manage these as a stack, in order
921 control_state = acpi_ut_create_control_state ();
922 if (!control_state) {
923 status = AE_NO_MEMORY;
927 * Save a pointer to the predicate for multiple executions
930 control_state->control.aml_predicate_start = walk_state->parser_state.aml - 1;
931 control_state->control.package_end = walk_state->parser_state.pkg_end;
932 control_state->control.opcode = op->common.aml_opcode;
935 /* Push the control state on this walk's control stack */
937 acpi_ut_push_generic_state (&walk_state->control_state, control_state);
942 /* Predicate is in the state object */
943 /* If predicate is true, the IF was executed, ignore ELSE part */
945 if (walk_state->last_predicate) {
946 status = AE_CTRL_TRUE;
963 /*******************************************************************************
965 * FUNCTION: acpi_ds_exec_end_control_op
967 * PARAMETERS: walk_list - The list that owns the walk stack
968 * Op - The control Op
972 * DESCRIPTION: Handles all control ops encountered during control method
975 ******************************************************************************/
978 acpi_ds_exec_end_control_op (
979 struct acpi_walk_state *walk_state,
980 union acpi_parse_object *op)
982 acpi_status status = AE_OK;
983 union acpi_generic_state *control_state;
986 ACPI_FUNCTION_NAME ("ds_exec_end_control_op");
989 switch (op->common.aml_opcode) {
992 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
995 * Save the result of the predicate in case there is an
998 walk_state->last_predicate =
999 (u8) walk_state->control_state->common.value;
1002 * Pop the control state that was created at the start
1003 * of the IF and free it
1005 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
1006 acpi_ut_delete_generic_state (control_state);
1017 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
1019 if (walk_state->control_state->common.value) {
1020 /* Predicate was true, go back and evaluate it again! */
1022 status = AE_CTRL_PENDING;
1025 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1026 "[WHILE_OP] termination! Op=%p\n",op));
1028 /* Pop this control state and free it */
1030 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
1032 walk_state->aml_last_while = control_state->control.aml_predicate_start;
1033 acpi_ut_delete_generic_state (control_state);
1039 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1040 "[RETURN_OP] Op=%p Arg=%p\n",op, op->common.value.arg));
1043 * One optional operand -- the return value
1044 * It can be either an immediate operand or a result that
1045 * has been bubbled up the tree
1047 if (op->common.value.arg) {
1048 /* Since we have a real Return(), delete any implicit return */
1050 acpi_ds_clear_implicit_return (walk_state);
1052 /* Return statement has an immediate operand */
1054 status = acpi_ds_create_operands (walk_state, op->common.value.arg);
1055 if (ACPI_FAILURE (status)) {
1060 * If value being returned is a Reference (such as
1061 * an arg or local), resolve it now because it may
1062 * cease to exist at the end of the method.
1064 status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state);
1065 if (ACPI_FAILURE (status)) {
1070 * Get the return value and save as the last result
1071 * value. This is the only place where walk_state->return_desc
1072 * is set to anything other than zero!
1074 walk_state->return_desc = walk_state->operands[0];
1076 else if ((walk_state->results) &&
1077 (walk_state->results->results.num_results > 0)) {
1078 /* Since we have a real Return(), delete any implicit return */
1080 acpi_ds_clear_implicit_return (walk_state);
1083 * The return value has come from a previous calculation.
1085 * If value being returned is a Reference (such as
1086 * an arg or local), resolve it now because it may
1087 * cease to exist at the end of the method.
1089 * Allow references created by the Index operator to return unchanged.
1091 if ((ACPI_GET_DESCRIPTOR_TYPE (walk_state->results->results.obj_desc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1092 (ACPI_GET_OBJECT_TYPE (walk_state->results->results.obj_desc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1093 ((walk_state->results->results.obj_desc [0])->reference.opcode != AML_INDEX_OP)) {
1094 status = acpi_ex_resolve_to_value (&walk_state->results->results.obj_desc [0], walk_state);
1095 if (ACPI_FAILURE (status)) {
1100 walk_state->return_desc = walk_state->results->results.obj_desc [0];
1103 /* No return operand */
1105 if (walk_state->num_operands) {
1106 acpi_ut_remove_reference (walk_state->operands [0]);
1109 walk_state->operands [0] = NULL;
1110 walk_state->num_operands = 0;
1111 walk_state->return_desc = NULL;
1115 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1116 "Completed RETURN_OP State=%p, ret_val=%p\n",
1117 walk_state, walk_state->return_desc));
1119 /* End the control method execution right now */
1121 status = AE_CTRL_TERMINATE;
1127 /* Just do nothing! */
1131 case AML_BREAK_POINT_OP:
1133 /* Call up to the OS service layer to handle this */
1135 status = acpi_os_signal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1137 /* If and when it returns, all done. */
1143 case AML_CONTINUE_OP: /* ACPI 2.0 */
1146 /* Pop and delete control states until we find a while */
1148 while (walk_state->control_state &&
1149 (walk_state->control_state->control.opcode != AML_WHILE_OP)) {
1150 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
1151 acpi_ut_delete_generic_state (control_state);
1154 /* No while found? */
1156 if (!walk_state->control_state) {
1157 return (AE_AML_NO_WHILE);
1160 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1162 walk_state->aml_last_while = walk_state->control_state->control.package_end;
1164 /* Return status depending on opcode */
1166 if (op->common.aml_opcode == AML_BREAK_OP) {
1167 status = AE_CTRL_BREAK;
1170 status = AE_CTRL_CONTINUE;
1177 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
1178 op->common.aml_opcode, op));
1180 status = AE_AML_BAD_OPCODE;