1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2015, 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 <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nsrepair2")
54 * Information structure and handler for ACPI predefined names that can
55 * be repaired on a per-name basis.
58 ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
59 ACPI_EVALUATE_INFO *Info,
60 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
62 typedef struct acpi_repair_info
64 char Name[ACPI_NAME_SIZE];
65 ACPI_REPAIR_FUNCTION RepairFunction;
70 /* Local prototypes */
72 static const ACPI_REPAIR_INFO *
73 AcpiNsMatchComplexRepair (
74 ACPI_NAMESPACE_NODE *Node);
78 ACPI_EVALUATE_INFO *Info,
79 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
83 ACPI_EVALUATE_INFO *Info,
84 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
88 ACPI_EVALUATE_INFO *Info,
89 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
93 ACPI_EVALUATE_INFO *Info,
94 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
98 ACPI_EVALUATE_INFO *Info,
99 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
103 ACPI_EVALUATE_INFO *Info,
104 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
108 ACPI_EVALUATE_INFO *Info,
109 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
113 ACPI_EVALUATE_INFO *Info,
114 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
117 AcpiNsCheckSortedList (
118 ACPI_EVALUATE_INFO *Info,
119 ACPI_OPERAND_OBJECT *ReturnObject,
121 UINT32 ExpectedCount,
126 /* Values for SortDirection above */
128 #define ACPI_SORT_ASCENDING 0
129 #define ACPI_SORT_DESCENDING 1
132 AcpiNsRemoveElement (
133 ACPI_OPERAND_OBJECT *ObjDesc,
138 ACPI_OPERAND_OBJECT **Elements,
141 UINT8 SortDirection);
145 * This table contains the names of the predefined methods for which we can
146 * perform more complex repairs.
150 * _ALR: Sort the list ascending by AmbientIlluminance
151 * _CID: Strings: uppercase all, remove any leading asterisk
152 * _CST: Sort the list ascending by C state type
153 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
154 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
155 * _HID: Strings: uppercase all, remove any leading asterisk
156 * _PRT: Fix reversed SourceName and SourceIndex
157 * _PSS: Sort the list descending by Power
158 * _TSS: Sort the list descending by Power
160 * Names that must be packages, but cannot be sorted:
162 * _BCL: Values are tied to the Package index where they appear, and cannot
163 * be moved or sorted. These index values are used for _BQC and _BCM.
164 * However, we can fix the case where a buffer is returned, by converting
165 * it to a Package of integers.
167 static const ACPI_REPAIR_INFO AcpiNsRepairableNames[] =
169 {"_ALR", AcpiNsRepair_ALR},
170 {"_CID", AcpiNsRepair_CID},
171 {"_CST", AcpiNsRepair_CST},
172 {"_FDE", AcpiNsRepair_FDE},
173 {"_GTM", AcpiNsRepair_FDE}, /* _GTM has same repair as _FDE */
174 {"_HID", AcpiNsRepair_HID},
175 {"_PRT", AcpiNsRepair_PRT},
176 {"_PSS", AcpiNsRepair_PSS},
177 {"_TSS", AcpiNsRepair_TSS},
178 {{0,0,0,0}, NULL} /* Table terminator */
182 #define ACPI_FDE_FIELD_COUNT 5
183 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
184 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
187 /******************************************************************************
189 * FUNCTION: AcpiNsComplexRepairs
191 * PARAMETERS: Info - Method execution information block
192 * Node - Namespace node for the method/object
193 * ValidateStatus - Original status of earlier validation
194 * ReturnObjectPtr - Pointer to the object returned from the
195 * evaluation of a method or object
197 * RETURN: Status. AE_OK if repair was successful. If name is not
198 * matched, ValidateStatus is returned.
200 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
203 *****************************************************************************/
206 AcpiNsComplexRepairs (
207 ACPI_EVALUATE_INFO *Info,
208 ACPI_NAMESPACE_NODE *Node,
209 ACPI_STATUS ValidateStatus,
210 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
212 const ACPI_REPAIR_INFO *Predefined;
216 /* Check if this name is in the list of repairable names */
218 Predefined = AcpiNsMatchComplexRepair (Node);
221 return (ValidateStatus);
224 Status = Predefined->RepairFunction (Info, ReturnObjectPtr);
229 /******************************************************************************
231 * FUNCTION: AcpiNsMatchComplexRepair
233 * PARAMETERS: Node - Namespace node for the method/object
235 * RETURN: Pointer to entry in repair table. NULL indicates not found.
237 * DESCRIPTION: Check an object name against the repairable object list.
239 *****************************************************************************/
241 static const ACPI_REPAIR_INFO *
242 AcpiNsMatchComplexRepair (
243 ACPI_NAMESPACE_NODE *Node)
245 const ACPI_REPAIR_INFO *ThisName;
248 /* Search info table for a repairable predefined method/object name */
250 ThisName = AcpiNsRepairableNames;
251 while (ThisName->RepairFunction)
253 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
260 return (NULL); /* Not found */
264 /******************************************************************************
266 * FUNCTION: AcpiNsRepair_ALR
268 * PARAMETERS: Info - Method execution information block
269 * ReturnObjectPtr - Pointer to the object returned from the
270 * evaluation of a method or object
272 * RETURN: Status. AE_OK if object is OK or was repaired successfully
274 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
275 * ascending by the ambient illuminance values.
277 *****************************************************************************/
281 ACPI_EVALUATE_INFO *Info,
282 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
284 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
288 Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 2, 1,
289 ACPI_SORT_ASCENDING, "AmbientIlluminance");
295 /******************************************************************************
297 * FUNCTION: AcpiNsRepair_FDE
299 * PARAMETERS: Info - Method execution information block
300 * ReturnObjectPtr - Pointer to the object returned from the
301 * evaluation of a method or object
303 * RETURN: Status. AE_OK if object is OK or was repaired successfully
305 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
306 * value is a Buffer of 5 DWORDs. This function repairs a common
307 * problem where the return value is a Buffer of BYTEs, not
310 *****************************************************************************/
314 ACPI_EVALUATE_INFO *Info,
315 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
317 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
318 ACPI_OPERAND_OBJECT *BufferObject;
324 ACPI_FUNCTION_NAME (NsRepair_FDE);
327 switch (ReturnObject->Common.Type)
329 case ACPI_TYPE_BUFFER:
331 /* This is the expected type. Length should be (at least) 5 DWORDs */
333 if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
338 /* We can only repair if we have exactly 5 BYTEs */
340 if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
342 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
343 "Incorrect return buffer length %u, expected %u",
344 ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
346 return (AE_AML_OPERAND_TYPE);
349 /* Create the new (larger) buffer object */
351 BufferObject = AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE);
354 return (AE_NO_MEMORY);
357 /* Expand each byte to a DWORD */
359 ByteBuffer = ReturnObject->Buffer.Pointer;
360 DwordBuffer = ACPI_CAST_PTR (UINT32, BufferObject->Buffer.Pointer);
362 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
364 *DwordBuffer = (UINT32) *ByteBuffer;
369 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
370 "%s Expanded Byte Buffer to expected DWord Buffer\n",
371 Info->FullPathname));
376 return (AE_AML_OPERAND_TYPE);
379 /* Delete the original return object, return the new buffer object */
381 AcpiUtRemoveReference (ReturnObject);
382 *ReturnObjectPtr = BufferObject;
384 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
389 /******************************************************************************
391 * FUNCTION: AcpiNsRepair_CID
393 * PARAMETERS: Info - Method execution information block
394 * ReturnObjectPtr - Pointer to the object returned from the
395 * evaluation of a method or object
397 * RETURN: Status. AE_OK if object is OK or was repaired successfully
399 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
400 * letters are uppercase and that there is no leading asterisk.
401 * If a Package, ensure same for all string elements.
403 *****************************************************************************/
407 ACPI_EVALUATE_INFO *Info,
408 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
411 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
412 ACPI_OPERAND_OBJECT **ElementPtr;
413 ACPI_OPERAND_OBJECT *OriginalElement;
414 UINT16 OriginalRefCount;
418 /* Check for _CID as a simple string */
420 if (ReturnObject->Common.Type == ACPI_TYPE_STRING)
422 Status = AcpiNsRepair_HID (Info, ReturnObjectPtr);
426 /* Exit if not a Package */
428 if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
433 /* Examine each element of the _CID package */
435 ElementPtr = ReturnObject->Package.Elements;
436 for (i = 0; i < ReturnObject->Package.Count; i++)
438 OriginalElement = *ElementPtr;
439 OriginalRefCount = OriginalElement->Common.ReferenceCount;
441 Status = AcpiNsRepair_HID (Info, ElementPtr);
442 if (ACPI_FAILURE (Status))
447 /* Take care with reference counts */
449 if (OriginalElement != *ElementPtr)
451 /* Element was replaced */
453 (*ElementPtr)->Common.ReferenceCount =
456 AcpiUtRemoveReference (OriginalElement);
466 /******************************************************************************
468 * FUNCTION: AcpiNsRepair_CST
470 * PARAMETERS: Info - Method execution information block
471 * ReturnObjectPtr - Pointer to the object returned from the
472 * evaluation of a method or object
474 * RETURN: Status. AE_OK if object is OK or was repaired successfully
476 * DESCRIPTION: Repair for the _CST object:
477 * 1. Sort the list ascending by C state type
478 * 2. Ensure type cannot be zero
479 * 3. A subpackage count of zero means _CST is meaningless
480 * 4. Count must match the number of C state subpackages
482 *****************************************************************************/
486 ACPI_EVALUATE_INFO *Info,
487 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
489 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
490 ACPI_OPERAND_OBJECT **OuterElements;
491 UINT32 OuterElementCount;
492 ACPI_OPERAND_OBJECT *ObjDesc;
498 ACPI_FUNCTION_NAME (NsRepair_CST);
502 * Check if the C-state type values are proportional.
504 OuterElementCount = ReturnObject->Package.Count - 1;
506 while (i < OuterElementCount)
508 OuterElements = &ReturnObject->Package.Elements[i + 1];
511 if ((*OuterElements)->Package.Count == 0)
513 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
514 "SubPackage[%u] - removing entry due to zero count", i));
519 ObjDesc = (*OuterElements)->Package.Elements[1]; /* Index1 = Type */
520 if ((UINT32) ObjDesc->Integer.Value == 0)
522 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
523 "SubPackage[%u] - removing entry due to invalid Type(0)", i));
530 AcpiNsRemoveElement (ReturnObject, i + 1);
539 /* Update top-level package count, Type "Integer" checked elsewhere */
541 ObjDesc = ReturnObject->Package.Elements[0];
542 ObjDesc->Integer.Value = OuterElementCount;
545 * Entries (subpackages) in the _CST Package must be sorted by the
546 * C-state type, in ascending order.
548 Status = AcpiNsCheckSortedList (Info, ReturnObject, 1, 4, 1,
549 ACPI_SORT_ASCENDING, "C-State Type");
550 if (ACPI_FAILURE (Status))
559 /******************************************************************************
561 * FUNCTION: AcpiNsRepair_HID
563 * PARAMETERS: Info - Method execution information block
564 * ReturnObjectPtr - Pointer to the object returned from the
565 * evaluation of a method or object
567 * RETURN: Status. AE_OK if object is OK or was repaired successfully
569 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
570 * letters are uppercase and that there is no leading asterisk.
572 *****************************************************************************/
576 ACPI_EVALUATE_INFO *Info,
577 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
579 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
580 ACPI_OPERAND_OBJECT *NewString;
585 ACPI_FUNCTION_NAME (NsRepair_HID);
588 /* We only care about string _HID objects (not integers) */
590 if (ReturnObject->Common.Type != ACPI_TYPE_STRING)
595 if (ReturnObject->String.Length == 0)
597 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
598 "Invalid zero-length _HID or _CID string"));
600 /* Return AE_OK anyway, let driver handle it */
602 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
606 /* It is simplest to always create a new string object */
608 NewString = AcpiUtCreateStringObject (ReturnObject->String.Length);
611 return (AE_NO_MEMORY);
615 * Remove a leading asterisk if present. For some unknown reason, there
616 * are many machines in the field that contains IDs like this.
618 * Examples: "*PNP0C03", "*ACPI0003"
620 Source = ReturnObject->String.Pointer;
624 NewString->String.Length--;
626 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
627 "%s: Removed invalid leading asterisk\n", Info->FullPathname));
631 * Copy and uppercase the string. From the ACPI 5.0 specification:
633 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
634 * letter and # is a hex digit. A valid ACPI ID must be of the form
635 * "NNNN####" where N is an uppercase letter or decimal digit, and
638 for (Dest = NewString->String.Pointer; *Source; Dest++, Source++)
640 *Dest = (char) ACPI_TOUPPER (*Source);
643 AcpiUtRemoveReference (ReturnObject);
644 *ReturnObjectPtr = NewString;
649 /******************************************************************************
651 * FUNCTION: AcpiNsRepair_PRT
653 * PARAMETERS: Info - Method execution information block
654 * ReturnObjectPtr - Pointer to the object returned from the
655 * evaluation of a method or object
657 * RETURN: Status. AE_OK if object is OK or was repaired successfully
659 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
660 * SourceName and SourceIndex field, a common BIOS bug.
662 *****************************************************************************/
666 ACPI_EVALUATE_INFO *Info,
667 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
669 ACPI_OPERAND_OBJECT *PackageObject = *ReturnObjectPtr;
670 ACPI_OPERAND_OBJECT **TopObjectList;
671 ACPI_OPERAND_OBJECT **SubObjectList;
672 ACPI_OPERAND_OBJECT *ObjDesc;
673 ACPI_OPERAND_OBJECT *SubPackage;
678 /* Each element in the _PRT package is a subpackage */
680 TopObjectList = PackageObject->Package.Elements;
681 ElementCount = PackageObject->Package.Count;
683 /* Examine each subpackage */
685 for (Index = 0; Index < ElementCount; Index++, TopObjectList++)
687 SubPackage = *TopObjectList;
688 SubObjectList = SubPackage->Package.Elements;
690 /* Check for minimum required element count */
692 if (SubPackage->Package.Count < 4)
698 * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
699 * and the SourceIndex (index 3), fix it. _PRT is important enough to
700 * workaround this BIOS error. This also provides compatibility with
701 * other ACPI implementations.
703 ObjDesc = SubObjectList[3];
704 if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
706 SubObjectList[3] = SubObjectList[2];
707 SubObjectList[2] = ObjDesc;
708 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
710 ACPI_WARN_PREDEFINED ((AE_INFO,
711 Info->FullPathname, Info->NodeFlags,
712 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
721 /******************************************************************************
723 * FUNCTION: AcpiNsRepair_PSS
725 * PARAMETERS: Info - Method execution information block
726 * ReturnObjectPtr - Pointer to the object returned from the
727 * evaluation of a method or object
729 * RETURN: Status. AE_OK if object is OK or was repaired successfully
731 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
732 * by the CPU frequencies. Check that the power dissipation values
733 * are all proportional to CPU frequency (i.e., sorting by
734 * frequency should be the same as sorting by power.)
736 *****************************************************************************/
740 ACPI_EVALUATE_INFO *Info,
741 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
743 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
744 ACPI_OPERAND_OBJECT **OuterElements;
745 UINT32 OuterElementCount;
746 ACPI_OPERAND_OBJECT **Elements;
747 ACPI_OPERAND_OBJECT *ObjDesc;
748 UINT32 PreviousValue;
754 * Entries (subpackages) in the _PSS Package must be sorted by power
755 * dissipation, in descending order. If it appears that the list is
756 * incorrectly sorted, sort it. We sort by CpuFrequency, since this
757 * should be proportional to the power.
759 Status =AcpiNsCheckSortedList (Info, ReturnObject, 0, 6, 0,
760 ACPI_SORT_DESCENDING, "CpuFrequency");
761 if (ACPI_FAILURE (Status))
767 * We now know the list is correctly sorted by CPU frequency. Check if
768 * the power dissipation values are proportional.
770 PreviousValue = ACPI_UINT32_MAX;
771 OuterElements = ReturnObject->Package.Elements;
772 OuterElementCount = ReturnObject->Package.Count;
774 for (i = 0; i < OuterElementCount; i++)
776 Elements = (*OuterElements)->Package.Elements;
777 ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
779 if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
781 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
782 "SubPackage[%u,%u] - suspicious power dissipation values",
786 PreviousValue = (UINT32) ObjDesc->Integer.Value;
794 /******************************************************************************
796 * FUNCTION: AcpiNsRepair_TSS
798 * PARAMETERS: Info - Method execution information block
799 * ReturnObjectPtr - Pointer to the object returned from the
800 * evaluation of a method or object
802 * RETURN: Status. AE_OK if object is OK or was repaired successfully
804 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
805 * descending by the power dissipation values.
807 *****************************************************************************/
811 ACPI_EVALUATE_INFO *Info,
812 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
814 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
816 ACPI_NAMESPACE_NODE *Node;
820 * We can only sort the _TSS return package if there is no _PSS in the
821 * same scope. This is because if _PSS is present, the ACPI specification
822 * dictates that the _TSS Power Dissipation field is to be ignored, and
823 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
824 * In this case, it is best to just return the _TSS package as-is.
827 Status = AcpiNsGetNode (Info->Node, "^_PSS",
828 ACPI_NS_NO_UPSEARCH, &Node);
829 if (ACPI_SUCCESS (Status))
834 Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 5, 1,
835 ACPI_SORT_DESCENDING, "PowerDissipation");
841 /******************************************************************************
843 * FUNCTION: AcpiNsCheckSortedList
845 * PARAMETERS: Info - Method execution information block
846 * ReturnObject - Pointer to the top-level returned object
847 * StartIndex - Index of the first subpackage
848 * ExpectedCount - Minimum length of each subpackage
849 * SortIndex - Subpackage entry to sort on
850 * SortDirection - Ascending or descending
851 * SortKeyName - Name of the SortIndex field
853 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
854 * has been repaired by sorting the list.
856 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
857 * SortIndex. If not, then sort the list.
859 *****************************************************************************/
862 AcpiNsCheckSortedList (
863 ACPI_EVALUATE_INFO *Info,
864 ACPI_OPERAND_OBJECT *ReturnObject,
866 UINT32 ExpectedCount,
871 UINT32 OuterElementCount;
872 ACPI_OPERAND_OBJECT **OuterElements;
873 ACPI_OPERAND_OBJECT **Elements;
874 ACPI_OPERAND_OBJECT *ObjDesc;
876 UINT32 PreviousValue;
879 ACPI_FUNCTION_NAME (NsCheckSortedList);
882 /* The top-level object must be a package */
884 if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
886 return (AE_AML_OPERAND_TYPE);
890 * NOTE: assumes list of subpackages contains no NULL elements.
891 * Any NULL elements should have been removed by earlier call
892 * to AcpiNsRemoveNullElements.
894 OuterElementCount = ReturnObject->Package.Count;
895 if (!OuterElementCount || StartIndex >= OuterElementCount)
897 return (AE_AML_PACKAGE_LIMIT);
900 OuterElements = &ReturnObject->Package.Elements[StartIndex];
901 OuterElementCount -= StartIndex;
904 if (SortDirection == ACPI_SORT_DESCENDING)
906 PreviousValue = ACPI_UINT32_MAX;
909 /* Examine each subpackage */
911 for (i = 0; i < OuterElementCount; i++)
913 /* Each element of the top-level package must also be a package */
915 if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
917 return (AE_AML_OPERAND_TYPE);
920 /* Each subpackage must have the minimum length */
922 if ((*OuterElements)->Package.Count < ExpectedCount)
924 return (AE_AML_PACKAGE_LIMIT);
927 Elements = (*OuterElements)->Package.Elements;
928 ObjDesc = Elements[SortIndex];
930 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
932 return (AE_AML_OPERAND_TYPE);
936 * The list must be sorted in the specified order. If we detect a
937 * discrepancy, sort the entire list.
939 if (((SortDirection == ACPI_SORT_ASCENDING) &&
940 (ObjDesc->Integer.Value < PreviousValue)) ||
941 ((SortDirection == ACPI_SORT_DESCENDING) &&
942 (ObjDesc->Integer.Value > PreviousValue)))
944 AcpiNsSortList (&ReturnObject->Package.Elements[StartIndex],
945 OuterElementCount, SortIndex, SortDirection);
947 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
949 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
950 "%s: Repaired unsorted list - now sorted by %s\n",
951 Info->FullPathname, SortKeyName));
955 PreviousValue = (UINT32) ObjDesc->Integer.Value;
963 /******************************************************************************
965 * FUNCTION: AcpiNsSortList
967 * PARAMETERS: Elements - Package object element list
968 * Count - Element count for above
969 * Index - Sort by which package element
970 * SortDirection - Ascending or Descending sort
974 * DESCRIPTION: Sort the objects that are in a package element list.
976 * NOTE: Assumes that all NULL elements have been removed from the package,
977 * and that all elements have been verified to be of type Integer.
979 *****************************************************************************/
983 ACPI_OPERAND_OBJECT **Elements,
988 ACPI_OPERAND_OBJECT *ObjDesc1;
989 ACPI_OPERAND_OBJECT *ObjDesc2;
990 ACPI_OPERAND_OBJECT *TempObj;
995 /* Simple bubble sort */
997 for (i = 1; i < Count; i++)
999 for (j = (Count - 1); j >= i; j--)
1001 ObjDesc1 = Elements[j-1]->Package.Elements[Index];
1002 ObjDesc2 = Elements[j]->Package.Elements[Index];
1004 if (((SortDirection == ACPI_SORT_ASCENDING) &&
1005 (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
1007 ((SortDirection == ACPI_SORT_DESCENDING) &&
1008 (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
1010 TempObj = Elements[j-1];
1011 Elements[j-1] = Elements[j];
1012 Elements[j] = TempObj;
1019 /******************************************************************************
1021 * FUNCTION: AcpiNsRemoveElement
1023 * PARAMETERS: ObjDesc - Package object element list
1024 * Index - Index of element to remove
1028 * DESCRIPTION: Remove the requested element of a package and delete it.
1030 *****************************************************************************/
1033 AcpiNsRemoveElement (
1034 ACPI_OPERAND_OBJECT *ObjDesc,
1037 ACPI_OPERAND_OBJECT **Source;
1038 ACPI_OPERAND_OBJECT **Dest;
1044 ACPI_FUNCTION_NAME (NsRemoveElement);
1047 Count = ObjDesc->Package.Count;
1048 NewCount = Count - 1;
1050 Source = ObjDesc->Package.Elements;
1053 /* Examine all elements of the package object, remove matched index */
1055 for (i = 0; i < Count; i++)
1059 AcpiUtRemoveReference (*Source); /* Remove one ref for being in pkg */
1060 AcpiUtRemoveReference (*Source);
1070 /* NULL terminate list and update the package count */
1073 ObjDesc->Package.Count = NewCount;