Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] media: verisilicon: Get ride of hantro_av1_decoded_buffer_info structure
       [not found] <20261201165442.235578-1-benjamin.gaignard@collabora.com>
@ 2026-12-01 16:54 ` Benjamin Gaignard
  2026-12-01 16:54 ` [PATCH v1 2/2] media: verisilicon: Get ride of hantro_vp9_decoded_buffer_info structure Benjamin Gaignard
  1 sibling, 0 replies; 2+ messages in thread
From: Benjamin Gaignard @ 2026-12-01 16:54 UTC (permalink / raw)
  To: nicolas.dufresne, p.zabel, mchehab, heiko
  Cc: linux-media, linux-rockchip, linux-kernel, linux-arm-kernel,
	kernel, Benjamin Gaignard

Remove hantro_av1_decoded_buffer_info structure to simplify driver code.
Only compute one luma, chroma and motion vectors addresses to avoid code
duplication.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
 drivers/media/platform/verisilicon/hantro.h   | 11 ++----
 .../verisilicon/rockchip_vpu981_hw_av1_dec.c  | 34 ++++++-------------
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index 1efa032506e1..bf99187ba7c6 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -332,19 +332,14 @@ struct hantro_vp9_decoded_buffer_info {
 	u32 bit_depth : 4;
 };
 
-struct hantro_av1_decoded_buffer_info {
-	/* Info needed when the decoded frame serves as a reference frame. */
-	size_t chroma_offset;
-	size_t mv_offset;
-};
-
 struct hantro_decoded_buffer {
 	/* Must be the first field in this struct. */
 	struct v4l2_m2m_buffer base;
-
+	dma_addr_t luma_addr;
+	dma_addr_t chroma_addr;
+	dma_addr_t mv_addr;
 	union {
 		struct hantro_vp9_decoded_buffer_info vp9;
-		struct hantro_av1_decoded_buffer_info av1;
 	};
 };
 
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 f143df99cdb5..aea67c881ccf 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
@@ -74,7 +74,6 @@ rockchip_vpu981_av1_dec_set_ref(struct hantro_ctx *ctx, int ref, int idx,
 	const struct v4l2_ctrl_av1_frame *frame = ctrls->frame;
 	struct hantro_dev *vpu = ctx->dev;
 	struct hantro_decoded_buffer *dst;
-	dma_addr_t luma_addr, chroma_addr, mv_addr = 0;
 	int cur_width = frame->frame_width_minus_1 + 1;
 	int cur_height = frame->frame_height_minus_1 + 1;
 	int scale_width =
@@ -130,13 +129,9 @@ rockchip_vpu981_av1_dec_set_ref(struct hantro_ctx *ctx, int ref, int idx,
 	}
 
 	dst = vb2_to_hantro_decoded_buf(&av1_dec->frame_refs[idx].vb2_ref->vb2_buf);
-	luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
-	chroma_addr = luma_addr + dst->av1.chroma_offset;
-	mv_addr = luma_addr + dst->av1.mv_offset;
-
-	hantro_write_addr(vpu, AV1_REFERENCE_Y(ref), luma_addr);
-	hantro_write_addr(vpu, AV1_REFERENCE_CB(ref), chroma_addr);
-	hantro_write_addr(vpu, AV1_REFERENCE_MV(ref), mv_addr);
+	hantro_write_addr(vpu, AV1_REFERENCE_Y(ref), dst->luma_addr);
+	hantro_write_addr(vpu, AV1_REFERENCE_CB(ref), dst->chroma_addr);
+	hantro_write_addr(vpu, AV1_REFERENCE_MV(ref), dst->mv_addr);
 
 	return (scale_width != (1 << AV1_REF_SCALE_SHIFT)) ||
 		(scale_height != (1 << AV1_REF_SCALE_SHIFT));
@@ -190,15 +185,10 @@ static void rockchip_vpu981_av1_dec_set_segmentation(struct hantro_ctx *ctx)
 		int idx = hantro_av1_get_frame_index(ctx, frame->primary_ref_frame);
 
 		if (idx != AV1_INVALID_IDX) {
-			dma_addr_t luma_addr, mv_addr = 0;
 			struct hantro_decoded_buffer *seg;
-			size_t mv_offset = hantro_av1_chroma_size(ctx);
 
 			seg = vb2_to_hantro_decoded_buf(&av1_dec->frame_refs[idx].vb2_ref->vb2_buf);
-			luma_addr = hantro_get_dec_buf_addr(ctx, &seg->base.vb.vb2_buf);
-			mv_addr = luma_addr + mv_offset;
-
-			hantro_write_addr(vpu, AV1_SEGMENTATION, mv_addr);
+			hantro_write_addr(vpu, AV1_SEGMENTATION, seg->mv_addr);
 			hantro_reg_write(vpu, &av1_use_temporal3_mvs, 1);
 		}
 	}
