157190917SDana Myers /******************************************************************************
257190917SDana Myers  *
357190917SDana Myers  * Module Name: nsrepair - Repair for objects returned by predefined methods
457190917SDana Myers  *
557190917SDana Myers  *****************************************************************************/
657190917SDana Myers 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
1257190917SDana Myers  * All rights reserved.
1357190917SDana Myers  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
13357190917SDana Myers  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
15157190917SDana Myers 
15257190917SDana Myers #include "acpi.h"
15357190917SDana Myers #include "accommon.h"
15457190917SDana Myers #include "acnamesp.h"
15557190917SDana Myers #include "acinterp.h"
15657190917SDana Myers #include "acpredef.h"
1577b1019a6SJerry Jelinek #include "amlresrc.h"
15857190917SDana Myers 
15957190917SDana Myers #define _COMPONENT          ACPI_NAMESPACE
16057190917SDana Myers         ACPI_MODULE_NAME    ("nsrepair")
16157190917SDana Myers 
16257190917SDana Myers 
16326f3cdf0SGordon Ross /*******************************************************************************
16426f3cdf0SGordon Ross  *
16526f3cdf0SGordon Ross  * This module attempts to repair or convert objects returned by the
16626f3cdf0SGordon Ross  * predefined methods to an object type that is expected, as per the ACPI
16726f3cdf0SGordon Ross  * specification. The need for this code is dictated by the many machines that
16826f3cdf0SGordon Ross  * return incorrect types for the standard predefined methods. Performing these
16926f3cdf0SGordon Ross  * conversions here, in one place, eliminates the need for individual ACPI
17026f3cdf0SGordon Ross  * device drivers to do the same. Note: Most of these conversions are different
17126f3cdf0SGordon Ross  * than the internal object conversion routines used for implicit object
17226f3cdf0SGordon Ross  * conversion.
17326f3cdf0SGordon Ross  *
17426f3cdf0SGordon Ross  * The following conversions can be performed as necessary:
17526f3cdf0SGordon Ross  *
17626f3cdf0SGordon Ross  * Integer -> String
17726f3cdf0SGordon Ross  * Integer -> Buffer
17826f3cdf0SGordon Ross  * String  -> Integer
17926f3cdf0SGordon Ross  * String  -> Buffer
18026f3cdf0SGordon Ross  * Buffer  -> Integer
18126f3cdf0SGordon Ross  * Buffer  -> String
18226f3cdf0SGordon Ross  * Buffer  -> Package of Integers
18326f3cdf0SGordon Ross  * Package -> Package of one Package
18426f3cdf0SGordon Ross  *
1857b1019a6SJerry Jelinek  * Additional conversions that are available:
1867b1019a6SJerry Jelinek  *  Convert a null return or zero return value to an EndTag descriptor
1877b1019a6SJerry Jelinek  *  Convert an ASCII string to a Unicode buffer
18826f3cdf0SGordon Ross  *
1897b1019a6SJerry Jelinek  * An incorrect standalone object is wrapped with required outer package
1907b1019a6SJerry Jelinek  *
1917b1019a6SJerry Jelinek  * Additional possible repairs:
19226f3cdf0SGordon Ross  * Required package elements that are NULL replaced by Integer/String/Buffer
19326f3cdf0SGordon Ross  *
19426f3cdf0SGordon Ross  ******************************************************************************/
19526f3cdf0SGordon Ross 
19626f3cdf0SGordon Ross 
19726f3cdf0SGordon Ross /* Local prototypes */
19826f3cdf0SGordon Ross 
1997b1019a6SJerry Jelinek static const ACPI_SIMPLE_REPAIR_INFO *
2007b1019a6SJerry Jelinek AcpiNsMatchSimpleRepair (
2017b1019a6SJerry Jelinek     ACPI_NAMESPACE_NODE     *Node,
2027b1019a6SJerry Jelinek     UINT32                  ReturnBtype,
2037b1019a6SJerry Jelinek     UINT32                  PackageIndex);
20426f3cdf0SGordon Ross 
20526f3cdf0SGordon Ross 
2067b1019a6SJerry Jelinek /*
2077b1019a6SJerry Jelinek  * Special but simple repairs for some names.
2087b1019a6SJerry Jelinek  *
2097b1019a6SJerry Jelinek  * 2nd argument: Unexpected types that can be repaired
2107b1019a6SJerry Jelinek  */
2117b1019a6SJerry Jelinek static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
2127b1019a6SJerry Jelinek {
2137b1019a6SJerry Jelinek     /* Resource descriptor conversions */
21426f3cdf0SGordon Ross 
2157b1019a6SJerry Jelinek     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
2167b1019a6SJerry Jelinek                 ACPI_NOT_PACKAGE_ELEMENT,
2177b1019a6SJerry Jelinek                 AcpiNsConvertToResource },
2187b1019a6SJerry Jelinek     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
2197b1019a6SJerry Jelinek                 ACPI_NOT_PACKAGE_ELEMENT,
2207b1019a6SJerry Jelinek                 AcpiNsConvertToResource },
2217b1019a6SJerry Jelinek     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
2227b1019a6SJerry Jelinek                 ACPI_NOT_PACKAGE_ELEMENT,
2237b1019a6SJerry Jelinek                 AcpiNsConvertToResource },
2247b1019a6SJerry Jelinek 
2257b1019a6SJerry Jelinek     /* Object reference conversions */
2267b1019a6SJerry Jelinek 
2277b1019a6SJerry Jelinek     { "_DEP", ACPI_RTYPE_STRING, ACPI_ALL_PACKAGE_ELEMENTS,
2287b1019a6SJerry Jelinek                 AcpiNsConvertToReference },
2297b1019a6SJerry Jelinek 
2307b1019a6SJerry Jelinek     /* Unicode conversions */
2317b1019a6SJerry Jelinek 
2327b1019a6SJerry Jelinek     { "_MLS", ACPI_RTYPE_STRING, 1,
2337b1019a6SJerry Jelinek                 AcpiNsConvertToUnicode },
2347b1019a6SJerry Jelinek     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
2357b1019a6SJerry Jelinek                 ACPI_NOT_PACKAGE_ELEMENT,
2367b1019a6SJerry Jelinek                 AcpiNsConvertToUnicode },
2377b1019a6SJerry Jelinek     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
2387b1019a6SJerry Jelinek };
23926f3cdf0SGordon Ross 
24026f3cdf0SGordon Ross 
24157190917SDana Myers /*******************************************************************************
24257190917SDana Myers  *
2437b1019a6SJerry Jelinek  * FUNCTION:    AcpiNsSimpleRepair
24457190917SDana Myers  *
2457b1019a6SJerry Jelinek  * PARAMETERS:  Info                - Method execution information block
24657190917SDana Myers  *              ExpectedBtypes      - Object types expected
24757190917SDana Myers  *              PackageIndex        - Index of object within parent package (if
24857190917SDana Myers  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
24957190917SDana Myers  *                                    otherwise)
25057190917SDana Myers  *              ReturnObjectPtr     - Pointer to the object returned from the
25157190917SDana Myers  *                                    evaluation of a method or object
25257190917SDana Myers  *
25357190917SDana Myers  * RETURN:      Status. AE_OK if repair was successful.
25457190917SDana Myers  *
25557190917SDana Myers  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
25657190917SDana Myers  *              not expected.
25757190917SDana Myers  *
25857190917SDana Myers  ******************************************************************************/
25957190917SDana Myers 
26057190917SDana Myers ACPI_STATUS
AcpiNsSimpleRepair(ACPI_EVALUATE_INFO * Info,UINT32 ExpectedBtypes,UINT32 PackageIndex,ACPI_OPERAND_OBJECT ** ReturnObjectPtr)2617b1019a6SJerry Jelinek AcpiNsSimpleRepair (
2627b1019a6SJerry Jelinek     ACPI_EVALUATE_INFO      *Info,
26357190917SDana Myers     UINT32                  ExpectedBtypes,
26457190917SDana Myers     UINT32                  PackageIndex,
26557190917SDana Myers     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
26657190917SDana Myers {
26757190917SDana Myers     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
2687b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *NewObject = NULL;
26957190917SDana Myers     ACPI_STATUS             Status;
2707b1019a6SJerry Jelinek     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
27157190917SDana Myers 
27257190917SDana Myers 
2737b1019a6SJerry Jelinek     ACPI_FUNCTION_NAME (NsSimpleRepair);
27426f3cdf0SGordon Ross 
27526f3cdf0SGordon Ross 
2767b1019a6SJerry Jelinek     /*
2777b1019a6SJerry Jelinek      * Special repairs for certain names that are in the repair table.
2787b1019a6SJerry Jelinek      * Check if this name is in the list of repairable names.
2797b1019a6SJerry Jelinek      */
2807b1019a6SJerry Jelinek     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
2817b1019a6SJerry Jelinek         Info->ReturnBtype, PackageIndex);
2827b1019a6SJerry Jelinek     if (Predefined)
2837b1019a6SJerry Jelinek     {
2847b1019a6SJerry Jelinek         if (!ReturnObject)
2857b1019a6SJerry Jelinek         {
2867b1019a6SJerry Jelinek             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
2877b1019a6SJerry Jelinek                 ACPI_WARN_ALWAYS, "Missing expected return value"));
2887b1019a6SJerry Jelinek         }
2897b1019a6SJerry Jelinek 
2907b1019a6SJerry Jelinek         Status = Predefined->ObjectConverter (Info->Node, ReturnObject,
2917b1019a6SJerry Jelinek             &NewObject);
2927b1019a6SJerry Jelinek         if (ACPI_FAILURE (Status))
2937b1019a6SJerry Jelinek         {
2947b1019a6SJerry Jelinek             /* A fatal error occurred during a conversion */
2957b1019a6SJerry Jelinek 
2967b1019a6SJerry Jelinek             ACPI_EXCEPTION ((AE_INFO, Status,
2977b1019a6SJerry Jelinek                 "During return object analysis"));
2987b1019a6SJerry Jelinek             return (Status);
2997b1019a6SJerry Jelinek         }
3007b1019a6SJerry Jelinek         if (NewObject)
3017b1019a6SJerry Jelinek         {
3027b1019a6SJerry Jelinek             goto ObjectRepaired;
3037b1019a6SJerry Jelinek         }
3047b1019a6SJerry Jelinek     }
3057b1019a6SJerry Jelinek 
3067b1019a6SJerry Jelinek     /*
3077b1019a6SJerry Jelinek      * Do not perform simple object repair unless the return type is not
3087b1019a6SJerry Jelinek      * expected.
3097b1019a6SJerry Jelinek      */
3107b1019a6SJerry Jelinek     if (Info->ReturnBtype & ExpectedBtypes)
3117b1019a6SJerry Jelinek     {
3127b1019a6SJerry Jelinek         return (AE_OK);
3137b1019a6SJerry Jelinek     }
3147b1019a6SJerry Jelinek 
31557190917SDana Myers     /*
31657190917SDana Myers      * At this point, we know that the type of the returned object was not
31757190917SDana Myers      * one of the expected types for this predefined name. Attempt to
31826f3cdf0SGordon Ross      * repair the object by converting it to one of the expected object
31926f3cdf0SGordon Ross      * types for this predefined name.
32026f3cdf0SGordon Ross      */
3217b1019a6SJerry Jelinek 
3227b1019a6SJerry Jelinek     /*
3237b1019a6SJerry Jelinek      * If there is no return value, check if we require a return value for
3247b1019a6SJerry Jelinek      * this predefined name. Either one return value is expected, or none,
3257b1019a6SJerry Jelinek      * for both methods and other objects.
3267b1019a6SJerry Jelinek      *
3277b1019a6SJerry Jelinek      * Try to fix if there was no return object. Warning if failed to fix.
3287b1019a6SJerry Jelinek      */
3297b1019a6SJerry Jelinek     if (!ReturnObject)
3307b1019a6SJerry Jelinek     {
3317b1019a6SJerry Jelinek         if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
3327b1019a6SJerry Jelinek         {
3337b1019a6SJerry Jelinek             if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
3347b1019a6SJerry Jelinek             {
3357b1019a6SJerry Jelinek                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
3367b1019a6SJerry Jelinek                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
3377b1019a6SJerry Jelinek 
3387b1019a6SJerry Jelinek                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
3397b1019a6SJerry Jelinek                     PackageIndex, ReturnObjectPtr);
3407b1019a6SJerry Jelinek                 if (ACPI_SUCCESS (Status))
3417b1019a6SJerry Jelinek                 {
3427b1019a6SJerry Jelinek                     return (AE_OK); /* Repair was successful */
3437b1019a6SJerry Jelinek                 }
3447b1019a6SJerry Jelinek             }
3457b1019a6SJerry Jelinek             else
3467b1019a6SJerry Jelinek             {
3477b1019a6SJerry Jelinek                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
3487b1019a6SJerry Jelinek                     ACPI_WARN_ALWAYS, "Missing expected return value"));
3497b1019a6SJerry Jelinek             }
3507b1019a6SJerry Jelinek 
3517b1019a6SJerry Jelinek             return (AE_AML_NO_RETURN_VALUE);
3527b1019a6SJerry Jelinek         }
3537b1019a6SJerry Jelinek     }
3547b1019a6SJerry Jelinek 
35526f3cdf0SGordon Ross     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
35626f3cdf0SGordon Ross     {
35726f3cdf0SGordon Ross         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
35826f3cdf0SGordon Ross         if (ACPI_SUCCESS (Status))
35926f3cdf0SGordon Ross         {
36026f3cdf0SGordon Ross             goto ObjectRepaired;
36126f3cdf0SGordon Ross         }
36226f3cdf0SGordon Ross     }
36326f3cdf0SGordon Ross     if (ExpectedBtypes & ACPI_RTYPE_STRING)
36426f3cdf0SGordon Ross     {
36526f3cdf0SGordon Ross         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
36626f3cdf0SGordon Ross         if (ACPI_SUCCESS (Status))
36726f3cdf0SGordon Ross         {
36826f3cdf0SGordon Ross             goto ObjectRepaired;
36926f3cdf0SGordon Ross         }
37026f3cdf0SGordon Ross     }
37126f3cdf0SGordon Ross     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
37226f3cdf0SGordon Ross     {
37326f3cdf0SGordon Ross         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
37426f3cdf0SGordon Ross         if (ACPI_SUCCESS (Status))
37526f3cdf0SGordon Ross         {
37626f3cdf0SGordon Ross             goto ObjectRepaired;
37726f3cdf0SGordon Ross         }
37826f3cdf0SGordon Ross     }
37926f3cdf0SGordon Ross     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
38026f3cdf0SGordon Ross     {
3817b1019a6SJerry Jelinek         /*
3827b1019a6SJerry Jelinek          * A package is expected. We will wrap the existing object with a
3837b1019a6SJerry Jelinek          * new package object. It is often the case that if a variable-length
3847b1019a6SJerry Jelinek          * package is required, but there is only a single object needed, the
3857b1019a6SJerry Jelinek          * BIOS will return that object instead of wrapping it with a Package
3867b1019a6SJerry Jelinek          * object. Note: after the wrapping, the package will be validated
3877b1019a6SJerry Jelinek          * for correct contents (expected object type or types).
3887b1019a6SJerry Jelinek          */
3897b1019a6SJerry Jelinek         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
39026f3cdf0SGordon Ross         if (ACPI_SUCCESS (Status))
39126f3cdf0SGordon Ross         {
3927b1019a6SJerry Jelinek             /*
3937b1019a6SJerry Jelinek              * The original object just had its reference count
3947b1019a6SJerry Jelinek              * incremented for being inserted into the new package.
3957b1019a6SJerry Jelinek              */
3967b1019a6SJerry Jelinek             *ReturnObjectPtr = NewObject;       /* New Package object */
3977b1019a6SJerry Jelinek             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
3987b1019a6SJerry Jelinek             return (AE_OK);
39926f3cdf0SGordon Ross         }
40026f3cdf0SGordon Ross     }
40126f3cdf0SGordon Ross 
40226f3cdf0SGordon Ross     /* We cannot repair this object */
40326f3cdf0SGordon Ross 
40426f3cdf0SGordon Ross     return (AE_AML_OPERAND_TYPE);
40526f3cdf0SGordon Ross 
40626f3cdf0SGordon Ross 
40726f3cdf0SGordon Ross ObjectRepaired:
40826f3cdf0SGordon Ross 
40926f3cdf0SGordon Ross     /* Object was successfully repaired */
41026f3cdf0SGordon Ross 
41126f3cdf0SGordon Ross     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
41226f3cdf0SGordon Ross     {
413*35786f68SRobert Mustacchi         /* Update reference count of new object */
414*35786f68SRobert Mustacchi 
4157b1019a6SJerry Jelinek         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
41626f3cdf0SGordon Ross         {
4177b1019a6SJerry Jelinek             NewObject->Common.ReferenceCount =
4187b1019a6SJerry Jelinek                 ReturnObject->Common.ReferenceCount;
41926f3cdf0SGordon Ross         }
42026f3cdf0SGordon Ross 
42126f3cdf0SGordon Ross         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
4227b1019a6SJerry Jelinek             "%s: Converted %s to expected %s at Package index %u\n",
4237b1019a6SJerry Jelinek             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
42426f3cdf0SGordon Ross             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
42526f3cdf0SGordon Ross     }
42626f3cdf0SGordon Ross     else
42726f3cdf0SGordon Ross     {
42826f3cdf0SGordon Ross         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
42926f3cdf0SGordon Ross             "%s: Converted %s to expected %s\n",
4307b1019a6SJerry Jelinek             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
43126f3cdf0SGordon Ross             AcpiUtGetObjectTypeName (NewObject)));
43226f3cdf0SGordon Ross     }
43326f3cdf0SGordon Ross 
43426f3cdf0SGordon Ross     /* Delete old object, install the new return object */
43526f3cdf0SGordon Ross 
43626f3cdf0SGordon Ross     AcpiUtRemoveReference (ReturnObject);
43726f3cdf0SGordon Ross     *ReturnObjectPtr = NewObject;
4387b1019a6SJerry Jelinek     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
43926f3cdf0SGordon Ross     return (AE_OK);
44026f3cdf0SGordon Ross }
44126f3cdf0SGordon Ross 
44226f3cdf0SGordon Ross 
4437b1019a6SJerry Jelinek /******************************************************************************
44426f3cdf0SGordon Ross  *
4457b1019a6SJerry Jelinek  * FUNCTION:    AcpiNsMatchSimpleRepair
44626f3cdf0SGordon Ross  *
4477b1019a6SJerry Jelinek  * PARAMETERS:  Node                - Namespace node for the method/object
4487b1019a6SJerry Jelinek  *              ReturnBtype         - Object type that was returned
4497b1019a6SJerry Jelinek  *              PackageIndex        - Index of object within parent package (if
4507b1019a6SJerry Jelinek  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
4517b1019a6SJerry Jelinek  *                                    otherwise)
45226f3cdf0SGordon Ross  *
4537b1019a6SJerry Jelinek  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
45426f3cdf0SGordon Ross  *
4557b1019a6SJerry Jelinek  * DESCRIPTION: Check an object name against the repairable object list.
45626f3cdf0SGordon Ross  *
4577b1019a6SJerry Jelinek  *****************************************************************************/
45826f3cdf0SGordon Ross 
4597b1019a6SJerry Jelinek static const ACPI_SIMPLE_REPAIR_INFO *
AcpiNsMatchSimpleRepair(ACPI_NAMESPACE_NODE * Node,UINT32 ReturnBtype,UINT32 PackageIndex)4607b1019a6SJerry Jelinek AcpiNsMatchSimpleRepair (
4617b1019a6SJerry Jelinek     ACPI_NAMESPACE_NODE     *Node,
4627b1019a6SJerry Jelinek     UINT32                  ReturnBtype,
4637b1019a6SJerry Jelinek     UINT32                  PackageIndex)
46426f3cdf0SGordon Ross {
4657b1019a6SJerry Jelinek     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
46626f3cdf0SGordon Ross 
46726f3cdf0SGordon Ross 
4687b1019a6SJerry Jelinek     /* Search info table for a repairable predefined method/object name */
46957190917SDana Myers 
4707b1019a6SJerry Jelinek     ThisName = AcpiObjectRepairInfo;
4717b1019a6SJerry Jelinek     while (ThisName->ObjectConverter)
47226f3cdf0SGordon Ross     {
4737b1019a6SJerry Jelinek         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
47426f3cdf0SGordon Ross         {
4757b1019a6SJerry Jelinek             /* Check if we can actually repair this name/type combination */
47626f3cdf0SGordon Ross 
4777b1019a6SJerry Jelinek             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
4787b1019a6SJerry Jelinek                 (ThisName->PackageIndex == ACPI_ALL_PACKAGE_ELEMENTS ||
4797b1019a6SJerry Jelinek                  PackageIndex == ThisName->PackageIndex))
48057190917SDana Myers             {
4817b1019a6SJerry Jelinek                 return (ThisName);
48257190917SDana Myers             }
48357190917SDana Myers 
4847b1019a6SJerry Jelinek             return (NULL);
48557190917SDana Myers         }
48657190917SDana Myers 
4877b1019a6SJerry Jelinek         ThisName++;
48826f3cdf0SGordon Ross     }
48926f3cdf0SGordon Ross 
4907b1019a6SJerry Jelinek     return (NULL); /* Name was not found in the repair table */
49126f3cdf0SGordon Ross }
49226f3cdf0SGordon Ross 
49326f3cdf0SGordon Ross 
49426f3cdf0SGordon Ross /*******************************************************************************
49526f3cdf0SGordon Ross  *
49626f3cdf0SGordon Ross  * FUNCTION:    AcpiNsRepairNullElement
49726f3cdf0SGordon Ross  *
4987b1019a6SJerry Jelinek  * PARAMETERS:  Info                - Method execution information block
49926f3cdf0SGordon Ross  *              ExpectedBtypes      - Object types expected
50026f3cdf0SGordon Ross  *              PackageIndex        - Index of object within parent package (if
50126f3cdf0SGordon Ross  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
50226f3cdf0SGordon Ross  *                                    otherwise)
50326f3cdf0SGordon Ross  *              ReturnObjectPtr     - Pointer to the object returned from the
50426f3cdf0SGordon Ross  *                                    evaluation of a method or object
50526f3cdf0SGordon Ross  *
50626f3cdf0SGordon Ross  * RETURN:      Status. AE_OK if repair was successful.
50726f3cdf0SGordon Ross  *
50826f3cdf0SGordon Ross  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
50926f3cdf0SGordon Ross  *
51026f3cdf0SGordon Ross  ******************************************************************************/
51126f3cdf0SGordon Ross 
51226f3cdf0SGordon Ross ACPI_STATUS
AcpiNsRepairNullElement(ACPI_EVALUATE_INFO * Info,UINT32 ExpectedBtypes,UINT32 PackageIndex,ACPI_OPERAND_OBJECT ** ReturnObjectPtr)51326f3cdf0SGordon Ross AcpiNsRepairNullElement (
5147b1019a6SJerry Jelinek     ACPI_EVALUATE_INFO      *Info,
51526f3cdf0SGordon Ross     UINT32                  ExpectedBtypes,
51626f3cdf0SGordon Ross     UINT32                  PackageIndex,
51726f3cdf0SGordon Ross     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
51826f3cdf0SGordon Ross {
51926f3cdf0SGordon Ross     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
52026f3cdf0SGordon Ross     ACPI_OPERAND_OBJECT     *NewObject;
52126f3cdf0SGordon Ross 
52226f3cdf0SGordon Ross 
52326f3cdf0SGordon Ross     ACPI_FUNCTION_NAME (NsRepairNullElement);
52426f3cdf0SGordon Ross 
52526f3cdf0SGordon Ross 
52626f3cdf0SGordon Ross     /* No repair needed if return object is non-NULL */
52726f3cdf0SGordon Ross 
52826f3cdf0SGordon Ross     if (ReturnObject)
52926f3cdf0SGordon Ross     {
53026f3cdf0SGordon Ross         return (AE_OK);
53126f3cdf0SGordon Ross     }
53257190917SDana Myers 
53357190917SDana Myers     /*
53426f3cdf0SGordon Ross      * Attempt to repair a NULL element of a Package object. This applies to
53526f3cdf0SGordon Ross      * predefined names that return a fixed-length package and each element
53626f3cdf0SGordon Ross      * is required. It does not apply to variable-length packages where NULL
53726f3cdf0SGordon Ross      * elements are allowed, especially at the end of the package.
53857190917SDana Myers      */
53926f3cdf0SGordon Ross     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
54057190917SDana Myers     {
54126f3cdf0SGordon Ross         /* Need an Integer - create a zero-value integer */
54257190917SDana Myers 
54326f3cdf0SGordon Ross         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
54426f3cdf0SGordon Ross     }
54526f3cdf0SGordon Ross     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
54626f3cdf0SGordon Ross     {
54726f3cdf0SGordon Ross         /* Need a String - create a NULL string */
54857190917SDana Myers 
54926f3cdf0SGordon Ross         NewObject = AcpiUtCreateStringObject (0);
55026f3cdf0SGordon Ross     }
55126f3cdf0SGordon Ross     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
55226f3cdf0SGordon Ross     {
55326f3cdf0SGordon Ross         /* Need a Buffer - create a zero-length buffer */
55426f3cdf0SGordon Ross 
55526f3cdf0SGordon Ross         NewObject = AcpiUtCreateBufferObject (0);
55657190917SDana Myers     }
55757190917SDana Myers     else
55857190917SDana Myers     {
55926f3cdf0SGordon Ross         /* Error for all other expected types */
56026f3cdf0SGordon Ross 
56126f3cdf0SGordon Ross         return (AE_AML_OPERAND_TYPE);
56257190917SDana Myers     }
56357190917SDana Myers 
56426f3cdf0SGordon Ross     if (!NewObject)
56526f3cdf0SGordon Ross     {
56626f3cdf0SGordon Ross         return (AE_NO_MEMORY);
56726f3cdf0SGordon Ross     }
56826f3cdf0SGordon Ross 
56926f3cdf0SGordon Ross     /* Set the reference count according to the parent Package object */
57026f3cdf0SGordon Ross 
5717b1019a6SJerry Jelinek     NewObject->Common.ReferenceCount =
5727b1019a6SJerry Jelinek         Info->ParentPackage->Common.ReferenceCount;
57326f3cdf0SGordon Ross 
57426f3cdf0SGordon Ross     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
57526f3cdf0SGordon Ross         "%s: Converted NULL package element to expected %s at index %u\n",
5767b1019a6SJerry Jelinek         Info->FullPathname, AcpiUtGetObjectTypeName (NewObject),
5777b1019a6SJerry Jelinek         PackageIndex));
57857190917SDana Myers 
57957190917SDana Myers     *ReturnObjectPtr = NewObject;
5807b1019a6SJerry Jelinek     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
58157190917SDana Myers     return (AE_OK);
58257190917SDana Myers }
58357190917SDana Myers 
58457190917SDana Myers 
58526f3cdf0SGordon Ross /******************************************************************************
58626f3cdf0SGordon Ross  *
58726f3cdf0SGordon Ross  * FUNCTION:    AcpiNsRemoveNullElements
58826f3cdf0SGordon Ross  *
5897b1019a6SJerry Jelinek  * PARAMETERS:  Info                - Method execution information block
59026f3cdf0SGordon Ross  *              PackageType         - An AcpiReturnPackageTypes value
59126f3cdf0SGordon Ross  *              ObjDesc             - A Package object
59226f3cdf0SGordon Ross  *
59326f3cdf0SGordon Ross  * RETURN:      None.
59426f3cdf0SGordon Ross  *
59526f3cdf0SGordon Ross  * DESCRIPTION: Remove all NULL package elements from packages that contain
5967b1019a6SJerry Jelinek  *              a variable number of subpackages. For these types of
59726f3cdf0SGordon Ross  *              packages, NULL elements can be safely removed.
59826f3cdf0SGordon Ross  *
59926f3cdf0SGordon Ross  *****************************************************************************/
60026f3cdf0SGordon Ross 
60126f3cdf0SGordon Ross void
AcpiNsRemoveNullElements(ACPI_EVALUATE_INFO * Info,UINT8 PackageType,ACPI_OPERAND_OBJECT * ObjDesc)60226f3cdf0SGordon Ross AcpiNsRemoveNullElements (
6037b1019a6SJerry Jelinek     ACPI_EVALUATE_INFO      *Info,
60426f3cdf0SGordon Ross     UINT8                   PackageType,
60526f3cdf0SGordon Ross     ACPI_OPERAND_OBJECT     *ObjDesc)
60626f3cdf0SGordon Ross {
60726f3cdf0SGordon Ross     ACPI_OPERAND_OBJECT     **Source;
60826f3cdf0SGordon Ross     ACPI_OPERAND_OBJECT     **Dest;
60926f3cdf0SGordon Ross     UINT32                  Count;
61026f3cdf0SGordon Ross     UINT32                  NewCount;
61126f3cdf0SGordon Ross     UINT32                  i;
61226f3cdf0SGordon Ross 
61326f3cdf0SGordon Ross 
61426f3cdf0SGordon Ross     ACPI_FUNCTION_NAME (NsRemoveNullElements);
61526f3cdf0SGordon Ross 
61626f3cdf0SGordon Ross 
61726f3cdf0SGordon Ross     /*
61826f3cdf0SGordon Ross      * We can safely remove all NULL elements from these package types:
61926f3cdf0SGordon Ross      * PTYPE1_VAR packages contain a variable number of simple data types.
6207b1019a6SJerry Jelinek      * PTYPE2 packages contain a variable number of subpackages.
62126f3cdf0SGordon Ross      */
62226f3cdf0SGordon Ross     switch (PackageType)
62326f3cdf0SGordon Ross     {
62426f3cdf0SGordon Ross     case ACPI_PTYPE1_VAR:
62526f3cdf0SGordon Ross     case ACPI_PTYPE2:
62626f3cdf0SGordon Ross     case ACPI_PTYPE2_COUNT:
62726f3cdf0SGordon Ross     case ACPI_PTYPE2_PKG_COUNT:
62826f3cdf0SGordon Ross     case ACPI_PTYPE2_FIXED:
62926f3cdf0SGordon Ross     case ACPI_PTYPE2_MIN:
63026f3cdf0SGordon Ross     case ACPI_PTYPE2_REV_FIXED:
6317b1019a6SJerry Jelinek     case ACPI_PTYPE2_FIX_VAR:
63226f3cdf0SGordon Ross         break;
63326f3cdf0SGordon Ross 
63426f3cdf0SGordon Ross     default:
6357b1019a6SJerry Jelinek     case ACPI_PTYPE2_VAR_VAR:
63626f3cdf0SGordon Ross     case ACPI_PTYPE1_FIXED:
63726f3cdf0SGordon Ross     case ACPI_PTYPE1_OPTION:
63826f3cdf0SGordon Ross         return;
63926f3cdf0SGordon Ross     }
64026f3cdf0SGordon Ross 
64126f3cdf0SGordon Ross     Count = ObjDesc->Package.Count;
64226f3cdf0SGordon Ross     NewCount = Count;
64326f3cdf0SGordon Ross 
64426f3cdf0SGordon Ross     Source = ObjDesc->Package.Elements;
64526f3cdf0SGordon Ross     Dest = Source;
64626f3cdf0SGordon Ross 
64726f3cdf0SGordon Ross     /* Examine all elements of the package object, remove nulls */
64826f3cdf0SGordon Ross 
64926f3cdf0SGordon Ross     for (i = 0; i < Count; i++)
65026f3cdf0SGordon Ross     {
65126f3cdf0SGordon Ross         if (!*Source)
65226f3cdf0SGordon Ross         {
65326f3cdf0SGordon Ross             NewCount--;
65426f3cdf0SGordon Ross         }
65526f3cdf0SGordon Ross         else
65626f3cdf0SGordon Ross         {
65726f3cdf0SGordon Ross             *Dest = *Source;
65826f3cdf0SGordon Ross             Dest++;
65926f3cdf0SGordon Ross         }
6607b1019a6SJerry Jelinek 
66126f3cdf0SGordon Ross         Source++;
66226f3cdf0SGordon Ross     }
66326f3cdf0SGordon Ross 
66426f3cdf0SGordon Ross     /* Update parent package if any null elements were removed */
66526f3cdf0SGordon Ross 
66626f3cdf0SGordon Ross     if (NewCount < Count)
66726f3cdf0SGordon Ross     {
66826f3cdf0SGordon Ross         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
66926f3cdf0SGordon Ross             "%s: Found and removed %u NULL elements\n",
6707b1019a6SJerry Jelinek             Info->FullPathname, (Count - NewCount)));
67126f3cdf0SGordon Ross 
67226f3cdf0SGordon Ross         /* NULL terminate list and update the package count */
67326f3cdf0SGordon Ross 
67426f3cdf0SGordon Ross         *Dest = NULL;
67526f3cdf0SGordon Ross         ObjDesc->Package.Count = NewCount;
67626f3cdf0SGordon Ross     }
67726f3cdf0SGordon Ross }
67826f3cdf0SGordon Ross 
67926f3cdf0SGordon Ross 
68057190917SDana Myers /*******************************************************************************
68157190917SDana Myers  *
6827b1019a6SJerry Jelinek  * FUNCTION:    AcpiNsWrapWithPackage
68357190917SDana Myers  *
6847b1019a6SJerry Jelinek  * PARAMETERS:  Info                - Method execution information block
6857b1019a6SJerry Jelinek  *              OriginalObject      - Pointer to the object to repair.
6867b1019a6SJerry Jelinek  *              ObjDescPtr          - The new package object is returned here
68757190917SDana Myers  *
68857190917SDana Myers  * RETURN:      Status, new object in *ObjDescPtr
68957190917SDana Myers  *
6907b1019a6SJerry Jelinek  * DESCRIPTION: Repair a common problem with objects that are defined to
6917b1019a6SJerry Jelinek  *              return a variable-length Package of sub-objects. If there is
6927b1019a6SJerry Jelinek  *              only one sub-object, some BIOS code mistakenly simply declares
6937b1019a6SJerry Jelinek  *              the single object instead of a Package with one sub-object.
6947b1019a6SJerry Jelinek  *              This function attempts to repair this error by wrapping a
6957b1019a6SJerry Jelinek  *              Package object around the original object, creating the
6967b1019a6SJerry Jelinek  *              correct and expected Package with one sub-object.
69757190917SDana Myers  *
69857190917SDana Myers  *              Names that can be repaired in this manner include:
6997b1019a6SJerry Jelinek  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
7007b1019a6SJerry Jelinek  *              _BCL, _DOD, _FIX, _Sx
70157190917SDana Myers  *
70257190917SDana Myers  ******************************************************************************/
70357190917SDana Myers 
70457190917SDana Myers ACPI_STATUS
AcpiNsWrapWithPackage(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT * OriginalObject,ACPI_OPERAND_OBJECT ** ObjDescPtr)7057b1019a6SJerry Jelinek AcpiNsWrapWithPackage (
7067b1019a6SJerry Jelinek     ACPI_EVALUATE_INFO      *Info,
7077b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *OriginalObject,
70857190917SDana Myers     ACPI_OPERAND_OBJECT     **ObjDescPtr)
70957190917SDana Myers {
71057190917SDana Myers     ACPI_OPERAND_OBJECT     *PkgObjDesc;
71157190917SDana Myers 
71257190917SDana Myers 
7137b1019a6SJerry Jelinek     ACPI_FUNCTION_NAME (NsWrapWithPackage);
71426f3cdf0SGordon Ross 
71526f3cdf0SGordon Ross 
71657190917SDana Myers     /*
7177b1019a6SJerry Jelinek      * Create the new outer package and populate it. The new
7187b1019a6SJerry Jelinek      * package will have a single element, the lone sub-object.
71957190917SDana Myers      */
72057190917SDana Myers     PkgObjDesc = AcpiUtCreatePackageObject (1);
72157190917SDana Myers     if (!PkgObjDesc)
72257190917SDana Myers     {
72357190917SDana Myers         return (AE_NO_MEMORY);
72457190917SDana Myers     }
72557190917SDana Myers 
7267b1019a6SJerry Jelinek     PkgObjDesc->Package.Elements[0] = OriginalObject;
7277b1019a6SJerry Jelinek 
7287b1019a6SJerry Jelinek     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
7297b1019a6SJerry Jelinek         "%s: Wrapped %s with expected Package object\n",
7307b1019a6SJerry Jelinek         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
73157190917SDana Myers 
73257190917SDana Myers     /* Return the new object in the object pointer */
73357190917SDana Myers 
73457190917SDana Myers     *ObjDescPtr = PkgObjDesc;
7357b1019a6SJerry Jelinek     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
73657190917SDana Myers     return (AE_OK);
73757190917SDana Myers }
738