From a938da0682c2487f6aafc9a7c3caa8d675acdb38 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Sun, 12 Aug 2012 00:17:02 +0200 Subject: PM / Sleep: Print name of wakeup source that aborts suspend A driver or app may repeatedly request a wakeup source while the system is attempting to enter suspend, which may indicate a bug or at least point out a highly active system component that is responsible for decreased battery life on a mobile device. Even when the incidence of suspend abort is not severe, identifying wakeup sources that frequently abort suspend can be a useful clue for power management analysis. In some cases the existing stats can point out the offender where there is an unexpectedly high activation count that stands out from the others, but in other cases the wakeup source frequently taken just after the rest of the system thinks its time to suspend might not stand out in the overall stats. It is also often useful to have information about what's been happening recently, rather than totals of all activity for the system boot. It's suggested to dump a line about which wakeup source aborted suspend to aid analysis of these situations. Signed-off-by: Todd Poynor Signed-off-by: Rafael J. Wysocki --- drivers/base/power/wakeup.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'drivers/base/power') diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index cbb463b..8a0a9ca 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -649,6 +649,31 @@ void pm_wakeup_event(struct device *dev, unsigned int msec) } EXPORT_SYMBOL_GPL(pm_wakeup_event); +static void print_active_wakeup_sources(void) +{ + struct wakeup_source *ws; + int active = 0; + struct wakeup_source *last_activity_ws = NULL; + + rcu_read_lock(); + list_for_each_entry_rcu(ws, &wakeup_sources, entry) { + if (ws->active) { + pr_info("active wakeup source: %s\n", ws->name); + active = 1; + } else if (!active && + (!last_activity_ws || + ktime_to_ns(ws->last_time) > + ktime_to_ns(last_activity_ws->last_time))) { + last_activity_ws = ws; + } + } + + if (!active && last_activity_ws) + pr_info("last active wakeup source: %s\n", + last_activity_ws->name); + rcu_read_unlock(); +} + /** * pm_wakeup_pending - Check if power transition in progress should be aborted. * @@ -671,6 +696,10 @@ bool pm_wakeup_pending(void) events_check_enabled = !ret; } spin_unlock_irqrestore(&events_lock, flags); + + if (ret) + print_active_wakeup_sources(); + return ret; } -- cgit v1.1 From 802d8b49a7705298b62ac35a59b867f1288caaf3 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:39:16 +0200 Subject: PM / Domains: Introduce simplified power on routine for system resume Introduce function pm_genpd_sync_poweron() for restoring domain power during resume from system suspend and hibernation. It can be much simpler than pm_genpd_poweron(), because it doesn't have to care about locking and it can skip many checks done by the latter. Modify pm_genpd_resume_noirq() and pm_genpd_restore_noirq() to use the new function. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index ba3487c..55c39f5 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -777,6 +777,32 @@ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) } /** + * pm_genpd_sync_poweron - Synchronously power on a PM domain and its masters. + * @genpd: PM domain to power on. + * + * This function is only called in "noirq" stage of system power transitions, so + * it need not acquire locks (all of the "noirq" callbacks are executed + * sequentially, so it is guaranteed that it will never run twice in parallel). + */ +static void pm_genpd_sync_poweron(struct generic_pm_domain *genpd) +{ + struct gpd_link *link; + + if (genpd->status != GPD_STATE_POWER_OFF) + return; + + list_for_each_entry(link, &genpd->slave_links, slave_node) { + pm_genpd_sync_poweron(link->master); + genpd_sd_counter_inc(link->master); + } + + if (genpd->power_on) + genpd->power_on(genpd); + + genpd->status = GPD_STATE_ACTIVE; +} + +/** * resume_needed - Check whether to resume a device before system suspend. * @dev: Device to check. * @genpd: PM domain the device belongs to. @@ -979,7 +1005,7 @@ static int pm_genpd_resume_noirq(struct device *dev) * guaranteed that this function will never run twice in parallel for * the same PM domain, so it is not necessary to use locking here. */ - pm_genpd_poweron(genpd); + pm_genpd_sync_poweron(genpd); genpd->suspended_count--; return genpd_start_dev(genpd, dev); @@ -1186,8 +1212,8 @@ static int pm_genpd_restore_noirq(struct device *dev) if (genpd->suspended_count++ == 0) { /* * The boot kernel might put the domain into arbitrary state, - * so make it appear as powered off to pm_genpd_poweron(), so - * that it tries to power it on in case it was really off. + * so make it appear as powered off to pm_genpd_sync_poweron(), + * so that it tries to power it on in case it was really off. */ genpd->status = GPD_STATE_POWER_OFF; if (genpd->suspend_power_off) { @@ -1205,7 +1231,7 @@ static int pm_genpd_restore_noirq(struct device *dev) if (genpd->suspend_power_off) return 0; - pm_genpd_poweron(genpd); + pm_genpd_sync_poweron(genpd); return dev_gpd_data(dev)->always_on ? 0 : genpd_start_dev(genpd, dev); } -- cgit v1.1 From 77f827de07432a74821cf0f831d699544b2d474f Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:39:57 +0200 Subject: PM / Domains: Add power off/on function for system core suspend stage Introduce function pm_genpd_syscore_switch() and two wrappers around it, pm_genpd_syscore_poweroff() and pm_genpd_syscore_poweron(), allowing the callers to let the generic PM domains framework know that the given device is not necessary any more and its PM domain can be turned off (the former) or that the given device will be required immediately, so its PM domain has to be turned on (the latter) during the system core (syscore) stage of system suspend (or hibernation) and resume. These functions will be used for handling devices registered as clock sources and clock event devices that belong to PM domains. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 57 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 55c39f5..515c8ec 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -697,6 +697,24 @@ static inline void genpd_power_off_work_fn(struct work_struct *work) {} #ifdef CONFIG_PM_SLEEP +/** + * pm_genpd_present - Check if the given PM domain has been initialized. + * @genpd: PM domain to check. + */ +static bool pm_genpd_present(struct generic_pm_domain *genpd) +{ + struct generic_pm_domain *gpd; + + if (IS_ERR_OR_NULL(genpd)) + return false; + + list_for_each_entry(gpd, &gpd_list, gpd_list_node) + if (gpd == genpd) + return true; + + return false; +} + static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd, struct device *dev) { @@ -750,9 +768,10 @@ static int genpd_thaw_dev(struct generic_pm_domain *genpd, struct device *dev) * Check if the given PM domain can be powered off (during system suspend or * hibernation) and do that if so. Also, in that case propagate to its masters. * - * This function is only called in "noirq" stages of system power transitions, - * so it need not acquire locks (all of the "noirq" callbacks are executed - * sequentially, so it is guaranteed that it will never run twice in parallel). + * This function is only called in "noirq" and "syscore" stages of system power + * transitions, so it need not acquire locks (all of the "noirq" callbacks are + * executed sequentially, so it is guaranteed that it will never run twice in + * parallel). */ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) { @@ -780,9 +799,10 @@ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) * pm_genpd_sync_poweron - Synchronously power on a PM domain and its masters. * @genpd: PM domain to power on. * - * This function is only called in "noirq" stage of system power transitions, so - * it need not acquire locks (all of the "noirq" callbacks are executed - * sequentially, so it is guaranteed that it will never run twice in parallel). + * This function is only called in "noirq" and "syscore" stages of system power + * transitions, so it need not acquire locks (all of the "noirq" callbacks are + * executed sequentially, so it is guaranteed that it will never run twice in + * parallel). */ static void pm_genpd_sync_poweron(struct generic_pm_domain *genpd) { @@ -1272,6 +1292,31 @@ static void pm_genpd_complete(struct device *dev) } } +/** + * pm_genpd_syscore_switch - Switch power during system core suspend or resume. + * @dev: Device that normally is marked as "always on" to switch power for. + * + * This routine may only be called during the system core (syscore) suspend or + * resume phase for devices whose "always on" flags are set. + */ +void pm_genpd_syscore_switch(struct device *dev, bool suspend) +{ + struct generic_pm_domain *genpd; + + genpd = dev_to_genpd(dev); + if (!pm_genpd_present(genpd)) + return; + + if (suspend) { + genpd->suspended_count++; + pm_genpd_sync_poweroff(genpd); + } else { + pm_genpd_sync_poweron(genpd); + genpd->suspended_count--; + } +} +EXPORT_SYMBOL_GPL(pm_genpd_syscore_switch); + #else #define pm_genpd_prepare NULL -- cgit v1.1 From e91c11b1a7f876c6f056d872eb210734150a1795 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:44:28 +0200 Subject: PM: Reorganize device PM initialization Make the device power management initialization more straightforward by moving the initialization of common (i.e. used by both runtime PM and system suspend) fields to a separate routine. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/main.c | 7 ++----- drivers/base/power/power.h | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 0113adc..7bd1fe4 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -57,20 +57,17 @@ static pm_message_t pm_transition; static int async_error; /** - * device_pm_init - Initialize the PM-related part of a device object. + * device_pm_sleep_init - Initialize system suspend-related device fields. * @dev: Device object being initialized. */ -void device_pm_init(struct device *dev) +void device_pm_sleep_init(struct device *dev) { dev->power.is_prepared = false; dev->power.is_suspended = false; init_completion(&dev->power.completion); complete_all(&dev->power.completion); dev->power.wakeup = NULL; - spin_lock_init(&dev->power.lock); - pm_runtime_init(dev); INIT_LIST_HEAD(&dev->power.entry); - dev->power.power_state = PMSG_INVALID; } /** diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index eeb4bff..8a0dcc7 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -1,5 +1,11 @@ #include +static inline void device_pm_init_common(struct device *dev) +{ + spin_lock_init(&dev->power.lock); + dev->power.power_state = PMSG_INVALID; +} + #ifdef CONFIG_PM_RUNTIME extern void pm_runtime_init(struct device *dev); @@ -25,7 +31,7 @@ static inline struct device *to_device(struct list_head *entry) return container_of(entry, struct device, power.entry); } -extern void device_pm_init(struct device *dev); +extern void device_pm_sleep_init(struct device *dev); extern void device_pm_add(struct device *); extern void device_pm_remove(struct device *); extern void device_pm_move_before(struct device *, struct device *); @@ -34,12 +40,7 @@ extern void device_pm_move_last(struct device *); #else /* !CONFIG_PM_SLEEP */ -static inline void device_pm_init(struct device *dev) -{ - spin_lock_init(&dev->power.lock); - dev->power.power_state = PMSG_INVALID; - pm_runtime_init(dev); -} +static inline void device_pm_sleep_init(struct device *dev) {} static inline void device_pm_add(struct device *dev) { @@ -60,6 +61,13 @@ static inline void device_pm_move_last(struct device *dev) {} #endif /* !CONFIG_PM_SLEEP */ +static inline void device_pm_init(struct device *dev) +{ + device_pm_init_common(dev); + device_pm_sleep_init(dev); + pm_runtime_init(dev); +} + #ifdef CONFIG_PM /* -- cgit v1.1 From bed2b42d9f0b411f384c5619870ab0fea5dd116b Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:45:11 +0200 Subject: PM / Runtime: Allow helpers to be called by early platform drivers Runtime PM helper functions, like pm_runtime_get_sync(), cannot be called by early platform device drivers, because the devices' power management locks are not initialized at that time. This is quite inconvenient, so modify early_platform_add_devices() to initialize the devices power management locks as appropriate and make sure that they won't be initialized more than once if an early platform device is going to be used as a regular one later. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/power.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index 8a0dcc7..0dbfdf4 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -2,17 +2,31 @@ static inline void device_pm_init_common(struct device *dev) { - spin_lock_init(&dev->power.lock); - dev->power.power_state = PMSG_INVALID; + if (!dev->power.early_init) { + spin_lock_init(&dev->power.lock); + dev->power.power_state = PMSG_INVALID; + dev->power.early_init = true; + } } #ifdef CONFIG_PM_RUNTIME +static inline void pm_runtime_early_init(struct device *dev) +{ + dev->power.disable_depth = 1; + device_pm_init_common(dev); +} + extern void pm_runtime_init(struct device *dev); extern void pm_runtime_remove(struct device *dev); #else /* !CONFIG_PM_RUNTIME */ +static inline void pm_runtime_early_init(struct device *dev) +{ + device_pm_init_common(dev); +} + static inline void pm_runtime_init(struct device *dev) {} static inline void pm_runtime_remove(struct device *dev) {} -- cgit v1.1 From 6fb28badf207a6d8a78906353772e1c3f560a977 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:45:54 +0200 Subject: PM / Domains: Rename the always_on device flag to syscore The always_on device flag is used to mark the devices (belonging to a PM domain) that should never be turned off, except for the system core (syscore) suspend/hibernation and resume stages. Change name of that flag to "syscore" to better reflect its purpose. Signed-off-by: Rafael J. Wysocki Acked-by: Magnus Damm --- drivers/base/power/domain.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 515c8ec..15234ec 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -436,7 +436,7 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd) not_suspended = 0; list_for_each_entry(pdd, &genpd->dev_list, list_node) if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev) - || pdd->dev->power.irq_safe || to_gpd_data(pdd)->always_on)) + || pdd->dev->power.irq_safe || to_gpd_data(pdd)->syscore)) not_suspended++; if (not_suspended > genpd->in_progress) @@ -578,7 +578,7 @@ static int pm_genpd_runtime_suspend(struct device *dev) might_sleep_if(!genpd->dev_irq_safe); - if (dev_gpd_data(dev)->always_on) + if (dev_gpd_data(dev)->syscore) return -EBUSY; stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL; @@ -983,7 +983,7 @@ static int pm_genpd_suspend_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on + if (genpd->suspend_power_off || dev_gpd_data(dev)->syscore || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) return 0; @@ -1016,7 +1016,7 @@ static int pm_genpd_resume_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on + if (genpd->suspend_power_off || dev_gpd_data(dev)->syscore || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) return 0; @@ -1136,7 +1136,7 @@ static int pm_genpd_freeze_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ? + return genpd->suspend_power_off || dev_gpd_data(dev)->syscore ? 0 : genpd_stop_dev(genpd, dev); } @@ -1157,7 +1157,7 @@ static int pm_genpd_thaw_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ? + return genpd->suspend_power_off || dev_gpd_data(dev)->syscore ? 0 : genpd_start_dev(genpd, dev); } @@ -1253,7 +1253,7 @@ static int pm_genpd_restore_noirq(struct device *dev) pm_genpd_sync_poweron(genpd); - return dev_gpd_data(dev)->always_on ? 0 : genpd_start_dev(genpd, dev); + return dev_gpd_data(dev)->syscore ? 0 : genpd_start_dev(genpd, dev); } /** @@ -1526,11 +1526,11 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, } /** - * pm_genpd_dev_always_on - Set/unset the "always on" flag for a given device. + * pm_genpd_dev_syscore - Set/unset the "syscore" flag for a given device. * @dev: Device to set/unset the flag for. - * @val: The new value of the device's "always on" flag. + * @val: The new value of the device's "syscore" flag. */ -void pm_genpd_dev_always_on(struct device *dev, bool val) +void pm_genpd_dev_syscore(struct device *dev, bool val) { struct pm_subsys_data *psd; unsigned long flags; @@ -1539,11 +1539,11 @@ void pm_genpd_dev_always_on(struct device *dev, bool val) psd = dev_to_psd(dev); if (psd && psd->domain_data) - to_gpd_data(psd->domain_data)->always_on = val; + to_gpd_data(psd->domain_data)->syscore = val; spin_unlock_irqrestore(&dev->power.lock, flags); } -EXPORT_SYMBOL_GPL(pm_genpd_dev_always_on); +EXPORT_SYMBOL_GPL(pm_genpd_dev_syscore); /** * pm_genpd_dev_need_restore - Set/unset the device's "need restore" flag. -- cgit v1.1 From dbf374142dd7a3c394ec124ebe7339a6c412d9b6 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:46:39 +0200 Subject: PM / Domains: Move syscore flag from subsys data to struct device The syscore device PM flag is used to mark the devices (belonging to a PM domain) that should never be turned off, except for the system core (syscore) suspend/hibernation and resume stages. That flag is stored in the device's struct pm_subsys_data object whose address is available from struct device. However, in some situations it may be convenient to set that flag before the device is added to a PM domain, so it is better to move it directly to the "power" member of struct device. Then, it can be checked by the routines in drivers/base/power/runtime.c and drivers/base/power/main.c, which is more straightforward. This also reduces the number of dev_gpd_data() invocations in the generic PM domains framework, so the overhead related to the syscore flag is slightly smaller. Signed-off-by: Rafael J. Wysocki Acked-by: Magnus Damm --- drivers/base/power/common.c | 15 +++++++++++++++ drivers/base/power/domain.c | 37 ++++++------------------------------- drivers/base/power/main.c | 28 ++++++++++++++++++++++++++++ drivers/base/power/runtime.c | 2 +- 4 files changed, 50 insertions(+), 32 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index 39c3252..cf7a851 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -83,3 +83,18 @@ int dev_pm_put_subsys_data(struct device *dev) return ret; } EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data); + +/** + * dev_pm_syscore_device - Set/unset the given device's power.syscore flag. + * @dev: Device whose flag is to be modified. + * @val: New value of the flag. + */ +void dev_pm_syscore_device(struct device *dev, bool val) +{ + unsigned long flags; + + spin_lock_irqsave(&dev->power.lock, flags); + dev->power.syscore = val; + spin_unlock_irqrestore(&dev->power.lock, flags); +} +EXPORT_SYMBOL_GPL(dev_pm_syscore_device); diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 15234ec..5217275 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -436,7 +436,7 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd) not_suspended = 0; list_for_each_entry(pdd, &genpd->dev_list, list_node) if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev) - || pdd->dev->power.irq_safe || to_gpd_data(pdd)->syscore)) + || pdd->dev->power.irq_safe || pdd->dev->power.syscore)) not_suspended++; if (not_suspended > genpd->in_progress) @@ -578,9 +578,6 @@ static int pm_genpd_runtime_suspend(struct device *dev) might_sleep_if(!genpd->dev_irq_safe); - if (dev_gpd_data(dev)->syscore) - return -EBUSY; - stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL; if (stop_ok && !stop_ok(dev)) return -EBUSY; @@ -983,7 +980,7 @@ static int pm_genpd_suspend_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - if (genpd->suspend_power_off || dev_gpd_data(dev)->syscore + if (genpd->suspend_power_off || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) return 0; @@ -1016,7 +1013,7 @@ static int pm_genpd_resume_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - if (genpd->suspend_power_off || dev_gpd_data(dev)->syscore + if (genpd->suspend_power_off || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) return 0; @@ -1136,8 +1133,7 @@ static int pm_genpd_freeze_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - return genpd->suspend_power_off || dev_gpd_data(dev)->syscore ? - 0 : genpd_stop_dev(genpd, dev); + return genpd->suspend_power_off ? 0 : genpd_stop_dev(genpd, dev); } /** @@ -1157,8 +1153,7 @@ static int pm_genpd_thaw_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - return genpd->suspend_power_off || dev_gpd_data(dev)->syscore ? - 0 : genpd_start_dev(genpd, dev); + return genpd->suspend_power_off ? 0 : genpd_start_dev(genpd, dev); } /** @@ -1253,7 +1248,7 @@ static int pm_genpd_restore_noirq(struct device *dev) pm_genpd_sync_poweron(genpd); - return dev_gpd_data(dev)->syscore ? 0 : genpd_start_dev(genpd, dev); + return genpd_start_dev(genpd, dev); } /** @@ -1526,26 +1521,6 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, } /** - * pm_genpd_dev_syscore - Set/unset the "syscore" flag for a given device. - * @dev: Device to set/unset the flag for. - * @val: The new value of the device's "syscore" flag. - */ -void pm_genpd_dev_syscore(struct device *dev, bool val) -{ - struct pm_subsys_data *psd; - unsigned long flags; - - spin_lock_irqsave(&dev->power.lock, flags); - - psd = dev_to_psd(dev); - if (psd && psd->domain_data) - to_gpd_data(psd->domain_data)->syscore = val; - - spin_unlock_irqrestore(&dev->power.lock, flags); -} -EXPORT_SYMBOL_GPL(pm_genpd_dev_syscore); - -/** * pm_genpd_dev_need_restore - Set/unset the device's "need restore" flag. * @dev: Device to set/unset the flag for. * @val: The new value of the device's "need restore" flag. diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 7bd1fe4..57f5814 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -405,6 +405,9 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) TRACE_DEVICE(dev); TRACE_RESUME(0); + if (dev->power.syscore) + goto Out; + if (dev->pm_domain) { info = "noirq power domain "; callback = pm_noirq_op(&dev->pm_domain->ops, state); @@ -426,6 +429,7 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) error = dpm_run_callback(callback, dev, state, info); + Out: TRACE_RESUME(error); return error; } @@ -483,6 +487,9 @@ static int device_resume_early(struct device *dev, pm_message_t state) TRACE_DEVICE(dev); TRACE_RESUME(0); + if (dev->power.syscore) + goto Out; + if (dev->pm_domain) { info = "early power domain "; callback = pm_late_early_op(&dev->pm_domain->ops, state); @@ -504,6 +511,7 @@ static int device_resume_early(struct device *dev, pm_message_t state) error = dpm_run_callback(callback, dev, state, info); + Out: TRACE_RESUME(error); return error; } @@ -567,6 +575,9 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) TRACE_DEVICE(dev); TRACE_RESUME(0); + if (dev->power.syscore) + goto Complete; + dpm_wait(dev->parent, async); device_lock(dev); @@ -629,6 +640,8 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) Unlock: device_unlock(dev); + + Complete: complete_all(&dev->power.completion); TRACE_RESUME(error); @@ -719,6 +732,9 @@ static void device_complete(struct device *dev, pm_message_t state) void (*callback)(struct device *) = NULL; char *info = NULL; + if (dev->power.syscore) + return; + device_lock(dev); if (dev->pm_domain) { @@ -831,6 +847,9 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) pm_callback_t callback = NULL; char *info = NULL; + if (dev->power.syscore) + return 0; + if (dev->pm_domain) { info = "noirq power domain "; callback = pm_noirq_op(&dev->pm_domain->ops, state); @@ -914,6 +933,9 @@ static int device_suspend_late(struct device *dev, pm_message_t state) pm_callback_t callback = NULL; char *info = NULL; + if (dev->power.syscore) + return 0; + if (dev->pm_domain) { info = "late power domain "; callback = pm_late_early_op(&dev->pm_domain->ops, state); @@ -1050,6 +1072,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) goto Complete; } + if (dev->power.syscore) + goto Complete; + device_lock(dev); if (dev->pm_domain) { @@ -1206,6 +1231,9 @@ static int device_prepare(struct device *dev, pm_message_t state) char *info = NULL; int error = 0; + if (dev->power.syscore) + return 0; + device_lock(dev); dev->power.wakeup_path = device_may_wakeup(dev); diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 7d9c1cb..bd1de39 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -134,7 +134,7 @@ static int rpm_check_suspend_allowed(struct device *dev) if (dev->power.runtime_error) retval = -EINVAL; - else if (dev->power.disable_depth > 0) + else if (dev->power.disable_depth > 0 || dev->power.syscore) retval = -EACCES; else if (atomic_read(&dev->power.usage_count) > 0) retval = -EAGAIN; -- cgit v1.1 From e2e3e4e51ebdcd757079bd7ec5dcc9dfb2ebce24 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 6 Aug 2012 01:47:29 +0200 Subject: PM / Domains: Do not measure start time for "irq safe" devices The genpd_start_dev() routine used by pm_genpd_runtime_resume() to put "irq safe" devices into the full power state measures the time necessary to "start" the device and updates its PM QoS timing data if necessary. This may lead to a deadlock if the given device is a clock source and genpd_start_dev() is invoked from within the clock source's .enable() routine, which will happen if that routine uses pm_runtime_get_sync(), for example, to ensure that the device is operational. For this reason, introduce a special routine analogous to genpd_start_dev(), called genpd_start_dev_no_timing(), that doesn't carry out the time measurement, and make pm_genpd_runtime_resume() use it instead of genpd_start_dev() to power up "irq safe" devices. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5217275..d7e71b5 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -75,6 +75,12 @@ static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev) start_latency_ns, "start"); } +static int genpd_start_dev_no_timing(struct generic_pm_domain *genpd, + struct device *dev) +{ + return GENPD_DEV_CALLBACK(genpd, int, start, dev); +} + static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) { bool ret = false; @@ -626,7 +632,7 @@ static int pm_genpd_runtime_resume(struct device *dev) /* If power.irq_safe, the PM domain is never powered off. */ if (dev->power.irq_safe) - return genpd_start_dev(genpd, dev); + return genpd_start_dev_no_timing(genpd, dev); mutex_lock(&genpd->lock); ret = __pm_genpd_poweron(genpd); -- cgit v1.1 From feb70af0e3ac6817327be70b47731039ea135dbc Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 13 Aug 2012 14:00:25 +0200 Subject: PM: Do not use the syscore flag for runtime PM The syscore device PM flag used to mark the devices (belonging to PM domains) that should never be turned off, except for the system core (syscore) suspend/hibernation and resume stages, need not be accessed by the runtime PM core functions, because all of the devices it is set for need to be marked as "irq safe" anyway and are protected from being turned off by runtime PM by ensuring that their usage counters are always set. For this reason, make the syscore flag system-wide PM-specific and simplify the code used for manipulating it, because it need not acquire the device's power.lock any more. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/common.c | 15 --------------- drivers/base/power/domain.c | 2 +- drivers/base/power/runtime.c | 2 +- 3 files changed, 2 insertions(+), 17 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index cf7a851..39c3252 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -83,18 +83,3 @@ int dev_pm_put_subsys_data(struct device *dev) return ret; } EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data); - -/** - * dev_pm_syscore_device - Set/unset the given device's power.syscore flag. - * @dev: Device whose flag is to be modified. - * @val: New value of the flag. - */ -void dev_pm_syscore_device(struct device *dev, bool val) -{ - unsigned long flags; - - spin_lock_irqsave(&dev->power.lock, flags); - dev->power.syscore = val; - spin_unlock_irqrestore(&dev->power.lock, flags); -} -EXPORT_SYMBOL_GPL(dev_pm_syscore_device); diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index d7e71b5..5f4606f 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -442,7 +442,7 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd) not_suspended = 0; list_for_each_entry(pdd, &genpd->dev_list, list_node) if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev) - || pdd->dev->power.irq_safe || pdd->dev->power.syscore)) + || pdd->dev->power.irq_safe)) not_suspended++; if (not_suspended > genpd->in_progress) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index bd1de39..7d9c1cb 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -134,7 +134,7 @@ static int rpm_check_suspend_allowed(struct device *dev) if (dev->power.runtime_error) retval = -EINVAL; - else if (dev->power.disable_depth > 0 || dev->power.syscore) + else if (dev->power.disable_depth > 0) retval = -EACCES; else if (atomic_read(&dev->power.usage_count) > 0) retval = -EAGAIN; -- cgit v1.1 From b5abb085f5540a612b0b7a6326ae2a07de2330dd Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 7 Aug 2012 01:06:11 +0200 Subject: PM / Domains: Make it possible to use domain names when adding devices Add a new helper function __pm_genpd_name_add_device() allowing a device to be added to a (registered) generic PM domain identified by name. Add a wrapper around it, pm_genpd_name_add_device(), passing NULL as the last argument and reorganize pm_domains.h for the new functions to be defined consistently with the existing ones. These functions are useful for adding devices to PM domains whose representations are stored in tables, when the caller doesn't know the index of the domain to add the device to, but it knows the domain's name. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5f4606f..ac06d02 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1465,6 +1465,33 @@ int __pm_genpd_of_add_device(struct device_node *genpd_node, struct device *dev, return __pm_genpd_add_device(genpd, dev, td); } + +/** + * __pm_genpd_name_add_device - Find I/O PM domain and add a device to it. + * @domain_name: Name of the PM domain to add the device to. + * @dev: Device to be added. + * @td: Set of PM QoS timing parameters to attach to the device. + */ +int __pm_genpd_name_add_device(const char *domain_name, struct device *dev, + struct gpd_timing_data *td) +{ + struct generic_pm_domain *genpd = NULL, *gpd; + + if (IS_ERR_OR_NULL(domain_name) || IS_ERR_OR_NULL(dev)) + return -EINVAL; + + mutex_lock(&gpd_list_lock); + list_for_each_entry(gpd, &gpd_list, gpd_list_node) { + if (!strcmp(gpd->name, domain_name)) { + genpd = gpd; + break; + } + } + mutex_unlock(&gpd_list_lock); + + return __pm_genpd_add_device(genpd, dev, td); +} + /** * pm_genpd_remove_device - Remove a device from an I/O PM domain. * @genpd: PM domain to remove the device from. -- cgit v1.1 From fb7268be9f72bed6ae48554f00f2dcb2ef333bfc Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 7 Aug 2012 01:08:37 +0200 Subject: PM / Domains: Make it possible to use names when adding subdomains Add a new helper function, pm_genpd_add_subdomain_names(), allowing the caller to add a subdomain to a generic PM domain using names for domain identification (both domains have to be initialized before). This function is useful for adding subdomains to PM domains whose representations are stored in tables, when the caller doesn't know the indices of the domain to add the subdomain to and of the subdomain itself, but it knows the domains' names. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index ac06d02..cddf818 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1584,7 +1584,8 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, struct gpd_link *link; int ret = 0; - if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)) + if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain) + || genpd == subdomain) return -EINVAL; start: @@ -1631,6 +1632,35 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, } /** + * pm_genpd_add_subdomain_names - Add a subdomain to an I/O PM domain. + * @master_name: Name of the master PM domain to add the subdomain to. + * @subdomain_name: Name of the subdomain to be added. + */ +int pm_genpd_add_subdomain_names(const char *master_name, + const char *subdomain_name) +{ + struct generic_pm_domain *master = NULL, *subdomain = NULL, *gpd; + + if (IS_ERR_OR_NULL(master_name) || IS_ERR_OR_NULL(subdomain_name)) + return -EINVAL; + + mutex_lock(&gpd_list_lock); + list_for_each_entry(gpd, &gpd_list, gpd_list_node) { + if (!master && !strcmp(gpd->name, master_name)) + master = gpd; + + if (!subdomain && !strcmp(gpd->name, subdomain_name)) + subdomain = gpd; + + if (master && subdomain) + break; + } + mutex_unlock(&gpd_list_lock); + + return pm_genpd_add_subdomain(master, subdomain); +} + +/** * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. * @genpd: Master PM domain to remove the subdomain from. * @subdomain: Subdomain to be removed. -- cgit v1.1 From 8bc0251de2932e603f8ed73b76ba2d64b2dc1d18 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 7 Aug 2012 01:11:14 +0200 Subject: PM / Domains: Add power-on function using names to identify domains It sometimes is necessary to turn on a given PM domain when only the name of it is known and the domain pointer is not readily available. For this reason, add a new helper function, pm_genpd_name_poweron(), allowing the caller to turn on a PM domain using its name for identification. To avoid code duplication, move the domain lookup code to a separate function. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 46 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index cddf818..4d63340 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -53,6 +53,24 @@ static LIST_HEAD(gpd_list); static DEFINE_MUTEX(gpd_list_lock); +static struct generic_pm_domain *pm_genpd_lookup_name(const char *domain_name) +{ + struct generic_pm_domain *genpd = NULL, *gpd; + + if (IS_ERR_OR_NULL(domain_name)) + return NULL; + + mutex_lock(&gpd_list_lock); + list_for_each_entry(gpd, &gpd_list, gpd_list_node) { + if (!strcmp(gpd->name, domain_name)) { + genpd = gpd; + break; + } + } + mutex_unlock(&gpd_list_lock); + return genpd; +} + #ifdef CONFIG_PM struct generic_pm_domain *dev_to_genpd(struct device *dev) @@ -262,6 +280,18 @@ int pm_genpd_poweron(struct generic_pm_domain *genpd) return ret; } +/** + * pm_genpd_name_poweron - Restore power to a given PM domain and its masters. + * @domain_name: Name of the PM domain to power up. + */ +int pm_genpd_name_poweron(const char *domain_name) +{ + struct generic_pm_domain *genpd; + + genpd = pm_genpd_lookup_name(domain_name); + return genpd ? pm_genpd_poweron(genpd) : -EINVAL; +} + #endif /* CONFIG_PM */ #ifdef CONFIG_PM_RUNTIME @@ -1475,21 +1505,7 @@ int __pm_genpd_of_add_device(struct device_node *genpd_node, struct device *dev, int __pm_genpd_name_add_device(const char *domain_name, struct device *dev, struct gpd_timing_data *td) { - struct generic_pm_domain *genpd = NULL, *gpd; - - if (IS_ERR_OR_NULL(domain_name) || IS_ERR_OR_NULL(dev)) - return -EINVAL; - - mutex_lock(&gpd_list_lock); - list_for_each_entry(gpd, &gpd_list, gpd_list_node) { - if (!strcmp(gpd->name, domain_name)) { - genpd = gpd; - break; - } - } - mutex_unlock(&gpd_list_lock); - - return __pm_genpd_add_device(genpd, dev, td); + return __pm_genpd_add_device(pm_genpd_lookup_name(domain_name), dev, td); } /** -- cgit v1.1 From 40114447a7f89860b46a64e5504f313656cb5f27 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 15 Aug 2012 20:32:43 +0200 Subject: PM / Domains: Document cpuidle-related functions and change their names The names of the cpuidle-related functions in drivers/base/power/domain.c are inconsistent with the names of the other exported functions in that file (the "pm_" prefix is missing from them) and they are missing kerneldoc comments. Fix that by adding the missing "pm_" prefix to the names of those functions and add kerneldoc comments documenting them. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 4d63340..e44e1a8 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1829,7 +1829,16 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td) } EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks); -int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) +/** + * pm_genpd_attach_cpuidle - Connect the given PM domain with cpuidle. + * @genpd: PM domain to be connected with cpuidle. + * @state: cpuidle state this domain can disable/enable. + * + * Make a PM domain behave as though it contained a CPU core, that is, instead + * of calling its power down routine it will enable the given cpuidle state so + * that the cpuidle subsystem can power it down (if possible and desirable). + */ +int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) { struct cpuidle_driver *cpuidle_drv; struct gpd_cpu_data *cpu_data; @@ -1878,7 +1887,14 @@ int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) goto out; } -int genpd_detach_cpuidle(struct generic_pm_domain *genpd) +/** + * pm_genpd_detach_cpuidle - Remove the cpuidle connection from a PM domain. + * @genpd: PM domain to remove the cpuidle connection from. + * + * Remove the cpuidle connection set up by pm_genpd_attach_cpuidle() from the + * given PM domain. + */ +int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd) { struct gpd_cpu_data *cpu_data; struct cpuidle_state *idle_state; -- cgit v1.1 From 74a2799ab51acec9410f467fef8678ebb1125d7d Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 15 Aug 2012 20:32:59 +0200 Subject: PM / Domains: Operations related to cpuidle using domain names Make it possible to use domain names in operations connecting cpuidle to and disconnecting it from a PM domain. This is useful on platforms where PM domain objects are organized in such a way that the names of the domains are easier to use than the addresses of those objects. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index e44e1a8..12ad070 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1888,6 +1888,16 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) } /** + * pm_genpd_name_attach_cpuidle - Find PM domain and connect cpuidle to it. + * @name: Name of the domain to connect to cpuidle. + * @state: cpuidle state this domain can manipulate. + */ +int pm_genpd_name_attach_cpuidle(const char *name, int state) +{ + return pm_genpd_attach_cpuidle(pm_genpd_lookup_name(name), state); +} + +/** * pm_genpd_detach_cpuidle - Remove the cpuidle connection from a PM domain. * @genpd: PM domain to remove the cpuidle connection from. * @@ -1925,6 +1935,15 @@ int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd) return ret; } +/** + * pm_genpd_name_detach_cpuidle - Find PM domain and disconnect cpuidle from it. + * @name: Name of the domain to disconnect cpuidle from. + */ +int pm_genpd_name_detach_cpuidle(const char *name) +{ + return pm_genpd_detach_cpuidle(pm_genpd_lookup_name(name)); +} + /* Default device callbacks for generic PM domains. */ /** -- cgit v1.1 From b3d3b9fb6016e6eacd3ae49fb786806d00c43e7b Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Thu, 6 Sep 2012 08:18:57 +0000 Subject: PM / Domains: Fix compilation warning related to genpd_start_dev_no_timing() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Function genpd_start_dev_no_timing was accessed inside CONFIG_PM_RUNTIME macro but defined outside it. When the above macro was not defined the compiler gave the following warning: drivers/base/power/domain.c:96:12: warning: ‘genpd_start_dev_no_timing’ defined but not used [-Wunused-function] Signed-off-by: Sachin Kamat Signed-off-by: Rafael J. Wysocki --- drivers/base/power/domain.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 12ad070..c22b869 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -93,12 +93,6 @@ static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev) start_latency_ns, "start"); } -static int genpd_start_dev_no_timing(struct generic_pm_domain *genpd, - struct device *dev) -{ - return GENPD_DEV_CALLBACK(genpd, int, start, dev); -} - static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) { bool ret = false; @@ -296,6 +290,12 @@ int pm_genpd_name_poweron(const char *domain_name) #ifdef CONFIG_PM_RUNTIME +static int genpd_start_dev_no_timing(struct generic_pm_domain *genpd, + struct device *dev) +{ + return GENPD_DEV_CALLBACK(genpd, int, start, dev); +} + static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev) { return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev, -- cgit v1.1 From 4955070974ecfa0b1ae9d2506f529460fd3a4b0b Mon Sep 17 00:00:00 2001 From: John Stultz Date: Thu, 6 Sep 2012 23:19:06 +0200 Subject: PM / wakeup: Use irqsave/irqrestore for events_lock Jon Medhurst (Tixy) recently noticed a problem with the events_lock usage. One of the Android patches that uses wakeup_sources calls wakeup_source_add() with irqs disabled. However, the event_lock usage in wakeup_source_add() uses spin_lock_irq()/spin_unlock_irq(), which reenables interrupts. This results in lockdep warnings. The fix is to use spin_lock_irqsave()/spin_lock_irqrestore() instead for the events_lock. References: https://bugs.launchpad.net/linaro-landing-team-arm/+bug/1037565 Reported-and-debugged-by: Jon Medhurst (Tixy) Signed-off-by: John Stultz Signed-off-by: Rafael J. Wysocki --- drivers/base/power/wakeup.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index 8a0a9ca..e6ee5e8 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -127,6 +127,8 @@ EXPORT_SYMBOL_GPL(wakeup_source_destroy); */ void wakeup_source_add(struct wakeup_source *ws) { + unsigned long flags; + if (WARN_ON(!ws)) return; @@ -135,9 +137,9 @@ void wakeup_source_add(struct wakeup_source *ws) ws->active = false; ws->last_time = ktime_get(); - spin_lock_irq(&events_lock); + spin_lock_irqsave(&events_lock, flags); list_add_rcu(&ws->entry, &wakeup_sources); - spin_unlock_irq(&events_lock); + spin_unlock_irqrestore(&events_lock, flags); } EXPORT_SYMBOL_GPL(wakeup_source_add); @@ -147,12 +149,14 @@ EXPORT_SYMBOL_GPL(wakeup_source_add); */ void wakeup_source_remove(struct wakeup_source *ws) { + unsigned long flags; + if (WARN_ON(!ws)) return; - spin_lock_irq(&events_lock); + spin_lock_irqsave(&events_lock, flags); list_del_rcu(&ws->entry); - spin_unlock_irq(&events_lock); + spin_unlock_irqrestore(&events_lock, flags); synchronize_rcu(); } EXPORT_SYMBOL_GPL(wakeup_source_remove); @@ -752,15 +756,16 @@ bool pm_get_wakeup_count(unsigned int *count, bool block) bool pm_save_wakeup_count(unsigned int count) { unsigned int cnt, inpr; + unsigned long flags; events_check_enabled = false; - spin_lock_irq(&events_lock); + spin_lock_irqsave(&events_lock, flags); split_counters(&cnt, &inpr); if (cnt == count && inpr == 0) { saved_count = count; events_check_enabled = true; } - spin_unlock_irq(&events_lock); + spin_unlock_irqrestore(&events_lock, flags); return events_check_enabled; } -- cgit v1.1 From b496dfbc94ab86f970ef0167eaabe51f930aa5fb Mon Sep 17 00:00:00 2001 From: Shawn Guo Date: Wed, 5 Sep 2012 01:09:12 +0200 Subject: PM / OPP: Initialize OPP table from device tree With a lot of devices booting from device tree nowadays, it requires that OPP table can be initialized from device tree. The patch adds a helper function of_init_opp_table together with a binding doc for that purpose. Signed-off-by: Shawn Guo Acked-by: Rob Herring Signed-off-by: Rafael J. Wysocki --- drivers/base/power/opp.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'drivers/base/power') diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index ac993ea..d946864 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -22,6 +22,7 @@ #include #include #include +#include /* * Internal data structure organization with the OPP layer library is as @@ -674,3 +675,49 @@ struct srcu_notifier_head *opp_get_notifier(struct device *dev) return &dev_opp->head; } + +#ifdef CONFIG_OF +/** + * of_init_opp_table() - Initialize opp table from device tree + * @dev: device pointer used to lookup device OPPs. + * + * Register the initial OPP table with the OPP library for given device. + */ +int of_init_opp_table(struct device *dev) +{ + const struct property *prop; + const __be32 *val; + int nr; + + prop = of_find_property(dev->of_node, "operating-points", NULL); + if (!prop) + return -ENODEV; + if (!prop->value) + return -ENODATA; + + /* + * Each OPP is a set of tuples consisting of frequency and + * voltage like . + */ + nr = prop->length / sizeof(u32); + if (nr % 2) { + dev_err(dev, "%s: Invalid OPP list\n", __func__); + return -EINVAL; + } + + val = prop->value; + while (nr) { + unsigned long freq = be32_to_cpup(val++) * 1000; + unsigned long volt = be32_to_cpup(val++); + + if (opp_add(dev, freq, volt)) { + dev_warn(dev, "%s: Failed to add OPP %ld\n", + __func__, freq); + continue; + } + nr -= 2; + } + + return 0; +} +#endif -- cgit v1.1 From 997a031107ec962967ce36db9bc500f1fad491c1 Mon Sep 17 00:00:00 2001 From: Feng Hong Date: Wed, 19 Sep 2012 14:16:00 +0200 Subject: PM / Sleep: use resume event when call dpm_resume_early When dpm_suspend_noirq fail, state is PMSG_SUSPEND, should change to PMSG_RESUME when dpm_resume_early is called Signed-off-by: Feng Hong Signed-off-by: Raul Xiong Signed-off-by: Neil Zhang Cc: stable@vger.kernel.org Signed-off-by: Rafael J. Wysocki --- drivers/base/power/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 0113adc..2700f2e 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -996,7 +996,7 @@ int dpm_suspend_end(pm_message_t state) error = dpm_suspend_noirq(state); if (error) { - dpm_resume_early(state); + dpm_resume_early(resume_event(state)); return error; } -- cgit v1.1 From fc2fb3a075c206927d3fbad251dae82ba82ccf2d Mon Sep 17 00:00:00 2001 From: Jean Pihet Date: Wed, 19 Sep 2012 14:17:20 +0200 Subject: PM QoS: Use spinlock in the per-device PM QoS constraints code The per-device PM QoS locking requires a spinlock to be used. The reasons are: - an alignement with the PM QoS core code, which is used by the per-device PM QoS code for the constraints lists management. The PM QoS core code uses spinlocks to protect the constraints lists, - some drivers need to use the per-device PM QoS functionality from interrupt context or spinlock protected context. An example of such a driver is the OMAP HSI (high-speed synchronous serial interface) driver which needs to control the IP block idle state depending on the FIFO empty state, from interrupt context. Reported-by: Djamil Elaidi Signed-off-by: Jean Pihet Signed-off-by: Rafael J. Wysocki --- drivers/base/power/qos.c | 67 +++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 26 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index 74a67e0..968a771 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -24,26 +24,32 @@ * . a system-wide notification callback using the dev_pm_qos_*_global_notifier * API. The notification chain data is stored in a static variable. * - * Note about the per-device constraint data struct allocation: - * . The per-device constraints data struct ptr is tored into the device + * Notes about the per-device constraint data struct allocation: + * . The per-device constraints data struct ptr is stored into the device * dev_pm_info. * . To minimize the data usage by the per-device constraints, the data struct - * is only allocated at the first call to dev_pm_qos_add_request. + * is only allocated at the first call to dev_pm_qos_add_request. * . The data is later free'd when the device is removed from the system. - * . A global mutex protects the constraints users from the data being - * allocated and free'd. + * + * Notes about locking: + * . The dev->power.lock lock protects the constraints list + * (dev->power.constraints) allocation and free, as triggered by the + * driver core code at device insertion and removal, + * . A global lock dev_pm_qos_lock protects the constraints list entries + * from any modification and the notifiers registration and unregistration. + * . For both locks a spinlock is needed since this code can be called from + * interrupt context or spinlock protected context. */ #include #include #include #include -#include #include #include "power.h" -static DEFINE_MUTEX(dev_pm_qos_mtx); +static DEFINE_SPINLOCK(dev_pm_qos_lock); static BLOCKING_NOTIFIER_HEAD(dev_pm_notifiers); @@ -110,18 +116,19 @@ static int apply_constraint(struct dev_pm_qos_request *req, * @dev: device to allocate data for * * Called at the first call to add_request, for constraint data allocation - * Must be called with the dev_pm_qos_mtx mutex held + * Must be called with the dev_pm_qos_lock lock held */ static int dev_pm_qos_constraints_allocate(struct device *dev) { struct pm_qos_constraints *c; struct blocking_notifier_head *n; + unsigned long flags; - c = kzalloc(sizeof(*c), GFP_KERNEL); + c = kzalloc(sizeof(*c), GFP_ATOMIC); if (!c) return -ENOMEM; - n = kzalloc(sizeof(*n), GFP_KERNEL); + n = kzalloc(sizeof(*n), GFP_ATOMIC); if (!n) { kfree(c); return -ENOMEM; @@ -134,9 +141,9 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) c->type = PM_QOS_MIN; c->notifiers = n; - spin_lock_irq(&dev->power.lock); + spin_lock_irqsave(&dev->power.lock, flags); dev->power.constraints = c; - spin_unlock_irq(&dev->power.lock); + spin_unlock_irqrestore(&dev->power.lock, flags); return 0; } @@ -150,10 +157,12 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) */ void dev_pm_qos_constraints_init(struct device *dev) { - mutex_lock(&dev_pm_qos_mtx); + unsigned long flags; + + spin_lock_irqsave(&dev_pm_qos_lock, flags); dev->power.constraints = NULL; dev->power.power_state = PMSG_ON; - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); } /** @@ -166,6 +175,7 @@ void dev_pm_qos_constraints_destroy(struct device *dev) { struct dev_pm_qos_request *req, *tmp; struct pm_qos_constraints *c; + unsigned long flags; /* * If the device's PM QoS resume latency limit has been exposed to user @@ -173,7 +183,7 @@ void dev_pm_qos_constraints_destroy(struct device *dev) */ dev_pm_qos_hide_latency_limit(dev); - mutex_lock(&dev_pm_qos_mtx); + spin_lock_irqsave(&dev_pm_qos_lock, flags); dev->power.power_state = PMSG_INVALID; c = dev->power.constraints; @@ -198,7 +208,7 @@ void dev_pm_qos_constraints_destroy(struct device *dev) kfree(c); out: - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); } /** @@ -223,6 +233,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, s32 value) { int ret = 0; + unsigned long flags; if (!dev || !req) /*guard against callers passing in null */ return -EINVAL; @@ -233,7 +244,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, req->dev = dev; - mutex_lock(&dev_pm_qos_mtx); + spin_lock_irqsave(&dev_pm_qos_lock, flags); if (!dev->power.constraints) { if (dev->power.power_state.event == PM_EVENT_INVALID) { @@ -255,7 +266,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, ret = apply_constraint(req, PM_QOS_ADD_REQ, value); out: - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); return ret; } @@ -280,6 +291,7 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value) { int ret = 0; + unsigned long flags; if (!req) /*guard against callers passing in null */ return -EINVAL; @@ -288,7 +300,7 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req, "%s() called for unknown object\n", __func__)) return -EINVAL; - mutex_lock(&dev_pm_qos_mtx); + spin_lock_irqsave(&dev_pm_qos_lock, flags); if (req->dev->power.constraints) { if (new_value != req->node.prio) @@ -299,7 +311,7 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req, ret = -ENODEV; } - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_update_request); @@ -319,6 +331,7 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_update_request); int dev_pm_qos_remove_request(struct dev_pm_qos_request *req) { int ret = 0; + unsigned long flags; if (!req) /*guard against callers passing in null */ return -EINVAL; @@ -327,7 +340,7 @@ int dev_pm_qos_remove_request(struct dev_pm_qos_request *req) "%s() called for unknown object\n", __func__)) return -EINVAL; - mutex_lock(&dev_pm_qos_mtx); + spin_lock_irqsave(&dev_pm_qos_lock, flags); if (req->dev->power.constraints) { ret = apply_constraint(req, PM_QOS_REMOVE_REQ, @@ -338,7 +351,7 @@ int dev_pm_qos_remove_request(struct dev_pm_qos_request *req) ret = -ENODEV; } - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request); @@ -359,8 +372,9 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request); int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier) { int ret = 0; + unsigned long flags; - mutex_lock(&dev_pm_qos_mtx); + spin_lock_irqsave(&dev_pm_qos_lock, flags); if (!dev->power.constraints) ret = dev->power.power_state.event != PM_EVENT_INVALID ? @@ -370,7 +384,7 @@ int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier) ret = blocking_notifier_chain_register( dev->power.constraints->notifiers, notifier); - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier); @@ -389,8 +403,9 @@ int dev_pm_qos_remove_notifier(struct device *dev, struct notifier_block *notifier) { int retval = 0; + unsigned long flags; - mutex_lock(&dev_pm_qos_mtx); + spin_lock_irqsave(&dev_pm_qos_lock, flags); /* Silently return if the constraints object is not present. */ if (dev->power.constraints) @@ -398,7 +413,7 @@ int dev_pm_qos_remove_notifier(struct device *dev, dev->power.constraints->notifiers, notifier); - mutex_unlock(&dev_pm_qos_mtx); + spin_unlock_irqrestore(&dev_pm_qos_lock, flags); return retval; } EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier); -- cgit v1.1 From 88d26136a256576e444db312179e17af6dd0ea87 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Wed, 19 Sep 2012 21:59:02 +0200 Subject: PM: Prevent runtime suspend during system resume This patch (as1591) moves the pm_runtime_get_noresume() and pm_runtime_put_sync() calls from __device_suspend() and device_resume() to device_prepare() and device_complete() in the PM core. The reason for doing this is to make sure that parent devices remain at full power (i.e., don't go into runtime suspend) while their children are being resumed from a system sleep. The PCI core already contained equivalent code to serve the same purpose. The patch removes the duplicated code, since it is no longer needed. One of the comments from the PCI core gets moved into the PM core, and a second comment is added to explain whe the _get_noresume and _put_sync calls are present. Signed-off-by: Alan Stern Signed-off-by: Rafael J. Wysocki --- drivers/base/power/main.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 2700f2e..077b975 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -565,7 +565,6 @@ 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; TRACE_DEVICE(dev); TRACE_RESUME(0); @@ -583,7 +582,6 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) goto Unlock; pm_runtime_enable(dev); - put = true; if (dev->pm_domain) { info = "power domain "; @@ -636,9 +634,6 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) TRACE_RESUME(error); - if (put) - pm_runtime_put_sync(dev); - return error; } @@ -749,6 +744,8 @@ static void device_complete(struct device *dev, pm_message_t state) } device_unlock(dev); + + pm_runtime_put_sync(dev); } /** @@ -1043,12 +1040,16 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) if (async_error) goto Complete; - pm_runtime_get_noresume(dev); + /* + * If a device configured to wake up the system from sleep states + * has been suspended at run time and there's a resume request pending + * for it, this is equivalent to the device signaling wakeup, so the + * system suspend operation should be aborted. + */ if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) pm_wakeup_event(dev, 0); if (pm_wakeup_pending()) { - pm_runtime_put_sync(dev); async_error = -EBUSY; goto Complete; } @@ -1111,12 +1112,10 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) Complete: complete_all(&dev->power.completion); - if (error) { - pm_runtime_put_sync(dev); + if (error) async_error = error; - } else if (dev->power.is_suspended) { + else if (dev->power.is_suspended) __pm_runtime_disable(dev, false); - } return error; } @@ -1209,6 +1208,14 @@ static int device_prepare(struct device *dev, pm_message_t state) char *info = NULL; int error = 0; + /* + * If a device's parent goes into runtime suspend at the wrong time, + * it won't be possible to resume the device. To prevent this we + * block runtime suspend here, during the prepare phase, and allow + * it again during the complete phase. + */ + pm_runtime_get_noresume(dev); + device_lock(dev); dev->power.wakeup_path = device_may_wakeup(dev); -- cgit v1.1 From 6f3c77b040fc24708228607bba504878de5236d1 Mon Sep 17 00:00:00 2001 From: Kevin Hilman Date: Fri, 21 Sep 2012 22:47:34 +0000 Subject: PM / Runtime: let rpm_resume() succeed if RPM_ACTIVE, even when disabled, v2 There are several drivers where the return value of pm_runtime_get_sync() is used to decide whether or not it is safe to access hardware and that don't provide .suspend() callbacks for system suspend (but may use late/noirq callbacks.) If such a driver happens to call pm_runtime_get_sync() during system suspend, after the core has disabled runtime PM, it will get the error code and will decide that the hardware should not be accessed, although this may be a wrong conclusion, depending on the state of the device when runtime PM was disabled. Drivers might work around this problem by using a test like: ret = pm_runtime_get_sync(dev); if (!ret || (ret == -EACCES && driver_private_data(dev)->suspended)) { /* access hardware */ } where driver_private_data(dev)->suspended is a flag set by the driver's .suspend() method (that would have to be added for this purpose). However, that potentially would need to be done by multiple drivers which means quite a lot of duplicated code and bloat. To avoid that we can use the observation that the core sets dev->power.is_suspended before disabling runtime PM and use that instead of the driver's private flag. Still, potentially many drivers would need to repeat that same check in quite a few places, so it's better to let the core do it. Then we can be a bit smarter and check whether or not runtime PM was disabled by the core only (disable_depth == 1) or by someone else in addition to the core (disable_depth > 1). In the former case rpm_resume() can return 1 if the runtime PM status is RPM_ACTIVE, because it means the device was active when the core disabled runtime PM. In the latter case it should still return -EACCES, because it isn't clear why runtime PM has been disabled. Tested on AM3730/Beagle-xM where a wakeup IRQ firing during the late suspend phase triggers runtime PM activity in the I2C driver since the wakeup IRQ is on an I2C-connected PMIC. [rjw: Modified whitespace to follow the file's convention.] Signed-off-by: Kevin Hilman Signed-off-by: Rafael J. Wysocki --- drivers/base/power/runtime.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/base/power') diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 7d9c1cb..3148b10 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -509,6 +509,9 @@ static int rpm_resume(struct device *dev, int rpmflags) repeat: if (dev->power.runtime_error) retval = -EINVAL; + else if (dev->power.disable_depth == 1 && dev->power.is_suspended + && dev->power.runtime_status == RPM_ACTIVE) + retval = 1; else if (dev->power.disable_depth > 0) retval = -EACCES; if (retval) -- cgit v1.1 From 8376869e51f5094e87229aa6200c43ada85c9aaf Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 24 Sep 2012 21:39:36 +0200 Subject: Revert "PM QoS: Use spinlock in the per-device PM QoS constraints code" This reverts commit fc2fb3a075c206927d3fbad251dae82ba82ccf2d. The problem with the above commit is that it makes the device PM QoS core code hold a spinlock around blocking_notifier_call_chain() invocations. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/qos.c | 67 +++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) (limited to 'drivers/base/power') diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index 968a771..74a67e0 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -24,32 +24,26 @@ * . a system-wide notification callback using the dev_pm_qos_*_global_notifier * API. The notification chain data is stored in a static variable. * - * Notes about the per-device constraint data struct allocation: - * . The per-device constraints data struct ptr is stored into the device + * Note about the per-device constraint data struct allocation: + * . The per-device constraints data struct ptr is tored into the device * dev_pm_info. * . To minimize the data usage by the per-device constraints, the data struct - * is only allocated at the first call to dev_pm_qos_add_request. + * is only allocated at the first call to dev_pm_qos_add_request. * . The data is later free'd when the device is removed from the system. - * - * Notes about locking: - * . The dev->power.lock lock protects the constraints list - * (dev->power.constraints) allocation and free, as triggered by the - * driver core code at device insertion and removal, - * . A global lock dev_pm_qos_lock protects the constraints list entries - * from any modification and the notifiers registration and unregistration. - * . For both locks a spinlock is needed since this code can be called from - * interrupt context or spinlock protected context. + * . A global mutex protects the constraints users from the data being + * allocated and free'd. */ #include #include #include #include +#include #include #include "power.h" -static DEFINE_SPINLOCK(dev_pm_qos_lock); +static DEFINE_MUTEX(dev_pm_qos_mtx); static BLOCKING_NOTIFIER_HEAD(dev_pm_notifiers); @@ -116,19 +110,18 @@ static int apply_constraint(struct dev_pm_qos_request *req, * @dev: device to allocate data for * * Called at the first call to add_request, for constraint data allocation - * Must be called with the dev_pm_qos_lock lock held + * Must be called with the dev_pm_qos_mtx mutex held */ static int dev_pm_qos_constraints_allocate(struct device *dev) { struct pm_qos_constraints *c; struct blocking_notifier_head *n; - unsigned long flags; - c = kzalloc(sizeof(*c), GFP_ATOMIC); + c = kzalloc(sizeof(*c), GFP_KERNEL); if (!c) return -ENOMEM; - n = kzalloc(sizeof(*n), GFP_ATOMIC); + n = kzalloc(sizeof(*n), GFP_KERNEL); if (!n) { kfree(c); return -ENOMEM; @@ -141,9 +134,9 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) c->type = PM_QOS_MIN; c->notifiers = n; - spin_lock_irqsave(&dev->power.lock, flags); + spin_lock_irq(&dev->power.lock); dev->power.constraints = c; - spin_unlock_irqrestore(&dev->power.lock, flags); + spin_unlock_irq(&dev->power.lock); return 0; } @@ -157,12 +150,10 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) */ void dev_pm_qos_constraints_init(struct device *dev) { - unsigned long flags; - - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); dev->power.constraints = NULL; dev->power.power_state = PMSG_ON; - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); } /** @@ -175,7 +166,6 @@ void dev_pm_qos_constraints_destroy(struct device *dev) { struct dev_pm_qos_request *req, *tmp; struct pm_qos_constraints *c; - unsigned long flags; /* * If the device's PM QoS resume latency limit has been exposed to user @@ -183,7 +173,7 @@ void dev_pm_qos_constraints_destroy(struct device *dev) */ dev_pm_qos_hide_latency_limit(dev); - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); dev->power.power_state = PMSG_INVALID; c = dev->power.constraints; @@ -208,7 +198,7 @@ void dev_pm_qos_constraints_destroy(struct device *dev) kfree(c); out: - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); } /** @@ -233,7 +223,6 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, s32 value) { int ret = 0; - unsigned long flags; if (!dev || !req) /*guard against callers passing in null */ return -EINVAL; @@ -244,7 +233,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, req->dev = dev; - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); if (!dev->power.constraints) { if (dev->power.power_state.event == PM_EVENT_INVALID) { @@ -266,7 +255,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, ret = apply_constraint(req, PM_QOS_ADD_REQ, value); out: - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); return ret; } @@ -291,7 +280,6 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value) { int ret = 0; - unsigned long flags; if (!req) /*guard against callers passing in null */ return -EINVAL; @@ -300,7 +288,7 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req, "%s() called for unknown object\n", __func__)) return -EINVAL; - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); if (req->dev->power.constraints) { if (new_value != req->node.prio) @@ -311,7 +299,7 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req, ret = -ENODEV; } - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_update_request); @@ -331,7 +319,6 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_update_request); int dev_pm_qos_remove_request(struct dev_pm_qos_request *req) { int ret = 0; - unsigned long flags; if (!req) /*guard against callers passing in null */ return -EINVAL; @@ -340,7 +327,7 @@ int dev_pm_qos_remove_request(struct dev_pm_qos_request *req) "%s() called for unknown object\n", __func__)) return -EINVAL; - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); if (req->dev->power.constraints) { ret = apply_constraint(req, PM_QOS_REMOVE_REQ, @@ -351,7 +338,7 @@ int dev_pm_qos_remove_request(struct dev_pm_qos_request *req) ret = -ENODEV; } - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request); @@ -372,9 +359,8 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request); int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier) { int ret = 0; - unsigned long flags; - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); if (!dev->power.constraints) ret = dev->power.power_state.event != PM_EVENT_INVALID ? @@ -384,7 +370,7 @@ int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier) ret = blocking_notifier_chain_register( dev->power.constraints->notifiers, notifier); - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier); @@ -403,9 +389,8 @@ int dev_pm_qos_remove_notifier(struct device *dev, struct notifier_block *notifier) { int retval = 0; - unsigned long flags; - spin_lock_irqsave(&dev_pm_qos_lock, flags); + mutex_lock(&dev_pm_qos_mtx); /* Silently return if the constraints object is not present. */ if (dev->power.constraints) @@ -413,7 +398,7 @@ int dev_pm_qos_remove_notifier(struct device *dev, dev->power.constraints->notifiers, notifier); - spin_unlock_irqrestore(&dev_pm_qos_lock, flags); + mutex_unlock(&dev_pm_qos_mtx); return retval; } EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier); -- cgit v1.1