Commit 2ed8d2b3 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM: Rework handling of interrupts during suspend-resume

Use the functions introduced in by the previous patch,
suspend_device_irqs(), resume_device_irqs() and check_wakeup_irqs(),
to rework the handling of interrupts during suspend (hibernation) and
resume.  Namely, interrupts will only be disabled on the CPU right
before suspending sysdevs, while device drivers will be prevented
from receiving interrupts, with the help of the new helper function,
before their "late" suspend callbacks run (and analogously during
resume).

In addition, since the device interrups are now disabled before the
CPU has turned all interrupts off and the CPU will ACK the interrupts
setting the IRQ_PENDING bit for them, check in sysdev_suspend() if
any wake-up interrupts are pending and abort suspend if that's the
case.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
parent 0a0c5168
...@@ -1190,8 +1190,10 @@ static int suspend(int vetoable) ...@@ -1190,8 +1190,10 @@ static int suspend(int vetoable)
struct apm_user *as; struct apm_user *as;
device_suspend(PMSG_SUSPEND); device_suspend(PMSG_SUSPEND);
local_irq_disable();
device_power_down(PMSG_SUSPEND); device_power_down(PMSG_SUSPEND);
local_irq_disable();
sysdev_suspend(PMSG_SUSPEND); sysdev_suspend(PMSG_SUSPEND);
local_irq_enable(); local_irq_enable();
...@@ -1209,9 +1211,12 @@ static int suspend(int vetoable) ...@@ -1209,9 +1211,12 @@ static int suspend(int vetoable)
if (err != APM_SUCCESS) if (err != APM_SUCCESS)
apm_error("suspend", err); apm_error("suspend", err);
err = (err == APM_SUCCESS) ? 0 : -EIO; err = (err == APM_SUCCESS) ? 0 : -EIO;
sysdev_resume(); sysdev_resume();
device_power_up(PMSG_RESUME);
local_irq_enable(); local_irq_enable();
device_power_up(PMSG_RESUME);
device_resume(PMSG_RESUME); device_resume(PMSG_RESUME);
queue_event(APM_NORMAL_RESUME, NULL); queue_event(APM_NORMAL_RESUME, NULL);
spin_lock(&user_list_lock); spin_lock(&user_list_lock);
...@@ -1228,8 +1233,9 @@ static void standby(void) ...@@ -1228,8 +1233,9 @@ static void standby(void)
{ {
int err; int err;
local_irq_disable();
device_power_down(PMSG_SUSPEND); device_power_down(PMSG_SUSPEND);
local_irq_disable();
sysdev_suspend(PMSG_SUSPEND); sysdev_suspend(PMSG_SUSPEND);
local_irq_enable(); local_irq_enable();
...@@ -1239,8 +1245,9 @@ static void standby(void) ...@@ -1239,8 +1245,9 @@ static void standby(void)
local_irq_disable(); local_irq_disable();
sysdev_resume(); sysdev_resume();
device_power_up(PMSG_RESUME);
local_irq_enable(); local_irq_enable();
device_power_up(PMSG_RESUME);
} }
static apm_event_t get_event(void) static apm_event_t get_event(void)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/resume-trace.h> #include <linux/resume-trace.h>
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/interrupt.h>
#include "../base.h" #include "../base.h"
#include "power.h" #include "power.h"
...@@ -349,7 +350,8 @@ static int resume_device_noirq(struct device *dev, pm_message_t state) ...@@ -349,7 +350,8 @@ static int resume_device_noirq(struct device *dev, pm_message_t state)
* Execute the appropriate "noirq resume" callback for all devices marked * Execute the appropriate "noirq resume" callback for all devices marked
* as DPM_OFF_IRQ. * as DPM_OFF_IRQ.
* *
* Must be called with interrupts disabled and only one CPU running. * Must be called under dpm_list_mtx. Device drivers should not receive
* interrupts while it's being executed.
*/ */
static void dpm_power_up(pm_message_t state) static void dpm_power_up(pm_message_t state)
{ {
...@@ -370,14 +372,13 @@ static void dpm_power_up(pm_message_t state) ...@@ -370,14 +372,13 @@ static void dpm_power_up(pm_message_t state)
* device_power_up - Turn on all devices that need special attention. * device_power_up - Turn on all devices that need special attention.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
* *
* Power on system devices, then devices that required we shut them down * Call the "early" resume handlers and enable device drivers to receive
* with interrupts disabled. * interrupts.
*
* Must be called with interrupts disabled.
*/ */
void device_power_up(pm_message_t state) void device_power_up(pm_message_t state)
{ {
dpm_power_up(state); dpm_power_up(state);
resume_device_irqs();
} }
EXPORT_SYMBOL_GPL(device_power_up); EXPORT_SYMBOL_GPL(device_power_up);
...@@ -602,16 +603,17 @@ static int suspend_device_noirq(struct device *dev, pm_message_t state) ...@@ -602,16 +603,17 @@ static int suspend_device_noirq(struct device *dev, pm_message_t state)
* device_power_down - Shut down special devices. * device_power_down - Shut down special devices.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
* *
* Power down devices that require interrupts to be disabled. * Prevent device drivers from receiving interrupts and call the "late"
* Then power down system devices. * suspend handlers.
* *
* Must be called with interrupts disabled and only one CPU running. * Must be called under dpm_list_mtx.
*/ */
int device_power_down(pm_message_t state) int device_power_down(pm_message_t state)
{ {
struct device *dev; struct device *dev;
int error = 0; int error = 0;
suspend_device_irqs();
list_for_each_entry_reverse(dev, &dpm_list, power.entry) { list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
error = suspend_device_noirq(dev, state); error = suspend_device_noirq(dev, state);
if (error) { if (error) {
...@@ -621,7 +623,7 @@ int device_power_down(pm_message_t state) ...@@ -621,7 +623,7 @@ int device_power_down(pm_message_t state)
dev->power.status = DPM_OFF_IRQ; dev->power.status = DPM_OFF_IRQ;
} }
if (error) if (error)
dpm_power_up(resume_event(state)); device_power_up(resume_event(state));
return error; return error;
} }
EXPORT_SYMBOL_GPL(device_power_down); EXPORT_SYMBOL_GPL(device_power_down);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/interrupt.h>
#include "base.h" #include "base.h"
...@@ -369,6 +370,13 @@ int sysdev_suspend(pm_message_t state) ...@@ -369,6 +370,13 @@ int sysdev_suspend(pm_message_t state)
struct sysdev_driver *drv, *err_drv; struct sysdev_driver *drv, *err_drv;
int ret; int ret;
pr_debug("Checking wake-up interrupts\n");
/* Return error code if there are any wake-up interrupts pending */
ret = check_wakeup_irqs();
if (ret)
return ret;
pr_debug("Suspending System Devices\n"); pr_debug("Suspending System Devices\n");
list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) {
......
...@@ -39,12 +39,6 @@ static int xen_suspend(void *data) ...@@ -39,12 +39,6 @@ static int xen_suspend(void *data)
BUG_ON(!irqs_disabled()); BUG_ON(!irqs_disabled());
err = device_power_down(PMSG_SUSPEND);
if (err) {
printk(KERN_ERR "xen_suspend: device_power_down failed: %d\n",
err);
return err;
}
err = sysdev_suspend(PMSG_SUSPEND); err = sysdev_suspend(PMSG_SUSPEND);
if (err) { if (err) {
printk(KERN_ERR "xen_suspend: sysdev_suspend failed: %d\n", printk(KERN_ERR "xen_suspend: sysdev_suspend failed: %d\n",
...@@ -69,7 +63,6 @@ static int xen_suspend(void *data) ...@@ -69,7 +63,6 @@ static int xen_suspend(void *data)
xen_mm_unpin_all(); xen_mm_unpin_all();
sysdev_resume(); sysdev_resume();
device_power_up(PMSG_RESUME);
if (!*cancelled) { if (!*cancelled) {
xen_irq_resume(); xen_irq_resume();
...@@ -108,6 +101,12 @@ static void do_suspend(void) ...@@ -108,6 +101,12 @@ static void do_suspend(void)
/* XXX use normal device tree? */ /* XXX use normal device tree? */
xenbus_suspend(); xenbus_suspend();
err = device_power_down(PMSG_SUSPEND);
if (err) {
printk(KERN_ERR "device_power_down failed: %d\n", err);
goto resume_devices;
}
err = stop_machine(xen_suspend, &cancelled, cpumask_of(0)); err = stop_machine(xen_suspend, &cancelled, cpumask_of(0));
if (err) { if (err) {
printk(KERN_ERR "failed to start xen_suspend: %d\n", err); printk(KERN_ERR "failed to start xen_suspend: %d\n", err);
...@@ -120,6 +119,9 @@ static void do_suspend(void) ...@@ -120,6 +119,9 @@ static void do_suspend(void)
} else } else
xenbus_suspend_cancel(); xenbus_suspend_cancel();
device_power_up(PMSG_RESUME);
resume_devices:
device_resume(PMSG_RESUME); device_resume(PMSG_RESUME);
/* Make sure timer events get retriggered on all CPUs */ /* Make sure timer events get retriggered on all CPUs */
......
...@@ -1454,7 +1454,6 @@ int kernel_kexec(void) ...@@ -1454,7 +1454,6 @@ int kernel_kexec(void)
if (error) if (error)
goto Resume_devices; goto Resume_devices;
device_pm_lock(); device_pm_lock();
local_irq_disable();
/* At this point, device_suspend() has been called, /* At this point, device_suspend() has been called,
* but *not* device_power_down(). We *must* * but *not* device_power_down(). We *must*
* device_power_down() now. Otherwise, drivers for * device_power_down() now. Otherwise, drivers for
...@@ -1464,8 +1463,9 @@ int kernel_kexec(void) ...@@ -1464,8 +1463,9 @@ int kernel_kexec(void)
*/ */
error = device_power_down(PMSG_FREEZE); error = device_power_down(PMSG_FREEZE);
if (error) if (error)
goto Enable_irqs; goto Unlock_pm;
local_irq_disable();
/* Suspend system devices */ /* Suspend system devices */
error = sysdev_suspend(PMSG_FREEZE); error = sysdev_suspend(PMSG_FREEZE);
if (error) if (error)
...@@ -1484,9 +1484,9 @@ int kernel_kexec(void) ...@@ -1484,9 +1484,9 @@ int kernel_kexec(void)
if (kexec_image->preserve_context) { if (kexec_image->preserve_context) {
sysdev_resume(); sysdev_resume();
Power_up_devices: Power_up_devices:
device_power_up(PMSG_RESTORE);
Enable_irqs:
local_irq_enable(); local_irq_enable();
device_power_up(PMSG_RESTORE);
Unlock_pm:
device_pm_unlock(); device_pm_unlock();
enable_nonboot_cpus(); enable_nonboot_cpus();
Resume_devices: Resume_devices:
......
...@@ -214,7 +214,7 @@ static int create_image(int platform_mode) ...@@ -214,7 +214,7 @@ static int create_image(int platform_mode)
return error; return error;
device_pm_lock(); device_pm_lock();
local_irq_disable();
/* At this point, device_suspend() has been called, but *not* /* At this point, device_suspend() has been called, but *not*
* device_power_down(). We *must* call device_power_down() now. * device_power_down(). We *must* call device_power_down() now.
* Otherwise, drivers for some devices (e.g. interrupt controllers) * Otherwise, drivers for some devices (e.g. interrupt controllers)
...@@ -225,8 +225,11 @@ static int create_image(int platform_mode) ...@@ -225,8 +225,11 @@ static int create_image(int platform_mode)
if (error) { if (error) {
printk(KERN_ERR "PM: Some devices failed to power down, " printk(KERN_ERR "PM: Some devices failed to power down, "
"aborting hibernation\n"); "aborting hibernation\n");
goto Enable_irqs; goto Unlock;
} }
local_irq_disable();
sysdev_suspend(PMSG_FREEZE); sysdev_suspend(PMSG_FREEZE);
if (error) { if (error) {
printk(KERN_ERR "PM: Some devices failed to power down, " printk(KERN_ERR "PM: Some devices failed to power down, "
...@@ -252,12 +255,16 @@ static int create_image(int platform_mode) ...@@ -252,12 +255,16 @@ static int create_image(int platform_mode)
/* NOTE: device_power_up() is just a resume() for devices /* NOTE: device_power_up() is just a resume() for devices
* that suspended with irqs off ... no overall powerup. * that suspended with irqs off ... no overall powerup.
*/ */
Power_up_devices: Power_up_devices:
local_irq_enable();
device_power_up(in_suspend ? device_power_up(in_suspend ?
(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
Enable_irqs:
local_irq_enable(); Unlock:
device_pm_unlock(); device_pm_unlock();
return error; return error;
} }
...@@ -336,13 +343,16 @@ static int resume_target_kernel(void) ...@@ -336,13 +343,16 @@ static int resume_target_kernel(void)
int error; int error;
device_pm_lock(); device_pm_lock();
local_irq_disable();
error = device_power_down(PMSG_QUIESCE); error = device_power_down(PMSG_QUIESCE);
if (error) { if (error) {
printk(KERN_ERR "PM: Some devices failed to power down, " printk(KERN_ERR "PM: Some devices failed to power down, "
"aborting resume\n"); "aborting resume\n");
goto Enable_irqs; goto Unlock;
} }
local_irq_disable();
sysdev_suspend(PMSG_QUIESCE); sysdev_suspend(PMSG_QUIESCE);
/* We'll ignore saved state, but this gets preempt count (etc) right */ /* We'll ignore saved state, but this gets preempt count (etc) right */
save_processor_state(); save_processor_state();
...@@ -366,11 +376,16 @@ static int resume_target_kernel(void) ...@@ -366,11 +376,16 @@ static int resume_target_kernel(void)
swsusp_free(); swsusp_free();
restore_processor_state(); restore_processor_state();
touch_softlockup_watchdog(); touch_softlockup_watchdog();
sysdev_resume(); sysdev_resume();
device_power_up(PMSG_RECOVER);
Enable_irqs:
local_irq_enable(); local_irq_enable();
device_power_up(PMSG_RECOVER);
Unlock:
device_pm_unlock(); device_pm_unlock();
return error; return error;
} }
...@@ -447,15 +462,16 @@ int hibernation_platform_enter(void) ...@@ -447,15 +462,16 @@ int hibernation_platform_enter(void)
goto Finish; goto Finish;
device_pm_lock(); device_pm_lock();
local_irq_disable();
error = device_power_down(PMSG_HIBERNATE); error = device_power_down(PMSG_HIBERNATE);
if (!error) { if (!error) {
local_irq_disable();
sysdev_suspend(PMSG_HIBERNATE); sysdev_suspend(PMSG_HIBERNATE);
hibernation_ops->enter(); hibernation_ops->enter();
/* We should never get here */ /* We should never get here */
while (1); while (1);
} }
local_irq_enable();
device_pm_unlock(); device_pm_unlock();
/* /*
...@@ -464,12 +480,15 @@ int hibernation_platform_enter(void) ...@@ -464,12 +480,15 @@ int hibernation_platform_enter(void)
*/ */
Finish: Finish:
hibernation_ops->finish(); hibernation_ops->finish();
Resume_devices: Resume_devices:
entering_platform_hibernation = false; entering_platform_hibernation = false;
device_resume(PMSG_RESTORE); device_resume(PMSG_RESTORE);
resume_console(); resume_console();
Close: Close:
hibernation_ops->end(); hibernation_ops->end();
return error; return error;
} }
......
...@@ -287,17 +287,19 @@ void __attribute__ ((weak)) arch_suspend_enable_irqs(void) ...@@ -287,17 +287,19 @@ void __attribute__ ((weak)) arch_suspend_enable_irqs(void)
*/ */
static int suspend_enter(suspend_state_t state) static int suspend_enter(suspend_state_t state)
{ {
int error = 0; int error;
device_pm_lock(); device_pm_lock();
arch_suspend_disable_irqs();
BUG_ON(!irqs_disabled());
if ((error = device_power_down(PMSG_SUSPEND))) { error = device_power_down(PMSG_SUSPEND);
if (error) {
printk(KERN_ERR "PM: Some devices failed to power down\n"); printk(KERN_ERR "PM: Some devices failed to power down\n");
goto Done; goto Done;
} }
arch_suspend_disable_irqs();
BUG_ON(!irqs_disabled());
error = sysdev_suspend(PMSG_SUSPEND); error = sysdev_suspend(PMSG_SUSPEND);
if (!error) { if (!error) {
if (!suspend_test(TEST_CORE)) if (!suspend_test(TEST_CORE))
...@@ -305,11 +307,14 @@ static int suspend_enter(suspend_state_t state) ...@@ -305,11 +307,14 @@ static int suspend_enter(suspend_state_t state)
sysdev_resume(); sysdev_resume();
} }
device_power_up(PMSG_RESUME);
Done:
arch_suspend_enable_irqs(); arch_suspend_enable_irqs();
BUG_ON(irqs_disabled()); BUG_ON(irqs_disabled());
device_power_up(PMSG_RESUME);
Done:
device_pm_unlock(); device_pm_unlock();
return error; return error;
} }
......
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