2 /******************************************************************************
4 * Module Name: exstore - AML Interpreter object store support
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/acdispat.h>
47 #include <acpi/acinterp.h>
48 #include <acpi/amlcode.h>
49 #include <acpi/acnamesp.h>
50 #include <acpi/acparser.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME("exstore")
55 /* Local prototypes */
57 acpi_ex_do_debug_object(union acpi_operand_object
*source_desc
,
58 u32 level
, u32 index
);
61 acpi_ex_store_object_to_index(union acpi_operand_object
*val_desc
,
62 union acpi_operand_object
*dest_desc
,
63 struct acpi_walk_state
*walk_state
);
65 /*******************************************************************************
67 * FUNCTION: acpi_ex_do_debug_object
69 * PARAMETERS: source_desc - Value to be stored
70 * Level - Indentation level (used for packages)
71 * Index - Current package element, zero if not pkg
75 * DESCRIPTION: Handles stores to the Debug Object.
77 ******************************************************************************/
80 acpi_ex_do_debug_object(union acpi_operand_object
*source_desc
,
85 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object
, source_desc
);
87 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[ACPI Debug] %*s",
90 /* Display index for package output only */
93 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
94 "(%.2u) ", index
- 1));
98 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "<Null Object>\n"));
102 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc
) == ACPI_DESC_TYPE_OPERAND
) {
103 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "%s: ",
104 acpi_ut_get_object_type_name
107 if (!acpi_ut_valid_internal_object(source_desc
)) {
108 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
109 "%p, Invalid Internal Object!\n",
113 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc
) ==
114 ACPI_DESC_TYPE_NAMED
) {
115 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "%s: %p\n",
116 acpi_ut_get_type_name(((struct
126 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
128 switch (ACPI_GET_OBJECT_TYPE(source_desc
)) {
129 case ACPI_TYPE_INTEGER
:
131 /* Output correct integer width */
133 if (acpi_gbl_integer_byte_width
== 4) {
134 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X\n",
135 (u32
) source_desc
->integer
.
138 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
140 ACPI_FORMAT_UINT64(source_desc
->
146 case ACPI_TYPE_BUFFER
:
148 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X]\n",
149 (u32
) source_desc
->buffer
.length
));
150 ACPI_DUMP_BUFFER(source_desc
->buffer
.pointer
,
151 (source_desc
->buffer
.length
<
152 256) ? source_desc
->buffer
.length
: 256);
155 case ACPI_TYPE_STRING
:
157 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X] \"%s\"\n",
158 source_desc
->string
.length
,
159 source_desc
->string
.pointer
));
162 case ACPI_TYPE_PACKAGE
:
164 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
165 "[0x%.2X Elements]\n",
166 source_desc
->package
.count
));
168 /* Output the entire contents of the package */
170 for (i
= 0; i
< source_desc
->package
.count
; i
++) {
171 acpi_ex_do_debug_object(source_desc
->package
.
172 elements
[i
], level
+ 4, i
+ 1);
176 case ACPI_TYPE_LOCAL_REFERENCE
:
178 if (source_desc
->reference
.opcode
== AML_INDEX_OP
) {
179 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
181 acpi_ps_get_opcode_name
182 (source_desc
->reference
.opcode
),
183 source_desc
->reference
.offset
));
185 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[%s]",
186 acpi_ps_get_opcode_name
187 (source_desc
->reference
.opcode
)));
190 if (source_desc
->reference
.opcode
== AML_LOAD_OP
) { /* Load and load_table */
191 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
192 " Table OwnerId %p\n",
193 source_desc
->reference
.object
));
197 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "\n"));
198 if (source_desc
->reference
.object
) {
199 if (ACPI_GET_DESCRIPTOR_TYPE
200 (source_desc
->reference
.object
) ==
201 ACPI_DESC_TYPE_NAMED
) {
202 acpi_ex_do_debug_object(((struct
203 acpi_namespace_node
*)
204 source_desc
->reference
.
208 acpi_ex_do_debug_object(source_desc
->reference
.
209 object
, level
+ 4, 0);
211 } else if (source_desc
->reference
.node
) {
212 if (ACPI_GET_DESCRIPTOR_TYPE
213 (source_desc
->reference
.node
) !=
214 ACPI_DESC_TYPE_NAMED
) {
215 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
216 " %p - Not a valid namespace node\n",
217 source_desc
->reference
.
220 acpi_ex_do_debug_object((source_desc
->reference
.
229 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "%p %s\n",
231 acpi_ut_get_object_type_name
236 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
, "\n"));
240 /*******************************************************************************
242 * FUNCTION: acpi_ex_store
244 * PARAMETERS: *source_desc - Value to be stored
245 * *dest_desc - Where to store it. Must be an NS node
246 * or an union acpi_operand_object of type
248 * walk_state - Current walk state
252 * DESCRIPTION: Store the value described by source_desc into the location
253 * described by dest_desc. Called by various interpreter
254 * functions to store the result of an operation into
255 * the destination operand -- not just simply the actual "Store"
258 ******************************************************************************/
261 acpi_ex_store(union acpi_operand_object
*source_desc
,
262 union acpi_operand_object
*dest_desc
,
263 struct acpi_walk_state
*walk_state
)
265 acpi_status status
= AE_OK
;
266 union acpi_operand_object
*ref_desc
= dest_desc
;
268 ACPI_FUNCTION_TRACE_PTR(ex_store
, dest_desc
);
270 /* Validate parameters */
272 if (!source_desc
|| !dest_desc
) {
273 ACPI_ERROR((AE_INFO
, "Null parameter"));
274 return_ACPI_STATUS(AE_AML_NO_OPERAND
);
277 /* dest_desc can be either a namespace node or an ACPI object */
279 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc
) == ACPI_DESC_TYPE_NAMED
) {
281 * Dest is a namespace node,
282 * Storing an object into a Named node.
284 status
= acpi_ex_store_object_to_node(source_desc
,
286 acpi_namespace_node
*)
287 dest_desc
, walk_state
,
288 ACPI_IMPLICIT_CONVERSION
);
290 return_ACPI_STATUS(status
);
293 /* Destination object must be a Reference or a Constant object */
295 switch (ACPI_GET_OBJECT_TYPE(dest_desc
)) {
296 case ACPI_TYPE_LOCAL_REFERENCE
:
299 case ACPI_TYPE_INTEGER
:
301 /* Allow stores to Constants -- a Noop as per ACPI spec */
303 if (dest_desc
->common
.flags
& AOPOBJ_AML_CONSTANT
) {
304 return_ACPI_STATUS(AE_OK
);
307 /*lint -fallthrough */
311 /* Destination is not a Reference object */
314 "Target is not a Reference or Constant object - %s [%p]",
315 acpi_ut_get_object_type_name(dest_desc
),
318 ACPI_DUMP_STACK_ENTRY(source_desc
);
319 ACPI_DUMP_STACK_ENTRY(dest_desc
);
320 ACPI_DUMP_OPERANDS(&dest_desc
, ACPI_IMODE_EXECUTE
, "ExStore",
322 "Target is not a Reference or Constant object");
324 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
328 * Examine the Reference opcode. These cases are handled:
330 * 1) Store to Name (Change the object associated with a name)
331 * 2) Store to an indexed area of a Buffer or Package
332 * 3) Store to a Method Local or Arg
333 * 4) Store to the debug object
335 switch (ref_desc
->reference
.opcode
) {
338 /* Storing an object into a Name "container" */
340 status
= acpi_ex_store_object_to_node(source_desc
,
343 ACPI_IMPLICIT_CONVERSION
);
348 /* Storing to an Index (pointer into a packager or buffer) */
351 acpi_ex_store_object_to_index(source_desc
, ref_desc
,
358 /* Store to a method local/arg */
361 acpi_ds_store_object_to_local(ref_desc
->reference
.opcode
,
362 ref_desc
->reference
.offset
,
363 source_desc
, walk_state
);
369 * Storing to the Debug object causes the value stored to be
370 * displayed and otherwise has no effect -- see ACPI Specification
372 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
373 "**** Write to Debug Object: Object %p %s ****:\n\n",
375 acpi_ut_get_object_type_name(source_desc
)));
377 acpi_ex_do_debug_object(source_desc
, 0, 0);
382 ACPI_ERROR((AE_INFO
, "Unknown Reference opcode %X",
383 ref_desc
->reference
.opcode
));
384 ACPI_DUMP_ENTRY(ref_desc
, ACPI_LV_ERROR
);
386 status
= AE_AML_INTERNAL
;
390 return_ACPI_STATUS(status
);
393 /*******************************************************************************
395 * FUNCTION: acpi_ex_store_object_to_index
397 * PARAMETERS: *source_desc - Value to be stored
398 * *dest_desc - Named object to receive the value
399 * walk_state - Current walk state
403 * DESCRIPTION: Store the object to indexed Buffer or Package element
405 ******************************************************************************/
408 acpi_ex_store_object_to_index(union acpi_operand_object
*source_desc
,
409 union acpi_operand_object
*index_desc
,
410 struct acpi_walk_state
*walk_state
)
412 acpi_status status
= AE_OK
;
413 union acpi_operand_object
*obj_desc
;
414 union acpi_operand_object
*new_desc
;
418 ACPI_FUNCTION_TRACE(ex_store_object_to_index
);
421 * Destination must be a reference pointer, and
422 * must point to either a buffer or a package
424 switch (index_desc
->reference
.target_type
) {
425 case ACPI_TYPE_PACKAGE
:
427 * Storing to a package element. Copy the object and replace
428 * any existing object with the new object. No implicit
429 * conversion is performed.
431 * The object at *(index_desc->Reference.Where) is the
432 * element within the package that is to be modified.
433 * The parent package object is at index_desc->Reference.Object
435 obj_desc
= *(index_desc
->reference
.where
);
437 if (ACPI_GET_OBJECT_TYPE(source_desc
) ==
438 ACPI_TYPE_LOCAL_REFERENCE
439 && source_desc
->reference
.opcode
== AML_LOAD_OP
) {
441 /* This is a DDBHandle, just add a reference to it */
443 acpi_ut_add_reference(source_desc
);
444 new_desc
= source_desc
;
446 /* Normal object, copy it */
449 acpi_ut_copy_iobject_to_iobject(source_desc
,
452 if (ACPI_FAILURE(status
)) {
453 return_ACPI_STATUS(status
);
459 /* Decrement reference count by the ref count of the parent package */
461 for (i
= 0; i
< ((union acpi_operand_object
*)
462 index_desc
->reference
.object
)->common
.
463 reference_count
; i
++) {
464 acpi_ut_remove_reference(obj_desc
);
468 *(index_desc
->reference
.where
) = new_desc
;
470 /* Increment ref count by the ref count of the parent package-1 */
472 for (i
= 1; i
< ((union acpi_operand_object
*)
473 index_desc
->reference
.object
)->common
.
474 reference_count
; i
++) {
475 acpi_ut_add_reference(new_desc
);
480 case ACPI_TYPE_BUFFER_FIELD
:
483 * Store into a Buffer or String (not actually a real buffer_field)
484 * at a location defined by an Index.
486 * The first 8-bit element of the source object is written to the
487 * 8-bit Buffer location defined by the Index destination object,
488 * according to the ACPI 2.0 specification.
492 * Make sure the target is a Buffer or String. An error should
493 * not happen here, since the reference_object was constructed
494 * by the INDEX_OP code.
496 obj_desc
= index_desc
->reference
.object
;
497 if ((ACPI_GET_OBJECT_TYPE(obj_desc
) != ACPI_TYPE_BUFFER
) &&
498 (ACPI_GET_OBJECT_TYPE(obj_desc
) != ACPI_TYPE_STRING
)) {
499 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
503 * The assignment of the individual elements will be slightly
504 * different for each source type.
506 switch (ACPI_GET_OBJECT_TYPE(source_desc
)) {
507 case ACPI_TYPE_INTEGER
:
509 /* Use the least-significant byte of the integer */
511 value
= (u8
) (source_desc
->integer
.value
);
514 case ACPI_TYPE_BUFFER
:
515 case ACPI_TYPE_STRING
:
517 /* Note: Takes advantage of common string/buffer fields */
519 value
= source_desc
->buffer
.pointer
[0];
524 /* All other types are invalid */
527 "Source must be Integer/Buffer/String type, not %s",
528 acpi_ut_get_object_type_name(source_desc
)));
529 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
532 /* Store the source value into the target buffer byte */
534 obj_desc
->buffer
.pointer
[index_desc
->reference
.offset
] = value
;
538 ACPI_ERROR((AE_INFO
, "Target is not a Package or BufferField"));
539 status
= AE_AML_OPERAND_TYPE
;
543 return_ACPI_STATUS(status
);
546 /*******************************************************************************
548 * FUNCTION: acpi_ex_store_object_to_node
550 * PARAMETERS: source_desc - Value to be stored
551 * Node - Named object to receive the value
552 * walk_state - Current walk state
553 * implicit_conversion - Perform implicit conversion (yes/no)
557 * DESCRIPTION: Store the object to the named object.
559 * The Assignment of an object to a named object is handled here
560 * The value passed in will replace the current value (if any)
561 * with the input value.
563 * When storing into an object the data is converted to the
564 * target object type then stored in the object. This means
565 * that the target object type (for an initialized target) will
566 * not be changed by a store operation.
568 * Assumes parameters are already validated.
570 ******************************************************************************/
573 acpi_ex_store_object_to_node(union acpi_operand_object
*source_desc
,
574 struct acpi_namespace_node
*node
,
575 struct acpi_walk_state
*walk_state
,
576 u8 implicit_conversion
)
578 acpi_status status
= AE_OK
;
579 union acpi_operand_object
*target_desc
;
580 union acpi_operand_object
*new_desc
;
581 acpi_object_type target_type
;
583 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node
, source_desc
);
585 /* Get current type of the node, and object attached to Node */
587 target_type
= acpi_ns_get_type(node
);
588 target_desc
= acpi_ns_get_attached_object(node
);
590 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Storing %p(%s) into node %p(%s)\n",
592 acpi_ut_get_object_type_name(source_desc
), node
,
593 acpi_ut_get_type_name(target_type
)));
596 * Resolve the source object to an actual value
597 * (If it is a reference object)
599 status
= acpi_ex_resolve_object(&source_desc
, target_type
, walk_state
);
600 if (ACPI_FAILURE(status
)) {
601 return_ACPI_STATUS(status
);
604 /* If no implicit conversion, drop into the default case below */
606 if ((!implicit_conversion
) || (walk_state
->opcode
== AML_COPY_OP
)) {
608 /* Force execution of default (no implicit conversion) */
610 target_type
= ACPI_TYPE_ANY
;
613 /* Do the actual store operation */
615 switch (target_type
) {
616 case ACPI_TYPE_BUFFER_FIELD
:
617 case ACPI_TYPE_LOCAL_REGION_FIELD
:
618 case ACPI_TYPE_LOCAL_BANK_FIELD
:
619 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
621 /* For fields, copy the source data to the target field. */
623 status
= acpi_ex_write_data_to_field(source_desc
, target_desc
,
624 &walk_state
->result_obj
);
627 case ACPI_TYPE_INTEGER
:
628 case ACPI_TYPE_STRING
:
629 case ACPI_TYPE_BUFFER
:
632 * These target types are all of type Integer/String/Buffer, and
633 * therefore support implicit conversion before the store.
635 * Copy and/or convert the source object to a new target object
638 acpi_ex_store_object_to_object(source_desc
, target_desc
,
639 &new_desc
, walk_state
);
640 if (ACPI_FAILURE(status
)) {
641 return_ACPI_STATUS(status
);
644 if (new_desc
!= target_desc
) {
646 * Store the new new_desc as the new value of the Name, and set
647 * the Name's type to that of the value being stored in it.
648 * source_desc reference count is incremented by attach_object.
650 * Note: This may change the type of the node if an explicit store
651 * has been performed such that the node/object type has been
655 acpi_ns_attach_object(node
, new_desc
,
656 new_desc
->common
.type
);
658 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
659 "Store %s into %s via Convert/Attach\n",
660 acpi_ut_get_object_type_name
662 acpi_ut_get_object_type_name
669 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
670 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
671 acpi_ut_get_object_type_name(source_desc
),
674 /* No conversions for all other types. Just attach the source object */
676 status
= acpi_ns_attach_object(node
, source_desc
,
682 return_ACPI_STATUS(status
);