From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Nicolas Frattaroli <frattaroli.nicolas@gmail.com>,
Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Hans Verkuil <hverkuil@kernel.org>,
Boris Brezillon <boris.brezillon@collabora.com>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Ulf Hansson <ulfh@kernel.org>
Cc: linux-media@vger.kernel.org, iommu@lists.linux.dev,
linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Sergei Khomenkov <shomenkow@gmail.com>,
Tharit Tangkijwanichakul <tharitt97@gmail.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH v4 17/18] media: verisilicon: Reset the RK3588 AV1 decoder after an error
Date: Sun, 06 Dec 2026 05:57:52 +0000 [thread overview]
Message-ID: <20261206-hantro-robust-v4-17-b99d33a5ec6d@gmail.com> (raw)
In-Reply-To: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
Nothing resets the AV1 core after an error interrupt, and the frames
after it time out: 50 watchdog timeouts in one AV1 test run.
Reset the core from the watchdog work as the vendor driver does: its AXI
and APB lines only, with the bus of its power domain stopped and its
interrupt masked. A reset of all four lines without the bus stop left
the domain unable to go idle, and an SError followed.
Stop a core still running after a timeout with its abort first, as
hantro_g2_reset() does: a reset during its bus transfers corrupted
memory. If it does not stop, refuse further jobs.
Attach the empty IOMMU domain for the reset, so that unmaps of other
contexts do not write the IOMMU of the stopped bus; the vendor driver
blocks them with a lock. With two decoders, a reset failed to idle the
domain, and a write from an unmap then raised an SError. If the bus
does not stop or restart, keep the empty domain and refuse further
jobs.
Fixes: 003afda97c65 ("media: verisilicon: Enable AV1 decoder on rk3588")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/media/platform/verisilicon/hantro.h | 7 +-
drivers/media/platform/verisilicon/hantro_drv.c | 51 ++++++++++---
drivers/media/platform/verisilicon/hantro_hw.h | 5 +-
.../platform/verisilicon/rockchip_vpu981_regs.h | 3 +
.../media/platform/verisilicon/rockchip_vpu_hw.c | 86 +++++++++++++++++++++-
5 files changed, 140 insertions(+), 12 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index 5a9acc8c82a8..2d021c98f085 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -180,6 +180,7 @@ hantro_vdev_to_func(struct video_device *vdev)
* dev_ macros.
* @clocks: Array of clock handles.
* @resets: Array of reset handles.
+ * @core_resets: AXI and APB resets of the core, without the bus interfaces.
* @reg_base: Mapped address of VPU registers.
* @enc_base: Mapped address of VPU encoder register for convenience.
* @dec_base: Mapped address of VPU decoder register for convenience.
@@ -190,7 +191,9 @@ hantro_vdev_to_func(struct video_device *vdev)
* @watchdog_work: Delayed work for hardware timeout handling.
* @empty_domain: Empty IOMMU domain, used to reinitialize the IOMMU after
* a reset of the core. NULL if not needed.
- * @iommu_lost: The IOMMU couldn't be reinitialized, no job can run.
+ * @iommu_lost: The IOMMU couldn't be reinitialized, or the bus of the
+ * core hangs: no job can run.
+ * @error_reset: The watchdog was queued by hantro_irq_reset().
*/
struct hantro_dev {
struct v4l2_device v4l2_dev;
@@ -202,6 +205,7 @@ struct hantro_dev {
struct device *dev;
struct clk_bulk_data *clocks;
struct reset_control *resets;
+ struct reset_control_bulk_data core_resets[2];
void __iomem *reg_base;
void __iomem *enc_base;
void __iomem *dec_base;
@@ -212,6 +216,7 @@ struct hantro_dev {
struct delayed_work watchdog_work;
struct iommu_domain *empty_domain;
bool iommu_lost;
+ bool error_reset;
};
/**
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 26b273cd339d..bb611b414e75 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -117,10 +117,12 @@ void hantro_irq_done(struct hantro_dev *vpu,
/*
* Pulsing the reset lines of a core can reset its IOMMU behind the IOMMU
* driver. Attaching and detaching the empty domain makes the driver reprogram
- * it; the default domain keeps its mappings. A failed attach may leave the
- * IOMMU without translation, so no further job may run.
+ * it; the default domain keeps its mappings. While the empty domain is
+ * attached, maps and unmaps of the default domain leave the IOMMU alone. A
+ * failed attach may leave the IOMMU without translation, so no further job may
+ * run.
*/
-int hantro_iommu_restore(struct hantro_dev *vpu)
+int hantro_iommu_park(struct hantro_dev *vpu)
{
int ret;
@@ -132,29 +134,55 @@ int hantro_iommu_restore(struct hantro_dev *vpu)
dev_err(vpu->dev, "Failed to reinitialize the IOMMU (%d), refusing further jobs\n",
ret);
vpu->iommu_lost = true;
- return ret;
}
- iommu_detach_device(vpu->empty_domain, vpu->dev);
- return 0;
+ return ret;
+}
+
+void hantro_iommu_unpark(struct hantro_dev *vpu)
+{
+ if (vpu->empty_domain)
+ iommu_detach_device(vpu->empty_domain, vpu->dev);
+}
+
+int hantro_iommu_restore(struct hantro_dev *vpu)
+{
+ int ret = hantro_iommu_park(vpu);
+
+ if (!ret)
+ hantro_iommu_unpark(vpu);
+ return ret;
}
void hantro_watchdog(struct work_struct *work)
{
struct hantro_dev *vpu;
struct hantro_ctx *ctx;
+ bool error_reset;
vpu = container_of(to_delayed_work(work),
struct hantro_dev, watchdog_work);
+ error_reset = vpu->error_reset;
+ vpu->error_reset = false;
ctx = v4l2_m2m_get_curr_priv(vpu->m2m_dev);
if (ctx) {
- vpu_err("frame processing timed out!\n");
+ if (!error_reset)
+ vpu_err("frame processing timed out!\n");
if (ctx->codec_ops->reset)
ctx->codec_ops->reset(ctx);
hantro_job_finish(ctx, VB2_BUF_STATE_ERROR);
}
}
+/* For a failed job whose core needs a reset: the watchdog work resets it and ends the job. */
+void hantro_irq_reset(struct hantro_dev *vpu)
+{
+ if (cancel_delayed_work(&vpu->watchdog_work)) {
+ vpu->error_reset = true;
+ schedule_delayed_work(&vpu->watchdog_work, 0);
+ }
+}
+
void hantro_start_prepare_run(struct hantro_ctx *ctx)
{
struct vb2_v4l2_buffer *src_buf;
@@ -1152,7 +1180,12 @@ static void hantro_disable_runtime_pm(struct hantro_dev *vpu)
static void hantro_free_empty_domain(void *data)
{
- iommu_domain_free(data);
+ struct hantro_dev *vpu = data;
+
+ /* Still attached after a failed reset */
+ if (iommu_get_domain_for_dev(vpu->dev) == vpu->empty_domain)
+ hantro_iommu_unpark(vpu);
+ iommu_domain_free(vpu->empty_domain);
}
static int hantro_alloc_empty_domain(struct hantro_dev *vpu)
@@ -1178,7 +1211,7 @@ static int hantro_alloc_empty_domain(struct hantro_dev *vpu)
vpu->empty_domain = domain;
ret = devm_add_action_or_reset(vpu->dev, hantro_free_empty_domain,
- domain);
+ vpu);
if (ret)
return ret;
diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h
index d3c36948208d..b63893a17df0 100644
--- a/drivers/media/platform/verisilicon/hantro_hw.h
+++ b/drivers/media/platform/verisilicon/hantro_hw.h
@@ -382,7 +382,7 @@ struct hantro_postproc_ops {
* should be programmed and started. Returns zero if OK, a
* negative value in error cases.
* @done: Read back processing results and additional data from hardware.
- * @reset: Reset the hardware in case of a timeout.
+ * @reset: Reset the hardware in case of a timeout or hantro_irq_reset().
*/
struct hantro_codec_ops {
int (*init)(struct hantro_ctx *ctx);
@@ -431,12 +431,15 @@ extern const struct hantro_postproc_ops rockchip_vpu981_postproc_ops;
extern const u32 hantro_vp8_dec_mc_filter[8][6];
void hantro_watchdog(struct work_struct *work);
+int hantro_iommu_park(struct hantro_dev *vpu);
+void hantro_iommu_unpark(struct hantro_dev *vpu);
int hantro_iommu_restore(struct hantro_dev *vpu);
void hantro_irq_done(struct hantro_dev *vpu,
enum vb2_buffer_state result);
void hantro_start_prepare_run(struct hantro_ctx *ctx);
void hantro_end_prepare_run(struct hantro_ctx *ctx);
void hantro_abort_prepare_run(struct hantro_ctx *ctx);
+void hantro_irq_reset(struct hantro_dev *vpu);
irqreturn_t hantro_g1_irq(int irq, void *dev_id);
void hantro_g1_reset(struct hantro_ctx *ctx);
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h b/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h
index e4008da64f19..b88df093b5e2 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h
@@ -21,6 +21,9 @@
#define AV1_REG_INTERRUPT AV1_SWREG(1)
#define AV1_REG_INTERRUPT_DEC_RDY_INT BIT(12)
+#define AV1_REG_INTERRUPT_DEC_ABORT_E BIT(5)
+#define AV1_REG_INTERRUPT_DEC_IRQ_DIS BIT(4)
+#define AV1_REG_INTERRUPT_DEC_E BIT(0)
#define AV1_REG_CONFIG AV1_SWREG(2)
#define AV1_REG_CONFIG_DEC_CLK_GATE_E BIT(10)
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
index f04d3cc0c1a8..6bb85ccbf460 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
@@ -8,6 +8,9 @@
#include <linux/clk.h>
#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <soc/rockchip/pm_domains.h>
#include "hantro.h"
#include "hantro_av1.h"
@@ -435,11 +438,23 @@ static irqreturn_t rk3588_vpu981_irq(int irq, void *dev_id)
vdpu_write(vpu, 0, AV1_REG_INTERRUPT);
vdpu_write(vpu, AV1_REG_CONFIG_DEC_CLK_GATE_E, AV1_REG_CONFIG);
- hantro_irq_done(vpu, state);
+ if (state == VB2_BUF_STATE_DONE)
+ hantro_irq_done(vpu, state);
+ else
+ hantro_irq_reset(vpu);
return IRQ_HANDLED;
}
+static int rk3588_vpu981_hw_init(struct hantro_dev *vpu)
+{
+ vpu->core_resets[0].id = "axi";
+ vpu->core_resets[1].id = "apb";
+
+ return devm_reset_control_bulk_get_optional_exclusive_released(vpu->dev,
+ ARRAY_SIZE(vpu->core_resets), vpu->core_resets);
+}
+
static int rk3036_vpu_hw_init(struct hantro_dev *vpu)
{
/* Bump ACLK to max. possible freq. to improve performance. */
@@ -540,6 +555,73 @@ static void rockchip_vpu2_enc_reset(struct hantro_ctx *ctx)
vepu_write(vpu, 0, VEPU_REG_INTERRUPT);
}
+static int rockchip_vpu981_core_reset(void *data)
+{
+ struct hantro_dev *vpu = data;
+ int n = ARRAY_SIZE(vpu->core_resets);
+ int ret;
+
+ ret = reset_control_bulk_assert(n, vpu->core_resets);
+ udelay(5);
+ return reset_control_bulk_deassert(n, vpu->core_resets) ?: ret;
+}
+
+static void rockchip_vpu981_av1_dec_reset(struct hantro_ctx *ctx)
+{
+ struct hantro_dev *vpu = ctx->dev;
+ struct reset_control_bulk_data *rst = vpu->core_resets;
+ int n = ARRAY_SIZE(vpu->core_resets);
+ int irq, ret;
+ u32 status;
+
+ if (!rst[0].rstc)
+ return;
+
+ irq = platform_get_irq(vpu->pdev, 0);
+ if (irq < 0)
+ return;
+
+ ret = reset_control_bulk_acquire(n, rst);
+ if (ret) {
+ dev_err(vpu->dev, "Failed to acquire the core resets: %d\n", ret);
+ return;
+ }
+
+ /* After a timeout, keep the handler off the core and the next job. */
+ disable_irq(irq);
+
+ status = vdpu_read(vpu, AV1_REG_INTERRUPT);
+ if (status & AV1_REG_INTERRUPT_DEC_E) {
+ vdpu_write(vpu, status | AV1_REG_INTERRUPT_DEC_ABORT_E |
+ AV1_REG_INTERRUPT_DEC_IRQ_DIS, AV1_REG_INTERRUPT);
+ if (readl_poll_timeout(vpu->dec_base + AV1_REG_INTERRUPT, status,
+ !(status & AV1_REG_INTERRUPT_DEC_E), 100, 100000)) {
+ dev_err(vpu->dev, "The core does not stop, refusing further jobs\n");
+ hantro_iommu_park(vpu);
+ vpu->iommu_lost = true;
+ goto release;
+ }
+ }
+
+ if (hantro_iommu_park(vpu))
+ goto out;
+
+ ret = rockchip_pmu_idle_reset(vpu->dev, rockchip_vpu981_core_reset, vpu);
+ if (ret) {
+ dev_err(vpu->dev, "Failed to reset the core: %d\n", ret);
+ /* Bus state unknown: keep the IOMMU and the handler off it. */
+ if (ret == -ETIMEDOUT) {
+ vpu->iommu_lost = true;
+ goto release;
+ }
+ }
+ hantro_iommu_unpark(vpu);
+out:
+ enable_irq(irq);
+release:
+ reset_control_bulk_release(n, rst);
+}
+
/*
* Supported codec ops.
*/
@@ -656,6 +738,7 @@ static const struct hantro_codec_ops rk3588_vpu981_codec_ops[] = {
.init = hantro_av1_init,
.exit = hantro_av1_exit,
.done = hantro_av1_update_prob,
+ .reset = rockchip_vpu981_av1_dec_reset,
},
};
/*
@@ -856,6 +939,7 @@ const struct hantro_variant rk3588_vpu981_variant = {
.postproc_ops = &rockchip_vpu981_postproc_ops,
.codec = HANTRO_AV1_DECODER,
.codec_ops = rk3588_vpu981_codec_ops,
+ .init = rk3588_vpu981_hw_init,
.irqs = rk3588_vpu981_irqs,
.num_irqs = ARRAY_SIZE(rk3588_vpu981_irqs),
.clk_names = rk3588_vpu981_vpu_clk_names,
--
2.55.0
next prev parent reply other threads:[~2026-12-06 5:57 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 5:57 [PATCH v4 00/18] media: verisilicon: Recover the Rockchip VPUs from faults and timeouts Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 01/18] dt-bindings: media: rockchip,rk3568-vepu: Add the reset lines Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 02/18] media: verisilicon: Check the match data in hantro_probe() Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 03/18] media: verisilicon: Complete the request when the VPU can't resume Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 04/18] media: verisilicon: Copy the buffer metadata before a job can fail Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 05/18] media: verisilicon: Don't hold the VPU in reset after remove Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 06/18] media: verisilicon: Disable runtime PM before unpreparing the clocks on probe failure Arun Iyengar via B4 Relay
2026-12-06 6:11 ` sashiko-bot
2026-12-06 5:57 ` [PATCH v4 07/18] media: verisilicon: Enable the Rockchip encoder interrupt again after a reset Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 08/18] media: verisilicon: Reset the Rockchip encoder cores on timeout Arun Iyengar via B4 Relay
2026-12-06 6:23 ` sashiko-bot
2026-12-06 5:57 ` [PATCH v4 09/18] media: verisilicon: Reinitialize the IOMMU after resetting an encoder core Arun Iyengar via B4 Relay
2026-12-06 6:21 ` sashiko-bot
2026-12-06 5:57 ` [PATCH v4 10/18] media: verisilicon: Acquire the reset lines only while using them Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 11/18] dt-bindings: iommu: verisilicon: Add the reset lines Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 12/18] iommu/vsi: Deassert the reset lines on probe Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 13/18] arm64: dts: rockchip: Add the reset lines of the RK3588 VEPU121 cores Arun Iyengar via B4 Relay
2026-12-06 6:26 ` sashiko-bot
2026-12-06 5:57 ` [PATCH v4 14/18] arm64: dts: rockchip: Add the reset lines of the RK3588 AV1 IOMMU Arun Iyengar via B4 Relay
2026-12-06 6:21 ` sashiko-bot
2026-12-06 5:57 ` [PATCH v4 15/18] pmdomain: rockchip: Add rockchip_pmu_idle_reset() Arun Iyengar via B4 Relay
2026-12-06 5:57 ` [PATCH v4 16/18] dt-bindings: media: rockchip-vpu: Add reset-names Arun Iyengar via B4 Relay
2026-12-06 5:57 ` Arun Iyengar via B4 Relay [this message]
2026-12-06 6:32 ` [PATCH v4 17/18] media: verisilicon: Reset the RK3588 AV1 decoder after an error sashiko-bot
2026-12-06 5:57 ` [PATCH v4 18/18] arm64: dts: rockchip: Name the RK3588 AV1 decoder resets Arun Iyengar via B4 Relay
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=20261206-hantro-robust-v4-17-b99d33a5ec6d@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=andrzej.p@collabora.com \
--cc=benjamin.gaignard@collabora.com \
--cc=boris.brezillon@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=frattaroli.nicolas@gmail.com \
--cc=heiko@sntech.de \
--cc=hverkuil@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jernej.skrabec@gmail.com \
--cc=joro@8bytes.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=s.hauer@pengutronix.de \
--cc=shomenkow@gmail.com \
--cc=tharitt97@gmail.com \
--cc=ulfh@kernel.org \
--cc=will@kernel.org \
/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