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>
53 #define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exstore")
57 /*******************************************************************************
59 * FUNCTION: acpi_ex_store
61 * PARAMETERS: *source_desc - Value to be stored
62 * *dest_desc - Where to store it. Must be an NS node
63 * or an union acpi_operand_object of type
65 * walk_state - Current walk state
69 * DESCRIPTION: Store the value described by source_desc into the location
70 * described by dest_desc. Called by various interpreter
71 * functions to store the result of an operation into
72 * the destination operand -- not just simply the actual "Store"
75 ******************************************************************************/
79 union acpi_operand_object
*source_desc
,
80 union acpi_operand_object
*dest_desc
,
81 struct acpi_walk_state
*walk_state
)
83 acpi_status status
= AE_OK
;
84 union acpi_operand_object
*ref_desc
= dest_desc
;
87 ACPI_FUNCTION_TRACE_PTR ("ex_store", dest_desc
);
90 /* Validate parameters */
92 if (!source_desc
|| !dest_desc
) {
93 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Null parameter\n"));
94 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
97 /* dest_desc can be either a namespace node or an ACPI object */
99 if (ACPI_GET_DESCRIPTOR_TYPE (dest_desc
) == ACPI_DESC_TYPE_NAMED
) {
101 * Dest is a namespace node,
102 * Storing an object into a Named node.
104 status
= acpi_ex_store_object_to_node (source_desc
,
105 (struct acpi_namespace_node
*) dest_desc
, walk_state
,
106 ACPI_IMPLICIT_CONVERSION
);
108 return_ACPI_STATUS (status
);
111 /* Destination object must be a Reference or a Constant object */
113 switch (ACPI_GET_OBJECT_TYPE (dest_desc
)) {
114 case ACPI_TYPE_LOCAL_REFERENCE
:
117 case ACPI_TYPE_INTEGER
:
119 /* Allow stores to Constants -- a Noop as per ACPI spec */
121 if (dest_desc
->common
.flags
& AOPOBJ_AML_CONSTANT
) {
122 return_ACPI_STATUS (AE_OK
);
125 /*lint -fallthrough */
129 /* Destination is not a Reference object */
131 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
132 "Target is not a Reference or Constant object - %s [%p]\n",
133 acpi_ut_get_object_type_name (dest_desc
), dest_desc
));
135 ACPI_DUMP_STACK_ENTRY (source_desc
);
136 ACPI_DUMP_STACK_ENTRY (dest_desc
);
137 ACPI_DUMP_OPERANDS (&dest_desc
, ACPI_IMODE_EXECUTE
, "ex_store",
138 2, "Target is not a Reference or Constant object");
140 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
144 * Examine the Reference opcode. These cases are handled:
146 * 1) Store to Name (Change the object associated with a name)
147 * 2) Store to an indexed area of a Buffer or Package
148 * 3) Store to a Method Local or Arg
149 * 4) Store to the debug object
151 switch (ref_desc
->reference
.opcode
) {
155 /* Storing an object into a Name "container" */
157 status
= acpi_ex_store_object_to_node (source_desc
, ref_desc
->reference
.object
,
158 walk_state
, ACPI_IMPLICIT_CONVERSION
);
164 /* Storing to an Index (pointer into a packager or buffer) */
166 status
= acpi_ex_store_object_to_index (source_desc
, ref_desc
, walk_state
);
173 /* Store to a method local/arg */
175 status
= acpi_ds_store_object_to_local (ref_desc
->reference
.opcode
,
176 ref_desc
->reference
.offset
, source_desc
, walk_state
);
183 * Storing to the Debug object causes the value stored to be
184 * displayed and otherwise has no effect -- see ACPI Specification
186 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
187 "**** Write to Debug Object: Object %p %s ****:\n\n",
188 source_desc
, acpi_ut_get_object_type_name (source_desc
)));
190 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[ACPI Debug] %s: ",
191 acpi_ut_get_object_type_name (source_desc
)));
193 if (!acpi_ut_valid_internal_object (source_desc
)) {
194 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
,
195 "%p, Invalid Internal Object!\n", source_desc
));
199 switch (ACPI_GET_OBJECT_TYPE (source_desc
)) {
200 case ACPI_TYPE_INTEGER
:
202 if (acpi_gbl_integer_byte_width
== 4) {
203 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X\n",
204 (u32
) source_desc
->integer
.value
));
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X%8.8X\n",
208 ACPI_FORMAT_UINT64 (source_desc
->integer
.value
)));
213 case ACPI_TYPE_BUFFER
:
215 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X]",
216 (u32
) source_desc
->buffer
.length
));
217 ACPI_DUMP_BUFFER (source_desc
->buffer
.pointer
,
218 (source_desc
->buffer
.length
< 32) ? source_desc
->buffer
.length
: 32);
222 case ACPI_TYPE_STRING
:
224 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X] \"%s\"\n",
225 source_desc
->string
.length
, source_desc
->string
.pointer
));
229 case ACPI_TYPE_PACKAGE
:
231 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[0x%.2X] Elements Ptr - %p\n",
232 source_desc
->package
.count
, source_desc
->package
.elements
));
238 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "%p\n",
243 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC
, "\n"));
249 ACPI_REPORT_ERROR (("ex_store: Unknown Reference opcode %X\n",
250 ref_desc
->reference
.opcode
));
251 ACPI_DUMP_ENTRY (ref_desc
, ACPI_LV_ERROR
);
253 status
= AE_AML_INTERNAL
;
257 return_ACPI_STATUS (status
);
261 /*******************************************************************************
263 * FUNCTION: acpi_ex_store_object_to_index
265 * PARAMETERS: *source_desc - Value to be stored
266 * *dest_desc - Named object to receive the value
267 * walk_state - Current walk state
271 * DESCRIPTION: Store the object to indexed Buffer or Package element
273 ******************************************************************************/
276 acpi_ex_store_object_to_index (
277 union acpi_operand_object
*source_desc
,
278 union acpi_operand_object
*index_desc
,
279 struct acpi_walk_state
*walk_state
)
281 acpi_status status
= AE_OK
;
282 union acpi_operand_object
*obj_desc
;
283 union acpi_operand_object
*new_desc
;
288 ACPI_FUNCTION_TRACE ("ex_store_object_to_index");
292 * Destination must be a reference pointer, and
293 * must point to either a buffer or a package
295 switch (index_desc
->reference
.target_type
) {
296 case ACPI_TYPE_PACKAGE
:
298 * Storing to a package element. Copy the object and replace
299 * any existing object with the new object. No implicit
300 * conversion is performed.
302 * The object at *(index_desc->Reference.Where) is the
303 * element within the package that is to be modified.
304 * The parent package object is at index_desc->Reference.Object
306 obj_desc
= *(index_desc
->reference
.where
);
308 status
= acpi_ut_copy_iobject_to_iobject (source_desc
, &new_desc
, walk_state
);
309 if (ACPI_FAILURE (status
)) {
310 return_ACPI_STATUS (status
);
314 /* Decrement reference count by the ref count of the parent package */
316 for (i
= 0; i
< ((union acpi_operand_object
*) index_desc
->reference
.object
)->common
.reference_count
; i
++) {
317 acpi_ut_remove_reference (obj_desc
);
321 *(index_desc
->reference
.where
) = new_desc
;
323 /* Increment reference count by the ref count of the parent package -1 */
325 for (i
= 1; i
< ((union acpi_operand_object
*) index_desc
->reference
.object
)->common
.reference_count
; i
++) {
326 acpi_ut_add_reference (new_desc
);
332 case ACPI_TYPE_BUFFER_FIELD
:
335 * Store into a Buffer or String (not actually a real buffer_field)
336 * at a location defined by an Index.
338 * The first 8-bit element of the source object is written to the
339 * 8-bit Buffer location defined by the Index destination object,
340 * according to the ACPI 2.0 specification.
344 * Make sure the target is a Buffer or String. An error should
345 * not happen here, since the reference_object was constructed
346 * by the INDEX_OP code.
348 obj_desc
= index_desc
->reference
.object
;
349 if ((ACPI_GET_OBJECT_TYPE (obj_desc
) != ACPI_TYPE_BUFFER
) &&
350 (ACPI_GET_OBJECT_TYPE (obj_desc
) != ACPI_TYPE_STRING
)) {
351 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
355 * The assignment of the individual elements will be slightly
356 * different for each source type.
358 switch (ACPI_GET_OBJECT_TYPE (source_desc
)) {
359 case ACPI_TYPE_INTEGER
:
361 /* Use the least-significant byte of the integer */
363 value
= (u8
) (source_desc
->integer
.value
);
366 case ACPI_TYPE_BUFFER
:
367 case ACPI_TYPE_STRING
:
369 /* Note: Takes advantage of common string/buffer fields */
371 value
= source_desc
->buffer
.pointer
[0];
376 /* All other types are invalid */
378 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
379 "Source must be Integer/Buffer/String type, not %s\n",
380 acpi_ut_get_object_type_name (source_desc
)));
381 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
384 /* Store the source value into the target buffer byte */
386 obj_desc
->buffer
.pointer
[index_desc
->reference
.offset
] = value
;
391 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
392 "Target is not a Package or buffer_field\n"));
393 status
= AE_AML_OPERAND_TYPE
;
397 return_ACPI_STATUS (status
);
401 /*******************************************************************************
403 * FUNCTION: acpi_ex_store_object_to_node
405 * PARAMETERS: source_desc - Value to be stored
406 * Node - Named object to receive the value
407 * walk_state - Current walk state
408 * implicit_conversion - Perform implicit conversion (yes/no)
412 * DESCRIPTION: Store the object to the named object.
414 * The Assignment of an object to a named object is handled here
415 * The value passed in will replace the current value (if any)
416 * with the input value.
418 * When storing into an object the data is converted to the
419 * target object type then stored in the object. This means
420 * that the target object type (for an initialized target) will
421 * not be changed by a store operation.
423 * Assumes parameters are already validated.
425 ******************************************************************************/
428 acpi_ex_store_object_to_node (
429 union acpi_operand_object
*source_desc
,
430 struct acpi_namespace_node
*node
,
431 struct acpi_walk_state
*walk_state
,
432 u8 implicit_conversion
)
434 acpi_status status
= AE_OK
;
435 union acpi_operand_object
*target_desc
;
436 union acpi_operand_object
*new_desc
;
437 acpi_object_type target_type
;
440 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc
);
444 * Get current type of the node, and object attached to Node
446 target_type
= acpi_ns_get_type (node
);
447 target_desc
= acpi_ns_get_attached_object (node
);
449 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Storing %p(%s) into node %p(%s)\n",
450 source_desc
, acpi_ut_get_object_type_name (source_desc
),
451 node
, acpi_ut_get_type_name (target_type
)));
454 * Resolve the source object to an actual value
455 * (If it is a reference object)
457 status
= acpi_ex_resolve_object (&source_desc
, target_type
, walk_state
);
458 if (ACPI_FAILURE (status
)) {
459 return_ACPI_STATUS (status
);
462 /* If no implicit conversion, drop into the default case below */
464 if (!implicit_conversion
) {
465 /* Force execution of default (no implicit conversion) */
467 target_type
= ACPI_TYPE_ANY
;
471 * Do the actual store operation
473 switch (target_type
) {
474 case ACPI_TYPE_BUFFER_FIELD
:
475 case ACPI_TYPE_LOCAL_REGION_FIELD
:
476 case ACPI_TYPE_LOCAL_BANK_FIELD
:
477 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
480 * For fields, copy the source data to the target field.
482 status
= acpi_ex_write_data_to_field (source_desc
, target_desc
, &walk_state
->result_obj
);
486 case ACPI_TYPE_INTEGER
:
487 case ACPI_TYPE_STRING
:
488 case ACPI_TYPE_BUFFER
:
491 * These target types are all of type Integer/String/Buffer, and
492 * therefore support implicit conversion before the store.
494 * Copy and/or convert the source object to a new target object
496 status
= acpi_ex_store_object_to_object (source_desc
, target_desc
, &new_desc
, walk_state
);
497 if (ACPI_FAILURE (status
)) {
498 return_ACPI_STATUS (status
);
501 if (new_desc
!= target_desc
) {
503 * Store the new new_desc as the new value of the Name, and set
504 * the Name's type to that of the value being stored in it.
505 * source_desc reference count is incremented by attach_object.
507 * Note: This may change the type of the node if an explicit store
508 * has been performed such that the node/object type has been
511 status
= acpi_ns_attach_object (node
, new_desc
, new_desc
->common
.type
);
513 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
514 "Store %s into %s via Convert/Attach\n",
515 acpi_ut_get_object_type_name (source_desc
),
516 acpi_ut_get_object_type_name (new_desc
)));
523 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
524 "Storing %s (%p) directly into node (%p), no implicit conversion\n",
525 acpi_ut_get_object_type_name (source_desc
), source_desc
, node
));
527 /* No conversions for all other types. Just attach the source object */
529 status
= acpi_ns_attach_object (node
, source_desc
, ACPI_GET_OBJECT_TYPE (source_desc
));
533 return_ACPI_STATUS (status
);