1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2013, 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 #define __NSREPAIR2_C__
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsrepair2")
56 * Information structure and handler for ACPI predefined names that can
57 * be repaired on a per-name basis.
60 ACPI_STATUS (*ACPI_REPAIR_FUNCTION
) (
61 ACPI_EVALUATE_INFO
*Info
,
62 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
64 typedef struct acpi_repair_info
66 char Name
[ACPI_NAME_SIZE
];
67 ACPI_REPAIR_FUNCTION RepairFunction
;
72 /* Local prototypes */
74 static const ACPI_REPAIR_INFO
*
75 AcpiNsMatchComplexRepair (
76 ACPI_NAMESPACE_NODE
*Node
);
80 ACPI_EVALUATE_INFO
*Info
,
81 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
85 ACPI_EVALUATE_INFO
*Info
,
86 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
90 ACPI_EVALUATE_INFO
*Info
,
91 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
95 ACPI_EVALUATE_INFO
*Info
,
96 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
100 ACPI_EVALUATE_INFO
*Info
,
101 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
105 ACPI_EVALUATE_INFO
*Info
,
106 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
110 ACPI_EVALUATE_INFO
*Info
,
111 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
115 ACPI_EVALUATE_INFO
*Info
,
116 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
);
119 AcpiNsCheckSortedList (
120 ACPI_EVALUATE_INFO
*Info
,
121 ACPI_OPERAND_OBJECT
*ReturnObject
,
123 UINT32 ExpectedCount
,
128 /* Values for SortDirection above */
130 #define ACPI_SORT_ASCENDING 0
131 #define ACPI_SORT_DESCENDING 1
134 AcpiNsRemoveElement (
135 ACPI_OPERAND_OBJECT
*ObjDesc
,
140 ACPI_OPERAND_OBJECT
**Elements
,
143 UINT8 SortDirection
);
147 * This table contains the names of the predefined methods for which we can
148 * perform more complex repairs.
152 * _ALR: Sort the list ascending by AmbientIlluminance
153 * _CID: Strings: uppercase all, remove any leading asterisk
154 * _CST: Sort the list ascending by C state type
155 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
156 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
157 * _HID: Strings: uppercase all, remove any leading asterisk
158 * _PRT: Fix reversed SourceName and SourceIndex
159 * _PSS: Sort the list descending by Power
160 * _TSS: Sort the list descending by Power
162 * Names that must be packages, but cannot be sorted:
164 * _BCL: Values are tied to the Package index where they appear, and cannot
165 * be moved or sorted. These index values are used for _BQC and _BCM.
166 * However, we can fix the case where a buffer is returned, by converting
167 * it to a Package of integers.
169 static const ACPI_REPAIR_INFO AcpiNsRepairableNames
[] =
171 {"_ALR", AcpiNsRepair_ALR
},
172 {"_CID", AcpiNsRepair_CID
},
173 {"_CST", AcpiNsRepair_CST
},
174 {"_FDE", AcpiNsRepair_FDE
},
175 {"_GTM", AcpiNsRepair_FDE
}, /* _GTM has same repair as _FDE */
176 {"_HID", AcpiNsRepair_HID
},
177 {"_PRT", AcpiNsRepair_PRT
},
178 {"_PSS", AcpiNsRepair_PSS
},
179 {"_TSS", AcpiNsRepair_TSS
},
180 {{0,0,0,0}, NULL
} /* Table terminator */
184 #define ACPI_FDE_FIELD_COUNT 5
185 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
186 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
189 /******************************************************************************
191 * FUNCTION: AcpiNsComplexRepairs
193 * PARAMETERS: Info - Method execution information block
194 * Node - Namespace node for the method/object
195 * ValidateStatus - Original status of earlier validation
196 * ReturnObjectPtr - Pointer to the object returned from the
197 * evaluation of a method or object
199 * RETURN: Status. AE_OK if repair was successful. If name is not
200 * matched, ValidateStatus is returned.
202 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
205 *****************************************************************************/
208 AcpiNsComplexRepairs (
209 ACPI_EVALUATE_INFO
*Info
,
210 ACPI_NAMESPACE_NODE
*Node
,
211 ACPI_STATUS ValidateStatus
,
212 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
214 const ACPI_REPAIR_INFO
*Predefined
;
218 /* Check if this name is in the list of repairable names */
220 Predefined
= AcpiNsMatchComplexRepair (Node
);
223 return (ValidateStatus
);
226 Status
= Predefined
->RepairFunction (Info
, ReturnObjectPtr
);
231 /******************************************************************************
233 * FUNCTION: AcpiNsMatchComplexRepair
235 * PARAMETERS: Node - Namespace node for the method/object
237 * RETURN: Pointer to entry in repair table. NULL indicates not found.
239 * DESCRIPTION: Check an object name against the repairable object list.
241 *****************************************************************************/
243 static const ACPI_REPAIR_INFO
*
244 AcpiNsMatchComplexRepair (
245 ACPI_NAMESPACE_NODE
*Node
)
247 const ACPI_REPAIR_INFO
*ThisName
;
250 /* Search info table for a repairable predefined method/object name */
252 ThisName
= AcpiNsRepairableNames
;
253 while (ThisName
->RepairFunction
)
255 if (ACPI_COMPARE_NAME (Node
->Name
.Ascii
, ThisName
->Name
))
262 return (NULL
); /* Not found */
266 /******************************************************************************
268 * FUNCTION: AcpiNsRepair_ALR
270 * PARAMETERS: Info - Method execution information block
271 * ReturnObjectPtr - Pointer to the object returned from the
272 * evaluation of a method or object
274 * RETURN: Status. AE_OK if object is OK or was repaired successfully
276 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
277 * ascending by the ambient illuminance values.
279 *****************************************************************************/
283 ACPI_EVALUATE_INFO
*Info
,
284 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
286 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
290 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 0, 2, 1,
291 ACPI_SORT_ASCENDING
, "AmbientIlluminance");
297 /******************************************************************************
299 * FUNCTION: AcpiNsRepair_FDE
301 * PARAMETERS: Info - Method execution information block
302 * ReturnObjectPtr - Pointer to the object returned from the
303 * evaluation of a method or object
305 * RETURN: Status. AE_OK if object is OK or was repaired successfully
307 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
308 * value is a Buffer of 5 DWORDs. This function repairs a common
309 * problem where the return value is a Buffer of BYTEs, not
312 *****************************************************************************/
316 ACPI_EVALUATE_INFO
*Info
,
317 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
319 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
320 ACPI_OPERAND_OBJECT
*BufferObject
;
326 ACPI_FUNCTION_NAME (NsRepair_FDE
);
329 switch (ReturnObject
->Common
.Type
)
331 case ACPI_TYPE_BUFFER
:
333 /* This is the expected type. Length should be (at least) 5 DWORDs */
335 if (ReturnObject
->Buffer
.Length
>= ACPI_FDE_DWORD_BUFFER_SIZE
)
340 /* We can only repair if we have exactly 5 BYTEs */
342 if (ReturnObject
->Buffer
.Length
!= ACPI_FDE_BYTE_BUFFER_SIZE
)
344 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
345 "Incorrect return buffer length %u, expected %u",
346 ReturnObject
->Buffer
.Length
, ACPI_FDE_DWORD_BUFFER_SIZE
));
348 return (AE_AML_OPERAND_TYPE
);
351 /* Create the new (larger) buffer object */
353 BufferObject
= AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE
);
356 return (AE_NO_MEMORY
);
359 /* Expand each byte to a DWORD */
361 ByteBuffer
= ReturnObject
->Buffer
.Pointer
;
362 DwordBuffer
= ACPI_CAST_PTR (UINT32
, BufferObject
->Buffer
.Pointer
);
364 for (i
= 0; i
< ACPI_FDE_FIELD_COUNT
; i
++)
366 *DwordBuffer
= (UINT32
) *ByteBuffer
;
371 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
372 "%s Expanded Byte Buffer to expected DWord Buffer\n",
373 Info
->FullPathname
));
378 return (AE_AML_OPERAND_TYPE
);
381 /* Delete the original return object, return the new buffer object */
383 AcpiUtRemoveReference (ReturnObject
);
384 *ReturnObjectPtr
= BufferObject
;
386 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
391 /******************************************************************************
393 * FUNCTION: AcpiNsRepair_CID
395 * PARAMETERS: Info - Method execution information block
396 * ReturnObjectPtr - Pointer to the object returned from the
397 * evaluation of a method or object
399 * RETURN: Status. AE_OK if object is OK or was repaired successfully
401 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
402 * letters are uppercase and that there is no leading asterisk.
403 * If a Package, ensure same for all string elements.
405 *****************************************************************************/
409 ACPI_EVALUATE_INFO
*Info
,
410 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
413 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
414 ACPI_OPERAND_OBJECT
**ElementPtr
;
415 ACPI_OPERAND_OBJECT
*OriginalElement
;
416 UINT16 OriginalRefCount
;
420 /* Check for _CID as a simple string */
422 if (ReturnObject
->Common
.Type
== ACPI_TYPE_STRING
)
424 Status
= AcpiNsRepair_HID (Info
, ReturnObjectPtr
);
428 /* Exit if not a Package */
430 if (ReturnObject
->Common
.Type
!= ACPI_TYPE_PACKAGE
)
435 /* Examine each element of the _CID package */
437 ElementPtr
= ReturnObject
->Package
.Elements
;
438 for (i
= 0; i
< ReturnObject
->Package
.Count
; i
++)
440 OriginalElement
= *ElementPtr
;
441 OriginalRefCount
= OriginalElement
->Common
.ReferenceCount
;
443 Status
= AcpiNsRepair_HID (Info
, ElementPtr
);
444 if (ACPI_FAILURE (Status
))
449 /* Take care with reference counts */
451 if (OriginalElement
!= *ElementPtr
)
453 /* Element was replaced */
455 (*ElementPtr
)->Common
.ReferenceCount
=
458 AcpiUtRemoveReference (OriginalElement
);
468 /******************************************************************************
470 * FUNCTION: AcpiNsRepair_CST
472 * PARAMETERS: Info - Method execution information block
473 * ReturnObjectPtr - Pointer to the object returned from the
474 * evaluation of a method or object
476 * RETURN: Status. AE_OK if object is OK or was repaired successfully
478 * DESCRIPTION: Repair for the _CST object:
479 * 1. Sort the list ascending by C state type
480 * 2. Ensure type cannot be zero
481 * 3. A sub-package count of zero means _CST is meaningless
482 * 4. Count must match the number of C state sub-packages
484 *****************************************************************************/
488 ACPI_EVALUATE_INFO
*Info
,
489 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
491 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
492 ACPI_OPERAND_OBJECT
**OuterElements
;
493 UINT32 OuterElementCount
;
494 ACPI_OPERAND_OBJECT
*ObjDesc
;
500 ACPI_FUNCTION_NAME (NsRepair_CST
);
504 * Check if the C-state type values are proportional.
506 OuterElementCount
= ReturnObject
->Package
.Count
- 1;
508 while (i
< OuterElementCount
)
510 OuterElements
= &ReturnObject
->Package
.Elements
[i
+ 1];
513 if ((*OuterElements
)->Package
.Count
== 0)
515 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
516 "SubPackage[%u] - removing entry due to zero count", i
));
521 ObjDesc
= (*OuterElements
)->Package
.Elements
[1]; /* Index1 = Type */
522 if ((UINT32
) ObjDesc
->Integer
.Value
== 0)
524 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
525 "SubPackage[%u] - removing entry due to invalid Type(0)", i
));
532 AcpiNsRemoveElement (ReturnObject
, i
+ 1);
541 /* Update top-level package count, Type "Integer" checked elsewhere */
543 ObjDesc
= ReturnObject
->Package
.Elements
[0];
544 ObjDesc
->Integer
.Value
= OuterElementCount
;
547 * Entries (subpackages) in the _CST Package must be sorted by the
548 * C-state type, in ascending order.
550 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 1, 4, 1,
551 ACPI_SORT_ASCENDING
, "C-State Type");
552 if (ACPI_FAILURE (Status
))
561 /******************************************************************************
563 * FUNCTION: AcpiNsRepair_HID
565 * PARAMETERS: Info - Method execution information block
566 * ReturnObjectPtr - Pointer to the object returned from the
567 * evaluation of a method or object
569 * RETURN: Status. AE_OK if object is OK or was repaired successfully
571 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
572 * letters are uppercase and that there is no leading asterisk.
574 *****************************************************************************/
578 ACPI_EVALUATE_INFO
*Info
,
579 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
581 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
582 ACPI_OPERAND_OBJECT
*NewString
;
587 ACPI_FUNCTION_NAME (NsRepair_HID
);
590 /* We only care about string _HID objects (not integers) */
592 if (ReturnObject
->Common
.Type
!= ACPI_TYPE_STRING
)
597 if (ReturnObject
->String
.Length
== 0)
599 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
600 "Invalid zero-length _HID or _CID string"));
602 /* Return AE_OK anyway, let driver handle it */
604 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
608 /* It is simplest to always create a new string object */
610 NewString
= AcpiUtCreateStringObject (ReturnObject
->String
.Length
);
613 return (AE_NO_MEMORY
);
617 * Remove a leading asterisk if present. For some unknown reason, there
618 * are many machines in the field that contains IDs like this.
620 * Examples: "*PNP0C03", "*ACPI0003"
622 Source
= ReturnObject
->String
.Pointer
;
626 NewString
->String
.Length
--;
628 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
629 "%s: Removed invalid leading asterisk\n", Info
->FullPathname
));
633 * Copy and uppercase the string. From the ACPI 5.0 specification:
635 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
636 * letter and # is a hex digit. A valid ACPI ID must be of the form
637 * "NNNN####" where N is an uppercase letter or decimal digit, and
640 for (Dest
= NewString
->String
.Pointer
; *Source
; Dest
++, Source
++)
642 *Dest
= (char) ACPI_TOUPPER (*Source
);
645 AcpiUtRemoveReference (ReturnObject
);
646 *ReturnObjectPtr
= NewString
;
651 /******************************************************************************
653 * FUNCTION: AcpiNsRepair_PRT
655 * PARAMETERS: Info - Method execution information block
656 * ReturnObjectPtr - Pointer to the object returned from the
657 * evaluation of a method or object
659 * RETURN: Status. AE_OK if object is OK or was repaired successfully
661 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
662 * SourceName and SourceIndex field, a common BIOS bug.
664 *****************************************************************************/
668 ACPI_EVALUATE_INFO
*Info
,
669 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
671 ACPI_OPERAND_OBJECT
*PackageObject
= *ReturnObjectPtr
;
672 ACPI_OPERAND_OBJECT
**TopObjectList
;
673 ACPI_OPERAND_OBJECT
**SubObjectList
;
674 ACPI_OPERAND_OBJECT
*ObjDesc
;
679 /* Each element in the _PRT package is a subpackage */
681 TopObjectList
= PackageObject
->Package
.Elements
;
682 ElementCount
= PackageObject
->Package
.Count
;
684 for (Index
= 0; Index
< ElementCount
; Index
++)
686 SubObjectList
= (*TopObjectList
)->Package
.Elements
;
689 * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
690 * and the SourceIndex (index 3), fix it. _PRT is important enough to
691 * workaround this BIOS error. This also provides compatibility with
692 * other ACPI implementations.
694 ObjDesc
= SubObjectList
[3];
695 if (!ObjDesc
|| (ObjDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
))
697 SubObjectList
[3] = SubObjectList
[2];
698 SubObjectList
[2] = ObjDesc
;
699 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
701 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
702 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
706 /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
715 /******************************************************************************
717 * FUNCTION: AcpiNsRepair_PSS
719 * PARAMETERS: Info - Method execution information block
720 * ReturnObjectPtr - Pointer to the object returned from the
721 * evaluation of a method or object
723 * RETURN: Status. AE_OK if object is OK or was repaired successfully
725 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
726 * by the CPU frequencies. Check that the power dissipation values
727 * are all proportional to CPU frequency (i.e., sorting by
728 * frequency should be the same as sorting by power.)
730 *****************************************************************************/
734 ACPI_EVALUATE_INFO
*Info
,
735 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
737 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
738 ACPI_OPERAND_OBJECT
**OuterElements
;
739 UINT32 OuterElementCount
;
740 ACPI_OPERAND_OBJECT
**Elements
;
741 ACPI_OPERAND_OBJECT
*ObjDesc
;
742 UINT32 PreviousValue
;
748 * Entries (sub-packages) in the _PSS Package must be sorted by power
749 * dissipation, in descending order. If it appears that the list is
750 * incorrectly sorted, sort it. We sort by CpuFrequency, since this
751 * should be proportional to the power.
753 Status
=AcpiNsCheckSortedList (Info
, ReturnObject
, 0, 6, 0,
754 ACPI_SORT_DESCENDING
, "CpuFrequency");
755 if (ACPI_FAILURE (Status
))
761 * We now know the list is correctly sorted by CPU frequency. Check if
762 * the power dissipation values are proportional.
764 PreviousValue
= ACPI_UINT32_MAX
;
765 OuterElements
= ReturnObject
->Package
.Elements
;
766 OuterElementCount
= ReturnObject
->Package
.Count
;
768 for (i
= 0; i
< OuterElementCount
; i
++)
770 Elements
= (*OuterElements
)->Package
.Elements
;
771 ObjDesc
= Elements
[1]; /* Index1 = PowerDissipation */
773 if ((UINT32
) ObjDesc
->Integer
.Value
> PreviousValue
)
775 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
776 "SubPackage[%u,%u] - suspicious power dissipation values",
780 PreviousValue
= (UINT32
) ObjDesc
->Integer
.Value
;
788 /******************************************************************************
790 * FUNCTION: AcpiNsRepair_TSS
792 * PARAMETERS: Info - Method execution information block
793 * ReturnObjectPtr - Pointer to the object returned from the
794 * evaluation of a method or object
796 * RETURN: Status. AE_OK if object is OK or was repaired successfully
798 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
799 * descending by the power dissipation values.
801 *****************************************************************************/
805 ACPI_EVALUATE_INFO
*Info
,
806 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
808 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
810 ACPI_NAMESPACE_NODE
*Node
;
814 * We can only sort the _TSS return package if there is no _PSS in the
815 * same scope. This is because if _PSS is present, the ACPI specification
816 * dictates that the _TSS Power Dissipation field is to be ignored, and
817 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
818 * In this case, it is best to just return the _TSS package as-is.
821 Status
= AcpiNsGetNode (Info
->Node
, "^_PSS",
822 ACPI_NS_NO_UPSEARCH
, &Node
);
823 if (ACPI_SUCCESS (Status
))
828 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 0, 5, 1,
829 ACPI_SORT_DESCENDING
, "PowerDissipation");
835 /******************************************************************************
837 * FUNCTION: AcpiNsCheckSortedList
839 * PARAMETERS: Info - Method execution information block
840 * ReturnObject - Pointer to the top-level returned object
841 * StartIndex - Index of the first sub-package
842 * ExpectedCount - Minimum length of each sub-package
843 * SortIndex - Sub-package entry to sort on
844 * SortDirection - Ascending or descending
845 * SortKeyName - Name of the SortIndex field
847 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
848 * has been repaired by sorting the list.
850 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
851 * SortIndex. If not, then sort the list.
853 *****************************************************************************/
856 AcpiNsCheckSortedList (
857 ACPI_EVALUATE_INFO
*Info
,
858 ACPI_OPERAND_OBJECT
*ReturnObject
,
860 UINT32 ExpectedCount
,
865 UINT32 OuterElementCount
;
866 ACPI_OPERAND_OBJECT
**OuterElements
;
867 ACPI_OPERAND_OBJECT
**Elements
;
868 ACPI_OPERAND_OBJECT
*ObjDesc
;
870 UINT32 PreviousValue
;
873 ACPI_FUNCTION_NAME (NsCheckSortedList
);
876 /* The top-level object must be a package */
878 if (ReturnObject
->Common
.Type
!= ACPI_TYPE_PACKAGE
)
880 return (AE_AML_OPERAND_TYPE
);
884 * NOTE: assumes list of sub-packages contains no NULL elements.
885 * Any NULL elements should have been removed by earlier call
886 * to AcpiNsRemoveNullElements.
888 OuterElementCount
= ReturnObject
->Package
.Count
;
889 if (!OuterElementCount
|| StartIndex
>= OuterElementCount
)
891 return (AE_AML_PACKAGE_LIMIT
);
894 OuterElements
= &ReturnObject
->Package
.Elements
[StartIndex
];
895 OuterElementCount
-= StartIndex
;
898 if (SortDirection
== ACPI_SORT_DESCENDING
)
900 PreviousValue
= ACPI_UINT32_MAX
;
903 /* Examine each subpackage */
905 for (i
= 0; i
< OuterElementCount
; i
++)
907 /* Each element of the top-level package must also be a package */
909 if ((*OuterElements
)->Common
.Type
!= ACPI_TYPE_PACKAGE
)
911 return (AE_AML_OPERAND_TYPE
);
914 /* Each sub-package must have the minimum length */
916 if ((*OuterElements
)->Package
.Count
< ExpectedCount
)
918 return (AE_AML_PACKAGE_LIMIT
);
921 Elements
= (*OuterElements
)->Package
.Elements
;
922 ObjDesc
= Elements
[SortIndex
];
924 if (ObjDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
)
926 return (AE_AML_OPERAND_TYPE
);
930 * The list must be sorted in the specified order. If we detect a
931 * discrepancy, sort the entire list.
933 if (((SortDirection
== ACPI_SORT_ASCENDING
) &&
934 (ObjDesc
->Integer
.Value
< PreviousValue
)) ||
935 ((SortDirection
== ACPI_SORT_DESCENDING
) &&
936 (ObjDesc
->Integer
.Value
> PreviousValue
)))
938 AcpiNsSortList (&ReturnObject
->Package
.Elements
[StartIndex
],
939 OuterElementCount
, SortIndex
, SortDirection
);
941 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
943 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
944 "%s: Repaired unsorted list - now sorted by %s\n",
945 Info
->FullPathname
, SortKeyName
));
949 PreviousValue
= (UINT32
) ObjDesc
->Integer
.Value
;
957 /******************************************************************************
959 * FUNCTION: AcpiNsSortList
961 * PARAMETERS: Elements - Package object element list
962 * Count - Element count for above
963 * Index - Sort by which package element
964 * SortDirection - Ascending or Descending sort
968 * DESCRIPTION: Sort the objects that are in a package element list.
970 * NOTE: Assumes that all NULL elements have been removed from the package,
971 * and that all elements have been verified to be of type Integer.
973 *****************************************************************************/
977 ACPI_OPERAND_OBJECT
**Elements
,
982 ACPI_OPERAND_OBJECT
*ObjDesc1
;
983 ACPI_OPERAND_OBJECT
*ObjDesc2
;
984 ACPI_OPERAND_OBJECT
*TempObj
;
989 /* Simple bubble sort */
991 for (i
= 1; i
< Count
; i
++)
993 for (j
= (Count
- 1); j
>= i
; j
--)
995 ObjDesc1
= Elements
[j
-1]->Package
.Elements
[Index
];
996 ObjDesc2
= Elements
[j
]->Package
.Elements
[Index
];
998 if (((SortDirection
== ACPI_SORT_ASCENDING
) &&
999 (ObjDesc1
->Integer
.Value
> ObjDesc2
->Integer
.Value
)) ||
1001 ((SortDirection
== ACPI_SORT_DESCENDING
) &&
1002 (ObjDesc1
->Integer
.Value
< ObjDesc2
->Integer
.Value
)))
1004 TempObj
= Elements
[j
-1];
1005 Elements
[j
-1] = Elements
[j
];
1006 Elements
[j
] = TempObj
;
1013 /******************************************************************************
1015 * FUNCTION: AcpiNsRemoveElement
1017 * PARAMETERS: ObjDesc - Package object element list
1018 * Index - Index of element to remove
1022 * DESCRIPTION: Remove the requested element of a package and delete it.
1024 *****************************************************************************/
1027 AcpiNsRemoveElement (
1028 ACPI_OPERAND_OBJECT
*ObjDesc
,
1031 ACPI_OPERAND_OBJECT
**Source
;
1032 ACPI_OPERAND_OBJECT
**Dest
;
1038 ACPI_FUNCTION_NAME (NsRemoveElement
);
1041 Count
= ObjDesc
->Package
.Count
;
1042 NewCount
= Count
- 1;
1044 Source
= ObjDesc
->Package
.Elements
;
1047 /* Examine all elements of the package object, remove matched index */
1049 for (i
= 0; i
< Count
; i
++)
1053 AcpiUtRemoveReference (*Source
); /* Remove one ref for being in pkg */
1054 AcpiUtRemoveReference (*Source
);
1064 /* NULL terminate list and update the package count */
1067 ObjDesc
->Package
.Count
= NewCount
;