blob: f88b18163206423dc207d5e1b119dd8bcebfec8b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exstore - AML Interpreter object store support
5 *
6 *****************************************************************************/
7
8/*
Bob Moore6c9deb72007-02-02 19:48:24 +03009 * Copyright (C) 2000 - 2007, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
26 *
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.
30 *
31 * NO WARRANTY
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.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acdispat.h>
47#include <acpi/acinterp.h>
48#include <acpi/amlcode.h>
49#include <acpi/acnamesp.h>
Robert Moore44f6c012005-04-18 22:49:35 -040050#include <acpi/acparser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040053ACPI_MODULE_NAME("exstore")
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Robert Moore44f6c012005-04-18 22:49:35 -040055/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040056static void
Len Brown4be44fc2005-08-05 00:44:28 -040057acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
58 u32 level, u32 index);
Robert Moore44f6c012005-04-18 22:49:35 -040059
60static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040061acpi_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);
Robert Moore44f6c012005-04-18 22:49:35 -040064
65/*******************************************************************************
66 *
67 * FUNCTION: acpi_ex_do_debug_object
68 *
69 * PARAMETERS: source_desc - Value to be stored
70 * Level - Indentation level (used for packages)
71 * Index - Current package element, zero if not pkg
72 *
73 * RETURN: None
74 *
75 * DESCRIPTION: Handles stores to the Debug Object.
76 *
77 ******************************************************************************/
78
79static void
Len Brown4be44fc2005-08-05 00:44:28 -040080acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
81 u32 level, u32 index)
Robert Moore44f6c012005-04-18 22:49:35 -040082{
Len Brown4be44fc2005-08-05 00:44:28 -040083 u32 i;
Robert Moore44f6c012005-04-18 22:49:35 -040084
Bob Mooreb229cf92006-04-21 17:15:00 -040085 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040086
Len Brown4be44fc2005-08-05 00:44:28 -040087 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
88 level, " "));
Robert Moore44f6c012005-04-18 22:49:35 -040089
90 /* Display index for package output only */
91
92 if (index > 0) {
Len Brown4be44fc2005-08-05 00:44:28 -040093 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
94 "(%.2u) ", index - 1));
Robert Moore44f6c012005-04-18 22:49:35 -040095 }
96
97 if (!source_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -040098 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n"));
Robert Moore44f6c012005-04-18 22:49:35 -040099 return_VOID;
100 }
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
103 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: ",
104 acpi_ut_get_object_type_name
105 (source_desc)));
Robert Moore44f6c012005-04-18 22:49:35 -0400106
Len Brown4be44fc2005-08-05 00:44:28 -0400107 if (!acpi_ut_valid_internal_object(source_desc)) {
108 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
109 "%p, Invalid Internal Object!\n",
110 source_desc));
111 return_VOID;
Robert Moore44f6c012005-04-18 22:49:35 -0400112 }
Len Brown4be44fc2005-08-05 00:44:28 -0400113 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
114 ACPI_DESC_TYPE_NAMED) {
115 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
116 acpi_ut_get_type_name(((struct
117 acpi_namespace_node
118 *)source_desc)->
119 type),
120 source_desc));
Robert Moore44f6c012005-04-18 22:49:35 -0400121 return_VOID;
Len Brown4be44fc2005-08-05 00:44:28 -0400122 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400123 return_VOID;
124 }
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
Robert Moore44f6c012005-04-18 22:49:35 -0400127 case ACPI_TYPE_INTEGER:
128
129 /* Output correct integer width */
130
131 if (acpi_gbl_integer_byte_width == 4) {
Len Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
133 (u32) source_desc->integer.
134 value));
135 } else {
136 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
137 "0x%8.8X%8.8X\n",
138 ACPI_FORMAT_UINT64(source_desc->
139 integer.
140 value)));
Robert Moore44f6c012005-04-18 22:49:35 -0400141 }
142 break;
143
144 case ACPI_TYPE_BUFFER:
145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
147 (u32) source_desc->buffer.length));
148 ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
149 (source_desc->buffer.length <
Bob Moore422f4f92008-04-10 19:06:37 +0400150 256) ? source_desc->buffer.length : 256);
Robert Moore44f6c012005-04-18 22:49:35 -0400151 break;
152
153 case ACPI_TYPE_STRING:
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
156 source_desc->string.length,
157 source_desc->string.pointer));
Robert Moore44f6c012005-04-18 22:49:35 -0400158 break;
159
160 case ACPI_TYPE_PACKAGE:
161
Len Brown4be44fc2005-08-05 00:44:28 -0400162 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
163 "[0x%.2X Elements]\n",
164 source_desc->package.count));
Robert Moore44f6c012005-04-18 22:49:35 -0400165
166 /* Output the entire contents of the package */
167
168 for (i = 0; i < source_desc->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400169 acpi_ex_do_debug_object(source_desc->package.
170 elements[i], level + 4, i + 1);
Robert Moore44f6c012005-04-18 22:49:35 -0400171 }
172 break;
173
174 case ACPI_TYPE_LOCAL_REFERENCE:
175
176 if (source_desc->reference.opcode == AML_INDEX_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400177 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
178 "[%s, 0x%X]\n",
179 acpi_ps_get_opcode_name
180 (source_desc->reference.opcode),
181 source_desc->reference.offset));
182 } else {
183 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]\n",
184 acpi_ps_get_opcode_name
185 (source_desc->reference.opcode)));
Robert Moore44f6c012005-04-18 22:49:35 -0400186 }
Robert Moore44f6c012005-04-18 22:49:35 -0400187
188 if (source_desc->reference.object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400189 if (ACPI_GET_DESCRIPTOR_TYPE
190 (source_desc->reference.object) ==
191 ACPI_DESC_TYPE_NAMED) {
192 acpi_ex_do_debug_object(((struct
193 acpi_namespace_node *)
194 source_desc->reference.
195 object)->object,
196 level + 4, 0);
197 } else {
198 acpi_ex_do_debug_object(source_desc->reference.
199 object, level + 4, 0);
Robert Moore44f6c012005-04-18 22:49:35 -0400200 }
Len Brown4be44fc2005-08-05 00:44:28 -0400201 } else if (source_desc->reference.node) {
202 acpi_ex_do_debug_object((source_desc->reference.node)->
203 object, level + 4, 0);
Robert Moore44f6c012005-04-18 22:49:35 -0400204 }
205 break;
206
207 default:
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
210 source_desc,
211 acpi_ut_get_object_type_name
212 (source_desc)));
Robert Moore44f6c012005-04-18 22:49:35 -0400213 break;
214 }
215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
Robert Moore44f6c012005-04-18 22:49:35 -0400217 return_VOID;
218}
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/*******************************************************************************
221 *
222 * FUNCTION: acpi_ex_store
223 *
224 * PARAMETERS: *source_desc - Value to be stored
225 * *dest_desc - Where to store it. Must be an NS node
226 * or an union acpi_operand_object of type
227 * Reference;
228 * walk_state - Current walk state
229 *
230 * RETURN: Status
231 *
232 * DESCRIPTION: Store the value described by source_desc into the location
233 * described by dest_desc. Called by various interpreter
234 * functions to store the result of an operation into
235 * the destination operand -- not just simply the actual "Store"
236 * ASL operator.
237 *
238 ******************************************************************************/
239
240acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400241acpi_ex_store(union acpi_operand_object *source_desc,
242 union acpi_operand_object *dest_desc,
243 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Len Brown4be44fc2005-08-05 00:44:28 -0400245 acpi_status status = AE_OK;
246 union acpi_operand_object *ref_desc = dest_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Bob Mooreb229cf92006-04-21 17:15:00 -0400248 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 /* Validate parameters */
251
252 if (!source_desc || !dest_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500253 ACPI_ERROR((AE_INFO, "Null parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -0400254 return_ACPI_STATUS(AE_AML_NO_OPERAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
257 /* dest_desc can be either a namespace node or an ACPI object */
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 /*
261 * Dest is a namespace node,
262 * Storing an object into a Named node.
263 */
Len Brown4be44fc2005-08-05 00:44:28 -0400264 status = acpi_ex_store_object_to_node(source_desc,
265 (struct
266 acpi_namespace_node *)
267 dest_desc, walk_state,
268 ACPI_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
272
273 /* Destination object must be a Reference or a Constant object */
274
Len Brown4be44fc2005-08-05 00:44:28 -0400275 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 case ACPI_TYPE_LOCAL_REFERENCE:
277 break;
278
279 case ACPI_TYPE_INTEGER:
280
281 /* Allow stores to Constants -- a Noop as per ACPI spec */
282
283 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400284 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
286
287 /*lint -fallthrough */
288
289 default:
290
291 /* Destination is not a Reference object */
292
Bob Mooreb8e4d892006-01-27 16:43:00 -0500293 ACPI_ERROR((AE_INFO,
294 "Target is not a Reference or Constant object - %s [%p]",
295 acpi_ut_get_object_type_name(dest_desc),
296 dest_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 ACPI_DUMP_STACK_ENTRY(source_desc);
299 ACPI_DUMP_STACK_ENTRY(dest_desc);
Bob Mooreb229cf92006-04-21 17:15:00 -0400300 ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore",
Len Brown4be44fc2005-08-05 00:44:28 -0400301 2,
302 "Target is not a Reference or Constant object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Len Brown4be44fc2005-08-05 00:44:28 -0400304 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306
307 /*
308 * Examine the Reference opcode. These cases are handled:
309 *
310 * 1) Store to Name (Change the object associated with a name)
311 * 2) Store to an indexed area of a Buffer or Package
312 * 3) Store to a Method Local or Arg
313 * 4) Store to the debug object
314 */
315 switch (ref_desc->reference.opcode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 case AML_REF_OF_OP:
317
318 /* Storing an object into a Name "container" */
319
Len Brown4be44fc2005-08-05 00:44:28 -0400320 status = acpi_ex_store_object_to_node(source_desc,
321 ref_desc->reference.
322 object, walk_state,
323 ACPI_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 break;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 case AML_INDEX_OP:
327
328 /* Storing to an Index (pointer into a packager or buffer) */
329
Len Brown4be44fc2005-08-05 00:44:28 -0400330 status =
331 acpi_ex_store_object_to_index(source_desc, ref_desc,
332 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 break;
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 case AML_LOCAL_OP:
336 case AML_ARG_OP:
337
338 /* Store to a method local/arg */
339
Len Brown4be44fc2005-08-05 00:44:28 -0400340 status =
341 acpi_ds_store_object_to_local(ref_desc->reference.opcode,
342 ref_desc->reference.offset,
343 source_desc, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 case AML_DEBUG_OP:
347
348 /*
349 * Storing to the Debug object causes the value stored to be
350 * displayed and otherwise has no effect -- see ACPI Specification
351 */
Len Brown4be44fc2005-08-05 00:44:28 -0400352 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
353 "**** Write to Debug Object: Object %p %s ****:\n\n",
354 source_desc,
355 acpi_ut_get_object_type_name(source_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Len Brown4be44fc2005-08-05 00:44:28 -0400357 acpi_ex_do_debug_object(source_desc, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 break;
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 default:
361
Bob Mooreb8e4d892006-01-27 16:43:00 -0500362 ACPI_ERROR((AE_INFO, "Unknown Reference opcode %X",
363 ref_desc->reference.opcode));
Len Brown4be44fc2005-08-05 00:44:28 -0400364 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 status = AE_AML_INTERNAL;
367 break;
368 }
369
Len Brown4be44fc2005-08-05 00:44:28 -0400370 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373/*******************************************************************************
374 *
375 * FUNCTION: acpi_ex_store_object_to_index
376 *
377 * PARAMETERS: *source_desc - Value to be stored
378 * *dest_desc - Named object to receive the value
379 * walk_state - Current walk state
380 *
381 * RETURN: Status
382 *
383 * DESCRIPTION: Store the object to indexed Buffer or Package element
384 *
385 ******************************************************************************/
386
Robert Moore44f6c012005-04-18 22:49:35 -0400387static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400388acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
389 union acpi_operand_object *index_desc,
390 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Len Brown4be44fc2005-08-05 00:44:28 -0400392 acpi_status status = AE_OK;
393 union acpi_operand_object *obj_desc;
394 union acpi_operand_object *new_desc;
395 u8 value = 0;
396 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Bob Mooreb229cf92006-04-21 17:15:00 -0400398 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /*
401 * Destination must be a reference pointer, and
402 * must point to either a buffer or a package
403 */
404 switch (index_desc->reference.target_type) {
405 case ACPI_TYPE_PACKAGE:
406 /*
407 * Storing to a package element. Copy the object and replace
408 * any existing object with the new object. No implicit
409 * conversion is performed.
410 *
411 * The object at *(index_desc->Reference.Where) is the
412 * element within the package that is to be modified.
413 * The parent package object is at index_desc->Reference.Object
414 */
415 obj_desc = *(index_desc->reference.where);
416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 status =
418 acpi_ut_copy_iobject_to_iobject(source_desc, &new_desc,
419 walk_state);
420 if (ACPI_FAILURE(status)) {
421 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
424 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* Decrement reference count by the ref count of the parent package */
427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 for (i = 0; i < ((union acpi_operand_object *)
429 index_desc->reference.object)->common.
430 reference_count; i++) {
431 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433 }
434
435 *(index_desc->reference.where) = new_desc;
436
Robert Moore44f6c012005-04-18 22:49:35 -0400437 /* Increment ref count by the ref count of the parent package-1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 for (i = 1; i < ((union acpi_operand_object *)
440 index_desc->reference.object)->common.
441 reference_count; i++) {
442 acpi_ut_add_reference(new_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
445 break;
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 case ACPI_TYPE_BUFFER_FIELD:
448
449 /*
450 * Store into a Buffer or String (not actually a real buffer_field)
451 * at a location defined by an Index.
452 *
453 * The first 8-bit element of the source object is written to the
454 * 8-bit Buffer location defined by the Index destination object,
455 * according to the ACPI 2.0 specification.
456 */
457
458 /*
459 * Make sure the target is a Buffer or String. An error should
460 * not happen here, since the reference_object was constructed
461 * by the INDEX_OP code.
462 */
463 obj_desc = index_desc->reference.object;
Len Brown4be44fc2005-08-05 00:44:28 -0400464 if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) &&
465 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) {
466 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
469 /*
470 * The assignment of the individual elements will be slightly
471 * different for each source type.
472 */
Len Brown4be44fc2005-08-05 00:44:28 -0400473 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 case ACPI_TYPE_INTEGER:
475
476 /* Use the least-significant byte of the integer */
477
478 value = (u8) (source_desc->integer.value);
479 break;
480
481 case ACPI_TYPE_BUFFER:
482 case ACPI_TYPE_STRING:
483
484 /* Note: Takes advantage of common string/buffer fields */
485
486 value = source_desc->buffer.pointer[0];
487 break;
488
489 default:
490
491 /* All other types are invalid */
492
Bob Mooreb8e4d892006-01-27 16:43:00 -0500493 ACPI_ERROR((AE_INFO,
494 "Source must be Integer/Buffer/String type, not %s",
495 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400496 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498
499 /* Store the source value into the target buffer byte */
500
501 obj_desc->buffer.pointer[index_desc->reference.offset] = value;
502 break;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 default:
Bob Mooreb229cf92006-04-21 17:15:00 -0400505 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 status = AE_AML_OPERAND_TYPE;
507 break;
508 }
509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513/*******************************************************************************
514 *
515 * FUNCTION: acpi_ex_store_object_to_node
516 *
517 * PARAMETERS: source_desc - Value to be stored
518 * Node - Named object to receive the value
519 * walk_state - Current walk state
520 * implicit_conversion - Perform implicit conversion (yes/no)
521 *
522 * RETURN: Status
523 *
524 * DESCRIPTION: Store the object to the named object.
525 *
526 * The Assignment of an object to a named object is handled here
527 * The value passed in will replace the current value (if any)
528 * with the input value.
529 *
530 * When storing into an object the data is converted to the
531 * target object type then stored in the object. This means
532 * that the target object type (for an initialized target) will
533 * not be changed by a store operation.
534 *
535 * Assumes parameters are already validated.
536 *
537 ******************************************************************************/
538
539acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400540acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
541 struct acpi_namespace_node *node,
542 struct acpi_walk_state *walk_state,
543 u8 implicit_conversion)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Len Brown4be44fc2005-08-05 00:44:28 -0400545 acpi_status status = AE_OK;
546 union acpi_operand_object *target_desc;
547 union acpi_operand_object *new_desc;
548 acpi_object_type target_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Bob Mooreb229cf92006-04-21 17:15:00 -0400550 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Robert Moore44f6c012005-04-18 22:49:35 -0400552 /* Get current type of the node, and object attached to Node */
553
Len Brown4be44fc2005-08-05 00:44:28 -0400554 target_type = acpi_ns_get_type(node);
555 target_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Len Brown4be44fc2005-08-05 00:44:28 -0400557 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
558 source_desc,
559 acpi_ut_get_object_type_name(source_desc), node,
560 acpi_ut_get_type_name(target_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 /*
563 * Resolve the source object to an actual value
564 * (If it is a reference object)
565 */
Len Brown4be44fc2005-08-05 00:44:28 -0400566 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
567 if (ACPI_FAILURE(status)) {
568 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570
571 /* If no implicit conversion, drop into the default case below */
572
Robert Moore6f42ccf2005-05-13 00:00:00 -0400573 if ((!implicit_conversion) || (walk_state->opcode == AML_COPY_OP)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /* Force execution of default (no implicit conversion) */
576
577 target_type = ACPI_TYPE_ANY;
578 }
579
Robert Moore44f6c012005-04-18 22:49:35 -0400580 /* Do the actual store operation */
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 switch (target_type) {
583 case ACPI_TYPE_BUFFER_FIELD:
584 case ACPI_TYPE_LOCAL_REGION_FIELD:
585 case ACPI_TYPE_LOCAL_BANK_FIELD:
586 case ACPI_TYPE_LOCAL_INDEX_FIELD:
587
Robert Moore44f6c012005-04-18 22:49:35 -0400588 /* For fields, copy the source data to the target field. */
589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 status = acpi_ex_write_data_to_field(source_desc, target_desc,
591 &walk_state->result_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 break;
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 case ACPI_TYPE_INTEGER:
595 case ACPI_TYPE_STRING:
596 case ACPI_TYPE_BUFFER:
597
598 /*
599 * These target types are all of type Integer/String/Buffer, and
600 * therefore support implicit conversion before the store.
601 *
602 * Copy and/or convert the source object to a new target object
603 */
Len Brown4be44fc2005-08-05 00:44:28 -0400604 status =
605 acpi_ex_store_object_to_object(source_desc, target_desc,
606 &new_desc, walk_state);
607 if (ACPI_FAILURE(status)) {
608 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610
611 if (new_desc != target_desc) {
612 /*
613 * Store the new new_desc as the new value of the Name, and set
614 * the Name's type to that of the value being stored in it.
615 * source_desc reference count is incremented by attach_object.
616 *
617 * Note: This may change the type of the node if an explicit store
618 * has been performed such that the node/object type has been
619 * changed.
620 */
Len Brown4be44fc2005-08-05 00:44:28 -0400621 status =
622 acpi_ns_attach_object(node, new_desc,
623 new_desc->common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
626 "Store %s into %s via Convert/Attach\n",
627 acpi_ut_get_object_type_name
628 (source_desc),
629 acpi_ut_get_object_type_name
630 (new_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
632 break;
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 default:
635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 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),
639 source_desc, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 /* No conversions for all other types. Just attach the source object */
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 status = acpi_ns_attach_object(node, source_desc,
644 ACPI_GET_OBJECT_TYPE
645 (source_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 break;
647 }
648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}