Skip to contentSkip to conversation

media: rkvdec: Add support for VDPU381 and VDPU383

PATCH Superseded Detlev Casanova 9 participants 35 messages Aug 8, 2025 – Sep 29, 2025

Subsystems (3)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Detlev Casanova

author maintainer
#0 lore raw

v2 cover media: rkvdec: Add support for VDPU381 and VDPU383

These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.

As there is a considerable part of the code that can be shared with the already supported rkvdec decoder driver, the support for these variants is added here rather than writing a new driver.

This patch set uses the newly introduced hevc_ext_sps_[ls]t_rps v4l2 controls for HEVC [1].
Therefore, a patched version of userpace tools is needed for HEVC support (added for GStreamer[2] and in an early stage for FFmpeg[3]).

This patch set also depends on the preparation patch set sent earlier [4] as well as the iommu restore fix [5] (already merged in linux-media) and Nicolas Frattaroli's bitmap patch [6] to support setting registers that uses upper 16 bits as masks.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9355
[3]: https://gitlab.collabora.com/detlev/ffmpeg
[4]: https://lore.kernel.org/all/[email protected]/
[5]: https://lore.kernel.org/all/[email protected]/
[6]: https://lore.kernel.org/all/[email protected]/

Changes since v1:
- Add parsing of the short and long term ref frame sets from the new v4l2 controls
- Add RPS cache to avoid parsing the same data again
- Fix HEVC pixel formats selection
- Fix multiple indentation errors

Detlev Casanova (12):
media: rkvdec: Switch to using structs instead of writel
media: rkvdec: Move cabac table to its own source file
media: rkvdec: Use structs to represent the HW RPS
media: rkvdec: Move h264 functions to common file
media: rkvdec: Add per variant configuration
media: rkvdec: Add RCB and SRAM support
media: rkvdec: Support per-variant interrupt handler
media: rkvdec: Enable all clocks without naming them
media: rkvdec: Add H264 support for the VDPU381 variant
media: rkvdec: Add H264 support for the VDPU383 variant
media: rkvdec: Add HEVC support for the VDPU381 variant
media: rkvdec: Add HEVC support for the VDPU383 variant

 .../media/platform/rockchip/rkvdec/Kconfig    |    1 +
 .../media/platform/rockchip/rkvdec/Makefile   |   13 +-
 .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 3944 +++++++++++++++++
 .../rockchip/rkvdec/rkvdec-h264-common.c      |  253 ++
 .../rockchip/rkvdec/rkvdec-h264-common.h      |   81 +
 .../platform/rockchip/rkvdec/rkvdec-h264.c    |  891 +---
 .../rockchip/rkvdec/rkvdec-hevc-common.c      |  511 +++
 .../rockchip/rkvdec/rkvdec-hevc-common.h      |  101 +
 .../platform/rockchip/rkvdec/rkvdec-rcb.c     |  174 +
 .../platform/rockchip/rkvdec/rkvdec-rcb.h     |   29 +
 .../platform/rockchip/rkvdec/rkvdec-regs.h    |  567 ++-
 .../rockchip/rkvdec/rkvdec-vdpu381-h264.c     |  469 ++
 .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c     |  596 +++
 .../rockchip/rkvdec/rkvdec-vdpu381-regs.h     |  427 ++
 .../rockchip/rkvdec/rkvdec-vdpu383-h264.c     |  582 +++
 .../rockchip/rkvdec/rkvdec-vdpu383-hevc.c     |  688 +++
 .../rockchip/rkvdec/rkvdec-vdpu383-regs.h     |  284 ++
 .../platform/rockchip/rkvdec/rkvdec-vp9.c     |  230 +-
 .../media/platform/rockchip/rkvdec/rkvdec.c   |  569 ++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   39 +
 20 files changed, 9260 insertions(+), 1189 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-cabac.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h
Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH v2 1/12 media: rkvdec: Switch to using structs instead of writel

In an effort to merge the rkvdec2 driver [1] with this one, switch from writel() calls to using structs to represent the register mappings.

This is done in order to have all supported decoders use the same format in the future and ease reading of the code.

Using structs also improves stability as the hardware is tested and validated downstream using a similar method.
It was noticed, on decoders, that:
- Some registers require to be writen in increasing order [2]
- Some registers, even if unrelated, need to be written to their reset values (it was the case here for axi_ddr_[rw]data).

Using structs can also help improving performance later when, e.g. multicore support is added on RK3588.

Performance seems to be slightly improved, but at least, not made worse. Running fluster's JVT-AVC_V1 test suite with GStreamer on the Radxa ROCK PI 4 SE gives the following times:

Before this patch:

- --jobs 1: Ran 129/135 tests successfully in 77.167 secs
- --jobs 6: Ran 129/135 tests successfully in 23.046 secs

With this patch:
- --jobs 1: Ran 129/135 tests successfully in 70.698 secs
- --jobs 6: Ran 129/135 tests successfully in 22.917 secs

This also shows that the fluster score hasn't changed.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

---
 .../platform/rockchip/rkvdec/rkvdec-h264.c    | 165 +++--
 .../platform/rockchip/rkvdec/rkvdec-regs.h    | 567 ++++++++++++------
 .../platform/rockchip/rkvdec/rkvdec-vp9.c     | 230 +++----
 .../media/platform/rockchip/rkvdec/rkvdec.c   |  10 +-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   1 +
 5 files changed, 558 insertions(+), 415 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +70 -95
index d14b4d173448d..1adb2e1f5f0ed 100644
@@ -115,6 +115,7 @@ struct rkvdec_h264_run {
 struct rkvdec_h264_ctx {
 	struct rkvdec_aux_buf priv_tbl;
 	struct rkvdec_h264_reflists reflists;
+	struct rkvdec_regs regs;
 };
 
 #define CABAC_ENTRY(ctxidx, idc0_m, idc0_n, idc1_m, idc1_n,		\
@@ -841,45 +842,41 @@ static void assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
 }
 
 /*
- * dpb poc related registers table
+ * Set the ref POC in the correct register.
+ *
+ * The 32 registers are spread across 3 regions, each alternating top and bottom ref POCs:
+ *  - 1: ref 0 to 14 contain top 0 to 7 and bottoms 0 to 6
+ *  - 2: ref 15 to 29 contain top 8 to 14 and bottoms 7 to 14
+ *  - 3: ref 30 and 31 which correspond to top 15 and bottom 15 respectively.
  */
-static const u32 poc_reg_tbl_top_field[16] = {
-	RKVDEC_REG_H264_POC_REFER0(0),
-	RKVDEC_REG_H264_POC_REFER0(2),
-	RKVDEC_REG_H264_POC_REFER0(4),
-	RKVDEC_REG_H264_POC_REFER0(6),
-	RKVDEC_REG_H264_POC_REFER0(8),
-	RKVDEC_REG_H264_POC_REFER0(10),
-	RKVDEC_REG_H264_POC_REFER0(12),
-	RKVDEC_REG_H264_POC_REFER0(14),
-	RKVDEC_REG_H264_POC_REFER1(1),
-	RKVDEC_REG_H264_POC_REFER1(3),
-	RKVDEC_REG_H264_POC_REFER1(5),
-	RKVDEC_REG_H264_POC_REFER1(7),
-	RKVDEC_REG_H264_POC_REFER1(9),
-	RKVDEC_REG_H264_POC_REFER1(11),
-	RKVDEC_REG_H264_POC_REFER1(13),
-	RKVDEC_REG_H264_POC_REFER2(0)
-};
-
-static const u32 poc_reg_tbl_bottom_field[16] = {
-	RKVDEC_REG_H264_POC_REFER0(1),
-	RKVDEC_REG_H264_POC_REFER0(3),
-	RKVDEC_REG_H264_POC_REFER0(5),
-	RKVDEC_REG_H264_POC_REFER0(7),
-	RKVDEC_REG_H264_POC_REFER0(9),
-	RKVDEC_REG_H264_POC_REFER0(11),
-	RKVDEC_REG_H264_POC_REFER0(13),
-	RKVDEC_REG_H264_POC_REFER1(0),
-	RKVDEC_REG_H264_POC_REFER1(2),
-	RKVDEC_REG_H264_POC_REFER1(4),
-	RKVDEC_REG_H264_POC_REFER1(6),
-	RKVDEC_REG_H264_POC_REFER1(8),
-	RKVDEC_REG_H264_POC_REFER1(10),
-	RKVDEC_REG_H264_POC_REFER1(12),
-	RKVDEC_REG_H264_POC_REFER1(14),
-	RKVDEC_REG_H264_POC_REFER2(1)
-};
+static void set_poc_reg(struct rkvdec_regs *regs, uint32_t poc, int id, bool bottom)
+{
+	if (!bottom) {
+		switch (id) {
+		case 0 ... 7:
+			regs->h264.ref0_14_poc[id * 2] = poc;
+			break;
+		case 8 ... 14:
+			regs->h264.ref15_29_poc[(id - 8) * 2 + 1] = poc;
+			break;
+		case 15:
+			regs->h264.ref30_poc = poc;
+			break;
+		}
+	} else {
+		switch (id) {
+		case 0 ... 6:
+			regs->h264.ref0_14_poc[id * 2 + 1] = poc;
+			break;
+		case 7 ... 14:
+			regs->h264.ref15_29_poc[(id - 7) * 2] = poc;
+			break;
+		case 15:
+			regs->h264.ref31_poc = poc;
+			break;
+		}
+	}
+}
 
 static void config_registers(struct rkvdec_ctx *ctx,
 			     struct rkvdec_h264_run *run)
@@ -894,6 +891,7 @@ static void config_registers(struct rkvdec_ctx *ctx,
 	struct vb2_v4l2_buffer *src_buf = run->base.bufs.src;
 	struct vb2_v4l2_buffer *dst_buf = run->base.bufs.dst;
 	const struct v4l2_format *f;
+	struct rkvdec_regs *regs = &h264_ctx->regs;
 	dma_addr_t rlc_addr;
 	dma_addr_t refer_addr;
 	u32 rlc_len;
@@ -903,10 +901,11 @@ static void config_registers(struct rkvdec_ctx *ctx,
 	u32 yuv_virstride = 0;
 	u32 offset;
 	dma_addr_t dst_addr;
-	u32 reg, i;
+	u32 i;
 
-	reg = RKVDEC_MODE(RKVDEC_MODE_H264);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_SYSCTRL);
+	memset(regs, 0, sizeof(*regs));
+
+	regs->common.reg02.dec_mode = RKVDEC_MODE_H264;
 
 	f = &ctx->decoded_fmt;
 	dst_fmt = &f->fmt.pix_mp;
@@ -921,39 +920,35 @@ static void config_registers(struct rkvdec_ctx *ctx,
 	else if (sps->chroma_format_idc == 2)
 		yuv_virstride = 2 * y_virstride;
 
-	reg = RKVDEC_Y_HOR_VIRSTRIDE(hor_virstride / 16) |
-	      RKVDEC_UV_HOR_VIRSTRIDE(hor_virstride / 16) |
-	      RKVDEC_SLICE_NUM_HIGHBIT |
-	      RKVDEC_SLICE_NUM_LOWBITS(0x7ff);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_PICPAR);
+	regs->common.reg03.uv_hor_virstride = hor_virstride / 16;
+	regs->common.reg03.y_hor_virstride = hor_virstride / 16;
+	regs->common.reg03.slice_num_highbit = 1;
+	regs->common.reg03.slice_num_lowbits = 0x7ff;
 
 	/* config rlc base address */
 	rlc_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
-	writel_relaxed(rlc_addr, rkvdec->regs + RKVDEC_REG_STRM_RLC_BASE);
-	writel_relaxed(rlc_addr, rkvdec->regs + RKVDEC_REG_RLCWRITE_BASE);
+	regs->common.strm_rlc_base = rlc_addr;
+	regs->h264.rlcwrite_base = rlc_addr;
 
 	rlc_len = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
-	reg = RKVDEC_STRM_LEN(rlc_len);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_STRM_LEN);
+	regs->common.stream_len = rlc_len;
 
 	/* config cabac table */
 	offset = offsetof(struct rkvdec_h264_priv_tbl, cabac_table);
-	writel_relaxed(priv_start_addr + offset,
-		       rkvdec->regs + RKVDEC_REG_CABACTBL_PROB_BASE);
+	regs->common.cabactbl_base = priv_start_addr + offset;
 
 	/* config output base address */
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
-	writel_relaxed(dst_addr, rkvdec->regs + RKVDEC_REG_DECOUT_BASE);
+	regs->common.decout_base = dst_addr;
 
-	reg = RKVDEC_Y_VIRSTRIDE(y_virstride / 16);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_Y_VIRSTRIDE);
+	regs->common.reg08.y_virstride = y_virstride / 16;
 
-	reg = RKVDEC_YUV_VIRSTRIDE(yuv_virstride / 16);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_YUV_VIRSTRIDE);
+	regs->common.reg09.yuv_virstride = yuv_virstride / 16;
 
 	/* config ref pic address & poc */
 	for (i = 0; i < ARRAY_SIZE(dec_params->dpb); i++) {
 		struct vb2_buffer *vb_buf = run->ref_buf[i];
+		struct ref_base *base;
 
 		/*
 		 * If a DPB entry is unused or invalid, address of current destination
@@ -963,54 +958,36 @@ static void config_registers(struct rkvdec_ctx *ctx,
 			vb_buf = &dst_buf->vb2_buf;
 		refer_addr = vb2_dma_contig_plane_dma_addr(vb_buf, 0);
 
-		if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
-			refer_addr |= RKVDEC_COLMV_USED_FLAG_REF;
-		if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_FIELD)
-			refer_addr |= RKVDEC_FIELD_REF;
-
-		if (dpb[i].fields & V4L2_H264_TOP_FIELD_REF)
-			refer_addr |= RKVDEC_TOPFIELD_USED_REF;
-		if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF)
-			refer_addr |= RKVDEC_BOTFIELD_USED_REF;
-
-		writel_relaxed(dpb[i].top_field_order_cnt,
-			       rkvdec->regs +  poc_reg_tbl_top_field[i]);
-		writel_relaxed(dpb[i].bottom_field_order_cnt,
-			       rkvdec->regs + poc_reg_tbl_bottom_field[i]);
-
 		if (i < V4L2_H264_NUM_DPB_ENTRIES - 1)
-			writel_relaxed(refer_addr,
-				       rkvdec->regs + RKVDEC_REG_H264_BASE_REFER(i));
+			base = &regs->h264.ref0_14_base[i];
 		else
-			writel_relaxed(refer_addr,
-				       rkvdec->regs + RKVDEC_REG_H264_BASE_REFER15);
-	}
+			base = &regs->h264.ref15_base;
 
-	reg = RKVDEC_CUR_POC(dec_params->top_field_order_cnt);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_CUR_POC0);
+		base->field_ref = !!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_FIELD);
+		base->colmv_used_flag_ref = !!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE);
+		base->topfield_used_ref = !!(dpb[i].fields & V4L2_H264_TOP_FIELD_REF);
+		base->botfield_used_ref = !!(dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF);
+		base->base_addr = refer_addr >> 4;
 
-	reg = RKVDEC_CUR_POC(dec_params->bottom_field_order_cnt);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_CUR_POC1);
+		set_poc_reg(regs, dpb[i].top_field_order_cnt, i, false);
+		set_poc_reg(regs, dpb[i].bottom_field_order_cnt, i, true);
+	}
+
+	regs->h264.cur_poc = dec_params->top_field_order_cnt;
+	regs->h264.cur_poc1 = dec_params->bottom_field_order_cnt;
 
 	/* config hw pps address */
 	offset = offsetof(struct rkvdec_h264_priv_tbl, param_set);
-	writel_relaxed(priv_start_addr + offset,
-		       rkvdec->regs + RKVDEC_REG_PPS_BASE);
+	regs->h264.pps_base = priv_start_addr + offset;
 
 	/* config hw rps address */
 	offset = offsetof(struct rkvdec_h264_priv_tbl, rps);
-	writel_relaxed(priv_start_addr + offset,
-		       rkvdec->regs + RKVDEC_REG_RPS_BASE);
-
-	reg = RKVDEC_AXI_DDR_RDATA(0);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_AXI_DDR_RDATA);
-
-	reg = RKVDEC_AXI_DDR_WDATA(0);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_AXI_DDR_WDATA);
+	regs->h264.rps_base = priv_start_addr + offset;
 
 	offset = offsetof(struct rkvdec_h264_priv_tbl, err_info);
-	writel_relaxed(priv_start_addr + offset,
-		       rkvdec->regs + RKVDEC_REG_H264_ERRINFO_BASE);
+	regs->h264.errorinfo_base = priv_start_addr + offset;
+
+	rkvdec_memcpy_toio(rkvdec->regs, regs, sizeof(*regs));
 }
 
 #define RKVDEC_H264_MAX_DEPTH_IN_BYTES		2
@@ -1181,8 +1158,6 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx)
 
 	schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000));
 
-	writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN);
-	writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E);
 	writel(1, rkvdec->regs + RKVDEC_REG_PREF_LUMA_CACHE_COMMAND);
 	writel(1, rkvdec->regs + RKVDEC_REG_PREF_CHR_CACHE_COMMAND);
 
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +379 -188

581 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c +99 -131

357 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.c +9 -1
index d707088ec0dc1..a71837103b71d 100644
@@ -795,6 +795,15 @@ void rkvdec_run_postamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run)
 		v4l2_ctrl_request_complete(src_req, &ctx->ctrl_hdl);
 }
 
+void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len)
+{
+#ifdef CONFIG_ARM64
+	__iowrite32_copy(dst, src, len / 4);
+#else
+	memcpy_toio(dst, src, len);
+#endif
+}
+
 static void rkvdec_device_run(void *priv)
 {
 	struct rkvdec_ctx *ctx = priv;
@@ -1106,7 +1115,6 @@ static void rkvdec_watchdog_func(struct work_struct *work)
 	if (ctx) {
 		dev_err(rkvdec->dev, "Frame processing timed out!\n");
 		writel(RKVDEC_IRQ_DIS, rkvdec->regs + RKVDEC_REG_INTERRUPT);
-		writel(0, rkvdec->regs + RKVDEC_REG_SYSCTRL);
 		rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);
 	}
 }
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index f6e8bf38add3a..3451c4bf7cb75 100644
@@ -137,6 +137,7 @@ struct rkvdec_aux_buf {
 
 void rkvdec_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
 void rkvdec_run_postamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
+void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);
 
 extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;
 extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
Signature · 1 line
2.50.1
author maintainer
#2 lore raw

PATCH v2 2/12 media: rkvdec: Move cabac table to its own source file

In reply to Detlev Casanova

This is in preparation to add support for new variants that will use the same table.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   6 +-
 .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 509 ++++++++++++++++++
 .../platform/rockchip/rkvdec/rkvdec-h264.c    | 501 +----------------
 3 files changed, 516 insertions(+), 500 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-cabac.c
drivers/media/platform/rockchip/rkvdec/Makefile +5 -1
index cb86b429cfaac..164ea06c26c2a 100644
@@ -1,3 +1,7 @@
 obj-$(CONFIG_VIDEO_ROCKCHIP_VDEC) += rockchip-vdec.o
 
-rockchip-vdec-y += rkvdec.o rkvdec-h264.o rkvdec-vp9.o
+rockchip-vdec-y += \
+		   rkvdec.o \
+		   rkvdec-cabac.o \
+		   rkvdec-h264.o \
+		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-cabac.c new file +509 -0

509 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +2 -499

513 lines not on this page · raw message

Signature · 1 line
2.50.1
author maintainer
#3 lore raw

PATCH v2 3/12 media: rkvdec: Use structs to represent the HW RPS

In reply to Detlev Casanova

This is in preparation to add support for other variants of the decoder.

Moving to struct representation is mainly to prepare for multicore support that is present in e.g. rk3588.

---
 .../platform/rockchip/rkvdec/rkvdec-h264.c    | 97 ++++++++++++++++---
 1 file changed, 86 insertions(+), 11 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +86 -11
index 15f2378bbc020..3527919aa8ff6 100644
@@ -19,7 +19,6 @@ extern const s8 rkvdec_h264_cabac_table[4][464][2];
 
 /* Size with u32 units. */
 #define RKV_CABAC_INIT_BUFFER_SIZE	(3680 + 128)
-#define RKV_RPS_SIZE			((128 + 128) / 4)
 #define RKV_ERROR_INFO_SIZE		(256 * 144 * 4)
 
 #define RKVDEC_NUM_REFLIST		3
@@ -34,6 +33,40 @@ struct rkvdec_sps_pps_packet {
 	u32 info[8];
 };
 
