Skip to content

Commit

Permalink
FROMLIST: PM / Domains: add setter for dev.pm_domain
Browse files Browse the repository at this point in the history
Adds a function that sets the pointer to dev_pm_domain in struct device
and that warns if the device has already finished probing. The reason
why we want to enforce that is because in the general case that can
cause problems and also that we can simplify code quite a bit if we can
always assume that.

This patch also changes all current code that directly sets the
dev.pm_domain pointer.

BUG=chrome-os-partner:46491
TEST=boot glados

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
(am from https://patchwork.kernel.org/patch/7328141/)
Signed-off-by: Derek Basehore <dbasehore@chromium.org>

Change-Id: I2eaf04084337c9a9b6f7f188f94d7ebada8dbb57
Reviewed-on: https://chromium-review.googlesource.com/305814
Commit-Ready: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
  • Loading branch information
Tomeu Vizoso authored and chrome-bot committed Oct 23, 2015
1 parent 123b0e7 commit 8a679b9
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 20 deletions.
7 changes: 4 additions & 3 deletions arch/arm/mach-omap2/omap_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
#include <linux/of.h>
#include <linux/notifier.h>
Expand Down Expand Up @@ -174,7 +175,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev)
r->name = dev_name(&pdev->dev);
}

pdev->dev.pm_domain = &omap_device_pm_domain;
dev_pm_domain_set(&pdev->dev, &omap_device_pm_domain);

if (device_active) {
omap_device_enable(pdev);
Expand All @@ -186,7 +187,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev)
odbfd_exit:
/* if data/we are at fault.. load up a fail handler */
if (ret)
pdev->dev.pm_domain = &omap_device_fail_pm_domain;
dev_pm_domain_set(&pdev->dev, &omap_device_fail_pm_domain);

return ret;
}
Expand Down Expand Up @@ -705,7 +706,7 @@ int omap_device_register(struct platform_device *pdev)
{
pr_debug("omap_device: %s: registering\n", pdev->name);

pdev->dev.pm_domain = &omap_device_pm_domain;
dev_pm_domain_set(&pdev->dev, &omap_device_pm_domain);
return platform_device_add(pdev);
}

Expand Down
6 changes: 4 additions & 2 deletions drivers/acpi/acpi_lpss.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/platform_data/clk-lpss.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
#include <linux/delay.h>

