: ACPI / PM: Rework wakeup GPE handling for suspend-to-idle
Subsystems (6)
cover : ACPI / PM: Rework wakeup GPE handling for suspend-to-idle
Hi,
This series is based on the pm-genirq branch of linux-pm.git which has been included into linux-next for a few weeks. That branch reworks the handling of wakeup interrupts in general so that enable_irq_wake() can be used to indicate that the given interrupt is to be used to wake up from suspend-to-idle as well as from the other sleep states. At the same time, using IRQF_NO_SUSPEND with wakeup interrupts is not regarded as correct any more.
Along these lines, rework the handling of wakeup GPEs for suspend-to-idle so as to make use of the new mechanism.
This has been tested on Toshiba Portege R500 with ACPI button wakeup and with ACPI-based PCI Wake-on-LAN.
[1/5] Export dpm_suspend_late(), dpm_suspend_noirq(), dpm_resume_noirq() and
dpm_resume_early() from the PM core.
[2/5] Rename local functions in the suspend core to better reflect their purpose. [3/5] Rework ACPICA's acpi_hw_enable_wakeup_gpe_block() to disable all non-wakeup
GPEs along with enabling the wakeup ones.
[4/5] Introduce acpi_enable_all_wakeup_gpes() in ACPICA (along the lines of the
analogous function for runtime GPEs).
[5/5] Modify the handling of wakeup GPEs for suspend-to-idle.
Thanks!
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 1/5 PM / sleep: Export dpm_suspend_late/noirq() and dpm_resume_early/noirq()
From: Rafael J. Wysocki <[email protected]>
Subsequent change sets will add platform-related operations between dpm_suspend_late() and dpm_suspend_noirq() as well as between dpm_resume_noirq() and dpm_resume_early() in suspend_enter(), so export these functions for suspend_enter() to be able to call them separately and split the invocations of dpm_suspend_end() and dpm_resume_start() in there accordingly.
--- drivers/base/power/main.c | 8 ++++---- include/linux/pm.h | 4 ++++ kernel/power/suspend.c | 14 +++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/base/power/main.c +4 -4
@@ -540,7 +540,7 @@ static void async_resume_noirq(void *dat* Call the "noirq" resume handlers for all devices in dpm_noirq_list and * enable device drivers to receive interrupts. */ -static void dpm_resume_noirq (pm_message_t state) +void dpm_resume_noirq (pm_message_t state) {struct device *dev;ktime_t starttime =ktime_get ();
@@ -662,7 +662,7 @@ static void async_resume_early(void *dat* dpm_resume_early - Execute "early resume" callbacks for all devices. * @state: PM transition of the system being carried out. */ -static void dpm_resume_early (pm_message_t state) +void dpm_resume_early (pm_message_t state) {struct device *dev;ktime_t starttime =ktime_get ();
@@ -1093,7 +1093,7 @@ static int device_suspend_noirq(struct d* Prevent device drivers from receiving interrupts and call the "noirq" suspend * handlers for all non-sysdev devices. */ -static int dpm_suspend_noirq (pm_message_t state) +int dpm_suspend_noirq (pm_message_t state) {ktime_t starttime =ktime_get ();int error =0 ;
@@ -1232,7 +1232,7 @@ static int device_suspend_late(struct de* dpm_suspend_late - Execute "late suspend" callbacks for all devices. * @state: PM transition of the system being carried out. */ -static int dpm_suspend_late (pm_message_t state) +int dpm_suspend_late (pm_message_t state) {ktime_t starttime =ktime_get ();int error =0 ;
kernel/power/suspend.c +11 -3
@@ -265,11 +265,16 @@ static int suspend_enter(suspend_state_tif (error) goto Platform_finish; - error =dpm_suspend_end (PMSG_SUSPEND ); + error =dpm_suspend_late (PMSG_SUSPEND );if (error) { -printk (KERN_ERR "PM: Some devices failed to power down\n" ); +printk (KERN_ERR "PM: late suspend of devices failed\n" ); goto Platform_finish; } + error =dpm_suspend_noirq (PMSG_SUSPEND ); +if (error) { +printk (KERN_ERR "PM: noirq suspend of devices failed\n" ); + goto Devices_early_resume; + } error =platform_suspend_prepare_late (state);if (error) goto Platform_wake;
@@ -319,7 +324,10 @@ static int suspend_enter(suspend_state_t Platform_wake:platform_suspend_wake (state); -dpm_resume_start (PMSG_RESUME ); +dpm_resume_noirq (PMSG_RESUME ); + + Devices_early_resume: +dpm_resume_early (PMSG_RESUME ); Platform_finish:platform_suspend_finish (state);
include/linux/pm.h +4 -0
@@ -680,12 +680,16 @@ struct dev_pm_domain {extern void device_pm_lock (void );extern void dpm_resume_start (pm_message_t state);extern void dpm_resume_end (pm_message_t state); +extern void dpm_resume_noirq (pm_message_t state); +extern void dpm_resume_early (pm_message_t state);extern void dpm_resume (pm_message_t state);extern void dpm_complete (pm_message_t state);extern void device_pm_unlock (void );extern int dpm_suspend_end (pm_message_t state);extern int dpm_suspend_start (pm_message_t state); +extern int dpm_suspend_noirq (pm_message_t state); +extern int dpm_suspend_late (pm_message_t state);extern int dpm_suspend (pm_message_t state);extern int dpm_prepare (pm_message_t state);
PATCH 2/5 PM / sleep: Rename platform suspend/resume functions in suspend.c
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Rename several local functions related to platform handling during system suspend resume in suspend.c so that their names better reflect their roles.
--- kernel/power/suspend.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
kernel/power/suspend.c +10 -10
@@ -144,19 +144,19 @@ static int platform_suspend_prepare(susp suspend_ops->prepare() : 0; } -static int platform_suspend_prepare_late (suspend_state_t state) +static int platform_suspend_prepare_noirq (suspend_state_t state) {return state !=PM_SUSPEND_FREEZE && suspend_ops->prepare_late ? suspend_ops->prepare_late () :0 ; } -static void platform_suspend_wake (suspend_state_t state) +static void platform_resume_noirq (suspend_state_t state) {if (state !=PM_SUSPEND_FREEZE && suspend_ops->wake) suspend_ops->wake (); } -static void platform_suspend_finish (suspend_state_t state) +static void platform_resume_finish (suspend_state_t state) {if (state !=PM_SUSPEND_FREEZE && suspend_ops->finish) suspend_ops->finish ();
@@ -172,7 +172,7 @@ static int platform_suspend_begin(suspenreturn 0 ; } -static void platform_suspend_end (suspend_state_t state) +static void platform_resume_end (suspend_state_t state) {if (state ==PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->end) freeze_ops->end ();
@@ -180,7 +180,7 @@ static void platform_suspend_end(suspend suspend_ops->end (); } -static void platform_suspend_recover (suspend_state_t state) +static void platform_recover (suspend_state_t state) {if (state !=PM_SUSPEND_FREEZE && suspend_ops->recover) suspend_ops->recover ();
@@ -275,7 +275,7 @@ static int suspend_enter(suspend_state_tprintk (KERN_ERR "PM: noirq suspend of devices failed\n" ); goto Devices_early_resume; } - error =platform_suspend_prepare_late (state); + error =platform_suspend_prepare_noirq (state);if (error) goto Platform_wake;
@@ -323,14 +323,14 @@ static int suspend_enter(suspend_state_tenable_nonboot_cpus (); Platform_wake: -platform_suspend_wake (state); +platform_resume_noirq (state);dpm_resume_noirq (PMSG_RESUME ); Devices_early_resume:dpm_resume_early (PMSG_RESUME ); Platform_finish: -platform_suspend_finish (state); +platform_resume_finish (state);return error; }
@@ -374,11 +374,11 @@ int suspend_devices_and_enter(suspend_sttrace_suspend_resume (TPS ("resume_console" ), state, false); Close: -platform_suspend_end (state); +platform_resume_end (state);return error; Recover_platform: -platform_suspend_recover (state); +platform_recover (state); goto Resume_devices; }
PATCH 3/5 ACPICA: Clear all non-wakeup GPEs in acpi_hw_enable_wakeup_gpe_block()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since acpi_hw_enable_wakeup_gpe_block() is currently always called after disabling all GPEs, it can actually write zeros to all non-wakeup enable bits unconditionally.
That will be useful going forward for disabling runtime GPEs and enabling wakeup GPEs in one go instead of doing that in two steps (disable runtime and enable wakeup) which in theory may lead to a loss of a wakeup event.
---
Bob, please let me know if I can fast-track this.
--- drivers/acpi/acpica/hwgpe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/acpi/acpica/hwgpe.c +4 -4
@@ -396,11 +396,11 @@ acpi_hw_enable_wakeup_gpe_block(struct a/* Examine each GPE Register within the block */ for (i =0 ; i < gpe_block->register_count; i++) { -if (!gpe_block->register_info[i].enable_for_wake) { -continue ; - } -/* Enable all "wake" GPEs in this register */ +/* +* Enable all "wake" GPEs in this register and disable the +* remaining ones. +*/ status = acpi_hw_write(gpe_block->register_info[i].enable_for_wake,
PATCH 4/5 ACPICA: Introduce acpi_enable_all_wakeup_gpes()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Add a routine for host OSes to enable all wakeup GPEs and disable all of the non-wakeup ones at the same time.
It will be used for the handling of GPE wakeup from suspend-to-idle in Linux.
---
Bob, please let me know if I can fast-track this one.
--- drivers/acpi/acpica/evxfgpe.c | 32 ++++++++++++++++++++++++++++++++ include/acpi/acpixf.h | 1 + 2 files changed, 33 insertions(+)
drivers/acpi/acpica/evxfgpe.c +32 -0
@@ -596,6 +596,38 @@ acpi_status acpi_enable_all_runtime_gpesACPI_EXPORT_SYMBOL (acpi_enable_all_runtime_gpes) +/****************************************************************************** +* +* FUNCTION: acpi_enable_all_wakeup_gpes +* +* PARAMETERS: None +* +* RETURN: Status +* +* DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in +* all GPE blocks. +* +******************************************************************************/ + +acpi_status acpi_enable_all_wakeup_gpes(void) +{ +acpi_status status; + +ACPI_FUNCTION_TRACE (acpi_enable_all_wakeup_gpes); + + status =acpi_ut_acquire_mutex (ACPI_MTX_EVENTS ); +if (ACPI_FAILURE (status)) { +return_ACPI_STATUS (status); + } + + status =acpi_hw_enable_all_wakeup_gpes (); + (void )acpi_ut_release_mutex (ACPI_MTX_EVENTS ); + +return_ACPI_STATUS (status); +} + +ACPI_EXPORT_SYMBOL (acpi_enable_all_wakeup_gpes) +/******************************************************************************* * * FUNCTION: acpi_install_gpe_block
include/acpi/acpixf.h +1 -0
@@ -692,6 +692,7 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_sta *event_status)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_runtime_gpes(void)) +ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_wakeup_gpes(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_get_gpe_device(u32 gpe_index,
RE: [PATCH 4/5] ACPICA: Introduce acpi_enable_all_wakeup_gpes()
If you need it, sure.
Let me know when there is an ACPICA version
Quoted 87 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Monday, September 29, 2014 5:26 PM
To: ACPI Devel Maling List; Moore, Robert
Cc: Linux Kernel Mailing List; Zhang, Rui; Linux PM list
Subject: [PATCH 4/5] ACPICA: Introduceacpi_enable_all_wakeup_gpes()From: Rafael J. Wysocki <[email protected]>
Add a routine for host OSes to enable all wakeup GPEs and disable all of the non-wakeup ones at the same time.
It will be used for the handling of GPE wakeup from suspend-to-idle in Linux.
Signed-off-by Rafael J. Wysocki <[email protected]>---
Bob, please let me know if I can fast-track this one.
--- drivers/acpi/acpica/evxfgpe.c | 32 ++++++++++++++++++++++++++++++++ include/acpi/acpixf.h | 1 + 2 files changed, 33 insertions(+)Index:
linux-pm/drivers/acpi/acpica/evxfgpe.c
===================================================================drivers/acpi/acpica/evxfgpe.c +10
-0@@ -596,6 +596,38 @@ acpi_status acpi_enable_all_runtime_gpesACPI_EXPORT_SYMBOL (acpi_enable_all_runtime_gpes) +/********************************************************************** +******** +* +* FUNCTION: acpi_enable_all_wakeup_gpes +* +* PARAMETERS: None +* +* RETURN: Status +* +* DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
+ * all GPE blocks.
+ *drivers/acpi/acpica/evxfgpe.c +22
-0+ +*********************************************************************** +*******/ + +acpi_status acpi_enable_all_wakeup_gpes (void ) { +acpi_status status; + +ACPI_FUNCTION_TRACE (acpi_enable_all_wakeup_gpes); + + status =acpi_ut_acquire_mutex (ACPI_MTX_EVENTS ); +if (ACPI_FAILURE (status)) { +return_ACPI_STATUS (status); + } + + status =acpi_hw_enable_all_wakeup_gpes (); + (void )acpi_ut_release_mutex (ACPI_MTX_EVENTS ); + +return_ACPI_STATUS (status); +} + +ACPI_EXPORT_SYMBOL (acpi_enable_all_wakeup_gpes) +/*************************************************************************
******
*
* FUNCTION:acpi_install_gpe_block
Index:linux-pm/include/acpi/acpixf.h
===================================================================include/acpi/acpixf.h +0
-0@@ -692,6 +692,7 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_sta *event_status)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void))ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
acpi_enable_all_runtime_gpes(void))include/acpi/acpixf.h +2
-0+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status +acpi_enable_all_wakeup_gpes(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_get_gpe_device(u32 gpe_index,
Re: [PATCH 4/5] ACPICA: Introduce acpi_enable_all_wakeup_gpes()
Quoted 1 line · Robert
If you need it, sure.
Thanks!
I hope this applies to https://patchwork.kernel.org/patch/4999321/ too?
Quoted 1 line
Let me know when there is an ACPICA version
OK
Quoted 89 lines
Quoted 87 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Monday, September 29, 2014 5:26 PM
To: ACPI Devel Maling List; Moore, Robert
Cc: Linux Kernel Mailing List; Zhang, Rui; Linux PM list
Subject: [PATCH 4/5] ACPICA: Introduceacpi_enable_all_wakeup_gpes()From: Rafael J. Wysocki <[email protected]>
Add a routine for host OSes to enable all wakeup GPEs and disable all of the non-wakeup ones at the same time.
It will be used for the handling of GPE wakeup from suspend-to-idle in Linux.
Signed-off-by Rafael J. Wysocki <[email protected]>---
Bob, please let me know if I can fast-track this one.
--- drivers/acpi/acpica/evxfgpe.c | 32 ++++++++++++++++++++++++++++++++ include/acpi/acpixf.h | 1 + 2 files changed, 33 insertions(+)Index:
linux-pm/drivers/acpi/acpica/evxfgpe.c
===================================================================drivers/acpi/acpica/evxfgpe.c +10
-0@@ -596,6 +596,38 @@ acpi_status acpi_enable_all_runtime_gpesACPI_EXPORT_SYMBOL (acpi_enable_all_runtime_gpes) +/********************************************************************** +******** +* +* FUNCTION: acpi_enable_all_wakeup_gpes +* +* PARAMETERS: None +* +* RETURN: Status +* +* DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
+ * all GPE blocks.
+ *drivers/acpi/acpica/evxfgpe.c +22
-0+ +*********************************************************************** +*******/ + +acpi_status acpi_enable_all_wakeup_gpes (void ) { +acpi_status status; + +ACPI_FUNCTION_TRACE (acpi_enable_all_wakeup_gpes); + + status =acpi_ut_acquire_mutex (ACPI_MTX_EVENTS ); +if (ACPI_FAILURE (status)) { +return_ACPI_STATUS (status); + } + + status =acpi_hw_enable_all_wakeup_gpes (); + (void )acpi_ut_release_mutex (ACPI_MTX_EVENTS ); + +return_ACPI_STATUS (status); +} + +ACPI_EXPORT_SYMBOL (acpi_enable_all_wakeup_gpes) +/*************************************************************************
******
*
* FUNCTION:acpi_install_gpe_block
Index:linux-pm/include/acpi/acpixf.h
===================================================================include/acpi/acpixf.h +0
-0@@ -692,6 +692,7 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_sta *event_status)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void))ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
acpi_enable_all_runtime_gpes(void))include/acpi/acpixf.h +2
-0+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status +acpi_enable_all_wakeup_gpes(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_get_gpe_device(u32 gpe_index,
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 5/5 ACPI / sleep: Rework the handling of ACPI GPE wakeup from suspend-to-idle
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ACPI GPE wakeup from suspend-to-idle is currently based on using the IRQF_NO_SUSPEND flag for the ACPI SCI, but that is problematic for a couple of reasons. First, in principle the ACPI SCI may be shared and IRQF_NO_SUSPEND does not really work well with shared interrupts. Second, it may require the ACPI subsystem to special-case the handling of device notifications depending on whether or not they are received during suspend-to-idle in some places which would lead to fragile code. Finally, it's better the handle ACPI wakeup interrupts consistently with wakeup interrupts from other sources.
For this reason, remove the IRQF_NO_SUSPEND flag from the ACPI SCI and use enable_irq_wake()/disable_irq_wake() with it instead, which requires two additional platform hooks to be added to struct platform_freeze_ops.
--- drivers/acpi/osl.c | 2 +- drivers/acpi/sleep.c | 16 ++++++++++++++++ include/linux/suspend.h | 2 ++ kernel/power/suspend.c | 21 ++++++++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-)
include/linux/suspend.h +2 -0
@@ -189,6 +189,8 @@ struct platform_suspend_ops {struct platform_freeze_ops {int (*begin)(void ); +int (*prepare)(void ); +void (*restore)(void );void (*end)(void ); };
kernel/power/suspend.c +20 -1
@@ -144,6 +144,12 @@ static int platform_suspend_prepare(susp suspend_ops->prepare() : 0; } +static int platform_suspend_prepare_late (suspend_state_t state) +{ +return state ==PM_SUSPEND_FREEZE && freeze_ops->prepare ? + freeze_ops->prepare () :0 ; +} +static int platform_suspend_prepare_noirq (suspend_state_t state) { return state != PM_SUSPEND_FREEZE && suspend_ops->prepare_late ?
@@ -156,6 +162,12 @@ static void platform_resume_noirq(suspen suspend_ops->wake (); } +static void platform_resume_early (suspend_state_t state) +{ +if (state ==PM_SUSPEND_FREEZE && freeze_ops->restore) + freeze_ops->restore (); +} +static void platform_resume_finish (suspend_state_t state) {if (state !=PM_SUSPEND_FREEZE && suspend_ops->finish)
@@ -270,10 +282,14 @@ static int suspend_enter(suspend_state_tprintk (KERN_ERR "PM: late suspend of devices failed\n" ); goto Platform_finish; } + error =platform_suspend_prepare_late (state); +if (error) + goto Devices_early_resume; + error =dpm_suspend_noirq (PMSG_SUSPEND );if (error) {printk (KERN_ERR "PM: noirq suspend of devices failed\n" ); - goto Devices_early_resume; + goto Platform_early_resume; } error =platform_suspend_prepare_noirq (state);if (error)
@@ -326,6 +342,9 @@ static int suspend_enter(suspend_state_tplatform_resume_noirq (state);dpm_resume_noirq (PMSG_RESUME ); + Platform_early_resume: +platform_resume_early (state); + Devices_early_resume:dpm_resume_early (PMSG_RESUME );
drivers/acpi/sleep.c +16 -0
@@ -14,6 +14,7 @@#include <linux/irq.h> #include <linux/dmi.h> #include <linux/device.h> +#include <linux/interrupt.h> #include <linux/suspend.h> #include <linux/reboot.h> #include <linux/acpi.h>
@@ -626,6 +627,19 @@ static int acpi_freeze_begin(void)return 0 ; } +static int acpi_freeze_prepare (void ) +{ +acpi_enable_all_wakeup_gpes (); +enable_irq_wake (acpi_gbl_FADT.sci_interrupt); +return 0 ; +} + +static void acpi_freeze_restore (void ) +{ +disable_irq_wake (acpi_gbl_FADT.sci_interrupt); +acpi_enable_all_runtime_gpes (); +} +static void acpi_freeze_end (void ) {acpi_scan_lock_release ();
@@ -633,6 +647,8 @@ static void acpi_freeze_end(void)static const struct platform_freeze_ops acpi_freeze_ops = { .begin = acpi_freeze_begin, + .prepare = acpi_freeze_prepare, + .restore = acpi_freeze_restore, .end = acpi_freeze_end, };
drivers/acpi/osl.c +1 -1
@@ -835,7 +835,7 @@ acpi_os_install_interrupt_handler(u32 gs acpi_irq_handler = handler; acpi_irq_context = context; -if (request_irq (irq, acpi_irq,IRQF_SHARED |IRQF_NO_SUSPEND ,"acpi" , acpi_irq)) { +if (request_irq (irq, acpi_irq,IRQF_SHARED ,"acpi" , acpi_irq)) { printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); acpi_irq_handler =NULL ;return AE_NOT_ACQUIRED ;