1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2014, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nsrepair2")
53 * Information structure and handler for ACPI predefined names that can
54 * be repaired on a per-name basis.
57 acpi_status(*acpi_repair_function) (struct acpi_evaluate_info * info,
58 union acpi_operand_object
61 typedef struct acpi_repair_info {
62 char name[ACPI_NAME_SIZE];
63 acpi_repair_function repair_function;
67 /* Local prototypes */
69 static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
74 acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
75 union acpi_operand_object **return_object_ptr);
78 acpi_ns_repair_CID(struct acpi_evaluate_info *info,
79 union acpi_operand_object **return_object_ptr);
82 acpi_ns_repair_CST(struct acpi_evaluate_info *info,
83 union acpi_operand_object **return_object_ptr);
86 acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
87 union acpi_operand_object **return_object_ptr);
90 acpi_ns_repair_HID(struct acpi_evaluate_info *info,
91 union acpi_operand_object **return_object_ptr);
94 acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
95 union acpi_operand_object **return_object_ptr);
98 acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
99 union acpi_operand_object **return_object_ptr);
102 acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
103 union acpi_operand_object **return_object_ptr);
106 acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
107 union acpi_operand_object *return_object,
111 u8 sort_direction, char *sort_key_name);
113 /* Values for sort_direction above */
115 #define ACPI_SORT_ASCENDING 0
116 #define ACPI_SORT_DESCENDING 1
119 acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index);
122 acpi_ns_sort_list(union acpi_operand_object **elements,
123 u32 count, u32 index, u8 sort_direction);
126 * This table contains the names of the predefined methods for which we can
127 * perform more complex repairs.
131 * _ALR: Sort the list ascending by ambient_illuminance
132 * _CID: Strings: uppercase all, remove any leading asterisk
133 * _CST: Sort the list ascending by C state type
134 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
135 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
136 * _HID: Strings: uppercase all, remove any leading asterisk
137 * _PRT: Fix reversed source_name and source_index
138 * _PSS: Sort the list descending by Power
139 * _TSS: Sort the list descending by Power
141 * Names that must be packages, but cannot be sorted:
143 * _BCL: Values are tied to the Package index where they appear, and cannot
144 * be moved or sorted. These index values are used for _BQC and _BCM.
145 * However, we can fix the case where a buffer is returned, by converting
146 * it to a Package of integers.
148 static const struct acpi_repair_info acpi_ns_repairable_names[] = {
149 {"_ALR", acpi_ns_repair_ALR},
150 {"_CID", acpi_ns_repair_CID},
151 {"_CST", acpi_ns_repair_CST},
152 {"_FDE", acpi_ns_repair_FDE},
153 {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */
154 {"_HID", acpi_ns_repair_HID},
155 {"_PRT", acpi_ns_repair_PRT},
156 {"_PSS", acpi_ns_repair_PSS},
157 {"_TSS", acpi_ns_repair_TSS},
158 {{0, 0, 0, 0}, NULL} /* Table terminator */
161 #define ACPI_FDE_FIELD_COUNT 5
162 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
163 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (u32))
165 /******************************************************************************
167 * FUNCTION: acpi_ns_complex_repairs
169 * PARAMETERS: info - Method execution information block
170 * node - Namespace node for the method/object
171 * validate_status - Original status of earlier validation
172 * return_object_ptr - Pointer to the object returned from the
173 * evaluation of a method or object
175 * RETURN: Status. AE_OK if repair was successful. If name is not
176 * matched, validate_status is returned.
178 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
181 *****************************************************************************/
184 acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
185 struct acpi_namespace_node *node,
186 acpi_status validate_status,
187 union acpi_operand_object **return_object_ptr)
189 const struct acpi_repair_info *predefined;
192 /* Check if this name is in the list of repairable names */
194 predefined = acpi_ns_match_complex_repair(node);
196 return (validate_status);
199 status = predefined->repair_function(info, return_object_ptr);
203 /******************************************************************************
205 * FUNCTION: acpi_ns_match_complex_repair
207 * PARAMETERS: node - Namespace node for the method/object
209 * RETURN: Pointer to entry in repair table. NULL indicates not found.
211 * DESCRIPTION: Check an object name against the repairable object list.
213 *****************************************************************************/
215 static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
219 const struct acpi_repair_info *this_name;
221 /* Search info table for a repairable predefined method/object name */
223 this_name = acpi_ns_repairable_names;
224 while (this_name->repair_function) {
225 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->name)) {
231 return (NULL); /* Not found */
234 /******************************************************************************
236 * FUNCTION: acpi_ns_repair_ALR
238 * PARAMETERS: info - Method execution information block
239 * return_object_ptr - Pointer to the object returned from the
240 * evaluation of a method or object
242 * RETURN: Status. AE_OK if object is OK or was repaired successfully
244 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
245 * ascending by the ambient illuminance values.
247 *****************************************************************************/
250 acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
251 union acpi_operand_object **return_object_ptr)
253 union acpi_operand_object *return_object = *return_object_ptr;
256 status = acpi_ns_check_sorted_list(info, return_object, 0, 2, 1,
258 "AmbientIlluminance");
263 /******************************************************************************
265 * FUNCTION: acpi_ns_repair_FDE
267 * PARAMETERS: info - Method execution information block
268 * return_object_ptr - Pointer to the object returned from the
269 * evaluation of a method or object
271 * RETURN: Status. AE_OK if object is OK or was repaired successfully
273 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
274 * value is a Buffer of 5 DWORDs. This function repairs a common
275 * problem where the return value is a Buffer of BYTEs, not
278 *****************************************************************************/
281 acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
282 union acpi_operand_object **return_object_ptr)
284 union acpi_operand_object *return_object = *return_object_ptr;
285 union acpi_operand_object *buffer_object;
290 ACPI_FUNCTION_NAME(ns_repair_FDE);
292 switch (return_object->common.type) {
293 case ACPI_TYPE_BUFFER:
295 /* This is the expected type. Length should be (at least) 5 DWORDs */
297 if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) {
301 /* We can only repair if we have exactly 5 BYTEs */
303 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) {
304 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
306 "Incorrect return buffer length %u, expected %u",
307 return_object->buffer.length,
308 ACPI_FDE_DWORD_BUFFER_SIZE));
310 return (AE_AML_OPERAND_TYPE);
313 /* Create the new (larger) buffer object */
316 acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE);
317 if (!buffer_object) {
318 return (AE_NO_MEMORY);
321 /* Expand each byte to a DWORD */
323 byte_buffer = return_object->buffer.pointer;
325 ACPI_CAST_PTR(u32, buffer_object->buffer.pointer);
327 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) {
328 *dword_buffer = (u32) *byte_buffer;
333 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
334 "%s Expanded Byte Buffer to expected DWord Buffer\n",
335 info->full_pathname));
340 return (AE_AML_OPERAND_TYPE);
343 /* Delete the original return object, return the new buffer object */
345 acpi_ut_remove_reference(return_object);
346 *return_object_ptr = buffer_object;
348 info->return_flags |= ACPI_OBJECT_REPAIRED;
352 /******************************************************************************
354 * FUNCTION: acpi_ns_repair_CID
356 * PARAMETERS: info - Method execution information block
357 * return_object_ptr - Pointer to the object returned from the
358 * evaluation of a method or object
360 * RETURN: Status. AE_OK if object is OK or was repaired successfully
362 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
363 * letters are uppercase and that there is no leading asterisk.
364 * If a Package, ensure same for all string elements.
366 *****************************************************************************/
369 acpi_ns_repair_CID(struct acpi_evaluate_info *info,
370 union acpi_operand_object **return_object_ptr)
373 union acpi_operand_object *return_object = *return_object_ptr;
374 union acpi_operand_object **element_ptr;
375 union acpi_operand_object *original_element;
376 u16 original_ref_count;
379 /* Check for _CID as a simple string */
381 if (return_object->common.type == ACPI_TYPE_STRING) {
382 status = acpi_ns_repair_HID(info, return_object_ptr);
386 /* Exit if not a Package */
388 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
392 /* Examine each element of the _CID package */
394 element_ptr = return_object->package.elements;
395 for (i = 0; i < return_object->package.count; i++) {
396 original_element = *element_ptr;
397 original_ref_count = original_element->common.reference_count;
399 status = acpi_ns_repair_HID(info, element_ptr);
400 if (ACPI_FAILURE(status)) {
404 /* Take care with reference counts */
406 if (original_element != *element_ptr) {
408 /* Element was replaced */
410 (*element_ptr)->common.reference_count =
413 acpi_ut_remove_reference(original_element);
422 /******************************************************************************
424 * FUNCTION: acpi_ns_repair_CST
426 * PARAMETERS: info - Method execution information block
427 * return_object_ptr - Pointer to the object returned from the
428 * evaluation of a method or object
430 * RETURN: Status. AE_OK if object is OK or was repaired successfully
432 * DESCRIPTION: Repair for the _CST object:
433 * 1. Sort the list ascending by C state type
434 * 2. Ensure type cannot be zero
435 * 3. A sub-package count of zero means _CST is meaningless
436 * 4. Count must match the number of C state sub-packages
438 *****************************************************************************/
441 acpi_ns_repair_CST(struct acpi_evaluate_info *info,
442 union acpi_operand_object **return_object_ptr)
444 union acpi_operand_object *return_object = *return_object_ptr;
445 union acpi_operand_object **outer_elements;
446 u32 outer_element_count;
447 union acpi_operand_object *obj_desc;
452 ACPI_FUNCTION_NAME(ns_repair_CST);
455 * Check if the C-state type values are proportional.
457 outer_element_count = return_object->package.count - 1;
459 while (i < outer_element_count) {
460 outer_elements = &return_object->package.elements[i + 1];
463 if ((*outer_elements)->package.count == 0) {
464 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
466 "SubPackage[%u] - removing entry due to zero count",
472 obj_desc = (*outer_elements)->package.elements[1]; /* Index1 = Type */
473 if ((u32)obj_desc->integer.value == 0) {
474 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
476 "SubPackage[%u] - removing entry due to invalid Type(0)",
483 acpi_ns_remove_element(return_object, i + 1);
484 outer_element_count--;
490 /* Update top-level package count, Type "Integer" checked elsewhere */
492 obj_desc = return_object->package.elements[0];
493 obj_desc->integer.value = outer_element_count;
496 * Entries (subpackages) in the _CST Package must be sorted by the
497 * C-state type, in ascending order.
499 status = acpi_ns_check_sorted_list(info, return_object, 1, 4, 1,
500 ACPI_SORT_ASCENDING, "C-State Type");
501 if (ACPI_FAILURE(status)) {
508 /******************************************************************************
510 * FUNCTION: acpi_ns_repair_HID
512 * PARAMETERS: info - Method execution information block
513 * return_object_ptr - Pointer to the object returned from the
514 * evaluation of a method or object
516 * RETURN: Status. AE_OK if object is OK or was repaired successfully
518 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
519 * letters are uppercase and that there is no leading asterisk.
521 *****************************************************************************/
524 acpi_ns_repair_HID(struct acpi_evaluate_info *info,
525 union acpi_operand_object **return_object_ptr)
527 union acpi_operand_object *return_object = *return_object_ptr;
528 union acpi_operand_object *new_string;
532 ACPI_FUNCTION_NAME(ns_repair_HID);
534 /* We only care about string _HID objects (not integers) */
536 if (return_object->common.type != ACPI_TYPE_STRING) {
540 if (return_object->string.length == 0) {
541 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
543 "Invalid zero-length _HID or _CID string"));
545 /* Return AE_OK anyway, let driver handle it */
547 info->return_flags |= ACPI_OBJECT_REPAIRED;
551 /* It is simplest to always create a new string object */
553 new_string = acpi_ut_create_string_object(return_object->string.length);
555 return (AE_NO_MEMORY);
559 * Remove a leading asterisk if present. For some unknown reason, there
560 * are many machines in the field that contains IDs like this.
562 * Examples: "*PNP0C03", "*ACPI0003"
564 source = return_object->string.pointer;
565 if (*source == '*') {
567 new_string->string.length--;
569 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
570 "%s: Removed invalid leading asterisk\n",
571 info->full_pathname));
575 * Copy and uppercase the string. From the ACPI 5.0 specification:
577 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
578 * letter and # is a hex digit. A valid ACPI ID must be of the form
579 * "NNNN####" where N is an uppercase letter or decimal digit, and
582 for (dest = new_string->string.pointer; *source; dest++, source++) {
583 *dest = (char)ACPI_TOUPPER(*source);
586 acpi_ut_remove_reference(return_object);
587 *return_object_ptr = new_string;
591 /******************************************************************************
593 * FUNCTION: acpi_ns_repair_PRT
595 * PARAMETERS: info - Method execution information block
596 * return_object_ptr - Pointer to the object returned from the
597 * evaluation of a method or object
599 * RETURN: Status. AE_OK if object is OK or was repaired successfully
601 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
602 * source_name and source_index field, a common BIOS bug.
604 *****************************************************************************/
607 acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
608 union acpi_operand_object **return_object_ptr)
610 union acpi_operand_object *package_object = *return_object_ptr;
611 union acpi_operand_object **top_object_list;
612 union acpi_operand_object **sub_object_list;
613 union acpi_operand_object *obj_desc;
614 union acpi_operand_object *sub_package;
618 /* Each element in the _PRT package is a subpackage */
620 top_object_list = package_object->package.elements;
621 element_count = package_object->package.count;
623 for (index = 0; index < element_count; index++) {
624 sub_package = *top_object_list;
625 sub_object_list = sub_package->package.elements;
627 if (sub_package->package.count < 4) { /* Minimum required element count */
632 * If the BIOS has erroneously reversed the _PRT source_name (index 2)
633 * and the source_index (index 3), fix it. _PRT is important enough to
634 * workaround this BIOS error. This also provides compatibility with
635 * other ACPI implementations.
637 obj_desc = sub_object_list[3];
638 if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
639 sub_object_list[3] = sub_object_list[2];
640 sub_object_list[2] = obj_desc;
641 info->return_flags |= ACPI_OBJECT_REPAIRED;
643 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
645 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
649 /* Point to the next union acpi_operand_object in the top level package */
657 /******************************************************************************
659 * FUNCTION: acpi_ns_repair_PSS
661 * PARAMETERS: info - Method execution information block
662 * return_object_ptr - Pointer to the object returned from the
663 * evaluation of a method or object
665 * RETURN: Status. AE_OK if object is OK or was repaired successfully
667 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
668 * by the CPU frequencies. Check that the power dissipation values
669 * are all proportional to CPU frequency (i.e., sorting by
670 * frequency should be the same as sorting by power.)
672 *****************************************************************************/
675 acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
676 union acpi_operand_object **return_object_ptr)
678 union acpi_operand_object *return_object = *return_object_ptr;
679 union acpi_operand_object **outer_elements;
680 u32 outer_element_count;
681 union acpi_operand_object **elements;
682 union acpi_operand_object *obj_desc;
688 * Entries (sub-packages) in the _PSS Package must be sorted by power
689 * dissipation, in descending order. If it appears that the list is
690 * incorrectly sorted, sort it. We sort by cpu_frequency, since this
691 * should be proportional to the power.
693 status = acpi_ns_check_sorted_list(info, return_object, 0, 6, 0,
694 ACPI_SORT_DESCENDING,
696 if (ACPI_FAILURE(status)) {
701 * We now know the list is correctly sorted by CPU frequency. Check if
702 * the power dissipation values are proportional.
704 previous_value = ACPI_UINT32_MAX;
705 outer_elements = return_object->package.elements;
706 outer_element_count = return_object->package.count;
708 for (i = 0; i < outer_element_count; i++) {
709 elements = (*outer_elements)->package.elements;
710 obj_desc = elements[1]; /* Index1 = power_dissipation */
712 if ((u32) obj_desc->integer.value > previous_value) {
713 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
715 "SubPackage[%u,%u] - suspicious power dissipation values",
719 previous_value = (u32) obj_desc->integer.value;
726 /******************************************************************************
728 * FUNCTION: acpi_ns_repair_TSS
730 * PARAMETERS: info - Method execution information block
731 * return_object_ptr - Pointer to the object returned from the
732 * evaluation of a method or object
734 * RETURN: Status. AE_OK if object is OK or was repaired successfully
736 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
737 * descending by the power dissipation values.
739 *****************************************************************************/
742 acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
743 union acpi_operand_object **return_object_ptr)
745 union acpi_operand_object *return_object = *return_object_ptr;
747 struct acpi_namespace_node *node;
750 * We can only sort the _TSS return package if there is no _PSS in the
751 * same scope. This is because if _PSS is present, the ACPI specification
752 * dictates that the _TSS Power Dissipation field is to be ignored, and
753 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
754 * In this case, it is best to just return the _TSS package as-is.
757 status = acpi_ns_get_node(info->node, "^_PSS",
758 ACPI_NS_NO_UPSEARCH, &node);
759 if (ACPI_SUCCESS(status)) {
763 status = acpi_ns_check_sorted_list(info, return_object, 0, 5, 1,
764 ACPI_SORT_DESCENDING,
770 /******************************************************************************
772 * FUNCTION: acpi_ns_check_sorted_list
774 * PARAMETERS: info - Method execution information block
775 * return_object - Pointer to the top-level returned object
776 * start_index - Index of the first sub-package
777 * expected_count - Minimum length of each sub-package
778 * sort_index - Sub-package entry to sort on
779 * sort_direction - Ascending or descending
780 * sort_key_name - Name of the sort_index field
782 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
783 * has been repaired by sorting the list.
785 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
786 * sort_index. If not, then sort the list.
788 *****************************************************************************/
791 acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
792 union acpi_operand_object *return_object,
796 u8 sort_direction, char *sort_key_name)
798 u32 outer_element_count;
799 union acpi_operand_object **outer_elements;
800 union acpi_operand_object **elements;
801 union acpi_operand_object *obj_desc;
805 ACPI_FUNCTION_NAME(ns_check_sorted_list);
807 /* The top-level object must be a package */
809 if (return_object->common.type != ACPI_TYPE_PACKAGE) {
810 return (AE_AML_OPERAND_TYPE);
814 * NOTE: assumes list of sub-packages contains no NULL elements.
815 * Any NULL elements should have been removed by earlier call
816 * to acpi_ns_remove_null_elements.
818 outer_element_count = return_object->package.count;
819 if (!outer_element_count || start_index >= outer_element_count) {
820 return (AE_AML_PACKAGE_LIMIT);
823 outer_elements = &return_object->package.elements[start_index];
824 outer_element_count -= start_index;
827 if (sort_direction == ACPI_SORT_DESCENDING) {
828 previous_value = ACPI_UINT32_MAX;
831 /* Examine each subpackage */
833 for (i = 0; i < outer_element_count; i++) {
835 /* Each element of the top-level package must also be a package */
837 if ((*outer_elements)->common.type != ACPI_TYPE_PACKAGE) {
838 return (AE_AML_OPERAND_TYPE);
841 /* Each sub-package must have the minimum length */
843 if ((*outer_elements)->package.count < expected_count) {
844 return (AE_AML_PACKAGE_LIMIT);
847 elements = (*outer_elements)->package.elements;
848 obj_desc = elements[sort_index];
850 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
851 return (AE_AML_OPERAND_TYPE);
855 * The list must be sorted in the specified order. If we detect a
856 * discrepancy, sort the entire list.
858 if (((sort_direction == ACPI_SORT_ASCENDING) &&
859 (obj_desc->integer.value < previous_value)) ||
860 ((sort_direction == ACPI_SORT_DESCENDING) &&
861 (obj_desc->integer.value > previous_value))) {
862 acpi_ns_sort_list(&return_object->package.
863 elements[start_index],
864 outer_element_count, sort_index,
867 info->return_flags |= ACPI_OBJECT_REPAIRED;
869 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
870 "%s: Repaired unsorted list - now sorted by %s\n",
871 info->full_pathname, sort_key_name));
875 previous_value = (u32) obj_desc->integer.value;
882 /******************************************************************************
884 * FUNCTION: acpi_ns_sort_list
886 * PARAMETERS: elements - Package object element list
887 * count - Element count for above
888 * index - Sort by which package element
889 * sort_direction - Ascending or Descending sort
893 * DESCRIPTION: Sort the objects that are in a package element list.
895 * NOTE: Assumes that all NULL elements have been removed from the package,
896 * and that all elements have been verified to be of type Integer.
898 *****************************************************************************/
901 acpi_ns_sort_list(union acpi_operand_object **elements,
902 u32 count, u32 index, u8 sort_direction)
904 union acpi_operand_object *obj_desc1;
905 union acpi_operand_object *obj_desc2;
906 union acpi_operand_object *temp_obj;
910 /* Simple bubble sort */
912 for (i = 1; i < count; i++) {
913 for (j = (count - 1); j >= i; j--) {
914 obj_desc1 = elements[j - 1]->package.elements[index];
915 obj_desc2 = elements[j]->package.elements[index];
917 if (((sort_direction == ACPI_SORT_ASCENDING) &&
918 (obj_desc1->integer.value >
919 obj_desc2->integer.value))
920 || ((sort_direction == ACPI_SORT_DESCENDING)
921 && (obj_desc1->integer.value <
922 obj_desc2->integer.value))) {
923 temp_obj = elements[j - 1];
924 elements[j - 1] = elements[j];
925 elements[j] = temp_obj;
931 /******************************************************************************
933 * FUNCTION: acpi_ns_remove_element
935 * PARAMETERS: obj_desc - Package object element list
936 * index - Index of element to remove
940 * DESCRIPTION: Remove the requested element of a package and delete it.
942 *****************************************************************************/
945 acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index)
947 union acpi_operand_object **source;
948 union acpi_operand_object **dest;
953 ACPI_FUNCTION_NAME(ns_remove_element);
955 count = obj_desc->package.count;
956 new_count = count - 1;
958 source = obj_desc->package.elements;
961 /* Examine all elements of the package object, remove matched index */
963 for (i = 0; i < count; i++) {
965 acpi_ut_remove_reference(*source); /* Remove one ref for being in pkg */
966 acpi_ut_remove_reference(*source);
974 /* NULL terminate list and update the package count */
977 obj_desc->package.count = new_count;