* [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
@ 2026-11-27 3:39 Baihui Liang
2026-11-29 6:27 ` Gyeyoung Baek
2026-11-30 8:20 ` Brajesh Gupta
0 siblings, 2 replies; 6+ messages in thread
From: Baihui Liang @ 2026-11-27 3:39 UTC (permalink / raw)
To: 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
Cc: imagination, dri-devel, linux-kernel, linux-riscv, spacemit,
gye976, 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.
Factor the power-off sequence into a helper and call it from the
removal path with runtime PM disabled, bypassing the idle check.
Power off before destroying the job and free-list ID arrays, since
the IRQ handler can still process firmware commands during shutdown
and look up free-list IDs.
Signed-off-by: Baihui Liang <liangbaihui@linux.spacemit.com>
---
Changes in v3:
- Factor the shared power-off sequence out of the runtime suspend callback.
- On driver removal, disable runtime PM and bypass the firmware idle check.
Power off the GPU before destroying the job and free-list ID arrays.
- Link to v2: https://patch.msgid.link/20261111-img-pm-autosuspend-v2-1-427689f6f2f9@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 | 9 ++++-
drivers/gpu/drm/imagination/pvr_power.c | 72 +++++++++++++++++++++++++--------
drivers/gpu/drm/imagination/pvr_power.h | 2 +-
3 files changed, 63 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
index 5c965ef0274..bf70cd5c6df 100644
--- a/drivers/gpu/drm/imagination/pvr_drv.c
+++ b/drivers/gpu/drm/imagination/pvr_drv.c
@@ -1469,19 +1469,24 @@ static void pvr_remove(struct platform_device *plat_dev)
struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
+ pm_runtime_disable(drm_dev->dev);
+
WARN_ON(!xa_empty(&pvr_dev->job_ids));
WARN_ON(!xa_empty(&pvr_dev->free_list_ids));
+ pvr_power_device_shutdown(pvr_dev);
+
xa_destroy(&pvr_dev->job_ids);
xa_destroy(&pvr_dev->free_list_ids);
- pm_runtime_suspend(drm_dev->dev);
pvr_device_fini(pvr_dev);
drm_dev_unplug(drm_dev);
pvr_watchdog_fini(pvr_dev);
pvr_queue_device_fini(pvr_dev);
pvr_context_device_fini(pvr_dev);
pvr_power_domains_fini(pvr_dev);
+
+ pm_runtime_enable(drm_dev->dev);
}
static const struct pvr_device_data pvr_device_data_manual = {
@@ -1516,7 +1521,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..a0537a888d8 100644
--- a/drivers/gpu/drm/imagination/pvr_power.c
+++ b/drivers/gpu/drm/imagination/pvr_power.c
@@ -366,6 +366,50 @@ const struct pvr_power_sequence_ops pvr_power_sequence_ops_pwrseq = {
.power_off = pvr_power_off_sequence_pwrseq,
};
+static int
+pvr_power_device_off(struct pvr_device *pvr_dev)
+{
+ int err;
+
+ /* Caller must hold a drm_dev_enter() reference. */
+ if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
+ err = pvr_power_fw_disable(pvr_dev, false, true);
+ if (err)
+ return err;
+ }
+
+ return pvr_dev->device_data->pwr_ops->power_off(pvr_dev);
+}
+
+/* Power the device off on driver removal, skipping the idle check done by
+ * pvr_power_device_suspend() as the device won't be resumed. Runtime PM must be
+ * disabled by the caller.
+ */
+void
+pvr_power_device_shutdown(struct pvr_device *pvr_dev)
+{
+ struct drm_device *drm_dev = from_pvr_device(pvr_dev);
+ struct device *dev = drm_dev->dev;
+ int idx;
+ int err;
+
+ if (pm_runtime_status_suspended(dev))
+ return;
+
+ if (!drm_dev_enter(drm_dev, &idx)) {
+ drm_err(drm_dev, "Device is unplugged, cannot power it off\n");
+ return;
+ }
+
+ err = pvr_power_device_off(pvr_dev);
+ drm_dev_exit(idx);
+ if (!err)
+ err = pm_runtime_set_suspended(dev);
+
+ if (err)
+ drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
+}
+
int
pvr_power_device_suspend(struct device *dev)
{
@@ -378,15 +422,19 @@ pvr_power_device_suspend(struct device *dev)
if (!drm_dev_enter(drm_dev, &idx))
return -EIO;
- if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
- err = pvr_power_fw_disable(pvr_dev, false, true);
- if (err)
- goto err_drm_dev_exit;
- }
+ 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);
- err = pvr_dev->device_data->pwr_ops->power_off(pvr_dev);
+ return -EBUSY;
+ }
-err_drm_dev_exit:
+ err = pvr_power_device_off(pvr_dev);
drm_dev_exit(idx);
return err;
@@ -427,16 +475,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..dde765f18ce 100644
--- a/drivers/gpu/drm/imagination/pvr_power.h
+++ b/drivers/gpu/drm/imagination/pvr_power.h
@@ -16,9 +16,9 @@ void pvr_device_lost(struct pvr_device *pvr_dev);
bool pvr_power_is_idle(struct pvr_device *pvr_dev);
+void pvr_power_device_shutdown(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] 6+ messages in thread
* Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
2026-11-27 3:39 [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend Baihui Liang
@ 2026-11-29 6:27 ` Gyeyoung Baek
2026-11-29 13:40 ` Troy Mitchell
2026-11-30 8:20 ` Brajesh Gupta
1 sibling, 1 reply; 6+ messages in thread
From: Gyeyoung Baek @ 2026-11-29 6:27 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 Fri, Nov 27, 2026 at 12:41 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.
>
> Factor the power-off sequence into a helper and call it from the
> removal path with runtime PM disabled, bypassing the idle check.
> Power off before destroying the job and free-list ID arrays, since
> the IRQ handler can still process firmware commands during shutdown
> and look up free-list IDs.
>
This looks like the right fix to me. However, testing it on J722S
exposed a separate, pre-existing issue:
- The firmware doesn't seem to report ROGUE_FWIF_POW_IDLE after boot
until it has processed a command.
- Without this patch the GPU just stays active after probe; with it,
runtime suspend is retried indefinitely.
I've sent a fix for that separately [1]. I think that one should be
applied before this patch. With both, it works fine on J722S.
Two minor things:
- The Fixes tag seems to be missing (as sashiko suggested)
- The reproduction steps from v1 (repeated vulkaninfo on K3) are no
longer in the commit message. It would be good to add them back, so
it's clear when the issue occurs.
With these addressed:
Tested-by: Gyeyoung Baek <gye976@gmail.com> # J722S
Reviewed-by: Gyeyoung Baek <gye976@gmail.com>
[1] https://lore.kernel.org/dri-devel/20261129-pvr-fw-idle-after-boot-v1-1-f56572cc8f4c@gmail.com/
--
Thanks,
Gyeyoung
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
2026-11-29 6:27 ` Gyeyoung Baek
@ 2026-11-29 13:40 ` Troy Mitchell
2026-12-01 1:46 ` Baihui Liang
0 siblings, 1 reply; 6+ messages in thread
From: Troy Mitchell @ 2026-11-29 13:40 UTC (permalink / raw)
To: Gyeyoung Baek, 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
[-- Attachment #1.1: Type: text/plain, Size: 2259 bytes --]
Hi Gyeyoung and Baihui,
On Sun Nov 29, 2026 at 6:27 AM GMT, Gyeyoung Baek wrote:
> Hi Baihui,
>
> On Fri, Nov 27, 2026 at 12:41 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.
>>
>> Factor the power-off sequence into a helper and call it from the
>> removal path with runtime PM disabled, bypassing the idle check.
>> Power off before destroying the job and free-list ID arrays, since
>> the IRQ handler can still process firmware commands during shutdown
>> and look up free-list IDs.
>>
>
> This looks like the right fix to me. However, testing it on J722S
> exposed a separate, pre-existing issue:
> - The firmware doesn't seem to report ROGUE_FWIF_POW_IDLE after boot
> until it has processed a command.
> - Without this patch the GPU just stays active after probe; with it,
> runtime suspend is retried indefinitely.
>
> I've sent a fix for that separately [1]. I think that one should be
> applied before this patch. With both, it works fine on J722S.
Thanks for testing on J722S. I don't think this patch depends on [1],
though. The post-boot idle report is a separate, pre-existing issue.
So I'd leave the order to the maintainers, and Baihui doesn't need
to mention the dependency.
>
> Two minor things:
> - The Fixes tag seems to be missing (as sashiko suggested)
Agreed.
> - The reproduction steps from v1 (repeated vulkaninfo on K3) are no
> longer in the commit message. It would be good to add them back, so
> it's clear when the issue occurs.
Yes, below the --- line.
With these addressed:
Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> [1] https://lore.kernel.org/dri-devel/20261129-pvr-fw-idle-after-boot-v1-1-f56572cc8f4c@gmail.com/
--
Troy Mitchell
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
2026-11-27 3:39 [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend Baihui Liang
2026-11-29 6:27 ` Gyeyoung Baek
@ 2026-11-30 8:20 ` Brajesh Gupta
2026-12-01 2:48 ` Baihui Liang
1 sibling, 1 reply; 6+ messages in thread
From: Brajesh Gupta @ 2026-11-30 8:20 UTC (permalink / raw)
To: Luigi Santivetti, aou@eecs.berkeley.edu, tzimmermann@suse.de,
simona@ffwll.ch, dlan@kernel.org,
troy.mitchell@linux.spacemit.com, liangbaihui@linux.spacemit.com,
airlied@gmail.com, Alessio Belle, alex@ghiti.fr,
maarten.lankhorst@linux.intel.com, pjw@kernel.org,
mripard@kernel.org, palmer@dabbelt.com
Cc: dri-devel@lists.freedesktop.org, linux-riscv@lists.infradead.org,
gye976@gmail.com, imagination@lists.freedesktop.org,
linux-kernel@vger.kernel.org, spacemit@lists.linux.dev
On Fri, 2026-11-27 at 11:39 +0800, Baihui Liang wrote:
Hi Baihui,
> 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.
>
> Factor the power-off sequence into a helper and call it from the
> removal path with runtime PM disabled, bypassing the idle check.
> Power off before destroying the job and free-list ID arrays, since
> the IRQ handler can still process firmware commands during shutdown
> and look up free-list IDs.
>
> Signed-off-by: Baihui Liang <liangbaihui@linux.spacemit.com>
> ---
> Changes in v3:
> - Factor the shared power-off sequence out of the runtime suspend callback.
> - On driver removal, disable runtime PM and bypass the firmware idle check.
> Power off the GPU before destroying the job and free-list ID arrays.
> - Link to v2: https://patch.msgid.link/20261111-img-pm-autosuspend-v2-1-427689f6f2f9@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 | 9 ++++-
> drivers/gpu/drm/imagination/pvr_power.c | 72 +++++++++++++++++++++++++--------
> drivers/gpu/drm/imagination/pvr_power.h | 2 +-
> 3 files changed, 63 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
> index 5c965ef0274..bf70cd5c6df 100644
> --- a/drivers/gpu/drm/imagination/pvr_drv.c
> +++ b/drivers/gpu/drm/imagination/pvr_drv.c
> @@ -1469,19 +1469,24 @@ static void pvr_remove(struct platform_device *plat_dev)
> struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
> struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
>
> + pm_runtime_disable(drm_dev->dev);
> +
> WARN_ON(!xa_empty(&pvr_dev->job_ids));
> WARN_ON(!xa_empty(&pvr_dev->free_list_ids));
>
> + pvr_power_device_shutdown(pvr_dev);
> +
We could potentially drop the interface pvr_power_device_shutdown by rearranging
code as follows (please check my other comments first for this one):
pm_runtime_disable(drm_dev->dev);
if (!pm_runtime_status_suspended(dev)) {
int err = pvr_power_device_off(pvr_dev);
if (!err)
pm_runtime_set_suspended(dev);
else
drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
}
pm_runtime_enable(drm_dev->dev);
Please add following comment from the description to the code as well.
"Power off before destroying the job and free-list ID arrays, since
the IRQ handler can still process firmware commands during shutdown
and look up free-list IDs."
> xa_destroy(&pvr_dev->job_ids);
> xa_destroy(&pvr_dev->free_list_ids);
>
> - pm_runtime_suspend(drm_dev->dev);
> pvr_device_fini(pvr_dev);
> drm_dev_unplug(drm_dev);
> pvr_watchdog_fini(pvr_dev);
> pvr_queue_device_fini(pvr_dev);
> pvr_context_device_fini(pvr_dev);
> pvr_power_domains_fini(pvr_dev);
> +
> + pm_runtime_enable(drm_dev->dev);
> }
>
> static const struct pvr_device_data pvr_device_data_manual = {
> @@ -1516,7 +1521,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..a0537a888d8 100644
> --- a/drivers/gpu/drm/imagination/pvr_power.c
> +++ b/drivers/gpu/drm/imagination/pvr_power.c
> @@ -366,6 +366,50 @@ const struct pvr_power_sequence_ops pvr_power_sequence_ops_pwrseq = {
> .power_off = pvr_power_off_sequence_pwrseq,
> };
>
> +static int
> +pvr_power_device_off(struct pvr_device *pvr_dev)
> +{
> + int err;
> +
> + /* Caller must hold a drm_dev_enter() reference. */
> + if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
> + err = pvr_power_fw_disable(pvr_dev, false, true);
> + if (err)
> + return err;
> + }
> +
> + return pvr_dev->device_data->pwr_ops->power_off(pvr_dev);
> +}
> +
> +/* Power the device off on driver removal, skipping the idle check done by
> + * pvr_power_device_suspend() as the device won't be resumed. Runtime PM must be
> + * disabled by the caller.
> + */
> +void
> +pvr_power_device_shutdown(struct pvr_device *pvr_dev)
> +{
> + struct drm_device *drm_dev = from_pvr_device(pvr_dev);
> + struct device *dev = drm_dev->dev;
> + int idx;
> + int err;
> +
> + if (pm_runtime_status_suspended(dev))
> + return;
> +
> + if (!drm_dev_enter(drm_dev, &idx)) {
> + drm_err(drm_dev, "Device is unplugged, cannot power it off\n");
> + return;
> + }
> +
> + err = pvr_power_device_off(pvr_dev);
> + drm_dev_exit(idx);
> + if (!err)
> + err = pm_runtime_set_suspended(dev);
> +
> + if (err)
Change to 'else' part of the if condition.
> + drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
> +}
> +
> int
> pvr_power_device_suspend(struct device *dev)
> {
> @@ -378,15 +422,19 @@ pvr_power_device_suspend(struct device *dev)
> if (!drm_dev_enter(drm_dev, &idx))
> return -EIO;
>
> - if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
> - err = pvr_power_fw_disable(pvr_dev, false, true);
> - if (err)
> - goto err_drm_dev_exit;
> - }
> + if (READ_ONCE(pvr_dev->fw_dev.initialised) && !pvr_power_is_idle(pvr_dev)) {
Check for READ_ONCE(pvr_dev->fw_dev.initialised) can be dropped from the
condition.
> + /*
> + * 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);
>
> - err = pvr_dev->device_data->pwr_ops->power_off(pvr_dev);
> + return -EBUSY;
> + }
>
> -err_drm_dev_exit:
> + err = pvr_power_device_off(pvr_dev);
drm_dev_enter and drm_dev_exit can be moved under the interface
pvr_power_device_off to simplify pvr_power_device_suspend interface.
> drm_dev_exit(idx);
>
> return err;
> @@ -427,16 +475,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..dde765f18ce 100644
> --- a/drivers/gpu/drm/imagination/pvr_power.h
> +++ b/drivers/gpu/drm/imagination/pvr_power.h
> @@ -16,9 +16,9 @@ void pvr_device_lost(struct pvr_device *pvr_dev);
>
> bool pvr_power_is_idle(struct pvr_device *pvr_dev);
>
> +void pvr_power_device_shutdown(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 [flat|nested] 6+ messages in thread
* Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
2026-11-29 13:40 ` Troy Mitchell
@ 2026-12-01 1:46 ` Baihui Liang
0 siblings, 0 replies; 6+ messages in thread
From: Baihui Liang @ 2026-12-01 1:46 UTC (permalink / raw)
To: Troy Mitchell, gye976
Cc: alessio.belle, luigi.santivetti, maarten.lankhorst, mripard,
tzimmermann, airlied, simona, dlan, pjw, palmer, aou, alex,
imagination, dri-devel, linux-kernel, linux-riscv, spacemit
Hi Gyeyong and Troy,
On Sun Nov 29, 2026 at 9:40 PM CST, Troy Mitchell wrote:
> Hi Gyeyoung and Baihui,
>
> On Sun Nov 29, 2026 at 6:27 AM GMT, Gyeyoung Baek wrote:
> > Hi Baihui,
> >
> > On Fri, Nov 27, 2026 at 12:41 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.
> >>
> >> Factor the power-off sequence into a helper and call it from the
> >> removal path with runtime PM disabled, bypassing the idle check.
> >> Power off before destroying the job and free-list ID arrays, since
> >> the IRQ handler can still process firmware commands during shutdown
> >> and look up free-list IDs.
> >>
> >
> > This looks like the right fix to me. However, testing it on J722S
> > exposed a separate, pre-existing issue:
> > - The firmware doesn't seem to report ROGUE_FWIF_POW_IDLE after boot
> > until it has processed a command.
> > - Without this patch the GPU just stays active after probe; with it,
> > runtime suspend is retried indefinitely.
> >
> > I've sent a fix for that separately [1]. I think that one should be
> > applied before this patch. With both, it works fine on J722S.
>
> Thanks for testing on J722S. I don't think this patch depends on [1],
> though. The post-boot idle report is a separate, pre-existing issue.
> So I'd leave the order to the maintainers, and Baihui doesn't need
> to mention the dependency.
Agreed with Troy and thanks for testing on J722S and catching that
separate issue. I'll keep this patch standalone and leave the merge
order to the maintainers.
> >
> > Two minor things:
> > - The Fixes tag seems to be missing (as sashiko suggested)
>
> Agreed.
>
> > - The reproduction steps from v1 (repeated vulkaninfo on K3) are no
> > longer in the commit message. It would be good to add them back, so
> > it's clear when the issue occurs.
>
> Yes, below the --- line.
>
> With these addressed:
>
> Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
>
> > [1] https://lore.kernel.org/dri-devel/20261129-pvr-fw-idle-after-boot-v1-1-f56572cc8f4c@gmail.com/
Thanks both for the testing and review!
I'll add the Fixes tag and put the K3 reproduction steps back below
the '---' line in v4.
Since the maintainer also requested some code changes on this patch,
I'll drop the Tested-by and Reviewed-by tags for v4 and CC you both
once it's ready.
Best regards,
Baihui
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
2026-11-30 8:20 ` Brajesh Gupta
@ 2026-12-01 2:48 ` Baihui Liang
0 siblings, 0 replies; 6+ messages in thread
From: Baihui Liang @ 2026-12-01 2:48 UTC (permalink / raw)
To: Brajesh Gupta, Luigi.Santivetti, aou, tzimmermann, simona, dlan,
troy.mitchell, airlied, Alessio.Belle, alex, maarten.lankhorst,
pjw, mripard, palmer
Cc: dri-devel, linux-riscv, gye976, imagination, linux-kernel,
spacemit
Hi Brajesh,
Thanks for the review.
On Mon Nov 30, 2026 at 4:20 PM CST, Brajesh Gupta wrote:
[...]
> > diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
> > index 5c965ef0274..bf70cd5c6df 100644
> > --- a/drivers/gpu/drm/imagination/pvr_drv.c
> > +++ b/drivers/gpu/drm/imagination/pvr_drv.c
> > @@ -1469,19 +1469,24 @@ static void pvr_remove(struct platform_device *plat_dev)
> > struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
> > struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
> >
> > + pm_runtime_disable(drm_dev->dev);
> > +
> > WARN_ON(!xa_empty(&pvr_dev->job_ids));
> > WARN_ON(!xa_empty(&pvr_dev->free_list_ids));
> >
> > + pvr_power_device_shutdown(pvr_dev);
> > +
> We could potentially drop the interface pvr_power_device_shutdown by rearranging
> code as follows (please check my other comments first for this one):
>
> pm_runtime_disable(drm_dev->dev);
>
> if (!pm_runtime_status_suspended(dev)) {
> int err = pvr_power_device_off(pvr_dev);
> if (!err)
> pm_runtime_set_suspended(dev);
> else
> drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
> }
> pm_runtime_enable(drm_dev->dev);
Agreed, will inline it, and keep the drm_dev_enter()/drm_dev_exit() pair
inside pvr_power_device_off() as suggested below.
> Please add following comment from the description to the code as well.
> "Power off before destroying the job and free-list ID arrays, since
> the IRQ handler can still process firmware commands during shutdown
> and look up free-list IDs."
Will add.
> > xa_destroy(&pvr_dev->job_ids);
> > xa_destroy(&pvr_dev->free_list_ids);
> >
[...]
> > +{
> > + struct drm_device *drm_dev = from_pvr_device(pvr_dev);
> > + struct device *dev = drm_dev->dev;
> > + int idx;
> > + int err;
> > +
> > + if (pm_runtime_status_suspended(dev))
> > + return;
> > +
> > + if (!drm_dev_enter(drm_dev, &idx)) {
> > + drm_err(drm_dev, "Device is unplugged, cannot power it off\n");
> > + return;
> > + }
> > +
> > + err = pvr_power_device_off(pvr_dev);
> > + drm_dev_exit(idx);
> > + if (!err)
> > + err = pm_runtime_set_suspended(dev);
> > +
> > + if (err)
> Change to 'else' part of the if condition.
>
This one goes away with the inlining above — the function is removed.
> > + drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
> > +}
> > +
> > int
> > pvr_power_device_suspend(struct device *dev)
> > {
> > @@ -378,15 +422,19 @@ pvr_power_device_suspend(struct device *dev)
> > if (!drm_dev_enter(drm_dev, &idx))
> > return -EIO;
> >
> > - if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
> > - err = pvr_power_fw_disable(pvr_dev, false, true);
> > - if (err)
> > - goto err_drm_dev_exit;
> > - }
> > + if (READ_ONCE(pvr_dev->fw_dev.initialised) && !pvr_power_is_idle(pvr_dev)) {
> Check for READ_ONCE(pvr_dev->fw_dev.initialised) can be dropped from the
> condition.
I'd rather not drop it as-is: pvr_fw_fini() clears initialised and then frees
fwif_sysdata (pvr_fw.c:566,593) without NULLing the pointer, so on the probe
failure path (pvr_device_init() -> err_pm_runtime_put -> pm_runtime_put_sync_suspend())
this would be a NULL deref or a use-after-free.
How about moving the guard into pvr_power_is_idle() instead?
> > + /*
> > + * 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);
> >
> > - err = pvr_dev->device_data->pwr_ops->power_off(pvr_dev);
> > + return -EBUSY;
> > + }
> >
> > -err_drm_dev_exit:
> > + err = pvr_power_device_off(pvr_dev);
> drm_dev_enter and drm_dev_exit can be moved under the interface
> pvr_power_device_off to simplify pvr_power_device_suspend interface.
Will do, together with the inlining above.
Thanks,
Baihui
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-01 2:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 3:39 [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend Baihui Liang
2026-11-29 6:27 ` Gyeyoung Baek
2026-11-29 13:40 ` Troy Mitchell
2026-12-01 1:46 ` Baihui Liang
2026-11-30 8:20 ` Brajesh Gupta
2026-12-01 2:48 ` Baihui Liang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox