Re: [PATCH] opp: Return genpd virtual devices from dev_pm_opp_attach_genpd()

From: Viresh Kumar
Date: Wed Jul 17 2019 - 01:47:38 EST


On 11-07-19, 15:09, Rajendra Nayak wrote:
> Sorry for the delay

Same here :)

> I seem to have completely missed this patch.
> I just gave this a try and here are some observations,
>
> I have a case where I have one device with 2 power domains, one of them
> is scale-able (supports perf state) and the other one supports only being
> turned on and off.
>
> 1. In the driver I now need to use dev_pm_domain_attach_by_name/id to attach the
> power domain which supports only on/off and then use dev_pm_opp_attach_genpd()
> for the one which supports perf states.
>
> 2. My OPP table has only 1 required_opps, so the required_opp_count for the OPP table is 1.
> Now if my device tree has my scale-able powerdomain at index 1 (it works if its at index 0)
> then I end up with this error
>
> [ 2.858628] ufshcd-qcom 1d84000.ufshc: Index can't be greater than required-opp-count - 1, rpmh_pd (1 : 1)
>
> so it looks like a lot of the OPP core today just assumes that if a device has multiple power domains,
> all of them are scale-able which isn't necessarily true.

I don't think a lot of OPP core has these problems, but maybe only
this place. I was taking care of this since the beginning just forgot
it now.

What about this over this commit:

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index d76ead4eff4c..1f11f8c92337 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1789,13 +1789,16 @@ static void _opp_detach_genpd(struct opp_table *opp_table)
*
* This helper needs to be called once with a list of all genpd to attach.
* Otherwise the original device structure will be used instead by the OPP core.
+ *
+ * The order of entries in the names array must match the order in which
+ * "required-opps" are added in DT.
*/
struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
const char **names, struct device ***virt_devs)
{
struct opp_table *opp_table;
struct device *virt_dev;
- int index, ret = -EINVAL;
+ int index = 0, ret = -EINVAL;
const char **name = names;

opp_table = dev_pm_opp_get_opp_table(dev);
@@ -1821,14 +1824,6 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
goto unlock;

while (*name) {
- index = of_property_match_string(dev->of_node,
- "power-domain-names", *name);
- if (index < 0) {
- dev_err(dev, "Failed to find power domain: %s (%d)\n",
- *name, index);
- goto err;
- }
-
if (index >= opp_table->required_opp_count) {
dev_err(dev, "Index can't be greater than required-opp-count - 1, %s (%d : %d)\n",
*name, opp_table->required_opp_count, index);
@@ -1849,6 +1844,7 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
}

opp_table->genpd_virt_devs[index] = virt_dev;
+ index++;
name++;
}


--
viresh