2020-01-12 00:20:08

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH RFT v2 0/3] devfreq fixes for panfrost

These are a bunch of devfreq fixes for panfrost that came up in a
discussion with Robin Murphy during the code-review of the lima
devfreq patches: [0]

I am only able to test patch #1 properly because the only boards with
panfrost GPU that I have are using an Amlogic SoC. We don't have
support for the OPP tables or dynamic clock changes there yet.
So patches #2 and #3 are compile-tested only.


Changes since v1 at [1]
- added Steven's Reviewed-by to patch #2 (thank you!)
- only use dev_pm_opp_put_regulators() to clean up in
panfrost_devfreq_init() if regulators_opp_table is not NULL to fix
a potential crash inside dev_pm_opp_put_regulators() as spotted by
Steven Price (thank you!). While here, I also switched to "goto err"
pattern to avoid lines with more than 80 characters.

Known discussion topics (I have no way to test either of these, so I am
looking for help here):
- Steven Price reported the following message on his firefly (RK3288)
board:
"debugfs: Directory 'ffa30000.gpu-mali' with parent 'vdd_gpu' already
present!"
- Robin Murphy suggested that patch #1 may not work once the OPP table
for the GPU comes from SCMI


[0] https://patchwork.freedesktop.org/patch/346898/
[1] https://patchwork.freedesktop.org/series/71744/


Martin Blumenstingl (3):
drm/panfrost: enable devfreq based the "operating-points-v2" property
drm/panfrost: call dev_pm_opp_of_remove_table() in all error-paths
drm/panfrost: Use the mali-supply regulator for control again

drivers/gpu/drm/panfrost/panfrost_devfreq.c | 44 +++++++++++++++++----
drivers/gpu/drm/panfrost/panfrost_device.h | 1 +
2 files changed, 37 insertions(+), 8 deletions(-)

--
2.24.1


2020-01-12 00:20:08

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH RFT v2 1/3] drm/panfrost: enable devfreq based the "operating-points-v2" property

Decouple the check to see whether we want to enable devfreq for the GPU
from dev_pm_opp_set_regulators(). This is preparation work for adding
back support for regulator control (which means we need to call
dev_pm_opp_set_regulators() before dev_pm_opp_of_add_table(), which
means having a check for "is devfreq enabled" that is not tied to
dev_pm_opp_of_add_table() makes things easier).

Signed-off-by: Martin Blumenstingl <[email protected]>
---
drivers/gpu/drm/panfrost/panfrost_devfreq.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
index 413987038fbf..1471588763ce 100644
--- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c
+++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
@@ -5,6 +5,7 @@
#include <linux/platform_device.h>
#include <linux/pm_opp.h>
#include <linux/clk.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>

#include "panfrost_device.h"
@@ -79,10 +80,12 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
struct devfreq *devfreq;
struct thermal_cooling_device *cooling;

- ret = dev_pm_opp_of_add_table(dev);
- if (ret == -ENODEV) /* Optional, continue without devfreq */
+ if (!device_property_present(dev, "operating-points-v2"))
+ /* Optional, continue without devfreq */
return 0;
- else if (ret)
+
+ ret = dev_pm_opp_of_add_table(dev);
+ if (ret)
return ret;

panfrost_devfreq_reset(pfdev);
--
2.24.1

2020-01-12 00:20:08

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH RFT v2 3/3] drm/panfrost: Use the mali-supply regulator for control again

dev_pm_opp_set_rate() needs a reference to the regulator which should be
updated when updating the GPU frequency. The name of the regulator has
to be passed at initialization-time using dev_pm_opp_set_regulators().
Add the call to dev_pm_opp_set_regulators() so dev_pm_opp_set_rate()
will update the GPU regulator when updating the frequency (just like
we did this manually before when we open-coded dev_pm_opp_set_rate()).