+struct rkvdec_rps_entry {
+	u32 dpb_info0:          5;
+	u32 bottom_flag0:       1;
+	u32 view_index_off0:    1;
+	u32 dpb_info1:          5;
+	u32 bottom_flag1:       1;
+	u32 view_index_off1:    1;
+	u32 dpb_info2:          5;
+	u32 bottom_flag2:       1;
+	u32 view_index_off2:    1;
+	u32 dpb_info3:          5;
+	u32 bottom_flag3:       1;
+	u32 view_index_off3:    1;
+	u32 dpb_info4:          5;
+	u32 bottom_flag4:       1;
+	u32 view_index_off4:    1;
+	u32 dpb_info5:          5;
+	u32 bottom_flag5:       1;
+	u32 view_index_off5:    1;
+	u32 dpb_info6:          5;
+	u32 bottom_flag6:       1;
+	u32 view_index_off6:    1;
+	u32 dpb_info7:          5;
+	u32 bottom_flag7:       1;
+	u32 view_index_off7:    1;
+} __packed;
+
+struct rkvdec_rps {
+	u16 frame_num[16];
+	u32 reserved0;
+	struct rkvdec_rps_entry entries[12];
+	u32 reserved1[66];
+} __packed;
+
 struct rkvdec_ps_field {
 	u16 offset;
 	u8 len;
@@ -94,7 +127,7 @@ struct rkvdec_ps_field {
 struct rkvdec_h264_priv_tbl {
 	s8 cabac_table[4][464][2];
 	struct rkvdec_h264_scaling_list scaling_list;
-	u32 rps[RKV_RPS_SIZE];
+	struct rkvdec_rps rps;
 	struct rkvdec_sps_pps_packet param_set[256];
 	u8 err_info[RKV_ERROR_INFO_SIZE];
 };
@@ -260,20 +293,64 @@ static void lookup_ref_buf_idx(struct rkvdec_ctx *ctx,
 	}
 }
 
+static void set_dpb_info(struct rkvdec_rps_entry *entries,
+			 u8 reflist,
+			 u8 refnum,
+			 u8 info,
+			 bool bottom)
+{
+	struct rkvdec_rps_entry *entry = &entries[(reflist * 4) + refnum / 8];
+	u8 idx = refnum % 8;
+
+	switch (idx) {
+	case 0:
+		entry->dpb_info0 = info;
+		entry->bottom_flag0 = bottom;
+		break;
+	case 1:
+		entry->dpb_info1 = info;
+		entry->bottom_flag1 = bottom;
+		break;
+	case 2:
+		entry->dpb_info2 = info;
+		entry->bottom_flag2 = bottom;
+		break;
+	case 3:
+		entry->dpb_info3 = info;
+		entry->bottom_flag3 = bottom;
+		break;
+	case 4:
+		entry->dpb_info4 = info;
+		entry->bottom_flag4 = bottom;
+		break;
+	case 5:
+		entry->dpb_info5 = info;
+		entry->bottom_flag5 = bottom;
+		break;
+	case 6:
+		entry->dpb_info6 = info;
+		entry->bottom_flag6 = bottom;
+		break;
+	case 7:
+		entry->dpb_info7 = info;
+		entry->bottom_flag7 = bottom;
+		break;
+	}
+}
+
 static void assemble_hw_rps(struct rkvdec_ctx *ctx,
-			    struct v4l2_h264_reflist_builder *builder,
-			    struct rkvdec_h264_run *run)
+		     struct v4l2_h264_reflist_builder *builder,
+		     struct rkvdec_h264_run *run)
 {
 	const struct v4l2_ctrl_h264_decode_params *dec_params = run->decode_params;
 	const struct v4l2_h264_dpb_entry *dpb = dec_params->dpb;
 	struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
 	struct rkvdec_h264_priv_tbl *priv_tbl = h264_ctx->priv_tbl.cpu;
 
-	u32 *hw_rps = priv_tbl->rps;
+	struct rkvdec_rps *hw_rps = &priv_tbl->rps;
 	u32 i, j;
-	u16 *p = (u16 *)hw_rps;
 
-	memset(hw_rps, 0, sizeof(priv_tbl->rps));
+	memset(hw_rps, 0, sizeof(*hw_rps));
 
 	/*
 	 * Assign an invalid pic_num if DPB entry at that position is inactive.
@@ -285,7 +362,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,
 		if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE))
 			continue;
 
-		p[i] = builder->refs[i].frame_num;
+		hw_rps->frame_num[i] = builder->refs[i].frame_num;
 	}
 
 	for (j = 0; j < RKVDEC_NUM_REFLIST; j++) {
@@ -312,9 +389,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,
 			dpb_valid = run->ref_buf[ref->index] != NULL;
 			bottom = ref->fields == V4L2_H264_BOTTOM_FIELD_REF;
 
-			set_ps_field(hw_rps, DPB_INFO(i, j),
-				     ref->index | dpb_valid << 4);
-			set_ps_field(hw_rps, BOTTOM_FLAG(i, j), bottom);
+			set_dpb_info(hw_rps->entries, j, i, ref->index | (dpb_valid << 4), bottom);
 		}
 	}
 }
Signature · 1 line
2.50.1
author maintainer
#4 lore raw

PATCH v2 4/12 media: rkvdec: Move h264 functions to common file

In reply to Detlev Casanova

This is a preparation commit to add support for new variants of the decoder.

The functions will later be shared with vdpu381 (rk3588) and vdpu383 (rk3576).

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-h264-common.c      | 253 ++++++++++++++++
 .../rockchip/rkvdec/rkvdec-h264-common.h      |  79 +++++
 .../platform/rockchip/rkvdec/rkvdec-h264.c    | 274 +-----------------
 4 files changed, 337 insertions(+), 270 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
index 164ea06c26c2a..94c067084acd1 100644
@@ -4,4 +4,5 @@ rockchip-vdec-y += \
 		   rkvdec.o \
 		   rkvdec-cabac.o \
 		   rkvdec-h264.o \
+		   rkvdec-h264-common.o \
 		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.c new file +253 -0

253 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h new file +79 -0

79 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +4 -270

330 lines not on this page · raw message

Signature · 1 line
2.50.1
author maintainer
#5 lore raw

PATCH v2 5/12 media: rkvdec: Add per variant configuration

In reply to Detlev Casanova

This is to prepare for adding different variants of the decoder and support specific formats and ops.

---
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 50 ++++++++++++-------
 .../media/platform/rockchip/rkvdec/rkvdec.h   |  6 +++
 2 files changed, 39 insertions(+), 17 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +33 -17
index a71837103b71d..28585522523c7 100644
@@ -286,13 +286,14 @@ static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = {
 };
 
 static const struct rkvdec_coded_fmt_desc *
-rkvdec_find_coded_fmt_desc(u32 fourcc)
+rkvdec_find_coded_fmt_desc(struct rkvdec_ctx *ctx, u32 fourcc)
 {
+	struct rkvdec_config *cfg = ctx->dev->config;
 	unsigned int i;
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
-		if (rkvdec_coded_fmts[i].fourcc == fourcc)
-			return &rkvdec_coded_fmts[i];
+	for (i = 0; i < cfg->coded_fmts_num; i++) {
+		if (cfg->coded_fmts[i].fourcc == fourcc)
+			return &cfg->coded_fmts[i];
 	}
 
 	return NULL;
@@ -300,9 +301,10 @@ rkvdec_find_coded_fmt_desc(u32 fourcc)
 
 static void rkvdec_reset_coded_fmt(struct rkvdec_ctx *ctx)
 {
+	struct rkvdec_config *cfg = ctx->dev->config;
 	struct v4l2_format *f = &ctx->coded_fmt;
 
-	ctx->coded_fmt_desc = &rkvdec_coded_fmts[0];
+	ctx->coded_fmt_desc = &cfg->coded_fmts[0];
 	rkvdec_reset_fmt(ctx, f, ctx->coded_fmt_desc->fourcc);
 
 	f->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
@@ -316,12 +318,13 @@ static void rkvdec_reset_coded_fmt(struct rkvdec_ctx *ctx)
 static int rkvdec_enum_framesizes(struct file *file, void *priv,
 				  struct v4l2_frmsizeenum *fsize)
 {
+	struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv);
 	const struct rkvdec_coded_fmt_desc *fmt;
 
 	if (fsize->index != 0)
 		return -EINVAL;
 
-	fmt = rkvdec_find_coded_fmt_desc(fsize->pixel_format);
+	fmt = rkvdec_find_coded_fmt_desc(ctx, fsize->pixel_format);
 	if (!fmt)
 		return -EINVAL;
 
@@ -388,12 +391,13 @@ static int rkvdec_try_output_fmt(struct file *file, void *priv,
 {
 	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
 	struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv);
+	struct rkvdec_config *cfg = ctx->dev->config;
 	const struct rkvdec_coded_fmt_desc *desc;
 
-	desc = rkvdec_find_coded_fmt_desc(pix_mp->pixelformat);
+	desc = rkvdec_find_coded_fmt_desc(ctx, pix_mp->pixelformat);
 	if (!desc) {
-		pix_mp->pixelformat = rkvdec_coded_fmts[0].fourcc;
-		desc = &rkvdec_coded_fmts[0];
+		pix_mp->pixelformat = cfg->coded_fmts[0].fourcc;
+		desc = &cfg->coded_fmts[0];
 	}
 
 	v4l2_apply_frmsize_constraints(&pix_mp->width,
@@ -470,7 +474,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv,
 	if (ret)
 		return ret;
 
-	desc = rkvdec_find_coded_fmt_desc(f->fmt.pix_mp.pixelformat);
+	desc = rkvdec_find_coded_fmt_desc(ctx, f->fmt.pix_mp.pixelformat);
 	if (!desc)
 		return -EINVAL;
 	ctx->coded_fmt_desc = desc;
@@ -522,10 +526,13 @@ static int rkvdec_g_capture_fmt(struct file *file, void *priv,
 static int rkvdec_enum_output_fmt(struct file *file, void *priv,
 				  struct v4l2_fmtdesc *f)
 {
-	if (f->index >= ARRAY_SIZE(rkvdec_coded_fmts))
+	struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv);
+	struct rkvdec_config *cfg = ctx->dev->config;
+
+	if (f->index >= cfg->coded_fmts_num)
 		return -EINVAL;
 
-	f->pixelformat = rkvdec_coded_fmts[f->index].fourcc;
+	f->pixelformat = cfg->coded_fmts[f->index].fourcc;
 	return 0;
 }
 
@@ -895,16 +902,17 @@ static int rkvdec_add_ctrls(struct rkvdec_ctx *ctx,
 
 static int rkvdec_init_ctrls(struct rkvdec_ctx *ctx)
 {
+	struct rkvdec_config *cfg = ctx->dev->config;
 	unsigned int i, nctrls = 0;
 	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++)
-		nctrls += rkvdec_coded_fmts[i].ctrls->num_ctrls;
+	for (i = 0; i < cfg->coded_fmts_num; i++)
+		nctrls += cfg->coded_fmts[i].ctrls->num_ctrls;
 
 	v4l2_ctrl_handler_init(&ctx->ctrl_hdl, nctrls);
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
-		ret = rkvdec_add_ctrls(ctx, rkvdec_coded_fmts[i].ctrls);
+	for (i = 0; i < cfg->coded_fmts_num; i++) {
+		ret = rkvdec_add_ctrls(ctx, cfg->coded_fmts[i].ctrls);
 		if (ret)
 			goto err_free_handler;
 	}
@@ -1119,8 +1127,13 @@ static void rkvdec_watchdog_func(struct work_struct *work)
 	}
 }
 
+const struct rkvdec_config config_rkvdec = {
+	.coded_fmts = (struct rkvdec_coded_fmt_desc *)rkvdec_coded_fmts,
+	.coded_fmts_num = ARRAY_SIZE(rkvdec_coded_fmts),
+};
+
 static const struct of_device_id of_rkvdec_match[] = {
-	{ .compatible = "rockchip,rk3399-vdec" },
+	{ .compatible = "rockchip,rk3399-vdec", .data = &config_rkvdec },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, of_rkvdec_match);
@@ -1144,6 +1157,9 @@ static int rkvdec_probe(struct platform_device *pdev)
 	mutex_init(&rkvdec->vdev_lock);
 	INIT_DELAYED_WORK(&rkvdec->watchdog_work, rkvdec_watchdog_func);
 
+	rkvdec->config =
+		(struct rkvdec_config *)of_device_get_match_data(rkvdec->dev);
+
 	rkvdec->clocks = devm_kcalloc(&pdev->dev, ARRAY_SIZE(rkvdec_clk_names),
 				      sizeof(*rkvdec->clocks), GFP_KERNEL);
 	if (!rkvdec->clocks)
drivers/media/platform/rockchip/rkvdec/rkvdec.h +6 -0
index 3451c4bf7cb75..14717c646c665 100644
@@ -100,6 +100,11 @@ struct rkvdec_coded_fmt_desc {
 	u32 subsystem_flags;
 };
 
+struct rkvdec_config {
+	struct rkvdec_coded_fmt_desc *coded_fmts;
+	size_t coded_fmts_num;
+};
+
 struct rkvdec_dev {
 	struct v4l2_device v4l2_dev;
 	struct media_device mdev;
@@ -111,6 +116,7 @@ struct rkvdec_dev {
 	struct mutex vdev_lock; /* serializes ioctls */
 	struct delayed_work watchdog_work;
 	struct iommu_domain *empty_domain;
+	struct rkvdec_config *config;
 };
 
 struct rkvdec_ctx {
Signature · 1 line
2.50.1
#6 lore raw

Re: [PATCH v2 05/12] media: rkvdec: Add per variant configuration

Quoted 1 line · Detlev Casanova

This is to prepare for adding different variants of the decoder and

Prepare for...

Quoted 4 lines

support specific formats and ops.

---

...

Quoted 21 lines

static int rkvdec_init_ctrls(struct rkvdec_ctx *ctx) {

drivers/media/platform/rockchip/rkvdec/rkvdec.c +5 -4
+	struct rkvdec_config *cfg = ctx->dev->config;
 	unsigned int i, nctrls = 0;
 	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++)
-		nctrls += rkvdec_coded_fmts[i].ctrls->num_ctrls;
+	for (i = 0; i < cfg->coded_fmts_num; i++)
+		nctrls += cfg->coded_fmts[i].ctrls->num_ctrls;
 
 	v4l2_ctrl_handler_init(&ctx->ctrl_hdl, nctrls);
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
-		ret = rkvdec_add_ctrls(ctx, rkvdec_coded_fmts[i].ctrls);
+	for (i = 0; i < cfg->coded_fmts_num; i++) {
+		ret = rkvdec_add_ctrls(ctx, cfg->coded_fmts[i].ctrls);
 		if (ret)
 			goto err_free_handler;
 	}

drivers/media/platform/rockchip/rkvdec/rkvdec.c static void rkvdec_watchdog_func(struct work_struct *work) · line 1130

Quoted 4 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
@@ -1119,8 +1127,13 @@ static void rkvdec_watchdog_func(struct work_struct *work)
 	}
 }
 
+const struct rkvdec_config config_rkvdec = {

Why isn't this static?

Quoted 11 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +5 -1
+	.coded_fmts = (struct rkvdec_coded_fmt_desc *)rkvdec_coded_fmts,
+	.coded_fmts_num = ARRAY_SIZE(rkvdec_coded_fmts),
+};
+
 static const struct of_device_id of_rkvdec_match[] = {
-	{ .compatible = "rockchip,rk3399-vdec" },
+	{ .compatible = "rockchip,rk3399-vdec", .data = &config_rkvdec },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, of_rkvdec_match);

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1161

Quoted 5 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +2 -0
@@ -1144,6 +1157,9 @@ static int rkvdec_probe(struct platform_device *pdev)
 	mutex_init(&rkvdec->vdev_lock);
 	INIT_DELAYED_WORK(&rkvdec->watchdog_work, rkvdec_watchdog_func);
 
+	rkvdec->config =
+		(struct rkvdec_config *)of_device_get_match_data(rkvdec->dev);

If you need a cast, your code is wrong.

Best regards,
Krzysztof

author maintainer
#7 lore raw

Re: [PATCH v2 05/12] media: rkvdec: Add per variant configuration

Hi Krzysztof,

Quoted 4 lines · On Monday, 11 August 2025 02:13:04 EDT Krzysztof Kozlowski wrote:
Quoted 1 line · Detlev Casanova

This is to prepare for adding different variants of the decoder and

Prepare for...

Sounds better indeed.

Quoted 20 lines
Quoted 4 lines

support specific formats and ops.

---

...

Quoted 13 lines

static int rkvdec_init_ctrls(struct rkvdec_ctx *ctx) {

drivers/media/platform/rockchip/rkvdec/rkvdec.c +3 -2
+	struct rkvdec_config *cfg = ctx->dev->config;
 
 	unsigned int i, nctrls = 0;
 	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++)
-		nctrls += rkvdec_coded_fmts[i].ctrls->num_ctrls;
+	for (i = 0; i < cfg->coded_fmts_num; i++)
+		nctrls += cfg->coded_fmts[i].ctrls->num_ctrls;
Quoted 4 lines

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_add_ctrls(struct rkvdec_ctx *ctx,

Quoted 4 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -2
 	v4l2_ctrl_handler_init(&ctx->ctrl_hdl, nctrls);
 
-	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
-		ret = rkvdec_add_ctrls(ctx, 

rkvdec_coded_fmts[i].ctrls);

Quoted 37 lines
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +2 -0
+	for (i = 0; i < cfg->coded_fmts_num; i++) {
+		ret = rkvdec_add_ctrls(ctx, cfg->coded_fmts[i].ctrls);
 
 		if (ret)
 
 			goto err_free_handler;
 
 	}

drivers/media/platform/rockchip/rkvdec/rkvdec.c static void rkvdec_watchdog_func(struct work_struct · line 1132

Quoted 6 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
@@ -1119,8 +1127,13 @@ static void rkvdec_watchdog_func(struct work_struct
 *work)> 
 	}
 
 }
 
+const struct rkvdec_config config_rkvdec = {

Why isn't this static?

Quoted 18 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +5 -1
+	.coded_fmts = (struct rkvdec_coded_fmt_desc *)rkvdec_coded_fmts,
+	.coded_fmts_num = ARRAY_SIZE(rkvdec_coded_fmts),
+};
+
 
 static const struct of_device_id of_rkvdec_match[] = {
 
-	{ .compatible = "rockchip,rk3399-vdec" },
+	{ .compatible = "rockchip,rk3399-vdec", .data = &config_rkvdec },
 
 	{ /* sentinel */ }
 
 };
 MODULE_DEVICE_TABLE(of, of_rkvdec_match);
@@ -1144,6 +1157,9 @@ static int rkvdec_probe(struct platform_device
 *pdev)
 
Quoted 8 lines

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +2 -0
 	mutex_init(&rkvdec->vdev_lock);
 	INIT_DELAYED_WORK(&rkvdec->watchdog_work, rkvdec_watchdog_func);
 
+	rkvdec->config =
+		(struct rkvdec_config *)of_device_get_match_data(rkvdec-

dev);

If you need a cast, your code is wrong.

Right, some const/static addition is needed. I'll fix that :)

Detlev.

author maintainer
#8 lore raw

PATCH v2 6/12 media: rkvdec: Add RCB and SRAM support

In reply to Detlev Casanova

The RCB (Rows and Cols Buffers) are a set of buffers used by other variations of the decoder to store temporary data.

Those variation come with a dedicated SRAM area used to store those buffers for better performances.

The buffer sizes are either the width or height of the frame being decoded multiplied by a documented factor and can be stored either in SRAM or RAM.
A fallback to RAM is provided if the SRAM is full (e.g.: multiple streams are being decoded at the same time).

To manage the different kind of allocation, an enum is added to the rkvdec_aux_buf struct to specify how the buffer was allocated, and so, how to free it.

This commit is in preparation of other variants support.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../platform/rockchip/rkvdec/rkvdec-rcb.c     | 174 ++++++++++++++++++
 .../platform/rockchip/rkvdec/rkvdec-rcb.h     |  29 +++
 .../media/platform/rockchip/rkvdec/rkvdec.c   |  29 ++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |  13 ++
 5 files changed, 242 insertions(+), 4 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
index 94c067084acd1..2b7ba9f7de286 100644
@@ -5,4 +5,5 @@ rockchip-vdec-y += \
 		   rkvdec-cabac.o \
 		   rkvdec-h264.o \
 		   rkvdec-h264-common.o \
+		   rkvdec-rcb.o \
 		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c new file +174 -0

174 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h new file +29 -0
new file mode 100644
index 0000000000000..30e8002555c8a
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Rockchip video decoder Rows and Cols Buffers manager
+ *
+ * Copyright (C) 2025 Collabora, Ltd.
+ *  Detlev Casanova <[email protected]>
+ */
+
+#include <linux/types.h>
+
+struct rkvdec_ctx;
+
+enum rcb_axis {
+	PIC_WIDTH = 0,
+	PIC_HEIGHT = 1
+};
+
+struct rcb_size_info {
+	u8 multiplier;
+	enum rcb_axis axis;
+};
+
+int rkvdec_allocate_rcb(struct rkvdec_ctx *ctx,
+			const struct rcb_size_info *size_info,
+			size_t rcb_count);
+dma_addr_t rkvdec_rcb_buf_dma_addr(struct rkvdec_ctx *ctx, int id);
+size_t rkvdec_rcb_buf_size(struct rkvdec_ctx *ctx, int id);
+int rkvdec_rcb_buf_count(struct rkvdec_ctx *ctx);
+void rkvdec_free_rcb(struct rkvdec_ctx *ctx);
drivers/media/platform/rockchip/rkvdec/rkvdec.c +25 -4
index 28585522523c7..2602676a047a1 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/genalloc.h>
 #include <linux/interrupt.h>
 #include <linux/iommu.h>
 #include <linux/module.h>
@@ -27,6 +28,7 @@
 
 #include "rkvdec.h"
 #include "rkvdec-regs.h"
+#include "rkvdec-rcb.h"
 
 static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,
 				   enum rkvdec_image_fmt fmt2)
@@ -668,6 +670,7 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct rkvdec_ctx *ctx = vb2_get_drv_priv(q);
 	const struct rkvdec_coded_fmt_desc *desc;
+	struct rkvdec_config *cfg = ctx->dev->config;
 	int ret;
 
 	if (V4L2_TYPE_IS_CAPTURE(q->type))
@@ -677,13 +680,22 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)
 	if (WARN_ON(!desc))
 		return -EINVAL;
 
+	ret = rkvdec_allocate_rcb(ctx, cfg->rcb_size_info, cfg->rcb_num);
+	if (ret)
+		return ret;
+
 	if (desc->ops->start) {
 		ret = desc->ops->start(ctx);
 		if (ret)
-			return ret;
+			goto err_ops_start;
 	}
 
 	return 0;
+
+err_ops_start:
+	rkvdec_free_rcb(ctx);
+
+	return ret;
 }
 
 static void rkvdec_queue_cleanup(struct vb2_queue *vq, u32 state)
@@ -719,6 +731,8 @@ static void rkvdec_stop_streaming(struct vb2_queue *q)
 
 		if (desc->ops->stop)
 			desc->ops->stop(ctx);
