PM / Sleep: Introduce new phases of device suspend/resume
Subsystems (8)
cover PM / Sleep: Introduce new phases of device suspend/resume
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct dev_pm_ops and makes the PM core use them during system power transitions.
[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
Comments welcome!
Thanks,
Rafael
RFC PATCH 1/2 PM / Sleep: Introduce "late suspend" and "early resume" of devices
From: Rafael J. Wysocki <[email protected]>
The current device suspend/resume phases during system-wide power transitions appear to be insufficient for some platforms that want to use the same callback routines for saving device states and related operations during runtime suspend/resume as well as during system suspend/resume. In principle, they could point their .suspend_noirq() and .resume_noirq() to the same callback routines as their .runtime_suspend() and .runtime_resume(), respectively, but at least some of them require device interrupts to be enabled while the code in those routines is running.
It also makes sense to have device suspend-resume callbacks that will be executed with runtime PM disabled and with device interrupts enabled in case someone needs to run some special code in that context during system-wide power transitions.
Apart from this, .suspend_noirq() and .resume_noirq() were introduced as a workaround for drivers using shared interrupts and failing to prevent their interrupt handlers from accessing suspended hardware. It appears to be better not to use them for other porposes, or we may have to deal with some serious confusion (which seems to be happening already).
For the above reasons, introduce new device suspend/resume phases, "late suspend" and "early resume" (and analogously for hibernation) whose callback will be executed with runtime PM disabled and with device interrupts enabled and whose callback pointers generally may point to runtime suspend/resume routines.
--- Documentation/power/devices.txt | 93 +++++++++------ arch/x86/kernel/apm_32.c | 11 - drivers/base/power/main.c | 247 ++++++++++++++++++++++++++++++++++++---- drivers/xen/manage.c | 6 include/linux/pm.h | 43 +++++- include/linux/suspend.h | 4 kernel/kexec.c | 8 - kernel/power/hibernate.c | 24 +-- kernel/power/main.c | 8 - kernel/power/suspend.c | 4 10 files changed, 357 insertions(+), 91 deletions(-)
drivers/base/power/main.c +225 -22
@@ -47,6 +47,7 @@ typedef int (*pm_callback_t)(struct deviLIST_HEAD (dpm_list);LIST_HEAD (dpm_prepared_list);LIST_HEAD (dpm_suspended_list); +LIST_HEAD (dpm_late_early_list);LIST_HEAD (dpm_noirq_list);struct suspend_stats suspend_stats;
@@ -246,6 +247,40 @@ static pm_callback_t pm_op(const struct }/** +* pm_late_early_op - Return the PM operation appropriate for given PM event. +* @ops: PM operations to choose from. +* @state: PM transition of the system being carried out. +* +* Runtime PM is disabled for @dev while this function is being executed. +*/ +static pm_callback_t pm_late_early_op (const struct dev_pm_ops *ops, +pm_message_t state) +{ +switch (state.event) { +#ifdef CONFIG_SUSPEND +case PM_EVENT_SUSPEND : +return ops->suspend_late; +case PM_EVENT_RESUME : +return ops->resume_early; +#endif /* CONFIG_SUSPEND */ +#ifdef CONFIG_HIBERNATE_CALLBACKS +case PM_EVENT_FREEZE : +case PM_EVENT_QUIESCE : +return ops->freeze_late; +case PM_EVENT_HIBERNATE : +return ops->poweroff_late; +case PM_EVENT_THAW : +case PM_EVENT_RECOVER : +return ops->thaw_early; +case PM_EVENT_RESTORE : +return ops->restore_early; +#endif /* CONFIG_HIBERNATE_CALLBACKS */ + } + +return NULL ; +} + +/** * pm_noirq_op - Return the PM operation appropriate for given PM event. * @ops: PM operations to choose from. * @state: PM transition of the system being carried out.
@@ -374,21 +409,21 @@ static int device_resume_noirq(struct deTRACE_RESUME (0 );if (dev->pm_domain) { - info ="EARLY power domain " ; + info ="noirq power domain " ; callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { - info ="EARLY type " ; + info ="noirq type " ; callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { - info ="EARLY class " ; + info ="noirq class " ; callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { - info ="EARLY bus " ; + info ="noirq bus " ; callback =pm_noirq_op (dev->bus->pm, state); }if (!callback && dev->driver && dev->driver->pm) { - info ="EARLY driver " ; + info ="noirq driver " ; callback =pm_noirq_op (dev->driver->pm, state); }
@@ -399,13 +434,13 @@ static int device_resume_noirq(struct de }/** -* dpm_resume_noirq - Execute "early resume" callbacks for non-sysdev devices. +* dpm_resume_noirq - Execute "noirq resume" callbacks for all devices. * @state: PM transition of the system being carried out. * -* Call the "noirq" resume handlers for all devices marked as DPM_OFF_IRQ and +* Call the "noirq" resume handlers for all devices in dpm_noirq_list and * enable device drivers to receive interrupts. */ -void dpm_resume_noirq (pm_message_t state) +static void dpm_resume_noirq (pm_message_t state) {ktime_t starttime =ktime_get ();
@@ -415,7 +450,7 @@ void dpm_resume_noirq(pm_message_t stateint error;get_device (dev); -list_move_tail (&dev->power.entry, &dpm_suspended_list); +list_move_tail (&dev->power.entry, &dpm_late_early_list);mutex_unlock (&dpm_list_mtx); error =device_resume_noirq (dev, state);
@@ -423,6 +458,80 @@ void dpm_resume_noirq(pm_message_t state suspend_stats.failed_resume_noirq++;dpm_save_failed_step (SUSPEND_RESUME_NOIRQ );dpm_save_failed_dev (dev_name (dev)); +pm_dev_err (dev, state," noirq" , error); + } + +mutex_lock (&dpm_list_mtx); +put_device (dev); + } +mutex_unlock (&dpm_list_mtx); +dpm_show_time (starttime, state,"noirq" ); +resume_device_irqs (); +} + +/** +* device_resume_early - Execute an "early resume" callback for given device. +* @dev: Device to handle. +* @state: PM transition of the system being carried out. +* +* Runtime PM is disabled for @dev while this function is being executed. +*/ +static int device_resume_early (struct device *dev,pm_message_t state) +{ +pm_callback_t callback =NULL ; +char *info =NULL ; +int error =0 ; + +TRACE_DEVICE (dev); +TRACE_RESUME (0 ); + +if (dev->pm_domain) { + info ="early power domain " ; + callback =pm_late_early_op (&dev->pm_domain->ops, state); + }else if (dev->type && dev->type->pm) { + info ="early type " ; + callback =pm_late_early_op (dev->type->pm, state); + }else if (dev->class && dev->class->pm) { + info ="early class " ; + callback =pm_late_early_op (dev->class->pm, state); + }else if (dev->bus && dev->bus->pm) { + info ="early bus " ; + callback =pm_late_early_op (dev->bus->pm, state); + } + +if (!callback && dev->driver && dev->driver->pm) { + info ="early driver " ; + callback =pm_late_early_op (dev->driver->pm, state); + } + + error =dpm_run_callback (callback, dev, state, info); + +TRACE_RESUME (error); +return error; +} + +/** +* 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) +{ +ktime_t starttime =ktime_get (); + +mutex_lock (&dpm_list_mtx); +while (!list_empty (&dpm_late_early_list)) { +struct device *dev =to_device (dpm_late_early_list.next); +int error; + +get_device (dev); +list_move_tail (&dev->power.entry, &dpm_suspended_list); +mutex_unlock (&dpm_list_mtx); + + error =device_resume_early (dev, state); +if (error) { + suspend_stats.failed_resume_early++; +dpm_save_failed_step (SUSPEND_RESUME_EARLY ); +dpm_save_failed_dev (dev_name (dev));pm_dev_err (dev, state," early" , error); }
@@ -431,9 +540,18 @@ void dpm_resume_noirq(pm_message_t state }mutex_unlock (&dpm_list_mtx);dpm_show_time (starttime, state,"early" ); -resume_device_irqs (); } -EXPORT_SYMBOL_GPL (dpm_resume_noirq); + +/** +* dpm_resume_start - Execute "noirq" and "early" device callbacks. +* @state: PM transition of the system being carried out. +*/ +void dpm_resume_start (pm_message_t state) +{ +dpm_resume_noirq (state); +dpm_resume_early (state); +} +EXPORT_SYMBOL_GPL (dpm_resume_start);/** * device_resume - Execute "resume" callbacks for given device.
@@ -716,21 +834,21 @@ static int device_suspend_noirq(struct dchar *info =NULL ;if (dev->pm_domain) { - info ="LATE power domain " ; + info ="noirq power domain " ; callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { - info ="LATE type " ; + info ="noirq type " ; callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { - info ="LATE class " ; + info ="noirq class " ; callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { - info ="LATE bus " ; + info ="noirq bus " ; callback =pm_noirq_op (dev->bus->pm, state); }if (!callback && dev->driver && dev->driver->pm) { - info ="LATE driver " ; + info ="noirq driver " ; callback =pm_noirq_op (dev->driver->pm, state); }
@@ -738,21 +856,21 @@ static int device_suspend_noirq(struct d }/** -* dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices. +* dpm_suspend_noirq - Execute "noirq suspend" callbacks for all devices. * @state: PM transition of the system being carried out. * * Prevent device drivers from receiving interrupts and call the "noirq" suspend * handlers for all non-sysdev devices. */ -int dpm_suspend_noirq (pm_message_t state) +static int dpm_suspend_noirq (pm_message_t state) {ktime_t starttime =ktime_get ();int error =0 ;suspend_device_irqs ();mutex_lock (&dpm_list_mtx); -while (!list_empty (&dpm_suspended_list)) { -struct device *dev =to_device (dpm_suspended_list.prev); +while (!list_empty (&dpm_late_early_list)) { +struct device *dev =to_device (dpm_late_early_list.prev);get_device (dev);mutex_unlock (&dpm_list_mtx);
@@ -761,7 +879,7 @@ int dpm_suspend_noirq(pm_message_t statemutex_lock (&dpm_list_mtx);if (error) { -pm_dev_err (dev, state," late" , error); +pm_dev_err (dev, state," noirq" , error); suspend_stats.failed_suspend_noirq++;dpm_save_failed_step (SUSPEND_SUSPEND_NOIRQ );dpm_save_failed_dev (dev_name (dev));
@@ -776,10 +894,95 @@ int dpm_suspend_noirq(pm_message_t stateif (error)dpm_resume_noirq (resume_event (state));else +dpm_show_time (starttime, state,"noirq" ); +return error; +} + +/** +* device_suspend_late - Execute a "late suspend" callback for given device. +* @dev: Device to handle. +* @state: PM transition of the system being carried out. +* +* Runtime PM is disabled for @dev while this function is being executed. +*/ +static int device_suspend_late (struct device *dev,pm_message_t state) +{ +pm_callback_t callback =NULL ; +char *info =NULL ; + +if (dev->pm_domain) { + info ="late power domain " ; + callback =pm_late_early_op (&dev->pm_domain->ops, state); + }else if (dev->type && dev->type->pm) { + info ="late type " ; + callback =pm_late_early_op (dev->type->pm, state); + }else if (dev->class && dev->class->pm) { + info ="late class " ; + callback =pm_late_early_op (dev->class->pm, state); + }else if (dev->bus && dev->bus->pm) { + info ="late bus " ; + callback =pm_late_early_op (dev->bus->pm, state); + } + +if (!callback && dev->driver && dev->driver->pm) { + info ="late driver " ; + callback =pm_late_early_op (dev->driver->pm, state); + } + +return dpm_run_callback (callback, dev, state, info); +} + +/** +* 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) +{ +ktime_t starttime =ktime_get (); +int error =0 ; + +mutex_lock (&dpm_list_mtx); +while (!list_empty (&dpm_suspended_list)) { +struct device *dev =to_device (dpm_suspended_list.prev); + +get_device (dev); +mutex_unlock (&dpm_list_mtx); + + error =device_suspend_late (dev, state); + +mutex_lock (&dpm_list_mtx); +if (error) { +pm_dev_err (dev, state," late" , error); + suspend_stats.failed_suspend_late++; +dpm_save_failed_step (SUSPEND_SUSPEND_LATE ); +dpm_save_failed_dev (dev_name (dev)); +put_device (dev); +break ; + } +if (!list_empty (&dev->power.entry)) +list_move (&dev->power.entry, &dpm_late_early_list); +put_device (dev); + } +mutex_unlock (&dpm_list_mtx); +if (error) +dpm_resume_early (resume_event (state)); +else dpm_show_time (starttime, state,"late" ); +return error; } -EXPORT_SYMBOL_GPL (dpm_suspend_noirq); + +/** +* dpm_suspend_end - Execute "late" and "noirq" device suspend callbacks. +* @state: PM transition of the system being carried out. +*/ +int dpm_suspend_end (pm_message_t state) +{ +int error =dpm_suspend_late (state); + +return error ? :dpm_suspend_noirq (state); +} +EXPORT_SYMBOL_GPL (dpm_suspend_end);/** * legacy_suspend - Execute a legacy (bus or class) suspend callback for device.
kernel/power/suspend.c +2 -2
@@ -149,7 +149,7 @@ static int suspend_enter(suspend_state_t goto Platform_finish; } - error =dpm_suspend_noirq (PMSG_SUSPEND ); + error =dpm_suspend_end (PMSG_SUSPEND );if (error) {printk (KERN_ERR "PM: Some devices failed to power down\n" ); goto Platform_finish;
@@ -191,7 +191,7 @@ static int suspend_enter(suspend_state_tif (suspend_ops->wake) suspend_ops->wake (); -dpm_resume_noirq (PMSG_RESUME ); +dpm_resume_start (PMSG_RESUME ); Platform_finish:if (suspend_ops->finish)
include/linux/suspend.h +4 -0
@@ -42,8 +42,10 @@ enum suspend_stat_step {SUSPEND_FREEZE =1 ,SUSPEND_PREPARE ,SUSPEND_SUSPEND , +SUSPEND_SUSPEND_LATE ,SUSPEND_SUSPEND_NOIRQ ,SUSPEND_RESUME_NOIRQ , +SUSPEND_RESUME_EARLY , SUSPEND_RESUME };
@@ -53,8 +55,10 @@ struct suspend_stats {int failed_freeze;int failed_prepare;int failed_suspend; +int failed_suspend_late;int failed_suspend_noirq;int failed_resume; +int failed_resume_early;int failed_resume_noirq;#define REC_FAILED_NUM 2int last_failed_dev;
include/linux/pm.h +35 -8
105 lines not on this page · raw message
kernel/power/hibernate.c +12 -12
@@ -245,8 +245,8 @@ void swsusp_show_speed(struct timeval *s* create_image - Create a hibernation image. * @platform_mode: Whether or not to use the platform driver. * -* Execute device drivers' .freeze_noirq() callbacks, create a hibernation image -* and execute the drivers' .thaw_noirq() callbacks. +* Execute device drivers' "late" and "noirq" freeze callbacks, create a +* hibernation image and run the drivers' "noirq" and "early" thaw callbacks. * * Control reappears in this routine after the subsequent restore. */
@@ -254,7 +254,7 @@ static int create_image(int platform_mod {int error; - error =dpm_suspend_noirq (PMSG_FREEZE ); + error =dpm_suspend_end (PMSG_FREEZE );if (error) {printk (KERN_ERR "PM: Some devices failed to power down, " "aborting hibernation\n" );
@@ -306,7 +306,7 @@ static int create_image(int platform_mod Platform_finish:platform_finish (platform_mode); -dpm_resume_noirq (in_suspend ? +dpm_resume_start (in_suspend ? (error ?PMSG_RECOVER :PMSG_THAW ) :PMSG_RESTORE );return error;
@@ -394,16 +394,16 @@ int hibernation_snapshot(int platform_mo* resume_target_kernel - Restore system state from a hibernation image. * @platform_mode: Whether or not to use the platform driver. * -* Execute device drivers' .freeze_noirq() callbacks, restore the contents of -* highmem that have not been restored yet from the image and run the low-level -* code that will restore the remaining contents of memory and switch to the -* just restored target kernel. +* Execute device drivers' "noirq" and "late" freeze callbacks, restore the +* contents of highmem that have not been restored yet from the image and run +* the low-level code that will restore the remaining contents of memory and +* switch to the just restored target kernel. */ static int resume_target_kernel (bool platform_mode) {int error; - error =dpm_suspend_noirq (PMSG_QUIESCE ); + error =dpm_suspend_end (PMSG_QUIESCE );if (error) {printk (KERN_ERR "PM: Some devices failed to power down, " "aborting resume\n" );
@@ -460,7 +460,7 @@ static int resume_target_kernel(bool pla Cleanup:platform_restore_cleanup (platform_mode); -dpm_resume_noirq (PMSG_RECOVER ); +dpm_resume_start (PMSG_RECOVER );return error; }
@@ -518,7 +518,7 @@ int hibernation_platform_enter(void) goto Resume_devices; } - error =dpm_suspend_noirq (PMSG_HIBERNATE ); + error =dpm_suspend_end (PMSG_HIBERNATE );if (error) goto Resume_devices;
@@ -549,7 +549,7 @@ int hibernation_platform_enter(void) Platform_finish: hibernation_ops->finish (); -dpm_resume_noirq (PMSG_RESTORE ); +dpm_resume_start (PMSG_RESTORE ); Resume_devices: entering_platform_hibernation = false;
arch/x86/kernel/apm_32.c +5 -6
@@ -1234,8 +1234,7 @@ static int suspend(int vetoable)struct apm_user *as;dpm_suspend_start (PMSG_SUSPEND ); - -dpm_suspend_noirq (PMSG_SUSPEND ); +dpm_suspend_end (PMSG_SUSPEND );local_irq_disable ();syscore_suspend ();
@@ -1259,9 +1258,9 @@ static int suspend(int vetoable)syscore_resume ();local_irq_enable (); -dpm_resume_noirq (PMSG_RESUME ); - +dpm_resume_start (PMSG_RESUME );dpm_resume_end (PMSG_RESUME ); +queue_event (APM_NORMAL_RESUME ,NULL );spin_lock (&user_list_lock);for (as = user_list; as !=NULL ; as = as->next) {
@@ -1277,7 +1276,7 @@ static void standby(void) {int err; -dpm_suspend_noirq (PMSG_SUSPEND ); +dpm_suspend_end (PMSG_SUSPEND );local_irq_disable ();syscore_suspend ();
@@ -1291,7 +1290,7 @@ static void standby(void)syscore_resume ();local_irq_enable (); -dpm_resume_noirq (PMSG_RESUME ); +dpm_resume_start (PMSG_RESUME ); }static apm_event_t get_event (void )
drivers/xen/manage.c +3 -3
@@ -129,9 +129,9 @@ static void do_suspend(void)printk (KERN_DEBUG "suspending xenstore...\n" );xs_suspend (); - err =dpm_suspend_noirq (PMSG_FREEZE ); + err =dpm_suspend_end (PMSG_FREEZE );if (err) { -printk (KERN_ERR "dpm_suspend_noirq failed: %d\n" , err); +printk (KERN_ERR "dpm_suspend_end failed: %d\n" , err); goto out_resume; }
@@ -149,7 +149,7 @@ static void do_suspend(void) err =stop_machine (xen_suspend, &si,cpumask_of (0 )); -dpm_resume_noirq (si.cancelled ?PMSG_THAW :PMSG_RESTORE ); +dpm_resume_start (si.cancelled ?PMSG_THAW :PMSG_RESTORE );if (err) {printk (KERN_ERR "failed to start xen_suspend: %d\n" , err);
kernel/kexec.c +4 -4
@@ -1535,13 +1535,13 @@ int kernel_kexec(void)if (error) goto Resume_console;/* At this point, dpm_suspend_start() has been called, -* but *not* dpm_suspend_noirq(). We *must* call -* dpm_suspend_noirq() now. Otherwise, drivers for +* but *not* dpm_suspend_end(). We *must* call +* dpm_suspend_end() now. Otherwise, drivers for * some devices (e.g. interrupt controllers) become * desynchronized with the actual state of the * hardware at resume time, and evil weirdness ensues. */ - error =dpm_suspend_noirq (PMSG_FREEZE ); + error =dpm_suspend_end (PMSG_FREEZE );if (error) goto Resume_devices; error =disable_nonboot_cpus ();
@@ -1568,7 +1568,7 @@ int kernel_kexec(void)local_irq_enable (); Enable_cpus:enable_nonboot_cpus (); -dpm_resume_noirq (PMSG_RESTORE ); +dpm_resume_start (PMSG_RESTORE ); Resume_devices:dpm_resume_end (PMSG_RESTORE ); Resume_console:
kernel/power/main.c +6 -2
@@ -165,16 +165,20 @@ static int suspend_stats_show(struct seq last_errno %=REC_FAILED_NUM ; last_step = suspend_stats.last_failed_step +REC_FAILED_NUM -1 ; last_step %=REC_FAILED_NUM ; -seq_printf (s,"%s: %d\n%s: %d\n%s: %d\n%s: %d\n" -"%s: %d\n%s: %d\n%s: %d\n%s: %d\n" , +seq_printf (s,"%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n" +"%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n" ,"success" , suspend_stats.success,"fail" , suspend_stats.fail,"failed_freeze" , suspend_stats.failed_freeze,"failed_prepare" , suspend_stats.failed_prepare,"failed_suspend" , suspend_stats.failed_suspend, +"failed_suspend_late" , + suspend_stats.failed_suspend_late,"failed_suspend_noirq" , suspend_stats.failed_suspend_noirq,"failed_resume" , suspend_stats.failed_resume, +"failed_resume_early" , + suspend_stats.failed_resume_early,"failed_resume_noirq" , suspend_stats.failed_resume_noirq); seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
Documentation/power/devices.txt +61 -32
170 lines not on this page · raw message
Re: [RFC][PATCH 1/2] PM / Sleep: Introduce "late suspend" and "early resume" of devices
Quoted 5 lines · Rafael J. Wysocki
For the above reasons, introduce new device suspend/resume phases, "late suspend" and "early resume" (and analogously for hibernation) whose callback will be executed with runtime PM disabled and with device interrupts enabled and whose callback pointers generally may point to runtime suspend/resume routines.
I can't claim to have gone through the code with a fine toothcomb but from an interface point of view this is really clear and helpful, should be very useful:
RFC PATCH 2/2 PM / Sleep: Introduce generic callbacks for new device PM phases
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Introduce generic subsystem callbacks for the new phases of device suspend/resume during system power transitions: "late suspend", "early resume", "late freeze", "early thaw", "late poweroff", "early restore".
--- drivers/base/power/generic_ops.c | 163 +++++++++++++++++++++++++-------------- include/linux/pm.h | 6 + 2 files changed, 113 insertions(+), 56 deletions(-)
drivers/base/power/generic_ops.c +107 -56
@@ -92,59 +92,28 @@ int pm_generic_prepare(struct device *de }/** -* __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback. -* @dev: Device to handle. -* @event: PM transition of the system under way. -* @bool: Whether or not this is the "noirq" stage. -* -* Execute the PM callback corresponding to @event provided by the driver of -* @dev, if defined, and return its error code. Return 0 if the callback is -* not present. -*/ -static int __pm_generic_call (struct device *dev,int event,bool noirq) -{ -const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -int (*callback)(struct device *); - -if (!pm) -return 0 ; - -switch (event) { -case PM_EVENT_SUSPEND : - callback = noirq ? pm->suspend_noirq : pm->suspend; -break ; -case PM_EVENT_FREEZE : - callback = noirq ? pm->freeze_noirq : pm->freeze; -break ; -case PM_EVENT_HIBERNATE : - callback = noirq ? pm->poweroff_noirq : pm->poweroff; -break ; -case PM_EVENT_RESUME : - callback = noirq ? pm->resume_noirq : pm->resume; -break ; -case PM_EVENT_THAW : - callback = noirq ? pm->thaw_noirq : pm->thaw; -break ; -case PM_EVENT_RESTORE : - callback = noirq ? pm->restore_noirq : pm->restore; -break ; -default : - callback =NULL ; -break ; - } +* pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems. +* @dev: Device to suspend. +*/ +int pm_generic_suspend_noirq (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -return callback ?callback (dev) :0 ; +return pm && pm->suspend_noirq ? pm->suspend_noirq (dev) :0 ; } +EXPORT_SYMBOL_GPL (pm_generic_suspend_noirq);/** -* pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems. +* pm_generic_suspend_late - Generic suspend_late callback for subsystems. * @dev: Device to suspend. */ -int pm_generic_suspend_noirq (struct device *dev) +int pm_generic_suspend_late (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_SUSPEND , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->suspend_late ? pm->suspend_late (dev) :0 ; } -EXPORT_SYMBOL_GPL (pm_generic_suspend_noirq); +EXPORT_SYMBOL_GPL (pm_generic_suspend_late);/** * pm_generic_suspend - Generic suspend callback for subsystems.
@@ -152,7 +121,9 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend_noi*/ int pm_generic_suspend (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_SUSPEND , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->suspend ? pm->suspend (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_suspend);
@@ -162,17 +133,33 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend);*/ int pm_generic_freeze_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_FREEZE , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->freeze_noirq ? pm->freeze_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_freeze_noirq);/** +* pm_generic_freeze_late - Generic freeze_late callback for subsystems. +* @dev: Device to freeze. +*/ +int pm_generic_freeze_late (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->freeze_late ? pm->freeze_late (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_freeze_late); + +/** * pm_generic_freeze - Generic freeze callback for subsystems. * @dev: Device to freeze. */ int pm_generic_freeze (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_FREEZE , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->freeze ? pm->freeze (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_freeze);
@@ -182,17 +169,33 @@ EXPORT_SYMBOL_GPL(pm_generic_freeze);*/ int pm_generic_poweroff_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_HIBERNATE , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->poweroff_noirq ? pm->poweroff_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_poweroff_noirq);/** +* pm_generic_poweroff_late - Generic poweroff_late callback for subsystems. +* @dev: Device to handle. +*/ +int pm_generic_poweroff_late (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->poweroff_late ? pm->poweroff_late (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_poweroff_late); + +/** * pm_generic_poweroff - Generic poweroff callback for subsystems. * @dev: Device to handle. */ int pm_generic_poweroff (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_HIBERNATE , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->poweroff ? pm->poweroff (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_poweroff);
@@ -202,17 +205,33 @@ EXPORT_SYMBOL_GPL(pm_generic_poweroff);*/ int pm_generic_thaw_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_THAW , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->thaw_noirq ? pm->thaw_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_thaw_noirq);/** +* pm_generic_thaw_early - Generic thaw_early callback for subsystems. +* @dev: Device to thaw. +*/ +int pm_generic_thaw_early (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->thaw_early ? pm->thaw_early (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_thaw_early); + +/** * pm_generic_thaw - Generic thaw callback for subsystems. * @dev: Device to thaw. */ int pm_generic_thaw (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_THAW , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->thaw ? pm->thaw (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_thaw);
@@ -222,17 +241,33 @@ EXPORT_SYMBOL_GPL(pm_generic_thaw);*/ int pm_generic_resume_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESUME , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->resume_noirq ? pm->resume_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_resume_noirq);/** +* pm_generic_resume_early - Generic resume_early callback for subsystems. +* @dev: Device to resume. +*/ +int pm_generic_resume_early (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->resume_early ? pm->resume_early (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_resume_early); + +/** * pm_generic_resume - Generic resume callback for subsystems. * @dev: Device to resume. */ int pm_generic_resume (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESUME , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->resume ? pm->resume (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_resume);
@@ -242,17 +277,33 @@ EXPORT_SYMBOL_GPL(pm_generic_resume);*/ int pm_generic_restore_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESTORE , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->restore_noirq ? pm->restore_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_restore_noirq);/** +* pm_generic_restore_early - Generic restore_early callback for subsystems. +* @dev: Device to resume. +*/ +int pm_generic_restore_early (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->restore_early ? pm->restore_early (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_restore_early); + +/** * pm_generic_restore - Generic restore callback for subsystems. * @dev: Device to restore. */ int pm_generic_restore (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESTORE , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->restore ? pm->restore (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_restore);
include/linux/pm.h +6 -0
@@ -632,17 +632,23 @@ extern void __suspend_report_result(consextern int device_pm_wait_for_dev (struct device *sub,struct device *dev);extern int pm_generic_prepare (struct device *dev); +extern int pm_generic_suspend_late (struct device *dev);extern int pm_generic_suspend_noirq (struct device *dev);extern int pm_generic_suspend (struct device *dev); +extern int pm_generic_resume_early (struct device *dev);extern int pm_generic_resume_noirq (struct device *dev);extern int pm_generic_resume (struct device *dev);extern int pm_generic_freeze_noirq (struct device *dev); +extern int pm_generic_freeze_late (struct device *dev);extern int pm_generic_freeze (struct device *dev);extern int pm_generic_thaw_noirq (struct device *dev); +extern int pm_generic_thaw_early (struct device *dev);extern int pm_generic_thaw (struct device *dev);extern int pm_generic_restore_noirq (struct device *dev); +extern int pm_generic_restore_early (struct device *dev);extern int pm_generic_restore (struct device *dev);extern int pm_generic_poweroff_noirq (struct device *dev); +extern int pm_generic_poweroff_late (struct device *dev);extern int pm_generic_poweroff (struct device *dev);extern void pm_generic_complete (struct device *dev);
cover PM / Sleep: Introduce new phases of device suspend/resume
In reply to Rafael J. WysockiHi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
I'm considering these patches as v3.4 material, if there are no objections.
Thanks,
Rafael
PATCH RESEND 1/3 PM / Sleep: Introduce "late suspend" and "early resume" of devices
From: Rafael J. Wysocki <[email protected]>
The current device suspend/resume phases during system-wide power transitions appear to be insufficient for some platforms that want to use the same callback routines for saving device states and related operations during runtime suspend/resume as well as during system suspend/resume. In principle, they could point their .suspend_noirq() and .resume_noirq() to the same callback routines as their .runtime_suspend() and .runtime_resume(), respectively, but at least some of them require device interrupts to be enabled while the code in those routines is running.
It also makes sense to have device suspend-resume callbacks that will be executed with runtime PM disabled and with device interrupts enabled in case someone needs to run some special code in that context during system-wide power transitions.
Apart from this, .suspend_noirq() and .resume_noirq() were introduced as a workaround for drivers using shared interrupts and failing to prevent their interrupt handlers from accessing suspended hardware. It appears to be better not to use them for other porposes, or we may have to deal with some serious confusion (which seems to be happening already).
For the above reasons, introduce new device suspend/resume phases, "late suspend" and "early resume" (and analogously for hibernation) whose callback will be executed with runtime PM disabled and with device interrupts enabled and whose callback pointers generally may point to runtime suspend/resume routines.
--- Documentation/power/devices.txt | 93 +++++++++------ arch/x86/kernel/apm_32.c | 11 - drivers/base/power/main.c | 247 ++++++++++++++++++++++++++++++++++++---- drivers/xen/manage.c | 6 include/linux/pm.h | 43 +++++- include/linux/suspend.h | 4 kernel/kexec.c | 8 - kernel/power/hibernate.c | 24 +-- kernel/power/main.c | 8 - kernel/power/suspend.c | 4 10 files changed, 357 insertions(+), 91 deletions(-)
drivers/base/power/main.c +225 -22
@@ -47,6 +47,7 @@ typedef int (*pm_callback_t)(struct deviLIST_HEAD (dpm_list);LIST_HEAD (dpm_prepared_list);LIST_HEAD (dpm_suspended_list); +LIST_HEAD (dpm_late_early_list);LIST_HEAD (dpm_noirq_list);struct suspend_stats suspend_stats;
@@ -246,6 +247,40 @@ static pm_callback_t pm_op(const struct }/** +* pm_late_early_op - Return the PM operation appropriate for given PM event. +* @ops: PM operations to choose from. +* @state: PM transition of the system being carried out. +* +* Runtime PM is disabled for @dev while this function is being executed. +*/ +static pm_callback_t pm_late_early_op (const struct dev_pm_ops *ops, +pm_message_t state) +{ +switch (state.event) { +#ifdef CONFIG_SUSPEND +case PM_EVENT_SUSPEND : +return ops->suspend_late; +case PM_EVENT_RESUME : +return ops->resume_early; +#endif /* CONFIG_SUSPEND */ +#ifdef CONFIG_HIBERNATE_CALLBACKS +case PM_EVENT_FREEZE : +case PM_EVENT_QUIESCE : +return ops->freeze_late; +case PM_EVENT_HIBERNATE : +return ops->poweroff_late; +case PM_EVENT_THAW : +case PM_EVENT_RECOVER : +return ops->thaw_early; +case PM_EVENT_RESTORE : +return ops->restore_early; +#endif /* CONFIG_HIBERNATE_CALLBACKS */ + } + +return NULL ; +} + +/** * pm_noirq_op - Return the PM operation appropriate for given PM event. * @ops: PM operations to choose from. * @state: PM transition of the system being carried out.
@@ -374,21 +409,21 @@ static int device_resume_noirq(struct deTRACE_RESUME (0 );if (dev->pm_domain) { - info ="EARLY power domain " ; + info ="noirq power domain " ; callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { - info ="EARLY type " ; + info ="noirq type " ; callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { - info ="EARLY class " ; + info ="noirq class " ; callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { - info ="EARLY bus " ; + info ="noirq bus " ; callback =pm_noirq_op (dev->bus->pm, state); }if (!callback && dev->driver && dev->driver->pm) { - info ="EARLY driver " ; + info ="noirq driver " ; callback =pm_noirq_op (dev->driver->pm, state); }
@@ -399,13 +434,13 @@ static int device_resume_noirq(struct de }/** -* dpm_resume_noirq - Execute "early resume" callbacks for non-sysdev devices. +* dpm_resume_noirq - Execute "noirq resume" callbacks for all devices. * @state: PM transition of the system being carried out. * -* Call the "noirq" resume handlers for all devices marked as DPM_OFF_IRQ and +* Call the "noirq" resume handlers for all devices in dpm_noirq_list and * enable device drivers to receive interrupts. */ -void dpm_resume_noirq (pm_message_t state) +static void dpm_resume_noirq (pm_message_t state) {ktime_t starttime =ktime_get ();
@@ -415,7 +450,7 @@ void dpm_resume_noirq(pm_message_t stateint error;get_device (dev); -list_move_tail (&dev->power.entry, &dpm_suspended_list); +list_move_tail (&dev->power.entry, &dpm_late_early_list);mutex_unlock (&dpm_list_mtx); error =device_resume_noirq (dev, state);
@@ -423,6 +458,80 @@ void dpm_resume_noirq(pm_message_t state suspend_stats.failed_resume_noirq++;dpm_save_failed_step (SUSPEND_RESUME_NOIRQ );dpm_save_failed_dev (dev_name (dev)); +pm_dev_err (dev, state," noirq" , error); + } + +mutex_lock (&dpm_list_mtx); +put_device (dev); + } +mutex_unlock (&dpm_list_mtx); +dpm_show_time (starttime, state,"noirq" ); +resume_device_irqs (); +} + +/** +* device_resume_early - Execute an "early resume" callback for given device. +* @dev: Device to handle. +* @state: PM transition of the system being carried out. +* +* Runtime PM is disabled for @dev while this function is being executed. +*/ +static int device_resume_early (struct device *dev,pm_message_t state) +{ +pm_callback_t callback =NULL ; +char *info =NULL ; +int error =0 ; + +TRACE_DEVICE (dev); +TRACE_RESUME (0 ); + +if (dev->pm_domain) { + info ="early power domain " ; + callback =pm_late_early_op (&dev->pm_domain->ops, state); + }else if (dev->type && dev->type->pm) { + info ="early type " ; + callback =pm_late_early_op (dev->type->pm, state); + }else if (dev->class && dev->class->pm) { + info ="early class " ; + callback =pm_late_early_op (dev->class->pm, state); + }else if (dev->bus && dev->bus->pm) { + info ="early bus " ; + callback =pm_late_early_op (dev->bus->pm, state); + } + +if (!callback && dev->driver && dev->driver->pm) { + info ="early driver " ; + callback =pm_late_early_op (dev->driver->pm, state); + } + + error =dpm_run_callback (callback, dev, state, info); + +TRACE_RESUME (error); +return error; +} + +/** +* 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) +{ +ktime_t starttime =ktime_get (); + +mutex_lock (&dpm_list_mtx); +while (!list_empty (&dpm_late_early_list)) { +struct device *dev =to_device (dpm_late_early_list.next); +int error; + +get_device (dev); +list_move_tail (&dev->power.entry, &dpm_suspended_list); +mutex_unlock (&dpm_list_mtx); + + error =device_resume_early (dev, state); +if (error) { + suspend_stats.failed_resume_early++; +dpm_save_failed_step (SUSPEND_RESUME_EARLY ); +dpm_save_failed_dev (dev_name (dev));pm_dev_err (dev, state," early" , error); }
@@ -431,9 +540,18 @@ void dpm_resume_noirq(pm_message_t state }mutex_unlock (&dpm_list_mtx);dpm_show_time (starttime, state,"early" ); -resume_device_irqs (); } -EXPORT_SYMBOL_GPL (dpm_resume_noirq); + +/** +* dpm_resume_start - Execute "noirq" and "early" device callbacks. +* @state: PM transition of the system being carried out. +*/ +void dpm_resume_start (pm_message_t state) +{ +dpm_resume_noirq (state); +dpm_resume_early (state); +} +EXPORT_SYMBOL_GPL (dpm_resume_start);/** * device_resume - Execute "resume" callbacks for given device.
@@ -716,21 +834,21 @@ static int device_suspend_noirq(struct dchar *info =NULL ;if (dev->pm_domain) { - info ="LATE power domain " ; + info ="noirq power domain " ; callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { - info ="LATE type " ; + info ="noirq type " ; callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { - info ="LATE class " ; + info ="noirq class " ; callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { - info ="LATE bus " ; + info ="noirq bus " ; callback =pm_noirq_op (dev->bus->pm, state); }if (!callback && dev->driver && dev->driver->pm) { - info ="LATE driver " ; + info ="noirq driver " ; callback =pm_noirq_op (dev->driver->pm, state); }
@@ -738,21 +856,21 @@ static int device_suspend_noirq(struct d }/** -* dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices. +* dpm_suspend_noirq - Execute "noirq suspend" callbacks for all devices. * @state: PM transition of the system being carried out. * * Prevent device drivers from receiving interrupts and call the "noirq" suspend * handlers for all non-sysdev devices. */ -int dpm_suspend_noirq (pm_message_t state) +static int dpm_suspend_noirq (pm_message_t state) {ktime_t starttime =ktime_get ();int error =0 ;suspend_device_irqs ();mutex_lock (&dpm_list_mtx); -while (!list_empty (&dpm_suspended_list)) { -struct device *dev =to_device (dpm_suspended_list.prev); +while (!list_empty (&dpm_late_early_list)) { +struct device *dev =to_device (dpm_late_early_list.prev);get_device (dev);mutex_unlock (&dpm_list_mtx);
@@ -761,7 +879,7 @@ int dpm_suspend_noirq(pm_message_t statemutex_lock (&dpm_list_mtx);if (error) { -pm_dev_err (dev, state," late" , error); +pm_dev_err (dev, state," noirq" , error); suspend_stats.failed_suspend_noirq++;dpm_save_failed_step (SUSPEND_SUSPEND_NOIRQ );dpm_save_failed_dev (dev_name (dev));
@@ -776,10 +894,95 @@ int dpm_suspend_noirq(pm_message_t stateif (error)dpm_resume_noirq (resume_event (state));else +dpm_show_time (starttime, state,"noirq" ); +return error; +} + +/** +* device_suspend_late - Execute a "late suspend" callback for given device. +* @dev: Device to handle. +* @state: PM transition of the system being carried out. +* +* Runtime PM is disabled for @dev while this function is being executed. +*/ +static int device_suspend_late (struct device *dev,pm_message_t state) +{ +pm_callback_t callback =NULL ; +char *info =NULL ; + +if (dev->pm_domain) { + info ="late power domain " ; + callback =pm_late_early_op (&dev->pm_domain->ops, state); + }else if (dev->type && dev->type->pm) { + info ="late type " ; + callback =pm_late_early_op (dev->type->pm, state); + }else if (dev->class && dev->class->pm) { + info ="late class " ; + callback =pm_late_early_op (dev->class->pm, state); + }else if (dev->bus && dev->bus->pm) { + info ="late bus " ; + callback =pm_late_early_op (dev->bus->pm, state); + } + +if (!callback && dev->driver && dev->driver->pm) { + info ="late driver " ; + callback =pm_late_early_op (dev->driver->pm, state); + } + +return dpm_run_callback (callback, dev, state, info); +} + +/** +* 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) +{ +ktime_t starttime =ktime_get (); +int error =0 ; + +mutex_lock (&dpm_list_mtx); +while (!list_empty (&dpm_suspended_list)) { +struct device *dev =to_device (dpm_suspended_list.prev); + +get_device (dev); +mutex_unlock (&dpm_list_mtx); + + error =device_suspend_late (dev, state); + +mutex_lock (&dpm_list_mtx); +if (error) { +pm_dev_err (dev, state," late" , error); + suspend_stats.failed_suspend_late++; +dpm_save_failed_step (SUSPEND_SUSPEND_LATE ); +dpm_save_failed_dev (dev_name (dev)); +put_device (dev); +break ; + } +if (!list_empty (&dev->power.entry)) +list_move (&dev->power.entry, &dpm_late_early_list); +put_device (dev); + } +mutex_unlock (&dpm_list_mtx); +if (error) +dpm_resume_early (resume_event (state)); +else dpm_show_time (starttime, state,"late" ); +return error; } -EXPORT_SYMBOL_GPL (dpm_suspend_noirq); + +/** +* dpm_suspend_end - Execute "late" and "noirq" device suspend callbacks. +* @state: PM transition of the system being carried out. +*/ +int dpm_suspend_end (pm_message_t state) +{ +int error =dpm_suspend_late (state); + +return error ? :dpm_suspend_noirq (state); +} +EXPORT_SYMBOL_GPL (dpm_suspend_end);/** * legacy_suspend - Execute a legacy (bus or class) suspend callback for device.
kernel/power/suspend.c +2 -2
@@ -147,7 +147,7 @@ static int suspend_enter(suspend_state_t goto Platform_finish; } - error =dpm_suspend_noirq (PMSG_SUSPEND ); + error =dpm_suspend_end (PMSG_SUSPEND );if (error) {printk (KERN_ERR "PM: Some devices failed to power down\n" ); goto Platform_finish;
@@ -189,7 +189,7 @@ static int suspend_enter(suspend_state_tif (suspend_ops->wake) suspend_ops->wake (); -dpm_resume_noirq (PMSG_RESUME ); +dpm_resume_start (PMSG_RESUME ); Platform_finish:if (suspend_ops->finish)
include/linux/suspend.h +4 -0
@@ -42,8 +42,10 @@ enum suspend_stat_step {SUSPEND_FREEZE =1 ,SUSPEND_PREPARE ,SUSPEND_SUSPEND , +SUSPEND_SUSPEND_LATE ,SUSPEND_SUSPEND_NOIRQ ,SUSPEND_RESUME_NOIRQ , +SUSPEND_RESUME_EARLY , SUSPEND_RESUME };
@@ -53,8 +55,10 @@ struct suspend_stats {int failed_freeze;int failed_prepare;int failed_suspend; +int failed_suspend_late;int failed_suspend_noirq;int failed_resume; +int failed_resume_early;int failed_resume_noirq;#define REC_FAILED_NUM 2int last_failed_dev;
include/linux/pm.h +35 -8
105 lines not on this page · raw message
kernel/power/hibernate.c +12 -12
@@ -245,8 +245,8 @@ void swsusp_show_speed(struct timeval *s* create_image - Create a hibernation image. * @platform_mode: Whether or not to use the platform driver. * -* Execute device drivers' .freeze_noirq() callbacks, create a hibernation image -* and execute the drivers' .thaw_noirq() callbacks. +* Execute device drivers' "late" and "noirq" freeze callbacks, create a +* hibernation image and run the drivers' "noirq" and "early" thaw callbacks. * * Control reappears in this routine after the subsequent restore. */
@@ -254,7 +254,7 @@ static int create_image(int platform_mod {int error; - error =dpm_suspend_noirq (PMSG_FREEZE ); + error =dpm_suspend_end (PMSG_FREEZE );if (error) {printk (KERN_ERR "PM: Some devices failed to power down, " "aborting hibernation\n" );
@@ -306,7 +306,7 @@ static int create_image(int platform_mod Platform_finish:platform_finish (platform_mode); -dpm_resume_noirq (in_suspend ? +dpm_resume_start (in_suspend ? (error ?PMSG_RECOVER :PMSG_THAW ) :PMSG_RESTORE );return error;
@@ -394,16 +394,16 @@ int hibernation_snapshot(int platform_mo* resume_target_kernel - Restore system state from a hibernation image. * @platform_mode: Whether or not to use the platform driver. * -* Execute device drivers' .freeze_noirq() callbacks, restore the contents of -* highmem that have not been restored yet from the image and run the low-level -* code that will restore the remaining contents of memory and switch to the -* just restored target kernel. +* Execute device drivers' "noirq" and "late" freeze callbacks, restore the +* contents of highmem that have not been restored yet from the image and run +* the low-level code that will restore the remaining contents of memory and +* switch to the just restored target kernel. */ static int resume_target_kernel (bool platform_mode) {int error; - error =dpm_suspend_noirq (PMSG_QUIESCE ); + error =dpm_suspend_end (PMSG_QUIESCE );if (error) {printk (KERN_ERR "PM: Some devices failed to power down, " "aborting resume\n" );
@@ -460,7 +460,7 @@ static int resume_target_kernel(bool pla Cleanup:platform_restore_cleanup (platform_mode); -dpm_resume_noirq (PMSG_RECOVER ); +dpm_resume_start (PMSG_RECOVER );return error; }
@@ -518,7 +518,7 @@ int hibernation_platform_enter(void) goto Resume_devices; } - error =dpm_suspend_noirq (PMSG_HIBERNATE ); + error =dpm_suspend_end (PMSG_HIBERNATE );if (error) goto Resume_devices;
@@ -549,7 +549,7 @@ int hibernation_platform_enter(void) Platform_finish: hibernation_ops->finish (); -dpm_resume_noirq (PMSG_RESTORE ); +dpm_resume_start (PMSG_RESTORE ); Resume_devices: entering_platform_hibernation = false;
arch/x86/kernel/apm_32.c +5 -6
@@ -1234,8 +1234,7 @@ static int suspend(int vetoable)struct apm_user *as;dpm_suspend_start (PMSG_SUSPEND ); - -dpm_suspend_noirq (PMSG_SUSPEND ); +dpm_suspend_end (PMSG_SUSPEND );local_irq_disable ();syscore_suspend ();
@@ -1259,9 +1258,9 @@ static int suspend(int vetoable)syscore_resume ();local_irq_enable (); -dpm_resume_noirq (PMSG_RESUME ); - +dpm_resume_start (PMSG_RESUME );dpm_resume_end (PMSG_RESUME ); +queue_event (APM_NORMAL_RESUME ,NULL );spin_lock (&user_list_lock);for (as = user_list; as !=NULL ; as = as->next) {
@@ -1277,7 +1276,7 @@ static void standby(void) {int err; -dpm_suspend_noirq (PMSG_SUSPEND ); +dpm_suspend_end (PMSG_SUSPEND );local_irq_disable ();syscore_suspend ();
@@ -1291,7 +1290,7 @@ static void standby(void)syscore_resume ();local_irq_enable (); -dpm_resume_noirq (PMSG_RESUME ); +dpm_resume_start (PMSG_RESUME ); }static apm_event_t get_event (void )
drivers/xen/manage.c +3 -3
@@ -129,9 +129,9 @@ static void do_suspend(void)printk (KERN_DEBUG "suspending xenstore...\n" );xs_suspend (); - err =dpm_suspend_noirq (PMSG_FREEZE ); + err =dpm_suspend_end (PMSG_FREEZE );if (err) { -printk (KERN_ERR "dpm_suspend_noirq failed: %d\n" , err); +printk (KERN_ERR "dpm_suspend_end failed: %d\n" , err); goto out_resume; }
@@ -149,7 +149,7 @@ static void do_suspend(void) err =stop_machine (xen_suspend, &si,cpumask_of (0 )); -dpm_resume_noirq (si.cancelled ?PMSG_THAW :PMSG_RESTORE ); +dpm_resume_start (si.cancelled ?PMSG_THAW :PMSG_RESTORE );if (err) {printk (KERN_ERR "failed to start xen_suspend: %d\n" , err);
kernel/kexec.c +4 -4
@@ -1546,13 +1546,13 @@ int kernel_kexec(void)if (error) goto Resume_console;/* At this point, dpm_suspend_start() has been called, -* but *not* dpm_suspend_noirq(). We *must* call -* dpm_suspend_noirq() now. Otherwise, drivers for +* but *not* dpm_suspend_end(). We *must* call +* dpm_suspend_end() now. Otherwise, drivers for * some devices (e.g. interrupt controllers) become * desynchronized with the actual state of the * hardware at resume time, and evil weirdness ensues. */ - error =dpm_suspend_noirq (PMSG_FREEZE ); + error =dpm_suspend_end (PMSG_FREEZE );if (error) goto Resume_devices; error =disable_nonboot_cpus ();
@@ -1579,7 +1579,7 @@ int kernel_kexec(void)local_irq_enable (); Enable_cpus:enable_nonboot_cpus (); -dpm_resume_noirq (PMSG_RESTORE ); +dpm_resume_start (PMSG_RESTORE ); Resume_devices:dpm_resume_end (PMSG_RESTORE ); Resume_console:
kernel/power/main.c +6 -2
@@ -165,16 +165,20 @@ static int suspend_stats_show(struct seq last_errno %=REC_FAILED_NUM ; last_step = suspend_stats.last_failed_step +REC_FAILED_NUM -1 ; last_step %=REC_FAILED_NUM ; -seq_printf (s,"%s: %d\n%s: %d\n%s: %d\n%s: %d\n" -"%s: %d\n%s: %d\n%s: %d\n%s: %d\n" , +seq_printf (s,"%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n" +"%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n" ,"success" , suspend_stats.success,"fail" , suspend_stats.fail,"failed_freeze" , suspend_stats.failed_freeze,"failed_prepare" , suspend_stats.failed_prepare,"failed_suspend" , suspend_stats.failed_suspend, +"failed_suspend_late" , + suspend_stats.failed_suspend_late,"failed_suspend_noirq" , suspend_stats.failed_suspend_noirq,"failed_resume" , suspend_stats.failed_resume, +"failed_resume_early" , + suspend_stats.failed_resume_early,"failed_resume_noirq" , suspend_stats.failed_resume_noirq); seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
Documentation/power/devices.txt +61 -32
170 lines not on this page · raw message
PATCH RESEND 2/3 PM / Sleep: Introduce generic callbacks for new device PM phases
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Introduce generic subsystem callbacks for the new phases of device suspend/resume during system power transitions: "late suspend", "early resume", "late freeze", "early thaw", "late poweroff", "early restore".
--- drivers/base/power/generic_ops.c | 163 +++++++++++++++++++++++++-------------- include/linux/pm.h | 6 + 2 files changed, 113 insertions(+), 56 deletions(-)
drivers/base/power/generic_ops.c +107 -56
@@ -92,59 +92,28 @@ int pm_generic_prepare(struct device *de }/** -* __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback. -* @dev: Device to handle. -* @event: PM transition of the system under way. -* @bool: Whether or not this is the "noirq" stage. -* -* Execute the PM callback corresponding to @event provided by the driver of -* @dev, if defined, and return its error code. Return 0 if the callback is -* not present. -*/ -static int __pm_generic_call (struct device *dev,int event,bool noirq) -{ -const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -int (*callback)(struct device *); - -if (!pm) -return 0 ; - -switch (event) { -case PM_EVENT_SUSPEND : - callback = noirq ? pm->suspend_noirq : pm->suspend; -break ; -case PM_EVENT_FREEZE : - callback = noirq ? pm->freeze_noirq : pm->freeze; -break ; -case PM_EVENT_HIBERNATE : - callback = noirq ? pm->poweroff_noirq : pm->poweroff; -break ; -case PM_EVENT_RESUME : - callback = noirq ? pm->resume_noirq : pm->resume; -break ; -case PM_EVENT_THAW : - callback = noirq ? pm->thaw_noirq : pm->thaw; -break ; -case PM_EVENT_RESTORE : - callback = noirq ? pm->restore_noirq : pm->restore; -break ; -default : - callback =NULL ; -break ; - } +* pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems. +* @dev: Device to suspend. +*/ +int pm_generic_suspend_noirq (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -return callback ?callback (dev) :0 ; +return pm && pm->suspend_noirq ? pm->suspend_noirq (dev) :0 ; } +EXPORT_SYMBOL_GPL (pm_generic_suspend_noirq);/** -* pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems. +* pm_generic_suspend_late - Generic suspend_late callback for subsystems. * @dev: Device to suspend. */ -int pm_generic_suspend_noirq (struct device *dev) +int pm_generic_suspend_late (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_SUSPEND , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->suspend_late ? pm->suspend_late (dev) :0 ; } -EXPORT_SYMBOL_GPL (pm_generic_suspend_noirq); +EXPORT_SYMBOL_GPL (pm_generic_suspend_late);/** * pm_generic_suspend - Generic suspend callback for subsystems.
@@ -152,7 +121,9 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend_noi*/ int pm_generic_suspend (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_SUSPEND , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->suspend ? pm->suspend (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_suspend);
@@ -162,17 +133,33 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend);*/ int pm_generic_freeze_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_FREEZE , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->freeze_noirq ? pm->freeze_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_freeze_noirq);/** +* pm_generic_freeze_late - Generic freeze_late callback for subsystems. +* @dev: Device to freeze. +*/ +int pm_generic_freeze_late (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->freeze_late ? pm->freeze_late (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_freeze_late); + +/** * pm_generic_freeze - Generic freeze callback for subsystems. * @dev: Device to freeze. */ int pm_generic_freeze (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_FREEZE , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->freeze ? pm->freeze (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_freeze);
@@ -182,17 +169,33 @@ EXPORT_SYMBOL_GPL(pm_generic_freeze);*/ int pm_generic_poweroff_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_HIBERNATE , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->poweroff_noirq ? pm->poweroff_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_poweroff_noirq);/** +* pm_generic_poweroff_late - Generic poweroff_late callback for subsystems. +* @dev: Device to handle. +*/ +int pm_generic_poweroff_late (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->poweroff_late ? pm->poweroff_late (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_poweroff_late); + +/** * pm_generic_poweroff - Generic poweroff callback for subsystems. * @dev: Device to handle. */ int pm_generic_poweroff (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_HIBERNATE , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->poweroff ? pm->poweroff (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_poweroff);
@@ -202,17 +205,33 @@ EXPORT_SYMBOL_GPL(pm_generic_poweroff);*/ int pm_generic_thaw_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_THAW , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->thaw_noirq ? pm->thaw_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_thaw_noirq);/** +* pm_generic_thaw_early - Generic thaw_early callback for subsystems. +* @dev: Device to thaw. +*/ +int pm_generic_thaw_early (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->thaw_early ? pm->thaw_early (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_thaw_early); + +/** * pm_generic_thaw - Generic thaw callback for subsystems. * @dev: Device to thaw. */ int pm_generic_thaw (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_THAW , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->thaw ? pm->thaw (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_thaw);
@@ -222,17 +241,33 @@ EXPORT_SYMBOL_GPL(pm_generic_thaw);*/ int pm_generic_resume_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESUME , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->resume_noirq ? pm->resume_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_resume_noirq);/** +* pm_generic_resume_early - Generic resume_early callback for subsystems. +* @dev: Device to resume. +*/ +int pm_generic_resume_early (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->resume_early ? pm->resume_early (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_resume_early); + +/** * pm_generic_resume - Generic resume callback for subsystems. * @dev: Device to resume. */ int pm_generic_resume (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESUME , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->resume ? pm->resume (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_resume);
@@ -242,17 +277,33 @@ EXPORT_SYMBOL_GPL(pm_generic_resume);*/ int pm_generic_restore_noirq (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESTORE , true); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->restore_noirq ? pm->restore_noirq (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_restore_noirq);/** +* pm_generic_restore_early - Generic restore_early callback for subsystems. +* @dev: Device to resume. +*/ +int pm_generic_restore_early (struct device *dev) +{ +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->restore_early ? pm->restore_early (dev) :0 ; +} +EXPORT_SYMBOL_GPL (pm_generic_restore_early); + +/** * pm_generic_restore - Generic restore callback for subsystems. * @dev: Device to restore. */ int pm_generic_restore (struct device *dev) { -return __pm_generic_call (dev,PM_EVENT_RESTORE , false); +const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; + +return pm && pm->restore ? pm->restore (dev) :0 ; }EXPORT_SYMBOL_GPL (pm_generic_restore);
include/linux/pm.h +6 -0
@@ -632,17 +632,23 @@ extern void __suspend_report_result(consextern int device_pm_wait_for_dev (struct device *sub,struct device *dev);extern int pm_generic_prepare (struct device *dev); +extern int pm_generic_suspend_late (struct device *dev);extern int pm_generic_suspend_noirq (struct device *dev);extern int pm_generic_suspend (struct device *dev); +extern int pm_generic_resume_early (struct device *dev);extern int pm_generic_resume_noirq (struct device *dev);extern int pm_generic_resume (struct device *dev);extern int pm_generic_freeze_noirq (struct device *dev); +extern int pm_generic_freeze_late (struct device *dev);extern int pm_generic_freeze (struct device *dev);extern int pm_generic_thaw_noirq (struct device *dev); +extern int pm_generic_thaw_early (struct device *dev);extern int pm_generic_thaw (struct device *dev);extern int pm_generic_restore_noirq (struct device *dev); +extern int pm_generic_restore_early (struct device *dev);extern int pm_generic_restore (struct device *dev);extern int pm_generic_poweroff_noirq (struct device *dev); +extern int pm_generic_poweroff_late (struct device *dev);extern int pm_generic_poweroff (struct device *dev);extern void pm_generic_complete (struct device *dev);
PATCH 3/3 PM / Domains: Run late/early device suspend callbacks at the right time
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
After the introduction of the late/early phases of device suspend/resume during system-wide power transitions it is possible to make the generic PM domains code execute its default late/early device suspend/resume callbacks during those phases instead of the corresponding _noirq phases. The _noirq device suspend/resume phases were only used for executing those callbacks, because this was the only way it could be done, but now we can do better.
--- drivers/base/power/domain.c | 157 +++++++++++++++++++++++++++++++------------- 1 file changed, 111 insertions(+), 46 deletions(-)
drivers/base/power/domain.c +111 -46
@@ -820,17 +820,16 @@ static int pm_genpd_suspend(struct devic }/** -* pm_genpd_suspend_noirq - Late suspend of a device from an I/O PM domain. +* pm_genpd_suspend_late - Late suspend of a device from an I/O PM domain. * @dev: Device to suspend. * * Carry out a late suspend of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a PM domain consisting of I/O devices. */ -static int pm_genpd_suspend_noirq (struct device *dev) +static int pm_genpd_suspend_late (struct device *dev) {struct generic_pm_domain *genpd; -int ret;dev_dbg (dev,"%s()\n" , __func__);
@@ -838,14 +837,28 @@ static int pm_genpd_suspend_noirq(structif (IS_ERR (genpd))return -EINVAL ; -if (genpd->suspend_power_off) -return 0 ; +return genpd->suspend_power_off ?0 :genpd_suspend_late (genpd, dev); +} - ret =genpd_suspend_late (genpd, dev); -if (ret) -return ret; +/** +* pm_genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain. +* @dev: Device to suspend. +* +* Stop the device and remove power from the domain if all devices in it have +* been stopped. +*/ +static int pm_genpd_suspend_noirq (struct device *dev) +{ +struct generic_pm_domain *genpd; -if (dev->power.wakeup_path &&genpd_dev_active_wakeup (genpd, dev)) +dev_dbg (dev,"%s()\n" , __func__); + + genpd =dev_to_genpd (dev); +if (IS_ERR (genpd)) +return -EINVAL ; + +if (genpd->suspend_power_off + || (dev->power.wakeup_path &&genpd_dev_active_wakeup (genpd, dev)))return 0 ;genpd_stop_dev (genpd, dev);
@@ -862,13 +875,10 @@ static int pm_genpd_suspend_noirq(struct }/** -* pm_genpd_resume_noirq - Early resume of a device from an I/O power domain. +* pm_genpd_resume_noirq - Start of resume of device in an I/O PM domain. * @dev: Device to resume. * -* Carry out an early resume of a device under the assumption that its -* pm_domain field points to the domain member of an object of type -* struct generic_pm_domain representing a power domain consisting of I/O -* devices. +* Restore power to the device's PM domain, if necessary, and start the device. */ static int pm_genpd_resume_noirq (struct device *dev) {
@@ -890,13 +900,34 @@ static int pm_genpd_resume_noirq(struct*/ pm_genpd_poweron (genpd); genpd->suspended_count--; -genpd_start_dev (genpd, dev); -return genpd_resume_early (genpd, dev); +return genpd_start_dev (genpd, dev); }/** -* pm_genpd_resume - Resume a device belonging to an I/O power domain. +* pm_genpd_resume_early - Early resume of a device in an I/O PM domain. +* @dev: Device to resume. +* +* Carry out an early resume of a device under the assumption that its +* pm_domain field points to the domain member of an object of type +* struct generic_pm_domain representing a power domain consisting of I/O +* devices. +*/ +static int pm_genpd_resume_early (struct device *dev) +{ +struct generic_pm_domain *genpd; + +dev_dbg (dev,"%s()\n" , __func__); + + genpd =dev_to_genpd (dev); +if (IS_ERR (genpd)) +return -EINVAL ; + +return genpd->suspend_power_off ?0 :genpd_resume_early (genpd, dev); +} + +/** +* pm_genpd_resume - Resume of device in an I/O PM domain. * @dev: Device to resume. * * Resume a device under the assumption that its pm_domain field points to the
@@ -917,7 +948,7 @@ static int pm_genpd_resume(struct device }/** -* pm_genpd_freeze - Freeze a device belonging to an I/O power domain. +* pm_genpd_freeze - Freezing a device in an I/O PM domain. * @dev: Device to freeze. * * Freeze a device under the assumption that its pm_domain field points to the
@@ -938,7 +969,29 @@ static int pm_genpd_freeze(struct device }/** -* pm_genpd_freeze_noirq - Late freeze of a device from an I/O power domain. +* pm_genpd_freeze_late - Late freeze of a device in an I/O PM domain. +* @dev: Device to freeze. +* +* Carry out a late freeze of a device under the assumption that its +* pm_domain field points to the domain member of an object of type +* struct generic_pm_domain representing a power domain consisting of I/O +* devices. +*/ +static int pm_genpd_freeze_late (struct device *dev) +{ +struct generic_pm_domain *genpd; + +dev_dbg (dev,"%s()\n" , __func__); + + genpd =dev_to_genpd (dev); +if (IS_ERR (genpd)) +return -EINVAL ; + +return genpd->suspend_power_off ?0 :genpd_freeze_late (genpd, dev); +} + +/** +* pm_genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain. * @dev: Device to freeze. * * Carry out a late freeze of a device under the assumption that its
@@ -949,7 +1002,6 @@ static int pm_genpd_freeze(struct devicestatic int pm_genpd_freeze_noirq (struct device *dev) {struct generic_pm_domain *genpd; -int ret;dev_dbg (dev,"%s()\n" , __func__);
@@ -957,20 +1009,31 @@ static int pm_genpd_freeze_noirq(structif (IS_ERR (genpd))return -EINVAL ; -if (genpd->suspend_power_off) -return 0 ; +return genpd->suspend_power_off ?0 :genpd_stop_dev (genpd, dev); +} + +/** +* pm_genpd_thaw_noirq - Early thaw of device in an I/O PM domain. +* @dev: Device to thaw. +* +* Start the device, unless power has been removed from the domain already +* before the system transition. +*/ +static int pm_genpd_thaw_noirq (struct device *dev) +{ +struct generic_pm_domain *genpd; - ret =genpd_freeze_late (genpd, dev); -if (ret) -return ret; +dev_dbg (dev,"%s()\n" , __func__); -genpd_stop_dev (genpd, dev); + genpd =dev_to_genpd (dev); +if (IS_ERR (genpd)) +return -EINVAL ; -return 0 ; +return genpd->suspend_power_off ?0 :genpd_start_dev (genpd, dev); }/** -* pm_genpd_thaw_noirq - Early thaw of a device from an I/O power domain. +* pm_genpd_thaw_early - Early thaw of device in an I/O PM domain. * @dev: Device to thaw. * * Carry out an early thaw of a device under the assumption that its
@@ -978,7 +1041,7 @@ static int pm_genpd_freeze_noirq(struct* struct generic_pm_domain representing a power domain consisting of I/O * devices. */ -static int pm_genpd_thaw_noirq (struct device *dev) +static int pm_genpd_thaw_early (struct device *dev) {struct generic_pm_domain *genpd;
@@ -988,12 +1051,7 @@ static int pm_genpd_thaw_noirq(struct deif (IS_ERR (genpd))return -EINVAL ; -if (genpd->suspend_power_off) -return 0 ; - -genpd_start_dev (genpd, dev); - -return genpd_thaw_early (genpd, dev); +return genpd->suspend_power_off ?0 :genpd_thaw_early (genpd, dev); }/**
@@ -1018,13 +1076,11 @@ static int pm_genpd_thaw(struct device * }/** -* pm_genpd_restore_noirq - Early restore of a device from an I/O power domain. +* pm_genpd_restore_noirq - Start of restore of device in an I/O PM domain. * @dev: Device to resume. * -* Carry out an early restore of a device under the assumption that its -* pm_domain field points to the domain member of an object of type -* struct generic_pm_domain representing a power domain consisting of I/O -* devices. +* Make sure the domain will be in the same power state as before the +* hibernation the system is resuming from and start the device if necessary. */ static int pm_genpd_restore_noirq (struct device *dev) {
@@ -1054,9 +1110,8 @@ static int pm_genpd_restore_noirq(structpm_genpd_poweron (genpd); genpd->suspended_count--; -genpd_start_dev (genpd, dev); -return genpd_resume_early (genpd, dev); +return genpd_start_dev (genpd, dev); }/**
@@ -1099,11 +1154,15 @@ static void pm_genpd_complete(struct dev#define pm_genpd_prepare NULL#define pm_genpd_suspend NULL +#define pm_genpd_suspend_late NULL#define pm_genpd_suspend_noirq NULL +#define pm_genpd_resume_early NULL#define pm_genpd_resume_noirq NULL#define pm_genpd_resume NULL#define pm_genpd_freeze NULL +#define pm_genpd_freeze_late NULL#define pm_genpd_freeze_noirq NULL +#define pm_genpd_thaw_early NULL#define pm_genpd_thaw_noirq NULL#define pm_genpd_thaw NULL#define pm_genpd_restore_noirq NULL
@@ -1450,7 +1509,7 @@ static int pm_genpd_default_suspend_late {int (*cb)(struct device *__dev) =dev_gpd_data (dev)->ops.suspend_late; -return cb ?cb (dev) :pm_generic_suspend_noirq (dev); +return cb ?cb (dev) :pm_generic_suspend_late (dev); }/**
@@ -1461,7 +1520,7 @@ static int pm_genpd_default_resume_early {int (*cb)(struct device *__dev) =dev_gpd_data (dev)->ops.resume_early; -return cb ?cb (dev) :pm_generic_resume_noirq (dev); +return cb ?cb (dev) :pm_generic_resume_early (dev); }/**
@@ -1494,7 +1553,7 @@ static int pm_genpd_default_freeze_late( {int (*cb)(struct device *__dev) =dev_gpd_data (dev)->ops.freeze_late; -return cb ?cb (dev) :pm_generic_freeze_noirq (dev); +return cb ?cb (dev) :pm_generic_freeze_late (dev); }/**
@@ -1505,7 +1564,7 @@ static int pm_genpd_default_thaw_early(s {int (*cb)(struct device *__dev) =dev_gpd_data (dev)->ops.thaw_early; -return cb ?cb (dev) :pm_generic_thaw_noirq (dev); +return cb ?cb (dev) :pm_generic_thaw_early (dev); }/**
@@ -1564,16 +1623,22 @@ void pm_genpd_init(struct generic_pm_dom genpd->domain.ops.runtime_idle = pm_generic_runtime_idle; genpd->domain.ops.prepare = pm_genpd_prepare; genpd->domain.ops.suspend = pm_genpd_suspend; + genpd->domain.ops.suspend_late = pm_genpd_suspend_late; genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq; genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq; + genpd->domain.ops.resume_early = pm_genpd_resume_early; genpd->domain.ops.resume = pm_genpd_resume; genpd->domain.ops.freeze = pm_genpd_freeze; + genpd->domain.ops.freeze_late = pm_genpd_freeze_late; genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq; genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq; + genpd->domain.ops.thaw_early = pm_genpd_thaw_early; genpd->domain.ops.thaw = pm_genpd_thaw; genpd->domain.ops.poweroff = pm_genpd_suspend; + genpd->domain.ops.poweroff_late = pm_genpd_suspend_late; genpd->domain.ops.poweroff_noirq = pm_genpd_suspend_noirq; genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq; + genpd->domain.ops.restore_early = pm_genpd_resume_early; genpd->domain.ops.restore = pm_genpd_resume; genpd->domain.ops.complete = pm_genpd_complete; genpd->dev_ops.save_state = pm_genpd_default_save_state;
Quoted 23 lines · Rafael J. Wysocki
Hi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
Quoted 6 lines
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
I'm considering these patches as v3.4 material, if there are no objections.
No objection from me.
greg k-h
Quoted 24 lines · Greg KH
Quoted 23 lines · Rafael J. Wysocki
Hi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
Quoted 8 lines
Quoted 6 lines
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
I'm considering these patches as v3.4 material, if there are no objections.
No objection from me.
Thanks!
Rafael
Quoted 23 lines · Rafael J. Wysocki
Hi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
Quoted 6 lines
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
I'm considering these patches as v3.4 material, if there are no objections.
Thanks Rafael for working on this.
So far I've only reviewed it, but I plan to convert my PM domain noirq usage to this and give it some testing as well, hopefully this week.
Kevin
Quoted 30 lines · Kevin Hilman
Quoted 28 lines · Rafael J. Wysocki
Hi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
Quoted 8 lines
Quoted 1 line
I'm considering these patches as v3.4 material, if there are no objections.
Reviewed-by Kevin Hilman <[email protected]>Thanks Rafael for working on this.
So far I've only reviewed it, but I plan to convert my PM domain noirq usage to this and give it some testing as well, hopefully this week.
Great, thanks!
Rafael
Kevin Hilman
Tested-byQuoted 33 lines · Rafael J. Wysocki
Quoted 32 lines · Kevin Hilman
Quoted 29 lines · Rafael J. Wysocki
Hi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
I'm considering these patches as v3.4 material, if there are no objections.
Quoted 9 lines
Quoted 6 lines
Reviewed-by Kevin Hilman <[email protected]>Thanks Rafael for working on this.
So far I've only reviewed it, but I plan to convert my PM domain noirq usage to this and give it some testing as well, hopefully this week.
Great, thanks!
OK, I gave it a test on OMAP by converting our _noirq usage to the new early/late callbacks. Works great. Thanks!
Kevin
Quoted 42 lines · Kevin Hilman
Quoted 40 lines · Rafael J. Wysocki
Quoted 38 lines · Kevin Hilman
Quoted 23 lines · Rafael J. Wysocki
Hi,
Quoted 10 lines · Rafael J. Wysocki
Hi,
On the request of some driver PM developers, that appears to have been quite popular lately, this series of patches adds new system suspend/resume (and hibernation/restore) callbacks to struct
dev_pm_opsand makes the PM core use them during system power transitions.[1/2] - Introduce "late suspend" and "early resume" of devices. [2/2] - Introduce generic callbacks for new device PM phases.
Quoted 6 lines
The series is on top of the linux-next branch of the linux-pm tree.
These patches have been tested on Toshiba Portege R500 with openSUSE 12.1 without crashing the box in the process, which looks promising. Also, they shouldn't actually have any impact on the existing setups other than adding a very short delay to the system suspend/resume code paths.
The patches have received some more testing since the were first posted and I've added a PM domains patch on top of them:
Quoted 6 lines
[3/3] - Make generic PM domains use the new device suspend/resume phases.
The series applies on top of linux-pm/pm-for-linus (although it should apply on top of the current mainline too).
I'm considering these patches as v3.4 material, if there are no objections.
Reviewed-by Kevin Hilman <[email protected]>Thanks Rafael for working on this.
So far I've only reviewed it, but I plan to convert my PM domain noirq usage to this and give it some testing as well, hopefully this week.
Quoted 7 lines
Quoted 2 lines
Great, thanks!
OK, I gave it a test on OMAP by converting our
_noirqusage to the new early/late callbacks. Works great. Thanks!Tested-by Kevin Hilman <[email protected]>
Many thanks for the testing!
Rafael