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); /* Clear wake status */ Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * 1) Disable all GPEs * 2) Enable all wakeup GPEs */ Status = AcpiHwDisableAllGpes (); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } AcpiGbl_SystemAwakeAndRunning = FALSE; Status = AcpiHwEnableAllWakeupGpes (); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Get current value of PM1A control */ 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)); /* Clear the SLP_EN and SLP_TYP fields */ Pm1aControl &= ~(SleepTypeRegInfo->AccessBitMask | SleepEnableRegInfo->AccessBitMask); Pm1bControl = Pm1aControl; /* Insert the SLP_TYP bits */ Pm1aControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition); Pm1bControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition); /* * 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 */ Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Insert the sleep enable (SLP_EN) bit */ Pm1aControl |= SleepEnableRegInfo->AccessBitMask; Pm1bControl |= SleepEnableRegInfo->AccessBitMask; /* Flush caches, as per ACPI specification */ ACPI_FLUSH_CPU_CACHE (); Status = AcpiOsEnterSleep (SleepState, Pm1aControl, Pm1bControl); if (Status == AE_CTRL_TERMINATE) { return_ACPI_STATUS (AE_OK); } if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Write #2: Write both SLP_TYP + SLP_EN */ Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (SleepState > ACPI_STATE_S3) { /* * 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. */ AcpiOsStall (10 * ACPI_USEC_PER_SEC); Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_CONTROL, SleepEnableRegInfo->AccessBitMask); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* Wait for transition back to Working State */ 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 AcpiHwExtendedSleep ( UINT8 SleepState) { ACPI_STATUS Status; UINT8 SleepControl; UINT64 SleepStatus; ACPI_FUNCTION_TRACE (HwExtendedSleep); /* Extended sleep registers must be valid */ if (!AcpiGbl_FADT.SleepControl.Address || !AcpiGbl_FADT.SleepStatus.Address) { return_ACPI_STATUS (AE_NOT_EXIST); } /* Clear wake status (WAK_STS) */ Status = AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS, &AcpiGbl_FADT.SleepStatus); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } AcpiGbl_SystemAwakeAndRunning = FALSE; /* * Set the SLP_TYP and SLP_EN bits. * * Note: We only use the first value returned by the \_Sx method * (AcpiGbl_SleepTypeA) - As per ACPI specification. */ ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Entering sleep state [S%u]\n", SleepState)); SleepControl = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) & ACPI_X_SLEEP_TYPE_MASK) | ACPI_X_SLEEP_ENABLE; /* Flush caches, as per ACPI specification */ ACPI_FLUSH_CPU_CACHE (); Status = AcpiOsEnterSleep (SleepState, SleepControl, 0); if (Status == AE_CTRL_TERMINATE) { return_ACPI_STATUS (AE_OK); } if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiWrite ((UINT64) SleepControl, &AcpiGbl_FADT.SleepControl); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Wait for transition back to Working State */ do { Status = AcpiRead (&SleepStatus, &AcpiGbl_FADT.SleepStatus); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } while (!(((UINT8) SleepStatus) & ACPI_X_WAKE_STATUS)); return_ACPI_STATUS (AE_OK); }