+
+		rkvdec_free_rcb(ctx);
 	}
 
 	rkvdec_queue_cleanup(q, VB2_BUF_STATE_ERROR);
@@ -1183,15 +1197,14 @@ static int rkvdec_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	if (iommu_get_domain_for_dev(&pdev->dev)) {
+	rkvdec->iommu_domain = iommu_get_domain_for_dev(&pdev->dev);
+	if (rkvdec->iommu_domain) {
 		rkvdec->empty_domain = iommu_paging_domain_alloc(rkvdec->dev);
 
 		if (!rkvdec->empty_domain)
 			dev_warn(rkvdec->dev, "cannot alloc new empty domain\n");
 	}
 
-	vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
-
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0)
 		return -ENXIO;
@@ -1204,6 +1217,10 @@ static int rkvdec_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	rkvdec->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
+	if (!rkvdec->sram_pool && rkvdec->config->rcb_num > 0)
+		dev_info(&pdev->dev, "No sram node, RCB will be stored in RAM\n");
+
 	pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
 	pm_runtime_use_autosuspend(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
@@ -1217,6 +1234,10 @@ static int rkvdec_probe(struct platform_device *pdev)
 err_disable_runtime_pm:
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
+
+	if (rkvdec->sram_pool)
+		gen_pool_destroy(rkvdec->sram_pool);
+
 	return ret;
 }
 
drivers/media/platform/rockchip/rkvdec/rkvdec.h +13 -0
index 14717c646c665..3a073883d21eb 100644
@@ -19,10 +19,12 @@
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
+#include <media/v4l2-mem2mem.h>
 #include <media/videobuf2-core.h>
 #include <media/videobuf2-dma-contig.h>
 
 struct rkvdec_ctx;
+struct rkvdec_rcb_config;
 
 struct rkvdec_ctrl_desc {
 	struct v4l2_ctrl_config cfg;
@@ -103,6 +105,8 @@ struct rkvdec_coded_fmt_desc {
 struct rkvdec_config {
 	struct rkvdec_coded_fmt_desc *coded_fmts;
 	size_t coded_fmts_num;
+	struct rcb_size_info *rcb_size_info;
+	size_t rcb_num;
 };
 
 struct rkvdec_dev {
@@ -115,6 +119,8 @@ struct rkvdec_dev {
 	void __iomem *regs;
 	struct mutex vdev_lock; /* serializes ioctls */
 	struct delayed_work watchdog_work;
+	struct gen_pool *sram_pool;
+	struct iommu_domain *iommu_domain;
 	struct iommu_domain *empty_domain;
 	struct rkvdec_config *config;
 };
@@ -127,6 +133,7 @@ struct rkvdec_ctx {
 	struct v4l2_ctrl_handler ctrl_hdl;
 	struct rkvdec_dev *dev;
 	enum rkvdec_image_fmt image_fmt;
+	struct rkvdec_rcb_config *rcb_config;
 	void *priv;
 };
 
@@ -135,10 +142,16 @@ static inline struct rkvdec_ctx *fh_to_rkvdec_ctx(struct v4l2_fh *fh)
 	return container_of(fh, struct rkvdec_ctx, fh);
 }
 
+enum rkvdec_alloc_type {
+	RKVDEC2_ALLOC_DMA  = 0,
+	RKVDEC2_ALLOC_SRAM = 1,
+};
+
 struct rkvdec_aux_buf {
 	void *cpu;
 	dma_addr_t dma;
 	size_t size;
+	enum rkvdec_alloc_type type;
 };
 
 void rkvdec_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
Signature · 1 line
2.50.1
#9 lore raw

Re: [PATCH v2 06/12] media: rkvdec: Add RCB and SRAM support

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1220

Quoted 11 lines · Detlev Casanova
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -2
-	vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
-
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0)
 		return -ENXIO;
@@ -1204,6 +1217,10 @@ static int rkvdec_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	rkvdec->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);

Didn't you just add new ABI?

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1223

Quoted 3 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +3 -0
+	if (!rkvdec->sram_pool && rkvdec->config->rcb_num > 0)
+		dev_info(&pdev->dev, "No sram node, RCB will be stored in RAM\n");
+

Best regards,
Krzysztof

author maintainer
#10 lore raw

Re: [PATCH v2 06/12] media: rkvdec: Add RCB and SRAM support

Quoted 13 lines · On Monday, 11 August 2025 02:13:42 EDT Krzysztof Kozlowski wrote:
Quoted 12 lines · Detlev Casanova
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -2
-	vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
-
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0)
 
 		return -ENXIO;
@@ -1204,6 +1217,10 @@ static int rkvdec_probe(struct platform_device
 *pdev)> 
 		return ret;
 
Quoted 5 lines

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1220

Quoted 3 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
 	}
 
+	rkvdec->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);

Didn't you just add new ABI?

Oh do you mean rkvdec_rcb_buf_count() ? I could indeed use that instead here.

Quoted 2 lines

Review static int rkvdec_probe(struct platform_device · line 1224

Quoted 2 lines
(quoted diff) +2 -0
+	if (!rkvdec->sram_pool && rkvdec->config->rcb_num > 0)
+		dev_info(&pdev->dev, "No sram node, RCB will be stored 

in RAM\n");

Quoted 4 lines

Review static int rkvdec_probe(struct platform_device · line 1225

Quoted 1 line
(quoted diff) +1 -0
+

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH v2 06/12] media: rkvdec: Add RCB and SRAM support

Quoted 14 lines · Detlev Casanova
Quoted 13 lines · On Monday, 11 August 2025 02:13:42 EDT Krzysztof Kozlowski wrote:
Quoted 12 lines · Detlev Casanova
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -2
-	vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
-
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0)
 
 		return -ENXIO;
@@ -1204,6 +1217,10 @@ static int rkvdec_probe(struct platform_device
 *pdev)> 
 		return ret;
 
Quoted 7 lines
Quoted 5 lines

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1220

Quoted 3 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
 	}
 
+	rkvdec->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);

Didn't you just add new ABI?

Oh do you mean rkvdec_rcb_buf_count() ? I could indeed use that instead here.

No, I meant DT/OF ABI for "sram".

Best regards,
Krzysztof

author maintainer
#12 lore raw

Re: [PATCH v2 06/12] media: rkvdec: Add RCB and SRAM support

Quoted 18 lines · On Monday, 11 August 2025 10:01:59 EDT Krzysztof Kozlowski wrote:
Quoted 17 lines · Detlev Casanova
Quoted 16 lines · On Monday, 11 August 2025 02:13:42 EDT Krzysztof Kozlowski wrote:
Quoted 15 lines · Detlev Casanova
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -2
-	vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
-
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq <= 0)
 
 		return -ENXIO;
@@ -1204,6 +1217,10 @@ static int rkvdec_probe(struct platform_device
 *pdev)>
 
 		return ret;
 
 	}
 
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1220

Quoted 1 line
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
+	rkvdec->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);

Didn't you just add new ABI?

Oh do you mean rkvdec_rcb_buf_count() ? I could indeed use that instead here.

No, I meant DT/OF ABI for "sram".

Yes, the sram Documentation was added in commit c6ffb7e1fb90 "media: dt-
bindings: rockchip: Document RK3588 Video Decoder bindings".

Is that not how it is supposed to be used ?

Detlev.

author maintainer
#13 lore raw

PATCH v2 7/12 media: rkvdec: Support per-variant interrupt handler

In reply to Detlev Casanova

Preparation commit for supporting different variants with different interrupt management.

---
 drivers/media/platform/rockchip/rkvdec/rkvdec.c | 15 ++++++++++++---
 drivers/media/platform/rockchip/rkvdec/rkvdec.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +12 -3
index 2602676a047a1..5f3057e8136b5 100644
@@ -1102,10 +1102,9 @@ static void rkvdec_iommu_restore(struct rkvdec_dev *rkvdec)
 	}
 }
 
-static irqreturn_t rkvdec_irq_handler(int irq, void *priv)
+static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)
 {
-	struct rkvdec_dev *rkvdec = priv;
-	struct rkvdec_ctx *ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
+	struct rkvdec_dev *rkvdec = ctx->dev;
 	enum vb2_buffer_state state;
 	u32 status;
 
@@ -1126,6 +1125,15 @@ static irqreturn_t rkvdec_irq_handler(int irq, void *priv)
 	return IRQ_HANDLED;
 }
 
+static irqreturn_t rkvdec_irq_handler(int irq, void *priv)
+{
+	struct rkvdec_dev *rkvdec = priv;
+	struct rkvdec_ctx *ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
+	struct rkvdec_config *cfg = rkvdec->config;
+
+	return cfg->irq_handler(ctx);
+}
+
 static void rkvdec_watchdog_func(struct work_struct *work)
 {
 	struct rkvdec_dev *rkvdec;
@@ -1144,6 +1152,7 @@ static void rkvdec_watchdog_func(struct work_struct *work)
 const struct rkvdec_config config_rkvdec = {
 	.coded_fmts = (struct rkvdec_coded_fmt_desc *)rkvdec_coded_fmts,
 	.coded_fmts_num = ARRAY_SIZE(rkvdec_coded_fmts),
+	.irq_handler = rk3399_irq_handler,
 };
 
 static const struct of_device_id of_rkvdec_match[] = {
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index 3a073883d21eb..679de66df2479 100644
@@ -107,6 +107,7 @@ struct rkvdec_config {
 	size_t coded_fmts_num;
 	struct rcb_size_info *rcb_size_info;
 	size_t rcb_num;
+	irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx);
 };
 
 struct rkvdec_dev {
Signature · 1 line
2.50.1
author maintainer
#14 lore raw

PATCH v2 8/12 media: rkvdec: Enable all clocks without naming them

In reply to Detlev Casanova

For other variants, the clock names and number will differ.

There is no need to keep track of the clock names in the driver so drop them to avoid having a list for each variant.

---
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 24 +++++--------------
 .../media/platform/rockchip/rkvdec/rkvdec.h   |  1 +
 2 files changed, 7 insertions(+), 18 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6 -18
index 5f3057e8136b5..0ccf1ba81958a 100644
@@ -1161,14 +1161,9 @@ static const struct of_device_id of_rkvdec_match[] = {
 };
 MODULE_DEVICE_TABLE(of, of_rkvdec_match);
 
-static const char * const rkvdec_clk_names[] = {
-	"axi", "ahb", "cabac", "core"
-};
-
 static int rkvdec_probe(struct platform_device *pdev)
 {
 	struct rkvdec_dev *rkvdec;
-	unsigned int i;
 	int ret, irq;
 
 	rkvdec = devm_kzalloc(&pdev->dev, sizeof(*rkvdec), GFP_KERNEL);
@@ -1183,19 +1178,12 @@ static int rkvdec_probe(struct platform_device *pdev)
 	rkvdec->config =
 		(struct rkvdec_config *)of_device_get_match_data(rkvdec->dev);
 
-	rkvdec->clocks = devm_kcalloc(&pdev->dev, ARRAY_SIZE(rkvdec_clk_names),
-				      sizeof(*rkvdec->clocks), GFP_KERNEL);
-	if (!rkvdec->clocks)
-		return -ENOMEM;
-
-	for (i = 0; i < ARRAY_SIZE(rkvdec_clk_names); i++)
-		rkvdec->clocks[i].id = rkvdec_clk_names[i];
-
-	ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(rkvdec_clk_names),
-				rkvdec->clocks);
-	if (ret)
+	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &rkvdec->clocks);
+	if (ret < 0)
 		return ret;
 
+	rkvdec->clk_count = ret;
+
 	rkvdec->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(rkvdec->regs))
 		return PTR_ERR(rkvdec->regs);
@@ -1269,7 +1257,7 @@ static int rkvdec_runtime_resume(struct device *dev)
 {
 	struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
 
-	return clk_bulk_prepare_enable(ARRAY_SIZE(rkvdec_clk_names),
+	return clk_bulk_prepare_enable(rkvdec->clk_count,
 				       rkvdec->clocks);
 }
 
@@ -1277,7 +1265,7 @@ static int rkvdec_runtime_suspend(struct device *dev)
 {
 	struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
 
-	clk_bulk_disable_unprepare(ARRAY_SIZE(rkvdec_clk_names),
+	clk_bulk_disable_unprepare(rkvdec->clk_count,
 				   rkvdec->clocks);
 	return 0;
 }
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index 679de66df2479..af47f16cb417d 100644
@@ -117,6 +117,7 @@ struct rkvdec_dev {
 	struct v4l2_m2m_dev *m2m_dev;
 	struct device *dev;
 	struct clk_bulk_data *clocks;
+	unsigned int clk_count;
 	void __iomem *regs;
 	struct mutex vdev_lock; /* serializes ioctls */
 	struct delayed_work watchdog_work;
Signature · 1 line
2.50.1
author maintainer
#15 lore raw

PATCH v2 9/12 media: rkvdec: Add H264 support for the VDPU381 variant

In reply to Detlev Casanova

This decoder variant is found in Rockchip RK3588 SoC family.

Like for rkvdec on rk3399, it supports the NV12, NV15, NV16 and NV20 output formats and level up to 5.1.

The maximum width and height have been significantly increased supporting up to 65520 pixels for both.

Also make sure to only expose the first core and ignore the other until mutli-core is supported.

Fluster score for JVT-AVC_V1 is 129/135.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-h264-common.h      |   2 +
 .../platform/rockchip/rkvdec/rkvdec-h264.c    |  36 --
 .../rockchip/rkvdec/rkvdec-vdpu381-h264.c     | 469 ++++++++++++++++++
 .../rockchip/rkvdec/rkvdec-vdpu381-regs.h     | 427 ++++++++++++++++
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 164 +++++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   6 +
 7 files changed, 1067 insertions(+), 38 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
index 2b7ba9f7de286..20128bb6e35dc 100644
@@ -6,4 +6,5 @@ rockchip-vdec-y += \
 		   rkvdec-h264.o \
 		   rkvdec-h264-common.o \
 		   rkvdec-rcb.o \
+		   rkvdec-vdpu381-h264.o \
 		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h +2 -0
index df95a16787341..38446e2886e3d 100644
@@ -66,6 +66,8 @@ struct rkvdec_rps {
 	u32 reserved1[66];
 } __packed;
 
+extern const s8 rkvdec_h264_cabac_table[4][464][2];
+
 void lookup_ref_buf_idx(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run);
 void assemble_hw_rps(struct v4l2_h264_reflist_builder *builder,
 		     struct rkvdec_h264_run *run,
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +0 -36
index 28a0ab7840c3e..d50e985cff953 100644
@@ -16,8 +16,6 @@
 #include "rkvdec-regs.h"
 #include "rkvdec-h264-common.h"
 
-extern const s8 rkvdec_h264_cabac_table[4][464][2];
-
 /* Size with u32 units. */
 #define RKV_CABAC_INIT_BUFFER_SIZE	(3680 + 128)
 #define RKV_ERROR_INFO_SIZE		(256 * 144 * 4)
@@ -26,40 +24,6 @@ struct rkvdec_sps_pps_packet {
 	u32 info[8];
 };
 
-struct rkvdec_rps_entry {
-	u32 dpb_info0:          5;
-	u32 bottom_flag0:       1;
-	u32 view_index_off0:    1;
-	u32 dpb_info1:          5;
-	u32 bottom_flag1:       1;
-	u32 view_index_off1:    1;
-	u32 dpb_info2:          5;
-	u32 bottom_flag2:       1;
-	u32 view_index_off2:    1;
-	u32 dpb_info3:          5;
-	u32 bottom_flag3:       1;
-	u32 view_index_off3:    1;
-	u32 dpb_info4:          5;
-	u32 bottom_flag4:       1;
-	u32 view_index_off4:    1;
-	u32 dpb_info5:          5;
-	u32 bottom_flag5:       1;
-	u32 view_index_off5:    1;
-	u32 dpb_info6:          5;
-	u32 bottom_flag6:       1;
-	u32 view_index_off6:    1;
-	u32 dpb_info7:          5;
-	u32 bottom_flag7:       1;
-	u32 view_index_off7:    1;
-} __packed;
-
-struct rkvdec_rps {
-	u16 frame_num[16];
-	u32 reserved0;
-	struct rkvdec_rps_entry entries[12];
-	u32 reserved1[66];
-} __packed;
-
 struct rkvdec_ps_field {
 	u16 offset;
 	u8 len;
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c new file +469 -0

469 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +427 -0

427 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.c +162 -2

217 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.h +6 -0
index af47f16cb417d..9e0fef2445abc 100644
@@ -108,6 +108,8 @@ struct rkvdec_config {
 	struct rcb_size_info *rcb_size_info;
 	size_t rcb_num;
 	irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx);
+	int (*fill_pixfmt_mp)(struct v4l2_pix_format_mplane *pix_mp, u32 pixelformat,
+			      u32 width, u32 height);
 };
 
 struct rkvdec_dev {
@@ -118,6 +120,7 @@ struct rkvdec_dev {
 	struct device *dev;
 	struct clk_bulk_data *clocks;
 	unsigned int clk_count;
+	struct clk *axi_clk;
 	void __iomem *regs;
 	struct mutex vdev_lock; /* serializes ioctls */
 	struct delayed_work watchdog_work;
@@ -136,6 +139,7 @@ struct rkvdec_ctx {
 	struct rkvdec_dev *dev;
 	enum rkvdec_image_fmt image_fmt;
 	struct rkvdec_rcb_config *rcb_config;
+	u32 colmv_offset;
 	void *priv;
 };
 
@@ -163,4 +167,6 @@ void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);
 extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;
 extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
 
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops;
+
 #endif /* RKVDEC_H_ */
Signature · 1 line
2.50.1
#16 lore raw

Re: [PATCH v2 09/12] media: rkvdec: Add H264 support for the VDPU381 variant

Quoted 4 lines · Detlev Casanova
drivers/media/platform/rockchip/rkvdec/rkvdec.c +4 -0
+static struct rcb_size_info vdpu381_rcb_sizes[] = {
+	{6,	PIC_WIDTH},	// intrar
+	{1,	PIC_WIDTH},	// transdr (Is actually 0.4*pic_width)
+	{1,	PIC_HEIGHT},	// transdc (Is actually 0.1*pic_height)

drivers/media/platform/rockchip/rkvdec/rkvdec.c static void rkvdec_watchdog_func(struct work_struct *work) · line 1303

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{3,	PIC_WIDTH},	// streamdr
+	{6,	PIC_WIDTH},	// interr
+	{3,	PIC_HEIGHT},	// interc
+	{22,	PIC_WIDTH},	// dblkr
+	{6,	PIC_WIDTH},	// saor
+	{11,	PIC_WIDTH},	// fbcr
+	{67,	PIC_HEIGHT},	// filtc col
+};
+
+const struct rkvdec_config config_vdpu381 = {

Nit: config_vdpu381 should be declared as "static", same for config_vdpu383 in the next patch

Signature · 2 lines
Best regards,
Dmitry
#17 lore raw

Re: [PATCH v2 09/12] media: rkvdec: Add H264 support for the VDPU381 variant

In reply to Detlev Casanova

Hi Detlev,

Thanks a LOT for this patch set!
As already reported the results were quite impressive :-D

To figure out how to make VDPU346 for rk3568 work, I had a close look at the TRM and compared that to rk3588's TRM and compared it to your code. I think I may have found a few potential issue, but I may also not understand things correctly.

Quoted 48 lines · Detlev Casanova

This decoder variant is found in Rockchip RK3588 SoC family.

Like for rkvdec on rk3399, it supports the NV12, NV15, NV16 and NV20 output formats and level up to 5.1.

The maximum width and height have been significantly increased supporting up to 65520 pixels for both.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-h264-common.h      |   2 +
 .../platform/rockchip/rkvdec/rkvdec-h264.c    |  36 --
 .../rockchip/rkvdec/rkvdec-vdpu381-h264.c     | 469 ++++++++++++++++++
 .../rockchip/rkvdec/rkvdec-vdpu381-regs.h     | 427 ++++++++++++++++
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 164 +++++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   6 +
 7 files changed, 1067 insertions(+), 38 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h

...

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +19 -0
new file mode 100644
index 0000000000000..11b545e9ee7ea
@@ -0,0 +1,427 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Rockchip VDPU381 Video Decoder driver registers description
+ *
+ * Copyright (C) 2024 Collabora, Ltd.
+ *  Detlev Casanova <[email protected]>
+ */
+
+#include <linux/types.h>
+
+#ifndef _RKVDEC_REGS_H_
+#define _RKVDEC_REGS_H_
+
+#define OFFSET_COMMON_REGS		(8 * sizeof(u32))
+#define OFFSET_CODEC_PARAMS_REGS	(64 * sizeof(u32))
+#define OFFSET_COMMON_ADDR_REGS		(128 * sizeof(u32))
+#define OFFSET_CODEC_ADDR_REGS		(160 * sizeof(u32))
+#define OFFSET_POC_HIGHBIT_REGS		(200 * sizeof(u32))
+

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h line 29

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +10 -0
+#define VDPU381_MODE_HEVC	0
+#define VDPU381_MODE_H264	1
+#define VDPU381_MODE_VP9	2
+#define VDPU381_MODE_AVS2	3
+
+#define MAX_SLICE_NUMBER	0x3fff
+
+#define RKVDEC_1080P_PIXELS		(1920 * 1080)
+#define RKVDEC_4K_PIXELS		(4096 * 2304)
+#define RKVDEC_8K_PIXELS		(7680 * 4320)

In the RK3588 TRM Part 1 paragraph 5.4.3 I can find the values for 4K and 8K, but the 1080P resolution seems to be 1920x1088 (not 1080).

Quoted 91 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +18 -0
+#define RKVDEC_TIMEOUT_1080p		(0xefffff)
+#define RKVDEC_TIMEOUT_4K		(0x2cfffff)
+#define RKVDEC_TIMEOUT_8K		(0x4ffffff)
+#define RKVDEC_TIMEOUT_MAX		(0xffffffff)
+
+#define VDPU381_REG_DEC_E		0x028
+#define VDPU381_DEC_E_BIT		1
+
+#define VDPU381_REG_IMPORTANT_EN	0x02c
+#define VDPU381_DEC_IRQ_DISABLE	BIT(4)
+
+#define VDPU381_REG_STA_INT		0x380
+#define VDPU381_STA_INT_DEC_RDY_STA	BIT(2)
+#define VDPU381_STA_INT_ERROR		BIT(4)
+#define VDPU381_STA_INT_TIMEOUT		BIT(5)
+#define VDPU381_STA_INT_SOFTRESET_RDY	BIT(9)
+
+/* base: OFFSET_COMMON_REGS */
 
...
drivers/media/platform/rockchip/rkvdec/rkvdec.c +43 -2
index 0ccf1ba81958a..1b55fe4ff2baf 100644
@@ -28,6 +28,7 @@
 
 #include "rkvdec.h"
 #include "rkvdec-regs.h"
+#include "rkvdec-vdpu381-regs.h"
 #include "rkvdec-rcb.h"
 
 static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,
@@ -84,11 +85,50 @@ static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc,
 	return false;
 }
 
+#define VDPU38X_STRIDE_ALIGN	16
+
+/**
+ * The default v4l2_fill_pixfmt_mp() function doesn't allow for specific alignment values.
+ * As the VDPU381 and VDPU383 need lines to be aligned on 16, use our own implementation here.
+ */
+static int vdpu38x_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pix_mp, u32 pixelformat,
+				  u32 width, u32 height)
+{
+	const struct v4l2_format_info *info = v4l2_format_info(pix_mp->pixelformat);
+	struct v4l2_plane_pix_format *plane = &pix_mp->plane_fmt[0];
+
+	if (!info)
+		return -EINVAL;
+
+	pix_mp->num_planes = 1;
+
+	memset(plane, 0, sizeof(*plane));
+
+	plane->bytesperline = pix_mp->width * info->bpp[0] / info->bpp_div[0];
+	plane->bytesperline = ALIGN(plane->bytesperline, VDPU38X_STRIDE_ALIGN);
+
+	for (int i = 0; i < info->comp_planes; i++) {
+		unsigned int vdiv = i ? info->vdiv : 1;
+		unsigned int hdiv = i ? info->hdiv : 1;
+		unsigned int stride = DIV_ROUND_UP(pix_mp->width, hdiv)
+				    * info->bpp[i] / info->bpp_div[i];
+		unsigned int height = DIV_ROUND_UP(pix_mp->height, vdiv);
+
+		plane->sizeimage += ALIGN(stride, VDPU38X_STRIDE_ALIGN) * height;
+	}
+
+	return 0;
+}
+
 static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx *ctx,
 				       struct v4l2_pix_format_mplane *pix_mp)
 {
-	v4l2_fill_pixfmt_mp(pix_mp, pix_mp->pixelformat,
-			    pix_mp->width, pix_mp->height);
+	struct rkvdec_config *cfg = ctx->dev->config;
+
+	cfg->fill_pixfmt_mp(pix_mp, pix_mp->pixelformat, pix_mp->width, pix_mp->height);
+
+	ctx->colmv_offset = pix_mp->plane_fmt[0].sizeimage;
+
 	pix_mp->plane_fmt[0].sizeimage += 128 *
 		DIV_ROUND_UP(pix_mp->width, 16) *
 		DIV_ROUND_UP(pix_mp->height, 16);
@@ -287,6 +327,25 @@ static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = {
 	}
 };
 
+static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = { · line 340

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_H264_SLICE,
+		.frmsize = {
+			.min_width = 64,
+			.max_width =  65520,
+			.step_width = 64,
+			.min_height = 16,
+			.max_height =  65520,
+			.step_height = 16,
+		},

Also in the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
16x16 to 65520x65520; step size 16 pixels

I interpret that that .min_width and .step_width should both be 16. (.min_height and .step_height are correct at 16; if I read the TRM right)

drivers/media/platform/rockchip/rkvdec/rkvdec.c static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)

Quoted 12 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +8 -0
+		.ctrls = &rkvdec_h264_ctrls,
+		.ops = &rkvdec_vdpu381_h264_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_h264_decoded_fmts),
+		.decoded_fmts = rkvdec_h264_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
+};
+
 static const struct rkvdec_coded_fmt_desc *
 rkvdec_find_coded_fmt_desc(struct rkvdec_ctx *ctx, u32 fourcc)
 {
@@ -1125,6 +1184,35 @@ static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)

Cheers,
Diederik

#18 lore raw

Re: [PATCH v2 09/12] media: rkvdec: Add H264 support for the VDPU381 variant

Hi Diederik,

Quoted 178 lines · Diederik de Haas

Hi Detlev,

Thanks a LOT for this patch set!
As already reported the results were quite impressive :-D

To figure out how to make VDPU346 for rk3568 work, I had a close look at the TRM and compared that to rk3588's TRM and compared it to your code. I think I may have found a few potential issue, but I may also not understand things correctly.

Quoted 48 lines · Detlev Casanova

This decoder variant is found in Rockchip RK3588 SoC family.

Like for rkvdec on rk3399, it supports the NV12, NV15, NV16 and NV20 output formats and level up to 5.1.

The maximum width and height have been significantly increased supporting up to 65520 pixels for both.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-h264-common.h      |   2 +
 .../platform/rockchip/rkvdec/rkvdec-h264.c    |  36 --
 .../rockchip/rkvdec/rkvdec-vdpu381-h264.c     | 469 ++++++++++++++++++
 .../rockchip/rkvdec/rkvdec-vdpu381-regs.h     | 427 ++++++++++++++++
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 164 +++++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   6 +
 7 files changed, 1067 insertions(+), 38 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h

...

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +19 -0
new file mode 100644
index 0000000000000..11b545e9ee7ea
@@ -0,0 +1,427 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Rockchip VDPU381 Video Decoder driver registers description
+ *
+ * Copyright (C) 2024 Collabora, Ltd.
+ *  Detlev Casanova <[email protected]>
+ */
+
+#include <linux/types.h>
+
+#ifndef _RKVDEC_REGS_H_
+#define _RKVDEC_REGS_H_
+
+#define OFFSET_COMMON_REGS		(8 * sizeof(u32))
+#define OFFSET_CODEC_PARAMS_REGS	(64 * sizeof(u32))
+#define OFFSET_COMMON_ADDR_REGS		(128 * sizeof(u32))
+#define OFFSET_CODEC_ADDR_REGS		(160 * sizeof(u32))
+#define OFFSET_POC_HIGHBIT_REGS		(200 * sizeof(u32))
+

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h line 29

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +10 -0
+#define VDPU381_MODE_HEVC	0
+#define VDPU381_MODE_H264	1
+#define VDPU381_MODE_VP9	2
+#define VDPU381_MODE_AVS2	3
+
+#define MAX_SLICE_NUMBER	0x3fff
+
+#define RKVDEC_1080P_PIXELS		(1920 * 1080)
+#define RKVDEC_4K_PIXELS		(4096 * 2304)
+#define RKVDEC_8K_PIXELS		(7680 * 4320)

In the RK3588 TRM Part 1 paragraph 5.4.3 I can find the values for 4K and 8K, but the 1080P resolution seems to be 1920x1088 (not 1080).

Quoted 91 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +18 -0
+#define RKVDEC_TIMEOUT_1080p		(0xefffff)
+#define RKVDEC_TIMEOUT_4K		(0x2cfffff)
+#define RKVDEC_TIMEOUT_8K		(0x4ffffff)
+#define RKVDEC_TIMEOUT_MAX		(0xffffffff)
+
+#define VDPU381_REG_DEC_E		0x028
+#define VDPU381_DEC_E_BIT		1
+
+#define VDPU381_REG_IMPORTANT_EN	0x02c
+#define VDPU381_DEC_IRQ_DISABLE	BIT(4)
+
+#define VDPU381_REG_STA_INT		0x380
+#define VDPU381_STA_INT_DEC_RDY_STA	BIT(2)
+#define VDPU381_STA_INT_ERROR		BIT(4)
+#define VDPU381_STA_INT_TIMEOUT		BIT(5)
+#define VDPU381_STA_INT_SOFTRESET_RDY	BIT(9)
+
+/* base: OFFSET_COMMON_REGS */
 
...
drivers/media/platform/rockchip/rkvdec/rkvdec.c +43 -2
index 0ccf1ba81958a..1b55fe4ff2baf 100644
@@ -28,6 +28,7 @@
 
 #include "rkvdec.h"
 #include "rkvdec-regs.h"
+#include "rkvdec-vdpu381-regs.h"
 #include "rkvdec-rcb.h"
 
 static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,
@@ -84,11 +85,50 @@ static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc,
 	return false;
 }
 
