2 /******************************************************************************
4 * Module Name: exstore - AML Interpreter object store support
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, 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.
46 #include <acpi/acpi.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/amlcode.h>
50 #include <acpi/acnamesp.h>
51 #include <acpi/acparser.h>
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exstore")
57 /* Local prototypes */
60 acpi_ex_do_debug_object (
61 union acpi_operand_object
*source_desc
,
66 acpi_ex_store_object_to_index (
67 union acpi_operand_object
*val_desc
,
68 union acpi_operand_object
*dest_desc
,
69 struct acpi_walk_state
*walk_state
);
72 /*******************************************************************************
74 * FUNCTION: acpi_ex_do_debug_object
76 * PARAMETERS: source_desc - Value to be stored
77 * Level - Indentation level (used for packages)
78 * Index - Current package element, zero if not pkg
82 * DESCRIPTION: Handles stores to the Debug Object.
84 ******************************************************************************/
87 acpi_ex_do_debug_object (
88 union acpi_operand_object
*source_desc
,
95 ACPI_FUNCTION_TRACE_PTR ("ex_do_debug_object", source_desc
);
98 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[ACPI Debug] %*s",
101 /* Display index for package output only */
104 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
,
105 "(%.2u) ", index
-1));
109 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "<Null Object>\n"));
113 if (ACPI_GET_DESCRIPTOR_TYPE (source_desc
) == ACPI_DESC_TYPE_OPERAND
) {
114 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "%s: ",
115 acpi_ut_get_object_type_name (source_desc
)));
117 if (!acpi_ut_valid_internal_object (source_desc
)) {
118 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
,
119 "%p, Invalid Internal Object!\n", source_desc
));
123 else if (ACPI_GET_DESCRIPTOR_TYPE (source_desc
) == ACPI_DESC_TYPE_NAMED
) {
124 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "%s: %p\n",
125 acpi_ut_get_type_name (((struct acpi_namespace_node
*) source_desc
)->type
),
133 switch (ACPI_GET_OBJECT_TYPE (source_desc
)) {
134 case ACPI_TYPE_INTEGER
:
136 /* Output correct integer width */
138 if (acpi_gbl_integer_byte_width
== 4) {
139 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X\n",
140 (u32
) source_desc
->integer
.value
));
143 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X%8.8X\n",
144 ACPI_FORMAT_UINT64 (source_desc
->integer
.value
)));
148 case ACPI_TYPE_BUFFER
:
150 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X]",
151 (u32
) source_desc
->buffer
.length
));
152 ACPI_DUMP_BUFFER (source_desc
->buffer
.pointer
,
153 (source_desc
->buffer
.length
< 32) ? source_desc
->buffer
.length
: 32);
156 case ACPI_TYPE_STRING
:
158 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X] \"%s\"\n",
159 source_desc
->string
.length
, source_desc
->string
.pointer
));
162 case ACPI_TYPE_PACKAGE
:
164 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X Elements]\n",
165 source_desc
->package
.count
));
167 /* Output the entire contents of the package */
169 for (i
= 0; i
< source_desc
->package
.count
; i
++) {
170 acpi_ex_do_debug_object (source_desc
->package
.elements
[i
],
175 case ACPI_TYPE_LOCAL_REFERENCE
:
177 if (source_desc
->reference
.opcode
== AML_INDEX_OP
) {
178 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[%s, 0x%X]\n",
179 acpi_ps_get_opcode_name (source_desc
->reference
.opcode
),
180 source_desc
->reference
.offset
));
183 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[%s]\n",
184 acpi_ps_get_opcode_name (source_desc
->reference
.opcode
)));
188 if (source_desc
->reference
.object
) {
189 if (ACPI_GET_DESCRIPTOR_TYPE (source_desc
->reference
.object
) ==
190 ACPI_DESC_TYPE_NAMED
) {
191 acpi_ex_do_debug_object (((struct acpi_namespace_node
*)
192 source_desc
->reference
.object
)->object
,
196 acpi_ex_do_debug_object (source_desc
->reference
.object
, level
+4, 0);
199 else if (source_desc
->reference
.node
) {
200 acpi_ex_do_debug_object ((source_desc
->reference
.node
)->object
,
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "%p %s\n",
208 source_desc
, acpi_ut_get_object_type_name (source_desc
)));
212 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC
, "\n"));
217 /*******************************************************************************
219 * FUNCTION: acpi_ex_store
221 * PARAMETERS: *source_desc - Value to be stored
222 * *dest_desc - Where to store it. Must be an NS node
223 * or an union acpi_operand_object of type
225 * walk_state - Current walk state
229 * DESCRIPTION: Store the value described by source_desc into the location
230 * described by dest_desc. Called by various interpreter
231 * functions to store the result of an operation into
232 * the destination operand -- not just simply the actual "Store"
235 ******************************************************************************/
239 union acpi_operand_object
*source_desc
,
240 union acpi_operand_object
*dest_desc
,
241 struct acpi_walk_state
*walk_state
)
243 acpi_status status
= AE_OK
;
244 union acpi_operand_object
*ref_desc
= dest_desc
;
247 ACPI_FUNCTION_TRACE_PTR ("ex_store", dest_desc
);
250 /* Validate parameters */
252 if (!source_desc
|| !dest_desc
) {
253 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Null parameter\n"));
254 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
257 /* dest_desc can be either a namespace node or an ACPI object */
259 if (ACPI_GET_DESCRIPTOR_TYPE (dest_desc
) == ACPI_DESC_TYPE_NAMED
) {
261 * Dest is a namespace node,
262 * Storing an object into a Named node.
264 status
= acpi_ex_store_object_to_node (source_desc
,
265 (struct acpi_namespace_node
*) dest_desc
, walk_state
,
266 ACPI_IMPLICIT_CONVERSION
);
268 return_ACPI_STATUS (status
);
271 /* Destination object must be a Reference or a Constant object */
273 switch (ACPI_GET_OBJECT_TYPE (dest_desc
)) {
274 case ACPI_TYPE_LOCAL_REFERENCE
:
277 case ACPI_TYPE_INTEGER
:
279 /* Allow stores to Constants -- a Noop as per ACPI spec */
281 if (dest_desc
->common
.flags
& AOPOBJ_AML_CONSTANT
) {
282 return_ACPI_STATUS (AE_OK
);
285 /*lint -fallthrough */
289 /* Destination is not a Reference object */
291 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
292 "Target is not a Reference or Constant object - %s [%p]\n",
293 acpi_ut_get_object_type_name (dest_desc
), dest_desc
));
295 ACPI_DUMP_STACK_ENTRY (source_desc
);
296 ACPI_DUMP_STACK_ENTRY (dest_desc
);
297 ACPI_DUMP_OPERANDS (&dest_desc
, ACPI_IMODE_EXECUTE
, "ex_store",
298 2, "Target is not a Reference or Constant object");
300 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
304 * Examine the Reference opcode. These cases are handled:
306 * 1) Store to Name (Change the object associated with a name)
307 * 2) Store to an indexed area of a Buffer or Package
308 * 3) Store to a Method Local or Arg
309 * 4) Store to the debug object
311 switch (ref_desc
->reference
.opcode
) {
315 /* Storing an object into a Name "container" */
317 status
= acpi_ex_store_object_to_node (source_desc
,
318 ref_desc
->reference
.object
,
319 walk_state
, ACPI_IMPLICIT_CONVERSION
);
325 /* Storing to an Index (pointer into a packager or buffer) */
327 status
= acpi_ex_store_object_to_index (source_desc
, ref_desc
, walk_state
);
334 /* Store to a method local/arg */
336 status
= acpi_ds_store_object_to_local (ref_desc
->reference
.opcode
,
337 ref_desc
->reference
.offset
, source_desc
, walk_state
);
344 * Storing to the Debug object causes the value stored to be
345 * displayed and otherwise has no effect -- see ACPI Specification
347 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
348 "**** Write to Debug Object: Object %p %s ****:\n\n",
349 source_desc
, acpi_ut_get_object_type_name (source_desc
)));
351 acpi_ex_do_debug_object (source_desc
, 0, 0);
357 ACPI_REPORT_ERROR (("ex_store: Unknown Reference opcode %X\n",
358 ref_desc
->reference
.opcode
));
359 ACPI_DUMP_ENTRY (ref_desc
, ACPI_LV_ERROR
);
361 status
= AE_AML_INTERNAL
;
365 return_ACPI_STATUS (status
);
369 /*******************************************************************************
371 * FUNCTION: acpi_ex_store_object_to_index
373 * PARAMETERS: *source_desc - Value to be stored
374 * *dest_desc - Named object to receive the value
375 * walk_state - Current walk state
379 * DESCRIPTION: Store the object to indexed Buffer or Package element
381 ******************************************************************************/
384 acpi_ex_store_object_to_index (
385 union acpi_operand_object
*source_desc
,
386 union acpi_operand_object
*index_desc
,
387 struct acpi_walk_state
*walk_state
)
389 acpi_status status
= AE_OK
;
390 union acpi_operand_object
*obj_desc
;
391 union acpi_operand_object
*new_desc
;
396 ACPI_FUNCTION_TRACE ("ex_store_object_to_index");
400 * Destination must be a reference pointer, and
401 * must point to either a buffer or a package
403 switch (index_desc
->reference
.target_type
) {
404 case ACPI_TYPE_PACKAGE
:
406 * Storing to a package element. Copy the object and replace
407 * any existing object with the new object. No implicit
408 * conversion is performed.
410 * The object at *(index_desc->Reference.Where) is the
411 * element within the package that is to be modified.
412 * The parent package object is at index_desc->Reference.Object
414 obj_desc
= *(index_desc
->reference
.where
);
416 status
= acpi_ut_copy_iobject_to_iobject (source_desc
, &new_desc
, walk_state
);
417 if (ACPI_FAILURE (status
)) {
418 return_ACPI_STATUS (status
);
422 /* Decrement reference count by the ref count of the parent package */
425 i
< ((union acpi_operand_object
*)
426 index_desc
->reference
.object
)->common
.reference_count
;
428 acpi_ut_remove_reference (obj_desc
);
432 *(index_desc
->reference
.where
) = new_desc
;
434 /* Increment ref count by the ref count of the parent package-1 */
437 i
< ((union acpi_operand_object
*)
438 index_desc
->reference
.object
)->common
.reference_count
;
440 acpi_ut_add_reference (new_desc
);
446 case ACPI_TYPE_BUFFER_FIELD
:
449 * Store into a Buffer or String (not actually a real buffer_field)
450 * at a location defined by an Index.
452 * The first 8-bit element of the source object is written to the
453 * 8-bit Buffer location defined by the Index destination object,
454 * according to the ACPI 2.0 specification.
458 * Make sure the target is a Buffer or String. An error should
459 * not happen here, since the reference_object was constructed
460 * by the INDEX_OP code.
462 obj_desc
= index_desc
->reference
.object
;
463 if ((ACPI_GET_OBJECT_TYPE (obj_desc
) != ACPI_TYPE_BUFFER
) &&
464 (ACPI_GET_OBJECT_TYPE (obj_desc
) != ACPI_TYPE_STRING
)) {
465 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
469 * The assignment of the individual elements will be slightly
470 * different for each source type.
472 switch (ACPI_GET_OBJECT_TYPE (source_desc
)) {
473 case ACPI_TYPE_INTEGER
:
475 /* Use the least-significant byte of the integer */
477 value
= (u8
) (source_desc
->integer
.value
);
480 case ACPI_TYPE_BUFFER
:
481 case ACPI_TYPE_STRING
:
483 /* Note: Takes advantage of common string/buffer fields */
485 value
= source_desc
->buffer
.pointer
[0];
490 /* All other types are invalid */
492 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
493 "Source must be Integer/Buffer/String type, not %s\n",
494 acpi_ut_get_object_type_name (source_desc
)));
495 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
498 /* Store the source value into the target buffer byte */
500 obj_desc
->buffer
.pointer
[index_desc
->reference
.offset
] = value
;
505 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
506 "Target is not a Package or buffer_field\n"));
507 status
= AE_AML_OPERAND_TYPE
;
511 return_ACPI_STATUS (status
);
515 /*******************************************************************************
517 * FUNCTION: acpi_ex_store_object_to_node
519 * PARAMETERS: source_desc - Value to be stored
520 * Node - Named object to receive the value
521 * walk_state - Current walk state
522 * implicit_conversion - Perform implicit conversion (yes/no)
526 * DESCRIPTION: Store the object to the named object.
528 * The Assignment of an object to a named object is handled here
529 * The value passed in will replace the current value (if any)
530 * with the input value.
532 * When storing into an object the data is converted to the
533 * target object type then stored in the object. This means
534 * that the target object type (for an initialized target) will
535 * not be changed by a store operation.
537 * Assumes parameters are already validated.
539 ******************************************************************************/
542 acpi_ex_store_object_to_node (
543 union acpi_operand_object
*source_desc
,
544 struct acpi_namespace_node
*node
,
545 struct acpi_walk_state
*walk_state
,
546 u8 implicit_conversion
)
548 acpi_status status
= AE_OK
;
549 union acpi_operand_object
*target_desc
;
550 union acpi_operand_object
*new_desc
;
551 acpi_object_type target_type
;
554 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc
);
557 /* Get current type of the node, and object attached to Node */
559 target_type
= acpi_ns_get_type (node
);
560 target_desc
= acpi_ns_get_attached_object (node
);
562 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Storing %p(%s) into node %p(%s)\n",
563 source_desc
, acpi_ut_get_object_type_name (source_desc
),
564 node
, acpi_ut_get_type_name (target_type
)));
567 * Resolve the source object to an actual value
568 * (If it is a reference object)
570 status
= acpi_ex_resolve_object (&source_desc
, target_type
, walk_state
);
571 if (ACPI_FAILURE (status
)) {
572 return_ACPI_STATUS (status
);
575 /* If no implicit conversion, drop into the default case below */
577 if ((!implicit_conversion
) || (walk_state
->opcode
== AML_COPY_OP
)) {
578 /* Force execution of default (no implicit conversion) */
580 target_type
= ACPI_TYPE_ANY
;
583 /* Do the actual store operation */
585 switch (target_type
) {
586 case ACPI_TYPE_BUFFER_FIELD
:
587 case ACPI_TYPE_LOCAL_REGION_FIELD
:
588 case ACPI_TYPE_LOCAL_BANK_FIELD
:
589 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
591 /* For fields, copy the source data to the target field. */
593 status
= acpi_ex_write_data_to_field (source_desc
, target_desc
,
594 &walk_state
->result_obj
);
598 case ACPI_TYPE_INTEGER
:
599 case ACPI_TYPE_STRING
:
600 case ACPI_TYPE_BUFFER
:
603 * These target types are all of type Integer/String/Buffer, and
604 * therefore support implicit conversion before the store.
606 * Copy and/or convert the source object to a new target object
608 status
= acpi_ex_store_object_to_object (source_desc
, target_desc
,
609 &new_desc
, walk_state
);
610 if (ACPI_FAILURE (status
)) {
611 return_ACPI_STATUS (status
);
614 if (new_desc
!= target_desc
) {
616 * Store the new new_desc as the new value of the Name, and set
617 * the Name's type to that of the value being stored in it.
618 * source_desc reference count is incremented by attach_object.
620 * Note: This may change the type of the node if an explicit store
621 * has been performed such that the node/object type has been
624 status
= acpi_ns_attach_object (node
, new_desc
, new_desc
->common
.type
);
626 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
627 "Store %s into %s via Convert/Attach\n",
628 acpi_ut_get_object_type_name (source_desc
),
629 acpi_ut_get_object_type_name (new_desc
)));
636 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
637 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
638 acpi_ut_get_object_type_name (source_desc
), source_desc
, node
));
640 /* No conversions for all other types. Just attach the source object */
642 status
= acpi_ns_attach_object (node
, source_desc
,
643 ACPI_GET_OBJECT_TYPE (source_desc
));
647 return_ACPI_STATUS (status
);