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__
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acnamesp.h>
123 #define _COMPONENT ACPI_NAMESPACE
124 ACPI_MODULE_NAME ("nsrepair2")
128 * Information structure and handler for ACPI predefined names that can
129 * be repaired on a per-name basis.
132 ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
133 ACPI_PREDEFINED_DATA *Data,
134 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
136 typedef struct acpi_repair_info
138 char Name[ACPI_NAME_SIZE];
139 ACPI_REPAIR_FUNCTION RepairFunction;
144 /* Local prototypes */
146 static const ACPI_REPAIR_INFO *
147 AcpiNsMatchRepairableName (
148 ACPI_NAMESPACE_NODE *Node);
152 ACPI_PREDEFINED_DATA *Data,
153 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
157 ACPI_PREDEFINED_DATA *Data,
158 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
162 ACPI_PREDEFINED_DATA *Data,
163 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
166 AcpiNsCheckSortedList (
167 ACPI_PREDEFINED_DATA *Data,
168 ACPI_OPERAND_OBJECT *ReturnObject,
169 UINT32 ExpectedCount,
175 AcpiNsRemoveNullElements (
176 ACPI_OPERAND_OBJECT *Package);
180 ACPI_OPERAND_OBJECT **Elements,
183 UINT8 SortDirection);
185 /* Values for SortDirection above */
187 #define ACPI_SORT_ASCENDING 0
188 #define ACPI_SORT_DESCENDING 1
192 * This table contains the names of the predefined methods for which we can
193 * perform more complex repairs.
195 * _ALR: Sort the list ascending by AmbientIlluminance if necessary
196 * _PSS: Sort the list descending by Power if necessary
197 * _TSS: Sort the list descending by Power if necessary
199 static const ACPI_REPAIR_INFO AcpiNsRepairableNames[] =
201 {"_ALR", AcpiNsRepair_ALR},
202 {"_PSS", AcpiNsRepair_PSS},
203 {"_TSS", AcpiNsRepair_TSS},
204 {{0,0,0,0}, NULL} /* Table terminator */
208 /******************************************************************************
210 * FUNCTION: AcpiNsComplexRepairs
212 * PARAMETERS: Data - Pointer to validation data structure
213 * Node - Namespace node for the method/object
214 * ValidateStatus - Original status of earlier validation
215 * ReturnObjectPtr - Pointer to the object returned from the
216 * evaluation of a method or object
218 * RETURN: Status. AE_OK if repair was successful. If name is not
219 * matched, ValidateStatus is returned.
221 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
224 *****************************************************************************/
227 AcpiNsComplexRepairs (
228 ACPI_PREDEFINED_DATA *Data,
229 ACPI_NAMESPACE_NODE *Node,
230 ACPI_STATUS ValidateStatus,
231 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
233 const ACPI_REPAIR_INFO *Predefined;
237 /* Check if this name is in the list of repairable names */
239 Predefined = AcpiNsMatchRepairableName (Node);
242 return (ValidateStatus);
245 Status = Predefined->RepairFunction (Data, ReturnObjectPtr);
250 /******************************************************************************
252 * FUNCTION: AcpiNsMatchRepairableName
254 * PARAMETERS: Node - Namespace node for the method/object
256 * RETURN: Pointer to entry in repair table. NULL indicates not found.
258 * DESCRIPTION: Check an object name against the repairable object list.
260 *****************************************************************************/
262 static const ACPI_REPAIR_INFO *
263 AcpiNsMatchRepairableName (
264 ACPI_NAMESPACE_NODE *Node)
266 const ACPI_REPAIR_INFO *ThisName;
269 /* Search info table for a repairable predefined method/object name */
271 ThisName = AcpiNsRepairableNames;
272 while (ThisName->RepairFunction)
274 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
281 return (NULL); /* Not found */
285 /******************************************************************************
287 * FUNCTION: AcpiNsRepair_ALR
289 * PARAMETERS: Data - Pointer to validation data structure
290 * ReturnObjectPtr - Pointer to the object returned from the
291 * evaluation of a method or object
293 * RETURN: Status. AE_OK if object is OK or was repaired successfully
295 * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
296 * ascending by the ambient illuminance values.
298 *****************************************************************************/
302 ACPI_PREDEFINED_DATA *Data,
303 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
305 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
309 Status = AcpiNsCheckSortedList (Data, ReturnObject, 2, 1,
310 ACPI_SORT_ASCENDING, "AmbientIlluminance");
316 /******************************************************************************
318 * FUNCTION: AcpiNsRepair_TSS
320 * PARAMETERS: Data - Pointer to validation data structure
321 * ReturnObjectPtr - Pointer to the object returned from the
322 * evaluation of a method or object
324 * RETURN: Status. AE_OK if object is OK or was repaired successfully
326 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
327 * descending by the power dissipation values.
329 *****************************************************************************/
333 ACPI_PREDEFINED_DATA *Data,
334 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
336 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
340 Status = AcpiNsCheckSortedList (Data, ReturnObject, 5, 1,
341 ACPI_SORT_DESCENDING, "PowerDissipation");
347 /******************************************************************************
349 * FUNCTION: AcpiNsRepair_PSS
351 * PARAMETERS: Data - Pointer to validation data structure
352 * ReturnObjectPtr - Pointer to the object returned from the
353 * evaluation of a method or object
355 * RETURN: Status. AE_OK if object is OK or was repaired successfully
357 * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
358 * by the CPU frequencies. Check that the power dissipation values
359 * are all proportional to CPU frequency (i.e., sorting by
360 * frequency should be the same as sorting by power.)
362 *****************************************************************************/
366 ACPI_PREDEFINED_DATA *Data,
367 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
369 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
370 ACPI_OPERAND_OBJECT **OuterElements;
371 UINT32 OuterElementCount;
372 ACPI_OPERAND_OBJECT **Elements;
373 ACPI_OPERAND_OBJECT *ObjDesc;
374 UINT32 PreviousValue;
380 * Entries (sub-packages) in the _PSS Package must be sorted by power
381 * dissipation, in descending order. If it appears that the list is
382 * incorrectly sorted, sort it. We sort by CpuFrequency, since this
383 * should be proportional to the power.
385 Status =AcpiNsCheckSortedList (Data, ReturnObject, 6, 0,
386 ACPI_SORT_DESCENDING, "CpuFrequency");
387 if (ACPI_FAILURE (Status))
393 * We now know the list is correctly sorted by CPU frequency. Check if
394 * the power dissipation values are proportional.
396 PreviousValue = ACPI_UINT32_MAX;
397 OuterElements = ReturnObject->Package.Elements;
398 OuterElementCount = ReturnObject->Package.Count;
400 for (i = 0; i < OuterElementCount; i++)
402 Elements = (*OuterElements)->Package.Elements;
403 ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
405 if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
407 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
408 "SubPackage[%u,%u] - suspicious power dissipation values",
412 PreviousValue = (UINT32) ObjDesc->Integer.Value;
420 /******************************************************************************
422 * FUNCTION: AcpiNsCheckSortedList
424 * PARAMETERS: Data - Pointer to validation data structure
425 * ReturnObject - Pointer to the top-level returned object
426 * ExpectedCount - Minimum length of each sub-package
427 * SortIndex - Sub-package entry to sort on
428 * SortDirection - Ascending or descending
429 * SortKeyName - Name of the SortIndex field
431 * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
432 * has been repaired by sorting the list.
434 * DESCRIPTION: Check if the package list is valid and sorted correctly by the
435 * SortIndex. If not, then sort the list.
437 *****************************************************************************/
440 AcpiNsCheckSortedList (
441 ACPI_PREDEFINED_DATA *Data,
442 ACPI_OPERAND_OBJECT *ReturnObject,
443 UINT32 ExpectedCount,
448 UINT32 OuterElementCount;
449 ACPI_OPERAND_OBJECT **OuterElements;
450 ACPI_OPERAND_OBJECT **Elements;
451 ACPI_OPERAND_OBJECT *ObjDesc;
453 UINT32 PreviousValue;
457 /* The top-level object must be a package */
459 if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
461 return (AE_AML_OPERAND_TYPE);
465 * Detect any NULL package elements and remove them from the
468 * TBD: We may want to do this for all predefined names that
469 * return a variable-length package of packages.
471 Status = AcpiNsRemoveNullElements (ReturnObject);
472 if (Status == AE_NULL_ENTRY)
474 ACPI_INFO_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
475 "NULL elements removed from package"));
477 /* Exit if package is now zero length */
479 if (!ReturnObject->Package.Count)
481 return (AE_NULL_ENTRY);
485 OuterElements = ReturnObject->Package.Elements;
486 OuterElementCount = ReturnObject->Package.Count;
487 if (!OuterElementCount)
489 return (AE_AML_PACKAGE_LIMIT);
493 if (SortDirection == ACPI_SORT_DESCENDING)
495 PreviousValue = ACPI_UINT32_MAX;
498 /* Examine each subpackage */
500 for (i = 0; i < OuterElementCount; i++)
502 /* Each element of the top-level package must also be a package */
504 if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
506 return (AE_AML_OPERAND_TYPE);
509 /* Each sub-package must have the minimum length */
511 if ((*OuterElements)->Package.Count < ExpectedCount)
513 return (AE_AML_PACKAGE_LIMIT);
516 Elements = (*OuterElements)->Package.Elements;
517 ObjDesc = Elements[SortIndex];
519 if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
521 return (AE_AML_OPERAND_TYPE);
525 * The list must be sorted in the specified order. If we detect a
526 * discrepancy, issue a warning and sort the entire list
528 if (((SortDirection == ACPI_SORT_ASCENDING) &&
529 (ObjDesc->Integer.Value < PreviousValue)) ||
530 ((SortDirection == ACPI_SORT_DESCENDING) &&
531 (ObjDesc->Integer.Value > PreviousValue)))
533 Status = AcpiNsSortList (ReturnObject->Package.Elements,
534 OuterElementCount, SortIndex, SortDirection);
535 if (ACPI_FAILURE (Status))
540 Data->Flags |= ACPI_OBJECT_REPAIRED;
542 ACPI_INFO_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
543 "Repaired unsorted list - now sorted by %s", SortKeyName));
547 PreviousValue = (UINT32) ObjDesc->Integer.Value;
555 /******************************************************************************
557 * FUNCTION: AcpiNsRemoveNullElements
559 * PARAMETERS: ObjDesc - A Package object
561 * RETURN: Status. AE_NULL_ENTRY means that one or more elements were
564 * DESCRIPTION: Remove all NULL package elements and update the package count.
566 *****************************************************************************/
569 AcpiNsRemoveNullElements (
570 ACPI_OPERAND_OBJECT *ObjDesc)
572 ACPI_OPERAND_OBJECT **Source;
573 ACPI_OPERAND_OBJECT **Dest;
574 ACPI_STATUS Status = AE_OK;
580 Count = ObjDesc->Package.Count;
583 Source = ObjDesc->Package.Elements;
586 /* Examine all elements of the package object */
588 for (i = 0; i < Count; i++)
592 Status = AE_NULL_ENTRY;
603 if (Status == AE_NULL_ENTRY)
605 /* NULL terminate list and update the package count */
608 ObjDesc->Package.Count = NewCount;
615 /******************************************************************************
617 * FUNCTION: AcpiNsSortList
619 * PARAMETERS: Elements - Package object element list
620 * Count - Element count for above
621 * Index - Sort by which package element
622 * SortDirection - Ascending or Descending sort
626 * DESCRIPTION: Sort the objects that are in a package element list.
628 * NOTE: Assumes that all NULL elements have been removed from the package.
630 *****************************************************************************/
634 ACPI_OPERAND_OBJECT **Elements,
639 ACPI_OPERAND_OBJECT *ObjDesc1;
640 ACPI_OPERAND_OBJECT *ObjDesc2;
641 ACPI_OPERAND_OBJECT *TempObj;
646 /* Simple bubble sort */
648 for (i = 1; i < Count; i++)
650 for (j = (Count - 1); j >= i; j--)
652 ObjDesc1 = Elements[j-1]->Package.Elements[Index];
653 ObjDesc2 = Elements[j]->Package.Elements[Index];
655 if (((SortDirection == ACPI_SORT_ASCENDING) &&
656 (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
658 ((SortDirection == ACPI_SORT_DESCENDING) &&
659 (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
661 TempObj = Elements[j-1];
662 Elements[j-1] = Elements[j];
663 Elements[j] = TempObj;