+#define VDPU38X_STRIDE_ALIGN	16
+
+/**
+ * The default v4l2_fill_pixfmt_mp() function doesn't allow for specific alignment values.
+ * As the VDPU381 and VDPU383 need lines to be aligned on 16, use our own implementation here.
+ */
+static int vdpu38x_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pix_mp, u32 pixelformat,
+				  u32 width, u32 height)
+{
+	const struct v4l2_format_info *info = v4l2_format_info(pix_mp->pixelformat);
+	struct v4l2_plane_pix_format *plane = &pix_mp->plane_fmt[0];
+
+	if (!info)
+		return -EINVAL;
+
+	pix_mp->num_planes = 1;
+
+	memset(plane, 0, sizeof(*plane));
+
+	plane->bytesperline = pix_mp->width * info->bpp[0] / info->bpp_div[0];
+	plane->bytesperline = ALIGN(plane->bytesperline, VDPU38X_STRIDE_ALIGN);
+
+	for (int i = 0; i < info->comp_planes; i++) {
+		unsigned int vdiv = i ? info->vdiv : 1;
+		unsigned int hdiv = i ? info->hdiv : 1;
+		unsigned int stride = DIV_ROUND_UP(pix_mp->width, hdiv)
+				    * info->bpp[i] / info->bpp_div[i];
+		unsigned int height = DIV_ROUND_UP(pix_mp->height, vdiv);
+
+		plane->sizeimage += ALIGN(stride, VDPU38X_STRIDE_ALIGN) * height;
+	}
+
+	return 0;
+}
+
 static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx *ctx,
 				       struct v4l2_pix_format_mplane *pix_mp)
 {
-	v4l2_fill_pixfmt_mp(pix_mp, pix_mp->pixelformat,
-			    pix_mp->width, pix_mp->height);
+	struct rkvdec_config *cfg = ctx->dev->config;
+
+	cfg->fill_pixfmt_mp(pix_mp, pix_mp->pixelformat, pix_mp->width, pix_mp->height);
+
+	ctx->colmv_offset = pix_mp->plane_fmt[0].sizeimage;
+
 	pix_mp->plane_fmt[0].sizeimage += 128 *
 		DIV_ROUND_UP(pix_mp->width, 16) *
 		DIV_ROUND_UP(pix_mp->height, 16);
@@ -287,6 +327,25 @@ static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = {
 	}
 };
 
+static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = { · line 340

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_H264_SLICE,
+		.frmsize = {
+			.min_width = 64,
+			.max_width =  65520,
+			.step_width = 64,
+			.min_height = 16,
+			.max_height =  65520,
+			.step_height = 16,
+		},

Also in the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
16x16 to 65520x65520; step size 16 pixels

Quoted 2 lines

I interpret that that .min_width and .step_width should both be 16. (.min_height and .step_height are correct at 16; if I read the TRM right)

The frmsize used internally for rkvdec is only meant to restrict/align the frame buffer use while decoding, It does not reflect sizes the HW can decode.

frmsize should typically be min 64x64 with step_height 16 and step_width 64 to ensure stride is 16 byte aligned for both 8-bit and 10-bit video.

Only max_width and max_height is used from here to signal userspace what max res is supported, together with min/max res and step of 1.

Regards,
Jonas

Quoted 16 lines

drivers/media/platform/rockchip/rkvdec/rkvdec.c static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)

Quoted 13 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +8 -0
+		.ctrls = &rkvdec_h264_ctrls,
+		.ops = &rkvdec_vdpu381_h264_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_h264_decoded_fmts),
+		.decoded_fmts = rkvdec_h264_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
+};
+
 static const struct rkvdec_coded_fmt_desc *
 rkvdec_find_coded_fmt_desc(struct rkvdec_ctx *ctx, u32 fourcc)
 {
@@ -1125,6 +1184,35 @@ static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)

Cheers,
Diederik

#19 lore raw

Re: [PATCH v2 09/12] media: rkvdec: Add H264 support for the VDPU381 variant

Hi Jonas,

Quoted 66 lines · Jonas Karlman
Quoted 58 lines · Diederik de Haas

Thanks a LOT for this patch set!
As already reported the results were quite impressive :-D

To figure out how to make VDPU346 for rk3568 work, I had a close look at the TRM and compared that to rk3588's TRM and compared it to your code. I think I may have found a few potential issue, but I may also not understand things correctly.

Quoted 35 lines · Detlev Casanova

This decoder variant is found in Rockchip RK3588 SoC family.

Like for rkvdec on rk3399, it supports the NV12, NV15, NV16 and NV20 output formats and level up to 5.1.

The maximum width and height have been significantly increased supporting up to 65520 pixels for both.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-h264-common.h      |   2 +
 .../platform/rockchip/rkvdec/rkvdec-h264.c    |  36 --
 .../rockchip/rkvdec/rkvdec-vdpu381-h264.c     | 469 ++++++++++++++++++
 .../rockchip/rkvdec/rkvdec-vdpu381-regs.h     | 427 ++++++++++++++++
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 164 +++++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   6 +
 7 files changed, 1067 insertions(+), 38 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h

...

drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
index 0ccf1ba81958a..1b55fe4ff2baf 100644
 
...
@@ -287,6 +327,25 @@ static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = {
 	}
 };
 
+static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = { · line 340

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_H264_SLICE,
+		.frmsize = {
+			.min_width = 64,
+			.max_width =  65520,
+			.step_width = 64,
+			.min_height = 16,
+			.max_height =  65520,
+			.step_height = 16,
+		},

Also in the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
16x16 to 65520x65520; step size 16 pixels

Quoted 2 lines

I interpret that that .min_width and .step_width should both be 16. (.min_height and .step_height are correct at 16; if I read the TRM right)

The frmsize used internally for rkvdec is only meant to restrict/align the frame buffer use while decoding, It does not reflect sizes the HW can decode.

Quoted 5 lines

frmsize should typically be min 64x64 with step_height 16 and step_width 64 to ensure stride is 16 byte aligned for both 8-bit and 10-bit video.

Only max_width and max_height is used from here to signal userspace what max res is supported, together with min/max res and step of 1.

Interesting, thanks for the explanation :-)

So if I understand correctly, only .min_height should be changed to '64' here? And it should also be 64+64+64+16 for HEVC (patch 11)? (and also for VP9 and AVS2?)

Quoted 2 lines

Regards,
Jonas

Cheers,
Diederik

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +8 -0
+		.ctrls = &rkvdec_h264_ctrls,
+		.ops = &rkvdec_vdpu381_h264_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_h264_decoded_fmts),
+		.decoded_fmts = rkvdec_h264_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
+};
+
 static const struct rkvdec_coded_fmt_desc *
 rkvdec_find_coded_fmt_desc(struct rkvdec_ctx *ctx, u32 fourcc)
 {
@@ -1125,6 +1184,35 @@ static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)
author maintainer
#20 lore raw

PATCH v2 10/12 media: rkvdec: Add H264 support for the VDPU383 variant

In reply to Detlev Casanova

This variant is used on the RK3576 SoC.

The moving vectors size requirements are slightly different so support for a colmv_size function per variant is added.

Also, the link registers are used to start the decoder and read IRQ status. Per variant support for named register sections is added.

The fluster score is 128/135 for JVT-AVC_V1.
The other test suites are not supported yet.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-vdpu383-h264.c     | 582 ++++++++++++++++++
 .../rockchip/rkvdec/rkvdec-vdpu383-regs.h     | 284 +++++++++
 .../media/platform/rockchip/rkvdec/rkvdec.c   | 109 +++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   8 +
 5 files changed, 978 insertions(+), 6 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
index 20128bb6e35dc..c38ce1e8d3601 100644
@@ -7,4 +7,5 @@ rockchip-vdec-y += \
 		   rkvdec-h264-common.o \
 		   rkvdec-rcb.o \
 		   rkvdec-vdpu381-h264.o \
+		   rkvdec-vdpu383-h264.o \
 		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +582 -0

582 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +284 -0

284 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.c +103 -6

168 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.h +8 -0
index 9e0fef2445abc..acb9d72b130bb 100644
@@ -110,6 +110,8 @@ struct rkvdec_config {
 	irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx);
 	int (*fill_pixfmt_mp)(struct v4l2_pix_format_mplane *pix_mp, u32 pixelformat,
 			      u32 width, u32 height);
