[PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383

Detlev Casanova posted 12 patches 3 months ago
There is a newer version of this series
.../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      |  331 ++
.../rockchip/rkvdec/rkvdec-hevc-common.h      |   99 +
.../platform/rockchip/rkvdec/rkvdec-rcb.c     |  175 +
.../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     |  425 ++
.../rockchip/rkvdec/rkvdec-vdpu383-h264.c     |  583 +++
.../rockchip/rkvdec/rkvdec-vdpu383-hevc.c     |  687 +++
.../rockchip/rkvdec/rkvdec-vdpu383-regs.h     |  284 ++
.../platform/rockchip/rkvdec/rkvdec-vp9.c     |  230 +-
.../media/platform/rockchip/rkvdec/rkvdec.c   |  565 ++-
.../media/platform/rockchip/rkvdec/rkvdec.h   |   39 +
20 files changed, 9073 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
[PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383
Posted by Detlev Casanova 3 months ago
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 EXT_SPS_RPS v4l2 control for
HEVC [1].
Therefore, a patched version of userpace tools is needed for HEVC
support (currently only added for GStreamer[2])

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

[1]: https://lore.kernel.org/all/20250623160722.55938-7-detlev.casanova@collabora.com/
[2]: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9355
[3]: https://lore.kernel.org/all/20250623160722.55938-1-detlev.casanova@collabora.com/
[4]: https://lore.kernel.org/all/20250508-rkvdec-iommu-reset-v1-1-c46b6efa6e9b@collabora.com/
[5]: https://lore.kernel.org/all/20250623-byeword-update-v2-1-cf1fc08a2e1f@collabora.com/

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      |  331 ++
 .../rockchip/rkvdec/rkvdec-hevc-common.h      |   99 +
 .../platform/rockchip/rkvdec/rkvdec-rcb.c     |  175 +
 .../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     |  425 ++
 .../rockchip/rkvdec/rkvdec-vdpu383-h264.c     |  583 +++
 .../rockchip/rkvdec/rkvdec-vdpu383-hevc.c     |  687 +++
 .../rockchip/rkvdec/rkvdec-vdpu383-regs.h     |  284 ++
 .../platform/rockchip/rkvdec/rkvdec-vp9.c     |  230 +-
 .../media/platform/rockchip/rkvdec/rkvdec.c   |  565 ++-
 .../media/platform/rockchip/rkvdec/rkvdec.h   |   39 +
 20 files changed, 9073 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

-- 
2.50.0
Re:[PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383
Posted by Jianfeng Liu 2 months, 3 weeks ago
Hi,

On Tue,  8 Jul 2025 11:19:33 -0400, Detlev Casanova wrote:
>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.

I have tested the new series on rk3588 and rk3399 with chromium. Since the
HEVC decoder need EXT_SPS_RPS related patches, I ony test the H264 decoder.
There are two issues:

1, The decoder max size is detected 1920x1088, which should be the fallback
size when queryig VIDIOC_ENUM_FRAMESIZES[1].

2, Playing H264 videos ends up with green screen.

These above issues don't happen with the old rkvdec2 series.

[1] https://github.com/chromium/chromium/blob/138.0.7204.92/media/gpu/v4l2/v4l2_utils.cc#L520-L533

Best regards,
Jianfeng
Re: [PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383
Posted by Detlev Casanova 2 months, 3 weeks ago
Hi Jianfeng,

On Sunday, 13 July 2025 10:25:14 EDT Jianfeng Liu wrote:
> Hi,
> 
> On Tue,  8 Jul 2025 11:19:33 -0400, Detlev Casanova wrote:
> >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.
> 
> I have tested the new series on rk3588 and rk3399 with chromium. Since the
> HEVC decoder need EXT_SPS_RPS related patches, I ony test the H264 decoder.
> There are two issues:
> 
> 1, The decoder max size is detected 1920x1088, which should be the fallback
> size when queryig VIDIOC_ENUM_FRAMESIZES[1].

From the linked code, the max size is hard coded to 1920x1088.
The driver sets the frame size type to V4L2_FRMSIZE_TYPE_CONTINUOUS, so the 
snippet you pointed to doesn't update the values for max/min. See [2] for the 
discussion about using V4L2_FRMSIZE_TYPE_CONTINUOUS.

> 2, Playing H264 videos ends up with green screen.

Can you elaborate a bit ? What videos ?
Is that on both SoCs ?
Is there any logs in dmesg ?

> These above issues don't happen with the old rkvdec2 series.
> 
> [1]
> https://github.com/chromium/chromium/blob/138.0.7204.92/media/gpu/v4l2/v4l2
> _utils.cc#L520-L533

[2] https://lore.kernel.org/all/c7882f94-e2cb-4023-a53e-87ebc8fa3460@gmail.com/

Regards,
Detlev
Re: [PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383
Posted by Jianfeng Liu 2 months, 3 weeks ago
Hi Detlev,

On Mon, 14 Jul 2025 09:35:19, Detlev Casanova wrote:
>From the linked code, the max size is hard coded to 1920x1088.
>The driver sets the frame size type to V4L2_FRMSIZE_TYPE_CONTINUOUS, so the 
>snippet you pointed to doesn't update the values for max/min. See [2] for the 
>discussion about using V4L2_FRMSIZE_TYPE_CONTINUOUS.

You are right, the code of chromium should be fixed for frame size type
V4L2_FRMSIZE_TYPE_CONTINUOUS.

>> 2, Playing H264 videos ends up with green screen.
>
>Can you elaborate a bit ? What videos ?
>Is that on both SoCs ?
>Is there any logs in dmesg ?

I am playing a 1080p h264 BBB video[1]. There is no error logs from both
chromium and dmesg, but there is only frames refreshing at the top left
corner while the other part of place is green. This happens on both rk3399
and rk3588.

I have checked that this issue is not introduced by your series. After
reverting this commit[2] which adds Support High 10 and 4:2:2 profiles,
chromium can play video well on rk3399. I will investigate further.

[1] https://mirrors.tuna.tsinghua.edu.cn/blender/demo/movies/BBB/bbb_sunflower_1080p_60fps_normal.mp4.zip
[2] https://github.com/torvalds/linux/commit/5e1ff2314797bf53636468a97719a8222deca9ae

Best regards
Jianfeng
Re: [PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383
Posted by Jianfeng Liu 2 months, 3 weeks ago
Hi,

On Mon, 14 Jul 2025 22:46:10 +0800, Jianfeng Liu wrote:
>You are right, the code of chromium should be fixed for frame size type
>V4L2_FRMSIZE_TYPE_CONTINUOUS.

I have just sent a cr at chromium[1] to fix this.

>I have checked that this issue is not introduced by your series. After
>reverting this commit[2] which adds Support High 10 and 4:2:2 profiles,
>chromium can play video well on rk3399. I will investigate further.

I found that this issue is caused by this code block[2]. Before adding
.get_image_fmt, rkvdec_s_ctrl will just return 0. But now when detecting
image format change(usually from RKVDEC_IMG_FMT_ANY to real video format
like RKVDEC_IMG_FMT_420_8BIT), it will return -EBUSY, then I get green
frame at chromium.

After taking a look at hantro's code, I find that it is not necessary to
let .s_ctrl return -EBUSY when format changes, here is a commit[3]
disabling this check in hantro_set_fmt_cap. I have written a patch that
can fix my issue with chromium, you can see it at the bottom of my mail.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/6767118
[2] https://github.com/torvalds/linux/blob/v6.16-rc6/drivers/staging/media/rkvdec/rkvdec.c#L143-L146
[3] https://github.com/torvalds/linux/commit/bbd267daf4fc831f58bf4a2530a8b64881779e6a

diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
index 5d86fb7cdd6..7800d159fad 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
@@ -185,7 +185,6 @@ static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)
 	struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
 	const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc;
 	enum rkvdec_image_fmt image_fmt;
-	struct vb2_queue *vq;
 
 	/* Check if this change requires a capture format reset */
 	if (!desc->ops->get_image_fmt)
@@ -193,11 +192,6 @@ static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)
 
 	image_fmt = desc->ops->get_image_fmt(ctx, ctrl);
 	if (rkvdec_image_fmt_changed(ctx, image_fmt)) {
-		vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
-				     V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
-		if (vb2_is_busy(vq))
-			return -EBUSY;
-
 		ctx->image_fmt = image_fmt;
 		rkvdec_reset_decoded_fmt(ctx);
 	}
Re: [PATCH 00/12] media: rkvdec: Add support for VDPU381 and VDPU383
Posted by Nicolas Dufresne 2 months, 1 week ago
Le vendredi 18 juillet 2025 à 17:37 +0800, Jianfeng Liu a écrit :
> Hi,
> 
> On Mon, 14 Jul 2025 22:46:10 +0800, Jianfeng Liu wrote:
> > You are right, the code of chromium should be fixed for frame size type
> > V4L2_FRMSIZE_TYPE_CONTINUOUS.
> 
> I have just sent a cr at chromium[1] to fix this.
> 
> > I have checked that this issue is not introduced by your series. After
> > reverting this commit[2] which adds Support High 10 and 4:2:2 profiles,
> > chromium can play video well on rk3399. I will investigate further.
> 
> I found that this issue is caused by this code block[2]. Before adding
> .get_image_fmt, rkvdec_s_ctrl will just return 0. But now when detecting
> image format change(usually from RKVDEC_IMG_FMT_ANY to real video format
> like RKVDEC_IMG_FMT_420_8BIT), it will return -EBUSY, then I get green
> frame at chromium.
> 
> After taking a look at hantro's code, I find that it is not necessary to
> let .s_ctrl return -EBUSY when format changes, here is a commit[3]
> disabling this check in hantro_set_fmt_cap. I have written a patch that
> can fix my issue with chromium, you can see it at the bottom of my mail.
> 
> [1] https://chromium-review.googlesource.com/c/chromium/src/+/6767118
> [2]
> https://github.com/torvalds/linux/blob/v6.16-rc6/drivers/staging/media/rkvdec/rkvdec.c#L143-L146
> [3]
> https://github.com/torvalds/linux/commit/bbd267daf4fc831f58bf4a2530a8b64881779e6a
> 
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> index 5d86fb7cdd6..7800d159fad 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> @@ -185,7 +185,6 @@ static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)
>  	struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct
> rkvdec_ctx, ctrl_hdl);
>  	const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc;
>  	enum rkvdec_image_fmt image_fmt;
> -	struct vb2_queue *vq;
>  
>  	/* Check if this change requires a capture format reset */
>  	if (!desc->ops->get_image_fmt)
> @@ -193,11 +192,6 @@ static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)
>  
>  	image_fmt = desc->ops->get_image_fmt(ctx, ctrl);
>  	if (rkvdec_image_fmt_changed(ctx, image_fmt)) {
> -		vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
> -				     V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> -		if (vb2_is_busy(vq))
> -			return -EBUSY;
> -

Hantro driver have extra code to protect against the fact that the queue format
may not match the currently allocated buffer size. This change alone seems
unsafe and may allow tricking the driver into buffer overflow. It believe some
further thought and care need to be put into this.

Nicolas

>  		ctx->image_fmt = image_fmt;
>  		rkvdec_reset_decoded_fmt(ctx);
>  	}