hwsleep.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2015, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#define _COMPONENT ACPI_HARDWARE
ACPI_MODULE_NAME ("hwsleep")
#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
/*******************************************************************************
*
* 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
*
******************************************************************************/
{
/* Clear wake status */
if (ACPI_FAILURE (Status))
{
}
/* Clear all fixed and general purpose status bits */
Status = AcpiHwClearAcpiStatus ();
if (ACPI_FAILURE (Status))
{
}
/*
* 2) Enable all wakeup GPEs
*/
Status = AcpiHwDisableAllGpes ();
if (ACPI_FAILURE (Status))
{
}
if (ACPI_FAILURE (Status))
{
}
/* Get current value of PM1A control */
&Pm1aControl);
if (ACPI_FAILURE (Status))
{
}
"Entering sleep state [S%u]\n", SleepState));
/* 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 */
if (ACPI_FAILURE (Status))
{
}
/* Insert the sleep enable (SLP_EN) bit */
/* Flush caches, as per ACPI specification */
/* Write #2: Write both SLP_TYP + SLP_EN */
if (ACPI_FAILURE (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!)
*
* 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.
*/
if (ACPI_FAILURE (Status))
{
}
}
/* Wait for transition back to Working State */
do
{
if (ACPI_FAILURE (Status))
{
}
} while (!InValue);
}
/*******************************************************************************
*
* FUNCTION: AcpiHwLegacyWakePrep
*
* PARAMETERS: SleepState - Which sleep state we just exited
*
* RETURN: Status
*
* DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
* sleep.
* Called with interrupts ENABLED.
*
******************************************************************************/
{
/*
* Set SLP_TYPE and SLP_EN to state S0.
* This is unclear from the ACPI Spec, but it is required
* by some machines.
*/
if (ACPI_SUCCESS (Status))
{
/* Get current value of PM1A control */
&Pm1aControl);
if (ACPI_SUCCESS (Status))
{
/* Clear the SLP_EN and SLP_TYP fields */
/* Insert the SLP_TYP bits */
Pm1aControl |= (AcpiGbl_SleepTypeA <<
Pm1bControl |= (AcpiGbl_SleepTypeB <<
/* Write the control registers and ignore any errors */
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiHwLegacyWake
*
* PARAMETERS: SleepState - Which sleep state we just exited
*
* RETURN: Status
*
* DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
* Called with interrupts ENABLED.
*
******************************************************************************/
{
/* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
/*
* GPEs must be enabled before _WAK is called as GPEs
* might get fired there
*
* Restore the GPEs:
* 2) Enable all runtime GPEs
*/
Status = AcpiHwDisableAllGpes ();
if (ACPI_FAILURE (Status))
{
}
if (ACPI_FAILURE (Status))
{
}
/*
* Now we can execute _WAK, etc. Some machines require that the GPEs
* are enabled before the wake methods are executed.
*/
/*
* Some BIOS code assumes that WAK_STS will be cleared on resume
* and use it to determine whether the system is rebooting or
* resuming. Clear WAK_STS for compatibility.
*/
/* Enable power button */
(void) AcpiWriteBitRegister(
(void) AcpiWriteBitRegister(
}
#endif /* !ACPI_REDUCED_HARDWARE */