+	u32 (*colmv_size)(u16 width, u16 height);
+	bool named_regs;
 };
 
 struct rkvdec_dev {
@@ -122,6 +124,7 @@ struct rkvdec_dev {
 	unsigned int clk_count;
 	struct clk *axi_clk;
 	void __iomem *regs;
+	void __iomem *link;
 	struct mutex vdev_lock; /* serializes ioctls */
 	struct delayed_work watchdog_work;
 	struct gen_pool *sram_pool;
@@ -164,9 +167,14 @@ void rkvdec_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
 void rkvdec_run_postamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
 void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);
 
+/* RKVDEC ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;
 extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
 
+/* VDPU381 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops;
 
+/* VDPU383 ops */
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
+
 #endif /* RKVDEC_H_ */
Signature · 1 line
2.50.1
#21 lore raw

Re: [PATCH v2 10/12] media: rkvdec: Add H264 support for the VDPU383 variant

kernel test robot noticed the following build errors:

Hi Detlev,

kernel test robot noticed the following build errors:

[auto build test ERROR on linuxtv-media-pending/master]
[also build test ERROR on linus/master next-20250808]
[cannot apply to rockchip/for-next sailus-media-tree/master sailus-media-tree/streams v6.16] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Detlev-Casanova/media-rkvdec-Switch-to-using-structs-instead-of-writel/20250809-041049
base:   https://git.linuxtv.org/media-ci/media-pending.git master
patch link:    https://lore.kernel.org/r/20250808200340.156393-11-detlev.casanova%40collabora.com
patch subject: [PATCH v2 10/12] media: rkvdec: Add H264 support for the VDPU383 variant
config: i386-buildonly-randconfig-005-20250809 (https://download.01.org/0day-ci/archive/20250809/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250809/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/media/platform/rockchip/rkvdec/rkvdec.c:12:10: fatal error: 'linux/hw_bitfield.h' file not found
      12 | #include <linux/hw_bitfield.h>
         |          ^~~~~~~~~~~~~~~~~~~~~

1 error generated.

vim +12 drivers/media/platform/rockchip/rkvdec/rkvdec.c

  > 12	#include <linux/hw_bitfield.h>
    13	#include <linux/clk.h>
    14	#include <linux/genalloc.h>
    15	#include <linux/interrupt.h>
    16	#include <linux/iommu.h>
    17	#include <linux/module.h>
    18	#include <linux/of.h>
    19	#include <linux/platform_device.h>
    20	#include <linux/pm.h>
    21	#include <linux/pm_runtime.h>
    22	#include <linux/slab.h>
    23	#include <linux/videodev2.h>
    24	#include <linux/workqueue.h>
    25	#include <media/v4l2-event.h>
    26	#include <media/v4l2-mem2mem.h>
    27	#include <media/videobuf2-core.h>
    28	#include <media/videobuf2-vmalloc.h>
    29	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#22 lore raw

Re: [PATCH v2 10/12] media: rkvdec: Add H264 support for the VDPU383 variant

In reply to Detlev Casanova

Hi Detlev,

Le vendredi 08 août 2025 à 16:03 -0400, Detlev Casanova a écrit :

Quoted 10 lines

This variant is used on the RK3576 SoC.

The moving vectors size requirements are slightly different so support for a colmv_size function per variant is added.

Also, the link registers are used to start the decoder and read IRQ status. Per variant support for named register sections is added.

The fluster score is 128/135 for JVT-AVC_V1.
The other test suites are not supported yet.

Since its the same family as RK3399, which scores 129/135, can you explicitly document which one failed, and if you happen to know why ?

Nicolas

Quoted 1,172 lines

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 + .../rockchip/rkvdec/rkvdec-vdpu383-h264.c     | 582 ++++++++++++++++++ .../rockchip/rkvdec/rkvdec-vdpu383-regs.h     | 284 +++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c   | 109 +++- .../media/platform/rockchip/rkvdec/rkvdec.h   |   8 +

 5 files changed, 978 insertions(+), 6 deletions(-)

 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383- h264.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383- regs.h

drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
index 20128bb6e35dc..c38ce1e8d3601 100644
@@ -7,4 +7,5 @@ rockchip-vdec-y += \
  		   rkvdec-h264-common.o \
  		   rkvdec-rcb.o \
  		   rkvdec-vdpu381-h264.o \
+		   rkvdec-vdpu383-h264.o \

     rkvdec-vp9.o

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +132 -0
new file mode 100644
index 0000000000000..bb2c62d9c3d47
@@ -0,0 +1,582 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Rockchip Video Decoder VDPU383 H264 backend
+ *
+ * Copyright (C) 2024 Collabora, Ltd.
+ *  Detlev Casanova <[email protected]>
+ */
+
+#include <media/v4l2-h264.h>
+#include <media/v4l2-mem2mem.h>
+
+#include <linux/iopoll.h>
+
+#include "rkvdec-rcb.h"
+#include "rkvdec-vdpu383-regs.h"
+#include "rkvdec-h264-common.h"
+
+struct rkvdec_sps {
+	u16 seq_parameter_set_id:			4;
+	u16 profile_idc:				8;
+	u16 constraint_set3_flag:			1;
+	u16 chroma_format_idc:				2;
+	u16 bit_depth_luma:				3;
+	u16 bit_depth_chroma:				3;
+	u16 qpprime_y_zero_transform_bypass_flag:	1;
+	u16 log2_max_frame_num_minus4:			4;
+	u16 max_num_ref_frames:				5;
+	u16 pic_order_cnt_type:				2;
+	u16 log2_max_pic_order_cnt_lsb_minus4:		4;
+	u16 delta_pic_order_always_zero_flag:		1;
+
+	u16 pic_width_in_mbs:				16;
+	u16 pic_height_in_mbs:				16;
+
+	u16 frame_mbs_only_flag:			1;
+	u16 mb_adaptive_frame_field_flag:		1;
+	u16 direct_8x8_inference_flag:			1;
+	u16 mvc_extension_enable:			1;
+	u16 num_views:					2;
+	u16 view_id0:                                   10;
+	u16 view_id1:                                   10;
+} __packed;
+
+struct rkvdec_pps {
+	u32 pic_parameter_set_id:				8;
+	u32 pps_seq_parameter_set_id:				5;
+	u32 entropy_coding_mode_flag:				1;
+	u32 bottom_field_pic_order_in_frame_present_flag:	1;
+	u32 num_ref_idx_l0_default_active_minus1:		5;
+	u32 num_ref_idx_l1_default_active_minus1:		5;
+	u32 weighted_pred_flag:					1;
+	u32 weighted_bipred_idc:				2;
+	u32 pic_init_qp_minus26:				7;
+	u32 pic_init_qs_minus26:				6;
+	u32 chroma_qp_index_offset:				5;
+	u32 deblocking_filter_control_present_flag:		1;
+	u32 constrained_intra_pred_flag:			1;
+	u32 redundant_pic_cnt_present:				1;
+	u32 transform_8x8_mode_flag:				1;
+	u32 second_chroma_qp_index_offset:			5;
+	u32 scaling_list_enable_flag:				1;
+	u32 is_longterm:					16;
+	u32 voidx:						16;
+
+	// dpb
+	u32 pic_field_flag:                                     1;
+	u32 pic_associated_flag:                                1;
+	u32 cur_top_field:					32;
+	u32 cur_bot_field:					32;
+
+	u32 top_field_order_cnt0:				32;
+	u32 bot_field_order_cnt0:				32;
+	u32 top_field_order_cnt1:				32;
+	u32 bot_field_order_cnt1:				32;
+	u32 top_field_order_cnt2:				32;
+	u32 bot_field_order_cnt2:				32;
+	u32 top_field_order_cnt3:				32;
+	u32 bot_field_order_cnt3:				32;
+	u32 top_field_order_cnt4:				32;
+	u32 bot_field_order_cnt4:				32;
+	u32 top_field_order_cnt5:				32;
+	u32 bot_field_order_cnt5:				32;
+	u32 top_field_order_cnt6:				32;
+	u32 bot_field_order_cnt6:				32;
+	u32 top_field_order_cnt7:				32;
+	u32 bot_field_order_cnt7:				32;
+	u32 top_field_order_cnt8:				32;
+	u32 bot_field_order_cnt8:				32;
+	u32 top_field_order_cnt9:				32;
+	u32 bot_field_order_cnt9:				32;
+	u32 top_field_order_cnt10:				32;
+	u32 bot_field_order_cnt10:				32;
+	u32 top_field_order_cnt11:				32;
+	u32 bot_field_order_cnt11:				32;
+	u32 top_field_order_cnt12:				32;
+	u32 bot_field_order_cnt12:				32;
+	u32 top_field_order_cnt13:				32;
+	u32 bot_field_order_cnt13:				32;
+	u32 top_field_order_cnt14:				32;
+	u32 bot_field_order_cnt14:				32;
+	u32 top_field_order_cnt15:				32;
+	u32 bot_field_order_cnt15:				32;
+
+	u32 ref_field_flags:					16;
+	u32 ref_topfield_used:					16;
+	u32 ref_botfield_used:					16;
+	u32 ref_colmv_use_flag:					16;
+
+	u32 reserved0:						30;
+	u32 reserved[3];
+} __packed;
+
+struct rkvdec_sps_pps {
+	struct rkvdec_sps sps;
+	struct rkvdec_pps pps;
+} __packed;
+
+/* Data structure describing auxiliary buffer format. */
+struct rkvdec_h264_priv_tbl {
+	s8 cabac_table[4][464][2];
+	struct rkvdec_h264_scaling_list scaling_list;
+	struct rkvdec_sps_pps param_set[256];
+	struct rkvdec_rps rps;
+} __packed;
+
+struct rkvdec_h264_ctx {
+	struct rkvdec_aux_buf priv_tbl;
+	struct rkvdec_h264_reflists reflists;
+	struct vdpu383_regs_h26x regs;
+};
+
+static void set_field_order_cnt(struct rkvdec_sps_pps *hw_ps, int id, u32

top, u32 bottom)

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +76 -0
+{
+	switch (id) {
+	case 0:
+		hw_ps->pps.top_field_order_cnt0 = top;
+		hw_ps->pps.bot_field_order_cnt0 = bottom;
+		break;
+	case 1:
+		hw_ps->pps.top_field_order_cnt1 = top;
+		hw_ps->pps.bot_field_order_cnt1 = bottom;
+		break;
+	case 2:
+		hw_ps->pps.top_field_order_cnt2 = top;
+		hw_ps->pps.bot_field_order_cnt2 = bottom;
+		break;
+	case 3:
+		hw_ps->pps.top_field_order_cnt3 = top;
+		hw_ps->pps.bot_field_order_cnt3 = bottom;
+		break;
+	case 4:
+		hw_ps->pps.top_field_order_cnt4 = top;
+		hw_ps->pps.bot_field_order_cnt4 = bottom;
+		break;
+	case 5:
+		hw_ps->pps.top_field_order_cnt5 = top;
+		hw_ps->pps.bot_field_order_cnt5 = bottom;
+		break;
+	case 6:
+		hw_ps->pps.top_field_order_cnt6 = top;
+		hw_ps->pps.bot_field_order_cnt6 = bottom;
+		break;
+	case 7:
+		hw_ps->pps.top_field_order_cnt7 = top;
+		hw_ps->pps.bot_field_order_cnt7 = bottom;
+		break;
+	case 8:
+		hw_ps->pps.top_field_order_cnt8 = top;
+		hw_ps->pps.bot_field_order_cnt8 = bottom;
+		break;
+	case 9:
+		hw_ps->pps.top_field_order_cnt9 = top;
+		hw_ps->pps.bot_field_order_cnt9 = bottom;
+		break;
+	case 10:
+		hw_ps->pps.top_field_order_cnt10 = top;
+		hw_ps->pps.bot_field_order_cnt10 = bottom;
+		break;
+	case 11:
+		hw_ps->pps.top_field_order_cnt11 = top;
+		hw_ps->pps.bot_field_order_cnt11 = bottom;
+		break;
+	case 12:
+		hw_ps->pps.top_field_order_cnt12 = top;
+		hw_ps->pps.bot_field_order_cnt12 = bottom;
+		break;
+	case 13:
+		hw_ps->pps.top_field_order_cnt13 = top;
+		hw_ps->pps.bot_field_order_cnt13 = bottom;
+		break;
+	case 14:
+		hw_ps->pps.top_field_order_cnt14 = top;
+		hw_ps->pps.bot_field_order_cnt14 = bottom;
+		break;
+	case 15:
+		hw_ps->pps.top_field_order_cnt15 = top;
+		hw_ps->pps.bot_field_order_cnt15 = bottom;
+		break;
+	}
+}
+
+static void assemble_hw_pps(struct rkvdec_ctx *ctx,
+			    struct rkvdec_h264_run *run)
+{
+	struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
+	const struct v4l2_ctrl_h264_sps *sps = run->sps;
+	const struct v4l2_ctrl_h264_pps *pps = run->pps;
+	const struct v4l2_ctrl_h264_decode_params *dec_params = run-
Quoted 1 line

decode_params;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +9 -0
+	const struct v4l2_h264_dpb_entry *dpb = dec_params->dpb;
+	struct rkvdec_h264_priv_tbl *priv_tbl = h264_ctx->priv_tbl.cpu;
+	struct rkvdec_sps_pps *hw_ps;
+	u32 pic_width, pic_height;
+	u32 i;
+
+	/*
+	 * HW read the SPS/PPS information from PPS packet index by PPS id.
+	 * offset from the base can be calculated by PPS_id * 32 (size per

PPS

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +1 -0
+	 * packet unit). so the driver copy SPS/PPS information to the exact

PPS

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +9 -0
+	 * packet unit for HW accessing.
+	 */
+	hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id];
+	memset(hw_ps, 0, sizeof(*hw_ps));
+
+	/* write sps */
+	hw_ps->sps.seq_parameter_set_id = sps->seq_parameter_set_id;
+	hw_ps->sps.profile_idc = sps->profile_idc;
+	hw_ps->sps.constraint_set3_flag = !!(sps->constraint_set_flags & (1

<< 3));

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +5 -0
+	hw_ps->sps.chroma_format_idc = sps->chroma_format_idc;
+	hw_ps->sps.bit_depth_luma = sps->bit_depth_luma_minus8;
+	hw_ps->sps.bit_depth_chroma = sps->bit_depth_chroma_minus8;
+	hw_ps->sps.qpprime_y_zero_transform_bypass_flag =
+		!!(sps->flags &

V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +1 -0
+	hw_ps->sps.log2_max_frame_num_minus4 = sps-
Quoted 1 line

log2_max_frame_num_minus4;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +6 -0
+	hw_ps->sps.max_num_ref_frames = sps->max_num_ref_frames;
+	hw_ps->sps.pic_order_cnt_type = sps->pic_order_cnt_type;
+	hw_ps->sps.log2_max_pic_order_cnt_lsb_minus4 =
+		sps->log2_max_pic_order_cnt_lsb_minus4;
+	hw_ps->sps.delta_pic_order_always_zero_flag =
+		!!(sps->flags &

V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +34 -0
+	hw_ps->sps.mvc_extension_enable = 0;
+	hw_ps->sps.num_views = 0;
+
+	/*
+	 * Use the SPS values since they are already in macroblocks
+	 * dimensions, height can be field height (halved) if
+	 * V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY is not set and also it allows
+	 * decoding smaller images into larger allocation which can be used
+	 * to implementing SVC spatial layer support.
+	 */
+	pic_width = 16 * (sps->pic_width_in_mbs_minus1 + 1);
+	pic_height = 16 * (sps->pic_height_in_map_units_minus1 + 1);
+	if (!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY))
+		pic_height *= 2;
+	if (!!(dec_params->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC))
+		pic_height /= 2;
+
+	hw_ps->sps.pic_width_in_mbs = pic_width;
+	hw_ps->sps.pic_height_in_mbs = pic_height;
+
+	hw_ps->sps.frame_mbs_only_flag =
+		!!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY);
+	hw_ps->sps.mb_adaptive_frame_field_flag =
+		!!(sps->flags & V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD);
+	hw_ps->sps.direct_8x8_inference_flag =
+		!!(sps->flags & V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE);
+
+	/* write pps */
+	hw_ps->pps.pic_parameter_set_id = pps->pic_parameter_set_id;
+	hw_ps->pps.pps_seq_parameter_set_id = pps->seq_parameter_set_id;
+	hw_ps->pps.entropy_coding_mode_flag =
+		!!(pps->flags & V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE);
+	hw_ps->pps.bottom_field_pic_order_in_frame_present_flag =
+		!!(pps->flags &

V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +12 -0
+	hw_ps->pps.num_ref_idx_l0_default_active_minus1 =
+		pps->num_ref_idx_l0_default_active_minus1;
+	hw_ps->pps.num_ref_idx_l1_default_active_minus1 =
+		pps->num_ref_idx_l1_default_active_minus1;
+	hw_ps->pps.weighted_pred_flag =
+		!!(pps->flags & V4L2_H264_PPS_FLAG_WEIGHTED_PRED);
+	hw_ps->pps.weighted_bipred_idc = pps->weighted_bipred_idc;
+	hw_ps->pps.pic_init_qp_minus26 = pps->pic_init_qp_minus26;
+	hw_ps->pps.pic_init_qs_minus26 = pps->pic_init_qs_minus26;
+	hw_ps->pps.chroma_qp_index_offset = pps->chroma_qp_index_offset;
+	hw_ps->pps.deblocking_filter_control_present_flag =
+		!!(pps->flags &

V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +4 -0
+	hw_ps->pps.constrained_intra_pred_flag =
+		!!(pps->flags & V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED);
+	hw_ps->pps.redundant_pic_cnt_present =
+		!!(pps->flags &

V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +3 -0
+	hw_ps->pps.transform_8x8_mode_flag =
+		!!(pps->flags & V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE);
+	hw_ps->pps.second_chroma_qp_index_offset = pps-
Quoted 1 line

second_chroma_qp_index_offset;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +12 -0
+	hw_ps->pps.scaling_list_enable_flag =
+		!!(pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT);
+
+	for (i = 0; i < ARRAY_SIZE(dec_params->dpb); i++) {
+		if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)
+			hw_ps->pps.is_longterm |= (1 << i);
+
+		set_field_order_cnt(hw_ps, i, dpb[i].top_field_order_cnt,
+				    dpb[i].bottom_field_order_cnt);
+
+		hw_ps->pps.ref_field_flags |=
+			(!!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_FIELD))

<< i;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +2 -0
+		hw_ps->pps.ref_colmv_use_flag |=
+			(!!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE))

<< i;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +4 -0
+		hw_ps->pps.ref_topfield_used |=
+			(!!(dpb[i].fields & V4L2_H264_TOP_FIELD_REF)) << i;
+		hw_ps->pps.ref_botfield_used |=
+			(!!(dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF)) <<

i;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +4 -0
+	}
+
+	hw_ps->pps.pic_field_flag =
+		!!(dec_params->flags &

V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +2 -0
+	hw_ps->pps.pic_associated_flag =
+		!!(dec_params->flags &

V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +28 -0
+
+	hw_ps->pps.cur_top_field = dec_params->top_field_order_cnt;
+	hw_ps->pps.cur_bot_field = dec_params->bottom_field_order_cnt;
+}
+
+static void rkvdec_write_regs(struct rkvdec_ctx *ctx)
+{
+	struct rkvdec_dev *rkvdec = ctx->dev;
+	struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
+
+	rkvdec_memcpy_toio(rkvdec->regs + VDPU383_OFFSET_COMMON_REGS,
+			   &h264_ctx->regs.common,
+			   sizeof(h264_ctx->regs.common));
+	rkvdec_memcpy_toio(rkvdec->regs + VDPU383_OFFSET_COMMON_ADDR_REGS,
+			   &h264_ctx->regs.common_addr,
+			   sizeof(h264_ctx->regs.common_addr));
+	rkvdec_memcpy_toio(rkvdec->regs + VDPU383_OFFSET_CODEC_PARAMS_REGS,
+			   &h264_ctx->regs.h26x_params,
+			   sizeof(h264_ctx->regs.h26x_params));
+	rkvdec_memcpy_toio(rkvdec->regs + VDPU383_OFFSET_CODEC_ADDR_REGS,
+			   &h264_ctx->regs.h26x_addr,
+			   sizeof(h264_ctx->regs.h26x_addr));
+}
+
+static void config_registers(struct rkvdec_ctx *ctx,
+			     struct rkvdec_h264_run *run)
+{
+	const struct v4l2_ctrl_h264_decode_params *dec_params = run-
Quoted 1 line

decode_params;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +23 -0
+	struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
+	dma_addr_t priv_start_addr = h264_ctx->priv_tbl.dma;
+	const struct v4l2_pix_format_mplane *dst_fmt;
+	struct vb2_v4l2_buffer *src_buf = run->base.bufs.src;
+	struct vb2_v4l2_buffer *dst_buf = run->base.bufs.dst;
+	struct vdpu383_regs_h26x *regs = &h264_ctx->regs;
+	const struct v4l2_format *f;
+	dma_addr_t rlc_addr;
+	dma_addr_t dst_addr;
+	u32 hor_virstride;
+	u32 ver_virstride;
+	u32 y_virstride;
+	u32 offset;
+	u32 pixels;
+	u32 i;
+
+	memset(regs, 0, sizeof(*regs));
+
+	/* Set H264 mode */
+	regs->common.reg008_dec_mode = VDPU383_MODE_H264;
+
+	/* Set input stream length */
+	regs->h26x_params.reg066_stream_len = vb2_get_plane_payload(&src_buf-
Quoted 1 line

vb2_buf, 0);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +12 -0
+
+	/* Set strides */
+	f = &ctx->decoded_fmt;
+	dst_fmt = &f->fmt.pix_mp;
+	hor_virstride = dst_fmt->plane_fmt[0].bytesperline;
+	ver_virstride = dst_fmt->height;
+	y_virstride = hor_virstride * ver_virstride;
+
+	pixels = dst_fmt->height * dst_fmt->width;
+
+	regs->h26x_params.reg068_hor_virstride = hor_virstride / 16;
+	regs->h26x_params.reg069_raster_uv_hor_virstride = hor_virstride /

16;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +17 -0
+	regs->h26x_params.reg070_y_virstride = y_virstride / 16;
+
+	/* Activate block gating */
+	regs->common.reg010.strmd_auto_gating_e      = 1;
+	regs->common.reg010.inter_auto_gating_e      = 1;
+	regs->common.reg010.intra_auto_gating_e      = 1;
+	regs->common.reg010.transd_auto_gating_e     = 1;
+	regs->common.reg010.recon_auto_gating_e      = 1;
+	regs->common.reg010.filterd_auto_gating_e    = 1;
+	regs->common.reg010.bus_auto_gating_e        = 1;
+	regs->common.reg010.ctrl_auto_gating_e       = 1;
+	regs->common.reg010.rcb_auto_gating_e        = 1;
+	regs->common.reg010.err_prc_auto_gating_e    = 1;
+
+	/* Set timeout threshold */
+	if (pixels < VDPU383_1080P_PIXELS)
+		regs->common.reg013_core_timeout_threshold =

VDPU383_TIMEOUT_1080p;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +2 -0
+	else if (pixels < VDPU383_4K_PIXELS)
+		regs->common.reg013_core_timeout_threshold =

VDPU383_TIMEOUT_4K;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +2 -0
+	else if (pixels < VDPU383_8K_PIXELS)
+		regs->common.reg013_core_timeout_threshold =

VDPU383_TIMEOUT_8K;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +2 -0
+	else
+		regs->common.reg013_core_timeout_threshold =

VDPU383_TIMEOUT_MAX;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +10 -0
+
+	regs->common.reg016.error_proc_disable = 1;
+
+	/* Set ref pic address & poc */
+	for (i = 0; i < ARRAY_SIZE(dec_params->dpb); i++) {
+		struct vb2_buffer *vb_buf = run->ref_buf[i];
+		dma_addr_t buf_dma;
+
+		/*
+		 * If a DPB entry is unused or invalid, address of current

destination

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +13 -0
+		 * buffer is returned.
+		 */
+		if (!vb_buf)
+			vb_buf = &dst_buf->vb2_buf;
+
+		buf_dma = vb2_dma_contig_plane_dma_addr(vb_buf, 0);
+
+		/* Set reference addresses */
+		regs->h26x_addr.reg170_185_ref_base[i] = buf_dma;
+		regs->h26x_addr.reg195_210_payload_st_ref_base[i] = buf_dma;
+
+		/* Set COLMV addresses */
+		regs->h26x_addr.reg217_232_colmv_ref_base[i] = buf_dma + ctx-
Quoted 1 line

colmv_offset;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +18 -0
+	}
+
+	/* Set rlc base address (input stream) */
+	rlc_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+	regs->common_addr.reg128_strm_base = rlc_addr;
+
+	/* Set output base address */
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
+	regs->h26x_addr.reg168_decout_base = dst_addr;
+	regs->h26x_addr.reg169_error_ref_base = dst_addr;
+	regs->h26x_addr.reg192_payload_st_cur_base = dst_addr;
+
+	/* Set colmv address */
+	regs->h26x_addr.reg216_colmv_cur_base = dst_addr + ctx->colmv_offset;
+
+	/* Set RCB addresses */
+	for (i = 0; i < rkvdec_rcb_buf_count(ctx); i++) {
+		regs->common_addr.reg140_162_rcb_info[i].offset =

rkvdec_rcb_buf_dma_addr(ctx, i);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +1 -0
+		regs->common_addr.reg140_162_rcb_info[i].size =

rkvdec_rcb_buf_size(ctx, i);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +6 -0
+	}
+
+	/* Set hw pps address */
+	offset = offsetof(struct rkvdec_h264_priv_tbl, param_set);
+	regs->common_addr.reg131_gbl_base = priv_start_addr + offset;
+	regs->h26x_params.reg067_global_len = sizeof(struct rkvdec_sps_pps) /

16;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +92 -0
+
+	/* Set hw rps address */
+	offset = offsetof(struct rkvdec_h264_priv_tbl, rps);
+	regs->common_addr.reg129_rps_base = priv_start_addr + offset;
+
+	/* Set cabac table */
+	offset = offsetof(struct rkvdec_h264_priv_tbl, cabac_table);
+	regs->common_addr.reg130_cabactbl_base = priv_start_addr + offset;
+
+	/* Set scaling list address */
+	offset = offsetof(struct rkvdec_h264_priv_tbl, scaling_list);
+	regs->common_addr.reg132_scanlist_addr = priv_start_addr + offset;
+
+	rkvdec_write_regs(ctx);
+}
+
+static int rkvdec_h264_start(struct rkvdec_ctx *ctx)
+{
+	struct rkvdec_dev *rkvdec = ctx->dev;
+	struct rkvdec_h264_priv_tbl *priv_tbl;
+	struct rkvdec_h264_ctx *h264_ctx;
+	struct v4l2_ctrl *ctrl;
+	int ret;
+
+	ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl,
+			      V4L2_CID_STATELESS_H264_SPS);
+	if (!ctrl)
+		return -EINVAL;
+
+	ret = rkvdec_h264_validate_sps(ctx, ctrl->p_new.p_h264_sps);
+	if (ret)
+		return ret;
+
+	h264_ctx = kzalloc(sizeof(*h264_ctx), GFP_KERNEL);
+	if (!h264_ctx)
+		return -ENOMEM;
+
+	priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
+				      &h264_ctx->priv_tbl.dma, GFP_KERNEL);
+	if (!priv_tbl) {
+		ret = -ENOMEM;
+		goto err_free_ctx;
+	}
+
+	h264_ctx->priv_tbl.size = sizeof(*priv_tbl);
+	h264_ctx->priv_tbl.cpu = priv_tbl;
+	memcpy(priv_tbl->cabac_table, rkvdec_h264_cabac_table,
+	       sizeof(rkvdec_h264_cabac_table));
+
+	ctx->priv = h264_ctx;
+
+	return 0;
+
+err_free_ctx:
+	kfree(h264_ctx);
+	return ret;
+}
+
+static void rkvdec_h264_stop(struct rkvdec_ctx *ctx)
+{
+	struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
+	struct rkvdec_dev *rkvdec = ctx->dev;
+
+	dma_free_coherent(rkvdec->dev, h264_ctx->priv_tbl.size,
+			  h264_ctx->priv_tbl.cpu, h264_ctx->priv_tbl.dma);
+	kfree(h264_ctx);
+}
+
+static int rkvdec_h264_run(struct rkvdec_ctx *ctx)
+{
+	struct v4l2_h264_reflist_builder reflist_builder;
+	struct rkvdec_dev *rkvdec = ctx->dev;
+	struct rkvdec_h264_ctx *h264_ctx = ctx->priv;
+	struct rkvdec_h264_run run;
+	struct rkvdec_h264_priv_tbl *tbl = h264_ctx->priv_tbl.cpu;
+	u32 watchdog_time;
+	u64 timeout_threshold;
+	unsigned long axi_rate;
+
+	rkvdec_h264_run_preamble(ctx, &run);
+
+	/* Build the P/B{0,1} ref lists. */
+	v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params,
+				       run.sps, run.decode_params->dpb);
+	v4l2_h264_build_p_ref_list(&reflist_builder, h264_ctx->reflists.p);
+	v4l2_h264_build_b_ref_lists(&reflist_builder, h264_ctx->reflists.b0,
+				    h264_ctx->reflists.b1);
+
+	assemble_hw_scaling_list(&run, &tbl->scaling_list);
+	assemble_hw_pps(ctx, &run);
+	lookup_ref_buf_idx(ctx, &run);
+	assemble_hw_rps(&reflist_builder, &run, &h264_ctx->reflists, &tbl-
Quoted 1 line

rps);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +7 -0
+
+	config_registers(ctx, &run);
+
+	rkvdec_run_postamble(ctx, &run.base);
+
+	/* Set watchdog at 2 times the hardware timeout threshold */
+	timeout_threshold = h264_ctx-
Quoted 1 line

regs.common.reg013_core_timeout_threshold;

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +11 -0
+	axi_rate = clk_get_rate(rkvdec->axi_clk);
+
+	if (axi_rate)
+		watchdog_time = 2 * (1000 * timeout_threshold) / axi_rate;
+	else
+		watchdog_time = 2000;
+	schedule_delayed_work(&rkvdec->watchdog_work,
+			      msecs_to_jiffies(watchdog_time));
+
+	/* Start decoding! */
+	writel(timeout_threshold, rkvdec->link +

VDPU383_LINK_TIMEOUT_THRESHOLD);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +7 -0
+	writel(0, rkvdec->link + VDPU383_LINK_IP_ENABLE);
+	writel(VDPU383_DEC_E_BIT, rkvdec->link + VDPU383_LINK_DEC_ENABLE);
+
+	return 0;
+}
+
+static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl

