xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/namespace/nsrepair.c (revision 39d6c466d8217dcb3004074f29c27c60f0fa1ac1)
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 - 2015, 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 #include "acpi.h"
117 #include "accommon.h"
118 #include "acnamesp.h"
119 #include "acinterp.h"
120 #include "acpredef.h"
121 #include "amlresrc.h"
122 
123 #define _COMPONENT          ACPI_NAMESPACE
124         ACPI_MODULE_NAME    ("nsrepair")
125 
126 
127 /*******************************************************************************
128  *
129  * This module attempts to repair or convert objects returned by the
130  * predefined methods to an object type that is expected, as per the ACPI
131  * specification. The need for this code is dictated by the many machines that
132  * return incorrect types for the standard predefined methods. Performing these
133  * conversions here, in one place, eliminates the need for individual ACPI
134  * device drivers to do the same. Note: Most of these conversions are different
135  * than the internal object conversion routines used for implicit object
136  * conversion.
137  *
138  * The following conversions can be performed as necessary:
139  *
140  * Integer -> String
141  * Integer -> Buffer
142  * String  -> Integer
143  * String  -> Buffer
144  * Buffer  -> Integer
145  * Buffer  -> String
146  * Buffer  -> Package of Integers
147  * Package -> Package of one Package
148  *
149  * Additional conversions that are available:
150  *  Convert a null return or zero return value to an EndTag descriptor
151  *  Convert an ASCII string to a Unicode buffer
152  *
153  * An incorrect standalone object is wrapped with required outer package
154  *
155  * Additional possible repairs:
156  * Required package elements that are NULL replaced by Integer/String/Buffer
157  *
158  ******************************************************************************/
159 
160 
161 /* Local prototypes */
162 
163 static const ACPI_SIMPLE_REPAIR_INFO *
164 AcpiNsMatchSimpleRepair (
165     ACPI_NAMESPACE_NODE     *Node,
166     UINT32                  ReturnBtype,
167     UINT32                  PackageIndex);
168 
169 
170 /*
171  * Special but simple repairs for some names.
172  *
173  * 2nd argument: Unexpected types that can be repaired
174  */
175 static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
176 {
177     /* Resource descriptor conversions */
178 
179     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
180                 ACPI_NOT_PACKAGE_ELEMENT,
181                 AcpiNsConvertToResource },
182     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
183                 ACPI_NOT_PACKAGE_ELEMENT,
184                 AcpiNsConvertToResource },
185     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
186                 ACPI_NOT_PACKAGE_ELEMENT,
187                 AcpiNsConvertToResource },
188 
189     /* Unicode conversions */
190 
191     { "_MLS", ACPI_RTYPE_STRING, 1,
192                 AcpiNsConvertToUnicode },
193     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
194                 ACPI_NOT_PACKAGE_ELEMENT,
195                 AcpiNsConvertToUnicode },
196     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
197 };
198 
199 
200 /*******************************************************************************
201  *
202  * FUNCTION:    AcpiNsSimpleRepair
203  *
204  * PARAMETERS:  Info                - Method execution information block
205  *              ExpectedBtypes      - Object types expected
206  *              PackageIndex        - Index of object within parent package (if
207  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
208  *                                    otherwise)
209  *              ReturnObjectPtr     - Pointer to the object returned from the
210  *                                    evaluation of a method or object
211  *
212  * RETURN:      Status. AE_OK if repair was successful.
213  *
214  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
215  *              not expected.
216  *
217  ******************************************************************************/
218 
219 ACPI_STATUS
220 AcpiNsSimpleRepair (
221     ACPI_EVALUATE_INFO      *Info,
222     UINT32                  ExpectedBtypes,
223     UINT32                  PackageIndex,
224     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
225 {
226     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
227     ACPI_OPERAND_OBJECT     *NewObject = NULL;
228     ACPI_STATUS             Status;
229     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
230 
231 
232     ACPI_FUNCTION_NAME (NsSimpleRepair);
233 
234 
235     /*
236      * Special repairs for certain names that are in the repair table.
237      * Check if this name is in the list of repairable names.
238      */
239     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
240         Info->ReturnBtype, PackageIndex);
241     if (Predefined)
242     {
243         if (!ReturnObject)
244         {
245             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
246                 ACPI_WARN_ALWAYS, "Missing expected return value"));
247         }
248 
249         Status = Predefined->ObjectConverter (ReturnObject, &NewObject);
250         if (ACPI_FAILURE (Status))
251         {
252             /* A fatal error occurred during a conversion */
253 
254             ACPI_EXCEPTION ((AE_INFO, Status,
255                 "During return object analysis"));
256             return (Status);
257         }
258         if (NewObject)
259         {
260             goto ObjectRepaired;
261         }
262     }
263 
264     /*
265      * Do not perform simple object repair unless the return type is not
266      * expected.
267      */
268     if (Info->ReturnBtype & ExpectedBtypes)
269     {
270         return (AE_OK);
271     }
272 
273     /*
274      * At this point, we know that the type of the returned object was not
275      * one of the expected types for this predefined name. Attempt to
276      * repair the object by converting it to one of the expected object
277      * types for this predefined name.
278      */
279 
280     /*
281      * If there is no return value, check if we require a return value for
282      * this predefined name. Either one return value is expected, or none,
283      * for both methods and other objects.
284      *
285      * Try to fix if there was no return object. Warning if failed to fix.
286      */
287     if (!ReturnObject)
288     {
289         if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
290         {
291             if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
292             {
293                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
294                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
295 
296                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
297                             PackageIndex, ReturnObjectPtr);
298                 if (ACPI_SUCCESS (Status))
299                 {
300                     return (AE_OK); /* Repair was successful */
301                 }
302             }
303             else
304             {
305                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
306                     ACPI_WARN_ALWAYS, "Missing expected return value"));
307             }
308 
309             return (AE_AML_NO_RETURN_VALUE);
310         }
311     }
312 
313     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
314     {
315         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
316         if (ACPI_SUCCESS (Status))
317         {
318             goto ObjectRepaired;
319         }
320     }
321     if (ExpectedBtypes & ACPI_RTYPE_STRING)
322     {
323         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
324         if (ACPI_SUCCESS (Status))
325         {
326             goto ObjectRepaired;
327         }
328     }
329     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
330     {
331         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
332         if (ACPI_SUCCESS (Status))
333         {
334             goto ObjectRepaired;
335         }
336     }
337     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
338     {
339         /*
340          * A package is expected. We will wrap the existing object with a
341          * new package object. It is often the case that if a variable-length
342          * package is required, but there is only a single object needed, the
343          * BIOS will return that object instead of wrapping it with a Package
344          * object. Note: after the wrapping, the package will be validated
345          * for correct contents (expected object type or types).
346          */
347         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
348         if (ACPI_SUCCESS (Status))
349         {
350             /*
351              * The original object just had its reference count
352              * incremented for being inserted into the new package.
353              */
354             *ReturnObjectPtr = NewObject;       /* New Package object */
355             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
356             return (AE_OK);
357         }
358     }
359 
360     /* We cannot repair this object */
361 
362     return (AE_AML_OPERAND_TYPE);
363 
364 
365 ObjectRepaired:
366 
367     /* Object was successfully repaired */
368 
369     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
370     {
371         /*
372          * The original object is a package element. We need to
373          * decrement the reference count of the original object,
374          * for removing it from the package.
375          *
376          * However, if the original object was just wrapped with a
377          * package object as part of the repair, we don't need to
378          * change the reference count.
379          */
380         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
381         {
382             NewObject->Common.ReferenceCount =
383                 ReturnObject->Common.ReferenceCount;
384 
385             if (ReturnObject->Common.ReferenceCount > 1)
386             {
387                 ReturnObject->Common.ReferenceCount--;
388             }
389         }
390 
391         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
392             "%s: Converted %s to expected %s at Package index %u\n",
393             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
394             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
395     }
396     else
397     {
398         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
399             "%s: Converted %s to expected %s\n",
400             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
401             AcpiUtGetObjectTypeName (NewObject)));
402     }
403 
404     /* Delete old object, install the new return object */
405 
406     AcpiUtRemoveReference (ReturnObject);
407     *ReturnObjectPtr = NewObject;
408     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
409     return (AE_OK);
410 }
411 
412 
413 /******************************************************************************
414  *
415  * FUNCTION:    AcpiNsMatchSimpleRepair
416  *
417  * PARAMETERS:  Node                - Namespace node for the method/object
418  *              ReturnBtype         - Object type that was returned
419  *              PackageIndex        - Index of object within parent package (if
420  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
421  *                                    otherwise)
422  *
423  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
424  *
425  * DESCRIPTION: Check an object name against the repairable object list.
426  *
427  *****************************************************************************/
428 
429 static const ACPI_SIMPLE_REPAIR_INFO *
430 AcpiNsMatchSimpleRepair (
431     ACPI_NAMESPACE_NODE     *Node,
432     UINT32                  ReturnBtype,
433     UINT32                  PackageIndex)
434 {
435     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
436 
437 
438     /* Search info table for a repairable predefined method/object name */
439 
440     ThisName = AcpiObjectRepairInfo;
441     while (ThisName->ObjectConverter)
442     {
443         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
444         {
445             /* Check if we can actually repair this name/type combination */
446 
447             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
448                 (PackageIndex == ThisName->PackageIndex))
449             {
450                 return (ThisName);
451             }
452 
453             return (NULL);
454         }
455         ThisName++;
456     }
457 
458     return (NULL); /* Name was not found in the repair table */
459 }
460 
461 
462 /*******************************************************************************
463  *
464  * FUNCTION:    AcpiNsRepairNullElement
465  *
466  * PARAMETERS:  Info                - Method execution information block
467  *              ExpectedBtypes      - Object types expected
468  *              PackageIndex        - Index of object within parent package (if
469  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
470  *                                    otherwise)
471  *              ReturnObjectPtr     - Pointer to the object returned from the
472  *                                    evaluation of a method or object
473  *
474  * RETURN:      Status. AE_OK if repair was successful.
475  *
476  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
477  *
478  ******************************************************************************/
479 
480 ACPI_STATUS
481 AcpiNsRepairNullElement (
482     ACPI_EVALUATE_INFO      *Info,
483     UINT32                  ExpectedBtypes,
484     UINT32                  PackageIndex,
485     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
486 {
487     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
488     ACPI_OPERAND_OBJECT     *NewObject;
489 
490 
491     ACPI_FUNCTION_NAME (NsRepairNullElement);
492 
493 
494     /* No repair needed if return object is non-NULL */
495 
496     if (ReturnObject)
497     {
498         return (AE_OK);
499     }
500 
501     /*
502      * Attempt to repair a NULL element of a Package object. This applies to
503      * predefined names that return a fixed-length package and each element
504      * is required. It does not apply to variable-length packages where NULL
505      * elements are allowed, especially at the end of the package.
506      */
507     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
508     {
509         /* Need an Integer - create a zero-value integer */
510 
511         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
512     }
513     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
514     {
515         /* Need a String - create a NULL string */
516 
517         NewObject = AcpiUtCreateStringObject (0);
518     }
519     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
520     {
521         /* Need a Buffer - create a zero-length buffer */
522 
523         NewObject = AcpiUtCreateBufferObject (0);
524     }
525     else
526     {
527         /* Error for all other expected types */
528 
529         return (AE_AML_OPERAND_TYPE);
530     }
531 
532     if (!NewObject)
533     {
534         return (AE_NO_MEMORY);
535     }
536 
537     /* Set the reference count according to the parent Package object */
538 
539     NewObject->Common.ReferenceCount = Info->ParentPackage->Common.ReferenceCount;
540 
541     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
542         "%s: Converted NULL package element to expected %s at index %u\n",
543          Info->FullPathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
544 
545     *ReturnObjectPtr = NewObject;
546     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
547     return (AE_OK);
548 }
549 
550 
551 /******************************************************************************
552  *
553  * FUNCTION:    AcpiNsRemoveNullElements
554  *
555  * PARAMETERS:  Info                - Method execution information block
556  *              PackageType         - An AcpiReturnPackageTypes value
557  *              ObjDesc             - A Package object
558  *
559  * RETURN:      None.
560  *
561  * DESCRIPTION: Remove all NULL package elements from packages that contain
562  *              a variable number of subpackages. For these types of
563  *              packages, NULL elements can be safely removed.
564  *
565  *****************************************************************************/
566 
567 void
568 AcpiNsRemoveNullElements (
569     ACPI_EVALUATE_INFO      *Info,
570     UINT8                   PackageType,
571     ACPI_OPERAND_OBJECT     *ObjDesc)
572 {
573     ACPI_OPERAND_OBJECT     **Source;
574     ACPI_OPERAND_OBJECT     **Dest;
575     UINT32                  Count;
576     UINT32                  NewCount;
577     UINT32                  i;
578 
579 
580     ACPI_FUNCTION_NAME (NsRemoveNullElements);
581 
582 
583     /*
584      * We can safely remove all NULL elements from these package types:
585      * PTYPE1_VAR packages contain a variable number of simple data types.
586      * PTYPE2 packages contain a variable number of subpackages.
587      */
588     switch (PackageType)
589     {
590     case ACPI_PTYPE1_VAR:
591     case ACPI_PTYPE2:
592     case ACPI_PTYPE2_COUNT:
593     case ACPI_PTYPE2_PKG_COUNT:
594     case ACPI_PTYPE2_FIXED:
595     case ACPI_PTYPE2_MIN:
596     case ACPI_PTYPE2_REV_FIXED:
597     case ACPI_PTYPE2_FIX_VAR:
598         break;
599 
600     default:
601     case ACPI_PTYPE2_VAR_VAR:
602     case ACPI_PTYPE1_FIXED:
603     case ACPI_PTYPE1_OPTION:
604         return;
605     }
606 
607     Count = ObjDesc->Package.Count;
608     NewCount = Count;
609 
610     Source = ObjDesc->Package.Elements;
611     Dest = Source;
612 
613     /* Examine all elements of the package object, remove nulls */
614 
615     for (i = 0; i < Count; i++)
616     {
617         if (!*Source)
618         {
619             NewCount--;
620         }
621         else
622         {
623             *Dest = *Source;
624             Dest++;
625         }
626         Source++;
627     }
628 
629     /* Update parent package if any null elements were removed */
630 
631     if (NewCount < Count)
632     {
633         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
634             "%s: Found and removed %u NULL elements\n",
635             Info->FullPathname, (Count - NewCount)));
636 
637         /* NULL terminate list and update the package count */
638 
639         *Dest = NULL;
640         ObjDesc->Package.Count = NewCount;
641     }
642 }
643 
644 
645 /*******************************************************************************
646  *
647  * FUNCTION:    AcpiNsWrapWithPackage
648  *
649  * PARAMETERS:  Info                - Method execution information block
650  *              OriginalObject      - Pointer to the object to repair.
651  *              ObjDescPtr          - The new package object is returned here
652  *
653  * RETURN:      Status, new object in *ObjDescPtr
654  *
655  * DESCRIPTION: Repair a common problem with objects that are defined to
656  *              return a variable-length Package of sub-objects. If there is
657  *              only one sub-object, some BIOS code mistakenly simply declares
658  *              the single object instead of a Package with one sub-object.
659  *              This function attempts to repair this error by wrapping a
660  *              Package object around the original object, creating the
661  *              correct and expected Package with one sub-object.
662  *
663  *              Names that can be repaired in this manner include:
664  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
665  *              _BCL, _DOD, _FIX, _Sx
666  *
667  ******************************************************************************/
668 
669 ACPI_STATUS
670 AcpiNsWrapWithPackage (
671     ACPI_EVALUATE_INFO      *Info,
672     ACPI_OPERAND_OBJECT     *OriginalObject,
673     ACPI_OPERAND_OBJECT     **ObjDescPtr)
674 {
675     ACPI_OPERAND_OBJECT     *PkgObjDesc;
676 
677 
678     ACPI_FUNCTION_NAME (NsWrapWithPackage);
679 
680 
681     /*
682      * Create the new outer package and populate it. The new package will
683      * have a single element, the lone sub-object.
684      */
685     PkgObjDesc = AcpiUtCreatePackageObject (1);
686     if (!PkgObjDesc)
687     {
688         return (AE_NO_MEMORY);
689     }
690 
691     PkgObjDesc->Package.Elements[0] = OriginalObject;
692 
693     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
694         "%s: Wrapped %s with expected Package object\n",
695         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
696 
697     /* Return the new object in the object pointer */
698 
699     *ObjDescPtr = PkgObjDesc;
700     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
701     return (AE_OK);
702 }
703