Skip to contentSkip to conversation

media: mediatek: vcodec: support h264 extend vsi

PATCH Superseded Yunfei Dong 3 participants 6 messages Nov 7, 2024

Subsystems (3)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Yunfei Dong

author maintainer
#0 lore raw

v3 cover media: mediatek: vcodec: support h264 extend vsi

The working buffer address start and end are calculated in kernel side currently, the address end can't be calculated if the driver only getting the address file handle, not the real physical address. Need to send the extended vsi to firmware to calculate the address end.

Re-construct some interface and add configuration to support extend
and non extend driver at the same time. Needn't to parse nal info for
extended architecture.
---
This patch series depends on:
[1] https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]

---
compared with v2:
- squash patch 2/3/4 together
- re-write commit message for patch 1

compared with v1:
- combine some pathes together for patch 2
- re-write patch 4
---
Yunfei Dong (3):
media: mediatek: vcodec: remove vsi operation in common interface
media: mediatek: vcodec: support extended h264 decode
media: mediatek: vcodec: add description for vsi struct

 .../vcodec/decoder/mtk_vcodec_dec_drv.h       |   2 +
 .../decoder/vdec/vdec_h264_req_multi_if.c     | 505 +++++++++++++++++-
 2 files changed, 482 insertions(+), 25 deletions(-)
Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH v3 1/3 media: mediatek: vcodec: remove vsi operation in common interface

Extend struct video shared information (vsi) to send different parameters to scp for mt8188 architecture is changed. Remove vsi related operation in common interface to make sure the interface can be called by extended and non extended architecture at the same time. The new extended interfaces with new vsi will be introduced in later patches.

---
 .../vcodec/decoder/vdec/vdec_h264_req_multi_if.c    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7 -6
index 732d78f63e5a..851a8490b828 100644
@@ -171,9 +171,9 @@ struct vdec_h264_slice_inst {
 };
 
 static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *inst,
-						  struct vdec_h264_slice_share_info *share_info)
+						  struct vdec_h264_slice_share_info *share_info,
+						  struct vdec_h264_slice_lat_dec_param *slice_param)
 {
-	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->vsi->h264_slice_params;
 	const struct v4l2_ctrl_h264_decode_params *dec_params;
 	const struct v4l2_ctrl_h264_scaling_matrix *src_matrix;
 	const struct v4l2_ctrl_h264_sps *sps;
@@ -266,9 +266,6 @@ static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
 	mtk_vdec_h264_get_ref_list(b0_reflist, v4l2_b0_reflist, reflist_builder.num_valid);
 	mtk_vdec_h264_get_ref_list(b1_reflist, v4l2_b1_reflist, reflist_builder.num_valid);
 
-	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
-	       sizeof(inst->vsi_ctx.h264_slice_params));
-
 	return 0;
 }
 
@@ -608,7 +605,8 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 	lat_buf->vb2_v4l2_src = &src_buf_info->m2m_buf.vb;
 	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, true);
 
-	err = vdec_h264_slice_fill_decode_parameters(inst, share_info);
+	err = vdec_h264_slice_fill_decode_parameters(inst, share_info,
+						     &inst->vsi->h264_slice_params);
 	if (err)
 		goto err_free_fb_out;
 
@@ -749,6 +747,9 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs
 	if (err)
 		goto err_free_fb_out;
 
