diff mbox series

[v6,24/24] media: mediatek: vcodec: support vp9 svp decoder for mt8188

Message ID 20240516122102.16379-25-yunfei.dong@mediatek.com (mailing list archive)
State New, archived
Headers show
Series media: mediatek: add driver to support secure video decoder | expand

Commit Message

Yunfei Dong May 16, 2024, 12:21 p.m. UTC
From: Yilong Zhou <yilong.zhou@mediatek.com>

Change vp9 driver to support secure video playback(svp) for
mt8188. Need to map shared memory with optee interface and
wait interrupt in optee-os.

Signed-off-by: Yilong Zhou <yilong.zhou@mediatek.com>
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 91 ++++++++++++-------
 1 file changed, 59 insertions(+), 32 deletions(-)

Comments

Chen-Yu Tsai May 27, 2024, 7:54 a.m. UTC | #1
On Thu, May 16, 2024 at 8:21 PM Yunfei Dong <yunfei.dong@mediatek.com> wrote:
>
> From: Yilong Zhou <yilong.zhou@mediatek.com>
>
> Change vp9 driver to support secure video playback(svp) for
> mt8188. Need to map shared memory with optee interface and
> wait interrupt in optee-os.
>
> Signed-off-by: Yilong Zhou <yilong.zhou@mediatek.com>
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 91 ++++++++++++-------
>  1 file changed, 59 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
> index cf48d09b78d7..9f64661800af 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
> @@ -141,6 +141,7 @@ struct vdec_vp9_slice_frame_counts {
>   * @skip:      skip counts.
>   * @y_mode:    Y prediction mode counts.
>   * @filter:    interpolation filter counts.
> + * @mv_joint:  motion vector joint counts.
>   * @sign:      motion vector sign counts.
>   * @classes:   motion vector class counts.
>   * @class0:    motion vector class0 bit counts.
> @@ -804,6 +805,9 @@ static void vdec_vp9_slice_setup_frame_ctx(struct vdec_vp9_slice_instance *insta
>         error_resilient_mode = HDR_FLAG(ERROR_RESILIENT);
>         reset_frame_context = uh->reset_frame_context;
>
> +       if (instance->ctx->is_secure_playback)
> +               return;
> +
>         /*
>          * according to "6.2 Uncompressed header syntax" in
>          * "VP9 Bitstream & Decoding Process Specification",
> @@ -818,8 +822,7 @@ static void vdec_vp9_slice_setup_frame_ctx(struct vdec_vp9_slice_instance *insta
>                  * 2 resets just the context specified in the frame header
>                  * 3 resets all contexts
>                  */
> -               if (key_frame || error_resilient_mode ||
> -                   reset_frame_context == 3) {
> +               if (key_frame || error_resilient_mode || reset_frame_context == 3) {
>                         /* use default table */
>                         for (i = 0; i < 4; i++)
>                                 instance->dirty[i] = 0;
> @@ -1042,6 +1045,9 @@ static void vdec_vp9_slice_setup_seg_buffer(struct vdec_vp9_slice_instance *inst
>  {
>         struct vdec_vp9_slice_uncompressed_header *uh;
>
> +       if (instance->ctx->is_secure_playback)
> +               return;
> +
>         /* reset segment buffer */
>         uh = &vsi->frame.uh;
>         if (uh->frame_type == 0 ||
> @@ -1172,15 +1178,16 @@ static int vdec_vp9_slice_setup_lat(struct vdec_vp9_slice_instance *instance,
>
>         vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance->seg[0]);
>
> -       /* setup prob/tile buffers for LAT */
> -
> -       ret = vdec_vp9_slice_setup_prob_buffer(instance, vsi);
> -       if (ret)
> -               goto err;
> +       if (!instance->ctx->is_secure_playback) {
> +               /* setup prob/tile buffers for LAT */
> +               ret = vdec_vp9_slice_setup_prob_buffer(instance, vsi);
> +               if (ret)
> +                       goto err;
>
> -       ret = vdec_vp9_slice_setup_tile_buffer(instance, vsi, bs);
> -       if (ret)
> -               goto err;
> +               ret = vdec_vp9_slice_setup_tile_buffer(instance, vsi, bs);
> +               if (ret)
> +                       goto err;
> +       }
>
>         return 0;
>
> @@ -1599,7 +1606,8 @@ static int vdec_vp9_slice_update_single(struct vdec_vp9_slice_instance *instance
>                        pfc->seq, vsi->state.crc[4], vsi->state.crc[5],
>                        vsi->state.crc[6], vsi->state.crc[7]);
>
> -       vdec_vp9_slice_update_prob(instance, vsi);
> +       if (!instance->ctx->is_secure_playback)
> +               vdec_vp9_slice_update_prob(instance, vsi);
>
>         instance->width = vsi->frame.uh.frame_width;
>         instance->height = vsi->frame.uh.frame_height;
> @@ -1632,7 +1640,8 @@ static int vdec_vp9_slice_update_lat(struct vdec_vp9_slice_instance *instance,
>                 return -EAGAIN;
>         }
>
> -       vdec_vp9_slice_update_prob(instance, vsi);
> +       if (!instance->ctx->is_secure_playback)
> +               vdec_vp9_slice_update_prob(instance, vsi);
>
>         instance->width = vsi->frame.uh.frame_width;
>         instance->height = vsi->frame.uh.frame_height;
> @@ -1694,8 +1703,13 @@ static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst
>                 return -EINVAL;
>
>         /* update internal buffer's width/height */
> -       instance->dpb[vb->index].width = w;
> -       instance->dpb[vb->index].height = h;
> +       for (i = 0; i < vq->num_buffers; i++) {

Starting in v6.10-rc1 with the introduction of REMOVE_BUFS, vq->num_buffers
was removed. There is now vq->max_num_buffers.

> +               if (vb == vq->bufs[i]) {

This should probably use the helper "vb2_get_buffer(vq, i)".

ChenYu

> +                       instance->dpb[i].width = w;
> +                       instance->dpb[i].height = h;
> +                       break;
> +               }
> +       }
>
>         /*
>          * get buffer's width/height from instance
> @@ -1779,7 +1793,8 @@ static int vdec_vp9_slice_setup_core(struct vdec_vp9_slice_instance *instance,
>         if (ret)
>                 goto err;
>
> -       vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance->seg[1]);
> +       if (!instance->ctx->is_secure_playback)
> +               vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance->seg[1]);
>
>         return 0;
>
> @@ -1874,19 +1889,31 @@ static int vdec_vp9_slice_init(struct mtk_vcodec_dec_ctx *ctx)
>                 goto error_vsi;
>         }
>         instance->init_vsi = vsi;
> -       instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
> -                                                      (u32)vsi->core_vsi);
> -       if (!instance->core_vsi) {
> -               mtk_vdec_err(ctx, "failed to get VP9 core vsi\n");
> -               ret = -EINVAL;
> -               goto error_vsi;
> -       }
>
> -       instance->irq = 1;
> +       if (ctx->is_secure_playback) {
> +               instance->core_vsi =
> +                       mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE,
> +                                                        OPTEE_DATA_INDEX);
> +               if (!instance->core_vsi) {
> +                       mtk_vdec_err(ctx, "failed to get VP9 svp core vsi\n");
> +                       ret = -EINVAL;
> +                       goto error_vsi;
> +               }
> +               instance->irq = 0;
> +       } else {
> +               instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
> +                                                              (u32)vsi->core_vsi);
> +               if (!instance->core_vsi) {
> +                       mtk_vdec_err(ctx, "failed to get VP9 normal core vsi\n");
> +                       ret = -EINVAL;
> +                       goto error_vsi;
> +               }
> +               instance->irq = 1;
>
> -       ret = vdec_vp9_slice_init_default_frame_ctx(instance);
> -       if (ret)
> -               goto error_default_frame_ctx;
> +               ret = vdec_vp9_slice_init_default_frame_ctx(instance);
> +               if (ret)
> +                       goto error_default_frame_ctx;
> +       }
>
>         ctx->drv_handle = instance;
>
> @@ -2101,9 +2128,12 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
>                        (unsigned long)pfc->vsi.trans.dma_addr,
>                        (unsigned long)pfc->vsi.trans.dma_addr_end);
>
> -       vdec_msg_queue_update_ube_wptr(&ctx->msg_queue,
> -                                      vsi->trans.dma_addr_end +
> -                                      ctx->msg_queue.wdma_addr.dma_addr);
> +       if (!instance->ctx->is_secure_playback) {
> +               vsi->trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
> +               mtk_vdec_debug(ctx, "core dma_addr_end 0x%lx\n",
> +                              (unsigned long)pfc->vsi.trans.dma_addr_end);
> +       }
> +       vdec_msg_queue_update_ube_wptr(&ctx->msg_queue, vsi->trans.dma_addr_end);
>         vdec_msg_queue_qbuf(&ctx->msg_queue.core_ctx, lat_buf);
>
>         return 0;
> @@ -2183,9 +2213,6 @@ static int vdec_vp9_slice_core_decode(struct vdec_lat_buf *lat_buf)
>                 goto err;
>         }
>
> -       pfc->vsi.trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
> -       mtk_vdec_debug(ctx, "core dma_addr_end 0x%lx\n",
> -                      (unsigned long)pfc->vsi.trans.dma_addr_end);
>         vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc->vsi.trans.dma_addr_end);
>         ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf->src_buf_req);
>
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
index cf48d09b78d7..9f64661800af 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
@@ -141,6 +141,7 @@  struct vdec_vp9_slice_frame_counts {
  * @skip:	skip counts.
  * @y_mode:	Y prediction mode counts.
  * @filter:	interpolation filter counts.
+ * @mv_joint:	motion vector joint counts.
  * @sign:	motion vector sign counts.
  * @classes:	motion vector class counts.
  * @class0:	motion vector class0 bit counts.
@@ -804,6 +805,9 @@  static void vdec_vp9_slice_setup_frame_ctx(struct vdec_vp9_slice_instance *insta
 	error_resilient_mode = HDR_FLAG(ERROR_RESILIENT);
 	reset_frame_context = uh->reset_frame_context;
 
+	if (instance->ctx->is_secure_playback)
+		return;
+
 	/*
 	 * according to "6.2 Uncompressed header syntax" in
 	 * "VP9 Bitstream & Decoding Process Specification",
@@ -818,8 +822,7 @@  static void vdec_vp9_slice_setup_frame_ctx(struct vdec_vp9_slice_instance *insta
 		 * 2 resets just the context specified in the frame header
 		 * 3 resets all contexts
 		 */
-		if (key_frame || error_resilient_mode ||
-		    reset_frame_context == 3) {
+		if (key_frame || error_resilient_mode || reset_frame_context == 3) {
 			/* use default table */
 			for (i = 0; i < 4; i++)
 				instance->dirty[i] = 0;
@@ -1042,6 +1045,9 @@  static void vdec_vp9_slice_setup_seg_buffer(struct vdec_vp9_slice_instance *inst
 {
 	struct vdec_vp9_slice_uncompressed_header *uh;
 
+	if (instance->ctx->is_secure_playback)
+		return;
+
 	/* reset segment buffer */
 	uh = &vsi->frame.uh;
 	if (uh->frame_type == 0 ||
@@ -1172,15 +1178,16 @@  static int vdec_vp9_slice_setup_lat(struct vdec_vp9_slice_instance *instance,
 
 	vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance->seg[0]);
 
-	/* setup prob/tile buffers for LAT */
-
-	ret = vdec_vp9_slice_setup_prob_buffer(instance, vsi);
-	if (ret)
-		goto err;
+	if (!instance->ctx->is_secure_playback) {
+		/* setup prob/tile buffers for LAT */
+		ret = vdec_vp9_slice_setup_prob_buffer(instance, vsi);
+		if (ret)
+			goto err;
 
-	ret = vdec_vp9_slice_setup_tile_buffer(instance, vsi, bs);
-	if (ret)
-		goto err;
+		ret = vdec_vp9_slice_setup_tile_buffer(instance, vsi, bs);
+		if (ret)
+			goto err;
+	}
 
 	return 0;
 
@@ -1599,7 +1606,8 @@  static int vdec_vp9_slice_update_single(struct vdec_vp9_slice_instance *instance
 		       pfc->seq, vsi->state.crc[4], vsi->state.crc[5],
 		       vsi->state.crc[6], vsi->state.crc[7]);
 
-	vdec_vp9_slice_update_prob(instance, vsi);
+	if (!instance->ctx->is_secure_playback)
+		vdec_vp9_slice_update_prob(instance, vsi);
 
 	instance->width = vsi->frame.uh.frame_width;
 	instance->height = vsi->frame.uh.frame_height;
@@ -1632,7 +1640,8 @@  static int vdec_vp9_slice_update_lat(struct vdec_vp9_slice_instance *instance,
 		return -EAGAIN;
 	}
 
-	vdec_vp9_slice_update_prob(instance, vsi);
+	if (!instance->ctx->is_secure_playback)
+		vdec_vp9_slice_update_prob(instance, vsi);
 
 	instance->width = vsi->frame.uh.frame_width;
 	instance->height = vsi->frame.uh.frame_height;
@@ -1694,8 +1703,13 @@  static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst
 		return -EINVAL;
 
 	/* update internal buffer's width/height */
-	instance->dpb[vb->index].width = w;
-	instance->dpb[vb->index].height = h;
+	for (i = 0; i < vq->num_buffers; i++) {
+		if (vb == vq->bufs[i]) {
+			instance->dpb[i].width = w;
+			instance->dpb[i].height = h;
+			break;
+		}
+	}
 
 	/*
 	 * get buffer's width/height from instance
@@ -1779,7 +1793,8 @@  static int vdec_vp9_slice_setup_core(struct vdec_vp9_slice_instance *instance,
 	if (ret)
 		goto err;
 
-	vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance->seg[1]);
+	if (!instance->ctx->is_secure_playback)
+		vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance->seg[1]);
 
 	return 0;
 
@@ -1874,19 +1889,31 @@  static int vdec_vp9_slice_init(struct mtk_vcodec_dec_ctx *ctx)
 		goto error_vsi;
 	}
 	instance->init_vsi = vsi;
-	instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
-						       (u32)vsi->core_vsi);
-	if (!instance->core_vsi) {
-		mtk_vdec_err(ctx, "failed to get VP9 core vsi\n");
-		ret = -EINVAL;
-		goto error_vsi;
-	}
 
-	instance->irq = 1;
+	if (ctx->is_secure_playback) {
+		instance->core_vsi =
+			mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE,
+							 OPTEE_DATA_INDEX);
+		if (!instance->core_vsi) {
+			mtk_vdec_err(ctx, "failed to get VP9 svp core vsi\n");
+			ret = -EINVAL;
+			goto error_vsi;
+		}
+		instance->irq = 0;
+	} else {
+		instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
+							       (u32)vsi->core_vsi);
+		if (!instance->core_vsi) {
+			mtk_vdec_err(ctx, "failed to get VP9 normal core vsi\n");
+			ret = -EINVAL;
+			goto error_vsi;
+		}
+		instance->irq = 1;
 
-	ret = vdec_vp9_slice_init_default_frame_ctx(instance);
-	if (ret)
-		goto error_default_frame_ctx;
+		ret = vdec_vp9_slice_init_default_frame_ctx(instance);
+		if (ret)
+			goto error_default_frame_ctx;
+	}
 
 	ctx->drv_handle = instance;
 
@@ -2101,9 +2128,12 @@  static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 		       (unsigned long)pfc->vsi.trans.dma_addr,
 		       (unsigned long)pfc->vsi.trans.dma_addr_end);
 
-	vdec_msg_queue_update_ube_wptr(&ctx->msg_queue,
-				       vsi->trans.dma_addr_end +
-				       ctx->msg_queue.wdma_addr.dma_addr);
+	if (!instance->ctx->is_secure_playback) {
+		vsi->trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
+		mtk_vdec_debug(ctx, "core dma_addr_end 0x%lx\n",
+			       (unsigned long)pfc->vsi.trans.dma_addr_end);
+	}
+	vdec_msg_queue_update_ube_wptr(&ctx->msg_queue, vsi->trans.dma_addr_end);
 	vdec_msg_queue_qbuf(&ctx->msg_queue.core_ctx, lat_buf);
 
 	return 0;
@@ -2183,9 +2213,6 @@  static int vdec_vp9_slice_core_decode(struct vdec_lat_buf *lat_buf)
 		goto err;
 	}
 
-	pfc->vsi.trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
-	mtk_vdec_debug(ctx, "core dma_addr_end 0x%lx\n",
-		       (unsigned long)pfc->vsi.trans.dma_addr_end);
 	vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc->vsi.trans.dma_addr_end);
 	ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf->src_buf_req);