1 /******************************************************************************
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __NSREPAIR_C__
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME ("nsrepair")
57 /*******************************************************************************
59 * This module attempts to repair or convert objects returned by the
60 * predefined methods to an object type that is expected, as per the ACPI
61 * specification. The need for this code is dictated by the many machines that
62 * return incorrect types for the standard predefined methods. Performing these
63 * conversions here, in one place, eliminates the need for individual ACPI
64 * device drivers to do the same. Note: Most of these conversions are different
65 * than the internal object conversion routines used for implicit object
68 * The following conversions can be performed as necessary:
76 * Buffer -> Package of Integers
77 * Package -> Package of one Package
79 * Additional conversions that are available:
80 * Convert a null return or zero return value to an EndTag descriptor
81 * Convert an ASCII string to a Unicode buffer
83 * An incorrect standalone object is wrapped with required outer package
85 * Additional possible repairs:
86 * Required package elements that are NULL replaced by Integer/String/Buffer
88 ******************************************************************************/
91 /* Local prototypes */
93 static const ACPI_SIMPLE_REPAIR_INFO *
94 AcpiNsMatchSimpleRepair (
95 ACPI_NAMESPACE_NODE *Node,
101 * Special but simple repairs for some names.
103 * 2nd argument: Unexpected types that can be repaired
105 static const ACPI_SIMPLE_REPAIR_INFO AcpiObjectRepairInfo[] =
107 /* Resource descriptor conversions */
109 { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
110 ACPI_NOT_PACKAGE_ELEMENT,
111 AcpiNsConvertToResource },
112 { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
113 ACPI_NOT_PACKAGE_ELEMENT,
114 AcpiNsConvertToResource },
115 { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
116 ACPI_NOT_PACKAGE_ELEMENT,
117 AcpiNsConvertToResource },
119 /* Unicode conversions */
121 { "_MLS", ACPI_RTYPE_STRING, 1,
122 AcpiNsConvertToUnicode },
123 { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
124 ACPI_NOT_PACKAGE_ELEMENT,
125 AcpiNsConvertToUnicode },
126 { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
130 /*******************************************************************************
132 * FUNCTION: AcpiNsSimpleRepair
134 * PARAMETERS: Info - Method execution information block
135 * ExpectedBtypes - Object types expected
136 * PackageIndex - Index of object within parent package (if
137 * applicable - ACPI_NOT_PACKAGE_ELEMENT
139 * ReturnObjectPtr - Pointer to the object returned from the
140 * evaluation of a method or object
142 * RETURN: Status. AE_OK if repair was successful.
144 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
147 ******************************************************************************/
151 ACPI_EVALUATE_INFO *Info,
152 UINT32 ExpectedBtypes,
154 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
156 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
157 ACPI_OPERAND_OBJECT *NewObject = NULL;
159 const ACPI_SIMPLE_REPAIR_INFO *Predefined;
162 ACPI_FUNCTION_NAME (NsSimpleRepair);
166 * Special repairs for certain names that are in the repair table.
167 * Check if this name is in the list of repairable names.
169 Predefined = AcpiNsMatchSimpleRepair (Info->Node,
170 Info->ReturnBtype, PackageIndex);
175 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
176 ACPI_WARN_ALWAYS, "Missing expected return value"));
179 Status = Predefined->ObjectConverter (ReturnObject, &NewObject);
180 if (ACPI_FAILURE (Status))
182 /* A fatal error occurred during a conversion */
184 ACPI_EXCEPTION ((AE_INFO, Status,
185 "During return object analysis"));
195 * Do not perform simple object repair unless the return type is not
198 if (Info->ReturnBtype & ExpectedBtypes)
204 * At this point, we know that the type of the returned object was not
205 * one of the expected types for this predefined name. Attempt to
206 * repair the object by converting it to one of the expected object
207 * types for this predefined name.
211 * If there is no return value, check if we require a return value for
212 * this predefined name. Either one return value is expected, or none,
213 * for both methods and other objects.
215 * Try to fix if there was no return object. Warning if failed to fix.
219 if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
221 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
223 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
224 ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
226 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
227 PackageIndex, ReturnObjectPtr);
228 if (ACPI_SUCCESS (Status))
230 return (AE_OK); /* Repair was successful */
235 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
236 ACPI_WARN_ALWAYS, "Missing expected return value"));
239 return (AE_AML_NO_RETURN_VALUE);
243 if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
245 Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
246 if (ACPI_SUCCESS (Status))
251 if (ExpectedBtypes & ACPI_RTYPE_STRING)
253 Status = AcpiNsConvertToString (ReturnObject, &NewObject);
254 if (ACPI_SUCCESS (Status))
259 if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
261 Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
262 if (ACPI_SUCCESS (Status))
267 if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
270 * A package is expected. We will wrap the existing object with a
271 * new package object. It is often the case that if a variable-length
272 * package is required, but there is only a single object needed, the
273 * BIOS will return that object instead of wrapping it with a Package
274 * object. Note: after the wrapping, the package will be validated
275 * for correct contents (expected object type or types).
277 Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
278 if (ACPI_SUCCESS (Status))
281 * The original object just had its reference count
282 * incremented for being inserted into the new package.
284 *ReturnObjectPtr = NewObject; /* New Package object */
285 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
290 /* We cannot repair this object */
292 return (AE_AML_OPERAND_TYPE);
297 /* Object was successfully repaired */
299 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
302 * The original object is a package element. We need to
303 * decrement the reference count of the original object,
304 * for removing it from the package.
306 * However, if the original object was just wrapped with a
307 * package object as part of the repair, we don't need to
308 * change the reference count.
310 if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
312 NewObject->Common.ReferenceCount =
313 ReturnObject->Common.ReferenceCount;
315 if (ReturnObject->Common.ReferenceCount > 1)
317 ReturnObject->Common.ReferenceCount--;
321 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
322 "%s: Converted %s to expected %s at Package index %u\n",
323 Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
324 AcpiUtGetObjectTypeName (NewObject), PackageIndex));
328 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
329 "%s: Converted %s to expected %s\n",
330 Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
331 AcpiUtGetObjectTypeName (NewObject)));
334 /* Delete old object, install the new return object */
336 AcpiUtRemoveReference (ReturnObject);
337 *ReturnObjectPtr = NewObject;
338 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
343 /******************************************************************************
345 * FUNCTION: AcpiNsMatchSimpleRepair
347 * PARAMETERS: Node - Namespace node for the method/object
348 * ReturnBtype - Object type that was returned
349 * PackageIndex - Index of object within parent package (if
350 * applicable - ACPI_NOT_PACKAGE_ELEMENT
353 * RETURN: Pointer to entry in repair table. NULL indicates not found.
355 * DESCRIPTION: Check an object name against the repairable object list.
357 *****************************************************************************/
359 static const ACPI_SIMPLE_REPAIR_INFO *
360 AcpiNsMatchSimpleRepair (
361 ACPI_NAMESPACE_NODE *Node,
365 const ACPI_SIMPLE_REPAIR_INFO *ThisName;
368 /* Search info table for a repairable predefined method/object name */
370 ThisName = AcpiObjectRepairInfo;
371 while (ThisName->ObjectConverter)
373 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
375 /* Check if we can actually repair this name/type combination */
377 if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
378 (PackageIndex == ThisName->PackageIndex))
388 return (NULL); /* Name was not found in the repair table */
392 /*******************************************************************************
394 * FUNCTION: AcpiNsRepairNullElement
396 * PARAMETERS: Info - Method execution information block
397 * ExpectedBtypes - Object types expected
398 * PackageIndex - Index of object within parent package (if
399 * applicable - ACPI_NOT_PACKAGE_ELEMENT
401 * ReturnObjectPtr - Pointer to the object returned from the
402 * evaluation of a method or object
404 * RETURN: Status. AE_OK if repair was successful.
406 * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
408 ******************************************************************************/
411 AcpiNsRepairNullElement (
412 ACPI_EVALUATE_INFO *Info,
413 UINT32 ExpectedBtypes,
415 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
417 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
418 ACPI_OPERAND_OBJECT *NewObject;
421 ACPI_FUNCTION_NAME (NsRepairNullElement);
424 /* No repair needed if return object is non-NULL */
432 * Attempt to repair a NULL element of a Package object. This applies to
433 * predefined names that return a fixed-length package and each element
434 * is required. It does not apply to variable-length packages where NULL
435 * elements are allowed, especially at the end of the package.
437 if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
439 /* Need an Integer - create a zero-value integer */
441 NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
443 else if (ExpectedBtypes & ACPI_RTYPE_STRING)
445 /* Need a String - create a NULL string */
447 NewObject = AcpiUtCreateStringObject (0);
449 else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
451 /* Need a Buffer - create a zero-length buffer */
453 NewObject = AcpiUtCreateBufferObject (0);
457 /* Error for all other expected types */
459 return (AE_AML_OPERAND_TYPE);
464 return (AE_NO_MEMORY);
467 /* Set the reference count according to the parent Package object */
469 NewObject->Common.ReferenceCount = Info->ParentPackage->Common.ReferenceCount;
471 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
472 "%s: Converted NULL package element to expected %s at index %u\n",
473 Info->FullPathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
475 *ReturnObjectPtr = NewObject;
476 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
481 /******************************************************************************
483 * FUNCTION: AcpiNsRemoveNullElements
485 * PARAMETERS: Info - Method execution information block
486 * PackageType - An AcpiReturnPackageTypes value
487 * ObjDesc - A Package object
491 * DESCRIPTION: Remove all NULL package elements from packages that contain
492 * a variable number of subpackages. For these types of
493 * packages, NULL elements can be safely removed.
495 *****************************************************************************/
498 AcpiNsRemoveNullElements (
499 ACPI_EVALUATE_INFO *Info,
501 ACPI_OPERAND_OBJECT *ObjDesc)
503 ACPI_OPERAND_OBJECT **Source;
504 ACPI_OPERAND_OBJECT **Dest;
510 ACPI_FUNCTION_NAME (NsRemoveNullElements);
514 * We can safely remove all NULL elements from these package types:
515 * PTYPE1_VAR packages contain a variable number of simple data types.
516 * PTYPE2 packages contain a variable number of subpackages.
520 case ACPI_PTYPE1_VAR:
522 case ACPI_PTYPE2_COUNT:
523 case ACPI_PTYPE2_PKG_COUNT:
524 case ACPI_PTYPE2_FIXED:
525 case ACPI_PTYPE2_MIN:
526 case ACPI_PTYPE2_REV_FIXED:
527 case ACPI_PTYPE2_FIX_VAR:
532 case ACPI_PTYPE1_FIXED:
533 case ACPI_PTYPE1_OPTION:
537 Count = ObjDesc->Package.Count;
540 Source = ObjDesc->Package.Elements;
543 /* Examine all elements of the package object, remove nulls */
545 for (i = 0; i < Count; i++)
559 /* Update parent package if any null elements were removed */
561 if (NewCount < Count)
563 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
564 "%s: Found and removed %u NULL elements\n",
565 Info->FullPathname, (Count - NewCount)));
567 /* NULL terminate list and update the package count */
570 ObjDesc->Package.Count = NewCount;
575 /*******************************************************************************
577 * FUNCTION: AcpiNsWrapWithPackage
579 * PARAMETERS: Info - Method execution information block
580 * OriginalObject - Pointer to the object to repair.
581 * ObjDescPtr - The new package object is returned here
583 * RETURN: Status, new object in *ObjDescPtr
585 * DESCRIPTION: Repair a common problem with objects that are defined to
586 * return a variable-length Package of sub-objects. If there is
587 * only one sub-object, some BIOS code mistakenly simply declares
588 * the single object instead of a Package with one sub-object.
589 * This function attempts to repair this error by wrapping a
590 * Package object around the original object, creating the
591 * correct and expected Package with one sub-object.
593 * Names that can be repaired in this manner include:
594 * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
595 * _BCL, _DOD, _FIX, _Sx
597 ******************************************************************************/
600 AcpiNsWrapWithPackage (
601 ACPI_EVALUATE_INFO *Info,
602 ACPI_OPERAND_OBJECT *OriginalObject,
603 ACPI_OPERAND_OBJECT **ObjDescPtr)
605 ACPI_OPERAND_OBJECT *PkgObjDesc;
608 ACPI_FUNCTION_NAME (NsWrapWithPackage);
612 * Create the new outer package and populate it. The new package will
613 * have a single element, the lone sub-object.
615 PkgObjDesc = AcpiUtCreatePackageObject (1);
618 return (AE_NO_MEMORY);
621 PkgObjDesc->Package.Elements[0] = OriginalObject;
623 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
624 "%s: Wrapped %s with expected Package object\n",
625 Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
627 /* Return the new object in the object pointer */
629 *ObjDescPtr = PkgObjDesc;
630 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;