public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Diederik de Haas" <didi.debian@cknow.org>
To: "Detlev Casanova" <detlev.casanova@collabora.com>,
	<linux-kernel@vger.kernel.org>
Cc: "Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Heiko Stuebner" <heiko@sntech.de>, <linux-media@vger.kernel.org>,
	<linux-rockchip@lists.infradead.org>,
	<linux-arm-kernel@lists.infradead.org>, <kernel@collabora.com>
Subject: Re: [PATCH v2 09/12] media: rkvdec: Add H264 support for the VDPU381 variant
Date: Sat, 20 Sep 2025 17:00:07 +0200	[thread overview]
Message-ID: <DCXPTZRNNTDY.1773L2181HWF@cknow.org> (raw)
In-Reply-To: <20250808200340.156393-10-detlev.casanova@collabora.com>

[-- Attachment #1: Type: text/plain, Size: 7068 bytes --]

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.

On Fri Aug 8, 2025 at 10:03 PM CEST, Detlev Casanova wrote:
> 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.
>
> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
> ---
>  .../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
>
> ...
>
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
> new file mode 100644
> index 0000000000000..11b545e9ee7ea
> --- /dev/null
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
> @@ -0,0 +1,427 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Rockchip VDPU381 Video Decoder driver registers description
> + *
> + * Copyright (C) 2024 Collabora, Ltd.
> + *  Detlev Casanova <detlev.casanova@collabora.com>
> + */
> +
> +#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))
> +
> +#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).

> +#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 */
>
> ...
>
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> index 0ccf1ba81958a..1b55fe4ff2baf 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> @@ -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[] = {
> +	{
> +		.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)

> +		.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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  parent reply	other threads:[~2025-09-20 15:00 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 20:03 [PATCH v2 00/12] media: rkvdec: Add support for VDPU381 and VDPU383 Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 01/12] media: rkvdec: Switch to using structs instead of writel Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 02/12] media: rkvdec: Move cabac table to its own source file Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 03/12] media: rkvdec: Use structs to represent the HW RPS Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 04/12] media: rkvdec: Move h264 functions to common file Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 05/12] media: rkvdec: Add per variant configuration Detlev Casanova
2025-08-11  6:13   ` Krzysztof Kozlowski
2025-08-11 13:52     ` Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 06/12] media: rkvdec: Add RCB and SRAM support Detlev Casanova
2025-08-11  6:13   ` Krzysztof Kozlowski
2025-08-11 13:54     ` Detlev Casanova
2025-08-11 14:01       ` Krzysztof Kozlowski
2025-08-11 18:44         ` Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 07/12] media: rkvdec: Support per-variant interrupt handler Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 08/12] media: rkvdec: Enable all clocks without naming them Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 09/12] media: rkvdec: Add H264 support for the VDPU381 variant Detlev Casanova
2025-08-12 17:07   ` Dmitry Osipenko
2025-09-20 15:00   ` Diederik de Haas [this message]
2025-09-20 16:15     ` Jonas Karlman
2025-09-20 18:06       ` Diederik de Haas
2025-08-08 20:03 ` [PATCH v2 10/12] media: rkvdec: Add H264 support for the VDPU383 variant Detlev Casanova
2025-08-09 11:53   ` kernel test robot
2025-08-11 18:28   ` Nicolas Dufresne
2025-08-08 20:03 ` [PATCH v2 11/12] media: rkvdec: Add HEVC support for the VDPU381 variant Detlev Casanova
2025-08-09 13:17   ` kernel test robot
2025-09-20 15:07   ` Diederik de Haas
2025-09-20 16:23     ` Jonas Karlman
2025-09-22 14:19       ` Nicolas Dufresne
2025-09-29 12:47     ` Detlev Casanova
2025-08-08 20:03 ` [PATCH v2 12/12] media: rkvdec: Add HEVC support for the VDPU383 variant Detlev Casanova
2025-08-11  9:56 ` [PATCH v2 00/12] media: rkvdec: Add support for VDPU381 and VDPU383 Heiko Stübner
2025-08-11 16:33   ` Detlev Casanova
2025-08-12  7:20 ` Piotr Oniszczuk
2025-09-17 17:34 ` Diederik de Haas
2025-09-18 13:31   ` Nicolas Dufresne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DCXPTZRNNTDY.1773L2181HWF@cknow.org \
    --to=didi.debian@cknow.org \
    --cc=detlev.casanova@collabora.com \
    --cc=heiko@sntech.de \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox