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 <linux/module.h>
45
46#include <acpi/acpi.h>
47#include "accommon.h"
48#include "acnamesp.h"
49
50#define _COMPONENT ACPI_UTILITIES
51ACPI_MODULE_NAME("utmisc")
52
53
54
55
56#define ACPI_COMMON_MSG_SUFFIX \
57 acpi_os_printf(" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
58
59
60
61
62
63
64
65
66
67
68
69
70
71const char *acpi_ut_validate_exception(acpi_status status)
72{
73 u32 sub_status;
74 const char *exception = NULL;
75
76 ACPI_FUNCTION_ENTRY();
77
78
79
80
81 sub_status = (status & ~AE_CODE_MASK);
82
83 switch (status & AE_CODE_MASK) {
84 case AE_CODE_ENVIRONMENTAL:
85
86 if (sub_status <= AE_CODE_ENV_MAX) {
87 exception = acpi_gbl_exception_names_env[sub_status];
88 }
89 break;
90
91 case AE_CODE_PROGRAMMER:
92
93 if (sub_status <= AE_CODE_PGM_MAX) {
94 exception = acpi_gbl_exception_names_pgm[sub_status];
95 }
96 break;
97
98 case AE_CODE_ACPI_TABLES:
99
100 if (sub_status <= AE_CODE_TBL_MAX) {
101 exception = acpi_gbl_exception_names_tbl[sub_status];
102 }
103 break;
104
105 case AE_CODE_AML:
106
107 if (sub_status <= AE_CODE_AML_MAX) {
108 exception = acpi_gbl_exception_names_aml[sub_status];
109 }
110 break;
111
112 case AE_CODE_CONTROL:
113
114 if (sub_status <= AE_CODE_CTRL_MAX) {
115 exception = acpi_gbl_exception_names_ctrl[sub_status];
116 }
117 break;
118
119 default:
120 break;
121 }
122
123 return (ACPI_CAST_PTR(const char, exception));
124}
125
126
127
128
129
130
131
132
133
134
135
136
137
138u8 acpi_ut_is_pci_root_bridge(char *id)
139{
140
141
142
143
144
145 if (!(ACPI_STRCMP(id,
146 PCI_ROOT_HID_STRING)) ||
147 !(ACPI_STRCMP(id, PCI_EXPRESS_ROOT_HID_STRING))) {
148 return (TRUE);
149 }
150
151 return (FALSE);
152}
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
169{
170
171
172
173 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
174 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
175 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
176 return (TRUE);
177 }
178
179 return (FALSE);
180}
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
197{
198 u32 i;
199 u32 j;
200 u32 k;
201 acpi_status status;
202
203 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
204
205
206
207 if (*owner_id) {
208 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
209 *owner_id));
210 return_ACPI_STATUS(AE_ALREADY_EXISTS);
211 }
212
213
214
215 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
216 if (ACPI_FAILURE(status)) {
217 return_ACPI_STATUS(status);
218 }
219
220
221
222
223
224
225 for (i = 0, j = acpi_gbl_last_owner_id_index;
226 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
227 if (j >= ACPI_NUM_OWNERID_MASKS) {
228 j = 0;
229 }
230
231 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
232 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
233
234
235
236 break;
237 }
238
239 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
240
241
242
243
244
245 acpi_gbl_owner_id_mask[j] |= (1 << k);
246
247 acpi_gbl_last_owner_id_index = (u8) j;
248 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
249
250
251
252
253
254
255
256 *owner_id =
257 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
258
259 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
260 "Allocated OwnerId: %2.2X\n",
261 (unsigned int)*owner_id));
262 goto exit;
263 }
264 }
265
266 acpi_gbl_next_owner_id_offset = 0;
267 }
268
269
270
271
272
273
274
275
276
277
278
279 status = AE_OWNER_ID_LIMIT;
280 ACPI_ERROR((AE_INFO,
281 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
282
283 exit:
284 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
285 return_ACPI_STATUS(status);
286}
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
303{
304 acpi_owner_id owner_id = *owner_id_ptr;
305 acpi_status status;
306 u32 index;
307 u32 bit;
308
309 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
310
311
312
313 *owner_id_ptr = 0;
314
315
316
317 if (owner_id == 0) {
318 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
319 return_VOID;
320 }
321
322
323
324 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
325 if (ACPI_FAILURE(status)) {
326 return_VOID;
327 }
328
329
330
331 owner_id--;
332
333
334
335 index = ACPI_DIV_32(owner_id);
336 bit = 1 << ACPI_MOD_32(owner_id);
337
338
339
340 if (acpi_gbl_owner_id_mask[index] & bit) {
341 acpi_gbl_owner_id_mask[index] ^= bit;
342 } else {
343 ACPI_ERROR((AE_INFO,
344 "Release of non-allocated OwnerId: %2.2X",
345 owner_id + 1));
346 }
347
348 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
349 return_VOID;
350}
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366void acpi_ut_strupr(char *src_string)
367{
368 char *string;
369
370 ACPI_FUNCTION_ENTRY();
371
372 if (!src_string) {
373 return;
374 }
375
376
377
378 for (string = src_string; *string; string++) {
379 *string = (char)ACPI_TOUPPER(*string);
380 }
381
382 return;
383}
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399void acpi_ut_print_string(char *string, u8 max_length)
400{
401 u32 i;
402
403 if (!string) {
404 acpi_os_printf("<\"NULL STRING PTR\">");
405 return;
406 }
407
408 acpi_os_printf("\"");
409 for (i = 0; string[i] && (i < max_length); i++) {
410
411
412
413 switch (string[i]) {
414 case 0x07:
415 acpi_os_printf("\\a");
416 break;
417
418 case 0x08:
419 acpi_os_printf("\\b");
420 break;
421
422 case 0x0C:
423 acpi_os_printf("\\f");
424 break;
425
426 case 0x0A:
427 acpi_os_printf("\\n");
428 break;
429
430 case 0x0D:
431 acpi_os_printf("\\r");
432 break;
433
434 case 0x09:
435 acpi_os_printf("\\t");
436 break;
437
438 case 0x0B:
439 acpi_os_printf("\\v");
440 break;
441
442 case '\'':
443 case '\"':
444 case '\\':
445 acpi_os_printf("\\%c", (int)string[i]);
446 break;
447
448 default:
449
450
451
452 if (ACPI_IS_PRINT(string[i])) {
453
454
455 acpi_os_printf("%c", (int)string[i]);
456 } else {
457
458
459 acpi_os_printf("\\x%2.2X", (s32) string[i]);
460 }
461 break;
462 }
463 }
464 acpi_os_printf("\"");
465
466 if (i == max_length && string[i]) {
467 acpi_os_printf("...");
468 }
469}
470
471
472
473
474
475
476
477
478
479
480
481
482
483u32 acpi_ut_dword_byte_swap(u32 value)
484{
485 union {
486 u32 value;
487 u8 bytes[4];
488 } out;
489 union {
490 u32 value;
491 u8 bytes[4];
492 } in;
493
494 ACPI_FUNCTION_ENTRY();
495
496 in.value = value;
497
498 out.bytes[0] = in.bytes[3];
499 out.bytes[1] = in.bytes[2];
500 out.bytes[2] = in.bytes[1];
501 out.bytes[3] = in.bytes[0];
502
503 return (out.value);
504}
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521void acpi_ut_set_integer_width(u8 revision)
522{
523
524 if (revision < 2) {
525
526
527
528 acpi_gbl_integer_bit_width = 32;
529 acpi_gbl_integer_nybble_width = 8;
530 acpi_gbl_integer_byte_width = 4;
531 } else {
532
533
534 acpi_gbl_integer_bit_width = 64;
535 acpi_gbl_integer_nybble_width = 16;
536 acpi_gbl_integer_byte_width = 8;
537 }
538}
539
540#ifdef ACPI_DEBUG_OUTPUT
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556void
557acpi_ut_display_init_pathname(u8 type,
558 struct acpi_namespace_node *obj_handle,
559 char *path)
560{
561 acpi_status status;
562 struct acpi_buffer buffer;
563
564 ACPI_FUNCTION_ENTRY();
565
566
567
568 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
569 return;
570 }
571
572
573
574 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
575 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
576 if (ACPI_FAILURE(status)) {
577 return;
578 }
579
580
581
582 switch (type) {
583 case ACPI_TYPE_METHOD:
584 acpi_os_printf("Executing ");
585 break;
586
587 default:
588 acpi_os_printf("Initializing ");
589 break;
590 }
591
592
593
594 acpi_os_printf("%-12s %s",
595 acpi_ut_get_type_name(type), (char *)buffer.pointer);
596
597
598
599 if (path) {
600 acpi_os_printf(".%s", path);
601 }
602 acpi_os_printf("\n");
603
604 ACPI_FREE(buffer.pointer);
605}
606#endif
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626u8 acpi_ut_valid_acpi_char(char character, u32 position)
627{
628
629 if (!((character >= 'A' && character <= 'Z') ||
630 (character >= '0' && character <= '9') || (character == '_'))) {
631
632
633
634 if (character == '!' && position == 3) {
635 return (TRUE);
636 }
637
638 return (FALSE);
639 }
640
641 return (TRUE);
642}
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659u8 acpi_ut_valid_acpi_name(u32 name)
660{
661 u32 i;
662
663 ACPI_FUNCTION_ENTRY();
664
665 for (i = 0; i < ACPI_NAME_SIZE; i++) {
666 if (!acpi_ut_valid_acpi_char
667 ((ACPI_CAST_PTR(char, &name))[i], i)) {
668 return (FALSE);
669 }
670 }
671
672 return (TRUE);
673}
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688acpi_name acpi_ut_repair_name(char *name)
689{
690 u32 i;
691 char new_name[ACPI_NAME_SIZE];
692
693 for (i = 0; i < ACPI_NAME_SIZE; i++) {
694 new_name[i] = name[i];
695
696
697
698
699
700
701 if (!acpi_ut_valid_acpi_char(name[i], i)) {
702 new_name[i] = '*';
703 }
704 }
705
706 return (*(u32 *) new_name);
707}
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727acpi_status
728acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
729{
730 u32 this_digit = 0;
731 acpi_integer return_value = 0;
732 acpi_integer quotient;
733 acpi_integer dividend;
734 u32 to_integer_op = (base == ACPI_ANY_BASE);
735 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
736 u8 valid_digits = 0;
737 u8 sign_of0x = 0;
738 u8 term = 0;
739
740 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
741
742 switch (base) {
743 case ACPI_ANY_BASE:
744 case 16:
745 break;
746
747 default:
748
749 return_ACPI_STATUS(AE_BAD_PARAMETER);
750 }
751
752 if (!string) {
753 goto error_exit;
754 }
755
756
757
758 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
759 string++;
760 }
761
762 if (to_integer_op) {
763
764
765
766
767 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
768 sign_of0x = 1;
769 base = 16;
770
771
772 string += 2;
773 } else {
774 base = 10;
775 }
776 }
777
778
779
780 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
781 if (to_integer_op) {
782 goto error_exit;
783 } else {
784 goto all_done;
785 }
786 }
787
788
789
790
791
792 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
793
794
795
796 while (*string) {
797 if (ACPI_IS_DIGIT(*string)) {
798
799
800
801 this_digit = ((u8) * string) - '0';
802 } else if (base == 10) {
803
804
805
806 term = 1;
807 } else {
808 this_digit = (u8) ACPI_TOUPPER(*string);
809 if (ACPI_IS_XDIGIT((char)this_digit)) {
810
811
812
813 this_digit = this_digit - 'A' + 10;
814 } else {
815 term = 1;
816 }
817 }
818
819 if (term) {
820 if (to_integer_op) {
821 goto error_exit;
822 } else {
823 break;
824 }
825 } else if ((valid_digits == 0) && (this_digit == 0)
826 && !sign_of0x) {
827
828
829 string++;
830 continue;
831 }
832
833 valid_digits++;
834
835 if (sign_of0x && ((valid_digits > 16)
836 || ((valid_digits > 8) && mode32))) {
837
838
839
840
841
842 goto error_exit;
843 }
844
845
846
847 (void)
848 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
849 base, "ient, NULL);
850
851 if (return_value > quotient) {
852 if (to_integer_op) {
853 goto error_exit;
854 } else {
855 break;
856 }
857 }
858
859 return_value *= base;
860 return_value += this_digit;
861 string++;
862 }
863
864
865
866 all_done:
867
868 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
869 ACPI_FORMAT_UINT64(return_value)));
870
871 *ret_integer = return_value;
872 return_ACPI_STATUS(AE_OK);
873
874 error_exit:
875
876
877 if (base == 10) {
878 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
879 } else {
880 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
881 }
882}
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898acpi_status
899acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
900 u16 action,
901 union acpi_generic_state **state_list)
902{
903 union acpi_generic_state *state;
904
905 ACPI_FUNCTION_ENTRY();
906
907
908
909 if (!object) {
910 return (AE_OK);
911 }
912
913 state = acpi_ut_create_update_state(object, action);
914 if (!state) {
915 return (AE_NO_MEMORY);
916 }
917
918 acpi_ut_push_generic_state(state_list, state);
919 return (AE_OK);
920}
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937acpi_status
938acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
939 void *target_object,
940 acpi_pkg_callback walk_callback, void *context)
941{
942 acpi_status status = AE_OK;
943 union acpi_generic_state *state_list = NULL;
944 union acpi_generic_state *state;
945 u32 this_index;
946 union acpi_operand_object *this_source_obj;
947
948 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
949
950 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
951 if (!state) {
952 return_ACPI_STATUS(AE_NO_MEMORY);
953 }
954
955 while (state) {
956
957
958
959 this_index = state->pkg.index;
960 this_source_obj = (union acpi_operand_object *)
961 state->pkg.source_object->package.elements[this_index];
962
963
964
965
966
967
968
969
970
971 if ((!this_source_obj) ||
972 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
973 ACPI_DESC_TYPE_OPERAND)
974 || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) {
975 status =
976 walk_callback(ACPI_COPY_TYPE_SIMPLE,
977 this_source_obj, state, context);
978 if (ACPI_FAILURE(status)) {
979 return_ACPI_STATUS(status);
980 }
981
982 state->pkg.index++;
983 while (state->pkg.index >=
984 state->pkg.source_object->package.count) {
985
986
987
988
989
990
991
992 acpi_ut_delete_generic_state(state);
993 state = acpi_ut_pop_generic_state(&state_list);
994
995
996
997 if (!state) {
998
999
1000
1001
1002
1003 return_ACPI_STATUS(AE_OK);
1004 }
1005
1006
1007
1008
1009
1010 state->pkg.index++;
1011 }
1012 } else {
1013
1014
1015 status =
1016 walk_callback(ACPI_COPY_TYPE_PACKAGE,
1017 this_source_obj, state, context);
1018 if (ACPI_FAILURE(status)) {
1019 return_ACPI_STATUS(status);
1020 }
1021
1022
1023
1024
1025
1026 acpi_ut_push_generic_state(&state_list, state);
1027 state = acpi_ut_create_pkg_state(this_source_obj,
1028 state->pkg.
1029 this_target_obj, 0);
1030 if (!state) {
1031
1032
1033
1034 while (state_list) {
1035 state =
1036 acpi_ut_pop_generic_state
1037 (&state_list);
1038 acpi_ut_delete_generic_state(state);
1039 }
1040 return_ACPI_STATUS(AE_NO_MEMORY);
1041 }
1042 }
1043 }
1044
1045
1046
1047 return_ACPI_STATUS(AE_AML_INTERNAL);
1048}
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064void ACPI_INTERNAL_VAR_XFACE
1065acpi_error(const char *module_name, u32 line_number, const char *format, ...)
1066{
1067 va_list args;
1068
1069 acpi_os_printf("ACPI Error: ");
1070
1071 va_start(args, format);
1072 acpi_os_vprintf(format, args);
1073 ACPI_COMMON_MSG_SUFFIX;
1074 va_end(args);
1075}
1076
1077void ACPI_INTERNAL_VAR_XFACE
1078acpi_exception(const char *module_name,
1079 u32 line_number, acpi_status status, const char *format, ...)
1080{
1081 va_list args;
1082
1083 acpi_os_printf("ACPI Exception: %s, ", acpi_format_exception(status));
1084
1085 va_start(args, format);
1086 acpi_os_vprintf(format, args);
1087 ACPI_COMMON_MSG_SUFFIX;
1088 va_end(args);
1089}
1090
1091void ACPI_INTERNAL_VAR_XFACE
1092acpi_warning(const char *module_name, u32 line_number, const char *format, ...)
1093{
1094 va_list args;
1095
1096 acpi_os_printf("ACPI Warning: ");
1097
1098 va_start(args, format);
1099 acpi_os_vprintf(format, args);
1100 ACPI_COMMON_MSG_SUFFIX;
1101 va_end(args);
1102}
1103
1104void ACPI_INTERNAL_VAR_XFACE
1105acpi_info(const char *module_name, u32 line_number, const char *format, ...)
1106{
1107 va_list args;
1108
1109 acpi_os_printf("ACPI: ");
1110
1111 va_start(args, format);
1112 acpi_os_vprintf(format, args);
1113 acpi_os_printf("\n");
1114 va_end(args);
1115}
1116
1117ACPI_EXPORT_SYMBOL(acpi_error)
1118ACPI_EXPORT_SYMBOL(acpi_exception)
1119ACPI_EXPORT_SYMBOL(acpi_warning)
1120ACPI_EXPORT_SYMBOL(acpi_info)
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141void ACPI_INTERNAL_VAR_XFACE
1142acpi_ut_predefined_warning(const char *module_name,
1143 u32 line_number,
1144 char *pathname,
1145 u8 node_flags, const char *format, ...)
1146{
1147 va_list args;
1148
1149
1150
1151
1152
1153 if (node_flags & ANOBJ_EVALUATED) {
1154 return;
1155 }
1156
1157 acpi_os_printf("ACPI Warning for %s: ", pathname);
1158
1159 va_start(args, format);
1160 acpi_os_vprintf(format, args);
1161 ACPI_COMMON_MSG_SUFFIX;
1162 va_end(args);
1163}
1164