Commit 6a99b1c9 authored by Bob Moore's avatar Bob Moore Committed by Len Brown

ACPICA: Object repair code: Support to add Package wrappers

Repair a common problem with objects that are defined to return
a variable-length Package of sub-objects. If there is only one
sub-object, some BIOS code mistakenly simply declares the single
object instead of a Package with one sub-object.  This function
attempts to repair this error by wrapping a Package object around
the original object, creating the correct and expected Package
with one sub-object.
Signed-off-by: default avatarBob Moore <robert.moore@intel.com>
Signed-off-by: default avatarLin Ming <ming.m.lin@intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent a2ef5c4f
...@@ -370,6 +370,7 @@ struct acpi_predefined_data { ...@@ -370,6 +370,7 @@ struct acpi_predefined_data {
/* Defines for Flags field above */ /* Defines for Flags field above */
#define ACPI_OBJECT_REPAIRED 1 #define ACPI_OBJECT_REPAIRED 1
#define ACPI_OBJECT_WRAPPED 2
/* /*
* Bitmapped return value types * Bitmapped return value types
......
...@@ -283,8 +283,9 @@ acpi_ns_repair_object(struct acpi_predefined_data *data, ...@@ -283,8 +283,9 @@ acpi_ns_repair_object(struct acpi_predefined_data *data,
union acpi_operand_object **return_object_ptr); union acpi_operand_object **return_object_ptr);
acpi_status acpi_status
acpi_ns_repair_package_list(struct acpi_predefined_data *data, acpi_ns_wrap_with_package(struct acpi_predefined_data *data,
union acpi_operand_object **obj_desc_ptr); union acpi_operand_object *original_object,
union acpi_operand_object **obj_desc_ptr);
acpi_status acpi_status
acpi_ns_repair_null_element(struct acpi_predefined_data *data, acpi_ns_repair_null_element(struct acpi_predefined_data *data,
......
...@@ -638,8 +638,8 @@ acpi_ns_check_package(struct acpi_predefined_data *data, ...@@ -638,8 +638,8 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
/* Create the new outer package and populate it */ /* Create the new outer package and populate it */
status = status =
acpi_ns_repair_package_list(data, acpi_ns_wrap_with_package(data, *elements,
return_object_ptr); return_object_ptr);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
return (status); return (status);
} }
......
...@@ -71,11 +71,10 @@ ACPI_MODULE_NAME("nsrepair") ...@@ -71,11 +71,10 @@ ACPI_MODULE_NAME("nsrepair")
* Buffer -> String * Buffer -> String
* Buffer -> Package of Integers * Buffer -> Package of Integers
* Package -> Package of one Package * Package -> Package of one Package
* An incorrect standalone object is wrapped with required outer package
* *
* Additional possible repairs: * Additional possible repairs:
*
* Required package elements that are NULL replaced by Integer/String/Buffer * Required package elements that are NULL replaced by Integer/String/Buffer
* Incorrect standalone package wrapped with required outer package
* *
******************************************************************************/ ******************************************************************************/
/* Local prototypes */ /* Local prototypes */
...@@ -91,10 +90,6 @@ static acpi_status ...@@ -91,10 +90,6 @@ static acpi_status
acpi_ns_convert_to_buffer(union acpi_operand_object *original_object, acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
union acpi_operand_object **return_object); union acpi_operand_object **return_object);
static acpi_status
acpi_ns_convert_to_package(union acpi_operand_object *original_object,
union acpi_operand_object **return_object);
/******************************************************************************* /*******************************************************************************
* *
* FUNCTION: acpi_ns_repair_object * FUNCTION: acpi_ns_repair_object
...@@ -151,9 +146,24 @@ acpi_ns_repair_object(struct acpi_predefined_data *data, ...@@ -151,9 +146,24 @@ acpi_ns_repair_object(struct acpi_predefined_data *data,
} }
} }
if (expected_btypes & ACPI_RTYPE_PACKAGE) { if (expected_btypes & ACPI_RTYPE_PACKAGE) {
status = acpi_ns_convert_to_package(return_object, &new_object); /*
* A package is expected. We will wrap the existing object with a
* new package object. It is often the case that if a variable-length
* package is required, but there is only a single object needed, the
* BIOS will return that object instead of wrapping it with a Package
* object. Note: after the wrapping, the package will be validated
* for correct contents (expected object type or types).
*/
status =
acpi_ns_wrap_with_package(data, return_object, &new_object);
if (ACPI_SUCCESS(status)) { if (ACPI_SUCCESS(status)) {
goto object_repaired; /*
* The original object just had its reference count
* incremented for being inserted into the new package.
*/
*return_object_ptr = new_object; /* New Package object */
data->flags |= ACPI_OBJECT_REPAIRED;
return (AE_OK);
} }
} }
...@@ -165,22 +175,27 @@ acpi_ns_repair_object(struct acpi_predefined_data *data, ...@@ -165,22 +175,27 @@ acpi_ns_repair_object(struct acpi_predefined_data *data,
/* Object was successfully repaired */ /* Object was successfully repaired */
/*
* If the original object is a package element, we need to:
* 1. Set the reference count of the new object to match the
* reference count of the old object.
* 2. Decrement the reference count of the original object.
*/
if (package_index != ACPI_NOT_PACKAGE_ELEMENT) { if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
new_object->common.reference_count = /*
return_object->common.reference_count; * The original object is a package element. We need to
* decrement the reference count of the original object,
* for removing it from the package.
*
* However, if the original object was just wrapped with a
* package object as part of the repair, we don't need to
* change the reference count.
*/
if (!(data->flags & ACPI_OBJECT_WRAPPED)) {
new_object->common.reference_count =
return_object->common.reference_count;
if (return_object->common.reference_count > 1) { if (return_object->common.reference_count > 1) {
return_object->common.reference_count--; return_object->common.reference_count--;
}
} }
ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
"%s: Converted %s to expected %s at index %u\n", "%s: Converted %s to expected %s at Package index %u\n",
data->pathname, data->pathname,
acpi_ut_get_object_type_name(return_object), acpi_ut_get_object_type_name(return_object),
acpi_ut_get_object_type_name(new_object), acpi_ut_get_object_type_name(new_object),
...@@ -451,65 +466,6 @@ acpi_ns_convert_to_buffer(union acpi_operand_object *original_object, ...@@ -451,65 +466,6 @@ acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
return (AE_OK); return (AE_OK);
} }
/*******************************************************************************
*
* FUNCTION: acpi_ns_convert_to_package
*
* PARAMETERS: original_object - Object to be converted
* return_object - Where the new converted object is returned
*
* RETURN: Status. AE_OK if conversion was successful.
*
* DESCRIPTION: Attempt to convert a Buffer object to a Package. Each byte of
* the buffer is converted to a single integer package element.
*
******************************************************************************/
static acpi_status
acpi_ns_convert_to_package(union acpi_operand_object *original_object,
union acpi_operand_object **return_object)
{
union acpi_operand_object *new_object;
union acpi_operand_object **elements;
u32 length;
u8 *buffer;
switch (original_object->common.type) {
case ACPI_TYPE_BUFFER:
/* Buffer-to-Package conversion */
length = original_object->buffer.length;
new_object = acpi_ut_create_package_object(length);
if (!new_object) {
return (AE_NO_MEMORY);
}
/* Convert each buffer byte to an integer package element */
elements = new_object->package.elements;
buffer = original_object->buffer.pointer;
while (length--) {
*elements =
acpi_ut_create_integer_object((u64) *buffer);
if (!*elements) {
acpi_ut_remove_reference(new_object);
return (AE_NO_MEMORY);
}
elements++;
buffer++;
}
break;
default:
return (AE_AML_OPERAND_TYPE);
}
*return_object = new_object;
return (AE_OK);
}
/******************************************************************************* /*******************************************************************************
* *
* FUNCTION: acpi_ns_repair_null_element * FUNCTION: acpi_ns_repair_null_element
...@@ -677,55 +633,56 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data, ...@@ -677,55 +633,56 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
/******************************************************************************* /*******************************************************************************
* *
* FUNCTION: acpi_ns_repair_package_list * FUNCTION: acpi_ns_wrap_with_package
* *
* PARAMETERS: Data - Pointer to validation data structure * PARAMETERS: Data - Pointer to validation data structure
* obj_desc_ptr - Pointer to the object to repair. The new * original_object - Pointer to the object to repair.
* package object is returned here, * obj_desc_ptr - The new package object is returned here
* overwriting the old object.
* *
* RETURN: Status, new object in *obj_desc_ptr * RETURN: Status, new object in *obj_desc_ptr
* *
* DESCRIPTION: Repair a common problem with objects that are defined to return * DESCRIPTION: Repair a common problem with objects that are defined to
* a variable-length Package of Packages. If the variable-length * return a variable-length Package of sub-objects. If there is
* is one, some BIOS code mistakenly simply declares a single * only one sub-object, some BIOS code mistakenly simply declares
* Package instead of a Package with one sub-Package. This * the single object instead of a Package with one sub-object.
* function attempts to repair this error by wrapping a Package * This function attempts to repair this error by wrapping a
* object around the original Package, creating the correct * Package object around the original object, creating the
* Package with one sub-Package. * correct and expected Package with one sub-object.
* *
* Names that can be repaired in this manner include: * Names that can be repaired in this manner include:
* _ALR, _CSD, _HPX, _MLS, _PRT, _PSS, _TRT, TSS * _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
* _BCL, _DOD, _FIX, _Sx
* *
******************************************************************************/ ******************************************************************************/
acpi_status acpi_status
acpi_ns_repair_package_list(struct acpi_predefined_data *data, acpi_ns_wrap_with_package(struct acpi_predefined_data *data,
union acpi_operand_object **obj_desc_ptr) union acpi_operand_object *original_object,
union acpi_operand_object **obj_desc_ptr)
{ {
union acpi_operand_object *pkg_obj_desc; union acpi_operand_object *pkg_obj_desc;
ACPI_FUNCTION_NAME(ns_repair_package_list); ACPI_FUNCTION_NAME(ns_wrap_with_package);
/* /*
* Create the new outer package and populate it. The new package will * Create the new outer package and populate it. The new package will
* have a single element, the lone subpackage. * have a single element, the lone sub-object.
*/ */
pkg_obj_desc = acpi_ut_create_package_object(1); pkg_obj_desc = acpi_ut_create_package_object(1);
if (!pkg_obj_desc) { if (!pkg_obj_desc) {
return (AE_NO_MEMORY); return (AE_NO_MEMORY);
} }
pkg_obj_desc->package.elements[0] = *obj_desc_ptr; pkg_obj_desc->package.elements[0] = original_object;
ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
"%s: Wrapped %s with expected Package object\n",
data->pathname,
acpi_ut_get_object_type_name(original_object)));
/* Return the new object in the object pointer */ /* Return the new object in the object pointer */
*obj_desc_ptr = pkg_obj_desc; *obj_desc_ptr = pkg_obj_desc;
data->flags |= ACPI_OBJECT_REPAIRED; data->flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
"%s: Repaired incorrectly formed Package\n",
data->pathname));
return (AE_OK); return (AE_OK);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment