diff mbox series

[v2,15/48] opp: Support set_opp() customization without requiring to use regulators

Message ID 20201217180638.22748-16-digetx@gmail.com
State New
Headers show
Series Introduce core voltage scaling for NVIDIA Tegra20/30 SoCs | expand

Commit Message

Dmitry Osipenko Dec. 17, 2020, 6:06 p.m. UTC
Support set_opp() customization without requiring to use regulators. This
is needed by drivers which want to use dev_pm_opp_set_rate() for changing
rates of a multiple clocks and don't need to touch regulator.

One example is NVIDIA Tegra30/114 SoCs which have two sibling 3D hardware
units which should be use to the same clock rate, meanwhile voltage
scaling is done using a power domain. In this case OPP table doesn't have
a regulator, causing a NULL dereference in _set_opp_custom().

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/opp/core.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Viresh Kumar Dec. 22, 2020, 9:01 a.m. UTC | #1
On 17-12-20, 21:06, Dmitry Osipenko wrote:
> Support set_opp() customization without requiring to use regulators. This

> is needed by drivers which want to use dev_pm_opp_set_rate() for changing

> rates of a multiple clocks and don't need to touch regulator.

> 

> One example is NVIDIA Tegra30/114 SoCs which have two sibling 3D hardware

> units which should be use to the same clock rate, meanwhile voltage

> scaling is done using a power domain. In this case OPP table doesn't have

> a regulator, causing a NULL dereference in _set_opp_custom().

> 

> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

> ---

>  drivers/opp/core.c | 16 ++++++++++++----

>  1 file changed, 12 insertions(+), 4 deletions(-)

> 

> diff --git a/drivers/opp/core.c b/drivers/opp/core.c

> index 3d02fe33630b..625dae7a5ecb 100644

> --- a/drivers/opp/core.c

> +++ b/drivers/opp/core.c

> @@ -828,17 +828,25 @@ static int _set_opp_custom(const struct opp_table *opp_table,

>  			   struct dev_pm_opp_supply *old_supply,

>  			   struct dev_pm_opp_supply *new_supply)

