1
2
3
4
5
6
7
8
9
10
11#include <acpi/acpi.h>
12#include "accommon.h"
13#include "acnamesp.h"
14
15#define _COMPONENT ACPI_NAMESPACE
16ACPI_MODULE_NAME("nsrepair2")
17
18
19
20
21
22typedef
23acpi_status (*acpi_repair_function) (struct acpi_evaluate_info * info,
24 union acpi_operand_object **
25 return_object_ptr);
26
27typedef struct acpi_repair_info {
28 char name[ACPI_NAMESEG_SIZE];
29 acpi_repair_function repair_function;
30
31} acpi_repair_info;
32
33
34
35static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
36 acpi_namespace_node
37 *node);
38
39static acpi_status
40acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
41 union acpi_operand_object **return_object_ptr);
42
43static acpi_status
44acpi_ns_repair_CID(struct acpi_evaluate_info *info,
45 union acpi_operand_object **return_object_ptr);
46
47static acpi_status
48acpi_ns_repair_CST(struct acpi_evaluate_info *info,
49 union acpi_operand_object **return_object_ptr);
50
51static acpi_status
52acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
53 union acpi_operand_object **return_object_ptr);
54
55static acpi_status
56acpi_ns_repair_HID(struct acpi_evaluate_info *info,
57 union acpi_operand_object **return_object_ptr);
58
59static acpi_status
60acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
61 union acpi_operand_object **return_object_ptr);
62
63static acpi_status
64acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
65 union acpi_operand_object **return_object_ptr);
66
67static acpi_status
68acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
69 union acpi_operand_object **return_object_ptr);
70
71static acpi_status
72acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
73 union acpi_operand_object *return_object,
74 u32 start_index,
75 u32 expected_count,
76 u32 sort_index,
77 u8 sort_direction, char *sort_key_name);
78
79
80
81#define ACPI_SORT_ASCENDING 0
82#define ACPI_SORT_DESCENDING 1
83
84static void
85acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index);
86
87static void
88acpi_ns_sort_list(union acpi_operand_object **elements,
89 u32 count, u32 index, u8 sort_direction);
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114static const struct acpi_repair_info acpi_ns_repairable_names[] = {
115 {"_ALR", acpi_ns_repair_ALR},
116 {"_CID", acpi_ns_repair_CID},
117 {"_CST", acpi_ns_repair_CST},
118 {"_FDE", acpi_ns_repair_FDE},
119 {"_GTM", acpi_ns_repair_FDE},
120 {"_HID", acpi_ns_repair_HID},
121 {"_PRT", acpi_ns_repair_PRT},
122 {"_PSS", acpi_ns_repair_PSS},
123 {"_TSS", acpi_ns_repair_TSS},
124 {{0, 0, 0, 0}, NULL}
125};
126
127#define ACPI_FDE_FIELD_COUNT 5
128#define ACPI_FDE_BYTE_BUFFER_SIZE 5
129#define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * (u32) sizeof (u32))
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149acpi_status
150acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
151 struct acpi_namespace_node *node,
152 acpi_status validate_status,
153 union acpi_operand_object **return_object_ptr)
154{
155 const struct acpi_repair_info *predefined;
156 acpi_status status;
157
158
159
160 predefined = acpi_ns_match_complex_repair(node);
161 if (!predefined) {
162 return (validate_status);
163 }
164
165 status = predefined->repair_function(info, return_object_ptr);
166 return (status);
167}
168
169
170
171
172
173
174
175
176
177
178
179
180
181static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
182 acpi_namespace_node
183 *node)
184{
185 const struct acpi_repair_info *this_name;
186
187
188
189 this_name = acpi_ns_repairable_names;
190 while (this_name->repair_function) {
191 if (ACPI_COMPARE_NAMESEG(node->name.ascii, this_name->name)) {
192 return (this_name);
193 }
194
195 this_name++;
196 }
197
198 return (NULL);
199}
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216static acpi_status
217acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
218 union acpi_operand_object **return_object_ptr)
219{
220 union acpi_operand_object *return_object = *return_object_ptr;
221 acpi_status status;
222
223 status = acpi_ns_check_sorted_list(info, return_object, 0, 2, 1,
224 ACPI_SORT_ASCENDING,
225 "AmbientIlluminance");
226
227 return (status);
228}
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247static acpi_status
248acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
249 union acpi_operand_object **return_object_ptr)
250{
251 union acpi_operand_object *return_object = *return_object_ptr;
252 union acpi_operand_object *buffer_object;
253 u8 *byte_buffer;
254 u32 *dword_buffer;
255 u32 i;
256
257 ACPI_FUNCTION_NAME(ns_repair_FDE);
258
259 switch (return_object->common.type) {
260 case ACPI_TYPE_BUFFER:
261
262
263
264 if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) {
265 return (AE_OK);
266 }
267
268
269
270 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) {
271 ACPI_WARN_PREDEFINED((AE_INFO,
272 info->full_pathname,
273 info->node_flags,
274 "Incorrect return buffer length %u, expected %u",
275 return_object->buffer.length,
276 ACPI_FDE_DWORD_BUFFER_SIZE));
277
278 return (AE_AML_OPERAND_TYPE);
279 }
280
281
282
283 buffer_object =
284 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE);
285 if (!buffer_object) {
286 return (AE_NO_MEMORY);
287 }
288
289
290
291 byte_buffer = return_object->buffer.pointer;
292 dword_buffer = ACPI_CAST_PTR(u32,
293 buffer_object->buffer.pointer);
294
295 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) {
296 *dword_buffer = (u32) *byte_buffer;
297 dword_buffer++;
298 byte_buffer++;
299 }
300
301 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
302 "%s Expanded Byte Buffer to expected DWord Buffer\n",
303 info->full_pathname));
304 break;
305
306 default:
307
308 return (AE_AML_OPERAND_TYPE);
309 }
310
311
312
313 acpi_ut_remove_reference(return_object);
314 *return_object_ptr = buffer_object;
315
316 info->return_flags |= ACPI_OBJECT_REPAIRED;
317 return (AE_OK);
318}
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336static acpi_status
337acpi_ns_repair_CID(struct acpi_evaluate_info *info,
338 union acpi_operand_object **return_object_ptr)
339{
340 acpi_status status;
341 union acpi_operand_object *return_object = *return_object_ptr;
342 union acpi_operand_object **element_ptr;
343 union acpi_operand_object *original_element;
344 u16 original_ref_count;
345 u32 i;
346
347
348
349 if (return_object->common.type == ACPI_TYPE_STRING) {
350 status = acpi_ns_repair_HID(info, return_object_ptr);
351 return (status);
352 }
353
354
355
356 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
357 return (AE_OK);
358 }
359
360
361
362 element_ptr = return_object->package.elements;
363 for (i = 0; i < return_object->package.count; i++) {
364 original_element = *element_ptr;
365 original_ref_count = original_element->common.reference_count;
366
367 status = acpi_ns_repair_HID(info, element_ptr);
368 if (ACPI_FAILURE(status)) {
369 return (status);
370 }
371
372 if (original_element != *element_ptr) {
373
374
375
376 (*element_ptr)->common.reference_count =
377 original_ref_count;
378 }
379
380 element_ptr++;
381 }
382
383 return (AE_OK);
384}
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404static acpi_status
405acpi_ns_repair_CST(struct acpi_evaluate_info *info,
406 union acpi_operand_object **return_object_ptr)
407{
408 union acpi_operand_object *return_object = *return_object_ptr;
409 union acpi_operand_object **outer_elements;
410 u32 outer_element_count;
411 union acpi_operand_object *obj_desc;
412 acpi_status status;
413 u8 removing;
414 u32 i;
415
416 ACPI_FUNCTION_NAME(ns_repair_CST);
417
418
419
420
421 outer_element_count = return_object->package.count - 1;
422 i = 0;
423 while (i < outer_element_count) {
424 outer_elements = &return_object->package.elements[i + 1];
425 removing = FALSE;
426
427 if ((*outer_elements)->package.count == 0) {
428 ACPI_WARN_PREDEFINED((AE_INFO,
429 info->full_pathname,
430 info->node_flags,
431 "SubPackage[%u] - removing entry due to zero count",
432 i));
433 removing = TRUE;
434 goto remove_element;
435 }
436
437 obj_desc = (*outer_elements)->package.elements[1];
438 if ((u32)obj_desc->integer.value == 0) {
439 ACPI_WARN_PREDEFINED((AE_INFO,
440 info->full_pathname,
441 info->node_flags,
442 "SubPackage[%u] - removing entry due to invalid Type(0)",
443 i));
444 removing = TRUE;
445 }
446
447remove_element:
448 if (removing) {
449 acpi_ns_remove_element(return_object, i + 1);
450 outer_element_count--;
451 } else {
452 i++;
453 }
454 }
455
456
457
458 obj_desc = return_object->package.elements[0];
459 obj_desc->integer.value = outer_element_count;
460
461
462
463
464
465 status = acpi_ns_check_sorted_list(info, return_object, 1, 4, 1,
466 ACPI_SORT_ASCENDING, "C-State Type");
467 if (ACPI_FAILURE(status)) {
468 return (status);
469 }
470
471 return (AE_OK);
472}
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489static acpi_status
490acpi_ns_repair_HID(struct acpi_evaluate_info *info,
491 union acpi_operand_object **return_object_ptr)
492{
493 union acpi_operand_object *return_object = *return_object_ptr;
494 union acpi_operand_object *new_string;
495 char *source;
496 char *dest;
497
498 ACPI_FUNCTION_NAME(ns_repair_HID);
499
500
501
502 if (return_object->common.type != ACPI_TYPE_STRING) {
503 return (AE_OK);
504 }
505
506 if (return_object->string.length == 0) {
507 ACPI_WARN_PREDEFINED((AE_INFO,
508 info->full_pathname, info->node_flags,
509 "Invalid zero-length _HID or _CID string"));
510
511
512
513 info->return_flags |= ACPI_OBJECT_REPAIRED;
514 return (AE_OK);
515 }
516
517
518
519 new_string = acpi_ut_create_string_object(return_object->string.length);
520 if (!new_string) {
521 return (AE_NO_MEMORY);
522 }
523
524
525
526
527
528
529
530 source = return_object->string.pointer;
531 if (*source == '*') {
532 source++;
533 new_string->string.length--;
534
535 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
536 "%s: Removed invalid leading asterisk\n",
537 info->full_pathname));
538 }
539
540
541
542
543
544
545
546
547
548 for (dest = new_string->string.pointer; *source; dest++, source++) {
549 *dest = (char)toupper((int)*source);
550 }
551
552 acpi_ut_remove_reference(return_object);
553 *return_object_ptr = new_string;
554 return (AE_OK);
555}
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572static acpi_status
573acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
574 union acpi_operand_object **return_object_ptr)
575{
576 union acpi_operand_object *package_object = *return_object_ptr;
577 union acpi_operand_object **top_object_list;
578 union acpi_operand_object **sub_object_list;
579 union acpi_operand_object *obj_desc;
580 union acpi_operand_object *sub_package;
581 u32 element_count;
582 u32 index;
583
584
585
586 top_object_list = package_object->package.elements;
587 element_count = package_object->package.count;
588
589
590
591 for (index = 0; index < element_count; index++, top_object_list++) {
592 sub_package = *top_object_list;
593 sub_object_list = sub_package->package.elements;
594
595
596
597 if (sub_package->package.count < 4) {
598 continue;
599 }
600
601
602
603
604
605
606
607 obj_desc = sub_object_list[3];
608 if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
609 sub_object_list[3] = sub_object_list[2];
610 sub_object_list[2] = obj_desc;
611 info->return_flags |= ACPI_OBJECT_REPAIRED;
612
613 ACPI_WARN_PREDEFINED((AE_INFO,
614 info->full_pathname,
615 info->node_flags,
616 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
617 index));
618 }
619 }
620
621 return (AE_OK);
622}
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641static acpi_status
642acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
643 union acpi_operand_object **return_object_ptr)
644{
645 union acpi_operand_object *return_object = *return_object_ptr;
646 union acpi_operand_object **outer_elements;
647 u32 outer_element_count;
648 union acpi_operand_object **elements;
649 union acpi_operand_object *obj_desc;
650 u32 previous_value;
651 acpi_status status;
652 u32 i;
653
654
655
656
657
658
659
660 status = acpi_ns_check_sorted_list(info, return_object, 0, 6, 0,
661 ACPI_SORT_DESCENDING,
662 "CpuFrequency");
663 if (ACPI_FAILURE(status)) {
664 return (status);
665 }
666
667
668
669
670
671 previous_value = ACPI_UINT32_MAX;
672 outer_elements = return_object->package.elements;
673 outer_element_count = return_object->package.count;
674
675 for (i = 0; i < outer_element_count; i++) {
676 elements = (*outer_elements)->package.elements;
677 obj_desc = elements[1];
678
679 if ((u32)obj_desc->integer.value > previous_value) {
680 ACPI_WARN_PREDEFINED((AE_INFO,
681 info->full_pathname,
682 info->node_flags,
683 "SubPackage[%u,%u] - suspicious power dissipation values",
684 i - 1, i));
685 }
686
687 previous_value = (u32) obj_desc->integer.value;
688 outer_elements++;
689 }
690
691 return (AE_OK);
692}
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709static acpi_status
710acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
711 union acpi_operand_object **return_object_ptr)
712{
713 union acpi_operand_object *return_object = *return_object_ptr;
714 acpi_status status;
715 struct acpi_namespace_node *node;
716
717
718
719
720
721
722
723
724
725 status = acpi_ns_get_node(info->node, "^_PSS",
726 ACPI_NS_NO_UPSEARCH, &node);
727 if (ACPI_SUCCESS(status)) {
728 return (AE_OK);
729 }
730
731 status = acpi_ns_check_sorted_list(info, return_object, 0, 5, 1,
732 ACPI_SORT_DESCENDING,
733 "PowerDissipation");
734
735 return (status);
736}
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758static acpi_status
759acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
760 union acpi_operand_object *return_object,
761 u32 start_index,
762 u32 expected_count,
763 u32 sort_index,
764 u8 sort_direction, char *sort_key_name)
765{
766 u32 outer_element_count;
767 union acpi_operand_object **outer_elements;
768 union acpi_operand_object **elements;
769 union acpi_operand_object *obj_desc;
770 u32 i;
771 u32 previous_value;
772
773 ACPI_FUNCTION_NAME(ns_check_sorted_list);
774
775
776
777 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
778 return (AE_AML_OPERAND_TYPE);
779 }
780
781
782
783
784
785
786 outer_element_count = return_object->package.count;
787 if (!outer_element_count || start_index >= outer_element_count) {
788 return (AE_AML_PACKAGE_LIMIT);
789 }
790
791 outer_elements = &return_object->package.elements[start_index];
792 outer_element_count -= start_index;
793
794 previous_value = 0;
795 if (sort_direction == ACPI_SORT_DESCENDING) {
796 previous_value = ACPI_UINT32_MAX;
797 }
798
799
800
801 for (i = 0; i < outer_element_count; i++) {
802
803
804
805 if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) {
806 return (AE_AML_OPERAND_TYPE);
807 }
808
809
810
811 if ((*outer_elements)->package.count < expected_count) {
812 return (AE_AML_PACKAGE_LIMIT);
813 }
814
815 elements = (*outer_elements)->package.elements;
816 obj_desc = elements[sort_index];
817
818 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
819 return (AE_AML_OPERAND_TYPE);
820 }
821
822
823
824
825
826 if (((sort_direction == ACPI_SORT_ASCENDING) &&
827 (obj_desc->integer.value < previous_value)) ||
828 ((sort_direction == ACPI_SORT_DESCENDING) &&
829 (obj_desc->integer.value > previous_value))) {
830 acpi_ns_sort_list(&return_object->package.
831 elements[start_index],
832 outer_element_count, sort_index,
833 sort_direction);
834
835 info->return_flags |= ACPI_OBJECT_REPAIRED;
836
837 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
838 "%s: Repaired unsorted list - now sorted by %s\n",
839 info->full_pathname, sort_key_name));
840 return (AE_OK);
841 }
842
843 previous_value = (u32) obj_desc->integer.value;
844 outer_elements++;
845 }
846
847 return (AE_OK);
848}
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868static void
869acpi_ns_sort_list(union acpi_operand_object **elements,
870 u32 count, u32 index, u8 sort_direction)
871{
872 union acpi_operand_object *obj_desc1;
873 union acpi_operand_object *obj_desc2;
874 union acpi_operand_object *temp_obj;
875 u32 i;
876 u32 j;
877
878
879
880 for (i = 1; i < count; i++) {
881 for (j = (count - 1); j >= i; j--) {
882 obj_desc1 = elements[j - 1]->package.elements[index];
883 obj_desc2 = elements[j]->package.elements[index];
884
885 if (((sort_direction == ACPI_SORT_ASCENDING) &&
886 (obj_desc1->integer.value >
887 obj_desc2->integer.value))
888 || ((sort_direction == ACPI_SORT_DESCENDING)
889 && (obj_desc1->integer.value <
890 obj_desc2->integer.value))) {
891 temp_obj = elements[j - 1];
892 elements[j - 1] = elements[j];
893 elements[j] = temp_obj;
894 }
895 }
896 }
897}
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912static void
913acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index)
914{
915 union acpi_operand_object **source;
916 union acpi_operand_object **dest;
917 u32 count;
918 u32 new_count;
919 u32 i;
920
921 ACPI_FUNCTION_NAME(ns_remove_element);
922
923 count = obj_desc->package.count;
924 new_count = count - 1;
925
926 source = obj_desc->package.elements;
927 dest = source;
928
929
930
931 for (i = 0; i < count; i++) {
932 if (i == index) {
933 acpi_ut_remove_reference(*source);
934 acpi_ut_remove_reference(*source);
935 } else {
936 *dest = *source;
937 dest++;
938 }
939
940 source++;
941 }
942
943
944
945 *dest = NULL;
946 obj_desc->package.count = new_count;
947}
948