]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/contrib/dev/acpica/namespace/nsrepair2.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / contrib / dev / acpica / namespace / nsrepair2.c
1 /******************************************************************************
2  *
3  * Module Name: nsrepair2 - Repair for objects returned by specific
4  *                          predefined methods
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
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
20  * property rights.
21  *
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
28  *
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;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
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.
54  *
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
65  * make.
66  *
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
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
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.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
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
89  * PARTICULAR PURPOSE.
90  *
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
98  * LIMITED REMEDY.
99  *
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.
114  *
115  *****************************************************************************/
116
117 #define __NSREPAIR2_C__
118
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acnamesp.h>
122
123 #define _COMPONENT          ACPI_NAMESPACE
124         ACPI_MODULE_NAME    ("nsrepair2")
125
126
127 /*
128  * Information structure and handler for ACPI predefined names that can
129  * be repaired on a per-name basis.
130  */
131 typedef
132 ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
133     ACPI_PREDEFINED_DATA    *Data,
134     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
135
136 typedef struct acpi_repair_info
137 {
138     char                    Name[ACPI_NAME_SIZE];
139     ACPI_REPAIR_FUNCTION    RepairFunction;
140
141 } ACPI_REPAIR_INFO;
142
143
144 /* Local prototypes */
145
146 static const ACPI_REPAIR_INFO *
147 AcpiNsMatchRepairableName (
148     ACPI_NAMESPACE_NODE     *Node);
149
150 static ACPI_STATUS
151 AcpiNsRepair_ALR (
152     ACPI_PREDEFINED_DATA    *Data,
153     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
154
155 static ACPI_STATUS
156 AcpiNsRepair_FDE (
157     ACPI_PREDEFINED_DATA    *Data,
158     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
159
160 static ACPI_STATUS
161 AcpiNsRepair_PSS (
162     ACPI_PREDEFINED_DATA    *Data,
163     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
164
165 static ACPI_STATUS
166 AcpiNsRepair_TSS (
167     ACPI_PREDEFINED_DATA    *Data,
168     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
169
170 static ACPI_STATUS
171 AcpiNsCheckSortedList (
172     ACPI_PREDEFINED_DATA    *Data,
173     ACPI_OPERAND_OBJECT     *ReturnObject,
174     UINT32                  ExpectedCount,
175     UINT32                  SortIndex,
176     UINT8                   SortDirection,
177     char                    *SortKeyName);
178
179 static void
180 AcpiNsSortList (
181     ACPI_OPERAND_OBJECT     **Elements,
182     UINT32                  Count,
183     UINT32                  Index,
184     UINT8                   SortDirection);
185
186 /* Values for SortDirection above */
187
188 #define ACPI_SORT_ASCENDING     0
189 #define ACPI_SORT_DESCENDING    1
190
191
192 /*
193  * This table contains the names of the predefined methods for which we can
194  * perform more complex repairs.
195  *
196  * As necessary:
197  *
198  * _ALR: Sort the list ascending by AmbientIlluminance
199  * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
200  * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
201  * _PSS: Sort the list descending by Power
202  * _TSS: Sort the list descending by Power
203  */
204 static const ACPI_REPAIR_INFO       AcpiNsRepairableNames[] =
205 {
206     {"_ALR", AcpiNsRepair_ALR},
207     {"_FDE", AcpiNsRepair_FDE},
208     {"_GTM", AcpiNsRepair_FDE},     /* _GTM has same repair as _FDE */
209     {"_PSS", AcpiNsRepair_PSS},
210     {"_TSS", AcpiNsRepair_TSS},
211     {{0,0,0,0}, NULL}               /* Table terminator */
212 };
213
214
215 #define ACPI_FDE_FIELD_COUNT        5
216 #define ACPI_FDE_BYTE_BUFFER_SIZE   5
217 #define ACPI_FDE_DWORD_BUFFER_SIZE  (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
218
219
220 /******************************************************************************
221  *
222  * FUNCTION:    AcpiNsComplexRepairs
223  *
224  * PARAMETERS:  Data                - Pointer to validation data structure
225  *              Node                - Namespace node for the method/object
226  *              ValidateStatus      - Original status of earlier validation
227  *              ReturnObjectPtr     - Pointer to the object returned from the
228  *                                    evaluation of a method or object
229  *
230  * RETURN:      Status. AE_OK if repair was successful. If name is not
231  *              matched, ValidateStatus is returned.
232  *
233  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
234  *              not expected.
235  *
236  *****************************************************************************/
237
238 ACPI_STATUS
239 AcpiNsComplexRepairs (
240     ACPI_PREDEFINED_DATA    *Data,
241     ACPI_NAMESPACE_NODE     *Node,
242     ACPI_STATUS             ValidateStatus,
243     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
244 {
245     const ACPI_REPAIR_INFO  *Predefined;
246     ACPI_STATUS             Status;
247
248
249     /* Check if this name is in the list of repairable names */
250
251     Predefined = AcpiNsMatchRepairableName (Node);
252     if (!Predefined)
253     {
254         return (ValidateStatus);
255     }
256
257     Status = Predefined->RepairFunction (Data, ReturnObjectPtr);
258     return (Status);
259 }
260
261
262 /******************************************************************************
263  *
264  * FUNCTION:    AcpiNsMatchRepairableName
265  *
266  * PARAMETERS:  Node                - Namespace node for the method/object
267  *
268  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
269  *
270  * DESCRIPTION: Check an object name against the repairable object list.
271  *
272  *****************************************************************************/
273
274 static const ACPI_REPAIR_INFO *
275 AcpiNsMatchRepairableName (
276     ACPI_NAMESPACE_NODE     *Node)
277 {
278     const ACPI_REPAIR_INFO  *ThisName;
279
280
281     /* Search info table for a repairable predefined method/object name */
282
283     ThisName = AcpiNsRepairableNames;
284     while (ThisName->RepairFunction)
285     {
286         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
287         {
288             return (ThisName);
289         }
290         ThisName++;
291     }
292
293     return (NULL); /* Not found */
294 }
295
296
297 /******************************************************************************
298  *
299  * FUNCTION:    AcpiNsRepair_ALR
300  *
301  * PARAMETERS:  Data                - Pointer to validation data structure
302  *              ReturnObjectPtr     - Pointer to the object returned from the
303  *                                    evaluation of a method or object
304  *
305  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
306  *
307  * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
308  *              ascending by the ambient illuminance values.
309  *
310  *****************************************************************************/
311
312 static ACPI_STATUS
313 AcpiNsRepair_ALR (
314     ACPI_PREDEFINED_DATA    *Data,
315     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
316 {
317     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
318     ACPI_STATUS             Status;
319
320
321     Status = AcpiNsCheckSortedList (Data, ReturnObject, 2, 1,
322                 ACPI_SORT_ASCENDING, "AmbientIlluminance");
323
324     return (Status);
325 }
326
327
328 /******************************************************************************
329  *
330  * FUNCTION:    AcpiNsRepair_FDE
331  *
332  * PARAMETERS:  Data                - Pointer to validation data structure
333  *              ReturnObjectPtr     - Pointer to the object returned from the
334  *                                    evaluation of a method or object
335  *
336  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
337  *
338  * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
339  *              value is a Buffer of 5 DWORDs. This function repairs a common
340  *              problem where the return value is a Buffer of BYTEs, not
341  *              DWORDs.
342  *
343  *****************************************************************************/
344
345 static ACPI_STATUS
346 AcpiNsRepair_FDE (
347     ACPI_PREDEFINED_DATA    *Data,
348     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
349 {
350     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
351     ACPI_OPERAND_OBJECT     *BufferObject;
352     UINT8                   *ByteBuffer;
353     UINT32                  *DwordBuffer;
354     UINT32                  i;
355
356
357     ACPI_FUNCTION_NAME (NsRepair_FDE);
358
359
360     switch (ReturnObject->Common.Type)
361     {
362     case ACPI_TYPE_BUFFER:
363
364         /* This is the expected type. Length should be (at least) 5 DWORDs */
365
366         if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
367         {
368             return (AE_OK);
369         }
370
371         /* We can only repair if we have exactly 5 BYTEs */
372
373         if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
374         {
375             ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
376                 "Incorrect return buffer length %u, expected %u",
377                 ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
378
379             return (AE_AML_OPERAND_TYPE);
380         }
381
382         /* Create the new (larger) buffer object */
383
384         BufferObject = AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE);
385         if (!BufferObject)
386         {
387             return (AE_NO_MEMORY);
388         }
389
390         /* Expand each byte to a DWORD */
391
392         ByteBuffer = ReturnObject->Buffer.Pointer;
393         DwordBuffer = ACPI_CAST_PTR (UINT32, BufferObject->Buffer.Pointer);
394
395         for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
396         {
397             *DwordBuffer = (UINT32) *ByteBuffer;
398             DwordBuffer++;
399             ByteBuffer++;
400         }
401
402         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
403             "%s Expanded Byte Buffer to expected DWord Buffer\n",
404             Data->Pathname));
405         break;
406
407     default:
408         return (AE_AML_OPERAND_TYPE);
409     }
410
411     /* Delete the original return object, return the new buffer object */
412
413     AcpiUtRemoveReference (ReturnObject);
414     *ReturnObjectPtr = BufferObject;
415
416     Data->Flags |= ACPI_OBJECT_REPAIRED;
417     return (AE_OK);
418 }
419
420
421 /******************************************************************************
422  *
423  * FUNCTION:    AcpiNsRepair_TSS
424  *
425  * PARAMETERS:  Data                - Pointer to validation data structure
426  *              ReturnObjectPtr     - Pointer to the object returned from the
427  *                                    evaluation of a method or object
428  *
429  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
430  *
431  * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
432  *              descending by the power dissipation values.
433  *
434  *****************************************************************************/
435
436 static ACPI_STATUS
437 AcpiNsRepair_TSS (
438     ACPI_PREDEFINED_DATA    *Data,
439     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
440 {
441     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
442     ACPI_STATUS             Status;
443
444
445     Status = AcpiNsCheckSortedList (Data, ReturnObject, 5, 1,
446                 ACPI_SORT_DESCENDING, "PowerDissipation");
447
448     return (Status);
449 }
450
451
452 /******************************************************************************
453  *
454  * FUNCTION:    AcpiNsRepair_PSS
455  *
456  * PARAMETERS:  Data                - Pointer to validation data structure
457  *              ReturnObjectPtr     - Pointer to the object returned from the
458  *                                    evaluation of a method or object
459  *
460  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
461  *
462  * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
463  *              by the CPU frequencies. Check that the power dissipation values
464  *              are all proportional to CPU frequency (i.e., sorting by
465  *              frequency should be the same as sorting by power.)
466  *
467  *****************************************************************************/
468
469 static ACPI_STATUS
470 AcpiNsRepair_PSS (
471     ACPI_PREDEFINED_DATA    *Data,
472     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
473 {
474     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
475     ACPI_OPERAND_OBJECT     **OuterElements;
476     UINT32                  OuterElementCount;
477     ACPI_OPERAND_OBJECT     **Elements;
478     ACPI_OPERAND_OBJECT     *ObjDesc;
479     UINT32                  PreviousValue;
480     ACPI_STATUS             Status;
481     UINT32                  i;
482
483
484     /*
485      * Entries (sub-packages) in the _PSS Package must be sorted by power
486      * dissipation, in descending order. If it appears that the list is
487      * incorrectly sorted, sort it. We sort by CpuFrequency, since this
488      * should be proportional to the power.
489      */
490     Status =AcpiNsCheckSortedList (Data, ReturnObject, 6, 0,
491                 ACPI_SORT_DESCENDING, "CpuFrequency");
492     if (ACPI_FAILURE (Status))
493     {
494         return (Status);
495     }
496
497     /*
498      * We now know the list is correctly sorted by CPU frequency. Check if
499      * the power dissipation values are proportional.
500      */
501     PreviousValue = ACPI_UINT32_MAX;
502     OuterElements = ReturnObject->Package.Elements;
503     OuterElementCount = ReturnObject->Package.Count;
504
505     for (i = 0; i < OuterElementCount; i++)
506     {
507         Elements = (*OuterElements)->Package.Elements;
508         ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
509
510         if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
511         {
512             ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
513                 "SubPackage[%u,%u] - suspicious power dissipation values",
514                 i-1, i));
515         }
516
517         PreviousValue = (UINT32) ObjDesc->Integer.Value;
518         OuterElements++;
519     }
520
521     return (AE_OK);
522 }
523
524
525 /******************************************************************************
526  *
527  * FUNCTION:    AcpiNsCheckSortedList
528  *
529  * PARAMETERS:  Data                - Pointer to validation data structure
530  *              ReturnObject        - Pointer to the top-level returned object
531  *              ExpectedCount       - Minimum length of each sub-package
532  *              SortIndex           - Sub-package entry to sort on
533  *              SortDirection       - Ascending or descending
534  *              SortKeyName         - Name of the SortIndex field
535  *
536  * RETURN:      Status. AE_OK if the list is valid and is sorted correctly or
537  *              has been repaired by sorting the list.
538  *
539  * DESCRIPTION: Check if the package list is valid and sorted correctly by the
540  *              SortIndex. If not, then sort the list.
541  *
542  *****************************************************************************/
543
544 static ACPI_STATUS
545 AcpiNsCheckSortedList (
546     ACPI_PREDEFINED_DATA    *Data,
547     ACPI_OPERAND_OBJECT     *ReturnObject,
548     UINT32                  ExpectedCount,
549     UINT32                  SortIndex,
550     UINT8                   SortDirection,
551     char                    *SortKeyName)
552 {
553     UINT32                  OuterElementCount;
554     ACPI_OPERAND_OBJECT     **OuterElements;
555     ACPI_OPERAND_OBJECT     **Elements;
556     ACPI_OPERAND_OBJECT     *ObjDesc;
557     UINT32                  i;
558     UINT32                  PreviousValue;
559
560
561     ACPI_FUNCTION_NAME (NsCheckSortedList);
562
563
564     /* The top-level object must be a package */
565
566     if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
567     {
568         return (AE_AML_OPERAND_TYPE);
569     }
570
571     /*
572      * NOTE: assumes list of sub-packages contains no NULL elements.
573      * Any NULL elements should have been removed by earlier call
574      * to AcpiNsRemoveNullElements.
575      */
576     OuterElements = ReturnObject->Package.Elements;
577     OuterElementCount = ReturnObject->Package.Count;
578     if (!OuterElementCount)
579     {
580         return (AE_AML_PACKAGE_LIMIT);
581     }
582
583     PreviousValue = 0;
584     if (SortDirection == ACPI_SORT_DESCENDING)
585     {
586         PreviousValue = ACPI_UINT32_MAX;
587     }
588
589     /* Examine each subpackage */
590
591     for (i = 0; i < OuterElementCount; i++)
592     {
593         /* Each element of the top-level package must also be a package */
594
595         if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
596         {
597             return (AE_AML_OPERAND_TYPE);
598         }
599
600         /* Each sub-package must have the minimum length */
601
602         if ((*OuterElements)->Package.Count < ExpectedCount)
603         {
604             return (AE_AML_PACKAGE_LIMIT);
605         }
606
607         Elements = (*OuterElements)->Package.Elements;
608         ObjDesc = Elements[SortIndex];
609
610         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
611         {
612             return (AE_AML_OPERAND_TYPE);
613         }
614
615         /*
616          * The list must be sorted in the specified order. If we detect a
617          * discrepancy, sort the entire list.
618          */
619         if (((SortDirection == ACPI_SORT_ASCENDING) &&
620                 (ObjDesc->Integer.Value < PreviousValue)) ||
621             ((SortDirection == ACPI_SORT_DESCENDING) &&
622                 (ObjDesc->Integer.Value > PreviousValue)))
623         {
624             AcpiNsSortList (ReturnObject->Package.Elements,
625                 OuterElementCount, SortIndex, SortDirection);
626
627             Data->Flags |= ACPI_OBJECT_REPAIRED;
628
629             ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
630                 "%s: Repaired unsorted list - now sorted by %s\n",
631                 Data->Pathname, SortKeyName));
632             return (AE_OK);
633         }
634
635         PreviousValue = (UINT32) ObjDesc->Integer.Value;
636         OuterElements++;
637     }
638
639     return (AE_OK);
640 }
641
642
643 /******************************************************************************
644  *
645  * FUNCTION:    AcpiNsSortList
646  *
647  * PARAMETERS:  Elements            - Package object element list
648  *              Count               - Element count for above
649  *              Index               - Sort by which package element
650  *              SortDirection       - Ascending or Descending sort
651  *
652  * RETURN:      None
653  *
654  * DESCRIPTION: Sort the objects that are in a package element list.
655  *
656  * NOTE: Assumes that all NULL elements have been removed from the package,
657  *       and that all elements have been verified to be of type Integer.
658  *
659  *****************************************************************************/
660
661 static void
662 AcpiNsSortList (
663     ACPI_OPERAND_OBJECT     **Elements,
664     UINT32                  Count,
665     UINT32                  Index,
666     UINT8                   SortDirection)
667 {
668     ACPI_OPERAND_OBJECT     *ObjDesc1;
669     ACPI_OPERAND_OBJECT     *ObjDesc2;
670     ACPI_OPERAND_OBJECT     *TempObj;
671     UINT32                  i;
672     UINT32                  j;
673
674
675     /* Simple bubble sort */
676
677     for (i = 1; i < Count; i++)
678     {
679         for (j = (Count - 1); j >= i; j--)
680         {
681             ObjDesc1 = Elements[j-1]->Package.Elements[Index];
682             ObjDesc2 = Elements[j]->Package.Elements[Index];
683
684             if (((SortDirection == ACPI_SORT_ASCENDING) &&
685                     (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
686
687                 ((SortDirection == ACPI_SORT_DESCENDING) &&
688                     (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
689             {
690                 TempObj = Elements[j-1];
691                 Elements[j-1] = Elements[j];
692                 Elements[j] = TempObj;
693             }
694         }
695     }
696 }