PM: Make the PM core execute driver callbacks if subsystem ones are not present
Subsystems (6)
cover PM: Make the PM core execute driver callbacks if subsystem ones are not present
Hi,
The following patchset changes the PM core so that driver callbacks are executed automatically when subsystem ones are not present and uses the new PM core's behavior to simplify the platform and AMBA bus types (there probably are many more bus types that may be simplified this way, but those two were the easiest targets for me).
The reasons why to do this are outlined in the changelog of the second patch.
Comments welcome!
Thanks,
Rafael
PATCH 1/4 PM / Sleep: Make pm_op() and pm_noirq_op() return callback pointers
From: Rafael J. Wysocki <[email protected]>
Make the pm_op() and pm_noirq_op() functions return pointers to appropriate callbacks instead of executing those callbacks and returning their results.
This change is required for a subsequent modification that will execute the corresponding driver callback if the subsystem callback returned by either pm_op(), or pm_noirq_op() is NULL.
--- drivers/base/power/main.c | 195 +++++++++++++++++++++------------------------- 1 file changed, 93 insertions(+), 102 deletions(-)
drivers/base/power/main.c +93 -102
@@ -211,113 +211,70 @@ static void dpm_wait_for_children(structdevice_for_each_child (dev, &async, dpm_wait_fn); } -static int dpm_run_callback (struct device *dev,int (*cb)(struct device *)) -{ -ktime_t calltime; -int error; - -if (!cb) -return 0 ; - - calltime =initcall_debug_start (dev); - - error =cb (dev); -suspend_report_result (cb, error); - -initcall_debug_report (dev, calltime, error); - -return error; -} -/** -* pm_op - Execute the PM operation appropriate for given PM event. -* @dev: Device to handle. +* pm_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. */ -static int pm_op (struct device *dev, -const struct dev_pm_ops *ops, -pm_message_t state) +static int (*pm_op (const struct dev_pm_ops *ops,pm_message_t state))(struct device *) { -int error =0 ; -switch (state.event) {#ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND : - error =dpm_run_callback (dev, ops->suspend); -break ; +return ops->suspend;case PM_EVENT_RESUME : - error =dpm_run_callback (dev, ops->resume); -break ; +return ops->resume;#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE :case PM_EVENT_QUIESCE : - error =dpm_run_callback (dev, ops->freeze); -break ; +return ops->freeze;case PM_EVENT_HIBERNATE : - error =dpm_run_callback (dev, ops->poweroff); -break ; +return ops->poweroff;case PM_EVENT_THAW :case PM_EVENT_RECOVER : - error =dpm_run_callback (dev, ops->thaw); +return ops->thaw;break ;case PM_EVENT_RESTORE : - error =dpm_run_callback (dev, ops->restore); -break ; +return ops->restore;#endif /* CONFIG_HIBERNATE_CALLBACKS */ -default : - error = -EINVAL ; } -return error; +return NULL ; }/** -* pm_noirq_op - Execute the PM operation appropriate for given PM event. -* @dev: Device to handle. +* 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. * * The driver of @dev will not receive interrupts while this function is being * executed. */ -static int pm_noirq_op (struct device *dev, -const struct dev_pm_ops *ops, -pm_message_t state) +static int (*pm_noirq_op (const struct dev_pm_ops *ops,pm_message_t state))(struct device *) { -int error =0 ; -switch (state.event) {#ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND : - error =dpm_run_callback (dev, ops->suspend_noirq); -break ; +return ops->suspend_noirq;case PM_EVENT_RESUME : - error =dpm_run_callback (dev, ops->resume_noirq); -break ; +return ops->resume_noirq;#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE :case PM_EVENT_QUIESCE : - error =dpm_run_callback (dev, ops->freeze_noirq); -break ; +return ops->freeze_noirq;case PM_EVENT_HIBERNATE : - error =dpm_run_callback (dev, ops->poweroff_noirq); -break ; +return ops->poweroff_noirq;case PM_EVENT_THAW :case PM_EVENT_RECOVER : - error =dpm_run_callback (dev, ops->thaw_noirq); -break ; +return ops->thaw_noirq;case PM_EVENT_RESTORE : - error =dpm_run_callback (dev, ops->restore_noirq); -break ; +return ops->restore_noirq;#endif /* CONFIG_HIBERNATE_CALLBACKS */ -default : - error = -EINVAL ; } -return error; +return NULL ; }static char *pm_verb (int event)
@@ -375,6 +332,26 @@ static void dpm_show_time(ktime_t startt usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); } +static int dpm_run_callback (int (*cb)(struct device *),struct device *dev, +pm_message_t state,char *info) +{ +ktime_t calltime; +int error; + +if (!cb) +return 0 ; + + calltime =initcall_debug_start (dev); + +pm_dev_dbg (dev, state, info); + error =cb (dev); +suspend_report_result (cb, error); + +initcall_debug_report (dev, calltime, error); + +return error; +} +/*------------------------- Resume routines -------------------------*/ /**
@@ -387,25 +364,29 @@ static void dpm_show_time(ktime_t startt*/ static int device_resume_noirq (struct device *dev,pm_message_t state) { +int (*callback)(struct device *) =NULL ; +char *info =NULL ;int error =0 ;TRACE_DEVICE (dev);TRACE_RESUME (0 );if (dev->pm_domain) { -pm_dev_dbg (dev, state,"EARLY power domain " ); - error =pm_noirq_op (dev, &dev->pm_domain->ops, state); + info ="EARLY power domain " ; + callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"EARLY type " ); - error =pm_noirq_op (dev, dev->type->pm, state); + info ="EARLY type " ; + callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { -pm_dev_dbg (dev, state,"EARLY class " ); - error =pm_noirq_op (dev, dev->class->pm, state); + info ="EARLY class " ; + callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { -pm_dev_dbg (dev, state,"EARLY " ); - error =pm_noirq_op (dev, dev->bus->pm, state); + info ="EARLY " ; + callback =pm_noirq_op (dev->bus->pm, state); } + error =dpm_run_callback (callback, dev, state, info); +TRACE_RESUME (error);return error; }
@@ -455,6 +436,8 @@ EXPORT_SYMBOL_GPL(dpm_resume_noirq);*/ static int device_resume (struct device *dev,pm_message_t state,bool async) { +int (*callback)(struct device *) =NULL ; +char *info =NULL ;int error =0 ;bool put = false;
@@ -477,40 +460,41 @@ static int device_resume(struct device * put = true;if (dev->pm_domain) { -pm_dev_dbg (dev, state,"power domain " ); - error =pm_op (dev, &dev->pm_domain->ops, state); + info ="power domain " ; + callback =pm_op (&dev->pm_domain->ops, state); goto End; }if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"type " ); - error =pm_op (dev, dev->type->pm, state); + info ="type " ; + callback =pm_op (dev->type->pm, state); goto End; }if (dev->class) {if (dev->class->pm) { -pm_dev_dbg (dev, state,"class " ); - error =pm_op (dev, dev->class->pm, state); + info ="class " ; + callback =pm_op (dev->class->pm, state); goto End; }else if (dev->class->resume) { -pm_dev_dbg (dev, state,"legacy class " ); - error =dpm_run_callback (dev, dev->class->resume); + info ="legacy class " ; + callback = dev->class->resume; goto End; } }if (dev->bus) {if (dev->bus->pm) { -pm_dev_dbg (dev, state,"" ); - error =pm_op (dev, dev->bus->pm, state); + info ="" ; + callback =pm_op (dev->bus->pm, state); }else if (dev->bus->resume) { -pm_dev_dbg (dev, state,"legacy " ); - error =dpm_run_callback (dev, dev->bus->resume); + info ="legacy " ; + callback = dev->bus->resume; } } End: + error =dpm_run_callback (callback, dev, state, info); dev->power.is_suspended = false; Unlock:
@@ -705,23 +689,24 @@ static pm_message_t resume_event(pm_mess*/ static int device_suspend_noirq (struct device *dev,pm_message_t state) { -int error =0 ; +int (*callback)(struct device *) =NULL ; +char *info =NULL ;if (dev->pm_domain) { -pm_dev_dbg (dev, state,"LATE power domain " ); - error =pm_noirq_op (dev, &dev->pm_domain->ops, state); + info ="LATE power domain " ; + callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"LATE type " ); - error =pm_noirq_op (dev, dev->type->pm, state); + info ="LATE type " ; + callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { -pm_dev_dbg (dev, state,"LATE class " ); - error =pm_noirq_op (dev, dev->class->pm, state); + info ="LATE class " ; + callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { -pm_dev_dbg (dev, state,"LATE " ); - error =pm_noirq_op (dev, dev->bus->pm, state); + info ="LATE " ; + callback =pm_noirq_op (dev->bus->pm, state); } -return error; +return dpm_run_callback (callback, dev, state, info); }/**
@@ -798,6 +783,8 @@ static int legacy_suspend(struct device*/ static int __device_suspend (struct device *dev,pm_message_t state,bool async) { +int (*callback)(struct device *) =NULL ; +char *info =NULL ;int error =0 ;dpm_wait_for_children (dev, async);
@@ -818,22 +805,22 @@ static int __device_suspend(struct devicdevice_lock (dev);if (dev->pm_domain) { -pm_dev_dbg (dev, state,"power domain " ); - error =pm_op (dev, &dev->pm_domain->ops, state); - goto End; + info ="power domain " ; + callback =pm_op (&dev->pm_domain->ops, state); + goto Run; }if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"type " ); - error =pm_op (dev, dev->type->pm, state); - goto End; + info ="type " ; + callback =pm_op (dev->type->pm, state); + goto Run; }if (dev->class) {if (dev->class->pm) { -pm_dev_dbg (dev, state,"class " ); - error =pm_op (dev, dev->class->pm, state); - goto End; + info ="class " ; + callback =pm_op (dev->class->pm, state); + goto Run; }else if (dev->class->suspend) {pm_dev_dbg (dev, state,"legacy class " ); error =legacy_suspend (dev, state, dev->class->suspend);
@@ -843,14 +830,18 @@ static int __device_suspend(struct devicif (dev->bus) {if (dev->bus->pm) { -pm_dev_dbg (dev, state,"" ); - error =pm_op (dev, dev->bus->pm, state); + info ="" ; + callback =pm_op (dev->bus->pm, state); }else if (dev->bus->suspend) {pm_dev_dbg (dev, state,"legacy " ); error =legacy_suspend (dev, state, dev->bus->suspend); + goto End; } } + Run: + error =dpm_run_callback (callback, dev, state, info); + End:if (!error) { dev->power.is_suspended = true;
Re: [PATCH 1/4] PM / Sleep: Make pm_op() and pm_noirq_op() return callback pointers
Quoted 11 lines · Rafael J. Wysocki <rjw <at> sisk.pl> writes:
From: Rafael J. Wysocki <rjw <at> sisk.pl>
Make the
pm_op()andpm_noirq_op()functions return pointers to appropriate callbacks instead of executing those callbacks and returning their results.This change is required for a subsequent modification that will execute the corresponding driver callback if the subsystem callback returned by either
pm_op(), orpm_noirq_op()is NULL.
Hello Rafael,
How about typedef'ing something like pm_callback_t for readability?
typedef int (*pm_callback_t)(struct device *);
This way, the code will be easier to read.
(Dropped inline changes below due to the grumpiness of the GMANE's web interface)
Thanks.
Namhyung Kim
Re: [PATCH 1/4] PM / Sleep: Make pm_op() and pm_noirq_op() return callback pointers
Quoted 14 lines · Namhyung Kim
Quoted 11 lines · Rafael J. Wysocki <rjw <at> sisk.pl> writes:
From: Rafael J. Wysocki <rjw <at> sisk.pl>
Make the
pm_op()andpm_noirq_op()functions return pointers to appropriate callbacks instead of executing those callbacks and returning their results.This change is required for a subsequent modification that will execute the corresponding driver callback if the subsystem callback returned by either
pm_op(), orpm_noirq_op()is NULL.
Quoted 7 lines
Hello Rafael,
How about typedef'ing something like
pm_callback_tfor readability?typedef int (*pm_callback_t)(struct device *);This way, the code will be easier to read.
Do you mean something like in the patch below? It does look a bit simpler.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make pm_op() and pm_noirq_op() return callback pointers
Make the pm_op() and pm_noirq_op() functions return pointers to appropriate callbacks instead of executing those callbacks and returning their results.
This change is required for a subsequent modification that will execute the corresponding driver callback if the subsystem callback returned by either pm_op(), or pm_noirq_op() is NULL.
--- drivers/base/power/main.c | 197 ++++++++++++++++++++++------------------------ 1 file changed, 95 insertions(+), 102 deletions(-)
drivers/base/power/main.c +95 -102
@@ -32,6 +32,8 @@#include "../base.h" #include "power.h" +typedef int (*pm_callback_t )(struct device *); +/* * The entries in the dpm_list list are in a depth first order, simply * because children are guaranteed to be discovered after parents, and
@@ -211,113 +213,70 @@ static void dpm_wait_for_children(structdevice_for_each_child (dev, &async, dpm_wait_fn); } -static int dpm_run_callback (struct device *dev,int (*cb)(struct device *)) -{ -ktime_t calltime; -int error; - -if (!cb) -return 0 ; - - calltime =initcall_debug_start (dev); - - error =cb (dev); -suspend_report_result (cb, error); - -initcall_debug_report (dev, calltime, error); - -return error; -} -/** -* pm_op - Execute the PM operation appropriate for given PM event. -* @dev: Device to handle. +* pm_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. */ -static int pm_op (struct device *dev, -const struct dev_pm_ops *ops, -pm_message_t state) +static pm_callback_t pm_op (const struct dev_pm_ops *ops,pm_message_t state) { -int error =0 ; -switch (state.event) {#ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND : - error =dpm_run_callback (dev, ops->suspend); -break ; +return ops->suspend;case PM_EVENT_RESUME : - error =dpm_run_callback (dev, ops->resume); -break ; +return ops->resume;#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE :case PM_EVENT_QUIESCE : - error =dpm_run_callback (dev, ops->freeze); -break ; +return ops->freeze;case PM_EVENT_HIBERNATE : - error =dpm_run_callback (dev, ops->poweroff); -break ; +return ops->poweroff;case PM_EVENT_THAW :case PM_EVENT_RECOVER : - error =dpm_run_callback (dev, ops->thaw); +return ops->thaw;break ;case PM_EVENT_RESTORE : - error =dpm_run_callback (dev, ops->restore); -break ; +return ops->restore;#endif /* CONFIG_HIBERNATE_CALLBACKS */ -default : - error = -EINVAL ; } -return error; +return NULL ; }/** -* pm_noirq_op - Execute the PM operation appropriate for given PM event. -* @dev: Device to handle. +* 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. * * The driver of @dev will not receive interrupts while this function is being * executed. */ -static int pm_noirq_op (struct device *dev, -const struct dev_pm_ops *ops, -pm_message_t state) +static pm_callback_t pm_noirq_op (const struct dev_pm_ops *ops,pm_message_t state) { -int error =0 ; -switch (state.event) {#ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND : - error =dpm_run_callback (dev, ops->suspend_noirq); -break ; +return ops->suspend_noirq;case PM_EVENT_RESUME : - error =dpm_run_callback (dev, ops->resume_noirq); -break ; +return ops->resume_noirq;#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE :case PM_EVENT_QUIESCE : - error =dpm_run_callback (dev, ops->freeze_noirq); -break ; +return ops->freeze_noirq;case PM_EVENT_HIBERNATE : - error =dpm_run_callback (dev, ops->poweroff_noirq); -break ; +return ops->poweroff_noirq;case PM_EVENT_THAW :case PM_EVENT_RECOVER : - error =dpm_run_callback (dev, ops->thaw_noirq); -break ; +return ops->thaw_noirq;case PM_EVENT_RESTORE : - error =dpm_run_callback (dev, ops->restore_noirq); -break ; +return ops->restore_noirq;#endif /* CONFIG_HIBERNATE_CALLBACKS */ -default : - error = -EINVAL ; } -return error; +return NULL ; }static char *pm_verb (int event)
@@ -375,6 +334,26 @@ static void dpm_show_time(ktime_t startt usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); } +static int dpm_run_callback (pm_callback_t cb,struct device *dev, +pm_message_t state,char *info) +{ +ktime_t calltime; +int error; + +if (!cb) +return 0 ; + + calltime =initcall_debug_start (dev); + +pm_dev_dbg (dev, state, info); + error =cb (dev); +suspend_report_result (cb, error); + +initcall_debug_report (dev, calltime, error); + +return error; +} +/*------------------------- Resume routines -------------------------*/ /**
@@ -387,25 +366,29 @@ static void dpm_show_time(ktime_t startt*/ static int device_resume_noirq (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) { -pm_dev_dbg (dev, state,"EARLY power domain " ); - error =pm_noirq_op (dev, &dev->pm_domain->ops, state); + info ="EARLY power domain " ; + callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"EARLY type " ); - error =pm_noirq_op (dev, dev->type->pm, state); + info ="EARLY type " ; + callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { -pm_dev_dbg (dev, state,"EARLY class " ); - error =pm_noirq_op (dev, dev->class->pm, state); + info ="EARLY class " ; + callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { -pm_dev_dbg (dev, state,"EARLY " ); - error =pm_noirq_op (dev, dev->bus->pm, state); + info ="EARLY " ; + callback =pm_noirq_op (dev->bus->pm, state); } + error =dpm_run_callback (callback, dev, state, info); +TRACE_RESUME (error);return error; }
@@ -455,6 +438,8 @@ EXPORT_SYMBOL_GPL(dpm_resume_noirq);*/ static int device_resume (struct device *dev,pm_message_t state,bool async) { +pm_callback_t callback =NULL ; +char *info =NULL ;int error =0 ;bool put = false;
@@ -477,40 +462,41 @@ static int device_resume(struct device * put = true;if (dev->pm_domain) { -pm_dev_dbg (dev, state,"power domain " ); - error =pm_op (dev, &dev->pm_domain->ops, state); + info ="power domain " ; + callback =pm_op (&dev->pm_domain->ops, state); goto End; }if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"type " ); - error =pm_op (dev, dev->type->pm, state); + info ="type " ; + callback =pm_op (dev->type->pm, state); goto End; }if (dev->class) {if (dev->class->pm) { -pm_dev_dbg (dev, state,"class " ); - error =pm_op (dev, dev->class->pm, state); + info ="class " ; + callback =pm_op (dev->class->pm, state); goto End; }else if (dev->class->resume) { -pm_dev_dbg (dev, state,"legacy class " ); - error =dpm_run_callback (dev, dev->class->resume); + info ="legacy class " ; + callback = dev->class->resume; goto End; } }if (dev->bus) {if (dev->bus->pm) { -pm_dev_dbg (dev, state,"" ); - error =pm_op (dev, dev->bus->pm, state); + info ="" ; + callback =pm_op (dev->bus->pm, state); }else if (dev->bus->resume) { -pm_dev_dbg (dev, state,"legacy " ); - error =dpm_run_callback (dev, dev->bus->resume); + info ="legacy " ; + callback = dev->bus->resume; } } End: + error =dpm_run_callback (callback, dev, state, info); dev->power.is_suspended = false; Unlock:
@@ -705,23 +691,24 @@ static pm_message_t resume_event(pm_mess*/ static int device_suspend_noirq (struct device *dev,pm_message_t state) { -int error =0 ; +pm_callback_t callback =NULL ; +char *info =NULL ;if (dev->pm_domain) { -pm_dev_dbg (dev, state,"LATE power domain " ); - error =pm_noirq_op (dev, &dev->pm_domain->ops, state); + info ="LATE power domain " ; + callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"LATE type " ); - error =pm_noirq_op (dev, dev->type->pm, state); + info ="LATE type " ; + callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { -pm_dev_dbg (dev, state,"LATE class " ); - error =pm_noirq_op (dev, dev->class->pm, state); + info ="LATE class " ; + callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { -pm_dev_dbg (dev, state,"LATE " ); - error =pm_noirq_op (dev, dev->bus->pm, state); + info ="LATE " ; + callback =pm_noirq_op (dev->bus->pm, state); } -return error; +return dpm_run_callback (callback, dev, state, info); }/**
@@ -798,6 +785,8 @@ static int legacy_suspend(struct device*/ static int __device_suspend (struct device *dev,pm_message_t state,bool async) { +pm_callback_t callback =NULL ; +char *info =NULL ;int error =0 ;dpm_wait_for_children (dev, async);
@@ -818,22 +807,22 @@ static int __device_suspend(struct devicdevice_lock (dev);if (dev->pm_domain) { -pm_dev_dbg (dev, state,"power domain " ); - error =pm_op (dev, &dev->pm_domain->ops, state); - goto End; + info ="power domain " ; + callback =pm_op (&dev->pm_domain->ops, state); + goto Run; }if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"type " ); - error =pm_op (dev, dev->type->pm, state); - goto End; + info ="type " ; + callback =pm_op (dev->type->pm, state); + goto Run; }if (dev->class) {if (dev->class->pm) { -pm_dev_dbg (dev, state,"class " ); - error =pm_op (dev, dev->class->pm, state); - goto End; + info ="class " ; + callback =pm_op (dev->class->pm, state); + goto Run; }else if (dev->class->suspend) {pm_dev_dbg (dev, state,"legacy class " ); error =legacy_suspend (dev, state, dev->class->suspend);
@@ -843,14 +832,18 @@ static int __device_suspend(struct devicif (dev->bus) {if (dev->bus->pm) { -pm_dev_dbg (dev, state,"" ); - error =pm_op (dev, dev->bus->pm, state); + info ="" ; + callback =pm_op (dev->bus->pm, state); }else if (dev->bus->suspend) {pm_dev_dbg (dev, state,"legacy " ); error =legacy_suspend (dev, state, dev->bus->suspend); + goto End; } } + Run: + error =dpm_run_callback (callback, dev, state, info); + End:if (!error) { dev->power.is_suspended = true;
Re: [PATCH 1/4] PM / Sleep: Make pm_op() and pm_noirq_op() return callback pointers
2011-12-13 (화), 00:53 +0100, Rafael J. Wysocki:
Quoted 17 lines · Namhyung Kim
Quoted 16 lines
Quoted 11 lines · Rafael J. Wysocki <rjw <at> sisk.pl> writes:
From: Rafael J. Wysocki <rjw <at> sisk.pl>
Make the
pm_op()andpm_noirq_op()functions return pointers to appropriate callbacks instead of executing those callbacks and returning their results.This change is required for a subsequent modification that will execute the corresponding driver callback if the subsystem callback returned by either
pm_op(), orpm_noirq_op()is NULL.Hello Rafael,
Quoted 8 lines
Quoted 5 lines
How about typedef'ing something like
pm_callback_tfor readability?typedef int (*pm_callback_t)(struct device *);This way, the code will be easier to read.
Do you mean something like in the patch below? It does look a bit simpler.
Yes, indeed. The patch looks better to me. :)
Thanks,
Namhyung Kim
PATCH 2/4 PM: Run the driver callback directly if the subsystem one is not there
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make the PM core execute driver PM callbacks directly if the corresponding subsystem callbacks are not present.
There are three reasons for doing that. First, it reflects the behavior of drivers/base/dd.c:really_probe() that runs the driver's .probe() callback directly if the bus type's one is not defined, so this change will remove one arbitrary difference between the PM core and the remaining parts of the driver core. Second, it will allow some subsystems, whose PM callbacks don't do anything except for executing driver callbacks, to be simplified quite a bit by removing those "forward-only" callbacks. Finally, it will allow us to remove one level of indirection in the system suspend and resume code paths where it is not necessary, which is going to lead to less debug noise with initcall_debug passed in the kernel command line (messages won't be printed for driverless devices whose subsystems don't provide PM callbacks among other things).
--- Documentation/power/devices.txt | 39 ++++++----- Documentation/power/runtime_pm.txt | 128 +++++++++++++++++++------------------ drivers/base/power/main.c | 109 ++++++++++++++++++++----------- drivers/base/power/runtime.c | 9 ++ 4 files changed, 170 insertions(+), 115 deletions(-)
drivers/base/power/runtime.c +9 -0
@@ -250,6 +250,9 @@ static int rpm_idle(struct device *dev,else callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_idle; +if (callback)__rpm_callback (callback, dev);
@@ -713,6 +716,12 @@ static int rpm_resume(struct device *develse callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_suspend; + +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_resume; + retval =rpm_callback (callback, dev);if (retval) {__update_runtime_status (dev,RPM_SUSPENDED );
Documentation/power/devices.txt +22 -17
@@ -126,7 +126,9 @@ The core methods to suspend and resume d pointed to by the ops member of struct dev_pm_domain, or by the pm member of struct bus_type, struct device_type and struct class. They are mostly of interest to the people writing infrastructure for platforms and buses, like PCI -or USB, or device type and device class drivers. +or USB, or device type and device class drivers. They also are relevant to the +writers of device drivers whose subsystems (PM domains, device types, device +classes and bus types) don't provide all power management methods. Bus drivers implement these methods as appropriate for the hardware and the drivers using it; PCI works differently from USB, and so on. Not many people
@@ -268,32 +270,35 @@ various phases always run after tasks ha unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have been disabled (except for those marked with the IRQF_NO_SUSPEND flag). -All phases use PM domain, bus, type, or class callbacks (that is, methods -defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, or dev->class->pm). -These callbacks are regarded by the PM core as mutually exclusive. Moreover, -PM domain callbacks always take precedence over bus, type and class callbacks, -while type callbacks take precedence over bus and class callbacks, and class -callbacks take precedence over bus callbacks. To be precise, the following -rules are used to determine which callback to execute in the given phase: - - 1. If dev->pm_domain is present, the PM core will attempt to execute the - callback included in dev->pm_domain->ops. If that callback is not - present, no action will be carried out for the given device. +All phases use PM domain, bus, type, class or driver callbacks (that is, methods +defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, dev->class->pm or +dev->driver->pm). These callbacks are regarded by the PM core as mutually +exclusive. Moreover, PM domain callbacks always take precedence over all of the +other callbacks and, for example, type callbacks take precedence over bus, class +and driver callbacks. To be precise, the following rules are used to determine +which callback to execute in the given phase: + + 1. If dev->pm_domain is present, the PM core will choose the callback + included in dev->pm_domain->ops for execution 2. Otherwise, if both dev->type and dev->type->pm are present, the callback - included in dev->type->pm will be executed. + included in dev->type->pm will be chosen for execution. 3. Otherwise, if both dev->class and dev->class->pm are present, the - callback included in dev->class->pm will be executed. + callback included in dev->class->pm will be chosen for execution. 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback - included in dev->bus->pm will be executed. + included in dev->bus->pm will be chosen for execution. This allows PM domains and device types to override callbacks provided by bus types or device classes if necessary. -These callbacks may in turn invoke device- or driver-specific methods stored in -dev->driver->pm, but they don't have to. +The PM domain, type, class and bus callbacks may in turn invoke device- or +driver-specific methods stored in dev->driver->pm, but they don't have to do +that. + +If the subsystem callback chosen for execution is not present, the PM core will +execute the corresponding method from dev->driver->pm instead if there is one. Entering System Suspend
Documentation/power/runtime_pm.txt +67 -61
159 lines not on this page · raw message
drivers/base/power/main.c +72 -37
197 lines not on this page · raw message
Re: [PATCH 2/4] PM: Run the driver callback directly if the subsystem one is not there
Quoted 19 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Make the PM core execute driver PM callbacks directly if the corresponding subsystem callbacks are not present.
drivers/base/power/runtime.c +3
-0@@ -250,6 +250,9 @@ static int rpm_idle(struct device *dev,else callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_idle; +if (callback)__rpm_callback (callback, dev);@@ -713,6 +716,12 @@ static int rpm_resume(struct device *develse callback =NULL ;
drivers/base/power/runtime.c static int rpm_resume(struct device *dev · line 727
Quoted 10 lines
drivers/base/power/runtime.c +6
-0+if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_suspend; + +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_resume; + retval =rpm_callback (callback, dev);if (retval) {__update_runtime_status (dev,RPM_SUSPENDED );
Looks like part of that got added in the wrong place.
Alan Stern
Re: [PATCH 2/4] PM: Run the driver callback directly if the subsystem one is not there
Quoted 22 lines · Alan Stern
Quoted 20 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Make the PM core execute driver PM callbacks directly if the corresponding subsystem callbacks are not present.
drivers/base/power/runtime.c +3
-0@@ -250,6 +250,9 @@ static int rpm_idle(struct device *dev,else callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_idle; +if (callback)__rpm_callback (callback, dev);@@ -713,6 +716,12 @@ static int rpm_resume(struct device *develse callback =NULL ;
Quoted 11 lines
drivers/base/power/runtime.c static int rpm_resume(struct device *dev · line 727
Quoted 9 lines
drivers/base/power/runtime.c +6
-0+if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_suspend; + +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_resume; + retval =rpm_callback (callback, dev);if (retval) {__update_runtime_status (dev,RPM_SUSPENDED );Looks like part of that got added in the wrong place.
Indeed, thanks for spotting this!
Updated patch is appended.
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM: Run the driver callback directly if the subsystem one is not there
Make the PM core execute driver PM callbacks directly if the corresponding subsystem callbacks are not present.
There are three reasons for doing that. First, it reflects the behavior of drivers/base/dd.c:really_probe() that runs the driver's .probe() callback directly if the bus type's one is not defined, so this change will remove one arbitrary difference between the PM core and the remaining parts of the driver core. Second, it will allow some subsystems, whose PM callbacks don't do anything except for executing driver callbacks, to be simplified quite a bit by removing those "forward-only" callbacks. Finally, it will allow us to remove one level of indirection in the system suspend and resume code paths where it is not necessary, which is going to lead to less debug noise with initcall_debug passed in the kernel command line (messages won't be printed for driverless devices whose subsystems don't provide PM callbacks among other things).
--- Documentation/power/devices.txt | 39 ++++++----- Documentation/power/runtime_pm.txt | 128 +++++++++++++++++++------------------ drivers/base/power/main.c | 109 ++++++++++++++++++++----------- drivers/base/power/runtime.c | 9 ++ 4 files changed, 170 insertions(+), 115 deletions(-)
drivers/base/power/runtime.c +9 -0
@@ -250,6 +250,9 @@ static int rpm_idle(struct device *dev,else callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_idle; +if (callback)__rpm_callback (callback, dev);
@@ -485,6 +488,9 @@ static int rpm_suspend(struct device *deelse callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_suspend; + retval =rpm_callback (callback, dev);if (retval) goto fail;
@@ -713,6 +719,9 @@ static int rpm_resume(struct device *develse callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_resume; + retval =rpm_callback (callback, dev);if (retval) {__update_runtime_status (dev,RPM_SUSPENDED );
Documentation/power/devices.txt +22 -17
@@ -126,7 +126,9 @@ The core methods to suspend and resume d pointed to by the ops member of struct dev_pm_domain, or by the pm member of struct bus_type, struct device_type and struct class. They are mostly of interest to the people writing infrastructure for platforms and buses, like PCI -or USB, or device type and device class drivers. +or USB, or device type and device class drivers. They also are relevant to the +writers of device drivers whose subsystems (PM domains, device types, device +classes and bus types) don't provide all power management methods. Bus drivers implement these methods as appropriate for the hardware and the drivers using it; PCI works differently from USB, and so on. Not many people
@@ -268,32 +270,35 @@ various phases always run after tasks ha unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have been disabled (except for those marked with the IRQF_NO_SUSPEND flag). -All phases use PM domain, bus, type, or class callbacks (that is, methods -defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, or dev->class->pm). -These callbacks are regarded by the PM core as mutually exclusive. Moreover, -PM domain callbacks always take precedence over bus, type and class callbacks, -while type callbacks take precedence over bus and class callbacks, and class -callbacks take precedence over bus callbacks. To be precise, the following -rules are used to determine which callback to execute in the given phase: - - 1. If dev->pm_domain is present, the PM core will attempt to execute the - callback included in dev->pm_domain->ops. If that callback is not - present, no action will be carried out for the given device. +All phases use PM domain, bus, type, class or driver callbacks (that is, methods +defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, dev->class->pm or +dev->driver->pm). These callbacks are regarded by the PM core as mutually +exclusive. Moreover, PM domain callbacks always take precedence over all of the +other callbacks and, for example, type callbacks take precedence over bus, class +and driver callbacks. To be precise, the following rules are used to determine +which callback to execute in the given phase: + + 1. If dev->pm_domain is present, the PM core will choose the callback + included in dev->pm_domain->ops for execution 2. Otherwise, if both dev->type and dev->type->pm are present, the callback - included in dev->type->pm will be executed. + included in dev->type->pm will be chosen for execution. 3. Otherwise, if both dev->class and dev->class->pm are present, the - callback included in dev->class->pm will be executed. + callback included in dev->class->pm will be chosen for execution. 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback - included in dev->bus->pm will be executed. + included in dev->bus->pm will be chosen for execution. This allows PM domains and device types to override callbacks provided by bus types or device classes if necessary. -These callbacks may in turn invoke device- or driver-specific methods stored in -dev->driver->pm, but they don't have to. +The PM domain, type, class and bus callbacks may in turn invoke device- or +driver-specific methods stored in dev->driver->pm, but they don't have to do +that. + +If the subsystem callback chosen for execution is not present, the PM core will +execute the corresponding method from dev->driver->pm instead if there is one. Entering System Suspend
Documentation/power/runtime_pm.txt +67 -61
159 lines not on this page · raw message
drivers/base/power/main.c +72 -37
197 lines not on this page · raw message
PATCH 3/4 PM / Sleep: Remove forward-only callbacks from platform bus type
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The forward-only PM callbacks provided by the platform bus type are not necessary any more, because the PM core executes driver callbacks when the corresponding subsystem callbacks are not present, so drop them.
--- drivers/base/platform.c | 115 ---------------------------------------- include/linux/platform_device.h | 30 ---------- 2 files changed, 1 insertion(+), 144 deletions(-)
drivers/base/platform.c +0 -115
@@ -700,25 +700,6 @@ static int platform_legacy_resume(struct return ret; } -int platform_pm_prepare (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (drv && drv->pm && drv->pm->prepare) - ret = drv->pm->prepare (dev); - -return ret; -} - -void platform_pm_complete (struct device *dev) -{ -struct device_driver *drv = dev->driver; - -if (drv && drv->pm && drv->pm->complete) - drv->pm->complete (dev); -} -#endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_SUSPEND
@@ -741,22 +722,6 @@ int platform_pm_suspend(struct device *dreturn ret; } -int platform_pm_suspend_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->suspend_noirq) - ret = drv->pm->suspend_noirq (dev); - } - -return ret; -} -int platform_pm_resume (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -775,22 +740,6 @@ int platform_pm_resume(struct device *de return ret; } -int platform_pm_resume_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->resume_noirq) - ret = drv->pm->resume_noirq (dev); - } - -return ret; -} -#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS
@@ -813,22 +762,6 @@ int platform_pm_freeze(struct device *dereturn ret; } -int platform_pm_freeze_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->freeze_noirq) - ret = drv->pm->freeze_noirq (dev); - } - -return ret; -} -int platform_pm_thaw (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -847,22 +780,6 @@ int platform_pm_thaw(struct device *dev)return ret; } -int platform_pm_thaw_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->thaw_noirq) - ret = drv->pm->thaw_noirq (dev); - } - -return ret; -} -int platform_pm_poweroff (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -881,22 +798,6 @@ int platform_pm_poweroff(struct device *return ret; } -int platform_pm_poweroff_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->poweroff_noirq) - ret = drv->pm->poweroff_noirq (dev); - } - -return ret; -} -int platform_pm_restore (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -913,22 +814,6 @@ int platform_pm_restore(struct device *d }return ret; -} - -int platform_pm_restore_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->restore_noirq) - ret = drv->pm->restore_noirq (dev); - } - -return ret; }#endif /* CONFIG_HIBERNATE_CALLBACKS */
include/linux/platform_device.h +1 -29
@@ -264,62 +264,34 @@ static inline char *early_platform_drive }#endif /* MODULE */ -#ifdef CONFIG_PM_SLEEP -extern int platform_pm_prepare (struct device *dev); -extern void platform_pm_complete (struct device *dev); -#else -#define platform_pm_prepare NULL -#define platform_pm_complete NULL -#endif -#ifdef CONFIG_SUSPEND extern int platform_pm_suspend (struct device *dev); -extern int platform_pm_suspend_noirq (struct device *dev);extern int platform_pm_resume (struct device *dev); -extern int platform_pm_resume_noirq (struct device *dev);#else #define platform_pm_suspend NULL#define platform_pm_resume NULL -#define platform_pm_suspend_noirq NULL -#define platform_pm_resume_noirq NULL#endif #ifdef CONFIG_HIBERNATE_CALLBACKS extern int platform_pm_freeze (struct device *dev); -extern int platform_pm_freeze_noirq (struct device *dev);extern int platform_pm_thaw (struct device *dev); -extern int platform_pm_thaw_noirq (struct device *dev);extern int platform_pm_poweroff (struct device *dev); -extern int platform_pm_poweroff_noirq (struct device *dev);extern int platform_pm_restore (struct device *dev); -extern int platform_pm_restore_noirq (struct device *dev);#else #define platform_pm_freeze NULL#define platform_pm_thaw NULL#define platform_pm_poweroff NULL#define platform_pm_restore NULL -#define platform_pm_freeze_noirq NULL -#define platform_pm_thaw_noirq NULL -#define platform_pm_poweroff_noirq NULL -#define platform_pm_restore_noirq NULL#endif #ifdef CONFIG_PM_SLEEP #define USE_PLATFORM_PM_SLEEP_OPS \ - .prepare = platform_pm_prepare, \ - .complete = platform_pm_complete, \ .suspend = platform_pm_suspend, \ .resume = platform_pm_resume, \ .freeze = platform_pm_freeze, \ .thaw = platform_pm_thaw, \ .poweroff = platform_pm_poweroff, \ - .restore = platform_pm_restore, \ - .suspend_noirq = platform_pm_suspend_noirq, \ - .resume_noirq = platform_pm_resume_noirq, \ - .freeze_noirq = platform_pm_freeze_noirq, \ - .thaw_noirq = platform_pm_thaw_noirq, \ - .poweroff_noirq = platform_pm_poweroff_noirq, \ - .restore_noirq = platform_pm_restore_noirq, + .restore = platform_pm_restore,#else #define USE_PLATFORM_PM_SLEEP_OPS #endif
PATCH 4/4 PM / Sleep: Remove forward-only callbacks from AMBA bus type
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The forward-only PM callbacks provided by the AMBA bus type are not necessary any more, because the PM core executes driver callbacks when the corresponding subsystem callbacks are not present, so drop them.
--- drivers/amba/bus.c | 136 ----------------------------------------------------- 1 file changed, 1 insertion(+), 135 deletions(-)
drivers/amba/bus.c +1 -135
@@ -109,31 +109,7 @@ static int amba_legacy_resume(struct dev return ret; } -static int amba_pm_prepare (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (drv && drv->pm && drv->pm->prepare) - ret = drv->pm->prepare (dev); - -return ret; -} - -static void amba_pm_complete (struct device *dev) -{ -struct device_driver *drv = dev->driver; - -if (drv && drv->pm && drv->pm->complete) - drv->pm->complete (dev); -} - -#else /* !CONFIG_PM_SLEEP */ - -#define amba_pm_prepare NULL -#define amba_pm_complete NULL - -#endif /* !CONFIG_PM_SLEEP */ +#endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_SUSPEND
@@ -155,22 +131,6 @@ static int amba_pm_suspend(struct devicereturn ret; } -static int amba_pm_suspend_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->suspend_noirq) - ret = drv->pm->suspend_noirq (dev); - } - -return ret; -} -static int amba_pm_resume (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -189,28 +149,10 @@ static int amba_pm_resume(struct device return ret; } -static int amba_pm_resume_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->resume_noirq) - ret = drv->pm->resume_noirq (dev); - } - -return ret; -} -#else /* !CONFIG_SUSPEND */ #define amba_pm_suspend NULL#define amba_pm_resume NULL -#define amba_pm_suspend_noirq NULL -#define amba_pm_resume_noirq NULL#endif /* !CONFIG_SUSPEND */
@@ -234,22 +176,6 @@ static int amba_pm_freeze(struct devicereturn ret; } -static int amba_pm_freeze_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->freeze_noirq) - ret = drv->pm->freeze_noirq (dev); - } - -return ret; -} -static int amba_pm_thaw (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -268,22 +194,6 @@ static int amba_pm_thaw(struct device *dreturn ret; } -static int amba_pm_thaw_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->thaw_noirq) - ret = drv->pm->thaw_noirq (dev); - } - -return ret; -} -static int amba_pm_poweroff (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -302,22 +212,6 @@ static int amba_pm_poweroff(struct devicreturn ret; } -static int amba_pm_poweroff_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->poweroff_noirq) - ret = drv->pm->poweroff_noirq (dev); - } - -return ret; -} -static int amba_pm_restore (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -336,32 +230,12 @@ static int amba_pm_restore(struct device return ret; } -static int amba_pm_restore_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->restore_noirq) - ret = drv->pm->restore_noirq (dev); - } - -return ret; -} -#else /* !CONFIG_HIBERNATE_CALLBACKS */ #define amba_pm_freeze NULL#define amba_pm_thaw NULL#define amba_pm_poweroff NULL#define amba_pm_restore NULL -#define amba_pm_freeze_noirq NULL -#define amba_pm_thaw_noirq NULL -#define amba_pm_poweroff_noirq NULL -#define amba_pm_restore_noirq NULL#endif /* !CONFIG_HIBERNATE_CALLBACKS */
@@ -402,20 +276,12 @@ static int amba_pm_runtime_resume(struct #ifdef CONFIG_PM static const struct dev_pm_ops amba_pm = { - .prepare = amba_pm_prepare, - .complete = amba_pm_complete, .suspend = amba_pm_suspend, .resume = amba_pm_resume, .freeze = amba_pm_freeze, .thaw = amba_pm_thaw, .poweroff = amba_pm_poweroff, .restore = amba_pm_restore, - .suspend_noirq = amba_pm_suspend_noirq, - .resume_noirq = amba_pm_resume_noirq, - .freeze_noirq = amba_pm_freeze_noirq, - .thaw_noirq = amba_pm_thaw_noirq, - .poweroff_noirq = amba_pm_poweroff_noirq, - .restore_noirq = amba_pm_restore_noirq, SET_RUNTIME_PM_OPS( amba_pm_runtime_suspend, amba_pm_runtime_resume,
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following patchset changes the PM core so that driver callbacks are executed automatically when subsystem ones are not present and uses the new PM core's behavior to simplify the platform and AMBA bus types (there probably are many more bus types that may be simplified this way, but those two were the easiest targets for me).
The reasons why to do this are outlined in the changelog of the second patch.
Comments welcome!
Looks sane to me, nice work.
greg k-h
Quoted 9 lines · Greg KH
Quoted 8 lines · Rafael J. Wysocki
Hi,
The following patchset changes the PM core so that driver callbacks are executed automatically when subsystem ones are not present and uses the new PM core's behavior to simplify the platform and AMBA bus types (there probably are many more bus types that may be simplified this way, but those two were the easiest targets for me).
Quoted 5 lines
Quoted 3 lines
The reasons why to do this are outlined in the changelog of the second patch.
Comments welcome!
Looks sane to me, nice work.
Thanks!
Rafael
cover PM: Make the PM core execute driver callbacks if subsystem ones are not present
In reply to Rafael J. WysockiHi,
I have one more patch for this series and a couple of fixes.
Quoted 8 lines · Rafael J. Wysocki
The following patchset changes the PM core so that driver callbacks are executed automatically when subsystem ones are not present and uses the new PM core's behavior to simplify the platform and AMBA bus types (there probably are many more bus types that may be simplified this way, but those two were the easiest targets for me).
The reasons why to do this are outlined in the changelog of the second patch.
[1/5] - Make pm_op and pm_noirq_op return callbacks
[2/5] - Make PM core call driver callbacks directly if subsystem ones are not present [3/5] - Remove unnecessary bus type PM callback from platform bus type [4/5] - Remove unnecessary bus type PM callback from AMBA bus type [5/5] - Drop generic_subsys_pm_ops
If there are no objections, I'd like to take these patches for 3.3.
Thanks,
Rafael
PATCH 1/5 PM / Sleep: Make pm_op() and pm_noirq_op() return callback pointers
From: Rafael J. Wysocki <[email protected]>
Make the pm_op() and pm_noirq_op() functions return pointers to appropriate callbacks instead of executing those callbacks and returning their results.
This change is required for a subsequent modification that will execute the corresponding driver callback if the subsystem callback returned by either pm_op(), or pm_noirq_op() is NULL.
--- drivers/base/power/main.c | 197 ++++++++++++++++++++++------------------------ 1 file changed, 95 insertions(+), 102 deletions(-)
drivers/base/power/main.c +95 -102
@@ -32,6 +32,8 @@#include "../base.h" #include "power.h" +typedef int (*pm_callback_t )(struct device *); +/* * The entries in the dpm_list list are in a depth first order, simply * because children are guaranteed to be discovered after parents, and
@@ -211,113 +213,70 @@ static void dpm_wait_for_children(structdevice_for_each_child (dev, &async, dpm_wait_fn); } -static int dpm_run_callback (struct device *dev,int (*cb)(struct device *)) -{ -ktime_t calltime; -int error; - -if (!cb) -return 0 ; - - calltime =initcall_debug_start (dev); - - error =cb (dev); -suspend_report_result (cb, error); - -initcall_debug_report (dev, calltime, error); - -return error; -} -/** -* pm_op - Execute the PM operation appropriate for given PM event. -* @dev: Device to handle. +* pm_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. */ -static int pm_op (struct device *dev, -const struct dev_pm_ops *ops, -pm_message_t state) +static pm_callback_t pm_op (const struct dev_pm_ops *ops,pm_message_t state) { -int error =0 ; -switch (state.event) {#ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND : - error =dpm_run_callback (dev, ops->suspend); -break ; +return ops->suspend;case PM_EVENT_RESUME : - error =dpm_run_callback (dev, ops->resume); -break ; +return ops->resume;#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE :case PM_EVENT_QUIESCE : - error =dpm_run_callback (dev, ops->freeze); -break ; +return ops->freeze;case PM_EVENT_HIBERNATE : - error =dpm_run_callback (dev, ops->poweroff); -break ; +return ops->poweroff;case PM_EVENT_THAW :case PM_EVENT_RECOVER : - error =dpm_run_callback (dev, ops->thaw); +return ops->thaw;break ;case PM_EVENT_RESTORE : - error =dpm_run_callback (dev, ops->restore); -break ; +return ops->restore;#endif /* CONFIG_HIBERNATE_CALLBACKS */ -default : - error = -EINVAL ; } -return error; +return NULL ; }/** -* pm_noirq_op - Execute the PM operation appropriate for given PM event. -* @dev: Device to handle. +* 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. * * The driver of @dev will not receive interrupts while this function is being * executed. */ -static int pm_noirq_op (struct device *dev, -const struct dev_pm_ops *ops, -pm_message_t state) +static pm_callback_t pm_noirq_op (const struct dev_pm_ops *ops,pm_message_t state) { -int error =0 ; -switch (state.event) {#ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND : - error =dpm_run_callback (dev, ops->suspend_noirq); -break ; +return ops->suspend_noirq;case PM_EVENT_RESUME : - error =dpm_run_callback (dev, ops->resume_noirq); -break ; +return ops->resume_noirq;#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE :case PM_EVENT_QUIESCE : - error =dpm_run_callback (dev, ops->freeze_noirq); -break ; +return ops->freeze_noirq;case PM_EVENT_HIBERNATE : - error =dpm_run_callback (dev, ops->poweroff_noirq); -break ; +return ops->poweroff_noirq;case PM_EVENT_THAW :case PM_EVENT_RECOVER : - error =dpm_run_callback (dev, ops->thaw_noirq); -break ; +return ops->thaw_noirq;case PM_EVENT_RESTORE : - error =dpm_run_callback (dev, ops->restore_noirq); -break ; +return ops->restore_noirq;#endif /* CONFIG_HIBERNATE_CALLBACKS */ -default : - error = -EINVAL ; } -return error; +return NULL ; }static char *pm_verb (int event)
@@ -375,6 +334,26 @@ static void dpm_show_time(ktime_t startt usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); } +static int dpm_run_callback (pm_callback_t cb,struct device *dev, +pm_message_t state,char *info) +{ +ktime_t calltime; +int error; + +if (!cb) +return 0 ; + + calltime =initcall_debug_start (dev); + +pm_dev_dbg (dev, state, info); + error =cb (dev); +suspend_report_result (cb, error); + +initcall_debug_report (dev, calltime, error); + +return error; +} +/*------------------------- Resume routines -------------------------*/ /**
@@ -387,25 +366,29 @@ static void dpm_show_time(ktime_t startt*/ static int device_resume_noirq (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) { -pm_dev_dbg (dev, state,"EARLY power domain " ); - error =pm_noirq_op (dev, &dev->pm_domain->ops, state); + info ="EARLY power domain " ; + callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"EARLY type " ); - error =pm_noirq_op (dev, dev->type->pm, state); + info ="EARLY type " ; + callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { -pm_dev_dbg (dev, state,"EARLY class " ); - error =pm_noirq_op (dev, dev->class->pm, state); + info ="EARLY class " ; + callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { -pm_dev_dbg (dev, state,"EARLY " ); - error =pm_noirq_op (dev, dev->bus->pm, state); + info ="EARLY " ; + callback =pm_noirq_op (dev->bus->pm, state); } + error =dpm_run_callback (callback, dev, state, info); +TRACE_RESUME (error);return error; }
@@ -455,6 +438,8 @@ EXPORT_SYMBOL_GPL(dpm_resume_noirq);*/ static int device_resume (struct device *dev,pm_message_t state,bool async) { +pm_callback_t callback =NULL ; +char *info =NULL ;int error =0 ;bool put = false;
@@ -477,40 +462,41 @@ static int device_resume(struct device * put = true;if (dev->pm_domain) { -pm_dev_dbg (dev, state,"power domain " ); - error =pm_op (dev, &dev->pm_domain->ops, state); + info ="power domain " ; + callback =pm_op (&dev->pm_domain->ops, state); goto End; }if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"type " ); - error =pm_op (dev, dev->type->pm, state); + info ="type " ; + callback =pm_op (dev->type->pm, state); goto End; }if (dev->class) {if (dev->class->pm) { -pm_dev_dbg (dev, state,"class " ); - error =pm_op (dev, dev->class->pm, state); + info ="class " ; + callback =pm_op (dev->class->pm, state); goto End; }else if (dev->class->resume) { -pm_dev_dbg (dev, state,"legacy class " ); - error =dpm_run_callback (dev, dev->class->resume); + info ="legacy class " ; + callback = dev->class->resume; goto End; } }if (dev->bus) {if (dev->bus->pm) { -pm_dev_dbg (dev, state,"" ); - error =pm_op (dev, dev->bus->pm, state); + info ="" ; + callback =pm_op (dev->bus->pm, state); }else if (dev->bus->resume) { -pm_dev_dbg (dev, state,"legacy " ); - error =dpm_run_callback (dev, dev->bus->resume); + info ="legacy " ; + callback = dev->bus->resume; } } End: + error =dpm_run_callback (callback, dev, state, info); dev->power.is_suspended = false; Unlock:
@@ -705,23 +691,24 @@ static pm_message_t resume_event(pm_mess*/ static int device_suspend_noirq (struct device *dev,pm_message_t state) { -int error =0 ; +pm_callback_t callback =NULL ; +char *info =NULL ;if (dev->pm_domain) { -pm_dev_dbg (dev, state,"LATE power domain " ); - error =pm_noirq_op (dev, &dev->pm_domain->ops, state); + info ="LATE power domain " ; + callback =pm_noirq_op (&dev->pm_domain->ops, state); }else if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"LATE type " ); - error =pm_noirq_op (dev, dev->type->pm, state); + info ="LATE type " ; + callback =pm_noirq_op (dev->type->pm, state); }else if (dev->class && dev->class->pm) { -pm_dev_dbg (dev, state,"LATE class " ); - error =pm_noirq_op (dev, dev->class->pm, state); + info ="LATE class " ; + callback =pm_noirq_op (dev->class->pm, state); }else if (dev->bus && dev->bus->pm) { -pm_dev_dbg (dev, state,"LATE " ); - error =pm_noirq_op (dev, dev->bus->pm, state); + info ="LATE " ; + callback =pm_noirq_op (dev->bus->pm, state); } -return error; +return dpm_run_callback (callback, dev, state, info); }/**
@@ -798,6 +785,8 @@ static int legacy_suspend(struct device*/ static int __device_suspend (struct device *dev,pm_message_t state,bool async) { +pm_callback_t callback =NULL ; +char *info =NULL ;int error =0 ;dpm_wait_for_children (dev, async);
@@ -818,22 +807,22 @@ static int __device_suspend(struct devicdevice_lock (dev);if (dev->pm_domain) { -pm_dev_dbg (dev, state,"power domain " ); - error =pm_op (dev, &dev->pm_domain->ops, state); - goto End; + info ="power domain " ; + callback =pm_op (&dev->pm_domain->ops, state); + goto Run; }if (dev->type && dev->type->pm) { -pm_dev_dbg (dev, state,"type " ); - error =pm_op (dev, dev->type->pm, state); - goto End; + info ="type " ; + callback =pm_op (dev->type->pm, state); + goto Run; }if (dev->class) {if (dev->class->pm) { -pm_dev_dbg (dev, state,"class " ); - error =pm_op (dev, dev->class->pm, state); - goto End; + info ="class " ; + callback =pm_op (dev->class->pm, state); + goto Run; }else if (dev->class->suspend) {pm_dev_dbg (dev, state,"legacy class " ); error =legacy_suspend (dev, state, dev->class->suspend);
@@ -843,14 +832,18 @@ static int __device_suspend(struct devicif (dev->bus) {if (dev->bus->pm) { -pm_dev_dbg (dev, state,"" ); - error =pm_op (dev, dev->bus->pm, state); + info ="" ; + callback =pm_op (dev->bus->pm, state); }else if (dev->bus->suspend) {pm_dev_dbg (dev, state,"legacy " ); error =legacy_suspend (dev, state, dev->bus->suspend); + goto End; } } + Run: + error =dpm_run_callback (callback, dev, state, info); + End:if (!error) { dev->power.is_suspended = true;
PATCH 2/5 PM: Run the driver callback directly if the subsystem one is not there
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make the PM core execute driver PM callbacks directly if the corresponding subsystem callbacks are not present.
There are three reasons for doing that. First, it reflects the behavior of drivers/base/dd.c:really_probe() that runs the driver's .probe() callback directly if the bus type's one is not defined, so this change will remove one arbitrary difference between the PM core and the remaining parts of the driver core. Second, it will allow some subsystems, whose PM callbacks don't do anything except for executing driver callbacks, to be simplified quite a bit by removing those "forward-only" callbacks. Finally, it will allow us to remove one level of indirection in the system suspend and resume code paths where it is not necessary, which is going to lead to less debug noise with initcall_debug passed in the kernel command line (messages won't be printed for driverless devices whose subsystems don't provide PM callbacks among other things).
--- Documentation/power/devices.txt | 39 ++++++----- Documentation/power/runtime_pm.txt | 128 +++++++++++++++++++------------------ drivers/base/power/main.c | 109 ++++++++++++++++++++----------- drivers/base/power/runtime.c | 9 ++ 4 files changed, 170 insertions(+), 115 deletions(-)
drivers/base/power/runtime.c +9 -0
@@ -250,6 +250,9 @@ static int rpm_idle(struct device *dev,else callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_idle; +if (callback)__rpm_callback (callback, dev);
@@ -485,6 +488,9 @@ static int rpm_suspend(struct device *deelse callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_suspend; + retval =rpm_callback (callback, dev);if (retval) goto fail;
@@ -713,6 +719,9 @@ static int rpm_resume(struct device *develse callback =NULL ; +if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_resume; + retval =rpm_callback (callback, dev);if (retval) {__update_runtime_status (dev,RPM_SUSPENDED );
Documentation/power/devices.txt +22 -17
@@ -126,7 +126,9 @@ The core methods to suspend and resume d pointed to by the ops member of struct dev_pm_domain, or by the pm member of struct bus_type, struct device_type and struct class. They are mostly of interest to the people writing infrastructure for platforms and buses, like PCI -or USB, or device type and device class drivers. +or USB, or device type and device class drivers. They also are relevant to the +writers of device drivers whose subsystems (PM domains, device types, device +classes and bus types) don't provide all power management methods. Bus drivers implement these methods as appropriate for the hardware and the drivers using it; PCI works differently from USB, and so on. Not many people
@@ -268,32 +270,35 @@ various phases always run after tasks ha unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have been disabled (except for those marked with the IRQF_NO_SUSPEND flag). -All phases use PM domain, bus, type, or class callbacks (that is, methods -defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, or dev->class->pm). -These callbacks are regarded by the PM core as mutually exclusive. Moreover, -PM domain callbacks always take precedence over bus, type and class callbacks, -while type callbacks take precedence over bus and class callbacks, and class -callbacks take precedence over bus callbacks. To be precise, the following -rules are used to determine which callback to execute in the given phase: - - 1. If dev->pm_domain is present, the PM core will attempt to execute the - callback included in dev->pm_domain->ops. If that callback is not - present, no action will be carried out for the given device. +All phases use PM domain, bus, type, class or driver callbacks (that is, methods +defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, dev->class->pm or +dev->driver->pm). These callbacks are regarded by the PM core as mutually +exclusive. Moreover, PM domain callbacks always take precedence over all of the +other callbacks and, for example, type callbacks take precedence over bus, class +and driver callbacks. To be precise, the following rules are used to determine +which callback to execute in the given phase: + + 1. If dev->pm_domain is present, the PM core will choose the callback + included in dev->pm_domain->ops for execution 2. Otherwise, if both dev->type and dev->type->pm are present, the callback - included in dev->type->pm will be executed. + included in dev->type->pm will be chosen for execution. 3. Otherwise, if both dev->class and dev->class->pm are present, the - callback included in dev->class->pm will be executed. + callback included in dev->class->pm will be chosen for execution. 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback - included in dev->bus->pm will be executed. + included in dev->bus->pm will be chosen for execution. This allows PM domains and device types to override callbacks provided by bus types or device classes if necessary. -These callbacks may in turn invoke device- or driver-specific methods stored in -dev->driver->pm, but they don't have to. +The PM domain, type, class and bus callbacks may in turn invoke device- or +driver-specific methods stored in dev->driver->pm, but they don't have to do +that. + +If the subsystem callback chosen for execution is not present, the PM core will +execute the corresponding method from dev->driver->pm instead if there is one. Entering System Suspend
Documentation/power/runtime_pm.txt +67 -61
159 lines not on this page · raw message
drivers/base/power/main.c +72 -37
197 lines not on this page · raw message
PATCH 3/5 PM / Sleep: Remove forward-only callbacks from platform bus type
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The forward-only PM callbacks provided by the platform bus type are not necessary any more, because the PM core executes driver callbacks when the corresponding subsystem callbacks are not present, so drop them.
--- drivers/base/platform.c | 115 ---------------------------------------- include/linux/platform_device.h | 30 ---------- 2 files changed, 1 insertion(+), 144 deletions(-)
drivers/base/platform.c +0 -115
@@ -700,25 +700,6 @@ static int platform_legacy_resume(struct return ret; } -int platform_pm_prepare (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (drv && drv->pm && drv->pm->prepare) - ret = drv->pm->prepare (dev); - -return ret; -} - -void platform_pm_complete (struct device *dev) -{ -struct device_driver *drv = dev->driver; - -if (drv && drv->pm && drv->pm->complete) - drv->pm->complete (dev); -} -#endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_SUSPEND
@@ -741,22 +722,6 @@ int platform_pm_suspend(struct device *dreturn ret; } -int platform_pm_suspend_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->suspend_noirq) - ret = drv->pm->suspend_noirq (dev); - } - -return ret; -} -int platform_pm_resume (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -775,22 +740,6 @@ int platform_pm_resume(struct device *de return ret; } -int platform_pm_resume_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->resume_noirq) - ret = drv->pm->resume_noirq (dev); - } - -return ret; -} -#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS
@@ -813,22 +762,6 @@ int platform_pm_freeze(struct device *dereturn ret; } -int platform_pm_freeze_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->freeze_noirq) - ret = drv->pm->freeze_noirq (dev); - } - -return ret; -} -int platform_pm_thaw (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -847,22 +780,6 @@ int platform_pm_thaw(struct device *dev)return ret; } -int platform_pm_thaw_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->thaw_noirq) - ret = drv->pm->thaw_noirq (dev); - } - -return ret; -} -int platform_pm_poweroff (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -881,22 +798,6 @@ int platform_pm_poweroff(struct device *return ret; } -int platform_pm_poweroff_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->poweroff_noirq) - ret = drv->pm->poweroff_noirq (dev); - } - -return ret; -} -int platform_pm_restore (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -913,22 +814,6 @@ int platform_pm_restore(struct device *d }return ret; -} - -int platform_pm_restore_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->restore_noirq) - ret = drv->pm->restore_noirq (dev); - } - -return ret; }#endif /* CONFIG_HIBERNATE_CALLBACKS */
include/linux/platform_device.h +1 -29
@@ -264,62 +264,34 @@ static inline char *early_platform_drive }#endif /* MODULE */ -#ifdef CONFIG_PM_SLEEP -extern int platform_pm_prepare (struct device *dev); -extern void platform_pm_complete (struct device *dev); -#else -#define platform_pm_prepare NULL -#define platform_pm_complete NULL -#endif -#ifdef CONFIG_SUSPEND extern int platform_pm_suspend (struct device *dev); -extern int platform_pm_suspend_noirq (struct device *dev);extern int platform_pm_resume (struct device *dev); -extern int platform_pm_resume_noirq (struct device *dev);#else #define platform_pm_suspend NULL#define platform_pm_resume NULL -#define platform_pm_suspend_noirq NULL -#define platform_pm_resume_noirq NULL#endif #ifdef CONFIG_HIBERNATE_CALLBACKS extern int platform_pm_freeze (struct device *dev); -extern int platform_pm_freeze_noirq (struct device *dev);extern int platform_pm_thaw (struct device *dev); -extern int platform_pm_thaw_noirq (struct device *dev);extern int platform_pm_poweroff (struct device *dev); -extern int platform_pm_poweroff_noirq (struct device *dev);extern int platform_pm_restore (struct device *dev); -extern int platform_pm_restore_noirq (struct device *dev);#else #define platform_pm_freeze NULL#define platform_pm_thaw NULL#define platform_pm_poweroff NULL#define platform_pm_restore NULL -#define platform_pm_freeze_noirq NULL -#define platform_pm_thaw_noirq NULL -#define platform_pm_poweroff_noirq NULL -#define platform_pm_restore_noirq NULL#endif #ifdef CONFIG_PM_SLEEP #define USE_PLATFORM_PM_SLEEP_OPS \ - .prepare = platform_pm_prepare, \ - .complete = platform_pm_complete, \ .suspend = platform_pm_suspend, \ .resume = platform_pm_resume, \ .freeze = platform_pm_freeze, \ .thaw = platform_pm_thaw, \ .poweroff = platform_pm_poweroff, \ - .restore = platform_pm_restore, \ - .suspend_noirq = platform_pm_suspend_noirq, \ - .resume_noirq = platform_pm_resume_noirq, \ - .freeze_noirq = platform_pm_freeze_noirq, \ - .thaw_noirq = platform_pm_thaw_noirq, \ - .poweroff_noirq = platform_pm_poweroff_noirq, \ - .restore_noirq = platform_pm_restore_noirq, + .restore = platform_pm_restore,#else #define USE_PLATFORM_PM_SLEEP_OPS #endif
PATCH 4/5 PM / Sleep: Remove forward-only callbacks from AMBA bus type
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The forward-only PM callbacks provided by the AMBA bus type are not necessary any more, because the PM core executes driver callbacks when the corresponding subsystem callbacks are not present, so drop them.
--- drivers/amba/bus.c | 136 ----------------------------------------------------- 1 file changed, 1 insertion(+), 135 deletions(-)
drivers/amba/bus.c +1 -135
@@ -109,31 +109,7 @@ static int amba_legacy_resume(struct dev return ret; } -static int amba_pm_prepare (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (drv && drv->pm && drv->pm->prepare) - ret = drv->pm->prepare (dev); - -return ret; -} - -static void amba_pm_complete (struct device *dev) -{ -struct device_driver *drv = dev->driver; - -if (drv && drv->pm && drv->pm->complete) - drv->pm->complete (dev); -} - -#else /* !CONFIG_PM_SLEEP */ - -#define amba_pm_prepare NULL -#define amba_pm_complete NULL - -#endif /* !CONFIG_PM_SLEEP */ +#endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_SUSPEND
@@ -155,22 +131,6 @@ static int amba_pm_suspend(struct devicereturn ret; } -static int amba_pm_suspend_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->suspend_noirq) - ret = drv->pm->suspend_noirq (dev); - } - -return ret; -} -static int amba_pm_resume (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -189,28 +149,10 @@ static int amba_pm_resume(struct device return ret; } -static int amba_pm_resume_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->resume_noirq) - ret = drv->pm->resume_noirq (dev); - } - -return ret; -} -#else /* !CONFIG_SUSPEND */ #define amba_pm_suspend NULL#define amba_pm_resume NULL -#define amba_pm_suspend_noirq NULL -#define amba_pm_resume_noirq NULL#endif /* !CONFIG_SUSPEND */
@@ -234,22 +176,6 @@ static int amba_pm_freeze(struct devicereturn ret; } -static int amba_pm_freeze_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->freeze_noirq) - ret = drv->pm->freeze_noirq (dev); - } - -return ret; -} -static int amba_pm_thaw (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -268,22 +194,6 @@ static int amba_pm_thaw(struct device *dreturn ret; } -static int amba_pm_thaw_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->thaw_noirq) - ret = drv->pm->thaw_noirq (dev); - } - -return ret; -} -static int amba_pm_poweroff (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -302,22 +212,6 @@ static int amba_pm_poweroff(struct devicreturn ret; } -static int amba_pm_poweroff_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->poweroff_noirq) - ret = drv->pm->poweroff_noirq (dev); - } - -return ret; -} -static int amba_pm_restore (struct device *dev) {struct device_driver *drv = dev->driver;
@@ -336,32 +230,12 @@ static int amba_pm_restore(struct device return ret; } -static int amba_pm_restore_noirq (struct device *dev) -{ -struct device_driver *drv = dev->driver; -int ret =0 ; - -if (!drv) -return 0 ; - -if (drv->pm) { -if (drv->pm->restore_noirq) - ret = drv->pm->restore_noirq (dev); - } - -return ret; -} -#else /* !CONFIG_HIBERNATE_CALLBACKS */ #define amba_pm_freeze NULL#define amba_pm_thaw NULL#define amba_pm_poweroff NULL#define amba_pm_restore NULL -#define amba_pm_freeze_noirq NULL -#define amba_pm_thaw_noirq NULL -#define amba_pm_poweroff_noirq NULL -#define amba_pm_restore_noirq NULL#endif /* !CONFIG_HIBERNATE_CALLBACKS */
@@ -402,20 +276,12 @@ static int amba_pm_runtime_resume(struct #ifdef CONFIG_PM static const struct dev_pm_ops amba_pm = { - .prepare = amba_pm_prepare, - .complete = amba_pm_complete, .suspend = amba_pm_suspend, .resume = amba_pm_resume, .freeze = amba_pm_freeze, .thaw = amba_pm_thaw, .poweroff = amba_pm_poweroff, .restore = amba_pm_restore, - .suspend_noirq = amba_pm_suspend_noirq, - .resume_noirq = amba_pm_resume_noirq, - .freeze_noirq = amba_pm_freeze_noirq, - .thaw_noirq = amba_pm_thaw_noirq, - .poweroff_noirq = amba_pm_poweroff_noirq, - .restore_noirq = amba_pm_restore_noirq, SET_RUNTIME_PM_OPS( amba_pm_runtime_suspend, amba_pm_runtime_resume,
PATCH 5/5 PM: Drop generic_subsys_pm_ops
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since the PM core is now going to execute driver callbacks directly if the corresponding subsystem callbacks are not present, forward-only subsystem callbacks (i.e. such that only execute the corresponding driver callbacks) are not necessary any more. Thus it is possible to remove generic_subsys_pm_ops, because the only callback in there that is not forward-only, .runtime_idle, is not really used by the only user of generic_subsys_pm_ops, which is vio_bus_type.
However, the generic callback routines themselves cannot be removed from generic_ops.c, because they are used individually by a number of subsystems.
--- arch/powerpc/kernel/vio.c | 1 - drivers/base/power/generic_ops.c | 25 ------------------------- include/linux/pm.h | 13 ------------- 3 files changed, 39 deletions(-)
drivers/base/power/generic_ops.c +0 -25
@@ -302,28 +302,3 @@ void pm_generic_complete(struct device * pm_runtime_idle(dev); }#endif /* CONFIG_PM_SLEEP */ - -struct dev_pm_ops generic_subsys_pm_ops = { -#ifdef CONFIG_PM_SLEEP - .prepare = pm_generic_prepare, - .suspend = pm_generic_suspend, - .suspend_noirq = pm_generic_suspend_noirq, - .resume = pm_generic_resume, - .resume_noirq = pm_generic_resume_noirq, - .freeze = pm_generic_freeze, - .freeze_noirq = pm_generic_freeze_noirq, - .thaw = pm_generic_thaw, - .thaw_noirq = pm_generic_thaw_noirq, - .poweroff = pm_generic_poweroff, - .poweroff_noirq = pm_generic_poweroff_noirq, - .restore = pm_generic_restore, - .restore_noirq = pm_generic_restore_noirq, - .complete = pm_generic_complete, -#endif -#ifdef CONFIG_PM_RUNTIME - .runtime_suspend = pm_generic_runtime_suspend, - .runtime_resume = pm_generic_runtime_resume, - .runtime_idle = pm_generic_runtime_idle, -#endif -}; -EXPORT_SYMBOL_GPL (generic_subsys_pm_ops);
include/linux/pm.h +0 -13
@@ -300,19 +300,6 @@ const struct dev_pm_ops name = { \ SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ } -/* -* Use this for subsystems (bus types, device types, device classes) that don't -* need any special suspend/resume handling in addition to invoking the PM -* callbacks provided by device drivers supporting both the system sleep PM and -* runtime PM, make the pm member point to generic_subsys_pm_ops. -*/ -#ifdef CONFIG_PM -extern struct dev_pm_ops generic_subsys_pm_ops; -#define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops) -#else -#define GENERIC_SUBSYS_PM_OPS NULL -#endif -/** * PM_EVENT_ messages *
arch/powerpc/kernel/vio.c +0 -1
@@ -1406,7 +1406,6 @@ static struct bus_type vio_bus_type = { .match = vio_bus_match, .probe = vio_bus_probe, .remove = vio_bus_remove, - .pm = GENERIC_SUBSYS_PM_OPS, };/**
Re: [Update][PATCH 5/5] PM: Drop generic_subsys_pm_ops
Quoted 11 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since the PM core is now going to execute driver callbacks directly if the corresponding subsystem callbacks are not present, forward-only subsystem callbacks (i.e. such that only execute the corresponding driver callbacks) are not necessary any more. Thus it is possible to remove
generic_subsys_pm_ops, because the only callback in there that is not forward-only, .runtime_idle, is not really used by the only user ofgeneric_subsys_pm_ops, which isvio_bus_type.
Quoted 5 lines
However, the generic callback routines themselves cannot be removed from
generic_ops.c, because they are used individually by a number of subsystems.Signed-off-by Rafael J. Wysocki <[email protected]>
Well, Ben should have a look at this one too. Now CCed.
Thanks,
Rafael
Quoted 83 lines
--- arch/powerpc/kernel/vio.c | 1 - drivers/base/power/generic_ops.c | 25 ------------------------- include/linux/pm.h | 13 ------------- 3 files changed, 39 deletions(-)Index:
linux/drivers/base/power/generic_ops.c
===================================================================drivers/base/power/generic_ops.c +0
-25@@ -302,28 +302,3 @@ void pm_generic_complete(struct device * pm_runtime_idle(dev); }#endif /* CONFIG_PM_SLEEP */ - -struct dev_pm_ops generic_subsys_pm_ops = { -#ifdef CONFIG_PM_SLEEP - .prepare = pm_generic_prepare, - .suspend = pm_generic_suspend, - .suspend_noirq = pm_generic_suspend_noirq, - .resume = pm_generic_resume, - .resume_noirq = pm_generic_resume_noirq, - .freeze = pm_generic_freeze, - .freeze_noirq = pm_generic_freeze_noirq, - .thaw = pm_generic_thaw, - .thaw_noirq = pm_generic_thaw_noirq, - .poweroff = pm_generic_poweroff, - .poweroff_noirq = pm_generic_poweroff_noirq, - .restore = pm_generic_restore, - .restore_noirq = pm_generic_restore_noirq, - .complete = pm_generic_complete, -#endif -#ifdef CONFIG_PM_RUNTIME - .runtime_suspend = pm_generic_runtime_suspend, - .runtime_resume = pm_generic_runtime_resume, - .runtime_idle = pm_generic_runtime_idle, -#endif -}; -EXPORT_SYMBOL_GPL (generic_subsys_pm_ops);Index:
linux/include/linux/pm.h
===================================================================include/linux/pm.h +0
-13@@ -300,19 +300,6 @@ const struct dev_pm_ops name = { \ SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ } -/* -* Use this for subsystems (bus types, device types, device classes) that don't -* need any special suspend/resume handling in addition to invoking the PM -* callbacks provided by device drivers supporting both the system sleep PM and -* runtime PM, make the pm member point to generic_subsys_pm_ops. -*/ -#ifdef CONFIG_PM -extern struct dev_pm_ops generic_subsys_pm_ops; -#define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops) -#else -#define GENERIC_SUBSYS_PM_OPS NULL -#endif -/** * PM_EVENT_ messages * Index:
linux/arch/powerpc/kernel/vio.c
===================================================================arch/powerpc/kernel/vio.c +0
-2@@ -1406,7 +1406,6 @@ static struct bus_type vio_bus_type = { .match = vio_bus_match, .probe = vio_bus_probe, .remove = vio_bus_remove, - .pm = GENERIC_SUBSYS_PM_OPS, };/** -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 14 lines · Rafael J. Wysocki
Hi,
I have one more patch for this series and a couple of fixes.
Quoted 8 lines · Rafael J. Wysocki
The following patchset changes the PM core so that driver callbacks are executed automatically when subsystem ones are not present and uses the new PM core's behavior to simplify the platform and AMBA bus types (there probably are many more bus types that may be simplified this way, but those two were the easiest targets for me).
The reasons why to do this are outlined in the changelog of the second patch.
Quoted 7 lines
[1/5] - Make
pm_opandpm_noirq_opreturn callbacks
[2/5] - Make PM core call driver callbacks directly if subsystem ones are not present [3/5] - Remove unnecessary bus type PM callback from platform bus type [4/5] - Remove unnecessary bus type PM callback from AMBA bus type [5/5] - Dropgeneric_subsys_pm_opsIf there are no objections, I'd like to take these patches for 3.3.
No objection from me, thanks for doing this.
greg k-h