1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
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>
55 #define _COMPONENT ACPI_DISPATCHER
56 ACPI_MODULE_NAME("dsopcode")
58 /* Local prototypes */
60 acpi_ds_execute_arguments(struct acpi_namespace_node
*node
,
61 struct acpi_namespace_node
*scope_node
,
62 u32 aml_length
, u8
* aml_start
);
65 acpi_ds_init_buffer_field(u16 aml_opcode
,
66 union acpi_operand_object
*obj_desc
,
67 union acpi_operand_object
*buffer_desc
,
68 union acpi_operand_object
*offset_desc
,
69 union acpi_operand_object
*length_desc
,
70 union acpi_operand_object
*result_desc
);
72 /*******************************************************************************
74 * FUNCTION: acpi_ds_execute_arguments
76 * PARAMETERS: Node - Object NS node
77 * scope_node - Parent NS node
78 * aml_length - Length of executable AML
79 * aml_start - Pointer to the AML
83 * DESCRIPTION: Late (deferred) execution of region or field arguments
85 ******************************************************************************/
88 acpi_ds_execute_arguments(struct acpi_namespace_node
*node
,
89 struct acpi_namespace_node
*scope_node
,
90 u32 aml_length
, u8
* aml_start
)
93 union acpi_parse_object
*op
;
94 struct acpi_walk_state
*walk_state
;
96 ACPI_FUNCTION_TRACE(ds_execute_arguments
);
99 * Allocate a new parser op to be the root of the parsed tree
101 op
= acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP
);
103 return_ACPI_STATUS(AE_NO_MEMORY
);
106 /* Save the Node for use in acpi_ps_parse_aml */
108 op
->common
.node
= scope_node
;
110 /* Create and initialize a new parser state */
112 walk_state
= acpi_ds_create_walk_state(0, NULL
, NULL
, NULL
);
114 status
= AE_NO_MEMORY
;
118 status
= acpi_ds_init_aml_walk(walk_state
, op
, NULL
, aml_start
,
119 aml_length
, NULL
, ACPI_IMODE_LOAD_PASS1
);
120 if (ACPI_FAILURE(status
)) {
121 acpi_ds_delete_walk_state(walk_state
);
125 /* Mark this parse as a deferred opcode */
127 walk_state
->parse_flags
= ACPI_PARSE_DEFERRED_OP
;
128 walk_state
->deferred_node
= node
;
130 /* Pass1: Parse the entire declaration */
132 status
= acpi_ps_parse_aml(walk_state
);
133 if (ACPI_FAILURE(status
)) {
137 /* Get and init the Op created above */
139 op
->common
.node
= node
;
140 acpi_ps_delete_parse_tree(op
);
142 /* Evaluate the deferred arguments */
144 op
= acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP
);
146 return_ACPI_STATUS(AE_NO_MEMORY
);
149 op
->common
.node
= scope_node
;
151 /* Create and initialize a new parser state */
153 walk_state
= acpi_ds_create_walk_state(0, NULL
, NULL
, NULL
);
155 status
= AE_NO_MEMORY
;
159 /* Execute the opcode and arguments */
161 status
= acpi_ds_init_aml_walk(walk_state
, op
, NULL
, aml_start
,
162 aml_length
, NULL
, ACPI_IMODE_EXECUTE
);
163 if (ACPI_FAILURE(status
)) {
164 acpi_ds_delete_walk_state(walk_state
);
168 /* Mark this execution as a deferred opcode */
170 walk_state
->deferred_node
= node
;
171 status
= acpi_ps_parse_aml(walk_state
);
174 acpi_ps_delete_parse_tree(op
);
175 return_ACPI_STATUS(status
);
178 /*******************************************************************************
180 * FUNCTION: acpi_ds_get_buffer_field_arguments
182 * PARAMETERS: obj_desc - A valid buffer_field object
186 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
187 * evaluation of these field attributes.
189 ******************************************************************************/
192 acpi_ds_get_buffer_field_arguments(union acpi_operand_object
*obj_desc
)
194 union acpi_operand_object
*extra_desc
;
195 struct acpi_namespace_node
*node
;
198 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments
, obj_desc
);
200 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
201 return_ACPI_STATUS(AE_OK
);
204 /* Get the AML pointer (method object) and buffer_field node */
206 extra_desc
= acpi_ns_get_secondary_object(obj_desc
);
207 node
= obj_desc
->buffer_field
.node
;
209 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
210 (ACPI_TYPE_BUFFER_FIELD
, node
, NULL
));
211 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "[%4.4s] BufferField Arg Init\n",
212 acpi_ut_get_node_name(node
)));
214 /* Execute the AML code for the term_arg arguments */
216 status
= acpi_ds_execute_arguments(node
, acpi_ns_get_parent_node(node
),
217 extra_desc
->extra
.aml_length
,
218 extra_desc
->extra
.aml_start
);
219 return_ACPI_STATUS(status
);
222 /*******************************************************************************
224 * FUNCTION: acpi_ds_get_bank_field_arguments
226 * PARAMETERS: obj_desc - A valid bank_field object
230 * DESCRIPTION: Get bank_field bank_value. This implements the late
231 * evaluation of these field attributes.
233 ******************************************************************************/
236 acpi_ds_get_bank_field_arguments(union acpi_operand_object
*obj_desc
)
238 union acpi_operand_object
*extra_desc
;
239 struct acpi_namespace_node
*node
;
242 ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments
, obj_desc
);
244 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
245 return_ACPI_STATUS(AE_OK
);
248 /* Get the AML pointer (method object) and bank_field node */
250 extra_desc
= acpi_ns_get_secondary_object(obj_desc
);
251 node
= obj_desc
->bank_field
.node
;
253 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
254 (ACPI_TYPE_LOCAL_BANK_FIELD
, node
, NULL
));
255 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "[%4.4s] BankField Arg Init\n",
256 acpi_ut_get_node_name(node
)));
258 /* Execute the AML code for the term_arg arguments */
260 status
= acpi_ds_execute_arguments(node
, acpi_ns_get_parent_node(node
),
261 extra_desc
->extra
.aml_length
,
262 extra_desc
->extra
.aml_start
);
263 return_ACPI_STATUS(status
);
266 /*******************************************************************************
268 * FUNCTION: acpi_ds_get_buffer_arguments
270 * PARAMETERS: obj_desc - A valid Buffer object
274 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
275 * the late evaluation of these attributes.
277 ******************************************************************************/
279 acpi_status
acpi_ds_get_buffer_arguments(union acpi_operand_object
*obj_desc
)
281 struct acpi_namespace_node
*node
;
284 ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments
, obj_desc
);
286 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
287 return_ACPI_STATUS(AE_OK
);
290 /* Get the Buffer node */
292 node
= obj_desc
->buffer
.node
;
295 "No pointer back to NS node in buffer obj %p",
297 return_ACPI_STATUS(AE_AML_INTERNAL
);
300 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Buffer Arg Init\n"));
302 /* Execute the AML code for the term_arg arguments */
304 status
= acpi_ds_execute_arguments(node
, node
,
305 obj_desc
->buffer
.aml_length
,
306 obj_desc
->buffer
.aml_start
);
307 return_ACPI_STATUS(status
);
310 /*******************************************************************************
312 * FUNCTION: acpi_ds_get_package_arguments
314 * PARAMETERS: obj_desc - A valid Package object
318 * DESCRIPTION: Get Package length and initializer byte list. This implements
319 * the late evaluation of these attributes.
321 ******************************************************************************/
323 acpi_status
acpi_ds_get_package_arguments(union acpi_operand_object
*obj_desc
)
325 struct acpi_namespace_node
*node
;
328 ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments
, obj_desc
);
330 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
331 return_ACPI_STATUS(AE_OK
);
334 /* Get the Package node */
336 node
= obj_desc
->package
.node
;
339 "No pointer back to NS node in package %p",
341 return_ACPI_STATUS(AE_AML_INTERNAL
);
344 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Package Arg Init\n"));
346 /* Execute the AML code for the term_arg arguments */
348 status
= acpi_ds_execute_arguments(node
, node
,
349 obj_desc
->package
.aml_length
,
350 obj_desc
->package
.aml_start
);
351 return_ACPI_STATUS(status
);
354 /*****************************************************************************
356 * FUNCTION: acpi_ds_get_region_arguments
358 * PARAMETERS: obj_desc - A valid region object
362 * DESCRIPTION: Get region address and length. This implements the late
363 * evaluation of these region attributes.
365 ****************************************************************************/
367 acpi_status
acpi_ds_get_region_arguments(union acpi_operand_object
*obj_desc
)
369 struct acpi_namespace_node
*node
;
371 union acpi_operand_object
*extra_desc
;
373 ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments
, obj_desc
);
375 if (obj_desc
->region
.flags
& AOPOBJ_DATA_VALID
) {
376 return_ACPI_STATUS(AE_OK
);
379 extra_desc
= acpi_ns_get_secondary_object(obj_desc
);
381 return_ACPI_STATUS(AE_NOT_EXIST
);
384 /* Get the Region node */
386 node
= obj_desc
->region
.node
;
388 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
389 (ACPI_TYPE_REGION
, node
, NULL
));
391 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "[%4.4s] OpRegion Arg Init at AML %p\n",
392 acpi_ut_get_node_name(node
),
393 extra_desc
->extra
.aml_start
));
395 /* Execute the argument AML */
397 status
= acpi_ds_execute_arguments(node
, acpi_ns_get_parent_node(node
),
398 extra_desc
->extra
.aml_length
,
399 extra_desc
->extra
.aml_start
);
400 return_ACPI_STATUS(status
);
403 /*******************************************************************************
405 * FUNCTION: acpi_ds_initialize_region
407 * PARAMETERS: obj_handle - Region namespace node
411 * DESCRIPTION: Front end to ev_initialize_region
413 ******************************************************************************/
415 acpi_status
acpi_ds_initialize_region(acpi_handle obj_handle
)
417 union acpi_operand_object
*obj_desc
;
420 obj_desc
= acpi_ns_get_attached_object(obj_handle
);
422 /* Namespace is NOT locked */
424 status
= acpi_ev_initialize_region(obj_desc
, FALSE
);
428 /*******************************************************************************
430 * FUNCTION: acpi_ds_init_buffer_field
432 * PARAMETERS: aml_opcode - create_xxx_field
433 * obj_desc - buffer_field object
434 * buffer_desc - Host Buffer
435 * offset_desc - Offset into buffer
436 * length_desc - Length of field (CREATE_FIELD_OP only)
437 * result_desc - Where to store the result
441 * DESCRIPTION: Perform actual initialization of a buffer field
443 ******************************************************************************/
446 acpi_ds_init_buffer_field(u16 aml_opcode
,
447 union acpi_operand_object
*obj_desc
,
448 union acpi_operand_object
*buffer_desc
,
449 union acpi_operand_object
*offset_desc
,
450 union acpi_operand_object
*length_desc
,
451 union acpi_operand_object
*result_desc
)
459 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field
, obj_desc
);
461 /* Host object must be a Buffer */
463 if (buffer_desc
->common
.type
!= ACPI_TYPE_BUFFER
) {
465 "Target of Create Field is not a Buffer object - %s",
466 acpi_ut_get_object_type_name(buffer_desc
)));
468 status
= AE_AML_OPERAND_TYPE
;
473 * The last parameter to all of these opcodes (result_desc) started
474 * out as a name_string, and should therefore now be a NS node
475 * after resolution in acpi_ex_resolve_operands().
477 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc
) != ACPI_DESC_TYPE_NAMED
) {
479 "(%s) destination not a NS Node [%s]",
480 acpi_ps_get_opcode_name(aml_opcode
),
481 acpi_ut_get_descriptor_name(result_desc
)));
483 status
= AE_AML_OPERAND_TYPE
;
487 offset
= (u32
) offset_desc
->integer
.value
;
490 * Setup the Bit offsets and counts, according to the opcode
492 switch (aml_opcode
) {
493 case AML_CREATE_FIELD_OP
:
495 /* Offset is in bits, count is in bits */
497 field_flags
= AML_FIELD_ACCESS_BYTE
;
499 bit_count
= (u32
) length_desc
->integer
.value
;
501 /* Must have a valid (>0) bit count */
503 if (bit_count
== 0) {
505 "Attempt to CreateField of length zero"));
506 status
= AE_AML_OPERAND_VALUE
;
511 case AML_CREATE_BIT_FIELD_OP
:
513 /* Offset is in bits, Field is one bit */
517 field_flags
= AML_FIELD_ACCESS_BYTE
;
520 case AML_CREATE_BYTE_FIELD_OP
:
522 /* Offset is in bytes, field is one byte */
524 bit_offset
= 8 * offset
;
526 field_flags
= AML_FIELD_ACCESS_BYTE
;
529 case AML_CREATE_WORD_FIELD_OP
:
531 /* Offset is in bytes, field is one word */
533 bit_offset
= 8 * offset
;
535 field_flags
= AML_FIELD_ACCESS_WORD
;
538 case AML_CREATE_DWORD_FIELD_OP
:
540 /* Offset is in bytes, field is one dword */
542 bit_offset
= 8 * offset
;
544 field_flags
= AML_FIELD_ACCESS_DWORD
;
547 case AML_CREATE_QWORD_FIELD_OP
:
549 /* Offset is in bytes, field is one qword */
551 bit_offset
= 8 * offset
;
553 field_flags
= AML_FIELD_ACCESS_QWORD
;
559 "Unknown field creation opcode %02x", aml_opcode
));
560 status
= AE_AML_BAD_OPCODE
;
564 /* Entire field must fit within the current length of the buffer */
566 if ((bit_offset
+ bit_count
) > (8 * (u32
) buffer_desc
->buffer
.length
)) {
568 "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
569 acpi_ut_get_node_name(result_desc
),
570 bit_offset
+ bit_count
,
571 acpi_ut_get_node_name(buffer_desc
->buffer
.node
),
572 8 * (u32
) buffer_desc
->buffer
.length
));
573 status
= AE_AML_BUFFER_LIMIT
;
578 * Initialize areas of the field object that are common to all fields
579 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
580 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
582 status
= acpi_ex_prep_common_field_object(obj_desc
, field_flags
, 0,
583 bit_offset
, bit_count
);
584 if (ACPI_FAILURE(status
)) {
588 obj_desc
->buffer_field
.buffer_obj
= buffer_desc
;
590 /* Reference count for buffer_desc inherits obj_desc count */
592 buffer_desc
->common
.reference_count
= (u16
)
593 (buffer_desc
->common
.reference_count
+
594 obj_desc
->common
.reference_count
);
598 /* Always delete the operands */
600 acpi_ut_remove_reference(offset_desc
);
601 acpi_ut_remove_reference(buffer_desc
);
603 if (aml_opcode
== AML_CREATE_FIELD_OP
) {
604 acpi_ut_remove_reference(length_desc
);
607 /* On failure, delete the result descriptor */
609 if (ACPI_FAILURE(status
)) {
610 acpi_ut_remove_reference(result_desc
); /* Result descriptor */
612 /* Now the address and length are valid for this buffer_field */
614 obj_desc
->buffer_field
.flags
|= AOPOBJ_DATA_VALID
;
617 return_ACPI_STATUS(status
);
620 /*******************************************************************************
622 * FUNCTION: acpi_ds_eval_buffer_field_operands
624 * PARAMETERS: walk_state - Current walk
625 * Op - A valid buffer_field Op object
629 * DESCRIPTION: Get buffer_field Buffer and Index
630 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
632 ******************************************************************************/
635 acpi_ds_eval_buffer_field_operands(struct acpi_walk_state
*walk_state
,
636 union acpi_parse_object
*op
)
639 union acpi_operand_object
*obj_desc
;
640 struct acpi_namespace_node
*node
;
641 union acpi_parse_object
*next_op
;
643 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands
, op
);
646 * This is where we evaluate the address and length fields of the
647 * create_xxx_field declaration
649 node
= op
->common
.node
;
651 /* next_op points to the op that holds the Buffer */
653 next_op
= op
->common
.value
.arg
;
655 /* Evaluate/create the address and length operands */
657 status
= acpi_ds_create_operands(walk_state
, next_op
);
658 if (ACPI_FAILURE(status
)) {
659 return_ACPI_STATUS(status
);
662 obj_desc
= acpi_ns_get_attached_object(node
);
664 return_ACPI_STATUS(AE_NOT_EXIST
);
667 /* Resolve the operands */
669 status
= acpi_ex_resolve_operands(op
->common
.aml_opcode
,
670 ACPI_WALK_OPERANDS
, walk_state
);
671 if (ACPI_FAILURE(status
)) {
672 ACPI_ERROR((AE_INFO
, "(%s) bad operand(s) (%X)",
673 acpi_ps_get_opcode_name(op
->common
.aml_opcode
),
676 return_ACPI_STATUS(status
);
679 /* Initialize the Buffer Field */
681 if (op
->common
.aml_opcode
== AML_CREATE_FIELD_OP
) {
683 /* NOTE: Slightly different operands for this opcode */
686 acpi_ds_init_buffer_field(op
->common
.aml_opcode
, obj_desc
,
687 walk_state
->operands
[0],
688 walk_state
->operands
[1],
689 walk_state
->operands
[2],
690 walk_state
->operands
[3]);
692 /* All other, create_xxx_field opcodes */
695 acpi_ds_init_buffer_field(op
->common
.aml_opcode
, obj_desc
,
696 walk_state
->operands
[0],
697 walk_state
->operands
[1], NULL
,
698 walk_state
->operands
[2]);
701 return_ACPI_STATUS(status
);
704 /*******************************************************************************
706 * FUNCTION: acpi_ds_eval_region_operands
708 * PARAMETERS: walk_state - Current walk
709 * Op - A valid region Op object
713 * DESCRIPTION: Get region address and length
714 * Called from acpi_ds_exec_end_op during op_region parse tree walk
716 ******************************************************************************/
719 acpi_ds_eval_region_operands(struct acpi_walk_state
*walk_state
,
720 union acpi_parse_object
*op
)
723 union acpi_operand_object
*obj_desc
;
724 union acpi_operand_object
*operand_desc
;
725 struct acpi_namespace_node
*node
;
726 union acpi_parse_object
*next_op
;
728 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands
, op
);
731 * This is where we evaluate the address and length fields of the
732 * op_region declaration
734 node
= op
->common
.node
;
736 /* next_op points to the op that holds the space_iD */
738 next_op
= op
->common
.value
.arg
;
740 /* next_op points to address op */
742 next_op
= next_op
->common
.next
;
744 /* Evaluate/create the address and length operands */
746 status
= acpi_ds_create_operands(walk_state
, next_op
);
747 if (ACPI_FAILURE(status
)) {
748 return_ACPI_STATUS(status
);
751 /* Resolve the length and address operands to numbers */
753 status
= acpi_ex_resolve_operands(op
->common
.aml_opcode
,
754 ACPI_WALK_OPERANDS
, walk_state
);
755 if (ACPI_FAILURE(status
)) {
756 return_ACPI_STATUS(status
);
759 obj_desc
= acpi_ns_get_attached_object(node
);
761 return_ACPI_STATUS(AE_NOT_EXIST
);
765 * Get the length operand and save it
768 operand_desc
= walk_state
->operands
[walk_state
->num_operands
- 1];
770 obj_desc
->region
.length
= (u32
) operand_desc
->integer
.value
;
771 acpi_ut_remove_reference(operand_desc
);
774 * Get the address and save it
775 * (at top of stack - 1)
777 operand_desc
= walk_state
->operands
[walk_state
->num_operands
- 2];
779 obj_desc
->region
.address
= (acpi_physical_address
)
780 operand_desc
->integer
.value
;
781 acpi_ut_remove_reference(operand_desc
);
783 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
785 ACPI_FORMAT_NATIVE_UINT(obj_desc
->region
.address
),
786 obj_desc
->region
.length
));
788 /* Now the address and length are valid for this opregion */
790 obj_desc
->region
.flags
|= AOPOBJ_DATA_VALID
;
792 return_ACPI_STATUS(status
);
795 /*******************************************************************************
797 * FUNCTION: acpi_ds_eval_table_region_operands
799 * PARAMETERS: walk_state - Current walk
800 * Op - A valid region Op object
804 * DESCRIPTION: Get region address and length
805 * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
807 ******************************************************************************/
810 acpi_ds_eval_table_region_operands(struct acpi_walk_state
*walk_state
,
811 union acpi_parse_object
*op
)
814 union acpi_operand_object
*obj_desc
;
815 union acpi_operand_object
**operand
;
816 struct acpi_namespace_node
*node
;
817 union acpi_parse_object
*next_op
;
819 struct acpi_table_header
*table
;
821 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands
, op
);
824 * This is where we evaluate the signature_string and oem_iDString
825 * and oem_table_iDString of the data_table_region declaration
827 node
= op
->common
.node
;
829 /* next_op points to signature_string op */
831 next_op
= op
->common
.value
.arg
;
834 * Evaluate/create the signature_string and oem_iDString
835 * and oem_table_iDString operands
837 status
= acpi_ds_create_operands(walk_state
, next_op
);
838 if (ACPI_FAILURE(status
)) {
839 return_ACPI_STATUS(status
);
843 * Resolve the signature_string and oem_iDString
844 * and oem_table_iDString operands
846 status
= acpi_ex_resolve_operands(op
->common
.aml_opcode
,
847 ACPI_WALK_OPERANDS
, walk_state
);
848 if (ACPI_FAILURE(status
)) {
849 return_ACPI_STATUS(status
);
852 operand
= &walk_state
->operands
[0];
854 /* Find the ACPI table */
856 status
= acpi_tb_find_table(operand
[0]->string
.pointer
,
857 operand
[1]->string
.pointer
,
858 operand
[2]->string
.pointer
, &table_index
);
859 if (ACPI_FAILURE(status
)) {
860 return_ACPI_STATUS(status
);
863 acpi_ut_remove_reference(operand
[0]);
864 acpi_ut_remove_reference(operand
[1]);
865 acpi_ut_remove_reference(operand
[2]);
867 status
= acpi_get_table_by_index(table_index
, &table
);
868 if (ACPI_FAILURE(status
)) {
869 return_ACPI_STATUS(status
);
872 obj_desc
= acpi_ns_get_attached_object(node
);
874 return_ACPI_STATUS(AE_NOT_EXIST
);
877 obj_desc
->region
.address
=
878 (acpi_physical_address
) ACPI_TO_INTEGER(table
);
879 obj_desc
->region
.length
= table
->length
;
881 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
883 ACPI_FORMAT_NATIVE_UINT(obj_desc
->region
.address
),
884 obj_desc
->region
.length
));
886 /* Now the address and length are valid for this opregion */
888 obj_desc
->region
.flags
|= AOPOBJ_DATA_VALID
;
890 return_ACPI_STATUS(status
);
893 /*******************************************************************************
895 * FUNCTION: acpi_ds_eval_data_object_operands
897 * PARAMETERS: walk_state - Current walk
898 * Op - A valid data_object Op object
899 * obj_desc - data_object
903 * DESCRIPTION: Get the operands and complete the following data object types:
906 ******************************************************************************/
909 acpi_ds_eval_data_object_operands(struct acpi_walk_state
*walk_state
,
910 union acpi_parse_object
*op
,
911 union acpi_operand_object
*obj_desc
)
914 union acpi_operand_object
*arg_desc
;
917 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands
);
919 /* The first operand (for all of these data objects) is the length */
922 * Set proper index into operand stack for acpi_ds_obj_stack_push
923 * invoked inside acpi_ds_create_operand.
925 walk_state
->operand_index
= walk_state
->num_operands
;
927 status
= acpi_ds_create_operand(walk_state
, op
->common
.value
.arg
, 1);
928 if (ACPI_FAILURE(status
)) {
929 return_ACPI_STATUS(status
);
932 status
= acpi_ex_resolve_operands(walk_state
->opcode
,
934 operands
[walk_state
->num_operands
-
936 if (ACPI_FAILURE(status
)) {
937 return_ACPI_STATUS(status
);
940 /* Extract length operand */
942 arg_desc
= walk_state
->operands
[walk_state
->num_operands
- 1];
943 length
= (u32
) arg_desc
->integer
.value
;
945 /* Cleanup for length operand */
947 status
= acpi_ds_obj_stack_pop(1, walk_state
);
948 if (ACPI_FAILURE(status
)) {
949 return_ACPI_STATUS(status
);
952 acpi_ut_remove_reference(arg_desc
);
955 * Create the actual data object
957 switch (op
->common
.aml_opcode
) {
961 acpi_ds_build_internal_buffer_obj(walk_state
, op
, length
,
966 case AML_VAR_PACKAGE_OP
:
969 acpi_ds_build_internal_package_obj(walk_state
, op
, length
,
974 return_ACPI_STATUS(AE_AML_BAD_OPCODE
);
977 if (ACPI_SUCCESS(status
)) {
979 * Return the object in the walk_state, unless the parent is a package -
980 * in this case, the return object will be stored in the parse tree
983 if ((!op
->common
.parent
) ||
984 ((op
->common
.parent
->common
.aml_opcode
!= AML_PACKAGE_OP
) &&
985 (op
->common
.parent
->common
.aml_opcode
!=
987 && (op
->common
.parent
->common
.aml_opcode
!= AML_NAME_OP
))) {
988 walk_state
->result_obj
= obj_desc
;
992 return_ACPI_STATUS(status
);
995 /*******************************************************************************
997 * FUNCTION: acpi_ds_eval_bank_field_operands
999 * PARAMETERS: walk_state - Current walk
1000 * Op - A valid bank_field Op object
1004 * DESCRIPTION: Get bank_field bank_value
1005 * Called from acpi_ds_exec_end_op during bank_field parse tree walk
1007 ******************************************************************************/
1010 acpi_ds_eval_bank_field_operands(struct acpi_walk_state
*walk_state
,
1011 union acpi_parse_object
*op
)
1014 union acpi_operand_object
*obj_desc
;
1015 union acpi_operand_object
*operand_desc
;
1016 struct acpi_namespace_node
*node
;
1017 union acpi_parse_object
*next_op
;
1018 union acpi_parse_object
*arg
;
1020 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands
, op
);
1023 * This is where we evaluate the bank_value field of the
1024 * bank_field declaration
1027 /* next_op points to the op that holds the Region */
1029 next_op
= op
->common
.value
.arg
;
1031 /* next_op points to the op that holds the Bank Register */
1033 next_op
= next_op
->common
.next
;
1035 /* next_op points to the op that holds the Bank Value */
1037 next_op
= next_op
->common
.next
;
1040 * Set proper index into operand stack for acpi_ds_obj_stack_push
1041 * invoked inside acpi_ds_create_operand.
1043 * We use walk_state->Operands[0] to store the evaluated bank_value
1045 walk_state
->operand_index
= 0;
1047 status
= acpi_ds_create_operand(walk_state
, next_op
, 0);
1048 if (ACPI_FAILURE(status
)) {
1049 return_ACPI_STATUS(status
);
1052 status
= acpi_ex_resolve_to_value(&walk_state
->operands
[0], walk_state
);
1053 if (ACPI_FAILURE(status
)) {
1054 return_ACPI_STATUS(status
);
1057 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS
,
1058 acpi_ps_get_opcode_name(op
->common
.aml_opcode
), 1);
1060 * Get the bank_value operand and save it
1063 operand_desc
= walk_state
->operands
[0];
1065 /* Arg points to the start Bank Field */
1067 arg
= acpi_ps_get_arg(op
, 4);
1070 /* Ignore OFFSET and ACCESSAS terms here */
1072 if (arg
->common
.aml_opcode
== AML_INT_NAMEDFIELD_OP
) {
1073 node
= arg
->common
.node
;
1075 obj_desc
= acpi_ns_get_attached_object(node
);
1077 return_ACPI_STATUS(AE_NOT_EXIST
);
1080 obj_desc
->bank_field
.value
=
1081 (u32
) operand_desc
->integer
.value
;
1084 /* Move to next field in the list */
1086 arg
= arg
->common
.next
;
1089 acpi_ut_remove_reference(operand_desc
);
1090 return_ACPI_STATUS(status
);
1093 /*******************************************************************************
1095 * FUNCTION: acpi_ds_exec_begin_control_op
1097 * PARAMETERS: walk_list - The list that owns the walk stack
1098 * Op - The control Op
1102 * DESCRIPTION: Handles all control ops encountered during control method
1105 ******************************************************************************/
1108 acpi_ds_exec_begin_control_op(struct acpi_walk_state
*walk_state
,
1109 union acpi_parse_object
*op
)
1111 acpi_status status
= AE_OK
;
1112 union acpi_generic_state
*control_state
;
1114 ACPI_FUNCTION_NAME(ds_exec_begin_control_op
);
1116 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p Opcode=%2.2X State=%p\n", op
,
1117 op
->common
.aml_opcode
, walk_state
));
1119 switch (op
->common
.aml_opcode
) {
1123 * If this is an additional iteration of a while loop, continue.
1124 * There is no need to allocate a new control state.
1126 if (walk_state
->control_state
) {
1127 if (walk_state
->control_state
->control
.aml_predicate_start
1128 == (walk_state
->parser_state
.aml
- 1)) {
1130 /* Reset the state to start-of-loop */
1132 walk_state
->control_state
->common
.state
=
1133 ACPI_CONTROL_CONDITIONAL_EXECUTING
;
1138 /*lint -fallthrough */
1143 * IF/WHILE: Create a new control state to manage these
1144 * constructs. We need to manage these as a stack, in order
1145 * to handle nesting.
1147 control_state
= acpi_ut_create_control_state();
1148 if (!control_state
) {
1149 status
= AE_NO_MEMORY
;
1153 * Save a pointer to the predicate for multiple executions
1156 control_state
->control
.aml_predicate_start
=
1157 walk_state
->parser_state
.aml
- 1;
1158 control_state
->control
.package_end
=
1159 walk_state
->parser_state
.pkg_end
;
1160 control_state
->control
.opcode
= op
->common
.aml_opcode
;
1162 /* Push the control state on this walk's control stack */
1164 acpi_ut_push_generic_state(&walk_state
->control_state
,
1170 /* Predicate is in the state object */
1171 /* If predicate is true, the IF was executed, ignore ELSE part */
1173 if (walk_state
->last_predicate
) {
1174 status
= AE_CTRL_TRUE
;
1190 /*******************************************************************************
1192 * FUNCTION: acpi_ds_exec_end_control_op
1194 * PARAMETERS: walk_list - The list that owns the walk stack
1195 * Op - The control Op
1199 * DESCRIPTION: Handles all control ops encountered during control method
1202 ******************************************************************************/
1205 acpi_ds_exec_end_control_op(struct acpi_walk_state
* walk_state
,
1206 union acpi_parse_object
* op
)
1208 acpi_status status
= AE_OK
;
1209 union acpi_generic_state
*control_state
;
1211 ACPI_FUNCTION_NAME(ds_exec_end_control_op
);
1213 switch (op
->common
.aml_opcode
) {
1216 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "[IF_OP] Op=%p\n", op
));
1219 * Save the result of the predicate in case there is an
1222 walk_state
->last_predicate
=
1223 (u8
) walk_state
->control_state
->common
.value
;
1226 * Pop the control state that was created at the start
1227 * of the IF and free it
1230 acpi_ut_pop_generic_state(&walk_state
->control_state
);
1231 acpi_ut_delete_generic_state(control_state
);
1240 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "[WHILE_OP] Op=%p\n", op
));
1242 control_state
= walk_state
->control_state
;
1243 if (control_state
->common
.value
) {
1245 /* Predicate was true, the body of the loop was just executed */
1248 * This loop counter mechanism allows the interpreter to escape
1249 * possibly infinite loops. This can occur in poorly written AML
1250 * when the hardware does not respond within a while loop and the
1251 * loop does not implement a timeout.
1253 control_state
->control
.loop_count
++;
1254 if (control_state
->control
.loop_count
>
1255 ACPI_MAX_LOOP_ITERATIONS
) {
1256 status
= AE_AML_INFINITE_LOOP
;
1261 * Go back and evaluate the predicate and maybe execute the loop
1264 status
= AE_CTRL_PENDING
;
1265 walk_state
->aml_last_while
=
1266 control_state
->control
.aml_predicate_start
;
1270 /* Predicate was false, terminate this while loop */
1272 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
1273 "[WHILE_OP] termination! Op=%p\n", op
));
1275 /* Pop this control state and free it */
1278 acpi_ut_pop_generic_state(&walk_state
->control_state
);
1279 acpi_ut_delete_generic_state(control_state
);
1284 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
1285 "[RETURN_OP] Op=%p Arg=%p\n", op
,
1286 op
->common
.value
.arg
));
1289 * One optional operand -- the return value
1290 * It can be either an immediate operand or a result that
1291 * has been bubbled up the tree
1293 if (op
->common
.value
.arg
) {
1295 /* Since we have a real Return(), delete any implicit return */
1297 acpi_ds_clear_implicit_return(walk_state
);
1299 /* Return statement has an immediate operand */
1302 acpi_ds_create_operands(walk_state
,
1303 op
->common
.value
.arg
);
1304 if (ACPI_FAILURE(status
)) {
1309 * If value being returned is a Reference (such as
1310 * an arg or local), resolve it now because it may
1311 * cease to exist at the end of the method.
1314 acpi_ex_resolve_to_value(&walk_state
->operands
[0],
1316 if (ACPI_FAILURE(status
)) {
1321 * Get the return value and save as the last result
1322 * value. This is the only place where walk_state->return_desc
1323 * is set to anything other than zero!
1325 walk_state
->return_desc
= walk_state
->operands
[0];
1326 } else if (walk_state
->result_count
) {
1328 /* Since we have a real Return(), delete any implicit return */
1330 acpi_ds_clear_implicit_return(walk_state
);
1333 * The return value has come from a previous calculation.
1335 * If value being returned is a Reference (such as
1336 * an arg or local), resolve it now because it may
1337 * cease to exist at the end of the method.
1339 * Allow references created by the Index operator to return unchanged.
1341 if ((ACPI_GET_DESCRIPTOR_TYPE
1342 (walk_state
->results
->results
.obj_desc
[0]) ==
1343 ACPI_DESC_TYPE_OPERAND
)
1344 && ((walk_state
->results
->results
.obj_desc
[0])->
1345 common
.type
== ACPI_TYPE_LOCAL_REFERENCE
)
1346 && ((walk_state
->results
->results
.obj_desc
[0])->
1347 reference
.class != ACPI_REFCLASS_INDEX
)) {
1349 acpi_ex_resolve_to_value(&walk_state
->
1353 if (ACPI_FAILURE(status
)) {
1358 walk_state
->return_desc
=
1359 walk_state
->results
->results
.obj_desc
[0];
1361 /* No return operand */
1363 if (walk_state
->num_operands
) {
1364 acpi_ut_remove_reference(walk_state
->
1368 walk_state
->operands
[0] = NULL
;
1369 walk_state
->num_operands
= 0;
1370 walk_state
->return_desc
= NULL
;
1373 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
1374 "Completed RETURN_OP State=%p, RetVal=%p\n",
1375 walk_state
, walk_state
->return_desc
));
1377 /* End the control method execution right now */
1379 status
= AE_CTRL_TERMINATE
;
1384 /* Just do nothing! */
1387 case AML_BREAK_POINT_OP
:
1390 * Set the single-step flag. This will cause the debugger (if present)
1391 * to break to the console within the AML debugger at the start of the
1392 * next AML instruction.
1394 ACPI_DEBUGGER_EXEC(acpi_gbl_cm_single_step
= TRUE
);
1395 ACPI_DEBUGGER_EXEC(acpi_os_printf
1396 ("**break** Executed AML BreakPoint opcode\n"));
1398 /* Call to the OSL in case OS wants a piece of the action */
1400 status
= acpi_os_signal(ACPI_SIGNAL_BREAKPOINT
,
1401 "Executed AML Breakpoint opcode");
1405 case AML_CONTINUE_OP
: /* ACPI 2.0 */
1407 /* Pop and delete control states until we find a while */
1409 while (walk_state
->control_state
&&
1410 (walk_state
->control_state
->control
.opcode
!=
1413 acpi_ut_pop_generic_state(&walk_state
->
1415 acpi_ut_delete_generic_state(control_state
);
1418 /* No while found? */
1420 if (!walk_state
->control_state
) {
1421 return (AE_AML_NO_WHILE
);
1424 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1426 walk_state
->aml_last_while
=
1427 walk_state
->control_state
->control
.package_end
;
1429 /* Return status depending on opcode */
1431 if (op
->common
.aml_opcode
== AML_BREAK_OP
) {
1432 status
= AE_CTRL_BREAK
;
1434 status
= AE_CTRL_CONTINUE
;
1440 ACPI_ERROR((AE_INFO
, "Unknown control opcode=%X Op=%p",
1441 op
->common
.aml_opcode
, op
));
1443 status
= AE_AML_BAD_OPCODE
;