mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Detlev Casanova <detlev.casanova@collabora.com>,
	 Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Heiko Stuebner <heiko@sntech.de>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	 Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	 Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	 Alex Kazinsky <a.kazinsky@ideco.ru>,
	stable@vger.kernel.org,  Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH v2 1/2] media: rkvdec: Stop the VDPU381 core on timeout
Date: Tue, 01 Dec 2026 10:30:53 +0000	[thread overview]
Message-ID: <20261201-rkvdec-wdt-stop-v2-1-0f2662ea15e8@gmail.com> (raw)
In-Reply-To: <20261201-rkvdec-wdt-stop-v2-0-0f2662ea15e8@gmail.com>

From: Arun Iyengar <aiyengar1990@gmail.com>

On a timeout, rkvdec_watchdog_func() writes RKVDEC_IRQ_DIS to
RKVDEC_REG_INTERRUPT, an RK3399 register. On VDPU381 that offset is
another register, so the core keeps running after the job completes
and its IOMMU and power domain are suspended. On RK3588:

  Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: cpu_suspend+0x380/0x3d0

Add a ->stop() variant op, called with the IRQ disabled. VDPU381 soft
resets the core as the Rockchip BSP does, with the reset lines as a
fallback, and reprograms the IOMMU, which the reset leaves in bypass.
VDPU383 is fixed separately.

Fixes: e5aa698ea659 ("media: rkvdec: Add H264 support for the VDPU381 variant")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 .../platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h |  4 ++
 drivers/media/platform/rockchip/rkvdec/rkvdec.c    | 64 +++++++++++++++++++++-
 drivers/media/platform/rockchip/rkvdec/rkvdec.h    |  3 +
 3 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
index 6da36031df2dc..57ab23d76d736 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
@@ -34,6 +34,7 @@
 
 #define VDPU381_REG_IMPORTANT_EN	0x02c
 #define VDPU381_DEC_IRQ_DISABLE	BIT(4)
+#define VDPU381_SOFT_RESET_EN		BIT(20)
 
 #define VDPU381_REG_STA_INT		0x380
 #define VDPU381_STA_INT_DEC_RDY_STA	BIT(2)
@@ -41,6 +42,9 @@
 #define VDPU381_STA_INT_TIMEOUT		BIT(5)
 #define VDPU381_STA_INT_SOFTRESET_RDY	BIT(9)
 
