1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher Op Region support and handling of
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, 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
, node
->parent
,
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
, node
->parent
,
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 namespace node in buffer object %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 namespace 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
, node
->parent
,
398 extra_desc
->extra
.aml_length
,
399 extra_desc
->extra
.aml_start
);
400 if (ACPI_FAILURE(status
)) {
401 return_ACPI_STATUS(status
);
404 /* Validate the region address/length via the host OS */
406 status
= acpi_os_validate_address(obj_desc
->region
.space_id
,
407 obj_desc
->region
.address
,
408 (acpi_size
) obj_desc
->region
.length
,
409 acpi_ut_get_node_name(node
));
411 if (ACPI_FAILURE(status
)) {
413 * Invalid address/length. We will emit an error message and mark
414 * the region as invalid, so that it will cause an additional error if
415 * it is ever used. Then return AE_OK.
417 ACPI_EXCEPTION((AE_INFO
, status
,
418 "During address validation of OpRegion [%4.4s]",
420 obj_desc
->common
.flags
|= AOPOBJ_INVALID
;
424 return_ACPI_STATUS(status
);
427 /*******************************************************************************
429 * FUNCTION: acpi_ds_initialize_region
431 * PARAMETERS: obj_handle - Region namespace node
435 * DESCRIPTION: Front end to ev_initialize_region
437 ******************************************************************************/
439 acpi_status
acpi_ds_initialize_region(acpi_handle obj_handle
)
441 union acpi_operand_object
*obj_desc
;
444 obj_desc
= acpi_ns_get_attached_object(obj_handle
);
446 /* Namespace is NOT locked */
448 status
= acpi_ev_initialize_region(obj_desc
, FALSE
);
452 /*******************************************************************************
454 * FUNCTION: acpi_ds_init_buffer_field
456 * PARAMETERS: aml_opcode - create_xxx_field
457 * obj_desc - buffer_field object
458 * buffer_desc - Host Buffer
459 * offset_desc - Offset into buffer
460 * length_desc - Length of field (CREATE_FIELD_OP only)
461 * result_desc - Where to store the result
465 * DESCRIPTION: Perform actual initialization of a buffer field
467 ******************************************************************************/
470 acpi_ds_init_buffer_field(u16 aml_opcode
,
471 union acpi_operand_object
*obj_desc
,
472 union acpi_operand_object
*buffer_desc
,
473 union acpi_operand_object
*offset_desc
,
474 union acpi_operand_object
*length_desc
,
475 union acpi_operand_object
*result_desc
)
483 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field
, obj_desc
);
485 /* Host object must be a Buffer */
487 if (buffer_desc
->common
.type
!= ACPI_TYPE_BUFFER
) {
489 "Target of Create Field is not a Buffer object - %s",
490 acpi_ut_get_object_type_name(buffer_desc
)));
492 status
= AE_AML_OPERAND_TYPE
;
497 * The last parameter to all of these opcodes (result_desc) started
498 * out as a name_string, and should therefore now be a NS node
499 * after resolution in acpi_ex_resolve_operands().
501 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc
) != ACPI_DESC_TYPE_NAMED
) {
503 "(%s) destination not a NS Node [%s]",
504 acpi_ps_get_opcode_name(aml_opcode
),
505 acpi_ut_get_descriptor_name(result_desc
)));
507 status
= AE_AML_OPERAND_TYPE
;
511 offset
= (u32
) offset_desc
->integer
.value
;
514 * Setup the Bit offsets and counts, according to the opcode
516 switch (aml_opcode
) {
517 case AML_CREATE_FIELD_OP
:
519 /* Offset is in bits, count is in bits */
521 field_flags
= AML_FIELD_ACCESS_BYTE
;
523 bit_count
= (u32
) length_desc
->integer
.value
;
525 /* Must have a valid (>0) bit count */
527 if (bit_count
== 0) {
529 "Attempt to CreateField of length zero"));
530 status
= AE_AML_OPERAND_VALUE
;
535 case AML_CREATE_BIT_FIELD_OP
:
537 /* Offset is in bits, Field is one bit */
541 field_flags
= AML_FIELD_ACCESS_BYTE
;
544 case AML_CREATE_BYTE_FIELD_OP
:
546 /* Offset is in bytes, field is one byte */
548 bit_offset
= 8 * offset
;
550 field_flags
= AML_FIELD_ACCESS_BYTE
;
553 case AML_CREATE_WORD_FIELD_OP
:
555 /* Offset is in bytes, field is one word */
557 bit_offset
= 8 * offset
;
559 field_flags
= AML_FIELD_ACCESS_WORD
;
562 case AML_CREATE_DWORD_FIELD_OP
:
564 /* Offset is in bytes, field is one dword */
566 bit_offset
= 8 * offset
;
568 field_flags
= AML_FIELD_ACCESS_DWORD
;
571 case AML_CREATE_QWORD_FIELD_OP
:
573 /* Offset is in bytes, field is one qword */
575 bit_offset
= 8 * offset
;
577 field_flags
= AML_FIELD_ACCESS_QWORD
;
583 "Unknown field creation opcode 0x%02X",
585 status
= AE_AML_BAD_OPCODE
;
589 /* Entire field must fit within the current length of the buffer */
591 if ((bit_offset
+ bit_count
) > (8 * (u32
) buffer_desc
->buffer
.length
)) {
593 "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
594 acpi_ut_get_node_name(result_desc
),
595 bit_offset
+ bit_count
,
596 acpi_ut_get_node_name(buffer_desc
->buffer
.node
),
597 8 * (u32
) buffer_desc
->buffer
.length
));
598 status
= AE_AML_BUFFER_LIMIT
;
603 * Initialize areas of the field object that are common to all fields
604 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
605 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
607 status
= acpi_ex_prep_common_field_object(obj_desc
, field_flags
, 0,
608 bit_offset
, bit_count
);
609 if (ACPI_FAILURE(status
)) {
613 obj_desc
->buffer_field
.buffer_obj
= buffer_desc
;
615 /* Reference count for buffer_desc inherits obj_desc count */
617 buffer_desc
->common
.reference_count
= (u16
)
618 (buffer_desc
->common
.reference_count
+
619 obj_desc
->common
.reference_count
);
623 /* Always delete the operands */
625 acpi_ut_remove_reference(offset_desc
);
626 acpi_ut_remove_reference(buffer_desc
);
628 if (aml_opcode
== AML_CREATE_FIELD_OP
) {
629 acpi_ut_remove_reference(length_desc
);
632 /* On failure, delete the result descriptor */
634 if (ACPI_FAILURE(status
)) {
635 acpi_ut_remove_reference(result_desc
); /* Result descriptor */
637 /* Now the address and length are valid for this buffer_field */
639 obj_desc
->buffer_field
.flags
|= AOPOBJ_DATA_VALID
;
642 return_ACPI_STATUS(status
);
645 /*******************************************************************************
647 * FUNCTION: acpi_ds_eval_buffer_field_operands
649 * PARAMETERS: walk_state - Current walk
650 * Op - A valid buffer_field Op object
654 * DESCRIPTION: Get buffer_field Buffer and Index
655 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
657 ******************************************************************************/
660 acpi_ds_eval_buffer_field_operands(struct acpi_walk_state
*walk_state
,
661 union acpi_parse_object
*op
)
664 union acpi_operand_object
*obj_desc
;
665 struct acpi_namespace_node
*node
;
666 union acpi_parse_object
*next_op
;
668 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands
, op
);
671 * This is where we evaluate the address and length fields of the
672 * create_xxx_field declaration
674 node
= op
->common
.node
;
676 /* next_op points to the op that holds the Buffer */
678 next_op
= op
->common
.value
.arg
;
680 /* Evaluate/create the address and length operands */
682 status
= acpi_ds_create_operands(walk_state
, next_op
);
683 if (ACPI_FAILURE(status
)) {
684 return_ACPI_STATUS(status
);
687 obj_desc
= acpi_ns_get_attached_object(node
);
689 return_ACPI_STATUS(AE_NOT_EXIST
);
692 /* Resolve the operands */
694 status
= acpi_ex_resolve_operands(op
->common
.aml_opcode
,
695 ACPI_WALK_OPERANDS
, walk_state
);
696 if (ACPI_FAILURE(status
)) {
697 ACPI_ERROR((AE_INFO
, "(%s) bad operand(s), status 0x%X",
698 acpi_ps_get_opcode_name(op
->common
.aml_opcode
),
701 return_ACPI_STATUS(status
);
704 /* Initialize the Buffer Field */
706 if (op
->common
.aml_opcode
== AML_CREATE_FIELD_OP
) {
708 /* NOTE: Slightly different operands for this opcode */
711 acpi_ds_init_buffer_field(op
->common
.aml_opcode
, obj_desc
,
712 walk_state
->operands
[0],
713 walk_state
->operands
[1],
714 walk_state
->operands
[2],
715 walk_state
->operands
[3]);
717 /* All other, create_xxx_field opcodes */
720 acpi_ds_init_buffer_field(op
->common
.aml_opcode
, obj_desc
,
721 walk_state
->operands
[0],
722 walk_state
->operands
[1], NULL
,
723 walk_state
->operands
[2]);
726 return_ACPI_STATUS(status
);
729 /*******************************************************************************
731 * FUNCTION: acpi_ds_eval_region_operands
733 * PARAMETERS: walk_state - Current walk
734 * Op - A valid region Op object
738 * DESCRIPTION: Get region address and length
739 * Called from acpi_ds_exec_end_op during op_region parse tree walk
741 ******************************************************************************/
744 acpi_ds_eval_region_operands(struct acpi_walk_state
*walk_state
,
745 union acpi_parse_object
*op
)
748 union acpi_operand_object
*obj_desc
;
749 union acpi_operand_object
*operand_desc
;
750 struct acpi_namespace_node
*node
;
751 union acpi_parse_object
*next_op
;
753 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands
, op
);
756 * This is where we evaluate the address and length fields of the
757 * op_region declaration
759 node
= op
->common
.node
;
761 /* next_op points to the op that holds the space_iD */
763 next_op
= op
->common
.value
.arg
;
765 /* next_op points to address op */
767 next_op
= next_op
->common
.next
;
769 /* Evaluate/create the address and length operands */
771 status
= acpi_ds_create_operands(walk_state
, next_op
);
772 if (ACPI_FAILURE(status
)) {
773 return_ACPI_STATUS(status
);
776 /* Resolve the length and address operands to numbers */
778 status
= acpi_ex_resolve_operands(op
->common
.aml_opcode
,
779 ACPI_WALK_OPERANDS
, walk_state
);
780 if (ACPI_FAILURE(status
)) {
781 return_ACPI_STATUS(status
);
784 obj_desc
= acpi_ns_get_attached_object(node
);
786 return_ACPI_STATUS(AE_NOT_EXIST
);
790 * Get the length operand and save it
793 operand_desc
= walk_state
->operands
[walk_state
->num_operands
- 1];
795 obj_desc
->region
.length
= (u32
) operand_desc
->integer
.value
;
796 acpi_ut_remove_reference(operand_desc
);
799 * Get the address and save it
800 * (at top of stack - 1)
802 operand_desc
= walk_state
->operands
[walk_state
->num_operands
- 2];
804 obj_desc
->region
.address
= (acpi_physical_address
)
805 operand_desc
->integer
.value
;
806 acpi_ut_remove_reference(operand_desc
);
808 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
810 ACPI_FORMAT_NATIVE_UINT(obj_desc
->region
.address
),
811 obj_desc
->region
.length
));
813 /* Now the address and length are valid for this opregion */
815 obj_desc
->region
.flags
|= AOPOBJ_DATA_VALID
;
817 return_ACPI_STATUS(status
);
820 /*******************************************************************************
822 * FUNCTION: acpi_ds_eval_table_region_operands
824 * PARAMETERS: walk_state - Current walk
825 * Op - A valid region Op object
829 * DESCRIPTION: Get region address and length
830 * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
832 ******************************************************************************/
835 acpi_ds_eval_table_region_operands(struct acpi_walk_state
*walk_state
,
836 union acpi_parse_object
*op
)
839 union acpi_operand_object
*obj_desc
;
840 union acpi_operand_object
**operand
;
841 struct acpi_namespace_node
*node
;
842 union acpi_parse_object
*next_op
;
844 struct acpi_table_header
*table
;
846 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands
, op
);
849 * This is where we evaluate the signature_string and oem_iDString
850 * and oem_table_iDString of the data_table_region declaration
852 node
= op
->common
.node
;
854 /* next_op points to signature_string op */
856 next_op
= op
->common
.value
.arg
;
859 * Evaluate/create the signature_string and oem_iDString
860 * and oem_table_iDString operands
862 status
= acpi_ds_create_operands(walk_state
, next_op
);
863 if (ACPI_FAILURE(status
)) {
864 return_ACPI_STATUS(status
);
868 * Resolve the signature_string and oem_iDString
869 * and oem_table_iDString operands
871 status
= acpi_ex_resolve_operands(op
->common
.aml_opcode
,
872 ACPI_WALK_OPERANDS
, walk_state
);
873 if (ACPI_FAILURE(status
)) {
874 return_ACPI_STATUS(status
);
877 operand
= &walk_state
->operands
[0];
879 /* Find the ACPI table */
881 status
= acpi_tb_find_table(operand
[0]->string
.pointer
,
882 operand
[1]->string
.pointer
,
883 operand
[2]->string
.pointer
, &table_index
);
884 if (ACPI_FAILURE(status
)) {
885 return_ACPI_STATUS(status
);
888 acpi_ut_remove_reference(operand
[0]);
889 acpi_ut_remove_reference(operand
[1]);
890 acpi_ut_remove_reference(operand
[2]);
892 status
= acpi_get_table_by_index(table_index
, &table
);
893 if (ACPI_FAILURE(status
)) {
894 return_ACPI_STATUS(status
);
897 obj_desc
= acpi_ns_get_attached_object(node
);
899 return_ACPI_STATUS(AE_NOT_EXIST
);
902 obj_desc
->region
.address
=
903 (acpi_physical_address
) ACPI_TO_INTEGER(table
);
904 obj_desc
->region
.length
= table
->length
;
906 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
908 ACPI_FORMAT_NATIVE_UINT(obj_desc
->region
.address
),
909 obj_desc
->region
.length
));
911 /* Now the address and length are valid for this opregion */
913 obj_desc
->region
.flags
|= AOPOBJ_DATA_VALID
;
915 return_ACPI_STATUS(status
);
918 /*******************************************************************************
920 * FUNCTION: acpi_ds_eval_data_object_operands
922 * PARAMETERS: walk_state - Current walk
923 * Op - A valid data_object Op object
924 * obj_desc - data_object
928 * DESCRIPTION: Get the operands and complete the following data object types:
931 ******************************************************************************/
934 acpi_ds_eval_data_object_operands(struct acpi_walk_state
*walk_state
,
935 union acpi_parse_object
*op
,
936 union acpi_operand_object
*obj_desc
)
939 union acpi_operand_object
*arg_desc
;
942 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands
);
944 /* The first operand (for all of these data objects) is the length */
947 * Set proper index into operand stack for acpi_ds_obj_stack_push
948 * invoked inside acpi_ds_create_operand.
950 walk_state
->operand_index
= walk_state
->num_operands
;
952 status
= acpi_ds_create_operand(walk_state
, op
->common
.value
.arg
, 1);
953 if (ACPI_FAILURE(status
)) {
954 return_ACPI_STATUS(status
);
957 status
= acpi_ex_resolve_operands(walk_state
->opcode
,
959 operands
[walk_state
->num_operands
-
961 if (ACPI_FAILURE(status
)) {
962 return_ACPI_STATUS(status
);
965 /* Extract length operand */
967 arg_desc
= walk_state
->operands
[walk_state
->num_operands
- 1];
968 length
= (u32
) arg_desc
->integer
.value
;
970 /* Cleanup for length operand */
972 status
= acpi_ds_obj_stack_pop(1, walk_state
);
973 if (ACPI_FAILURE(status
)) {
974 return_ACPI_STATUS(status
);
977 acpi_ut_remove_reference(arg_desc
);
980 * Create the actual data object
982 switch (op
->common
.aml_opcode
) {
986 acpi_ds_build_internal_buffer_obj(walk_state
, op
, length
,
991 case AML_VAR_PACKAGE_OP
:
994 acpi_ds_build_internal_package_obj(walk_state
, op
, length
,
999 return_ACPI_STATUS(AE_AML_BAD_OPCODE
);
1002 if (ACPI_SUCCESS(status
)) {
1004 * Return the object in the walk_state, unless the parent is a package -
1005 * in this case, the return object will be stored in the parse tree
1008 if ((!op
->common
.parent
) ||
1009 ((op
->common
.parent
->common
.aml_opcode
!= AML_PACKAGE_OP
) &&
1010 (op
->common
.parent
->common
.aml_opcode
!=
1012 && (op
->common
.parent
->common
.aml_opcode
!= AML_NAME_OP
))) {
1013 walk_state
->result_obj
= obj_desc
;
1017 return_ACPI_STATUS(status
);
1020 /*******************************************************************************
1022 * FUNCTION: acpi_ds_eval_bank_field_operands
1024 * PARAMETERS: walk_state - Current walk
1025 * Op - A valid bank_field Op object
1029 * DESCRIPTION: Get bank_field bank_value
1030 * Called from acpi_ds_exec_end_op during bank_field parse tree walk
1032 ******************************************************************************/
1035 acpi_ds_eval_bank_field_operands(struct acpi_walk_state
*walk_state
,
1036 union acpi_parse_object
*op
)
1039 union acpi_operand_object
*obj_desc
;
1040 union acpi_operand_object
*operand_desc
;
1041 struct acpi_namespace_node
*node
;
1042 union acpi_parse_object
*next_op
;
1043 union acpi_parse_object
*arg
;
1045 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands
, op
);
1048 * This is where we evaluate the bank_value field of the
1049 * bank_field declaration
1052 /* next_op points to the op that holds the Region */
1054 next_op
= op
->common
.value
.arg
;
1056 /* next_op points to the op that holds the Bank Register */
1058 next_op
= next_op
->common
.next
;
1060 /* next_op points to the op that holds the Bank Value */
1062 next_op
= next_op
->common
.next
;
1065 * Set proper index into operand stack for acpi_ds_obj_stack_push
1066 * invoked inside acpi_ds_create_operand.
1068 * We use walk_state->Operands[0] to store the evaluated bank_value
1070 walk_state
->operand_index
= 0;
1072 status
= acpi_ds_create_operand(walk_state
, next_op
, 0);
1073 if (ACPI_FAILURE(status
)) {
1074 return_ACPI_STATUS(status
);
1077 status
= acpi_ex_resolve_to_value(&walk_state
->operands
[0], walk_state
);
1078 if (ACPI_FAILURE(status
)) {
1079 return_ACPI_STATUS(status
);
1082 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS
,
1083 acpi_ps_get_opcode_name(op
->common
.aml_opcode
), 1);
1085 * Get the bank_value operand and save it
1088 operand_desc
= walk_state
->operands
[0];
1090 /* Arg points to the start Bank Field */
1092 arg
= acpi_ps_get_arg(op
, 4);
1095 /* Ignore OFFSET and ACCESSAS terms here */
1097 if (arg
->common
.aml_opcode
== AML_INT_NAMEDFIELD_OP
) {
1098 node
= arg
->common
.node
;
1100 obj_desc
= acpi_ns_get_attached_object(node
);
1102 return_ACPI_STATUS(AE_NOT_EXIST
);
1105 obj_desc
->bank_field
.value
=
1106 (u32
) operand_desc
->integer
.value
;
1109 /* Move to next field in the list */
1111 arg
= arg
->common
.next
;
1114 acpi_ut_remove_reference(operand_desc
);
1115 return_ACPI_STATUS(status
);
1118 /*******************************************************************************
1120 * FUNCTION: acpi_ds_exec_begin_control_op
1122 * PARAMETERS: walk_list - The list that owns the walk stack
1123 * Op - The control Op
1127 * DESCRIPTION: Handles all control ops encountered during control method
1130 ******************************************************************************/
1133 acpi_ds_exec_begin_control_op(struct acpi_walk_state
*walk_state
,
1134 union acpi_parse_object
*op
)
1136 acpi_status status
= AE_OK
;
1137 union acpi_generic_state
*control_state
;
1139 ACPI_FUNCTION_NAME(ds_exec_begin_control_op
);
1141 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "Op=%p Opcode=%2.2X State=%p\n", op
,
1142 op
->common
.aml_opcode
, walk_state
));
1144 switch (op
->common
.aml_opcode
) {
1148 * If this is an additional iteration of a while loop, continue.
1149 * There is no need to allocate a new control state.
1151 if (walk_state
->control_state
) {
1152 if (walk_state
->control_state
->control
.aml_predicate_start
1153 == (walk_state
->parser_state
.aml
- 1)) {
1155 /* Reset the state to start-of-loop */
1157 walk_state
->control_state
->common
.state
=
1158 ACPI_CONTROL_CONDITIONAL_EXECUTING
;
1163 /*lint -fallthrough */
1168 * IF/WHILE: Create a new control state to manage these
1169 * constructs. We need to manage these as a stack, in order
1170 * to handle nesting.
1172 control_state
= acpi_ut_create_control_state();
1173 if (!control_state
) {
1174 status
= AE_NO_MEMORY
;
1178 * Save a pointer to the predicate for multiple executions
1181 control_state
->control
.aml_predicate_start
=
1182 walk_state
->parser_state
.aml
- 1;
1183 control_state
->control
.package_end
=
1184 walk_state
->parser_state
.pkg_end
;
1185 control_state
->control
.opcode
= op
->common
.aml_opcode
;
1187 /* Push the control state on this walk's control stack */
1189 acpi_ut_push_generic_state(&walk_state
->control_state
,
1195 /* Predicate is in the state object */
1196 /* If predicate is true, the IF was executed, ignore ELSE part */
1198 if (walk_state
->last_predicate
) {
1199 status
= AE_CTRL_TRUE
;
1215 /*******************************************************************************
1217 * FUNCTION: acpi_ds_exec_end_control_op
1219 * PARAMETERS: walk_list - The list that owns the walk stack
1220 * Op - The control Op
1224 * DESCRIPTION: Handles all control ops encountered during control method
1227 ******************************************************************************/
1230 acpi_ds_exec_end_control_op(struct acpi_walk_state
* walk_state
,
1231 union acpi_parse_object
* op
)
1233 acpi_status status
= AE_OK
;
1234 union acpi_generic_state
*control_state
;
1236 ACPI_FUNCTION_NAME(ds_exec_end_control_op
);
1238 switch (op
->common
.aml_opcode
) {
1241 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "[IF_OP] Op=%p\n", op
));
1244 * Save the result of the predicate in case there is an
1247 walk_state
->last_predicate
=
1248 (u8
) walk_state
->control_state
->common
.value
;
1251 * Pop the control state that was created at the start
1252 * of the IF and free it
1255 acpi_ut_pop_generic_state(&walk_state
->control_state
);
1256 acpi_ut_delete_generic_state(control_state
);
1265 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "[WHILE_OP] Op=%p\n", op
));
1267 control_state
= walk_state
->control_state
;
1268 if (control_state
->common
.value
) {
1270 /* Predicate was true, the body of the loop was just executed */
1273 * This loop counter mechanism allows the interpreter to escape
1274 * possibly infinite loops. This can occur in poorly written AML
1275 * when the hardware does not respond within a while loop and the
1276 * loop does not implement a timeout.
1278 control_state
->control
.loop_count
++;
1279 if (control_state
->control
.loop_count
>
1280 ACPI_MAX_LOOP_ITERATIONS
) {
1281 status
= AE_AML_INFINITE_LOOP
;
1286 * Go back and evaluate the predicate and maybe execute the loop
1289 status
= AE_CTRL_PENDING
;
1290 walk_state
->aml_last_while
=
1291 control_state
->control
.aml_predicate_start
;
1295 /* Predicate was false, terminate this while loop */
1297 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
1298 "[WHILE_OP] termination! Op=%p\n", op
));
1300 /* Pop this control state and free it */
1303 acpi_ut_pop_generic_state(&walk_state
->control_state
);
1304 acpi_ut_delete_generic_state(control_state
);
1309 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
1310 "[RETURN_OP] Op=%p Arg=%p\n", op
,
1311 op
->common
.value
.arg
));
1314 * One optional operand -- the return value
1315 * It can be either an immediate operand or a result that
1316 * has been bubbled up the tree
1318 if (op
->common
.value
.arg
) {
1320 /* Since we have a real Return(), delete any implicit return */
1322 acpi_ds_clear_implicit_return(walk_state
);
1324 /* Return statement has an immediate operand */
1327 acpi_ds_create_operands(walk_state
,
1328 op
->common
.value
.arg
);
1329 if (ACPI_FAILURE(status
)) {
1334 * If value being returned is a Reference (such as
1335 * an arg or local), resolve it now because it may
1336 * cease to exist at the end of the method.
1339 acpi_ex_resolve_to_value(&walk_state
->operands
[0],
1341 if (ACPI_FAILURE(status
)) {
1346 * Get the return value and save as the last result
1347 * value. This is the only place where walk_state->return_desc
1348 * is set to anything other than zero!
1350 walk_state
->return_desc
= walk_state
->operands
[0];
1351 } else if (walk_state
->result_count
) {
1353 /* Since we have a real Return(), delete any implicit return */
1355 acpi_ds_clear_implicit_return(walk_state
);
1358 * The return value has come from a previous calculation.
1360 * If value being returned is a Reference (such as
1361 * an arg or local), resolve it now because it may
1362 * cease to exist at the end of the method.
1364 * Allow references created by the Index operator to return unchanged.
1366 if ((ACPI_GET_DESCRIPTOR_TYPE
1367 (walk_state
->results
->results
.obj_desc
[0]) ==
1368 ACPI_DESC_TYPE_OPERAND
)
1369 && ((walk_state
->results
->results
.obj_desc
[0])->
1370 common
.type
== ACPI_TYPE_LOCAL_REFERENCE
)
1371 && ((walk_state
->results
->results
.obj_desc
[0])->
1372 reference
.class != ACPI_REFCLASS_INDEX
)) {
1374 acpi_ex_resolve_to_value(&walk_state
->
1378 if (ACPI_FAILURE(status
)) {
1383 walk_state
->return_desc
=
1384 walk_state
->results
->results
.obj_desc
[0];
1386 /* No return operand */
1388 if (walk_state
->num_operands
) {
1389 acpi_ut_remove_reference(walk_state
->
1393 walk_state
->operands
[0] = NULL
;
1394 walk_state
->num_operands
= 0;
1395 walk_state
->return_desc
= NULL
;
1398 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
1399 "Completed RETURN_OP State=%p, RetVal=%p\n",
1400 walk_state
, walk_state
->return_desc
));
1402 /* End the control method execution right now */
1404 status
= AE_CTRL_TERMINATE
;
1409 /* Just do nothing! */
1412 case AML_BREAK_POINT_OP
:
1415 * Set the single-step flag. This will cause the debugger (if present)
1416 * to break to the console within the AML debugger at the start of the
1417 * next AML instruction.
1419 ACPI_DEBUGGER_EXEC(acpi_gbl_cm_single_step
= TRUE
);
1420 ACPI_DEBUGGER_EXEC(acpi_os_printf
1421 ("**break** Executed AML BreakPoint opcode\n"));
1423 /* Call to the OSL in case OS wants a piece of the action */
1425 status
= acpi_os_signal(ACPI_SIGNAL_BREAKPOINT
,
1426 "Executed AML Breakpoint opcode");
1430 case AML_CONTINUE_OP
: /* ACPI 2.0 */
1432 /* Pop and delete control states until we find a while */
1434 while (walk_state
->control_state
&&
1435 (walk_state
->control_state
->control
.opcode
!=
1438 acpi_ut_pop_generic_state(&walk_state
->
1440 acpi_ut_delete_generic_state(control_state
);
1443 /* No while found? */
1445 if (!walk_state
->control_state
) {
1446 return (AE_AML_NO_WHILE
);
1449 /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
1451 walk_state
->aml_last_while
=
1452 walk_state
->control_state
->control
.package_end
;
1454 /* Return status depending on opcode */
1456 if (op
->common
.aml_opcode
== AML_BREAK_OP
) {
1457 status
= AE_CTRL_BREAK
;
1459 status
= AE_CTRL_CONTINUE
;
1465 ACPI_ERROR((AE_INFO
, "Unknown control opcode=0x%X Op=%p",
1466 op
->common
.aml_opcode
, op
));
1468 status
= AE_AML_BAD_OPCODE
;