FreeBSD/sys/contrib/dev/acpica/components/hardware/hwxface.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiGetSleepTypeData
 *
 * PARAMETERS:  SleepState          - Numeric sleep state
 *              *SleepTypeA         - Where SLP_TYPa is returned
 *              *SleepTypeB         - Where SLP_TYPb is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
 *              sleep state via the appropriate \_Sx object.
 *
 *  The sleep state package returned from the corresponding \_Sx_ object
 *  must contain at least one integer.
 *
 *  March 2005:
 *  Added support for a package that contains two integers. This
 *  goes against the ACPI specification which defines this object as a
 *  package with one encoded DWORD integer. However, existing practice
 *  by many BIOS vendors is to return a package with 2 or more integer
 *  elements, at least one per sleep type (A/B).
 *
 *  January 2013:
 *  Therefore, we must be prepared to accept a package with either a
 *  single integer or multiple integers.
 *
 *  The single integer DWORD format is as follows:
 *      BYTE 0 - Value for the PM1A SLP_TYP register
 *      BYTE 1 - Value for the PM1B SLP_TYP register
 *      BYTE 2-3 - Reserved
 *
 *  The dual integer format is as follows:
 *      Integer 0 - Value for the PM1A SLP_TYP register
 *      Integer 1 - Value for the PM1A SLP_TYP register
 *
 ******************************************************************************/


Status

Obtain the SLP_TYPa and SLP_TYPb values for the requested
sleep state via the appropriate \_Sx object.

The sleep state package returned from the corresponding \_Sx_ object
must contain at least one integer.

March 2005:
Added support for a package that contains two integers. This
goes against the ACPI specification which defines this object as a
package with one encoded DWORD integer. However, existing practice
by many BIOS vendors is to return a package with 2 or more integer
elements, at least one per sleep type (A/B).

January 2013:
Therefore, we must be prepared to accept a package with either a
single integer or multiple integers.

The single integer DWORD format is as follows:
BYTE 0 - Value for the PM1A SLP_TYP register
BYTE 1 - Value for the PM1B SLP_TYP register
BYTE 2-3 - Reserved

The dual integer format is as follows:
Integer 0 - Value for the PM1A SLP_TYP register
Integer 1 - Value for the PM1A SLP_TYP register
Status Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep state via the appropriate \ _Sx object . The sleep state package returned from the corresponding \ _Sx_ object must contain at least one integer . March 2005 : Added support for a package that contains two integers . This goes against the ACPI specification which defines this object as a package with one encoded DWORD integer . However existing practice by many BIOS vendors is to return a package with 2 or more integer elements at least one per sleep type ( A / B ) . January 2013 : Therefore we must be prepared to accept a package with either a single integer or multiple integers . The single integer DWORD format is as follows : BYTE 0 - Value for the PM1A SLP_TYP register BYTE 1 - Value for the PM1B SLP_TYP register BYTE 2 - 3 - Reserved The dual integer format is as follows : Integer 0 - Value for the PM1A SLP_TYP register Integer 1 - Value for the PM1A SLP_TYP register
ACPI_STATUS
AcpiGetSleepTypeData (
    UINT8                   SleepState,
    UINT8                   *SleepTypeA,
    UINT8                   *SleepTypeB)
{
    ACPI_STATUS             Status;
    ACPI_EVALUATE_INFO      *Info;
    ACPI_OPERAND_OBJECT     **Elements;
    ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
    if ((SleepState > ACPI_S_STATES_MAX) ||
        !SleepTypeA || !SleepTypeB)
    {
        return_ACPI_STATUS (AE_BAD_PARAMETER);
    }
    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    if (!Info)
    {
        return_ACPI_STATUS (AE_NO_MEMORY);
    }
    Info->RelativePathname = AcpiGbl_SleepStateNames[SleepState];
    Status = AcpiNsEvaluate (Info);
    if (ACPI_FAILURE (Status))
    {
        if (Status == AE_NOT_FOUND)
        {
            goto FinalCleanup;
        }
        goto WarningCleanup;
    }
    if (!Info->ReturnObject)
    {
        ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
            Info->RelativePathname));
        Status = AE_AML_NO_RETURN_VALUE;
        goto WarningCleanup;
    }
    if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
    {
        ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
        Status = AE_AML_OPERAND_TYPE;
        goto ReturnValueCleanup;
    }
    Elements = Info->ReturnObject->Package.Elements;
    switch (Info->ReturnObject->Package.Count)
    {
    case 0:
        Status = AE_AML_PACKAGE_LIMIT;
        break;
    case 1:
        if (Elements[0]->Common.Type != ACPI_TYPE_INTEGER)
        {
            Status = AE_AML_OPERAND_TYPE;
            break;
        }
        *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
        *SleepTypeB = (UINT8) (Elements[0]->Integer.Value >> 8);
        break;
    case 2:
    default:
        if ((Elements[0]->Common.Type != ACPI_TYPE_INTEGER) ||
            (Elements[1]->Common.Type != ACPI_TYPE_INTEGER))
        {
            Status = AE_AML_OPERAND_TYPE;
            break;
        }
        *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
        *SleepTypeB = (UINT8) Elements[1]->Integer.Value;
        break;
    }
