Skip to content

Commit

Permalink
Merge branches 'pm-devfreq' and 'pm-domains'
Browse files Browse the repository at this point in the history
* pm-devfreq:
  PM / devfreq: add tracing for scheduling work
  trace: events: add devfreq trace event file
  PM / devfreq: rk3399_dmc: Pass ODT and auto power down parameters to TF-A.
  PM / devfreq: rockchip-dfi: Move GRF definitions to a common place.
  PM / devfreq: exynos-bus: Suspend all devices on system shutdown
  PM / devfreq: Fix static checker warning in try_then_request_governor
  PM / devfreq: Restart previous governor if new governor fails to start
  PM / devfreq: tegra: remove unneeded variable
  PM / devfreq: rockchip-dfi: remove unneeded semicolon
  PM / devfreq: rk3399_dmc: remove unneeded semicolon
  PM / devfreq: consistent indentation
  PM / devfreq: fix missing check of return value in devfreq_add_device()
  PM / devfreq: fix mem leak in devfreq_add_device()
  PM / devfreq: Use of_node_name_eq for node name comparisons

* pm-domains:
  PM / Domains: Allow to attach a CPU via genpd_dev_pm_attach_by_id|name()
  PM / Domains: Search for the CPU device outside the genpd lock
  PM / Domains: Drop unused in-parameter to some genpd functions
  PM / Domains: Use the base device for driver_deferred_probe_check_state()
  PM / Domains: Enable genpd_dev_pm_attach_by_id|name() for single PM domain
  PM / Domains: Allow OF lookup for multi PM domain case from ->attach_dev()
  PM / Domains: Don't kfree() the virtual device in the error path
  PM / Domains: remove unnecessary unlikely()
  • Loading branch information
Rafael J. Wysocki committed May 6, 2019
3 parents 7afc539 + e32d939 + f9ccd7c commit e07095c
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 102 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,7 @@ S: Maintained
F: drivers/devfreq/
F: include/linux/devfreq.h
F: Documentation/devicetree/bindings/devfreq/
F: include/trace/events/devfreq.h

DEVICE FREQUENCY EVENT (DEVFREQ-EVENT)
M: Chanwoo Choi <cw00.choi@samsung.com>
Expand Down
87 changes: 42 additions & 45 deletions drivers/base/power/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,9 @@ int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state)
if (unlikely(!genpd->set_performance_state))
return -EINVAL;

if (unlikely(!dev->power.subsys_data ||
!dev->power.subsys_data->domain_data)) {
WARN_ON(1);
if (WARN_ON(!dev->power.subsys_data ||
!dev->power.subsys_data->domain_data))
return -EINVAL;
}

genpd_lock(genpd);

Expand Down Expand Up @@ -1398,8 +1396,7 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron);

#endif /* CONFIG_PM_SLEEP */

static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
struct gpd_timing_data *td)
static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev)
{
struct generic_pm_domain_data *gpd_data;
int ret;
Expand All @@ -1414,9 +1411,6 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
goto err_put;
}

if (td)
gpd_data->td = *td;

gpd_data->base.dev = dev;
gpd_data->td.constraint_changed = true;
gpd_data->td.effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
Expand Down Expand Up @@ -1456,8 +1450,8 @@ static void genpd_free_dev_data(struct device *dev,
dev_pm_put_subsys_data(dev);
}

static void __genpd_update_cpumask(struct generic_pm_domain *genpd,
int cpu, bool set, unsigned int depth)
static void genpd_update_cpumask(struct generic_pm_domain *genpd,
int cpu, bool set, unsigned int depth)
{
struct gpd_link *link;

Expand All @@ -1468,7 +1462,7 @@ static void __genpd_update_cpumask(struct generic_pm_domain *genpd,
struct generic_pm_domain *master = link->master;

genpd_lock_nested(master, depth + 1);
__genpd_update_cpumask(master, cpu, set, depth + 1);
genpd_update_cpumask(master, cpu, set, depth + 1);
genpd_unlock(master);
}

Expand All @@ -1478,36 +1472,35 @@ static void __genpd_update_cpumask(struct generic_pm_domain *genpd,
cpumask_clear_cpu(cpu, genpd->cpus);
}

static void genpd_update_cpumask(struct generic_pm_domain *genpd,
struct device *dev, bool set)
static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu)
{
if (cpu >= 0)
genpd_update_cpumask(genpd, cpu, true, 0);
}

static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu)
{
if (cpu >= 0)
genpd_update_cpumask(genpd, cpu, false, 0);
}

static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev)
{
int cpu;

if (!genpd_is_cpu_domain(genpd))
return;
return -1;

for_each_possible_cpu(cpu) {
if (get_cpu_device(cpu) == dev) {
__genpd_update_cpumask(genpd, cpu, set, 0);
return;
}
if (get_cpu_device(cpu) == dev)
return cpu;
}
}

static void genpd_set_cpumask(struct generic_pm_domain *genpd,
struct device *dev)
{
genpd_update_cpumask(genpd, dev, true);
}

