1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: nsrepair2 - Repair for objects returned by specific
7 * Copyright (C) 2000 - 2020, Intel Corp.
9 *****************************************************************************/
11 #include <acpi/acpi.h>
15 #define _COMPONENT ACPI_NAMESPACE
16 ACPI_MODULE_NAME("nsrepair2")
19 * Information structure and handler for ACPI predefined names that can
20 * be repaired on a per-name basis.
23 acpi_status (*acpi_repair_function
) (struct acpi_evaluate_info
* info
,
24 union acpi_operand_object
**
27 typedef struct acpi_repair_info
{
28 char name
[ACPI_NAMESEG_SIZE
];
29 acpi_repair_function repair_function
;
33 /* Local prototypes */
35 static const struct acpi_repair_info
*acpi_ns_match_complex_repair(struct
40 acpi_ns_repair_ALR(struct acpi_evaluate_info
*info
,
41 union acpi_operand_object
**return_object_ptr
);
44 acpi_ns_repair_CID(struct acpi_evaluate_info
*info
,
45 union acpi_operand_object
**return_object_ptr
);
48 acpi_ns_repair_CST(struct acpi_evaluate_info
*info
,
49 union acpi_operand_object
**return_object_ptr
);
52 acpi_ns_repair_FDE(struct acpi_evaluate_info
*info
,
53 union acpi_operand_object
**return_object_ptr
);
56 acpi_ns_repair_HID(struct acpi_evaluate_info
*info
,
57 union acpi_operand_object
**return_object_ptr
);
60 acpi_ns_repair_PRT(struct acpi_evaluate_info
*info
,
61 union acpi_operand_object
**return_object_ptr
);
64 acpi_ns_repair_PSS(struct acpi_evaluate_info
*info
,
65 union acpi_operand_object
**return_object_ptr
);
68 acpi_ns_repair_TSS(struct acpi_evaluate_info
*info
,
69 union acpi_operand_object
**return_object_ptr
);
72 acpi_ns_check_sorted_list(struct acpi_evaluate_info
*info
,
73 union acpi_operand_object
*return_object
,
77 u8 sort_direction
, char *sort_key_name
);
79 /* Values for sort_direction above */
81 #define ACPI_SORT_ASCENDING 0
82 #define ACPI_SORT_DESCENDING 1
85 acpi_ns_remove_element(union acpi_operand_object
*obj_desc
, u32 index
);
88 acpi_ns_sort_list(union acpi_operand_object
**elements
,
89 u32 count
, u32 index
, u8 sort_direction
);
92 * This table contains the names of the predefined methods for which we can
93 * perform more complex repairs.
97 * _ALR: Sort the list ascending by ambient_illuminance
98 * _CID: Strings: uppercase all, remove any leading asterisk
99 * _CST: Sort the list ascending by C state type
100 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
101 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
102 * _HID: Strings: uppercase all, remove any leading asterisk
103 * _PRT: Fix reversed source_name and source_index
104 * _PSS: Sort the list descending by Power
105 * _TSS: Sort the list descending by Power
107 * Names that must be packages, but cannot be sorted:
109 * _BCL: Values are tied to the Package index where they appear, and cannot
110 * be moved or sorted. These index values are used for _BQC and _BCM.
111 * However, we can fix the case where a buffer is returned, by converting
112 * it to a Package of integers.
114 static 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
}, /* _GTM has same repair as _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
} /* Table terminator */
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))
131 /******************************************************************************
133 * FUNCTION: acpi_ns_complex_repairs
135 * PARAMETERS: info - Method execution information block
136 * node - Namespace node for the method/object
137 * validate_status - Original status of earlier validation
138 * return_object_ptr - Pointer to the object returned from the
139 * evaluation of a method or object
141 * RETURN: Status. AE_OK if repair was successful. If name is not
142 * matched, validate_status is returned.
144 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
147 *****************************************************************************/
150 acpi_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
)
155 const struct acpi_repair_info
*predefined
;
158 ACPI_FUNCTION_TRACE(ns_complex_repairs
);
160 /* Check if this name is in the list of repairable names */
162 predefined
= acpi_ns_match_complex_repair(node
);
164 return_ACPI_STATUS(validate_status
);
167 status
= predefined
->repair_function(info
, return_object_ptr
);
168 return_ACPI_STATUS(status
);
171 /******************************************************************************
173 * FUNCTION: acpi_ns_match_complex_repair
175 * PARAMETERS: node - Namespace node for the method/object
177 * RETURN: Pointer to entry in repair table. NULL indicates not found.
179 * DESCRIPTION: Check an object name against the repairable object list.
181 *****************************************************************************/
183 static const struct acpi_repair_info
*acpi_ns_match_complex_repair(struct
187 const struct acpi_repair_info
*this_name
;
189 /* Search info table for a repairable predefined method/object name */
191 this_name
= acpi_ns_repairable_names
;
192 while (this_name
->repair_function
) {
193 if (ACPI_COMPARE_NAMESEG(node
->name
.ascii
, this_name
->name
)) {
200 return (NULL
); /* Not found */
203 /******************************************************************************
205 * FUNCTION: acpi_ns_repair_ALR
207 * PARAMETERS: info - Method execution information block
208 * return_object_ptr - Pointer to the object returned from the
209 * evaluation of a method or object
211 * RETURN: Status. AE_OK if object is OK or was repaired successfully
213 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
214 * ascending by the ambient illuminance values.
216 *****************************************************************************/
219 acpi_ns_repair_ALR(struct acpi_evaluate_info
*info
,
220 union acpi_operand_object
**return_object_ptr
)
222 union acpi_operand_object
*return_object
= *return_object_ptr
;
225 status
= acpi_ns_check_sorted_list(info
, return_object
, 0, 2, 1,
227 "AmbientIlluminance");
232 /******************************************************************************
234 * FUNCTION: acpi_ns_repair_FDE
236 * PARAMETERS: info - Method execution information block
237 * return_object_ptr - Pointer to the object returned from the
238 * evaluation of a method or object
240 * RETURN: Status. AE_OK if object is OK or was repaired successfully
242 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
243 * value is a Buffer of 5 DWORDs. This function repairs a common
244 * problem where the return value is a Buffer of BYTEs, not
247 *****************************************************************************/
250 acpi_ns_repair_FDE(struct acpi_evaluate_info
*info
,
251 union acpi_operand_object
**return_object_ptr
)
253 union acpi_operand_object
*return_object
= *return_object_ptr
;
254 union acpi_operand_object
*buffer_object
;
259 ACPI_FUNCTION_NAME(ns_repair_FDE
);
261 switch (return_object
->common
.type
) {
262 case ACPI_TYPE_BUFFER
:
264 /* This is the expected type. Length should be (at least) 5 DWORDs */
266 if (return_object
->buffer
.length
>= ACPI_FDE_DWORD_BUFFER_SIZE
) {
270 /* We can only repair if we have exactly 5 BYTEs */
272 if (return_object
->buffer
.length
!= ACPI_FDE_BYTE_BUFFER_SIZE
) {
273 ACPI_WARN_PREDEFINED((AE_INFO
,
276 "Incorrect return buffer length %u, expected %u",
277 return_object
->buffer
.length
,
278 ACPI_FDE_DWORD_BUFFER_SIZE
));
280 return (AE_AML_OPERAND_TYPE
);
283 /* Create the new (larger) buffer object */
286 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE
);
287 if (!buffer_object
) {
288 return (AE_NO_MEMORY
);
291 /* Expand each byte to a DWORD */
293 byte_buffer
= return_object
->buffer
.pointer
;
294 dword_buffer
= ACPI_CAST_PTR(u32
,
295 buffer_object
->buffer
.pointer
);
297 for (i
= 0; i
< ACPI_FDE_FIELD_COUNT
; i
++) {
298 *dword_buffer
= (u32
) *byte_buffer
;
303 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR
,
304 "%s Expanded Byte Buffer to expected DWord Buffer\n",
305 info
->full_pathname
));
310 return (AE_AML_OPERAND_TYPE
);
313 /* Delete the original return object, return the new buffer object */
315 acpi_ut_remove_reference(return_object
);
316 *return_object_ptr
= buffer_object
;
318 info
->return_flags
|= ACPI_OBJECT_REPAIRED
;
322 /******************************************************************************
324 * FUNCTION: acpi_ns_repair_CID
326 * PARAMETERS: info - Method execution information block
327 * return_object_ptr - Pointer to the object returned from the
328 * evaluation of a method or object
330 * RETURN: Status. AE_OK if object is OK or was repaired successfully
332 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
333 * letters are uppercase and that there is no leading asterisk.
334 * If a Package, ensure same for all string elements.
336 *****************************************************************************/
339 acpi_ns_repair_CID(struct acpi_evaluate_info
*info
,
340 union acpi_operand_object
**return_object_ptr
)
343 union acpi_operand_object
*return_object
= *return_object_ptr
;
344 union acpi_operand_object
**element_ptr
;
345 union acpi_operand_object
*original_element
;
346 u16 original_ref_count
;
349 ACPI_FUNCTION_TRACE(ns_repair_CID
);
351 /* Check for _CID as a simple string */
353 if (return_object
->common
.type
== ACPI_TYPE_STRING
) {
354 status
= acpi_ns_repair_HID(info
, return_object_ptr
);
355 return_ACPI_STATUS(status
);
358 /* Exit if not a Package */
360 if (return_object
->common
.type
!= ACPI_TYPE_PACKAGE
) {
361 return_ACPI_STATUS(AE_OK
);
364 /* Examine each element of the _CID package */
366 element_ptr
= return_object
->package
.elements
;
367 for (i
= 0; i
< return_object
->package
.count
; i
++) {
368 original_element
= *element_ptr
;
369 original_ref_count
= original_element
->common
.reference_count
;
371 status
= acpi_ns_repair_HID(info
, element_ptr
);
372 if (ACPI_FAILURE(status
)) {
373 return_ACPI_STATUS(status
);
376 if (original_element
!= *element_ptr
) {
378 /* Update reference count of new object */
380 (*element_ptr
)->common
.reference_count
=
387 return_ACPI_STATUS(AE_OK
);
390 /******************************************************************************
392 * FUNCTION: acpi_ns_repair_CST
394 * PARAMETERS: info - Method execution information block
395 * return_object_ptr - Pointer to the object returned from the
396 * evaluation of a method or object
398 * RETURN: Status. AE_OK if object is OK or was repaired successfully
400 * DESCRIPTION: Repair for the _CST object:
401 * 1. Sort the list ascending by C state type
402 * 2. Ensure type cannot be zero
403 * 3. A subpackage count of zero means _CST is meaningless
404 * 4. Count must match the number of C state subpackages
406 *****************************************************************************/
409 acpi_ns_repair_CST(struct acpi_evaluate_info
*info
,
410 union acpi_operand_object
**return_object_ptr
)
412 union acpi_operand_object
*return_object
= *return_object_ptr
;
413 union acpi_operand_object
**outer_elements
;
414 u32 outer_element_count
;
415 union acpi_operand_object
*obj_desc
;
420 ACPI_FUNCTION_NAME(ns_repair_CST
);
423 * Check if the C-state type values are proportional.
425 outer_element_count
= return_object
->package
.count
- 1;
427 while (i
< outer_element_count
) {
428 outer_elements
= &return_object
->package
.elements
[i
+ 1];
431 if ((*outer_elements
)->package
.count
== 0) {
432 ACPI_WARN_PREDEFINED((AE_INFO
,
435 "SubPackage[%u] - removing entry due to zero count",
441 obj_desc
= (*outer_elements
)->package
.elements
[1]; /* Index1 = Type */
442 if ((u32
)obj_desc
->integer
.value
== 0) {
443 ACPI_WARN_PREDEFINED((AE_INFO
,
446 "SubPackage[%u] - removing entry due to invalid Type(0)",
453 acpi_ns_remove_element(return_object
, i
+ 1);
454 outer_element_count
--;
460 /* Update top-level package count, Type "Integer" checked elsewhere */
462 obj_desc
= return_object
->package
.elements
[0];
463 obj_desc
->integer
.value
= outer_element_count
;
466 * Entries (subpackages) in the _CST Package must be sorted by the
467 * C-state type, in ascending order.
469 status
= acpi_ns_check_sorted_list(info
, return_object
, 1, 4, 1,
470 ACPI_SORT_ASCENDING
, "C-State Type");
471 if (ACPI_FAILURE(status
)) {
478 /******************************************************************************
480 * FUNCTION: acpi_ns_repair_HID
482 * PARAMETERS: info - Method execution information block
483 * return_object_ptr - Pointer to the object returned from the
484 * evaluation of a method or object
486 * RETURN: Status. AE_OK if object is OK or was repaired successfully
488 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
489 * letters are uppercase and that there is no leading asterisk.
491 *****************************************************************************/
494 acpi_ns_repair_HID(struct acpi_evaluate_info
*info
,
495 union acpi_operand_object
**return_object_ptr
)
497 union acpi_operand_object
*return_object
= *return_object_ptr
;
501 ACPI_FUNCTION_NAME(ns_repair_HID
);
503 /* We only care about string _HID objects (not integers) */
505 if (return_object
->common
.type
!= ACPI_TYPE_STRING
) {
506 return_ACPI_STATUS(AE_OK
);
509 if (return_object
->string
.length
== 0) {
510 ACPI_WARN_PREDEFINED((AE_INFO
,
511 info
->full_pathname
, info
->node_flags
,
512 "Invalid zero-length _HID or _CID string"));
514 /* Return AE_OK anyway, let driver handle it */
516 info
->return_flags
|= ACPI_OBJECT_REPAIRED
;
517 return_ACPI_STATUS(AE_OK
);
521 * Remove a leading asterisk if present. For some unknown reason, there
522 * are many machines in the field that contains IDs like this.
524 * Examples: "*PNP0C03", "*ACPI0003"
526 source
= return_object
->string
.pointer
;
527 if (*source
== '*') {
529 return_object
->string
.length
--;
531 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR
,
532 "%s: Removed invalid leading asterisk\n",
533 info
->full_pathname
));
537 * Copy and uppercase the string. From the ACPI 5.0 specification:
539 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
540 * letter and # is a hex digit. A valid ACPI ID must be of the form
541 * "NNNN####" where N is an uppercase letter or decimal digit, and
544 for (dest
= return_object
->string
.pointer
; *source
; dest
++, source
++) {
545 *dest
= (char)toupper((int)*source
);
547 return_object
->string
.pointer
[return_object
->string
.length
] = 0;
549 return_ACPI_STATUS(AE_OK
);
552 /******************************************************************************
554 * FUNCTION: acpi_ns_repair_PRT
556 * PARAMETERS: info - Method execution information block
557 * return_object_ptr - Pointer to the object returned from the
558 * evaluation of a method or object
560 * RETURN: Status. AE_OK if object is OK or was repaired successfully
562 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
563 * source_name and source_index field, a common BIOS bug.
565 *****************************************************************************/
568 acpi_ns_repair_PRT(struct acpi_evaluate_info
*info
,
569 union acpi_operand_object
**return_object_ptr
)
571 union acpi_operand_object
*package_object
= *return_object_ptr
;
572 union acpi_operand_object
**top_object_list
;
573 union acpi_operand_object
**sub_object_list
;
574 union acpi_operand_object
*obj_desc
;
575 union acpi_operand_object
*sub_package
;
579 /* Each element in the _PRT package is a subpackage */
581 top_object_list
= package_object
->package
.elements
;
582 element_count
= package_object
->package
.count
;
584 /* Examine each subpackage */
586 for (index
= 0; index
< element_count
; index
++, top_object_list
++) {
587 sub_package
= *top_object_list
;
588 sub_object_list
= sub_package
->package
.elements
;
590 /* Check for minimum required element count */
592 if (sub_package
->package
.count
< 4) {
597 * If the BIOS has erroneously reversed the _PRT source_name (index 2)
598 * and the source_index (index 3), fix it. _PRT is important enough to
599 * workaround this BIOS error. This also provides compatibility with
600 * other ACPI implementations.
602 obj_desc
= sub_object_list
[3];
603 if (!obj_desc
|| (obj_desc
->common
.type
!= ACPI_TYPE_INTEGER
)) {
604 sub_object_list
[3] = sub_object_list
[2];
605 sub_object_list
[2] = obj_desc
;
606 info
->return_flags
|= ACPI_OBJECT_REPAIRED
;
608 ACPI_WARN_PREDEFINED((AE_INFO
,
611 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
619 /******************************************************************************
621 * FUNCTION: acpi_ns_repair_PSS
623 * PARAMETERS: info - Method execution information block
624 * return_object_ptr - Pointer to the object returned from the
625 * evaluation of a method or object
627 * RETURN: Status. AE_OK if object is OK or was repaired successfully
629 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
630 * by the CPU frequencies. Check that the power dissipation values
631 * are all proportional to CPU frequency (i.e., sorting by
632 * frequency should be the same as sorting by power.)
634 *****************************************************************************/
637 acpi_ns_repair_PSS(struct acpi_evaluate_info
*info
,
638 union acpi_operand_object
**return_object_ptr
)
640 union acpi_operand_object
*return_object
= *return_object_ptr
;
641 union acpi_operand_object
**outer_elements
;
642 u32 outer_element_count
;
643 union acpi_operand_object
**elements
;
644 union acpi_operand_object
*obj_desc
;
650 * Entries (subpackages) in the _PSS Package must be sorted by power
651 * dissipation, in descending order. If it appears that the list is
652 * incorrectly sorted, sort it. We sort by cpu_frequency, since this
653 * should be proportional to the power.
655 status
= acpi_ns_check_sorted_list(info
, return_object
, 0, 6, 0,
656 ACPI_SORT_DESCENDING
,
658 if (ACPI_FAILURE(status
)) {
663 * We now know the list is correctly sorted by CPU frequency. Check if
664 * the power dissipation values are proportional.
666 previous_value
= ACPI_UINT32_MAX
;
667 outer_elements
= return_object
->package
.elements
;
668 outer_element_count
= return_object
->package
.count
;
670 for (i
= 0; i
< outer_element_count
; i
++) {
671 elements
= (*outer_elements
)->package
.elements
;
672 obj_desc
= elements
[1]; /* Index1 = power_dissipation */
674 if ((u32
)obj_desc
->integer
.value
> previous_value
) {
675 ACPI_WARN_PREDEFINED((AE_INFO
,
678 "SubPackage[%u,%u] - suspicious power dissipation values",
682 previous_value
= (u32
) obj_desc
->integer
.value
;
689 /******************************************************************************
691 * FUNCTION: acpi_ns_repair_TSS
693 * PARAMETERS: info - Method execution information block
694 * return_object_ptr - Pointer to the object returned from the
695 * evaluation of a method or object
697 * RETURN: Status. AE_OK if object is OK or was repaired successfully
699 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
700 * descending by the power dissipation values.
702 *****************************************************************************/
705 acpi_ns_repair_TSS(struct acpi_evaluate_info
*info
,
706 union acpi_operand_object
**return_object_ptr
)
708 union acpi_operand_object
*return_object
= *return_object_ptr
;
710 struct acpi_namespace_node
*node
;
713 * We can only sort the _TSS return package if there is no _PSS in the
714 * same scope. This is because if _PSS is present, the ACPI specification
715 * dictates that the _TSS Power Dissipation field is to be ignored, and
716 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
717 * In this case, it is best to just return the _TSS package as-is.
720 status
= acpi_ns_get_node(info
->node
, "^_PSS",
721 ACPI_NS_NO_UPSEARCH
, &node
);
722 if (ACPI_SUCCESS(status
)) {
726 status
= acpi_ns_check_sorted_list(info
, return_object
, 0, 5, 1,
727 ACPI_SORT_DESCENDING
,
733 /******************************************************************************
735 * FUNCTION: acpi_ns_check_sorted_list
737 * PARAMETERS: info - Method execution information block
738 * return_object - Pointer to the top-level returned object
739 * start_index - Index of the first subpackage
740 * expected_count - Minimum length of each subpackage
741 * sort_index - Subpackage entry to sort on
742 * sort_direction - Ascending or descending
743 * sort_key_name - Name of the sort_index field
745 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
746 * has been repaired by sorting the list.
748 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
749 * sort_index. If not, then sort the list.
751 *****************************************************************************/
754 acpi_ns_check_sorted_list(struct acpi_evaluate_info
*info
,
755 union acpi_operand_object
*return_object
,
759 u8 sort_direction
, char *sort_key_name
)
761 u32 outer_element_count
;
762 union acpi_operand_object
**outer_elements
;
763 union acpi_operand_object
**elements
;
764 union acpi_operand_object
*obj_desc
;
768 ACPI_FUNCTION_NAME(ns_check_sorted_list
);
770 /* The top-level object must be a package */
772 if (return_object
->common
.type
!= ACPI_TYPE_PACKAGE
) {
773 return (AE_AML_OPERAND_TYPE
);
777 * NOTE: assumes list of subpackages contains no NULL elements.
778 * Any NULL elements should have been removed by earlier call
779 * to acpi_ns_remove_null_elements.
781 outer_element_count
= return_object
->package
.count
;
782 if (!outer_element_count
|| start_index
>= outer_element_count
) {
783 return (AE_AML_PACKAGE_LIMIT
);
786 outer_elements
= &return_object
->package
.elements
[start_index
];
787 outer_element_count
-= start_index
;
790 if (sort_direction
== ACPI_SORT_DESCENDING
) {
791 previous_value
= ACPI_UINT32_MAX
;
794 /* Examine each subpackage */
796 for (i
= 0; i
< outer_element_count
; i
++) {
798 /* Each element of the top-level package must also be a package */
800 if ((*outer_elements
)->common
.type
!= ACPI_TYPE_PACKAGE
) {
801 return (AE_AML_OPERAND_TYPE
);
804 /* Each subpackage must have the minimum length */
806 if ((*outer_elements
)->package
.count
< expected_count
) {
807 return (AE_AML_PACKAGE_LIMIT
);
810 elements
= (*outer_elements
)->package
.elements
;
811 obj_desc
= elements
[sort_index
];
813 if (obj_desc
->common
.type
!= ACPI_TYPE_INTEGER
) {
814 return (AE_AML_OPERAND_TYPE
);
818 * The list must be sorted in the specified order. If we detect a
819 * discrepancy, sort the entire list.
821 if (((sort_direction
== ACPI_SORT_ASCENDING
) &&
822 (obj_desc
->integer
.value
< previous_value
)) ||
823 ((sort_direction
== ACPI_SORT_DESCENDING
) &&
824 (obj_desc
->integer
.value
> previous_value
))) {
825 acpi_ns_sort_list(&return_object
->package
.
826 elements
[start_index
],
827 outer_element_count
, sort_index
,
830 info
->return_flags
|= ACPI_OBJECT_REPAIRED
;
832 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR
,
833 "%s: Repaired unsorted list - now sorted by %s\n",
834 info
->full_pathname
, sort_key_name
));
838 previous_value
= (u32
) obj_desc
->integer
.value
;
845 /******************************************************************************
847 * FUNCTION: acpi_ns_sort_list
849 * PARAMETERS: elements - Package object element list
850 * count - Element count for above
851 * index - Sort by which package element
852 * sort_direction - Ascending or Descending sort
856 * DESCRIPTION: Sort the objects that are in a package element list.
858 * NOTE: Assumes that all NULL elements have been removed from the package,
859 * and that all elements have been verified to be of type Integer.
861 *****************************************************************************/
864 acpi_ns_sort_list(union acpi_operand_object
**elements
,
865 u32 count
, u32 index
, u8 sort_direction
)
867 union acpi_operand_object
*obj_desc1
;
868 union acpi_operand_object
*obj_desc2
;
869 union acpi_operand_object
*temp_obj
;
873 /* Simple bubble sort */
875 for (i
= 1; i
< count
; i
++) {
876 for (j
= (count
- 1); j
>= i
; j
--) {
877 obj_desc1
= elements
[j
- 1]->package
.elements
[index
];
878 obj_desc2
= elements
[j
]->package
.elements
[index
];
880 if (((sort_direction
== ACPI_SORT_ASCENDING
) &&
881 (obj_desc1
->integer
.value
>
882 obj_desc2
->integer
.value
))
883 || ((sort_direction
== ACPI_SORT_DESCENDING
)
884 && (obj_desc1
->integer
.value
<
885 obj_desc2
->integer
.value
))) {
886 temp_obj
= elements
[j
- 1];
887 elements
[j
- 1] = elements
[j
];
888 elements
[j
] = temp_obj
;
894 /******************************************************************************
896 * FUNCTION: acpi_ns_remove_element
898 * PARAMETERS: obj_desc - Package object element list
899 * index - Index of element to remove
903 * DESCRIPTION: Remove the requested element of a package and delete it.
905 *****************************************************************************/
908 acpi_ns_remove_element(union acpi_operand_object
*obj_desc
, u32 index
)
910 union acpi_operand_object
**source
;
911 union acpi_operand_object
**dest
;
916 ACPI_FUNCTION_NAME(ns_remove_element
);
918 count
= obj_desc
->package
.count
;
919 new_count
= count
- 1;
921 source
= obj_desc
->package
.elements
;
924 /* Examine all elements of the package object, remove matched index */
926 for (i
= 0; i
< count
; i
++) {
928 acpi_ut_remove_reference(*source
); /* Remove one ref for being in pkg */
929 acpi_ut_remove_reference(*source
);
938 /* NULL terminate list and update the package count */
941 obj_desc
->package
.count
= new_count
;