Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/imagination: re-check firmware idle state before runtime suspend
@ 2026-11-11  9:26 Baihui Liang
  2026-11-21 17:57 ` Gyeyoung Baek
  0 siblings, 1 reply; 3+ messages in thread
From: Baihui Liang @ 2026-11-11  9:26 UTC (permalink / raw)
  To: Alessio Belle, Luigi Santivetti, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Yixun Lan,
	Troy Mitchell
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	imagination, dri-devel, linux-kernel, linux-riscv, spacemit,
	Baihui Liang

pvr_power_device_idle() rejects runtime suspend while the firmware
hasn't reached ROGUE_FWIF_POW_IDLE. The PM core doesn't reschedule
idle notification after rejection, so no further pm_runtime_put()
arrives on an idle GPU and the device stays powered indefinitely.

Move the idle check into pvr_power_device_suspend() and return -EBUSY
after pm_runtime_mark_last_busy() so the PM core reschedules the
autosuspend timer and retries until the firmware is idle.

Signed-off-by: Baihui Liang <liangbaihui@linux.spacemit.com>
---
Changes in v2:
- Move the pvr_power_is_idle() check into pvr_power_device_suspend()
  and return -EBUSY after pm_runtime_mark_last_busy().
- Drop pvr_power_device_idle() and pass NULL in RUNTIME_PM_OPS().
- Link to v1: https://patch.msgid.link/20261029-img-pm-autosuspend-v1-1-26851840a34e@linux.spacemit.com
---
 drivers/gpu/drm/imagination/pvr_drv.c   |  2 +-
 drivers/gpu/drm/imagination/pvr_power.c | 22 ++++++++++++----------
 drivers/gpu/drm/imagination/pvr_power.h |  1 -
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
index 5c965ef0274..541351d4bb6 100644
--- a/drivers/gpu/drm/imagination/pvr_drv.c
+++ b/drivers/gpu/drm/imagination/pvr_drv.c
@@ -1516,7 +1516,7 @@ static const struct of_device_id dt_match[] = {
 MODULE_DEVICE_TABLE(of, dt_match);
 
 static const struct dev_pm_ops pvr_pm_ops = {
-	RUNTIME_PM_OPS(pvr_power_device_suspend, pvr_power_device_resume, pvr_power_device_idle)
+	RUNTIME_PM_OPS(pvr_power_device_suspend, pvr_power_device_resume, NULL)
 };
 
 static struct platform_driver pvr_driver = {
diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c
index eb4b6ecdf4f..71267f714c7 100644
--- a/drivers/gpu/drm/imagination/pvr_power.c
+++ b/drivers/gpu/drm/imagination/pvr_power.c
@@ -378,6 +378,18 @@ pvr_power_device_suspend(struct device *dev)
 	if (!drm_dev_enter(drm_dev, &idx))
 		return -EIO;
 
+	if (READ_ONCE(pvr_dev->fw_dev.initialised) && !pvr_power_is_idle(pvr_dev)) {
+		/*
+		 * The firmware has not drained the GPU yet. Refresh last_busy so
+		 * the PM core reschedules the autosuspend and retries this callback
+		 * until the firmware becomes idle.
+		 */
+		pm_runtime_mark_last_busy(dev);
+		drm_dev_exit(idx);
+
+		return -EBUSY;
+	}
+
 	if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
 		err = pvr_power_fw_disable(pvr_dev, false, true);
 		if (err)
@@ -427,16 +439,6 @@ pvr_power_device_resume(struct device *dev)
 	return err;
 }
 
-int
-pvr_power_device_idle(struct device *dev)
-{
-	struct platform_device *plat_dev = to_platform_device(dev);
-	struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
-	struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
-
-	return pvr_power_is_idle(pvr_dev) ? 0 : -EBUSY;
-}
-
 static int
 pvr_power_clear_error(struct pvr_device *pvr_dev)
 {
diff --git a/drivers/gpu/drm/imagination/pvr_power.h b/drivers/gpu/drm/imagination/pvr_power.h
index c34252bda07..7d8df45c7b1 100644
--- a/drivers/gpu/drm/imagination/pvr_power.h
+++ b/drivers/gpu/drm/imagination/pvr_power.h
@@ -18,7 +18,6 @@ bool pvr_power_is_idle(struct pvr_device *pvr_dev);
 
 int pvr_power_device_suspend(struct device *dev);
 int pvr_power_device_resume(struct device *dev);
-int pvr_power_device_idle(struct device *dev);
 
 int pvr_power_reset(struct pvr_device *pvr_dev, bool hard_reset);
 

---
base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
change-id: 20261029-img-pm-autosuspend-7772d83416f7

Best regards,
--  
Baihui Liang <liangbaihui@linux.spacemit.com>


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/imagination: re-check firmware idle state before runtime suspend
  2026-11-11  9:26 [PATCH v2] drm/imagination: re-check firmware idle state before runtime suspend Baihui Liang
@ 2026-11-21 17:57 ` Gyeyoung Baek
  2026-11-23 10:08   ` Baihui Liang
  0 siblings, 1 reply; 3+ messages in thread
From: Gyeyoung Baek @ 2026-11-21 17:57 UTC (permalink / raw)
  To: Baihui Liang
  Cc: Alessio Belle, Luigi Santivetti, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Yixun Lan,
	Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, imagination, dri-devel, linux-kernel,
	linux-riscv, spacemit

Hi Baihui,

On Wed, Nov 11, 2026 at 6:29 PM Baihui Liang
<liangbaihui@linux.spacemit.com> wrote:
>
> pvr_power_device_idle() rejects runtime suspend while the firmware
> hasn't reached ROGUE_FWIF_POW_IDLE. The PM core doesn't reschedule
> idle notification after rejection, so no further pm_runtime_put()
> arrives on an idle GPU and the device stays powered indefinitely.
>
> Move the idle check into pvr_power_device_suspend() and return -EBUSY
> after pm_runtime_mark_last_busy() so the PM core reschedules the
> autosuspend timer and retries until the firmware is idle.

My understanding of Sashiko's point (correct me if I'm wrong):

- pvr_remove(): must power off unconditionally
- runtime suspend: power off only once idle (-EBUSY otherwise)

Since remove goes through the suspend callback, it can now skip the
power-off on -EBUSY.

Moving the idle check into runtime suspend looks right to me, so how
about keeping just the power-off logic in a common helper, called by
runtime suspend after the idle check and by remove directly? Roughly:

  pvr_power_device_off()        /* fw_disable + power_off */

  pvr_remove()
      pm_runtime_disable();
      if (!pm_runtime_status_suspended()) {
          pvr_power_device_off();
          pm_runtime_set_suspended();
      }
      pm_runtime_enable();      /* balance devm_pm_runtime_enable() */

-- 
Thanks,
Gyeyoung

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/imagination: re-check firmware idle state before runtime suspend
  2026-11-21 17:57 ` Gyeyoung Baek
