2 /******************************************************************************
4 * Module Name: exstore - AML Interpreter object store support
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>
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 /* Print line header as long as we are not in the middle of an object display */
89 if (!((level
> 0) && index
== 0)) {
90 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[ACPI Debug] %*s",
94 /* Display index for package output only */
97 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
98 "(%.2u) ", index
- 1));
102 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[Null Object]\n"));
106 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc
) == ACPI_DESC_TYPE_OPERAND
) {
107 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "%s ",
108 acpi_ut_get_object_type_name
111 if (!acpi_ut_valid_internal_object(source_desc
)) {
112 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
113 "%p, Invalid Internal Object!\n",
117 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc
) ==
118 ACPI_DESC_TYPE_NAMED
) {
119 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "%s: %p\n",
120 acpi_ut_get_type_name(((struct
130 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
132 switch (ACPI_GET_OBJECT_TYPE(source_desc
)) {
133 case ACPI_TYPE_INTEGER
:
135 /* Output correct integer width */
137 if (acpi_gbl_integer_byte_width
== 4) {
138 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X\n",
139 (u32
) source_desc
->integer
.
142 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
144 ACPI_FORMAT_UINT64(source_desc
->
150 case ACPI_TYPE_BUFFER
:
152 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X]\n",
153 (u32
) source_desc
->buffer
.length
));
154 ACPI_DUMP_BUFFER(source_desc
->buffer
.pointer
,
155 (source_desc
->buffer
.length
<
156 256) ? source_desc
->buffer
.length
: 256);
159 case ACPI_TYPE_STRING
:
161 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X] \"%s\"\n",
162 source_desc
->string
.length
,
163 source_desc
->string
.pointer
));
166 case ACPI_TYPE_PACKAGE
:
168 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
169 "[Contains 0x%.2X Elements]\n",
170 source_desc
->package
.count
));
172 /* Output the entire contents of the package */
174 for (i
= 0; i
< source_desc
->package
.count
; i
++) {
175 acpi_ex_do_debug_object(source_desc
->package
.
176 elements
[i
], level
+ 4, i
+ 1);
180 case ACPI_TYPE_LOCAL_REFERENCE
:
182 if (source_desc
->reference
.opcode
== AML_INDEX_OP
) {
183 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
185 acpi_ps_get_opcode_name
186 (source_desc
->reference
.opcode
),
187 source_desc
->reference
.offset
));
189 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "[%s]",
190 acpi_ps_get_opcode_name
191 (source_desc
->reference
.opcode
)));
194 if (source_desc
->reference
.opcode
== AML_LOAD_OP
) { /* Load and load_table */
195 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
196 " Table OwnerId %p\n",
197 source_desc
->reference
.object
));
201 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, " "));
203 /* Check for valid node first, then valid object */
205 if (source_desc
->reference
.node
) {
206 if (ACPI_GET_DESCRIPTOR_TYPE
207 (source_desc
->reference
.node
) !=
208 ACPI_DESC_TYPE_NAMED
) {
209 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
210 " %p - Not a valid namespace node\n",
211 source_desc
->reference
.
214 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
,
216 source_desc
->reference
.
218 (source_desc
->reference
.
221 switch ((source_desc
->reference
.node
)->type
) {
223 /* These types have no attached object */
225 case ACPI_TYPE_DEVICE
:
226 acpi_os_printf("Device\n");
229 case ACPI_TYPE_THERMAL
:
230 acpi_os_printf("Thermal Zone\n");
234 acpi_ex_do_debug_object((source_desc
->
241 } else if (source_desc
->reference
.object
) {
242 if (ACPI_GET_DESCRIPTOR_TYPE
243 (source_desc
->reference
.object
) ==
244 ACPI_DESC_TYPE_NAMED
) {
245 acpi_ex_do_debug_object(((struct
246 acpi_namespace_node
*)
247 source_desc
->reference
.
251 acpi_ex_do_debug_object(source_desc
->reference
.
252 object
, level
+ 4, 0);
259 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT
, "%p\n",
264 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC
, "\n"));
268 /*******************************************************************************
270 * FUNCTION: acpi_ex_store
272 * PARAMETERS: *source_desc - Value to be stored
273 * *dest_desc - Where to store it. Must be an NS node
274 * or an union acpi_operand_object of type
276 * walk_state - Current walk state
280 * DESCRIPTION: Store the value described by source_desc into the location
281 * described by dest_desc. Called by various interpreter
282 * functions to store the result of an operation into
283 * the destination operand -- not just simply the actual "Store"
286 ******************************************************************************/
289 acpi_ex_store(union acpi_operand_object
*source_desc
,
290 union acpi_operand_object
*dest_desc
,
291 struct acpi_walk_state
*walk_state
)
293 acpi_status status
= AE_OK
;
294 union acpi_operand_object
*ref_desc
= dest_desc
;
296 ACPI_FUNCTION_TRACE_PTR(ex_store
, dest_desc
);
298 /* Validate parameters */
300 if (!source_desc
|| !dest_desc
) {
301 ACPI_ERROR((AE_INFO
, "Null parameter"));
302 return_ACPI_STATUS(AE_AML_NO_OPERAND
);
305 /* dest_desc can be either a namespace node or an ACPI object */
307 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc
) == ACPI_DESC_TYPE_NAMED
) {
309 * Dest is a namespace node,
310 * Storing an object into a Named node.
312 status
= acpi_ex_store_object_to_node(source_desc
,
314 acpi_namespace_node
*)
315 dest_desc
, walk_state
,
316 ACPI_IMPLICIT_CONVERSION
);
318 return_ACPI_STATUS(status
);
321 /* Destination object must be a Reference or a Constant object */
323 switch (ACPI_GET_OBJECT_TYPE(dest_desc
)) {
324 case ACPI_TYPE_LOCAL_REFERENCE
:
327 case ACPI_TYPE_INTEGER
:
329 /* Allow stores to Constants -- a Noop as per ACPI spec */
331 if (dest_desc
->common
.flags
& AOPOBJ_AML_CONSTANT
) {
332 return_ACPI_STATUS(AE_OK
);
335 /*lint -fallthrough */
339 /* Destination is not a Reference object */
342 "Target is not a Reference or Constant object - %s [%p]",
343 acpi_ut_get_object_type_name(dest_desc
),
346 ACPI_DUMP_STACK_ENTRY(source_desc
);
347 ACPI_DUMP_STACK_ENTRY(dest_desc
);
348 ACPI_DUMP_OPERANDS(&dest_desc
, ACPI_IMODE_EXECUTE
, "ExStore",
350 "Target is not a Reference or Constant object");
352 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
356 * Examine the Reference opcode. These cases are handled:
358 * 1) Store to Name (Change the object associated with a name)
359 * 2) Store to an indexed area of a Buffer or Package
360 * 3) Store to a Method Local or Arg
361 * 4) Store to the debug object
363 switch (ref_desc
->reference
.opcode
) {
366 /* Storing an object into a Name "container" */
368 status
= acpi_ex_store_object_to_node(source_desc
,
371 ACPI_IMPLICIT_CONVERSION
);
376 /* Storing to an Index (pointer into a packager or buffer) */
379 acpi_ex_store_object_to_index(source_desc
, ref_desc
,
386 /* Store to a method local/arg */
389 acpi_ds_store_object_to_local(ref_desc
->reference
.opcode
,
390 ref_desc
->reference
.offset
,
391 source_desc
, walk_state
);
397 * Storing to the Debug object causes the value stored to be
398 * displayed and otherwise has no effect -- see ACPI Specification
400 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
401 "**** Write to Debug Object: Object %p %s ****:\n\n",
403 acpi_ut_get_object_type_name(source_desc
)));
405 acpi_ex_do_debug_object(source_desc
, 0, 0);
410 ACPI_ERROR((AE_INFO
, "Unknown Reference opcode %X",
411 ref_desc
->reference
.opcode
));
412 ACPI_DUMP_ENTRY(ref_desc
, ACPI_LV_ERROR
);
414 status
= AE_AML_INTERNAL
;
418 return_ACPI_STATUS(status
);
421 /*******************************************************************************
423 * FUNCTION: acpi_ex_store_object_to_index
425 * PARAMETERS: *source_desc - Value to be stored
426 * *dest_desc - Named object to receive the value
427 * walk_state - Current walk state
431 * DESCRIPTION: Store the object to indexed Buffer or Package element
433 ******************************************************************************/
436 acpi_ex_store_object_to_index(union acpi_operand_object
*source_desc
,
437 union acpi_operand_object
*index_desc
,
438 struct acpi_walk_state
*walk_state
)
440 acpi_status status
= AE_OK
;
441 union acpi_operand_object
*obj_desc
;
442 union acpi_operand_object
*new_desc
;
446 ACPI_FUNCTION_TRACE(ex_store_object_to_index
);
449 * Destination must be a reference pointer, and
450 * must point to either a buffer or a package
452 switch (index_desc
->reference
.target_type
) {
453 case ACPI_TYPE_PACKAGE
:
455 * Storing to a package element. Copy the object and replace
456 * any existing object with the new object. No implicit
457 * conversion is performed.
459 * The object at *(index_desc->Reference.Where) is the
460 * element within the package that is to be modified.
461 * The parent package object is at index_desc->Reference.Object
463 obj_desc
= *(index_desc
->reference
.where
);
465 if (ACPI_GET_OBJECT_TYPE(source_desc
) ==
466 ACPI_TYPE_LOCAL_REFERENCE
467 && source_desc
->reference
.opcode
== AML_LOAD_OP
) {
469 /* This is a DDBHandle, just add a reference to it */
471 acpi_ut_add_reference(source_desc
);
472 new_desc
= source_desc
;
474 /* Normal object, copy it */
477 acpi_ut_copy_iobject_to_iobject(source_desc
,
480 if (ACPI_FAILURE(status
)) {
481 return_ACPI_STATUS(status
);
487 /* Decrement reference count by the ref count of the parent package */
489 for (i
= 0; i
< ((union acpi_operand_object
*)
490 index_desc
->reference
.object
)->common
.
491 reference_count
; i
++) {
492 acpi_ut_remove_reference(obj_desc
);
496 *(index_desc
->reference
.where
) = new_desc
;
498 /* Increment ref count by the ref count of the parent package-1 */
500 for (i
= 1; i
< ((union acpi_operand_object
*)
501 index_desc
->reference
.object
)->common
.
502 reference_count
; i
++) {
503 acpi_ut_add_reference(new_desc
);
508 case ACPI_TYPE_BUFFER_FIELD
:
511 * Store into a Buffer or String (not actually a real buffer_field)
512 * at a location defined by an Index.
514 * The first 8-bit element of the source object is written to the
515 * 8-bit Buffer location defined by the Index destination object,
516 * according to the ACPI 2.0 specification.
520 * Make sure the target is a Buffer or String. An error should
521 * not happen here, since the reference_object was constructed
522 * by the INDEX_OP code.
524 obj_desc
= index_desc
->reference
.object
;
525 if ((ACPI_GET_OBJECT_TYPE(obj_desc
) != ACPI_TYPE_BUFFER
) &&
526 (ACPI_GET_OBJECT_TYPE(obj_desc
) != ACPI_TYPE_STRING
)) {
527 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
531 * The assignment of the individual elements will be slightly
532 * different for each source type.
534 switch (ACPI_GET_OBJECT_TYPE(source_desc
)) {
535 case ACPI_TYPE_INTEGER
:
537 /* Use the least-significant byte of the integer */
539 value
= (u8
) (source_desc
->integer
.value
);
542 case ACPI_TYPE_BUFFER
:
543 case ACPI_TYPE_STRING
:
545 /* Note: Takes advantage of common string/buffer fields */
547 value
= source_desc
->buffer
.pointer
[0];
552 /* All other types are invalid */
555 "Source must be Integer/Buffer/String type, not %s",
556 acpi_ut_get_object_type_name(source_desc
)));
557 return_ACPI_STATUS(AE_AML_OPERAND_TYPE
);
560 /* Store the source value into the target buffer byte */
562 obj_desc
->buffer
.pointer
[index_desc
->reference
.offset
] = value
;
566 ACPI_ERROR((AE_INFO
, "Target is not a Package or BufferField"));
567 status
= AE_AML_OPERAND_TYPE
;
571 return_ACPI_STATUS(status
);
574 /*******************************************************************************
576 * FUNCTION: acpi_ex_store_object_to_node
578 * PARAMETERS: source_desc - Value to be stored
579 * Node - Named object to receive the value
580 * walk_state - Current walk state
581 * implicit_conversion - Perform implicit conversion (yes/no)
585 * DESCRIPTION: Store the object to the named object.
587 * The Assignment of an object to a named object is handled here
588 * The value passed in will replace the current value (if any)
589 * with the input value.
591 * When storing into an object the data is converted to the
592 * target object type then stored in the object. This means
593 * that the target object type (for an initialized target) will
594 * not be changed by a store operation.
596 * Assumes parameters are already validated.
598 ******************************************************************************/
601 acpi_ex_store_object_to_node(union acpi_operand_object
*source_desc
,
602 struct acpi_namespace_node
*node
,
603 struct acpi_walk_state
*walk_state
,
604 u8 implicit_conversion
)
606 acpi_status status
= AE_OK
;
607 union acpi_operand_object
*target_desc
;
608 union acpi_operand_object
*new_desc
;
609 acpi_object_type target_type
;
611 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node
, source_desc
);
613 /* Get current type of the node, and object attached to Node */
615 target_type
= acpi_ns_get_type(node
);
616 target_desc
= acpi_ns_get_attached_object(node
);
618 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Storing %p(%s) into node %p(%s)\n",
620 acpi_ut_get_object_type_name(source_desc
), node
,
621 acpi_ut_get_type_name(target_type
)));
624 * Resolve the source object to an actual value
625 * (If it is a reference object)
627 status
= acpi_ex_resolve_object(&source_desc
, target_type
, walk_state
);
628 if (ACPI_FAILURE(status
)) {
629 return_ACPI_STATUS(status
);
632 /* If no implicit conversion, drop into the default case below */
634 if ((!implicit_conversion
) ||
635 ((walk_state
->opcode
== AML_COPY_OP
) &&
636 (target_type
!= ACPI_TYPE_LOCAL_REGION_FIELD
) &&
637 (target_type
!= ACPI_TYPE_LOCAL_BANK_FIELD
) &&
638 (target_type
!= ACPI_TYPE_LOCAL_INDEX_FIELD
))) {
640 * Force execution of default (no implicit conversion). Note:
641 * copy_object does not perform an implicit conversion, as per the ACPI
642 * spec -- except in case of region/bank/index fields -- because these
643 * objects must retain their original type permanently.
645 target_type
= ACPI_TYPE_ANY
;
648 /* Do the actual store operation */
650 switch (target_type
) {
651 case ACPI_TYPE_BUFFER_FIELD
:
652 case ACPI_TYPE_LOCAL_REGION_FIELD
:
653 case ACPI_TYPE_LOCAL_BANK_FIELD
:
654 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
656 /* For fields, copy the source data to the target field. */
658 status
= acpi_ex_write_data_to_field(source_desc
, target_desc
,
659 &walk_state
->result_obj
);
662 case ACPI_TYPE_INTEGER
:
663 case ACPI_TYPE_STRING
:
664 case ACPI_TYPE_BUFFER
:
667 * These target types are all of type Integer/String/Buffer, and
668 * therefore support implicit conversion before the store.
670 * Copy and/or convert the source object to a new target object
673 acpi_ex_store_object_to_object(source_desc
, target_desc
,
674 &new_desc
, walk_state
);
675 if (ACPI_FAILURE(status
)) {
676 return_ACPI_STATUS(status
);
679 if (new_desc
!= target_desc
) {
681 * Store the new new_desc as the new value of the Name, and set
682 * the Name's type to that of the value being stored in it.
683 * source_desc reference count is incremented by attach_object.
685 * Note: This may change the type of the node if an explicit store
686 * has been performed such that the node/object type has been
690 acpi_ns_attach_object(node
, new_desc
,
691 new_desc
->common
.type
);
693 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
694 "Store %s into %s via Convert/Attach\n",
695 acpi_ut_get_object_type_name
697 acpi_ut_get_object_type_name
704 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
705 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
706 acpi_ut_get_object_type_name(source_desc
),
709 /* No conversions for all other types. Just attach the source object */
711 status
= acpi_ns_attach_object(node
, source_desc
,
717 return_ACPI_STATUS(status
);