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

Simplifies the code, especially the compile-time
ACPI_REDUCED_HARDWARE option.

Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Bob Moore 2012-02-14 18:57:13 +08:00 committed by Len Brown
parent 7095857657
commit 72a8887a35
3 changed files with 97 additions and 54 deletions

View file

@ -516,6 +516,12 @@
#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.
* Note that this is entirely independent of whether the

View file

@ -48,6 +48,34 @@
#define _COMPONENT ACPI_HARDWARE
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)
/*******************************************************************************
*
@ -61,6 +89,7 @@ ACPI_MODULE_NAME("hwxfsleep")
* DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS
*
******************************************************************************/
acpi_status acpi_set_firmware_waking_vector(u32 physical_address)
{
ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
@ -191,6 +220,52 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
#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
@ -199,12 +274,13 @@ ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
*
* 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.
* We break sleeping into 2 stages so that OSPM can handle
* various OS-specific tasks between the two steps.
*
******************************************************************************/
acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
{
acpi_status status;
@ -291,23 +367,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
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);
}
@ -330,26 +391,9 @@ acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
{
acpi_status status;
ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
#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 */
ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep);
status = acpi_hw_sleep_dispatch(sleep_state, ACPI_WAKE_PREP_FUNCTION);
return_ACPI_STATUS(status);
}
@ -359,7 +403,7 @@ ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep)
*
* 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
*
@ -374,23 +418,7 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
#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(sleep_state);
} else {
/* Legacy sleep */
status = acpi_hw_legacy_wake(sleep_state);
}
#else
status = acpi_hw_extended_wake(sleep_state);
#endif /* !ACPI_REDUCED_HARDWARE */
status = acpi_hw_sleep_dispatch(sleep_state, ACPI_WAKE_FUNCTION);
return_ACPI_STATUS(status);
}

View file

@ -788,6 +788,15 @@ typedef u8 acpi_adr_space_type;
#define ACPI_ENABLE_EVENT 1
#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
*/