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/acinterp.h>
47#include <acpi/amlcode.h>
48#include <acpi/amlresrc.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exmisc")
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67acpi_status
68acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
69 union acpi_operand_object **return_desc,
70 struct acpi_walk_state *walk_state)
71{
72 union acpi_operand_object *reference_obj;
73 union acpi_operand_object *referenced_obj;
74
75 ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc);
76
77 *return_desc = NULL;
78
79 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
80 case ACPI_DESC_TYPE_OPERAND:
81
82 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_LOCAL_REFERENCE) {
83 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
84 }
85
86
87
88
89 switch (obj_desc->reference.class) {
90 case ACPI_REFCLASS_LOCAL:
91 case ACPI_REFCLASS_ARG:
92 case ACPI_REFCLASS_DEBUG:
93
94
95
96 referenced_obj = obj_desc->reference.object;
97 break;
98
99 default:
100
101 ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X",
102 obj_desc->reference.class));
103 return_ACPI_STATUS(AE_AML_INTERNAL);
104 }
105 break;
106
107 case ACPI_DESC_TYPE_NAMED:
108
109
110
111
112 referenced_obj = obj_desc;
113 break;
114
115 default:
116
117 ACPI_ERROR((AE_INFO, "Invalid descriptor type %X",
118 ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
119 return_ACPI_STATUS(AE_TYPE);
120 }
121
122
123
124 reference_obj =
125 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
126 if (!reference_obj) {
127 return_ACPI_STATUS(AE_NO_MEMORY);
128 }
129
130 reference_obj->reference.class = ACPI_REFCLASS_REFOF;
131 reference_obj->reference.object = referenced_obj;
132 *return_desc = reference_obj;
133
134 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
135 "Object %p Type [%s], returning Reference %p\n",
136 obj_desc, acpi_ut_get_object_type_name(obj_desc),
137 *return_desc));
138
139 return_ACPI_STATUS(AE_OK);
140}
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157acpi_status
158acpi_ex_concat_template(union acpi_operand_object *operand0,
159 union acpi_operand_object *operand1,
160 union acpi_operand_object **actual_return_desc,
161 struct acpi_walk_state *walk_state)
162{
163 acpi_status status;
164 union acpi_operand_object *return_desc;
165 u8 *new_buf;
166 u8 *end_tag;
167 acpi_size length0;
168 acpi_size length1;
169 acpi_size new_length;
170
171 ACPI_FUNCTION_TRACE(ex_concat_template);
172
173
174
175
176
177
178
179
180
181 status = acpi_ut_get_resource_end_tag(operand0, &end_tag);
182 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status);
184 }
185
186 length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer);
187
188
189
190 status = acpi_ut_get_resource_end_tag(operand1, &end_tag);
191 if (ACPI_FAILURE(status)) {
192 return_ACPI_STATUS(status);
193 }
194
195 length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer);
196
197
198
199 new_length = length0 + length1 + sizeof(struct aml_resource_end_tag);
200
201
202
203 return_desc = acpi_ut_create_buffer_object(new_length);
204 if (!return_desc) {
205 return_ACPI_STATUS(AE_NO_MEMORY);
206 }
207
208
209
210
211
212 new_buf = return_desc->buffer.pointer;
213 ACPI_MEMCPY(new_buf, operand0->buffer.pointer, length0);
214 ACPI_MEMCPY(new_buf + length0, operand1->buffer.pointer, length1);
215
216
217
218 new_buf[new_length - 1] = 0;
219 new_buf[new_length - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
220
221
222
223 *actual_return_desc = return_desc;
224 return_ACPI_STATUS(AE_OK);
225}
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242acpi_status
243acpi_ex_do_concatenate(union acpi_operand_object *operand0,
244 union acpi_operand_object *operand1,
245 union acpi_operand_object **actual_return_desc,
246 struct acpi_walk_state *walk_state)
247{
248 union acpi_operand_object *local_operand1 = operand1;
249 union acpi_operand_object *return_desc;
250 char *new_buf;
251 acpi_status status;
252
253 ACPI_FUNCTION_TRACE(ex_do_concatenate);
254
255
256
257
258
259
260
261
262 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
263 case ACPI_TYPE_INTEGER:
264 status =
265 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
266 break;
267
268 case ACPI_TYPE_STRING:
269 status = acpi_ex_convert_to_string(operand1, &local_operand1,
270 ACPI_IMPLICIT_CONVERT_HEX);
271 break;
272
273 case ACPI_TYPE_BUFFER:
274 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
275 break;
276
277 default:
278 ACPI_ERROR((AE_INFO, "Invalid object type: %X",
279 ACPI_GET_OBJECT_TYPE(operand0)));
280 status = AE_AML_INTERNAL;
281 }
282
283 if (ACPI_FAILURE(status)) {
284 goto cleanup;
285 }
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
301 case ACPI_TYPE_INTEGER:
302
303
304
305
306 return_desc = acpi_ut_create_buffer_object((acpi_size)
307 ACPI_MUL_2
308 (acpi_gbl_integer_byte_width));
309 if (!return_desc) {
310 status = AE_NO_MEMORY;
311 goto cleanup;
312 }
313
314 new_buf = (char *)return_desc->buffer.pointer;
315
316
317
318 ACPI_MEMCPY(new_buf, &operand0->integer.value,
319 acpi_gbl_integer_byte_width);
320
321
322
323 ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width,
324 &local_operand1->integer.value,
325 acpi_gbl_integer_byte_width);
326 break;
327
328 case ACPI_TYPE_STRING:
329
330
331
332 return_desc = acpi_ut_create_string_object(((acpi_size)
333 operand0->string.
334 length +
335 local_operand1->
336 string.length));
337 if (!return_desc) {
338 status = AE_NO_MEMORY;
339 goto cleanup;
340 }
341
342 new_buf = return_desc->string.pointer;
343
344
345
346 ACPI_STRCPY(new_buf, operand0->string.pointer);
347 ACPI_STRCPY(new_buf + operand0->string.length,
348 local_operand1->string.pointer);
349 break;
350
351 case ACPI_TYPE_BUFFER:
352
353
354
355 return_desc = acpi_ut_create_buffer_object(((acpi_size)
356 operand0->buffer.
357 length +
358 local_operand1->
359 buffer.length));
360 if (!return_desc) {
361 status = AE_NO_MEMORY;
362 goto cleanup;
363 }
364
365 new_buf = (char *)return_desc->buffer.pointer;
366
367
368
369 ACPI_MEMCPY(new_buf, operand0->buffer.pointer,
370 operand0->buffer.length);
371 ACPI_MEMCPY(new_buf + operand0->buffer.length,
372 local_operand1->buffer.pointer,
373 local_operand1->buffer.length);
374 break;
375
376 default:
377
378
379
380 ACPI_ERROR((AE_INFO, "Invalid object type: %X",
381 ACPI_GET_OBJECT_TYPE(operand0)));
382 status = AE_AML_INTERNAL;
383 goto cleanup;
384 }
385
386 *actual_return_desc = return_desc;
387
388 cleanup:
389 if (local_operand1 != operand1) {
390 acpi_ut_remove_reference(local_operand1);
391 }
392 return_ACPI_STATUS(status);
393}
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411acpi_integer
412acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1)
413{
414
415 ACPI_FUNCTION_ENTRY();
416
417 switch (opcode) {
418 case AML_ADD_OP:
419
420 return (integer0 + integer1);
421
422 case AML_BIT_AND_OP:
423
424 return (integer0 & integer1);
425
426 case AML_BIT_NAND_OP:
427
428 return (~(integer0 & integer1));
429
430 case AML_BIT_OR_OP:
431
432 return (integer0 | integer1);
433
434 case AML_BIT_NOR_OP:
435
436 return (~(integer0 | integer1));
437
438 case AML_BIT_XOR_OP:
439
440 return (integer0 ^ integer1);
441
442 case AML_MULTIPLY_OP:
443
444 return (integer0 * integer1);
445
446 case AML_SHIFT_LEFT_OP:
447
448
449
450
451
452 if (integer1 >= acpi_gbl_integer_bit_width) {
453 return (0);
454 }
455 return (integer0 << integer1);
456
457 case AML_SHIFT_RIGHT_OP:
458
459
460
461
462
463 if (integer1 >= acpi_gbl_integer_bit_width) {
464 return (0);
465 }
466 return (integer0 >> integer1);
467
468 case AML_SUBTRACT_OP:
469
470 return (integer0 - integer1);
471
472 default:
473
474 return (0);
475 }
476}
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498acpi_status
499acpi_ex_do_logical_numeric_op(u16 opcode,
500 acpi_integer integer0,
501 acpi_integer integer1, u8 * logical_result)
502{
503 acpi_status status = AE_OK;
504 u8 local_result = FALSE;
505
506 ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op);
507
508 switch (opcode) {
509 case AML_LAND_OP:
510
511 if (integer0 && integer1) {
512 local_result = TRUE;
513 }
514 break;
515
516 case AML_LOR_OP:
517
518 if (integer0 || integer1) {
519 local_result = TRUE;
520 }
521 break;
522
523 default:
524 status = AE_AML_INTERNAL;
525 break;
526 }
527
528
529
530 *logical_result = local_result;
531 return_ACPI_STATUS(status);
532}
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560acpi_status
561acpi_ex_do_logical_op(u16 opcode,
562 union acpi_operand_object *operand0,
563 union acpi_operand_object *operand1, u8 * logical_result)
564{
565 union acpi_operand_object *local_operand1 = operand1;
566 acpi_integer integer0;
567 acpi_integer integer1;
568 u32 length0;
569 u32 length1;
570 acpi_status status = AE_OK;
571 u8 local_result = FALSE;
572 int compare;
573
574 ACPI_FUNCTION_TRACE(ex_do_logical_op);
575
576
577
578
579
580
581
582
583 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
584 case ACPI_TYPE_INTEGER:
585 status =
586 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
587 break;
588
589 case ACPI_TYPE_STRING:
590 status = acpi_ex_convert_to_string(operand1, &local_operand1,
591 ACPI_IMPLICIT_CONVERT_HEX);
592 break;
593
594 case ACPI_TYPE_BUFFER:
595 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
596 break;
597
598 default:
599 status = AE_AML_INTERNAL;
600 break;
601 }
602
603 if (ACPI_FAILURE(status)) {
604 goto cleanup;
605 }
606
607
608
609
610 if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) {
611
612
613
614
615 integer0 = operand0->integer.value;
616 integer1 = local_operand1->integer.value;
617
618 switch (opcode) {
619 case AML_LEQUAL_OP:
620
621 if (integer0 == integer1) {
622 local_result = TRUE;
623 }
624 break;
625
626 case AML_LGREATER_OP:
627
628 if (integer0 > integer1) {
629 local_result = TRUE;
630 }
631 break;
632
633 case AML_LLESS_OP:
634
635 if (integer0 < integer1) {
636 local_result = TRUE;
637 }
638 break;
639
640 default:
641 status = AE_AML_INTERNAL;
642 break;
643 }
644 } else {
645
646
647
648
649
650
651 length0 = operand0->buffer.length;
652 length1 = local_operand1->buffer.length;
653
654
655
656 compare = ACPI_MEMCMP(operand0->buffer.pointer,
657 local_operand1->buffer.pointer,
658 (length0 > length1) ? length1 : length0);
659
660 switch (opcode) {
661 case AML_LEQUAL_OP:
662
663
664
665 if ((length0 == length1) && (compare == 0)) {
666
667
668
669 local_result = TRUE;
670 }
671 break;
672
673 case AML_LGREATER_OP:
674
675 if (compare > 0) {
676 local_result = TRUE;
677 goto cleanup;
678 }
679 if (compare < 0) {
680 goto cleanup;
681 }
682
683
684
685 if (length0 > length1) {
686 local_result = TRUE;
687 }
688 break;
689
690 case AML_LLESS_OP:
691
692 if (compare > 0) {
693 goto cleanup;
694 }
695 if (compare < 0) {
696 local_result = TRUE;
697 goto cleanup;
698 }
699
700
701
702 if (length0 < length1) {
703 local_result = TRUE;
704 }
705 break;
706
707 default:
708 status = AE_AML_INTERNAL;
709 break;
710 }
711 }
712
713 cleanup:
714
715
716
717 if (local_operand1 != operand1) {
718 acpi_ut_remove_reference(local_operand1);
719 }
720
721
722
723 *logical_result = local_result;
724 return_ACPI_STATUS(status);
725}
726