* [PATCH v2 0/6] media: mediatek: vcodec: support h264 extend vsi
@ 2024-10-16 3:49 Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface Yunfei Dong
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Yunfei Dong @ 2024-10-16 3:49 UTC (permalink / raw)
To: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida
Cc: Hsin-Yi Wang, Chen-Yu Tsai, Fritz Koenig, Daniel Vetter,
Steve Cho, Yunfei Dong, linux-media, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
The working buffer address start and end are calculated in kernel
side currently, can't calculate the address end if the driver only
getting the address file handle, not the real physical address. Need
to extend the vsi to calculate the address end in scp.
Re-construct some interface and add configuration to support extend
and non extend at the same time. Needn't to parse nal info for extend
architecture.
---
This patch series depends on:
[1] https://patchwork.kernel.org/project/linux-mediatek/cover/20241012064333.27269-1-yunfei.dong@mediatek.com
---
compared with v1:
- combine some pathes together for patch 2
- re-write patch 4
---
Yunfei Dong (4):
media: mediatek: vcodec: remove vsi operation in common interface
media: mediatek: vcodec: support extend h264 video shared information
media: mediatek: vcodec: support extend h264 driver
media: mediatek: vcodec: remove parse nal info in kernel
.../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 +
.../decoder/vdec/vdec_h264_req_multi_if.c | 511 +++++++++++++++++-
2 files changed, 486 insertions(+), 27 deletions(-)
--
2.46.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface
2024-10-16 3:49 [PATCH v2 0/6] media: mediatek: vcodec: support h264 extend vsi Yunfei Dong
@ 2024-10-16 3:49 ` Yunfei Dong
2024-10-22 3:58 ` Chen-Yu Tsai
2024-10-16 3:49 ` [PATCH v2 2/4] media: mediatek: vcodec: support extend h264 video shared information Yunfei Dong
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Yunfei Dong @ 2024-10-16 3:49 UTC (permalink / raw)
To: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida
Cc: Hsin-Yi Wang, Chen-Yu Tsai, Fritz Koenig, Daniel Vetter,
Steve Cho, Yunfei Dong, linux-media, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
Remove vsi related operation in common interface to make sure the
interface can be called by different architecture at the same time.
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
.../decoder/vdec/vdec_h264_req_multi_if.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
index 732d78f63e5a..57c85af5ffb4 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
@@ -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_data)
{
- 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;
@@ -203,9 +203,9 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
return -EINVAL;
}
- mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
- mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
- mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, src_matrix);
+ mtk_vdec_h264_copy_sps_params(&slice_data->sps, sps);
+ mtk_vdec_h264_copy_pps_params(&slice_data->pps, pps);
+ mtk_vdec_h264_copy_scaling_matrix(&slice_data->scaling_matrix, src_matrix);
memcpy(&share_info->sps, sps, sizeof(*sps));
memcpy(&share_info->dec_params, dec_params, sizeof(*dec_params));
@@ -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) {
--
2.46.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] media: mediatek: vcodec: support extend h264 video shared information
2024-10-16 3:49 [PATCH v2 0/6] media: mediatek: vcodec: support h264 extend vsi Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface Yunfei Dong
@ 2024-10-16 3:49 ` Yunfei Dong
2024-10-22 7:08 ` Chen-Yu Tsai
2024-10-16 3:49 ` [PATCH v2 3/4] media: mediatek: vcodec: support extend h264 driver Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 4/4] media: mediatek: vcodec: remove parse nal info in kernel Yunfei Dong
3 siblings, 1 reply; 8+ messages in thread
From: Yunfei Dong @ 2024-10-16 3:49 UTC (permalink / raw)
To: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida
Cc: Hsin-Yi Wang, Chen-Yu Tsai, Fritz Koenig, Daniel Vetter,
Steve Cho, Yunfei Dong, linux-media, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
The address end of working buffer can't be calculated directly
with buffer size in kernel for some special architecture. Adding
new extend vsi to calculate the address end in other os.
Refactoring the driver flow to make the driver looks more reasonable.
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
.../decoder/vdec/vdec_h264_req_multi_if.c | 355 ++++++++++++------
1 file changed, 238 insertions(+), 117 deletions(-)
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
index 57c85af5ffb4..e02ed8dfe0ce 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
@@ -48,10 +48,29 @@ struct vdec_h264_slice_lat_dec_param {
};
/**
- * struct vdec_h264_slice_info - decode information
+ * struct vdec_h264_slice_info_ex - extend decode information
*
+ * @wdma_end_addr_offset: offset from buffer start
* @nal_info: nal info of current picture
* @timeout: Decode timeout: 1 timeout, 0 no timeout
+ * @vdec_fb_va: VDEC frame buffer struct virtual address
+ * @crc: Used to check whether hardware's status is right
+ * @reserved: reserved
+ */
+struct vdec_h264_slice_info_ex {
+ u64 wdma_end_addr_offset;
+ u16 nal_info;
+ u16 timeout;
+ u64 vdec_fb_va;
+ u32 crc[8];
+ u32 reserved;
+};
+
+/**
+ * struct vdec_h264_slice_info - decode information
+ *
+ * @nal_info: nal info of current picture
+ * @timeout: Decode timeout: 1 timeout, 0 no timeount
* @bs_buf_size: bitstream size
* @bs_buf_addr: bitstream buffer dma address
* @y_fb_dma: Y frame buffer dma address
@@ -70,6 +89,64 @@ struct vdec_h264_slice_info {
u32 crc[8];
};
+/*
+ * struct vdec_h264_slice_mem - memory address and size
+ */
+struct vdec_h264_slice_mem {
+ union {
+ u64 buf;
+ u64 dma_addr;
+ };
+ union {
+ size_t size;
+ u64 dma_addr_end;
+ };
+};
+
+/**
+ * struct vdec_h264_slice_fb - frame buffer for decoding
+ *
+ * @y: current y buffer address info
+ * @c: current c buffer address info
+ */
+struct vdec_h264_slice_fb {
+ struct vdec_h264_slice_mem y;
+ struct vdec_h264_slice_mem c;
+};
+
+/**
+ * struct vdec_h264_slice_vsi_ex - extend shared memory for decode information exchange
+ * between SCP and Host.
+ *
+ * @bs: input buffer info
+ * @fb: current y/c buffer
+ *
+ * @ube: ube buffer
+ * @trans: transcoded buffer
+ * @row_info: row info buffer
+ * @err_map: err map buffer
+ * @slice_bc: slice buffer
+ *
+ * @mv_buf_dma: HW working motion vector buffer
+ * @dec: decode information (AP-R, VPU-W)
+ * @h264_slice_params: decode parameters for hw used
+ */
+struct vdec_h264_slice_vsi_ex {
+ /* LAT dec addr */
+ struct vdec_h264_slice_mem bs;
+ struct vdec_h264_slice_fb fb;
+
+ struct vdec_h264_slice_mem ube;
+ struct vdec_h264_slice_mem trans;
+ struct vdec_h264_slice_mem row_info;
+ struct vdec_h264_slice_mem err_map;
+ struct vdec_h264_slice_mem slice_bc;
+
+ struct vdec_h264_slice_mem mv_buf_dma[H264_MAX_MV_NUM];
+ struct vdec_h264_slice_info_ex dec;
+ struct vdec_h264_slice_lat_dec_param h264_slice_params;
+};
+
/**
* struct vdec_h264_slice_vsi - shared memory for decode information exchange
* between SCP and Host.
@@ -136,10 +213,10 @@ struct vdec_h264_slice_share_info {
* @pred_buf: HW working prediction buffer
* @mv_buf: HW working motion vector buffer
* @vpu: VPU instance
- * @vsi: vsi used for lat
- * @vsi_core: vsi used for core
+ * @vsi_ex: extend vsi used for lat
+ * @vsi_core_ex: extend vsi used for core
*
- * @vsi_ctx: Local VSI data for this decoding context
+ * @vsi_ctx_ex: Local extend vsi data for this decoding context
* @h264_slice_param: the parameters that hardware use to decode
*
* @resolution_changed:resolution changed
@@ -156,10 +233,19 @@ struct vdec_h264_slice_inst {
struct mtk_vcodec_mem pred_buf;
struct mtk_vcodec_mem mv_buf[H264_MAX_MV_NUM];
struct vdec_vpu_inst vpu;
- struct vdec_h264_slice_vsi *vsi;
- struct vdec_h264_slice_vsi *vsi_core;
-
- struct vdec_h264_slice_vsi vsi_ctx;
+ union {
+ struct vdec_h264_slice_vsi_ex *vsi_ex;
+ struct vdec_h264_slice_vsi *vsi;
+ };
+ union {
+ struct vdec_h264_slice_vsi_ex *vsi_core_ex;
+ struct vdec_h264_slice_vsi *vsi_core;
+ };
+
+ union {
+ struct vdec_h264_slice_vsi_ex vsi_ctx_ex;
+ struct vdec_h264_slice_vsi vsi_ctx;
+ };
struct vdec_h264_slice_lat_dec_param h264_slice_param;
unsigned int resolution_changed;
@@ -389,6 +475,98 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst,
cr->left, cr->top, cr->width, cr->height);
}
+static void vdec_h264_slice_setup_lat_buffer(struct vdec_h264_slice_inst *inst,
+ struct mtk_vcodec_mem *bs,
+ struct vdec_lat_buf *lat_buf)
+{
+ struct mtk_vcodec_mem *mem;
+ int i;
+
+ inst->vsi_ex->bs.dma_addr = (u64)bs->dma_addr;
+ inst->vsi_ex->bs.size = bs->size;
+
+ for (i = 0; i < H264_MAX_MV_NUM; i++) {
+ mem = &inst->mv_buf[i];
+ inst->vsi_ex->mv_buf_dma[i].dma_addr = mem->dma_addr;
+ inst->vsi_ex->mv_buf_dma[i].size = mem->size;
+ }
+ inst->vsi_ex->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
+ inst->vsi_ex->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size;
+
+ inst->vsi_ex->row_info.dma_addr = 0;
+ inst->vsi_ex->row_info.size = 0;
+
+ inst->vsi_ex->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr;
+ inst->vsi_ex->err_map.size = lat_buf->wdma_err_addr.size;
+
+ inst->vsi_ex->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr;
+ inst->vsi_ex->slice_bc.size = lat_buf->slice_bc_addr.size;
+
+ inst->vsi_ex->trans.dma_addr_end = inst->ctx->msg_queue.wdma_rptr_addr;
+ inst->vsi_ex->trans.dma_addr = inst->ctx->msg_queue.wdma_wptr_addr;
+}
+
+static int vdec_h264_slice_setup_core_buffer(struct vdec_h264_slice_inst *inst,
+ struct vdec_h264_slice_share_info *share_info,
+ struct vdec_lat_buf *lat_buf)
+{
+ struct mtk_vcodec_mem *mem;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
+ struct vb2_v4l2_buffer *vb2_v4l2;
+ struct vdec_fb *fb;
+ u64 y_fb_dma, c_fb_dma = 0;
+ int i;
+
+ fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx);
+ if (!fb) {
+ mtk_vdec_err(ctx, "fb buffer is NULL");
+ return -EBUSY;
+ }
+
+ y_fb_dma = (u64)fb->base_y.dma_addr;
+ if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1)
+ c_fb_dma =
+ y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h;
+ else
+ c_fb_dma = (u64)fb->base_c.dma_addr;
+
+ mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma);
+
+ inst->vsi_core_ex->fb.y.dma_addr = y_fb_dma;
+ inst->vsi_core_ex->fb.y.size = ctx->picinfo.fb_sz[0];
+ inst->vsi_core_ex->fb.c.dma_addr = c_fb_dma;
+ inst->vsi_core_ex->fb.c.size = ctx->picinfo.fb_sz[1];
+
+ inst->vsi_core_ex->dec.vdec_fb_va = (unsigned long)fb;
+ inst->vsi_core_ex->dec.nal_info = share_info->nal_info;
+
+ inst->vsi_core_ex->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
+ inst->vsi_core_ex->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size;
+
+ inst->vsi_core_ex->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr;
+ inst->vsi_core_ex->err_map.size = lat_buf->wdma_err_addr.size;
+
+ inst->vsi_core_ex->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr;
+ inst->vsi_core_ex->slice_bc.size = lat_buf->slice_bc_addr.size;
+
+ inst->vsi_core_ex->row_info.dma_addr = 0;
+ inst->vsi_core_ex->row_info.size = 0;
+
+ inst->vsi_core_ex->trans.dma_addr = share_info->trans_start;
+ inst->vsi_core_ex->trans.dma_addr_end = share_info->trans_end;
+
+ for (i = 0; i < H264_MAX_MV_NUM; i++) {
+ mem = &inst->mv_buf[i];
+ inst->vsi_core_ex->mv_buf_dma[i].dma_addr = mem->dma_addr;
+ inst->vsi_core_ex->mv_buf_dma[i].size = mem->size;
+ }
+
+ vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
+ v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true);
+
+ return 0;
+}
+
static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_h264_slice_inst *inst;
@@ -412,10 +590,10 @@ static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
goto error_free_inst;
}
- vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi), VCODEC_DEC_ALIGNED_64);
- inst->vsi = inst->vpu.vsi;
- inst->vsi_core =
- (struct vdec_h264_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size);
+ vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi_ex), VCODEC_DEC_ALIGNED_64);
+ inst->vsi_ex = inst->vpu.vsi;
+ inst->vsi_core_ex =
+ (struct vdec_h264_slice_vsi_ex *)(((char *)inst->vpu.vsi) + vsi_size);
inst->resolution_changed = true;
inst->realloc_mv_buf = true;
@@ -449,64 +627,22 @@ static void vdec_h264_slice_deinit(void *h_vdec)
static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
{
- struct vdec_fb *fb;
- u64 vdec_fb_va;
- u64 y_fb_dma, c_fb_dma;
- int err, timeout, i;
+ int err, timeout;
struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx;
struct vdec_h264_slice_inst *inst = ctx->drv_handle;
- struct vb2_v4l2_buffer *vb2_v4l2;
struct vdec_h264_slice_share_info *share_info = lat_buf->private_data;
- struct mtk_vcodec_mem *mem;
struct vdec_vpu_inst *vpu = &inst->vpu;
mtk_vdec_debug(ctx, "[h264-core] vdec_h264 core decode");
- memcpy(&inst->vsi_core->h264_slice_params, &share_info->h264_slice_params,
+ memcpy(&inst->vsi_core_ex->h264_slice_params, &share_info->h264_slice_params,
sizeof(share_info->h264_slice_params));
- fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx);
- if (!fb) {
- err = -EBUSY;
- mtk_vdec_err(ctx, "fb buffer is NULL");
+ err = vdec_h264_slice_setup_core_buffer(inst, share_info, lat_buf);
+ if (err)
goto vdec_dec_end;
- }
-
- vdec_fb_va = (unsigned long)fb;
- y_fb_dma = (u64)fb->base_y.dma_addr;
- if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1)
- c_fb_dma =
- y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h;
- else
- c_fb_dma = (u64)fb->base_c.dma_addr;
-
- mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma);
- inst->vsi_core->dec.y_fb_dma = y_fb_dma;
- inst->vsi_core->dec.c_fb_dma = c_fb_dma;
- inst->vsi_core->dec.vdec_fb_va = vdec_fb_va;
- inst->vsi_core->dec.nal_info = share_info->nal_info;
- inst->vsi_core->wdma_start_addr =
- lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
- inst->vsi_core->wdma_end_addr =
- lat_buf->ctx->msg_queue.wdma_addr.dma_addr +
- lat_buf->ctx->msg_queue.wdma_addr.size;
- inst->vsi_core->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr;
- inst->vsi_core->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr;
- inst->vsi_core->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr +
- lat_buf->slice_bc_addr.size;
- inst->vsi_core->trans_start = share_info->trans_start;
- inst->vsi_core->trans_end = share_info->trans_end;
- for (i = 0; i < H264_MAX_MV_NUM; i++) {
- mem = &inst->mv_buf[i];
- inst->vsi_core->mv_buf_dma[i] = mem->dma_addr;
- }
-
- vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
- v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true);
-
- vdec_h264_slice_fill_decode_reflist(inst, &inst->vsi_core->h264_slice_params,
+ vdec_h264_slice_fill_decode_reflist(inst, &inst->vsi_core_ex->h264_slice_params,
share_info);
-
err = vpu_dec_core(vpu);
if (err) {
mtk_vdec_err(ctx, "core decode err=%d", err);
@@ -518,15 +654,15 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
if (timeout)
mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt);
- inst->vsi_core->dec.timeout = !!timeout;
+ inst->vsi_core_ex->dec.timeout = !!timeout;
vpu_dec_core_end(vpu);
mtk_vdec_debug(ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
ctx->decoded_frame_cnt,
- inst->vsi_core->dec.crc[0], inst->vsi_core->dec.crc[1],
- inst->vsi_core->dec.crc[2], inst->vsi_core->dec.crc[3],
- inst->vsi_core->dec.crc[4], inst->vsi_core->dec.crc[5],
- inst->vsi_core->dec.crc[6], inst->vsi_core->dec.crc[7]);
+ inst->vsi_core_ex->dec.crc[0], inst->vsi_core_ex->dec.crc[1],
+ inst->vsi_core_ex->dec.crc[2], inst->vsi_core_ex->dec.crc[3],
+ inst->vsi_core_ex->dec.crc[4], inst->vsi_core_ex->dec.crc[5],
+ inst->vsi_core_ex->dec.crc[6], inst->vsi_core_ex->dec.crc[7]);
vdec_dec_end:
vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->trans_end);
@@ -565,12 +701,11 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
struct vdec_h264_slice_inst *inst = h_vdec;
struct vdec_vpu_inst *vpu = &inst->vpu;
struct mtk_video_dec_buf *src_buf_info;
- int nal_start_idx, err, timeout = 0, i;
+ int nal_start_idx, err, timeout = 0;
unsigned int data[2];
struct vdec_lat_buf *lat_buf;
struct vdec_h264_slice_share_info *share_info;
unsigned char *buf;
- struct mtk_vcodec_mem *mem;
if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx,
vdec_h264_slice_core_decode,
@@ -606,16 +741,13 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
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,
- &inst->vsi->h264_slice_params);
+ &inst->vsi_ex->h264_slice_params);
if (err)
goto err_free_fb_out;
vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size,
&share_info->h264_slice_params.pps);
- inst->vsi->dec.bs_buf_addr = (uint64_t)bs->dma_addr;
- inst->vsi->dec.bs_buf_size = bs->size;
-
*res_chg = inst->resolution_changed;
if (inst->resolution_changed) {
mtk_vdec_debug(inst->ctx, "- resolution changed -");
@@ -627,30 +759,16 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
}
inst->resolution_changed = false;
}
- for (i = 0; i < H264_MAX_MV_NUM; i++) {
- mem = &inst->mv_buf[i];
- inst->vsi->mv_buf_dma[i] = mem->dma_addr;
- }
- inst->vsi->wdma_start_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
- inst->vsi->wdma_end_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr +
- lat_buf->ctx->msg_queue.wdma_addr.size;
- inst->vsi->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr;
- inst->vsi->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr;
- inst->vsi->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr +
- lat_buf->slice_bc_addr.size;
-
- inst->vsi->trans_end = inst->ctx->msg_queue.wdma_rptr_addr;
- inst->vsi->trans_start = inst->ctx->msg_queue.wdma_wptr_addr;
- mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%llx) err:0x%llx",
- inst->vsi->wdma_start_addr,
- inst->vsi->wdma_end_addr,
- inst->vsi->wdma_err_addr);
-
- mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%llx) rprt((0x%llx 0x%llx))",
- inst->vsi->slice_bc_start_addr,
- inst->vsi->slice_bc_end_addr,
- inst->vsi->trans_start,
- inst->vsi->trans_end);
+
+ vdec_h264_slice_setup_lat_buffer(inst, bs, lat_buf);
+ mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%lx) err:0x%llx",
+ inst->vsi_ex->ube.dma_addr, (unsigned long)inst->vsi_ex->ube.size,
+ inst->vsi_ex->err_map.dma_addr);
+
+ mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%lx) rprt((0x%llx 0x%llx))",
+ inst->vsi_ex->slice_bc.dma_addr, (unsigned long)inst->vsi_ex->slice_bc.size,
+ inst->vsi_ex->trans.dma_addr, inst->vsi_ex->trans.dma_addr_end);
+
err = vpu_dec_start(vpu, data, 2);
if (err) {
mtk_vdec_debug(inst->ctx, "lat decode err: %d", err);
@@ -658,12 +776,13 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
}
share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr +
- inst->vsi->wdma_end_addr_offset;
+ inst->vsi_ex->dec.wdma_end_addr_offset;
+
share_info->trans_start = inst->ctx->msg_queue.wdma_wptr_addr;
- share_info->nal_info = inst->vsi->dec.nal_info;
+ share_info->nal_info = inst->vsi_ex->dec.nal_info;
if (IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
- memcpy(&share_info->h264_slice_params, &inst->vsi->h264_slice_params,
+ memcpy(&share_info->h264_slice_params, &inst->vsi_ex->h264_slice_params,
sizeof(share_info->h264_slice_params));
vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
}
@@ -673,7 +792,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0);
if (timeout)
mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num);
- inst->vsi->dec.timeout = !!timeout;
+ inst->vsi_ex->dec.timeout = !!timeout;
err = vpu_dec_end(vpu);
if (err == SLICE_HEADER_FULL || err == TRANS_BUFFER_FULL) {
@@ -685,16 +804,18 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
}
share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr +
- inst->vsi->wdma_end_addr_offset;
+ inst->vsi_ex->dec.wdma_end_addr_offset;
+
vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue, share_info->trans_end);
if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
- memcpy(&share_info->h264_slice_params, &inst->vsi->h264_slice_params,
+ memcpy(&share_info->h264_slice_params, &inst->vsi_ex->h264_slice_params,
sizeof(share_info->h264_slice_params));
vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
}
mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x 0x%x", inst->slice_dec_num,
- inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], inst->vsi->dec.crc[2]);
+ inst->vsi_ex->dec.crc[0], inst->vsi_ex->dec.crc[1],
+ inst->vsi_ex->dec.crc[2]);
inst->slice_dec_num++;
return 0;
@@ -735,11 +856,11 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs
mtk_vdec_debug(inst->ctx, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
- inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
- inst->vsi_ctx.dec.bs_buf_size = bs->size;
- inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
- inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
- inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
+ inst->vsi_ctx_ex.bs.dma_addr = (u64)bs->dma_addr;
+ inst->vsi_ctx_ex.bs.size = bs->size;
+ inst->vsi_ctx_ex.fb.y.dma_addr = y_fb_dma;
+ inst->vsi_ctx_ex.fb.c.dma_addr = c_fb_dma;
+ inst->vsi_ctx_ex.dec.vdec_fb_va = (u64)(uintptr_t)fb;
v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
&dst_buf_info->m2m_buf.vb, true);
@@ -747,8 +868,8 @@ 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));
+ memcpy(&inst->vsi_ctx_ex.h264_slice_params, &inst->h264_slice_param,
+ sizeof(inst->vsi_ctx_ex.h264_slice_params));
buf = (unsigned char *)bs->va;
nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
@@ -756,7 +877,7 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs
err = -EINVAL;
goto err_free_fb_out;
}
- inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
+ inst->vsi_ctx_ex.dec.nal_info = buf[nal_start_idx];
*res_chg = inst->resolution_changed;
if (inst->resolution_changed) {
@@ -771,11 +892,11 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs
for (i = 0; i < H264_MAX_MV_NUM; i++) {
mem = &inst->mv_buf[i];
- inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
+ inst->vsi_ctx_ex.mv_buf_dma[i].dma_addr = mem->dma_addr;
}
}
- memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
+ memcpy(inst->vpu.vsi, &inst->vsi_ctx_ex, sizeof(inst->vsi_ctx_ex));
err = vpu_dec_start(vpu, data, 2);
if (err)
goto err_free_fb_out;
@@ -786,18 +907,18 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs
if (err)
mtk_vdec_err(inst->ctx, "decode timeout: pic_%d", inst->ctx->decoded_frame_cnt);
- inst->vsi->dec.timeout = !!err;
+ inst->vsi_ex->dec.timeout = !!err;
err = vpu_dec_end(vpu);
if (err)
goto err_free_fb_out;
- memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
+ memcpy(&inst->vsi_ctx_ex, inst->vpu.vsi, sizeof(inst->vsi_ctx_ex));
mtk_vdec_debug(inst->ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
inst->ctx->decoded_frame_cnt,
- inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
- inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
- inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
- inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
+ inst->vsi_ctx_ex.dec.crc[0], inst->vsi_ctx_ex.dec.crc[1],
+ inst->vsi_ctx_ex.dec.crc[2], inst->vsi_ctx_ex.dec.crc[3],
+ inst->vsi_ctx_ex.dec.crc[4], inst->vsi_ctx_ex.dec.crc[5],
+ inst->vsi_ctx_ex.dec.crc[6], inst->vsi_ctx_ex.dec.crc[7]);
inst->ctx->decoded_frame_cnt++;
return 0;
--
2.46.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] media: mediatek: vcodec: support extend h264 driver
2024-10-16 3:49 [PATCH v2 0/6] media: mediatek: vcodec: support h264 extend vsi Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 2/4] media: mediatek: vcodec: support extend h264 video shared information Yunfei Dong
@ 2024-10-16 3:49 ` Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 4/4] media: mediatek: vcodec: remove parse nal info in kernel Yunfei Dong
3 siblings, 0 replies; 8+ messages in thread
From: Yunfei Dong @ 2024-10-16 3:49 UTC (permalink / raw)
To: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida
Cc: Hsin-Yi Wang, Chen-Yu Tsai, Fritz Koenig, Daniel Vetter,
Steve Cho, Yunfei Dong, linux-media, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
Adding capability to separate extend and non extend driver to support
different architecture.
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
.../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 +
.../decoder/vdec/vdec_h264_req_multi_if.c | 377 +++++++++++++++++-
2 files changed, 367 insertions(+), 12 deletions(-)
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
index 886fa385e2e6..1e697bc810b0 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
@@ -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,
};
/*
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
index e02ed8dfe0ce..69ca775bb3f1 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
@@ -571,6 +571,7 @@ static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_h264_slice_inst *inst;
int err, vsi_size;
+ unsigned char *temp;
inst = kzalloc(sizeof(*inst), GFP_KERNEL);
if (!inst)
@@ -590,10 +591,21 @@ static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
goto error_free_inst;
}
- vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi_ex), VCODEC_DEC_ALIGNED_64);
- inst->vsi_ex = inst->vpu.vsi;
- inst->vsi_core_ex =
- (struct vdec_h264_slice_vsi_ex *)(((char *)inst->vpu.vsi) + vsi_size);
+ if (IS_VDEC_SUPPORT_EX(ctx->dev->dec_capability)) {
+ vsi_size = sizeof(struct vdec_h264_slice_vsi_ex);
+
+ vsi_size = round_up(vsi_size, VCODEC_DEC_ALIGNED_64);
+ inst->vsi_ex = inst->vpu.vsi;
+ temp = (unsigned char *)inst->vsi_ex;
+ inst->vsi_core_ex = (struct vdec_h264_slice_vsi_ex *)(temp + vsi_size);
+ } else {
+ vsi_size = sizeof(struct vdec_h264_slice_vsi);
+
+ vsi_size = round_up(vsi_size, VCODEC_DEC_ALIGNED_64);
+ inst->vsi = inst->vpu.vsi;
+ temp = (unsigned char *)inst->vsi;
+ inst->vsi_core = (struct vdec_h264_slice_vsi *)(temp + vsi_size);
+ }
inst->resolution_changed = true;
inst->realloc_mv_buf = true;
@@ -625,7 +637,7 @@ static void vdec_h264_slice_deinit(void *h_vdec)
kfree(inst);
}
-static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
+static int vdec_h264_slice_core_decode_ex(struct vdec_lat_buf *lat_buf)
{
int err, timeout;
struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx;
@@ -672,6 +684,95 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
return 0;
}
+static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
+{
+ struct vdec_fb *fb;
+ u64 vdec_fb_va;
+ u64 y_fb_dma, c_fb_dma;
+ int err, timeout, i;
+ struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx;
+ struct vdec_h264_slice_inst *inst = ctx->drv_handle;
+ struct vb2_v4l2_buffer *vb2_v4l2;
+ struct vdec_h264_slice_share_info *share_info = lat_buf->private_data;
+ struct mtk_vcodec_mem *mem;
+ struct vdec_vpu_inst *vpu = &inst->vpu;
+
+ mtk_vdec_debug(ctx, "[h264-core] vdec_h264 core decode");
+ memcpy(&inst->vsi_core->h264_slice_params, &share_info->h264_slice_params,
+ sizeof(share_info->h264_slice_params));
+
+ fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx);
+ if (!fb) {
+ err = -EBUSY;
+ mtk_vdec_err(ctx, "fb buffer is NULL");
+ goto vdec_dec_end;
+ }
+
+ vdec_fb_va = (unsigned long)fb;
+ y_fb_dma = (u64)fb->base_y.dma_addr;
+ if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1)
+ c_fb_dma =
+ y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h;
+ else
+ c_fb_dma = (u64)fb->base_c.dma_addr;
+
+ mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma);
+
+ inst->vsi_core->dec.y_fb_dma = y_fb_dma;
+ inst->vsi_core->dec.c_fb_dma = c_fb_dma;
+ inst->vsi_core->dec.vdec_fb_va = vdec_fb_va;
+ inst->vsi_core->dec.nal_info = share_info->nal_info;
+ inst->vsi_core->wdma_start_addr =
+ lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
+ inst->vsi_core->wdma_end_addr =
+ lat_buf->ctx->msg_queue.wdma_addr.dma_addr +
+ lat_buf->ctx->msg_queue.wdma_addr.size;
+ inst->vsi_core->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr;
+ inst->vsi_core->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr;
+ inst->vsi_core->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr +
+ lat_buf->slice_bc_addr.size;
+ inst->vsi_core->trans_start = share_info->trans_start;
+ inst->vsi_core->trans_end = share_info->trans_end;
+ for (i = 0; i < H264_MAX_MV_NUM; i++) {
+ mem = &inst->mv_buf[i];
+ inst->vsi_core->mv_buf_dma[i] = mem->dma_addr;
+ }
+
+ vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
+ v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true);
+
+ vdec_h264_slice_fill_decode_reflist(inst, &inst->vsi_core->h264_slice_params,
+ share_info);
+
+ err = vpu_dec_core(vpu);
+ if (err) {
+ mtk_vdec_err(ctx, "core decode err=%d", err);
+ goto vdec_dec_end;
+ }
+
+ /* wait decoder done interrupt */
+ timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+ WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
+ if (timeout)
+ mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt);
+ inst->vsi_core->dec.timeout = !!timeout;
+
+ vpu_dec_core_end(vpu);
+ mtk_vdec_debug(ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
+ ctx->decoded_frame_cnt,
+ inst->vsi_core->dec.crc[0], inst->vsi_core->dec.crc[1],
+ inst->vsi_core->dec.crc[2], inst->vsi_core->dec.crc[3],
+ inst->vsi_core->dec.crc[4], inst->vsi_core->dec.crc[5],
+ inst->vsi_core->dec.crc[6], inst->vsi_core->dec.crc[7]);
+
+vdec_dec_end:
+ vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->trans_end);
+ ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->vb2_v4l2_src);
+ mtk_vdec_debug(ctx, "core decode done err=%d", err);
+ ctx->decoded_frame_cnt++;
+ return 0;
+}
+
static void vdec_h264_insert_startcode(struct mtk_vcodec_dec_dev *vcodec_dev, unsigned char *buf,
size_t *bs_size, struct mtk_h264_pps_param *pps)
{
@@ -695,8 +796,8 @@ static void vdec_h264_insert_startcode(struct mtk_vcodec_dec_dev *vcodec_dev, un
(*bs_size) += 4;
}
-static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
- struct vdec_fb *fb, bool *res_chg)
+static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs,
+ struct vdec_fb *fb, bool *res_chg)
{
struct vdec_h264_slice_inst *inst = h_vdec;
struct vdec_vpu_inst *vpu = &inst->vpu;
@@ -708,7 +809,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
unsigned char *buf;
if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx,
- vdec_h264_slice_core_decode,
+ vdec_h264_slice_core_decode_ex,
sizeof(*share_info)))
return -ENOMEM;
@@ -825,8 +926,153 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
return err;
}
-static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
- struct vdec_fb *unused, bool *res_chg)
+static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+ struct vdec_fb *fb, bool *res_chg)
+{
+ struct vdec_h264_slice_inst *inst = h_vdec;
+ struct vdec_vpu_inst *vpu = &inst->vpu;
+ struct mtk_video_dec_buf *src_buf_info;
+ int nal_start_idx, err, timeout = 0, i;
+ unsigned int data[2];
+ struct vdec_lat_buf *lat_buf;
+ struct vdec_h264_slice_share_info *share_info;
+ unsigned char *buf;
+ struct mtk_vcodec_mem *mem;
+
+ if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx,
+ vdec_h264_slice_core_decode,
+ sizeof(*share_info)))
+ return -ENOMEM;
+
+ /* bs NULL means flush decoder */
+ if (!bs) {
+ vdec_msg_queue_wait_lat_buf_full(&inst->ctx->msg_queue);
+ return vpu_dec_reset(vpu);
+ }
+
+ if (inst->is_field_bitstream)
+ return -EINVAL;
+
+ lat_buf = vdec_msg_queue_dqbuf(&inst->ctx->msg_queue.lat_ctx);
+ if (!lat_buf) {
+ mtk_vdec_debug(inst->ctx, "failed to get lat buffer");
+ return -EAGAIN;
+ }
+ share_info = lat_buf->private_data;
+ src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
+
+ buf = (unsigned char *)bs->va;
+ nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
+ if (nal_start_idx < 0) {
+ err = -EINVAL;
+ goto err_free_fb_out;
+ }
+
+ inst->vsi->dec.nal_info = buf[nal_start_idx];
+ 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,
+ &inst->vsi->h264_slice_params);
+ if (err)
+ goto err_free_fb_out;
+
+ vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size,
+ &share_info->h264_slice_params.pps);
+
+ inst->vsi->dec.bs_buf_addr = (uint64_t)bs->dma_addr;
+ inst->vsi->dec.bs_buf_size = bs->size;
+
+ *res_chg = inst->resolution_changed;
+ if (inst->resolution_changed) {
+ mtk_vdec_debug(inst->ctx, "- resolution changed -");
+ if (inst->realloc_mv_buf) {
+ err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
+ inst->realloc_mv_buf = false;
+ if (err)
+ goto err_free_fb_out;
+ }
+ inst->resolution_changed = false;
+ }
+ for (i = 0; i < H264_MAX_MV_NUM; i++) {
+ mem = &inst->mv_buf[i];
+ inst->vsi->mv_buf_dma[i] = mem->dma_addr;
+ }
+ inst->vsi->wdma_start_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
+ inst->vsi->wdma_end_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr +
+ lat_buf->ctx->msg_queue.wdma_addr.size;
+ inst->vsi->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr;
+ inst->vsi->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr;
+ inst->vsi->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr +
+ lat_buf->slice_bc_addr.size;
+
+ inst->vsi->trans_end = inst->ctx->msg_queue.wdma_rptr_addr;
+ inst->vsi->trans_start = inst->ctx->msg_queue.wdma_wptr_addr;
+ mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%llx) err:0x%llx",
+ inst->vsi->wdma_start_addr,
+ inst->vsi->wdma_end_addr,
+ inst->vsi->wdma_err_addr);
+
+ mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%llx) rprt((0x%llx 0x%llx))",
+ inst->vsi->slice_bc_start_addr,
+ inst->vsi->slice_bc_end_addr,
+ inst->vsi->trans_start,
+ inst->vsi->trans_end);
+ err = vpu_dec_start(vpu, data, 2);
+ if (err) {
+ mtk_vdec_debug(inst->ctx, "lat decode err: %d", err);
+ goto err_free_fb_out;
+ }
+
+ share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr +
+ inst->vsi->wdma_end_addr_offset;
+ share_info->trans_start = inst->ctx->msg_queue.wdma_wptr_addr;
+ share_info->nal_info = inst->vsi->dec.nal_info;
+
+ if (IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
+ memcpy(&share_info->h264_slice_params, &inst->vsi->h264_slice_params,
+ sizeof(share_info->h264_slice_params));
+ vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
+ }
+
+ /* wait decoder done interrupt */
+ timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+ WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0);
+ if (timeout)
+ mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num);
+ inst->vsi->dec.timeout = !!timeout;
+
+ err = vpu_dec_end(vpu);
+ if (err == SLICE_HEADER_FULL || err == TRANS_BUFFER_FULL) {
+ if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability))
+ vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf);
+ inst->slice_dec_num++;
+ mtk_vdec_err(inst->ctx, "lat dec fail: pic_%d err:%d", inst->slice_dec_num, err);
+ return -EINVAL;
+ }
+
+ share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr +
+ inst->vsi->wdma_end_addr_offset;
+ vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue, share_info->trans_end);
+
+ if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) {
+ memcpy(&share_info->h264_slice_params, &inst->vsi->h264_slice_params,
+ sizeof(share_info->h264_slice_params));
+ vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf);
+ }
+ mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x 0x%x", inst->slice_dec_num,
+ inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], inst->vsi->dec.crc[2]);
+
+ inst->slice_dec_num++;
+ return 0;
+err_free_fb_out:
+ vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf);
+ mtk_vdec_err(inst->ctx, "slice dec number: %d err: %d", inst->slice_dec_num, err);
+ return err;
+}
+
+static int vdec_h264_slice_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs,
+ struct vdec_fb *unused, bool *res_chg)
{
struct vdec_h264_slice_inst *inst = h_vdec;
struct vdec_vpu_inst *vpu = &inst->vpu;
@@ -928,6 +1174,104 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs
return err;
}
+static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+ struct vdec_fb *unused, bool *res_chg)
+{
+ struct vdec_h264_slice_inst *inst = h_vdec;
+ struct vdec_vpu_inst *vpu = &inst->vpu;
+ struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
+ struct vdec_fb *fb;
+ unsigned char *buf;
+ unsigned int data[2], i;
+ u64 y_fb_dma, c_fb_dma;
+ struct mtk_vcodec_mem *mem;
+ int err, nal_start_idx;
+
+ /* bs NULL means flush decoder */
+ if (!bs)
+ return vpu_dec_reset(vpu);
+
+ fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
+ src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
+ dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
+
+ y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
+ c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
+ mtk_vdec_debug(inst->ctx, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
+ inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
+
+ inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
+ inst->vsi_ctx.dec.bs_buf_size = bs->size;
+ inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
+ inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
+ inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
+
+ v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
+ &dst_buf_info->m2m_buf.vb, true);
+ err = get_vdec_sig_decode_parameters(inst);
+ 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) {
+ err = -EINVAL;
+ goto err_free_fb_out;
+ }
+ inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
+
+ *res_chg = inst->resolution_changed;
+ if (inst->resolution_changed) {
+ mtk_vdec_debug(inst->ctx, "- resolution changed -");
+ if (inst->realloc_mv_buf) {
+ err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
+ inst->realloc_mv_buf = false;
+ if (err)
+ goto err_free_fb_out;
+ }
+ inst->resolution_changed = false;
+
+ for (i = 0; i < H264_MAX_MV_NUM; i++) {
+ mem = &inst->mv_buf[i];
+ inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
+ }
+ }
+
+ memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
+ err = vpu_dec_start(vpu, data, 2);
+ if (err)
+ goto err_free_fb_out;
+
+ /* wait decoder done interrupt */
+ err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+ WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
+ if (err)
+ mtk_vdec_err(inst->ctx, "decode timeout: pic_%d", inst->ctx->decoded_frame_cnt);
+
+ inst->vsi->dec.timeout = !!err;
+ err = vpu_dec_end(vpu);
+ if (err)
+ goto err_free_fb_out;
+
+ memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
+ mtk_vdec_debug(inst->ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
+ inst->ctx->decoded_frame_cnt,
+ inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
+ inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
+ inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
+ inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
+
+ inst->ctx->decoded_frame_cnt++;
+ return 0;
+
+err_free_fb_out:
+ mtk_vdec_err(inst->ctx, "dec frame number: %d err: %d", inst->ctx->decoded_frame_cnt, err);
+ return err;
+}
+
static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
struct vdec_fb *unused, bool *res_chg)
{
@@ -937,8 +1281,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);
+ else
+ ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
+
+ return ret;
+ }
+
+ if (IS_VDEC_SUPPORT_EX(inst->ctx->dev->dec_capability))
+ ret = vdec_h264_slice_lat_decode_ex(h_vdec, bs, unused, res_chg);
else
ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
--
2.46.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] media: mediatek: vcodec: remove parse nal info in kernel
2024-10-16 3:49 [PATCH v2 0/6] media: mediatek: vcodec: support h264 extend vsi Yunfei Dong
` (2 preceding siblings ...)
2024-10-16 3:49 ` [PATCH v2 3/4] media: mediatek: vcodec: support extend h264 driver Yunfei Dong
@ 2024-10-16 3:49 ` Yunfei Dong
2024-10-22 7:10 ` Chen-Yu Tsai
3 siblings, 1 reply; 8+ messages in thread
From: Yunfei Dong @ 2024-10-16 3:49 UTC (permalink / raw)
To: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida
Cc: Hsin-Yi Wang, Chen-Yu Tsai, Fritz Koenig, Daniel Vetter,
Steve Cho, Yunfei Dong, linux-media, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
Hardware can parse the slice syntax to get nal information in
scp for extend architecture, needn't to parse it again in
kernel.
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
.../decoder/vdec/vdec_h264_req_multi_if.c | 24 +++----------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
index 69ca775bb3f1..c99a64384edf 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
@@ -802,11 +802,10 @@ static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs
struct vdec_h264_slice_inst *inst = h_vdec;
struct vdec_vpu_inst *vpu = &inst->vpu;
struct mtk_video_dec_buf *src_buf_info;
- int nal_start_idx, err, timeout = 0;
+ int err, timeout = 0;
unsigned int data[2];
struct vdec_lat_buf *lat_buf;
struct vdec_h264_slice_share_info *share_info;
- unsigned char *buf;
if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx,
vdec_h264_slice_core_decode_ex,
@@ -830,14 +829,6 @@ static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs
share_info = lat_buf->private_data;
src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
- buf = (unsigned char *)bs->va;
- nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
- if (nal_start_idx < 0) {
- err = -EINVAL;
- goto err_free_fb_out;
- }
-
- inst->vsi->dec.nal_info = buf[nal_start_idx];
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);
@@ -846,7 +837,7 @@ static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs
if (err)
goto err_free_fb_out;
- vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size,
+ vdec_h264_insert_startcode(inst->ctx->dev, bs->va, &bs->size,
&share_info->h264_slice_params.pps);
*res_chg = inst->resolution_changed;
@@ -1078,11 +1069,10 @@ static int vdec_h264_slice_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem
struct vdec_vpu_inst *vpu = &inst->vpu;
struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
struct vdec_fb *fb;
- unsigned char *buf;
unsigned int data[2], i;
u64 y_fb_dma, c_fb_dma;
struct mtk_vcodec_mem *mem;
- int err, nal_start_idx;
+ int err;
/* bs NULL means flush decoder */
if (!bs)
@@ -1117,14 +1107,6 @@ static int vdec_h264_slice_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem
memcpy(&inst->vsi_ctx_ex.h264_slice_params, &inst->h264_slice_param,
sizeof(inst->vsi_ctx_ex.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) {
- err = -EINVAL;
- goto err_free_fb_out;
- }
- inst->vsi_ctx_ex.dec.nal_info = buf[nal_start_idx];
-
*res_chg = inst->resolution_changed;
if (inst->resolution_changed) {
mtk_vdec_debug(inst->ctx, "- resolution changed -");
--
2.46.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface
2024-10-16 3:49 ` [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface Yunfei Dong
@ 2024-10-22 3:58 ` Chen-Yu Tsai
0 siblings, 0 replies; 8+ messages in thread
From: Chen-Yu Tsai @ 2024-10-22 3:58 UTC (permalink / raw)
To: Yunfei Dong
Cc: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida, Hsin-Yi Wang,
Fritz Koenig, Daniel Vetter, Steve Cho, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
On Wed, Oct 16, 2024 at 11:49 AM Yunfei Dong <yunfei.dong@mediatek.com> wrote:
>
> Remove vsi related operation in common interface to make sure the
> interface can be called by different architecture at the same time.
Nit: it would be nice to provide more context here. You could mention
that a new extended interface with a different shared memory layout (vsi)
will be introduced in later patches.
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
> .../decoder/vdec/vdec_h264_req_multi_if.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> index 732d78f63e5a..57c85af5ffb4 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> @@ -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_data)
Nit: you could just name this new parameter |slice_param| and avoid the
changes in the next bit.
> {
> - 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;
> @@ -203,9 +203,9 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
> return -EINVAL;
> }
>
> - mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> - mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> - mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, src_matrix);
> + mtk_vdec_h264_copy_sps_params(&slice_data->sps, sps);
> + mtk_vdec_h264_copy_pps_params(&slice_data->pps, pps);
> + mtk_vdec_h264_copy_scaling_matrix(&slice_data->scaling_matrix, src_matrix);
>
> memcpy(&share_info->sps, sps, sizeof(*sps));
> memcpy(&share_info->dec_params, dec_params, sizeof(*dec_params));
> @@ -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) {
Code wise this patch seems fine.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/4] media: mediatek: vcodec: support extend h264 video shared information
2024-10-16 3:49 ` [PATCH v2 2/4] media: mediatek: vcodec: support extend h264 video shared information Yunfei Dong
@ 2024-10-22 7:08 ` Chen-Yu Tsai
0 siblings, 0 replies; 8+ messages in thread
From: Chen-Yu Tsai @ 2024-10-22 7:08 UTC (permalink / raw)
To: Yunfei Dong
Cc: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida, Hsin-Yi Wang,
Fritz Koenig, Daniel Vetter, Steve Cho, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
On Wed, Oct 16, 2024 at 11:49 AM Yunfei Dong <yunfei.dong@mediatek.com> wrote:
>
> The address end of working buffer can't be calculated directly
> with buffer size in kernel for some special architecture. Adding
> new extend vsi to calculate the address end in other os.
> Refactoring the driver flow to make the driver looks more reasonable.
>
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
> .../decoder/vdec/vdec_h264_req_multi_if.c | 355 ++++++++++++------
> 1 file changed, 238 insertions(+), 117 deletions(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> index 57c85af5ffb4..e02ed8dfe0ce 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> @@ -48,10 +48,29 @@ struct vdec_h264_slice_lat_dec_param {
> };
>
> /**
> - * struct vdec_h264_slice_info - decode information
> + * struct vdec_h264_slice_info_ex - extend decode information
Please move these structs around so that the extended ones are
grouped together.
My suggestion is to keep |struct vdec_h264_slice_lat_dec_param|,
|struct vdec_h264_slice_info| and |struct vdec_h264_slice_vsi| at
the top of the file, and add the new ones below them. That way
the ones related are together, and also git won't produce such
a hard to read diff.
Please also mark every struct that is included in the `vsi` shared
memory struct as "shared interface with firmware" so that they do
not get changed accidentally.
> *
> + * @wdma_end_addr_offset: offset from buffer start
> * @nal_info: nal info of current picture
> * @timeout: Decode timeout: 1 timeout, 0 no timeout
> + * @vdec_fb_va: VDEC frame buffer struct virtual address
> + * @crc: Used to check whether hardware's status is right
> + * @reserved: reserved
> + */
> +struct vdec_h264_slice_info_ex {
> + u64 wdma_end_addr_offset;
> + u16 nal_info;
> + u16 timeout;
There is a 4 byte hole here. Can you make it explicit by adding
an extra reserved field?
> + u64 vdec_fb_va;
> + u32 crc[8];
> + u32 reserved;
> +};
> +
> +/**
> + * struct vdec_h264_slice_info - decode information
> + *
> + * @nal_info: nal info of current picture
> + * @timeout: Decode timeout: 1 timeout, 0 no timeount
> * @bs_buf_size: bitstream size
> * @bs_buf_addr: bitstream buffer dma address
> * @y_fb_dma: Y frame buffer dma address
> @@ -70,6 +89,64 @@ struct vdec_h264_slice_info {
> u32 crc[8];
> };
>
> +/*
> + * struct vdec_h264_slice_mem - memory address and size
> + */
> +struct vdec_h264_slice_mem {
> + union {
> + u64 buf;
> + u64 dma_addr;
> + };
> + union {
> + size_t size;
> + u64 dma_addr_end;
> + };
> +};
> +
> +/**
> + * struct vdec_h264_slice_fb - frame buffer for decoding
> + *
> + * @y: current y buffer address info
> + * @c: current c buffer address info
> + */
> +struct vdec_h264_slice_fb {
> + struct vdec_h264_slice_mem y;
> + struct vdec_h264_slice_mem c;
> +};
> +
> +/**
> + * struct vdec_h264_slice_vsi_ex - extend shared memory for decode information exchange
> + * between SCP and Host.
> + *
> + * @bs: input buffer info
> + * @fb: current y/c buffer
> + *
> + * @ube: ube buffer
> + * @trans: transcoded buffer
> + * @row_info: row info buffer
> + * @err_map: err map buffer
> + * @slice_bc: slice buffer
> + *
> + * @mv_buf_dma: HW working motion vector buffer
> + * @dec: decode information (AP-R, VPU-W)
> + * @h264_slice_params: decode parameters for hw used
> + */
> +struct vdec_h264_slice_vsi_ex {
> + /* LAT dec addr */
> + struct vdec_h264_slice_mem bs;
> + struct vdec_h264_slice_fb fb;
> +
> + struct vdec_h264_slice_mem ube;
> + struct vdec_h264_slice_mem trans;
> + struct vdec_h264_slice_mem row_info;
> + struct vdec_h264_slice_mem err_map;
> + struct vdec_h264_slice_mem slice_bc;
> +
> + struct vdec_h264_slice_mem mv_buf_dma[H264_MAX_MV_NUM];
> + struct vdec_h264_slice_info_ex dec;
> + struct vdec_h264_slice_lat_dec_param h264_slice_params;
> +};
> +
> /**
> * struct vdec_h264_slice_vsi - shared memory for decode information exchange
> * between SCP and Host.
> @@ -136,10 +213,10 @@ struct vdec_h264_slice_share_info {
> * @pred_buf: HW working prediction buffer
> * @mv_buf: HW working motion vector buffer
> * @vpu: VPU instance
> - * @vsi: vsi used for lat
> - * @vsi_core: vsi used for core
> + * @vsi_ex: extend vsi used for lat
> + * @vsi_core_ex: extend vsi used for core
> *
> - * @vsi_ctx: Local VSI data for this decoding context
> + * @vsi_ctx_ex: Local extend vsi data for this decoding context
> * @h264_slice_param: the parameters that hardware use to decode
> *
> * @resolution_changed:resolution changed
> @@ -156,10 +233,19 @@ struct vdec_h264_slice_inst {
> struct mtk_vcodec_mem pred_buf;
> struct mtk_vcodec_mem mv_buf[H264_MAX_MV_NUM];
> struct vdec_vpu_inst vpu;
> - struct vdec_h264_slice_vsi *vsi;
> - struct vdec_h264_slice_vsi *vsi_core;
> -
> - struct vdec_h264_slice_vsi vsi_ctx;
> + union {
> + struct vdec_h264_slice_vsi_ex *vsi_ex;
> + struct vdec_h264_slice_vsi *vsi;
> + };
> + union {
> + struct vdec_h264_slice_vsi_ex *vsi_core_ex;
> + struct vdec_h264_slice_vsi *vsi_core;
> + };
> +
> + union {
> + struct vdec_h264_slice_vsi_ex vsi_ctx_ex;
> + struct vdec_h264_slice_vsi vsi_ctx;
> + };
Code wise I think it would be better to have a union of structs of structs:
union {
struct {
struct vdec_h264_slice_vsi *vsi;
struct vdec_h264_slice_vsi *vsi_core;
struct vdec_h264_slice_vsi vsi_ctx;
};
struct {
struct vdec_h264_slice_vsi_ex *vsi_ex;
struct vdec_h264_slice_vsi_ex *vsi_core_ex;
struct vdec_h264_slice_vsi_ex vsi_ctx_ex;
};
};
This makes it clear that the *_ex variants are used together.
The code compiles down to the same layout.
> struct vdec_h264_slice_lat_dec_param h264_slice_param;
>
> unsigned int resolution_changed;
> @@ -389,6 +475,98 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst,
> cr->left, cr->top, cr->width, cr->height);
> }
>
> +static void vdec_h264_slice_setup_lat_buffer(struct vdec_h264_slice_inst *inst,
Please add the "_ex" suffix to mark this function as used for the extended
architecture.
> + struct mtk_vcodec_mem *bs,
> + struct vdec_lat_buf *lat_buf)
> +{
> + struct mtk_vcodec_mem *mem;
> + int i;
> +
> + inst->vsi_ex->bs.dma_addr = (u64)bs->dma_addr;
> + inst->vsi_ex->bs.size = bs->size;
> +
> + for (i = 0; i < H264_MAX_MV_NUM; i++) {
> + mem = &inst->mv_buf[i];
> + inst->vsi_ex->mv_buf_dma[i].dma_addr = mem->dma_addr;
> + inst->vsi_ex->mv_buf_dma[i].size = mem->size;
> + }
> + inst->vsi_ex->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
> + inst->vsi_ex->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size;
> +
> + inst->vsi_ex->row_info.dma_addr = 0;
> + inst->vsi_ex->row_info.size = 0;
> +
> + inst->vsi_ex->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr;
> + inst->vsi_ex->err_map.size = lat_buf->wdma_err_addr.size;
> +
> + inst->vsi_ex->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr;
> + inst->vsi_ex->slice_bc.size = lat_buf->slice_bc_addr.size;
> +
> + inst->vsi_ex->trans.dma_addr_end = inst->ctx->msg_queue.wdma_rptr_addr;
> + inst->vsi_ex->trans.dma_addr = inst->ctx->msg_queue.wdma_wptr_addr;
> +}
> +
> +static int vdec_h264_slice_setup_core_buffer(struct vdec_h264_slice_inst *inst,
> + struct vdec_h264_slice_share_info *share_info,
> + struct vdec_lat_buf *lat_buf)
Same here.
> +{
> + struct mtk_vcodec_mem *mem;
> + struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
> + struct vb2_v4l2_buffer *vb2_v4l2;
> + struct vdec_fb *fb;
> + u64 y_fb_dma, c_fb_dma = 0;
> + int i;
> +
> + fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx);
> + if (!fb) {
> + mtk_vdec_err(ctx, "fb buffer is NULL");
> + return -EBUSY;
> + }
> +
> + y_fb_dma = (u64)fb->base_y.dma_addr;
> + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1)
> + c_fb_dma =
> + y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h;
> + else
> + c_fb_dma = (u64)fb->base_c.dma_addr;
> +
> + mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma);
> +
> + inst->vsi_core_ex->fb.y.dma_addr = y_fb_dma;
> + inst->vsi_core_ex->fb.y.size = ctx->picinfo.fb_sz[0];
> + inst->vsi_core_ex->fb.c.dma_addr = c_fb_dma;
> + inst->vsi_core_ex->fb.c.size = ctx->picinfo.fb_sz[1];
> +
> + inst->vsi_core_ex->dec.vdec_fb_va = (unsigned long)fb;
> + inst->vsi_core_ex->dec.nal_info = share_info->nal_info;
> +
> + inst->vsi_core_ex->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr;
> + inst->vsi_core_ex->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size;
> +
> + inst->vsi_core_ex->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr;
> + inst->vsi_core_ex->err_map.size = lat_buf->wdma_err_addr.size;
> +
> + inst->vsi_core_ex->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr;
> + inst->vsi_core_ex->slice_bc.size = lat_buf->slice_bc_addr.size;
> +
> + inst->vsi_core_ex->row_info.dma_addr = 0;
> + inst->vsi_core_ex->row_info.size = 0;
> +
> + inst->vsi_core_ex->trans.dma_addr = share_info->trans_start;
> + inst->vsi_core_ex->trans.dma_addr_end = share_info->trans_end;
> +
> + for (i = 0; i < H264_MAX_MV_NUM; i++) {
> + mem = &inst->mv_buf[i];
> + inst->vsi_core_ex->mv_buf_dma[i].dma_addr = mem->dma_addr;
> + inst->vsi_core_ex->mv_buf_dma[i].size = mem->size;
> + }
> +
> + vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
> + v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true);
> +
> + return 0;
> +}
> +
> static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
> {
> struct vdec_h264_slice_inst *inst;
> @@ -412,10 +590,10 @@ static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
> goto error_free_inst;
> }
>
> - vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi), VCODEC_DEC_ALIGNED_64);
> - inst->vsi = inst->vpu.vsi;
> - inst->vsi_core =
> - (struct vdec_h264_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size);
> + vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi_ex), VCODEC_DEC_ALIGNED_64);
> + inst->vsi_ex = inst->vpu.vsi;
> + inst->vsi_core_ex =
> + (struct vdec_h264_slice_vsi_ex *)(((char *)inst->vpu.vsi) + vsi_size);
Changing this here without any feature checking will break existing
platforms because the vsi_core pointer now points to the wrong address.
You can't change the existing code path in a non backwards compatible
way in one patch then fix it back up in the next patch. It has to be
done at the same time.
In other words, existing platforms _must_ continue to work throughout
your patch series, i.e. with only patches 1 & 2 applied, MT8192 / MT8195
should continue to work properly.
Looking at this patch more, it seems that it is better to squash patches
2 & 3 together. The two patches are working on the same thing: adding
support for the extended architecture. Having the changes together in
one single patch makes more sense.
ChenYu
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 4/4] media: mediatek: vcodec: remove parse nal info in kernel
2024-10-16 3:49 ` [PATCH v2 4/4] media: mediatek: vcodec: remove parse nal info in kernel Yunfei Dong
@ 2024-10-22 7:10 ` Chen-Yu Tsai
0 siblings, 0 replies; 8+ messages in thread
From: Chen-Yu Tsai @ 2024-10-22 7:10 UTC (permalink / raw)
To: Yunfei Dong
Cc: Nícolas F . R . A . Prado, Sebastian Fricke,
Nicolas Dufresne, Hans Verkuil, AngeloGioacchino Del Regno,
Benjamin Gaignard, Nathan Hebert, Daniel Almeida, Hsin-Yi Wang,
Fritz Koenig, Daniel Vetter, Steve Cho, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group
On Wed, Oct 16, 2024 at 11:49 AM Yunfei Dong <yunfei.dong@mediatek.com> wrote:
>
> Hardware can parse the slice syntax to get nal information in
> scp for extend architecture, needn't to parse it again in
> kernel.
Squash this in with the other "add extended architecture" patches.
You are removing code that you just added. So why add it in the
first place?
You can just mention in the commit message that the new architecture
can parse the slice syntax directly.
ChenYu
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
> .../decoder/vdec/vdec_h264_req_multi_if.c | 24 +++----------------
> 1 file changed, 3 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> index 69ca775bb3f1..c99a64384edf 100644
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
> @@ -802,11 +802,10 @@ static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs
> struct vdec_h264_slice_inst *inst = h_vdec;
> struct vdec_vpu_inst *vpu = &inst->vpu;
> struct mtk_video_dec_buf *src_buf_info;
> - int nal_start_idx, err, timeout = 0;
> + int err, timeout = 0;
> unsigned int data[2];
> struct vdec_lat_buf *lat_buf;
> struct vdec_h264_slice_share_info *share_info;
> - unsigned char *buf;
>
> if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx,
> vdec_h264_slice_core_decode_ex,
> @@ -830,14 +829,6 @@ static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs
> share_info = lat_buf->private_data;
> src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
>
> - buf = (unsigned char *)bs->va;
> - nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> - if (nal_start_idx < 0) {
> - err = -EINVAL;
> - goto err_free_fb_out;
> - }
> -
> - inst->vsi->dec.nal_info = buf[nal_start_idx];
> 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);
>
> @@ -846,7 +837,7 @@ static int vdec_h264_slice_lat_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs
> if (err)
> goto err_free_fb_out;
>
> - vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size,
> + vdec_h264_insert_startcode(inst->ctx->dev, bs->va, &bs->size,
> &share_info->h264_slice_params.pps);
>
> *res_chg = inst->resolution_changed;
> @@ -1078,11 +1069,10 @@ static int vdec_h264_slice_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem
> struct vdec_vpu_inst *vpu = &inst->vpu;
> struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> struct vdec_fb *fb;
> - unsigned char *buf;
> unsigned int data[2], i;
> u64 y_fb_dma, c_fb_dma;
> struct mtk_vcodec_mem *mem;
> - int err, nal_start_idx;
> + int err;
>
> /* bs NULL means flush decoder */
> if (!bs)
> @@ -1117,14 +1107,6 @@ static int vdec_h264_slice_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem
> memcpy(&inst->vsi_ctx_ex.h264_slice_params, &inst->h264_slice_param,
> sizeof(inst->vsi_ctx_ex.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) {
> - err = -EINVAL;
> - goto err_free_fb_out;
> - }
> - inst->vsi_ctx_ex.dec.nal_info = buf[nal_start_idx];
> -
> *res_chg = inst->resolution_changed;
> if (inst->resolution_changed) {
> mtk_vdec_debug(inst->ctx, "- resolution changed -");
> --
> 2.46.0
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-10-22 7:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-16 3:49 [PATCH v2 0/6] media: mediatek: vcodec: support h264 extend vsi Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 1/4] media: mediatek: vcodec: remove vsi operation in common interface Yunfei Dong
2024-10-22 3:58 ` Chen-Yu Tsai
2024-10-16 3:49 ` [PATCH v2 2/4] media: mediatek: vcodec: support extend h264 video shared information Yunfei Dong
2024-10-22 7:08 ` Chen-Yu Tsai
2024-10-16 3:49 ` [PATCH v2 3/4] media: mediatek: vcodec: support extend h264 driver Yunfei Dong
2024-10-16 3:49 ` [PATCH v2 4/4] media: mediatek: vcodec: remove parse nal info in kernel Yunfei Dong
2024-10-22 7:10 ` Chen-Yu Tsai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).