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#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acdispat.h"
47#include "acinterp.h"
48#include "amlcode.h"
49#include "acnamesp.h"
50
51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("exstore")
53
54
55static acpi_status
56acpi_ex_store_object_to_index(union acpi_operand_object *val_desc,
57 union acpi_operand_object *dest_desc,
58 struct acpi_walk_state *walk_state);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80acpi_status
81acpi_ex_store(union acpi_operand_object *source_desc,
82 union acpi_operand_object *dest_desc,
83 struct acpi_walk_state *walk_state)
84{
85 acpi_status status = AE_OK;
86 union acpi_operand_object *ref_desc = dest_desc;
87
88 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
89
90
91
92 if (!source_desc || !dest_desc) {
93 ACPI_ERROR((AE_INFO, "Null parameter"));
94 return_ACPI_STATUS(AE_AML_NO_OPERAND);
95 }
96
97
98
99 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
100
101
102
103
104 status = acpi_ex_store_object_to_node(source_desc,
105 (struct
106 acpi_namespace_node *)
107 dest_desc, walk_state,
108 ACPI_IMPLICIT_CONVERSION);
109
110 return_ACPI_STATUS(status);
111 }
112
113
114
115 switch (dest_desc->common.type) {
116 case ACPI_TYPE_LOCAL_REFERENCE:
117 break;
118
119 case ACPI_TYPE_INTEGER:
120
121
122
123 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
124 return_ACPI_STATUS(AE_OK);
125 }
126
127
128
129 default:
130
131
132
133 ACPI_ERROR((AE_INFO,
134 "Target is not a Reference or Constant object - %s [%p]",
135 acpi_ut_get_object_type_name(dest_desc),
136 dest_desc));
137
138 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
139 }
140
141
142
143
144
145
146
147
148
149 switch (ref_desc->reference.class) {
150 case ACPI_REFCLASS_REFOF:
151
152
153
154 status = acpi_ex_store_object_to_node(source_desc,
155 ref_desc->reference.
156 object, walk_state,
157 ACPI_IMPLICIT_CONVERSION);
158 break;
159
160 case ACPI_REFCLASS_INDEX:
161
162
163
164 status =
165 acpi_ex_store_object_to_index(source_desc, ref_desc,
166 walk_state);
167 break;
168
169 case ACPI_REFCLASS_LOCAL:
170 case ACPI_REFCLASS_ARG:
171
172
173
174 status =
175 acpi_ds_store_object_to_local(ref_desc->reference.class,
176 ref_desc->reference.value,
177 source_desc, walk_state);
178 break;
179
180 case ACPI_REFCLASS_DEBUG:
181
182
183
184
185
186 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
187 "**** Write to Debug Object: Object %p %s ****:\n\n",
188 source_desc,
189 acpi_ut_get_object_type_name(source_desc)));
190
191 ACPI_DEBUG_OBJECT(source_desc, 0, 0);
192 break;
193
194 default:
195
196 ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X",
197 ref_desc->reference.class));
198 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO);
199
200 status = AE_AML_INTERNAL;
201 break;
202 }
203
204 return_ACPI_STATUS(status);
205}
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221static acpi_status
222acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
223 union acpi_operand_object *index_desc,
224 struct acpi_walk_state *walk_state)
225{
226 acpi_status status = AE_OK;
227 union acpi_operand_object *obj_desc;
228 union acpi_operand_object *new_desc;
229 u8 value = 0;
230 u32 i;
231
232 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
233
234
235
236
237
238 switch (index_desc->reference.target_type) {
239 case ACPI_TYPE_PACKAGE:
240
241
242
243
244
245
246
247
248
249 obj_desc = *(index_desc->reference.where);
250
251 if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE &&
252 source_desc->reference.class == ACPI_REFCLASS_TABLE) {
253
254
255
256 acpi_ut_add_reference(source_desc);
257 new_desc = source_desc;
258 } else {
259
260
261 status =
262 acpi_ut_copy_iobject_to_iobject(source_desc,
263 &new_desc,
264 walk_state);
265 if (ACPI_FAILURE(status)) {
266 return_ACPI_STATUS(status);
267 }
268 }
269
270 if (obj_desc) {
271
272
273
274 for (i = 0; i < ((union acpi_operand_object *)
275 index_desc->reference.object)->common.
276 reference_count; i++) {
277 acpi_ut_remove_reference(obj_desc);
278 }
279 }
280
281 *(index_desc->reference.where) = new_desc;
282
283
284
285 for (i = 1; i < ((union acpi_operand_object *)
286 index_desc->reference.object)->common.
287 reference_count; i++) {
288 acpi_ut_add_reference(new_desc);
289 }
290
291 break;
292
293 case ACPI_TYPE_BUFFER_FIELD:
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309 obj_desc = index_desc->reference.object;
310 if ((obj_desc->common.type != ACPI_TYPE_BUFFER) &&
311 (obj_desc->common.type != ACPI_TYPE_STRING)) {
312 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
313 }
314
315
316
317
318
319 switch (source_desc->common.type) {
320 case ACPI_TYPE_INTEGER:
321
322
323
324 value = (u8) (source_desc->integer.value);
325 break;
326
327 case ACPI_TYPE_BUFFER:
328 case ACPI_TYPE_STRING:
329
330
331
332 value = source_desc->buffer.pointer[0];
333 break;
334
335 default:
336
337
338
339 ACPI_ERROR((AE_INFO,
340 "Source must be Integer/Buffer/String type, not %s",
341 acpi_ut_get_object_type_name(source_desc)));
342 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
343 }
344
345
346
347 obj_desc->buffer.pointer[index_desc->reference.value] = value;
348 break;
349
350 default:
351 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
352 status = AE_AML_OPERAND_TYPE;
353 break;
354 }
355
356 return_ACPI_STATUS(status);
357}
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385acpi_status
386acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
387 struct acpi_namespace_node *node,
388 struct acpi_walk_state *walk_state,
389 u8 implicit_conversion)
390{
391 acpi_status status = AE_OK;
392 union acpi_operand_object *target_desc;
393 union acpi_operand_object *new_desc;
394 acpi_object_type target_type;
395
396 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
397
398
399
400 target_type = acpi_ns_get_type(node);
401 target_desc = acpi_ns_get_attached_object(node);
402
403 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
404 source_desc,
405 acpi_ut_get_object_type_name(source_desc), node,
406 acpi_ut_get_type_name(target_type)));
407
408
409
410
411
412 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
413 if (ACPI_FAILURE(status)) {
414 return_ACPI_STATUS(status);
415 }
416
417
418
419 if ((!implicit_conversion) ||
420 ((walk_state->opcode == AML_COPY_OP) &&
421 (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) &&
422 (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) &&
423 (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) {
424
425
426
427
428
429
430 target_type = ACPI_TYPE_ANY;
431 }
432
433
434
435 switch (target_type) {
436 case ACPI_TYPE_BUFFER_FIELD:
437 case ACPI_TYPE_LOCAL_REGION_FIELD:
438 case ACPI_TYPE_LOCAL_BANK_FIELD:
439 case ACPI_TYPE_LOCAL_INDEX_FIELD:
440
441
442
443 status = acpi_ex_write_data_to_field(source_desc, target_desc,
444 &walk_state->result_obj);
445 break;
446
447 case ACPI_TYPE_INTEGER:
448 case ACPI_TYPE_STRING:
449 case ACPI_TYPE_BUFFER:
450
451
452
453
454
455
456
457 status =
458 acpi_ex_store_object_to_object(source_desc, target_desc,
459 &new_desc, walk_state);
460 if (ACPI_FAILURE(status)) {
461 return_ACPI_STATUS(status);
462 }
463
464 if (new_desc != target_desc) {
465
466
467
468
469
470
471
472
473
474 status =
475 acpi_ns_attach_object(node, new_desc,
476 new_desc->common.type);
477
478 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
479 "Store %s into %s via Convert/Attach\n",
480 acpi_ut_get_object_type_name
481 (source_desc),
482 acpi_ut_get_object_type_name
483 (new_desc)));
484 }
485 break;
486
487 default:
488
489 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
490 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
491 acpi_ut_get_object_type_name(source_desc),
492 source_desc, node));
493
494
495
496 status = acpi_ns_attach_object(node, source_desc,
497 source_desc->common.type);
498 break;
499 }
500
501 return_ACPI_STATUS(status);
502}
503