2 /******************************************************************************
4 * Module Name: exstore - AML Interpreter object store support
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2004, 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 "Destination is not a Reference or Constant object [%p]\n", dest_desc
));
134 ACPI_DUMP_STACK_ENTRY (source_desc
);
135 ACPI_DUMP_STACK_ENTRY (dest_desc
);
136 ACPI_DUMP_OPERANDS (&dest_desc
, ACPI_IMODE_EXECUTE
, "ex_store",
137 2, "Target is not a Reference or Constant object");
139 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
143 * Examine the Reference opcode. These cases are handled:
145 * 1) Store to Name (Change the object associated with a name)
146 * 2) Store to an indexed area of a Buffer or Package
147 * 3) Store to a Method Local or Arg
148 * 4) Store to the debug object
150 switch (ref_desc
->reference
.opcode
) {
154 /* Storing an object into a Name "container" */
156 status
= acpi_ex_store_object_to_node (source_desc
, ref_desc
->reference
.object
,
157 walk_state
, ACPI_IMPLICIT_CONVERSION
);
163 /* Storing to an Index (pointer into a packager or buffer) */
165 status
= acpi_ex_store_object_to_index (source_desc
, ref_desc
, walk_state
);
172 /* Store to a method local/arg */
174 status
= acpi_ds_store_object_to_local (ref_desc
->reference
.opcode
,
175 ref_desc
->reference
.offset
, source_desc
, walk_state
);
182 * Storing to the Debug object causes the value stored to be
183 * displayed and otherwise has no effect -- see ACPI Specification
185 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "**** Write to Debug Object: ****:\n\n"));
187 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "[ACPI Debug] %s: ",
188 acpi_ut_get_object_type_name (source_desc
)));
190 switch (ACPI_GET_OBJECT_TYPE (source_desc
)) {
191 case ACPI_TYPE_INTEGER
:
193 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "0x%8.8X%8.8X\n",
194 ACPI_FORMAT_UINT64 (source_desc
->integer
.value
)));
198 case ACPI_TYPE_BUFFER
:
200 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "Length 0x%.2X",
201 (u32
) source_desc
->buffer
.length
));
202 ACPI_DUMP_BUFFER (source_desc
->buffer
.pointer
,
203 (source_desc
->buffer
.length
< 32) ? source_desc
->buffer
.length
: 32);
207 case ACPI_TYPE_STRING
:
209 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "Length 0x%.2X, \"%s\"\n",
210 source_desc
->string
.length
, source_desc
->string
.pointer
));
214 case ACPI_TYPE_PACKAGE
:
216 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "Size 0x%.2X Elements Ptr - %p\n",
217 source_desc
->package
.count
, source_desc
->package
.elements
));
223 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT
, "%p\n",
228 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC
, "\n"));
234 ACPI_REPORT_ERROR (("ex_store: Unknown Reference opcode %X\n",
235 ref_desc
->reference
.opcode
));
236 ACPI_DUMP_ENTRY (ref_desc
, ACPI_LV_ERROR
);
238 status
= AE_AML_INTERNAL
;
242 return_ACPI_STATUS (status
);
246 /*******************************************************************************
248 * FUNCTION: acpi_ex_store_object_to_index
250 * PARAMETERS: *source_desc - Value to be stored
251 * *dest_desc - Named object to receive the value
252 * walk_state - Current walk state
256 * DESCRIPTION: Store the object to indexed Buffer or Package element
258 ******************************************************************************/
261 acpi_ex_store_object_to_index (
262 union acpi_operand_object
*source_desc
,
263 union acpi_operand_object
*index_desc
,
264 struct acpi_walk_state
*walk_state
)
266 acpi_status status
= AE_OK
;
267 union acpi_operand_object
*obj_desc
;
268 union acpi_operand_object
*new_desc
;
273 ACPI_FUNCTION_TRACE ("ex_store_object_to_index");
277 * Destination must be a reference pointer, and
278 * must point to either a buffer or a package
280 switch (index_desc
->reference
.target_type
) {
281 case ACPI_TYPE_PACKAGE
:
283 * Storing to a package element is not simple. The source must be
284 * evaluated and converted to the type of the destination and then the
285 * source is copied into the destination - we can't just point to the
289 * The object at *(index_desc->Reference.Where) is the
290 * element within the package that is to be modified.
291 * The parent package object is at index_desc->Reference.Object
293 obj_desc
= *(index_desc
->reference
.where
);
295 /* Do the conversion/store */
297 status
= acpi_ex_store_object_to_object (source_desc
, obj_desc
, &new_desc
,
299 if (ACPI_FAILURE (status
)) {
300 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
301 "Could not store object to indexed package element\n"));
302 return_ACPI_STATUS (status
);
306 * If a new object was created, we must install it as the new
309 if (new_desc
!= obj_desc
) {
310 acpi_ut_remove_reference (obj_desc
);
311 *(index_desc
->reference
.where
) = new_desc
;
313 /* If same as the original source, add a reference */
315 if (new_desc
== source_desc
) {
316 acpi_ut_add_reference (new_desc
);
319 /* Increment reference count by the ref count of the parent package -1 */
321 for (i
= 1; i
< ((union acpi_operand_object
*) index_desc
->reference
.object
)->common
.reference_count
; i
++) {
322 acpi_ut_add_reference (new_desc
);
328 case ACPI_TYPE_BUFFER_FIELD
:
331 * Store into a Buffer (not actually a real buffer_field) at a
332 * location defined by an Index.
334 * The first 8-bit element of the source object is written to the
335 * 8-bit Buffer location defined by the Index destination object,
336 * according to the ACPI 2.0 specification.
340 * Make sure the target is a Buffer
342 obj_desc
= index_desc
->reference
.object
;
343 if (ACPI_GET_OBJECT_TYPE (obj_desc
) != ACPI_TYPE_BUFFER
) {
344 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
348 * The assignment of the individual elements will be slightly
349 * different for each source type.
351 switch (ACPI_GET_OBJECT_TYPE (source_desc
)) {
352 case ACPI_TYPE_INTEGER
:
354 /* Use the least-significant byte of the integer */
356 value
= (u8
) (source_desc
->integer
.value
);
359 case ACPI_TYPE_BUFFER
:
361 value
= source_desc
->buffer
.pointer
[0];
364 case ACPI_TYPE_STRING
:
366 value
= (u8
) source_desc
->string
.pointer
[0];
371 /* All other types are invalid */
373 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
374 "Source must be Integer/Buffer/String type, not %s\n",
375 acpi_ut_get_object_type_name (source_desc
)));
376 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
379 /* Store the source value into the target buffer byte */
381 obj_desc
->buffer
.pointer
[index_desc
->reference
.offset
] = value
;
386 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
387 "Target is not a Package or buffer_field\n"));
388 status
= AE_AML_OPERAND_TYPE
;
392 return_ACPI_STATUS (status
);
396 /*******************************************************************************
398 * FUNCTION: acpi_ex_store_object_to_node
400 * PARAMETERS: source_desc - Value to be stored
401 * Node - Named object to receive the value
402 * walk_state - Current walk state
403 * implicit_conversion - Perform implicit conversion (yes/no)
407 * DESCRIPTION: Store the object to the named object.
409 * The Assignment of an object to a named object is handled here
410 * The value passed in will replace the current value (if any)
411 * with the input value.
413 * When storing into an object the data is converted to the
414 * target object type then stored in the object. This means
415 * that the target object type (for an initialized target) will
416 * not be changed by a store operation.
418 * Assumes parameters are already validated.
420 ******************************************************************************/
423 acpi_ex_store_object_to_node (
424 union acpi_operand_object
*source_desc
,
425 struct acpi_namespace_node
*node
,
426 struct acpi_walk_state
*walk_state
,
427 u8 implicit_conversion
)
429 acpi_status status
= AE_OK
;
430 union acpi_operand_object
*target_desc
;
431 union acpi_operand_object
*new_desc
;
432 acpi_object_type target_type
;
435 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc
);
439 * Get current type of the node, and object attached to Node
441 target_type
= acpi_ns_get_type (node
);
442 target_desc
= acpi_ns_get_attached_object (node
);
444 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Storing %p(%s) into node %p(%s)\n",
445 source_desc
, acpi_ut_get_object_type_name (source_desc
),
446 node
, acpi_ut_get_type_name (target_type
)));
449 * Resolve the source object to an actual value
450 * (If it is a reference object)
452 status
= acpi_ex_resolve_object (&source_desc
, target_type
, walk_state
);
453 if (ACPI_FAILURE (status
)) {
454 return_ACPI_STATUS (status
);
457 /* If no implicit conversion, drop into the default case below */
459 if (!implicit_conversion
) {
460 /* Force execution of default (no implicit conversion) */
462 target_type
= ACPI_TYPE_ANY
;
466 * Do the actual store operation
468 switch (target_type
) {
469 case ACPI_TYPE_BUFFER_FIELD
:
470 case ACPI_TYPE_LOCAL_REGION_FIELD
:
471 case ACPI_TYPE_LOCAL_BANK_FIELD
:
472 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
475 * For fields, copy the source data to the target field.
477 status
= acpi_ex_write_data_to_field (source_desc
, target_desc
, &walk_state
->result_obj
);
481 case ACPI_TYPE_INTEGER
:
482 case ACPI_TYPE_STRING
:
483 case ACPI_TYPE_BUFFER
:
486 * These target types are all of type Integer/String/Buffer, and
487 * therefore support implicit conversion before the store.
489 * Copy and/or convert the source object to a new target object
491 status
= acpi_ex_store_object_to_object (source_desc
, target_desc
, &new_desc
, walk_state
);
492 if (ACPI_FAILURE (status
)) {
493 return_ACPI_STATUS (status
);
496 if (new_desc
!= target_desc
) {
498 * Store the new new_desc as the new value of the Name, and set
499 * the Name's type to that of the value being stored in it.
500 * source_desc reference count is incremented by attach_object.
502 * Note: This may change the type of the node if an explicit store
503 * has been performed such that the node/object type has been
506 status
= acpi_ns_attach_object (node
, new_desc
, new_desc
->common
.type
);
508 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
509 "Store %s into %s via Convert/Attach\n",
510 acpi_ut_get_object_type_name (source_desc
),
511 acpi_ut_get_object_type_name (new_desc
)));
518 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
519 "Storing %s (%p) directly into node (%p), no implicit conversion\n",
520 acpi_ut_get_object_type_name (source_desc
), source_desc
, node
));
522 /* No conversions for all other types. Just attach the source object */
524 status
= acpi_ns_attach_object (node
, source_desc
, ACPI_GET_OBJECT_TYPE (source_desc
));
528 return_ACPI_STATUS (status
);