PM / OPP: Move cpu specific code to opp/cpu.c
Move cpu device specific code out of generic opp library, and add it to cpu.c. Along with that, create a core-internal opp.h header, which will be used to share structures and function prototypes within opp core. Reviewed-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:

committed by
Rafael J. Wysocki

parent
33692dc381
commit
f59d3ee848
@@ -10,17 +10,18 @@
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/cpufreq.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/pm_opp.h>
|
||||
#include <linux/rcupdate.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "opp.h"
|
||||
|
||||
#ifdef CONFIG_CPU_FREQ
|
||||
|
||||
/**
|
||||
* dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
|
||||
* @dev: device for which we do this operation
|
||||
@@ -114,3 +115,154 @@ void dev_pm_opp_free_cpufreq_table(struct device *dev,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
|
||||
#endif /* CONFIG_CPU_FREQ */
|
||||
|
||||
/* Required only for V1 bindings, as v2 can manage it from DT itself */
|
||||
int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
|
||||
{
|
||||
struct device_list_opp *list_dev;
|
||||
struct device_opp *dev_opp;
|
||||
struct device *dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
dev_opp = _find_device_opp(cpu_dev);
|
||||
if (IS_ERR(dev_opp)) {
|
||||
ret = -EINVAL;
|
||||
goto out_rcu_read_unlock;
|
||||
}
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
if (cpu == cpu_dev->id)
|
||||
continue;
|
||||
|
||||
dev = get_cpu_device(cpu);
|
||||
if (!dev) {
|
||||
dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
|
||||
__func__, cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
list_dev = _add_list_dev(dev, dev_opp);
|
||||
if (!list_dev) {
|
||||
dev_err(dev, "%s: failed to add list-dev for cpu%d device\n",
|
||||
__func__, cpu);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
out_rcu_read_unlock:
|
||||
rcu_read_unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus);
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
void dev_pm_opp_of_cpumask_remove_table(cpumask_var_t cpumask)
|
||||
{
|
||||
struct device *cpu_dev;
|
||||
int cpu;
|
||||
|
||||
WARN_ON(cpumask_empty(cpumask));
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
cpu_dev = get_cpu_device(cpu);
|
||||
if (!cpu_dev) {
|
||||
pr_err("%s: failed to get cpu%d device\n", __func__,
|
||||
cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
dev_pm_opp_of_remove_table(cpu_dev);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);
|
||||
|
||||
int dev_pm_opp_of_cpumask_add_table(cpumask_var_t cpumask)
|
||||
{
|
||||
struct device *cpu_dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
WARN_ON(cpumask_empty(cpumask));
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
cpu_dev = get_cpu_device(cpu);
|
||||
if (!cpu_dev) {
|
||||
pr_err("%s: failed to get cpu%d device\n", __func__,
|
||||
cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = dev_pm_opp_of_add_table(cpu_dev);
|
||||
if (ret) {
|
||||
pr_err("%s: couldn't find opp table for cpu:%d, %d\n",
|
||||
__func__, cpu, ret);
|
||||
|
||||
/* Free all other OPPs */
|
||||
dev_pm_opp_of_cpumask_remove_table(cpumask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);
|
||||
|
||||
/*
|
||||
* Works only for OPP v2 bindings.
|
||||
*
|
||||
* cpumask should be already set to mask of cpu_dev->id.
|
||||
* Returns -ENOENT if operating-points-v2 bindings aren't supported.
|
||||
*/
|
||||
int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
|
||||
{
|
||||
struct device_node *np, *tmp_np;
|
||||
struct device *tcpu_dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
/* Get OPP descriptor node */
|
||||
np = _of_get_opp_desc_node(cpu_dev);
|
||||
if (!np) {
|
||||
dev_dbg(cpu_dev, "%s: Couldn't find opp node: %ld\n", __func__,
|
||||
PTR_ERR(np));
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* OPPs are shared ? */
|
||||
if (!of_property_read_bool(np, "opp-shared"))
|
||||
goto put_cpu_node;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
if (cpu == cpu_dev->id)
|
||||
continue;
|
||||
|
||||
tcpu_dev = get_cpu_device(cpu);
|
||||
if (!tcpu_dev) {
|
||||
dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
|
||||
__func__, cpu);
|
||||
ret = -ENODEV;
|
||||
goto put_cpu_node;
|
||||
}
|
||||
|
||||
/* Get OPP descriptor node */
|
||||
tmp_np = _of_get_opp_desc_node(tcpu_dev);
|
||||
if (!tmp_np) {
|
||||
dev_err(tcpu_dev, "%s: Couldn't find opp node: %ld\n",
|
||||
__func__, PTR_ERR(tmp_np));
|
||||
ret = PTR_ERR(tmp_np);
|
||||
goto put_cpu_node;
|
||||
}
|
||||
|
||||
/* CPUs are sharing opp node */
|
||||
if (np == tmp_np)
|
||||
cpumask_set_cpu(cpu, cpumask);
|
||||
|
||||
of_node_put(tmp_np);
|
||||
}
|
||||
|
||||
put_cpu_node:
|
||||
of_node_put(np);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user