Fixes: 221bc77914cbcc ("drm/panfrost: Use generic code for devfreq")
Reported-by: Robin Murphy <[email protected]>
Signed-off-by: Martin Blumenstingl <[email protected]>
---
drivers/gpu/drm/panfrost/panfrost_devfreq.c | 33 +++++++++++++++++----
drivers/gpu/drm/panfrost/panfrost_device.h | 1 +
2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
index 170f6c8c9651..3b580a0123e1 100644
--- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c
+++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
@@ -74,6 +74,7 @@ static struct devfreq_dev_profile panfrost_devfreq_profile = {
int panfrost_devfreq_init(struct panfrost_device *pfdev)
{
int ret;
+ struct opp_table *opp_table;
struct dev_pm_opp *opp;
unsigned long cur_freq;
struct device *dev = &pfdev->pdev->dev;
@@ -84,9 +85,22 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
/* Optional, continue without devfreq */
return 0;

+ opp_table = dev_pm_opp_set_regulators(dev,
+ (const char *[]){ "mali" },
+ 1);
+ if (IS_ERR(opp_table)) {
+ ret = PTR_ERR(opp_table);
+
+ /* Continue if the optional regulator is missing */
+ if (ret != -ENODEV)
+ return ret;
+ } else {
+ pfdev->devfreq.regulators_opp_table = opp_table;
+ }
+
ret = dev_pm_opp_of_add_table(dev);
if (ret)
- return ret;
+ goto err_opp_put_regulators;

panfrost_devfreq_reset(pfdev);

@@ -94,8 +108,8 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)

opp = devfreq_recommended_opp(dev, &cur_freq, 0);
if (IS_ERR(opp)) {
- dev_pm_opp_of_remove_table(dev);
- return PTR_ERR(opp);
+ ret = PTR_ERR(opp);
+ goto err_opp_of_remove_table;
}

panfrost_devfreq_profile.initial_freq = cur_freq;
@@ -105,8 +119,8 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
DEVFREQ_GOV_SIMPLE_ONDEMAND, NULL);
if (IS_ERR(devfreq)) {
DRM_DEV_ERROR(dev, "Couldn't initialize GPU devfreq\n");
- dev_pm_opp_of_remove_table(dev);
- return PTR_ERR(devfreq);
+ ret = PTR_ERR(devfreq);
+ goto err_opp_of_remove_table;
}
pfdev->devfreq.devfreq = devfreq;

@@ -117,6 +131,13 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
pfdev->devfreq.cooling = cooling;

return 0;
+
+err_opp_of_remove_table:
+ dev_pm_opp_of_remove_table(dev);
+err_opp_put_regulators:
+ if (pfdev->devfreq.regulators_opp_table)
+ dev_pm_opp_put_regulators(pfdev->devfreq.regulators_opp_table);
+ return ret;
}

void panfrost_devfreq_fini(struct panfrost_device *pfdev)
@@ -124,6 +145,8 @@ void panfrost_devfreq_fini(struct panfrost_device *pfdev)
if (pfdev->devfreq.cooling)
devfreq_cooling_unregister(pfdev->devfreq.cooling);
dev_pm_opp_of_remove_table(&pfdev->pdev->dev);
+ if (pfdev->devfreq.regulators_opp_table)
+ dev_pm_opp_put_regulators(pfdev->devfreq.regulators_opp_table);
}

