1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************
117 * Alternatively, you may choose to be licensed under the terms of the
120 * Redistribution and use in source and binary forms, with or without
121 * modification, are permitted provided that the following conditions
123 * 1. Redistributions of source code must retain the above copyright
124 * notice, this list of conditions, and the following disclaimer,
125 * without modification.
126 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127 * substantially similar to the "NO WARRANTY" disclaimer below
128 * ("Disclaimer") and any redistribution must be conditioned upon
129 * including a substantially similar Disclaimer requirement for further
130 * binary redistribution.
131 * 3. Neither the names of the above-listed copyright holders nor the names
132 * of any contributors may be used to endorse or promote products derived
133 * from this software without specific prior written permission.
135 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
147 * Alternatively, you may choose to be licensed under the terms of the
148 * GNU General Public License ("GPL") version 2 as published by the Free
149 * Software Foundation.
151 *****************************************************************************/
153 #include <contrib/dev/acpica/include/acpi.h>
154 #include <contrib/dev/acpica/include/accommon.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
157 #define _COMPONENT ACPI_NAMESPACE
158 ACPI_MODULE_NAME ("nsrepair2")
162 * Information structure and handler for ACPI predefined names that can
163 * be repaired on a per-name basis.
166 ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
167 ACPI_EVALUATE_INFO *Info,
168 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
170 typedef struct acpi_repair_info
172 char Name[ACPI_NAME_SIZE];
173 ACPI_REPAIR_FUNCTION RepairFunction;
178 /* Local prototypes */
180 static const ACPI_REPAIR_INFO *
181 AcpiNsMatchComplexRepair (
182 ACPI_NAMESPACE_NODE *Node);
186 ACPI_EVALUATE_INFO *Info,
187 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
191 ACPI_EVALUATE_INFO *Info,
192 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
196 ACPI_EVALUATE_INFO *Info,
197 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
201 ACPI_EVALUATE_INFO *Info,
202 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
206 ACPI_EVALUATE_INFO *Info,
207 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
211 ACPI_EVALUATE_INFO *Info,
212 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
216 ACPI_EVALUATE_INFO *Info,
217 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
221 ACPI_EVALUATE_INFO *Info,
222 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
225 AcpiNsCheckSortedList (
226 ACPI_EVALUATE_INFO *Info,
227 ACPI_OPERAND_OBJECT *ReturnObject,
229 UINT32 ExpectedCount,
234 /* Values for SortDirection above */
236 #define ACPI_SORT_ASCENDING 0
237 #define ACPI_SORT_DESCENDING 1
240 AcpiNsRemoveElement (
241 ACPI_OPERAND_OBJECT *ObjDesc,
246 ACPI_OPERAND_OBJECT **Elements,
249 UINT8 SortDirection);
253 * This table contains the names of the predefined methods for which we can
254 * perform more complex repairs.
258 * _ALR: Sort the list ascending by AmbientIlluminance
259 * _CID: Strings: uppercase all, remove any leading asterisk
260 * _CST: Sort the list ascending by C state type
261 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
262 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
263 * _HID: Strings: uppercase all, remove any leading asterisk
264 * _PRT: Fix reversed SourceName and SourceIndex
265 * _PSS: Sort the list descending by Power
266 * _TSS: Sort the list descending by Power
268 * Names that must be packages, but cannot be sorted:
270 * _BCL: Values are tied to the Package index where they appear, and cannot
271 * be moved or sorted. These index values are used for _BQC and _BCM.
272 * However, we can fix the case where a buffer is returned, by converting
273 * it to a Package of integers.
275 static const ACPI_REPAIR_INFO AcpiNsRepairableNames[] =
277 {"_ALR", AcpiNsRepair_ALR},
278 {"_CID", AcpiNsRepair_CID},
279 {"_CST", AcpiNsRepair_CST},
280 {"_FDE", AcpiNsRepair_FDE},
281 {"_GTM", AcpiNsRepair_FDE}, /* _GTM has same repair as _FDE */
282 {"_HID", AcpiNsRepair_HID},
283 {"_PRT", AcpiNsRepair_PRT},
284 {"_PSS", AcpiNsRepair_PSS},
285 {"_TSS", AcpiNsRepair_TSS},
286 {{0,0,0,0}, NULL} /* Table terminator */
290 #define ACPI_FDE_FIELD_COUNT 5
291 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
292 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
295 /******************************************************************************
297 * FUNCTION: AcpiNsComplexRepairs
299 * PARAMETERS: Info - Method execution information block
300 * Node - Namespace node for the method/object
301 * ValidateStatus - Original status of earlier validation
302 * ReturnObjectPtr - Pointer to the object returned from the
303 * evaluation of a method or object
305 * RETURN: Status. AE_OK if repair was successful. If name is not
306 * matched, ValidateStatus is returned.
308 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
311 *****************************************************************************/
314 AcpiNsComplexRepairs (
315 ACPI_EVALUATE_INFO *Info,
316 ACPI_NAMESPACE_NODE *Node,
317 ACPI_STATUS ValidateStatus,
318 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
320 const ACPI_REPAIR_INFO *Predefined;
324 /* Check if this name is in the list of repairable names */
326 Predefined = AcpiNsMatchComplexRepair (Node);
329 return (ValidateStatus);
332 Status = Predefined->RepairFunction (Info, ReturnObjectPtr);
337 /******************************************************************************
339 * FUNCTION: AcpiNsMatchComplexRepair
341 * PARAMETERS: Node - Namespace node for the method/object
343 * RETURN: Pointer to entry in repair table. NULL indicates not found.
345 * DESCRIPTION: Check an object name against the repairable object list.
347 *****************************************************************************/
349 static const ACPI_REPAIR_INFO *
350 AcpiNsMatchComplexRepair (
351 ACPI_NAMESPACE_NODE *Node)
353 const ACPI_REPAIR_INFO *ThisName;
356 /* Search info table for a repairable predefined method/object name */
358 ThisName = AcpiNsRepairableNames;
359 while (ThisName->RepairFunction)
361 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
369 return (NULL); /* Not found */
373 /******************************************************************************
375 * FUNCTION: AcpiNsRepair_ALR
377 * PARAMETERS: Info - Method execution information block
378 * ReturnObjectPtr - Pointer to the object returned from the
379 * evaluation of a method or object
381 * RETURN: Status. AE_OK if object is OK or was repaired successfully
383 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
384 * ascending by the ambient illuminance values.
386 *****************************************************************************/
390 ACPI_EVALUATE_INFO *Info,
391 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
393 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
397 Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 2, 1,
398 ACPI_SORT_ASCENDING, "AmbientIlluminance");
404 /******************************************************************************
406 * FUNCTION: AcpiNsRepair_FDE
408 * PARAMETERS: Info - Method execution information block
409 * ReturnObjectPtr - Pointer to the object returned from the
410 * evaluation of a method or object
412 * RETURN: Status. AE_OK if object is OK or was repaired successfully
414 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
415 * value is a Buffer of 5 DWORDs. This function repairs a common
416 * problem where the return value is a Buffer of BYTEs, not
419 *****************************************************************************/
423 ACPI_EVALUATE_INFO *Info,
424 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
426 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
427 ACPI_OPERAND_OBJECT *BufferObject;
433 ACPI_FUNCTION_NAME (NsRepair_FDE);
436 switch (ReturnObject->Common.Type)
438 case ACPI_TYPE_BUFFER:
440 /* This is the expected type. Length should be (at least) 5 DWORDs */
442 if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
447 /* We can only repair if we have exactly 5 BYTEs */
449 if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
451 ACPI_WARN_PREDEFINED ((AE_INFO,
452 Info->FullPathname, Info->NodeFlags,
453 "Incorrect return buffer length %u, expected %u",
454 ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
456 return (AE_AML_OPERAND_TYPE);
459 /* Create the new (larger) buffer object */
461 BufferObject = AcpiUtCreateBufferObject (
462 ACPI_FDE_DWORD_BUFFER_SIZE);
465 return (AE_NO_MEMORY);
468 /* Expand each byte to a DWORD */
470 ByteBuffer = ReturnObject->Buffer.Pointer;
471 DwordBuffer = ACPI_CAST_PTR (UINT32,
472 BufferObject->Buffer.Pointer);
474 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
476 *DwordBuffer = (UINT32) *ByteBuffer;
481 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
482 "%s Expanded Byte Buffer to expected DWord Buffer\n",
483 Info->FullPathname));
488 return (AE_AML_OPERAND_TYPE);
491 /* Delete the original return object, return the new buffer object */
493 AcpiUtRemoveReference (ReturnObject);
494 *ReturnObjectPtr = BufferObject;
496 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
501 /******************************************************************************
503 * FUNCTION: AcpiNsRepair_CID
505 * PARAMETERS: Info - Method execution information block
506 * ReturnObjectPtr - Pointer to the object returned from the
507 * evaluation of a method or object
509 * RETURN: Status. AE_OK if object is OK or was repaired successfully
511 * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
512 * letters are uppercase and that there is no leading asterisk.
513 * If a Package, ensure same for all string elements.
515 *****************************************************************************/
519 ACPI_EVALUATE_INFO *Info,
520 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
523 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
524 ACPI_OPERAND_OBJECT **ElementPtr;
525 ACPI_OPERAND_OBJECT *OriginalElement;
526 UINT16 OriginalRefCount;
530 /* Check for _CID as a simple string */
532 if (ReturnObject->Common.Type == ACPI_TYPE_STRING)
534 Status = AcpiNsRepair_HID (Info, ReturnObjectPtr);
538 /* Exit if not a Package */
540 if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
545 /* Examine each element of the _CID package */
547 ElementPtr = ReturnObject->Package.Elements;
548 for (i = 0; i < ReturnObject->Package.Count; i++)
550 OriginalElement = *ElementPtr;
551 OriginalRefCount = OriginalElement->Common.ReferenceCount;
553 Status = AcpiNsRepair_HID (Info, ElementPtr);
554 if (ACPI_FAILURE (Status))
559 if (OriginalElement != *ElementPtr)
561 /* Update reference count of new object */
563 (*ElementPtr)->Common.ReferenceCount =
574 /******************************************************************************
576 * FUNCTION: AcpiNsRepair_CST
578 * PARAMETERS: Info - Method execution information block
579 * ReturnObjectPtr - Pointer to the object returned from the
580 * evaluation of a method or object
582 * RETURN: Status. AE_OK if object is OK or was repaired successfully
584 * DESCRIPTION: Repair for the _CST object:
585 * 1. Sort the list ascending by C state type
586 * 2. Ensure type cannot be zero
587 * 3. A subpackage count of zero means _CST is meaningless
588 * 4. Count must match the number of C state subpackages
590 *****************************************************************************/
594 ACPI_EVALUATE_INFO *Info,
595 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
597 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
598 ACPI_OPERAND_OBJECT **OuterElements;
599 UINT32 OuterElementCount;
600 ACPI_OPERAND_OBJECT *ObjDesc;
606 ACPI_FUNCTION_NAME (NsRepair_CST);
610 * Check if the C-state type values are proportional.
612 OuterElementCount = ReturnObject->Package.Count - 1;
614 while (i < OuterElementCount)
616 OuterElements = &ReturnObject->Package.Elements[i + 1];
619 if ((*OuterElements)->Package.Count == 0)
621 ACPI_WARN_PREDEFINED ((AE_INFO,
622 Info->FullPathname, Info->NodeFlags,
623 "SubPackage[%u] - removing entry due to zero count", i));
628 ObjDesc = (*OuterElements)->Package.Elements[1]; /* Index1 = Type */
629 if ((UINT32) ObjDesc->Integer.Value == 0)
631 ACPI_WARN_PREDEFINED ((AE_INFO,
632 Info->FullPathname, Info->NodeFlags,
633 "SubPackage[%u] - removing entry due to invalid Type(0)", i));
640 AcpiNsRemoveElement (ReturnObject, i + 1);
649 /* Update top-level package count, Type "Integer" checked elsewhere */
651 ObjDesc = ReturnObject->Package.Elements[0];
652 ObjDesc->Integer.Value = OuterElementCount;
655 * Entries (subpackages) in the _CST Package must be sorted by the
656 * C-state type, in ascending order.
658 Status = AcpiNsCheckSortedList (Info, ReturnObject, 1, 4, 1,
659 ACPI_SORT_ASCENDING, "C-State Type");
660 if (ACPI_FAILURE (Status))
669 /******************************************************************************
671 * FUNCTION: AcpiNsRepair_HID
673 * PARAMETERS: Info - Method execution information block
674 * ReturnObjectPtr - Pointer to the object returned from the
675 * evaluation of a method or object
677 * RETURN: Status. AE_OK if object is OK or was repaired successfully
679 * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
680 * letters are uppercase and that there is no leading asterisk.
682 *****************************************************************************/
686 ACPI_EVALUATE_INFO *Info,
687 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
689 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
690 ACPI_OPERAND_OBJECT *NewString;
695 ACPI_FUNCTION_NAME (NsRepair_HID);
698 /* We only care about string _HID objects (not integers) */
700 if (ReturnObject->Common.Type != ACPI_TYPE_STRING)
705 if (ReturnObject->String.Length == 0)
707 ACPI_WARN_PREDEFINED ((AE_INFO,
708 Info->FullPathname, Info->NodeFlags,
709 "Invalid zero-length _HID or _CID string"));
711 /* Return AE_OK anyway, let driver handle it */
713 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
717 /* It is simplest to always create a new string object */
719 NewString = AcpiUtCreateStringObject (ReturnObject->String.Length);
722 return (AE_NO_MEMORY);
726 * Remove a leading asterisk if present. For some unknown reason, there
727 * are many machines in the field that contains IDs like this.
729 * Examples: "*PNP0C03", "*ACPI0003"
731 Source = ReturnObject->String.Pointer;
735 NewString->String.Length--;
737 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
738 "%s: Removed invalid leading asterisk\n", Info->FullPathname));
742 * Copy and uppercase the string. From the ACPI 5.0 specification:
744 * A valid PNP ID must be of the form "AAA####" where A is an uppercase
745 * letter and # is a hex digit. A valid ACPI ID must be of the form
746 * "NNNN####" where N is an uppercase letter or decimal digit, and
749 for (Dest = NewString->String.Pointer; *Source; Dest++, Source++)
751 *Dest = (char) toupper ((int) *Source);
754 AcpiUtRemoveReference (ReturnObject);
755 *ReturnObjectPtr = NewString;
760 /******************************************************************************
762 * FUNCTION: AcpiNsRepair_PRT
764 * PARAMETERS: Info - Method execution information block
765 * ReturnObjectPtr - Pointer to the object returned from the
766 * evaluation of a method or object
768 * RETURN: Status. AE_OK if object is OK or was repaired successfully
770 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
771 * SourceName and SourceIndex field, a common BIOS bug.
773 *****************************************************************************/
777 ACPI_EVALUATE_INFO *Info,
778 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
780 ACPI_OPERAND_OBJECT *PackageObject = *ReturnObjectPtr;
781 ACPI_OPERAND_OBJECT **TopObjectList;
782 ACPI_OPERAND_OBJECT **SubObjectList;
783 ACPI_OPERAND_OBJECT *ObjDesc;
784 ACPI_OPERAND_OBJECT *SubPackage;
789 /* Each element in the _PRT package is a subpackage */
791 TopObjectList = PackageObject->Package.Elements;
792 ElementCount = PackageObject->Package.Count;
794 /* Examine each subpackage */
796 for (Index = 0; Index < ElementCount; Index++, TopObjectList++)
798 SubPackage = *TopObjectList;
799 SubObjectList = SubPackage->Package.Elements;
801 /* Check for minimum required element count */
803 if (SubPackage->Package.Count < 4)
809 * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
810 * and the SourceIndex (index 3), fix it. _PRT is important enough to
811 * workaround this BIOS error. This also provides compatibility with
812 * other ACPI implementations.
814 ObjDesc = SubObjectList[3];
815 if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
817 SubObjectList[3] = SubObjectList[2];
818 SubObjectList[2] = ObjDesc;
819 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
821 ACPI_WARN_PREDEFINED ((AE_INFO,
822 Info->FullPathname, Info->NodeFlags,
823 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
832 /******************************************************************************
834 * FUNCTION: AcpiNsRepair_PSS
836 * PARAMETERS: Info - Method execution information block
837 * ReturnObjectPtr - Pointer to the object returned from the
838 * evaluation of a method or object
840 * RETURN: Status. AE_OK if object is OK or was repaired successfully
842 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
843 * by the CPU frequencies. Check that the power dissipation values
844 * are all proportional to CPU frequency (i.e., sorting by
845 * frequency should be the same as sorting by power.)
847 *****************************************************************************/
851 ACPI_EVALUATE_INFO *Info,
852 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
854 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
855 ACPI_OPERAND_OBJECT **OuterElements;
856 UINT32 OuterElementCount;
857 ACPI_OPERAND_OBJECT **Elements;
858 ACPI_OPERAND_OBJECT *ObjDesc;
859 UINT32 PreviousValue;
865 * Entries (subpackages) in the _PSS Package must be sorted by power
866 * dissipation, in descending order. If it appears that the list is
867 * incorrectly sorted, sort it. We sort by CpuFrequency, since this
868 * should be proportional to the power.
870 Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 6, 0,
871 ACPI_SORT_DESCENDING, "CpuFrequency");
872 if (ACPI_FAILURE (Status))
878 * We now know the list is correctly sorted by CPU frequency. Check if
879 * the power dissipation values are proportional.
881 PreviousValue = ACPI_UINT32_MAX;
882 OuterElements = ReturnObject->Package.Elements;
883 OuterElementCount = ReturnObject->Package.Count;
885 for (i = 0; i < OuterElementCount; i++)
887 Elements = (*OuterElements)->Package.Elements;
888 ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
890 if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
892 ACPI_WARN_PREDEFINED ((AE_INFO,
893 Info->FullPathname, Info->NodeFlags,
894 "SubPackage[%u,%u] - suspicious power dissipation values",
898 PreviousValue = (UINT32) ObjDesc->Integer.Value;
906 /******************************************************************************
908 * FUNCTION: AcpiNsRepair_TSS
910 * PARAMETERS: Info - Method execution information block
911 * ReturnObjectPtr - Pointer to the object returned from the
912 * evaluation of a method or object
914 * RETURN: Status. AE_OK if object is OK or was repaired successfully
916 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
917 * descending by the power dissipation values.
919 *****************************************************************************/
923 ACPI_EVALUATE_INFO *Info,
924 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
926 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
928 ACPI_NAMESPACE_NODE *Node;
932 * We can only sort the _TSS return package if there is no _PSS in the
933 * same scope. This is because if _PSS is present, the ACPI specification
934 * dictates that the _TSS Power Dissipation field is to be ignored, and
935 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
936 * In this case, it is best to just return the _TSS package as-is.
939 Status = AcpiNsGetNode (Info->Node, "^_PSS",
940 ACPI_NS_NO_UPSEARCH, &Node);
941 if (ACPI_SUCCESS (Status))
946 Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 5, 1,
947 ACPI_SORT_DESCENDING, "PowerDissipation");
953 /******************************************************************************
955 * FUNCTION: AcpiNsCheckSortedList
957 * PARAMETERS: Info - Method execution information block
958 * ReturnObject - Pointer to the top-level returned object
959 * StartIndex - Index of the first subpackage
960 * ExpectedCount - Minimum length of each subpackage
961 * SortIndex - Subpackage entry to sort on
962 * SortDirection - Ascending or descending
963 * SortKeyName - Name of the SortIndex field
965 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
966 * has been repaired by sorting the list.
968 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
969 * SortIndex. If not, then sort the list.
971 *****************************************************************************/
974 AcpiNsCheckSortedList (
975 ACPI_EVALUATE_INFO *Info,
976 ACPI_OPERAND_OBJECT *ReturnObject,
978 UINT32 ExpectedCount,
983 UINT32 OuterElementCount;
984 ACPI_OPERAND_OBJECT **OuterElements;
985 ACPI_OPERAND_OBJECT **Elements;
986 ACPI_OPERAND_OBJECT *ObjDesc;
988 UINT32 PreviousValue;
991 ACPI_FUNCTION_NAME (NsCheckSortedList);
994 /* The top-level object must be a package */
996 if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
998 return (AE_AML_OPERAND_TYPE);
1002 * NOTE: assumes list of subpackages contains no NULL elements.
1003 * Any NULL elements should have been removed by earlier call
1004 * to AcpiNsRemoveNullElements.
1006 OuterElementCount = ReturnObject->Package.Count;
1007 if (!OuterElementCount || StartIndex >= OuterElementCount)
1009 return (AE_AML_PACKAGE_LIMIT);
1012 OuterElements = &ReturnObject->Package.Elements[StartIndex];
1013 OuterElementCount -= StartIndex;
1016 if (SortDirection == ACPI_SORT_DESCENDING)
1018 PreviousValue = ACPI_UINT32_MAX;
1021 /* Examine each subpackage */
1023 for (i = 0; i < OuterElementCount; i++)
1025 /* Each element of the top-level package must also be a package */
1027 if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
1029 return (AE_AML_OPERAND_TYPE);
1032 /* Each subpackage must have the minimum length */
1034 if ((*OuterElements)->Package.Count < ExpectedCount)
1036 return (AE_AML_PACKAGE_LIMIT);
1039 Elements = (*OuterElements)->Package.Elements;
1040 ObjDesc = Elements[SortIndex];
1042 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
1044 return (AE_AML_OPERAND_TYPE);
1048 * The list must be sorted in the specified order. If we detect a
1049 * discrepancy, sort the entire list.
1051 if (((SortDirection == ACPI_SORT_ASCENDING) &&
1052 (ObjDesc->Integer.Value < PreviousValue)) ||
1053 ((SortDirection == ACPI_SORT_DESCENDING) &&
1054 (ObjDesc->Integer.Value > PreviousValue)))
1056 AcpiNsSortList (&ReturnObject->Package.Elements[StartIndex],
1057 OuterElementCount, SortIndex, SortDirection);
1059 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
1061 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
1062 "%s: Repaired unsorted list - now sorted by %s\n",
1063 Info->FullPathname, SortKeyName));
1067 PreviousValue = (UINT32) ObjDesc->Integer.Value;
1075 /******************************************************************************
1077 * FUNCTION: AcpiNsSortList
1079 * PARAMETERS: Elements - Package object element list
1080 * Count - Element count for above
1081 * Index - Sort by which package element
1082 * SortDirection - Ascending or Descending sort
1086 * DESCRIPTION: Sort the objects that are in a package element list.
1088 * NOTE: Assumes that all NULL elements have been removed from the package,
1089 * and that all elements have been verified to be of type Integer.
1091 *****************************************************************************/
1095 ACPI_OPERAND_OBJECT **Elements,
1098 UINT8 SortDirection)
1100 ACPI_OPERAND_OBJECT *ObjDesc1;
1101 ACPI_OPERAND_OBJECT *ObjDesc2;
1102 ACPI_OPERAND_OBJECT *TempObj;
1107 /* Simple bubble sort */
1109 for (i = 1; i < Count; i++)
1111 for (j = (Count - 1); j >= i; j--)
1113 ObjDesc1 = Elements[j-1]->Package.Elements[Index];
1114 ObjDesc2 = Elements[j]->Package.Elements[Index];
1116 if (((SortDirection == ACPI_SORT_ASCENDING) &&
1117 (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
1119 ((SortDirection == ACPI_SORT_DESCENDING) &&
1120 (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
1122 TempObj = Elements[j-1];
1123 Elements[j-1] = Elements[j];
1124 Elements[j] = TempObj;
1131 /******************************************************************************
1133 * FUNCTION: AcpiNsRemoveElement
1135 * PARAMETERS: ObjDesc - Package object element list
1136 * Index - Index of element to remove
1140 * DESCRIPTION: Remove the requested element of a package and delete it.
1142 *****************************************************************************/
1145 AcpiNsRemoveElement (
1146 ACPI_OPERAND_OBJECT *ObjDesc,
1149 ACPI_OPERAND_OBJECT **Source;
1150 ACPI_OPERAND_OBJECT **Dest;
1156 ACPI_FUNCTION_NAME (NsRemoveElement);
1159 Count = ObjDesc->Package.Count;
1160 NewCount = Count - 1;
1162 Source = ObjDesc->Package.Elements;
1165 /* Examine all elements of the package object, remove matched index */
1167 for (i = 0; i < Count; i++)
1171 AcpiUtRemoveReference (*Source); /* Remove one ref for being in pkg */
1172 AcpiUtRemoveReference (*Source);
1183 /* NULL terminate list and update the package count */
1186 ObjDesc->Package.Count = NewCount;