2018-03-14 16:13:07 -07:00
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2012-02-14 18:47:42 +08:00
/******************************************************************************
*
* Name : hwesleep . c - ACPI Hardware Sleep / Wake Support functions for the
* extended FADT - V5 sleep registers .
*
2020-01-10 11:31:49 -08:00
* Copyright ( C ) 2000 - 2020 , Intel Corp .
2012-02-14 18:47:42 +08:00
*
2018-03-14 16:13:07 -07:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-02-14 18:47:42 +08:00
# include <acpi/acpi.h>
# include "accommon.h"
# define _COMPONENT ACPI_HARDWARE
ACPI_MODULE_NAME ( " hwesleep " )
/*******************************************************************************
*
* FUNCTION : acpi_hw_execute_sleep_method
*
2012-03-21 09:42:45 +08:00
* PARAMETERS : method_pathname - Pathname of method to execute
2012-02-14 18:47:42 +08:00
* integer_argument - Argument to pass to the method
*
* RETURN : None
*
* DESCRIPTION : Execute a sleep / wake related method with one integer argument
* and no return value .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-03-21 09:42:45 +08:00
void acpi_hw_execute_sleep_method ( char * method_pathname , u32 integer_argument )
2012-02-14 18:47:42 +08:00
{
struct acpi_object_list arg_list ;
union acpi_object arg ;
acpi_status status ;
ACPI_FUNCTION_TRACE ( hw_execute_sleep_method ) ;
/* One argument, integer_argument; No return value expected */
arg_list . count = 1 ;
arg_list . pointer = & arg ;
arg . type = ACPI_TYPE_INTEGER ;
arg . integer . value = ( u64 ) integer_argument ;
2012-03-21 09:42:45 +08:00
status = acpi_evaluate_object ( NULL , method_pathname , & arg_list , NULL ) ;
2012-02-14 18:47:42 +08:00
if ( ACPI_FAILURE ( status ) & & status ! = AE_NOT_FOUND ) {
ACPI_EXCEPTION ( ( AE_INFO , status , " While executing method %s " ,
2012-03-21 09:42:45 +08:00
method_pathname ) ) ;
2012-02-14 18:47:42 +08:00
}
return_VOID ;
}
/*******************************************************************************
*
* FUNCTION : acpi_hw_extended_sleep
*
* PARAMETERS : sleep_state - Which sleep state to enter
*
* RETURN : Status
*
* DESCRIPTION : Enter a system sleep state via the extended FADT sleep
* registers ( V5 FADT ) .
* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-07-26 20:08:54 -04:00
acpi_status acpi_hw_extended_sleep ( u8 sleep_state )
2012-02-14 18:47:42 +08:00
{
acpi_status status ;
2016-12-28 15:28:49 +08:00
u8 sleep_control ;
2012-02-14 18:47:42 +08:00
u64 sleep_status ;
ACPI_FUNCTION_TRACE ( hw_extended_sleep ) ;
/* Extended sleep registers must be valid */
if ( ! acpi_gbl_FADT . sleep_control . address | |
! acpi_gbl_FADT . sleep_status . address ) {
return_ACPI_STATUS ( AE_NOT_EXIST ) ;
}
/* Clear wake status (WAK_STS) */
2015-12-29 13:54:36 +08:00
status = acpi_write ( ( u64 ) ACPI_X_WAKE_STATUS ,
& acpi_gbl_FADT . sleep_status ) ;
2012-02-14 18:47:42 +08:00
if ( ACPI_FAILURE ( status ) ) {
return_ACPI_STATUS ( status ) ;
}
acpi_gbl_system_awake_and_running = FALSE ;
/*
* Set the SLP_TYP and SLP_EN bits .
*
* Note : We only use the first value returned by the \ _Sx method
* ( acpi_gbl_sleep_type_a ) - As per ACPI specification .
*/
ACPI_DEBUG_PRINT ( ( ACPI_DB_INIT ,
" Entering sleep state [S%u] \n " , sleep_state ) ) ;
2016-12-28 15:28:49 +08:00
sleep_control = ( ( acpi_gbl_sleep_type_a < < 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 = acpi_os_enter_sleep ( sleep_state , sleep_control , 0 ) ;
if ( status = = AE_CTRL_TERMINATE ) {
return_ACPI_STATUS ( AE_OK ) ;
}
if ( ACPI_FAILURE ( status ) ) {
return_ACPI_STATUS ( status ) ;
}
2012-02-14 18:47:42 +08:00
2016-12-28 15:28:49 +08:00
status = acpi_write ( ( u64 ) sleep_control , & acpi_gbl_FADT . sleep_control ) ;
2012-02-14 18:47:42 +08:00
if ( ACPI_FAILURE ( status ) ) {
return_ACPI_STATUS ( status ) ;
}
/* Wait for transition back to Working State */
do {
status = acpi_read ( & sleep_status , & acpi_gbl_FADT . sleep_status ) ;
if ( ACPI_FAILURE ( status ) ) {
return_ACPI_STATUS ( status ) ;
}
} while ( ! ( ( ( u8 ) sleep_status ) & ACPI_X_WAKE_STATUS ) ) ;
return_ACPI_STATUS ( AE_OK ) ;
}
/*******************************************************************************
*
* FUNCTION : acpi_hw_extended_wake_prep
*
* PARAMETERS : sleep_state - Which sleep state we just exited
*
* RETURN : Status
*
* DESCRIPTION : Perform first part of OS - independent ACPI cleanup after
* a sleep . Called with interrupts ENABLED .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-07-26 20:08:54 -04:00
acpi_status acpi_hw_extended_wake_prep ( u8 sleep_state )
2012-02-14 18:47:42 +08:00
{
acpi_status status ;
u8 sleep_type_value ;
ACPI_FUNCTION_TRACE ( hw_extended_wake_prep ) ;
status = acpi_get_sleep_type_data ( ACPI_STATE_S0 ,
& acpi_gbl_sleep_type_a ,
& acpi_gbl_sleep_type_b ) ;
if ( ACPI_SUCCESS ( status ) ) {
sleep_type_value =
( ( acpi_gbl_sleep_type_a < < ACPI_X_SLEEP_TYPE_POSITION ) &
ACPI_X_SLEEP_TYPE_MASK ) ;
2012-05-03 09:43:21 +08:00
( void ) acpi_write ( ( u64 ) ( sleep_type_value | ACPI_X_SLEEP_ENABLE ) ,
2012-02-14 18:47:42 +08:00
& acpi_gbl_FADT . sleep_control ) ;
}
return_ACPI_STATUS ( AE_OK ) ;
}
/*******************************************************************************
*
* FUNCTION : acpi_hw_extended_wake
*
* PARAMETERS : sleep_state - Which sleep state we just exited
*
* RETURN : Status
*
* DESCRIPTION : Perform OS - independent ACPI cleanup after a sleep
* Called with interrupts ENABLED .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-07-26 20:08:54 -04:00
acpi_status acpi_hw_extended_wake ( u8 sleep_state )
2012-02-14 18:47:42 +08:00
{
ACPI_FUNCTION_TRACE ( hw_extended_wake ) ;
/* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID ;
/* Execute the wake methods */
2012-03-21 09:42:45 +08:00
acpi_hw_execute_sleep_method ( METHOD_PATHNAME__SST , ACPI_SST_WAKING ) ;
acpi_hw_execute_sleep_method ( METHOD_PATHNAME__WAK , sleep_state ) ;
2012-02-14 18:47:42 +08:00
/*
* 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 .
*/
2012-05-03 09:43:21 +08:00
( void ) acpi_write ( ( u64 ) ACPI_X_WAKE_STATUS , & acpi_gbl_FADT . sleep_status ) ;
2012-02-14 18:47:42 +08:00
acpi_gbl_system_awake_and_running = TRUE ;
2012-03-21 09:42:45 +08:00
acpi_hw_execute_sleep_method ( METHOD_PATHNAME__SST , ACPI_SST_WORKING ) ;
2012-02-14 18:47:42 +08:00
return_ACPI_STATUS ( AE_OK ) ;
}