1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
53ACPI_MODULE_NAME("exstore")
54
55
56static void
57acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
58 u32 level, u32 index);
59
60static acpi_status
61acpi_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
68
69
70
71
72
73
74
75
76
77
78
79static void
80acpi_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
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 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
127 case ACPI_TYPE_INTEGER:
128
129
130
131 if (acpi_gbl_integer_byte_width == 4) {
132 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
133 (u32) source_desc->integer.
134 value));
135 } else {
136 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
137 "0x%8.8X%8.8X\n",
138 ACPI_FORMAT_UINT64(source_desc->
139 integer.
140 value)));
141 }
142 break;
143
144 case ACPI_TYPE_BUFFER:
145
146 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
147 (u32) source_desc->buffer.length));
148 ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
149 (source_desc->buffer.length <
150 32) ? source_desc->buffer.length : 32);
151 break;
152
153 case ACPI_TYPE_STRING:
154
155 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
156 source_desc->string.length,
157 source_desc->string.pointer));
158 break;
159
160 case ACPI_TYPE_PACKAGE:
161
162 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
163 "[0x%.2X Elements]\n",
164 source_desc->package.count));
165
166
167
168 for (i = 0; i < source_desc->package.count; i++) {
169 acpi_ex_do_debug_object(source_desc->package.
170 elements[i], level + 4, i + 1);
171 }
172 break;
173
174 case ACPI_TYPE_LOCAL_REFERENCE:
175
176 if (source_desc->reference.opcode == AML_INDEX_OP) {
177 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
178 "[%s, 0x%X]\n",
179 acpi_ps_get_opcode_name
180 (source_desc->reference.opcode),
181 source_desc->reference.offset));
182 } else {
183 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]\n",
184 acpi_ps_get_opcode_name
185 (source_desc->reference.opcode)));
186 }
187
188 if (source_desc->reference.object) {
189 if (ACPI_GET_DESCRIPTOR_TYPE
190 (source_desc->reference.object) ==
191 ACPI_DESC_TYPE_NAMED) {
192 acpi_ex_do_debug_object(((struct
193 acpi_namespace_node *)
194 source_desc->reference.
195 object)->object,
196 level + 4, 0);
197 } else {
198 acpi_ex_do_debug_object(source_desc->reference.
199 object, level + 4, 0);
200 }
201 } else if (source_desc->reference.node) {
202 acpi_ex_do_debug_object((source_desc->reference.node)->
203 object, level + 4, 0);
204 }
205 break;
206
207 default:
208
209 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
210 source_desc,
211 acpi_ut_get_object_type_name
212 (source_desc)));
213 break;
214 }
215
216 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
217 return_VOID;
218}
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240acpi_status
241acpi_ex_store(union acpi_operand_object *source_desc,
242 union acpi_operand_object *dest_desc,
243 struct acpi_walk_state *walk_state)
244{
245 acpi_status status = AE_OK;
246 union acpi_operand_object *ref_desc = dest_desc;
247
248 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
249
250
251
252 if (!source_desc || !dest_desc) {
253 ACPI_ERROR((AE_INFO, "Null parameter"));
254 return_ACPI_STATUS(AE_AML_NO_OPERAND);
255 }
256
257
258
259 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
260
261
262
263
264 status = acpi_ex_store_object_to_node(source_desc,
265 (struct
266 acpi_namespace_node *)
267 dest_desc, walk_state,
268 ACPI_IMPLICIT_CONVERSION);
269
270 return_ACPI_STATUS(status);
271 }
272
273
274
275 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
276 case ACPI_TYPE_LOCAL_REFERENCE:
277 break;
278
279 case ACPI_TYPE_INTEGER:
280
281
282
283 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
284 return_ACPI_STATUS(AE_OK);
285 }
286
287
288
289 default:
290
291
292
293 ACPI_ERROR((AE_INFO,
294 "Target is not a Reference or Constant object - %s [%p]",
295 acpi_ut_get_object_type_name(dest_desc),
296 dest_desc));
297
298 ACPI_DUMP_STACK_ENTRY(source_desc);
299 ACPI_DUMP_STACK_ENTRY(dest_desc);
300 ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore",
301 2,
302 "Target is not a Reference or Constant object");
303
304 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
305 }
306
307
308
309
310
311
312
313
314
315 switch (ref_desc->reference.opcode) {
316 case AML_NAME_OP:
317 case AML_REF_OF_OP:
318
319
320
321 status = acpi_ex_store_object_to_node(source_desc,
322 ref_desc->reference.
323 object, walk_state,
324 ACPI_IMPLICIT_CONVERSION);
325 break;
326
327 case AML_INDEX_OP:
328
329
330
331 status =
332 acpi_ex_store_object_to_index(source_desc, ref_desc,
333 walk_state);
334 break;
335
336 case AML_LOCAL_OP:
337 case AML_ARG_OP:
338
339
340
341 status =
342 acpi_ds_store_object_to_local(ref_desc->reference.opcode,
343 ref_desc->reference.offset,
344 source_desc, walk_state);
345 break;
346
347 case AML_DEBUG_OP:
348
349
350
351
352
353 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
354 "**** Write to Debug Object: Object %p %s ****:\n\n",
355 source_desc,
356 acpi_ut_get_object_type_name(source_desc)));
357
358 acpi_ex_do_debug_object(source_desc, 0, 0);
359 break;
360
361 default:
362
363 ACPI_ERROR((AE_INFO, "Unknown Reference opcode %X",
364 ref_desc->reference.opcode));
365 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_ERROR);
366
367 status = AE_AML_INTERNAL;
368 break;
369 }
370
371 return_ACPI_STATUS(status);
372}
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388static acpi_status
389acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
390 union acpi_operand_object *index_desc,
391 struct acpi_walk_state *walk_state)
392{
393 acpi_status status = AE_OK;
394 union acpi_operand_object *obj_desc;
395 union acpi_operand_object *new_desc;
396 u8 value = 0;
397 u32 i;
398
399 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
400
401
402
403
404
405 switch (index_desc->reference.target_type) {
406 case ACPI_TYPE_PACKAGE:
407
408
409
410
411
412
413
414
415
416 obj_desc = *(index_desc->reference.where);
417
418 status =
419 acpi_ut_copy_iobject_to_iobject(source_desc, &new_desc,
420 walk_state);
421 if (ACPI_FAILURE(status)) {
422 return_ACPI_STATUS(status);
423 }
424
425 if (obj_desc) {
426
427
428
429 for (i = 0; i < ((union acpi_operand_object *)
430 index_desc->reference.object)->common.
431 reference_count; i++) {
432 acpi_ut_remove_reference(obj_desc);
433 }
434 }
435
436 *(index_desc->reference.where) = new_desc;
437
438
439
440 for (i = 1; i < ((union acpi_operand_object *)
441 index_desc->reference.object)->common.
442 reference_count; i++) {
443 acpi_ut_add_reference(new_desc);
444 }
445
446 break;
447
448 case ACPI_TYPE_BUFFER_FIELD:
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464 obj_desc = index_desc->reference.object;
465 if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) &&
466 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) {
467 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
468 }
469
470
471
472
473
474 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
475 case ACPI_TYPE_INTEGER:
476
477
478
479 value = (u8) (source_desc->integer.value);
480 break;
481
482 case ACPI_TYPE_BUFFER:
483 case ACPI_TYPE_STRING:
484
485
486
487 value = source_desc->buffer.pointer[0];
488 break;
489
490 default:
491
492
493
494 ACPI_ERROR((AE_INFO,
495 "Source must be Integer/Buffer/String type, not %s",
496 acpi_ut_get_object_type_name(source_desc)));
497 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
498 }
499
500
501
502 obj_desc->buffer.pointer[index_desc->reference.offset] = value;
503 break;
504
505 default:
506 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
507 status = AE_AML_OPERAND_TYPE;
508 break;
509 }
510
511 return_ACPI_STATUS(status);
512}
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540acpi_status
541acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
542 struct acpi_namespace_node *node,
543 struct acpi_walk_state *walk_state,
544 u8 implicit_conversion)
545{
546 acpi_status status = AE_OK;
547 union acpi_operand_object *target_desc;
548 union acpi_operand_object *new_desc;
549 acpi_object_type target_type;
550
551 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
552
553
554
555 target_type = acpi_ns_get_type(node);
556 target_desc = acpi_ns_get_attached_object(node);
557
558 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
559 source_desc,
560 acpi_ut_get_object_type_name(source_desc), node,
561 acpi_ut_get_type_name(target_type)));
562
563
564
565
566
567 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
568 if (ACPI_FAILURE(status)) {
569 return_ACPI_STATUS(status);
570 }
571
572
573
574 if ((!implicit_conversion) || (walk_state->opcode == AML_COPY_OP)) {
575
576
577
578 target_type = ACPI_TYPE_ANY;
579 }
580
581
582
583 switch (target_type) {
584 case ACPI_TYPE_BUFFER_FIELD:
585 case ACPI_TYPE_LOCAL_REGION_FIELD:
586 case ACPI_TYPE_LOCAL_BANK_FIELD:
587 case ACPI_TYPE_LOCAL_INDEX_FIELD:
588
589
590
591 status = acpi_ex_write_data_to_field(source_desc, target_desc,
592 &walk_state->result_obj);
593 break;
594
595 case ACPI_TYPE_INTEGER:
596 case ACPI_TYPE_STRING:
597 case ACPI_TYPE_BUFFER:
598
599
600
601
602
603
604
605 status =
606 acpi_ex_store_object_to_object(source_desc, target_desc,
607 &new_desc, walk_state);
608 if (ACPI_FAILURE(status)) {
609 return_ACPI_STATUS(status);
610 }
611
612 if (new_desc != target_desc) {
613
614
615
616
617
618
619
620
621
622 status =
623 acpi_ns_attach_object(node, new_desc,
624 new_desc->common.type);
625
626 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
627 "Store %s into %s via Convert/Attach\n",
628 acpi_ut_get_object_type_name
629 (source_desc),
630 acpi_ut_get_object_type_name
631 (new_desc)));
632 }
633 break;
634
635 default:
636
637 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
638 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
639 acpi_ut_get_object_type_name(source_desc),
640 source_desc, node));
641
642
643
644 status = acpi_ns_attach_object(node, source_desc,
645 ACPI_GET_OBJECT_TYPE
646 (source_desc));
647 break;
648 }
649
650 return_ACPI_STATUS(status);
651}
652