FreeBSD/sys/contrib/dev/acpica/components/hardware/hwsleep.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiHwLegacySleep
 *
 * PARAMETERS:  SleepState          - Which sleep state to enter
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers
 *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
 *
 ******************************************************************************/
AcpiHwLegacySleep
PARAMETERS:  SleepState          - Which sleep state to enter

Status


AcpiHwLegacySleep PARAMETERS : SleepState - Which sleep state to enter Status
ACPI_STATUS
AcpiHwLegacySleep (
    UINT8                   SleepState)
{
    ACPI_BIT_REGISTER_INFO  *SleepTypeRegInfo;
    ACPI_BIT_REGISTER_INFO  *SleepEnableRegInfo;
    UINT32                  Pm1aControl;
    UINT32                  Pm1bControl;
    UINT32                  InValue;
    ACPI_STATUS             Status;
    ACPI_FUNCTION_TRACE (HwLegacySleep);
    SleepTypeRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE);
    SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE);
    Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS,
        ACPI_CLEAR_STATUS);
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    Status = AcpiHwClearAcpiStatus ();
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    Status = AcpiHwDisableAllGpes ();
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    AcpiGbl_SystemAwakeAndRunning = FALSE;
    Status = AcpiHwEnableAllWakeupGpes ();
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    Status = AcpiHwRegisterRead (ACPI_REGISTER_PM1_CONTROL,
        &Pm1aControl);
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
        "Entering sleep state [S%u]\n", SleepState));
    Pm1aControl &= ~(SleepTypeRegInfo->AccessBitMask |
         SleepEnableRegInfo->AccessBitMask);
    Pm1bControl = Pm1aControl;
    Pm1aControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition);
    Pm1bControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition);
    Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    Pm1aControl |= SleepEnableRegInfo->AccessBitMask;
    Pm1bControl |= SleepEnableRegInfo->AccessBitMask;
    ACPI_FLUSH_CPU_CACHE ();
    Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    if (SleepState > ACPI_STATE_S3)
    {
        AcpiOsStall (10 * ACPI_USEC_PER_SEC);
        Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_CONTROL,
            SleepEnableRegInfo->AccessBitMask);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
    }
    do
    {
        Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &InValue);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
    } while (!InValue);
    return_ACPI_STATUS (AE_OK);
}
ACPI_STATUS AcpiHwLegacySleep ( UINT8 SleepState ) { ACPI_BIT_REGISTER_INFO * SleepTypeRegInfo ; ACPI_BIT_REGISTER_INFO * SleepEnableRegInfo ; UINT32 Pm1aControl ; UINT32 Pm1bControl ; UINT32 InValue ; ACPI_STATUS Status ; ACPI_FUNCTION_TRACE ( HwLegacySleep ) ; SleepTypeRegInfo = AcpiHwGetBitRegisterInfo ( ACPI_BITREG_SLEEP_TYPE ) ; SleepEnableRegInfo = AcpiHwGetBitRegisterInfo ( ACPI_BITREG_SLEEP_ENABLE ) ; Status = AcpiWriteBitRegister ( ACPI_BITREG_WAKE_STATUS , ACPI_CLEAR_STATUS ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } Status = AcpiHwClearAcpiStatus ( ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } Status = AcpiHwDisableAllGpes ( ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } AcpiGbl_SystemAwakeAndRunning = FALSE ; Status = AcpiHwEnableAllWakeupGpes ( ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } Status = AcpiHwRegisterRead ( ACPI_REGISTER_PM1_CONTROL , & Pm1aControl ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } ACPI_DEBUG_PRINT ( ( ACPI_DB_INIT , " \n " , SleepState ) ) ; Pm1aControl &= ~ ( SleepTypeRegInfo -> AccessBitMask | SleepEnableRegInfo -> AccessBitMask ) ; Pm1bControl = Pm1aControl ; Pm1aControl |= ( AcpiGbl_SleepTypeA << SleepTypeRegInfo -> BitPosition ) ; Pm1bControl |= ( AcpiGbl_SleepTypeB << SleepTypeRegInfo -> BitPosition ) ; Status = AcpiHwWritePm1Control ( Pm1aControl , Pm1bControl ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } Pm1aControl |= SleepEnableRegInfo -> AccessBitMask ; Pm1bControl |= SleepEnableRegInfo -> AccessBitMask ; ACPI_FLUSH_CPU_CACHE ( ) ; Status = AcpiHwWritePm1Control ( Pm1aControl , Pm1bControl ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } if ( SleepState > ACPI_STATE_S3 ) { AcpiOsStall ( 10 * ACPI_USEC_PER_SEC ) ; Status = AcpiHwRegisterWrite ( ACPI_REGISTER_PM1_CONTROL , SleepEnableRegInfo -> AccessBitMask ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } } do { Status = AcpiReadBitRegister ( ACPI_BITREG_WAKE_STATUS , & InValue ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } } while ( ! InValue ) ; return_ACPI_STATUS ( AE_OK ) ; }
FUNCTION:    AcpiHwLegacySleep
 PARAMETERS:  SleepState          - Which sleep state to enter
FUNCTION : AcpiHwLegacySleep PARAMETERS : SleepState - Which sleep state to enter
/* Clear wake status */ /* Clear all fixed and general purpose status bits */ /*
     * 1) Disable/Clear all GPEs
     * 2) Enable all wakeup GPEs
     */ /* Get current value of PM1A control */ /* Clear the SLP_EN and SLP_TYP fields */ /* Insert the SLP_TYP bits */ /*
     * We split the writes of SLP_TYP and SLP_EN to workaround
     * poorly implemented hardware.
     */ /* Write #1: write the SLP_TYP data to the PM1 Control registers */ /* Insert the sleep enable (SLP_EN) bit */ /* Flush caches, as per ACPI specification */ /* Write #2: Write both SLP_TYP + SLP_EN */ /*
         * We wanted to sleep > S3, but it didn't happen (by virtue of the
         * fact that we are still executing!)
         *
         * Wait ten seconds, then try again. This is to get S4/S5 to work on
         * all machines.
         *
         * We wait so long to allow chipsets that poll this reg very slowly
         * to still read the right value. Ideally, this block would go
         * away entirely.
         */ /* Wait for transition back to Working State */