Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / dispatcher / dsopcode.c
blob5c987a0e7b75e859863c6afc0dbfec4a9b8d3908
1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
4 * "control" opcodes
6 *****************************************************************************/
8 /*
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
14 * are met:
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.
31 * NO WARRANTY
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
66 * RETURN: Status.
68 * DESCRIPTION: Late (deferred) execution of region or field arguments
70 ****************************************************************************/
72 acpi_status
73 acpi_ds_execute_arguments (
74 struct acpi_namespace_node *node,
75 struct acpi_namespace_node *scope_node,
76 u32 aml_length,
77 u8 *aml_start)
79 acpi_status status;
80 union acpi_parse_object *op;
81 struct acpi_walk_state *walk_state;
84 ACPI_FUNCTION_TRACE ("ds_execute_arguments");
88 * Allocate a new parser op to be the root of the parsed tree
90 op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
91 if (!op) {
92 return_ACPI_STATUS (AE_NO_MEMORY);
95 /* Save the Node for use in acpi_ps_parse_aml */
97 op->common.node = scope_node;
99 /* Create and initialize a new parser state */
101 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
102 if (!walk_state) {
103 return_ACPI_STATUS (AE_NO_MEMORY);
106 status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
107 aml_length, NULL, 1);
108 if (ACPI_FAILURE (status)) {
109 acpi_ds_delete_walk_state (walk_state);
110 return_ACPI_STATUS (status);
113 /* Mark this parse as a deferred opcode */
115 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
116 walk_state->deferred_node = node;
118 /* Pass1: Parse the entire declaration */
120 status = acpi_ps_parse_aml (walk_state);
121 if (ACPI_FAILURE (status)) {
122 acpi_ps_delete_parse_tree (op);
123 return_ACPI_STATUS (status);
126 /* Get and init the Op created above */
128 op->common.node = node;
129 acpi_ps_delete_parse_tree (op);
131 /* Evaluate the deferred arguments */
133 op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
134 if (!op) {
135 return_ACPI_STATUS (AE_NO_MEMORY);
138 op->common.node = scope_node;
140 /* Create and initialize a new parser state */
142 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
143 if (!walk_state) {
144 return_ACPI_STATUS (AE_NO_MEMORY);
147 /* Execute the opcode and arguments */
149 status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
150 aml_length, NULL, 3);
151 if (ACPI_FAILURE (status)) {
152 acpi_ds_delete_walk_state (walk_state);
153 return_ACPI_STATUS (status);
156 /* Mark this execution as a deferred opcode */
158 walk_state->deferred_node = node;
159 status = acpi_ps_parse_aml (walk_state);
160 acpi_ps_delete_parse_tree (op);
161 return_ACPI_STATUS (status);
165 /*****************************************************************************
167 * FUNCTION: acpi_ds_get_buffer_field_arguments
169 * PARAMETERS: obj_desc - A valid buffer_field object
171 * RETURN: Status.
173 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
174 * evaluation of these field attributes.
176 ****************************************************************************/
178 acpi_status
179 acpi_ds_get_buffer_field_arguments (
180 union acpi_operand_object *obj_desc)
182 union acpi_operand_object *extra_desc;
183 struct acpi_namespace_node *node;
184 acpi_status status;
187 ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_field_arguments", obj_desc);
190 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
191 return_ACPI_STATUS (AE_OK);
194 /* Get the AML pointer (method object) and buffer_field node */
196 extra_desc = acpi_ns_get_secondary_object (obj_desc);
197 node = obj_desc->buffer_field.node;
199 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL));
200 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n",
201 acpi_ut_get_node_name (node)));
203 /* Execute the AML code for the term_arg arguments */
205 status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
206 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
207 return_ACPI_STATUS (status);
211 /*****************************************************************************
213 * FUNCTION: acpi_ds_get_buffer_arguments
215 * PARAMETERS: obj_desc - A valid Buffer object
217 * RETURN: Status.
219 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
220 * the late evaluation of these attributes.
222 ****************************************************************************/
224 acpi_status
225 acpi_ds_get_buffer_arguments (
226 union acpi_operand_object *obj_desc)
228 struct acpi_namespace_node *node;
229 acpi_status status;
232 ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_arguments", obj_desc);
235 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
236 return_ACPI_STATUS (AE_OK);
239 /* Get the Buffer node */
241 node = obj_desc->buffer.node;
242 if (!node) {
243 ACPI_REPORT_ERROR ((
244 "No pointer back to NS node in buffer obj %p\n", obj_desc));
245 return_ACPI_STATUS (AE_AML_INTERNAL);
248 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
250 /* Execute the AML code for the term_arg arguments */
252 status = acpi_ds_execute_arguments (node, node,
253 obj_desc->buffer.aml_length, obj_desc->buffer.aml_start);
254 return_ACPI_STATUS (status);
258 /*****************************************************************************
260 * FUNCTION: acpi_ds_get_package_arguments
262 * PARAMETERS: obj_desc - A valid Package object
264 * RETURN: Status.
266 * DESCRIPTION: Get Package length and initializer byte list. This implements
267 * the late evaluation of these attributes.
269 ****************************************************************************/
271 acpi_status
272 acpi_ds_get_package_arguments (
273 union acpi_operand_object *obj_desc)
275 struct acpi_namespace_node *node;
276 acpi_status status;
279 ACPI_FUNCTION_TRACE_PTR ("ds_get_package_arguments", obj_desc);
282 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
283 return_ACPI_STATUS (AE_OK);
286 /* Get the Package node */
288 node = obj_desc->package.node;
289 if (!node) {
290 ACPI_REPORT_ERROR ((
291 "No pointer back to NS node in package %p\n", obj_desc));
292 return_ACPI_STATUS (AE_AML_INTERNAL);
295 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
297 /* Execute the AML code for the term_arg arguments */
299 status = acpi_ds_execute_arguments (node, node,
300 obj_desc->package.aml_length, obj_desc->package.aml_start);
301 return_ACPI_STATUS (status);
305 /*****************************************************************************
307 * FUNCTION: acpi_ds_get_region_arguments
309 * PARAMETERS: obj_desc - A valid region object
311 * RETURN: Status.
313 * DESCRIPTION: Get region address and length. This implements the late
314 * evaluation of these region attributes.
316 ****************************************************************************/
318 acpi_status
319 acpi_ds_get_region_arguments (
320 union acpi_operand_object *obj_desc)
322 struct acpi_namespace_node *node;
323 acpi_status status;
324 union acpi_operand_object *extra_desc;
327 ACPI_FUNCTION_TRACE_PTR ("ds_get_region_arguments", obj_desc);
330 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
331 return_ACPI_STATUS (AE_OK);
334 extra_desc = acpi_ns_get_secondary_object (obj_desc);
335 if (!extra_desc) {
336 return_ACPI_STATUS (AE_NOT_EXIST);
339 /* Get the Region node */
341 node = obj_desc->region.node;
343 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL));
345 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] op_region Arg Init at AML %p\n",
346 acpi_ut_get_node_name (node), extra_desc->extra.aml_start));
348 /* Execute the argument AML */
350 status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
351 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
352 return_ACPI_STATUS (status);
356 /*****************************************************************************
358 * FUNCTION: acpi_ds_initialize_region
360 * PARAMETERS: Op - A valid region Op object
362 * RETURN: Status
364 * DESCRIPTION: Front end to ev_initialize_region
366 ****************************************************************************/
368 acpi_status
369 acpi_ds_initialize_region (
370 acpi_handle obj_handle)
372 union acpi_operand_object *obj_desc;
373 acpi_status status;
376 obj_desc = acpi_ns_get_attached_object (obj_handle);
378 /* Namespace is NOT locked */
380 status = acpi_ev_initialize_region (obj_desc, FALSE);
381 return (status);
385 /*****************************************************************************
387 * FUNCTION: acpi_ds_init_buffer_field
389 * PARAMETERS: aml_opcode - create_xxx_field
390 * obj_desc - buffer_field object
391 * buffer_desc - Host Buffer
392 * offset_desc - Offset into buffer
393 * Length - Length of field (CREATE_FIELD_OP only)
394 * Result - Where to store the result
396 * RETURN: Status
398 * DESCRIPTION: Perform actual initialization of a buffer field
400 ****************************************************************************/
402 acpi_status
403 acpi_ds_init_buffer_field (
404 u16 aml_opcode,
405 union acpi_operand_object *obj_desc,
406 union acpi_operand_object *buffer_desc,
407 union acpi_operand_object *offset_desc,
408 union acpi_operand_object *length_desc,
409 union acpi_operand_object *result_desc)
411 u32 offset;
412 u32 bit_offset;
413 u32 bit_count;
414 u8 field_flags;
415 acpi_status status;
418 ACPI_FUNCTION_TRACE_PTR ("ds_init_buffer_field", obj_desc);
421 /* Host object must be a Buffer */
423 if (ACPI_GET_OBJECT_TYPE (buffer_desc) != ACPI_TYPE_BUFFER) {
424 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
425 "Target of Create Field is not a Buffer object - %s\n",
426 acpi_ut_get_object_type_name (buffer_desc)));
428 status = AE_AML_OPERAND_TYPE;
429 goto cleanup;
433 * The last parameter to all of these opcodes (result_desc) started
434 * out as a name_string, and should therefore now be a NS node
435 * after resolution in acpi_ex_resolve_operands().
437 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
438 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n",
439 acpi_ps_get_opcode_name (aml_opcode), acpi_ut_get_descriptor_name (result_desc)));
441 status = AE_AML_OPERAND_TYPE;
442 goto cleanup;
445 offset = (u32) offset_desc->integer.value;
448 * Setup the Bit offsets and counts, according to the opcode
450 switch (aml_opcode) {
451 case AML_CREATE_FIELD_OP:
453 /* Offset is in bits, count is in bits */
455 bit_offset = offset;
456 bit_count = (u32) length_desc->integer.value;
457 field_flags = AML_FIELD_ACCESS_BYTE;
458 break;
460 case AML_CREATE_BIT_FIELD_OP:
462 /* Offset is in bits, Field is one bit */
464 bit_offset = offset;
465 bit_count = 1;
466 field_flags = AML_FIELD_ACCESS_BYTE;
467 break;
469 case AML_CREATE_BYTE_FIELD_OP:
471 /* Offset is in bytes, field is one byte */
473 bit_offset = 8 * offset;
474 bit_count = 8;
475 field_flags = AML_FIELD_ACCESS_BYTE;
476 break;
478 case AML_CREATE_WORD_FIELD_OP:
480 /* Offset is in bytes, field is one word */
482 bit_offset = 8 * offset;
483 bit_count = 16;
484 field_flags = AML_FIELD_ACCESS_WORD;
485 break;
487 case AML_CREATE_DWORD_FIELD_OP:
489 /* Offset is in bytes, field is one dword */
491 bit_offset = 8 * offset;
492 bit_count = 32;
493 field_flags = AML_FIELD_ACCESS_DWORD;
494 break;
496 case AML_CREATE_QWORD_FIELD_OP:
498 /* Offset is in bytes, field is one qword */
500 bit_offset = 8 * offset;
501 bit_count = 64;
502 field_flags = AML_FIELD_ACCESS_QWORD;
503 break;
505 default:
507 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
508 "Unknown field creation opcode %02x\n",
509 aml_opcode));
510 status = AE_AML_BAD_OPCODE;
511 goto cleanup;
514 /* Entire field must fit within the current length of the buffer */
516 if ((bit_offset + bit_count) >
517 (8 * (u32) buffer_desc->buffer.length)) {
518 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
519 "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
520 acpi_ut_get_node_name (result_desc),
521 bit_offset + bit_count,
522 acpi_ut_get_node_name (buffer_desc->buffer.node),
523 8 * (u32) buffer_desc->buffer.length));
524 status = AE_AML_BUFFER_LIMIT;
525 goto cleanup;
529 * Initialize areas of the field object that are common to all fields
530 * For field_flags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
532 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
533 bit_offset, bit_count);
534 if (ACPI_FAILURE (status)) {
535 goto cleanup;
538 obj_desc->buffer_field.buffer_obj = buffer_desc;
540 /* Reference count for buffer_desc inherits obj_desc count */
542 buffer_desc->common.reference_count = (u16) (buffer_desc->common.reference_count +
543 obj_desc->common.reference_count);
546 cleanup:
548 /* Always delete the operands */
550 acpi_ut_remove_reference (offset_desc);
551 acpi_ut_remove_reference (buffer_desc);
553 if (aml_opcode == AML_CREATE_FIELD_OP) {
554 acpi_ut_remove_reference (length_desc);
557 /* On failure, delete the result descriptor */
559 if (ACPI_FAILURE (status)) {
560 acpi_ut_remove_reference (result_desc); /* Result descriptor */
562 else {
563 /* Now the address and length are valid for this buffer_field */
565 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
568 return_ACPI_STATUS (status);
572 /*****************************************************************************
574 * FUNCTION: acpi_ds_eval_buffer_field_operands
576 * PARAMETERS: walk_state - Current walk
577 * Op - A valid buffer_field Op object
579 * RETURN: Status
581 * DESCRIPTION: Get buffer_field Buffer and Index
582 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
584 ****************************************************************************/
586 acpi_status
587 acpi_ds_eval_buffer_field_operands (
588 struct acpi_walk_state *walk_state,
589 union acpi_parse_object *op)
591 acpi_status status;
592 union acpi_operand_object *obj_desc;
593 struct acpi_namespace_node *node;
594 union acpi_parse_object *next_op;
597 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);
618 if (!obj_desc) {
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, "after acpi_ex_resolve_operands");
631 if (ACPI_FAILURE (status)) {
632 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
633 acpi_ps_get_opcode_name (op->common.aml_opcode), status));
635 return_ACPI_STATUS (status);
638 /* Initialize the Buffer Field */
640 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
641 /* NOTE: Slightly different operands for this opcode */
643 status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
644 walk_state->operands[0], walk_state->operands[1],
645 walk_state->operands[2], walk_state->operands[3]);
647 else {
648 /* All other, create_xxx_field opcodes */
650 status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
651 walk_state->operands[0], walk_state->operands[1],
652 NULL, walk_state->operands[2]);
655 return_ACPI_STATUS (status);
659 /*****************************************************************************
661 * FUNCTION: acpi_ds_eval_region_operands
663 * PARAMETERS: walk_state - Current walk
664 * Op - A valid region Op object
666 * RETURN: Status
668 * DESCRIPTION: Get region address and length
669 * Called from acpi_ds_exec_end_op during op_region parse tree walk
671 ****************************************************************************/
673 acpi_status
674 acpi_ds_eval_region_operands (
675 struct acpi_walk_state *walk_state,
676 union acpi_parse_object *op)
678 acpi_status status;
679 union acpi_operand_object *obj_desc;
680 union acpi_operand_object *operand_desc;
681 struct acpi_namespace_node *node;
682 union acpi_parse_object *next_op;
685 ACPI_FUNCTION_TRACE_PTR ("ds_eval_region_operands", op);
689 * This is where we evaluate the address and length fields of the op_region declaration
691 node = op->common.node;
693 /* next_op points to the op that holds the space_iD */
695 next_op = op->common.value.arg;
697 /* next_op points to address op */
699 next_op = next_op->common.next;
701 /* Evaluate/create the address and length operands */
703 status = acpi_ds_create_operands (walk_state, next_op);
704 if (ACPI_FAILURE (status)) {
705 return_ACPI_STATUS (status);
708 /* Resolve the length and address operands to numbers */
710 status = acpi_ex_resolve_operands (op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state);
711 if (ACPI_FAILURE (status)) {
712 return_ACPI_STATUS (status);
715 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
716 acpi_ps_get_opcode_name (op->common.aml_opcode),
717 1, "after acpi_ex_resolve_operands");
719 obj_desc = acpi_ns_get_attached_object (node);
720 if (!obj_desc) {
721 return_ACPI_STATUS (AE_NOT_EXIST);
725 * Get the length operand and save it
726 * (at Top of stack)
728 operand_desc = walk_state->operands[walk_state->num_operands - 1];
730 obj_desc->region.length = (u32) operand_desc->integer.value;
731 acpi_ut_remove_reference (operand_desc);
734 * Get the address and save it
735 * (at top of stack - 1)
737 operand_desc = walk_state->operands[walk_state->num_operands - 2];
739 obj_desc->region.address = (acpi_physical_address) operand_desc->integer.value;
740 acpi_ut_remove_reference (operand_desc);
742 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
743 obj_desc,
744 ACPI_FORMAT_UINT64 (obj_desc->region.address),
745 obj_desc->region.length));
747 /* Now the address and length are valid for this opregion */
749 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
751 return_ACPI_STATUS (status);
755 /*****************************************************************************
757 * FUNCTION: acpi_ds_eval_data_object_operands
759 * PARAMETERS: walk_state - Current walk
760 * Op - A valid data_object Op object
761 * obj_desc - data_object
763 * RETURN: Status
765 * DESCRIPTION: Get the operands and complete the following data object types:
766 * Buffer, Package.
768 ****************************************************************************/
770 acpi_status
771 acpi_ds_eval_data_object_operands (
772 struct acpi_walk_state *walk_state,
773 union acpi_parse_object *op,
774 union acpi_operand_object *obj_desc)
776 acpi_status status;
777 union acpi_operand_object *arg_desc;
778 u32 length;
781 ACPI_FUNCTION_TRACE ("ds_eval_data_object_operands");
784 /* The first operand (for all of these data objects) is the length */
786 status = acpi_ds_create_operand (walk_state, op->common.value.arg, 1);
787 if (ACPI_FAILURE (status)) {
788 return_ACPI_STATUS (status);
791 status = acpi_ex_resolve_operands (walk_state->opcode,
792 &(walk_state->operands [walk_state->num_operands -1]),
793 walk_state);
794 if (ACPI_FAILURE (status)) {
795 return_ACPI_STATUS (status);
798 /* Extract length operand */
800 arg_desc = walk_state->operands [walk_state->num_operands - 1];
801 length = (u32) arg_desc->integer.value;
803 /* Cleanup for length operand */
805 status = acpi_ds_obj_stack_pop (1, walk_state);
806 if (ACPI_FAILURE (status)) {
807 return_ACPI_STATUS (status);
810 acpi_ut_remove_reference (arg_desc);
813 * Create the actual data object
815 switch (op->common.aml_opcode) {
816 case AML_BUFFER_OP:
818 status = acpi_ds_build_internal_buffer_obj (walk_state, op, length, &obj_desc);
819 break;
821 case AML_PACKAGE_OP:
822 case AML_VAR_PACKAGE_OP:
824 status = acpi_ds_build_internal_package_obj (walk_state, op, length, &obj_desc);
825 break;
827 default:
828 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
831 if (ACPI_SUCCESS (status)) {
833 * Return the object in the walk_state, unless the parent is a package --
834 * in this case, the return object will be stored in the parse tree
835 * for the package.
837 if ((!op->common.parent) ||
838 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
839 (op->common.parent->common.aml_opcode != AML_VAR_PACKAGE_OP) &&
840 (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
841 walk_state->result_obj = obj_desc;
845 return_ACPI_STATUS (status);
849 /*******************************************************************************
851 * FUNCTION: acpi_ds_exec_begin_control_op
853 * PARAMETERS: walk_list - The list that owns the walk stack
854 * Op - The control Op
856 * RETURN: Status
858 * DESCRIPTION: Handles all control ops encountered during control method
859 * execution.
861 ******************************************************************************/
863 acpi_status
864 acpi_ds_exec_begin_control_op (
865 struct acpi_walk_state *walk_state,
866 union acpi_parse_object *op)
868 acpi_status status = AE_OK;
869 union acpi_generic_state *control_state;
872 ACPI_FUNCTION_NAME ("ds_exec_begin_control_op");
875 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
876 op->common.aml_opcode, walk_state));
878 switch (op->common.aml_opcode) {
879 case AML_IF_OP:
880 case AML_WHILE_OP:
883 * IF/WHILE: Create a new control state to manage these
884 * constructs. We need to manage these as a stack, in order
885 * to handle nesting.
887 control_state = acpi_ut_create_control_state ();
888 if (!control_state) {
889 status = AE_NO_MEMORY;
890 break;
893 * Save a pointer to the predicate for multiple executions
894 * of a loop
896 control_state->control.aml_predicate_start = walk_state->parser_state.aml - 1;
897 control_state->control.package_end = walk_state->parser_state.pkg_end;
898 control_state->control.opcode = op->common.aml_opcode;
901 /* Push the control state on this walk's control stack */
903 acpi_ut_push_generic_state (&walk_state->control_state, control_state);
904 break;
906 case AML_ELSE_OP:
908 /* Predicate is in the state object */
909 /* If predicate is true, the IF was executed, ignore ELSE part */
911 if (walk_state->last_predicate) {
912 status = AE_CTRL_TRUE;
915 break;
917 case AML_RETURN_OP:
919 break;
921 default:
922 break;
925 return (status);
929 /*******************************************************************************
931 * FUNCTION: acpi_ds_exec_end_control_op
933 * PARAMETERS: walk_list - The list that owns the walk stack
934 * Op - The control Op
936 * RETURN: Status
938 * DESCRIPTION: Handles all control ops encountered during control method
939 * execution.
941 ******************************************************************************/
943 acpi_status
944 acpi_ds_exec_end_control_op (
945 struct acpi_walk_state *walk_state,
946 union acpi_parse_object *op)
948 acpi_status status = AE_OK;
949 union acpi_generic_state *control_state;
952 ACPI_FUNCTION_NAME ("ds_exec_end_control_op");
955 switch (op->common.aml_opcode) {
956 case AML_IF_OP:
958 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
961 * Save the result of the predicate in case there is an
962 * ELSE to come
964 walk_state->last_predicate =
965 (u8) walk_state->control_state->common.value;
968 * Pop the control state that was created at the start
969 * of the IF and free it
971 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
972 acpi_ut_delete_generic_state (control_state);
973 break;
976 case AML_ELSE_OP:
978 break;
981 case AML_WHILE_OP:
983 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
985 if (walk_state->control_state->common.value) {
986 /* Predicate was true, go back and evaluate it again! */
988 status = AE_CTRL_PENDING;
991 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", op));
993 /* Pop this control state and free it */
995 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
997 walk_state->aml_last_while = control_state->control.aml_predicate_start;
998 acpi_ut_delete_generic_state (control_state);
999 break;
1002 case AML_RETURN_OP:
1004 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1005 "[RETURN_OP] Op=%p Arg=%p\n",op, op->common.value.arg));
1008 * One optional operand -- the return value
1009 * It can be either an immediate operand or a result that
1010 * has been bubbled up the tree
1012 if (op->common.value.arg) {
1013 /* Since we have a real Return(), delete any implicit return */
1015 acpi_ds_clear_implicit_return (walk_state);
1017 /* Return statement has an immediate operand */
1019 status = acpi_ds_create_operands (walk_state, op->common.value.arg);
1020 if (ACPI_FAILURE (status)) {
1021 return (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)) {
1031 return (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)) {
1043 /* Since we have a real Return(), delete any implicit return */
1045 acpi_ds_clear_implicit_return (walk_state);
1048 * The return value has come from a previous calculation.
1050 * If value being returned is a Reference (such as
1051 * an arg or local), resolve it now because it may
1052 * cease to exist at the end of the method.
1054 * Allow references created by the Index operator to return unchanged.
1056 if ((ACPI_GET_DESCRIPTOR_TYPE (walk_state->results->results.obj_desc[0]) == ACPI_DESC_TYPE_OPERAND) &&
1057 (ACPI_GET_OBJECT_TYPE (walk_state->results->results.obj_desc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
1058 ((walk_state->results->results.obj_desc [0])->reference.opcode != AML_INDEX_OP)) {
1059 status = acpi_ex_resolve_to_value (&walk_state->results->results.obj_desc [0], walk_state);
1060 if (ACPI_FAILURE (status)) {
1061 return (status);
1065 walk_state->return_desc = walk_state->results->results.obj_desc [0];
1067 else {
1068 /* No return operand */
1070 if (walk_state->num_operands) {
1071 acpi_ut_remove_reference (walk_state->operands [0]);
1074 walk_state->operands [0] = NULL;
1075 walk_state->num_operands = 0;
1076 walk_state->return_desc = NULL;
1080 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1081 "Completed RETURN_OP State=%p, ret_val=%p\n",
1082 walk_state, walk_state->return_desc));
1084 /* End the control method execution right now */
1086 status = AE_CTRL_TERMINATE;
1087 break;
1090 case AML_NOOP_OP:
1092 /* Just do nothing! */
1093 break;
1096 case AML_BREAK_POINT_OP:
1098 /* Call up to the OS service layer to handle this */
1100 status = acpi_os_signal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
1102 /* If and when it returns, all done. */
1104 break;
1107 case AML_BREAK_OP:
1108 case AML_CONTINUE_OP: /* ACPI 2.0 */
1111 /* Pop and delete control states until we find a while */
1113 while (walk_state->control_state &&
1114 (walk_state->control_state->control.opcode != AML_WHILE_OP)) {
1115 control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
1116 acpi_ut_delete_generic_state (control_state);
1119 /* No while found? */
1121 if (!walk_state->control_state) {
1122 return (AE_AML_NO_WHILE);
1125 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1127 walk_state->aml_last_while = walk_state->control_state->control.package_end;
1129 /* Return status depending on opcode */
1131 if (op->common.aml_opcode == AML_BREAK_OP) {
1132 status = AE_CTRL_BREAK;
1134 else {
1135 status = AE_CTRL_CONTINUE;
1137 break;
1140 default:
1142 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
1143 op->common.aml_opcode, op));
1145 status = AE_AML_BAD_OPCODE;
1146 break;
1149 return (status);