Commit 72a8887a authored by Bob Moore's avatar Bob Moore Committed by Len Brown

ACPICA: Add table-driven dispatch for sleep/wake functions

Simplifies the code, especially the compile-time
ACPI_REDUCED_HARDWARE option.
Signed-off-by: default avatarBob Moore <robert.moore@intel.com>
Signed-off-by: default avatarLin Ming <ming.m.lin@intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 70958576
...@@ -516,6 +516,12 @@ ...@@ -516,6 +516,12 @@
#endif /* ACPI_DEBUG_OUTPUT */ #endif /* ACPI_DEBUG_OUTPUT */
#if (!ACPI_REDUCED_HARDWARE)
#define ACPI_HW_OPTIONAL_FUNCTION(addr) addr
#else
#define ACPI_HW_OPTIONAL_FUNCTION(addr) NULL
#endif
/* /*
* Some code only gets executed when the debugger is built in. * Some code only gets executed when the debugger is built in.
* Note that this is entirely independent of whether the * Note that this is entirely independent of whether the
......
...@@ -48,6 +48,34 @@ ...@@ -48,6 +48,34 @@
#define _COMPONENT ACPI_HARDWARE #define _COMPONENT ACPI_HARDWARE
ACPI_MODULE_NAME("hwxfsleep") ACPI_MODULE_NAME("hwxfsleep")
/* Local prototypes */
static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
/*
* Dispatch table used to efficiently branch to the various sleep
* functions.
*/
#define ACPI_SLEEP_FUNCTION 0
#define ACPI_WAKE_PREP_FUNCTION 1
#define ACPI_WAKE_FUNCTION 2
/* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
acpi_hw_extended_sleep},
{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
acpi_hw_extended_wake_prep},
{ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
};
/*
* These functions are removed for the ACPI_REDUCED_HARDWARE case:
* acpi_set_firmware_waking_vector
* acpi_set_firmware_waking_vector64
* acpi_enter_sleep_state_s4bios
*/
#if (!ACPI_REDUCED_HARDWARE) #if (!ACPI_REDUCED_HARDWARE)
/******************************************************************************* /*******************************************************************************
* *
...@@ -61,6 +89,7 @@ ACPI_MODULE_NAME("hwxfsleep") ...@@ -61,6 +89,7 @@ ACPI_MODULE_NAME("hwxfsleep")
* DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS
* *
******************************************************************************/ ******************************************************************************/
acpi_status acpi_set_firmware_waking_vector(u32 physical_address) acpi_status acpi_set_firmware_waking_vector(u32 physical_address)
{ {
ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector); ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
...@@ -191,6 +220,52 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void) ...@@ -191,6 +220,52 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios) ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
#endif /* !ACPI_REDUCED_HARDWARE */ #endif /* !ACPI_REDUCED_HARDWARE */
/*******************************************************************************
*
* FUNCTION: acpi_hw_sleep_dispatch
*
* PARAMETERS: sleep_state - Which sleep state to enter/exit
* function_id - Sleep, wake_prep, or Wake
*
* RETURN: Status from the invoked sleep handling function.
*
* DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
* function.
*
******************************************************************************/
static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id)
{
acpi_status status;
struct acpi_sleep_functions *sleep_functions =
&acpi_sleep_dispatch[function_id];
#if (!ACPI_REDUCED_HARDWARE)
/*
* If the Hardware Reduced flag is set (from the FADT), we must
* use the extended sleep registers
*/
if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
status = sleep_functions->extended_function(sleep_state);
} else {
/* Legacy sleep */
status = sleep_functions->legacy_function(sleep_state);
}
return (status);
#else
/*
* For the case where reduced-hardware-only code is being generated,
* we know that only the extended sleep registers are available
*/
status = sleep_functions->extended_function(sleep_state);
return (status);
#endif /* !ACPI_REDUCED_HARDWARE */
}
/******************************************************************************* /*******************************************************************************
* *
* FUNCTION: acpi_enter_sleep_state_prep * FUNCTION: acpi_enter_sleep_state_prep
...@@ -199,12 +274,13 @@ ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios) ...@@ -199,12 +274,13 @@ ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
* *
* RETURN: Status * RETURN: Status
* *
* DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231) * DESCRIPTION: Prepare to enter a system sleep state.
* This function must execute with interrupts enabled. * This function must execute with interrupts enabled.
* We break sleeping into 2 stages so that OSPM can handle * We break sleeping into 2 stages so that OSPM can handle
* various OS-specific tasks between the two steps. * various OS-specific tasks between the two steps.
* *
******************************************************************************/ ******************************************************************************/
acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
{ {
acpi_status status; acpi_status status;
...@@ -291,23 +367,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) ...@@ -291,23 +367,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b)); acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
return_ACPI_STATUS(AE_AML_OPERAND_VALUE); return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
} }
#if (!ACPI_REDUCED_HARDWARE)
/* If Hardware Reduced flag is set, must use the extended sleep registers */
if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
status = acpi_hw_extended_sleep(sleep_state);
} else {
/* Legacy sleep */
status = acpi_hw_legacy_sleep(sleep_state);
}
#else
status = acpi_hw_extended_sleep(sleep_state);
#endif /* !ACPI_REDUCED_HARDWARE */
status = acpi_hw_sleep_dispatch(sleep_state, ACPI_SLEEP_FUNCTION);
return_ACPI_STATUS(status); return_ACPI_STATUS(status);
} }
...@@ -330,26 +391,9 @@ acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) ...@@ -330,26 +391,9 @@ acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
{ {
acpi_status status; acpi_status status;
ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep);
#if (!ACPI_REDUCED_HARDWARE)
/* If Hardware Reduced flag is set, must use the extended sleep registers */
if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
status = acpi_hw_extended_wake_prep(sleep_state);
} else {
/* Legacy sleep */
status = acpi_hw_legacy_wake_prep(sleep_state);
}
#else
status = acpi_hw_extended_wake_prep(sleep_state);
#endif /* !ACPI_REDUCED_HARDWARE */
status = acpi_hw_sleep_dispatch(sleep_state, ACPI_WAKE_PREP_FUNCTION);
return_ACPI_STATUS(status); return_ACPI_STATUS(status);
} }
...@@ -359,7 +403,7 @@ ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep) ...@@ -359,7 +403,7 @@ ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep)
* *
* FUNCTION: acpi_leave_sleep_state * FUNCTION: acpi_leave_sleep_state
* *
* PARAMETERS: sleep_state - Which sleep state we just exited * PARAMETERS: sleep_state - Which sleep state we are exiting
* *
* RETURN: Status * RETURN: Status
* *
...@@ -374,23 +418,7 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state) ...@@ -374,23 +418,7 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
#if (!ACPI_REDUCED_HARDWARE) status = acpi_hw_sleep_dispatch(sleep_state, ACPI_WAKE_FUNCTION);
/* If Hardware Reduced flag is set, must use the extended sleep registers */
if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
status = acpi_hw_extended_wake(sleep_state);
} else {
/* Legacy sleep */
status = acpi_hw_legacy_wake(sleep_state);
}
#else
status = acpi_hw_extended_wake(sleep_state);
#endif /* !ACPI_REDUCED_HARDWARE */
return_ACPI_STATUS(status); return_ACPI_STATUS(status);
} }
......
...@@ -788,6 +788,15 @@ typedef u8 acpi_adr_space_type; ...@@ -788,6 +788,15 @@ typedef u8 acpi_adr_space_type;
#define ACPI_ENABLE_EVENT 1 #define ACPI_ENABLE_EVENT 1
#define ACPI_DISABLE_EVENT 0 #define ACPI_DISABLE_EVENT 0
/* Sleep function dispatch */
typedef acpi_status(*ACPI_SLEEP_FUNCTION) (u8 sleep_state);
struct acpi_sleep_functions {
ACPI_SLEEP_FUNCTION legacy_function;
ACPI_SLEEP_FUNCTION extended_function;
};
/* /*
* External ACPI object definition * External ACPI object definition
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment