xref: /illumos-gate/usr/src/common/acpica/namespace/nsrepair.c (revision 5328fc53d11d7151861fa272e4fb0248b8f0e145)
1 /******************************************************************************
2  *
3  * Module Name: nsrepair - Repair for objects returned by predefined methods
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acnamesp.h"
155 #include "acinterp.h"
156 #include "acpredef.h"
157 #include "amlresrc.h"
158 
159 #define _COMPONENT          ACPI_NAMESPACE
160         ACPI_MODULE_NAME    ("nsrepair")
161 
162 
163 /*******************************************************************************
164  *
165  * This module attempts to repair or convert objects returned by the
166  * predefined methods to an object type that is expected, as per the ACPI
167  * specification. The need for this code is dictated by the many machines that
168  * return incorrect types for the standard predefined methods. Performing these
169  * conversions here, in one place, eliminates the need for individual ACPI
170  * device drivers to do the same. Note: Most of these conversions are different
171  * than the internal object conversion routines used for implicit object
172  * conversion.
173  *
174  * The following conversions can be performed as necessary:
175  *
176  * Integer -> String
177  * Integer -> Buffer
178  * String  -> Integer
179  * String  -> Buffer
180  * Buffer  -> Integer
181  * Buffer  -> String
182  * Buffer  -> Package of Integers
183  * Package -> Package of one Package
184  *
185  * Additional conversions that are available:
186  *  Convert a null return or zero return value to an EndTag descriptor
187  *  Convert an ASCII string to a Unicode buffer
188  *
189  * An incorrect standalone object is wrapped with required outer package
190  *
191  * Additional possible repairs:
192  * Required package elements that are NULL replaced by Integer/String/Buffer
193  *
194  ******************************************************************************/
195 
196 
197 /* Local prototypes */
198 
199 static const ACPI_SIMPLE_REPAIR_INFO *
200 AcpiNsMatchSimpleRepair (
201     ACPI_NAMESPACE_NODE     *Node,
202     UINT32                  ReturnBtype,
203     UINT32                  PackageIndex);
204 
205 
206 /*
207  * Special but simple repairs for some names.
208  *
209  * 2nd argument: Unexpected types that can be repaired
210  */
211 static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
212 {
213     /* Resource descriptor conversions */
214 
215     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
216                 ACPI_NOT_PACKAGE_ELEMENT,
217                 AcpiNsConvertToResource },
218     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
219                 ACPI_NOT_PACKAGE_ELEMENT,
220                 AcpiNsConvertToResource },
221     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
222                 ACPI_NOT_PACKAGE_ELEMENT,
223                 AcpiNsConvertToResource },
224 
225     /* Object reference conversions */
226 
227     { "_DEP", ACPI_RTYPE_STRING, ACPI_ALL_PACKAGE_ELEMENTS,
228                 AcpiNsConvertToReference },
229 
230     /* Unicode conversions */
231 
232     { "_MLS", ACPI_RTYPE_STRING, 1,
233                 AcpiNsConvertToUnicode },
234     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
235                 ACPI_NOT_PACKAGE_ELEMENT,
236                 AcpiNsConvertToUnicode },
237     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
238 };
239 
240 
241 /*******************************************************************************
242  *
243  * FUNCTION:    AcpiNsSimpleRepair
244  *
245  * PARAMETERS:  Info                - Method execution information block
246  *              ExpectedBtypes      - Object types expected
247  *              PackageIndex        - Index of object within parent package (if
248  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
249  *                                    otherwise)
250  *              ReturnObjectPtr     - Pointer to the object returned from the
251  *                                    evaluation of a method or object
252  *
253  * RETURN:      Status. AE_OK if repair was successful.
254  *
255  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
256  *              not expected.
257  *
258  ******************************************************************************/
259 
260 ACPI_STATUS
261 AcpiNsSimpleRepair (
262     ACPI_EVALUATE_INFO      *Info,
263     UINT32                  ExpectedBtypes,
264     UINT32                  PackageIndex,
265     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
266 {
267     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
268     ACPI_OPERAND_OBJECT     *NewObject = NULL;
269     ACPI_STATUS             Status;
270     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
271 
272 
273     ACPI_FUNCTION_NAME (NsSimpleRepair);
274 
275 
276     /*
277      * Special repairs for certain names that are in the repair table.
278      * Check if this name is in the list of repairable names.
279      */
280     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
281         Info->ReturnBtype, PackageIndex);
282     if (Predefined)
283     {
284         if (!ReturnObject)
285         {
286             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
287                 ACPI_WARN_ALWAYS, "Missing expected return value"));
288         }
289 
290         Status = Predefined->ObjectConverter (Info->Node, ReturnObject,
291             &NewObject);
292         if (ACPI_FAILURE (Status))
293         {
294             /* A fatal error occurred during a conversion */
295 
296             ACPI_EXCEPTION ((AE_INFO, Status,
297                 "During return object analysis"));
298             return (Status);
299         }
300         if (NewObject)
301         {
302             goto ObjectRepaired;
303         }
304     }
305 
306     /*
307      * Do not perform simple object repair unless the return type is not
308      * expected.
309      */
310     if (Info->ReturnBtype & ExpectedBtypes)
311     {
312         return (AE_OK);
313     }
314 
315     /*
316      * At this point, we know that the type of the returned object was not
317      * one of the expected types for this predefined name. Attempt to
318      * repair the object by converting it to one of the expected object
319      * types for this predefined name.
320      */
321 
322     /*
323      * If there is no return value, check if we require a return value for
324      * this predefined name. Either one return value is expected, or none,
325      * for both methods and other objects.
326      *
327      * Try to fix if there was no return object. Warning if failed to fix.
328      */
329     if (!ReturnObject)
330     {
331         if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
332         {
333             if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
334             {
335                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
336                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
337 
338                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
339                     PackageIndex, ReturnObjectPtr);
340                 if (ACPI_SUCCESS (Status))
341                 {
342                     return (AE_OK); /* Repair was successful */
343                 }
344             }
345             else
346             {
347                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
348                     ACPI_WARN_ALWAYS, "Missing expected return value"));
349             }
350 
351             return (AE_AML_NO_RETURN_VALUE);
352         }
353     }
354 
355     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
356     {
357         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
358         if (ACPI_SUCCESS (Status))
359         {
360             goto ObjectRepaired;
361         }
362     }
363     if (ExpectedBtypes & ACPI_RTYPE_STRING)
364     {
365         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
366         if (ACPI_SUCCESS (Status))
367         {
368             goto ObjectRepaired;
369         }
370     }
371     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
372     {
373         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
374         if (ACPI_SUCCESS (Status))
375         {
376             goto ObjectRepaired;
377         }
378     }
379     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
380     {
381         /*
382          * A package is expected. We will wrap the existing object with a
383          * new package object. It is often the case that if a variable-length
384          * package is required, but there is only a single object needed, the
385          * BIOS will return that object instead of wrapping it with a Package
386          * object. Note: after the wrapping, the package will be validated
387          * for correct contents (expected object type or types).
388          */
389         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
390         if (ACPI_SUCCESS (Status))
391         {
392             /*
393              * The original object just had its reference count
394              * incremented for being inserted into the new package.
395              */
396             *ReturnObjectPtr = NewObject;       /* New Package object */
397             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
398             return (AE_OK);
399         }
400     }
401 
402     /* We cannot repair this object */
403 
404     return (AE_AML_OPERAND_TYPE);
405 
406 
407 ObjectRepaired:
408 
409     /* Object was successfully repaired */
410 
411     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
412     {
413         /* Update reference count of new object */
414 
415         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
416         {
417             NewObject->Common.ReferenceCount =
418                 ReturnObject->Common.ReferenceCount;
419         }
420 
421         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
422             "%s: Converted %s to expected %s at Package index %u\n",
423             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
424             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
425     }
426     else
427     {
428         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
429             "%s: Converted %s to expected %s\n",
430             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
431             AcpiUtGetObjectTypeName (NewObject)));
432     }
433 
434     /* Delete old object, install the new return object */
435 
436     AcpiUtRemoveReference (ReturnObject);
437     *ReturnObjectPtr = NewObject;
438     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
439     return (AE_OK);
440 }
441 
442 
443 /******************************************************************************
444  *
445  * FUNCTION:    AcpiNsMatchSimpleRepair
446  *
447  * PARAMETERS:  Node                - Namespace node for the method/object
448  *              ReturnBtype         - Object type that was returned
449  *              PackageIndex        - Index of object within parent package (if
450  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
451  *                                    otherwise)
452  *
453  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
454  *
455  * DESCRIPTION: Check an object name against the repairable object list.
456  *
457  *****************************************************************************/
458 
459 static const ACPI_SIMPLE_REPAIR_INFO *
460 AcpiNsMatchSimpleRepair (
461     ACPI_NAMESPACE_NODE     *Node,
462     UINT32                  ReturnBtype,
463     UINT32                  PackageIndex)
464 {
465     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
466 
467 
468     /* Search info table for a repairable predefined method/object name */
469 
470     ThisName = AcpiObjectRepairInfo;
471     while (ThisName->ObjectConverter)
472     {
473         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
474         {
475             /* Check if we can actually repair this name/type combination */
476 
477             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
478                 (ThisName->PackageIndex == ACPI_ALL_PACKAGE_ELEMENTS ||
479                  PackageIndex == ThisName->PackageIndex))
480             {
481                 return (ThisName);
482             }
483 
484             return (NULL);
485         }
486 
487         ThisName++;
488     }
489 
490     return (NULL); /* Name was not found in the repair table */
491 }
492 
493 
494 /*******************************************************************************
495  *
496  * FUNCTION:    AcpiNsRepairNullElement
497  *
498  * PARAMETERS:  Info                - Method execution information block
499  *              ExpectedBtypes      - Object types expected
500  *              PackageIndex        - Index of object within parent package (if
501  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
502  *                                    otherwise)
503  *              ReturnObjectPtr     - Pointer to the object returned from the
504  *                                    evaluation of a method or object
505  *
506  * RETURN:      Status. AE_OK if repair was successful.
507  *
508  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
509  *
510  ******************************************************************************/
511 
512 ACPI_STATUS
513 AcpiNsRepairNullElement (
514     ACPI_EVALUATE_INFO      *Info,
515     UINT32                  ExpectedBtypes,
516     UINT32                  PackageIndex,
517     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
518 {
519     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
520     ACPI_OPERAND_OBJECT     *NewObject;
521 
522 
523     ACPI_FUNCTION_NAME (NsRepairNullElement);
524 
525 
526     /* No repair needed if return object is non-NULL */
527 
528     if (ReturnObject)
529     {
530         return (AE_OK);
531     }
532 
533     /*
534      * Attempt to repair a NULL element of a Package object. This applies to
535      * predefined names that return a fixed-length package and each element
536      * is required. It does not apply to variable-length packages where NULL
537      * elements are allowed, especially at the end of the package.
538      */
539     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
540     {
541         /* Need an Integer - create a zero-value integer */
542 
543         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
544     }
545     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
546     {
547         /* Need a String - create a NULL string */
548 
549         NewObject = AcpiUtCreateStringObject (0);
550     }
551     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
552     {
553         /* Need a Buffer - create a zero-length buffer */
554 
555         NewObject = AcpiUtCreateBufferObject (0);
556     }
557     else
558     {
559         /* Error for all other expected types */
560 
561         return (AE_AML_OPERAND_TYPE);
562     }
563 
564     if (!NewObject)
565     {
566         return (AE_NO_MEMORY);
567     }
568 
569     /* Set the reference count according to the parent Package object */
570 
571     NewObject->Common.ReferenceCount =
572         Info->ParentPackage->Common.ReferenceCount;
573 
574     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
575         "%s: Converted NULL package element to expected %s at index %u\n",
576         Info->FullPathname, AcpiUtGetObjectTypeName (NewObject),
577         PackageIndex));
578 
579     *ReturnObjectPtr = NewObject;
580     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
581     return (AE_OK);
582 }
583 
584 
585 /******************************************************************************
586  *
587  * FUNCTION:    AcpiNsRemoveNullElements
588  *
589  * PARAMETERS:  Info                - Method execution information block
590  *              PackageType         - An AcpiReturnPackageTypes value
591  *              ObjDesc             - A Package object
592  *
593  * RETURN:      None.
594  *
595  * DESCRIPTION: Remove all NULL package elements from packages that contain
596  *              a variable number of subpackages. For these types of
597  *              packages, NULL elements can be safely removed.
598  *
599  *****************************************************************************/
600 
601 void
602 AcpiNsRemoveNullElements (
603     ACPI_EVALUATE_INFO      *Info,
604     UINT8                   PackageType,
605     ACPI_OPERAND_OBJECT     *ObjDesc)
606 {
607     ACPI_OPERAND_OBJECT     **Source;
608     ACPI_OPERAND_OBJECT     **Dest;
609     UINT32                  Count;
610     UINT32                  NewCount;
611     UINT32                  i;
612 
613 
614     ACPI_FUNCTION_NAME (NsRemoveNullElements);
615 
616 
617     /*
618      * We can safely remove all NULL elements from these package types:
619      * PTYPE1_VAR packages contain a variable number of simple data types.
620      * PTYPE2 packages contain a variable number of subpackages.
621      */
622     switch (PackageType)
623     {
624     case ACPI_PTYPE1_VAR:
625     case ACPI_PTYPE2:
626     case ACPI_PTYPE2_COUNT:
627     case ACPI_PTYPE2_PKG_COUNT:
628     case ACPI_PTYPE2_FIXED:
629     case ACPI_PTYPE2_MIN:
630     case ACPI_PTYPE2_REV_FIXED:
631     case ACPI_PTYPE2_FIX_VAR:
632         break;
633 
634     default:
635     case ACPI_PTYPE2_VAR_VAR:
636     case ACPI_PTYPE1_FIXED:
637     case ACPI_PTYPE1_OPTION:
638         return;
639     }
640 
641     Count = ObjDesc->Package.Count;
642     NewCount = Count;
643 
644     Source = ObjDesc->Package.Elements;
645     Dest = Source;
646 
647     /* Examine all elements of the package object, remove nulls */
648 
649     for (i = 0; i < Count; i++)
650     {
651         if (!*Source)
652         {
653             NewCount--;
654         }
655         else
656         {
657             *Dest = *Source;
658             Dest++;
659         }
660 
661         Source++;
662     }
663 
664     /* Update parent package if any null elements were removed */
665 
666     if (NewCount < Count)
667     {
668         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
669             "%s: Found and removed %u NULL elements\n",
670             Info->FullPathname, (Count - NewCount)));
671 
672         /* NULL terminate list and update the package count */
673 
674         *Dest = NULL;
675         ObjDesc->Package.Count = NewCount;
676     }
677 }
678 
679 
680 /*******************************************************************************
681  *
682  * FUNCTION:    AcpiNsWrapWithPackage
683  *
684  * PARAMETERS:  Info                - Method execution information block
685  *              OriginalObject      - Pointer to the object to repair.
686  *              ObjDescPtr          - The new package object is returned here
687  *
688  * RETURN:      Status, new object in *ObjDescPtr
689  *
690  * DESCRIPTION: Repair a common problem with objects that are defined to
691  *              return a variable-length Package of sub-objects. If there is
692  *              only one sub-object, some BIOS code mistakenly simply declares
693  *              the single object instead of a Package with one sub-object.
694  *              This function attempts to repair this error by wrapping a
695  *              Package object around the original object, creating the
696  *              correct and expected Package with one sub-object.
697  *
698  *              Names that can be repaired in this manner include:
699  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
700  *              _BCL, _DOD, _FIX, _Sx
701  *
702  ******************************************************************************/
703 
704 ACPI_STATUS
705 AcpiNsWrapWithPackage (
706     ACPI_EVALUATE_INFO      *Info,
707     ACPI_OPERAND_OBJECT     *OriginalObject,
708     ACPI_OPERAND_OBJECT     **ObjDescPtr)
709 {
710     ACPI_OPERAND_OBJECT     *PkgObjDesc;
711 
712 
713     ACPI_FUNCTION_NAME (NsWrapWithPackage);
714 
715 
716     /*
717      * Create the new outer package and populate it. The new
718      * package will have a single element, the lone sub-object.
719      */
720     PkgObjDesc = AcpiUtCreatePackageObject (1);
721     if (!PkgObjDesc)
722     {
723         return (AE_NO_MEMORY);
724     }
725 
726     PkgObjDesc->Package.Elements[0] = OriginalObject;
727 
728     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
729         "%s: Wrapped %s with expected Package object\n",
730         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
731 
732     /* Return the new object in the object pointer */
733 
734     *ObjDescPtr = PkgObjDesc;
735     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
736     return (AE_OK);
737 }
738