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] BufferField 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, "[%4.4s] OpRegion Arg Init at AML %p\n",
346 acpi_ut_get_node_name(node),
347 extra_desc->extra.aml_start));
349 /* Execute the argument AML */
351 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
352 extra_desc->extra.aml_length,
353 extra_desc->extra.aml_start);
354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
358 /* Validate the region address/length via the host OS */
360 status = acpi_os_validate_address(obj_desc->region.space_id,
361 obj_desc->region.address,
362 (acpi_size) obj_desc->region.length);
363 if (ACPI_FAILURE(status)) {
365 * Invalid address/length. We will emit an error message and mark
366 * the region as invalid, so that it will cause an additional error if
367 * it is ever used. Then return AE_OK.
369 ACPI_EXCEPTION((AE_INFO, status,
370 "During address validation of OpRegion [%4.4s]",
372 obj_desc->common.flags |= AOPOBJ_INVALID;
376 return_ACPI_STATUS(status);
379 /*******************************************************************************
381 * FUNCTION: acpi_ds_initialize_region
383 * PARAMETERS: obj_handle - Region namespace node
387 * DESCRIPTION: Front end to ev_initialize_region
389 ******************************************************************************/
391 acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
393 union acpi_operand_object *obj_desc;
396 obj_desc = acpi_ns_get_attached_object(obj_handle);
398 /* Namespace is NOT locked */
400 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(u16 aml_opcode,
423 union acpi_operand_object *obj_desc,
424 union acpi_operand_object *buffer_desc,
425 union acpi_operand_object *offset_desc,
426 union acpi_operand_object *length_desc,
427 union acpi_operand_object *result_desc)
435 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
437 /* Host object must be a Buffer */
439 if (ACPI_GET_OBJECT_TYPE(buffer_desc) != ACPI_TYPE_BUFFER) {
441 "Target of Create Field is not a Buffer object - %s",
442 acpi_ut_get_object_type_name(buffer_desc)));
444 status = AE_AML_OPERAND_TYPE;
449 * The last parameter to all of these opcodes (result_desc) started
450 * out as a name_string, and should therefore now be a NS node
451 * after resolution in acpi_ex_resolve_operands().
453 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
455 "(%s) destination not a NS Node [%s]",
456 acpi_ps_get_opcode_name(aml_opcode),
457 acpi_ut_get_descriptor_name(result_desc)));
459 status = AE_AML_OPERAND_TYPE;
463 offset = (u32) offset_desc->integer.value;
466 * Setup the Bit offsets and counts, according to the opcode
468 switch (aml_opcode) {
469 case AML_CREATE_FIELD_OP:
471 /* Offset is in bits, count is in bits */
473 field_flags = AML_FIELD_ACCESS_BYTE;
475 bit_count = (u32) length_desc->integer.value;
477 /* Must have a valid (>0) bit count */
479 if (bit_count == 0) {
481 "Attempt to CreateField of length zero"));
482 status = AE_AML_OPERAND_VALUE;
487 case AML_CREATE_BIT_FIELD_OP:
489 /* Offset is in bits, Field is one bit */
493 field_flags = AML_FIELD_ACCESS_BYTE;
496 case AML_CREATE_BYTE_FIELD_OP:
498 /* Offset is in bytes, field is one byte */
500 bit_offset = 8 * offset;
502 field_flags = AML_FIELD_ACCESS_BYTE;
505 case AML_CREATE_WORD_FIELD_OP:
507 /* Offset is in bytes, field is one word */
509 bit_offset = 8 * offset;
511 field_flags = AML_FIELD_ACCESS_WORD;
514 case AML_CREATE_DWORD_FIELD_OP:
516 /* Offset is in bytes, field is one dword */
518 bit_offset = 8 * offset;
520 field_flags = AML_FIELD_ACCESS_DWORD;
523 case AML_CREATE_QWORD_FIELD_OP:
525 /* Offset is in bytes, field is one qword */
527 bit_offset = 8 * offset;
529 field_flags = AML_FIELD_ACCESS_QWORD;
535 "Unknown field creation opcode %02x", aml_opcode));
536 status = AE_AML_BAD_OPCODE;
540 /* Entire field must fit within the current length of the buffer */
542 if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
544 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
545 acpi_ut_get_node_name(result_desc),
546 bit_offset + bit_count,
547 acpi_ut_get_node_name(buffer_desc->buffer.node),
548 8 * (u32) buffer_desc->buffer.length));
549 status = AE_AML_BUFFER_LIMIT;
554 * Initialize areas of the field object that are common to all fields
555 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
556 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
558 status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
559 bit_offset, bit_count);
560 if (ACPI_FAILURE(status)) {
564 obj_desc->buffer_field.buffer_obj = buffer_desc;
566 /* Reference count for buffer_desc inherits obj_desc count */
568 buffer_desc->common.reference_count = (u16)
569 (buffer_desc->common.reference_count +
570 obj_desc->common.reference_count);
574 /* Always delete the operands */
576 acpi_ut_remove_reference(offset_desc);
577 acpi_ut_remove_reference(buffer_desc);
579 if (aml_opcode == AML_CREATE_FIELD_OP) {
580 acpi_ut_remove_reference(length_desc);
583 /* On failure, delete the result descriptor */
585 if (ACPI_FAILURE(status)) {
586 acpi_ut_remove_reference(result_desc); /* Result descriptor */
588 /* Now the address and length are valid for this buffer_field */
590 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
593 return_ACPI_STATUS(status);
596 /*******************************************************************************
598 * FUNCTION: acpi_ds_eval_buffer_field_operands
600 * PARAMETERS: walk_state - Current walk
601 * Op - A valid buffer_field Op object
605 * DESCRIPTION: Get buffer_field Buffer and Index
606 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
608 ******************************************************************************/
611 acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
612 union acpi_parse_object *op)
615 union acpi_operand_object *obj_desc;
616 struct acpi_namespace_node *node;
617 union acpi_parse_object *next_op;
619 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
622 * This is where we evaluate the address and length fields of the
623 * create_xxx_field declaration
625 node = op->common.node;
627 /* next_op points to the op that holds the Buffer */
629 next_op = op->common.value.arg;
631 /* Evaluate/create the address and length operands */
633 status = acpi_ds_create_operands(walk_state, next_op);
634 if (ACPI_FAILURE(status)) {
635 return_ACPI_STATUS(status);
638 obj_desc = acpi_ns_get_attached_object(node);
640 return_ACPI_STATUS(AE_NOT_EXIST);
643 /* Resolve the operands */
645 status = acpi_ex_resolve_operands(op->common.aml_opcode,
646 ACPI_WALK_OPERANDS, walk_state);
648 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
649 acpi_ps_get_opcode_name(op->common.aml_opcode),
650 walk_state->num_operands,
651 "after AcpiExResolveOperands");
653 if (ACPI_FAILURE(status)) {
654 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
655 acpi_ps_get_opcode_name(op->common.aml_opcode),
658 return_ACPI_STATUS(status);
661 /* Initialize the Buffer Field */
663 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
665 /* NOTE: Slightly different operands for this opcode */
668 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
669 walk_state->operands[0],
670 walk_state->operands[1],
671 walk_state->operands[2],
672 walk_state->operands[3]);
674 /* All other, create_xxx_field opcodes */
677 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
678 walk_state->operands[0],
679 walk_state->operands[1], NULL,
680 walk_state->operands[2]);
683 return_ACPI_STATUS(status);
686 /*******************************************************************************
688 * FUNCTION: acpi_ds_eval_region_operands
690 * PARAMETERS: walk_state - Current walk
691 * Op - A valid region Op object
695 * DESCRIPTION: Get region address and length
696 * Called from acpi_ds_exec_end_op during op_region parse tree walk
698 ******************************************************************************/
701 acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
702 union acpi_parse_object *op)
705 union acpi_operand_object *obj_desc;
706 union acpi_operand_object *operand_desc;
707 struct acpi_namespace_node *node;
708 union acpi_parse_object *next_op;
710 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
713 * This is where we evaluate the address and length fields of the
714 * op_region declaration
716 node = op->common.node;
718 /* next_op points to the op that holds the space_iD */
720 next_op = op->common.value.arg;
722 /* next_op points to address op */
724 next_op = next_op->common.next;
726 /* Evaluate/create the address and length operands */
728 status = acpi_ds_create_operands(walk_state, next_op);
729 if (ACPI_FAILURE(status)) {
730 return_ACPI_STATUS(status);
733 /* Resolve the length and address operands to numbers */
735 status = acpi_ex_resolve_operands(op->common.aml_opcode,
736 ACPI_WALK_OPERANDS, walk_state);
737 if (ACPI_FAILURE(status)) {
738 return_ACPI_STATUS(status);
741 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
742 acpi_ps_get_opcode_name(op->common.aml_opcode),
743 1, "after AcpiExResolveOperands");
745 obj_desc = acpi_ns_get_attached_object(node);
747 return_ACPI_STATUS(AE_NOT_EXIST);
751 * Get the length operand and save it
754 operand_desc = walk_state->operands[walk_state->num_operands - 1];
756 obj_desc->region.length = (u32) operand_desc->integer.value;
757 acpi_ut_remove_reference(operand_desc);
760 * Get the address and save it
761 * (at top of stack - 1)
763 operand_desc = walk_state->operands[walk_state->num_operands - 2];
765 obj_desc->region.address = (acpi_physical_address)
766 operand_desc->integer.value;
767 acpi_ut_remove_reference(operand_desc);
769 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
771 ACPI_FORMAT_UINT64(obj_desc->region.address),
772 obj_desc->region.length));
774 /* Now the address and length are valid for this opregion */
776 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
778 return_ACPI_STATUS(status);
781 /*******************************************************************************
783 * FUNCTION: acpi_ds_eval_data_object_operands
785 * PARAMETERS: walk_state - Current walk
786 * Op - A valid data_object Op object
787 * obj_desc - data_object
791 * DESCRIPTION: Get the operands and complete the following data object types:
794 ******************************************************************************/
797 acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
798 union acpi_parse_object *op,
799 union acpi_operand_object *obj_desc)
802 union acpi_operand_object *arg_desc;
805 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
807 /* The first operand (for all of these data objects) is the length */
809 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
810 if (ACPI_FAILURE(status)) {
811 return_ACPI_STATUS(status);
814 status = acpi_ex_resolve_operands(walk_state->opcode,
816 operands[walk_state->num_operands -
818 if (ACPI_FAILURE(status)) {
819 return_ACPI_STATUS(status);
822 /* Extract length operand */
824 arg_desc = walk_state->operands[walk_state->num_operands - 1];
825 length = (u32) arg_desc->integer.value;
827 /* Cleanup for length operand */
829 status = acpi_ds_obj_stack_pop(1, walk_state);
830 if (ACPI_FAILURE(status)) {
831 return_ACPI_STATUS(status);
834 acpi_ut_remove_reference(arg_desc);
837 * Create the actual data object
839 switch (op->common.aml_opcode) {
843 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
848 case AML_VAR_PACKAGE_OP:
851 acpi_ds_build_internal_package_obj(walk_state, op, length,
856 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
859 if (ACPI_SUCCESS(status)) {
861 * Return the object in the walk_state, unless the parent is a package -
862 * in this case, the return object will be stored in the parse tree
865 if ((!op->common.parent) ||
866 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
867 (op->common.parent->common.aml_opcode !=
869 && (op->common.parent->common.aml_opcode !=
871 walk_state->result_obj = obj_desc;
875 return_ACPI_STATUS(status);
878 /*******************************************************************************
880 * FUNCTION: acpi_ds_exec_begin_control_op
882 * PARAMETERS: walk_list - The list that owns the walk stack
883 * Op - The control Op
887 * DESCRIPTION: Handles all control ops encountered during control method
890 ******************************************************************************/
893 acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
894 union acpi_parse_object *op)
896 acpi_status status = AE_OK;
897 union acpi_generic_state *control_state;
899 ACPI_FUNCTION_NAME(ds_exec_begin_control_op);
901 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
902 op->common.aml_opcode, walk_state));
904 switch (op->common.aml_opcode) {
909 * IF/WHILE: Create a new control state to manage these
910 * constructs. We need to manage these as a stack, in order
913 control_state = acpi_ut_create_control_state();
914 if (!control_state) {
915 status = AE_NO_MEMORY;
919 * Save a pointer to the predicate for multiple executions
922 control_state->control.aml_predicate_start =
923 walk_state->parser_state.aml - 1;
924 control_state->control.package_end =
925 walk_state->parser_state.pkg_end;
926 control_state->control.opcode = op->common.aml_opcode;
928 /* Push the control state on this walk's control stack */
930 acpi_ut_push_generic_state(&walk_state->control_state,
936 /* Predicate is in the state object */
937 /* If predicate is true, the IF was executed, ignore ELSE part */
939 if (walk_state->last_predicate) {
940 status = AE_CTRL_TRUE;
956 /*******************************************************************************
958 * FUNCTION: acpi_ds_exec_end_control_op
960 * PARAMETERS: walk_list - The list that owns the walk stack
961 * Op - The control Op
965 * DESCRIPTION: Handles all control ops encountered during control method
968 ******************************************************************************/
971 acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
972 union acpi_parse_object * op)
974 acpi_status status = AE_OK;
975 union acpi_generic_state *control_state;
977 ACPI_FUNCTION_NAME(ds_exec_end_control_op);
979 switch (op->common.aml_opcode) {
982 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
985 * Save the result of the predicate in case there is an
988 walk_state->last_predicate =
989 (u8) walk_state->control_state->common.value;
992 * Pop the control state that was created at the start
993 * of the IF and free it
996 acpi_ut_pop_generic_state(&walk_state->control_state);
997 acpi_ut_delete_generic_state(control_state);
1006 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
1008 if (walk_state->control_state->common.value) {
1010 /* Predicate was true, go back and evaluate it again! */
1012 status = AE_CTRL_PENDING;
1015 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1016 "[WHILE_OP] termination! Op=%p\n", op));
1018 /* Pop this control state and free it */
1021 acpi_ut_pop_generic_state(&walk_state->control_state);
1023 walk_state->aml_last_while =
1024 control_state->control.aml_predicate_start;
1025 acpi_ut_delete_generic_state(control_state);
1030 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1031 "[RETURN_OP] Op=%p Arg=%p\n", op,
1032 op->common.value.arg));
1035 * One optional operand -- the return value
1036 * It can be either an immediate operand or a result that
1037 * has been bubbled up the tree
1039 if (op->common.value.arg) {
1041 /* Since we have a real Return(), delete any implicit return */
1043 acpi_ds_clear_implicit_return(walk_state);
1045 /* Return statement has an immediate operand */
1048 acpi_ds_create_operands(walk_state,
1049 op->common.value.arg);
1050 if (ACPI_FAILURE(status)) {
1055 * If value being returned is a Reference (such as
1056 * an arg or local), resolve it now because it may
1057 * cease to exist at the end of the method.
1060 acpi_ex_resolve_to_value(&walk_state->operands[0],
1062 if (ACPI_FAILURE(status)) {
1067 * Get the return value and save as the last result
1068 * value. This is the only place where walk_state->return_desc
1069 * is set to anything other than zero!
1071 walk_state->return_desc = walk_state->operands[0];
1072 } else if ((walk_state->results) &&
1073 (walk_state->results->results.num_results > 0)) {
1075 /* Since we have a real Return(), delete any implicit return */
1077 acpi_ds_clear_implicit_return(walk_state);
1080 * The return value has come from a previous calculation.
1082 * If value being returned is a Reference (such as
1083 * an arg or local), resolve it now because it may
1084 * cease to exist at the end of the method.
1086 * Allow references created by the Index operator to return unchanged.
1088 if ((ACPI_GET_DESCRIPTOR_TYPE
1089 (walk_state->results->results.obj_desc[0]) ==
1090 ACPI_DESC_TYPE_OPERAND)
1092 (ACPI_GET_OBJECT_TYPE
1093 (walk_state->results->results.obj_desc[0]) ==
1094 ACPI_TYPE_LOCAL_REFERENCE)
1095 && ((walk_state->results->results.obj_desc[0])->
1096 reference.opcode != AML_INDEX_OP)) {
1098 acpi_ex_resolve_to_value(&walk_state->
1102 if (ACPI_FAILURE(status)) {
1107 walk_state->return_desc =
1108 walk_state->results->results.obj_desc[0];
1110 /* No return operand */
1112 if (walk_state->num_operands) {
1113 acpi_ut_remove_reference(walk_state->
1117 walk_state->operands[0] = NULL;
1118 walk_state->num_operands = 0;
1119 walk_state->return_desc = NULL;
1122 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1123 "Completed RETURN_OP State=%p, RetVal=%p\n",
1124 walk_state, walk_state->return_desc));
1126 /* End the control method execution right now */
1128 status = AE_CTRL_TERMINATE;
1133 /* Just do nothing! */
1136 case AML_BREAK_POINT_OP:
1138 /* Call up to the OS service layer to handle this */
1141 acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
1142 "Executed AML Breakpoint opcode");
1144 /* If and when it returns, all done. */
1149 case AML_CONTINUE_OP: /* ACPI 2.0 */
1151 /* Pop and delete control states until we find a while */
1153 while (walk_state->control_state &&
1154 (walk_state->control_state->control.opcode !=
1157 acpi_ut_pop_generic_state(&walk_state->
1159 acpi_ut_delete_generic_state(control_state);
1162 /* No while found? */
1164 if (!walk_state->control_state) {
1165 return (AE_AML_NO_WHILE);
1168 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1170 walk_state->aml_last_while =
1171 walk_state->control_state->control.package_end;
1173 /* Return status depending on opcode */
1175 if (op->common.aml_opcode == AML_BREAK_OP) {
1176 status = AE_CTRL_BREAK;
1178 status = AE_CTRL_CONTINUE;
1184 ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
1185 op->common.aml_opcode, op));
1187 status = AE_AML_BAD_OPCODE;