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 "accommon.h"
47#include "acnamesp.h"
48
49#define _COMPONENT ACPI_NAMESPACE
50ACPI_MODULE_NAME("nsrepair2")
51
52
53
54
55
56typedef
57acpi_status(*acpi_repair_function) (struct acpi_predefined_data *data,
58 union acpi_operand_object **return_object_ptr);
59
60typedef struct acpi_repair_info {
61 char name[ACPI_NAME_SIZE];
62 acpi_repair_function repair_function;
63
64} acpi_repair_info;
65
66
67
68static const struct acpi_repair_info *acpi_ns_match_repairable_name(struct
69 acpi_namespace_node
70 *node);
71
72static acpi_status
73acpi_ns_repair_ALR(struct acpi_predefined_data *data,
74 union acpi_operand_object **return_object_ptr);
75
76static acpi_status
77acpi_ns_repair_CID(struct acpi_predefined_data *data,
78 union acpi_operand_object **return_object_ptr);
79
80static acpi_status
81acpi_ns_repair_FDE(struct acpi_predefined_data *data,
82 union acpi_operand_object **return_object_ptr);
83
84static acpi_status
85acpi_ns_repair_HID(struct acpi_predefined_data *data,
86 union acpi_operand_object **return_object_ptr);
87
88static acpi_status
89acpi_ns_repair_PSS(struct acpi_predefined_data *data,
90 union acpi_operand_object **return_object_ptr);
91
92static acpi_status
93acpi_ns_repair_TSS(struct acpi_predefined_data *data,
94 union acpi_operand_object **return_object_ptr);
95
96static acpi_status
97acpi_ns_check_sorted_list(struct acpi_predefined_data *data,
98 union acpi_operand_object *return_object,
99 u32 expected_count,
100 u32 sort_index,
101 u8 sort_direction, char *sort_key_name);
102
103static void
104acpi_ns_sort_list(union acpi_operand_object **elements,
105 u32 count, u32 index, u8 sort_direction);
106
107
108
109#define ACPI_SORT_ASCENDING 0
110#define ACPI_SORT_DESCENDING 1
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133static const struct acpi_repair_info acpi_ns_repairable_names[] = {
134 {"_ALR", acpi_ns_repair_ALR},
135 {"_CID", acpi_ns_repair_CID},
136 {"_FDE", acpi_ns_repair_FDE},
137 {"_GTM", acpi_ns_repair_FDE},
138 {"_HID", acpi_ns_repair_HID},
139 {"_PSS", acpi_ns_repair_PSS},
140 {"_TSS", acpi_ns_repair_TSS},
141 {{0, 0, 0, 0}, NULL}
142};
143
144#define ACPI_FDE_FIELD_COUNT 5
145#define ACPI_FDE_BYTE_BUFFER_SIZE 5
146#define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (u32))
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166acpi_status
167acpi_ns_complex_repairs(struct acpi_predefined_data *data,
168 struct acpi_namespace_node *node,
169 acpi_status validate_status,
170 union acpi_operand_object **return_object_ptr)
171{
172 const struct acpi_repair_info *predefined;
173 acpi_status status;
174
175
176
177 predefined = acpi_ns_match_repairable_name(node);
178 if (!predefined) {
179 return (validate_status);
180 }
181
182 status = predefined->repair_function(data, return_object_ptr);
183 return (status);
184}
185
186
187
188
189
190
191
192
193
194
195
196
197
198static const struct acpi_repair_info *acpi_ns_match_repairable_name(struct
199 acpi_namespace_node
200 *node)
201{
202 const struct acpi_repair_info *this_name;
203
204
205
206 this_name = acpi_ns_repairable_names;
207 while (this_name->repair_function) {
208 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) {
209 return (this_name);
210 }
211 this_name++;
212 }
213
214 return (NULL);
215}
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232static acpi_status
233acpi_ns_repair_ALR(struct acpi_predefined_data *data,
234 union acpi_operand_object **return_object_ptr)
235{
236 union acpi_operand_object *return_object = *return_object_ptr;
237 acpi_status status;
238
239 status = acpi_ns_check_sorted_list(data, return_object, 2, 1,
240 ACPI_SORT_ASCENDING,
241 "AmbientIlluminance");
242
243 return (status);
244}
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263static acpi_status
264acpi_ns_repair_FDE(struct acpi_predefined_data *data,
265 union acpi_operand_object **return_object_ptr)
266{
267 union acpi_operand_object *return_object = *return_object_ptr;
268 union acpi_operand_object *buffer_object;
269 u8 *byte_buffer;
270 u32 *dword_buffer;
271 u32 i;
272
273 ACPI_FUNCTION_NAME(ns_repair_FDE);
274
275 switch (return_object->common.type) {
276 case ACPI_TYPE_BUFFER:
277
278
279
280 if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) {
281 return (AE_OK);
282 }
283
284
285
286 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) {
287 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
288 data->node_flags,
289 "Incorrect return buffer length %u, expected %u",
290 return_object->buffer.length,
291 ACPI_FDE_DWORD_BUFFER_SIZE));
292
293 return (AE_AML_OPERAND_TYPE);
294 }
295
296
297
298 buffer_object =
299 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE);
300 if (!buffer_object) {
301 return (AE_NO_MEMORY);
302 }
303
304
305
306 byte_buffer = return_object->buffer.pointer;
307 dword_buffer =
308 ACPI_CAST_PTR(u32, buffer_object->buffer.pointer);
309
310 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) {
311 *dword_buffer = (u32) *byte_buffer;
312 dword_buffer++;
313 byte_buffer++;
314 }
315
316 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
317 "%s Expanded Byte Buffer to expected DWord Buffer\n",
318 data->pathname));
319 break;
320
321 default:
322 return (AE_AML_OPERAND_TYPE);
323 }
324
325
326
327 acpi_ut_remove_reference(return_object);
328 *return_object_ptr = buffer_object;
329
330 data->flags |= ACPI_OBJECT_REPAIRED;
331 return (AE_OK);
332}
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350static acpi_status
351acpi_ns_repair_CID(struct acpi_predefined_data *data,
352 union acpi_operand_object **return_object_ptr)
353{
354 acpi_status status;
355 union acpi_operand_object *return_object = *return_object_ptr;
356 union acpi_operand_object **element_ptr;
357 union acpi_operand_object *original_element;
358 u16 original_ref_count;
359 u32 i;
360
361
362
363 if (return_object->common.type == ACPI_TYPE_STRING) {
364 status = acpi_ns_repair_HID(data, return_object_ptr);
365 return (status);
366 }
367
368
369
370 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
371 return (AE_OK);
372 }
373
374
375
376 element_ptr = return_object->package.elements;
377 for (i = 0; i < return_object->package.count; i++) {
378 original_element = *element_ptr;
379 original_ref_count = original_element->common.reference_count;
380
381 status = acpi_ns_repair_HID(data, element_ptr);
382 if (ACPI_FAILURE(status)) {
383 return (status);
384 }
385
386
387
388 if (original_element != *element_ptr) {
389
390
391
392 (*element_ptr)->common.reference_count =
393 original_ref_count;
394
395 acpi_ut_remove_reference(original_element);
396 }
397
398 element_ptr++;
399 }
400
401 return (AE_OK);
402}
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419static acpi_status
420acpi_ns_repair_HID(struct acpi_predefined_data *data,
421 union acpi_operand_object **return_object_ptr)
422{
423 union acpi_operand_object *return_object = *return_object_ptr;
424 union acpi_operand_object *new_string;
425 char *source;
426 char *dest;
427
428 ACPI_FUNCTION_NAME(ns_repair_HID);
429
430
431
432 if (return_object->common.type != ACPI_TYPE_STRING) {
433 return (AE_OK);
434 }
435
436 if (return_object->string.length == 0) {
437 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
438 "Invalid zero-length _HID or _CID string"));
439
440
441
442 data->flags |= ACPI_OBJECT_REPAIRED;
443 return (AE_OK);
444 }
445
446
447
448 new_string = acpi_ut_create_string_object(return_object->string.length);
449 if (!new_string) {
450 return (AE_NO_MEMORY);
451 }
452
453
454
455
456
457
458
459 source = return_object->string.pointer;
460 if (*source == '*') {
461 source++;
462 new_string->string.length--;
463
464 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
465 "%s: Removed invalid leading asterisk\n",
466 data->pathname));
467 }
468
469
470
471
472
473
474
475
476
477 for (dest = new_string->string.pointer; *source; dest++, source++) {
478 *dest = (char)ACPI_TOUPPER(*source);
479 }
480
481 acpi_ut_remove_reference(return_object);
482 *return_object_ptr = new_string;
483 return (AE_OK);
484}
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501static acpi_status
502acpi_ns_repair_TSS(struct acpi_predefined_data *data,
503 union acpi_operand_object **return_object_ptr)
504{
505 union acpi_operand_object *return_object = *return_object_ptr;
506 acpi_status status;
507 struct acpi_namespace_node *node;
508
509
510
511
512
513
514
515
516
517 status =
518 acpi_ns_get_node(data->node, "^_PSS", ACPI_NS_NO_UPSEARCH, &node);
519 if (ACPI_SUCCESS(status)) {
520 return (AE_OK);
521 }
522
523 status = acpi_ns_check_sorted_list(data, return_object, 5, 1,
524 ACPI_SORT_DESCENDING,
525 "PowerDissipation");
526
527 return (status);
528}
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547static acpi_status
548acpi_ns_repair_PSS(struct acpi_predefined_data *data,
549 union acpi_operand_object **return_object_ptr)
550{
551 union acpi_operand_object *return_object = *return_object_ptr;
552 union acpi_operand_object **outer_elements;
553 u32 outer_element_count;
554 union acpi_operand_object **elements;
555 union acpi_operand_object *obj_desc;
556 u32 previous_value;
557 acpi_status status;
558 u32 i;
559
560
561
562
563
564
565
566 status = acpi_ns_check_sorted_list(data, return_object, 6, 0,
567 ACPI_SORT_DESCENDING,
568 "CpuFrequency");
569 if (ACPI_FAILURE(status)) {
570 return (status);
571 }
572
573
574
575
576
577 previous_value = ACPI_UINT32_MAX;
578 outer_elements = return_object->package.elements;
579 outer_element_count = return_object->package.count;
580
581 for (i = 0; i < outer_element_count; i++) {
582 elements = (*outer_elements)->package.elements;
583 obj_desc = elements[1];
584
585 if ((u32) obj_desc->integer.value > previous_value) {
586 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
587 data->node_flags,
588 "SubPackage[%u,%u] - suspicious power dissipation values",
589 i - 1, i));
590 }
591
592 previous_value = (u32) obj_desc->integer.value;
593 outer_elements++;
594 }
595
596 return (AE_OK);
597}
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618static acpi_status
619acpi_ns_check_sorted_list(struct acpi_predefined_data *data,
620 union acpi_operand_object *return_object,
621 u32 expected_count,
622 u32 sort_index,
623 u8 sort_direction, char *sort_key_name)
624{
625 u32 outer_element_count;
626 union acpi_operand_object **outer_elements;
627 union acpi_operand_object **elements;
628 union acpi_operand_object *obj_desc;
629 u32 i;
630 u32 previous_value;
631
632 ACPI_FUNCTION_NAME(ns_check_sorted_list);
633
634
635
636 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
637 return (AE_AML_OPERAND_TYPE);
638 }
639
640
641
642
643
644
645 outer_elements = return_object->package.elements;
646 outer_element_count = return_object->package.count;
647 if (!outer_element_count) {
648 return (AE_AML_PACKAGE_LIMIT);
649 }
650
651 previous_value = 0;
652 if (sort_direction == ACPI_SORT_DESCENDING) {
653 previous_value = ACPI_UINT32_MAX;
654 }
655
656
657
658 for (i = 0; i < outer_element_count; i++) {
659
660
661
662 if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) {
663 return (AE_AML_OPERAND_TYPE);
664 }
665
666
667
668 if ((*outer_elements)->package.count < expected_count) {
669 return (AE_AML_PACKAGE_LIMIT);
670 }
671
672 elements = (*outer_elements)->package.elements;
673 obj_desc = elements[sort_index];
674
675 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
676 return (AE_AML_OPERAND_TYPE);
677 }
678
679
680
681
682
683 if (((sort_direction == ACPI_SORT_ASCENDING) &&
684 (obj_desc->integer.value < previous_value)) ||
685 ((sort_direction == ACPI_SORT_DESCENDING) &&
686 (obj_desc->integer.value > previous_value))) {
687 acpi_ns_sort_list(return_object->package.elements,
688 outer_element_count, sort_index,
689 sort_direction);
690
691 data->flags |= ACPI_OBJECT_REPAIRED;
692
693 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
694 "%s: Repaired unsorted list - now sorted by %s\n",
695 data->pathname, sort_key_name));
696 return (AE_OK);
697 }
698
699 previous_value = (u32) obj_desc->integer.value;
700 outer_elements++;
701 }
702
703 return (AE_OK);
704}
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724static void
725acpi_ns_sort_list(union acpi_operand_object **elements,
726 u32 count, u32 index, u8 sort_direction)
727{
728 union acpi_operand_object *obj_desc1;
729 union acpi_operand_object *obj_desc2;
730 union acpi_operand_object *temp_obj;
731 u32 i;
732 u32 j;
733
734
735
736 for (i = 1; i < count; i++) {
737 for (j = (count - 1); j >= i; j--) {
738 obj_desc1 = elements[j - 1]->package.elements[index];
739 obj_desc2 = elements[j]->package.elements[index];
740
741 if (((sort_direction == ACPI_SORT_ASCENDING) &&
742 (obj_desc1->integer.value >
743 obj_desc2->integer.value))
744 || ((sort_direction == ACPI_SORT_DESCENDING)
745 && (obj_desc1->integer.value <
746 obj_desc2->integer.value))) {
747 temp_obj = elements[j - 1];
748 elements[j - 1] = elements[j];
749 elements[j] = temp_obj;
750 }
751 }
752 }
753}
754