mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Brajesh Gupta <Brajesh.Gupta@imgtec.com>
To: Luigi Santivetti <Luigi.Santivetti@imgtec.com>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	"airlied@gmail.com" <airlied@gmail.com>,
	Alessio Belle <Alessio.Belle@imgtec.com>,
	"ryanbrue.dev@gmail.com" <ryanbrue.dev@gmail.com>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"sarah.walker@imgtec.com" <sarah.walker@imgtec.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"imagination@lists.freedesktop.org"
	<imagination@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] drm/imagination: Wait for the firmware's interrupts before stopping it
Date: Fri, 27 Nov 2026 13:20:23 +0000	[thread overview]
Message-ID: <0eb9e32b040c698a5c0fa9b68debbcbaa20e3c35.camel@imgtec.com> (raw)
In-Reply-To: <20261117-rbrue-suez-upstreaming-pvr-fw-irq-handshake-v2-1-780e31f25220@gmail.com>

On Tue, 2026-11-17 at 11:38 -0600, Ryan Brue wrote:
Hi Ryan,
> Once the firmware has acknowledged the POW_OFF request, a runtime suspend
> disables the IRQ and stops the firmware straight away, even if the
> firmware has raised an interrupt the host has not taken yet. On an
> MT8173 (GX6250, META firmware), the SIDEKICK_IDLE.GARTEN poll at the end
> of pvr_fw_stop() can then time out. The suspend fails with -ETIMEDOUT,
> runtime PM latches the error, and every later pvr_power_get() returns
> -EINVAL. The recovery reset that follows can fail the same way and lose
> the device.
> 
> The firmware counts the interrupts it raises in its OS data. Sample that
> count every time the host clears the firmware interrupt, and before
> disabling the IRQ for a runtime suspend, wait until the host has seen
> every interrupt the firmware counted, as Imagination's DDK does.
> Sampling in pvr_fw_irq_clear() rather than in the IRQ thread also
> covers the clears at probe and in a reset, whose interrupts never reach
> the thread, and picks up the zeroed counts after a hard reset.
> 
> Fixes: cc1aeedb98ad ("drm/imagination: Implement firmware infrastructure and META FW support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
> ---
> Found on an Amazon Fire HD 10 (2017), an MT8173 tablet that's not upstream
> yet. Its GX6250 (4.40.2.51) is not on the driver's list and runs with
> exp_hw_support. With a compositor running, about one desktop start in five
> hit this before the patch. A debug build that logs timed-out register polls
> named the poll, SIDEKICK_IDLE read 0x7a, GARTEN not idle.
> 
> Only META firmware on this one GPU was tested. Each failing suspend in the
> instrumented runs was off by exactly one interrupt (for example firmware
> 14320, host 14319). Why the META core then can't go idle is inferred from
> the DDK, which waits at this point; a fixed 1s delay in the same place
> also stopped the failures here.
> 
> The reset paths were tested with a debug build that triggers a soft
> reset and can drop one count before the reset's clear. With v1's
> sampling, the next runtime suspend then waited the full second and
> warned, twice out of two; with v2 it didn't. A hard reset of this GPU
> times out and loses it, so the hard-reset path is still untested at
> runtime.
> 
> It reproduces within a minute with vkcube --present_mode 1 on the
> compositor's display and the GPU's power/autosuspend_delay_ms set to 1.
> ---
> This patch was developed with the help of an LLM. I know there's a Mesa
> policy against LLM use for the powervr driver there, so if there's a policy
> for drm/imagination too, let me know.
> ---
> Changes in v2:
> - Sample the firmware's interrupt counts in pvr_fw_irq_clear() rather
>   than in the IRQ thread, so that the clears at probe and in
>   pvr_power_reset() update the host's copy too (Sashiko). This replaces
>   the zeroing in fw_osdata_init(): after a hard reset, the reset path's
>   clear samples the zeroed counts.
> - Fixes: cc1aeedb98ad, which put pvr_fw_stop() into the runtime suspend
>   path; at 727538a4bbff it only gated the clocks (Sashiko).
> - Rebased on drm-misc-next.
> - Link to v1: https://lore.kernel.org/r/20261110-rbrue-suez-upstreaming-pvr-fw-irq-handshake-v1-1-8872686d14d0@gmail.com
> ---
> With continuous rendering and a 1 ms autosuspend delay, a suspend failed
> this way within 22 seconds in 7 of 7 unpatched runs. Three of them were
> instrumented: between them they made 2711 suspends, and the three that
> failed were the only ones with an interrupt still outstanding after
> disable_irq(). With this patch, 8 of 8 runs lasted 60 seconds without a
> failure, and in a further run the wait was needed in 15 of 6925
> suspends, for at most 6.1 ms.
> ---
>  drivers/gpu/drm/imagination/pvr_device.h | 15 +++++++++++++++
>  drivers/gpu/drm/imagination/pvr_power.c  | 27 +++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_device.h b/drivers/gpu/drm/imagination/pvr_device.h
> index c246122b4caf..9d46c41140b7 100644
> --- a/drivers/gpu/drm/imagination/pvr_device.h
> +++ b/drivers/gpu/drm/imagination/pvr_device.h
> @@ -176,6 +176,12 @@ struct pvr_device {
>  	/** @irq: IRQ number. */
>  	int irq;
>  
> +	/**
> +	 * @fw_irq_count: Firmware interrupt counts, as last sampled after
> +	 *                clearing the interrupt.
> +	 */
> +	u32 fw_irq_count[MAX_THREAD_NUM];
> +
>  	/** @fwccb: Firmware CCB. */
>  	struct pvr_ccb fwccb;
>  
> @@ -813,6 +819,15 @@ static __always_inline void
>  pvr_fw_irq_clear(struct pvr_device *pvr_dev)
>  {
>  	pvr_dev->fw_dev.defs->irq_clear(pvr_dev);
> +
> +	/* A cleared interrupt counts as taken, whoever cleared it. */
> +	if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
> +		struct rogue_fwif_osdata *osdata = pvr_dev->fw_dev.fwif_osdata;
> +
> +		for (u32 i = 0; i < MAX_THREAD_NUM; i++)
> +			WRITE_ONCE(pvr_dev->fw_irq_count[i],
> +				   READ_ONCE(osdata->interrupt_count[i]));
> +	}
>  }
>  
>  #endif /* PVR_DEVICE_H */
> diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c
> index eb4b6ecdf4f4..2d0fbcf457f6 100644
> --- a/drivers/gpu/drm/imagination/pvr_power.c
> +++ b/drivers/gpu/drm/imagination/pvr_power.c
> @@ -89,6 +89,26 @@ pvr_power_request_pwr_off(struct pvr_device *pvr_dev)
>  	return pvr_power_send_command(pvr_dev, &pow_cmd);
>  }
>  
> +static bool
> +pvr_power_fw_irqs_taken(struct pvr_device *pvr_dev, u32 thread)
> +{
> +	return READ_ONCE(pvr_dev->fw_dev.fwif_osdata->interrupt_count[thread]) ==
> +	       READ_ONCE(pvr_dev->fw_irq_count[thread]);
> +}
> +
> +static void
> +pvr_power_wait_for_fw_irqs(struct pvr_device *pvr_dev)
> +{
> +	bool taken;
> +
> +	for (u32 i = 0; i < MAX_THREAD_NUM; i++) {
> +		if (read_poll_timeout(pvr_power_fw_irqs_taken, taken, taken, 100,
> +				      POWER_SYNC_TIMEOUT_US, false, pvr_dev, i))
> +			drm_warn(from_pvr_device(pvr_dev),
> +				 "FW thread %u has IRQs the host has not taken\n", i);
> +	}
> +}
> +
>  static int
>  pvr_power_fw_disable(struct pvr_device *pvr_dev, bool hard_reset, bool rpm_suspend)
>  {
> @@ -107,6 +127,13 @@ pvr_power_fw_disable(struct pvr_device *pvr_dev, bool hard_reset, bool rpm_suspe
>  	}
>  
>  	if (rpm_suspend) {
> +		/*
> +		 * Let the IRQ thread take every interrupt the firmware has raised
> +		 * before stopping it, as the vendor driver does. Without this, the
> +		 * META firmware processor can fail to go idle in pvr_fw_stop().
> +		 */
> +		pvr_power_wait_for_fw_irqs(pvr_dev);

You can drop reference to 'META' from the comment and make it applicable for all
firmware processors.

With that update, you can add my RB tag
Reviewed-by: Brajesh Gupta <brajesh.gupta@imgtec.com>

Thanks,
Brajesh
> +
>  		/* This also waits for late processing of GPU or firmware IRQs in other cores */
>  		disable_irq(pvr_dev->irq);
>  	}
> 
> ---
> base-commit: 41b5458595c60143d0ebaa1e032c9cda5d764dff
> change-id: 20261004-rbrue-suez-upstreaming-pvr-fw-irq-handshake-b80953eb904b
> 
> Best regards,


      reply	other threads:[~2026-11-27 13:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:38 Ryan Brue
2026-11-27 13:20 ` Brajesh Gupta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0eb9e32b040c698a5c0fa9b68debbcbaa20e3c35.camel@imgtec.com \
    --to=brajesh.gupta@imgtec.com \
    --cc=Alessio.Belle@imgtec.com \
    --cc=Luigi.Santivetti@imgtec.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=imagination@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=ryanbrue.dev@gmail.com \
    --cc=sarah.walker@imgtec.com \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®