@@ -1355,22 +1345,18 @@ rockchip_vpu981_av1_dec_set_output_buffer(struct hantro_ctx *ctx)
 	struct hantro_dev *vpu = ctx->dev;
 	struct hantro_decoded_buffer *dst;
 	struct vb2_v4l2_buffer *vb2_dst;
-	dma_addr_t luma_addr, chroma_addr, mv_addr = 0;
 	size_t cr_offset = hantro_av1_luma_size(ctx);
 	size_t mv_offset = hantro_av1_chroma_size(ctx);
 
 	vb2_dst = av1_dec->frame_refs[av1_dec->current_frame_index].vb2_ref;
 	dst = vb2_to_hantro_decoded_buf(&vb2_dst->vb2_buf);
-	luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
-	chroma_addr = luma_addr + cr_offset;
-	mv_addr = luma_addr + mv_offset;
-
-	dst->av1.chroma_offset = cr_offset;
-	dst->av1.mv_offset = mv_offset;
+	dst->luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
+	dst->chroma_addr = dst->luma_addr + cr_offset;
+	dst->mv_addr = dst->luma_addr + mv_offset;
 
-	hantro_write_addr(vpu, AV1_TILE_OUT_LU, luma_addr);
-	hantro_write_addr(vpu, AV1_TILE_OUT_CH, chroma_addr);
-	hantro_write_addr(vpu, AV1_TILE_OUT_MV, mv_addr);
+	hantro_write_addr(vpu, AV1_TILE_OUT_LU, dst->luma_addr);
+	hantro_write_addr(vpu, AV1_TILE_OUT_CH, dst->chroma_addr);
+	hantro_write_addr(vpu, AV1_TILE_OUT_MV, dst->mv_addr);
 }
 
 int rockchip_vpu981_av1_dec_run(struct hantro_ctx *ctx)
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v1 2/2] media: verisilicon: Get ride of hantro_vp9_decoded_buffer_info structure
       [not found] <20261201165442.235578-1-benjamin.gaignard@collabora.com>
  2026-12-01 16:54 ` [PATCH v1 1/2] media: verisilicon: Get ride of hantro_av1_decoded_buffer_info structure Benjamin Gaignard
@ 2026-12-01 16:54 ` Benjamin Gaignard
  1 sibling, 0 replies; 2+ messages in thread
From: Benjamin Gaignard @ 2026-12-01 16:54 UTC (permalink / raw)
  To: nicolas.dufresne, p.zabel, mchehab, heiko
  Cc: linux-media, linux-rockchip, linux-kernel, linux-arm-kernel,
	kernel, Benjamin Gaignard

Remove hantro_vp9_decoded_buffer_info structure to simplify driver code.
Only compute once luma, chroma and motion vectors buffer addresses.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
 drivers/media/platform/verisilicon/hantro.h   | 15 +----
 .../platform/verisilicon/hantro_g2_vp9_dec.c  | 63 ++++++++-----------
 2 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index bf99187ba7c6..08c85053cebe 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -323,24 +323,15 @@ struct hantro_postproc_regs {
 	struct hantro_reg input_height_ext;
 };
 
-struct hantro_vp9_decoded_buffer_info {
-	/* Info needed when the decoded frame serves as a reference frame. */
-	unsigned short width;
-	unsigned short height;
-	size_t chroma_offset;
-	size_t mv_offset;
-	u32 bit_depth : 4;
-};
-
 struct hantro_decoded_buffer {
 	/* Must be the first field in this struct. */
 	struct v4l2_m2m_buffer base;
+	unsigned short width;
+	unsigned short height;
 	dma_addr_t luma_addr;
 	dma_addr_t chroma_addr;
 	dma_addr_t mv_addr;
-	union {
-		struct hantro_vp9_decoded_buffer_info vp9;
-	};
+	int bit_depth;
 };
 
 /* Logging helpers */
