]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/acpica/lib-acpi/src/acpica/namespace/nsrepair2.c
update
[l4.git] / l4 / pkg / acpica / lib-acpi / src / 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 - 2009, 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 "acpi.h"
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "acpredef.h"
123
124 #define _COMPONENT          ACPI_NAMESPACE
125         ACPI_MODULE_NAME    ("nsrepair2")
126
127
128 /*
129  * Information structure and handler for ACPI predefined names that can
130  * be repaired on a per-name basis.
131  */
132 typedef
133 ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
134     ACPI_PREDEFINED_DATA    *Data,
135     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
136
137 typedef struct acpi_repair_info
138 {
139     char                    Name[ACPI_NAME_SIZE];
140     ACPI_REPAIR_FUNCTION    RepairFunction;
141
142 } ACPI_REPAIR_INFO;
143
144
145 /* Local prototypes */
146
147 static const ACPI_REPAIR_INFO *
148 AcpiNsMatchRepairableName (
149     ACPI_NAMESPACE_NODE     *Node);
150
151 static ACPI_STATUS
152 AcpiNsRepair_ALR (
153     ACPI_PREDEFINED_DATA    *Data,
154     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
155
156 static ACPI_STATUS
157 AcpiNsRepair_FDE (
158     ACPI_PREDEFINED_DATA    *Data,
159     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
160
161 static ACPI_STATUS
162 AcpiNsRepair_PSS (
163     ACPI_PREDEFINED_DATA    *Data,
164     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
165
166 static ACPI_STATUS
167 AcpiNsRepair_TSS (
168     ACPI_PREDEFINED_DATA    *Data,
169     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
170
171 static ACPI_STATUS
172 AcpiNsCheckSortedList (
173     ACPI_PREDEFINED_DATA    *Data,
174     ACPI_OPERAND_OBJECT     *ReturnObject,
175     UINT32                  ExpectedCount,
176     UINT32                  SortIndex,
177     UINT8                   SortDirection,
178     char                    *SortKeyName);
179
180 static ACPI_STATUS
181 AcpiNsSortList (
182     ACPI_OPERAND_OBJECT     **Elements,
183     UINT32                  Count,
184     UINT32                  Index,
185     UINT8                   SortDirection);
186
187 /* Values for SortDirection above */
188
189 #define ACPI_SORT_ASCENDING     0
190 #define ACPI_SORT_DESCENDING    1
191
192
193 /*
194  * This table contains the names of the predefined methods for which we can
195  * perform more complex repairs.
196  *
197  * As necessary:
198  *
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
204  */
205 static const ACPI_REPAIR_INFO       AcpiNsRepairableNames[] =
206 {
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 */
213 };
214
215
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))
219
220
221 /******************************************************************************
222  *
223  * FUNCTION:    AcpiNsComplexRepairs
224  *
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
230  *
231  * RETURN:      Status. AE_OK if repair was successful. If name is not
232  *              matched, ValidateStatus is returned.
233  *
234  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
235  *              not expected.
236  *
237  *****************************************************************************/
238
239 ACPI_STATUS
240 AcpiNsComplexRepairs (
241     ACPI_PREDEFINED_DATA    *Data,
242     ACPI_NAMESPACE_NODE     *Node,
243     ACPI_STATUS             ValidateStatus,
244     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
245 {
246     const ACPI_REPAIR_INFO  *Predefined;
247     ACPI_STATUS             Status;
248
249
250     /* Check if this name is in the list of repairable names */
251
252     Predefined = AcpiNsMatchRepairableName (Node);
253     if (!Predefined)
254     {
255         return (ValidateStatus);
256     }
257
258     Status = Predefined->RepairFunction (Data, ReturnObjectPtr);
259     return (Status);
260 }
261
262
263 /******************************************************************************
264  *
265  * FUNCTION:    AcpiNsMatchRepairableName
266  *
267  * PARAMETERS:  Node                - Namespace node for the method/object
268  *
269  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
270  *
271  * DESCRIPTION: Check an object name against the repairable object list.
272  *
273  *****************************************************************************/
274
275 static const ACPI_REPAIR_INFO *
276 AcpiNsMatchRepairableName (
277     ACPI_NAMESPACE_NODE     *Node)
278 {
279     const ACPI_REPAIR_INFO  *ThisName;
280
281
282     /* Search info table for a repairable predefined method/object name */
283
284     ThisName = AcpiNsRepairableNames;
285     while (ThisName->RepairFunction)
286     {
287         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
288         {
289             return (ThisName);
290         }
291         ThisName++;
292     }
293
294     return (NULL); /* Not found */
295 }
296
297
298 /******************************************************************************
299  *
300  * FUNCTION:    AcpiNsRepair_ALR
301  *
302  * PARAMETERS:  Data                - Pointer to validation data structure
303  *              ReturnObjectPtr     - Pointer to the object returned from the
304  *                                    evaluation of a method or object
305  *
306  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
307  *
308  * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
309  *              ascending by the ambient illuminance values.
310  *
311  *****************************************************************************/
312
313 static ACPI_STATUS
314 AcpiNsRepair_ALR (
315     ACPI_PREDEFINED_DATA    *Data,
316     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
317 {
318     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
319     ACPI_STATUS             Status;
320
321
322     Status = AcpiNsCheckSortedList (Data, ReturnObject, 2, 1,
323                 ACPI_SORT_ASCENDING, "AmbientIlluminance");
324
325     return (Status);
326 }
327
328
329 /******************************************************************************
330  *
331  * FUNCTION:    AcpiNsRepair_FDE
332  *
333  * PARAMETERS:  Data                - Pointer to validation data structure
334  *              ReturnObjectPtr     - Pointer to the object returned from the
335  *                                    evaluation of a method or object
336  *
337  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
338  *
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
342  *              DWORDs.
343  *
344  *****************************************************************************/
345
346 static ACPI_STATUS
347 AcpiNsRepair_FDE (
348     ACPI_PREDEFINED_DATA    *Data,
349     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
350 {
351     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
352     ACPI_OPERAND_OBJECT     *BufferObject;
353     UINT8                   *ByteBuffer;
354     UINT32                  *DwordBuffer;
355     UINT32                  i;
356
357
358     ACPI_FUNCTION_NAME (NsRepair_FDE);
359
360
361     switch (ReturnObject->Common.Type)
362     {
363     case ACPI_TYPE_BUFFER:
364
365         /* This is the expected type. Length should be (at least) 5 DWORDs */
366
367         if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
368         {
369             return (AE_OK);
370         }
371
372         /* We can only repair if we have exactly 5 BYTEs */
373
374         if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
375         {
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));
379
380             return (AE_AML_OPERAND_TYPE);
381         }
382
383         /* Create the new (larger) buffer object */
384
385         BufferObject = AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE);
386         if (!BufferObject)
387         {
388             return (AE_NO_MEMORY);
389         }
390
391         /* Expand each byte to a DWORD */
392
393         ByteBuffer = ReturnObject->Buffer.Pointer;
394         DwordBuffer = ACPI_CAST_PTR (UINT32, BufferObject->Buffer.Pointer);
395
396         for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
397         {
398             *DwordBuffer = (UINT32) *ByteBuffer;
399             DwordBuffer++;
400             ByteBuffer++;
401         }
402
403         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
404             "%s Expanded Byte Buffer to expected DWord Buffer\n",
405             Data->Pathname));
406         break;
407
408     default:
409         return (AE_AML_OPERAND_TYPE);
410     }
411
412     /* Delete the original return object, return the new buffer object */
413
414     AcpiUtRemoveReference (ReturnObject);
415     *ReturnObjectPtr = BufferObject;
416
417     Data->Flags |= ACPI_OBJECT_REPAIRED;
418     return (AE_OK);
419 }
420
421
422 /******************************************************************************
423  *
424  * FUNCTION:    AcpiNsRepair_TSS
425  *
426  * PARAMETERS:  Data                - Pointer to validation data structure
427  *              ReturnObjectPtr     - Pointer to the object returned from the
428  *                                    evaluation of a method or object
429  *
430  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
431  *
432  * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
433  *              descending by the power dissipation values.
434  *
435  *****************************************************************************/
436
437 static ACPI_STATUS
438 AcpiNsRepair_TSS (
439     ACPI_PREDEFINED_DATA    *Data,
440     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
441 {
442     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
443     ACPI_STATUS             Status;
444
445
446     Status = AcpiNsCheckSortedList (Data, ReturnObject, 5, 1,
447                 ACPI_SORT_DESCENDING, "PowerDissipation");
448
449     return (Status);
450 }
451
452
453 /******************************************************************************
454  *
455  * FUNCTION:    AcpiNsRepair_PSS
456  *
457  * PARAMETERS:  Data                - Pointer to validation data structure
458  *              ReturnObjectPtr     - Pointer to the object returned from the
459  *                                    evaluation of a method or object
460  *
461  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
462  *
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.)
467  *
468  *****************************************************************************/
469
470 static ACPI_STATUS
471 AcpiNsRepair_PSS (
472     ACPI_PREDEFINED_DATA    *Data,
473     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
474 {
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;
481     ACPI_STATUS             Status;
482     UINT32                  i;
483
484
485     /*
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.
490      */
491     Status =AcpiNsCheckSortedList (Data, ReturnObject, 6, 0,
492                 ACPI_SORT_DESCENDING, "CpuFrequency");
493     if (ACPI_FAILURE (Status))
494     {
495         return (Status);
496     }
497
498     /*
499      * We now know the list is correctly sorted by CPU frequency. Check if
500      * the power dissipation values are proportional.
501      */
502     PreviousValue = ACPI_UINT32_MAX;
503     OuterElements = ReturnObject->Package.Elements;
504     OuterElementCount = ReturnObject->Package.Count;
505
506     for (i = 0; i < OuterElementCount; i++)
507     {
508         Elements = (*OuterElements)->Package.Elements;
509         ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
510
511         if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
512         {
513             ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
514                 "SubPackage[%u,%u] - suspicious power dissipation values",
515                 i-1, i));
516         }
517
518         PreviousValue = (UINT32) ObjDesc->Integer.Value;
519         OuterElements++;
520     }
521
522     return (AE_OK);
523 }
524
525
526 /******************************************************************************
527  *
528  * FUNCTION:    AcpiNsCheckSortedList
529  *
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
536  *
537  * RETURN:      Status. AE_OK if the list is valid and is sorted correctly or
538  *              has been repaired by sorting the list.
539  *
540  * DESCRIPTION: Check if the package list is valid and sorted correctly by the
541  *              SortIndex. If not, then sort the list.
542  *
543  *****************************************************************************/
544
545 static ACPI_STATUS
546 AcpiNsCheckSortedList (
547     ACPI_PREDEFINED_DATA    *Data,
548     ACPI_OPERAND_OBJECT     *ReturnObject,
549     UINT32                  ExpectedCount,
550     UINT32                  SortIndex,
551     UINT8                   SortDirection,
552     char                    *SortKeyName)
553 {
554     UINT32                  OuterElementCount;
555     ACPI_OPERAND_OBJECT     **OuterElements;
556     ACPI_OPERAND_OBJECT     **Elements;
557     ACPI_OPERAND_OBJECT     *ObjDesc;
558     UINT32                  i;
559     UINT32                  PreviousValue;
560     ACPI_STATUS             Status;
561
562
563     ACPI_FUNCTION_NAME (NsCheckSortedList);
564
565
566     /* The top-level object must be a package */
567
568     if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
569     {
570         return (AE_AML_OPERAND_TYPE);
571     }
572
573     /*
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.
577      */
578     OuterElements = ReturnObject->Package.Elements;
579     OuterElementCount = ReturnObject->Package.Count;
580     if (!OuterElementCount)
581     {
582         return (AE_AML_PACKAGE_LIMIT);
583     }
584
585     PreviousValue = 0;
586     if (SortDirection == ACPI_SORT_DESCENDING)
587     {
588         PreviousValue = ACPI_UINT32_MAX;
589     }
590
591     /* Examine each subpackage */
592
593     for (i = 0; i < OuterElementCount; i++)
594     {
595         /* Each element of the top-level package must also be a package */
596
597         if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
598         {
599             return (AE_AML_OPERAND_TYPE);
600         }
601
602         /* Each sub-package must have the minimum length */
603
604         if ((*OuterElements)->Package.Count < ExpectedCount)
605         {
606             return (AE_AML_PACKAGE_LIMIT);
607         }
608
609         Elements = (*OuterElements)->Package.Elements;
610         ObjDesc = Elements[SortIndex];
611
612         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
613         {
614             return (AE_AML_OPERAND_TYPE);
615         }
616
617         /*
618          * The list must be sorted in the specified order. If we detect a
619          * discrepancy, issue a warning and sort the entire list
620          */
621         if (((SortDirection == ACPI_SORT_ASCENDING) &&
622                 (ObjDesc->Integer.Value < PreviousValue)) ||
623             ((SortDirection == ACPI_SORT_DESCENDING) &&
624                 (ObjDesc->Integer.Value > PreviousValue)))
625         {
626             Status = AcpiNsSortList (ReturnObject->Package.Elements,
627                         OuterElementCount, SortIndex, SortDirection);
628             if (ACPI_FAILURE (Status))
629             {
630                 return (Status);
631             }
632
633             Data->Flags |= ACPI_OBJECT_REPAIRED;
634
635             ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
636                 "%s: Repaired unsorted list - now sorted by %s\n",
637                 Data->Pathname, SortKeyName));
638             return (AE_OK);
639         }
640
641         PreviousValue = (UINT32) ObjDesc->Integer.Value;
642         OuterElements++;
643     }
644
645     return (AE_OK);
646 }
647
648
649 /******************************************************************************
650  *
651  * FUNCTION:    AcpiNsRemoveNullElements
652  *
653  * PARAMETERS:  Data                - Pointer to validation data structure
654  *              PackageType         - An AcpiReturnPackageTypes value
655  *              ObjDesc             - A Package object
656  *
657  * RETURN:      None.
658  *
659  * DESCRIPTION: Remove all NULL package elements from packages that contain
660  *              a variable number of sub-packages.
661  *
662  *****************************************************************************/
663
664 void
665 AcpiNsRemoveNullElements (
666     ACPI_PREDEFINED_DATA    *Data,
667     UINT8                   PackageType,
668     ACPI_OPERAND_OBJECT     *ObjDesc)
669 {
670     ACPI_OPERAND_OBJECT     **Source;
671     ACPI_OPERAND_OBJECT     **Dest;
672     UINT32                  Count;
673     UINT32                  NewCount;
674     UINT32                  i;
675
676
677     ACPI_FUNCTION_NAME (NsRemoveNullElements);
678
679
680     /*
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.
684      */
685     switch (PackageType)
686     {
687     case ACPI_PTYPE1_FIXED:
688     case ACPI_PTYPE1_VAR:
689     case ACPI_PTYPE1_OPTION:
690         return;
691
692     case ACPI_PTYPE2:
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:
698         break;
699
700     default:
701         return;
702     }
703
704     Count = ObjDesc->Package.Count;
705     NewCount = Count;
706
707     Source = ObjDesc->Package.Elements;
708     Dest = Source;
709
710     /* Examine all elements of the package object, remove nulls */
711
712     for (i = 0; i < Count; i++)
713     {
714         if (!*Source)
715         {
716             NewCount--;
717         }
718         else
719         {
720             *Dest = *Source;
721             Dest++;
722         }
723         Source++;
724     }
725
726     /* Update parent package if any null elements were removed */
727
728     if (NewCount < Count)
729     {
730         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
731             "%s: Found and removed %u NULL elements\n",
732             Data->Pathname, (Count - NewCount)));
733
734         /* NULL terminate list and update the package count */
735
736         *Dest = NULL;
737         ObjDesc->Package.Count = NewCount;
738     }
739 }
740
741
742 /******************************************************************************
743  *
744  * FUNCTION:    AcpiNsSortList
745  *
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
750  *
751  * RETURN:      Status
752  *
753  * DESCRIPTION: Sort the objects that are in a package element list.
754  *
755  * NOTE: Assumes that all NULL elements have been removed from the package.
756  *
757  *****************************************************************************/
758
759 static ACPI_STATUS
760 AcpiNsSortList (
761     ACPI_OPERAND_OBJECT     **Elements,
762     UINT32                  Count,
763     UINT32                  Index,
764     UINT8                   SortDirection)
765 {
766     ACPI_OPERAND_OBJECT     *ObjDesc1;
767     ACPI_OPERAND_OBJECT     *ObjDesc2;
768     ACPI_OPERAND_OBJECT     *TempObj;
769     UINT32                  i;
770     UINT32                  j;
771
772
773     /* Simple bubble sort */
774
775     for (i = 1; i < Count; i++)
776     {
777         for (j = (Count - 1); j >= i; j--)
778         {
779             ObjDesc1 = Elements[j-1]->Package.Elements[Index];
780             ObjDesc2 = Elements[j]->Package.Elements[Index];
781
782             if (((SortDirection == ACPI_SORT_ASCENDING) &&
783                     (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
784
785                 ((SortDirection == ACPI_SORT_DESCENDING) &&
786                     (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
787             {
788                 TempObj = Elements[j-1];
789                 Elements[j-1] = Elements[j];
790                 Elements[j] = TempObj;
791             }
792         }
793     }
794
795     return (AE_OK);
796 }