nsrepair.c revision 1.1.1.4 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: nsrepair - Repair for objects returned by predefined methods
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.4 christos * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #define __NSREPAIR_C__
45 1.1 jruoho
46 1.1 jruoho #include "acpi.h"
47 1.1 jruoho #include "accommon.h"
48 1.1 jruoho #include "acnamesp.h"
49 1.1 jruoho #include "acinterp.h"
50 1.1 jruoho #include "acpredef.h"
51 1.1.1.4 christos #include "amlresrc.h"
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_NAMESPACE
54 1.1 jruoho ACPI_MODULE_NAME ("nsrepair")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /*******************************************************************************
58 1.1 jruoho *
59 1.1 jruoho * This module attempts to repair or convert objects returned by the
60 1.1 jruoho * predefined methods to an object type that is expected, as per the ACPI
61 1.1 jruoho * specification. The need for this code is dictated by the many machines that
62 1.1 jruoho * return incorrect types for the standard predefined methods. Performing these
63 1.1 jruoho * conversions here, in one place, eliminates the need for individual ACPI
64 1.1 jruoho * device drivers to do the same. Note: Most of these conversions are different
65 1.1 jruoho * than the internal object conversion routines used for implicit object
66 1.1 jruoho * conversion.
67 1.1 jruoho *
68 1.1 jruoho * The following conversions can be performed as necessary:
69 1.1 jruoho *
70 1.1 jruoho * Integer -> String
71 1.1 jruoho * Integer -> Buffer
72 1.1 jruoho * String -> Integer
73 1.1 jruoho * String -> Buffer
74 1.1 jruoho * Buffer -> Integer
75 1.1 jruoho * Buffer -> String
76 1.1 jruoho * Buffer -> Package of Integers
77 1.1 jruoho * Package -> Package of one Package
78 1.1 jruoho *
79 1.1.1.4 christos * Additional conversions that are available:
80 1.1.1.4 christos * Convert a null return or zero return value to an EndTag descriptor
81 1.1.1.4 christos * Convert an ASCII string to a Unicode buffer
82 1.1.1.4 christos *
83 1.1.1.4 christos * An incorrect standalone object is wrapped with required outer package
84 1.1 jruoho *
85 1.1.1.4 christos * Additional possible repairs:
86 1.1 jruoho * Required package elements that are NULL replaced by Integer/String/Buffer
87 1.1 jruoho *
88 1.1 jruoho ******************************************************************************/
89 1.1 jruoho
90 1.1 jruoho
91 1.1 jruoho /* Local prototypes */
92 1.1 jruoho
93 1.1.1.4 christos static const ACPI_SIMPLE_REPAIR_INFO *
94 1.1.1.4 christos AcpiNsMatchSimpleRepair (
95 1.1.1.4 christos ACPI_NAMESPACE_NODE *Node,
96 1.1.1.4 christos UINT32 ReturnBtype,
97 1.1.1.4 christos UINT32 PackageIndex);
98 1.1 jruoho
99 1.1 jruoho
100 1.1.1.4 christos /*
101 1.1.1.4 christos * Special but simple repairs for some names.
102 1.1.1.4 christos *
103 1.1.1.4 christos * 2nd argument: Unexpected types that can be repaired
104 1.1.1.4 christos */
105 1.1.1.4 christos static const ACPI_SIMPLE_REPAIR_INFO AcpiObjectRepairInfo[] =
106 1.1.1.4 christos {
107 1.1.1.4 christos /* Resource descriptor conversions */
108 1.1 jruoho
109 1.1.1.4 christos { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
110 1.1.1.4 christos ACPI_NOT_PACKAGE_ELEMENT,
111 1.1.1.4 christos AcpiNsConvertToResource },
112 1.1.1.4 christos { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
113 1.1.1.4 christos ACPI_NOT_PACKAGE_ELEMENT,
114 1.1.1.4 christos AcpiNsConvertToResource },
115 1.1.1.4 christos { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
116 1.1.1.4 christos ACPI_NOT_PACKAGE_ELEMENT,
117 1.1.1.4 christos AcpiNsConvertToResource },
118 1.1.1.4 christos
119 1.1.1.4 christos /* Unicode conversions */
120 1.1.1.4 christos
121 1.1.1.4 christos { "_MLS", ACPI_RTYPE_STRING, 1,
122 1.1.1.4 christos AcpiNsConvertToUnicode },
123 1.1.1.4 christos { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
124 1.1.1.4 christos ACPI_NOT_PACKAGE_ELEMENT,
125 1.1.1.4 christos AcpiNsConvertToUnicode },
126 1.1.1.4 christos { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
127 1.1.1.4 christos };
128 1.1 jruoho
129 1.1 jruoho
130 1.1 jruoho /*******************************************************************************
131 1.1 jruoho *
132 1.1.1.4 christos * FUNCTION: AcpiNsSimpleRepair
133 1.1 jruoho *
134 1.1.1.4 christos * PARAMETERS: Info - Method execution information block
135 1.1 jruoho * ExpectedBtypes - Object types expected
136 1.1 jruoho * PackageIndex - Index of object within parent package (if
137 1.1 jruoho * applicable - ACPI_NOT_PACKAGE_ELEMENT
138 1.1 jruoho * otherwise)
139 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
140 1.1 jruoho * evaluation of a method or object
141 1.1 jruoho *
142 1.1 jruoho * RETURN: Status. AE_OK if repair was successful.
143 1.1 jruoho *
144 1.1 jruoho * DESCRIPTION: Attempt to repair/convert a return object of a type that was
145 1.1 jruoho * not expected.
146 1.1 jruoho *
147 1.1 jruoho ******************************************************************************/
148 1.1 jruoho
149 1.1 jruoho ACPI_STATUS
150 1.1.1.4 christos AcpiNsSimpleRepair (
151 1.1.1.4 christos ACPI_EVALUATE_INFO *Info,
152 1.1 jruoho UINT32 ExpectedBtypes,
153 1.1 jruoho UINT32 PackageIndex,
154 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
155 1.1 jruoho {
156 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
157 1.1.1.4 christos ACPI_OPERAND_OBJECT *NewObject = NULL;
158 1.1 jruoho ACPI_STATUS Status;
159 1.1.1.4 christos const ACPI_SIMPLE_REPAIR_INFO *Predefined;
160 1.1.1.4 christos
161 1.1 jruoho
162 1.1.1.4 christos ACPI_FUNCTION_NAME (NsSimpleRepair);
163 1.1.1.4 christos
164 1.1.1.4 christos
165 1.1.1.4 christos /*
166 1.1.1.4 christos * Special repairs for certain names that are in the repair table.
167 1.1.1.4 christos * Check if this name is in the list of repairable names.
168 1.1.1.4 christos */
169 1.1.1.4 christos Predefined = AcpiNsMatchSimpleRepair (Info->Node,
170 1.1.1.4 christos Info->ReturnBtype, PackageIndex);
171 1.1.1.4 christos if (Predefined)
172 1.1.1.4 christos {
173 1.1.1.4 christos if (!ReturnObject)
174 1.1.1.4 christos {
175 1.1.1.4 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
176 1.1.1.4 christos ACPI_WARN_ALWAYS, "Missing expected return value"));
177 1.1.1.4 christos }
178 1.1 jruoho
179 1.1.1.4 christos Status = Predefined->ObjectConverter (ReturnObject, &NewObject);
180 1.1.1.4 christos if (ACPI_FAILURE (Status))
181 1.1.1.4 christos {
182 1.1.1.4 christos /* A fatal error occurred during a conversion */
183 1.1 jruoho
184 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
185 1.1.1.4 christos "During return object analysis"));
186 1.1.1.4 christos return (Status);
187 1.1.1.4 christos }
188 1.1.1.4 christos if (NewObject)
189 1.1.1.4 christos {
190 1.1.1.4 christos goto ObjectRepaired;
191 1.1.1.4 christos }
192 1.1.1.4 christos }
193 1.1.1.4 christos
194 1.1.1.4 christos /*
195 1.1.1.4 christos * Do not perform simple object repair unless the return type is not
196 1.1.1.4 christos * expected.
197 1.1.1.4 christos */
198 1.1.1.4 christos if (Info->ReturnBtype & ExpectedBtypes)
199 1.1.1.4 christos {
200 1.1.1.4 christos return (AE_OK);
201 1.1.1.4 christos }
202 1.1 jruoho
203 1.1 jruoho /*
204 1.1 jruoho * At this point, we know that the type of the returned object was not
205 1.1 jruoho * one of the expected types for this predefined name. Attempt to
206 1.1 jruoho * repair the object by converting it to one of the expected object
207 1.1 jruoho * types for this predefined name.
208 1.1 jruoho */
209 1.1.1.4 christos
210 1.1.1.4 christos /*
211 1.1.1.4 christos * If there is no return value, check if we require a return value for
212 1.1.1.4 christos * this predefined name. Either one return value is expected, or none,
213 1.1.1.4 christos * for both methods and other objects.
214 1.1.1.4 christos *
215 1.1.1.4 christos * Exit now if there is no return object. Warning if one was expected.
216 1.1.1.4 christos */
217 1.1.1.4 christos if (!ReturnObject)
218 1.1.1.4 christos {
219 1.1.1.4 christos if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
220 1.1.1.4 christos {
221 1.1.1.4 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
222 1.1.1.4 christos ACPI_WARN_ALWAYS, "Missing expected return value"));
223 1.1.1.4 christos
224 1.1.1.4 christos return (AE_AML_NO_RETURN_VALUE);
225 1.1.1.4 christos }
226 1.1.1.4 christos }
227 1.1.1.4 christos
228 1.1 jruoho if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
229 1.1 jruoho {
230 1.1 jruoho Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
231 1.1 jruoho if (ACPI_SUCCESS (Status))
232 1.1 jruoho {
233 1.1 jruoho goto ObjectRepaired;
234 1.1 jruoho }
235 1.1 jruoho }
236 1.1 jruoho if (ExpectedBtypes & ACPI_RTYPE_STRING)
237 1.1 jruoho {
238 1.1 jruoho Status = AcpiNsConvertToString (ReturnObject, &NewObject);
239 1.1 jruoho if (ACPI_SUCCESS (Status))
240 1.1 jruoho {
241 1.1 jruoho goto ObjectRepaired;
242 1.1 jruoho }
243 1.1 jruoho }
244 1.1 jruoho if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
245 1.1 jruoho {
246 1.1 jruoho Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
247 1.1 jruoho if (ACPI_SUCCESS (Status))
248 1.1 jruoho {
249 1.1 jruoho goto ObjectRepaired;
250 1.1 jruoho }
251 1.1 jruoho }
252 1.1 jruoho if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
253 1.1 jruoho {
254 1.1.1.4 christos /*
255 1.1.1.4 christos * A package is expected. We will wrap the existing object with a
256 1.1.1.4 christos * new package object. It is often the case that if a variable-length
257 1.1.1.4 christos * package is required, but there is only a single object needed, the
258 1.1.1.4 christos * BIOS will return that object instead of wrapping it with a Package
259 1.1.1.4 christos * object. Note: after the wrapping, the package will be validated
260 1.1.1.4 christos * for correct contents (expected object type or types).
261 1.1.1.4 christos */
262 1.1.1.4 christos Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
263 1.1 jruoho if (ACPI_SUCCESS (Status))
264 1.1 jruoho {
265 1.1.1.4 christos /*
266 1.1.1.4 christos * The original object just had its reference count
267 1.1.1.4 christos * incremented for being inserted into the new package.
268 1.1.1.4 christos */
269 1.1.1.4 christos *ReturnObjectPtr = NewObject; /* New Package object */
270 1.1.1.4 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
271 1.1.1.4 christos return (AE_OK);
272 1.1 jruoho }
273 1.1 jruoho }
274 1.1 jruoho
275 1.1 jruoho /* We cannot repair this object */
276 1.1 jruoho
277 1.1 jruoho return (AE_AML_OPERAND_TYPE);
278 1.1 jruoho
279 1.1 jruoho
280 1.1 jruoho ObjectRepaired:
281 1.1 jruoho
282 1.1 jruoho /* Object was successfully repaired */
283 1.1 jruoho
284 1.1 jruoho if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
285 1.1 jruoho {
286 1.1.1.4 christos /*
287 1.1.1.4 christos * The original object is a package element. We need to
288 1.1.1.4 christos * decrement the reference count of the original object,
289 1.1.1.4 christos * for removing it from the package.
290 1.1.1.4 christos *
291 1.1.1.4 christos * However, if the original object was just wrapped with a
292 1.1.1.4 christos * package object as part of the repair, we don't need to
293 1.1.1.4 christos * change the reference count.
294 1.1.1.4 christos */
295 1.1.1.4 christos if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
296 1.1 jruoho {
297 1.1.1.4 christos NewObject->Common.ReferenceCount =
298 1.1.1.4 christos ReturnObject->Common.ReferenceCount;
299 1.1.1.4 christos
300 1.1.1.4 christos if (ReturnObject->Common.ReferenceCount > 1)
301 1.1.1.4 christos {
302 1.1.1.4 christos ReturnObject->Common.ReferenceCount--;
303 1.1.1.4 christos }
304 1.1 jruoho }
305 1.1 jruoho
306 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
307 1.1.1.4 christos "%s: Converted %s to expected %s at Package index %u\n",
308 1.1.1.4 christos Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
309 1.1 jruoho AcpiUtGetObjectTypeName (NewObject), PackageIndex));
310 1.1 jruoho }
311 1.1 jruoho else
312 1.1 jruoho {
313 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
314 1.1 jruoho "%s: Converted %s to expected %s\n",
315 1.1.1.4 christos Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
316 1.1 jruoho AcpiUtGetObjectTypeName (NewObject)));
317 1.1 jruoho }
318 1.1 jruoho
319 1.1 jruoho /* Delete old object, install the new return object */
320 1.1 jruoho
321 1.1 jruoho AcpiUtRemoveReference (ReturnObject);
322 1.1 jruoho *ReturnObjectPtr = NewObject;
323 1.1.1.4 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
324 1.1 jruoho return (AE_OK);
325 1.1 jruoho }
326 1.1 jruoho
327 1.1 jruoho
328 1.1.1.4 christos /******************************************************************************
329 1.1 jruoho *
330 1.1.1.4 christos * FUNCTION: AcpiNsMatchSimpleRepair
331 1.1 jruoho *
332 1.1.1.4 christos * PARAMETERS: Node - Namespace node for the method/object
333 1.1.1.4 christos * ReturnBtype - Object type that was returned
334 1.1.1.4 christos * PackageIndex - Index of object within parent package (if
335 1.1.1.4 christos * applicable - ACPI_NOT_PACKAGE_ELEMENT
336 1.1.1.4 christos * otherwise)
337 1.1 jruoho *
338 1.1.1.4 christos * RETURN: Pointer to entry in repair table. NULL indicates not found.
339 1.1 jruoho *
340 1.1.1.4 christos * DESCRIPTION: Check an object name against the repairable object list.
341 1.1 jruoho *
342 1.1.1.4 christos *****************************************************************************/
343 1.1 jruoho
344 1.1.1.4 christos static const ACPI_SIMPLE_REPAIR_INFO *
345 1.1.1.4 christos AcpiNsMatchSimpleRepair (
346 1.1.1.4 christos ACPI_NAMESPACE_NODE *Node,
347 1.1.1.4 christos UINT32 ReturnBtype,
348 1.1.1.4 christos UINT32 PackageIndex)
349 1.1 jruoho {
350 1.1.1.4 christos const ACPI_SIMPLE_REPAIR_INFO *ThisName;
351 1.1 jruoho
352 1.1 jruoho
353 1.1.1.4 christos /* Search info table for a repairable predefined method/object name */
354 1.1 jruoho
355 1.1.1.4 christos ThisName = AcpiObjectRepairInfo;
356 1.1.1.4 christos while (ThisName->ObjectConverter)
357 1.1 jruoho {
358 1.1.1.4 christos if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
359 1.1 jruoho {
360 1.1.1.4 christos /* Check if we can actually repair this name/type combination */
361 1.1 jruoho
362 1.1.1.4 christos if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
363 1.1.1.4 christos (PackageIndex == ThisName->PackageIndex))
364 1.1 jruoho {
365 1.1.1.4 christos return (ThisName);
366 1.1 jruoho }
367 1.1 jruoho
368 1.1.1.4 christos return (NULL);
369 1.1 jruoho }
370 1.1.1.4 christos ThisName++;
371 1.1 jruoho }
372 1.1 jruoho
373 1.1.1.4 christos return (NULL); /* Name was not found in the repair table */
374 1.1 jruoho }
375 1.1 jruoho
376 1.1 jruoho
377 1.1 jruoho /*******************************************************************************
378 1.1 jruoho *
379 1.1 jruoho * FUNCTION: AcpiNsRepairNullElement
380 1.1 jruoho *
381 1.1.1.4 christos * PARAMETERS: Info - Method execution information block
382 1.1 jruoho * ExpectedBtypes - Object types expected
383 1.1 jruoho * PackageIndex - Index of object within parent package (if
384 1.1 jruoho * applicable - ACPI_NOT_PACKAGE_ELEMENT
385 1.1 jruoho * otherwise)
386 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
387 1.1 jruoho * evaluation of a method or object
388 1.1 jruoho *
389 1.1 jruoho * RETURN: Status. AE_OK if repair was successful.
390 1.1 jruoho *
391 1.1 jruoho * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
392 1.1 jruoho *
393 1.1 jruoho ******************************************************************************/
394 1.1 jruoho
395 1.1 jruoho ACPI_STATUS
396 1.1 jruoho AcpiNsRepairNullElement (
397 1.1.1.4 christos ACPI_EVALUATE_INFO *Info,
398 1.1 jruoho UINT32 ExpectedBtypes,
399 1.1 jruoho UINT32 PackageIndex,
400 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
401 1.1 jruoho {
402 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
403 1.1 jruoho ACPI_OPERAND_OBJECT *NewObject;
404 1.1 jruoho
405 1.1 jruoho
406 1.1 jruoho ACPI_FUNCTION_NAME (NsRepairNullElement);
407 1.1 jruoho
408 1.1 jruoho
409 1.1 jruoho /* No repair needed if return object is non-NULL */
410 1.1 jruoho
411 1.1 jruoho if (ReturnObject)
412 1.1 jruoho {
413 1.1 jruoho return (AE_OK);
414 1.1 jruoho }
415 1.1 jruoho
416 1.1 jruoho /*
417 1.1 jruoho * Attempt to repair a NULL element of a Package object. This applies to
418 1.1 jruoho * predefined names that return a fixed-length package and each element
419 1.1 jruoho * is required. It does not apply to variable-length packages where NULL
420 1.1 jruoho * elements are allowed, especially at the end of the package.
421 1.1 jruoho */
422 1.1 jruoho if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
423 1.1 jruoho {
424 1.1 jruoho /* Need an Integer - create a zero-value integer */
425 1.1 jruoho
426 1.1.1.2 jruoho NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
427 1.1 jruoho }
428 1.1 jruoho else if (ExpectedBtypes & ACPI_RTYPE_STRING)
429 1.1 jruoho {
430 1.1 jruoho /* Need a String - create a NULL string */
431 1.1 jruoho
432 1.1 jruoho NewObject = AcpiUtCreateStringObject (0);
433 1.1 jruoho }
434 1.1 jruoho else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
435 1.1 jruoho {
436 1.1 jruoho /* Need a Buffer - create a zero-length buffer */
437 1.1 jruoho
438 1.1 jruoho NewObject = AcpiUtCreateBufferObject (0);
439 1.1 jruoho }
440 1.1 jruoho else
441 1.1 jruoho {
442 1.1 jruoho /* Error for all other expected types */
443 1.1 jruoho
444 1.1 jruoho return (AE_AML_OPERAND_TYPE);
445 1.1 jruoho }
446 1.1 jruoho
447 1.1 jruoho if (!NewObject)
448 1.1 jruoho {
449 1.1 jruoho return (AE_NO_MEMORY);
450 1.1 jruoho }
451 1.1 jruoho
452 1.1 jruoho /* Set the reference count according to the parent Package object */
453 1.1 jruoho
454 1.1.1.4 christos NewObject->Common.ReferenceCount = Info->ParentPackage->Common.ReferenceCount;
455 1.1 jruoho
456 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
457 1.1 jruoho "%s: Converted NULL package element to expected %s at index %u\n",
458 1.1.1.4 christos Info->FullPathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
459 1.1 jruoho
460 1.1 jruoho *ReturnObjectPtr = NewObject;
461 1.1.1.4 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
462 1.1 jruoho return (AE_OK);
463 1.1 jruoho }
464 1.1 jruoho
465 1.1 jruoho
466 1.1 jruoho /******************************************************************************
467 1.1 jruoho *
468 1.1 jruoho * FUNCTION: AcpiNsRemoveNullElements
469 1.1 jruoho *
470 1.1.1.4 christos * PARAMETERS: Info - Method execution information block
471 1.1 jruoho * PackageType - An AcpiReturnPackageTypes value
472 1.1 jruoho * ObjDesc - A Package object
473 1.1 jruoho *
474 1.1 jruoho * RETURN: None.
475 1.1 jruoho *
476 1.1 jruoho * DESCRIPTION: Remove all NULL package elements from packages that contain
477 1.1 jruoho * a variable number of sub-packages. For these types of
478 1.1 jruoho * packages, NULL elements can be safely removed.
479 1.1 jruoho *
480 1.1 jruoho *****************************************************************************/
481 1.1 jruoho
482 1.1 jruoho void
483 1.1 jruoho AcpiNsRemoveNullElements (
484 1.1.1.4 christos ACPI_EVALUATE_INFO *Info,
485 1.1 jruoho UINT8 PackageType,
486 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc)
487 1.1 jruoho {
488 1.1 jruoho ACPI_OPERAND_OBJECT **Source;
489 1.1 jruoho ACPI_OPERAND_OBJECT **Dest;
490 1.1 jruoho UINT32 Count;
491 1.1 jruoho UINT32 NewCount;
492 1.1 jruoho UINT32 i;
493 1.1 jruoho
494 1.1 jruoho
495 1.1 jruoho ACPI_FUNCTION_NAME (NsRemoveNullElements);
496 1.1 jruoho
497 1.1 jruoho
498 1.1 jruoho /*
499 1.1.1.3 jruoho * We can safely remove all NULL elements from these package types:
500 1.1.1.3 jruoho * PTYPE1_VAR packages contain a variable number of simple data types.
501 1.1.1.3 jruoho * PTYPE2 packages contain a variable number of sub-packages.
502 1.1 jruoho */
503 1.1 jruoho switch (PackageType)
504 1.1 jruoho {
505 1.1 jruoho case ACPI_PTYPE1_VAR:
506 1.1 jruoho case ACPI_PTYPE2:
507 1.1 jruoho case ACPI_PTYPE2_COUNT:
508 1.1 jruoho case ACPI_PTYPE2_PKG_COUNT:
509 1.1 jruoho case ACPI_PTYPE2_FIXED:
510 1.1 jruoho case ACPI_PTYPE2_MIN:
511 1.1 jruoho case ACPI_PTYPE2_REV_FIXED:
512 1.1.1.4 christos case ACPI_PTYPE2_FIX_VAR:
513 1.1.1.4 christos
514 1.1 jruoho break;
515 1.1 jruoho
516 1.1 jruoho default:
517 1.1.1.3 jruoho case ACPI_PTYPE1_FIXED:
518 1.1.1.3 jruoho case ACPI_PTYPE1_OPTION:
519 1.1 jruoho return;
520 1.1 jruoho }
521 1.1 jruoho
522 1.1 jruoho Count = ObjDesc->Package.Count;
523 1.1 jruoho NewCount = Count;
524 1.1 jruoho
525 1.1 jruoho Source = ObjDesc->Package.Elements;
526 1.1 jruoho Dest = Source;
527 1.1 jruoho
528 1.1 jruoho /* Examine all elements of the package object, remove nulls */
529 1.1 jruoho
530 1.1 jruoho for (i = 0; i < Count; i++)
531 1.1 jruoho {
532 1.1 jruoho if (!*Source)
533 1.1 jruoho {
534 1.1 jruoho NewCount--;
535 1.1 jruoho }
536 1.1 jruoho else
537 1.1 jruoho {
538 1.1 jruoho *Dest = *Source;
539 1.1 jruoho Dest++;
540 1.1 jruoho }
541 1.1 jruoho Source++;
542 1.1 jruoho }
543 1.1 jruoho
544 1.1 jruoho /* Update parent package if any null elements were removed */
545 1.1 jruoho
546 1.1 jruoho if (NewCount < Count)
547 1.1 jruoho {
548 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
549 1.1 jruoho "%s: Found and removed %u NULL elements\n",
550 1.1.1.4 christos Info->FullPathname, (Count - NewCount)));
551 1.1 jruoho
552 1.1 jruoho /* NULL terminate list and update the package count */
553 1.1 jruoho
554 1.1 jruoho *Dest = NULL;
555 1.1 jruoho ObjDesc->Package.Count = NewCount;
556 1.1 jruoho }
557 1.1 jruoho }
558 1.1 jruoho
559 1.1 jruoho
560 1.1 jruoho /*******************************************************************************
561 1.1 jruoho *
562 1.1.1.4 christos * FUNCTION: AcpiNsWrapWithPackage
563 1.1 jruoho *
564 1.1.1.4 christos * PARAMETERS: Info - Method execution information block
565 1.1.1.4 christos * OriginalObject - Pointer to the object to repair.
566 1.1.1.4 christos * ObjDescPtr - The new package object is returned here
567 1.1 jruoho *
568 1.1 jruoho * RETURN: Status, new object in *ObjDescPtr
569 1.1 jruoho *
570 1.1.1.4 christos * DESCRIPTION: Repair a common problem with objects that are defined to
571 1.1.1.4 christos * return a variable-length Package of sub-objects. If there is
572 1.1.1.4 christos * only one sub-object, some BIOS code mistakenly simply declares
573 1.1.1.4 christos * the single object instead of a Package with one sub-object.
574 1.1.1.4 christos * This function attempts to repair this error by wrapping a
575 1.1.1.4 christos * Package object around the original object, creating the
576 1.1.1.4 christos * correct and expected Package with one sub-object.
577 1.1 jruoho *
578 1.1 jruoho * Names that can be repaired in this manner include:
579 1.1.1.4 christos * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
580 1.1.1.4 christos * _BCL, _DOD, _FIX, _Sx
581 1.1 jruoho *
582 1.1 jruoho ******************************************************************************/
583 1.1 jruoho
584 1.1 jruoho ACPI_STATUS
585 1.1.1.4 christos AcpiNsWrapWithPackage (
586 1.1.1.4 christos ACPI_EVALUATE_INFO *Info,
587 1.1.1.4 christos ACPI_OPERAND_OBJECT *OriginalObject,
588 1.1 jruoho ACPI_OPERAND_OBJECT **ObjDescPtr)
589 1.1 jruoho {
590 1.1 jruoho ACPI_OPERAND_OBJECT *PkgObjDesc;
591 1.1 jruoho
592 1.1 jruoho
593 1.1.1.4 christos ACPI_FUNCTION_NAME (NsWrapWithPackage);
594 1.1 jruoho
595 1.1 jruoho
596 1.1 jruoho /*
597 1.1 jruoho * Create the new outer package and populate it. The new package will
598 1.1.1.4 christos * have a single element, the lone sub-object.
599 1.1 jruoho */
600 1.1 jruoho PkgObjDesc = AcpiUtCreatePackageObject (1);
601 1.1 jruoho if (!PkgObjDesc)
602 1.1 jruoho {
603 1.1 jruoho return (AE_NO_MEMORY);
604 1.1 jruoho }
605 1.1 jruoho
606 1.1.1.4 christos PkgObjDesc->Package.Elements[0] = OriginalObject;
607 1.1.1.4 christos
608 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
609 1.1.1.4 christos "%s: Wrapped %s with expected Package object\n",
610 1.1.1.4 christos Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
611 1.1 jruoho
612 1.1 jruoho /* Return the new object in the object pointer */
613 1.1 jruoho
614 1.1 jruoho *ObjDescPtr = PkgObjDesc;
615 1.1.1.4 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
616 1.1 jruoho return (AE_OK);
617 1.1 jruoho }
618