Expand Down Expand Up @@ -642,11 +643,11 @@ static int acpi_lpss_platform_notify(struct notifier_block *nb,
switch (action) {
case BUS_NOTIFY_BOUND_DRIVER:
if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
pdev->dev.pm_domain = &acpi_lpss_pm_domain;
dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
break;
case BUS_NOTIFY_UNBOUND_DRIVER:
if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
pdev->dev.pm_domain = NULL;
dev_pm_domain_set(&pdev->dev, NULL);
break;
case BUS_NOTIFY_ADD_DEVICE:
if (pdata->dev_desc->flags & LPSS_LTR)
Expand All @@ -655,6 +656,7 @@ static int acpi_lpss_platform_notify(struct notifier_block *nb,
case BUS_NOTIFY_DEL_DEVICE:
if (pdata->dev_desc->flags & LPSS_LTR)
sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
break;
default:
break;
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/acpi/device_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/export.h>
#include <linux/mutex.h>
#include <linux/pm_qos.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>

#include "internal.h"
Expand Down Expand Up @@ -1058,7 +1059,7 @@ static void acpi_dev_pm_detach(struct device *dev, bool power_off)
struct acpi_device *adev = ACPI_COMPANION(dev);

if (adev && dev->pm_domain == &acpi_general_pm_domain) {
dev->pm_domain = NULL;
dev_pm_domain_set(dev, NULL);
acpi_remove_pm_notifier(adev);
if (power_off) {
/*
Expand Down Expand Up @@ -1115,7 +1116,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
return -EBUSY;

acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
dev->pm_domain = &acpi_general_pm_domain;
dev_pm_domain_set(dev, &acpi_general_pm_domain);
if (power_on) {
acpi_dev_pm_full_power(adev);
acpi_device_wakeup(adev, ACPI_STATE_S0, false);
Expand Down
7 changes: 5 additions & 2 deletions drivers/base/power/clock_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#include <linux/pm.h>
#include <linux/pm_clock.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>

#ifdef CONFIG_PM

Expand Down Expand Up @@ -323,7 +326,7 @@ static int pm_clk_notify(struct notifier_block *nb,
if (error)
break;

dev->pm_domain = clknb->pm_domain;
dev_pm_domain_set(dev, clknb->pm_domain);
if (clknb->con_ids[0]) {
for (con_id = clknb->con_ids; *con_id; con_id++)
pm_clk_add(dev, *con_id);
Expand All @@ -336,7 +339,7 @@ static int pm_clk_notify(struct notifier_block *nb,
if (dev->pm_domain != clknb->pm_domain)
break;

dev->pm_domain = NULL;
dev_pm_domain_set(dev, NULL);
pm_clk_destroy(dev);
break;
}
Expand Down
21 changes: 21 additions & 0 deletions drivers/base/power/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,24 @@ void dev_pm_domain_detach(struct device *dev, bool power_off)
dev->pm_domain->detach(dev, power_off);
}
EXPORT_SYMBOL_GPL(dev_pm_domain_detach);

/**
* dev_pm_domain_set - Set PM domain of a device.
* @dev: Device whose PM domain is to be set.
* @pd: PM domain to be set, or NULL.
*
* Sets the PM domain the device belongs to. The PM domain of a device needs
* to be set before its probe finishes (it's bound to a driver).
*
* This function must be called with the device lock held.
*/
void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
{
if (dev->pm_domain == pd)
return;

WARN(device_is_bound(dev),
"PM domains can only be changed for unbound devices\n");
dev->pm_domain = pd;
}
EXPORT_SYMBOL_GPL(dev_pm_domain_set);
4 changes: 2 additions & 2 deletions drivers/base/power/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,

spin_lock_irq(&dev->power.lock);

dev->pm_domain = &genpd->domain;
dev_pm_domain_set(dev, &genpd->domain);
if (dev->power.subsys_data->domain_data) {
gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
} else {
Expand Down Expand Up @@ -1529,7 +1529,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,

spin_lock_irq(&dev->power.lock);

dev->pm_domain = NULL;
dev_pm_domain_set(dev, NULL);
pdd = dev->power.subsys_data->domain_data;
list_del_init(&pdd->list_node);
gpd_data = to_gpd_data(pdd);
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpu/vga/vga_switcheroo.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,17 +652,17 @@ int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *
domain->ops.runtime_suspend = vga_switcheroo_runtime_suspend;
domain->ops.runtime_resume = vga_switcheroo_runtime_resume;

dev->pm_domain = domain;
dev_pm_domain_set(dev, domain);
return 0;
}
dev->pm_domain = NULL;
dev_pm_domain_set(dev, NULL);
return -EINVAL;
}
EXPORT_SYMBOL(vga_switcheroo_init_domain_pm_ops);

void vga_switcheroo_fini_domain_pm_ops(struct device *dev)
{
dev->pm_domain = NULL;
dev_pm_domain_set(dev, NULL);
}
EXPORT_SYMBOL(vga_switcheroo_fini_domain_pm_ops);

Expand Down Expand Up @@ -702,10 +702,10 @@ int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct
domain->ops = *dev->bus->pm;
domain->ops.runtime_resume = vga_switcheroo_runtime_resume_hdmi_audio;

dev->pm_domain = domain;
dev_pm_domain_set(dev, domain);
return 0;
}
dev->pm_domain = NULL;
dev_pm_domain_set(dev, NULL);
return -EINVAL;
}
EXPORT_SYMBOL(vga_switcheroo_init_domain_pm_optimus_hdmi_audio);
5 changes: 3 additions & 2 deletions drivers/misc/mei/pci-me.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <linux/jiffies.h>
#include <linux/interrupt.h>

#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>

#include <linux/mei.h>
Expand Down Expand Up @@ -439,7 +440,7 @@ static inline void mei_me_set_pm_domain(struct mei_device *dev)
dev->pg_domain.ops.runtime_resume = mei_me_pm_runtime_resume;
dev->pg_domain.ops.runtime_idle = mei_me_pm_runtime_idle;

pdev->dev.pm_domain = &dev->pg_domain;
dev_pm_domain_set(&pdev->dev, &dev->pg_domain);
}
}

Expand All @@ -451,7 +452,7 @@ static inline void mei_me_set_pm_domain(struct mei_device *dev)
static inline void mei_me_unset_pm_domain(struct mei_device *dev)
{
/* stop using pm callbacks if any */
dev->dev->pm_domain = NULL;
dev_pm_domain_set(dev->dev, NULL);
}
#endif /* CONFIG_PM_RUNTIME */

Expand Down
5 changes: 3 additions & 2 deletions drivers/misc/mei/pci-txe.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/jiffies.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>

#include <linux/mei.h>
Expand Down Expand Up @@ -387,7 +388,7 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev)
dev->pg_domain.ops.runtime_resume = mei_txe_pm_runtime_resume;
dev->pg_domain.ops.runtime_idle = mei_txe_pm_runtime_idle;

pdev->dev.pm_domain = &dev->pg_domain;
dev_pm_domain_set(&pdev->dev, &dev->pg_domain);
}
}

Expand All @@ -399,7 +400,7 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev)
static inline void mei_txe_unset_pm_domain(struct mei_device *dev)
{
/* stop using pm callbacks if any */
dev->dev->pm_domain = NULL;
dev_pm_domain_set(dev->dev, NULL);
}
#endif /* CONFIG_PM_RUNTIME */

Expand Down
3 changes: 3 additions & 0 deletions include/linux/pm_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,15 @@ static inline int of_genpd_add_provider_onecell(struct device_node *np,
#ifdef CONFIG_PM
extern int dev_pm_domain_attach(struct device *dev, bool power_on);
extern void dev_pm_domain_detach(struct device *dev, bool power_off);
extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
#else
static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
{
return -ENODEV;
}
static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
static inline void dev_pm_domain_set(struct device *dev,
struct dev_pm_domain *pd) {}
#endif

#endif /* _LINUX_PM_DOMAIN_H */

0 comments on commit 8a679b9

Please sign in to comment.