void panfrost_devfreq_resume(struct panfrost_device *pfdev)
diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h
index 06713811b92c..4878b239e301 100644
--- a/drivers/gpu/drm/panfrost/panfrost_device.h
+++ b/drivers/gpu/drm/panfrost/panfrost_device.h
@@ -85,6 +85,7 @@ struct panfrost_device {

struct {
struct devfreq *devfreq;
+ struct opp_table *regulators_opp_table;
struct thermal_cooling_device *cooling;
ktime_t busy_time;
ktime_t idle_time;
--
2.24.1

2020-01-12 00:21:25

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH RFT v2 2/3] drm/panfrost: call dev_pm_opp_of_remove_table() in all error-paths

If devfreq_recommended_opp() fails we need to undo
dev_pm_opp_of_add_table() by calling dev_pm_opp_of_remove_table() (just
like we do it in the other error-path below).

Fixes: f3ba91228e8e91 ("drm/panfrost: Add initial panfrost driver")
Reviewed-by: Steven Price <[email protected]>
Signed-off-by: Martin Blumenstingl <[email protected]>
---
drivers/gpu/drm/panfrost/panfrost_devfreq.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
index 1471588763ce..170f6c8c9651 100644
--- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c
+++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
@@ -93,8 +93,10 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
cur_freq = clk_get_rate(pfdev->clock);

opp = devfreq_recommended_opp(dev, &cur_freq, 0);
- if (IS_ERR(opp))
+ if (IS_ERR(opp)) {
+ dev_pm_opp_of_remove_table(dev);
return PTR_ERR(opp);
+ }

panfrost_devfreq_profile.initial_freq = cur_freq;
dev_pm_opp_put(opp);
--
2.24.1

2020-02-22 19:43:38

by Martin Blumenstingl

[permalink] [raw]
Subject: Re: [PATCH RFT v2 0/3] devfreq fixes for panfrost

Hi Steven,

On Sun, Jan 12, 2020 at 1:16 AM Martin Blumenstingl
<[email protected]> wrote:
>
> These are a bunch of devfreq fixes for panfrost that came up in a
> discussion with Robin Murphy during the code-review of the lima
> devfreq patches: [0]
>
> I am only able to test patch #1 properly because the only boards with
> panfrost GPU that I have are using an Amlogic SoC. We don't have
> support for the OPP tables or dynamic clock changes there yet.
> So patches #2 and #3 are compile-tested only.
>
>
> Changes since v1 at [1]
> - added Steven's Reviewed-by to patch #2 (thank you!)
> - only use dev_pm_opp_put_regulators() to clean up in
> panfrost_devfreq_init() if regulators_opp_table is not NULL to fix
> a potential crash inside dev_pm_opp_put_regulators() as spotted by
> Steven Price (thank you!). While here, I also switched to "goto err"
> pattern to avoid lines with more than 80 characters.
>
> Known discussion topics (I have no way to test either of these, so I am
> looking for help here):
> - Steven Price reported the following message on his firefly (RK3288)
> board:
> "debugfs: Directory 'ffa30000.gpu-mali' with parent 'vdd_gpu' already
> present!"
> - Robin Murphy suggested that patch #1 may not work once the OPP table
> for the GPU comes from SCMI
>
>
> [0] https://patchwork.freedesktop.org/patch/346898/
> [1] https://patchwork.freedesktop.org/series/71744/
>
>
> Martin Blumenstingl (3):
> drm/panfrost: enable devfreq based the "operating-points-v2" property
> drm/panfrost: call dev_pm_opp_of_remove_table() in all error-paths
> drm/panfrost: Use the mali-supply regulator for control again
I don't have time to work on these patches in the near future
can you (or if someone else is interested then please speak up) please
take these over? you are familiar with the panfrost devfreq code and
you have at least one board where the GPU regulator actually has to
change the voltage (which means you can test this properly; on Amlogic
SoCs the GPU voltage is fixed across all frequencies).


Martin

2020-03-02 14:59:28

by Steven Price

[permalink] [raw]
Subject: Re: [PATCH RFT v2 0/3] devfreq fixes for panfrost

On 22/02/2020 19:42, Martin Blumenstingl wrote:
> Hi Steven,
>
> On Sun, Jan 12, 2020 at 1:16 AM Martin Blumenstingl
> <[email protected]> wrote:
>>
[...]
>>
>>
>> Martin Blumenstingl (3):
>> drm/panfrost: enable devfreq based the "operating-points-v2" property
>> drm/panfrost: call dev_pm_opp_of_remove_table() in all error-paths
>> drm/panfrost: Use the mali-supply regulator for control again
> I don't have time to work on these patches in the near future
> can you (or if someone else is interested then please speak up) please
> take these over? you are familiar with the panfrost devfreq code and
> you have at least one board where the GPU regulator actually has to
> change the voltage (which means you can test this properly; on Amlogic
> SoCs the GPU voltage is fixed across all frequencies).

Hi Martin,

Sorry for the slow response - yes I can pick this up. Although I've got
some other things to catch up with first.

Thanks,

Steve