+	memcpy(&inst->vsi_ctx.h264_slice_params, &inst->h264_slice_param,
+	       sizeof(inst->vsi_ctx.h264_slice_params));
+
 	buf = (unsigned char *)bs->va;
 	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
 	if (nal_start_idx < 0) {
Signature · 1 line
2.46.0
author maintainer
#2 lore raw

PATCH v3 2/3 media: mediatek: vcodec: support extended h264 decode

In reply to Yunfei Dong

The address end of working buffer can't be calculated directly with buffer size in kernel for some special architecture. Adding new extend vsi_ex to calculate the address end in firmware.
Adding capability to separate extend and non extend driver for different platform.
At last, hardware can parse the syntax to get nal information in firmware for extend architecture, needn't to parse it again in kernel.

---
 .../vcodec/decoder/mtk_vcodec_dec_drv.h       |   2 +
 .../decoder/vdec/vdec_h264_req_multi_if.c     | 487 +++++++++++++++++-
 2 files changed, 472 insertions(+), 17 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +2 -0
index 886fa385e2e6..1e697bc810b0 100644
@@ -17,6 +17,7 @@
 
 #define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
 #define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING)
+#define IS_VDEC_SUPPORT_EX(capability) ((capability) & MTK_VDEC_IS_SUPPORT_EX)
 
 enum mtk_vcodec_dec_chip_name {
 	MTK_VDEC_INVAL = 0,
@@ -42,6 +43,7 @@ enum mtk_vdec_format_types {
 	MTK_VDEC_FORMAT_HEVC_FRAME = 0x1000,
 	MTK_VCODEC_INNER_RACING = 0x20000,
 	MTK_VDEC_IS_SUPPORT_10BIT = 0x40000,
+	MTK_VDEC_IS_SUPPORT_EX = 0x80000,
 };
 
 /*
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +470 -17

560 lines not on this page · raw message

Signature · 1 line
2.46.0
#3 lore raw

Re: [PATCH v3 2/3] media: mediatek: vcodec: support extended h264 decode

Il 07/11/24 08:45, Yunfei Dong ha scritto:

Quoted 38 lines

The address end of working buffer can't be calculated directly with buffer size in kernel for some special architecture. Adding new extend vsi_ex to calculate the address end in firmware.
Adding capability to separate extend and non extend driver for different platform.
At last, hardware can parse the syntax to get nal information in firmware for extend architecture, needn't to parse it again in kernel.

---
  .../vcodec/decoder/mtk_vcodec_dec_drv.h       |   2 +
  .../decoder/vdec/vdec_h264_req_multi_if.c     | 487 +++++++++++++++++-
  2 files changed, 472 insertions(+), 17 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +2 -0
index 886fa385e2e6..1e697bc810b0 100644
@@ -17,6 +17,7 @@
 
  #define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
  #define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING)
+#define IS_VDEC_SUPPORT_EX(capability) ((capability) & MTK_VDEC_IS_SUPPORT_EX)
 
  enum mtk_vcodec_dec_chip_name {
  	MTK_VDEC_INVAL = 0,
@@ -42,6 +43,7 @@ enum mtk_vdec_format_types {
  	MTK_VDEC_FORMAT_HEVC_FRAME = 0x1000,
  	MTK_VCODEC_INNER_RACING = 0x20000,
  	MTK_VDEC_IS_SUPPORT_10BIT = 0x40000,
+	MTK_VDEC_IS_SUPPORT_EX = 0x80000,
  };
 
  /*
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +0 -0
index 851a8490b828..d0aecd9621d9 100644

..snip..

drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs, · line 1265

Quoted 10 lines
  	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3 -2
@@ -816,8 +1260,17 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
  	if (!h_vdec)
  		return -EINVAL;
 
-	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
-		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
+	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE) {
+		if (IS_VDEC_SUPPORT_EX(inst->ctx->dev->dec_capability))
+			ret = vdec_h264_slice_single_decode_ex(h_vdec, bs, unused, res_chg);

I wonder if we can use function pointers here, as I feel like vcodec is becoming a bit "full of branches here and there"...

The rough idea is:

/* there, or somewhere that's called only once in the driver lifetime anyway */ static int vdec_h264_slice_init(.....)

{
	........

	if (hw_arch == MTK_VDEC_PURE_SINGLE_CORE) {
		if (inst->ctx->dev->dec_capability & MTK_VDEC_IS_SUPPORT_EX)
			inst->decode = vdec_h264_slice_single_decode_ex;
		else
			inst->decode = vdec_h264_slice_single_decode;
	}  else {
		if (inst->ctx->dev->dec_capability & MTK_VDEC_IS_SUPPORT_EX)
			inst->decode = vdec_h264_slice_lat_decode_ex;
		else
			inst->decode = vdec_h264_slice_lat_decode;
	}

	......
}

static int vdec_h264_slice_decode(...)

{
	if (!inst)
		return -EINVAL;

	return inst->decode( .... )
}

...less branches during decoding *of each frame* :-)

Cheers,
Angelo

author maintainer
#4 lore raw

PATCH v3 3/3 media: mediatek: vcodec: add description for vsi struct

In reply to Yunfei Dong

If the video shared information (vsi) is changed accidentally, will leading to play h264 bitstream fail if the firmware won't be changed at the same time. Marking the shared struct with "shared interface with firmware".

---
 .../mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c    | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3 -2
index d0aecd9621d9..661ea84b6621 100644
@@ -30,6 +30,7 @@ enum vdec_h264_core_dec_err_type {
 
 /**
  * struct vdec_h264_slice_lat_dec_param  - parameters for decode current frame
+ *        (shared interface with firmware)
  *
  * @sps:		h264 sps syntax parameters
  * @pps:		h264 pps syntax parameters
@@ -48,7 +49,7 @@ struct vdec_h264_slice_lat_dec_param {
 };
 
 /**
- * struct vdec_h264_slice_info - decode information
+ * struct vdec_h264_slice_info - decode information (shared interface with firmware)
  *
  * @nal_info:		nal info of current picture
  * @timeout:		Decode timeout: 1 timeout, 0 no timeout
@@ -72,7 +73,7 @@ struct vdec_h264_slice_info {
 
 /**
  * struct vdec_h264_slice_vsi - shared memory for decode information exchange
- *        between SCP and Host.
+ *        between SCP and Host (shared interface with firmware).
  *
  * @wdma_err_addr:		wdma error dma address
  * @wdma_start_addr:		wdma start dma address
Signature · 1 line
2.46.0
Reviewed-by on v3 3/3
#5 lore raw

Re: [PATCH v3 3/3] media: mediatek: vcodec: add description for vsi struct

Quoted 7 lines · Yunfei Dong

If the video shared information (vsi) is changed accidentally, will leading to play h264 bitstream fail if the firmware won't be changed at the same time. Marking the shared struct with "shared interface with firmware".