*ctrl)

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +15 -0
+{
+	if (ctrl->id == V4L2_CID_STATELESS_H264_SPS)
+		return rkvdec_h264_validate_sps(ctx, ctrl->p_new.p_h264_sps);
+
+	return 0;
+}
+
+const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops = {
+	.adjust_fmt = rkvdec_h264_adjust_fmt,
+	.get_image_fmt = rkvdec_h264_get_image_fmt,
+	.start = rkvdec_h264_start,
+	.stop = rkvdec_h264_stop,
+	.run = rkvdec_h264_run,
+	.try_ctrl = rkvdec_h264_try_ctrl,
+};
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +278 -0
new file mode 100644
index 0000000000000..2b614393a3afa
@@ -0,0 +1,284 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Rockchip Video Decoder VDPU383 driver registers description
+ *
+ * Copyright (C) 2025 Collabora, Ltd.
+ *  Detlev Casanova <[email protected]>
+ */
+
+#ifndef _RKVDEC_VDPU838_REGS_H_
+#define _RKVDEC_VDPU838_REGS_H_
+
+#include <linux/types.h>
+
+#define VDPU383_OFFSET_COMMON_REGS		(8 * sizeof(u32))
+#define VDPU383_OFFSET_CODEC_PARAMS_REGS	(64 * sizeof(u32))
+#define VDPU383_OFFSET_COMMON_ADDR_REGS		(128 * sizeof(u32))
+#define VDPU383_OFFSET_CODEC_ADDR_REGS		(168 * sizeof(u32))
+#define VDPU383_OFFSET_POC_HIGHBIT_REGS		(200 * sizeof(u32))
+
+#define VDPU383_MODE_HEVC	0
+#define VDPU383_MODE_H264	1
+
+#define VDPU383_1080P_PIXELS		(1920 * 1080)
+#define VDPU383_4K_PIXELS		(4096 * 2304)
+#define VDPU383_8K_PIXELS		(7680 * 4320)
+#define VDPU383_TIMEOUT_1080p		(0xffffff)
+#define VDPU383_TIMEOUT_4K		(0x2cfffff)
+#define VDPU383_TIMEOUT_8K		(0x4ffffff)
+#define VDPU383_TIMEOUT_MAX		(0xffffffff)
+
+#define VDPU383_LINK_TIMEOUT_THRESHOLD	0x54
+
+#define VDPU383_LINK_IP_ENABLE		0x58
+#define VDPU383_IP_CRU_MODE		BIT(24)
+
+#define VDPU383_LINK_DEC_ENABLE		0x40
+#define VDPU383_DEC_E_BIT		BIT(0)
+
+#define VDPU383_LINK_INT_EN		0x048
+#define VDPU383_INT_EN_IRQ		BIT(0)
+#define VDPU383_INT_EN_LINE_IRQ		BIT(1)
+
+#define VDPU383_LINK_STA_INT		0x04c
+#define VDPU383_STA_INT_DEC_RDY_STA	BIT(0)
+#define VDPU383_STA_INT_SOFTRESET_RDY	(BIT(10) | BIT(11))
+#define VDPU383_STA_INT_ALL		0x3ff
+
+struct vdpu383_regs_common {
+	u32 reg008_dec_mode;
+
+	struct swreg9_important_en {
+		u32 fbc_e			: 1;
+		u32 tile_e			: 1;
+		u32 reserve0			: 2;
+		u32 buf_empty_en		: 1;
+		u32 scale_down_en		: 1;
+		u32 reserve1			: 1;
+		u32 pix_range_det_e		: 1;
+		u32 av1_fgs_en			: 1;
+		u32 reserve2			: 7;
+		u32 line_irq_en			: 1;
+		u32 out_cbcr_swap		: 1;
+		u32 fbc_force_uncompress	: 1;
+		u32 fbc_sparse_mode		: 1;
+		u32 reserve3			: 12;
+	} reg009;
+
+	struct swreg010_block_gating_en {
+		u32 strmd_auto_gating_e		: 1;
+		u32 inter_auto_gating_e		: 1;
+		u32 intra_auto_gating_e		: 1;
+		u32 transd_auto_gating_e	: 1;
+		u32 recon_auto_gating_e		: 1;
+		u32 filterd_auto_gating_e	: 1;
+		u32 bus_auto_gating_e		: 1;
+		u32 ctrl_auto_gating_e		: 1;
+		u32 rcb_auto_gating_e		: 1;
+		u32 err_prc_auto_gating_e	: 1;
+		u32 reserve0			: 22;
+	} reg010;
+
+	struct swreg011_cfg_para {
+		u32 reserve0			: 9;
+		u32 dec_timeout_dis		: 1;
+		u32 reserve1			: 22;
+	} reg011;
+
+	struct swreg012_cache_hash_mask {
+		u32 reserve0			: 7;
+		u32 cache_hash_mask		: 25;
+	} reg012;
+
+	u32 reg013_core_timeout_threshold;
+
+	struct swreg014_line_irq_ctrl {
+		u32 dec_line_irq_step		: 16;
+		u32 dec_line_offset_y_st	: 16;
+	} reg014;
+
+	struct swreg015_irq_sta {
+		u32 rkvdec_frame_rdy_sta	: 1;
+		u32 rkvdec_strm_error_sta	: 1;
+		u32 rkvdec_core_timeout_sta	: 1;
+		u32 rkvdec_ip_timeout_sta	: 1;
+		u32 rkvdec_bus_error_sta	: 1;
+		u32 rkvdec_buffer_empty_sta	: 1;
+		u32 rkvdec_colmv_ref_error_sta	: 1;
+		u32 rkvdec_error_spread_sta	: 1;
+		u32 create_core_timeout_sta	: 1;
+		u32 wlast_miss_match_sta	: 1;
+		u32 rkvdec_core_rst_rdy_sta	: 1;
+		u32 rkvdec_ip_rst_rdy_sta	: 1;
+		u32 force_busidle_rdy_sta	: 1;
+		u32 ltb_pause_rdy_sta		: 1;
+		u32 ltb_end_flag		: 1;
+		u32 unsupport_decmode_error_sta	: 1;
+		u32 wmask_bits			: 15;
+		u32 reserve0			: 1;
+	} reg015;
+
+	struct swreg016_error_ctrl_set {
+		u32 error_proc_disable		: 1;
+		u32 reserve0			: 7;
+		u32 error_spread_disable	: 1;
+		u32 reserve1			: 15;
+		u32 roi_error_ctu_cal_en	: 1;
+		u32 reserve2			: 7;
+	} reg016;
+
+	struct swreg017_err_roi_ctu_offset_start {
+		u32 roi_x_ctu_offset_st		: 12;
+		u32 reserve0			: 4;
+		u32 roi_y_ctu_offset_st		: 12;
+		u32 reserve1			: 4;
+	} reg017;
+
+	struct swreg018_err_roi_ctu_offset_end {
+		u32 roi_x_ctu_offset_end	: 12;
+		u32 reserve0			: 4;
+		u32 roi_y_ctu_offset_end	: 12;
+		u32 reserve1			: 4;
+	} reg018;
+
+	struct swreg019_error_ref_info {
+		u32 avs2_ref_error_field	: 1;
+		u32 avs2_ref_error_topfield	: 1;
+		u32 ref_error_topfield_used	: 1;
+		u32 ref_error_botfield_used	: 1;
+		u32 reserve0			: 28;
+	} reg019;
+
+	u32 reg020_cabac_error_en_lowbits;
+	u32 reg021_cabac_error_en_highbits;
+
+	u32 reg022_reserved;
+
+	struct swreg023_invalid_pixel_fill {
+		u32 fill_y			: 10;
+		u32 fill_u			: 10;
+		u32 fill_v			: 10;
+		u32 reserve0			: 2;
+	} reg023;
+
+	u32 reg024_026_reserved[3];
+
+	struct swreg027_align_en {
+		u32 reserve0			: 4;
+		u32 ctu_align_wr_en		: 1;
+		u32 reserve1			: 27;
+	} reg027;
+
+	struct swreg028_debug_perf_latency_ctrl0 {
+		u32 axi_perf_work_e		: 1;
+		u32 reserve0			: 2;
+		u32 axi_cnt_type		: 1;
+		u32 rd_latency_id		: 8;
+		u32 reserve1			: 4;
+		u32 rd_latency_thr		: 12;
+		u32 reserve2			: 4;
+	} reg028;
+
+	struct swreg029_debug_perf_latency_ctrl1 {
+		u32 addr_align_type		: 2;
+		u32 ar_cnt_id_type		: 1;
+		u32 aw_cnt_id_type		: 1;
+		u32 ar_count_id			: 8;
+		u32 reserve0			: 4;
+		u32 aw_count_id			: 8;
+		u32 rd_band_width_mode		: 1;
+		u32 reserve1			: 7;
+	} reg029;
+
+	struct swreg030_qos_ctrl {
+		u32 axi_wr_qos_level		: 4;
+		u32 reserve0			: 4;
+		u32 axi_wr_qos			: 4;
+		u32 reserve1			: 4;
+		u32 axi_rd_qos_level		: 4;
+		u32 reserve2			: 4;
+		u32 axi_rd_qos			: 4;
+		u32 reserve3			: 4;
+	} reg030;
+};
+
+struct vdpu383_regs_common_addr {
+	u32 reg128_strm_base;
+	u32 reg129_rps_base;
+	u32 reg130_cabactbl_base;
+	u32 reg131_gbl_base;
+	u32 reg132_scanlist_addr;
+	u32 reg133_scale_down_base;
+	u32 reg134_fgs_base;
+	u32 reg135_139_reserved[5];
+
+	struct rcb_info {
+	u32 offset;
+	u32 size;
+	} reg140_162_rcb_info[11];
+};
+
+struct vdpu383_regs_h26x_addr {
+	u32 reg168_decout_base;
+	u32 reg169_error_ref_base;
+	u32 reg170_185_ref_base[16];
+	u32 reg186_191_reserved[6];
+	u32 reg192_payload_st_cur_base;
+	u32 reg193_fbc_payload_offset;
+	u32 reg194_payload_st_error_ref_base;
+	u32 reg195_210_payload_st_ref_base[16];
+	u32 reg211_215_reserved[5];
+	u32 reg216_colmv_cur_base;
+	u32 reg217_232_colmv_ref_base[16];
+};
+
+struct vdpu383_regs_h26x_params {
+	u32 reg064_start_decoder;
+	u32 reg065_strm_start_bit;
+	u32 reg066_stream_len;
+	u32 reg067_global_len;
+	u32 reg068_hor_virstride;
+	u32 reg069_raster_uv_hor_virstride;
+	u32 reg070_y_virstride;
+	u32 reg071_scl_ref_hor_virstride;
+	u32 reg072_scl_ref_raster_uv_hor_virstride;
+	u32 reg073_scl_ref_virstride;
+	u32 reg074_fgs_ref_hor_virstride;
+	u32 reg075_079_reserved[5];
+	u32 reg080_error_ref_hor_virstride;
+	u32 reg081_error_ref_raster_uv_hor_virstride;
+	u32 reg082_error_ref_virstride;
+	u32 reg083_ref0_hor_virstride;
+	u32 reg084_ref0_raster_uv_hor_virstride;
+	u32 reg085_ref0_virstride;
+	u32 reg086_ref1_hor_virstride;
+	u32 reg087_ref1_raster_uv_hor_virstride;
+	u32 reg088_ref1_virstride;
+	u32 reg089_ref2_hor_virstride;
+	u32 reg090_ref2_raster_uv_hor_virstride;
+	u32 reg091_ref2_virstride;
+	u32 reg092_ref3_hor_virstride;
+	u32 reg093_ref3_raster_uv_hor_virstride;
+	u32 reg094_ref3_virstride;
+	u32 reg095_ref4_hor_virstride;
+	u32 reg096_ref4_raster_uv_hor_virstride;
+	u32 reg097_ref4_virstride;
+	u32 reg098_ref5_hor_virstride;
+	u32 reg099_ref5_raster_uv_hor_virstride;
+	u32 reg100_ref5_virstride;
+	u32 reg101_ref6_hor_virstride;
+	u32 reg102_ref6_raster_uv_hor_virstride;
+	u32 reg103_ref6_virstride;
+	u32 reg104_ref7_hor_virstride;
+	u32 reg105_ref7_raster_uv_hor_virstride;
+	u32 reg106_ref7_virstride;
+};
+
+struct vdpu383_regs_h26x {
+	struct vdpu383_regs_common		common;		/* 8-

30 */

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +1 -0
+	struct vdpu383_regs_h26x_params		h26x_params;	/*

64-74, 80-106 */

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +1 -0
+	struct vdpu383_regs_common_addr		common_addr;	/*

128-134, 140-161 */

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +1 -0
+	struct vdpu383_regs_h26x_addr		h26x_addr;	/* 168-185,

192-210, 216-232 */

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +3 -0
+} __packed;
+
+#endif /* __RKVDEC_VDPU838_REGS_H__ */
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
index 1b55fe4ff2baf..dab34a2322c95 100644
@@ -9,6 +9,7 @@
   * Copyright (C) 2011 Samsung Electronics Co., Ltd.
   */


+#include <linux/hw_bitfield.h>
 #include <linux/clk.h>
 #include <linux/genalloc.h>
 #include <linux/interrupt.h>

drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
@@ -29,6 +30,7 @@
  #include "rkvdec.h"
  #include "rkvdec-regs.h"
  #include "rkvdec-vdpu381-regs.h"
+#include "rkvdec-vdpu383-regs.h"
  #include "rkvdec-rcb.h"


 static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -120,6 +122,16 @@ static int vdpu38x_fill_pixfmt_mp(struct

v4l2_pix_format_mplane *pix_mp, u32 pix
  return 0;
 }

drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+static u32 rkvdec_colmv_size(u16 width, u16 height)
+{
+	return 128 * DIV_ROUND_UP(width, 16) * DIV_ROUND_UP(height, 16);
+}
+
+static u32 rkvdec_vdpu383_colmv_size(u16 width, u16 height)
+{
+	return ALIGN(width, 64) * ALIGN(height, 16);
+}
+

 static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx *ctx, struct v4l2_pix_format_mplane *pix_mp) {

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -129,9 +141,7 @@ static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx
 *ctx,


  ctx->colmv_offset = pix_mp->plane_fmt[0].sizeimage;

drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -3
-	pix_mp->plane_fmt[0].sizeimage += 128 *
-		DIV_ROUND_UP(pix_mp->width, 16) *
-		DIV_ROUND_UP(pix_mp->height, 16);
+	pix_mp->plane_fmt[0].sizeimage += cfg->colmv_size(pix_mp->width,

pix_mp->height);
 }

 static void rkvdec_reset_fmt(struct rkvdec_ctx *ctx, struct v4l2_format *f,

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -346,6 +356,25 @@ static const struct rkvdec_coded_fmt_desc
 vdpu381_coded_fmts[] = {
  	},
  };

drivers/media/platform/rockchip/rkvdec/rkvdec.c +19 -0
+static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = {
+	{
+		.fourcc = V4L2_PIX_FMT_H264_SLICE,
+		.frmsize = {
+			.min_width = 64,
+			.max_width =  65520,
+			.step_width = 64,
+			.min_height = 16,
+			.max_height =  65520,
+			.step_height = 16,
+		},
+		.ctrls = &rkvdec_h264_ctrls,
+		.ops = &rkvdec_vdpu383_h264_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_h264_decoded_fmts),
+		.decoded_fmts = rkvdec_h264_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
+};
+

 static const struct rkvdec_coded_fmt_desc * rkvdec_find_coded_fmt_desc(struct rkvdec_ctx *ctx, u32 fourcc) {

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -1213,6 +1242,35 @@ static irqreturn_t vdpu381_irq_handler(struct
 rkvdec_ctx *ctx)
  	return IRQ_HANDLED;
  }

