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 "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 is not simple. The source must be
299 * evaluated and converted to the type of the destination and then the
300 * source is copied into the destination - we can't just point to the
304 * The object at *(index_desc->Reference.Where) is the
305 * element within the package that is to be modified.
306 * The parent package object is at index_desc->Reference.Object
308 obj_desc = *(index_desc->reference.where);
310 /* Do the conversion/store */
312 status = acpi_ex_store_object_to_object (source_desc, obj_desc, &new_desc,
314 if (ACPI_FAILURE (status)) {
315 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
316 "Could not store object to indexed package element\n"));
317 return_ACPI_STATUS (status);
321 * If a new object was created, we must install it as the new
324 if (new_desc != obj_desc) {
325 acpi_ut_remove_reference (obj_desc);
326 *(index_desc->reference.where) = new_desc;
328 /* If same as the original source, add a reference */
330 if (new_desc == source_desc) {
331 acpi_ut_add_reference (new_desc);
334 /* Increment reference count by the ref count of the parent package -1 */
336 for (i = 1; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) {
337 acpi_ut_add_reference (new_desc);
343 case ACPI_TYPE_BUFFER_FIELD:
346 * Store into a Buffer (not actually a real buffer_field) at a
347 * location defined by an Index.
349 * The first 8-bit element of the source object is written to the
350 * 8-bit Buffer location defined by the Index destination object,
351 * according to the ACPI 2.0 specification.
355 * Make sure the target is a Buffer
357 obj_desc = index_desc->reference.object;
358 if (ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_BUFFER) {
359 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
363 * The assignment of the individual elements will be slightly
364 * different for each source type.
366 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
367 case ACPI_TYPE_INTEGER:
369 /* Use the least-significant byte of the integer */
371 value = (u8) (source_desc->integer.value);
374 case ACPI_TYPE_BUFFER:
376 value = source_desc->buffer.pointer[0];
379 case ACPI_TYPE_STRING:
381 value = (u8) source_desc->string.pointer[0];
386 /* All other types are invalid */
388 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
389 "Source must be Integer/Buffer/String type, not %s\n",
390 acpi_ut_get_object_type_name (source_desc)));
391 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
394 /* Store the source value into the target buffer byte */
396 obj_desc->buffer.pointer[index_desc->reference.offset] = value;
401 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
402 "Target is not a Package or buffer_field\n"));
403 status = AE_AML_OPERAND_TYPE;
407 return_ACPI_STATUS (status);
411 /*******************************************************************************
413 * FUNCTION: acpi_ex_store_object_to_node
415 * PARAMETERS: source_desc - Value to be stored
416 * Node - Named object to receive the value
417 * walk_state - Current walk state
418 * implicit_conversion - Perform implicit conversion (yes/no)
422 * DESCRIPTION: Store the object to the named object.
424 * The Assignment of an object to a named object is handled here
425 * The value passed in will replace the current value (if any)
426 * with the input value.
428 * When storing into an object the data is converted to the
429 * target object type then stored in the object. This means
430 * that the target object type (for an initialized target) will
431 * not be changed by a store operation.
433 * Assumes parameters are already validated.
435 ******************************************************************************/
438 acpi_ex_store_object_to_node (
439 union acpi_operand_object *source_desc,
440 struct acpi_namespace_node *node,
441 struct acpi_walk_state *walk_state,
442 u8 implicit_conversion)
444 acpi_status status = AE_OK;
445 union acpi_operand_object *target_desc;
446 union acpi_operand_object *new_desc;
447 acpi_object_type target_type;
450 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc);
454 * Get current type of the node, and object attached to Node
456 target_type = acpi_ns_get_type (node);
457 target_desc = acpi_ns_get_attached_object (node);
459 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
460 source_desc, acpi_ut_get_object_type_name (source_desc),
461 node, acpi_ut_get_type_name (target_type)));
464 * Resolve the source object to an actual value
465 * (If it is a reference object)
467 status = acpi_ex_resolve_object (&source_desc, target_type, walk_state);
468 if (ACPI_FAILURE (status)) {
469 return_ACPI_STATUS (status);
472 /* If no implicit conversion, drop into the default case below */
474 if (!implicit_conversion) {
475 /* Force execution of default (no implicit conversion) */
477 target_type = ACPI_TYPE_ANY;
481 * Do the actual store operation
483 switch (target_type) {
484 case ACPI_TYPE_BUFFER_FIELD:
485 case ACPI_TYPE_LOCAL_REGION_FIELD:
486 case ACPI_TYPE_LOCAL_BANK_FIELD:
487 case ACPI_TYPE_LOCAL_INDEX_FIELD:
490 * For fields, copy the source data to the target field.
492 status = acpi_ex_write_data_to_field (source_desc, target_desc, &walk_state->result_obj);
496 case ACPI_TYPE_INTEGER:
497 case ACPI_TYPE_STRING:
498 case ACPI_TYPE_BUFFER:
501 * These target types are all of type Integer/String/Buffer, and
502 * therefore support implicit conversion before the store.
504 * Copy and/or convert the source object to a new target object
506 status = acpi_ex_store_object_to_object (source_desc, target_desc, &new_desc, walk_state);
507 if (ACPI_FAILURE (status)) {
508 return_ACPI_STATUS (status);
511 if (new_desc != target_desc) {
513 * Store the new new_desc as the new value of the Name, and set
514 * the Name's type to that of the value being stored in it.
515 * source_desc reference count is incremented by attach_object.
517 * Note: This may change the type of the node if an explicit store
518 * has been performed such that the node/object type has been
521 status = acpi_ns_attach_object (node, new_desc, new_desc->common.type);
523 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
524 "Store %s into %s via Convert/Attach\n",
525 acpi_ut_get_object_type_name (source_desc),
526 acpi_ut_get_object_type_name (new_desc)));
533 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
534 "Storing %s (%p) directly into node (%p), no implicit conversion\n",
535 acpi_ut_get_object_type_name (source_desc), source_desc, node));
537 /* No conversions for all other types. Just attach the source object */
539 status = acpi_ns_attach_object (node, source_desc, ACPI_GET_OBJECT_TYPE (source_desc));
543 return_ACPI_STATUS (status);