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