Add mechanism for early object repairs on a per-name basis.

Adds the framework to allow object repairs very early in the
return object analysis. Enables repairs like string->unicode,
etc. Bob Moore, Lv Zheng.
This commit is contained in:
Robert Moore 2013-02-06 10:18:09 -08:00
parent 0197232c08
commit 6cb3c06d1b
6 changed files with 233 additions and 88 deletions

View File

@ -159,6 +159,11 @@ AcpiNsGetExpectedTypes (
char *Buffer,
UINT32 ExpectedBtypes);
static UINT32
AcpiNsGetBitmappedType (
ACPI_OPERAND_OBJECT *ReturnObject);
/*
* Names for the types that can be returned by the predefined objects.
* Used for warning messages. Must be in the same order as the ACPI_RTYPEs
@ -196,7 +201,6 @@ AcpiNsCheckPredefinedNames (
ACPI_STATUS ReturnStatus,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_STATUS Status = AE_OK;
const ACPI_PREDEFINED_INFO *Predefined;
char *Pathname;
@ -238,26 +242,6 @@ AcpiNsCheckPredefinedNames (
goto Cleanup;
}
/*
* If there is no return value, check if we require a return value for
* this predefined name. Either one return value is expected, or none,
* for both methods and other objects.
*
* Exit now if there is no return object. Warning if one was expected.
*/
if (!ReturnObject)
{
if ((Predefined->Info.ExpectedBtypes) &&
(!(Predefined->Info.ExpectedBtypes & ACPI_RTYPE_NONE)))
{
ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
"Missing expected return value"));
Status = AE_AML_NO_RETURN_VALUE;
}
goto Cleanup;
}
/*
* Return value validation and possible repair.
*
@ -519,30 +503,13 @@ AcpiNsCheckObjectType (
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_STATUS Status = AE_OK;
UINT32 ReturnBtype;
char TypeBuffer[48]; /* Room for 5 types */
/*
* If we get a NULL ReturnObject here, it is a NULL package element.
* Since all extraneous NULL package elements were removed earlier by a
* call to AcpiNsRemoveNullElements, this is an unexpected NULL element.
* We will attempt to repair it.
*/
if (!ReturnObject)
{
Status = AcpiNsRepairNullElement (Data, ExpectedBtypes,
PackageIndex, ReturnObjectPtr);
if (ACPI_SUCCESS (Status))
{
return (AE_OK); /* Repair was successful */
}
goto TypeErrorExit;
}
/* A Namespace node should not get here, but make sure */
if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
if (ReturnObject &&
ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Invalid return type - Found a Namespace node [%4.4s] type %s",
@ -559,56 +526,26 @@ AcpiNsCheckObjectType (
* from all of the predefined names (including elements of returned
* packages)
*/
switch (ReturnObject->Common.Type)
Data->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject);
if (Data->ReturnBtype == ACPI_RTYPE_ANY)
{
case ACPI_TYPE_INTEGER:
ReturnBtype = ACPI_RTYPE_INTEGER;
break;
case ACPI_TYPE_BUFFER:
ReturnBtype = ACPI_RTYPE_BUFFER;
break;
case ACPI_TYPE_STRING:
ReturnBtype = ACPI_RTYPE_STRING;
break;
case ACPI_TYPE_PACKAGE:
ReturnBtype = ACPI_RTYPE_PACKAGE;
break;
case ACPI_TYPE_LOCAL_REFERENCE:
ReturnBtype = ACPI_RTYPE_REFERENCE;
break;
default:
/* Not one of the supported objects, must be incorrect */
goto TypeErrorExit;
}
/* Is the object one of the expected types? */
/* For reference objects, check that the reference type is correct */
if (ReturnBtype & ExpectedBtypes)
if ((Data->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE)
{
/* For reference objects, check that the reference type is correct */
if (ReturnObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
{
Status = AcpiNsCheckReference (Data, ReturnObject);
}
Status = AcpiNsCheckReference (Data, ReturnObject);
return (Status);
}
/* Type mismatch -- attempt repair of the returned object */
/* Attempt simple repair of the returned object if necessary */
Status = AcpiNsRepairObject (Data, ExpectedBtypes,
Status = AcpiNsSimpleRepair (Data, ExpectedBtypes,
PackageIndex, ReturnObjectPtr);
if (ACPI_SUCCESS (Status))
{
return (AE_OK); /* Repair was successful */
}
return (Status);
TypeErrorExit:
@ -676,6 +613,67 @@ AcpiNsCheckReference (
}
/*******************************************************************************
*
* FUNCTION: AcpiNsGetBitmappedType
*
* PARAMETERS: ReturnObject - Object returned from method/obj evaluation
*
* RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
* type is not supported. ACPI_RTYPE_NONE indicates that no
* object was returned (ReturnObject is NULL).
*
* DESCRIPTION: Convert object type into a bitmapped object return type.
*
******************************************************************************/
static UINT32
AcpiNsGetBitmappedType (
ACPI_OPERAND_OBJECT *ReturnObject)
{
UINT32 ReturnBtype;
if (!ReturnObject)
{
return (ACPI_RTYPE_NONE);
}
/* Map ACPI_OBJECT_TYPE to internal bitmapped type */
switch (ReturnObject->Common.Type)
{
case ACPI_TYPE_INTEGER:
ReturnBtype = ACPI_RTYPE_INTEGER;
break;
case ACPI_TYPE_BUFFER:
ReturnBtype = ACPI_RTYPE_BUFFER;
break;
case ACPI_TYPE_STRING:
ReturnBtype = ACPI_RTYPE_STRING;
break;
case ACPI_TYPE_PACKAGE:
ReturnBtype = ACPI_RTYPE_PACKAGE;
break;
case ACPI_TYPE_LOCAL_REFERENCE:
ReturnBtype = ACPI_RTYPE_REFERENCE;
break;
default:
/* Not one of the supported objects, must be incorrect */
ReturnBtype = ACPI_RTYPE_ANY;
break;
}
return (ReturnBtype);
}
/*******************************************************************************
*
* FUNCTION: AcpiNsGetExpectedTypes

View File

@ -120,6 +120,7 @@
#include "acnamesp.h"
#include "acinterp.h"
#include "acpredef.h"
#include "amlresrc.h"
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsrepair")
@ -146,6 +147,11 @@
* Buffer -> String
* Buffer -> Package of Integers
* Package -> Package of one Package
*
* Additional conversions that are available:
* Convert a null return or zero return value to an EndTag descriptor
* Convert an ASCII string to a Unicode buffer
*
* An incorrect standalone object is wrapped with required outer package
*
* Additional possible repairs:
@ -171,10 +177,27 @@ AcpiNsConvertToBuffer (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject);
static const ACPI_SIMPLE_REPAIR_INFO *
AcpiNsMatchSimpleRepair (
ACPI_NAMESPACE_NODE *Node,
UINT32 ReturnBtype,
UINT32 PackageIndex);
/*
* Special but simple repairs for some names.
*
* 2nd argument: Unexpected types that can be repaired
*/
static const ACPI_SIMPLE_REPAIR_INFO AcpiObjectRepairInfo[] =
{
{ {0,0,0,0}, 0, 0, NULL } /* Table terminator */
};
/*******************************************************************************
*
* FUNCTION: AcpiNsRepairObject
* FUNCTION: AcpiNsSimpleRepair
*
* PARAMETERS: Data - Pointer to validation data structure
* ExpectedBtypes - Object types expected
@ -192,26 +215,84 @@ AcpiNsConvertToBuffer (
******************************************************************************/
ACPI_STATUS
AcpiNsRepairObject (
AcpiNsSimpleRepair (
ACPI_PREDEFINED_DATA *Data,
UINT32 ExpectedBtypes,
UINT32 PackageIndex,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_OPERAND_OBJECT *NewObject;
ACPI_OPERAND_OBJECT *NewObject = NULL;
ACPI_STATUS Status;
const ACPI_SIMPLE_REPAIR_INFO *Predefined;
ACPI_FUNCTION_NAME (NsRepairObject);
ACPI_FUNCTION_NAME (NsSimpleRepair);
/*
* Special repairs for certain names that are in the repair table.
* Check if this name is in the list of repairable names.
*/
Predefined = AcpiNsMatchSimpleRepair (Data->Node,
Data->ReturnBtype, PackageIndex);
if (Predefined)
{
if (!ReturnObject)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname,
ACPI_WARN_ALWAYS, "Missing expected return value"));
}
Status = Predefined->ObjectConverter (ReturnObject, &NewObject);
if (ACPI_FAILURE (Status))
{
/* A fatal error occurred during a conversion */
ACPI_EXCEPTION ((AE_INFO, Status,
"During return object analysis"));
return (Status);
}
if (NewObject)
{
goto ObjectRepaired;
}
}
/*
* Do not perform simple object repair unless the return type is not
* expected.
*/
if (Data->ReturnBtype & ExpectedBtypes)
{
return (AE_OK);
}
/*
* At this point, we know that the type of the returned object was not
* one of the expected types for this predefined name. Attempt to
* repair the object by converting it to one of the expected object
* types for this predefined name.
*/
/*
* If there is no return value, check if we require a return value for
* this predefined name. Either one return value is expected, or none,
* for both methods and other objects.
*
* Exit now if there is no return object. Warning if one was expected.
*/
if (!ReturnObject)
{
if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname,
ACPI_WARN_ALWAYS, "Missing expected return value"));
return (AE_AML_NO_RETURN_VALUE);
}
}
if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
{
Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
@ -312,6 +393,55 @@ ObjectRepaired:
}
/******************************************************************************
*
* FUNCTION: AcpiNsMatchSimpleRepair
*
* PARAMETERS: Node - Namespace node for the method/object
* ReturnBtype - Object type that was returned
* PackageIndex - Index of object within parent package (if
* applicable - ACPI_NOT_PACKAGE_ELEMENT
* otherwise)
*
* RETURN: Pointer to entry in repair table. NULL indicates not found.
*
* DESCRIPTION: Check an object name against the repairable object list.
*
*****************************************************************************/
static const ACPI_SIMPLE_REPAIR_INFO *
AcpiNsMatchSimpleRepair (
ACPI_NAMESPACE_NODE *Node,
UINT32 ReturnBtype,
UINT32 PackageIndex)
{
const ACPI_SIMPLE_REPAIR_INFO *ThisName;
/* Search info table for a repairable predefined method/object name */
ThisName = AcpiObjectRepairInfo;
while (ThisName->ObjectConverter)
{
if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
{
/* Check if we can actually repair this name/type combination */
if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
(PackageIndex == ThisName->PackageIndex))
{
return (ThisName);
}
return (NULL);
}
ThisName++;
}
return (NULL); /* Name was not found in the repair table */
}
/*******************************************************************************
*
* FUNCTION: AcpiNsConvertToInteger

View File

@ -144,7 +144,7 @@ typedef struct acpi_repair_info
/* Local prototypes */
static const ACPI_REPAIR_INFO *
AcpiNsMatchRepairableName (
AcpiNsMatchComplexRepair (
ACPI_NAMESPACE_NODE *Node);
static ACPI_STATUS
@ -269,7 +269,7 @@ AcpiNsComplexRepairs (
/* Check if this name is in the list of repairable names */
Predefined = AcpiNsMatchRepairableName (Node);
Predefined = AcpiNsMatchComplexRepair (Node);
if (!Predefined)
{
return (ValidateStatus);
@ -282,7 +282,7 @@ AcpiNsComplexRepairs (
/******************************************************************************
*
* FUNCTION: AcpiNsMatchRepairableName
* FUNCTION: AcpiNsMatchComplexRepair
*
* PARAMETERS: Node - Namespace node for the method/object
*
@ -293,7 +293,7 @@ AcpiNsComplexRepairs (
*****************************************************************************/
static const ACPI_REPAIR_INFO *
AcpiNsMatchRepairableName (
AcpiNsMatchComplexRepair (
ACPI_NAMESPACE_NODE *Node)
{
const ACPI_REPAIR_INFO *ThisName;

View File

@ -489,6 +489,7 @@ typedef struct acpi_predefined_data
union acpi_operand_object *ParentPackage;
ACPI_NAMESPACE_NODE *Node;
UINT32 Flags;
UINT32 ReturnBtype;
UINT8 NodeFlags;
} ACPI_PREDEFINED_DATA;
@ -499,6 +500,22 @@ typedef struct acpi_predefined_data
#define ACPI_OBJECT_WRAPPED 2
/* Return object auto-repair info */
typedef ACPI_STATUS (*ACPI_OBJECT_CONVERTER) (
union acpi_operand_object *OriginalObject,
union acpi_operand_object **ConvertedObject);
typedef struct acpi_simple_repair_info
{
char Name[ACPI_NAME_SIZE];
UINT32 UnexpectedBtypes;
UINT32 PackageIndex;
ACPI_OBJECT_CONVERTER ObjectConverter;
} ACPI_SIMPLE_REPAIR_INFO;
/*
* Bitmapped return value types
* Note: the actual data types must be contiguous, a loop in nspredef.c

View File

@ -449,7 +449,7 @@ AcpiNsGetAttachedData (
* predefined methods/objects
*/
ACPI_STATUS
AcpiNsRepairObject (
AcpiNsSimpleRepair (
ACPI_PREDEFINED_DATA *Data,
UINT32 ExpectedBtypes,
UINT32 PackageIndex,

View File

@ -373,7 +373,6 @@ ACPI_TYPED_IDENTIFIER_TABLE AcpiIdentifiers[] = {
{"ACPI_OBJECT_REFERENCE", SRC_TYPE_STRUCT},
{"ACPI_OBJECT_REGION", SRC_TYPE_STRUCT},
{"ACPI_OBJECT_REGION_FIELD", SRC_TYPE_STRUCT},
{"ACPI_OBJECT_REPAIR_INFO", SRC_TYPE_STRUCT},
{"ACPI_OBJECT_STRING", SRC_TYPE_STRUCT},
{"ACPI_OBJECT_THERMAL_ZONE", SRC_TYPE_STRUCT},
{"ACPI_OBJECT_TYPE", SRC_TYPE_SIMPLE},
@ -458,6 +457,7 @@ ACPI_TYPED_IDENTIFIER_TABLE AcpiIdentifiers[] = {
{"ACPI_SCOPE_STATE", SRC_TYPE_STRUCT},
{"ACPI_SEMAPHORE", SRC_TYPE_SIMPLE},
{"ACPI_SIGNAL_FATAL_INFO", SRC_TYPE_STRUCT},
{"ACPI_SIMPLE_REPAIR_INFO", SRC_TYPE_STRUCT},
{"ACPI_SIZE", SRC_TYPE_SIMPLE},
{"ACPI_SLEEP_FUNCTION", SRC_TYPE_SIMPLE},
{"ACPI_SLEEP_FUNCTIONS", SRC_TYPE_STRUCT},