1 /******************************************************************************
3 * Module Name: nsrepair2 - Repair for objects returned by specific
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, 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 #define __NSREPAIR2_C__
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "acpredef.h"
124 #define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nsrepair2")
129 * Information structure and handler for ACPI predefined names that can
130 * be repaired on a per-name basis.
133 ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
134 ACPI_PREDEFINED_DATA *Data,
135 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
137 typedef struct acpi_repair_info
139 char Name[ACPI_NAME_SIZE];
140 ACPI_REPAIR_FUNCTION RepairFunction;
145 /* Local prototypes */
147 static const ACPI_REPAIR_INFO *
148 AcpiNsMatchRepairableName (
149 ACPI_NAMESPACE_NODE *Node);
153 ACPI_PREDEFINED_DATA *Data,
154 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
158 ACPI_PREDEFINED_DATA *Data,
159 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
163 ACPI_PREDEFINED_DATA *Data,
164 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
168 ACPI_PREDEFINED_DATA *Data,
169 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
172 AcpiNsCheckSortedList (
173 ACPI_PREDEFINED_DATA *Data,
174 ACPI_OPERAND_OBJECT *ReturnObject,
175 UINT32 ExpectedCount,
182 ACPI_OPERAND_OBJECT **Elements,
185 UINT8 SortDirection);
187 /* Values for SortDirection above */
189 #define ACPI_SORT_ASCENDING 0
190 #define ACPI_SORT_DESCENDING 1
194 * This table contains the names of the predefined methods for which we can
195 * perform more complex repairs.
199 * _ALR: Sort the list ascending by AmbientIlluminance
200 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
201 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
202 * _PSS: Sort the list descending by Power
203 * _TSS: Sort the list descending by Power
205 static const ACPI_REPAIR_INFO AcpiNsRepairableNames[] =
207 {"_ALR", AcpiNsRepair_ALR},
208 {"_FDE", AcpiNsRepair_FDE},
209 {"_GTM", AcpiNsRepair_FDE}, /* _GTM has same repair as _FDE */
210 {"_PSS", AcpiNsRepair_PSS},
211 {"_TSS", AcpiNsRepair_TSS},
212 {{0,0,0,0}, NULL} /* Table terminator */
216 #define ACPI_FDE_FIELD_COUNT 5
217 #define ACPI_FDE_BYTE_BUFFER_SIZE 5
218 #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
221 /******************************************************************************
223 * FUNCTION: AcpiNsComplexRepairs
225 * PARAMETERS: Data - Pointer to validation data structure
226 * Node - Namespace node for the method/object
227 * ValidateStatus - Original status of earlier validation
228 * ReturnObjectPtr - Pointer to the object returned from the
229 * evaluation of a method or object
231 * RETURN: Status. AE_OK if repair was successful. If name is not
232 * matched, ValidateStatus is returned.
234 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
237 *****************************************************************************/
240 AcpiNsComplexRepairs (
241 ACPI_PREDEFINED_DATA *Data,
242 ACPI_NAMESPACE_NODE *Node,
243 ACPI_STATUS ValidateStatus,
244 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
246 const ACPI_REPAIR_INFO *Predefined;
250 /* Check if this name is in the list of repairable names */
252 Predefined = AcpiNsMatchRepairableName (Node);
255 return (ValidateStatus);
258 Status = Predefined->RepairFunction (Data, ReturnObjectPtr);
263 /******************************************************************************
265 * FUNCTION: AcpiNsMatchRepairableName
267 * PARAMETERS: Node - Namespace node for the method/object
269 * RETURN: Pointer to entry in repair table. NULL indicates not found.
271 * DESCRIPTION: Check an object name against the repairable object list.
273 *****************************************************************************/
275 static const ACPI_REPAIR_INFO *
276 AcpiNsMatchRepairableName (
277 ACPI_NAMESPACE_NODE *Node)
279 const ACPI_REPAIR_INFO *ThisName;
282 /* Search info table for a repairable predefined method/object name */
284 ThisName = AcpiNsRepairableNames;
285 while (ThisName->RepairFunction)
287 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
294 return (NULL); /* Not found */
298 /******************************************************************************
300 * FUNCTION: AcpiNsRepair_ALR
302 * PARAMETERS: Data - Pointer to validation data structure
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 _ALR object. If necessary, sort the object list
309 * ascending by the ambient illuminance values.
311 *****************************************************************************/
315 ACPI_PREDEFINED_DATA *Data,
316 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
318 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
322 Status = AcpiNsCheckSortedList (Data, ReturnObject, 2, 1,
323 ACPI_SORT_ASCENDING, "AmbientIlluminance");
329 /******************************************************************************
331 * FUNCTION: AcpiNsRepair_FDE
333 * PARAMETERS: Data - Pointer to validation data structure
334 * ReturnObjectPtr - Pointer to the object returned from the
335 * evaluation of a method or object
337 * RETURN: Status. AE_OK if object is OK or was repaired successfully
339 * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
340 * value is a Buffer of 5 DWORDs. This function repairs a common
341 * problem where the return value is a Buffer of BYTEs, not
344 *****************************************************************************/
348 ACPI_PREDEFINED_DATA *Data,
349 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
351 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
352 ACPI_OPERAND_OBJECT *BufferObject;
358 ACPI_FUNCTION_NAME (NsRepair_FDE);
361 switch (ReturnObject->Common.Type)
363 case ACPI_TYPE_BUFFER:
365 /* This is the expected type. Length should be (at least) 5 DWORDs */
367 if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
372 /* We can only repair if we have exactly 5 BYTEs */
374 if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
376 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
377 "Incorrect return buffer length %u, expected %u",
378 ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
380 return (AE_AML_OPERAND_TYPE);
383 /* Create the new (larger) buffer object */
385 BufferObject = AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE);
388 return (AE_NO_MEMORY);
391 /* Expand each byte to a DWORD */
393 ByteBuffer = ReturnObject->Buffer.Pointer;
394 DwordBuffer = ACPI_CAST_PTR (UINT32, BufferObject->Buffer.Pointer);
396 for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
398 *DwordBuffer = (UINT32) *ByteBuffer;
403 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
404 "%s Expanded Byte Buffer to expected DWord Buffer\n",
409 return (AE_AML_OPERAND_TYPE);
412 /* Delete the original return object, return the new buffer object */
414 AcpiUtRemoveReference (ReturnObject);
415 *ReturnObjectPtr = BufferObject;
417 Data->Flags |= ACPI_OBJECT_REPAIRED;
422 /******************************************************************************
424 * FUNCTION: AcpiNsRepair_TSS
426 * PARAMETERS: Data - Pointer to validation data structure
427 * ReturnObjectPtr - Pointer to the object returned from the
428 * evaluation of a method or object
430 * RETURN: Status. AE_OK if object is OK or was repaired successfully
432 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
433 * descending by the power dissipation values.
435 *****************************************************************************/
439 ACPI_PREDEFINED_DATA *Data,
440 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
442 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
446 Status = AcpiNsCheckSortedList (Data, ReturnObject, 5, 1,
447 ACPI_SORT_DESCENDING, "PowerDissipation");
453 /******************************************************************************
455 * FUNCTION: AcpiNsRepair_PSS
457 * PARAMETERS: Data - Pointer to validation data structure
458 * ReturnObjectPtr - Pointer to the object returned from the
459 * evaluation of a method or object
461 * RETURN: Status. AE_OK if object is OK or was repaired successfully
463 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
464 * by the CPU frequencies. Check that the power dissipation values
465 * are all proportional to CPU frequency (i.e., sorting by
466 * frequency should be the same as sorting by power.)
468 *****************************************************************************/
472 ACPI_PREDEFINED_DATA *Data,
473 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
475 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
476 ACPI_OPERAND_OBJECT **OuterElements;
477 UINT32 OuterElementCount;
478 ACPI_OPERAND_OBJECT **Elements;
479 ACPI_OPERAND_OBJECT *ObjDesc;
480 UINT32 PreviousValue;
486 * Entries (sub-packages) in the _PSS Package must be sorted by power
487 * dissipation, in descending order. If it appears that the list is
488 * incorrectly sorted, sort it. We sort by CpuFrequency, since this
489 * should be proportional to the power.
491 Status =AcpiNsCheckSortedList (Data, ReturnObject, 6, 0,
492 ACPI_SORT_DESCENDING, "CpuFrequency");
493 if (ACPI_FAILURE (Status))
499 * We now know the list is correctly sorted by CPU frequency. Check if
500 * the power dissipation values are proportional.
502 PreviousValue = ACPI_UINT32_MAX;
503 OuterElements = ReturnObject->Package.Elements;
504 OuterElementCount = ReturnObject->Package.Count;
506 for (i = 0; i < OuterElementCount; i++)
508 Elements = (*OuterElements)->Package.Elements;
509 ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
511 if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
513 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
514 "SubPackage[%u,%u] - suspicious power dissipation values",
518 PreviousValue = (UINT32) ObjDesc->Integer.Value;
526 /******************************************************************************
528 * FUNCTION: AcpiNsCheckSortedList
530 * PARAMETERS: Data - Pointer to validation data structure
531 * ReturnObject - Pointer to the top-level returned object
532 * ExpectedCount - Minimum length of each sub-package
533 * SortIndex - Sub-package entry to sort on
534 * SortDirection - Ascending or descending
535 * SortKeyName - Name of the SortIndex field
537 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
538 * has been repaired by sorting the list.
540 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
541 * SortIndex. If not, then sort the list.
543 *****************************************************************************/
546 AcpiNsCheckSortedList (
547 ACPI_PREDEFINED_DATA *Data,
548 ACPI_OPERAND_OBJECT *ReturnObject,
549 UINT32 ExpectedCount,
554 UINT32 OuterElementCount;
555 ACPI_OPERAND_OBJECT **OuterElements;
556 ACPI_OPERAND_OBJECT **Elements;
557 ACPI_OPERAND_OBJECT *ObjDesc;
559 UINT32 PreviousValue;
563 ACPI_FUNCTION_NAME (NsCheckSortedList);
566 /* The top-level object must be a package */
568 if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
570 return (AE_AML_OPERAND_TYPE);
574 * NOTE: assumes list of sub-packages contains no NULL elements.
575 * Any NULL elements should have been removed by earlier call
576 * to AcpiNsRemoveNullElements.
578 OuterElements = ReturnObject->Package.Elements;
579 OuterElementCount = ReturnObject->Package.Count;
580 if (!OuterElementCount)
582 return (AE_AML_PACKAGE_LIMIT);
586 if (SortDirection == ACPI_SORT_DESCENDING)
588 PreviousValue = ACPI_UINT32_MAX;
591 /* Examine each subpackage */
593 for (i = 0; i < OuterElementCount; i++)
595 /* Each element of the top-level package must also be a package */
597 if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
599 return (AE_AML_OPERAND_TYPE);
602 /* Each sub-package must have the minimum length */
604 if ((*OuterElements)->Package.Count < ExpectedCount)
606 return (AE_AML_PACKAGE_LIMIT);
609 Elements = (*OuterElements)->Package.Elements;
610 ObjDesc = Elements[SortIndex];
612 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
614 return (AE_AML_OPERAND_TYPE);
618 * The list must be sorted in the specified order. If we detect a
619 * discrepancy, issue a warning and sort the entire list
621 if (((SortDirection == ACPI_SORT_ASCENDING) &&
622 (ObjDesc->Integer.Value < PreviousValue)) ||
623 ((SortDirection == ACPI_SORT_DESCENDING) &&
624 (ObjDesc->Integer.Value > PreviousValue)))
626 Status = AcpiNsSortList (ReturnObject->Package.Elements,
627 OuterElementCount, SortIndex, SortDirection);
628 if (ACPI_FAILURE (Status))
633 Data->Flags |= ACPI_OBJECT_REPAIRED;
635 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
636 "%s: Repaired unsorted list - now sorted by %s\n",
637 Data->Pathname, SortKeyName));
641 PreviousValue = (UINT32) ObjDesc->Integer.Value;
649 /******************************************************************************
651 * FUNCTION: AcpiNsRemoveNullElements
653 * PARAMETERS: Data - Pointer to validation data structure
654 * PackageType - An AcpiReturnPackageTypes value
655 * ObjDesc - A Package object
659 * DESCRIPTION: Remove all NULL package elements from packages that contain
660 * a variable number of sub-packages.
662 *****************************************************************************/
665 AcpiNsRemoveNullElements (
666 ACPI_PREDEFINED_DATA *Data,
668 ACPI_OPERAND_OBJECT *ObjDesc)
670 ACPI_OPERAND_OBJECT **Source;
671 ACPI_OPERAND_OBJECT **Dest;
677 ACPI_FUNCTION_NAME (NsRemoveNullElements);
681 * PTYPE1 packages contain no subpackages.
682 * PTYPE2 packages contain a variable number of sub-packages. We can
683 * safely remove all NULL elements from the PTYPE2 packages.
687 case ACPI_PTYPE1_FIXED:
688 case ACPI_PTYPE1_VAR:
689 case ACPI_PTYPE1_OPTION:
693 case ACPI_PTYPE2_COUNT:
694 case ACPI_PTYPE2_PKG_COUNT:
695 case ACPI_PTYPE2_FIXED:
696 case ACPI_PTYPE2_MIN:
697 case ACPI_PTYPE2_REV_FIXED:
704 Count = ObjDesc->Package.Count;
707 Source = ObjDesc->Package.Elements;
710 /* Examine all elements of the package object, remove nulls */
712 for (i = 0; i < Count; i++)
726 /* Update parent package if any null elements were removed */
728 if (NewCount < Count)
730 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
731 "%s: Found and removed %u NULL elements\n",
732 Data->Pathname, (Count - NewCount)));
734 /* NULL terminate list and update the package count */
737 ObjDesc->Package.Count = NewCount;
742 /******************************************************************************
744 * FUNCTION: AcpiNsSortList
746 * PARAMETERS: Elements - Package object element list
747 * Count - Element count for above
748 * Index - Sort by which package element
749 * SortDirection - Ascending or Descending sort
753 * DESCRIPTION: Sort the objects that are in a package element list.
755 * NOTE: Assumes that all NULL elements have been removed from the package.
757 *****************************************************************************/
761 ACPI_OPERAND_OBJECT **Elements,
766 ACPI_OPERAND_OBJECT *ObjDesc1;
767 ACPI_OPERAND_OBJECT *ObjDesc2;
768 ACPI_OPERAND_OBJECT *TempObj;
773 /* Simple bubble sort */
775 for (i = 1; i < Count; i++)
777 for (j = (Count - 1); j >= i; j--)
779 ObjDesc1 = Elements[j-1]->Package.Elements[Index];
780 ObjDesc2 = Elements[j]->Package.Elements[Index];
782 if (((SortDirection == ACPI_SORT_ASCENDING) &&
783 (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
785 ((SortDirection == ACPI_SORT_DESCENDING) &&
786 (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
788 TempObj = Elements[j-1];
789 Elements[j-1] = Elements[j];
790 Elements[j] = TempObj;