Re: [PATCH v2 14/14] media: mediatek: decoder: support av1 extend vsi

From: Nicolas Dufresne

Date: Fri Nov 28 2025 - 15:26:20 EST


Hi,

Le vendredi 15 août 2025 à 16:52 +0800, Yunfei Dong a écrit :
> The driver can't access tile buffer address for extend architecture,
> set tile group information in vcp and share it with kernel.
>
> Signed-off-by: Yunfei Dong <yunfei.dong@xxxxxxxxxxxx>
> ---
>  .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 46 ++++++++++++++++---
>  1 file changed, 39 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
> index 6070485e26c4..43541faeea87 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
> @@ -25,6 +25,8 @@
>  
>  #define AV1_INVALID_IDX -1
>  
> +#define AV1_NON_EXT_VSI_SIZE 0xD50
> +
>  #define AV1_DIV_ROUND_UP_POW2(value, n) \
>  ({ \
>   typeof(n) _n  = n; \
> @@ -641,6 +643,8 @@ struct vdec_av1_slice_fb {
>   * @frame: current frame info
>   * @state: status after decode done
>   * @cur_lst_tile_id: tile id for large scale
> + * @tile_group: tile group info
> + * @reserved: reserved
>   */
>  struct vdec_av1_slice_vsi {
>   /* lat */
> @@ -665,6 +669,8 @@ struct vdec_av1_slice_vsi {
>   struct vdec_av1_slice_frame frame;
>   struct vdec_av1_slice_state state;
>   u32 cur_lst_tile_id;
> + struct vdec_av1_slice_tile_group tile_group;
> + unsigned int reserved[4];
>  };
>  
>  /**
> @@ -1394,13 +1400,18 @@ static int vdec_av1_slice_setup_tile_group(struct vdec_av1_slice_instance *insta
>      struct vdec_av1_slice_vsi *vsi)
>  {
>   struct v4l2_ctrl_av1_tile_group_entry *ctrl_tge;
> - struct vdec_av1_slice_tile_group *tile_group = &instance->tile_group;
> + struct vdec_av1_slice_tile_group *tile_group;
>   struct vdec_av1_slice_uncompressed_header *uh = &vsi->frame.uh;
>   struct vdec_av1_slice_tile *tile = &uh->tile;
>   struct v4l2_ctrl *ctrl;
>   u32 tge_size;
>   int i;
>  
> + if (IS_VDEC_SUPPORT_EXT(instance->ctx->dev->dec_capability))
> + tile_group = &vsi->tile_group;
> + else
> + tile_group = &instance->tile_group;
> +
>   ctrl = v4l2_ctrl_find(&instance->ctx->ctrl_hdl, V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY);
>   if (!ctrl)
>   return -EINVAL;
> @@ -1601,6 +1612,7 @@ static void vdec_av1_slice_setup_lat_buffer(struct vdec_av1_slice_instance *inst
>       struct vdec_lat_buf *lat_buf)
>  {
>   struct vdec_av1_slice_work_buffer *work_buffer;
> + u32 num_tiles;
>   int i;
>  
>   vsi->bs.dma_addr = bs->dma_addr;
> @@ -1635,12 +1647,18 @@ static void vdec_av1_slice_setup_lat_buffer(struct vdec_av1_slice_instance *inst
>  
>   vsi->tile.buf = instance->tile.dma_addr;
>   vsi->tile.size = instance->tile.size;
> - memcpy(lat_buf->tile_addr.va, instance->tile.va, 64 * instance->tile_group.num_tiles);

Can you define the magic number 64 please.

>  
>   vsi->cdf_table.buf = instance->cdf_table.dma_addr;
>   vsi->cdf_table.size = instance->cdf_table.size;
>   vsi->iq_table.buf = instance->iq_table.dma_addr;
>   vsi->iq_table.size = instance->iq_table.size;
> +
> + if (IS_VDEC_SUPPORT_EXT(instance->ctx->dev->dec_capability))
> + num_tiles = vsi->tile_group.num_tiles;
> + else
> + num_tiles = instance->tile_group.num_tiles;
> +
> + memcpy(lat_buf->tile_addr.va, instance->tile.va, 64 * num_tiles);

I bet its shared.

>  }
>  
>  static void vdec_av1_slice_setup_seg_buffer(struct vdec_av1_slice_instance *instance,
> @@ -1663,7 +1681,7 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins
>        struct vdec_av1_slice_vsi *vsi,
>        struct mtk_vcodec_mem *bs)
>  {
> - struct vdec_av1_slice_tile_group *tile_group = &instance->tile_group;
> + struct vdec_av1_slice_tile_group *tile_group;
>   struct vdec_av1_slice_uncompressed_header *uh = &vsi->frame.uh;
>   struct vdec_av1_slice_tile *tile = &uh->tile;
>   u32 tile_num, tile_row, tile_col;
> @@ -1674,6 +1692,11 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins
>   u32 *tile_info_buf = instance->tile.va;
>   u64 pa = (u64)bs->dma_addr;
>  
> + if (IS_VDEC_SUPPORT_EXT(instance->ctx->dev->dec_capability))
> + tile_group = &vsi->tile_group;
> + else
> + tile_group = &instance->tile_group;
> +

Second time this is repeated, perhaps make a small helper ?

>   if (uh->disable_cdf_update == 0)
>   allow_update_cdf = 1;
>  
> @@ -1887,7 +1910,7 @@ static int vdec_av1_slice_init(struct mtk_vcodec_dec_ctx *ctx)
>  {
>   struct vdec_av1_slice_instance *instance;
>   struct vdec_av1_slice_init_vsi *vsi;
> - int ret;
> + int ret, vsi_size = AV1_NON_EXT_VSI_SIZE;
>  
>   instance = kzalloc(sizeof(*instance), GFP_KERNEL);
>   if (!instance)
> @@ -1926,9 +1949,18 @@ static int vdec_av1_slice_init(struct mtk_vcodec_dec_ctx *ctx)
>   goto error_vsi;
>   }
>  
> - if (vsi->vsi_size != sizeof(struct vdec_av1_slice_vsi))
> - mtk_vdec_err(ctx, "remote vsi size 0x%x mismatch! expected: 0x%zx\n",
> -      vsi->vsi_size, sizeof(struct vdec_av1_slice_vsi));
> + if (IS_VDEC_SUPPORT_EXT(ctx->dev->dec_capability)) {
> + vsi_size = sizeof(struct vdec_av1_slice_vsi);
> + vsi->iq_table_size = AV1_IQ_TABLE_SIZE;
> + vsi->cdf_table_size = AV1_CDF_SIZE;
> + }
> +
> + if (vsi->vsi_size != vsi_size) {
> + mtk_vdec_err(ctx, "remote vsi size 0x%x mismatch! expected: 0x%x\n",
> +      vsi->vsi_size, vsi_size);
> + ret = -EINVAL;
> + goto error_vsi;
> + }
>  
>   instance->irq_enabled = 1;
>   instance->inneracing_mode = IS_VDEC_INNER_RACING(instance->ctx->dev->dec_capability);

cheers,
Nicolas

Attachment: signature.asc
Description: This is a digitally signed message part