]> git.ipfire.org Git - thirdparty/kernel/stable.git/blob - drivers/acpi/executer/exstore.c
Linux-2.6.12-rc2
[thirdparty/kernel/stable.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 - 2005, 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
46 #include <acpi/acpi.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/amlcode.h>
50 #include <acpi/acnamesp.h>
51
52
53 #define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exstore")
55
56
57 /*******************************************************************************
58 *
59 * FUNCTION: acpi_ex_store
60 *
61 * PARAMETERS: *source_desc - Value to be stored
62 * *dest_desc - Where to store it. Must be an NS node
63 * or an union acpi_operand_object of type
64 * Reference;
65 * walk_state - Current walk state
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Store the value described by source_desc into the location
70 * described by dest_desc. Called by various interpreter
71 * functions to store the result of an operation into
72 * the destination operand -- not just simply the actual "Store"
73 * ASL operator.
74 *
75 ******************************************************************************/
76
77 acpi_status
78 acpi_ex_store (
79 union acpi_operand_object *source_desc,
80 union acpi_operand_object *dest_desc,
81 struct acpi_walk_state *walk_state)
82 {
83 acpi_status status = AE_OK;
84 union acpi_operand_object *ref_desc = dest_desc;
85
86
87 ACPI_FUNCTION_TRACE_PTR ("ex_store", dest_desc);
88
89
90 /* Validate parameters */
91
92 if (!source_desc || !dest_desc) {
93 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null parameter\n"));
94 return_ACPI_STATUS (AE_AML_NO_OPERAND);
95 }
96
97 /* dest_desc can be either a namespace node or an ACPI object */
98
99 if (ACPI_GET_DESCRIPTOR_TYPE (dest_desc) == ACPI_DESC_TYPE_NAMED) {
100 /*
101 * Dest is a namespace node,
102 * Storing an object into a Named node.
103 */
104 status = acpi_ex_store_object_to_node (source_desc,
105 (struct acpi_namespace_node *) dest_desc, walk_state,
106 ACPI_IMPLICIT_CONVERSION);
107
108 return_ACPI_STATUS (status);
109 }
110
111 /* Destination object must be a Reference or a Constant object */
112
113 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
114 case ACPI_TYPE_LOCAL_REFERENCE:
115 break;
116
117 case ACPI_TYPE_INTEGER:
118
119 /* Allow stores to Constants -- a Noop as per ACPI spec */
120
121 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
122 return_ACPI_STATUS (AE_OK);
123 }
124
125 /*lint -fallthrough */
126
127 default:
128
129 /* Destination is not a Reference object */
130
131 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
132 "Target is not a Reference or Constant object - %s [%p]\n",
133 acpi_ut_get_object_type_name (dest_desc), dest_desc));
134
135 ACPI_DUMP_STACK_ENTRY (source_desc);
136 ACPI_DUMP_STACK_ENTRY (dest_desc);
137 ACPI_DUMP_OPERANDS (&dest_desc, ACPI_IMODE_EXECUTE, "ex_store",
138 2, "Target is not a Reference or Constant object");
139
140 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
141 }
142
143 /*
144 * Examine the Reference opcode. These cases are handled:
145 *
146 * 1) Store to Name (Change the object associated with a name)
147 * 2) Store to an indexed area of a Buffer or Package
148 * 3) Store to a Method Local or Arg
149 * 4) Store to the debug object
150 */
151 switch (ref_desc->reference.opcode) {
152 case AML_NAME_OP:
153 case AML_REF_OF_OP:
154
155 /* Storing an object into a Name "container" */
156
157 status = acpi_ex_store_object_to_node (source_desc, ref_desc->reference.object,
158 walk_state, ACPI_IMPLICIT_CONVERSION);
159 break;
160
161
162 case AML_INDEX_OP:
163
164 /* Storing to an Index (pointer into a packager or buffer) */
165
166 status = acpi_ex_store_object_to_index (source_desc, ref_desc, walk_state);
167 break;
168
169
170 case AML_LOCAL_OP:
171 case AML_ARG_OP:
172
173 /* Store to a method local/arg */
174
175 status = acpi_ds_store_object_to_local (ref_desc->reference.opcode,
176 ref_desc->reference.offset, source_desc, walk_state);
177 break;
178
179
180 case AML_DEBUG_OP:
181
182 /*
183 * Storing to the Debug object causes the value stored to be
184 * displayed and otherwise has no effect -- see ACPI Specification
185 */
186 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
187 "**** Write to Debug Object: Object %p %s ****:\n\n",
188 source_desc, acpi_ut_get_object_type_name (source_desc)));
189
190 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ",
191 acpi_ut_get_object_type_name (source_desc)));
192
193 if (!acpi_ut_valid_internal_object (source_desc)) {
194 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
195 "%p, Invalid Internal Object!\n", source_desc));
196 break;
197 }
198
199 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
200 case ACPI_TYPE_INTEGER:
201
202 if (acpi_gbl_integer_byte_width == 4) {
203 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
204 (u32) source_desc->integer.value));
205 }
206 else {
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
208 ACPI_FORMAT_UINT64 (source_desc->integer.value)));
209 }
210 break;
211
212
213 case ACPI_TYPE_BUFFER:
214
215 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
216 (u32) source_desc->buffer.length));
217 ACPI_DUMP_BUFFER (source_desc->buffer.pointer,
218 (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
219 break;
220
221
222 case ACPI_TYPE_STRING:
223
224 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
225 source_desc->string.length, source_desc->string.pointer));
226 break;
227
228
229 case ACPI_TYPE_PACKAGE:
230
231 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] Elements Ptr - %p\n",
232 source_desc->package.count, source_desc->package.elements));
233 break;
234
235
236 default:
237
238 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n",
239 source_desc));
240 break;
241 }
242
243 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
244 break;
245
246
247 default:
248
249 ACPI_REPORT_ERROR (("ex_store: Unknown Reference opcode %X\n",
250 ref_desc->reference.opcode));
251 ACPI_DUMP_ENTRY (ref_desc, ACPI_LV_ERROR);
252
253 status = AE_AML_INTERNAL;
254 break;
255 }
256
257 return_ACPI_STATUS (status);
258 }
259
260
261 /*******************************************************************************
262 *
263 * FUNCTION: acpi_ex_store_object_to_index
264 *
265 * PARAMETERS: *source_desc - Value to be stored
266 * *dest_desc - Named object to receive the value
267 * walk_state - Current walk state
268 *
269 * RETURN: Status
270 *
271 * DESCRIPTION: Store the object to indexed Buffer or Package element
272 *
273 ******************************************************************************/
274
275 acpi_status
276 acpi_ex_store_object_to_index (
277 union acpi_operand_object *source_desc,
278 union acpi_operand_object *index_desc,
279 struct acpi_walk_state *walk_state)
280 {
281 acpi_status status = AE_OK;
282 union acpi_operand_object *obj_desc;
283 union acpi_operand_object *new_desc;
284 u8 value = 0;
285 u32 i;
286
287
288 ACPI_FUNCTION_TRACE ("ex_store_object_to_index");
289
290
291 /*
292 * Destination must be a reference pointer, and
293 * must point to either a buffer or a package
294 */
295 switch (index_desc->reference.target_type) {
296 case ACPI_TYPE_PACKAGE:
297 /*
298 * Storing to a package element. Copy the object and replace
299 * any existing object with the new object. No implicit
300 * conversion is performed.
301 *
302 * The object at *(index_desc->Reference.Where) is the
303 * element within the package that is to be modified.
304 * The parent package object is at index_desc->Reference.Object
305 */
306 obj_desc = *(index_desc->reference.where);
307
308 status = acpi_ut_copy_iobject_to_iobject (source_desc, &new_desc, walk_state);
309 if (ACPI_FAILURE (status)) {
310 return_ACPI_STATUS (status);
311 }
312
313 if (obj_desc) {
314 /* Decrement reference count by the ref count of the parent package */
315
316 for (i = 0; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) {
317 acpi_ut_remove_reference (obj_desc);
318 }
319 }
320
321 *(index_desc->reference.where) = new_desc;
322
323 /* Increment reference count by the ref count of the parent package -1 */
324
325 for (i = 1; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) {
326 acpi_ut_add_reference (new_desc);
327 }
328
329 break;
330
331
332 case ACPI_TYPE_BUFFER_FIELD:
333
334 /*
335 * Store into a Buffer or String (not actually a real buffer_field)
336 * at a location defined by an Index.
337 *
338 * The first 8-bit element of the source object is written to the
339 * 8-bit Buffer location defined by the Index destination object,
340 * according to the ACPI 2.0 specification.
341 */
342
343 /*
344 * Make sure the target is a Buffer or String. An error should
345 * not happen here, since the reference_object was constructed
346 * by the INDEX_OP code.
347 */
348 obj_desc = index_desc->reference.object;
349 if ((ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_BUFFER) &&
350 (ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_STRING)) {
351 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
352 }
353
354 /*
355 * The assignment of the individual elements will be slightly
356 * different for each source type.
357 */
358 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
359 case ACPI_TYPE_INTEGER:
360
361 /* Use the least-significant byte of the integer */
362
363 value = (u8) (source_desc->integer.value);
364 break;
365
366 case ACPI_TYPE_BUFFER:
367 case ACPI_TYPE_STRING:
368
369 /* Note: Takes advantage of common string/buffer fields */
370
371 value = source_desc->buffer.pointer[0];
372 break;
373
374 default:
375
376 /* All other types are invalid */
377
378 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
379 "Source must be Integer/Buffer/String type, not %s\n",
380 acpi_ut_get_object_type_name (source_desc)));
381 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
382 }
383
384 /* Store the source value into the target buffer byte */
385
386 obj_desc->buffer.pointer[index_desc->reference.offset] = value;
387 break;
388
389
390 default:
391 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
392 "Target is not a Package or buffer_field\n"));
393 status = AE_AML_OPERAND_TYPE;
394 break;
395 }
396
397 return_ACPI_STATUS (status);
398 }
399
400
401 /*******************************************************************************
402 *
403 * FUNCTION: acpi_ex_store_object_to_node
404 *
405 * PARAMETERS: source_desc - Value to be stored
406 * Node - Named object to receive the value
407 * walk_state - Current walk state
408 * implicit_conversion - Perform implicit conversion (yes/no)
409 *
410 * RETURN: Status
411 *
412 * DESCRIPTION: Store the object to the named object.
413 *
414 * The Assignment of an object to a named object is handled here
415 * The value passed in will replace the current value (if any)
416 * with the input value.
417 *
418 * When storing into an object the data is converted to the
419 * target object type then stored in the object. This means
420 * that the target object type (for an initialized target) will
421 * not be changed by a store operation.
422 *
423 * Assumes parameters are already validated.
424 *
425 ******************************************************************************/
426
427 acpi_status
428 acpi_ex_store_object_to_node (
429 union acpi_operand_object *source_desc,
430 struct acpi_namespace_node *node,
431 struct acpi_walk_state *walk_state,
432 u8 implicit_conversion)
433 {
434 acpi_status status = AE_OK;
435 union acpi_operand_object *target_desc;
436 union acpi_operand_object *new_desc;
437 acpi_object_type target_type;
438
439
440 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc);
441
442
443 /*
444 * Get current type of the node, and object attached to Node
445 */
446 target_type = acpi_ns_get_type (node);
447 target_desc = acpi_ns_get_attached_object (node);
448
449 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
450 source_desc, acpi_ut_get_object_type_name (source_desc),
451 node, acpi_ut_get_type_name (target_type)));
452
453 /*
454 * Resolve the source object to an actual value
455 * (If it is a reference object)
456 */
457 status = acpi_ex_resolve_object (&source_desc, target_type, walk_state);
458 if (ACPI_FAILURE (status)) {
459 return_ACPI_STATUS (status);
460 }
461
462 /* If no implicit conversion, drop into the default case below */
463
464 if (!implicit_conversion) {
465 /* Force execution of default (no implicit conversion) */
466
467 target_type = ACPI_TYPE_ANY;
468 }
469
470 /*
471 * Do the actual store operation
472 */
473 switch (target_type) {
474 case ACPI_TYPE_BUFFER_FIELD:
475 case ACPI_TYPE_LOCAL_REGION_FIELD:
476 case ACPI_TYPE_LOCAL_BANK_FIELD:
477 case ACPI_TYPE_LOCAL_INDEX_FIELD:
478
479 /*
480 * For fields, copy the source data to the target field.
481 */
482 status = acpi_ex_write_data_to_field (source_desc, target_desc, &walk_state->result_obj);
483 break;
484
485
486 case ACPI_TYPE_INTEGER:
487 case ACPI_TYPE_STRING:
488 case ACPI_TYPE_BUFFER:
489
490 /*
491 * These target types are all of type Integer/String/Buffer, and
492 * therefore support implicit conversion before the store.
493 *
494 * Copy and/or convert the source object to a new target object
495 */
496 status = acpi_ex_store_object_to_object (source_desc, target_desc, &new_desc, walk_state);
497 if (ACPI_FAILURE (status)) {
498 return_ACPI_STATUS (status);
499 }
500
501 if (new_desc != target_desc) {
502 /*
503 * Store the new new_desc as the new value of the Name, and set
504 * the Name's type to that of the value being stored in it.
505 * source_desc reference count is incremented by attach_object.
506 *
507 * Note: This may change the type of the node if an explicit store
508 * has been performed such that the node/object type has been
509 * changed.
510 */
511 status = acpi_ns_attach_object (node, new_desc, new_desc->common.type);
512
513 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
514 "Store %s into %s via Convert/Attach\n",
515 acpi_ut_get_object_type_name (source_desc),
516 acpi_ut_get_object_type_name (new_desc)));
517 }
518 break;
519
520
521 default:
522
523 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
524 "Storing %s (%p) directly into node (%p), no implicit conversion\n",
525 acpi_ut_get_object_type_name (source_desc), source_desc, node));
526
527 /* No conversions for all other types. Just attach the source object */
528
529 status = acpi_ns_attach_object (node, source_desc, ACPI_GET_OBJECT_TYPE (source_desc));
530 break;
531 }
532
533 return_ACPI_STATUS (status);
534 }
535
536