blob: 7c6d7e53e41e7a26ce81f49114da8263db77d003 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04009 * Copyright (C) 2000 - 2008, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acdispat.h"
48#include "acinterp.h"
49#include "amlcode.h"
50#include "acnamesp.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
Bob Moored8846572008-04-10 19:06:43 +040087 /* Print line header as long as we are not in the middle of an object display */
88
89 if (!((level > 0) && index == 0)) {
90 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
91 level, " "));
92 }
Robert Moore44f6c012005-04-18 22:49:35 -040093
94 /* Display index for package output only */
95
96 if (index > 0) {
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
98 "(%.2u) ", index - 1));
Robert Moore44f6c012005-04-18 22:49:35 -040099 }
100
101 if (!source_desc) {
Bob Moored8846572008-04-10 19:06:43 +0400102 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[Null Object]\n"));
Robert Moore44f6c012005-04-18 22:49:35 -0400103 return_VOID;
104 }
105
Len Brown4be44fc2005-08-05 00:44:28 -0400106 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
Bob Moored8846572008-04-10 19:06:43 +0400107 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s ",
Len Brown4be44fc2005-08-05 00:44:28 -0400108 acpi_ut_get_object_type_name
109 (source_desc)));
Robert Moore44f6c012005-04-18 22:49:35 -0400110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 if (!acpi_ut_valid_internal_object(source_desc)) {
112 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
113 "%p, Invalid Internal Object!\n",
114 source_desc));
115 return_VOID;
Robert Moore44f6c012005-04-18 22:49:35 -0400116 }
Len Brown4be44fc2005-08-05 00:44:28 -0400117 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
118 ACPI_DESC_TYPE_NAMED) {
119 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
120 acpi_ut_get_type_name(((struct
121 acpi_namespace_node
122 *)source_desc)->
123 type),
124 source_desc));
Robert Moore44f6c012005-04-18 22:49:35 -0400125 return_VOID;
Len Brown4be44fc2005-08-05 00:44:28 -0400126 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400127 return_VOID;
128 }
129
Bob Moore61ce4212008-04-10 19:06:39 +0400130 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
Robert Moore44f6c012005-04-18 22:49:35 -0400133 case ACPI_TYPE_INTEGER:
134
135 /* Output correct integer width */
136
137 if (acpi_gbl_integer_byte_width == 4) {
Len Brown4be44fc2005-08-05 00:44:28 -0400138 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
139 (u32) source_desc->integer.
140 value));
141 } else {
142 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
143 "0x%8.8X%8.8X\n",
144 ACPI_FORMAT_UINT64(source_desc->
145 integer.
146 value)));
Robert Moore44f6c012005-04-18 22:49:35 -0400147 }
148 break;
149
150 case ACPI_TYPE_BUFFER:
151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
153 (u32) source_desc->buffer.length));
154 ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
155 (source_desc->buffer.length <
Bob Moore422f4f92008-04-10 19:06:37 +0400156 256) ? source_desc->buffer.length : 256);
Robert Moore44f6c012005-04-18 22:49:35 -0400157 break;
158
159 case ACPI_TYPE_STRING:
160
Len Brown4be44fc2005-08-05 00:44:28 -0400161 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
162 source_desc->string.length,
163 source_desc->string.pointer));
Robert Moore44f6c012005-04-18 22:49:35 -0400164 break;
165
166 case ACPI_TYPE_PACKAGE:
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
Bob Moored8846572008-04-10 19:06:43 +0400169 "[Contains 0x%.2X Elements]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400170 source_desc->package.count));
Robert Moore44f6c012005-04-18 22:49:35 -0400171
172 /* Output the entire contents of the package */
173
174 for (i = 0; i < source_desc->package.count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400175 acpi_ex_do_debug_object(source_desc->package.
176 elements[i], level + 4, i + 1);
Robert Moore44f6c012005-04-18 22:49:35 -0400177 }
178 break;
179
180 case ACPI_TYPE_LOCAL_REFERENCE:
181
Bob Moore1044f1f2008-09-27 11:08:41 +0800182 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s] ",
183 acpi_ut_get_reference_name(source_desc)));
Robert Moore44f6c012005-04-18 22:49:35 -0400184
Bob Moore1044f1f2008-09-27 11:08:41 +0800185 /* Decode the reference */
186
187 switch (source_desc->reference.class) {
188 case ACPI_REFCLASS_INDEX:
189
190 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%X\n",
Bob Moore57e664c2008-09-27 10:40:39 +0800191 source_desc->reference.value));
Bob Moore61ce4212008-04-10 19:06:39 +0400192 break;
Bob Moore1044f1f2008-09-27 11:08:41 +0800193
194 case ACPI_REFCLASS_TABLE:
195
196 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
197 "Table Index 0x%X\n",
198 source_desc->reference.value));
199 break;
200
201 default:
202 break;
Bob Moore61ce4212008-04-10 19:06:39 +0400203 }
204
Bob Moored8846572008-04-10 19:06:43 +0400205 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, " "));
206
207 /* Check for valid node first, then valid object */
208
209 if (source_desc->reference.node) {
210 if (ACPI_GET_DESCRIPTOR_TYPE
211 (source_desc->reference.node) !=
212 ACPI_DESC_TYPE_NAMED) {
213 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
214 " %p - Not a valid namespace node\n",
215 source_desc->reference.
216 node));
217 } else {
218 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
219 "Node %p [%4.4s] ",
220 source_desc->reference.
221 node,
222 (source_desc->reference.
223 node)->name.ascii));
224
225 switch ((source_desc->reference.node)->type) {
226
227 /* These types have no attached object */
228
229 case ACPI_TYPE_DEVICE:
230 acpi_os_printf("Device\n");
231 break;
232
233 case ACPI_TYPE_THERMAL:
234 acpi_os_printf("Thermal Zone\n");
235 break;
236
237 default:
238 acpi_ex_do_debug_object((source_desc->
239 reference.
240 node)->object,
241 level + 4, 0);
242 break;
243 }
244 }
245 } else if (source_desc->reference.object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400246 if (ACPI_GET_DESCRIPTOR_TYPE
247 (source_desc->reference.object) ==
248 ACPI_DESC_TYPE_NAMED) {
249 acpi_ex_do_debug_object(((struct
250 acpi_namespace_node *)
251 source_desc->reference.
252 object)->object,
253 level + 4, 0);
254 } else {
255 acpi_ex_do_debug_object(source_desc->reference.
256 object, level + 4, 0);
Robert Moore44f6c012005-04-18 22:49:35 -0400257 }
Robert Moore44f6c012005-04-18 22:49:35 -0400258 }
259 break;
260
261 default:
262
Bob Moored8846572008-04-10 19:06:43 +0400263 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p\n",
264 source_desc));
Robert Moore44f6c012005-04-18 22:49:35 -0400265 break;
266 }
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
Robert Moore44f6c012005-04-18 22:49:35 -0400269 return_VOID;
270}
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272/*******************************************************************************
273 *
274 * FUNCTION: acpi_ex_store
275 *
276 * PARAMETERS: *source_desc - Value to be stored
277 * *dest_desc - Where to store it. Must be an NS node
278 * or an union acpi_operand_object of type
279 * Reference;
280 * walk_state - Current walk state
281 *
282 * RETURN: Status
283 *
284 * DESCRIPTION: Store the value described by source_desc into the location
285 * described by dest_desc. Called by various interpreter
286 * functions to store the result of an operation into
287 * the destination operand -- not just simply the actual "Store"
288 * ASL operator.
289 *
290 ******************************************************************************/
291
292acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400293acpi_ex_store(union acpi_operand_object *source_desc,
294 union acpi_operand_object *dest_desc,
295 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Len Brown4be44fc2005-08-05 00:44:28 -0400297 acpi_status status = AE_OK;
298 union acpi_operand_object *ref_desc = dest_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Bob Mooreb229cf92006-04-21 17:15:00 -0400300 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 /* Validate parameters */
303
304 if (!source_desc || !dest_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500305 ACPI_ERROR((AE_INFO, "Null parameter"));
Len Brown4be44fc2005-08-05 00:44:28 -0400306 return_ACPI_STATUS(AE_AML_NO_OPERAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308
309 /* dest_desc can be either a namespace node or an ACPI object */
310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 /*
313 * Dest is a namespace node,
314 * Storing an object into a Named node.
315 */
Len Brown4be44fc2005-08-05 00:44:28 -0400316 status = acpi_ex_store_object_to_node(source_desc,
317 (struct
318 acpi_namespace_node *)
319 dest_desc, walk_state,
320 ACPI_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Len Brown4be44fc2005-08-05 00:44:28 -0400322 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324
325 /* Destination object must be a Reference or a Constant object */
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 case ACPI_TYPE_LOCAL_REFERENCE:
329 break;
330
331 case ACPI_TYPE_INTEGER:
332
333 /* Allow stores to Constants -- a Noop as per ACPI spec */
334
335 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400336 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338
339 /*lint -fallthrough */
340
341 default:
342
343 /* Destination is not a Reference object */
344
Bob Mooreb8e4d892006-01-27 16:43:00 -0500345 ACPI_ERROR((AE_INFO,
346 "Target is not a Reference or Constant object - %s [%p]",
347 acpi_ut_get_object_type_name(dest_desc),
348 dest_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
353 /*
Bob Moore1044f1f2008-09-27 11:08:41 +0800354 * Examine the Reference class. These cases are handled:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 *
356 * 1) Store to Name (Change the object associated with a name)
357 * 2) Store to an indexed area of a Buffer or Package
358 * 3) Store to a Method Local or Arg
359 * 4) Store to the debug object
360 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800361 switch (ref_desc->reference.class) {
362 case ACPI_REFCLASS_REFOF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 /* Storing an object into a Name "container" */
365
Len Brown4be44fc2005-08-05 00:44:28 -0400366 status = acpi_ex_store_object_to_node(source_desc,
367 ref_desc->reference.
368 object, walk_state,
369 ACPI_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 break;
371
Bob Moore1044f1f2008-09-27 11:08:41 +0800372 case ACPI_REFCLASS_INDEX:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 /* Storing to an Index (pointer into a packager or buffer) */
375
Len Brown4be44fc2005-08-05 00:44:28 -0400376 status =
377 acpi_ex_store_object_to_index(source_desc, ref_desc,
378 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 break;
380
Bob Moore1044f1f2008-09-27 11:08:41 +0800381 case ACPI_REFCLASS_LOCAL:
382 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 /* Store to a method local/arg */
385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 status =
Bob Moore1044f1f2008-09-27 11:08:41 +0800387 acpi_ds_store_object_to_local(ref_desc->reference.class,
388 ref_desc->reference.value,
Len Brown4be44fc2005-08-05 00:44:28 -0400389 source_desc, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 break;
391
Bob Moore1044f1f2008-09-27 11:08:41 +0800392 case ACPI_REFCLASS_DEBUG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 /*
395 * Storing to the Debug object causes the value stored to be
396 * displayed and otherwise has no effect -- see ACPI Specification
397 */
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
399 "**** Write to Debug Object: Object %p %s ****:\n\n",
400 source_desc,
401 acpi_ut_get_object_type_name(source_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 acpi_ex_do_debug_object(source_desc, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 break;
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 default:
407
Bob Moore1044f1f2008-09-27 11:08:41 +0800408 ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X",
409 ref_desc->reference.class));
Bob Moore23d3e052008-09-28 15:00:47 +0800410 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 status = AE_AML_INTERNAL;
413 break;
414 }
415
Len Brown4be44fc2005-08-05 00:44:28 -0400416 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419/*******************************************************************************
420 *
421 * FUNCTION: acpi_ex_store_object_to_index
422 *
423 * PARAMETERS: *source_desc - Value to be stored
424 * *dest_desc - Named object to receive the value
425 * walk_state - Current walk state
426 *
427 * RETURN: Status
428 *
429 * DESCRIPTION: Store the object to indexed Buffer or Package element
430 *
431 ******************************************************************************/
432
Robert Moore44f6c012005-04-18 22:49:35 -0400433static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400434acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
435 union acpi_operand_object *index_desc,
436 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Len Brown4be44fc2005-08-05 00:44:28 -0400438 acpi_status status = AE_OK;
439 union acpi_operand_object *obj_desc;
440 union acpi_operand_object *new_desc;
441 u8 value = 0;
442 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Bob Mooreb229cf92006-04-21 17:15:00 -0400444 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 /*
447 * Destination must be a reference pointer, and
448 * must point to either a buffer or a package
449 */
450 switch (index_desc->reference.target_type) {
451 case ACPI_TYPE_PACKAGE:
452 /*
453 * Storing to a package element. Copy the object and replace
454 * any existing object with the new object. No implicit
455 * conversion is performed.
456 *
457 * The object at *(index_desc->Reference.Where) is the
458 * element within the package that is to be modified.
459 * The parent package object is at index_desc->Reference.Object
460 */
461 obj_desc = *(index_desc->reference.where);
462
Lin Mingbc7a36a2008-04-10 19:06:42 +0400463 if (ACPI_GET_OBJECT_TYPE(source_desc) ==
464 ACPI_TYPE_LOCAL_REFERENCE
Bob Moore1044f1f2008-09-27 11:08:41 +0800465 && source_desc->reference.class == ACPI_REFCLASS_TABLE) {
Lin Mingbc7a36a2008-04-10 19:06:42 +0400466
467 /* This is a DDBHandle, just add a reference to it */
468
469 acpi_ut_add_reference(source_desc);
470 new_desc = source_desc;
471 } else {
472 /* Normal object, copy it */
473
474 status =
475 acpi_ut_copy_iobject_to_iobject(source_desc,
476 &new_desc,
477 walk_state);
478 if (ACPI_FAILURE(status)) {
479 return_ACPI_STATUS(status);
480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482
483 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Decrement reference count by the ref count of the parent package */
486
Len Brown4be44fc2005-08-05 00:44:28 -0400487 for (i = 0; i < ((union acpi_operand_object *)
488 index_desc->reference.object)->common.
489 reference_count; i++) {
490 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492 }
493
494 *(index_desc->reference.where) = new_desc;
495
Robert Moore44f6c012005-04-18 22:49:35 -0400496 /* Increment ref count by the ref count of the parent package-1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Len Brown4be44fc2005-08-05 00:44:28 -0400498 for (i = 1; i < ((union acpi_operand_object *)
499 index_desc->reference.object)->common.
500 reference_count; i++) {
501 acpi_ut_add_reference(new_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
504 break;
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 case ACPI_TYPE_BUFFER_FIELD:
507
508 /*
509 * Store into a Buffer or String (not actually a real buffer_field)
510 * at a location defined by an Index.
511 *
512 * The first 8-bit element of the source object is written to the
513 * 8-bit Buffer location defined by the Index destination object,
514 * according to the ACPI 2.0 specification.
515 */
516
517 /*
518 * Make sure the target is a Buffer or String. An error should
519 * not happen here, since the reference_object was constructed
520 * by the INDEX_OP code.
521 */
522 obj_desc = index_desc->reference.object;
Len Brown4be44fc2005-08-05 00:44:28 -0400523 if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) &&
524 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) {
525 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
528 /*
529 * The assignment of the individual elements will be slightly
530 * different for each source type.
531 */
Len Brown4be44fc2005-08-05 00:44:28 -0400532 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 case ACPI_TYPE_INTEGER:
534
535 /* Use the least-significant byte of the integer */
536
537 value = (u8) (source_desc->integer.value);
538 break;
539
540 case ACPI_TYPE_BUFFER:
541 case ACPI_TYPE_STRING:
542
543 /* Note: Takes advantage of common string/buffer fields */
544
545 value = source_desc->buffer.pointer[0];
546 break;
547
548 default:
549
550 /* All other types are invalid */
551
Bob Mooreb8e4d892006-01-27 16:43:00 -0500552 ACPI_ERROR((AE_INFO,
553 "Source must be Integer/Buffer/String type, not %s",
554 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400555 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557
558 /* Store the source value into the target buffer byte */
559
Bob Moore1044f1f2008-09-27 11:08:41 +0800560 obj_desc->buffer.pointer[index_desc->reference.value] = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 break;
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 default:
Bob Mooreb229cf92006-04-21 17:15:00 -0400564 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 status = AE_AML_OPERAND_TYPE;
566 break;
567 }
568
Len Brown4be44fc2005-08-05 00:44:28 -0400569 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572/*******************************************************************************
573 *
574 * FUNCTION: acpi_ex_store_object_to_node
575 *
576 * PARAMETERS: source_desc - Value to be stored
577 * Node - Named object to receive the value
578 * walk_state - Current walk state
579 * implicit_conversion - Perform implicit conversion (yes/no)
580 *
581 * RETURN: Status
582 *
583 * DESCRIPTION: Store the object to the named object.
584 *
585 * The Assignment of an object to a named object is handled here
586 * The value passed in will replace the current value (if any)
587 * with the input value.
588 *
589 * When storing into an object the data is converted to the
590 * target object type then stored in the object. This means
591 * that the target object type (for an initialized target) will
592 * not be changed by a store operation.
593 *
594 * Assumes parameters are already validated.
595 *
596 ******************************************************************************/
597
598acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400599acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
600 struct acpi_namespace_node *node,
601 struct acpi_walk_state *walk_state,
602 u8 implicit_conversion)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Len Brown4be44fc2005-08-05 00:44:28 -0400604 acpi_status status = AE_OK;
605 union acpi_operand_object *target_desc;
606 union acpi_operand_object *new_desc;
607 acpi_object_type target_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Bob Mooreb229cf92006-04-21 17:15:00 -0400609 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Robert Moore44f6c012005-04-18 22:49:35 -0400611 /* Get current type of the node, and object attached to Node */
612
Len Brown4be44fc2005-08-05 00:44:28 -0400613 target_type = acpi_ns_get_type(node);
614 target_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
617 source_desc,
618 acpi_ut_get_object_type_name(source_desc), node,
619 acpi_ut_get_type_name(target_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 /*
622 * Resolve the source object to an actual value
623 * (If it is a reference object)
624 */
Len Brown4be44fc2005-08-05 00:44:28 -0400625 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
626 if (ACPI_FAILURE(status)) {
627 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
630 /* If no implicit conversion, drop into the default case below */
631
Lin Minga3df4da2008-04-10 19:06:43 +0400632 if ((!implicit_conversion) ||
633 ((walk_state->opcode == AML_COPY_OP) &&
634 (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) &&
635 (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) &&
636 (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) {
637 /*
638 * Force execution of default (no implicit conversion). Note:
639 * copy_object does not perform an implicit conversion, as per the ACPI
640 * spec -- except in case of region/bank/index fields -- because these
641 * objects must retain their original type permanently.
642 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 target_type = ACPI_TYPE_ANY;
644 }
645
Robert Moore44f6c012005-04-18 22:49:35 -0400646 /* Do the actual store operation */
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 switch (target_type) {
649 case ACPI_TYPE_BUFFER_FIELD:
650 case ACPI_TYPE_LOCAL_REGION_FIELD:
651 case ACPI_TYPE_LOCAL_BANK_FIELD:
652 case ACPI_TYPE_LOCAL_INDEX_FIELD:
653
Robert Moore44f6c012005-04-18 22:49:35 -0400654 /* For fields, copy the source data to the target field. */
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 status = acpi_ex_write_data_to_field(source_desc, target_desc,
657 &walk_state->result_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 break;
659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 case ACPI_TYPE_INTEGER:
661 case ACPI_TYPE_STRING:
662 case ACPI_TYPE_BUFFER:
663
664 /*
665 * These target types are all of type Integer/String/Buffer, and
666 * therefore support implicit conversion before the store.
667 *
668 * Copy and/or convert the source object to a new target object
669 */
Len Brown4be44fc2005-08-05 00:44:28 -0400670 status =
671 acpi_ex_store_object_to_object(source_desc, target_desc,
672 &new_desc, walk_state);
673 if (ACPI_FAILURE(status)) {
674 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
676
677 if (new_desc != target_desc) {
678 /*
679 * Store the new new_desc as the new value of the Name, and set
680 * the Name's type to that of the value being stored in it.
681 * source_desc reference count is incremented by attach_object.
682 *
683 * Note: This may change the type of the node if an explicit store
684 * has been performed such that the node/object type has been
685 * changed.
686 */
Len Brown4be44fc2005-08-05 00:44:28 -0400687 status =
688 acpi_ns_attach_object(node, new_desc,
689 new_desc->common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
692 "Store %s into %s via Convert/Attach\n",
693 acpi_ut_get_object_type_name
694 (source_desc),
695 acpi_ut_get_object_type_name
696 (new_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 }
698 break;
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 default:
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
703 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
704 acpi_ut_get_object_type_name(source_desc),
705 source_desc, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 /* No conversions for all other types. Just attach the source object */
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 status = acpi_ns_attach_object(node, source_desc,
710 ACPI_GET_OBJECT_TYPE
711 (source_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 break;
713 }
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}