media: verisilicon: g2: Use common helpers to compute chroma and mv offsets
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Thu, 9 Nov 2023 16:35:05 +0000 (17:35 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 23 Nov 2023 11:44:10 +0000 (12:44 +0100)
HEVC and VP9 are running on the same hardware and share the same
chroma and motion vectors offset constraint.
Create common helpers functions for these computation.
Source and destination buffer height may not be the same because
alignment constraint are different so use destination height to
compute chroma offset because we target this buffer as hardware
output.
To be able to use the helpers in both VP9 HEVC code remove dec_params
and use context->bit_depth instead.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
CC: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
CC: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/verisilicon/hantro_g2.c
drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c
drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c
drivers/media/platform/verisilicon/hantro_hw.h

index ee5f14c5f8f27359fe6dc8c226b94c94234a9c5a..b880a6849d5852aa985af7d30e14f352aa096b6c 100644 (file)
@@ -8,6 +8,8 @@
 #include "hantro_hw.h"
 #include "hantro_g2_regs.h"
 
+#define G2_ALIGN       16
+
 void hantro_g2_check_idle(struct hantro_dev *vpu)
 {
        int i;
@@ -42,3 +44,15 @@ irqreturn_t hantro_g2_irq(int irq, void *dev_id)
 
        return IRQ_HANDLED;
 }
+
+size_t hantro_g2_chroma_offset(struct hantro_ctx *ctx)
+{
+       return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8;
+}
+
+size_t hantro_g2_motion_vectors_offset(struct hantro_ctx *ctx)
+{
+       size_t cr_offset = hantro_g2_chroma_offset(ctx);
+
+       return ALIGN((cr_offset * 3) / 2, G2_ALIGN);
+}
index a9d4ac84a8d8d4886fdc34becc77b3f4514fea56..d3f8c33eb16c2b8949baa594a1d3e82c3dda9862 100644 (file)
@@ -8,20 +8,6 @@
 #include "hantro_hw.h"
 #include "hantro_g2_regs.h"
 
-#define G2_ALIGN       16
-
-static size_t hantro_hevc_chroma_offset(struct hantro_ctx *ctx)
-{
-       return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8;
-}
-
-static size_t hantro_hevc_motion_vectors_offset(struct hantro_ctx *ctx)
-{
-       size_t cr_offset = hantro_hevc_chroma_offset(ctx);
-
-       return ALIGN((cr_offset * 3) / 2, G2_ALIGN);
-}
-
 static void prepare_tile_info_buffer(struct hantro_ctx *ctx)
 {
        struct hantro_dev *vpu = ctx->dev;
@@ -384,8 +370,8 @@ static int set_ref(struct hantro_ctx *ctx)
        struct hantro_dev *vpu = ctx->dev;
        struct vb2_v4l2_buffer *vb2_dst;
        struct hantro_decoded_buffer *dst;
-       size_t cr_offset = hantro_hevc_chroma_offset(ctx);
-       size_t mv_offset = hantro_hevc_motion_vectors_offset(ctx);
+       size_t cr_offset = hantro_g2_chroma_offset(ctx);
+       size_t mv_offset = hantro_g2_motion_vectors_offset(ctx);
        u32 max_ref_frames;
        u16 dpb_longterm_e;
        static const struct hantro_reg cur_poc[] = {
index 6db1c32fce4dbedc2be7c6812e4feb024afd4433..342e543dee4c4cd4d685f7aafa56b83f653fa446 100644 (file)
@@ -16,8 +16,6 @@
 #include "hantro_vp9.h"
 #include "hantro_g2_regs.h"
 
-#define G2_ALIGN 16
-
 enum hantro_ref_frames {
        INTRA_FRAME = 0,
        LAST_FRAME = 1,
@@ -90,22 +88,6 @@ static int start_prepare_run(struct hantro_ctx *ctx, const struct v4l2_ctrl_vp9_
        return 0;
 }
 
-static size_t chroma_offset(const struct hantro_ctx *ctx,
-                           const struct v4l2_ctrl_vp9_frame *dec_params)
-{
-       int bytes_per_pixel = dec_params->bit_depth == 8 ? 1 : 2;
-
-       return ctx->src_fmt.width * ctx->src_fmt.height * bytes_per_pixel;
-}
-
-static size_t mv_offset(const struct hantro_ctx *ctx,
-                       const struct v4l2_ctrl_vp9_frame *dec_params)
-{
-       size_t cr_offset = chroma_offset(ctx, dec_params);
-
-       return ALIGN((cr_offset * 3) / 2, G2_ALIGN);
-}
-
 static struct hantro_decoded_buffer *
 get_ref_buf(struct hantro_ctx *ctx, struct vb2_v4l2_buffer *dst, u64 timestamp)
 {
@@ -156,13 +138,13 @@ static void config_output(struct hantro_ctx *ctx,
        luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf);
        hantro_write_addr(ctx->dev, G2_OUT_LUMA_ADDR, luma_addr);
 
-       chroma_addr = luma_addr + chroma_offset(ctx, dec_params);
+       chroma_addr = luma_addr + hantro_g2_chroma_offset(ctx);
        hantro_write_addr(ctx->dev, G2_OUT_CHROMA_ADDR, chroma_addr);
-       dst->vp9.chroma_offset = chroma_offset(ctx, dec_params);
+       dst->vp9.chroma_offset = hantro_g2_chroma_offset(ctx);
 
-       mv_addr = luma_addr + mv_offset(ctx, dec_params);
+       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 = mv_offset(ctx, dec_params);
+       dst->vp9.mv_offset = hantro_g2_motion_vectors_offset(ctx);
 }
 
 struct hantro_vp9_ref_reg {
index 292a76ef643e85110d86d618b7a634267a6b5349..9aec8a79acdca4b39849872fa679a8644113a640 100644 (file)
@@ -521,6 +521,9 @@ hantro_av1_mv_size(unsigned int width, unsigned int height)
        return ALIGN(num_sbs * 384, 16) * 2 + 512;
 }
 
+size_t hantro_g2_chroma_offset(struct hantro_ctx *ctx);
+size_t hantro_g2_motion_vectors_offset(struct hantro_ctx *ctx);
+
 int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
 int rockchip_vpu2_mpeg2_dec_run(struct hantro_ctx *ctx);
 void hantro_mpeg2_dec_copy_qtable(u8 *qtable,