1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acparser.h"
13#include "amlcode.h"
14#include "acdispat.h"
15#include "acinterp.h"
16#include "acnamesp.h"
17#include "acevents.h"
18#include "actables.h"
19
20#define _COMPONENT ACPI_DISPATCHER
21ACPI_MODULE_NAME("dsopcode")
22
23
24static acpi_status
25acpi_ds_init_buffer_field(u16 aml_opcode,
26 union acpi_operand_object *obj_desc,
27 union acpi_operand_object *buffer_desc,
28 union acpi_operand_object *offset_desc,
29 union acpi_operand_object *length_desc,
30 union acpi_operand_object *result_desc);
31
32
33
34
35
36
37
38
39
40
41
42
43
44acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
45{
46 union acpi_operand_object *obj_desc;
47 acpi_status status;
48
49 obj_desc = acpi_ns_get_attached_object(obj_handle);
50
51
52
53 status = acpi_ev_initialize_region(obj_desc);
54 return (status);
55}
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74static acpi_status
75acpi_ds_init_buffer_field(u16 aml_opcode,
76 union acpi_operand_object *obj_desc,
77 union acpi_operand_object *buffer_desc,
78 union acpi_operand_object *offset_desc,
79 union acpi_operand_object *length_desc,
80 union acpi_operand_object *result_desc)
81{
82 u32 offset;
83 u32 bit_offset;
84 u32 bit_count;
85 u8 field_flags;
86 acpi_status status;
87
88 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
89
90
91
92 if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
93 ACPI_ERROR((AE_INFO,
94 "Target of Create Field is not a Buffer object - %s",
95 acpi_ut_get_object_type_name(buffer_desc)));
96
97 status = AE_AML_OPERAND_TYPE;
98 goto cleanup;
99 }
100
101
102
103
104
105
106 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
107 ACPI_ERROR((AE_INFO,
108 "(%s) destination not a NS Node [%s]",
109 acpi_ps_get_opcode_name(aml_opcode),
110 acpi_ut_get_descriptor_name(result_desc)));
111
112 status = AE_AML_OPERAND_TYPE;
113 goto cleanup;
114 }
115
116 offset = (u32) offset_desc->integer.value;
117
118
119
120
121 switch (aml_opcode) {
122 case AML_CREATE_FIELD_OP:
123
124
125
126 field_flags = AML_FIELD_ACCESS_BYTE;
127 bit_offset = offset;
128 bit_count = (u32) length_desc->integer.value;
129
130
131
132 if (bit_count == 0) {
133 ACPI_ERROR((AE_INFO,
134 "Attempt to CreateField of length zero"));
135 status = AE_AML_OPERAND_VALUE;
136 goto cleanup;
137 }
138 break;
139
140 case AML_CREATE_BIT_FIELD_OP:
141
142
143
144 bit_offset = offset;
145 bit_count = 1;
146 field_flags = AML_FIELD_ACCESS_BYTE;
147 break;
148
149 case AML_CREATE_BYTE_FIELD_OP:
150
151
152
153 bit_offset = 8 * offset;
154 bit_count = 8;
155 field_flags = AML_FIELD_ACCESS_BYTE;
156 break;
157
158 case AML_CREATE_WORD_FIELD_OP:
159
160
161
162 bit_offset = 8 * offset;
163 bit_count = 16;
164 field_flags = AML_FIELD_ACCESS_WORD;
165 break;
166
167 case AML_CREATE_DWORD_FIELD_OP:
168
169
170
171 bit_offset = 8 * offset;
172 bit_count = 32;
173 field_flags = AML_FIELD_ACCESS_DWORD;
174 break;
175
176 case AML_CREATE_QWORD_FIELD_OP:
177
178
179
180 bit_offset = 8 * offset;
181 bit_count = 64;
182 field_flags = AML_FIELD_ACCESS_QWORD;
183 break;
184
185 default:
186
187 ACPI_ERROR((AE_INFO,
188 "Unknown field creation opcode 0x%02X",
189 aml_opcode));
190 status = AE_AML_BAD_OPCODE;
191 goto cleanup;
192 }
193
194
195
196 if ((bit_offset + bit_count) > (8 * (u32)buffer_desc->buffer.length)) {
197 ACPI_ERROR((AE_INFO,
198 "Field [%4.4s] at bit offset/length %u/%u "
199 "exceeds size of target Buffer (%u bits)",
200 acpi_ut_get_node_name(result_desc), bit_offset,
201 bit_count, 8 * (u32)buffer_desc->buffer.length));
202 status = AE_AML_BUFFER_LIMIT;
203 goto cleanup;
204 }
205
206
207
208
209
210
211 status =
212 acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
213 bit_offset, bit_count);
214 if (ACPI_FAILURE(status)) {
215 goto cleanup;
216 }
217
218 obj_desc->buffer_field.buffer_obj = buffer_desc;
219
220
221
222 buffer_desc->common.reference_count = (u16)
223 (buffer_desc->common.reference_count +
224 obj_desc->common.reference_count);
225
226cleanup:
227
228
229
230 acpi_ut_remove_reference(offset_desc);
231 acpi_ut_remove_reference(buffer_desc);
232
233 if (aml_opcode == AML_CREATE_FIELD_OP) {
234 acpi_ut_remove_reference(length_desc);
235 }
236
237
238
239 if (ACPI_FAILURE(status)) {
240 acpi_ut_remove_reference(result_desc);
241 } else {
242
243
244 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
245 }
246
247 return_ACPI_STATUS(status);
248}
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264acpi_status
265acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
266 union acpi_parse_object *op)
267{
268 acpi_status status;
269 union acpi_operand_object *obj_desc;
270 struct acpi_namespace_node *node;
271 union acpi_parse_object *next_op;
272
273 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
274
275
276
277
278
279 node = op->common.node;
280
281
282
283 next_op = op->common.value.arg;
284
285
286
287 status = acpi_ds_create_operands(walk_state, next_op);
288 if (ACPI_FAILURE(status)) {
289 return_ACPI_STATUS(status);
290 }
291
292 obj_desc = acpi_ns_get_attached_object(node);
293 if (!obj_desc) {
294 return_ACPI_STATUS(AE_NOT_EXIST);
295 }
296
297
298
299 status =
300 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
301 walk_state);
302 if (ACPI_FAILURE(status)) {
303 ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
304 acpi_ps_get_opcode_name(op->common.aml_opcode),
305 status));
306
307 return_ACPI_STATUS(status);
308 }
309
310
311
312 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
313
314
315
316 status =
317 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
318 walk_state->operands[0],
319 walk_state->operands[1],
320 walk_state->operands[2],
321 walk_state->operands[3]);
322 } else {
323
324
325 status =
326 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
327 walk_state->operands[0],
328 walk_state->operands[1], NULL,
329 walk_state->operands[2]);
330 }
331
332 return_ACPI_STATUS(status);
333}
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349acpi_status
350acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
351 union acpi_parse_object *op)
352{
353 acpi_status status;
354 union acpi_operand_object *obj_desc;
355 union acpi_operand_object *operand_desc;
356 struct acpi_namespace_node *node;
357 union acpi_parse_object *next_op;
358
359 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
360
361
362
363
364
365 node = op->common.node;
366
367
368
369 next_op = op->common.value.arg;
370
371
372
373 next_op = next_op->common.next;
374
375
376
377 status = acpi_ds_create_operands(walk_state, next_op);
378 if (ACPI_FAILURE(status)) {
379 return_ACPI_STATUS(status);
380 }
381
382
383
384 status =
385 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
386 walk_state);
387 if (ACPI_FAILURE(status)) {
388 return_ACPI_STATUS(status);
389 }
390
391 obj_desc = acpi_ns_get_attached_object(node);
392 if (!obj_desc) {
393 return_ACPI_STATUS(AE_NOT_EXIST);
394 }
395
396
397
398
399
400 operand_desc = walk_state->operands[walk_state->num_operands - 1];
401
402 obj_desc->region.length = (u32) operand_desc->integer.value;
403 acpi_ut_remove_reference(operand_desc);
404
405
406
407
408
409 operand_desc = walk_state->operands[walk_state->num_operands - 2];
410
411 obj_desc->region.address = (acpi_physical_address)
412 operand_desc->integer.value;
413 acpi_ut_remove_reference(operand_desc);
414
415 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
416 obj_desc,
417 ACPI_FORMAT_UINT64(obj_desc->region.address),
418 obj_desc->region.length));
419
420
421
422 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
423 return_ACPI_STATUS(status);
424}
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441acpi_status
442acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
443 union acpi_parse_object *op)
444{
445 acpi_status status;
446 union acpi_operand_object *obj_desc;
447 union acpi_operand_object **operand;
448 struct acpi_namespace_node *node;
449 union acpi_parse_object *next_op;
450 struct acpi_table_header *table;
451 u32 table_index;
452
453 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
454
455
456
457
458
459 node = op->common.node;
460
461
462
463 next_op = op->common.value.arg;
464
465
466
467
468
469 status = acpi_ds_create_operands(walk_state, next_op);
470 if (ACPI_FAILURE(status)) {
471 return_ACPI_STATUS(status);
472 }
473
474 operand = &walk_state->operands[0];
475
476
477
478
479
480 status =
481 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
482 walk_state);
483 if (ACPI_FAILURE(status)) {
484 goto cleanup;
485 }
486
487
488
489 status = acpi_tb_find_table(operand[0]->string.pointer,
490 operand[1]->string.pointer,
491 operand[2]->string.pointer, &table_index);
492 if (ACPI_FAILURE(status)) {
493 if (status == AE_NOT_FOUND) {
494 ACPI_ERROR((AE_INFO,
495 "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
496 operand[0]->string.pointer,
497 operand[1]->string.pointer,
498 operand[2]->string.pointer));
499 }
500 goto cleanup;
501 }
502
503 status = acpi_get_table_by_index(table_index, &table);
504 if (ACPI_FAILURE(status)) {
505 goto cleanup;
506 }
507
508 obj_desc = acpi_ns_get_attached_object(node);
509 if (!obj_desc) {
510 status = AE_NOT_EXIST;
511 goto cleanup;
512 }
513
514 obj_desc->region.address = ACPI_PTR_TO_PHYSADDR(table);
515 obj_desc->region.length = table->length;
516
517 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
518 obj_desc,
519 ACPI_FORMAT_UINT64(obj_desc->region.address),
520 obj_desc->region.length));
521
522
523
524 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
525
526cleanup:
527 acpi_ut_remove_reference(operand[0]);
528 acpi_ut_remove_reference(operand[1]);
529 acpi_ut_remove_reference(operand[2]);
530
531 return_ACPI_STATUS(status);
532}
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549acpi_status
550acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
551 union acpi_parse_object *op,
552 union acpi_operand_object *obj_desc)
553{
554 acpi_status status;
555 union acpi_operand_object *arg_desc;
556 u32 length;
557
558 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
559
560
561
562
563
564
565
566 walk_state->operand_index = walk_state->num_operands;
567
568
569
570 if (!op->common.value.arg) {
571 ACPI_ERROR((AE_INFO,
572 "Missing child while evaluating opcode %4.4X, Op %p",
573 op->common.aml_opcode, op));
574 return_ACPI_STATUS(AE_OK);
575 }
576
577 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
578 if (ACPI_FAILURE(status)) {
579 return_ACPI_STATUS(status);
580 }
581
582 status = acpi_ex_resolve_operands(walk_state->opcode,
583 &(walk_state->
584 operands[walk_state->num_operands -
585 1]), walk_state);
586 if (ACPI_FAILURE(status)) {
587 return_ACPI_STATUS(status);
588 }
589
590
591
592 arg_desc = walk_state->operands[walk_state->num_operands - 1];
593 length = (u32) arg_desc->integer.value;
594
595
596
597 status = acpi_ds_obj_stack_pop(1, walk_state);
598 if (ACPI_FAILURE(status)) {
599 return_ACPI_STATUS(status);
600 }
601
602 acpi_ut_remove_reference(arg_desc);
603
604
605
606
607 switch (op->common.aml_opcode) {
608 case AML_BUFFER_OP:
609
610 status =
611 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
612 &obj_desc);
613 break;
614
615 case AML_PACKAGE_OP:
616 case AML_VARIABLE_PACKAGE_OP:
617
618 status =
619 acpi_ds_build_internal_package_obj(walk_state, op, length,
620 &obj_desc);
621 break;
622
623 default:
624
625 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
626 }
627
628 if (ACPI_SUCCESS(status)) {
629
630
631
632
633
634 if ((!op->common.parent) ||
635 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
636 (op->common.parent->common.aml_opcode !=
637 AML_VARIABLE_PACKAGE_OP)
638 && (op->common.parent->common.aml_opcode !=
639 AML_NAME_OP))) {
640 walk_state->result_obj = obj_desc;
641 }
642 }
643
644 return_ACPI_STATUS(status);
645}
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661acpi_status
662acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
663 union acpi_parse_object *op)
664{
665 acpi_status status;
666 union acpi_operand_object *obj_desc;
667 union acpi_operand_object *operand_desc;
668 struct acpi_namespace_node *node;
669 union acpi_parse_object *next_op;
670 union acpi_parse_object *arg;
671
672 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
673
674
675
676
677
678
679
680
681 next_op = op->common.value.arg;
682
683
684
685 next_op = next_op->common.next;
686
687
688
689 next_op = next_op->common.next;
690
691
692
693
694
695
696
697 walk_state->operand_index = 0;
698
699 status = acpi_ds_create_operand(walk_state, next_op, 0);
700 if (ACPI_FAILURE(status)) {
701 return_ACPI_STATUS(status);
702 }
703
704 status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
705 if (ACPI_FAILURE(status)) {
706 return_ACPI_STATUS(status);
707 }
708
709 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
710 acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
711
712
713
714
715 operand_desc = walk_state->operands[0];
716
717
718
719 arg = acpi_ps_get_arg(op, 4);
720 while (arg) {
721
722
723
724 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
725 node = arg->common.node;
726
727 obj_desc = acpi_ns_get_attached_object(node);
728 if (!obj_desc) {
729 return_ACPI_STATUS(AE_NOT_EXIST);
730 }
731
732 obj_desc->bank_field.value =
733 (u32) operand_desc->integer.value;
734 }
735
736
737
738 arg = arg->common.next;
739 }
740
741 acpi_ut_remove_reference(operand_desc);
742 return_ACPI_STATUS(status);
743}
744