>  {

> -	struct dev_pm_set_opp_data *data;

> +	struct dev_pm_set_opp_data *data, tmp_data;

> +	unsigned int regulator_count;

>  	int size;

>  

> -	data = opp_table->set_opp_data;

> +	if (opp_table->set_opp_data) {

> +		data = opp_table->set_opp_data;

> +		regulator_count = opp_table->regulator_count;

> +	} else {

> +		data = &tmp_data;

> +		regulator_count = 0;

> +	}

> +

>  	data->regulators = opp_table->regulators;

> -	data->regulator_count = opp_table->regulator_count;

> +	data->regulator_count = regulator_count;

>  	data->clk = opp_table->clk;

>  	data->dev = dev;

>  

>  	data->old_opp.rate = old_freq;

> -	size = sizeof(*old_supply) * opp_table->regulator_count;

> +	size = sizeof(*old_supply) * regulator_count;

>  	if (!old_supply)

>  		memset(data->old_opp.supplies, 0, size);

>  	else


I don't see you making use of this in this patchset. How did you get this to
crash ?

-- 
viresh
Dmitry Osipenko Dec. 22, 2020, 7:18 p.m. UTC | #2
22.12.2020 12:01, Viresh Kumar пишет:
> On 17-12-20, 21:06, Dmitry Osipenko wrote:

>> Support set_opp() customization without requiring to use regulators. This

>> is needed by drivers which want to use dev_pm_opp_set_rate() for changing

>> rates of a multiple clocks and don't need to touch regulator.

>>

>> One example is NVIDIA Tegra30/114 SoCs which have two sibling 3D hardware

>> units which should be use to the same clock rate, meanwhile voltage

>> scaling is done using a power domain. In this case OPP table doesn't have

>> a regulator, causing a NULL dereference in _set_opp_custom().

>>

>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

>> ---

>>  drivers/opp/core.c | 16 ++++++++++++----

>>  1 file changed, 12 insertions(+), 4 deletions(-)

>>

>> diff --git a/drivers/opp/core.c b/drivers/opp/core.c

>> index 3d02fe33630b..625dae7a5ecb 100644

>> --- a/drivers/opp/core.c

>> +++ b/drivers/opp/core.c

>> @@ -828,17 +828,25 @@ static int _set_opp_custom(const struct opp_table *opp_table,

>>  			   struct dev_pm_opp_supply *old_supply,

>>  			   struct dev_pm_opp_supply *new_supply)

>>  {

>> -	struct dev_pm_set_opp_data *data;

>> +	struct dev_pm_set_opp_data *data, tmp_data;

>> +	unsigned int regulator_count;

>>  	int size;

>>  

>> -	data = opp_table->set_opp_data;

>> +	if (opp_table->set_opp_data) {

>> +		data = opp_table->set_opp_data;

>> +		regulator_count = opp_table->regulator_count;

>> +	} else {

>> +		data = &tmp_data;

>> +		regulator_count = 0;

>> +	}

>> +

>>  	data->regulators = opp_table->regulators;

>> -	data->regulator_count = opp_table->regulator_count;

>> +	data->regulator_count = regulator_count;

>>  	data->clk = opp_table->clk;

>>  	data->dev = dev;

>>  

>>  	data->old_opp.rate = old_freq;

>> -	size = sizeof(*old_supply) * opp_table->regulator_count;

>> +	size = sizeof(*old_supply) * regulator_count;

>>  	if (!old_supply)

>>  		memset(data->old_opp.supplies, 0, size);

>>  	else

> 

> I don't see you making use of this in this patchset. How did you get this to

> crash ?

> 


Please see patch 38 where 3d driver makes use of
devm_pm_opp_register_set_opp_helper().

The opp_table->set_opp_data=NULL and opp_table->regulator_count=-1 if
OPP table doesn't use a regulator, hence the crash happens.
Viresh Kumar Dec. 23, 2020, 6:01 a.m. UTC | #3
On 17-12-20, 21:06, Dmitry Osipenko wrote:
> Support set_opp() customization without requiring to use regulators. This
> is needed by drivers which want to use dev_pm_opp_set_rate() for changing
> rates of a multiple clocks and don't need to touch regulator.
> 
> One example is NVIDIA Tegra30/114 SoCs which have two sibling 3D hardware
> units which should be use to the same clock rate, meanwhile voltage
> scaling is done using a power domain. In this case OPP table doesn't have
> a regulator, causing a NULL dereference in _set_opp_custom().
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/opp/core.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 3d02fe33630b..625dae7a5ecb 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -828,17 +828,25 @@ static int _set_opp_custom(const struct opp_table *opp_table,
>  			   struct dev_pm_opp_supply *old_supply,
>  			   struct dev_pm_opp_supply *new_supply)
>  {
> -	struct dev_pm_set_opp_data *data;
> +	struct dev_pm_set_opp_data *data, tmp_data;
> +	unsigned int regulator_count;
>  	int size;
>  
> -	data = opp_table->set_opp_data;
> +	if (opp_table->set_opp_data) {
> +		data = opp_table->set_opp_data;
> +		regulator_count = opp_table->regulator_count;
> +	} else {
> +		data = &tmp_data;
> +		regulator_count = 0;
> +	}
> +

We should use the same structure, you can add some checks but not replace the
structure altogether.

>  	data->regulators = opp_table->regulators;
> -	data->regulator_count = opp_table->regulator_count;
> +	data->regulator_count = regulator_count;
>  	data->clk = opp_table->clk;
>  	data->dev = dev;
>  
>  	data->old_opp.rate = old_freq;
> -	size = sizeof(*old_supply) * opp_table->regulator_count;
> +	size = sizeof(*old_supply) * regulator_count;
>  	if (!old_supply)
>  		memset(data->old_opp.supplies, 0, size);
>  	else
Dmitry Osipenko Dec. 23, 2020, 8:38 p.m. UTC | #4
23.12.2020 09:01, Viresh Kumar пишет:
> On 17-12-20, 21:06, Dmitry Osipenko wrote:

>> Support set_opp() customization without requiring to use regulators. This

>> is needed by drivers which want to use dev_pm_opp_set_rate() for changing

>> rates of a multiple clocks and don't need to touch regulator.

>>

>> One example is NVIDIA Tegra30/114 SoCs which have two sibling 3D hardware

>> units which should be use to the same clock rate, meanwhile voltage

>> scaling is done using a power domain. In this case OPP table doesn't have

>> a regulator, causing a NULL dereference in _set_opp_custom().

>>

>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

>> ---

>>  drivers/opp/core.c | 16 ++++++++++++----

>>  1 file changed, 12 insertions(+), 4 deletions(-)

>>

>> diff --git a/drivers/opp/core.c b/drivers/opp/core.c

>> index 3d02fe33630b..625dae7a5ecb 100644

>> --- a/drivers/opp/core.c

>> +++ b/drivers/opp/core.c

>> @@ -828,17 +828,25 @@ static int _set_opp_custom(const struct opp_table *opp_table,

>>  			   struct dev_pm_opp_supply *old_supply,

>>  			   struct dev_pm_opp_supply *new_supply)

>>  {

>> -	struct dev_pm_set_opp_data *data;

>> +	struct dev_pm_set_opp_data *data, tmp_data;

>> +	unsigned int regulator_count;

>>  	int size;

>>  

>> -	data = opp_table->set_opp_data;

>> +	if (opp_table->set_opp_data) {

>> +		data = opp_table->set_opp_data;

>> +		regulator_count = opp_table->regulator_count;

>> +	} else {

>> +		data = &tmp_data;

>> +		regulator_count = 0;

>> +	}

>> +

> 

> We should use the same structure, you can add some checks but not replace the

> structure altogether.


Well, there is no "same structure", the opp_table->set_opp_data is NULL
there.

I can re-write it like this if it looks better to you:

static int _set_opp_custom(...)
{
	struct dev_pm_set_opp_data *data;
	unsigned int regulator_count;
	int size;

+	if (!opp_table->set_opp_data) {
+		struct dev_pm_set_opp_data freq_data = {};
+
+		freq_data.dev = dev;
+		freq_data.clk = opp_table->clk;
+		freq_data.new_opp.rate = freq;
+		freq_data.old_opp.rate = old_freq;
+
+		return opp_table->set_opp(&freq_data);
+	}
Viresh Kumar Dec. 24, 2020, 4:10 a.m. UTC | #5
On 23-12-20, 23:38, Dmitry Osipenko wrote:
> Well, there is no "same structure", the opp_table->set_opp_data is NULL
> there.

Right, I saw that yesterday. What I meant was that we need to start allocating
the structure for this case now.
diff mbox series

Patch

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 3d02fe33630b..625dae7a5ecb 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -828,17 +828,25 @@  static int _set_opp_custom(const struct opp_table *opp_table,
 			   struct dev_pm_opp_supply *old_supply,
 			   struct dev_pm_opp_supply *new_supply)
 {
-	struct dev_pm_set_opp_data *data;
+	struct dev_pm_set_opp_data *data, tmp_data;
+	unsigned int regulator_count;
 	int size;
 
-	data = opp_table->set_opp_data;
+	if (opp_table->set_opp_data) {
+		data = opp_table->set_opp_data;
+		regulator_count = opp_table->regulator_count;
+	} else {
+		data = &tmp_data;
+		regulator_count = 0;
+	}
+
 	data->regulators = opp_table->regulators;
-	data->regulator_count = opp_table->regulator_count;
+	data->regulator_count = regulator_count;
 	data->clk = opp_table->clk;
 	data->dev = dev;
 
 	data->old_opp.rate = old_freq;
-	size = sizeof(*old_supply) * opp_table->regulator_count;
+	size = sizeof(*old_supply) * regulator_count;
 	if (!old_supply)
 		memset(data->old_opp.supplies, 0, size);
 	else