From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796536675; b=m+1P50YK97XVu8ovrbjZynK0tF27LPNp/UM+c+YPAmHNg5VbGBqfyZ5yMCHADCw8FgDb 8qnRcucxf7sCwvlHRQkmhL3ulcWB2pPe3q8N4q2C5fdjBY0YBhHrZc9+Nb75Xn9EnMTaZ isYOQVeTD1swecUIDSE/FQuBTUcPrRxNleRGzeN8UB5VjhZB4XoHLkQb09VYNqJXi3IIC KFhylCC3lrvpwiedkdHegewOkPFxkAsEJM2JWS1MQasnHzWPF5sdGJmDOW6C+RICv3I1R Py7DVmy2WAd47LncUdeQSemCN+T5k2IyQD3vnJhjtX9bEG++ATEbY6vW+PmGacWi9Cw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796536675; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=CSBPD4hLHmIsBqaGd7xqrBXP4Aq4+Ig/xIrXG17nuIU=; b=YYzZWx0d0TXTHDyMWs2Z8tPP0SnkiLDUVtbtr/Jo7F3vSx9fNhfjZnWtB7HzwAf+QOQj pMYAEyNppHS7O3lniT221UlThhQio7xjNuAEGG+R/HDbogeSBAbHhpu8lnsNz+4HSoOwT JMcSsvD2Rqr3eqTEwZAS1dzFwl7uPHPU0TuCZoVTWSuYFzfMydTUjdFWbL8/U4FF+0Nk7 xTm8APZji8lJwZGx6viE2fZcrSf1jex7CD1WL2rTZIVOMidELkgN5kcZUFKfMwWRB99Fy SoI1DfxGx2YO7O9jyzIckEEoFdlpfahwBotVDxhoQeVSSdQPQFhesxMprUGLvfX/pGg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UA9pmuP5; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BA07606BF33; Sun, 6 Dec 2026 05:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UA9pmuP5 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796536675; b=py7qfitD3m+0gjkBSIxrg7Py70YZu/OVRWVGZl5QXyw8cYdB1vI52ZMVDHHHLihBNz0V OVjkjkgqonBSYO6OyaoaY8ZZnws0AGydCPvKs2zSuT8VOGCQumfhDBo5MLbIw1auwl7SR QYetkrded1nx4l3rTyQzLdgRma/td6DXc25wOGaiafenw0KzRMEue7fbr6rSc3m6C7Kdg my4pGiS8iHx+3J53N0q7Zpm6bk2k5dnh8lS+D7ttff6WH3iMllBkTOBDAYtn4hqZE2OKr SgF1yEBCjhhysCzoRRUHjxEM7K6yd7UzjuvdJddZ6lpVil1g8JN88eK0o9U8Sd5c0VA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796536675; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=CSBPD4hLHmIsBqaGd7xqrBXP4Aq4+Ig/xIrXG17nuIU=; b=EnAB1xPVxez0fOdRmWkTa+ogQ3U3HnlUCJgojzA1oZ70XiJHjKvT8b6POM4gckJ2Hn1b y5oQ5PlsyrtqpaFph/S6ScHyjbcfhf3wQX9+2KYoir3VtcT9tRB9s8Hz2ahctYbaFLzOg 0IH49Y8HiXBmg/ZSS+vb2JJ8oDSjSAp24Y4uNykgLbDA8cVXlUKzW/88rjeYonH6zD5hB mI2PAI4Zxv0XVTOEXDH7nUw/t2UsLV8JMO5m5uqELxKMrtXUNF5jj5RVbdu43JYvYeOD1 qFXYiLVaKt14bzG1O21RtF1T3h+hFjDnI0n0SoyLPbYGtvlYOy0rTpkJ+nTG4nZrBVw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 72A401F00A1E; Sun, 6 Dec 2026 05:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796536675; bh=CSBPD4hLHmIsBqaGd7xqrBXP4Aq4+Ig/xIrXG17nuIU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=UA9pmuP5SdgTiFh03qVhuDiMvaOV89vB8UIKSee9mWfn8BmRI8yd628pe7Ci3j/I8 FgE9qNjzaO9CSOhNb6idLVqDj2wP1xz4HGWXoOoYOo2U3J/T9mnUz5DJM38YUEHR6A PWbDw6JLYOcflN9v6RwxPTtuUBbicapWI9qkwyeUSyl1hb618JTIJ6bjKdq3wgwnfK kkLVvpgKZX6+hkACMqGkBLg9vg1b+m8ZK1AOTyT5mDWUM2TRdumiVW/f8AvoM7apCF ym2oXKKEhlLlIzgXE27GFgfFjNYcLWUlaxN9Kxr64DXb+xcP2ifRwxgF9SJRvFtLh6 brTTx/qNDzW0Q== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id E38855064A; Sun, 6 Dec 2026 05:57:40 +0000 (UTC) From: Arun Iyengar via B4 Relay Date: Sun, 06 Dec 2026 05:57:52 +0000 Subject: [PATCH v4 17/18] media: verisilicon: Reset the RK3588 AV1 decoder after an error X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261206-hantro-robust-v4-17-b99d33a5ec6d@gmail.com> References: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com> In-Reply-To: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com> To: Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Nicolas Frattaroli , Andrzej Pietrasiewicz , Ezequiel Garcia , Hans Verkuil , Boris Brezillon , Jernej Skrabec , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , Ulf Hansson 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 , Tharit Tangkijwanichakul , Sascha Hauer , Arun Iyengar X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796536657; l=12476; i=aiyengar1990@gmail.com; s=20261110; h=from:subject:message-id; bh=3h6I6PvectnAxoujnZ6F9wjZ7UtZAblem+Y0NizB/cg=; b=L19ZDJmuJ3tc8Fal7Dt6bygTEQQ09pdP6iK1VXIKSYPzKIPEFRZqeDVxkQRSODaKK2+CqBo3j 2mYWdK+w5PMAP0CF9FHy+69KRY423+Sg0jLCRY2MtcvDBFX3xABI1XT X-Developer-Key: i=aiyengar1990@gmail.com; a=ed25519; pk=zXpRgUTrhaFe6jLyPqbBy3ccfkj04w0g2690Wv3mg+0= X-Endpoint-Received: by B4 Relay for aiyengar1990@gmail.com/20261110 with auth_id=1480 X-Original-From: Arun Iyengar Reply-To: aiyengar1990@gmail.com Content-Transfer-Encoding: 7bit From: Arun Iyengar 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 --- 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 #include +#include +#include +#include #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