diff --git a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c
index 78100d1c7e85..8de51e94997b 100644
--- a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c
+++ b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c
@@ -109,9 +109,9 @@ get_ref_buf(struct hantro_ctx *ctx, struct vb2_v4l2_buffer *dst, u64 timestamp)
 static void update_dec_buf_info(struct hantro_decoded_buffer *buf,
 				const struct v4l2_ctrl_vp9_frame *dec_params)
 {
-	buf->vp9.width = dec_params->frame_width_minus_1 + 1;
-	buf->vp9.height = dec_params->frame_height_minus_1 + 1;
-	buf->vp9.bit_depth = dec_params->bit_depth;
+	buf->width = dec_params->frame_width_minus_1 + 1;
+	buf->height = dec_params->frame_height_minus_1 + 1;
+	buf->bit_depth = dec_params->bit_depth;
 }
 
 static void update_ctx_cur_info(struct hantro_vp9_dec_hw_ctx *vp9_ctx,
@@ -129,22 +129,18 @@ static void config_output(struct hantro_ctx *ctx,
 			  struct hantro_decoded_buffer *dst,
 			  const struct v4l2_ctrl_vp9_frame *dec_params)
 {
-	dma_addr_t luma_addr, chroma_addr, mv_addr;
-
 	hantro_reg_write(ctx->dev, &g2_out_dis, 0);
 	if (!ctx->dev->variant->legacy_regs)
 		hantro_reg_write(ctx->dev, &g2_output_format, 0);
 
-	luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
-	hantro_write_addr(ctx->dev, G2_OUT_LUMA_ADDR, luma_addr);
+	dst->luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
+	hantro_write_addr(ctx->dev, G2_OUT_LUMA_ADDR, dst->luma_addr);
 
-	chroma_addr = luma_addr + hantro_g2_chroma_offset(ctx);
-	hantro_write_addr(ctx->dev, G2_OUT_CHROMA_ADDR, chroma_addr);
-	dst->vp9.chroma_offset = hantro_g2_chroma_offset(ctx);
+	dst->chroma_addr = dst->luma_addr + hantro_g2_chroma_offset(ctx);
+	hantro_write_addr(ctx->dev, G2_OUT_CHROMA_ADDR, dst->chroma_addr);
 
-	mv_addr = luma_addr + hantro_g2_motion_vectors_offset(ctx);
-	hantro_write_addr(ctx->dev, G2_OUT_MV_ADDR, mv_addr);
-	dst->vp9.mv_offset = hantro_g2_motion_vectors_offset(ctx);
+	dst->mv_addr = dst->luma_addr + hantro_g2_motion_vectors_offset(ctx);
+	hantro_write_addr(ctx->dev, G2_OUT_MV_ADDR, dst->mv_addr);
 }
 
 struct hantro_vp9_ref_reg {
@@ -163,24 +159,20 @@ static void config_ref(struct hantro_ctx *ctx,
 		       u64 ref_ts)
 {
 	struct hantro_decoded_buffer *buf;
-	dma_addr_t luma_addr, chroma_addr;
 	u32 refw, refh;
 
 	buf = get_ref_buf(ctx, &dst->base.vb, ref_ts);
-	refw = buf->vp9.width;
-	refh = buf->vp9.height;
+	refw = buf->width;
+	refh = buf->height;
 
 	hantro_reg_write(ctx->dev, &ref_reg->width, refw);
 	hantro_reg_write(ctx->dev, &ref_reg->height, refh);
 
-	hantro_reg_write(ctx->dev, &ref_reg->hor_scale, (refw << 14) / dst->vp9.width);
-	hantro_reg_write(ctx->dev, &ref_reg->ver_scale, (refh << 14) / dst->vp9.height);
-
-	luma_addr = hantro_get_dec_buf_addr(ctx, &buf->base.vb.vb2_buf);
-	hantro_write_addr(ctx->dev, ref_reg->y_base, luma_addr);
+	hantro_reg_write(ctx->dev, &ref_reg->hor_scale, (refw << 14) / dst->width);
+	hantro_reg_write(ctx->dev, &ref_reg->ver_scale, (refh << 14) / dst->height);
 
-	chroma_addr = luma_addr + buf->vp9.chroma_offset;
-	hantro_write_addr(ctx->dev, ref_reg->c_base, chroma_addr);
+	hantro_write_addr(ctx->dev, ref_reg->y_base, buf->luma_addr);
+	hantro_write_addr(ctx->dev, ref_reg->c_base, buf->chroma_addr);
 }
 
 static void config_ref_registers(struct hantro_ctx *ctx,
@@ -215,15 +207,12 @@ static void config_ref_registers(struct hantro_ctx *ctx,
 			.c_base = G2_REF_CHROMA_ADDR(5),
 		},
 	};
-	dma_addr_t mv_addr;
 
 	config_ref(ctx, dst, &ref_regs[0], dec_params, dec_params->last_frame_ts);
 	config_ref(ctx, dst, &ref_regs[1], dec_params, dec_params->golden_frame_ts);
 	config_ref(ctx, dst, &ref_regs[2], dec_params, dec_params->alt_frame_ts);
 
-	mv_addr = hantro_get_dec_buf_addr(ctx, &mv_ref->base.vb.vb2_buf) +
-		  mv_ref->vp9.mv_offset;
-	hantro_write_addr(ctx->dev, G2_REF_MV_ADDR(0), mv_addr);
+	hantro_write_addr(ctx->dev, G2_REF_MV_ADDR(0), mv_ref->mv_addr);
 
 	hantro_reg_write(ctx->dev, &vp9_last_sign_bias,
 			 dec_params->ref_frame_sign_bias & V4L2_VP9_SIGN_BIAS_LAST ? 1 : 0);
@@ -321,8 +310,8 @@ config_tiles(struct hantro_ctx *ctx,
 	if (dec_params->tile_cols_log2 || dec_params->tile_rows_log2) {
 		unsigned int tile_r = (1 << dec_params->tile_rows_log2);
 		unsigned int tile_c = (1 << dec_params->tile_cols_log2);
-		unsigned int sbs_r = hantro_vp9_num_sbs(dst->vp9.height);
-		unsigned int sbs_c = hantro_vp9_num_sbs(dst->vp9.width);
+		unsigned int sbs_r = hantro_vp9_num_sbs(dst->height);
+		unsigned int sbs_c = hantro_vp9_num_sbs(dst->width);
 
 		if (tile_r != vp9_ctx->last_tile_r || tile_c != vp9_ctx->last_tile_c ||
 		    sbs_r != vp9_ctx->last_sbs_r || sbs_c != vp9_ctx->last_sbs_c)
@@ -334,8 +323,8 @@ config_tiles(struct hantro_ctx *ctx,
 		rows = tile_r;
 		hantro_reg_write(ctx->dev, &g2_tile_e, 1);
 	} else {
-		tile_mem[0] = hantro_vp9_num_sbs(dst->vp9.width);
-		tile_mem[1] = hantro_vp9_num_sbs(dst->vp9.height);
+		tile_mem[0] = hantro_vp9_num_sbs(dst->width);
+		tile_mem[1] = hantro_vp9_num_sbs(dst->height);
 
 		cols = 1;
 		rows = 1;
@@ -487,10 +476,10 @@ static void config_picture_dimensions(struct hantro_ctx *ctx, struct hantro_deco
 {
 	u32 pic_w_4x4, pic_h_4x4;
 
-	hantro_reg_write(ctx->dev, &g2_pic_width_in_cbs, (dst->vp9.width + 7) / 8);
-	hantro_reg_write(ctx->dev, &g2_pic_height_in_cbs, (dst->vp9.height + 7) / 8);
-	pic_w_4x4 = roundup(dst->vp9.width, 8) >> 2;
-	pic_h_4x4 = roundup(dst->vp9.height, 8) >> 2;
+	hantro_reg_write(ctx->dev, &g2_pic_width_in_cbs, (dst->width + 7) / 8);
+	hantro_reg_write(ctx->dev, &g2_pic_height_in_cbs, (dst->height + 7) / 8);
+	pic_w_4x4 = roundup(dst->width, 8) >> 2;
+	pic_h_4x4 = roundup(dst->height, 8) >> 2;
 	hantro_reg_write(ctx->dev, &g2_pic_width_4x4, pic_w_4x4);
 	hantro_reg_write(ctx->dev, &g2_pic_height_4x4, pic_h_4x4);
 }
@@ -837,8 +826,8 @@ config_registers(struct hantro_ctx *ctx, const struct v4l2_ctrl_vp9_frame *dec_p
 	else
 		mv_ref = dst;
 
-	resolution_change = dst->vp9.width != last->vp9.width ||
-			    dst->vp9.height != last->vp9.height;
+	resolution_change = dst->width != last->width ||
+			    dst->height != last->height;
 
 	/* configure basic registers */
 	hantro_reg_write(ctx->dev, &g2_mode, VP9_DEC_MODE);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261201165442.235578-1-benjamin.gaignard@collabora.com>
2026-12-01 16:54 ` [PATCH v1 1/2] media: verisilicon: Get ride of hantro_av1_decoded_buffer_info structure Benjamin Gaignard
2026-12-01 16:54 ` [PATCH v1 2/2] media: verisilicon: Get ride of hantro_vp9_decoded_buffer_info structure Benjamin Gaignard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox