The sampler must disable and re-enable counter sampling around
suspends, and must re-program the FW interface after a reset to
avoid losing data.

Signed-off-by: Lukas Zapolskas <[email protected]>
---
 drivers/gpu/drm/panthor/panthor_device.c |  7 ++-
 drivers/gpu/drm/panthor/panthor_perf.c   | 71 ++++++++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_perf.h   |  6 ++
 3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panthor/panthor_device.c 
b/drivers/gpu/drm/panthor/panthor_device.c
index 3063ffbead45..e6e279d91eae 100644
--- a/drivers/gpu/drm/panthor/panthor_device.c
+++ b/drivers/gpu/drm/panthor/panthor_device.c
@@ -162,6 +162,7 @@ static void panthor_device_reset_work(struct work_struct 
*work)
        if (!drm_dev_enter(&ptdev->base, &cookie))
                return;
 
+       panthor_perf_pre_reset(ptdev);
        panthor_sched_pre_reset(ptdev);
        panthor_fw_pre_reset(ptdev, true);
        panthor_mmu_pre_reset(ptdev);
@@ -171,6 +172,7 @@ static void panthor_device_reset_work(struct work_struct 
*work)
        ret = panthor_fw_post_reset(ptdev);
        atomic_set(&ptdev->reset.pending, 0);
        panthor_sched_post_reset(ptdev, ret != 0);
+       panthor_perf_post_reset(ptdev);
        drm_dev_exit(cookie);
 
        if (ret) {
@@ -549,8 +551,10 @@ int panthor_device_resume(struct device *dev)
                        ret = panthor_device_resume_hw_components(ptdev);
                }
 
-               if (!ret)
+               if (!ret) {
                        panthor_sched_resume(ptdev);
+                       panthor_perf_resume(ptdev);
+               }
 
                drm_dev_exit(cookie);
 
@@ -614,6 +618,7 @@ int panthor_device_suspend(struct device *dev)
                /* We prepare everything as if we were resetting the GPU.
                 * The end of the reset will happen in the resume path though.
                 */
+               panthor_perf_suspend(ptdev);
                panthor_sched_suspend(ptdev);
                panthor_fw_suspend(ptdev);
                panthor_mmu_suspend(ptdev);
diff --git a/drivers/gpu/drm/panthor/panthor_perf.c 
b/drivers/gpu/drm/panthor/panthor_perf.c
index e8f26805fe3a..208f93d516d4 100644
--- a/drivers/gpu/drm/panthor/panthor_perf.c
+++ b/drivers/gpu/drm/panthor/panthor_perf.c
@@ -1894,6 +1894,53 @@ void panthor_perf_session_destroy(struct panthor_file 
*pfile, struct panthor_per
        }
 }
 
+/**
+ * panthor_perf_suspend - Prepare the performance counter subsystem for system 
suspend.
+ * @ptdev: Panthor device.
+ *
+ * Indicate to the performance counters that the system is suspending.
+ *
+ * This function must not be used to handle MCU power state transitions: just 
before MCU goes
+ * from on to any inactive state, an automatic sample will be performed by the 
firmware, and
+ * the performance counter firmware state will be restored on warm boot.
+ *
+ */
+void panthor_perf_suspend(struct panthor_device *ptdev)
+{
+       struct panthor_perf *perf = ptdev->perf;
+       int ret;
+
+       if (!perf)
+               return;
+
+       ret = sampler_disable(&perf->sampler);
+
+       if (ret)
+               drm_warn(&ptdev->base, "Could not stop sampling before suspend, 
err = %d", ret);
+}
+
+/**
+ * panthor_perf_resume - Resume the performance counter subsystem after system 
resumption.
+ * @ptdev: Panthor device.
+ *
+ * Indicate to the performance counters that the system has resumed. This must 
not be used
+ * to handle MCU state transitions, for the same reasons as detailed in the 
kerneldoc for
+ * @panthor_perf_suspend.
+ */
+void panthor_perf_resume(struct panthor_device *ptdev)
+{
+       struct panthor_perf *perf = ptdev->perf;
+       int ret;
+
+       if (!perf)
+               return;
+
+       ret = sampler_enable(&perf->sampler);
+
+       if (ret)
+               drm_warn(&ptdev->base, "Could not resume sampling, err = %d", 
ret);
+}
+
 /**
  * panthor_perf_unplug - Terminate the performance counter subsystem.
  * @ptdev: Panthor device.
@@ -1927,3 +1974,27 @@ void panthor_perf_unplug(struct panthor_device *ptdev)
 
        ptdev->perf = NULL;
 }
+
+void panthor_perf_pre_reset(struct panthor_device *ptdev)
+{
+       struct panthor_perf_sampler *sampler;
+
+       if (drm_WARN_ON_ONCE(&ptdev->base, !ptdev->perf))
+               return;
+
+       sampler = &ptdev->perf->sampler;
+
+       sampler_disable(sampler);
+}
+
+void panthor_perf_post_reset(struct panthor_device *ptdev)
+{
+       struct panthor_perf_sampler *sampler;
+
+       if (drm_WARN_ON_ONCE(&ptdev->base, !ptdev->perf))
+               return;
+
+       sampler = &ptdev->perf->sampler;
+
+       sampler_enable(sampler);
+}
diff --git a/drivers/gpu/drm/panthor/panthor_perf.h 
b/drivers/gpu/drm/panthor/panthor_perf.h
index 5a14854368eb..1044b0a1cfaa 100644
--- a/drivers/gpu/drm/panthor/panthor_perf.h
+++ b/drivers/gpu/drm/panthor/panthor_perf.h
@@ -14,6 +14,8 @@ struct panthor_file;
 struct panthor_perf;
 
 int panthor_perf_init(struct panthor_device *ptdev);
+void panthor_perf_suspend(struct panthor_device *ptdev);
+void panthor_perf_resume(struct panthor_device *ptdev);
 void panthor_perf_unplug(struct panthor_device *ptdev);
 
 int panthor_perf_session_setup(struct drm_file *file, struct panthor_perf 
*perf,
@@ -30,5 +32,9 @@ void panthor_perf_session_destroy(struct panthor_file *pfile, 
struct panthor_per
 
 void panthor_perf_report_irq(struct panthor_device *ptdev, u32 status);
 
+void panthor_perf_pre_reset(struct panthor_device *ptdev);
+
+void panthor_perf_post_reset(struct panthor_device *ptdev);
+
 #endif /* __PANTHOR_PERF_H__ */
 
-- 
2.33.0.dirty

Reply via email to