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 "amlcode.h"
47#include "acparser.h"
48#include "acinterp.h"
49#include "acnamesp.h"
50
51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("exresop")
53
54
55static acpi_status
56acpi_ex_check_object_type(acpi_object_type type_needed,
57 acpi_object_type this_type, void *object);
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73static acpi_status
74acpi_ex_check_object_type(acpi_object_type type_needed,
75 acpi_object_type this_type, void *object)
76{
77 ACPI_FUNCTION_ENTRY();
78
79 if (type_needed == ACPI_TYPE_ANY) {
80
81
82
83 return (AE_OK);
84 }
85
86 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
87
88
89
90
91
92 if ((this_type == ACPI_TYPE_INTEGER) &&
93 (((union acpi_operand_object *)object)->common.
94 flags & AOPOBJ_AML_CONSTANT)) {
95 return (AE_OK);
96 }
97 }
98
99 if (type_needed != this_type) {
100 ACPI_ERROR((AE_INFO,
101 "Needed type [%s], found [%s] %p",
102 acpi_ut_get_type_name(type_needed),
103 acpi_ut_get_type_name(this_type), object));
104
105 return (AE_AML_OPERAND_TYPE);
106 }
107
108 return (AE_OK);
109}
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132acpi_status
133acpi_ex_resolve_operands(u16 opcode,
134 union acpi_operand_object ** stack_ptr,
135 struct acpi_walk_state * walk_state)
136{
137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK;
139 u8 object_type;
140 u32 arg_types;
141 const struct acpi_opcode_info *op_info;
142 u32 this_arg_type;
143 acpi_object_type type_needed;
144 u16 target_op = 0;
145
146 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
147
148 op_info = acpi_ps_get_opcode_info(opcode);
149 if (op_info->class == AML_CLASS_UNKNOWN) {
150 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
151 }
152
153 arg_types = op_info->runtime_args;
154 if (arg_types == ARGI_INVALID_OPCODE) {
155 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode));
156
157 return_ACPI_STATUS(AE_AML_INTERNAL);
158 }
159
160 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
161 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
162 opcode, op_info->name, arg_types));
163
164
165
166
167
168
169
170
171 while (GET_CURRENT_ARG_TYPE(arg_types)) {
172 if (!stack_ptr || !*stack_ptr) {
173 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
174 stack_ptr));
175
176 return_ACPI_STATUS(AE_AML_INTERNAL);
177 }
178
179
180
181 obj_desc = *stack_ptr;
182
183
184
185 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
186 case ACPI_DESC_TYPE_NAMED:
187
188
189
190 object_type =
191 ((struct acpi_namespace_node *)obj_desc)->type;
192
193
194
195
196
197
198 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
199 obj_desc =
200 acpi_ns_get_attached_object((struct
201 acpi_namespace_node
202 *)obj_desc);
203 *stack_ptr = obj_desc;
204 object_type =
205 ((struct acpi_namespace_node *)obj_desc)->
206 type;
207 }
208 break;
209
210 case ACPI_DESC_TYPE_OPERAND:
211
212
213
214 object_type = obj_desc->common.type;
215
216
217
218 if (!acpi_ut_valid_object_type(object_type)) {
219 ACPI_ERROR((AE_INFO,
220 "Bad operand object type [0x%X]",
221 object_type));
222
223 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
224 }
225
226 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
227
228
229
230 switch (obj_desc->reference.class) {
231 case ACPI_REFCLASS_DEBUG:
232
233 target_op = AML_DEBUG_OP;
234
235
236
237 case ACPI_REFCLASS_ARG:
238 case ACPI_REFCLASS_LOCAL:
239 case ACPI_REFCLASS_INDEX:
240 case ACPI_REFCLASS_REFOF:
241 case ACPI_REFCLASS_TABLE:
242 case ACPI_REFCLASS_NAME:
243
244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
245 "Operand is a Reference, Class [%s] %2.2X\n",
246 acpi_ut_get_reference_name
247 (obj_desc),
248 obj_desc->reference.
249 class));
250 break;
251
252 default:
253
254 ACPI_ERROR((AE_INFO,
255 "Unknown Reference Class 0x%2.2X in %p",
256 obj_desc->reference.class,
257 obj_desc));
258
259 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
260 }
261 }
262 break;
263
264 default:
265
266
267
268 ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
269 obj_desc,
270 acpi_ut_get_descriptor_name(obj_desc)));
271
272 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
273 }
274
275
276
277 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
278 INCREMENT_ARG_LIST(arg_types);
279
280
281
282
283
284 switch (this_arg_type) {
285 case ARGI_REF_OR_STRING:
286
287 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
288 ACPI_DESC_TYPE_OPERAND)
289 && (obj_desc->common.type == ACPI_TYPE_STRING)) {
290
291
292
293
294 goto next_operand;
295 }
296
297
298
299
300
301
302
303 case ARGI_REFERENCE:
304 case ARGI_INTEGER_REF:
305 case ARGI_OBJECT_REF:
306 case ARGI_DEVICE_REF:
307 case ARGI_TARGETREF:
308 case ARGI_FIXED_TARGET:
309 case ARGI_SIMPLE_TARGET:
310
311
312
313
314 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
315 ACPI_DESC_TYPE_NAMED) {
316 goto next_operand;
317 }
318
319 status =
320 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
321 object_type, obj_desc);
322 if (ACPI_FAILURE(status)) {
323 return_ACPI_STATUS(status);
324 }
325 goto next_operand;
326
327 case ARGI_DATAREFOBJ:
328
329
330
331
332
333
334 if ((opcode == AML_STORE_OP) &&
335 ((*stack_ptr)->common.type ==
336 ACPI_TYPE_LOCAL_REFERENCE)
337 && ((*stack_ptr)->reference.class ==
338 ACPI_REFCLASS_INDEX)) {
339 goto next_operand;
340 }
341 break;
342
343 default:
344
345
346
347 break;
348 }
349
350
351
352
353 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
356 }
357
358
359
360 obj_desc = *stack_ptr;
361
362
363
364
365 switch (this_arg_type) {
366
367
368
369
370 case ARGI_MUTEX:
371
372
373
374 type_needed = ACPI_TYPE_MUTEX;
375 break;
376
377 case ARGI_EVENT:
378
379
380
381 type_needed = ACPI_TYPE_EVENT;
382 break;
383
384 case ARGI_PACKAGE:
385
386
387
388 type_needed = ACPI_TYPE_PACKAGE;
389 break;
390
391 case ARGI_ANYTYPE:
392
393
394
395 type_needed = ACPI_TYPE_ANY;
396 break;
397
398 case ARGI_DDBHANDLE:
399
400
401
402 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
403 break;
404
405
406
407
408 case ARGI_INTEGER:
409
410
411
412
413
414
415 status =
416 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
417 if (ACPI_FAILURE(status)) {
418 if (status == AE_TYPE) {
419 ACPI_ERROR((AE_INFO,
420 "Needed [Integer/String/Buffer], found [%s] %p",
421 acpi_ut_get_object_type_name
422 (obj_desc), obj_desc));
423
424 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
425 }
426
427 return_ACPI_STATUS(status);
428 }
429
430 if (obj_desc != *stack_ptr) {
431 acpi_ut_remove_reference(obj_desc);
432 }
433 goto next_operand;
434
435 case ARGI_BUFFER:
436
437
438
439
440
441 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
442 if (ACPI_FAILURE(status)) {
443 if (status == AE_TYPE) {
444 ACPI_ERROR((AE_INFO,
445 "Needed [Integer/String/Buffer], found [%s] %p",
446 acpi_ut_get_object_type_name
447 (obj_desc), obj_desc));
448
449 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
450 }
451
452 return_ACPI_STATUS(status);
453 }
454
455 if (obj_desc != *stack_ptr) {
456 acpi_ut_remove_reference(obj_desc);
457 }
458 goto next_operand;
459
460 case ARGI_STRING:
461
462
463
464
465
466 status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
467 ACPI_IMPLICIT_CONVERT_HEX);
468 if (ACPI_FAILURE(status)) {
469 if (status == AE_TYPE) {
470 ACPI_ERROR((AE_INFO,
471 "Needed [Integer/String/Buffer], found [%s] %p",
472 acpi_ut_get_object_type_name
473 (obj_desc), obj_desc));
474
475 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
476 }
477
478 return_ACPI_STATUS(status);
479 }
480
481 if (obj_desc != *stack_ptr) {
482 acpi_ut_remove_reference(obj_desc);
483 }
484 goto next_operand;
485
486 case ARGI_COMPUTEDATA:
487
488
489
490 switch (obj_desc->common.type) {
491 case ACPI_TYPE_INTEGER:
492 case ACPI_TYPE_STRING:
493 case ACPI_TYPE_BUFFER:
494
495
496 break;
497
498 default:
499 ACPI_ERROR((AE_INFO,
500 "Needed [Integer/String/Buffer], found [%s] %p",
501 acpi_ut_get_object_type_name
502 (obj_desc), obj_desc));
503
504 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
505 }
506 goto next_operand;
507
508 case ARGI_BUFFER_OR_STRING:
509
510
511
512 switch (obj_desc->common.type) {
513 case ACPI_TYPE_STRING:
514 case ACPI_TYPE_BUFFER:
515
516
517 break;
518
519 case ACPI_TYPE_INTEGER:
520
521
522
523 status =
524 acpi_ex_convert_to_buffer(obj_desc,
525 stack_ptr);
526 if (ACPI_FAILURE(status)) {
527 return_ACPI_STATUS(status);
528 }
529
530 if (obj_desc != *stack_ptr) {
531 acpi_ut_remove_reference(obj_desc);
532 }
533 break;
534
535 default:
536 ACPI_ERROR((AE_INFO,
537 "Needed [Integer/String/Buffer], found [%s] %p",
538 acpi_ut_get_object_type_name
539 (obj_desc), obj_desc));
540
541 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
542 }
543 goto next_operand;
544
545 case ARGI_DATAOBJECT:
546
547
548
549
550
551
552
553 switch (obj_desc->common.type) {
554 case ACPI_TYPE_PACKAGE:
555 case ACPI_TYPE_STRING:
556 case ACPI_TYPE_BUFFER:
557 case ACPI_TYPE_LOCAL_REFERENCE:
558
559
560 break;
561
562 default:
563
564 ACPI_ERROR((AE_INFO,
565 "Needed [Buffer/String/Package/Reference], found [%s] %p",
566 acpi_ut_get_object_type_name
567 (obj_desc), obj_desc));
568
569 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
570 }
571 goto next_operand;
572
573 case ARGI_COMPLEXOBJ:
574
575
576
577 switch (obj_desc->common.type) {
578 case ACPI_TYPE_PACKAGE:
579 case ACPI_TYPE_STRING:
580 case ACPI_TYPE_BUFFER:
581
582
583 break;
584
585 default:
586
587 ACPI_ERROR((AE_INFO,
588 "Needed [Buffer/String/Package], found [%s] %p",
589 acpi_ut_get_object_type_name
590 (obj_desc), obj_desc));
591
592 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
593 }
594 goto next_operand;
595
596 case ARGI_REGION_OR_BUFFER:
597
598
599
600 switch (obj_desc->common.type) {
601 case ACPI_TYPE_BUFFER:
602 case ACPI_TYPE_REGION:
603
604
605 break;
606
607 default:
608
609 ACPI_ERROR((AE_INFO,
610 "Needed [Region/Buffer], found [%s] %p",
611 acpi_ut_get_object_type_name
612 (obj_desc), obj_desc));
613
614 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
615 }
616 goto next_operand;
617
618 case ARGI_DATAREFOBJ:
619
620
621
622 switch (obj_desc->common.type) {
623 case ACPI_TYPE_INTEGER:
624 case ACPI_TYPE_PACKAGE:
625 case ACPI_TYPE_STRING:
626 case ACPI_TYPE_BUFFER:
627 case ACPI_TYPE_BUFFER_FIELD:
628 case ACPI_TYPE_LOCAL_REFERENCE:
629 case ACPI_TYPE_LOCAL_REGION_FIELD:
630 case ACPI_TYPE_LOCAL_BANK_FIELD:
631 case ACPI_TYPE_LOCAL_INDEX_FIELD:
632 case ACPI_TYPE_DDB_HANDLE:
633
634
635 break;
636
637 default:
638
639 if (acpi_gbl_enable_interpreter_slack) {
640
641
642
643
644
645 break;
646 }
647
648 if (target_op == AML_DEBUG_OP) {
649
650
651
652 break;
653 }
654
655 ACPI_ERROR((AE_INFO,
656 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
657 acpi_ut_get_object_type_name
658 (obj_desc), obj_desc));
659
660 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
661 }
662 goto next_operand;
663
664 default:
665
666
667
668 ACPI_ERROR((AE_INFO,
669 "Internal - Unknown ARGI (required operand) type 0x%X",
670 this_arg_type));
671
672 return_ACPI_STATUS(AE_BAD_PARAMETER);
673 }
674
675
676
677
678
679 status = acpi_ex_check_object_type(type_needed,
680 (*stack_ptr)->common.type,
681 *stack_ptr);
682 if (ACPI_FAILURE(status)) {
683 return_ACPI_STATUS(status);
684 }
685
686next_operand:
687
688
689
690
691 if (GET_CURRENT_ARG_TYPE(arg_types)) {
692 stack_ptr--;
693 }
694 }
695
696 ACPI_DUMP_OPERANDS(walk_state->operands,
697 acpi_ps_get_opcode_name(opcode),
698 walk_state->num_operands);
699
700 return_ACPI_STATUS(status);
701}
702