1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2007, 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>
52 #include <acpi/actables.h>
54 #define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME("dsopcode")
57 /* Local prototypes */
59 acpi_ds_execute_arguments(struct acpi_namespace_node *node,
60 struct acpi_namespace_node *scope_node,
61 u32 aml_length, u8 * aml_start);
64 acpi_ds_init_buffer_field(u16 aml_opcode,
65 union acpi_operand_object *obj_desc,
66 union acpi_operand_object *buffer_desc,
67 union acpi_operand_object *offset_desc,
68 union acpi_operand_object *length_desc,
69 union acpi_operand_object *result_desc);
71 /*******************************************************************************
73 * FUNCTION: acpi_ds_execute_arguments
75 * PARAMETERS: Node - Object NS node
76 * scope_node - Parent NS node
77 * aml_length - Length of executable AML
78 * aml_start - Pointer to the AML
82 * DESCRIPTION: Late (deferred) execution of region or field arguments
84 ******************************************************************************/
87 acpi_ds_execute_arguments(struct acpi_namespace_node *node,
88 struct acpi_namespace_node *scope_node,
89 u32 aml_length, u8 * aml_start)
92 union acpi_parse_object *op;
93 struct acpi_walk_state *walk_state;
95 ACPI_FUNCTION_TRACE(ds_execute_arguments);
98 * Allocate a new parser op to be the root of the parsed tree
100 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
102 return_ACPI_STATUS(AE_NO_MEMORY);
105 /* Save the Node for use in acpi_ps_parse_aml */
107 op->common.node = scope_node;
109 /* Create and initialize a new parser state */
111 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
113 status = AE_NO_MEMORY;
117 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
118 aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
119 if (ACPI_FAILURE(status)) {
120 acpi_ds_delete_walk_state(walk_state);
124 /* Mark this parse as a deferred opcode */
126 walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
127 walk_state->deferred_node = node;
129 /* Pass1: Parse the entire declaration */
131 status = acpi_ps_parse_aml(walk_state);
132 if (ACPI_FAILURE(status)) {
136 /* Get and init the Op created above */
138 op->common.node = node;
139 acpi_ps_delete_parse_tree(op);
141 /* Evaluate the deferred arguments */
143 op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
145 return_ACPI_STATUS(AE_NO_MEMORY);
148 op->common.node = scope_node;
150 /* Create and initialize a new parser state */
152 walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
154 status = AE_NO_MEMORY;
158 /* Execute the opcode and arguments */
160 status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
161 aml_length, NULL, ACPI_IMODE_EXECUTE);
162 if (ACPI_FAILURE(status)) {
163 acpi_ds_delete_walk_state(walk_state);
167 /* Mark this execution as a deferred opcode */
169 walk_state->deferred_node = node;
170 status = acpi_ps_parse_aml(walk_state);
173 acpi_ps_delete_parse_tree(op);
174 return_ACPI_STATUS(status);
177 /*******************************************************************************
179 * FUNCTION: acpi_ds_get_buffer_field_arguments
181 * PARAMETERS: obj_desc - A valid buffer_field object
185 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
186 * evaluation of these field attributes.
188 ******************************************************************************/
191 acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
193 union acpi_operand_object *extra_desc;
194 struct acpi_namespace_node *node;
197 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc);
199 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
200 return_ACPI_STATUS(AE_OK);
203 /* Get the AML pointer (method object) and buffer_field node */
205 extra_desc = acpi_ns_get_secondary_object(obj_desc);
206 node = obj_desc->buffer_field.node;
208 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
209 (ACPI_TYPE_BUFFER_FIELD, node, NULL));
210 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
211 acpi_ut_get_node_name(node)));
213 /* Execute the AML code for the term_arg arguments */
215 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
216 extra_desc->extra.aml_length,
217 extra_desc->extra.aml_start);
218 return_ACPI_STATUS(status);
221 /*******************************************************************************
223 * FUNCTION: acpi_ds_get_buffer_arguments
225 * PARAMETERS: obj_desc - A valid Buffer object
229 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
230 * the late evaluation of these attributes.
232 ******************************************************************************/
234 acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
236 struct acpi_namespace_node *node;
239 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc);
241 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
242 return_ACPI_STATUS(AE_OK);
245 /* Get the Buffer node */
247 node = obj_desc->buffer.node;
250 "No pointer back to NS node in buffer obj %p",
252 return_ACPI_STATUS(AE_AML_INTERNAL);
255 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
257 /* Execute the AML code for the term_arg arguments */
259 status = acpi_ds_execute_arguments(node, node,
260 obj_desc->buffer.aml_length,
261 obj_desc->buffer.aml_start);
262 return_ACPI_STATUS(status);
265 /*******************************************************************************
267 * FUNCTION: acpi_ds_get_package_arguments
269 * PARAMETERS: obj_desc - A valid Package object
273 * DESCRIPTION: Get Package length and initializer byte list. This implements
274 * the late evaluation of these attributes.
276 ******************************************************************************/
278 acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
280 struct acpi_namespace_node *node;
283 ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc);
285 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
286 return_ACPI_STATUS(AE_OK);
289 /* Get the Package node */
291 node = obj_desc->package.node;
294 "No pointer back to NS node in package %p",
296 return_ACPI_STATUS(AE_AML_INTERNAL);
299 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
301 /* Execute the AML code for the term_arg arguments */
303 status = acpi_ds_execute_arguments(node, node,
304 obj_desc->package.aml_length,
305 obj_desc->package.aml_start);
306 return_ACPI_STATUS(status);
309 /*****************************************************************************
311 * FUNCTION: acpi_ds_get_region_arguments
313 * PARAMETERS: obj_desc - A valid region object
317 * DESCRIPTION: Get region address and length. This implements the late
318 * evaluation of these region attributes.
320 ****************************************************************************/
322 acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
324 struct acpi_namespace_node *node;
326 union acpi_operand_object *extra_desc;
328 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
344 (ACPI_TYPE_REGION, node, NULL));
346 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
347 acpi_ut_get_node_name(node),
348 extra_desc->extra.aml_start));
350 /* Execute the argument AML */
352 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
353 extra_desc->extra.aml_length,
354 extra_desc->extra.aml_start);
355 if (ACPI_FAILURE(status)) {
356 return_ACPI_STATUS(status);
359 /* Validate the region address/length via the host OS */
361 status = acpi_os_validate_address(obj_desc->region.space_id,
362 obj_desc->region.address,
363 (acpi_size) obj_desc->region.length,
364 acpi_ut_get_node_name(node));
366 if (ACPI_FAILURE(status)) {
368 * Invalid address/length. We will emit an error message and mark
369 * the region as invalid, so that it will cause an additional error if
370 * it is ever used. Then return AE_OK.
372 ACPI_EXCEPTION((AE_INFO, status,
373 "During address validation of OpRegion [%4.4s]",
375 obj_desc->common.flags |= AOPOBJ_INVALID;
379 return_ACPI_STATUS(status);
382 /*******************************************************************************
384 * FUNCTION: acpi_ds_initialize_region
386 * PARAMETERS: obj_handle - Region namespace node
390 * DESCRIPTION: Front end to ev_initialize_region
392 ******************************************************************************/
394 acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
396 union acpi_operand_object *obj_desc;
399 obj_desc = acpi_ns_get_attached_object(obj_handle);
401 /* Namespace is NOT locked */
403 status = acpi_ev_initialize_region(obj_desc, FALSE);
407 /*******************************************************************************
409 * FUNCTION: acpi_ds_init_buffer_field
411 * PARAMETERS: aml_opcode - create_xxx_field
412 * obj_desc - buffer_field object
413 * buffer_desc - Host Buffer
414 * offset_desc - Offset into buffer
415 * length_desc - Length of field (CREATE_FIELD_OP only)
416 * result_desc - Where to store the result
420 * DESCRIPTION: Perform actual initialization of a buffer field
422 ******************************************************************************/
425 acpi_ds_init_buffer_field(u16 aml_opcode,
426 union acpi_operand_object *obj_desc,
427 union acpi_operand_object *buffer_desc,
428 union acpi_operand_object *offset_desc,
429 union acpi_operand_object *length_desc,
430 union acpi_operand_object *result_desc)
438 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) {
444 "Target of Create Field is not a Buffer object - %s",
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) {
458 "(%s) destination not a NS Node [%s]",
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) {
484 "Attempt to CreateField of length zero"));
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;
538 "Unknown field creation opcode %02x", aml_opcode));
539 status = AE_AML_BAD_OPCODE;
543 /* Entire field must fit within the current length of the buffer */
545 if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
547 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
548 acpi_ut_get_node_name(result_desc),
549 bit_offset + bit_count,
550 acpi_ut_get_node_name(buffer_desc->buffer.node),
551 8 * (u32) buffer_desc->buffer.length));
552 status = AE_AML_BUFFER_LIMIT;
557 * Initialize areas of the field object that are common to all fields
558 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
559 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
561 status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
562 bit_offset, bit_count);
563 if (ACPI_FAILURE(status)) {
567 obj_desc->buffer_field.buffer_obj = buffer_desc;
569 /* Reference count for buffer_desc inherits obj_desc count */
571 buffer_desc->common.reference_count = (u16)
572 (buffer_desc->common.reference_count +
573 obj_desc->common.reference_count);
577 /* Always delete the operands */
579 acpi_ut_remove_reference(offset_desc);
580 acpi_ut_remove_reference(buffer_desc);
582 if (aml_opcode == AML_CREATE_FIELD_OP) {
583 acpi_ut_remove_reference(length_desc);
586 /* On failure, delete the result descriptor */
588 if (ACPI_FAILURE(status)) {
589 acpi_ut_remove_reference(result_desc); /* Result descriptor */
591 /* Now the address and length are valid for this buffer_field */
593 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
596 return_ACPI_STATUS(status);
599 /*******************************************************************************
601 * FUNCTION: acpi_ds_eval_buffer_field_operands
603 * PARAMETERS: walk_state - Current walk
604 * Op - A valid buffer_field Op object
608 * DESCRIPTION: Get buffer_field Buffer and Index
609 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
611 ******************************************************************************/
614 acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
615 union acpi_parse_object *op)
618 union acpi_operand_object *obj_desc;
619 struct acpi_namespace_node *node;
620 union acpi_parse_object *next_op;
622 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
625 * This is where we evaluate the address and length fields of the
626 * create_xxx_field declaration
628 node = op->common.node;
630 /* next_op points to the op that holds the Buffer */
632 next_op = op->common.value.arg;
634 /* Evaluate/create the address and length operands */
636 status = acpi_ds_create_operands(walk_state, next_op);
637 if (ACPI_FAILURE(status)) {
638 return_ACPI_STATUS(status);
641 obj_desc = acpi_ns_get_attached_object(node);
643 return_ACPI_STATUS(AE_NOT_EXIST);
646 /* Resolve the operands */
648 status = acpi_ex_resolve_operands(op->common.aml_opcode,
649 ACPI_WALK_OPERANDS, walk_state);
651 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
652 acpi_ps_get_opcode_name(op->common.aml_opcode),
653 walk_state->num_operands,
654 "after AcpiExResolveOperands");
656 if (ACPI_FAILURE(status)) {
657 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
658 acpi_ps_get_opcode_name(op->common.aml_opcode),
661 return_ACPI_STATUS(status);
664 /* Initialize the Buffer Field */
666 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
668 /* NOTE: Slightly different operands for this opcode */
671 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
672 walk_state->operands[0],
673 walk_state->operands[1],
674 walk_state->operands[2],
675 walk_state->operands[3]);
677 /* All other, create_xxx_field opcodes */
680 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
681 walk_state->operands[0],
682 walk_state->operands[1], NULL,
683 walk_state->operands[2]);
686 return_ACPI_STATUS(status);
689 /*******************************************************************************
691 * FUNCTION: acpi_ds_eval_region_operands
693 * PARAMETERS: walk_state - Current walk
694 * Op - A valid region Op object
698 * DESCRIPTION: Get region address and length
699 * Called from acpi_ds_exec_end_op during op_region parse tree walk
701 ******************************************************************************/
704 acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
705 union acpi_parse_object *op)
708 union acpi_operand_object *obj_desc;
709 union acpi_operand_object *operand_desc;
710 struct acpi_namespace_node *node;
711 union acpi_parse_object *next_op;
713 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
716 * This is where we evaluate the address and length fields of the
717 * op_region declaration
719 node = op->common.node;
721 /* next_op points to the op that holds the space_iD */
723 next_op = op->common.value.arg;
725 /* next_op points to address op */
727 next_op = next_op->common.next;
729 /* Evaluate/create the address and length operands */
731 status = acpi_ds_create_operands(walk_state, next_op);
732 if (ACPI_FAILURE(status)) {
733 return_ACPI_STATUS(status);
736 /* Resolve the length and address operands to numbers */
738 status = acpi_ex_resolve_operands(op->common.aml_opcode,
739 ACPI_WALK_OPERANDS, walk_state);
740 if (ACPI_FAILURE(status)) {
741 return_ACPI_STATUS(status);
744 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
745 acpi_ps_get_opcode_name(op->common.aml_opcode),
746 1, "after AcpiExResolveOperands");
748 obj_desc = acpi_ns_get_attached_object(node);
750 return_ACPI_STATUS(AE_NOT_EXIST);
754 * Get the length operand and save it
757 operand_desc = walk_state->operands[walk_state->num_operands - 1];
759 obj_desc->region.length = (u32) operand_desc->integer.value;
760 acpi_ut_remove_reference(operand_desc);
763 * Get the address and save it
764 * (at top of stack - 1)
766 operand_desc = walk_state->operands[walk_state->num_operands - 2];
768 obj_desc->region.address = (acpi_physical_address)
769 operand_desc->integer.value;
770 acpi_ut_remove_reference(operand_desc);
772 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
774 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
775 obj_desc->region.length));
777 /* Now the address and length are valid for this opregion */
779 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
781 return_ACPI_STATUS(status);
784 /*******************************************************************************
786 * FUNCTION: acpi_ds_eval_table_region_operands
788 * PARAMETERS: walk_state - Current walk
789 * Op - A valid region Op object
793 * DESCRIPTION: Get region address and length
794 * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
796 ******************************************************************************/
799 acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
800 union acpi_parse_object *op)
803 union acpi_operand_object *obj_desc;
804 union acpi_operand_object **operand;
805 struct acpi_namespace_node *node;
806 union acpi_parse_object *next_op;
807 acpi_native_uint table_index;
808 struct acpi_table_header *table;
810 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
813 * This is where we evaluate the signature_string and oem_iDString
814 * and oem_table_iDString of the data_table_region declaration
816 node = op->common.node;
818 /* next_op points to signature_string op */
820 next_op = op->common.value.arg;
823 * Evaluate/create the signature_string and oem_iDString
824 * and oem_table_iDString operands
826 status = acpi_ds_create_operands(walk_state, next_op);
827 if (ACPI_FAILURE(status)) {
828 return_ACPI_STATUS(status);
832 * Resolve the signature_string and oem_iDString
833 * and oem_table_iDString operands
835 status = acpi_ex_resolve_operands(op->common.aml_opcode,
836 ACPI_WALK_OPERANDS, walk_state);
837 if (ACPI_FAILURE(status)) {
838 return_ACPI_STATUS(status);
841 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
842 acpi_ps_get_opcode_name(op->common.aml_opcode),
843 1, "after AcpiExResolveOperands");
845 operand = &walk_state->operands[0];
847 /* Find the ACPI table */
849 status = acpi_tb_find_table(operand[0]->string.pointer,
850 operand[1]->string.pointer,
851 operand[2]->string.pointer, &table_index);
852 if (ACPI_FAILURE(status)) {
853 return_ACPI_STATUS(status);
856 acpi_ut_remove_reference(operand[0]);
857 acpi_ut_remove_reference(operand[1]);
858 acpi_ut_remove_reference(operand[2]);
860 status = acpi_get_table_by_index(table_index, &table);
861 if (ACPI_FAILURE(status)) {
862 return_ACPI_STATUS(status);
865 obj_desc = acpi_ns_get_attached_object(node);
867 return_ACPI_STATUS(AE_NOT_EXIST);
870 obj_desc->region.address =
871 (acpi_physical_address) ACPI_TO_INTEGER(table);
872 obj_desc->region.length = table->length;
874 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
876 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
877 obj_desc->region.length));
879 /* Now the address and length are valid for this opregion */
881 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
883 return_ACPI_STATUS(status);
886 /*******************************************************************************
888 * FUNCTION: acpi_ds_eval_data_object_operands
890 * PARAMETERS: walk_state - Current walk
891 * Op - A valid data_object Op object
892 * obj_desc - data_object
896 * DESCRIPTION: Get the operands and complete the following data object types:
899 ******************************************************************************/
902 acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
903 union acpi_parse_object *op,
904 union acpi_operand_object *obj_desc)
907 union acpi_operand_object *arg_desc;
910 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
912 /* The first operand (for all of these data objects) is the length */
915 * Set proper index into operand stack for acpi_ds_obj_stack_push
916 * invoked inside acpi_ds_create_operand.
918 walk_state->operand_index = walk_state->num_operands;
920 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
921 if (ACPI_FAILURE(status)) {
922 return_ACPI_STATUS(status);
925 status = acpi_ex_resolve_operands(walk_state->opcode,
927 operands[walk_state->num_operands -
929 if (ACPI_FAILURE(status)) {
930 return_ACPI_STATUS(status);
933 /* Extract length operand */
935 arg_desc = walk_state->operands[walk_state->num_operands - 1];
936 length = (u32) arg_desc->integer.value;
938 /* Cleanup for length operand */
940 status = acpi_ds_obj_stack_pop(1, walk_state);
941 if (ACPI_FAILURE(status)) {
942 return_ACPI_STATUS(status);
945 acpi_ut_remove_reference(arg_desc);
948 * Create the actual data object
950 switch (op->common.aml_opcode) {
954 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
959 case AML_VAR_PACKAGE_OP:
962 acpi_ds_build_internal_package_obj(walk_state, op, length,
967 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
970 if (ACPI_SUCCESS(status)) {
972 * Return the object in the walk_state, unless the parent is a package -
973 * in this case, the return object will be stored in the parse tree
976 if ((!op->common.parent) ||
977 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
978 (op->common.parent->common.aml_opcode !=
980 && (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
981 walk_state->result_obj = obj_desc;
985 return_ACPI_STATUS(status);
988 /*******************************************************************************
990 * FUNCTION: acpi_ds_exec_begin_control_op
992 * PARAMETERS: walk_list - The list that owns the walk stack
993 * Op - The control Op
997 * DESCRIPTION: Handles all control ops encountered during control method
1000 ******************************************************************************/
1003 acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
1004 union acpi_parse_object *op)
1006 acpi_status status = AE_OK;
1007 union acpi_generic_state *control_state;
1009 ACPI_FUNCTION_NAME(ds_exec_begin_control_op);
1011 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
1012 op->common.aml_opcode, walk_state));
1014 switch (op->common.aml_opcode) {
1019 * IF/WHILE: Create a new control state to manage these
1020 * constructs. We need to manage these as a stack, in order
1021 * to handle nesting.
1023 control_state = acpi_ut_create_control_state();
1024 if (!control_state) {
1025 status = AE_NO_MEMORY;
1029 * Save a pointer to the predicate for multiple executions
1032 control_state->control.aml_predicate_start =
1033 walk_state->parser_state.aml - 1;
1034 control_state->control.package_end =
1035 walk_state->parser_state.pkg_end;
1036 control_state->control.opcode = op->common.aml_opcode;
1038 /* Push the control state on this walk's control stack */
1040 acpi_ut_push_generic_state(&walk_state->control_state,
1046 /* Predicate is in the state object */
1047 /* If predicate is true, the IF was executed, ignore ELSE part */
1049 if (walk_state->last_predicate) {
1050 status = AE_CTRL_TRUE;
1066 /*******************************************************************************
1068 * FUNCTION: acpi_ds_exec_end_control_op
1070 * PARAMETERS: walk_list - The list that owns the walk stack
1071 * Op - The control Op
1075 * DESCRIPTION: Handles all control ops encountered during control method
1078 ******************************************************************************/
1081 acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
1082 union acpi_parse_object * op)
1084 acpi_status status = AE_OK;
1085 union acpi_generic_state *control_state;
1087 ACPI_FUNCTION_NAME(ds_exec_end_control_op);
1089 switch (op->common.aml_opcode) {
1092 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
1095 * Save the result of the predicate in case there is an
1098 walk_state->last_predicate =
1099 (u8) walk_state->control_state->common.value;
1102 * Pop the control state that was created at the start
1103 * of the IF and free it
1106 acpi_ut_pop_generic_state(&walk_state->control_state);
1107 acpi_ut_delete_generic_state(control_state);
1116 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
1118 if (walk_state->control_state->common.value) {
1120 /* Predicate was true, go back and evaluate it again! */
1122 status = AE_CTRL_PENDING;
1125 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1126 "[WHILE_OP] termination! Op=%p\n", op));
1128 /* Pop this control state and free it */
1131 acpi_ut_pop_generic_state(&walk_state->control_state);
1133 walk_state->aml_last_while =
1134 control_state->control.aml_predicate_start;
1135 acpi_ut_delete_generic_state(control_state);
1140 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1141 "[RETURN_OP] Op=%p Arg=%p\n", op,
1142 op->common.value.arg));
1145 * One optional operand -- the return value
1146 * It can be either an immediate operand or a result that
1147 * has been bubbled up the tree
1149 if (op->common.value.arg) {
1151 /* Since we have a real Return(), delete any implicit return */
1153 acpi_ds_clear_implicit_return(walk_state);
1155 /* Return statement has an immediate operand */
1158 acpi_ds_create_operands(walk_state,
1159 op->common.value.arg);
1160 if (ACPI_FAILURE(status)) {
1165 * If value being returned is a Reference (such as
1166 * an arg or local), resolve it now because it may
1167 * cease to exist at the end of the method.
1170 acpi_ex_resolve_to_value(&walk_state->operands[0],
1172 if (ACPI_FAILURE(status)) {
1177 * Get the return value and save as the last result
1178 * value. This is the only place where walk_state->return_desc
1179 * is set to anything other than zero!
1181 walk_state->return_desc = walk_state->operands[0];
1182 } else if (walk_state->result_count) {
1184 /* Since we have a real Return(), delete any implicit return */
1186 acpi_ds_clear_implicit_return(walk_state);
1189 * The return value has come from a previous calculation.
1191 * If value being returned is a Reference (such as
1192 * an arg or local), resolve it now because it may
1193 * cease to exist at the end of the method.
1195 * Allow references created by the Index operator to return unchanged.
1197 if ((ACPI_GET_DESCRIPTOR_TYPE
1198 (walk_state->results->results.obj_desc[0]) ==
1199 ACPI_DESC_TYPE_OPERAND)
1201 (ACPI_GET_OBJECT_TYPE
1202 (walk_state->results->results.obj_desc[0]) ==
1203 ACPI_TYPE_LOCAL_REFERENCE)
1204 && ((walk_state->results->results.obj_desc[0])->
1205 reference.opcode != AML_INDEX_OP)) {
1207 acpi_ex_resolve_to_value(&walk_state->
1211 if (ACPI_FAILURE(status)) {
1216 walk_state->return_desc =
1217 walk_state->results->results.obj_desc[0];
1219 /* No return operand */
1221 if (walk_state->num_operands) {
1222 acpi_ut_remove_reference(walk_state->
1226 walk_state->operands[0] = NULL;
1227 walk_state->num_operands = 0;
1228 walk_state->return_desc = NULL;
1231 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
1232 "Completed RETURN_OP State=%p, RetVal=%p\n",
1233 walk_state, walk_state->return_desc));
1235 /* End the control method execution right now */
1237 status = AE_CTRL_TERMINATE;
1242 /* Just do nothing! */
1245 case AML_BREAK_POINT_OP:
1247 /* Call up to the OS service layer to handle this */
1250 acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
1251 "Executed AML Breakpoint opcode");
1253 /* If and when it returns, all done. */
1258 case AML_CONTINUE_OP: /* ACPI 2.0 */
1260 /* Pop and delete control states until we find a while */
1262 while (walk_state->control_state &&
1263 (walk_state->control_state->control.opcode !=
1266 acpi_ut_pop_generic_state(&walk_state->
1268 acpi_ut_delete_generic_state(control_state);
1271 /* No while found? */
1273 if (!walk_state->control_state) {
1274 return (AE_AML_NO_WHILE);
1277 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1279 walk_state->aml_last_while =
1280 walk_state->control_state->control.package_end;
1282 /* Return status depending on opcode */
1284 if (op->common.aml_opcode == AML_BREAK_OP) {
1285 status = AE_CTRL_BREAK;
1287 status = AE_CTRL_CONTINUE;
1293 ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
1294 op->common.aml_opcode, op));
1296 status = AE_AML_BAD_OPCODE;