From: Christian Gmeiner <[email protected]>

etnaviv_gpu_bind(..) registers the cooling device before the workqueue,
the scheduler and the clocks are set up, and etnaviv_gpu_unbind(..)
unregisters it after they are gone. So a cooling request can come in
while the GPU is not set up yet or already torn down.

With CONFIG_PM the GPU is runtime suspended at these points and the
request only stores the new state. Without CONFIG_PM
pm_runtime_suspended(..) always returns false and the request accesses
a GPU whose clocks are off.

Register the cooling device as the last step of bind and unregister it
as the first step of unbind. A following patch makes cooling requests
wait for the queued jobs and needs this order too.

Fixes: bcdfb5e56dc5 ("drm/etnaviv: add etnaviv cooling device")
Cc: [email protected]
Signed-off-by: Christian Gmeiner <[email protected]>
---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 42 ++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c 
b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
index 2a15ae6135f5..2a56bdf2510a 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
@@ -1808,19 +1808,9 @@ static int etnaviv_gpu_bind(struct device *dev, struct 
device *master,
        struct etnaviv_gpu *gpu = dev_get_drvdata(dev);
        int ret;
 
-       if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL)) {
-               gpu->cooling = thermal_of_cooling_device_register(dev->of_node, 
0,
-                                                                 dev_name(dev),
-                                                                 gpu, 
&cooling_ops);
-               if (IS_ERR(gpu->cooling))
-                       return PTR_ERR(gpu->cooling);
-       }
-
        gpu->wq = alloc_ordered_workqueue(dev_name(dev), 0);
-       if (!gpu->wq) {
-               ret = -ENOMEM;
-               goto out_thermal;
-       }
+       if (!gpu->wq)
+               return -ENOMEM;
 
        ret = etnaviv_sched_init(gpu);
        if (ret)
@@ -1840,20 +1830,32 @@ static int etnaviv_gpu_bind(struct device *dev, struct 
device *master,
        INIT_WORK(&gpu->sync_point_work, sync_point_worker);
        init_waitqueue_head(&gpu->fence_event);
 
+       if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL)) {
+               gpu->cooling = thermal_of_cooling_device_register(dev->of_node, 
0,
+                                                                 dev_name(dev),
+                                                                 gpu, 
&cooling_ops);
+               if (IS_ERR(gpu->cooling)) {
+                       ret = PTR_ERR(gpu->cooling);
+                       gpu->cooling = NULL;
+                       goto out_clk;
+               }
+       }
+
        priv->gpu[priv->num_gpus++] = gpu;
 
        return 0;
 
+out_clk:
+       gpu->drm = NULL;
+       if (!IS_ENABLED(CONFIG_PM))
+               etnaviv_gpu_clk_disable(gpu);
+
 out_sched:
        etnaviv_sched_fini(gpu);
 
 out_workqueue:
        destroy_workqueue(gpu->wq);
 
-out_thermal:
-       if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL))
-               thermal_cooling_device_unregister(gpu->cooling);
-
        return ret;
 }
 
@@ -1864,6 +1866,10 @@ static void etnaviv_gpu_unbind(struct device *dev, 
struct device *master,
 
        DBG("%s", dev_name(gpu->dev));
 
+       if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL))
+               thermal_cooling_device_unregister(gpu->cooling);
+       gpu->cooling = NULL;
+
        destroy_workqueue(gpu->wq);
 
        etnaviv_sched_fini(gpu);
@@ -1887,10 +1893,6 @@ static void etnaviv_gpu_unbind(struct device *dev, 
struct device *master,
 
        gpu->drm = NULL;
        xa_destroy(&gpu->user_fences);
-
-       if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL))
-               thermal_cooling_device_unregister(gpu->cooling);
-       gpu->cooling = NULL;
 }
 
 static const struct component_ops gpu_ops = {

-- 
2.56.0

Reply via email to