+#define VDPU381_REG_DEBUG_INT		0x440
+#define VDPU381_DEBUG_INT_BUS_IDLE	BIT(0)
+
 /* base: OFFSET_COMMON_REGS */
 struct rkvdec_vdpu381_regs_common {
 	struct {
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
index 6cd7445b18c45..3d40f5f059c33 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
@@ -14,12 +14,14 @@
 #include <linux/genalloc.h>
 #include <linux/interrupt.h>
 #include <linux/iommu.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/reset.h>
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/workqueue.h>
@@ -1615,6 +1617,56 @@ static void vdpu383_flatten_matrices(u8 *output, const u8 *input, int matrices,
 	}
 }
 
+static int rkvdec_pulse_resets(struct rkvdec_dev *rkvdec)
+{
+	int ret;
+
+	if (!rkvdec->resets)
+		return -ENODEV;
+
+	ret = reset_control_assert(rkvdec->resets);
+	if (ret)
+		return ret;
+	udelay(5);
+	return reset_control_deassert(rkvdec->resets);
+}
+
+static void rk3399_stop(struct rkvdec_dev *rkvdec)
+{
+	writel(RKVDEC_IRQ_DIS, rkvdec->regs + RKVDEC_REG_INTERRUPT);
+}
+
+static void vdpu381_stop(struct rkvdec_dev *rkvdec)
+{
+	void __iomem *regs = rkvdec->regs;
+	u32 status;
+	int ret;
+
+	/* Soft reset needs an idle bus: let a busy core finish first. */
+	readl_poll_timeout(regs + VDPU381_REG_STA_INT, status, status,
+			   100, 100 * USEC_PER_MSEC);
+
+	writel(VDPU381_DEC_IRQ_DISABLE | VDPU381_SOFT_RESET_EN,
+	       regs + VDPU381_REG_IMPORTANT_EN);
+	ret = readl_poll_timeout_atomic(regs + VDPU381_REG_STA_INT, status,
+					status & VDPU381_STA_INT_SOFTRESET_RDY,
+					1, 100);
+	writel(0, regs + VDPU381_REG_STA_INT);
+	if (!ret)
+		ret = readl_poll_timeout(regs + VDPU381_REG_DEBUG_INT, status,
+					 status & VDPU381_DEBUG_INT_BUS_IDLE, 1, 1000);
+
+	if (ret) {
+		dev_warn(rkvdec->dev, "soft reset failed\n");
+		if (rkvdec_pulse_resets(rkvdec)) {
+			dev_err(rkvdec->dev, "cannot reset the core\n");
+			return;
+		}
+	}
+
+	rkvdec_iommu_restore(rkvdec);
+}
+
 static void rkvdec_watchdog_func(struct work_struct *work)
 {
 	struct rkvdec_dev *rkvdec;
@@ -1625,7 +1677,9 @@ static void rkvdec_watchdog_func(struct work_struct *work)
 	ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
 	if (ctx) {
 		dev_err(rkvdec->dev, "Frame processing timed out!\n");
-		writel(RKVDEC_IRQ_DIS, rkvdec->regs + RKVDEC_REG_INTERRUPT);
+		disable_irq(rkvdec->irq);
+		rkvdec->variant->ops->stop(rkvdec);
+		enable_irq(rkvdec->irq);
 		rkvdec_job_finish(rkvdec, VB2_BUF_STATE_ERROR);
 	}
 }
@@ -1675,6 +1729,7 @@ static int rkvdec_disable_multicore(struct rkvdec_dev *rkvdec)
 
 static const struct rkvdec_variant_ops rk3399_variant_ops = {
 	.irq_handler = rk3399_irq_handler,
+	.stop = rk3399_stop,
 	.colmv_size = rkvdec_colmv_size,
 	.flatten_matrices = transpose_and_flatten_matrices,
 };
@@ -1719,6 +1774,7 @@ static const struct rcb_size_info vdpu381_rcb_sizes[] = {
 
 static const struct rkvdec_variant_ops vdpu381_variant_ops = {
 	.irq_handler = vdpu381_irq_handler,
+	.stop = vdpu381_stop,
 	.colmv_size = rkvdec_colmv_size,
 	.flatten_matrices = transpose_and_flatten_matrices,
 };
@@ -1746,6 +1802,7 @@ static const struct rcb_size_info vdpu383_rcb_sizes[] = {
 
 static const struct rkvdec_variant_ops vdpu383_variant_ops = {
 	.irq_handler = vdpu383_irq_handler,
+	.stop = rk3399_stop,
 	.colmv_size = vdpu383_colmv_size,
 	.flatten_matrices = vdpu383_flatten_matrices,
 	.config_cache = rkvdec_vdpu383_config_cache,
@@ -1850,9 +1907,14 @@ static int rkvdec_probe(struct platform_device *pdev)
 
 	vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
 
+	rkvdec->resets = devm_reset_control_array_get_optional_exclusive(&pdev->dev);
+	if (IS_ERR(rkvdec->resets))
+		return PTR_ERR(rkvdec->resets);
+
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
+	rkvdec->irq = irq;
 
 	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
 					rkvdec_irq_handler, IRQF_ONESHOT,
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.h b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
index 42f33b12c2301..54bac85bb36bd 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.h
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
@@ -74,6 +74,7 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)
 
 struct rkvdec_variant_ops {
 	irqreturn_t (*irq_handler)(struct rkvdec_dev *rkvdec);
+	void (*stop)(struct rkvdec_dev *rkvdec);
 	u32 (*colmv_size)(u16 width, u16 height);
 	void (*flatten_matrices)(u8 *output, const u8 *input, int matrices, int row_length);
 	void (*config_cache)(struct rkvdec_dev *rkvdec);
@@ -141,6 +142,8 @@ struct rkvdec_dev {
 	void __iomem *cache;
 	struct mutex vdev_lock; /* serializes ioctls */
 	struct delayed_work watchdog_work;
+	struct reset_control *resets;
+	int irq;
 	struct gen_pool *sram_pool;
 	struct iommu_domain *iommu_domain;
 	struct iommu_domain *empty_domain;

-- 
2.55.0



  reply	other threads:[~2026-12-01 10:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 10:30 [PATCH v2 0/2] media: rkvdec: Stop VDPU381 and VDPU383 cores " Arun Iyengar via B4 Relay
2026-12-01 10:30 ` Arun Iyengar via B4 Relay [this message]
2026-12-01 10:30 ` [PATCH v2 2/2] media: rkvdec: Stop the VDPU383 core " 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=20261201-rkvdec-wdt-stop-v2-1-0f2662ea15e8@gmail.com \
    --to=devnull+aiyengar1990.gmail.com@kernel.org \
    --cc=a.kazinsky@ideco.ru \
    --cc=aiyengar1990@gmail.com \
    --cc=detlev.casanova@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=hverkuil+cisco@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=p.zabel@pengutronix.de \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®