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")
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
;
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
);
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
);
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
);
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
);
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
173 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
174 * evaluation of these field attributes.
176 ****************************************************************************/
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
;
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
219 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
220 * the late evaluation of these attributes.
222 ****************************************************************************/
225 acpi_ds_get_buffer_arguments (
226 union acpi_operand_object
*obj_desc
)
228 struct acpi_namespace_node
*node
;
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
;
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
266 * DESCRIPTION: Get Package length and initializer byte list. This implements
267 * the late evaluation of these attributes.
269 ****************************************************************************/
272 acpi_ds_get_package_arguments (
273 union acpi_operand_object
*obj_desc
)
275 struct acpi_namespace_node
*node
;
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
;
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
313 * DESCRIPTION: Get region address and length. This implements the late
314 * evaluation of these region attributes.
316 ****************************************************************************/
319 acpi_ds_get_region_arguments (
320 union acpi_operand_object
*obj_desc
)
322 struct acpi_namespace_node
*node
;
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
);
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
364 * DESCRIPTION: Front end to ev_initialize_region
366 ****************************************************************************/
369 acpi_ds_initialize_region (
370 acpi_handle obj_handle
)
372 union acpi_operand_object
*obj_desc
;
376 obj_desc
= acpi_ns_get_attached_object (obj_handle
);
378 /* Namespace is NOT locked */
380 status
= acpi_ev_initialize_region (obj_desc
, FALSE
);
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
398 * DESCRIPTION: Perform actual initialization of a buffer field
400 ****************************************************************************/
403 acpi_ds_init_buffer_field (
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
)
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
;
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
;
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 */
456 bit_count
= (u32
) length_desc
->integer
.value
;
457 field_flags
= AML_FIELD_ACCESS_BYTE
;
460 case AML_CREATE_BIT_FIELD_OP
:
462 /* Offset is in bits, Field is one bit */
466 field_flags
= AML_FIELD_ACCESS_BYTE
;
469 case AML_CREATE_BYTE_FIELD_OP
:
471 /* Offset is in bytes, field is one byte */
473 bit_offset
= 8 * offset
;
475 field_flags
= AML_FIELD_ACCESS_BYTE
;
478 case AML_CREATE_WORD_FIELD_OP
:
480 /* Offset is in bytes, field is one word */
482 bit_offset
= 8 * offset
;
484 field_flags
= AML_FIELD_ACCESS_WORD
;
487 case AML_CREATE_DWORD_FIELD_OP
:
489 /* Offset is in bytes, field is one dword */
491 bit_offset
= 8 * offset
;
493 field_flags
= AML_FIELD_ACCESS_DWORD
;
496 case AML_CREATE_QWORD_FIELD_OP
:
498 /* Offset is in bytes, field is one qword */
500 bit_offset
= 8 * offset
;
502 field_flags
= AML_FIELD_ACCESS_QWORD
;
507 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
508 "Unknown field creation opcode %02x\n",
510 status
= AE_AML_BAD_OPCODE
;
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
;
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
)) {
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
);
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 */
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
581 * DESCRIPTION: Get buffer_field Buffer and Index
582 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
584 ****************************************************************************/
587 acpi_ds_eval_buffer_field_operands (
588 struct acpi_walk_state
*walk_state
,
589 union acpi_parse_object
*op
)
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
);
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]);
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
668 * DESCRIPTION: Get region address and length
669 * Called from acpi_ds_exec_end_op during op_region parse tree walk
671 ****************************************************************************/
674 acpi_ds_eval_region_operands (
675 struct acpi_walk_state
*walk_state
,
676 union acpi_parse_object
*op
)
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
);
721 return_ACPI_STATUS (AE_NOT_EXIST
);
725 * Get the length operand and save it
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",
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
765 * DESCRIPTION: Get the operands and complete the following data object types:
768 ****************************************************************************/
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
)
777 union acpi_operand_object
*arg_desc
;
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]),
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
) {
818 status
= acpi_ds_build_internal_buffer_obj (walk_state
, op
, length
, &obj_desc
);
822 case AML_VAR_PACKAGE_OP
:
824 status
= acpi_ds_build_internal_package_obj (walk_state
, op
, length
, &obj_desc
);
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
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
858 * DESCRIPTION: Handles all control ops encountered during control method
861 ******************************************************************************/
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
) {
883 * IF/WHILE: Create a new control state to manage these
884 * constructs. We need to manage these as a stack, in order
887 control_state
= acpi_ut_create_control_state ();
888 if (!control_state
) {
889 status
= AE_NO_MEMORY
;
893 * Save a pointer to the predicate for multiple executions
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
);
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
;
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
938 * DESCRIPTION: Handles all control ops encountered during control method
941 ******************************************************************************/
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
) {
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
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
);
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
);
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
)) {
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)) {
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
)) {
1065 walk_state
->return_desc
= walk_state
->results
->results
.obj_desc
[0];
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
;
1092 /* Just do nothing! */
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. */
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
;
1135 status
= AE_CTRL_CONTINUE
;
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
;