xref: /minix3/minix/drivers/power/acpi/namespace/nsrepair.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: nsrepair - Repair for objects returned by predefined methods
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acnamesp.h"
47433d6423SLionel Sambuc #include "acinterp.h"
48433d6423SLionel Sambuc #include "acpredef.h"
49*29492bb7SDavid van Moolenbroek #include "amlresrc.h"
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc #define _COMPONENT          ACPI_NAMESPACE
52433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("nsrepair")
53433d6423SLionel Sambuc 
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc /*******************************************************************************
56433d6423SLionel Sambuc  *
57433d6423SLionel Sambuc  * This module attempts to repair or convert objects returned by the
58433d6423SLionel Sambuc  * predefined methods to an object type that is expected, as per the ACPI
59433d6423SLionel Sambuc  * specification. The need for this code is dictated by the many machines that
60433d6423SLionel Sambuc  * return incorrect types for the standard predefined methods. Performing these
61433d6423SLionel Sambuc  * conversions here, in one place, eliminates the need for individual ACPI
62433d6423SLionel Sambuc  * device drivers to do the same. Note: Most of these conversions are different
63433d6423SLionel Sambuc  * than the internal object conversion routines used for implicit object
64433d6423SLionel Sambuc  * conversion.
65433d6423SLionel Sambuc  *
66433d6423SLionel Sambuc  * The following conversions can be performed as necessary:
67433d6423SLionel Sambuc  *
68433d6423SLionel Sambuc  * Integer -> String
69433d6423SLionel Sambuc  * Integer -> Buffer
70433d6423SLionel Sambuc  * String  -> Integer
71433d6423SLionel Sambuc  * String  -> Buffer
72433d6423SLionel Sambuc  * Buffer  -> Integer
73433d6423SLionel Sambuc  * Buffer  -> String
74433d6423SLionel Sambuc  * Buffer  -> Package of Integers
75433d6423SLionel Sambuc  * Package -> Package of one Package
76433d6423SLionel Sambuc  *
77*29492bb7SDavid van Moolenbroek  * Additional conversions that are available:
78*29492bb7SDavid van Moolenbroek  *  Convert a null return or zero return value to an EndTag descriptor
79*29492bb7SDavid van Moolenbroek  *  Convert an ASCII string to a Unicode buffer
80433d6423SLionel Sambuc  *
81*29492bb7SDavid van Moolenbroek  * An incorrect standalone object is wrapped with required outer package
82*29492bb7SDavid van Moolenbroek  *
83*29492bb7SDavid van Moolenbroek  * Additional possible repairs:
84433d6423SLionel Sambuc  * Required package elements that are NULL replaced by Integer/String/Buffer
85433d6423SLionel Sambuc  *
86433d6423SLionel Sambuc  ******************************************************************************/
87433d6423SLionel Sambuc 
88433d6423SLionel Sambuc 
89433d6423SLionel Sambuc /* Local prototypes */
90433d6423SLionel Sambuc 
91*29492bb7SDavid van Moolenbroek static const ACPI_SIMPLE_REPAIR_INFO *
92*29492bb7SDavid van Moolenbroek AcpiNsMatchSimpleRepair (
93*29492bb7SDavid van Moolenbroek     ACPI_NAMESPACE_NODE     *Node,
94*29492bb7SDavid van Moolenbroek     UINT32                  ReturnBtype,
95*29492bb7SDavid van Moolenbroek     UINT32                  PackageIndex);
96433d6423SLionel Sambuc 
97433d6423SLionel Sambuc 
98*29492bb7SDavid van Moolenbroek /*
99*29492bb7SDavid van Moolenbroek  * Special but simple repairs for some names.
100*29492bb7SDavid van Moolenbroek  *
101*29492bb7SDavid van Moolenbroek  * 2nd argument: Unexpected types that can be repaired
102*29492bb7SDavid van Moolenbroek  */
103*29492bb7SDavid van Moolenbroek static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
104*29492bb7SDavid van Moolenbroek {
105*29492bb7SDavid van Moolenbroek     /* Resource descriptor conversions */
106433d6423SLionel Sambuc 
107*29492bb7SDavid van Moolenbroek     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
108*29492bb7SDavid van Moolenbroek                 ACPI_NOT_PACKAGE_ELEMENT,
109*29492bb7SDavid van Moolenbroek                 AcpiNsConvertToResource },
110*29492bb7SDavid van Moolenbroek     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
111*29492bb7SDavid van Moolenbroek                 ACPI_NOT_PACKAGE_ELEMENT,
112*29492bb7SDavid van Moolenbroek                 AcpiNsConvertToResource },
113*29492bb7SDavid van Moolenbroek     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
114*29492bb7SDavid van Moolenbroek                 ACPI_NOT_PACKAGE_ELEMENT,
115*29492bb7SDavid van Moolenbroek                 AcpiNsConvertToResource },
116*29492bb7SDavid van Moolenbroek 
117*29492bb7SDavid van Moolenbroek     /* Unicode conversions */
118*29492bb7SDavid van Moolenbroek 
119*29492bb7SDavid van Moolenbroek     { "_MLS", ACPI_RTYPE_STRING, 1,
120*29492bb7SDavid van Moolenbroek                 AcpiNsConvertToUnicode },
121*29492bb7SDavid van Moolenbroek     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
122*29492bb7SDavid van Moolenbroek                 ACPI_NOT_PACKAGE_ELEMENT,
123*29492bb7SDavid van Moolenbroek                 AcpiNsConvertToUnicode },
124*29492bb7SDavid van Moolenbroek     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
125*29492bb7SDavid van Moolenbroek };
126433d6423SLionel Sambuc 
127433d6423SLionel Sambuc 
128433d6423SLionel Sambuc /*******************************************************************************
129433d6423SLionel Sambuc  *
130*29492bb7SDavid van Moolenbroek  * FUNCTION:    AcpiNsSimpleRepair
131433d6423SLionel Sambuc  *
132*29492bb7SDavid van Moolenbroek  * PARAMETERS:  Info                - Method execution information block
133433d6423SLionel Sambuc  *              ExpectedBtypes      - Object types expected
134433d6423SLionel Sambuc  *              PackageIndex        - Index of object within parent package (if
135433d6423SLionel Sambuc  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
136433d6423SLionel Sambuc  *                                    otherwise)
137433d6423SLionel Sambuc  *              ReturnObjectPtr     - Pointer to the object returned from the
138433d6423SLionel Sambuc  *                                    evaluation of a method or object
139433d6423SLionel Sambuc  *
140433d6423SLionel Sambuc  * RETURN:      Status. AE_OK if repair was successful.
141433d6423SLionel Sambuc  *
142433d6423SLionel Sambuc  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
143433d6423SLionel Sambuc  *              not expected.
144433d6423SLionel Sambuc  *
145433d6423SLionel Sambuc  ******************************************************************************/
146433d6423SLionel Sambuc 
147433d6423SLionel Sambuc ACPI_STATUS
AcpiNsSimpleRepair(ACPI_EVALUATE_INFO * Info,UINT32 ExpectedBtypes,UINT32 PackageIndex,ACPI_OPERAND_OBJECT ** ReturnObjectPtr)148*29492bb7SDavid van Moolenbroek AcpiNsSimpleRepair (
149*29492bb7SDavid van Moolenbroek     ACPI_EVALUATE_INFO      *Info,
150433d6423SLionel Sambuc     UINT32                  ExpectedBtypes,
151433d6423SLionel Sambuc     UINT32                  PackageIndex,
152433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
153433d6423SLionel Sambuc {
154433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
155*29492bb7SDavid van Moolenbroek     ACPI_OPERAND_OBJECT     *NewObject = NULL;
156433d6423SLionel Sambuc     ACPI_STATUS             Status;
157*29492bb7SDavid van Moolenbroek     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
158433d6423SLionel Sambuc 
159433d6423SLionel Sambuc 
160*29492bb7SDavid van Moolenbroek     ACPI_FUNCTION_NAME (NsSimpleRepair);
161433d6423SLionel Sambuc 
162433d6423SLionel Sambuc 
163433d6423SLionel Sambuc     /*
164*29492bb7SDavid van Moolenbroek      * Special repairs for certain names that are in the repair table.
165*29492bb7SDavid van Moolenbroek      * Check if this name is in the list of repairable names.
166*29492bb7SDavid van Moolenbroek      */
167*29492bb7SDavid van Moolenbroek     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
168*29492bb7SDavid van Moolenbroek         Info->ReturnBtype, PackageIndex);
169*29492bb7SDavid van Moolenbroek     if (Predefined)
170*29492bb7SDavid van Moolenbroek     {
171*29492bb7SDavid van Moolenbroek         if (!ReturnObject)
172*29492bb7SDavid van Moolenbroek         {
173*29492bb7SDavid van Moolenbroek             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
174*29492bb7SDavid van Moolenbroek                 ACPI_WARN_ALWAYS, "Missing expected return value"));
175*29492bb7SDavid van Moolenbroek         }
176*29492bb7SDavid van Moolenbroek 
177*29492bb7SDavid van Moolenbroek         Status = Predefined->ObjectConverter (ReturnObject, &NewObject);
178*29492bb7SDavid van Moolenbroek         if (ACPI_FAILURE (Status))
179*29492bb7SDavid van Moolenbroek         {
180*29492bb7SDavid van Moolenbroek             /* A fatal error occurred during a conversion */
181*29492bb7SDavid van Moolenbroek 
182*29492bb7SDavid van Moolenbroek             ACPI_EXCEPTION ((AE_INFO, Status,
183*29492bb7SDavid van Moolenbroek                 "During return object analysis"));
184*29492bb7SDavid van Moolenbroek             return (Status);
185*29492bb7SDavid van Moolenbroek         }
186*29492bb7SDavid van Moolenbroek         if (NewObject)
187*29492bb7SDavid van Moolenbroek         {
188*29492bb7SDavid van Moolenbroek             goto ObjectRepaired;
189*29492bb7SDavid van Moolenbroek         }
190*29492bb7SDavid van Moolenbroek     }
191*29492bb7SDavid van Moolenbroek 
192*29492bb7SDavid van Moolenbroek     /*
193*29492bb7SDavid van Moolenbroek      * Do not perform simple object repair unless the return type is not
194*29492bb7SDavid van Moolenbroek      * expected.
195*29492bb7SDavid van Moolenbroek      */
196*29492bb7SDavid van Moolenbroek     if (Info->ReturnBtype & ExpectedBtypes)
197*29492bb7SDavid van Moolenbroek     {
198*29492bb7SDavid van Moolenbroek         return (AE_OK);
199*29492bb7SDavid van Moolenbroek     }
200*29492bb7SDavid van Moolenbroek 
201*29492bb7SDavid van Moolenbroek     /*
202433d6423SLionel Sambuc      * At this point, we know that the type of the returned object was not
203433d6423SLionel Sambuc      * one of the expected types for this predefined name. Attempt to
204433d6423SLionel Sambuc      * repair the object by converting it to one of the expected object
205433d6423SLionel Sambuc      * types for this predefined name.
206433d6423SLionel Sambuc      */
207*29492bb7SDavid van Moolenbroek 
208*29492bb7SDavid van Moolenbroek     /*
209*29492bb7SDavid van Moolenbroek      * If there is no return value, check if we require a return value for
210*29492bb7SDavid van Moolenbroek      * this predefined name. Either one return value is expected, or none,
211*29492bb7SDavid van Moolenbroek      * for both methods and other objects.
212*29492bb7SDavid van Moolenbroek      *
213*29492bb7SDavid van Moolenbroek      * Try to fix if there was no return object. Warning if failed to fix.
214*29492bb7SDavid van Moolenbroek      */
215*29492bb7SDavid van Moolenbroek     if (!ReturnObject)
216*29492bb7SDavid van Moolenbroek     {
217*29492bb7SDavid van Moolenbroek         if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
218*29492bb7SDavid van Moolenbroek         {
219*29492bb7SDavid van Moolenbroek             if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
220*29492bb7SDavid van Moolenbroek             {
221*29492bb7SDavid van Moolenbroek                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
222*29492bb7SDavid van Moolenbroek                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
223*29492bb7SDavid van Moolenbroek 
224*29492bb7SDavid van Moolenbroek                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
225*29492bb7SDavid van Moolenbroek                             PackageIndex, ReturnObjectPtr);
226*29492bb7SDavid van Moolenbroek                 if (ACPI_SUCCESS (Status))
227*29492bb7SDavid van Moolenbroek                 {
228*29492bb7SDavid van Moolenbroek                     return (AE_OK); /* Repair was successful */
229*29492bb7SDavid van Moolenbroek                 }
230*29492bb7SDavid van Moolenbroek             }
231*29492bb7SDavid van Moolenbroek             else
232*29492bb7SDavid van Moolenbroek             {
233*29492bb7SDavid van Moolenbroek                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
234*29492bb7SDavid van Moolenbroek                     ACPI_WARN_ALWAYS, "Missing expected return value"));
235*29492bb7SDavid van Moolenbroek             }
236*29492bb7SDavid van Moolenbroek 
237*29492bb7SDavid van Moolenbroek             return (AE_AML_NO_RETURN_VALUE);
238*29492bb7SDavid van Moolenbroek         }
239*29492bb7SDavid van Moolenbroek     }
240*29492bb7SDavid van Moolenbroek 
241433d6423SLionel Sambuc     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
242433d6423SLionel Sambuc     {
243433d6423SLionel Sambuc         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
244433d6423SLionel Sambuc         if (ACPI_SUCCESS (Status))
245433d6423SLionel Sambuc         {
246433d6423SLionel Sambuc             goto ObjectRepaired;
247433d6423SLionel Sambuc         }
248433d6423SLionel Sambuc     }
249433d6423SLionel Sambuc     if (ExpectedBtypes & ACPI_RTYPE_STRING)
250433d6423SLionel Sambuc     {
251433d6423SLionel Sambuc         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
252433d6423SLionel Sambuc         if (ACPI_SUCCESS (Status))
253433d6423SLionel Sambuc         {
254433d6423SLionel Sambuc             goto ObjectRepaired;
255433d6423SLionel Sambuc         }
256433d6423SLionel Sambuc     }
257433d6423SLionel Sambuc     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
258433d6423SLionel Sambuc     {
259433d6423SLionel Sambuc         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
260433d6423SLionel Sambuc         if (ACPI_SUCCESS (Status))
261433d6423SLionel Sambuc         {
262433d6423SLionel Sambuc             goto ObjectRepaired;
263433d6423SLionel Sambuc         }
264433d6423SLionel Sambuc     }
265433d6423SLionel Sambuc     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
266433d6423SLionel Sambuc     {
267*29492bb7SDavid van Moolenbroek         /*
268*29492bb7SDavid van Moolenbroek          * A package is expected. We will wrap the existing object with a
269*29492bb7SDavid van Moolenbroek          * new package object. It is often the case that if a variable-length
270*29492bb7SDavid van Moolenbroek          * package is required, but there is only a single object needed, the
271*29492bb7SDavid van Moolenbroek          * BIOS will return that object instead of wrapping it with a Package
272*29492bb7SDavid van Moolenbroek          * object. Note: after the wrapping, the package will be validated
273*29492bb7SDavid van Moolenbroek          * for correct contents (expected object type or types).
274*29492bb7SDavid van Moolenbroek          */
275*29492bb7SDavid van Moolenbroek         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
276433d6423SLionel Sambuc         if (ACPI_SUCCESS (Status))
277433d6423SLionel Sambuc         {
278*29492bb7SDavid van Moolenbroek             /*
279*29492bb7SDavid van Moolenbroek              * The original object just had its reference count
280*29492bb7SDavid van Moolenbroek              * incremented for being inserted into the new package.
281*29492bb7SDavid van Moolenbroek              */
282*29492bb7SDavid van Moolenbroek             *ReturnObjectPtr = NewObject;       /* New Package object */
283*29492bb7SDavid van Moolenbroek             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
284*29492bb7SDavid van Moolenbroek             return (AE_OK);
285433d6423SLionel Sambuc         }
286433d6423SLionel Sambuc     }
287433d6423SLionel Sambuc 
288433d6423SLionel Sambuc     /* We cannot repair this object */
289433d6423SLionel Sambuc 
290433d6423SLionel Sambuc     return (AE_AML_OPERAND_TYPE);
291433d6423SLionel Sambuc 
292433d6423SLionel Sambuc 
293433d6423SLionel Sambuc ObjectRepaired:
294433d6423SLionel Sambuc 
295433d6423SLionel Sambuc     /* Object was successfully repaired */
296433d6423SLionel Sambuc 
297433d6423SLionel Sambuc     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
298433d6423SLionel Sambuc     {
299*29492bb7SDavid van Moolenbroek         /*
300*29492bb7SDavid van Moolenbroek          * The original object is a package element. We need to
301*29492bb7SDavid van Moolenbroek          * decrement the reference count of the original object,
302*29492bb7SDavid van Moolenbroek          * for removing it from the package.
303*29492bb7SDavid van Moolenbroek          *
304*29492bb7SDavid van Moolenbroek          * However, if the original object was just wrapped with a
305*29492bb7SDavid van Moolenbroek          * package object as part of the repair, we don't need to
306*29492bb7SDavid van Moolenbroek          * change the reference count.
307*29492bb7SDavid van Moolenbroek          */
308*29492bb7SDavid van Moolenbroek         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
309*29492bb7SDavid van Moolenbroek         {
310433d6423SLionel Sambuc             NewObject->Common.ReferenceCount =
311433d6423SLionel Sambuc                 ReturnObject->Common.ReferenceCount;
312433d6423SLionel Sambuc 
313433d6423SLionel Sambuc             if (ReturnObject->Common.ReferenceCount > 1)
314433d6423SLionel Sambuc             {
315433d6423SLionel Sambuc                 ReturnObject->Common.ReferenceCount--;
316433d6423SLionel Sambuc             }
317*29492bb7SDavid van Moolenbroek         }
318433d6423SLionel Sambuc 
319433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
320*29492bb7SDavid van Moolenbroek             "%s: Converted %s to expected %s at Package index %u\n",
321*29492bb7SDavid van Moolenbroek             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
322433d6423SLionel Sambuc             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
323433d6423SLionel Sambuc     }
324433d6423SLionel Sambuc     else
325433d6423SLionel Sambuc     {
326433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
327433d6423SLionel Sambuc             "%s: Converted %s to expected %s\n",
328*29492bb7SDavid van Moolenbroek             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
329433d6423SLionel Sambuc             AcpiUtGetObjectTypeName (NewObject)));
330433d6423SLionel Sambuc     }
331433d6423SLionel Sambuc 
332433d6423SLionel Sambuc     /* Delete old object, install the new return object */
333433d6423SLionel Sambuc 
334433d6423SLionel Sambuc     AcpiUtRemoveReference (ReturnObject);
335433d6423SLionel Sambuc     *ReturnObjectPtr = NewObject;
336*29492bb7SDavid van Moolenbroek     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
337433d6423SLionel Sambuc     return (AE_OK);
338433d6423SLionel Sambuc }
339433d6423SLionel Sambuc 
340433d6423SLionel Sambuc 
341*29492bb7SDavid van Moolenbroek /******************************************************************************
342433d6423SLionel Sambuc  *
343*29492bb7SDavid van Moolenbroek  * FUNCTION:    AcpiNsMatchSimpleRepair
344433d6423SLionel Sambuc  *
345*29492bb7SDavid van Moolenbroek  * PARAMETERS:  Node                - Namespace node for the method/object
346*29492bb7SDavid van Moolenbroek  *              ReturnBtype         - Object type that was returned
347*29492bb7SDavid van Moolenbroek  *              PackageIndex        - Index of object within parent package (if
348*29492bb7SDavid van Moolenbroek  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
349*29492bb7SDavid van Moolenbroek  *                                    otherwise)
350433d6423SLionel Sambuc  *
351*29492bb7SDavid van Moolenbroek  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
352433d6423SLionel Sambuc  *
353*29492bb7SDavid van Moolenbroek  * DESCRIPTION: Check an object name against the repairable object list.
354433d6423SLionel Sambuc  *
355*29492bb7SDavid van Moolenbroek  *****************************************************************************/
356433d6423SLionel Sambuc 
357*29492bb7SDavid van Moolenbroek static const ACPI_SIMPLE_REPAIR_INFO *
AcpiNsMatchSimpleRepair(ACPI_NAMESPACE_NODE * Node,UINT32 ReturnBtype,UINT32 PackageIndex)358*29492bb7SDavid van Moolenbroek AcpiNsMatchSimpleRepair (
359*29492bb7SDavid van Moolenbroek     ACPI_NAMESPACE_NODE     *Node,
360*29492bb7SDavid van Moolenbroek     UINT32                  ReturnBtype,
361*29492bb7SDavid van Moolenbroek     UINT32                  PackageIndex)
362433d6423SLionel Sambuc {
363*29492bb7SDavid van Moolenbroek     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
364433d6423SLionel Sambuc 
365433d6423SLionel Sambuc 
366*29492bb7SDavid van Moolenbroek     /* Search info table for a repairable predefined method/object name */
367*29492bb7SDavid van Moolenbroek 
368*29492bb7SDavid van Moolenbroek     ThisName = AcpiObjectRepairInfo;
369*29492bb7SDavid van Moolenbroek     while (ThisName->ObjectConverter)
370433d6423SLionel Sambuc     {
371*29492bb7SDavid van Moolenbroek         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
372433d6423SLionel Sambuc         {
373*29492bb7SDavid van Moolenbroek             /* Check if we can actually repair this name/type combination */
374433d6423SLionel Sambuc 
375*29492bb7SDavid van Moolenbroek             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
376*29492bb7SDavid van Moolenbroek                 (PackageIndex == ThisName->PackageIndex))
377433d6423SLionel Sambuc             {
378*29492bb7SDavid van Moolenbroek                 return (ThisName);
379433d6423SLionel Sambuc             }
380433d6423SLionel Sambuc 
381*29492bb7SDavid van Moolenbroek             return (NULL);
382433d6423SLionel Sambuc         }
383*29492bb7SDavid van Moolenbroek         ThisName++;
384433d6423SLionel Sambuc     }
385433d6423SLionel Sambuc 
386*29492bb7SDavid van Moolenbroek     return (NULL); /* Name was not found in the repair table */
387433d6423SLionel Sambuc }
388433d6423SLionel Sambuc 
389433d6423SLionel Sambuc 
390433d6423SLionel Sambuc /*******************************************************************************
391433d6423SLionel Sambuc  *
392433d6423SLionel Sambuc  * FUNCTION:    AcpiNsRepairNullElement
393433d6423SLionel Sambuc  *
394*29492bb7SDavid van Moolenbroek  * PARAMETERS:  Info                - Method execution information block
395433d6423SLionel Sambuc  *              ExpectedBtypes      - Object types expected
396433d6423SLionel Sambuc  *              PackageIndex        - Index of object within parent package (if
397433d6423SLionel Sambuc  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
398433d6423SLionel Sambuc  *                                    otherwise)
399433d6423SLionel Sambuc  *              ReturnObjectPtr     - Pointer to the object returned from the
400433d6423SLionel Sambuc  *                                    evaluation of a method or object
401433d6423SLionel Sambuc  *
402433d6423SLionel Sambuc  * RETURN:      Status. AE_OK if repair was successful.
403433d6423SLionel Sambuc  *
404433d6423SLionel Sambuc  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
405433d6423SLionel Sambuc  *
406433d6423SLionel Sambuc  ******************************************************************************/
407433d6423SLionel Sambuc 
408433d6423SLionel Sambuc ACPI_STATUS
AcpiNsRepairNullElement(ACPI_EVALUATE_INFO * Info,UINT32 ExpectedBtypes,UINT32 PackageIndex,ACPI_OPERAND_OBJECT ** ReturnObjectPtr)409433d6423SLionel Sambuc AcpiNsRepairNullElement (
410*29492bb7SDavid van Moolenbroek     ACPI_EVALUATE_INFO      *Info,
411433d6423SLionel Sambuc     UINT32                  ExpectedBtypes,
412433d6423SLionel Sambuc     UINT32                  PackageIndex,
413433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
414433d6423SLionel Sambuc {
415433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
416433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *NewObject;
417433d6423SLionel Sambuc 
418433d6423SLionel Sambuc 
419433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (NsRepairNullElement);
420433d6423SLionel Sambuc 
421433d6423SLionel Sambuc 
422433d6423SLionel Sambuc     /* No repair needed if return object is non-NULL */
423433d6423SLionel Sambuc 
424433d6423SLionel Sambuc     if (ReturnObject)
425433d6423SLionel Sambuc     {
426433d6423SLionel Sambuc         return (AE_OK);
427433d6423SLionel Sambuc     }
428433d6423SLionel Sambuc 
429433d6423SLionel Sambuc     /*
430433d6423SLionel Sambuc      * Attempt to repair a NULL element of a Package object. This applies to
431433d6423SLionel Sambuc      * predefined names that return a fixed-length package and each element
432433d6423SLionel Sambuc      * is required. It does not apply to variable-length packages where NULL
433433d6423SLionel Sambuc      * elements are allowed, especially at the end of the package.
434433d6423SLionel Sambuc      */
435433d6423SLionel Sambuc     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
436433d6423SLionel Sambuc     {
437433d6423SLionel Sambuc         /* Need an Integer - create a zero-value integer */
438433d6423SLionel Sambuc 
439433d6423SLionel Sambuc         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
440433d6423SLionel Sambuc     }
441433d6423SLionel Sambuc     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
442433d6423SLionel Sambuc     {
443433d6423SLionel Sambuc         /* Need a String - create a NULL string */
444433d6423SLionel Sambuc 
445433d6423SLionel Sambuc         NewObject = AcpiUtCreateStringObject (0);
446433d6423SLionel Sambuc     }
447433d6423SLionel Sambuc     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
448433d6423SLionel Sambuc     {
449433d6423SLionel Sambuc         /* Need a Buffer - create a zero-length buffer */
450433d6423SLionel Sambuc 
451433d6423SLionel Sambuc         NewObject = AcpiUtCreateBufferObject (0);
452433d6423SLionel Sambuc     }
453433d6423SLionel Sambuc     else
454433d6423SLionel Sambuc     {
455433d6423SLionel Sambuc         /* Error for all other expected types */
456433d6423SLionel Sambuc 
457433d6423SLionel Sambuc         return (AE_AML_OPERAND_TYPE);
458433d6423SLionel Sambuc     }
459433d6423SLionel Sambuc 
460433d6423SLionel Sambuc     if (!NewObject)
461433d6423SLionel Sambuc     {
462433d6423SLionel Sambuc         return (AE_NO_MEMORY);
463433d6423SLionel Sambuc     }
464433d6423SLionel Sambuc 
465433d6423SLionel Sambuc     /* Set the reference count according to the parent Package object */
466433d6423SLionel Sambuc 
467*29492bb7SDavid van Moolenbroek     NewObject->Common.ReferenceCount = Info->ParentPackage->Common.ReferenceCount;
468433d6423SLionel Sambuc 
469433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
470433d6423SLionel Sambuc         "%s: Converted NULL package element to expected %s at index %u\n",
471*29492bb7SDavid van Moolenbroek          Info->FullPathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
472433d6423SLionel Sambuc 
473433d6423SLionel Sambuc     *ReturnObjectPtr = NewObject;
474*29492bb7SDavid van Moolenbroek     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
475433d6423SLionel Sambuc     return (AE_OK);
476433d6423SLionel Sambuc }
477433d6423SLionel Sambuc 
478433d6423SLionel Sambuc 
479433d6423SLionel Sambuc /******************************************************************************
480433d6423SLionel Sambuc  *
481433d6423SLionel Sambuc  * FUNCTION:    AcpiNsRemoveNullElements
482433d6423SLionel Sambuc  *
483*29492bb7SDavid van Moolenbroek  * PARAMETERS:  Info                - Method execution information block
484433d6423SLionel Sambuc  *              PackageType         - An AcpiReturnPackageTypes value
485433d6423SLionel Sambuc  *              ObjDesc             - A Package object
486433d6423SLionel Sambuc  *
487433d6423SLionel Sambuc  * RETURN:      None.
488433d6423SLionel Sambuc  *
489433d6423SLionel Sambuc  * DESCRIPTION: Remove all NULL package elements from packages that contain
490*29492bb7SDavid van Moolenbroek  *              a variable number of subpackages. For these types of
491433d6423SLionel Sambuc  *              packages, NULL elements can be safely removed.
492433d6423SLionel Sambuc  *
493433d6423SLionel Sambuc  *****************************************************************************/
494433d6423SLionel Sambuc 
495433d6423SLionel Sambuc void
AcpiNsRemoveNullElements(ACPI_EVALUATE_INFO * Info,UINT8 PackageType,ACPI_OPERAND_OBJECT * ObjDesc)496433d6423SLionel Sambuc AcpiNsRemoveNullElements (
497*29492bb7SDavid van Moolenbroek     ACPI_EVALUATE_INFO      *Info,
498433d6423SLionel Sambuc     UINT8                   PackageType,
499433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc)
500433d6423SLionel Sambuc {
501433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **Source;
502433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **Dest;
503433d6423SLionel Sambuc     UINT32                  Count;
504433d6423SLionel Sambuc     UINT32                  NewCount;
505433d6423SLionel Sambuc     UINT32                  i;
506433d6423SLionel Sambuc 
507433d6423SLionel Sambuc 
508433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (NsRemoveNullElements);
509433d6423SLionel Sambuc 
510433d6423SLionel Sambuc 
511433d6423SLionel Sambuc     /*
512*29492bb7SDavid van Moolenbroek      * We can safely remove all NULL elements from these package types:
513*29492bb7SDavid van Moolenbroek      * PTYPE1_VAR packages contain a variable number of simple data types.
514*29492bb7SDavid van Moolenbroek      * PTYPE2 packages contain a variable number of subpackages.
515433d6423SLionel Sambuc      */
516433d6423SLionel Sambuc     switch (PackageType)
517433d6423SLionel Sambuc     {
518433d6423SLionel Sambuc     case ACPI_PTYPE1_VAR:
519433d6423SLionel Sambuc     case ACPI_PTYPE2:
520433d6423SLionel Sambuc     case ACPI_PTYPE2_COUNT:
521433d6423SLionel Sambuc     case ACPI_PTYPE2_PKG_COUNT:
522433d6423SLionel Sambuc     case ACPI_PTYPE2_FIXED:
523433d6423SLionel Sambuc     case ACPI_PTYPE2_MIN:
524433d6423SLionel Sambuc     case ACPI_PTYPE2_REV_FIXED:
525*29492bb7SDavid van Moolenbroek     case ACPI_PTYPE2_FIX_VAR:
526*29492bb7SDavid van Moolenbroek 
527433d6423SLionel Sambuc         break;
528433d6423SLionel Sambuc 
529433d6423SLionel Sambuc     default:
530*29492bb7SDavid van Moolenbroek     case ACPI_PTYPE1_FIXED:
531*29492bb7SDavid van Moolenbroek     case ACPI_PTYPE1_OPTION:
532433d6423SLionel Sambuc         return;
533433d6423SLionel Sambuc     }
534433d6423SLionel Sambuc 
535433d6423SLionel Sambuc     Count = ObjDesc->Package.Count;
536433d6423SLionel Sambuc     NewCount = Count;
537433d6423SLionel Sambuc 
538433d6423SLionel Sambuc     Source = ObjDesc->Package.Elements;
539433d6423SLionel Sambuc     Dest = Source;
540433d6423SLionel Sambuc 
541433d6423SLionel Sambuc     /* Examine all elements of the package object, remove nulls */
542433d6423SLionel Sambuc 
543433d6423SLionel Sambuc     for (i = 0; i < Count; i++)
544433d6423SLionel Sambuc     {
545433d6423SLionel Sambuc         if (!*Source)
546433d6423SLionel Sambuc         {
547433d6423SLionel Sambuc             NewCount--;
548433d6423SLionel Sambuc         }
549433d6423SLionel Sambuc         else
550433d6423SLionel Sambuc         {
551433d6423SLionel Sambuc             *Dest = *Source;
552433d6423SLionel Sambuc             Dest++;
553433d6423SLionel Sambuc         }
554433d6423SLionel Sambuc         Source++;
555433d6423SLionel Sambuc     }
556433d6423SLionel Sambuc 
557433d6423SLionel Sambuc     /* Update parent package if any null elements were removed */
558433d6423SLionel Sambuc 
559433d6423SLionel Sambuc     if (NewCount < Count)
560433d6423SLionel Sambuc     {
561433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
562433d6423SLionel Sambuc             "%s: Found and removed %u NULL elements\n",
563*29492bb7SDavid van Moolenbroek             Info->FullPathname, (Count - NewCount)));
564433d6423SLionel Sambuc 
565433d6423SLionel Sambuc         /* NULL terminate list and update the package count */
566433d6423SLionel Sambuc 
567433d6423SLionel Sambuc         *Dest = NULL;
568433d6423SLionel Sambuc         ObjDesc->Package.Count = NewCount;
569433d6423SLionel Sambuc     }
570433d6423SLionel Sambuc }
571433d6423SLionel Sambuc 
572433d6423SLionel Sambuc 
573433d6423SLionel Sambuc /*******************************************************************************
574433d6423SLionel Sambuc  *
575*29492bb7SDavid van Moolenbroek  * FUNCTION:    AcpiNsWrapWithPackage
576433d6423SLionel Sambuc  *
577*29492bb7SDavid van Moolenbroek  * PARAMETERS:  Info                - Method execution information block
578*29492bb7SDavid van Moolenbroek  *              OriginalObject      - Pointer to the object to repair.
579*29492bb7SDavid van Moolenbroek  *              ObjDescPtr          - The new package object is returned here
580433d6423SLionel Sambuc  *
581433d6423SLionel Sambuc  * RETURN:      Status, new object in *ObjDescPtr
582433d6423SLionel Sambuc  *
583*29492bb7SDavid van Moolenbroek  * DESCRIPTION: Repair a common problem with objects that are defined to
584*29492bb7SDavid van Moolenbroek  *              return a variable-length Package of sub-objects. If there is
585*29492bb7SDavid van Moolenbroek  *              only one sub-object, some BIOS code mistakenly simply declares
586*29492bb7SDavid van Moolenbroek  *              the single object instead of a Package with one sub-object.
587*29492bb7SDavid van Moolenbroek  *              This function attempts to repair this error by wrapping a
588*29492bb7SDavid van Moolenbroek  *              Package object around the original object, creating the
589*29492bb7SDavid van Moolenbroek  *              correct and expected Package with one sub-object.
590433d6423SLionel Sambuc  *
591433d6423SLionel Sambuc  *              Names that can be repaired in this manner include:
592*29492bb7SDavid van Moolenbroek  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
593*29492bb7SDavid van Moolenbroek  *              _BCL, _DOD, _FIX, _Sx
594433d6423SLionel Sambuc  *
595433d6423SLionel Sambuc  ******************************************************************************/
596433d6423SLionel Sambuc 
597433d6423SLionel Sambuc ACPI_STATUS
AcpiNsWrapWithPackage(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT * OriginalObject,ACPI_OPERAND_OBJECT ** ObjDescPtr)598*29492bb7SDavid van Moolenbroek AcpiNsWrapWithPackage (
599*29492bb7SDavid van Moolenbroek     ACPI_EVALUATE_INFO      *Info,
600*29492bb7SDavid van Moolenbroek     ACPI_OPERAND_OBJECT     *OriginalObject,
601433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **ObjDescPtr)
602433d6423SLionel Sambuc {
603433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *PkgObjDesc;
604433d6423SLionel Sambuc 
605433d6423SLionel Sambuc 
606*29492bb7SDavid van Moolenbroek     ACPI_FUNCTION_NAME (NsWrapWithPackage);
607433d6423SLionel Sambuc 
608433d6423SLionel Sambuc 
609433d6423SLionel Sambuc     /*
610433d6423SLionel Sambuc      * Create the new outer package and populate it. The new package will
611*29492bb7SDavid van Moolenbroek      * have a single element, the lone sub-object.
612433d6423SLionel Sambuc      */
613433d6423SLionel Sambuc     PkgObjDesc = AcpiUtCreatePackageObject (1);
614433d6423SLionel Sambuc     if (!PkgObjDesc)
615433d6423SLionel Sambuc     {
616433d6423SLionel Sambuc         return (AE_NO_MEMORY);
617433d6423SLionel Sambuc     }
618433d6423SLionel Sambuc 
619*29492bb7SDavid van Moolenbroek     PkgObjDesc->Package.Elements[0] = OriginalObject;
620*29492bb7SDavid van Moolenbroek 
621*29492bb7SDavid van Moolenbroek     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
622*29492bb7SDavid van Moolenbroek         "%s: Wrapped %s with expected Package object\n",
623*29492bb7SDavid van Moolenbroek         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
624433d6423SLionel Sambuc 
625433d6423SLionel Sambuc     /* Return the new object in the object pointer */
626433d6423SLionel Sambuc 
627433d6423SLionel Sambuc     *ObjDescPtr = PkgObjDesc;
628*29492bb7SDavid van Moolenbroek     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
629433d6423SLionel Sambuc     return (AE_OK);
630433d6423SLionel Sambuc }
631