ACPICA: Fixes for Unload and DDBHandles
[deliverable/linux.git] / drivers / acpi / executer / exstore.c
1
2 /******************************************************************************
3 *
4 * Module Name: exstore - AML Interpreter object store support
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2007, R. Byron Moore
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
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>
50 #include <acpi/acparser.h>
51
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME("exstore")
54
55 /* Local prototypes */
56 static void
57 acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
58 u32 level, u32 index);
59
60 static acpi_status
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);
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
80 acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
81 u32 level, u32 index)
82 {
83 u32 i;
84
85 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
86
87 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
88 level, " "));
89
90 /* Display index for package output only */
91
92 if (index > 0) {
93 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
94 "(%.2u) ", index - 1));
95 }
96
97 if (!source_desc) {
98 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n"));
99 return_VOID;
100 }
101
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)));
106
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;
112 }
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));
121 return_VOID;
122 } else {
123 return_VOID;
124 }
125
126 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
127
128 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
129 case ACPI_TYPE_INTEGER:
130
131 /* Output correct integer width */
132
133 if (acpi_gbl_integer_byte_width == 4) {
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)));
143 }
144 break;
145
146 case ACPI_TYPE_BUFFER:
147
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 <
152 256) ? source_desc->buffer.length : 256);
153 break;
154
155 case ACPI_TYPE_STRING:
156
157 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
158 source_desc->string.length,
159 source_desc->string.pointer));
160 break;
161
162 case ACPI_TYPE_PACKAGE:
163
164 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
165 "[0x%.2X Elements]\n",
166 source_desc->package.count));
167
168 /* Output the entire contents of the package */
169
170 for (i = 0; i < source_desc->package.count; i++) {
171 acpi_ex_do_debug_object(source_desc->package.
172 elements[i], level + 4, i + 1);
173 }
174 break;
175
176 case ACPI_TYPE_LOCAL_REFERENCE:
177
178 if (source_desc->reference.opcode == AML_INDEX_OP) {
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 {
185 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]",
186 acpi_ps_get_opcode_name
187 (source_desc->reference.opcode)));
188 }
189
190 if (source_desc->reference.opcode == AML_LOAD_OP) { /* Load and load_table */
191 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
192 " Table OwnerId %p\n",
193 source_desc->reference.object));
194 break;
195 }
196
197 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "\n"));
198 if (source_desc->reference.object) {
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);
210 }
211 } else if (source_desc->reference.node) {
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,
216 " %p - Not a valid namespace node\n",
217 source_desc->reference.
218 node));
219 } else {
220 acpi_ex_do_debug_object((source_desc->reference.
221 node)->object,
222 level + 4, 0);
223 }
224 }
225 break;
226
227 default:
228
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)));
233 break;
234 }
235
236 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
237 return_VOID;
238 }
239
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
261 acpi_ex_store(union acpi_operand_object *source_desc,
262 union acpi_operand_object *dest_desc,
263 struct acpi_walk_state *walk_state)
264 {
265 acpi_status status = AE_OK;
266 union acpi_operand_object *ref_desc = dest_desc;
267
268 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
269
270 /* Validate parameters */
271
272 if (!source_desc || !dest_desc) {
273 ACPI_ERROR((AE_INFO, "Null parameter"));
274 return_ACPI_STATUS(AE_AML_NO_OPERAND);
275 }
276
277 /* dest_desc can be either a namespace node or an ACPI object */
278
279 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
280 /*
281 * Dest is a namespace node,
282 * Storing an object into a Named node.
283 */
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);
289
290 return_ACPI_STATUS(status);
291 }
292
293 /* Destination object must be a Reference or a Constant object */
294
295 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
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) {
304 return_ACPI_STATUS(AE_OK);
305 }
306
307 /*lint -fallthrough */
308
309 default:
310
311 /* Destination is not a Reference object */
312
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));
317
318 ACPI_DUMP_STACK_ENTRY(source_desc);
319 ACPI_DUMP_STACK_ENTRY(dest_desc);
320 ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore",
321 2,
322 "Target is not a Reference or Constant object");
323
324 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
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) {
336 case AML_REF_OF_OP:
337
338 /* Storing an object into a Name "container" */
339
340 status = acpi_ex_store_object_to_node(source_desc,
341 ref_desc->reference.
342 object, walk_state,
343 ACPI_IMPLICIT_CONVERSION);
344 break;
345
346 case AML_INDEX_OP:
347
348 /* Storing to an Index (pointer into a packager or buffer) */
349
350 status =
351 acpi_ex_store_object_to_index(source_desc, ref_desc,
352 walk_state);
353 break;
354
355 case AML_LOCAL_OP:
356 case AML_ARG_OP:
357
358 /* Store to a method local/arg */
359
360 status =
361 acpi_ds_store_object_to_local(ref_desc->reference.opcode,
362 ref_desc->reference.offset,
363 source_desc, walk_state);
364 break;
365
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 */
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)));
376
377 acpi_ex_do_debug_object(source_desc, 0, 0);
378 break;
379
380 default:
381
382 ACPI_ERROR((AE_INFO, "Unknown Reference opcode %X",
383 ref_desc->reference.opcode));
384 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_ERROR);
385
386 status = AE_AML_INTERNAL;
387 break;
388 }
389
390 return_ACPI_STATUS(status);
391 }
392
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
407 static acpi_status
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)
411 {
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;
417
418 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
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
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 }
455 }
456
457 if (obj_desc) {
458
459 /* Decrement reference count by the ref count of the parent package */
460
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);
465 }
466 }
467
468 *(index_desc->reference.where) = new_desc;
469
470 /* Increment ref count by the ref count of the parent package-1 */
471
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);
476 }
477
478 break;
479
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;
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);
500 }
501
502 /*
503 * The assignment of the individual elements will be slightly
504 * different for each source type.
505 */
506 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
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
526 ACPI_ERROR((AE_INFO,
527 "Source must be Integer/Buffer/String type, not %s",
528 acpi_ut_get_object_type_name(source_desc)));
529 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
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
537 default:
538 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
539 status = AE_AML_OPERAND_TYPE;
540 break;
541 }
542
543 return_ACPI_STATUS(status);
544 }
545
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
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)
577 {
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;
582
583 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
584
585 /* Get current type of the node, and object attached to Node */
586
587 target_type = acpi_ns_get_type(node);
588 target_desc = acpi_ns_get_attached_object(node);
589
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)));
594
595 /*
596 * Resolve the source object to an actual value
597 * (If it is a reference object)
598 */
599 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
600 if (ACPI_FAILURE(status)) {
601 return_ACPI_STATUS(status);
602 }
603
604 /* If no implicit conversion, drop into the default case below */
605
606 if ((!implicit_conversion) || (walk_state->opcode == AML_COPY_OP)) {
607
608 /* Force execution of default (no implicit conversion) */
609
610 target_type = ACPI_TYPE_ANY;
611 }
612
613 /* Do the actual store operation */
614
615 switch (target_type) {
616 case ACPI_TYPE_BUFFER_FIELD:
617 case ACPI_TYPE_LOCAL_REGION_FIELD:
618 case ACPI_TYPE_LOCAL_BANK_FIELD:
619 case ACPI_TYPE_LOCAL_INDEX_FIELD:
620
621 /* For fields, copy the source data to the target field. */
622
623 status = acpi_ex_write_data_to_field(source_desc, target_desc,
624 &walk_state->result_obj);
625 break;
626
627 case ACPI_TYPE_INTEGER:
628 case ACPI_TYPE_STRING:
629 case ACPI_TYPE_BUFFER:
630
631 /*
632 * These target types are all of type Integer/String/Buffer, and
633 * therefore support implicit conversion before the store.
634 *
635 * Copy and/or convert the source object to a new target object
636 */
637 status =
638 acpi_ex_store_object_to_object(source_desc, target_desc,
639 &new_desc, walk_state);
640 if (ACPI_FAILURE(status)) {
641 return_ACPI_STATUS(status);
642 }
643
644 if (new_desc != target_desc) {
645 /*
646 * Store the new new_desc as the new value of the Name, and set
647 * the Name's type to that of the value being stored in it.
648 * source_desc reference count is incremented by attach_object.
649 *
650 * Note: This may change the type of the node if an explicit store
651 * has been performed such that the node/object type has been
652 * changed.
653 */
654 status =
655 acpi_ns_attach_object(node, new_desc,
656 new_desc->common.type);
657
658 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
659 "Store %s into %s via Convert/Attach\n",
660 acpi_ut_get_object_type_name
661 (source_desc),
662 acpi_ut_get_object_type_name
663 (new_desc)));
664 }
665 break;
666
667 default:
668
669 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
670 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
671 acpi_ut_get_object_type_name(source_desc),
672 source_desc, node));
673
674 /* No conversions for all other types. Just attach the source object */
675
676 status = acpi_ns_attach_object(node, source_desc,
677 ACPI_GET_OBJECT_TYPE
678 (source_desc));
679 break;
680 }
681
682 return_ACPI_STATUS(status);
683 }
This page took 0.050821 seconds and 6 git commands to generate.