ReturnValueCleanup:
    AcpiUtRemoveReference (Info->ReturnObject);
WarningCleanup:
    if (ACPI_FAILURE (Status))
    {
        ACPI_EXCEPTION ((AE_INFO, Status,
            "While evaluating Sleep State [%s]",
            Info->RelativePathname));
    }
FinalCleanup:
    ACPI_FREE (Info);
    return_ACPI_STATUS (Status);
}
ACPI_STATUS AcpiGetSleepTypeData ( UINT8 SleepState , UINT8 * SleepTypeA , UINT8 * SleepTypeB ) { ACPI_STATUS Status ; ACPI_EVALUATE_INFO * Info ; ACPI_OPERAND_OBJECT * * Elements ; ACPI_FUNCTION_TRACE ( AcpiGetSleepTypeData ) ; if ( ( SleepState > ACPI_S_STATES_MAX ) || ! SleepTypeA || ! SleepTypeB ) { return_ACPI_STATUS ( AE_BAD_PARAMETER ) ; } Info = ACPI_ALLOCATE_ZEROED ( sizeof ( ACPI_EVALUATE_INFO ) ) ; if ( ! Info ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } Info -> RelativePathname = AcpiGbl_SleepStateNames [ SleepState ] ; Status = AcpiNsEvaluate ( Info ) ; if ( ACPI_FAILURE ( Status ) ) { if ( Status == AE_NOT_FOUND ) { goto FinalCleanup ; } goto WarningCleanup ; } if ( ! Info -> ReturnObject ) { ACPI_ERROR ( ( AE_INFO , " " , Info -> RelativePathname ) ) ; Status = AE_AML_NO_RETURN_VALUE ; goto WarningCleanup ; } if ( Info -> ReturnObject -> Common . Type != ACPI_TYPE_PACKAGE ) { ACPI_ERROR ( ( AE_INFO , " " ) ) ; Status = AE_AML_OPERAND_TYPE ; goto ReturnValueCleanup ; } Elements = Info -> ReturnObject -> Package . Elements ; switch ( Info -> ReturnObject -> Package . Count ) { case 0 : Status = AE_AML_PACKAGE_LIMIT ; break ; case 1 : if ( Elements [ 0 ] -> Common . Type != ACPI_TYPE_INTEGER ) { Status = AE_AML_OPERAND_TYPE ; break ; } * SleepTypeA = ( UINT8 ) Elements [ 0 ] -> Integer . Value ; * SleepTypeB = ( UINT8 ) ( Elements [ 0 ] -> Integer . Value >> 8 ) ; break ; case 2 : default : if ( ( Elements [ 0 ] -> Common . Type != ACPI_TYPE_INTEGER ) || ( Elements [ 1 ] -> Common . Type != ACPI_TYPE_INTEGER ) ) { Status = AE_AML_OPERAND_TYPE ; break ; } * SleepTypeA = ( UINT8 ) Elements [ 0 ] -> Integer . Value ; * SleepTypeB = ( UINT8 ) Elements [ 1 ] -> Integer . Value ; break ; } ReturnValueCleanup : AcpiUtRemoveReference ( Info -> ReturnObject ) ; WarningCleanup : if ( ACPI_FAILURE ( Status ) ) { ACPI_EXCEPTION ( ( AE_INFO , Status , " " , Info -> RelativePathname ) ) ; } FinalCleanup : ACPI_FREE ( Info ) ; return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiGetSleepTypeData
 PARAMETERS:  SleepState          - Numeric sleep state
              *SleepTypeA         - Where SLP_TYPa is returned
              *SleepTypeB         - Where SLP_TYPb is returned
FUNCTION : AcpiGetSleepTypeData PARAMETERS : SleepState - Numeric sleep state * SleepTypeA - Where SLP_TYPa is returned * SleepTypeB - Where SLP_TYPb is returned
/* Validate parameters */ /* Allocate the evaluation information block */ /*
     * Evaluate the \_Sx namespace object containing the register values
     * for this state
     */ /* The _Sx states are optional, ignore NOT_FOUND */ /* Must have a return object */ /* Return object must be of type Package */ /*
     * Any warnings about the package length or the object types have
     * already been issued by the predefined name module -- there is no
     * need to repeat them here.
     */ /* A valid _Sx_ package with one integer */ /* A valid _Sx_ package with two integers */