static void genpd_clear_cpumask(struct generic_pm_domain *genpd,
struct device *dev)
{
genpd_update_cpumask(genpd, dev, false);
return -1;
}

static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
struct gpd_timing_data *td)
struct device *base_dev)
{
struct generic_pm_domain_data *gpd_data;
int ret;
Expand All @@ -1517,17 +1510,19 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
return -EINVAL;

gpd_data = genpd_alloc_dev_data(dev, td);
gpd_data = genpd_alloc_dev_data(dev);
if (IS_ERR(gpd_data))
return PTR_ERR(gpd_data);

gpd_data->cpu = genpd_get_cpu(genpd, base_dev);

ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
if (ret)
goto out;

genpd_lock(genpd);

genpd_set_cpumask(genpd, dev);
genpd_set_cpumask(genpd, gpd_data->cpu);
dev_pm_domain_set(dev, &genpd->domain);

genpd->device_count++;
Expand Down Expand Up @@ -1555,7 +1550,7 @@ int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
int ret;

mutex_lock(&gpd_list_lock);
ret = genpd_add_device(genpd, dev, NULL);
ret = genpd_add_device(genpd, dev, dev);
mutex_unlock(&gpd_list_lock);

return ret;
Expand Down Expand Up @@ -1585,7 +1580,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd,
genpd->device_count--;
genpd->max_off_time_changed = true;

genpd_clear_cpumask(genpd, dev);
genpd_clear_cpumask(genpd, gpd_data->cpu);
dev_pm_domain_set(dev, NULL);

list_del_init(&pdd->list_node);
Expand Down Expand Up @@ -2261,7 +2256,7 @@ int of_genpd_add_device(struct of_phandle_args *genpdspec, struct device *dev)
goto out;
}

ret = genpd_add_device(genpd, dev, NULL);
ret = genpd_add_device(genpd, dev, dev);

out:
mutex_unlock(&gpd_list_lock);
Expand Down Expand Up @@ -2345,6 +2340,7 @@ EXPORT_SYMBOL_GPL(of_genpd_remove_last);

static void genpd_release_dev(struct device *dev)
{
of_node_put(dev->of_node);
kfree(dev);
}

Expand Down Expand Up @@ -2406,14 +2402,14 @@ static void genpd_dev_pm_sync(struct device *dev)
genpd_queue_power_off_work(pd);
}

static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
unsigned int index, bool power_on)
{
struct of_phandle_args pd_args;
struct generic_pm_domain *pd;
int ret;

ret = of_parse_phandle_with_args(np, "power-domains",
ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
"#power-domain-cells", index, &pd_args);
if (ret < 0)
return ret;
Expand All @@ -2425,12 +2421,12 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
mutex_unlock(&gpd_list_lock);
dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
__func__, PTR_ERR(pd));
return driver_deferred_probe_check_state(dev);
return driver_deferred_probe_check_state(base_dev);
}

dev_dbg(dev, "adding to PM domain %s\n", pd->name);

ret = genpd_add_device(pd, dev, NULL);
ret = genpd_add_device(pd, dev, base_dev);
mutex_unlock(&gpd_list_lock);

if (ret < 0) {
Expand Down Expand Up @@ -2481,7 +2477,7 @@ int genpd_dev_pm_attach(struct device *dev)
"#power-domain-cells") != 1)
return 0;

return __genpd_dev_pm_attach(dev, dev->of_node, 0, true);
return __genpd_dev_pm_attach(dev, dev, 0, true);
}
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);

Expand Down Expand Up @@ -2511,10 +2507,10 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
if (!dev->of_node)
return NULL;

/* Deal only with devices using multiple PM domains. */
/* Verify that the index is within a valid range. */
num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
"#power-domain-cells");
if (num_domains < 2 || index >= num_domains)
if (index >= num_domains)
return NULL;

/* Allocate and register device on the genpd bus. */
Expand All @@ -2525,15 +2521,16 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev));
virt_dev->bus = &genpd_bus_type;
virt_dev->release = genpd_release_dev;
virt_dev->of_node = of_node_get(dev->of_node);

ret = device_register(virt_dev);
if (ret) {
kfree(virt_dev);
put_device(virt_dev);
return ERR_PTR(ret);
}

/* Try to attach the device to the PM domain at the specified index. */
ret = __genpd_dev_pm_attach(virt_dev, dev->of_node, index, false);
ret = __genpd_dev_pm_attach(virt_dev, dev, index, false);
if (ret < 1) {
device_unregister(virt_dev);
return ret ? ERR_PTR(ret) : NULL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/devfreq/devfreq-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
}

list_for_each_entry(edev, &devfreq_event_list, node) {
if (!strcmp(edev->desc->name, node->name))
if (of_node_name_eq(node, edev->desc->name))
goto out;
}
edev = NULL;
Expand Down
Loading

0 comments on commit e07095c

Please sign in to comment.