* [PATCH v7 0/3] media: verisilicon: Create AV1 helper library
@ 2026-11-20 14:31 Benjamin Gaignard
2026-11-20 14:31 ` [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index Benjamin Gaignard
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Benjamin Gaignard @ 2026-11-20 14:31 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab, heiko, hverkuil
Cc: linux-kernel, linux-media, linux-rockchip, linux-arm-kernel,
Benjamin Gaignard
Regroup all none hardware related AV1 functions into a helper library.
The goal is to avoid code duplication for future AV1 codecs.
Tested on rock 5b board Fluster score remains the same 204/241.
change in v7:
- prepend 2 patches with Fixes tag for backport
- rebase the series on v7.4-rc3 tag
change in v6:
- include b84f6533a8ed ("media: verisilicon: rockchip: guard VPU981 AV1 divisor and tile buffer")
and 367db8b23c26 ("media: verisilicon: rockchip: reject AV1 frames exceeding the tile capacity")
fixes into the patch to not losing these improvements.
Benjamin Gaignard (3):
media: verisilicon: AV1: Check reference frame index
media: verisilicon: AV1: Fix luma size
media: verisilicon: Create AV1 helper library
drivers/media/platform/verisilicon/Makefile | 7 +-
.../media/platform/verisilicon/hantro_av1.c | 816 +++++++++++++
.../media/platform/verisilicon/hantro_av1.h | 64 +
...entropymode.c => hantro_av1_entropymode.c} | 18 +-
...entropymode.h => hantro_av1_entropymode.h} | 18 +-
...av1_filmgrain.c => hantro_av1_filmgrain.c} | 125 +-
.../verisilicon/hantro_av1_filmgrain.h | 48 +
.../media/platform/verisilicon/hantro_hw.h | 7 +-
.../verisilicon/rockchip_av1_filmgrain.h | 36 -
.../verisilicon/rockchip_vpu981_hw_av1_dec.c | 1082 ++---------------
.../platform/verisilicon/rockchip_vpu_hw.c | 7 +-
11 files changed, 1140 insertions(+), 1088 deletions(-)
create mode 100644 drivers/media/platform/verisilicon/hantro_av1.c
create mode 100644 drivers/media/platform/verisilicon/hantro_av1.h
rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.c => hantro_av1_entropymode.c} (99%)
rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.h => hantro_av1_entropymode.h} (95%)
rename drivers/media/platform/verisilicon/{rockchip_av1_filmgrain.c => hantro_av1_filmgrain.c} (85%)
create mode 100644 drivers/media/platform/verisilicon/hantro_av1_filmgrain.h
delete mode 100644 drivers/media/platform/verisilicon/rockchip_av1_filmgrain.h
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index 2026-11-20 14:31 [PATCH v7 0/3] media: verisilicon: Create AV1 helper library Benjamin Gaignard @ 2026-11-20 14:31 ` Benjamin Gaignard 2026-11-24 3:29 ` Nicolas Dufresne 2026-11-20 14:31 ` [PATCH v7 2/3] media: verisilicon: AV1: Fix luma size Benjamin Gaignard [not found] ` <20261120143135.71134-4-benjamin.gaignard@collabora.com> 2 siblings, 1 reply; 6+ messages in thread From: Benjamin Gaignard @ 2026-11-20 14:31 UTC (permalink / raw) To: nicolas.dufresne, p.zabel, mchehab, heiko, hverkuil Cc: linux-kernel, linux-media, linux-rockchip, linux-arm-kernel, Benjamin Gaignard Make sure that reference frame index is valid before using it. Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder") --- .../platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c index 2a145433e6d1..5da59104a966 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c @@ -121,7 +121,12 @@ static int rockchip_vpu981_get_frame_index(struct hantro_ctx *ctx, int ref) struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls; const struct v4l2_ctrl_av1_frame *frame = ctrls->frame; u64 timestamp; - int i, idx = frame->ref_frame_idx[ref]; + int i, idx; + + if (ref < 0 || ref >= V4L2_AV1_REFS_PER_FRAME) + return AV1_INVALID_IDX; + + idx = frame->ref_frame_idx[ref]; if (idx >= V4L2_AV1_TOTAL_REFS_PER_FRAME || idx < 0) return AV1_INVALID_IDX; @@ -1262,6 +1267,10 @@ static void rockchip_vpu981_av1_dec_set_prob(struct hantro_ctx *ctx) rockchip_av1_default_coeff_probs(quantization->base_q_idx, av1_dec->cdfs); } else { + if (frame->primary_ref_frame < 0 || + frame->primary_ref_frame >= V4L2_AV1_REFS_PER_FRAME) + return; + rockchip_av1_get_cdfs(ctx, frame->ref_frame_idx[frame->primary_ref_frame]); } rockchip_av1_store_cdfs(ctx, frame->refresh_frame_flags); -- 2.53.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index 2026-11-20 14:31 ` [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index Benjamin Gaignard @ 2026-11-24 3:29 ` Nicolas Dufresne 0 siblings, 0 replies; 6+ messages in thread From: Nicolas Dufresne @ 2026-11-24 3:29 UTC (permalink / raw) To: Benjamin Gaignard, p.zabel, mchehab, heiko, hverkuil Cc: linux-kernel, linux-media, linux-rockchip, linux-arm-kernel [-- Attachment #1: Type: text/plain, Size: 2176 bytes --] Le vendredi 20 novembre 2026 à 15:31 +0100, Benjamin Gaignard a écrit : > Make sure that reference frame index is valid before using it. > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder") > --- > .../platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c > index 2a145433e6d1..5da59104a966 100644 > --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c > +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c > @@ -121,7 +121,12 @@ static int rockchip_vpu981_get_frame_index(struct hantro_ctx *ctx, int ref) > struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls; > const struct v4l2_ctrl_av1_frame *frame = ctrls->frame; > u64 timestamp; > - int i, idx = frame->ref_frame_idx[ref]; > + int i, idx; > + > + if (ref < 0 || ref >= V4L2_AV1_REFS_PER_FRAME) > + return AV1_INVALID_IDX; > + > + idx = frame->ref_frame_idx[ref]; > > if (idx >= V4L2_AV1_TOTAL_REFS_PER_FRAME || idx < 0) > return AV1_INVALID_IDX; > @@ -1262,6 +1267,10 @@ static void rockchip_vpu981_av1_dec_set_prob(struct hantro_ctx *ctx) > rockchip_av1_default_coeff_probs(quantization->base_q_idx, > av1_dec->cdfs); > } else { > + if (frame->primary_ref_frame < 0 || > + frame->primary_ref_frame >= V4L2_AV1_REFS_PER_FRAME) > + return; Just returning does not abort dec_run() and will lead to triggering the HW with partially initialized data. Either this should lead to some default cdf to be picked, or we add a return value and check it in dec_run(). May I propose to validate these once once in prepare_run()? > + > rockchip_av1_get_cdfs(ctx, frame->ref_frame_idx[frame->primary_ref_frame]); Here, the index passed to get_cdfs() is not validated and will lead to out of band indexing inside that function.. > } > rockchip_av1_store_cdfs(ctx, frame->refresh_frame_flags); [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v7 2/3] media: verisilicon: AV1: Fix luma size 2026-11-20 14:31 [PATCH v7 0/3] media: verisilicon: Create AV1 helper library Benjamin Gaignard 2026-11-20 14:31 ` [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index Benjamin Gaignard @ 2026-11-20 14:31 ` Benjamin Gaignard 2026-11-24 3:30 ` Nicolas Dufresne [not found] ` <20261120143135.71134-4-benjamin.gaignard@collabora.com> 2 siblings, 1 reply; 6+ messages in thread From: Benjamin Gaignard @ 2026-11-20 14:31 UTC (permalink / raw) To: nicolas.dufresne, p.zabel, mchehab, heiko, hverkuil Cc: linux-kernel, linux-media, linux-rockchip, linux-arm-kernel, Benjamin Gaignard Use the values computed by v4l2 helpers to get luma size. Unlile before this will also take care of padding. Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder") --- drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c index 5da59104a966..5e0cd5268f22 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c @@ -221,7 +221,7 @@ static void rockchip_vpu981_av1_dec_clean_refs(struct hantro_ctx *ctx) static size_t rockchip_vpu981_av1_dec_luma_size(struct hantro_ctx *ctx) { - return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8; + return ctx->ref_fmt.plane_fmt[0].bytesperline * ctx->ref_fmt.height; } static size_t rockchip_vpu981_av1_dec_chroma_size(struct hantro_ctx *ctx) -- 2.53.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v7 2/3] media: verisilicon: AV1: Fix luma size 2026-11-20 14:31 ` [PATCH v7 2/3] media: verisilicon: AV1: Fix luma size Benjamin Gaignard @ 2026-11-24 3:30 ` Nicolas Dufresne 0 siblings, 0 replies; 6+ messages in thread From: Nicolas Dufresne @ 2026-11-24 3:30 UTC (permalink / raw) To: Benjamin Gaignard, p.zabel, mchehab, heiko, hverkuil Cc: linux-kernel, linux-media, linux-rockchip, linux-arm-kernel [-- Attachment #1: Type: text/plain, Size: 1296 bytes --] Le vendredi 20 novembre 2026 à 15:31 +0100, Benjamin Gaignard a écrit : > Use the values computed by v4l2 helpers to get luma size. > Unlile before this will also take care of padding. > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder") Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c > index 5da59104a966..5e0cd5268f22 100644 > --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c > +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c > @@ -221,7 +221,7 @@ static void rockchip_vpu981_av1_dec_clean_refs(struct hantro_ctx *ctx) > > static size_t rockchip_vpu981_av1_dec_luma_size(struct hantro_ctx *ctx) > { > - return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8; > + return ctx->ref_fmt.plane_fmt[0].bytesperline * ctx->ref_fmt.height; > } > > static size_t rockchip_vpu981_av1_dec_chroma_size(struct hantro_ctx *ctx) [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20261120143135.71134-4-benjamin.gaignard@collabora.com>]
* Re: [PATCH v7 3/3] media: verisilicon: Create AV1 helper library [not found] ` <20261120143135.71134-4-benjamin.gaignard@collabora.com> @ 2026-11-24 3:47 ` Nicolas Dufresne 0 siblings, 0 replies; 6+ messages in thread From: Nicolas Dufresne @ 2026-11-24 3:47 UTC (permalink / raw) To: Benjamin Gaignard, p.zabel, mchehab, heiko, hverkuil Cc: linux-kernel, linux-media, linux-rockchip, linux-arm-kernel [-- Attachment #1: Type: text/plain, Size: 3453 bytes --] Le vendredi 20 novembre 2026 à 15:31 +0100, Benjamin Gaignard a écrit : > Regroup all none hardware related AV1 functions into a helper library. > The goal is to avoid code duplication for future AV1 codecs. > > Tested on rock 5b board Fluster score remains the same 204/241. > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > change in v7: > - rebase the series on v7.4-rc3 tag > > change in v6: > - include b84f6533a8ed ("media: verisilicon: rockchip: guard VPU981 AV1 divisor and tile buffer") > and 367db8b23c26 ("media: verisilicon: rockchip: reject AV1 frames exceeding the tile capacity") > fixes into the patch to not losing these improvements. > > drivers/media/platform/verisilicon/Makefile | 7 +- > .../media/platform/verisilicon/hantro_av1.c | 816 ++++++++++++ > .../media/platform/verisilicon/hantro_av1.h | 64 + > ...entropymode.c => hantro_av1_entropymode.c} | 18 +- > ...entropymode.h => hantro_av1_entropymode.h} | 18 +- > ...av1_filmgrain.c => hantro_av1_filmgrain.c} | 125 +- > .../verisilicon/hantro_av1_filmgrain.h | 48 + > .../media/platform/verisilicon/hantro_hw.h | 7 +- > .../verisilicon/rockchip_av1_filmgrain.h | 36 - > .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 1091 ++--------------- > .../platform/verisilicon/rockchip_vpu_hw.c | 7 +- > 11 files changed, 1140 insertions(+), 1097 deletions(-) > create mode 100644 drivers/media/platform/verisilicon/hantro_av1.c > create mode 100644 drivers/media/platform/verisilicon/hantro_av1.h > rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.c => hantro_av1_entropymode.c} (99%) > rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.h => hantro_av1_entropymode.h} (95%) > rename drivers/media/platform/verisilicon/{rockchip_av1_filmgrain.c => hantro_av1_filmgrain.c} (85%) > create mode 100644 drivers/media/platform/verisilicon/hantro_av1_filmgrain.h > delete mode 100644 drivers/media/platform/verisilicon/rockchip_av1_filmgrain.h > > diff --git a/drivers/media/platform/verisilicon/Makefile b/drivers/media/platform/verisilicon/Makefile > index f6f019d04ff0..a1dd6c2d29be 100644 > --- a/drivers/media/platform/verisilicon/Makefile > +++ b/drivers/media/platform/verisilicon/Makefile > @@ -19,7 +19,10 @@ hantro-vpu-y += \ > hantro_hevc.o \ > hantro_mpeg2.o \ > hantro_vp8.o \ > - hantro_vp9.o > + hantro_vp9.o \ > + hantro_av1.o \ > + hantro_av1_filmgrain.o \ > + hantro_av1_entropymode.o > > hantro-vpu-$(CONFIG_VIDEO_HANTRO_IMX8M) += \ > imx8m_vpu_hw.o > @@ -33,8 +36,6 @@ hantro-vpu-$(CONFIG_VIDEO_HANTRO_ROCKCHIP) += \ > rockchip_vpu2_hw_mpeg2_dec.o \ > rockchip_vpu2_hw_vp8_dec.o \ > rockchip_vpu981_hw_av1_dec.o \ > - rockchip_av1_filmgrain.o \ > - rockchip_av1_entropymode.o \ > rockchip_vpu_hw.o > > hantro-vpu-$(CONFIG_VIDEO_HANTRO_SUNXI) += \ > diff --git a/drivers/media/platform/verisilicon/hantro_av1.c b/drivers/media/platform/verisilicon/hantro_av1.c > new file mode 100644 > index 000000000000..2cde32f0e935 > --- /dev/null > +++ b/drivers/media/platform/verisilicon/hantro_av1.c > @@ -0,0 +1,816 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2026, Collabora To be accurate: + * Copyright (c) 2023-2026, Collabora [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-24 4:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 14:31 [PATCH v7 0/3] media: verisilicon: Create AV1 helper library Benjamin Gaignard
2026-11-20 14:31 ` [PATCH v7 1/3] media: verisilicon: AV1: Check reference frame index Benjamin Gaignard
2026-11-24 3:29 ` Nicolas Dufresne
2026-11-20 14:31 ` [PATCH v7 2/3] media: verisilicon: AV1: Fix luma size Benjamin Gaignard
2026-11-24 3:30 ` Nicolas Dufresne
[not found] ` <20261120143135.71134-4-benjamin.gaignard@collabora.com>
2026-11-24 3:47 ` [PATCH v7 3/3] media: verisilicon: Create AV1 helper library Nicolas Dufresne
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox