PM / Runtime: Fetch runtime PM callbacks using a macro
Subsystems (4)
PATCH v3 1/8 PM / Runtime: Fetch runtime PM callbacks using a macro
While fetching the proper runtime PM callback, we walk the hierarchy of device's power domains, subsystems and drivers.
This is common for rpm_suspend(), rpm_idle() and rpm_resume(). Let's clean up the code by using a macro that handles this.
---
Changes in v3:
Added functions to return the callbacks, which will be the only users of the macro. According to comments from Alan Stern and Kevin Hilman.
Changes in v2:
Updated the macro to return a callback instead. Suggested by Josh Cartwright.
--- drivers/base/power/runtime.c | 78 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-)
drivers/base/power/runtime.c +39 -39
@@ -13,6 +13,42 @@#include <trace/events/rpm.h> #include "power.h" +#define RPM_GET_CALLBACK (dev, cb) \ +({ \ + int (*__rpm_cb)(struct device *__d); \ + \ + if (dev->pm_domain) \ + __rpm_cb = dev->pm_domain->ops.cb; \ + else if (dev->type && dev->type->pm) \ + __rpm_cb = dev->type->pm->cb; \ + else if (dev->class && dev->class->pm) \ + __rpm_cb = dev->class->pm->cb; \ + else if (dev->bus && dev->bus->pm) \ + __rpm_cb = dev->bus->pm->cb; \ + else \ + __rpm_cb = NULL; \ + \ + if (!__rpm_cb && dev->driver && dev->driver->pm) \ + __rpm_cb = dev->driver->pm->cb; \ + \ + __rpm_cb; \ +}) + +static int (*rpm_get_suspend_cb (struct device *dev))(struct device *) +{ +return RPM_GET_CALLBACK (dev, runtime_suspend); +} + +static int (*rpm_get_resume_cb (struct device *dev))(struct device *) +{ +return RPM_GET_CALLBACK (dev, runtime_resume); +} + +static int (*rpm_get_idle_cb (struct device *dev))(struct device *) +{ +return RPM_GET_CALLBACK (dev, runtime_idle); +} +static int rpm_resume (struct device *dev,int rpmflags);static int rpm_suspend (struct device *dev,int rpmflags);
@@ -310,19 +346,7 @@ static int rpm_idle(struct device *dev, int rpmflags) dev->power.idle_notification = true; -if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_idle; -else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_idle; -else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_idle; -else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_idle; -else - callback =NULL ; - -if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_idle; + callback =rpm_get_idle_cb (dev);if (callback) retval =__rpm_callback (callback, dev);
@@ -492,19 +516,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)__update_runtime_status (dev,RPM_SUSPENDING ); -if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_suspend; -else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_suspend; -else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_suspend; -else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_suspend; -else - callback =NULL ; - -if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_suspend; + callback =rpm_get_suspend_cb (dev); retval =rpm_callback (callback, dev);if (retval)
@@ -724,19 +736,7 @@ static int rpm_resume(struct device *dev, int rpmflags)__update_runtime_status (dev,RPM_RESUMING ); -if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_resume; -else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_resume; -else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_resume; -else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_resume; -else - callback =NULL ; - -if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_resume; + callback =rpm_get_resume_cb (dev); retval =rpm_callback (callback, dev);if (retval) {
Signature · 1 line
1.7.9.5
PATCH v3 1/8 PM / Runtime: Fetch runtime PM callbacks using a macro
Quoted 6 lines · Ulf Hansson
While fetching the proper runtime PM callback, we walk the hierarchy of device's power domains, subsystems and drivers.
This is common for
rpm_suspend(),rpm_idle()andrpm_resume(). Let's clean up the code by using a macro that handles this.
Quoted 9 lines
Cc Kevin Hilman <[email protected]>Cc Alan Stern <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Mark Brown <[email protected]>Cc Russell King <[email protected]>Cc Linus Walleij <[email protected]>Cc Wolfram Sang <[email protected]>Cc Alessandro Rubini <[email protected]>Signed-off-by Ulf Hansson <[email protected]>
Can you please repost the entire series? It would be a bit easier to handle this way.
Quoted 125 lines
---
Changes in v3:
Added functions to return the callbacks, which will be the only users of the macro. According to comments from Alan Stern and Kevin Hilman.Changes in v2:
Updated the macro to return a callback instead. Suggested by Josh Cartwright.--- drivers/base/power/runtime.c | 78 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-)drivers/base/power/runtime.c +39
-39@@ -13,6 +13,42 @@#include <trace/events/rpm.h> #include "power.h" +#define RPM_GET_CALLBACK (dev, cb) \ +({ \ + int (*__rpm_cb)(struct device *__d); \ + \ + if (dev->pm_domain) \ + __rpm_cb = dev->pm_domain->ops.cb; \ + else if (dev->type && dev->type->pm) \ + __rpm_cb = dev->type->pm->cb; \ + else if (dev->class && dev->class->pm) \ + __rpm_cb = dev->class->pm->cb; \ + else if (dev->bus && dev->bus->pm) \ + __rpm_cb = dev->bus->pm->cb; \ + else \ + __rpm_cb = NULL; \ + \ + if (!__rpm_cb && dev->driver && dev->driver->pm) \ + __rpm_cb = dev->driver->pm->cb; \ + \ + __rpm_cb; \ +}) + +static int (*rpm_get_suspend_cb (struct device *dev))(struct device *) +{ +return RPM_GET_CALLBACK (dev, runtime_suspend); +} + +static int (*rpm_get_resume_cb (struct device *dev))(struct device *) +{ +return RPM_GET_CALLBACK (dev, runtime_resume); +} + +static int (*rpm_get_idle_cb (struct device *dev))(struct device *) +{ +return RPM_GET_CALLBACK (dev, runtime_idle); +} +static int rpm_resume (struct device *dev,int rpmflags);static int rpm_suspend (struct device *dev,int rpmflags);@@ -310,19 +346,7 @@ static int rpm_idle(struct device *dev, int rpmflags) dev->power.idle_notification = true; -if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_idle; -else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_idle; -else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_idle; -else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_idle; -else - callback =NULL ; - -if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_idle; + callback =rpm_get_idle_cb (dev);if (callback) retval =__rpm_callback (callback, dev);@@ -492,19 +516,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)__update_runtime_status (dev,RPM_SUSPENDING ); -if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_suspend; -else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_suspend; -else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_suspend; -else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_suspend; -else - callback =NULL ; - -if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_suspend; + callback =rpm_get_suspend_cb (dev); retval =rpm_callback (callback, dev);if (retval)@@ -724,19 +736,7 @@ static int rpm_resume(struct device *dev, int rpmflags)__update_runtime_status (dev,RPM_RESUMING ); -if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_resume; -else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_resume; -else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_resume; -else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_resume; -else - callback =NULL ; - -if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_resume; + callback =rpm_get_resume_cb (dev); retval =rpm_callback (callback, dev);if (retval) {
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.