public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Bee <knaerzche@gmail.com>
To: Detlev Casanova <detlev.casanova@collabora.com>,
	linux-kernel@vger.kernel.org
Cc: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Dragan Simic <dsimic@manjaro.org>,
	Diederik de Haas <didi.debian@cknow.org>,
	Andy Yan <andy.yan@rock-chips.com>,
	Boris Brezillon <boris.brezillon@collabora.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Daniel Almeida <daniel.almeida@collabora.com>,
	Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-staging@lists.linux.dev
Subject: Re: [PATCH v3 2/4] media: rockchip: Introduce the rkvdec2 driver
Date: Wed, 26 Jun 2024 11:12:13 +0200	[thread overview]
Message-ID: <5a15b138-4e03-4487-8a53-b7ff3527701f@gmail.com> (raw)
In-Reply-To: <3815203.kQq0lBPeGt@arisu>

Hi Detlev,

Am 25.06.24 um 18:56 schrieb Detlev Casanova:
> Hi Alex,
>
> On Sunday, June 23, 2024 5:33:28 A.M. EDT you wrote:
>> Hi Detlev,
>>
>> Am 20.06.24 um 16:19 schrieb Detlev Casanova:
>>> This driver supports the second generation of the Rockchip Video
>>> decoder, also known as vdpu34x.
>>> It is currently only used on the RK3588(s) SoC.
>>>
>>> There are 2 decoders on the RK3588 SoC that can work in pair to decode
>>> 8K video at 30 FPS but currently, only using one core at a time is
>>> supported.
>>>
>>> Scheduling requests between the two cores will be implemented later.
>>>
>>> The core supports H264, HEVC, VP9 and AVS2 decoding but this driver
>>> currently only supports H264.
>>>
>>> The driver is based on rkvdec and they may share some code in the
>>> future.
>>> The decision to make a different driver is mainly because rkvdec2 has
>>> more features and can work with multiple cores.
>>>
>>> The registers are mapped in a struct in RAM using bitfields. It is IO
>>> copied to the HW when all values are configured.
>>> The decision to use such a struct instead of writing buffers one by one
>>>
>>> is based on the following reasons:
>>>    - Rockchip cores are known to misbehave when registers are not written
>>>    
>>>      in address order,
>>>    
>>>    - Those cores also need the software to write all registers, even if
>>>    
>>>      they are written their default values or are not related to the task
>>>      (this core will not start decoding some H264 frames if some VP9
>>>      registers are not written to 0)
>>>    
>>>    - In the future, to support multiple cores, the scheduler could be
>>>    
>>>      optimized by storing the precomputed registers values and copy them
>>>      to the HW as soos as a core becomes available.
>>>
>>> This makes the code more readable and may bring performance improvements
>>> in future features.
>>>
>>> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
>>> ---
>>>
>>>    drivers/staging/media/Kconfig                |    1 +
>>>    drivers/staging/media/Makefile               |    1 +
>>>    drivers/staging/media/rkvdec2/Kconfig        |   15 +
>>>    drivers/staging/media/rkvdec2/Makefile       |    3 +
>>>    drivers/staging/media/rkvdec2/TODO           |    9 +
>>>    drivers/staging/media/rkvdec2/rkvdec2-h264.c |  739 +++++++++++
>>>    drivers/staging/media/rkvdec2/rkvdec2-regs.h |  345 +++++
>>>    drivers/staging/media/rkvdec2/rkvdec2.c      | 1253 ++++++++++++++++++
>>>    drivers/staging/media/rkvdec2/rkvdec2.h      |  130 ++
>>>    9 files changed, 2496 insertions(+)
>>>    create mode 100644 drivers/staging/media/rkvdec2/Kconfig
>>>    create mode 100644 drivers/staging/media/rkvdec2/Makefile
>>>    create mode 100644 drivers/staging/media/rkvdec2/TODO
>>>    create mode 100644 drivers/staging/media/rkvdec2/rkvdec2-h264.c
>>>    create mode 100644 drivers/staging/media/rkvdec2/rkvdec2-regs.h
>>>    create mode 100644 drivers/staging/media/rkvdec2/rkvdec2.c
>>>    create mode 100644 drivers/staging/media/rkvdec2/rkvdec2.h
>> ...
>>
>>> +static inline void rkvdec2_memcpy_toio(void __iomem *dst, void *src,
>>> size_t len) +{
>>> +#ifdef CONFIG_ARM64
>>> +	__iowrite32_copy(dst, src, len);
>>> +#elif defined(CONFIG_ARM)
>> I guess that can get an "#else" since memcpy_toio exists for all archs.
>>
>>> +	memcpy_toio(dst, src, len);
>>> +#endif
>>> +}
>>> +
>> ...
>>
>>> +	/* Set timeout threshold */
>>> +	if (pixels < RKVDEC2_1080P_PIXELS)
>>> +		regs->common.timeout_threshold = RKVDEC2_TIMEOUT_1080p;
>>> +	else if (pixels < RKVDEC2_4K_PIXELS)
>>> +		regs->common.timeout_threshold = RKVDEC2_TIMEOUT_4K;
>>> +	else if (pixels < RKVDEC2_8K_PIXELS)
>>> +		regs->common.timeout_threshold = RKVDEC2_TIMEOUT_8K;
>>> +
>> Did you test if it works with anything > 8K? If so, you propably want to
>> make the check above
>>
>> +	else
>> +		regs->common.timeout_threshold = RKVDEC2_TIMEOUT_8K;
>>
>> Otherwise the timeout may not be set/contain invalid values from any former
>> stream.
> That's right, but it would be set to 0 because of the memset.
> RKVDEC2_TIMEOUT_8K might not be enough for bigger frame sizes, so I'll set it
> to the maximum value (0xffffffff) when frames are bigger than 8K and also adapt
> the watchdog time: RKVDEC2_TIMEOUT_8K is around 100 ms, but 0xffffffff is arnoud
> 5.3 seconds (reg032/axi_clock_freq)
>
> I'll do more tests with this as well.
>
>> ...
>>
>>> +
>>> +static const struct rkvdec2_coded_fmt_desc rkvdec2_coded_fmts[] = {
>>> +	{
>>> +		.fourcc = V4L2_PIX_FMT_H264_SLICE,
>>> +		.frmsize = {
>>> +			.min_width = 16,
>>> +			.max_width =  65520,
>>> +			.step_width = 16,
>>> +			.min_height = 16,
>>> +			.max_height =  65520,
>>> +			.step_height = 16,
>>> +		},
>>> +		.ctrls = &rkvdec2_h264_ctrls,
>>> +		.ops = &rkvdec2_h264_fmt_ops,
>>> +		.num_decoded_fmts =
> ARRAY_SIZE(rkvdec2_h264_decoded_fmts),
>>> +		.decoded_fmts = rkvdec2_h264_decoded_fmts,
>>> +		.subsystem_flags =
> VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
>>> +	},
>>> +};
>>> +
>> Note, that this is also given to userspace (VIDIOC_ENUM_FRAMESIZES) and
>> this is already incorrect in the old rkvdec driver (and hantro): From
>> userspace perspective we do not have a restriction in
>> step_width/step_width, as we are aligning any given width/height to HW
>> requirements in the driver - what we should give to userspace is
>> fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; fsize->stepwise.min_height =
>> 1; fsize->stepwise.min_width = 1; fsize->stepwise.max_height = 65520;
>> fsize->stepwise.max_width = 65520;
> Is fsize->stepwise.min_height = 1; and fsize->stepwise.min_width = 1 correct ?
> Or do you mean fsize->stepwise.step_height = 1; and fsize->stepwise.setp_width
> = 1 ?
>
> It would give this instead:
>
> .frmsize = {
> 	.min_width = 16,
> 	.max_width =  65520,
> 	.step_width = 1,
> 	.min_height = 16,
> 	.max_height =  65520,
> 	.step_height = 1,
> },
>
> and .vidioc_enum_framesizes sets fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
You can't adapt this here, because this .frmsize is also given to the
v4l2_apply_frmsize_constraints helper, which does the actual alignment to
HW requirements and requires the HW step_with and step_height.
IIRC, we also align framesizes which are below minimum HW requirement, at
least in rkvdec1 driver and it looks a lot like this is done here the same:
so this should be .min_height = 1 and .min_width = 1. (I remember because
there are VP9 conformance tests with very small framesizes). And yes, it
looks like you've had to set .step_width and .step_height to 1 for
V4L2_FRMSIZE_TYPE_CONTINUOUS, not sure why that is required.

