1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2021, 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 MERCHANTABILITY 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.
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_NAMESEG_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 * (UINT32) 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 ACPI_FUNCTION_TRACE (NsComplexRepairs
);
218 /* Check if this name is in the list of repairable names */
220 Predefined
= AcpiNsMatchComplexRepair (Node
);
223 return_ACPI_STATUS (ValidateStatus
);
226 Status
= Predefined
->RepairFunction (Info
, ReturnObjectPtr
);
227 return_ACPI_STATUS (Status
);
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_NAMESEG (Node
->Name
.Ascii
, ThisName
->Name
))
263 return (NULL
); /* Not found */
267 /******************************************************************************
269 * FUNCTION: AcpiNsRepair_ALR
271 * PARAMETERS: Info - Method execution information block
272 * ReturnObjectPtr - Pointer to the object returned from the
273 * evaluation of a method or object
275 * RETURN: Status. AE_OK if object is OK or was repaired successfully
277 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
278 * ascending by the ambient illuminance values.
280 *****************************************************************************/
284 ACPI_EVALUATE_INFO
*Info
,
285 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
287 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
291 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 0, 2, 1,
292 ACPI_SORT_ASCENDING
, "AmbientIlluminance");
298 /******************************************************************************
300 * FUNCTION: AcpiNsRepair_FDE
302 * PARAMETERS: Info - Method execution information block
303 * ReturnObjectPtr - Pointer to the object returned from the
304 * evaluation of a method or object
306 * RETURN: Status. AE_OK if object is OK or was repaired successfully
308 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
309 * value is a Buffer of 5 DWORDs. This function repairs a common
310 * problem where the return value is a Buffer of BYTEs, not
313 *****************************************************************************/
317 ACPI_EVALUATE_INFO
*Info
,
318 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
320 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
321 ACPI_OPERAND_OBJECT
*BufferObject
;
327 ACPI_FUNCTION_NAME (NsRepair_FDE
);
330 switch (ReturnObject
->Common
.Type
)
332 case ACPI_TYPE_BUFFER
:
334 /* This is the expected type. Length should be (at least) 5 DWORDs */
336 if (ReturnObject
->Buffer
.Length
>= ACPI_FDE_DWORD_BUFFER_SIZE
)
341 /* We can only repair if we have exactly 5 BYTEs */
343 if (ReturnObject
->Buffer
.Length
!= ACPI_FDE_BYTE_BUFFER_SIZE
)
345 ACPI_WARN_PREDEFINED ((AE_INFO
,
346 Info
->FullPathname
, Info
->NodeFlags
,
347 "Incorrect return buffer length %u, expected %u",
348 ReturnObject
->Buffer
.Length
, ACPI_FDE_DWORD_BUFFER_SIZE
));
350 return (AE_AML_OPERAND_TYPE
);
353 /* Create the new (larger) buffer object */
355 BufferObject
= AcpiUtCreateBufferObject (
356 ACPI_FDE_DWORD_BUFFER_SIZE
);
359 return (AE_NO_MEMORY
);
362 /* Expand each byte to a DWORD */
364 ByteBuffer
= ReturnObject
->Buffer
.Pointer
;
365 DwordBuffer
= ACPI_CAST_PTR (UINT32
,
366 BufferObject
->Buffer
.Pointer
);
368 for (i
= 0; i
< ACPI_FDE_FIELD_COUNT
; i
++)
370 *DwordBuffer
= (UINT32
) *ByteBuffer
;
375 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
376 "%s Expanded Byte Buffer to expected DWord Buffer\n",
377 Info
->FullPathname
));
382 return (AE_AML_OPERAND_TYPE
);
385 /* Delete the original return object, return the new buffer object */
387 AcpiUtRemoveReference (ReturnObject
);
388 *ReturnObjectPtr
= BufferObject
;
390 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
395 /******************************************************************************
397 * FUNCTION: AcpiNsRepair_CID
399 * PARAMETERS: Info - Method execution information block
400 * ReturnObjectPtr - Pointer to the object returned from the
401 * evaluation of a method or object
403 * RETURN: Status. AE_OK if object is OK or was repaired successfully
405 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
406 * letters are uppercase and that there is no leading asterisk.
407 * If a Package, ensure same for all string elements.
409 *****************************************************************************/
413 ACPI_EVALUATE_INFO
*Info
,
414 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
417 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
418 ACPI_OPERAND_OBJECT
**ElementPtr
;
419 ACPI_OPERAND_OBJECT
*OriginalElement
;
420 UINT16 OriginalRefCount
;
423 ACPI_FUNCTION_TRACE (NsRepair_CID
);
425 /* Check for _CID as a simple string */
427 if (ReturnObject
->Common
.Type
== ACPI_TYPE_STRING
)
429 Status
= AcpiNsRepair_HID (Info
, ReturnObjectPtr
);
430 return_ACPI_STATUS (Status
);
433 /* Exit if not a Package */
435 if (ReturnObject
->Common
.Type
!= ACPI_TYPE_PACKAGE
)
437 return_ACPI_STATUS (AE_OK
);
440 /* Examine each element of the _CID package */
442 ElementPtr
= ReturnObject
->Package
.Elements
;
443 for (i
= 0; i
< ReturnObject
->Package
.Count
; i
++)
445 OriginalElement
= *ElementPtr
;
446 OriginalRefCount
= OriginalElement
->Common
.ReferenceCount
;
448 Status
= AcpiNsRepair_HID (Info
, ElementPtr
);
449 if (ACPI_FAILURE (Status
))
451 return_ACPI_STATUS (Status
);
454 if (OriginalElement
!= *ElementPtr
)
456 /* Update reference count of new object */
458 (*ElementPtr
)->Common
.ReferenceCount
=
462 * The OriginalElement holds a reference from the package object
463 * that represents _HID. Since a new element was created by _HID,
464 * remove the reference from the _CID package.
466 AcpiUtRemoveReference (OriginalElement
);
472 return_ACPI_STATUS (AE_OK
);
476 /******************************************************************************
478 * FUNCTION: AcpiNsRepair_CST
480 * PARAMETERS: Info - Method execution information block
481 * ReturnObjectPtr - Pointer to the object returned from the
482 * evaluation of a method or object
484 * RETURN: Status. AE_OK if object is OK or was repaired successfully
486 * DESCRIPTION: Repair for the _CST object:
487 * 1. Sort the list ascending by C state type
488 * 2. Ensure type cannot be zero
489 * 3. A subpackage count of zero means _CST is meaningless
490 * 4. Count must match the number of C state subpackages
492 *****************************************************************************/
496 ACPI_EVALUATE_INFO
*Info
,
497 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
499 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
500 ACPI_OPERAND_OBJECT
**OuterElements
;
501 UINT32 OuterElementCount
;
502 ACPI_OPERAND_OBJECT
*ObjDesc
;
508 ACPI_FUNCTION_NAME (NsRepair_CST
);
512 * Check if the C-state type values are proportional.
514 OuterElementCount
= ReturnObject
->Package
.Count
- 1;
516 while (i
< OuterElementCount
)
518 OuterElements
= &ReturnObject
->Package
.Elements
[i
+ 1];
521 if ((*OuterElements
)->Package
.Count
== 0)
523 ACPI_WARN_PREDEFINED ((AE_INFO
,
524 Info
->FullPathname
, Info
->NodeFlags
,
525 "SubPackage[%u] - removing entry due to zero count", i
));
530 ObjDesc
= (*OuterElements
)->Package
.Elements
[1]; /* Index1 = Type */
531 if ((UINT32
) ObjDesc
->Integer
.Value
== 0)
533 ACPI_WARN_PREDEFINED ((AE_INFO
,
534 Info
->FullPathname
, Info
->NodeFlags
,
535 "SubPackage[%u] - removing entry due to invalid Type(0)", i
));
542 AcpiNsRemoveElement (ReturnObject
, i
+ 1);
551 /* Update top-level package count, Type "Integer" checked elsewhere */
553 ObjDesc
= ReturnObject
->Package
.Elements
[0];
554 ObjDesc
->Integer
.Value
= OuterElementCount
;
557 * Entries (subpackages) in the _CST Package must be sorted by the
558 * C-state type, in ascending order.
560 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 1, 4, 1,
561 ACPI_SORT_ASCENDING
, "C-State Type");
562 if (ACPI_FAILURE (Status
))
571 /******************************************************************************
573 * FUNCTION: AcpiNsRepair_HID
575 * PARAMETERS: Info - Method execution information block
576 * ReturnObjectPtr - Pointer to the object returned from the
577 * evaluation of a method or object
579 * RETURN: Status. AE_OK if object is OK or was repaired successfully
581 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
582 * letters are uppercase and that there is no leading asterisk.
584 *****************************************************************************/
588 ACPI_EVALUATE_INFO
*Info
,
589 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
591 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
592 ACPI_OPERAND_OBJECT
*NewString
;
597 ACPI_FUNCTION_NAME (NsRepair_HID
);
600 /* We only care about string _HID objects (not integers) */
602 if (ReturnObject
->Common
.Type
!= ACPI_TYPE_STRING
)
604 return_ACPI_STATUS (AE_OK
);
607 if (ReturnObject
->String
.Length
== 0)
609 ACPI_WARN_PREDEFINED ((AE_INFO
,
610 Info
->FullPathname
, Info
->NodeFlags
,
611 "Invalid zero-length _HID or _CID string"));
613 /* Return AE_OK anyway, let driver handle it */
615 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
616 return_ACPI_STATUS (AE_OK
);
619 /* It is simplest to always create a new string object */
621 NewString
= AcpiUtCreateStringObject (ReturnObject
->String
.Length
);
624 return_ACPI_STATUS (AE_NO_MEMORY
);
628 * Remove a leading asterisk if present. For some unknown reason, there
629 * are many machines in the field that contains IDs like this.
631 * Examples: "*PNP0C03", "*ACPI0003"
633 Source
= ReturnObject
->String
.Pointer
;
637 NewString
->String
.Length
--;
639 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
640 "%s: Removed invalid leading asterisk\n", Info
->FullPathname
));
644 * Copy and uppercase the string. From the ACPI 5.0 specification:
646 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
647 * letter and # is a hex digit. A valid ACPI ID must be of the form
648 * "NNNN####" where N is an uppercase letter or decimal digit, and
651 for (Dest
= NewString
->String
.Pointer
; *Source
; Dest
++, Source
++)
653 *Dest
= (char) toupper ((int) *Source
);
656 AcpiUtRemoveReference (ReturnObject
);
657 *ReturnObjectPtr
= NewString
;
658 return_ACPI_STATUS (AE_OK
);
662 /******************************************************************************
664 * FUNCTION: AcpiNsRepair_PRT
666 * PARAMETERS: Info - Method execution information block
667 * ReturnObjectPtr - Pointer to the object returned from the
668 * evaluation of a method or object
670 * RETURN: Status. AE_OK if object is OK or was repaired successfully
672 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
673 * SourceName and SourceIndex field, a common BIOS bug.
675 *****************************************************************************/
679 ACPI_EVALUATE_INFO
*Info
,
680 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
682 ACPI_OPERAND_OBJECT
*PackageObject
= *ReturnObjectPtr
;
683 ACPI_OPERAND_OBJECT
**TopObjectList
;
684 ACPI_OPERAND_OBJECT
**SubObjectList
;
685 ACPI_OPERAND_OBJECT
*ObjDesc
;
686 ACPI_OPERAND_OBJECT
*SubPackage
;
691 /* Each element in the _PRT package is a subpackage */
693 TopObjectList
= PackageObject
->Package
.Elements
;
694 ElementCount
= PackageObject
->Package
.Count
;
696 /* Examine each subpackage */
698 for (Index
= 0; Index
< ElementCount
; Index
++, TopObjectList
++)
700 SubPackage
= *TopObjectList
;
701 SubObjectList
= SubPackage
->Package
.Elements
;
703 /* Check for minimum required element count */
705 if (SubPackage
->Package
.Count
< 4)
711 * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
712 * and the SourceIndex (index 3), fix it. _PRT is important enough to
713 * workaround this BIOS error. This also provides compatibility with
714 * other ACPI implementations.
716 ObjDesc
= SubObjectList
[3];
717 if (!ObjDesc
|| (ObjDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
))
719 SubObjectList
[3] = SubObjectList
[2];
720 SubObjectList
[2] = ObjDesc
;
721 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
723 ACPI_WARN_PREDEFINED ((AE_INFO
,
724 Info
->FullPathname
, Info
->NodeFlags
,
725 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
734 /******************************************************************************
736 * FUNCTION: AcpiNsRepair_PSS
738 * PARAMETERS: Info - Method execution information block
739 * ReturnObjectPtr - Pointer to the object returned from the
740 * evaluation of a method or object
742 * RETURN: Status. AE_OK if object is OK or was repaired successfully
744 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
745 * by the CPU frequencies. Check that the power dissipation values
746 * are all proportional to CPU frequency (i.e., sorting by
747 * frequency should be the same as sorting by power.)
749 *****************************************************************************/
753 ACPI_EVALUATE_INFO
*Info
,
754 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
756 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
757 ACPI_OPERAND_OBJECT
**OuterElements
;
758 UINT32 OuterElementCount
;
759 ACPI_OPERAND_OBJECT
**Elements
;
760 ACPI_OPERAND_OBJECT
*ObjDesc
;
761 UINT32 PreviousValue
;
767 * Entries (subpackages) in the _PSS Package must be sorted by power
768 * dissipation, in descending order. If it appears that the list is
769 * incorrectly sorted, sort it. We sort by CpuFrequency, since this
770 * should be proportional to the power.
772 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 0, 6, 0,
773 ACPI_SORT_DESCENDING
, "CpuFrequency");
774 if (ACPI_FAILURE (Status
))
780 * We now know the list is correctly sorted by CPU frequency. Check if
781 * the power dissipation values are proportional.
783 PreviousValue
= ACPI_UINT32_MAX
;
784 OuterElements
= ReturnObject
->Package
.Elements
;
785 OuterElementCount
= ReturnObject
->Package
.Count
;
787 for (i
= 0; i
< OuterElementCount
; i
++)
789 Elements
= (*OuterElements
)->Package
.Elements
;
790 ObjDesc
= Elements
[1]; /* Index1 = PowerDissipation */
792 if ((UINT32
) ObjDesc
->Integer
.Value
> PreviousValue
)
794 ACPI_WARN_PREDEFINED ((AE_INFO
,
795 Info
->FullPathname
, Info
->NodeFlags
,
796 "SubPackage[%u,%u] - suspicious power dissipation values",
800 PreviousValue
= (UINT32
) ObjDesc
->Integer
.Value
;
808 /******************************************************************************
810 * FUNCTION: AcpiNsRepair_TSS
812 * PARAMETERS: Info - Method execution information block
813 * ReturnObjectPtr - Pointer to the object returned from the
814 * evaluation of a method or object
816 * RETURN: Status. AE_OK if object is OK or was repaired successfully
818 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
819 * descending by the power dissipation values.
821 *****************************************************************************/
825 ACPI_EVALUATE_INFO
*Info
,
826 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
828 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
830 ACPI_NAMESPACE_NODE
*Node
;
834 * We can only sort the _TSS return package if there is no _PSS in the
835 * same scope. This is because if _PSS is present, the ACPI specification
836 * dictates that the _TSS Power Dissipation field is to be ignored, and
837 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
838 * In this case, it is best to just return the _TSS package as-is.
841 Status
= AcpiNsGetNode (Info
->Node
, "^_PSS",
842 ACPI_NS_NO_UPSEARCH
, &Node
);
843 if (ACPI_SUCCESS (Status
))
848 Status
= AcpiNsCheckSortedList (Info
, ReturnObject
, 0, 5, 1,
849 ACPI_SORT_DESCENDING
, "PowerDissipation");
855 /******************************************************************************
857 * FUNCTION: AcpiNsCheckSortedList
859 * PARAMETERS: Info - Method execution information block
860 * ReturnObject - Pointer to the top-level returned object
861 * StartIndex - Index of the first subpackage
862 * ExpectedCount - Minimum length of each subpackage
863 * SortIndex - Subpackage entry to sort on
864 * SortDirection - Ascending or descending
865 * SortKeyName - Name of the SortIndex field
867 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
868 * has been repaired by sorting the list.
870 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
871 * SortIndex. If not, then sort the list.
873 *****************************************************************************/
876 AcpiNsCheckSortedList (
877 ACPI_EVALUATE_INFO
*Info
,
878 ACPI_OPERAND_OBJECT
*ReturnObject
,
880 UINT32 ExpectedCount
,
885 UINT32 OuterElementCount
;
886 ACPI_OPERAND_OBJECT
**OuterElements
;
887 ACPI_OPERAND_OBJECT
**Elements
;
888 ACPI_OPERAND_OBJECT
*ObjDesc
;
890 UINT32 PreviousValue
;
893 ACPI_FUNCTION_NAME (NsCheckSortedList
);
896 /* The top-level object must be a package */
898 if (ReturnObject
->Common
.Type
!= ACPI_TYPE_PACKAGE
)
900 return (AE_AML_OPERAND_TYPE
);
904 * NOTE: assumes list of subpackages contains no NULL elements.
905 * Any NULL elements should have been removed by earlier call
906 * to AcpiNsRemoveNullElements.
908 OuterElementCount
= ReturnObject
->Package
.Count
;
909 if (!OuterElementCount
|| StartIndex
>= OuterElementCount
)
911 return (AE_AML_PACKAGE_LIMIT
);
914 OuterElements
= &ReturnObject
->Package
.Elements
[StartIndex
];
915 OuterElementCount
-= StartIndex
;
918 if (SortDirection
== ACPI_SORT_DESCENDING
)
920 PreviousValue
= ACPI_UINT32_MAX
;
923 /* Examine each subpackage */
925 for (i
= 0; i
< OuterElementCount
; i
++)
927 /* Each element of the top-level package must also be a package */
929 if ((*OuterElements
)->Common
.Type
!= ACPI_TYPE_PACKAGE
)
931 return (AE_AML_OPERAND_TYPE
);
934 /* Each subpackage must have the minimum length */
936 if ((*OuterElements
)->Package
.Count
< ExpectedCount
)
938 return (AE_AML_PACKAGE_LIMIT
);
941 Elements
= (*OuterElements
)->Package
.Elements
;
942 ObjDesc
= Elements
[SortIndex
];
944 if (ObjDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
)
946 return (AE_AML_OPERAND_TYPE
);
950 * The list must be sorted in the specified order. If we detect a
951 * discrepancy, sort the entire list.
953 if (((SortDirection
== ACPI_SORT_ASCENDING
) &&
954 (ObjDesc
->Integer
.Value
< PreviousValue
)) ||
955 ((SortDirection
== ACPI_SORT_DESCENDING
) &&
956 (ObjDesc
->Integer
.Value
> PreviousValue
)))
958 AcpiNsSortList (&ReturnObject
->Package
.Elements
[StartIndex
],
959 OuterElementCount
, SortIndex
, SortDirection
);
961 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
963 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
964 "%s: Repaired unsorted list - now sorted by %s\n",
965 Info
->FullPathname
, SortKeyName
));
969 PreviousValue
= (UINT32
) ObjDesc
->Integer
.Value
;
977 /******************************************************************************
979 * FUNCTION: AcpiNsSortList
981 * PARAMETERS: Elements - Package object element list
982 * Count - Element count for above
983 * Index - Sort by which package element
984 * SortDirection - Ascending or Descending sort
988 * DESCRIPTION: Sort the objects that are in a package element list.
990 * NOTE: Assumes that all NULL elements have been removed from the package,
991 * and that all elements have been verified to be of type Integer.
993 *****************************************************************************/
997 ACPI_OPERAND_OBJECT
**Elements
,
1000 UINT8 SortDirection
)
1002 ACPI_OPERAND_OBJECT
*ObjDesc1
;
1003 ACPI_OPERAND_OBJECT
*ObjDesc2
;
1004 ACPI_OPERAND_OBJECT
*TempObj
;
1009 /* Simple bubble sort */
1011 for (i
= 1; i
< Count
; i
++)
1013 for (j
= (Count
- 1); j
>= i
; j
--)
1015 ObjDesc1
= Elements
[j
-1]->Package
.Elements
[Index
];
1016 ObjDesc2
= Elements
[j
]->Package
.Elements
[Index
];
1018 if (((SortDirection
== ACPI_SORT_ASCENDING
) &&
1019 (ObjDesc1
->Integer
.Value
> ObjDesc2
->Integer
.Value
)) ||
1021 ((SortDirection
== ACPI_SORT_DESCENDING
) &&
1022 (ObjDesc1
->Integer
.Value
< ObjDesc2
->Integer
.Value
)))
1024 TempObj
= Elements
[j
-1];
1025 Elements
[j
-1] = Elements
[j
];
1026 Elements
[j
] = TempObj
;
1033 /******************************************************************************
1035 * FUNCTION: AcpiNsRemoveElement
1037 * PARAMETERS: ObjDesc - Package object element list
1038 * Index - Index of element to remove
1042 * DESCRIPTION: Remove the requested element of a package and delete it.
1044 *****************************************************************************/
1047 AcpiNsRemoveElement (
1048 ACPI_OPERAND_OBJECT
*ObjDesc
,
1051 ACPI_OPERAND_OBJECT
**Source
;
1052 ACPI_OPERAND_OBJECT
**Dest
;
1058 ACPI_FUNCTION_NAME (NsRemoveElement
);
1061 Count
= ObjDesc
->Package
.Count
;
1062 NewCount
= Count
- 1;
1064 Source
= ObjDesc
->Package
.Elements
;
1067 /* Examine all elements of the package object, remove matched index */
1069 for (i
= 0; i
< Count
; i
++)
1073 AcpiUtRemoveReference (*Source
); /* Remove one ref for being in pkg */
1074 AcpiUtRemoveReference (*Source
);
1085 /* NULL terminate list and update the package count */
1088 ObjDesc
->Package
.Count
= NewCount
;