media: mediatek: vcodec: support h264 extend vsi
Subsystems (3)
Yunfei Dong
maintainerv6 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.
---
compared with v5:
- add some parameters comment for patch 2
compared with v4:
- rebase this patch series with latest vcodec driver
compared with v3:
- change code logic with callback to decode for patch 2
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 | 593 ++++++++++++++++-- 2 files changed, 528 insertions(+), 67 deletions(-)
Signature · 1 line
2.46.0
Yunfei Dong
maintainerPATCH v6 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
@@ -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->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req;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 *bsif (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
Re: [PATCH v6 1/3] media: mediatek: vcodec: remove vsi operation in common interface
Hey Yunfei,
Quoted 6 lines · Yunfei Dong
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.
My recommendation:
Extend the VSI (video shared information) struct to allow sending slice parameters to SCP, as the parameters have changed on MT8188 architecture. Remove VSI related information from the common interface to ensure, that the interface is usable by architectures with and without the extended parameters. The new VSI extensions will be introduced in later patches.
The rest looks good to me.
Regards,
Sebastian Fricke
Quoted 55 lines
Reviewed-by Chen-Yu Tsai <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>---
.../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@@ -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->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req;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 *bsif (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
Yunfei Dong
maintainerPATCH v6 2/3 media: mediatek: vcodec: support extended h264 decode
In reply to Yunfei DongThe 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 | 575 ++++++++++++++++-- 2 files changed, 518 insertions(+), 59 deletions(-)
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +2 -0
@@ -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 +516 -59
666 lines not on this page · raw message
Signature · 1 line
2.46.0
Re: [PATCH v6 2/3] media: mediatek: vcodec: support extended h264 decode
Hey Yunfei,
Quoted 7 lines · 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_exto 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.
I'd recommend changing this to:
Add a new extended vsi_ext struct besides the existing vsi struct, to enable calculating the end of the adress range of the current working buffer for architectures, where simply adding the buffer size to the start of the address range isn't sufficient.
Additionally, on extended architectures, the NAL information can be fetched directly from the firmware, which allows skipping the parsing step within the kernel.
Also, this sentence:
Quoted 2 lines
Adding capability to separate extend and non extend driver for different platform.
Is a bit ambigious for me and doesn't seem to be something worth mentioning. But maybe I misunderstand your point here.
Quoted 13 lines
Signed-off-by Yunfei Dong <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>---
.../vcodec/decoder/mtk_vcodec_dec_drv.h| 2 +.../decoder/vdec/vdec_h264_req_multi_if.c| 575 ++++++++++++++++--2 files changed, 518 insertions(+), 59 deletions(-)drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +0
-0
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h line 20
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +1
-0@@ -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)
I'd recommend changing this to: IS_VDEC_SUPPORT_EXT as EXT is way less ambigious acronym for extension, EX could mean way more. You'll see me mentioning that below a couple of times.
Quoted 27 lines
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +1
-0enum 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 +8
-0@@ -128,6 +128,83 @@ struct vdec_h264_slice_share_info {u16 nal_info; }; +/* +* struct vdec_h264_slice_mem - memory address and size (shared interface with firmware) +*/ +struct vdec_h264_slice_mem { +union { +u64 buf; +u64 dma_addr; + };
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 148
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+union { +size_t size; +u64 dma_addr_end; + }; +}; + +/** +* struct vdec_h264_slice_fb - frame buffer for decoding (shared interface with firmware) +* +* @y: current y buffer address info
As this is a description I'd say lets describe a bit more detailed and rewrite this to: "@y: current luma buffer address info"
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 149
Quoted 1 line
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-0+* @c: current c buffer address info
... and "@c: current chroma buffer address info"
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 157
Quoted 8 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +8
-0+*/ +struct vdec_h264_slice_fb { +struct vdec_h264_slice_mem y; +struct vdec_h264_slice_mem c; +}; + +/** +* struct vdec_h264_slice_info_ex - extend decode information (shared interface with firmware)
Can we call this also ..info_ext please?
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 161
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+* +* @wdma_end_addr_offset: offset from buffer start +* @nal_info: nal info of current picture +* @timeout: Decode timeout: 1 timeout, 0 no timeout
I'd rename the description to: "Toggles whether a decode operation can timeout" Then the effect of 1 and 0 becomes obvious.
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 164
Quoted 3 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+* @reserved: reserved +* @vdec_fb_va: VDEC frame buffer struct virtual address +* @crc: Used to check whether hardware's status is right
I'd rename this to: "Displays the hardware status" Saying whether a status is "right" is rather ambigious.
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 166
Quoted 2 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-0+*/ +struct vdec_h264_slice_info_ex {
... and this ... info_ext
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 176
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+u64 wdma_end_addr_offset; +u16 nal_info; +u16 timeout; +u32 reserved; +u64 vdec_fb_va; +u32 crc[8 ]; +}; + +/** +* struct vdec_h264_slice_vsi_ex - extend shared memory for decode information exchange
s/vsi_ex/vsi_ext/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 182
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+* between SCP and Host (shared interface with firmware). +* +* @bs: input buffer info +* @fb: current y/c buffer +* +* @ube: ube buffer
While we are at it and this acronym isn't terrible self-descriptive could you write in the description what ube stands for?
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 188
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+* @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
HW working sounds weird, do you want to say the current?
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 190
Quoted 2 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-0+* @dec: decode information (AP-R, VPU-W) +* @h264_slice_params: decode parameters for hw used
s/for hw used/used for the hw/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 192
Quoted 2 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-0+*/ +struct vdec_h264_slice_vsi_ex {
s/vsi_ex/vsi_ext/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 204
Quoted 12 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +12
-0+/* 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;
s/info_ex/info_ext/
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+struct vdec_h264_slice_lat_dec_param h264_slice_params; +}; +/** * struct vdec_h264_slice_inst - h264 decoder instance *
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 219
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-2@@ -138,8 +215,10 @@ struct vdec_h264_slice_share_info {* @vpu: VPU instance * @vsi: vsi used for lat * @vsi_core: vsi used for core -* -* @vsi_ctx: Local VSI data for this decoding context +* @vsi_ctx: Local vsi data for this decoding context +* @vsi_ex: extend vsi used for lat
s/vsi_ex/vsi_ext/
s/extend/extended/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 220
Quoted 1 line
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-0+* @vsi_core_ex: extend vsi used for core
s/vsi_core_ex/vsi_core_ext/
s/extend/extended/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 221
Quoted 1 line
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-0+* @vsi_ctx_ex: Local extend vsi data for this decoding context
s/vsi_ctx_ex/vsi_ctx_ext/
s/extend/extended/
Also you can drop the word Local as that is clear already with:
"for this decoding context"
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 230
Quoted 9 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-1* @h264_slice_param: the parameters that hardware use to decode * * @resolution_changed:resolution changed @@ -148,7 +227,9 @@ struct vdec_h264_slice_share_info {* * @dpb: decoded picture buffer used to store reference * buffer information -*@is_field_bitstream: is field bitstream +* @is_field_bitstream: is field bitstream
That is not a description, that is a repetition :)
Please make this a bit more descriptive. Like do you describe anywhere else already what a field bitstream is and how it differentiates from the alternative?
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 232
Quoted 2 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-0+* +* @decode: lat decoder pointer for different architecture
s/architecture/architectures/
Quoted 11 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +0
-4*/ struct vdec_h264_slice_inst {unsigned int slice_dec_num;@@ -156,10 +237,18 @@ 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;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_inst { · line 249
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+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;
s/vsi_ex/vsi_ext/
s/vsi_core_ex/vsi_core_ext/
s/vsi_ctx_ex/vsi_ctx_ext/
Quoted 16 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-0+ }; + };struct vdec_h264_slice_lat_dec_param h264_slice_param;unsigned int resolution_changed;@@ -168,6 +257,9 @@ struct vdec_h264_slice_inst {struct v4l2_h264_dpb_entry dpb[16 ];bool is_field_bitstream; + +int (*decode)(void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *unused,bool *res_chg); }; static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *inst,
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 484
Quoted 5 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-1@@ -389,62 +481,143 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, cr->left, cr->top, cr->width, cr->height); } -static int vdec_h264_slice_init (struct mtk_vcodec_dec_ctx *ctx) +static void vdec_h264_slice_setup_lat_buffer_ex(struct vdec_h264_slice_inst *inst,
s/buffer_ex/buffer_ext/
Quoted 8 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-2+struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf) { -struct vdec_h264_slice_inst *inst; -int err, vsi_size; + struct mtk_vcodec_mem *mem; +int i;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 496
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-4- inst =kzalloc (sizeof (*inst),GFP_KERNEL ); -if (!inst) -return -ENOMEM ; + inst->vsi_ex->bs.dma_addr = (u64 )bs->dma_addr; + inst->vsi_ex->bs.size = bs->size; - inst->ctx = ctx; +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;
s/vsi_ex/vsi_ext/
and in all other cases below ...
Quoted 18 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-9+ 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->vpu.id =SCP_IPI_VDEC_LAT ; - inst->vpu.core_id =SCP_IPI_VDEC_CORE ; - inst->vpu.ctx = ctx; - inst->vpu.codec_type = ctx->current_codec; - inst->vpu.capture_type = ctx->capture_fourcc; + inst->vsi_ex->row_info.dma_addr =0 ; + inst->vsi_ex->row_info.size =0 ; - err =vpu_dec_init (&inst->vpu); -if (err) { -mtk_vdec_err (ctx,"vdec_h264 init err=%d" , err); - goto error_free_inst; + inst->vsi_ex->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 515
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+ 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_ex(struct vdec_h264_slice_inst *inst,
s/buffer_ex/buffer_ext/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 528
Quoted 13 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +13
-0+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" );
A frame buffer buffer sounds a bit repetitive, lets just call it frame buffer. Also this error message tells the user nothing. When I look at the function within mtk_vcodec_dec_stateless it looks like the only way we get a NULL here is if v4l2_m2m_next_dst_buf returns nothing, e.g. if we don't have a next destination buffer. Can you confirm this? If that is the case a better error message would be:
"Unable to get a CAPTURE buffer, because the CAPTURE queue is empty" Or something along those lines.
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 535
Quoted 13 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-6+return -EBUSY ; } - 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); - inst->resolution_changed = true; - inst->realloc_mv_buf = true; + 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;
Looks like it is worth it to create a separate variable for picinfo as you use it here and below, so that you can do a bit less copy-paste.
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-3+else + c_fb_dma = (u64 )fb->base_c.dma_addr; - mtk_vdec_debug(ctx, "lat struct size = %d,%d,%d,%d vsi: %d\n", - (int)sizeof(struct mtk_h264_sps_param), - (int)sizeof(struct mtk_h264_pps_param),
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 541
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-7- (int )sizeof (struct vdec_h264_slice_lat_dec_param ), - (int )sizeof (struct mtk_h264_dpb_info ), - vsi_size); -mtk_vdec_debug (ctx,"lat H264 instance >> %p, codec_type = 0x%x" , - inst, inst->vpu.codec_type); +mtk_vdec_debug (ctx,"[h264-core] y/c addr = 0x%llx 0x%llx" , y_fb_dma, c_fb_dma); - ctx->drv_handle = inst; -return 0 ; + inst->vsi_core_ex->fb.y.dma_addr = y_fb_dma;
s/vsi_core_ex/vsi_core_ext/
and everywhere below ...
Quoted 29 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +25
-3+ 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 ]; -error_free_inst: -kfree (inst); -return err; + 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;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 576
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-1+ } + + 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 void vdec_h264_slice_deinit (void *h_vdec) +static int vdec_h264_slice_core_decode_ex (struct vdec_lat_buf *lat_buf)
s/decode_ex/decode_ext/
No no no, I don't like this or vdec_h264_slice_lat_decode_ex you basically just duplicated the whole decode function in both cases and added a few extended bits to them. Unless the two routines are substantially different (which from my point of view they are not) you should be able to create conditional branches for the extended bits into the decode functions.
But please also look at my general comments in the functions, I'd still like to know why timeouts are handled the way they are and whether the status of a device can be made a bit more obvious to the user.
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 584
Quoted 12 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-4{ -struct vdec_h264_slice_inst *inst = h_vdec; +int err, timeout; +struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx; +struct vdec_h264_slice_inst *inst = ctx->drv_handle; +struct vdec_h264_slice_share_info *share_info = lat_buf->private_data; +struct vdec_vpu_inst *vpu = &inst->vpu; -vpu_dec_deinit (&inst->vpu); -vdec_h264_slice_free_mv_buf (inst); -vdec_msg_queue_deinit (&inst->ctx->msg_queue, inst->ctx); +mtk_vdec_debug (ctx,"[h264-core] vdec_h264 core decode" );
This looks like a left over development comment, this is not useful for general debugging and shouldn't be upstreamed.
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 588
Quoted 5 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-1+memcpy (&inst->vsi_core_ex->h264_slice_params, &share_info->h264_slice_params, +sizeof (share_info->h264_slice_params)); -kfree (inst); + err =vdec_h264_slice_setup_core_buffer_ex (inst, share_info, lat_buf);
s/buffer_ex/buffer_ext/
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+if (err) + goto vdec_dec_end; + +vdec_h264_slice_fill_decode_reflist (inst, &inst->vsi_core_ex->h264_slice_params, + share_info); + err =vpu_dec_core (vpu);
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 604
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+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);
So as you don't bail out here, it looks like this conditional branch will end up returning 0. Why do you return 0 on a timeout? Isn't a timeout a failed decode?
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 613
Quoted 9 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +9
-0+ 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_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 ]);
Can you add a small comment above this that explains to the user what these CRCs are supposed to mean?
Quoted 140 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +128
-0+ +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->src_buf_req); +mtk_vdec_debug (ctx,"core decode done err=%d" , err); + ctx->decoded_frame_cnt++; +return 0 ; }static int vdec_h264_slice_core_decode (struct vdec_lat_buf *lat_buf)@@ -559,6 +732,127 @@ static void vdec_h264_insert_startcode(struct mtk_vcodec_dec_dev *vcodec_dev, un (*bs_size) +=4 ; } +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; +struct mtk_video_dec_buf *src_buf_info; +int err, timeout =0 ; +unsigned int data[2 ]; +struct vdec_lat_buf *lat_buf; +struct vdec_h264_slice_share_info *share_info; + +if (vdec_msg_queue_init (&inst->ctx->msg_queue, inst->ctx, + vdec_h264_slice_core_decode_ex, +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); + + lat_buf->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; +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_ex->h264_slice_params); +if (err) + goto err_free_fb_out; + +vdec_h264_insert_startcode (inst->ctx->dev, bs->va, &bs->size, + &share_info->h264_slice_params.pps); + + *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; + } + +vdec_h264_slice_setup_lat_buffer_ex (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); + goto err_free_fb_out; + } + + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + 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_ex->dec.nal_info; + +if (IS_VDEC_INNER_RACING (inst->ctx->dev->dec_capability)) { +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); + } + +/* 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_ex->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_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_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_ex->dec.crc[0 ], inst->vsi_ex->dec.crc[1 ], + inst->vsi_ex->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_lat_decode (void *h_vdec,struct mtk_vcodec_mem *bs,struct vdec_fb *fb,bool *res_chg){
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, · line 1001
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-2@@ -704,18 +998,17 @@ 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_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs,
s/decode_ex/decode_ext/
Quoted 131 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +107
-2+ 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; +int err;/* bs NULL means flush decoder */ if (!bs)@@ -735,6 +1028,96 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bsmtk_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_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); + err =get_vdec_sig_decode_parameters (inst); +if (err) + goto err_free_fb_out; + +memcpy (&inst->vsi_ctx_ex.h264_slice_params, &inst->h264_slice_param, +sizeof (inst->vsi_ctx_ex.h264_slice_params)); + + *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_ex.mv_buf_dma[i].dma_addr = mem->dma_addr; + } + } + +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; + +/* 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_ex->dec.timeout = !!err; + err =vpu_dec_end (vpu); +if (err) + goto err_free_fb_out; + +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_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 ; + +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_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;@@ -807,21 +1190,95 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bsreturn err; } +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) +return -ENOMEM ; + + inst->ctx = ctx; + + inst->vpu.id =SCP_IPI_VDEC_LAT ; + inst->vpu.core_id =SCP_IPI_VDEC_CORE ; + inst->vpu.ctx = ctx;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs · line 1217
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+ inst->vpu.codec_type = ctx->current_codec; + inst->vpu.capture_type = ctx->capture_fourcc; + + err =vpu_dec_init (&inst->vpu); +if (err) { +mtk_vdec_err (ctx,"vdec_h264 init err=%d" , err); + goto error_free_inst; + } + +if (IS_VDEC_SUPPORT_EX (ctx->dev->dec_capability)) {
s/SUPPORT_EX/SUPPORT_EXT/
same treatment for the other variables below ending with ex
Quoted 14 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +14
-0+ 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); + +if (inst->ctx->dev->vdec_pdata->hw_arch ==MTK_VDEC_PURE_SINGLE_CORE ) + inst->decode = vdec_h264_slice_single_decode_ex; +else + inst->decode = vdec_h264_slice_lat_decode_ex; + }else { + vsi_size =sizeof (struct vdec_h264_slice_vsi ); +
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs · line 1241
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+ 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); + +if (inst->ctx->dev->vdec_pdata->hw_arch ==MTK_VDEC_PURE_SINGLE_CORE ) + inst->decode = vdec_h264_slice_single_decode; +else + inst->decode = vdec_h264_slice_lat_decode; + }
This looks all so extremely similar to me ... Please help me out here, why do we need a vsi_core and a vsi_core_ext ? You could easily assign the same value that you assign to vsi_core_ext to vsi_core in case the architecture supports the extended VSI. So why do you need to have a the vsi structs besides the vsi_ext structs?
Quoted 37 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +31
-1+ inst->resolution_changed = true; + inst->realloc_mv_buf = true; + +mtk_vdec_debug (ctx,"lat struct size = %d,%d,%d,%d vsi: %d\n" , + (int )sizeof (struct mtk_h264_sps_param ), + (int )sizeof (struct mtk_h264_pps_param ), + (int )sizeof (struct vdec_h264_slice_lat_dec_param ), + (int )sizeof (struct mtk_h264_dpb_info ), + vsi_size); +mtk_vdec_debug (ctx,"lat H264 instance >> %p, codec_type = 0x%x" , + inst, inst->vpu.codec_type); + + ctx->drv_handle = inst; +return 0 ; + +error_free_inst: +kfree (inst); +return err; +} + +static void vdec_h264_slice_deinit (void *h_vdec) +{ +struct vdec_h264_slice_inst *inst = h_vdec; + +vpu_dec_deinit (&inst->vpu); +vdec_h264_slice_free_mv_buf (inst); +vdec_msg_queue_deinit (&inst->ctx->msg_queue, inst->ctx); + +kfree (inst); +} +static int vdec_h264_slice_decode (void *h_vdec,struct mtk_vcodec_mem *bs,struct vdec_fb *unused,bool *res_chg) {struct vdec_h264_slice_inst *inst = h_vdec; -int ret;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs · line 1281
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-6if (!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); -else - ret =vdec_h264_slice_lat_decode (h_vdec, bs, unused, res_chg); - -return ret; +return inst->decode (h_vdec, bs, unused, res_chg);
One reason more to try avoiding the split into separate functions for extended and non-extended, more callbacks make the code just harder and harder to navigate and understand.
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +0
-0} static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,Signature · 1 line
2.46.0
Regards,
Sebastian Fricke
Yunfei Dong (董云飞)
maintainerRe: [PATCH v6 2/3] media: mediatek: vcodec: support extended h264 decode
Hi Sebastian,
Thanks for your advice.
Quoted 187 lines · Sebastian Fricke
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hey Yunfei,
Quoted 11 lines · Yunfei Dong
The address end of working buffer can't be calculated directly with buffer
size in kernel for some special architecture. Adding new extendvsi_exto
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.I'd recommend changing this to:
Add a new extended
vsi_extstruct besides the existing vsi struct, to enable calculating the end of the adress range of the current working buffer for architectures, where simply adding the buffer size to the start of the address range isn't sufficient.
Additionally, on extended architectures, the NAL information can be fetched directly from the firmware, which allows skipping the parsing step within the kernel.Also, this sentence:
Quoted 3 lines
Adding capability to separate extend and non extend driver for different
platform.Is a bit ambigious for me and doesn't seem to be something worth mentioning. But maybe I misunderstand your point here.
Quoted 23 lines
Signed-off-by Yunfei Dong <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
---.../vcodec/decoder/mtk_vcodec_dec_drv.h| 2 +.../decoder/vdec/vdec_h264_req_multi_if.c| 575
++++++++++++++++--2 files changed, 518 insertions(+), 59 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
indexac568ed14fa2..a0bb23962209100644
---
a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv .h
+++
b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv .hReview line 23
Quoted 7 lines
(quoted diff) +1
-0@@ -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)I'd recommend changing this to:
IS_VDEC_SUPPORT_EXTas EXT is way less
ambigious acronym for extension, EX could mean way more. You'll see me mentioning that below a couple of times.Quoted 37 lines
enum mtk_vcodec_dec_chip_name { MTK_VDEC_INVAL = 0,drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +1
-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.cb/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c
indexab192ce0b851..a7de95b9a7c0100644
---
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.cdrivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +9
-0@@ -128,6 +128,83 @@ struct vdec_h264_slice_share_info {u16 nal_info; }; +/* +* struct vdec_h264_slice_mem - memory address and size (shared interface with firmware) +*/ +struct vdec_h264_slice_mem { +union { +u64 buf; +u64 dma_addr; + }; +union {drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 150
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +9
-0+size_t size; +u64 dma_addr_end; + }; +}; + +/** +* struct vdec_h264_slice_fb - frame buffer for decoding (shared interface with firmware) +* +* @y: current y buffer address info As this is a description I'd say lets describe a bit more detailed and
rewrite this to: "@y: current luma buffer address info"drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 149
Quoted 1 line
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-0+* @c: current c buffer address info ... and "@c: current chroma buffer address info"
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info {
Quoted 9 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +8
-0+*/ +struct vdec_h264_slice_fb { +struct vdec_h264_slice_mem y; +struct vdec_h264_slice_mem c; +}; + +/** +* struct vdec_h264_slice_info_ex - extend decode information (shared interface with firmware) Can we call this also ..info_ext please?
Quoted 5 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+* +* @wdma_end_addr_offset: offset from buffer start +* @nal_info: nal info of current picture +* @timeout: Decode timeout: 1 timeout, 0 no timeout
I'd rename the description to: "Toggles whether a decode operation can timeout"
Then the effect of 1 and 0 becomes obvious.Quoted 5 lines
+ * @reserved: reserved
+ * @vdec_fb_va: VDEC frame buffer struct virtual
address
+ * @crc: Used to check whether hardware's
status is rightI'd rename this to: "Displays the hardware status" Saying whether a status is "right" is rather ambigious.
Quoted 2 lines
+ */
+structvdec_h264_slice_info_ex{... and this ...
info_extQuoted 11 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+u64 wdma_end_addr_offset; +u16 nal_info; +u16 timeout; +u32 reserved; +u64 vdec_fb_va; +u32 crc[8 ]; +}; + +/** +* struct vdec_h264_slice_vsi_ex - extend shared memory for decode information exchange
s/vsi_ex/vsi_ext/
Quoted 6 lines
+ * between SCP and Host (shared interface with firmware).
+ *
+ * @bs: input buffer info
+ * @fb: current y/c buffer
+ *
+ * @ube: ube buffer
Quoted 2 lines
While we are at it and this acronym isn't terrible self-descriptive could you write in the description what ube stands for?
I can rewrite the description to: ube is a buffer used to share date between two hardware.
Quoted 67 lines
Quoted 7 lines
+ * @trans: transcoded buffer + * @row_info: row info buffer + * @err_map: err map buffer + * @slice_bc: slice buffer+ *
+ * @mv_buf_dma: HW working motion vector bufferHW working sounds weird, do you want to say the current?
Quoted 2 lines
+ * @dec: decode information (AP-R, VPU-W)
+ * @h264_slice_params: decode parameters for hw useds/for hw used/used for the hw/
Quoted 2 lines
+ */
+structvdec_h264_slice_vsi_ex{s/vsi_ex/vsi_ext/
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 204
Quoted 12 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +12
-0+/* 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;s/info_ex/info_ext/
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+struct vdec_h264_slice_lat_dec_param h264_slice_params; +}; +/**
* structvdec_h264_slice_inst- h264 decoder instance *drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 219
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-2@@ -138,8 +215,10 @@ struct vdec_h264_slice_share_info {* @vpu: VPU instance * @vsi: vsi used for lat * @vsi_core: vsi used for core -* -* @vsi_ctx: Local VSI data for this decoding context +* @vsi_ctx: Local vsi data for this decoding context +* @vsi_ex: extend vsi used for lat s/vsi_ex/vsi_ext/
s/extend/extended/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_share_info { · line 220
Quoted 1 line
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-0+* @vsi_core_ex: extend vsi used for core s/vsi_core_ex/vsi_core_ext/
s/extend/extended/Quoted 2 lines
(quoted diff) +1
-0+ * @vsi_ctx_ex: Local extend vsi data for this decodingcontext
s/vsi_ctx_ex/vsi_ctx_ext/
s/extend/extended/Also you can drop the word Local as that is clear already with:
"for this decoding context"
Quoted 17 lines
Quoted 10 lines
* @h264_slice_param: the parameters that hardware use to decode *
* @resolution_changed:resolution changed(quoted diff) +0
-0@@ -148,7 +227,9 @@ struct vdec_h264_slice_share_info { * * @dpb: decoded picture buffer used to storereference
* buffer information
- *@is_field_bitstream: is field bitstream
+ * @is_field_bitstream: is field bitstreamThat is not a description, that is a repetition :)
Please make this a bit more descriptive. Like do you describe anywhere
else already what a field bitstream is and how it differentiates from the alternative?
bitstream can be field / frame or adapt field frame. The driver only support frame decode.
Quoted 113 lines
Quoted 3 lines
+ *
+ * @decode: lat decoder pointer for different
architectures/architecture/architectures/
Quoted 11 lines
*/
struct vdec_h264_slice_inst { unsigned int slice_dec_num;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +0
-4@@ -156,10 +237,18 @@ 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;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_inst { · line 249
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+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;s/vsi_ex/vsi_ext/
s/vsi_core_ex/vsi_core_ext/
s/vsi_ctx_ex/vsi_ctx_ext/Quoted 17 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-0+ }; + };struct vdec_h264_slice_lat_dec_param h264_slice_param;unsigned int resolution_changed;@@ -168,6 +257,9 @@ struct vdec_h264_slice_inst {struct v4l2_h264_dpb_entry dpb[16 ];bool is_field_bitstream; + +int (*decode)(void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *unused,bool *res_chg); };static int vdec_h264_slice_fill_decode_parameters(struct
vdec_h264_slice_inst*inst,drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void · line 486
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-1@@ -389,62 +481,143 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, cr->left, cr->top, cr->width, cr->height); } -static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx) +static void vdec_h264_slice_setup_lat_buffer_ex(struct vdec_h264_slice_inst *inst,s/buffer_ex/buffer_ext/
Quoted 11 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-3+struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf) { -struct vdec_h264_slice_inst *inst; -int err, vsi_size; + struct mtk_vcodec_mem *mem; +int i; - inst =kzalloc (sizeof (*inst),GFP_KERNEL );drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst,
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-3-if (!inst) -return -ENOMEM ; + inst->vsi_ex->bs.dma_addr = (u64 )bs->dma_addr; + inst->vsi_ex->bs.size = bs->size; - inst->ctx = ctx; +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;s/vsi_ex/vsi_ext/
and in all other cases below ...Quoted 29 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +13
-9+ 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->vpu.id =SCP_IPI_VDEC_LAT ; - inst->vpu.core_id =SCP_IPI_VDEC_CORE ; - inst->vpu.ctx = ctx; - inst->vpu.codec_type = ctx->current_codec; - inst->vpu.capture_type = ctx->capture_fourcc; + inst->vsi_ex->row_info.dma_addr =0 ; + inst->vsi_ex->row_info.size =0 ; - err =vpu_dec_init (&inst->vpu); -if (err) { -mtk_vdec_err (ctx,"vdec_h264 init err=%d" , err); - goto error_free_inst; + 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;
Quoted 8 lines
Review static void · line 527
Quoted 6 lines
(quoted diff) +4
-0+ inst->vsi_ex->trans.dma_addr = inst->ctx- >msg_queue.wdma_wptr_addr; +} + +static int vdec_h264_slice_setup_core_buffer_ex(struct vdec_h264_slice_inst *inst,s/buffer_ex/buffer_ext/
Will fix all.
Quoted 20 lines
Quoted 6 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+struct vdec_h264_slice_share_info *share_info, + struct vdec_lat_buf *lat_buf) +{drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 528
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+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" );A frame buffer buffer sounds a bit repetitive, lets just call it frame
buffer. Also this error message tells the user nothing. When I look
Quoted 9 lines
at
the function withinmtk_vcodec_dec_statelessit looks like the only way we get a NULL here is ifv4l2_m2m_next_dst_bufreturns nothing, e.g. if we don't have a next destination buffer. Can you confirm this?
If that is the case a better error message would be:
"Unable to get a CAPTURE buffer, because the CAPTURE queue is empty" Or something along those lines.
I will change the error message.
Quoted 15 lines
Quoted 15 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-6+return -EBUSY ; } - 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); - inst->resolution_changed = true; - inst->realloc_mv_buf = true; + 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-
Quoted 6 lines
Review static void · line 552
Quoted 1 line
(quoted diff) +0
-0>ctx->picinfo.buf_h;Looks like it is worth it to create a separate variable for picinfo as
you use it here and below, so that you can do a bit less copy-paste.
Will fix.
Quoted 85 lines
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-5+else + c_fb_dma = (u64 )fb->base_c.dma_addr; - mtk_vdec_debug(ctx, "lat struct size = %d,%d,%d,%d vsi: %d\n", - (int)sizeof(struct mtk_h264_sps_param), - (int)sizeof(struct mtk_h264_pps_param), - (int)sizeof(struct vdec_h264_slice_lat_dec_param), - (int)sizeof(struct mtk_h264_dpb_info),drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 541
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-5- vsi_size); - mtk_vdec_debug(ctx, "lat H264 instance >> %p, codec_type = 0x%x", - inst, inst->vpu.codec_type); + mtk_vdec_debug(ctx,"[h264-core] y/c addr = 0x%llx 0x%llx" , y_fb_dma, c_fb_dma); - ctx->drv_handle = inst; -return 0 ; + inst->vsi_core_ex->fb.y.dma_addr = y_fb_dma;s/vsi_core_ex/vsi_core_ext/
and everywhere below ...Quoted 48 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-3+ 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 ]; -error_free_inst: -kfree (inst); -return err; + 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-Quoted 1 line
msg_queue.wdma_addr.dma_addr;
+
inst->vsi_core_ex->ube.size= lat_buf->ctx-Quoted 1 line
msg_queue.wdma_addr.size;
(quoted diff) +2
-0+ + inst->vsi_core_ex->err_map.dma_addr = lat_buf-Quoted 1 line
wdma_err_addr.dma_addr;
+
inst->vsi_core_ex->err_map.size= lat_buf-Quoted 1 line
wdma_err_addr.size;
(quoted diff) +2
-0+ + inst->vsi_core_ex->slice_bc.dma_addr = lat_buf-Quoted 1 line
slice_bc_addr.dma_addr;
+
inst->vsi_core_ex->slice_bc.size= lat_buf-Quoted 1 line
slice_bc_addr.size;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+ + 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-Quoted 1 line
trans_end;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ +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-Quoted 1 line
dma_addr;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-0+ 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);
(quoted diff) +2
-0+ + return 0;}
(quoted diff) +1
-1-static void vdec_h264_slice_deinit(void *h_vdec) +static int vdec_h264_slice_core_decode_ex(struct vdec_lat_bufQuoted 1 line
*lat_buf)s/decode_ex/decode_ext/
No no no, I don't like this or
vdec_h264_slice_lat_decode_exyou basically just duplicated the whole decode function in both cases and added a few extended bits to them. Unless the two routines are substantially different (which from my point of view they are not) you
should be able to create conditional branches for the extended bits into
the decode functions.
Quoted 6 lines
But please also look at my general comments in the functions, I'd still
like to know why timeouts are handled the way they are and whether the
status of a device can be made a bit more obvious to the user.
1: single decode and lat single decode (lat + core) are different architectures.
2: The vsi is different for extend and non extend, need to fill different parameters for vsi and vsi_ext. There are many if...else.. to separate vsi ane vsi_ext if the driver only use one function core decoder and one function lat decode.
Quoted 49 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, · line 584
Quoted 13 lines
{
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-1-struct vdec_h264_slice_inst *inst = h_vdec; +int err, timeout; +struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx; +struct vdec_h264_slice_inst *inst = ctx->drv_handle; + struct vdec_h264_slice_share_info *share_info = lat_buf-Quoted 1 line
private_data;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-3+struct vdec_vpu_inst *vpu = &inst->vpu; -vpu_dec_deinit (&inst->vpu); -vdec_h264_slice_free_mv_buf (inst); -vdec_msg_queue_deinit (&inst->ctx->msg_queue, inst->ctx); +mtk_vdec_debug (ctx,"[h264-core] vdec_h264 core decode" );This looks like a left over development comment, this is not useful for
general debugging and shouldn't be upstreamed.Quoted 7 lines
+ memcpy(&inst->vsi_core_ex->h264_slice_params, &share_info-
Quoted 1 line
h264_slice_params,drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +2
-1+ sizeof(share_info->h264_slice_params)); -kfree (inst); + err = vdec_h264_slice_setup_core_buffer_ex(inst, share_info,
lat_buf);s/buffer_ex/buffer_ext/
Quoted 19 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+if (err) + goto vdec_dec_end; + + vdec_h264_slice_fill_decode_reflist(inst, &inst-Quoted 1 line
vsi_core_ex->h264_slice_params,drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +9
-0+ 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);(quoted diff) +2
-0+ if (timeout) + mtk_vdec_err(ctx, "core decode timeout: pic_%d",Quoted 1 line
ctx->decoded_frame_cnt);
Quoted 3 lines
So as you don't bail out here, it looks like this conditional branch will end up returning 0. Why do you return 0 on a timeout? Isn't a timeout a failed decode?
If core decode timeout, the core can re-decode next frame, may show garbage or green picture, if lat decode timeout. It's mean the input data must be not correctly.
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ 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%x0x%x 0x%x 0x%x",
(quoted diff) +2
-0+ ctx->decoded_frame_cnt, + inst->vsi_core_ex->dec.crc[0], inst-Quoted 1 line
vsi_core_ex->dec.crc[1],
+ inst->vsi_core_ex->dec.crc[2], inst-
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
vsi_core_ex->dec.crc[3],
+ inst->vsi_core_ex->dec.crc[4], inst-
Quoted 1 line
vsi_core_ex->dec.crc[5],
+ inst->vsi_core_ex->dec.crc[6], inst-
Quoted 1 line
vsi_core_ex->dec.crc[7]);
Can you add a small comment above this that explains to the user what these CRCs are supposed to mean?
crc is just hardware checksume used for debug, I can add.
Quoted 402 lines
Quoted 182 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ +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-Quoted 1 line
src_buf_req);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+mtk_vdec_debug (ctx,"core decode done err=%d" , err); + ctx->decoded_frame_cnt++; +return 0 ;}
static int
vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)(quoted diff) +0
-0@@ -559,6 +732,127 @@ static void vdec_h264_insert_startcode(struct
mtk_vcodec_dec_dev*vcodec_dev, un(*bs_size) += 4; }+static int vdec_h264_slice_lat_decode_ex(void
*h_vdec, structmtk_vcodec_mem*bs,
+ structvdec_fb*fb, bool*res_chg)drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +17
-0+{ +struct vdec_h264_slice_inst *inst = h_vdec; +struct vdec_vpu_inst *vpu = &inst->vpu; +struct mtk_video_dec_buf *src_buf_info; +int err, timeout =0 ; +unsigned int data[2 ]; +struct vdec_lat_buf *lat_buf; +struct vdec_h264_slice_share_info *share_info; + +if (vdec_msg_queue_init (&inst->ctx->msg_queue, inst->ctx, + vdec_h264_slice_core_decode_ex, +sizeof (*share_info))) +return -ENOMEM ; + +/* bs NULL means flush decoder */ +if (!bs) { + vdec_msg_queue_wait_lat_buf_full(&inst->ctx-Quoted 1 line
msg_queue);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-0+return vpu_dec_reset (vpu); + } + +if (inst->is_field_bitstream) +return -EINVAL ; + + lat_buf = vdec_msg_queue_dqbuf(&inst->ctx-Quoted 1 line
msg_queue.lat_ctx);
(quoted diff) +2
-0+ if (!lat_buf) { + mtk_vdec_debug(inst->ctx, "failed to get latbuffer");
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+return -EAGAIN ; + } + share_info = lat_buf->private_data; + src_buf_info = container_of(bs, struct mtk_video_dec_buf,
bs_buffer);(quoted diff) +2
-0+ + lat_buf->src_buf_req = src_buf_info-Quoted 1 line
m2m_buf.vb.vb2_buf.req_obj.req;
+ v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
&lat_buf->ts_info, true);(quoted diff) +2
-0+ + err = vdec_h264_slice_fill_decode_parameters(inst,
share_info,
+ &inst->vsi_ex-Quoted 1 line
h264_slice_params);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+if (err) + goto err_free_fb_out; + + vdec_h264_insert_startcode(inst->ctx->dev, bs->va, &bs-Quoted 1 line
size,
+ &share_info-
Quoted 1 line
h264_slice_params.pps);
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+ + *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);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +9
-0+ inst->realloc_mv_buf = false; +if (err) + goto err_free_fb_out; + } + inst->resolution_changed = false; + } + +vdec_h264_slice_setup_lat_buffer_ex (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,drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ inst->vsi_ex->err_map.dma_addr); + + mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%lx) rprt((0x%llx0x%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-Quoted 1 line
trans.dma_addr_end);
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ + err =vpu_dec_start (vpu, data,2 ); +if (err) { + mtk_vdec_debug(inst->ctx, "lat decode err: %d",err);
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ goto err_free_fb_out; + } + + share_info->trans_end = inst->ctx-Quoted 1 line
msg_queue.wdma_addr.dma_addr +
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ inst->vsi_ex->dec.wdma_end_addr_offset; + + share_info->trans_start = inst->ctx-Quoted 1 line
msg_queue.wdma_wptr_addr;
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ 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-Quoted 1 line
vsi_ex->h264_slice_params,(quoted diff) +2
-0+ sizeof(share_info->h264_slice_params)); + vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx,
lat_buf);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ } + +/* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx,
MTK_INST_IRQ_RECEIVED,
+WAIT_INTR_TIMEOUT_MS,MTK_VDEC_LAT0);(quoted diff) +2
-0+ if (timeout) + mtk_vdec_err(inst->ctx, "lat decode timeout:pic_%d",
inst->slice_dec_num);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +5
-0+ inst->vsi_ex->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-Quoted 1 line
dec_capability))+ vdec_msg_queue_qbuf(&inst->ctx-
Quoted 1 line
msg_queue.lat_ctx,
lat_buf);(quoted diff) +2
-0+ inst->slice_dec_num++; + mtk_vdec_err(inst->ctx, "lat dec fail: pic_%derr:%d",
inst->slice_dec_num, err);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+return -EINVAL ; + } + + share_info->trans_end = inst->ctx-Quoted 1 line
msg_queue.wdma_addr.dma_addr +
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ inst->vsi_ex->dec.wdma_end_addr_offset; + + vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue,
share_info->trans_end);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ +if (!IS_VDEC_INNER_RACING (inst->ctx->dev->dec_capability)) { + memcpy(&share_info->h264_slice_params, &inst-Quoted 1 line
vsi_ex->h264_slice_params,(quoted diff) +2
-0+ sizeof(share_info->h264_slice_params)); + vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx,
lat_buf);(quoted diff) +2
-0+ } + mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x0x%x",
inst->slice_dec_num,
+ inst->vsi_ex->dec.crc[0], inst->vsi_ex-Quoted 1 line
dec.crc[1],
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-0+ inst->vsi_ex->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);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+return err; +} +static int vdec_h264_slice_lat_decode(void
*h_vdec, structmtk_vcodec_mem*bs,
structvdec_fb*fb, bool*res_chg)
{Review static int vdec_h264_slice_lat_decode(void · line 1005
Quoted 10 lines
(quoted diff) +1
-2@@ -704,18 +998,17 @@ 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_single_decode_ex(void *h_vdec, struct mtk_vcodec_mem *bs,s/decode_ex/decode_ext/
Quoted 157 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-1+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;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +14
-1-int err, nal_start_idx; +int err;/* bs NULL means flush decoder */ if (!bs)@@ -735,6 +1028,96 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bsmtk_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_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); + err =get_vdec_sig_decode_parameters (inst); +if (err) + goto err_free_fb_out; + + memcpy(&inst->vsi_ctx_ex.h264_slice_params, &inst-Quoted 1 line
h264_slice_param,drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-0+ sizeof(inst->vsi_ctx_ex.h264_slice_params)); + + *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);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +9
-0+ 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_ex.mv_buf_dma[i].dma_addr =
mem->dma_addr;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ } + } + + memcpy(inst->vpu.vsi, &inst->vsi_ctx_ex, sizeof(inst-Quoted 1 line
vsi_ctx_ex));drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+ 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);(quoted diff) +2
-0+ if (err) + mtk_vdec_err(inst->ctx, "decode timeout: pic_%d",
inst->ctx->decoded_frame_cnt);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +7
-0+ + inst->vsi_ex->dec.timeout = !!err; + err =vpu_dec_end (vpu); +if (err) + goto err_free_fb_out; + + memcpy(&inst->vsi_ctx_ex, inst->vpu.vsi, sizeof(inst-Quoted 1 line
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",(quoted diff) +2
-0+ inst->ctx->decoded_frame_cnt, + inst->vsi_ctx_ex.dec.crc[0], inst-Quoted 1 line
vsi_ctx_ex.dec.crc[1],
+ inst->vsi_ctx_ex.dec.crc[2], inst-
Quoted 1 line
vsi_ctx_ex.dec.crc[3],
+ inst->vsi_ctx_ex.dec.crc[4], inst-
Quoted 1 line
vsi_ctx_ex.dec.crc[5],
+ inst->vsi_ctx_ex.dec.crc[6], inst-
Quoted 1 line
vsi_ctx_ex.dec.crc[7]);
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+ + 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);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+return err; +} + +static int vdec_h264_slice_single_decode(void *h_vdec, struct
mtk_vcodec_mem*bs,
+ structvdec_fb*unused,
bool*res_chg)drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +17
-0+{ +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, structmtk_video_dec_buf,frame_buffer);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ + 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=%llxc_dma=%llx",
+inst->ctx->decoded_frame_cnt,y_fb_dma,c_fb_dma);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-0+ 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;@@ -807,21 +1190,95 @@ static intvdec_h264_slice_single_decode(void
*h_vdec, structmtk_vcodec_mem*bsreturn err; }drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +15
-0+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) +return -ENOMEM ; + + inst->ctx = ctx; + + inst->vpu.id =SCP_IPI_VDEC_LAT ; + inst->vpu.core_id =SCP_IPI_VDEC_CORE ; + inst->vpu.ctx = ctx;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs · line 1217
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +10
-0+ inst->vpu.codec_type = ctx->current_codec; + inst->vpu.capture_type = ctx->capture_fourcc; + + err =vpu_dec_init (&inst->vpu); +if (err) { +mtk_vdec_err (ctx,"vdec_h264 init err=%d" , err); + goto error_free_inst; + } + +if (IS_VDEC_SUPPORT_EX (ctx->dev->dec_capability)) {s/SUPPORT_EX/SUPPORT_EXT/
same treatment for the other variables below ending with ex
Quoted 30 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ vsi_size =sizeof (struct vdec_h264_slice_vsi_ex ); + + vsi_size = round_up(vsi_size,
VCODEC_DEC_ALIGNED_64);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ 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);(quoted diff) +2
-0+ + if (inst->ctx->dev->vdec_pdata->hw_arch ==
MTK_VDEC_PURE_SINGLE_CORE)
+inst->decode=vdec_h264_slice_single_decode_ex;(quoted diff) +2
-0+ else + inst->decode =
vdec_h264_slice_lat_decode_ex;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ }else { + vsi_size =sizeof (struct vdec_h264_slice_vsi ); + + vsi_size = round_up(vsi_size,
VCODEC_DEC_ALIGNED_64);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +6
-0+ inst->vsi = inst->vpu.vsi; + temp = (unsigned char *)inst->vsi; + inst->vsi_core = (struct vdec_h264_slice_vsi *)(temp + vsi_size); + + if (inst->ctx->dev->vdec_pdata->hw_arch ==
MTK_VDEC_PURE_SINGLE_CORE)
+inst->decode=vdec_h264_slice_single_decode;drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs · line 1241
Quoted 3 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+else + inst->decode = vdec_h264_slice_lat_decode; + }This looks all so extremely similar to me ... Please help me out
Quoted 8 lines
here,
why do we need avsi_coreand avsi_core_ext? You could easily assign
the same value that you assign tovsi_core_exttovsi_corein case the
architecture supports the extended VSI. So why do you need to have a the
vsi structs besides thevsi_extstructs?
vsi extend is added many parameters to support some special feature, vsi_core and vsi_core_ext are big different.
Quoted 46 lines
Quoted 46 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +4
-0+ inst->resolution_changed = true; + inst->realloc_mv_buf = true; + + mtk_vdec_debug(ctx, "lat struct size = %d,%d,%d,%d vsi:%d\n",
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ (int )sizeof (struct mtk_h264_sps_param ), + (int)sizeof(struct mtk_h264_pps_param), + (int)sizeof(struct
vdec_h264_slice_lat_dec_param),drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +3
-0+ (int )sizeof (struct mtk_h264_dpb_info ), + vsi_size); + mtk_vdec_debug(ctx, "lat H264 instance >> %p, codec_type =0x%x",
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +21
-0+ inst, inst->vpu.codec_type); + + ctx->drv_handle = inst; +return 0 ; + +error_free_inst: +kfree (inst); +return err; +} + +static void vdec_h264_slice_deinit (void *h_vdec) +{ +struct vdec_h264_slice_inst *inst = h_vdec; + +vpu_dec_deinit (&inst->vpu); +vdec_h264_slice_free_mv_buf (inst); +vdec_msg_queue_deinit (&inst->ctx->msg_queue, inst->ctx); + +kfree (inst); +} +static int vdec_h264_slice_decode(void
*h_vdec, structmtk_vcodec_mem*bs,
structvdec_fb*unused, bool*res_chg){ struct vdec_h264_slice_inst *inst = h_vdec;- int ret;
if (!h_vdec) return -EINVAL;
Quoted 16 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs · line 1281
Quoted 10 lines
- 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);(quoted diff) +0
-2- else - ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
res_chg);drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-2- -return ret; +return inst->decode (h_vdec, bs, unused, res_chg);One reason more to try avoiding the split into separate functions for extended and non-extended, more callbacks make the code just harder and
harder to navigate and understand.
If the driver not add one callback for each architecture, need to using many condition to separate here, looks much more complex.
Best Regards,
Yunfei Dong
Quoted 11 lines
Quoted 8 lines
}
static int vdec_h264_slice_get_param(void
*h_vdec, enumvdec_get_param_typetype,
--
2.46.0Regards,
Sebastian Fricke
Yunfei Dong
maintainerPATCH v6 3/3 media: mediatek: vcodec: add description for vsi struct
In reply to Yunfei DongIf 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
@@ -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
Re: [PATCH v6 3/3] media: mediatek: vcodec: add description for vsi struct
Hey Yunfei,
Quoted 1 line · Yunfei Dong
If the video shared information (vsi) is changed accidentally,
How can that struct be changed accidentally?
Quoted 2 lines
will leading to play h264 bitstream fail if the firmware won't be changed at the same time.
Okay I guess you mean that the struct has to be memcpy'd to the firmware to synchronize it right?
Also is this really just a H264 thing? I would imagine that incorrect data in the firmware will cause issues no matter which codec.
Quoted 1 line
Marking the shared struct with "shared interface with firmware".
Can we do anything more to ensure that the firmware doesn't fall out of sync besides adding a comment to the description?
To fix grammatical issues the description above should be changed to:
The vsi (video shared information) struct needs to be synchronized between the firmware and the host, as a change that is only done in the host version of the struct but isn't synchronized to the firmware can lead to decoding issues with H264 bitstreams. Highlight this requirement within the struct descriptions.
But as highlighted above it is not clear to me whether the content of this message is right yet.
Quoted 30 lines
Signed-off-by Yunfei Dong <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>---
.../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 +2
-1@@ -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
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c struct vdec_h264_slice_info { · line 76
Quoted 5 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +1
-1@@ -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).
In this case, I feel like the previous description made the fact, that this is shared data between the host and the firmware, rather clear already.
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +0
-0* * @wdma_err_addr: wdma error dma address * @wdma_start_addr: wdma start dma address Signature · 1 line
2.46.0
Regards,
Sebastian Fricke