Commit 0f5c890e authored by Nishanth Menon's avatar Nishanth Menon Committed by Rafael J. Wysocki

PM / OPP: Remove cpufreq wrapper dependency on internal data organization

CPUFREQ custom functions for OPP (Operating Performance Points)
currently exist inside the OPP library. These custom functions currently
depend on internal data structures to pick up OPP information to create
the cpufreq table.  For example, the cpufreq table is created precisely
in the same order of how OPP entries are stored inside the list implementation.

This kind of tight interdependency is purely artificial since the same
functionality can be achieved using the generic OPP functions
meant to do the same. This interdependency also limits the independent
modification of cpufreq and OPP library.

So use the generic dev_pm_opp_find_freq_ceil function that achieves the
table organization as we currently use.

As a result of this, we dont need to use the internal device_opp
structure anymore, and we hence we can switch over to rcu lock instead
of the mutex holding the internal list lock.

This breaking of dependency on internal data structure imposes no change
to usage of these.

NOTE: This change is a precursor to moving this cpufreq specific logic
out of the generic library into cpufreq.

Cc: Kevin Hilman <khilman@deeprootsystems.com>
Signed-off-by: default avatarNishanth Menon <nm@ti.com>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent ca654dc3
...@@ -617,53 +617,54 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_disable); ...@@ -617,53 +617,54 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_disable);
* the table if any of the mentioned functions have been invoked in the interim. * the table if any of the mentioned functions have been invoked in the interim.
* *
* Locking: The internal device_opp and opp structures are RCU protected. * Locking: The internal device_opp and opp structures are RCU protected.
* To simplify the logic, we pretend we are updater and hold relevant mutex here * Since we just use the regular accessor functions to access the internal data
* Callers should ensure that this function is *NOT* called under RCU protection * structures, we use RCU read lock inside this function. As a result, users of
* or in contexts where mutex locking cannot be used. * this function DONOT need to use explicit locks for invoking.
*/ */
int dev_pm_opp_init_cpufreq_table(struct device *dev, int dev_pm_opp_init_cpufreq_table(struct device *dev,
struct cpufreq_frequency_table **table) struct cpufreq_frequency_table **table)
{ {
struct device_opp *dev_opp;
struct dev_pm_opp *opp; struct dev_pm_opp *opp;
struct cpufreq_frequency_table *freq_table; struct cpufreq_frequency_table *freq_table = NULL;
int i = 0; int i, max_opps, ret = 0;
unsigned long rate;
/* Pretend as if I am an updater */ rcu_read_lock();
mutex_lock(&dev_opp_list_lock);
dev_opp = find_device_opp(dev); max_opps = dev_pm_opp_get_opp_count(dev);
if (IS_ERR(dev_opp)) { if (max_opps <= 0) {
int r = PTR_ERR(dev_opp); ret = max_opps ? max_opps : -ENODATA;
mutex_unlock(&dev_opp_list_lock); goto out;
dev_err(dev, "%s: Device OPP not found (%d)\n", __func__, r);
return r;
} }
freq_table = kzalloc(sizeof(struct cpufreq_frequency_table) * freq_table = kzalloc(sizeof(*freq_table) * (max_opps + 1), GFP_KERNEL);
(dev_pm_opp_get_opp_count(dev) + 1), GFP_KERNEL);
if (!freq_table) { if (!freq_table) {
mutex_unlock(&dev_opp_list_lock); ret = -ENOMEM;
dev_warn(dev, "%s: Unable to allocate frequency table\n", goto out;
__func__);
return -ENOMEM;
} }
list_for_each_entry(opp, &dev_opp->opp_list, node) { for (i = 0, rate = 0; i < max_opps; i++, rate++) {
if (opp->available) { /* find next rate */
freq_table[i].driver_data = i; opp = dev_pm_opp_find_freq_ceil(dev, &rate);
freq_table[i].frequency = opp->rate / 1000; if (IS_ERR(opp)) {
i++; ret = PTR_ERR(opp);
goto out;
} }
freq_table[i].driver_data = i;
freq_table[i].frequency = rate / 1000;
} }
mutex_unlock(&dev_opp_list_lock);
freq_table[i].driver_data = i; freq_table[i].driver_data = i;
freq_table[i].frequency = CPUFREQ_TABLE_END; freq_table[i].frequency = CPUFREQ_TABLE_END;
*table = &freq_table[0]; *table = &freq_table[0];
return 0; out:
rcu_read_unlock();
if (ret)
kfree(freq_table);
return ret;
} }
EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table); EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment