blob: d860f9c6172cc6a0b735911d16be2df5c679e977 [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
Bob Moore61ce4212008-04-10 19:06:39 +0400126 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
Robert Moore44f6c012005-04-18 22:49:35 -0400129 case ACPI_TYPE_INTEGER:
130
131 /* Output correct integer width */
132
133 if (acpi_gbl_integer_byte_width == 4) {
Len Brown4be44fc2005-08-05 00:44:28 -0400134 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
135 (u32) source_desc->integer.
136 value));
137 } else {
138 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
139 "0x%8.8X%8.8X\n",
140 ACPI_FORMAT_UINT64(source_desc->
141 integer.
142 value)));
Robert Moore44f6c012005-04-18 22:49:35 -0400143 }
144 break;
145
146 case ACPI_TYPE_BUFFER:
147
Len Brown4be44fc2005-08-05 00:44:28 -0400148 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
149 (u32) source_desc->buffer.length));
150 ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
151 (source_desc->buffer.length <
Bob Moore422f4f92008-04-10 19:06:37 +0400152 256) ? source_desc->buffer.length : 256);
Robert Moore44f6c012005-04-18 22:49:35 -0400153 break;
154
155 case ACPI_TYPE_STRING:
156
Len Brown4be44fc2005-08-05 00:44:28 -0400157 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
158 source_desc->string.length,
159 source_desc->string.pointer));
Robert Moore44f6c012005-04-18 22:49:35 -0400160 break;
161
162 case ACPI_TYPE_PACKAGE:
163
Len Brown4be44fc2005-08-05 00:44:28 -0400164 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
165 "[0x%.2X Elements]\n",
166 source_desc->package.count));
Robert Moore44f6c012005-04-18 22:49:35 -0400167
168 /* Output the entire contents of the package */
169
170 for (i = 0; i < source_desc->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400171 acpi_ex_do_debug_object(source_desc->package.
172 elements[i], level + 4, i + 1);
Robert Moore44f6c012005-04-18 22:49:35 -0400173 }
174 break;
175
176 case ACPI_TYPE_LOCAL_REFERENCE:
177
178 if (source_desc->reference.opcode == AML_INDEX_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400179 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
180 "[%s, 0x%X]\n",
181 acpi_ps_get_opcode_name
182 (source_desc->reference.opcode),
183 source_desc->reference.offset));
184 } else {
Bob Moore61ce4212008-04-10 19:06:39 +0400185 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]",
Len Brown4be44fc2005-08-05 00:44:28 -0400186 acpi_ps_get_opcode_name
187 (source_desc->reference.opcode)));
Robert Moore44f6c012005-04-18 22:49:35 -0400188 }
Robert Moore44f6c012005-04-18 22:49:35 -0400189
Bob Moore61ce4212008-04-10 19:06:39 +0400190 if (source_desc->reference.opcode == AML_LOAD_OP) { /* Load and load_table */
191 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
192 " Table OwnerId %X\n",
193 source_desc->reference.object));
194 break;
195 }
196
197 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "\n"));
Robert Moore44f6c012005-04-18 22:49:35 -0400198 if (source_desc->reference.object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400199 if (ACPI_GET_DESCRIPTOR_TYPE
200 (source_desc->reference.object) ==
201 ACPI_DESC_TYPE_NAMED) {
202 acpi_ex_do_debug_object(((struct
203 acpi_namespace_node *)
204 source_desc->reference.
205 object)->object,
206 level + 4, 0);
207 } else {
208 acpi_ex_do_debug_object(source_desc->reference.
209 object, level + 4, 0);
Robert Moore44f6c012005-04-18 22:49:35 -0400210 }
Len Brown4be44fc2005-08-05 00:44:28 -0400211 } else if (source_desc->reference.node) {
Bob Moored8841642008-04-10 19:06:39 +0400212 if (ACPI_GET_DESCRIPTOR_TYPE
213 (source_desc->reference.node) !=
214 ACPI_DESC_TYPE_NAMED) {
215 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
216 " %p - Not a valid namespace node\n"));
217 } else {
218 acpi_ex_do_debug_object((source_desc->reference.
219 node)->object,
220 level + 4, 0);
221 }
Robert Moore44f6c012005-04-18 22:49:35 -0400222 }
223 break;
224
225 default:
226
Len Brown4be44fc2005-08-05 00:44:28 -0400227 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
228 source_desc,
229 acpi_ut_get_object_type_name
230 (source_desc)));
Robert Moore44f6c012005-04-18 22:49:35 -0400231 break;
232 }
233
Len Brown4be44fc2005-08-05 00:44:28 -0400234 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
Robert Moore44f6c012005-04-18 22:49:35 -0400235 return_VOID;
236}
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*******************************************************************************
239 *
240 * FUNCTION: acpi_ex_store
241 *
242 * PARAMETERS: *source_desc - Value to be stored
243 * *dest_desc - Where to store it. Must be an NS node
244 * or an union acpi_operand_object of type
245 * Reference;
246 * walk_state - Current walk state
247 *
248 * RETURN: Status
249 *
250 * DESCRIPTION: Store the value described by source_desc into the location
251 * described by dest_desc. Called by various interpreter
252 * functions to store the result of an operation into
253 * the destination operand -- not just simply the actual "Store"
254 * ASL operator.
255 *
256 ******************************************************************************/
257
258acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400259acpi_ex_store(union acpi_operand_object *source_desc,
260 union acpi_operand_object *dest_desc,
261 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Len Brown4be44fc2005-08-05 00:44:28 -0400263 acpi_status status = AE_OK;
264 union acpi_operand_object *ref_desc = dest_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Bob Mooreb229cf92006-04-21 17:15:00 -0400266 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 /* Validate parameters */
269
270 if (!source_desc || !dest_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500271 ACPI_ERROR((AE_INFO, "Null parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -0400272 return_ACPI_STATUS(AE_AML_NO_OPERAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 /* dest_desc can be either a namespace node or an ACPI object */
276
Len Brown4be44fc2005-08-05 00:44:28 -0400277 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /*
279 * Dest is a namespace node,
280 * Storing an object into a Named node.
281 */
Len Brown4be44fc2005-08-05 00:44:28 -0400282 status = acpi_ex_store_object_to_node(source_desc,
283 (struct
284 acpi_namespace_node *)
285 dest_desc, walk_state,
286 ACPI_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Len Brown4be44fc2005-08-05 00:44:28 -0400288 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290
291 /* Destination object must be a Reference or a Constant object */
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 case ACPI_TYPE_LOCAL_REFERENCE:
295 break;
296
297 case ACPI_TYPE_INTEGER:
298
299 /* Allow stores to Constants -- a Noop as per ACPI spec */
300
301 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400302 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
305 /*lint -fallthrough */
306
307 default:
308
309 /* Destination is not a Reference object */
310
Bob Mooreb8e4d892006-01-27 16:43:00 -0500311 ACPI_ERROR((AE_INFO,
312 "Target is not a Reference or Constant object - %s [%p]",
313 acpi_ut_get_object_type_name(dest_desc),
314 dest_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Len Brown4be44fc2005-08-05 00:44:28 -0400316 ACPI_DUMP_STACK_ENTRY(source_desc);
317 ACPI_DUMP_STACK_ENTRY(dest_desc);
Bob Mooreb229cf92006-04-21 17:15:00 -0400318 ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore",
Len Brown4be44fc2005-08-05 00:44:28 -0400319 2,
320 "Target is not a Reference or Constant object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Len Brown4be44fc2005-08-05 00:44:28 -0400322 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324
325 /*
326 * Examine the Reference opcode. These cases are handled:
327 *
328 * 1) Store to Name (Change the object associated with a name)
329 * 2) Store to an indexed area of a Buffer or Package
330 * 3) Store to a Method Local or Arg
331 * 4) Store to the debug object
332 */
333 switch (ref_desc->reference.opcode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 case AML_REF_OF_OP:
335
336 /* Storing an object into a Name "container" */
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 status = acpi_ex_store_object_to_node(source_desc,
339 ref_desc->reference.
340 object, walk_state,
341 ACPI_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 case AML_INDEX_OP:
345
346 /* Storing to an Index (pointer into a packager or buffer) */
347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 status =
349 acpi_ex_store_object_to_index(source_desc, ref_desc,
350 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 case AML_LOCAL_OP:
354 case AML_ARG_OP:
355
356 /* Store to a method local/arg */
357
Len Brown4be44fc2005-08-05 00:44:28 -0400358 status =
359 acpi_ds_store_object_to_local(ref_desc->reference.opcode,
360 ref_desc->reference.offset,
361 source_desc, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 break;
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 case AML_DEBUG_OP:
365
366 /*
367 * Storing to the Debug object causes the value stored to be
368 * displayed and otherwise has no effect -- see ACPI Specification
369 */
Len Brown4be44fc2005-08-05 00:44:28 -0400370 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
371 "**** Write to Debug Object: Object %p %s ****:\n\n",
372 source_desc,
373 acpi_ut_get_object_type_name(source_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 acpi_ex_do_debug_object(source_desc, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 break;
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 default:
379
Bob Mooreb8e4d892006-01-27 16:43:00 -0500380 ACPI_ERROR((AE_INFO, "Unknown Reference opcode %X",
381 ref_desc->reference.opcode));
Len Brown4be44fc2005-08-05 00:44:28 -0400382 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 status = AE_AML_INTERNAL;
385 break;
386 }
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391/*******************************************************************************
392 *
393 * FUNCTION: acpi_ex_store_object_to_index
394 *
395 * PARAMETERS: *source_desc - Value to be stored
396 * *dest_desc - Named object to receive the value
397 * walk_state - Current walk state
398 *
399 * RETURN: Status
400 *
401 * DESCRIPTION: Store the object to indexed Buffer or Package element
402 *
403 ******************************************************************************/
404
Robert Moore44f6c012005-04-18 22:49:35 -0400405static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400406acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
407 union acpi_operand_object *index_desc,
408 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Len Brown4be44fc2005-08-05 00:44:28 -0400410 acpi_status status = AE_OK;
411 union acpi_operand_object *obj_desc;
412 union acpi_operand_object *new_desc;
413 u8 value = 0;
414 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Bob Mooreb229cf92006-04-21 17:15:00 -0400416 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 /*
419 * Destination must be a reference pointer, and
420 * must point to either a buffer or a package
421 */
422 switch (index_desc->reference.target_type) {
423 case ACPI_TYPE_PACKAGE:
424 /*
425 * Storing to a package element. Copy the object and replace
426 * any existing object with the new object. No implicit
427 * conversion is performed.
428 *
429 * The object at *(index_desc->Reference.Where) is the
430 * element within the package that is to be modified.
431 * The parent package object is at index_desc->Reference.Object
432 */
433 obj_desc = *(index_desc->reference.where);
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 status =
436 acpi_ut_copy_iobject_to_iobject(source_desc, &new_desc,
437 walk_state);
438 if (ACPI_FAILURE(status)) {
439 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 }
441
442 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 /* Decrement reference count by the ref count of the parent package */
445
Len Brown4be44fc2005-08-05 00:44:28 -0400446 for (i = 0; i < ((union acpi_operand_object *)
447 index_desc->reference.object)->common.
448 reference_count; i++) {
449 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451 }
452
453 *(index_desc->reference.where) = new_desc;
454
Robert Moore44f6c012005-04-18 22:49:35 -0400455 /* Increment ref count by the ref count of the parent package-1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 for (i = 1; i < ((union acpi_operand_object *)
458 index_desc->reference.object)->common.
459 reference_count; i++) {
460 acpi_ut_add_reference(new_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 break;
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 case ACPI_TYPE_BUFFER_FIELD:
466
467 /*
468 * Store into a Buffer or String (not actually a real buffer_field)
469 * at a location defined by an Index.
470 *
471 * The first 8-bit element of the source object is written to the
472 * 8-bit Buffer location defined by the Index destination object,
473 * according to the ACPI 2.0 specification.
474 */
475
476 /*
477 * Make sure the target is a Buffer or String. An error should
478 * not happen here, since the reference_object was constructed
479 * by the INDEX_OP code.
480 */
481 obj_desc = index_desc->reference.object;
Len Brown4be44fc2005-08-05 00:44:28 -0400482 if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) &&
483 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) {
484 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486
487 /*
488 * The assignment of the individual elements will be slightly
489 * different for each source type.
490 */
Len Brown4be44fc2005-08-05 00:44:28 -0400491 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 case ACPI_TYPE_INTEGER:
493
494 /* Use the least-significant byte of the integer */
495
496 value = (u8) (source_desc->integer.value);
497 break;
498
499 case ACPI_TYPE_BUFFER:
500 case ACPI_TYPE_STRING:
501
502 /* Note: Takes advantage of common string/buffer fields */
503
504 value = source_desc->buffer.pointer[0];
505 break;
506
507 default:
508
509 /* All other types are invalid */
510
Bob Mooreb8e4d892006-01-27 16:43:00 -0500511 ACPI_ERROR((AE_INFO,
512 "Source must be Integer/Buffer/String type, not %s",
513 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400514 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516
517 /* Store the source value into the target buffer byte */
518
519 obj_desc->buffer.pointer[index_desc->reference.offset] = value;
520 break;
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 default:
Bob Mooreb229cf92006-04-21 17:15:00 -0400523 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 status = AE_AML_OPERAND_TYPE;
525 break;
526 }
527
Len Brown4be44fc2005-08-05 00:44:28 -0400528 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531/*******************************************************************************
532 *
533 * FUNCTION: acpi_ex_store_object_to_node
534 *
535 * PARAMETERS: source_desc - Value to be stored
536 * Node - Named object to receive the value
537 * walk_state - Current walk state
538 * implicit_conversion - Perform implicit conversion (yes/no)
539 *
540 * RETURN: Status
541 *
542 * DESCRIPTION: Store the object to the named object.
543 *
544 * The Assignment of an object to a named object is handled here
545 * The value passed in will replace the current value (if any)
546 * with the input value.
547 *
548 * When storing into an object the data is converted to the
549 * target object type then stored in the object. This means
550 * that the target object type (for an initialized target) will
551 * not be changed by a store operation.
552 *
553 * Assumes parameters are already validated.
554 *
555 ******************************************************************************/
556
557acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400558acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
559 struct acpi_namespace_node *node,
560 struct acpi_walk_state *walk_state,
561 u8 implicit_conversion)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Len Brown4be44fc2005-08-05 00:44:28 -0400563 acpi_status status = AE_OK;
564 union acpi_operand_object *target_desc;
565 union acpi_operand_object *new_desc;
566 acpi_object_type target_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Bob Mooreb229cf92006-04-21 17:15:00 -0400568 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Robert Moore44f6c012005-04-18 22:49:35 -0400570 /* Get current type of the node, and object attached to Node */
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 target_type = acpi_ns_get_type(node);
573 target_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
576 source_desc,
577 acpi_ut_get_object_type_name(source_desc), node,
578 acpi_ut_get_type_name(target_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 /*
581 * Resolve the source object to an actual value
582 * (If it is a reference object)
583 */
Len Brown4be44fc2005-08-05 00:44:28 -0400584 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
585 if (ACPI_FAILURE(status)) {
586 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
589 /* If no implicit conversion, drop into the default case below */
590
Robert Moore6f42ccf2005-05-13 00:00:00 -0400591 if ((!implicit_conversion) || (walk_state->opcode == AML_COPY_OP)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 /* Force execution of default (no implicit conversion) */
594
595 target_type = ACPI_TYPE_ANY;
596 }
597
Robert Moore44f6c012005-04-18 22:49:35 -0400598 /* Do the actual store operation */
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 switch (target_type) {
601 case ACPI_TYPE_BUFFER_FIELD:
602 case ACPI_TYPE_LOCAL_REGION_FIELD:
603 case ACPI_TYPE_LOCAL_BANK_FIELD:
604 case ACPI_TYPE_LOCAL_INDEX_FIELD:
605
Robert Moore44f6c012005-04-18 22:49:35 -0400606 /* For fields, copy the source data to the target field. */
607
Len Brown4be44fc2005-08-05 00:44:28 -0400608 status = acpi_ex_write_data_to_field(source_desc, target_desc,
609 &walk_state->result_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 break;
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 case ACPI_TYPE_INTEGER:
613 case ACPI_TYPE_STRING:
614 case ACPI_TYPE_BUFFER:
615
616 /*
617 * These target types are all of type Integer/String/Buffer, and
618 * therefore support implicit conversion before the store.
619 *
620 * Copy and/or convert the source object to a new target object
621 */
Len Brown4be44fc2005-08-05 00:44:28 -0400622 status =
623 acpi_ex_store_object_to_object(source_desc, target_desc,
624 &new_desc, walk_state);
625 if (ACPI_FAILURE(status)) {
626 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628
629 if (new_desc != target_desc) {
630 /*
631 * Store the new new_desc as the new value of the Name, and set
632 * the Name's type to that of the value being stored in it.
633 * source_desc reference count is incremented by attach_object.
634 *
635 * Note: This may change the type of the node if an explicit store
636 * has been performed such that the node/object type has been
637 * changed.
638 */
Len Brown4be44fc2005-08-05 00:44:28 -0400639 status =
640 acpi_ns_attach_object(node, new_desc,
641 new_desc->common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
644 "Store %s into %s via Convert/Attach\n",
645 acpi_ut_get_object_type_name
646 (source_desc),
647 acpi_ut_get_object_type_name
648 (new_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 break;
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 default:
653
Len Brown4be44fc2005-08-05 00:44:28 -0400654 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
655 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
656 acpi_ut_get_object_type_name(source_desc),
657 source_desc, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* No conversions for all other types. Just attach the source object */
660
Len Brown4be44fc2005-08-05 00:44:28 -0400661 status = acpi_ns_attach_object(node, source_desc,
662 ACPI_GET_OBJECT_TYPE
663 (source_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 break;
665 }
666
Len Brown4be44fc2005-08-05 00:44:28 -0400667 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}