drivers/media/platform/rockchip/rkvdec/rkvdec.c +9 -0
+static irqreturn_t vdpu383_irq_handler(struct rkvdec_ctx *ctx)
+{
+	struct rkvdec_dev *rkvdec = ctx->dev;
+	enum vb2_buffer_state state;
+	bool need_reset = 0;
+	u32 status;
+
+	status = readl(rkvdec->link + VDPU383_LINK_STA_INT);
+	writel(FIELD_PREP_WM16(VDPU383_STA_INT_ALL, 0), rkvdec->link +

VDPU383_LINK_STA_INT);

drivers/media/platform/rockchip/rkvdec/rkvdec.c +2 -0
+	/* On vdpu383, the interrupts must be disabled */
+	writel(FIELD_PREP_WM16(VDPU383_INT_EN_IRQ | VDPU383_INT_EN_LINE_IRQ,

0),

drivers/media/platform/rockchip/rkvdec/rkvdec.c +18 -0
+	       rkvdec->link + VDPU383_LINK_INT_EN);
+
+	if (status & VDPU383_STA_INT_DEC_RDY_STA) {
+		state = VB2_BUF_STATE_DONE;
+	} else {
+		state = VB2_BUF_STATE_ERROR;
+		rkvdec_iommu_restore(rkvdec);
+	}
+
+	if (need_reset)
+		rkvdec_iommu_restore(rkvdec);
+
+	if (cancel_delayed_work(&rkvdec->watchdog_work))
+		rkvdec_job_finish(ctx, state);
+
+	return IRQ_HANDLED;
+}
+

 static irqreturn_t rkvdec_irq_handler(int irq, void *priv) {
  struct rkvdec_dev *rkvdec = priv;

drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
@@ -1285,6 +1343,7 @@ const struct rkvdec_config config_rkvdec = {
  	.coded_fmts_num = ARRAY_SIZE(rkvdec_coded_fmts),
  	.irq_handler = rk3399_irq_handler,
  	.fill_pixfmt_mp = v4l2_fill_pixfmt_mp,
+	.colmv_size = rkvdec_colmv_size,
  };


 static struct rcb_size_info vdpu381_rcb_sizes[] = {

drivers/media/platform/rockchip/rkvdec/rkvdec.c +27 -0
@@ -1307,11 +1366,39 @@ const struct rkvdec_config config_vdpu381 = {
  	.rcb_num = ARRAY_SIZE(vdpu381_rcb_sizes),
  	.irq_handler = vdpu381_irq_handler,
  	.fill_pixfmt_mp = vdpu38x_fill_pixfmt_mp,
+	.colmv_size = rkvdec_colmv_size,
+	.named_regs = true,
+};
+
+static struct rcb_size_info vdpu383_rcb_sizes[] = {
+	{6,	PIC_WIDTH},	// streamd
+	{6,	PIC_WIDTH},	// streamd_tile
+	{12,	PIC_WIDTH},	// inter
+	{12,	PIC_WIDTH},	// inter_tile
+	{16,	PIC_WIDTH},	// intra
+	{10,	PIC_WIDTH},	// intra_tile
+	{120,	PIC_WIDTH},	// filterd
+	{120,	PIC_WIDTH},	// filterd_protect
+	{120,	PIC_WIDTH},	// filterd_tile_row
+	{180,	PIC_HEIGHT},	// filterd_tile_col
+};
+
+const struct rkvdec_config config_vdpu383 = {
+	.coded_fmts = (struct rkvdec_coded_fmt_desc *)vdpu383_coded_fmts,
+	.coded_fmts_num = ARRAY_SIZE(vdpu383_coded_fmts),
+	.rcb_size_info = vdpu383_rcb_sizes,
+	.rcb_num = ARRAY_SIZE(vdpu383_rcb_sizes),
+	.irq_handler = vdpu383_irq_handler,
+	.fill_pixfmt_mp = vdpu38x_fill_pixfmt_mp,
+	.colmv_size = rkvdec_vdpu383_colmv_size,
+	.fill_pixfmt_mp = vdpu38x_fill_pixfmt_mp,
+	.named_regs = true,
  };


 static const struct of_device_id of_rkvdec_match[] = {
  { .compatible = "rockchip,rk3399-vdec", .data = &config_rkvdec }, { .compatible = "rockchip,rk3588-vdec", .data = &config_vdpu381 },

drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -0
+	{ .compatible = "rockchip,rk3576-vdec", .data = &config_vdpu383 },

  { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, of_rkvdec_match);

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -1344,9 +1431,19 @@ static int rkvdec_probe(struct platform_device *pdev)
  	rkvdec->clk_count = ret;
  	rkvdec->axi_clk = devm_clk_get(&pdev->dev, "axi");

drivers/media/platform/rockchip/rkvdec/rkvdec.c +2 -3
-	rkvdec->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(rkvdec->regs))
-		return PTR_ERR(rkvdec->regs);
+	if (rkvdec->config->named_regs) {
+		rkvdec->regs = devm_platform_ioremap_resource_byname(pdev,

"function");

drivers/media/platform/rockchip/rkvdec/rkvdec.c +4 -0
+		if (IS_ERR(rkvdec->regs))
+			return PTR_ERR(rkvdec->regs);
+
+		rkvdec->link = devm_platform_ioremap_resource_byname(pdev,

"link");

drivers/media/platform/rockchip/rkvdec/rkvdec.c +7 -0
+		if (IS_ERR(rkvdec->link))
+			return PTR_ERR(rkvdec->link);
+	} else {
+		rkvdec->regs = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(rkvdec->regs))
+			return PTR_ERR(rkvdec->regs);
+	}


  ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); if (ret) {

drivers/media/platform/rockchip/rkvdec/rkvdec.h +0 -0
index 9e0fef2445abc..acb9d72b130bb 100644
@@ -110,6 +110,8 @@ struct rkvdec_config {
  	irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx);

  int (*fill_pixfmt_mp)(struct v4l2_pix_format_mplane *pix_mp, u32 pixelformat,
        u32 width, u32 height);

drivers/media/platform/rockchip/rkvdec/rkvdec.h +2 -0
+	u32 (*colmv_size)(u16 width, u16 height);
+	bool named_regs;

 };

 struct rkvdec_dev {

drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
@@ -122,6 +124,7 @@ struct rkvdec_dev {
  	unsigned int clk_count;
  	struct clk *axi_clk;
  	void __iomem *regs;
+	void __iomem *link;

  struct mutex vdev_lock; /* serializes ioctls */ struct delayed_work watchdog_work; struct gen_pool *sram_pool;

drivers/media/platform/rockchip/rkvdec/rkvdec.h +0 -0
@@ -164,9 +167,14 @@ void rkvdec_run_preamble(struct rkvdec_ctx *ctx, struct
 rkvdec_run *run);
  void rkvdec_run_postamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
  void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);


+/* RKVDEC ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops; extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
+/* VDPU381 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops;

drivers/media/platform/rockchip/rkvdec/rkvdec.h +3 -0
+/* VDPU383 ops */
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
+

 #endif /* RKVDEC_H_ */

author maintainer
#23 lore raw

PATCH v2 11/12 media: rkvdec: Add HEVC support for the VDPU381 variant

In reply to Detlev Casanova

The VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.

It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)

The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.

---
 .../media/platform/rockchip/rkvdec/Kconfig    |    1 +
 .../media/platform/rockchip/rkvdec/Makefile   |    2 +
 .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 3435 +++++++++++++++++
 .../rockchip/rkvdec/rkvdec-hevc-common.c      |  546 +++
 .../rockchip/rkvdec/rkvdec-hevc-common.h      |  101 +
 .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c     |  596 +++
 .../media/platform/rockchip/rkvdec/rkvdec.c   |   81 +
 .../media/platform/rockchip/rkvdec/rkvdec.h   |    1 +
 8 files changed, 4763 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
drivers/media/platform/rockchip/rkvdec/Kconfig +1 -0
index 5f3bdd848a2cf..3303b0ce32809 100644
@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC
 	select VIDEOBUF2_VMALLOC
 	select V4L2_MEM2MEM_DEV
 	select V4L2_H264
+	select V4L2_HEVC
 	select V4L2_VP9
 	help
 	  Support for the Rockchip Video Decoder IP present on Rockchip SoCs,
drivers/media/platform/rockchip/rkvdec/Makefile +2 -0
index c38ce1e8d3601..fbc8d0d639ab6 100644
@@ -5,7 +5,9 @@ rockchip-vdec-y += \
 		   rkvdec-cabac.o \
 		   rkvdec-h264.o \
 		   rkvdec-h264-common.o \
+		   rkvdec-hevc-common.o \
 		   rkvdec-rcb.o \
 		   rkvdec-vdpu381-h264.o \
+		   rkvdec-vdpu381-hevc.o \
 		   rkvdec-vdpu383-h264.o \
 		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-cabac.c +3435 -0

2,984 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c new file +546 -0

546 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h new file +101 -0

101 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +596 -0

596 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.c +81 -0

81 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index acb9d72b130bb..df56bc0516ac9 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.50.1

Part of the diff is not shown here. View the raw message.

#24 lore raw

Re: [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant

kernel test robot noticed the following build errors:

Hi Detlev,

kernel test robot noticed the following build errors:

[auto build test ERROR on linuxtv-media-pending/master]
[also build test ERROR on linus/master next-20250808]
[cannot apply to rockchip/for-next sailus-media-tree/master sailus-media-tree/streams v6.16] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Detlev-Casanova/media-rkvdec-Switch-to-using-structs-instead-of-writel/20250809-041049
base:   https://git.linuxtv.org/media-ci/media-pending.git master
patch link:    https://lore.kernel.org/r/20250808200340.156393-12-detlev.casanova%40collabora.com
patch subject: [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant
config: i386-buildonly-randconfig-005-20250809 (https://download.01.org/0day-ci/archive/20250809/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250809/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c:119:39: error: field has incomplete type 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
     119 |         struct v4l2_ctrl_hevc_ext_sps_st_rps    st_cache;
         |                                                 ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   1 error generated.
--
>> drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:261:23: error: subscript of pointer to incomplete type 'const struct v4l2_ctrl_hevc_ext_sps_lt_rps'
     261 |                         run->ext_sps_lt_rps[i].lt_ref_pic_poc_lsb_sps;
         |                         ~~~~~~~~~~~~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:69:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_lt_rps'
      69 |         const struct v4l2_ctrl_hevc_ext_sps_lt_rps      *ext_sps_lt_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:263:26: error: subscript of pointer to incomplete type 'const struct v4l2_ctrl_hevc_ext_sps_lt_rps'
     263 |                         !!(run->ext_sps_lt_rps[i].flags & V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT);
         |                            ~~~~~~~~~~~~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:69:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_lt_rps'
      69 |         const struct v4l2_ctrl_hevc_ext_sps_lt_rps      *ext_sps_lt_rps;
         |                      ^
>> drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:263:38: error: use of undeclared identifier 'V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT'
     263 |                         !!(run->ext_sps_lt_rps[i].flags & V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT);
         |                                                           ^
>> drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:299:77: error: subscript of pointer to incomplete type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     299 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data = &run->ext_sps_st_rps[idx];
         |                                                                 ~~~~~~~~~~~~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
>> drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:310:38: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     310 |         ref_rps_idx = st_rps_idx - (rps_data->delta_idx_minus1 + 1); /* 7-59 */
         |                                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:311:31: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     311 |         delta_rps = (1 - 2 * rps_data->delta_rps_sign) *
         |                              ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:312:15: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     312 |                    (rps_data->abs_delta_rps_minus1 + 1); /* 7-60 */
         |                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:317:41: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     317 |                 used_by_curr_pic_flag[j] = !!(rps_data->used_by_curr_pic & (1 << j));
         |                                               ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:318:34: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     318 |                 use_delta_flag[j] = !!(rps_data->use_delta_flag & (1 << j));
         |                                        ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:376:77: error: subscript of pointer to incomplete type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     376 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data = &run->ext_sps_st_rps[idx];
         |                                                                 ~~~~~~~~~~~~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:381:38: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     381 |         st_rps->num_negative_pics = rps_data->num_negative_pics;
         |                                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:383:38: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     383 |         st_rps->num_positive_pics = rps_data->num_positive_pics;
         |                                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:387:47: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     387 |                 st_rps->used_by_curr_pic_s0[i] = !!(rps_data->used_by_curr_pic & (1 << i));
         |                                                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:391:40: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     391 |                         st_rps->delta_poc_s0[i] = -(rps_data->delta_poc_s0_minus1[i] + 1);
         |                                                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:396:14: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     396 |                                 (rps_data->delta_poc_s0_minus1[i] + 1);
         |                                  ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:402:47: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     402 |                 st_rps->used_by_curr_pic_s1[j] = !!(rps_data->used_by_curr_pic & (1 << (i + j)));
         |                                                     ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:406:38: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     406 |                         st_rps->delta_poc_s1[j] = rps_data->delta_poc_s1_minus1[j] + 1;
         |                                                   ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:411:14: error: incomplete definition of type 'const struct v4l2_ctrl_hevc_ext_sps_st_rps'
     411 |                                 (rps_data->delta_poc_s1_minus1[j] + 1);
         |                                  ~~~~~~~~^
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^
>> drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c:427:42: error: invalid application of 'sizeof' to an incomplete type 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
     427 |         if (!memcmp(cache, run->ext_sps_st_rps, sizeof(struct v4l2_ctrl_hevc_ext_sps_st_rps)))
         |                                                 ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h:68:15: note: forward declaration of 'struct v4l2_ctrl_hevc_ext_sps_st_rps'
      68 |         const struct v4l2_ctrl_hevc_ext_sps_st_rps      *ext_sps_st_rps;
         |                      ^

fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.

vim +119 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c

115
116 struct rkvdec_hevc_ctx {
117 struct rkvdec_aux_buf priv_tbl;
118 struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache;

 > 119		struct v4l2_ctrl_hevc_ext_sps_st_rps	st_cache;

120 struct rkvdec_vdpu381_regs_hevc regs;
121 };
122

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#25 lore raw

Re: [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant

In reply to Detlev Casanova

Hi again,

I think I've found a similar issue here as I did for H264.

Quoted 126 lines · Detlev Casanova

The VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.

It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)

The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.

---
 .../media/platform/rockchip/rkvdec/Kconfig    |    1 +
 .../media/platform/rockchip/rkvdec/Makefile   |    2 +
 .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 3435 +++++++++++++++++
 .../rockchip/rkvdec/rkvdec-hevc-common.c      |  546 +++
 .../rockchip/rkvdec/rkvdec-hevc-common.h      |  101 +
 .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c     |  596 +++
 .../media/platform/rockchip/rkvdec/rkvdec.c   |   81 +
 .../media/platform/rockchip/rkvdec/rkvdec.h   |    1 +
 8 files changed, 4763 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
drivers/media/platform/rockchip/rkvdec/Kconfig +1 -0
index 5f3bdd848a2cf..3303b0ce32809 100644
@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC
 	select VIDEOBUF2_VMALLOC
 	select V4L2_MEM2MEM_DEV
 	select V4L2_H264
+	select V4L2_HEVC
 	select V4L2_VP9
 	help
 	  Support for the Rockchip Video Decoder IP present on Rockchip SoCs,
 
...
drivers/media/platform/rockchip/rkvdec/rkvdec.c +65 -0
index dab34a2322c95..cd01f1e41beb5 100644
@@ -257,6 +257,60 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = {
 	.num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs),
 };
 
+static const struct rkvdec_ctrl_desc rkvdec_hevc_ctrl_descs[] = {
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_PARAMS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SPS,
+		.cfg.ops = &rkvdec_ctrl_ops,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_PPS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SCALING_MATRIX,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_MODE,
+		.cfg.min = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.max = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.def = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_START_CODE,
+		.cfg.min = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.def = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.max = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+		.cfg.menu_skip_mask =
+			BIT(V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE),
+		.cfg.def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS,
+		.cfg.dims = { 65 },
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS,
+		.cfg.dims = { 65 },
+	},
+};
+
+static const struct rkvdec_ctrls rkvdec_hevc_ctrls = {
+	.ctrls = rkvdec_hevc_ctrl_descs,
+	.num_ctrls = ARRAY_SIZE(rkvdec_hevc_ctrl_descs),
+};
+
 static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
 	{
 		.fourcc = V4L2_PIX_FMT_NV12,
@@ -276,6 +330,17 @@ static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
 	},
 };
 
