1 /******************************************************************************
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 * Exit now if there is no return object. Warning if one was expected.
219 if (ExpectedBtypes
&& (!(ExpectedBtypes
& ACPI_RTYPE_NONE
)))
221 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
,
222 ACPI_WARN_ALWAYS
, "Missing expected return value"));
224 return (AE_AML_NO_RETURN_VALUE
);
228 if (ExpectedBtypes
& ACPI_RTYPE_INTEGER
)
230 Status
= AcpiNsConvertToInteger (ReturnObject
, &NewObject
);
231 if (ACPI_SUCCESS (Status
))
236 if (ExpectedBtypes
& ACPI_RTYPE_STRING
)
238 Status
= AcpiNsConvertToString (ReturnObject
, &NewObject
);
239 if (ACPI_SUCCESS (Status
))
244 if (ExpectedBtypes
& ACPI_RTYPE_BUFFER
)
246 Status
= AcpiNsConvertToBuffer (ReturnObject
, &NewObject
);
247 if (ACPI_SUCCESS (Status
))
252 if (ExpectedBtypes
& ACPI_RTYPE_PACKAGE
)
255 * A package is expected. We will wrap the existing object with a
256 * new package object. It is often the case that if a variable-length
257 * package is required, but there is only a single object needed, the
258 * BIOS will return that object instead of wrapping it with a Package
259 * object. Note: after the wrapping, the package will be validated
260 * for correct contents (expected object type or types).
262 Status
= AcpiNsWrapWithPackage (Info
, ReturnObject
, &NewObject
);
263 if (ACPI_SUCCESS (Status
))
266 * The original object just had its reference count
267 * incremented for being inserted into the new package.
269 *ReturnObjectPtr
= NewObject
; /* New Package object */
270 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
275 /* We cannot repair this object */
277 return (AE_AML_OPERAND_TYPE
);
282 /* Object was successfully repaired */
284 if (PackageIndex
!= ACPI_NOT_PACKAGE_ELEMENT
)
287 * The original object is a package element. We need to
288 * decrement the reference count of the original object,
289 * for removing it from the package.
291 * However, if the original object was just wrapped with a
292 * package object as part of the repair, we don't need to
293 * change the reference count.
295 if (!(Info
->ReturnFlags
& ACPI_OBJECT_WRAPPED
))
297 NewObject
->Common
.ReferenceCount
=
298 ReturnObject
->Common
.ReferenceCount
;
300 if (ReturnObject
->Common
.ReferenceCount
> 1)
302 ReturnObject
->Common
.ReferenceCount
--;
306 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
307 "%s: Converted %s to expected %s at Package index %u\n",
308 Info
->FullPathname
, AcpiUtGetObjectTypeName (ReturnObject
),
309 AcpiUtGetObjectTypeName (NewObject
), PackageIndex
));
313 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
314 "%s: Converted %s to expected %s\n",
315 Info
->FullPathname
, AcpiUtGetObjectTypeName (ReturnObject
),
316 AcpiUtGetObjectTypeName (NewObject
)));
319 /* Delete old object, install the new return object */
321 AcpiUtRemoveReference (ReturnObject
);
322 *ReturnObjectPtr
= NewObject
;
323 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
328 /******************************************************************************
330 * FUNCTION: AcpiNsMatchSimpleRepair
332 * PARAMETERS: Node - Namespace node for the method/object
333 * ReturnBtype - Object type that was returned
334 * PackageIndex - Index of object within parent package (if
335 * applicable - ACPI_NOT_PACKAGE_ELEMENT
338 * RETURN: Pointer to entry in repair table. NULL indicates not found.
340 * DESCRIPTION: Check an object name against the repairable object list.
342 *****************************************************************************/
344 static const ACPI_SIMPLE_REPAIR_INFO
*
345 AcpiNsMatchSimpleRepair (
346 ACPI_NAMESPACE_NODE
*Node
,
350 const ACPI_SIMPLE_REPAIR_INFO
*ThisName
;
353 /* Search info table for a repairable predefined method/object name */
355 ThisName
= AcpiObjectRepairInfo
;
356 while (ThisName
->ObjectConverter
)
358 if (ACPI_COMPARE_NAME (Node
->Name
.Ascii
, ThisName
->Name
))
360 /* Check if we can actually repair this name/type combination */
362 if ((ReturnBtype
& ThisName
->UnexpectedBtypes
) &&
363 (PackageIndex
== ThisName
->PackageIndex
))
373 return (NULL
); /* Name was not found in the repair table */
377 /*******************************************************************************
379 * FUNCTION: AcpiNsRepairNullElement
381 * PARAMETERS: Info - Method execution information block
382 * ExpectedBtypes - Object types expected
383 * PackageIndex - Index of object within parent package (if
384 * applicable - ACPI_NOT_PACKAGE_ELEMENT
386 * ReturnObjectPtr - Pointer to the object returned from the
387 * evaluation of a method or object
389 * RETURN: Status. AE_OK if repair was successful.
391 * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
393 ******************************************************************************/
396 AcpiNsRepairNullElement (
397 ACPI_EVALUATE_INFO
*Info
,
398 UINT32 ExpectedBtypes
,
400 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
402 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
403 ACPI_OPERAND_OBJECT
*NewObject
;
406 ACPI_FUNCTION_NAME (NsRepairNullElement
);
409 /* No repair needed if return object is non-NULL */
417 * Attempt to repair a NULL element of a Package object. This applies to
418 * predefined names that return a fixed-length package and each element
419 * is required. It does not apply to variable-length packages where NULL
420 * elements are allowed, especially at the end of the package.
422 if (ExpectedBtypes
& ACPI_RTYPE_INTEGER
)
424 /* Need an Integer - create a zero-value integer */
426 NewObject
= AcpiUtCreateIntegerObject ((UINT64
) 0);
428 else if (ExpectedBtypes
& ACPI_RTYPE_STRING
)
430 /* Need a String - create a NULL string */
432 NewObject
= AcpiUtCreateStringObject (0);
434 else if (ExpectedBtypes
& ACPI_RTYPE_BUFFER
)
436 /* Need a Buffer - create a zero-length buffer */
438 NewObject
= AcpiUtCreateBufferObject (0);
442 /* Error for all other expected types */
444 return (AE_AML_OPERAND_TYPE
);
449 return (AE_NO_MEMORY
);
452 /* Set the reference count according to the parent Package object */
454 NewObject
->Common
.ReferenceCount
= Info
->ParentPackage
->Common
.ReferenceCount
;
456 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
457 "%s: Converted NULL package element to expected %s at index %u\n",
458 Info
->FullPathname
, AcpiUtGetObjectTypeName (NewObject
), PackageIndex
));
460 *ReturnObjectPtr
= NewObject
;
461 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
;
466 /******************************************************************************
468 * FUNCTION: AcpiNsRemoveNullElements
470 * PARAMETERS: Info - Method execution information block
471 * PackageType - An AcpiReturnPackageTypes value
472 * ObjDesc - A Package object
476 * DESCRIPTION: Remove all NULL package elements from packages that contain
477 * a variable number of sub-packages. For these types of
478 * packages, NULL elements can be safely removed.
480 *****************************************************************************/
483 AcpiNsRemoveNullElements (
484 ACPI_EVALUATE_INFO
*Info
,
486 ACPI_OPERAND_OBJECT
*ObjDesc
)
488 ACPI_OPERAND_OBJECT
**Source
;
489 ACPI_OPERAND_OBJECT
**Dest
;
495 ACPI_FUNCTION_NAME (NsRemoveNullElements
);
499 * We can safely remove all NULL elements from these package types:
500 * PTYPE1_VAR packages contain a variable number of simple data types.
501 * PTYPE2 packages contain a variable number of sub-packages.
505 case ACPI_PTYPE1_VAR
:
507 case ACPI_PTYPE2_COUNT
:
508 case ACPI_PTYPE2_PKG_COUNT
:
509 case ACPI_PTYPE2_FIXED
:
510 case ACPI_PTYPE2_MIN
:
511 case ACPI_PTYPE2_REV_FIXED
:
512 case ACPI_PTYPE2_FIX_VAR
:
517 case ACPI_PTYPE1_FIXED
:
518 case ACPI_PTYPE1_OPTION
:
522 Count
= ObjDesc
->Package
.Count
;
525 Source
= ObjDesc
->Package
.Elements
;
528 /* Examine all elements of the package object, remove nulls */
530 for (i
= 0; i
< Count
; i
++)
544 /* Update parent package if any null elements were removed */
546 if (NewCount
< Count
)
548 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
549 "%s: Found and removed %u NULL elements\n",
550 Info
->FullPathname
, (Count
- NewCount
)));
552 /* NULL terminate list and update the package count */
555 ObjDesc
->Package
.Count
= NewCount
;
560 /*******************************************************************************
562 * FUNCTION: AcpiNsWrapWithPackage
564 * PARAMETERS: Info - Method execution information block
565 * OriginalObject - Pointer to the object to repair.
566 * ObjDescPtr - The new package object is returned here
568 * RETURN: Status, new object in *ObjDescPtr
570 * DESCRIPTION: Repair a common problem with objects that are defined to
571 * return a variable-length Package of sub-objects. If there is
572 * only one sub-object, some BIOS code mistakenly simply declares
573 * the single object instead of a Package with one sub-object.
574 * This function attempts to repair this error by wrapping a
575 * Package object around the original object, creating the
576 * correct and expected Package with one sub-object.
578 * Names that can be repaired in this manner include:
579 * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
580 * _BCL, _DOD, _FIX, _Sx
582 ******************************************************************************/
585 AcpiNsWrapWithPackage (
586 ACPI_EVALUATE_INFO
*Info
,
587 ACPI_OPERAND_OBJECT
*OriginalObject
,
588 ACPI_OPERAND_OBJECT
**ObjDescPtr
)
590 ACPI_OPERAND_OBJECT
*PkgObjDesc
;
593 ACPI_FUNCTION_NAME (NsWrapWithPackage
);
597 * Create the new outer package and populate it. The new package will
598 * have a single element, the lone sub-object.
600 PkgObjDesc
= AcpiUtCreatePackageObject (1);
603 return (AE_NO_MEMORY
);
606 PkgObjDesc
->Package
.Elements
[0] = OriginalObject
;
608 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
609 "%s: Wrapped %s with expected Package object\n",
610 Info
->FullPathname
, AcpiUtGetObjectTypeName (OriginalObject
)));
612 /* Return the new object in the object pointer */
614 *ObjDescPtr
= PkgObjDesc
;
615 Info
->ReturnFlags
|= ACPI_OBJECT_REPAIRED
| ACPI_OBJECT_WRAPPED
;