So, imho, the final rkvdec2_enum_framesizes should look like

+static int rkvdec2_enum_framesizes(struct file *file, void *priv,
+                   struct v4l2_frmsizeenum *fsize)
....
+    fmt = rkvdec2_find_coded_fmt_desc(fsize->pixel_format);
+    if (!fmt)
+        return -EINVAL;
+
+    fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
+    fsize->stepwise.min_height = 1;
+    fsize->stepwise.max_height = fmt->frmsize.max_height;
+    fsize->stepwise.min_width = 1;
+    fsize->stepwise.max_width = fmt->frmsize.max_width;
+    fsize->stepwise.min_width = 1;
+    fsize->stepwise.step_height = 1;
+    fsize->stepwise.step_width = 1;
+    return 0;
+}

Note: Not even build tested :)
Jonas: maybe you can add a fixup patch to your rkvdec patches as well.

Regards,

Alex

>> I guess this new driver should be an
>> opportunity to fix that and distinguish between internal and external
>> frame size requirements and the .vidioc_enum_framesizes callback should
>> adapted accordingly. Regards, Alex
> Detlev.

  reply	other threads:[~2024-06-26  9:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 14:19 [PATCH v3 0/4] media: rockchip: Add rkvdec2 driver Detlev Casanova
2024-06-20 14:19 ` [PATCH v3 1/4] media: rockchip: Move H264 CABAC table to header file Detlev Casanova
2024-06-20 14:19 ` [PATCH v3 2/4] media: rockchip: Introduce the rkvdec2 driver Detlev Casanova
2024-06-21  8:20   ` Jonas Karlman
2024-06-23  9:33   ` Alex Bee
2024-06-25 16:56     ` Detlev Casanova
2024-06-26  9:12       ` Alex Bee [this message]
2024-06-27  9:41         ` Jonas Karlman
2024-06-27 11:10           ` Alex Bee
2024-06-20 14:19 ` [PATCH v3 3/4] media: dt-bindings: rockchip: Document RK3588 Video Decoder bindings Detlev Casanova
2024-06-20 16:01   ` Conor Dooley
2024-06-20 14:19 ` [PATCH v3 4/4] arm64: dts: rockchip: Add rkvdec2 Video Decoder on rk3588(s) Detlev Casanova
2024-06-20 15:00   ` Jonas Karlman
2024-06-25 17:40     ` Detlev Casanova
2024-06-27  9:50       ` Jonas Karlman
2024-06-21  8:07   ` Jonas Karlman
2024-06-26  9:29   ` Jianfeng Liu

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=5a15b138-4e03-4487-8a53-b7ff3527701f@gmail.com \
    --to=knaerzche@gmail.com \
    --cc=andy.yan@rock-chips.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=boris.brezillon@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=detlev.casanova@collabora.com \
    --cc=devicetree@vger.kernel.org \
    --cc=didi.debian@cknow.org \
    --cc=dsimic@manjaro.org \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=gregkh@linuxfoundation.org \
    --cc=heiko@sntech.de \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jonas@kwiboo.se \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=robh@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    /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