+static const struct rkvdec_decoded_fmt_desc rkvdec_hevc_decoded_fmts[] = {
+	{
+		.fourcc = V4L2_PIX_FMT_NV12,
+		.image_fmt = RKVDEC_IMG_FMT_420_8BIT,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_NV15,
+		.image_fmt = RKVDEC_IMG_FMT_420_10BIT,
+	},
+};
+
 static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] = {
 	{
 		.cfg.id = V4L2_CID_STATELESS_VP9_FRAME,
@@ -354,6 +419,22 @@ static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {
 		.decoded_fmts = rkvdec_h264_decoded_fmts,
 		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
 	},

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { · line 431

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+		.frmsize = {
+			.min_width = 16,
+			.max_width = 65472,
+			.step_width = 16,
+			.min_height = 16,
+			.max_height = 65472,
+			.step_height = 16,
+		},

In the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
64x64 to 65472x65472; step size 16 pixels

So I think .min_width and .min_height should be 64, not 16.

Cheers,
Diederik

Quoted 21 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6 -0
+		.ctrls = &rkvdec_hevc_ctrls,
+		.ops = &rkvdec_vdpu381_hevc_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_hevc_decoded_fmts),
+		.decoded_fmts = rkvdec_hevc_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
 };
 
 static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = {
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index acb9d72b130bb..df56bc0516ac9 100644
@@ -173,6 +173,7 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
 
 /* VDPU381 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops;
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;
 
 /* VDPU383 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
#26 lore raw

Re: [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant

Hi Diederik and Detlev,

Quoted 145 lines · Diederik de Haas

Hi again,

I think I've found a similar issue here as I did for H264.

Quoted 126 lines · Detlev Casanova

The VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.

It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)

The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.

---
 .../media/platform/rockchip/rkvdec/Kconfig    |    1 +
 .../media/platform/rockchip/rkvdec/Makefile   |    2 +
 .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 3435 +++++++++++++++++
 .../rockchip/rkvdec/rkvdec-hevc-common.c      |  546 +++
 .../rockchip/rkvdec/rkvdec-hevc-common.h      |  101 +
 .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c     |  596 +++
 .../media/platform/rockchip/rkvdec/rkvdec.c   |   81 +
 .../media/platform/rockchip/rkvdec/rkvdec.h   |    1 +
 8 files changed, 4763 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
drivers/media/platform/rockchip/rkvdec/Kconfig +1 -0
index 5f3bdd848a2cf..3303b0ce32809 100644
@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC
 	select VIDEOBUF2_VMALLOC
 	select V4L2_MEM2MEM_DEV
 	select V4L2_H264
+	select V4L2_HEVC
 	select V4L2_VP9
 	help
 	  Support for the Rockchip Video Decoder IP present on Rockchip SoCs,
 
...
drivers/media/platform/rockchip/rkvdec/rkvdec.c +65 -0
index dab34a2322c95..cd01f1e41beb5 100644
@@ -257,6 +257,60 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = {
 	.num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs),
 };
 
+static const struct rkvdec_ctrl_desc rkvdec_hevc_ctrl_descs[] = {
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_PARAMS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SPS,
+		.cfg.ops = &rkvdec_ctrl_ops,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_PPS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SCALING_MATRIX,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_MODE,
+		.cfg.min = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.max = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.def = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_START_CODE,
+		.cfg.min = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.def = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.max = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+		.cfg.menu_skip_mask =
+			BIT(V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE),
+		.cfg.def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS,
+		.cfg.dims = { 65 },
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS,
+		.cfg.dims = { 65 },
+	},
+};
+
+static const struct rkvdec_ctrls rkvdec_hevc_ctrls = {
+	.ctrls = rkvdec_hevc_ctrl_descs,
+	.num_ctrls = ARRAY_SIZE(rkvdec_hevc_ctrl_descs),
+};
+
 static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
 	{
 		.fourcc = V4L2_PIX_FMT_NV12,
@@ -276,6 +330,17 @@ static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
 	},
 };
 
+static const struct rkvdec_decoded_fmt_desc rkvdec_hevc_decoded_fmts[] = {
+	{
+		.fourcc = V4L2_PIX_FMT_NV12,
+		.image_fmt = RKVDEC_IMG_FMT_420_8BIT,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_NV15,
+		.image_fmt = RKVDEC_IMG_FMT_420_10BIT,
+	},
+};
+
 static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] = {
 	{
 		.cfg.id = V4L2_CID_STATELESS_VP9_FRAME,
@@ -354,6 +419,22 @@ static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {
 		.decoded_fmts = rkvdec_h264_decoded_fmts,
 		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
 	},

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { · line 431

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+		.frmsize = {
+			.min_width = 16,
+			.max_width = 65472,
+			.step_width = 16,
+			.min_height = 16,
+			.max_height = 65472,
+			.step_height = 16,
+		},

In the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
64x64 to 65472x65472; step size 16 pixels

Quoted 1 line

So I think .min_width and .min_height should be 64, not 16.

This should probably be changed to use min/max of 64 together with use of 64 as step_width. With that we should not really need the special vdpu38x_fill_pixfmt_mp, if I am not mistaken.

Use of 64 aligned buffers was introduced to correctly align buffers for H264 hi10 and 10-bit HEVC, I currently do not see any reason why we need to do something different for "rkvdec2".

Regards,
Jonas

Quoted 26 lines

Cheers,
Diederik

Quoted 21 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6 -0
+		.ctrls = &rkvdec_hevc_ctrls,
+		.ops = &rkvdec_vdpu381_hevc_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_hevc_decoded_fmts),
+		.decoded_fmts = rkvdec_hevc_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
 };
 
 static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = {
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index acb9d72b130bb..df56bc0516ac9 100644
@@ -173,6 +173,7 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
 
 /* VDPU381 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops;
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;
 
 /* VDPU383 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
#27 lore raw

Re: [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant

Le samedi 20 septembre 2025 à 18:23 +0200, Jonas Karlman a écrit :

Quoted 150 lines

Hi Diederik and Detlev,

Quoted 145 lines · Diederik de Haas

Hi again,

I think I've found a similar issue here as I did for H264.

Quoted 126 lines · Detlev Casanova

The VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.

It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)

The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.

---
 .../media/platform/rockchip/rkvdec/Kconfig    |    1 + .../media/platform/rockchip/rkvdec/Makefile   |    2 + .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 3435 +++++++++++++++++ .../rockchip/rkvdec/rkvdec-hevc-common.c      |  546 +++ .../rockchip/rkvdec/rkvdec-hevc-common.h      |  101 + .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c     |  596 +++ .../media/platform/rockchip/rkvdec/rkvdec.c   |   81 + .../media/platform/rockchip/rkvdec/rkvdec.h   |    1 +

 8 files changed, 4763 insertions(+)

 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c

drivers/media/platform/rockchip/rkvdec/Kconfig +0 -0
index 5f3bdd848a2cf..3303b0ce32809 100644
@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC

  select VIDEOBUF2_VMALLOC
  select V4L2_MEM2MEM_DEV
  select V4L2_H264

drivers/media/platform/rockchip/rkvdec/Kconfig +1 -0
+	select V4L2_HEVC

  select V4L2_VP9
  help
    Support for the Rockchip Video Decoder IP present on Rockchip SoCs,

...

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
index dab34a2322c95..cd01f1e41beb5 100644
@@ -257,6 +257,60 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = {
  	.num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs),
  };

drivers/media/platform/rockchip/rkvdec/rkvdec.c +54 -0
+static const struct rkvdec_ctrl_desc rkvdec_hevc_ctrl_descs[] = {
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_PARAMS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SPS,
+		.cfg.ops = &rkvdec_ctrl_ops,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_PPS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SCALING_MATRIX,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_MODE,
+		.cfg.min = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.max = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.def = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_START_CODE,
+		.cfg.min = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.def = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.max = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+		.cfg.menu_skip_mask =
+			BIT(V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE),
+		.cfg.def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS,
+		.cfg.dims = { 65 },
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS,
+		.cfg.dims = { 65 },
+	},
+};
+
+static const struct rkvdec_ctrls rkvdec_hevc_ctrls = {
+	.ctrls = rkvdec_hevc_ctrl_descs,
+	.num_ctrls = ARRAY_SIZE(rkvdec_hevc_ctrl_descs),
+};
+

 static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = { {
  .fourcc = V4L2_PIX_FMT_NV12,

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -276,6 +330,17 @@ static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
  	},
  };

drivers/media/platform/rockchip/rkvdec/rkvdec.c +11 -0
+static const struct rkvdec_decoded_fmt_desc rkvdec_hevc_decoded_fmts[] = {
+	{
+		.fourcc = V4L2_PIX_FMT_NV12,
+		.image_fmt = RKVDEC_IMG_FMT_420_8BIT,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_NV15,
+		.image_fmt = RKVDEC_IMG_FMT_420_10BIT,
+	},
+};
+

 static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] = { {
  .cfg.id = V4L2_CID_STATELESS_VP9_FRAME,

drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
@@ -354,6 +419,22 @@ static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {
  		.decoded_fmts = rkvdec_h264_decoded_fmts,
  		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
  	},

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { · line 431

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+		.frmsize = {
+			.min_width = 16,
+			.max_width = 65472,
+			.step_width = 16,
+			.min_height = 16,
+			.max_height = 65472,
+			.step_height = 16,
+		},

In the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
64x64 to 65472x65472; step size 16 pixels

Quoted 1 line

So I think .min_width and .min_height should be 64, not 16.

Quoted 7 lines

This should probably be changed to use min/max of 64 together with use of 64 as step_width. With that we should not really need the special vdpu38x_fill_pixfmt_mp, if I am not mistaken.

Use of 64 aligned buffers was introduced to correctly align buffers for H264 hi10 and 10-bit HEVC, I currently do not see any reason why we need to do something different for "rkvdec2".

And another data point, 64x64 have been picked in the past to improve compatibility with the Mali GPUs, which typically requires 64 x 64 alignment. Its not true if you use the YUV sampler, but there is a lot of use cases to pass decoder data to the normal 2D samplers.

More context, nearly all Rockchip SoC we support have GPUs based on ARM Mali technology.

Nicolas

Quoted 31 lines

Regards,
Jonas

Quoted 26 lines

Cheers,
  Diederik

Quoted 21 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6 -0
+		.ctrls = &rkvdec_hevc_ctrls,
+		.ops = &rkvdec_vdpu381_hevc_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_hevc_decoded_fmts),
+		.decoded_fmts = rkvdec_hevc_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
  };


 static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = {

drivers/media/platform/rockchip/rkvdec/rkvdec.h +0 -0
index acb9d72b130bb..df56bc0516ac9 100644
@@ -173,6 +173,7 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;


 /* VDPU381 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;
 /* VDPU383 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;

author maintainer
#28 lore raw

Re: [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant

In reply to Diederik de Haas

Hi Diederik

Thanks for spotting that ! I'll change it in the next patch set :)

Detlev.

Quoted 170 lines · Diederik de Haas

Hi again,

I think I've found a similar issue here as I did for H264.

Quoted 126 lines · Detlev Casanova

The VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.

It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)

The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.

---
  .../media/platform/rockchip/rkvdec/Kconfig    |    1 +
  .../media/platform/rockchip/rkvdec/Makefile   |    2 +
  .../platform/rockchip/rkvdec/rkvdec-cabac.c   | 3435 +++++++++++++++++
  .../rockchip/rkvdec/rkvdec-hevc-common.c      |  546 +++
  .../rockchip/rkvdec/rkvdec-hevc-common.h      |  101 +
  .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c     |  596 +++
  .../media/platform/rockchip/rkvdec/rkvdec.c   |   81 +
  .../media/platform/rockchip/rkvdec/rkvdec.h   |    1 +
  8 files changed, 4763 insertions(+)

create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c

drivers/media/platform/rockchip/rkvdec/Kconfig +1 -0
index 5f3bdd848a2cf..3303b0ce32809 100644
@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC
  	select VIDEOBUF2_VMALLOC
  	select V4L2_MEM2MEM_DEV
  	select V4L2_H264
+	select V4L2_HEVC
  	select V4L2_VP9
  	help
  	  Support for the Rockchip Video Decoder IP present on Rockchip SoCs,
 
...
drivers/media/platform/rockchip/rkvdec/rkvdec.c +65 -0
index dab34a2322c95..cd01f1e41beb5 100644
@@ -257,6 +257,60 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = {
  	.num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs),
  };
 
+static const struct rkvdec_ctrl_desc rkvdec_hevc_ctrl_descs[] = {
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_PARAMS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SPS,
+		.cfg.ops = &rkvdec_ctrl_ops,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_PPS,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_SCALING_MATRIX,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_DECODE_MODE,
+		.cfg.min = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.max = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+		.cfg.def = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_START_CODE,
+		.cfg.min = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.def = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+		.cfg.max = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+		.cfg.menu_skip_mask =
+			BIT(V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE),
+		.cfg.def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+	},
+	{
+		.cfg.id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+		.cfg.min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+		.cfg.max = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1,
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS,
+		.cfg.dims = { 65 },
+	},
+	{
+		.cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS,
+		.cfg.dims = { 65 },
+	},
+};
+
+static const struct rkvdec_ctrls rkvdec_hevc_ctrls = {
+	.ctrls = rkvdec_hevc_ctrl_descs,
+	.num_ctrls = ARRAY_SIZE(rkvdec_hevc_ctrl_descs),
+};
+
  static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
  	{
  		.fourcc = V4L2_PIX_FMT_NV12,
@@ -276,6 +330,17 @@ static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = {
  	},
  };
 
+static const struct rkvdec_decoded_fmt_desc rkvdec_hevc_decoded_fmts[] = {
+	{
+		.fourcc = V4L2_PIX_FMT_NV12,
+		.image_fmt = RKVDEC_IMG_FMT_420_8BIT,
+	},
+	{
+		.fourcc = V4L2_PIX_FMT_NV15,
+		.image_fmt = RKVDEC_IMG_FMT_420_10BIT,
+	},
+};
+
  static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] = {
  	{
  		.cfg.id = V4L2_CID_STATELESS_VP9_FRAME,
@@ -354,6 +419,22 @@ static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = {
  		.decoded_fmts = rkvdec_h264_decoded_fmts,
  		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
  	},

drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { · line 431

Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10 -0
+	{
+		.fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+		.frmsize = {
+			.min_width = 16,
+			.max_width = 65472,
+			.step_width = 16,
+			.min_height = 16,
+			.max_height = 65472,
+			.step_height = 16,
+		},

In the RK3588 TRM Part 1 paragraph 5.4.3, I see "Supported image size" :
64x64 to 65472x65472; step size 16 pixels

So I think .min_width and .min_height should be 64, not 16.

Cheers,
Diederik

Quoted 21 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6 -0
+		.ctrls = &rkvdec_hevc_ctrls,
+		.ops = &rkvdec_vdpu381_hevc_fmt_ops,
+		.num_decoded_fmts = ARRAY_SIZE(rkvdec_hevc_decoded_fmts),
+		.decoded_fmts = rkvdec_hevc_decoded_fmts,
+		.subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
+	},
  };
 
  static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = {
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
index acb9d72b130bb..df56bc0516ac9 100644
@@ -173,6 +173,7 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
 
  /* VDPU381 ops */
  extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops;
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;
 
  /* VDPU383 ops */
  extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
author maintainer
#29 lore raw

PATCH v2 12/12 media: rkvdec: Add HEVC support for the VDPU383 variant

In reply to Detlev Casanova

The VDPU383 decoder is used on the RK3576 SoC and has support for HEVC.

This patch also moves some functions to a common rkvdec-hevc-common.c file and adds a specific scaling matrix flatten function.

The fluster score for JCT-VC-HEVC_V1 is 146/147.

---
 .../media/platform/rockchip/rkvdec/Makefile   |   1 +
 .../rockchip/rkvdec/rkvdec-hevc-common.c      |  49 +-
 .../rockchip/rkvdec/rkvdec-vdpu383-hevc.c     | 688 ++++++++++++++++++
 .../media/platform/rockchip/rkvdec/rkvdec.c   |  91 +++
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   2 +
 5 files changed, 789 insertions(+), 42 deletions(-)
 create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
index fbc8d0d639ab6..3e072099894ea 100644
@@ -10,4 +10,5 @@ rockchip-vdec-y += \
 		   rkvdec-vdpu381-h264.o \
 		   rkvdec-vdpu381-hevc.o \
 		   rkvdec-vdpu383-h264.o \
+		   rkvdec-vdpu383-hevc.o \
 		   rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +7 -42

68 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c new file +688 -0

688 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.c +91 -0

121 lines not on this page · raw message

drivers/media/platform/rockchip/rkvdec/rkvdec.h +2 -0
index df56bc0516ac9..2434f928040e0 100644
@@ -111,6 +111,7 @@ struct rkvdec_config {
 	int (*fill_pixfmt_mp)(struct v4l2_pix_format_mplane *pix_mp, u32 pixelformat,
 			      u32 width, u32 height);
 	u32 (*colmv_size)(u16 width, u16 height);
+	void (*flatten_matrices)(u8 *output, const u8 *input, int matrices, int row_length);
 	bool named_regs;
 };
 
@@ -177,5 +178,6 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;
 
 /* VDPU383 ops */
 extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
+extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_hevc_fmt_ops;
 
 #endif /* RKVDEC_H_ */
Signature · 1 line
2.50.1
maintainer
#30 lore raw
In reply to Detlev Casanova

Hi Detlev,

Am Freitag, 8. August 2025, 22:03:22 Mitteleuropäische Sommerzeit schrieb Detlev Casanova:

Quoted 24 lines

These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.

As there is a considerable part of the code that can be shared with the already supported rkvdec decoder driver, the support for these variants is added here rather than writing a new driver.

This patch set uses the newly introduced hevc_ext_sps_[ls]t_rps v4l2 controls for HEVC [1].
Therefore, a patched version of userpace tools is needed for HEVC support (added for GStreamer[2] and in an early stage for FFmpeg[3]).

This patch set also depends on the preparation patch set sent earlier [4] as well as the iommu restore fix [5] (already merged in linux-media) and Nicolas Frattaroli's bitmap patch [6] to support setting registers that uses upper 16 bits as masks.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9355
[3]: https://gitlab.collabora.com/detlev/ffmpeg
[4]: https://lore.kernel.org/all/[email protected]/
[5]: https://lore.kernel.org/all/[email protected]/
[6]: https://lore.kernel.org/all/[email protected]/

Quoted 6 lines

Changes since v1:
- Add parsing of the short and long term ref frame sets from the new v4l2 controls
- Add RPS cache to avoid parsing the same data again
- Fix HEVC pixel formats selection
- Fix multiple indentation errors

when applying the series, git was a bit unhappy about some whitespaces:

Quoted 3 lines

Detlev Casanova (12):
media: rkvdec: Switch to using structs instead of writel
media: rkvdec: Move cabac table to its own source file

Applying: media: rkvdec: Move cabac table to its own source file .git/rebase-apply/patch:535: new blank line at EOF.
+
Warnung: 1 Zeile fügt Whitespace-Fehler hinzu.

Quoted 2 lines

media: rkvdec: Use structs to represent the HW RPS
media: rkvdec: Move h264 functions to common file

Applying: media: rkvdec: Move h264 functions to common file .git/rebase-apply/patch:278: new blank line at EOF. +
Warnung: 1 Zeile fügt Whitespace-Fehler hinzu.

Quoted 2 lines

media: rkvdec: Add per variant configuration
media: rkvdec: Add RCB and SRAM support

Applying: media: rkvdec: Add RCB and SRAM support .git/rebase-apply/patch:200: new blank line at EOF. +
Warnung: 1 Zeile fügt Whitespace-Fehler hinzu.

Quoted 5 lines

media: rkvdec: Support per-variant interrupt handler
media: rkvdec: Enable all clocks without naming them
media: rkvdec: Add H264 support for the VDPU381 variant
media: rkvdec: Add H264 support for the VDPU383 variant
media: rkvdec: Add HEVC support for the VDPU381 variant

Applying: media: rkvdec: Add HEVC support for the VDPU381 variant .git/rebase-apply/patch:3483: new blank line at EOF.
+
.git/rebase-apply/patch:4035: new blank line at EOF.
+
Warnung: 2 Zeilen fügen Whitespace-Fehler hinzu.

Heiko

author maintainer
#31 lore raw

Hi Heiko,

Quoted 3 lines · On Monday, 11 August 2025 05:56:00 EDT Heiko Stübner wrote:

Hi Detlev,

Am Freitag, 8. August 2025, 22:03:22 Mitteleuropäische Sommerzeit schrieb

Detlev Casanova:

Quoted 32 lines
Quoted 32 lines

These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.

As there is a considerable part of the code that can be shared with the already supported rkvdec decoder driver, the support for these variants is added here rather than writing a new driver.

This patch set uses the newly introduced hevc_ext_sps_[ls]t_rps v4l2 controls for HEVC [1].
Therefore, a patched version of userpace tools is needed for HEVC support (added for GStreamer[2] and in an early stage for FFmpeg[3]).

This patch set also depends on the preparation patch set sent earlier [4] as well as the iommu restore fix [5] (already merged in linux-media) and Nicolas Frattaroli's bitmap patch [6] to support setting registers that uses upper 16 bits as masks.

[1]:
https://lore.kernel.org/all/20250807194327.69900-1-detlev.casanova@collab
ora.com/ [2]:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9355
[3]: https://gitlab.collabora.com/detlev/ffmpeg
[4]:
https://lore.kernel.org/all/20250623160722.55938-1-detlev.casanova@collab
ora.com/ [5]:
https://lore.kernel.org/all/20250508-rkvdec-iommu-reset-v1-1-c46b6efa6e9b
@collabora.com/ [6]:
https://lore.kernel.org/all/20250623-byeword-update-v2-1-cf1fc08a2e1f@col
labora.com/>
Changes since v1:
- Add parsing of the short and long term ref frame sets from the new v4l2

Quoted 7 lines
Quoted 5 lines

controls

- Add RPS cache to avoid parsing the same data again
- Fix HEVC pixel formats selection
- Fix multiple indentation errors

when applying the series, git was a bit unhappy about some whitespaces:

Mmh, it looks like some rebase issues. Thanks, I'll fix those !

Quoted 40 lines
Quoted 3 lines

Detlev Casanova (12):
media: rkvdec: Switch to using structs instead of writel
media: rkvdec: Move cabac table to its own source file

Applying: media: rkvdec: Move cabac table to its own source file .git/rebase-apply/patch:535: new blank line at EOF.
+
Warnung: 1 Zeile fügt Whitespace-Fehler hinzu.

Quoted 2 lines

media: rkvdec: Use structs to represent the HW RPS
media: rkvdec: Move h264 functions to common file

Applying: media: rkvdec: Move h264 functions to common file .git/rebase-apply/patch:278: new blank line at EOF. +
Warnung: 1 Zeile fügt Whitespace-Fehler hinzu.

Quoted 2 lines

media: rkvdec: Add per variant configuration
media: rkvdec: Add RCB and SRAM support

Applying: media: rkvdec: Add RCB and SRAM support .git/rebase-apply/patch:200: new blank line at EOF. +
Warnung: 1 Zeile fügt Whitespace-Fehler hinzu.

Quoted 5 lines

media: rkvdec: Support per-variant interrupt handler
media: rkvdec: Enable all clocks without naming them
media: rkvdec: Add H264 support for the VDPU381 variant
media: rkvdec: Add H264 support for the VDPU383 variant
media: rkvdec: Add HEVC support for the VDPU381 variant

Applying: media: rkvdec: Add HEVC support for the VDPU381 variant .git/rebase-apply/patch:3483: new blank line at EOF.
+
.git/rebase-apply/patch:4035: new blank line at EOF.
+
Warnung: 2 Zeilen fügen Whitespace-Fehler hinzu.

Heiko

#32 lore raw
In reply to Detlev Casanova
Quoted 49 lines

Wiadomość napisana przez Detlev Casanova <[email protected]> w dniu 8 sie 2025, o godz. 22:03:

These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.

As there is a considerable part of the code that can be shared with the already supported rkvdec decoder driver, the support for these variants is added here rather than writing a new driver.

This patch set uses the newly introduced hevc_ext_sps_[ls]t_rps v4l2 controls for HEVC [1].
Therefore, a patched version of userpace tools is needed for HEVC support (added for GStreamer[2] and in an early stage for FFmpeg[3]).

This patch set also depends on the preparation patch set sent earlier [4] as well as the iommu restore fix [5] (already merged in linux-media) and Nicolas Frattaroli's bitmap patch [6] to support setting registers that uses upper 16 bits as masks.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9355
[3]: https://gitlab.collabora.com/detlev/ffmpeg
[4]: https://lore.kernel.org/all/[email protected]/
[5]: https://lore.kernel.org/all/[email protected]/
[6]: https://lore.kernel.org/all/[email protected]/

Changes since v1:
- Add parsing of the short and long term ref frame sets from the new v4l2 controls
- Add RPS cache to avoid parsing the same data again
- Fix HEVC pixel formats selection
- Fix multiple indentation errors

Detlev Casanova (12):
media: rkvdec: Switch to using structs instead of writel
media: rkvdec: Move cabac table to its own source file
media: rkvdec: Use structs to represent the HW RPS
media: rkvdec: Move h264 functions to common file
media: rkvdec: Add per variant configuration
media: rkvdec: Add RCB and SRAM support
media: rkvdec: Support per-variant interrupt handler
media: rkvdec: Enable all clocks without naming them
media: rkvdec: Add H264 support for the VDPU381 variant
media: rkvdec: Add H264 support for the VDPU383 variant
media: rkvdec: Add HEVC support for the VDPU381 variant
media: rkvdec: Add HEVC support for the VDPU383 variant

Quoted 1 line

..

Detlev,

I give run for this series on rk3576 and rk3588 devices (various SBC boards) on mainline 6.16 kernel. Userspace was: KODI, MythTV and mpv.
All are using ffmpeg - but without [3] applied*.
Tested video rendering pipelines was: EGL DAMBuf and DRM direct to plane

Happy to report:
-all h264 content** i tested was decoded ok.
-on some rk3576 h264 rendering manifest known "green lines" issue***
-hevc content**** was also decoded ok except samples requiring long sps/rps hinting from userspace (from ffmpeg in my case)

* - it looks (to me) your's ffmpeg branch changes are incompatible with yours rkvdec code (i.e. ffmpeg refers to V4L2_HEVC_EXT_SPS_RPS_FLAG_INTER_REF_PIC_SET_PRED but kernel v2 driver don't have it)

** - i'm referring to multiple h.264 movies and TV HD channels

*** - issue of thin green lines we discussed on rockchip IRC channel

**** - as my ffmpeg7.1 has not applied newly introduced hevc_ext_sps_[ls]t_rps v4l2 controls for HEVC (due *) - some content is not decoded properly.

If any extra tests can be helpful - i'' be more that happy to do so!

br

Tested-by on the v2 series
#33 lore raw
In reply to Detlev Casanova

Hi Detlev,

Quoted 2 lines · Detlev Casanova

These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.

I tested this on my Rock 5B (rk3588) with (ffmpeg and) mpv on Debian Forky with sway and I was quite impressed with the results :-)

In my earlier testing I found that the classic BBB video made for a really good test video and it played REALLY well. The 1080p version in both x264 and 8-bit x265 played without frame drops, although when pressing 'I' to show video info over the video it dropped some frames. But that never resulted in any visible artifacts.
On the 2160p version I did see quite a number of dropped frames, but didn't notice any visual artifacts. Maybe that it got displayed on a 1080p monitor had something to do with it?

10-bit encoded x265 files (still) resulted in a completely blue output, but I have strong reasons to believe that's due to 'missing pieces' (ie NV15 support) in the rest of the display pipeline.

The displayed video seemed sharper and better then in my other tests. I thought I did see an artifact around 5:50 when a big rock almost fell on the little animal. Looking further, it appears to be an artifact in the original video :-O (I saw it also on my AMD GPU on my amd64 system and also when using software decoding).
The fact I only noticed it when testing this patch set is saying a lot ... in a positive way! So I'm happy to provide my

#34 lore raw

Hi,

Le mercredi 17 septembre 2025 à 19:34 +0200, Diederik de Haas a écrit :

Quoted 9 lines

Hi Detlev,

Quoted 2 lines · Detlev Casanova

These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.

I tested this on my Rock 5B (rk3588) with (ffmpeg and) mpv on Debian Forky with sway and I was quite impressed with the results :-)

Quoted 8 lines

In my earlier testing I found that the classic BBB video made for a really good test video and it played REALLY well. The 1080p version in both x264 and 8-bit x265 played without frame drops, although when pressing 'I' to show video info over the video it dropped some frames. But that never resulted in any visible artifacts.
On the 2160p version I did see quite a number of dropped frames, but didn't notice any visual artifacts. Maybe that it got displayed on a 1080p monitor had something to do with it?

Sounds like we have "correctness" with ok performance, so that is enough for me to consider the patches. There is few things that are not implemented that could explain lower performance compare to the downstream stuff, such as the lack of AFBC. It will hopefully come later, giving nice boost when doing GPU streaming.

Quoted 4 lines

10-bit encoded x265 files (still) resulted in a completely blue output, but I have strong reasons to believe that's due to 'missing pieces' (ie NV15 support) in the rest of the display pipeline.

Its still quite early days for NV15 (and its derivatives) upstream of everything, so I would not block on that. It passes the tests when we read back the pixels from CPU I believe.

Quoted 8 lines

The displayed video seemed sharper and better then in my other tests. I thought I did see an artifact around 5:50 when a big rock almost fell on the little animal. Looking further, it appears to be an artifact in the original video :-O (I saw it also on my AMD GPU on my amd64 system and also when using software decoding).
The fact I only noticed it when testing this patch set is saying a lot ... in a positive way! So I'm happy to provide my

That's it, your video watching experience is now ruined for the rest of your life :-D

Quoted 2 lines

thanks a lot for testing,
Nicolas