Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exstore - AML Interpreter object store support | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
6c9deb72 | 9 | * Copyright (C) 2000 - 2007, R. Byron Moore |
1da177e4 LT |
10 | * 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 | ||
1da177e4 LT |
45 | #include <acpi/acpi.h> |
46 | #include <acpi/acdispat.h> | |
47 | #include <acpi/acinterp.h> | |
48 | #include <acpi/amlcode.h> | |
49 | #include <acpi/acnamesp.h> | |
44f6c012 | 50 | #include <acpi/acparser.h> |
1da177e4 | 51 | |
1da177e4 | 52 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 53 | ACPI_MODULE_NAME("exstore") |
1da177e4 | 54 | |
44f6c012 | 55 | /* Local prototypes */ |
44f6c012 | 56 | static void |
4be44fcd LB |
57 | acpi_ex_do_debug_object(union acpi_operand_object *source_desc, |
58 | u32 level, u32 index); | |
44f6c012 RM |
59 | |
60 | static acpi_status | |
4be44fcd LB |
61 | acpi_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); | |
44f6c012 RM |
64 | |
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 | ||
79 | static void | |
4be44fcd LB |
80 | acpi_ex_do_debug_object(union acpi_operand_object *source_desc, |
81 | u32 level, u32 index) | |
44f6c012 | 82 | { |
4be44fcd | 83 | u32 i; |
44f6c012 | 84 | |
b229cf92 | 85 | ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc); |
44f6c012 | 86 | |
4be44fcd LB |
87 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s", |
88 | level, " ")); | |
44f6c012 RM |
89 | |
90 | /* Display index for package output only */ | |
91 | ||
92 | if (index > 0) { | |
4be44fcd LB |
93 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, |
94 | "(%.2u) ", index - 1)); | |
44f6c012 RM |
95 | } |
96 | ||
97 | if (!source_desc) { | |
4be44fcd | 98 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n")); |
44f6c012 RM |
99 | return_VOID; |
100 | } | |
101 | ||
4be44fcd LB |
102 | 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))); | |
44f6c012 | 106 | |
4be44fcd LB |
107 | 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; | |
44f6c012 | 112 | } |
4be44fcd LB |
113 | } 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)); | |
44f6c012 | 121 | return_VOID; |
4be44fcd | 122 | } else { |
44f6c012 RM |
123 | return_VOID; |
124 | } | |
125 | ||
61ce421b BM |
126 | /* source_desc is of type ACPI_DESC_TYPE_OPERAND */ |
127 | ||
4be44fcd | 128 | switch (ACPI_GET_OBJECT_TYPE(source_desc)) { |
44f6c012 RM |
129 | case ACPI_TYPE_INTEGER: |
130 | ||
131 | /* Output correct integer width */ | |
132 | ||
133 | if (acpi_gbl_integer_byte_width == 4) { | |
4be44fcd LB |
134 | 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))); | |
44f6c012 RM |
143 | } |
144 | break; | |
145 | ||
146 | case ACPI_TYPE_BUFFER: | |
147 | ||
4be44fcd LB |
148 | 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 < | |
422f4f90 | 152 | 256) ? source_desc->buffer.length : 256); |
44f6c012 RM |
153 | break; |
154 | ||
155 | case ACPI_TYPE_STRING: | |
156 | ||
4be44fcd LB |
157 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n", |
158 | source_desc->string.length, | |
159 | source_desc->string.pointer)); | |
44f6c012 RM |
160 | break; |
161 | ||
162 | case ACPI_TYPE_PACKAGE: | |
163 | ||
4be44fcd LB |
164 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, |
165 | "[0x%.2X Elements]\n", | |
166 | source_desc->package.count)); | |
44f6c012 RM |
167 | |
168 | /* Output the entire contents of the package */ | |
169 | ||
170 | for (i = 0; i < source_desc->package.count; i++) { | |
4be44fcd LB |
171 | acpi_ex_do_debug_object(source_desc->package. |
172 | elements[i], level + 4, i + 1); | |
44f6c012 RM |
173 | } |
174 | break; | |
175 | ||
176 | case ACPI_TYPE_LOCAL_REFERENCE: | |
177 | ||
178 | if (source_desc->reference.opcode == AML_INDEX_OP) { | |
4be44fcd LB |
179 | 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 { | |
61ce421b | 185 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]", |
4be44fcd LB |
186 | acpi_ps_get_opcode_name |
187 | (source_desc->reference.opcode))); | |
44f6c012 | 188 | } |
44f6c012 | 189 | |
61ce421b BM |
190 | if (source_desc->reference.opcode == AML_LOAD_OP) { /* Load and load_table */ |
191 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, | |
b7f9f042 | 192 | " Table OwnerId %p\n", |
61ce421b BM |
193 | source_desc->reference.object)); |
194 | break; | |
195 | } | |
196 | ||
197 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "\n")); | |
44f6c012 | 198 | if (source_desc->reference.object) { |
4be44fcd LB |
199 | 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); | |
44f6c012 | 210 | } |
4be44fcd | 211 | } else if (source_desc->reference.node) { |
d8841647 BM |
212 | if (ACPI_GET_DESCRIPTOR_TYPE |
213 | (source_desc->reference.node) != | |
214 | ACPI_DESC_TYPE_NAMED) { | |
215 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, | |
b7f9f042 BM |
216 | " %p - Not a valid namespace node\n", |
217 | source_desc->reference. | |
218 | node)); | |
d8841647 BM |
219 | } else { |
220 | acpi_ex_do_debug_object((source_desc->reference. | |
221 | node)->object, | |
222 | level + 4, 0); | |
223 | } | |
44f6c012 RM |
224 | } |
225 | break; | |
226 | ||
227 | default: | |
228 | ||
4be44fcd LB |
229 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p %s\n", |
230 | source_desc, | |
231 | acpi_ut_get_object_type_name | |
232 | (source_desc))); | |
44f6c012 RM |
233 | break; |
234 | } | |
235 | ||
4be44fcd | 236 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n")); |
44f6c012 RM |
237 | return_VOID; |
238 | } | |
239 | ||
1da177e4 LT |
240 | /******************************************************************************* |
241 | * | |
242 | * FUNCTION: acpi_ex_store | |
243 | * | |
244 | * PARAMETERS: *source_desc - Value to be stored | |
245 | * *dest_desc - Where to store it. Must be an NS node | |
246 | * or an union acpi_operand_object of type | |
247 | * Reference; | |
248 | * walk_state - Current walk state | |
249 | * | |
250 | * RETURN: Status | |
251 | * | |
252 | * DESCRIPTION: Store the value described by source_desc into the location | |
253 | * described by dest_desc. Called by various interpreter | |
254 | * functions to store the result of an operation into | |
255 | * the destination operand -- not just simply the actual "Store" | |
256 | * ASL operator. | |
257 | * | |
258 | ******************************************************************************/ | |
259 | ||
260 | acpi_status | |
4be44fcd LB |
261 | acpi_ex_store(union acpi_operand_object *source_desc, |
262 | union acpi_operand_object *dest_desc, | |
263 | struct acpi_walk_state *walk_state) | |
1da177e4 | 264 | { |
4be44fcd LB |
265 | acpi_status status = AE_OK; |
266 | union acpi_operand_object *ref_desc = dest_desc; | |
1da177e4 | 267 | |
b229cf92 | 268 | ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc); |
1da177e4 LT |
269 | |
270 | /* Validate parameters */ | |
271 | ||
272 | if (!source_desc || !dest_desc) { | |
b8e4d893 | 273 | ACPI_ERROR((AE_INFO, "Null parameter")); |
4be44fcd | 274 | return_ACPI_STATUS(AE_AML_NO_OPERAND); |
1da177e4 LT |
275 | } |
276 | ||
277 | /* dest_desc can be either a namespace node or an ACPI object */ | |
278 | ||
4be44fcd | 279 | if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) { |
1da177e4 LT |
280 | /* |
281 | * Dest is a namespace node, | |
282 | * Storing an object into a Named node. | |
283 | */ | |
4be44fcd LB |
284 | status = acpi_ex_store_object_to_node(source_desc, |
285 | (struct | |
286 | acpi_namespace_node *) | |
287 | dest_desc, walk_state, | |
288 | ACPI_IMPLICIT_CONVERSION); | |
1da177e4 | 289 | |
4be44fcd | 290 | return_ACPI_STATUS(status); |
1da177e4 LT |
291 | } |
292 | ||
293 | /* Destination object must be a Reference or a Constant object */ | |
294 | ||
4be44fcd | 295 | switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { |
1da177e4 LT |
296 | case ACPI_TYPE_LOCAL_REFERENCE: |
297 | break; | |
298 | ||
299 | case ACPI_TYPE_INTEGER: | |
300 | ||
301 | /* Allow stores to Constants -- a Noop as per ACPI spec */ | |
302 | ||
303 | if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) { | |
4be44fcd | 304 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
305 | } |
306 | ||
307 | /*lint -fallthrough */ | |
308 | ||
309 | default: | |
310 | ||
311 | /* Destination is not a Reference object */ | |
312 | ||
b8e4d893 BM |
313 | ACPI_ERROR((AE_INFO, |
314 | "Target is not a Reference or Constant object - %s [%p]", | |
315 | acpi_ut_get_object_type_name(dest_desc), | |
316 | dest_desc)); | |
1da177e4 | 317 | |
4be44fcd LB |
318 | ACPI_DUMP_STACK_ENTRY(source_desc); |
319 | ACPI_DUMP_STACK_ENTRY(dest_desc); | |
b229cf92 | 320 | ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore", |
4be44fcd LB |
321 | 2, |
322 | "Target is not a Reference or Constant object"); | |
1da177e4 | 323 | |
4be44fcd | 324 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
325 | } |
326 | ||
327 | /* | |
328 | * Examine the Reference opcode. These cases are handled: | |
329 | * | |
330 | * 1) Store to Name (Change the object associated with a name) | |
331 | * 2) Store to an indexed area of a Buffer or Package | |
332 | * 3) Store to a Method Local or Arg | |
333 | * 4) Store to the debug object | |
334 | */ | |
335 | switch (ref_desc->reference.opcode) { | |
1da177e4 LT |
336 | case AML_REF_OF_OP: |
337 | ||
338 | /* Storing an object into a Name "container" */ | |
339 | ||
4be44fcd LB |
340 | status = acpi_ex_store_object_to_node(source_desc, |
341 | ref_desc->reference. | |
342 | object, walk_state, | |
343 | ACPI_IMPLICIT_CONVERSION); | |
1da177e4 LT |
344 | break; |
345 | ||
1da177e4 LT |
346 | case AML_INDEX_OP: |
347 | ||
348 | /* Storing to an Index (pointer into a packager or buffer) */ | |
349 | ||
4be44fcd LB |
350 | status = |
351 | acpi_ex_store_object_to_index(source_desc, ref_desc, | |
352 | walk_state); | |
1da177e4 LT |
353 | break; |
354 | ||
1da177e4 LT |
355 | case AML_LOCAL_OP: |
356 | case AML_ARG_OP: | |
357 | ||
358 | /* Store to a method local/arg */ | |
359 | ||
4be44fcd LB |
360 | status = |
361 | acpi_ds_store_object_to_local(ref_desc->reference.opcode, | |
362 | ref_desc->reference.offset, | |
363 | source_desc, walk_state); | |
1da177e4 LT |
364 | break; |
365 | ||
1da177e4 LT |
366 | case AML_DEBUG_OP: |
367 | ||
368 | /* | |
369 | * Storing to the Debug object causes the value stored to be | |
370 | * displayed and otherwise has no effect -- see ACPI Specification | |
371 | */ | |
4be44fcd LB |
372 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
373 | "**** Write to Debug Object: Object %p %s ****:\n\n", | |
374 | source_desc, | |
375 | acpi_ut_get_object_type_name(source_desc))); | |
1da177e4 | 376 | |
4be44fcd | 377 | acpi_ex_do_debug_object(source_desc, 0, 0); |
1da177e4 LT |
378 | break; |
379 | ||
1da177e4 LT |
380 | default: |
381 | ||
b8e4d893 BM |
382 | ACPI_ERROR((AE_INFO, "Unknown Reference opcode %X", |
383 | ref_desc->reference.opcode)); | |
4be44fcd | 384 | ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_ERROR); |
1da177e4 LT |
385 | |
386 | status = AE_AML_INTERNAL; | |
387 | break; | |
388 | } | |
389 | ||
4be44fcd | 390 | return_ACPI_STATUS(status); |
1da177e4 LT |
391 | } |
392 | ||
1da177e4 LT |
393 | /******************************************************************************* |
394 | * | |
395 | * FUNCTION: acpi_ex_store_object_to_index | |
396 | * | |
397 | * PARAMETERS: *source_desc - Value to be stored | |
398 | * *dest_desc - Named object to receive the value | |
399 | * walk_state - Current walk state | |
400 | * | |
401 | * RETURN: Status | |
402 | * | |
403 | * DESCRIPTION: Store the object to indexed Buffer or Package element | |
404 | * | |
405 | ******************************************************************************/ | |
406 | ||
44f6c012 | 407 | static acpi_status |
4be44fcd LB |
408 | acpi_ex_store_object_to_index(union acpi_operand_object *source_desc, |
409 | union acpi_operand_object *index_desc, | |
410 | struct acpi_walk_state *walk_state) | |
1da177e4 | 411 | { |
4be44fcd LB |
412 | acpi_status status = AE_OK; |
413 | union acpi_operand_object *obj_desc; | |
414 | union acpi_operand_object *new_desc; | |
415 | u8 value = 0; | |
416 | u32 i; | |
1da177e4 | 417 | |
b229cf92 | 418 | ACPI_FUNCTION_TRACE(ex_store_object_to_index); |
1da177e4 LT |
419 | |
420 | /* | |
421 | * Destination must be a reference pointer, and | |
422 | * must point to either a buffer or a package | |
423 | */ | |
424 | switch (index_desc->reference.target_type) { | |
425 | case ACPI_TYPE_PACKAGE: | |
426 | /* | |
427 | * Storing to a package element. Copy the object and replace | |
428 | * any existing object with the new object. No implicit | |
429 | * conversion is performed. | |
430 | * | |
431 | * The object at *(index_desc->Reference.Where) is the | |
432 | * element within the package that is to be modified. | |
433 | * The parent package object is at index_desc->Reference.Object | |
434 | */ | |
435 | obj_desc = *(index_desc->reference.where); | |
436 | ||
bc7a36ab LM |
437 | if (ACPI_GET_OBJECT_TYPE(source_desc) == |
438 | ACPI_TYPE_LOCAL_REFERENCE | |
439 | && source_desc->reference.opcode == AML_LOAD_OP) { | |
440 | ||
441 | /* This is a DDBHandle, just add a reference to it */ | |
442 | ||
443 | acpi_ut_add_reference(source_desc); | |
444 | new_desc = source_desc; | |
445 | } else { | |
446 | /* Normal object, copy it */ | |
447 | ||
448 | status = | |
449 | acpi_ut_copy_iobject_to_iobject(source_desc, | |
450 | &new_desc, | |
451 | walk_state); | |
452 | if (ACPI_FAILURE(status)) { | |
453 | return_ACPI_STATUS(status); | |
454 | } | |
1da177e4 LT |
455 | } |
456 | ||
457 | if (obj_desc) { | |
52fc0b02 | 458 | |
1da177e4 LT |
459 | /* Decrement reference count by the ref count of the parent package */ |
460 | ||
4be44fcd LB |
461 | for (i = 0; i < ((union acpi_operand_object *) |
462 | index_desc->reference.object)->common. | |
463 | reference_count; i++) { | |
464 | acpi_ut_remove_reference(obj_desc); | |
1da177e4 LT |
465 | } |
466 | } | |
467 | ||
468 | *(index_desc->reference.where) = new_desc; | |
469 | ||
44f6c012 | 470 | /* Increment ref count by the ref count of the parent package-1 */ |
1da177e4 | 471 | |
4be44fcd LB |
472 | for (i = 1; i < ((union acpi_operand_object *) |
473 | index_desc->reference.object)->common. | |
474 | reference_count; i++) { | |
475 | acpi_ut_add_reference(new_desc); | |
1da177e4 LT |
476 | } |
477 | ||
478 | break; | |
479 | ||
1da177e4 LT |
480 | case ACPI_TYPE_BUFFER_FIELD: |
481 | ||
482 | /* | |
483 | * Store into a Buffer or String (not actually a real buffer_field) | |
484 | * at a location defined by an Index. | |
485 | * | |
486 | * The first 8-bit element of the source object is written to the | |
487 | * 8-bit Buffer location defined by the Index destination object, | |
488 | * according to the ACPI 2.0 specification. | |
489 | */ | |
490 | ||
491 | /* | |
492 | * Make sure the target is a Buffer or String. An error should | |
493 | * not happen here, since the reference_object was constructed | |
494 | * by the INDEX_OP code. | |
495 | */ | |
496 | obj_desc = index_desc->reference.object; | |
4be44fcd LB |
497 | if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) && |
498 | (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) { | |
499 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | |
1da177e4 LT |
500 | } |
501 | ||
502 | /* | |
503 | * The assignment of the individual elements will be slightly | |
504 | * different for each source type. | |
505 | */ | |
4be44fcd | 506 | switch (ACPI_GET_OBJECT_TYPE(source_desc)) { |
1da177e4 LT |
507 | case ACPI_TYPE_INTEGER: |
508 | ||
509 | /* Use the least-significant byte of the integer */ | |
510 | ||
511 | value = (u8) (source_desc->integer.value); | |
512 | break; | |
513 | ||
514 | case ACPI_TYPE_BUFFER: | |
515 | case ACPI_TYPE_STRING: | |
516 | ||
517 | /* Note: Takes advantage of common string/buffer fields */ | |
518 | ||
519 | value = source_desc->buffer.pointer[0]; | |
520 | break; | |
521 | ||
522 | default: | |
523 | ||
524 | /* All other types are invalid */ | |
525 | ||
b8e4d893 BM |
526 | ACPI_ERROR((AE_INFO, |
527 | "Source must be Integer/Buffer/String type, not %s", | |
528 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 529 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
530 | } |
531 | ||
532 | /* Store the source value into the target buffer byte */ | |
533 | ||
534 | obj_desc->buffer.pointer[index_desc->reference.offset] = value; | |
535 | break; | |
536 | ||
1da177e4 | 537 | default: |
b229cf92 | 538 | ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField")); |
1da177e4 LT |
539 | status = AE_AML_OPERAND_TYPE; |
540 | break; | |
541 | } | |
542 | ||
4be44fcd | 543 | return_ACPI_STATUS(status); |
1da177e4 LT |
544 | } |
545 | ||
1da177e4 LT |
546 | /******************************************************************************* |
547 | * | |
548 | * FUNCTION: acpi_ex_store_object_to_node | |
549 | * | |
550 | * PARAMETERS: source_desc - Value to be stored | |
551 | * Node - Named object to receive the value | |
552 | * walk_state - Current walk state | |
553 | * implicit_conversion - Perform implicit conversion (yes/no) | |
554 | * | |
555 | * RETURN: Status | |
556 | * | |
557 | * DESCRIPTION: Store the object to the named object. | |
558 | * | |
559 | * The Assignment of an object to a named object is handled here | |
560 | * The value passed in will replace the current value (if any) | |
561 | * with the input value. | |
562 | * | |
563 | * When storing into an object the data is converted to the | |
564 | * target object type then stored in the object. This means | |
565 | * that the target object type (for an initialized target) will | |
566 | * not be changed by a store operation. | |
567 | * | |
568 | * Assumes parameters are already validated. | |
569 | * | |
570 | ******************************************************************************/ | |
571 | ||
572 | acpi_status | |
4be44fcd LB |
573 | acpi_ex_store_object_to_node(union acpi_operand_object *source_desc, |
574 | struct acpi_namespace_node *node, | |
575 | struct acpi_walk_state *walk_state, | |
576 | u8 implicit_conversion) | |
1da177e4 | 577 | { |
4be44fcd LB |
578 | acpi_status status = AE_OK; |
579 | union acpi_operand_object *target_desc; | |
580 | union acpi_operand_object *new_desc; | |
581 | acpi_object_type target_type; | |
1da177e4 | 582 | |
b229cf92 | 583 | ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc); |
1da177e4 | 584 | |
44f6c012 RM |
585 | /* Get current type of the node, and object attached to Node */ |
586 | ||
4be44fcd LB |
587 | target_type = acpi_ns_get_type(node); |
588 | target_desc = acpi_ns_get_attached_object(node); | |
1da177e4 | 589 | |
4be44fcd LB |
590 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n", |
591 | source_desc, | |
592 | acpi_ut_get_object_type_name(source_desc), node, | |
593 | acpi_ut_get_type_name(target_type))); | |
1da177e4 LT |
594 | |
595 | /* | |
596 | * Resolve the source object to an actual value | |
597 | * (If it is a reference object) | |
598 | */ | |
4be44fcd LB |
599 | status = acpi_ex_resolve_object(&source_desc, target_type, walk_state); |
600 | if (ACPI_FAILURE(status)) { | |
601 | return_ACPI_STATUS(status); | |
1da177e4 LT |
602 | } |
603 | ||
604 | /* If no implicit conversion, drop into the default case below */ | |
605 | ||
a3df4dad LM |
606 | if ((!implicit_conversion) || |
607 | ((walk_state->opcode == AML_COPY_OP) && | |
608 | (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) && | |
609 | (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) && | |
610 | (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) { | |
611 | /* | |
612 | * Force execution of default (no implicit conversion). Note: | |
613 | * copy_object does not perform an implicit conversion, as per the ACPI | |
614 | * spec -- except in case of region/bank/index fields -- because these | |
615 | * objects must retain their original type permanently. | |
616 | */ | |
1da177e4 LT |
617 | target_type = ACPI_TYPE_ANY; |
618 | } | |
619 | ||
44f6c012 RM |
620 | /* Do the actual store operation */ |
621 | ||
1da177e4 LT |
622 | switch (target_type) { |
623 | case ACPI_TYPE_BUFFER_FIELD: | |
624 | case ACPI_TYPE_LOCAL_REGION_FIELD: | |
625 | case ACPI_TYPE_LOCAL_BANK_FIELD: | |
626 | case ACPI_TYPE_LOCAL_INDEX_FIELD: | |
627 | ||
44f6c012 RM |
628 | /* For fields, copy the source data to the target field. */ |
629 | ||
4be44fcd LB |
630 | status = acpi_ex_write_data_to_field(source_desc, target_desc, |
631 | &walk_state->result_obj); | |
1da177e4 LT |
632 | break; |
633 | ||
1da177e4 LT |
634 | case ACPI_TYPE_INTEGER: |
635 | case ACPI_TYPE_STRING: | |
636 | case ACPI_TYPE_BUFFER: | |
637 | ||
638 | /* | |
639 | * These target types are all of type Integer/String/Buffer, and | |
640 | * therefore support implicit conversion before the store. | |
641 | * | |
642 | * Copy and/or convert the source object to a new target object | |
643 | */ | |
4be44fcd LB |
644 | status = |
645 | acpi_ex_store_object_to_object(source_desc, target_desc, | |
646 | &new_desc, walk_state); | |
647 | if (ACPI_FAILURE(status)) { | |
648 | return_ACPI_STATUS(status); | |
1da177e4 LT |
649 | } |
650 | ||
651 | if (new_desc != target_desc) { | |
652 | /* | |
653 | * Store the new new_desc as the new value of the Name, and set | |
654 | * the Name's type to that of the value being stored in it. | |
655 | * source_desc reference count is incremented by attach_object. | |
656 | * | |
657 | * Note: This may change the type of the node if an explicit store | |
658 | * has been performed such that the node/object type has been | |
659 | * changed. | |
660 | */ | |
4be44fcd LB |
661 | status = |
662 | acpi_ns_attach_object(node, new_desc, | |
663 | new_desc->common.type); | |
664 | ||
665 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | |
666 | "Store %s into %s via Convert/Attach\n", | |
667 | acpi_ut_get_object_type_name | |
668 | (source_desc), | |
669 | acpi_ut_get_object_type_name | |
670 | (new_desc))); | |
1da177e4 LT |
671 | } |
672 | break; | |
673 | ||
1da177e4 LT |
674 | default: |
675 | ||
4be44fcd LB |
676 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
677 | "Storing %s (%p) directly into node (%p) with no implicit conversion\n", | |
678 | acpi_ut_get_object_type_name(source_desc), | |
679 | source_desc, node)); | |
1da177e4 LT |
680 | |
681 | /* No conversions for all other types. Just attach the source object */ | |
682 | ||
4be44fcd LB |
683 | status = acpi_ns_attach_object(node, source_desc, |
684 | ACPI_GET_OBJECT_TYPE | |
685 | (source_desc)); | |
1da177e4 LT |
686 | break; |
687 | } | |
688 | ||
4be44fcd | 689 | return_ACPI_STATUS(status); |
1da177e4 | 690 | } |