@ 2026-11-23 10:08   ` Baihui Liang
  0 siblings, 0 replies; 3+ messages in thread
From: Baihui Liang @ 2026-11-23 10:08 UTC (permalink / raw)
  To: Gyeyoung Baek
  Cc: alessio.belle, luigi.santivetti, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, dlan, troy.mitchell, pjw, palmer,
	aou, alex, imagination, dri-devel, linux-kernel, linux-riscv,
	spacemit

On Sun Nov 22, 2026 at 1:57 AM CST, Gyeyoung Baek wrote:
> Hi Baihui,
>
> On Wed, Nov 11, 2026 at 6:29 PM Baihui Liang
> <liangbaihui@linux.spacemit.com> wrote:
> >
> > pvr_power_device_idle() rejects runtime suspend while the firmware
> > hasn't reached ROGUE_FWIF_POW_IDLE. The PM core doesn't reschedule
> > idle notification after rejection, so no further pm_runtime_put()
> > arrives on an idle GPU and the device stays powered indefinitely.
> >
> > Move the idle check into pvr_power_device_suspend() and return -EBUSY
> > after pm_runtime_mark_last_busy() so the PM core reschedules the
> > autosuspend timer and retries until the firmware is idle.
>
> My understanding of Sashiko's point (correct me if I'm wrong):
>
> - pvr_remove(): must power off unconditionally
> - runtime suspend: power off only once idle (-EBUSY otherwise)
>
> Since remove goes through the suspend callback, it can now skip the
> power-off on -EBUSY.

Exactly right.

> Moving the idle check into runtime suspend looks right to me, so how
> about keeping just the power-off logic in a common helper, called by
> runtime suspend after the idle check and by remove directly? Roughly:
>
>   pvr_power_device_off()        /* fw_disable + power_off */
>
>   pvr_remove()
>       pm_runtime_disable();
>       if (!pm_runtime_status_suspended()) {
>           pvr_power_device_off();
>           pm_runtime_set_suspended();
>       }
>       pm_runtime_enable();      /* balance devm_pm_runtime_enable() */

Agreed — that's the shape I ended up with: a common power-off helper called from runtime suspend after the idle check, and from pvr_remove() with runtime PM disabled around it.

Thanks,
Baihui

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-23 10:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  9:26 [PATCH v2] drm/imagination: re-check firmware idle state before runtime suspend Baihui Liang
2026-11-21 17:57 ` Gyeyoung Baek
2026-11-23 10:08   ` Baihui Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox