Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mediatek: vcodec: Extract H264 common code

Mt8192 can use some of common code with mt8183. Moves them to
a new file in order to reuse.

[hverkuil: replaced memcpy_toio by memcpy, was left over from a prev version]

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Yunfei Dong and committed by
Mauro Carvalho Chehab
024b1f4f ba9a7dbb

+629 -383
+1
drivers/media/platform/mediatek/vcodec/Makefile
··· 9 9 vdec/vdec_vp8_if.o \ 10 10 vdec/vdec_vp9_if.o \ 11 11 vdec/vdec_h264_req_if.o \ 12 + vdec/vdec_h264_req_common.o \ 12 13 mtk_vcodec_dec_drv.o \ 13 14 vdec_drv_if.o \ 14 15 vdec_vpu_if.o \
+310
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2022 MediaTek Inc. 4 + * Author: Yunfei Dong <yunfei.dong@mediatek.com> 5 + */ 6 + 7 + #include "vdec_h264_req_common.h" 8 + 9 + /* get used parameters for sps/pps */ 10 + #define GET_MTK_VDEC_FLAG(cond, flag) \ 11 + { dst_param->cond = ((src_param->flags & flag) ? (1) : (0)); } 12 + #define GET_MTK_VDEC_PARAM(param) \ 13 + { dst_param->param = src_param->param; } 14 + 15 + /* 16 + * The firmware expects unused reflist entries to have the value 0x20. 17 + */ 18 + void mtk_vdec_h264_fixup_ref_list(u8 *ref_list, size_t num_valid) 19 + { 20 + memset(&ref_list[num_valid], 0x20, 32 - num_valid); 21 + } 22 + 23 + void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id) 24 + { 25 + struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, id); 26 + 27 + if (!ctrl) 28 + return ERR_PTR(-EINVAL); 29 + 30 + return ctrl->p_cur.p; 31 + } 32 + 33 + void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx, 34 + struct slice_api_h264_decode_param *decode_params, 35 + struct mtk_h264_dpb_info *h264_dpb_info) 36 + { 37 + const struct slice_h264_dpb_entry *dpb; 38 + struct vb2_queue *vq; 39 + struct vb2_buffer *vb; 40 + struct vb2_v4l2_buffer *vb2_v4l2; 41 + int index, vb2_index; 42 + 43 + vq = v4l2_m2m_get_vq(ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 44 + 45 + for (index = 0; index < V4L2_H264_NUM_DPB_ENTRIES; index++) { 46 + dpb = &decode_params->dpb[index]; 47 + if (!(dpb->flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)) { 48 + h264_dpb_info[index].reference_flag = 0; 49 + continue; 50 + } 51 + 52 + vb2_index = vb2_find_timestamp(vq, dpb->reference_ts, 0); 53 + if (vb2_index < 0) { 54 + dev_err(&ctx->dev->plat_dev->dev, 55 + "Reference invalid: dpb_index(%d) reference_ts(%lld)", 56 + index, dpb->reference_ts); 57 + continue; 58 + } 59 + 60 + /* 1 for short term reference, 2 for long term reference */ 61 + if (!(dpb->flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)) 62 + h264_dpb_info[index].reference_flag = 1; 63 + else 64 + h264_dpb_info[index].reference_flag = 2; 65 + 66 + vb = vq->bufs[vb2_index]; 67 + vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); 68 + h264_dpb_info[index].field = vb2_v4l2->field; 69 + 70 + h264_dpb_info[index].y_dma_addr = 71 + vb2_dma_contig_plane_dma_addr(vb, 0); 72 + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) 73 + h264_dpb_info[index].c_dma_addr = 74 + vb2_dma_contig_plane_dma_addr(vb, 1); 75 + else 76 + h264_dpb_info[index].c_dma_addr = 77 + h264_dpb_info[index].y_dma_addr + 78 + ctx->picinfo.fb_sz[0]; 79 + } 80 + } 81 + 82 + void mtk_vdec_h264_copy_sps_params(struct mtk_h264_sps_param *dst_param, 83 + const struct v4l2_ctrl_h264_sps *src_param) 84 + { 85 + GET_MTK_VDEC_PARAM(chroma_format_idc); 86 + GET_MTK_VDEC_PARAM(bit_depth_luma_minus8); 87 + GET_MTK_VDEC_PARAM(bit_depth_chroma_minus8); 88 + GET_MTK_VDEC_PARAM(log2_max_frame_num_minus4); 89 + GET_MTK_VDEC_PARAM(pic_order_cnt_type); 90 + GET_MTK_VDEC_PARAM(log2_max_pic_order_cnt_lsb_minus4); 91 + GET_MTK_VDEC_PARAM(max_num_ref_frames); 92 + GET_MTK_VDEC_PARAM(pic_width_in_mbs_minus1); 93 + GET_MTK_VDEC_PARAM(pic_height_in_map_units_minus1); 94 + 95 + GET_MTK_VDEC_FLAG(separate_colour_plane_flag, 96 + V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE); 97 + GET_MTK_VDEC_FLAG(qpprime_y_zero_transform_bypass_flag, 98 + V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS); 99 + GET_MTK_VDEC_FLAG(delta_pic_order_always_zero_flag, 100 + V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO); 101 + GET_MTK_VDEC_FLAG(frame_mbs_only_flag, 102 + V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY); 103 + GET_MTK_VDEC_FLAG(mb_adaptive_frame_field_flag, 104 + V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD); 105 + GET_MTK_VDEC_FLAG(direct_8x8_inference_flag, 106 + V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE); 107 + } 108 + 109 + void mtk_vdec_h264_copy_pps_params(struct mtk_h264_pps_param *dst_param, 110 + const struct v4l2_ctrl_h264_pps *src_param) 111 + { 112 + GET_MTK_VDEC_PARAM(num_ref_idx_l0_default_active_minus1); 113 + GET_MTK_VDEC_PARAM(num_ref_idx_l1_default_active_minus1); 114 + GET_MTK_VDEC_PARAM(weighted_bipred_idc); 115 + GET_MTK_VDEC_PARAM(pic_init_qp_minus26); 116 + GET_MTK_VDEC_PARAM(chroma_qp_index_offset); 117 + GET_MTK_VDEC_PARAM(second_chroma_qp_index_offset); 118 + 119 + GET_MTK_VDEC_FLAG(entropy_coding_mode_flag, 120 + V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE); 121 + GET_MTK_VDEC_FLAG(pic_order_present_flag, 122 + V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT); 123 + GET_MTK_VDEC_FLAG(weighted_pred_flag, 124 + V4L2_H264_PPS_FLAG_WEIGHTED_PRED); 125 + GET_MTK_VDEC_FLAG(deblocking_filter_control_present_flag, 126 + V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT); 127 + GET_MTK_VDEC_FLAG(constrained_intra_pred_flag, 128 + V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED); 129 + GET_MTK_VDEC_FLAG(redundant_pic_cnt_present_flag, 130 + V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT); 131 + GET_MTK_VDEC_FLAG(transform_8x8_mode_flag, 132 + V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE); 133 + GET_MTK_VDEC_FLAG(scaling_matrix_present_flag, 134 + V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT); 135 + } 136 + 137 + void mtk_vdec_h264_copy_slice_hd_params(struct mtk_h264_slice_hd_param *dst_param, 138 + const struct v4l2_ctrl_h264_slice_params *src_param, 139 + const struct v4l2_ctrl_h264_decode_params *dec_param) 140 + { 141 + int temp; 142 + 143 + GET_MTK_VDEC_PARAM(first_mb_in_slice); 144 + GET_MTK_VDEC_PARAM(slice_type); 145 + GET_MTK_VDEC_PARAM(cabac_init_idc); 146 + GET_MTK_VDEC_PARAM(slice_qp_delta); 147 + GET_MTK_VDEC_PARAM(disable_deblocking_filter_idc); 148 + GET_MTK_VDEC_PARAM(slice_alpha_c0_offset_div2); 149 + GET_MTK_VDEC_PARAM(slice_beta_offset_div2); 150 + GET_MTK_VDEC_PARAM(num_ref_idx_l0_active_minus1); 151 + GET_MTK_VDEC_PARAM(num_ref_idx_l1_active_minus1); 152 + 153 + dst_param->frame_num = dec_param->frame_num; 154 + dst_param->pic_order_cnt_lsb = dec_param->pic_order_cnt_lsb; 155 + 156 + dst_param->delta_pic_order_cnt_bottom = 157 + dec_param->delta_pic_order_cnt_bottom; 158 + dst_param->delta_pic_order_cnt0 = 159 + dec_param->delta_pic_order_cnt0; 160 + dst_param->delta_pic_order_cnt1 = 161 + dec_param->delta_pic_order_cnt1; 162 + 163 + temp = dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC; 164 + dst_param->field_pic_flag = temp ? 1 : 0; 165 + 166 + temp = dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD; 167 + dst_param->bottom_field_flag = temp ? 1 : 0; 168 + 169 + GET_MTK_VDEC_FLAG(direct_spatial_mv_pred_flag, 170 + V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED); 171 + } 172 + 173 + void mtk_vdec_h264_copy_scaling_matrix(struct slice_api_h264_scaling_matrix *dst_matrix, 174 + const struct v4l2_ctrl_h264_scaling_matrix *src_matrix) 175 + { 176 + memcpy(dst_matrix->scaling_list_4x4, src_matrix->scaling_list_4x4, 177 + sizeof(dst_matrix->scaling_list_4x4)); 178 + 179 + memcpy(dst_matrix->scaling_list_8x8, src_matrix->scaling_list_8x8, 180 + sizeof(dst_matrix->scaling_list_8x8)); 181 + } 182 + 183 + void 184 + mtk_vdec_h264_copy_decode_params(struct slice_api_h264_decode_param *dst_params, 185 + const struct v4l2_ctrl_h264_decode_params *src_params, 186 + const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]) 187 + { 188 + struct slice_h264_dpb_entry *dst_entry; 189 + const struct v4l2_h264_dpb_entry *src_entry; 190 + int i; 191 + 192 + for (i = 0; i < ARRAY_SIZE(dst_params->dpb); i++) { 193 + dst_entry = &dst_params->dpb[i]; 194 + src_entry = &dpb[i]; 195 + 196 + dst_entry->reference_ts = src_entry->reference_ts; 197 + dst_entry->frame_num = src_entry->frame_num; 198 + dst_entry->pic_num = src_entry->pic_num; 199 + dst_entry->top_field_order_cnt = src_entry->top_field_order_cnt; 200 + dst_entry->bottom_field_order_cnt = 201 + src_entry->bottom_field_order_cnt; 202 + dst_entry->flags = src_entry->flags; 203 + } 204 + 205 + /* num_slices is a leftover from the old H.264 support and is ignored 206 + * by the firmware. 207 + */ 208 + dst_params->num_slices = 0; 209 + dst_params->nal_ref_idc = src_params->nal_ref_idc; 210 + dst_params->top_field_order_cnt = src_params->top_field_order_cnt; 211 + dst_params->bottom_field_order_cnt = src_params->bottom_field_order_cnt; 212 + dst_params->flags = src_params->flags; 213 + } 214 + 215 + static bool mtk_vdec_h264_dpb_entry_match(const struct v4l2_h264_dpb_entry *a, 216 + const struct v4l2_h264_dpb_entry *b) 217 + { 218 + return a->top_field_order_cnt == b->top_field_order_cnt && 219 + a->bottom_field_order_cnt == b->bottom_field_order_cnt; 220 + } 221 + 222 + /* 223 + * Move DPB entries of dec_param that refer to a frame already existing in dpb 224 + * into the already existing slot in dpb, and move other entries into new slots. 225 + * 226 + * This function is an adaptation of the similarly-named function in 227 + * hantro_h264.c. 228 + */ 229 + void mtk_vdec_h264_update_dpb(const struct v4l2_ctrl_h264_decode_params *dec_param, 230 + struct v4l2_h264_dpb_entry *dpb) 231 + { 232 + DECLARE_BITMAP(new, ARRAY_SIZE(dec_param->dpb)) = { 0, }; 233 + DECLARE_BITMAP(in_use, ARRAY_SIZE(dec_param->dpb)) = { 0, }; 234 + DECLARE_BITMAP(used, ARRAY_SIZE(dec_param->dpb)) = { 0, }; 235 + unsigned int i, j; 236 + 237 + /* Disable all entries by default, and mark the ones in use. */ 238 + for (i = 0; i < ARRAY_SIZE(dec_param->dpb); i++) { 239 + if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE) 240 + set_bit(i, in_use); 241 + dpb[i].flags &= ~V4L2_H264_DPB_ENTRY_FLAG_ACTIVE; 242 + } 243 + 244 + /* Try to match new DPB entries with existing ones by their POCs. */ 245 + for (i = 0; i < ARRAY_SIZE(dec_param->dpb); i++) { 246 + const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; 247 + 248 + if (!(ndpb->flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)) 249 + continue; 250 + 251 + /* 252 + * To cut off some comparisons, iterate only on target DPB 253 + * entries were already used. 254 + */ 255 + for_each_set_bit(j, in_use, ARRAY_SIZE(dec_param->dpb)) { 256 + struct v4l2_h264_dpb_entry *cdpb; 257 + 258 + cdpb = &dpb[j]; 259 + if (!mtk_vdec_h264_dpb_entry_match(cdpb, ndpb)) 260 + continue; 261 + 262 + *cdpb = *ndpb; 263 + set_bit(j, used); 264 + /* Don't reiterate on this one. */ 265 + clear_bit(j, in_use); 266 + break; 267 + } 268 + 269 + if (j == ARRAY_SIZE(dec_param->dpb)) 270 + set_bit(i, new); 271 + } 272 + 273 + /* For entries that could not be matched, use remaining free slots. */ 274 + for_each_set_bit(i, new, ARRAY_SIZE(dec_param->dpb)) { 275 + const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; 276 + struct v4l2_h264_dpb_entry *cdpb; 277 + 278 + /* 279 + * Both arrays are of the same sizes, so there is no way 280 + * we can end up with no space in target array, unless 281 + * something is buggy. 282 + */ 283 + j = find_first_zero_bit(used, ARRAY_SIZE(dec_param->dpb)); 284 + if (WARN_ON(j >= ARRAY_SIZE(dec_param->dpb))) 285 + return; 286 + 287 + cdpb = &dpb[j]; 288 + *cdpb = *ndpb; 289 + set_bit(j, used); 290 + } 291 + } 292 + 293 + unsigned int mtk_vdec_h264_get_mv_buf_size(unsigned int width, unsigned int height) 294 + { 295 + int unit_size = (width / MB_UNIT_LEN) * (height / MB_UNIT_LEN) + 8; 296 + 297 + return HW_MB_STORE_SZ * unit_size; 298 + } 299 + 300 + int mtk_vdec_h264_find_start_code(unsigned char *data, unsigned int data_sz) 301 + { 302 + if (data_sz > 3 && data[0] == 0 && data[1] == 0 && data[2] == 1) 303 + return 3; 304 + 305 + if (data_sz > 4 && data[0] == 0 && data[1] == 0 && data[2] == 0 && 306 + data[3] == 1) 307 + return 4; 308 + 309 + return -1; 310 + }
+274
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (c) 2022 MediaTek Inc. 4 + * Author: Yunfei Dong <yunfei.dong@mediatek.com> 5 + */ 6 + 7 + #ifndef _VDEC_H264_REQ_COMMON_H_ 8 + #define _VDEC_H264_REQ_COMMON_H_ 9 + 10 + #include <linux/module.h> 11 + #include <linux/slab.h> 12 + #include <media/v4l2-h264.h> 13 + #include <media/v4l2-mem2mem.h> 14 + #include <media/videobuf2-dma-contig.h> 15 + 16 + #include "../mtk_vcodec_drv.h" 17 + 18 + #define NAL_NON_IDR_SLICE 0x01 19 + #define NAL_IDR_SLICE 0x05 20 + #define NAL_TYPE(value) ((value) & 0x1F) 21 + 22 + #define BUF_PREDICTION_SZ (64 * 4096) 23 + #define MB_UNIT_LEN 16 24 + 25 + /* motion vector size (bytes) for every macro block */ 26 + #define HW_MB_STORE_SZ 64 27 + 28 + #define H264_MAX_MV_NUM 32 29 + 30 + /** 31 + * struct mtk_h264_dpb_info - h264 dpb information 32 + * 33 + * @y_dma_addr: Y bitstream physical address 34 + * @c_dma_addr: CbCr bitstream physical address 35 + * @reference_flag: reference picture flag (short/long term reference picture) 36 + * @field: field picture flag 37 + */ 38 + struct mtk_h264_dpb_info { 39 + dma_addr_t y_dma_addr; 40 + dma_addr_t c_dma_addr; 41 + int reference_flag; 42 + int field; 43 + }; 44 + 45 + /* 46 + * struct mtk_h264_sps_param - parameters for sps 47 + */ 48 + struct mtk_h264_sps_param { 49 + unsigned char chroma_format_idc; 50 + unsigned char bit_depth_luma_minus8; 51 + unsigned char bit_depth_chroma_minus8; 52 + unsigned char log2_max_frame_num_minus4; 53 + unsigned char pic_order_cnt_type; 54 + unsigned char log2_max_pic_order_cnt_lsb_minus4; 55 + unsigned char max_num_ref_frames; 56 + unsigned char separate_colour_plane_flag; 57 + unsigned short pic_width_in_mbs_minus1; 58 + unsigned short pic_height_in_map_units_minus1; 59 + unsigned int max_frame_nums; 60 + unsigned char qpprime_y_zero_transform_bypass_flag; 61 + unsigned char delta_pic_order_always_zero_flag; 62 + unsigned char frame_mbs_only_flag; 63 + unsigned char mb_adaptive_frame_field_flag; 64 + unsigned char direct_8x8_inference_flag; 65 + unsigned char reserved[3]; 66 + }; 67 + 68 + /* 69 + * struct mtk_h264_pps_param - parameters for pps 70 + */ 71 + struct mtk_h264_pps_param { 72 + unsigned char num_ref_idx_l0_default_active_minus1; 73 + unsigned char num_ref_idx_l1_default_active_minus1; 74 + unsigned char weighted_bipred_idc; 75 + char pic_init_qp_minus26; 76 + char chroma_qp_index_offset; 77 + char second_chroma_qp_index_offset; 78 + unsigned char entropy_coding_mode_flag; 79 + unsigned char pic_order_present_flag; 80 + unsigned char deblocking_filter_control_present_flag; 81 + unsigned char constrained_intra_pred_flag; 82 + unsigned char weighted_pred_flag; 83 + unsigned char redundant_pic_cnt_present_flag; 84 + unsigned char transform_8x8_mode_flag; 85 + unsigned char scaling_matrix_present_flag; 86 + unsigned char reserved[2]; 87 + }; 88 + 89 + /* 90 + * struct mtk_h264_slice_hd_param - parameters for slice header 91 + */ 92 + struct mtk_h264_slice_hd_param { 93 + unsigned int first_mb_in_slice; 94 + unsigned int field_pic_flag; 95 + unsigned int slice_type; 96 + unsigned int frame_num; 97 + int pic_order_cnt_lsb; 98 + int delta_pic_order_cnt_bottom; 99 + unsigned int bottom_field_flag; 100 + unsigned int direct_spatial_mv_pred_flag; 101 + int delta_pic_order_cnt0; 102 + int delta_pic_order_cnt1; 103 + unsigned int cabac_init_idc; 104 + int slice_qp_delta; 105 + unsigned int disable_deblocking_filter_idc; 106 + int slice_alpha_c0_offset_div2; 107 + int slice_beta_offset_div2; 108 + unsigned int num_ref_idx_l0_active_minus1; 109 + unsigned int num_ref_idx_l1_active_minus1; 110 + unsigned int reserved; 111 + }; 112 + 113 + /* 114 + * struct slice_api_h264_scaling_matrix - parameters for scaling list 115 + */ 116 + struct slice_api_h264_scaling_matrix { 117 + unsigned char scaling_list_4x4[6][16]; 118 + unsigned char scaling_list_8x8[6][64]; 119 + }; 120 + 121 + /* 122 + * struct slice_h264_dpb_entry - each dpb information 123 + */ 124 + struct slice_h264_dpb_entry { 125 + unsigned long long reference_ts; 126 + unsigned short frame_num; 127 + unsigned short pic_num; 128 + /* Note that field is indicated by v4l2_buffer.field */ 129 + int top_field_order_cnt; 130 + int bottom_field_order_cnt; 131 + unsigned int flags; 132 + }; 133 + 134 + /* 135 + * struct slice_api_h264_decode_param - parameters for decode. 136 + */ 137 + struct slice_api_h264_decode_param { 138 + struct slice_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]; 139 + unsigned short num_slices; 140 + unsigned short nal_ref_idc; 141 + unsigned char ref_pic_list_p0[32]; 142 + unsigned char ref_pic_list_b0[32]; 143 + unsigned char ref_pic_list_b1[32]; 144 + int top_field_order_cnt; 145 + int bottom_field_order_cnt; 146 + unsigned int flags; 147 + }; 148 + 149 + /** 150 + * struct h264_fb - h264 decode frame buffer information 151 + * 152 + * @vdec_fb_va: virtual address of struct vdec_fb 153 + * @y_fb_dma: dma address of Y frame buffer (luma) 154 + * @c_fb_dma: dma address of C frame buffer (chroma) 155 + * @poc: picture order count of frame buffer 156 + * @reserved: for 8 bytes alignment 157 + */ 158 + struct h264_fb { 159 + u64 vdec_fb_va; 160 + u64 y_fb_dma; 161 + u64 c_fb_dma; 162 + s32 poc; 163 + u32 reserved; 164 + }; 165 + 166 + /** 167 + * mtk_vdec_h264_fixup_ref_list - fixup unused reference to 0x20. 168 + * 169 + * @ref_list: reference picture list 170 + * @num_valid: used reference number 171 + */ 172 + void mtk_vdec_h264_fixup_ref_list(u8 *ref_list, size_t num_valid); 173 + 174 + /** 175 + * mtk_vdec_h264_get_ctrl_ptr - get each CID contrl address. 176 + * 177 + * @ctx: v4l2 ctx 178 + * @id: CID control ID 179 + * 180 + * Return: returns CID ctrl address. 181 + */ 182 + void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id); 183 + 184 + /** 185 + * mtk_vdec_h264_fill_dpb_info - get each CID contrl address. 186 + * 187 + * @ctx: v4l2 ctx 188 + * @decode_params: slice decode params 189 + * @h264_dpb_info: dpb buffer information 190 + */ 191 + void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx, 192 + struct slice_api_h264_decode_param *decode_params, 193 + struct mtk_h264_dpb_info *h264_dpb_info); 194 + 195 + /** 196 + * mtk_vdec_h264_copy_sps_params - get sps params. 197 + * 198 + * @dst_param: sps params for hw decoder 199 + * @src_param: sps params from user driver 200 + */ 201 + void mtk_vdec_h264_copy_sps_params(struct mtk_h264_sps_param *dst_param, 202 + const struct v4l2_ctrl_h264_sps *src_param); 203 + 204 + /** 205 + * mtk_vdec_h264_copy_pps_params - get pps params. 206 + * 207 + * @dst_param: pps params for hw decoder 208 + * @src_param: pps params from user driver 209 + */ 210 + void mtk_vdec_h264_copy_pps_params(struct mtk_h264_pps_param *dst_param, 211 + const struct v4l2_ctrl_h264_pps *src_param); 212 + 213 + /** 214 + * mtk_vdec_h264_copy_slice_hd_params - get slice header params. 215 + * 216 + * @dst_param: slice params for hw decoder 217 + * @src_param: slice params from user driver 218 + * @dec_param: decode params from user driver 219 + */ 220 + void mtk_vdec_h264_copy_slice_hd_params(struct mtk_h264_slice_hd_param *dst_param, 221 + const struct v4l2_ctrl_h264_slice_params *src_param, 222 + const struct v4l2_ctrl_h264_decode_params *dec_param); 223 + 224 + /** 225 + * mtk_vdec_h264_copy_scaling_matrix - get each CID contrl address. 226 + * 227 + * @dst_matrix: scaling list params for hw decoder 228 + * @src_matrix: scaling list params from user driver 229 + */ 230 + void mtk_vdec_h264_copy_scaling_matrix(struct slice_api_h264_scaling_matrix *dst_matrix, 231 + const struct v4l2_ctrl_h264_scaling_matrix *src_matrix); 232 + 233 + /** 234 + * mtk_vdec_h264_copy_decode_params - get decode params. 235 + * 236 + * @dst_params: dst params for hw decoder 237 + * @src_params: decode params from user driver 238 + * @dpb: dpb information 239 + */ 240 + void 241 + mtk_vdec_h264_copy_decode_params(struct slice_api_h264_decode_param *dst_params, 242 + const struct v4l2_ctrl_h264_decode_params *src_params, 243 + const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]); 244 + 245 + /** 246 + * mtk_vdec_h264_update_dpb - updata dpb list. 247 + * 248 + * @dec_param: v4l2 control decode params 249 + * @dpb: dpb entry informaton 250 + */ 251 + void mtk_vdec_h264_update_dpb(const struct v4l2_ctrl_h264_decode_params *dec_param, 252 + struct v4l2_h264_dpb_entry *dpb); 253 + 254 + /** 255 + * mtk_vdec_h264_find_start_code - find h264 start code using sofeware. 256 + * 257 + * @data: input buffer address 258 + * @data_sz: input buffer size 259 + * 260 + * Return: returns start code position. 261 + */ 262 + int mtk_vdec_h264_find_start_code(unsigned char *data, unsigned int data_sz); 263 + 264 + /** 265 + * mtk_vdec_h264_get_mv_buf_size - get mv buffer size. 266 + * 267 + * @width: picture width 268 + * @height: picture height 269 + * 270 + * Return: returns mv buffer size. 271 + */ 272 + unsigned int mtk_vdec_h264_get_mv_buf_size(unsigned int width, unsigned int height); 273 + 274 + #endif
+44 -383
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
··· 12 12 #include "../vdec_drv_base.h" 13 13 #include "../vdec_drv_if.h" 14 14 #include "../vdec_vpu_if.h" 15 - 16 - #define BUF_PREDICTION_SZ (64 * 4096) 17 - #define MB_UNIT_LEN 16 18 - 19 - /* get used parameters for sps/pps */ 20 - #define GET_MTK_VDEC_FLAG(cond, flag) \ 21 - { dst_param->cond = ((src_param->flags & (flag)) ? (1) : (0)); } 22 - #define GET_MTK_VDEC_PARAM(param) \ 23 - { dst_param->param = src_param->param; } 24 - /* motion vector size (bytes) for every macro block */ 25 - #define HW_MB_STORE_SZ 64 26 - 27 - #define H264_MAX_FB_NUM 17 28 - #define H264_MAX_MV_NUM 32 29 - #define HDR_PARSING_BUF_SZ 1024 30 - 31 - /** 32 - * struct mtk_h264_dpb_info - h264 dpb information 33 - * @y_dma_addr: Y bitstream physical address 34 - * @c_dma_addr: CbCr bitstream physical address 35 - * @reference_flag: reference picture flag (short/long term reference picture) 36 - * @field: field picture flag 37 - */ 38 - struct mtk_h264_dpb_info { 39 - dma_addr_t y_dma_addr; 40 - dma_addr_t c_dma_addr; 41 - int reference_flag; 42 - int field; 43 - }; 44 - 45 - /* 46 - * struct mtk_h264_sps_param - parameters for sps 47 - */ 48 - struct mtk_h264_sps_param { 49 - unsigned char chroma_format_idc; 50 - unsigned char bit_depth_luma_minus8; 51 - unsigned char bit_depth_chroma_minus8; 52 - unsigned char log2_max_frame_num_minus4; 53 - unsigned char pic_order_cnt_type; 54 - unsigned char log2_max_pic_order_cnt_lsb_minus4; 55 - unsigned char max_num_ref_frames; 56 - unsigned char separate_colour_plane_flag; 57 - unsigned short pic_width_in_mbs_minus1; 58 - unsigned short pic_height_in_map_units_minus1; 59 - unsigned int max_frame_nums; 60 - unsigned char qpprime_y_zero_transform_bypass_flag; 61 - unsigned char delta_pic_order_always_zero_flag; 62 - unsigned char frame_mbs_only_flag; 63 - unsigned char mb_adaptive_frame_field_flag; 64 - unsigned char direct_8x8_inference_flag; 65 - unsigned char reserved[3]; 66 - }; 67 - 68 - /* 69 - * struct mtk_h264_pps_param - parameters for pps 70 - */ 71 - struct mtk_h264_pps_param { 72 - unsigned char num_ref_idx_l0_default_active_minus1; 73 - unsigned char num_ref_idx_l1_default_active_minus1; 74 - unsigned char weighted_bipred_idc; 75 - char pic_init_qp_minus26; 76 - char chroma_qp_index_offset; 77 - char second_chroma_qp_index_offset; 78 - unsigned char entropy_coding_mode_flag; 79 - unsigned char pic_order_present_flag; 80 - unsigned char deblocking_filter_control_present_flag; 81 - unsigned char constrained_intra_pred_flag; 82 - unsigned char weighted_pred_flag; 83 - unsigned char redundant_pic_cnt_present_flag; 84 - unsigned char transform_8x8_mode_flag; 85 - unsigned char scaling_matrix_present_flag; 86 - unsigned char reserved[2]; 87 - }; 88 - 89 - struct slice_api_h264_scaling_matrix { 90 - unsigned char scaling_list_4x4[6][16]; 91 - unsigned char scaling_list_8x8[6][64]; 92 - }; 93 - 94 - struct slice_h264_dpb_entry { 95 - unsigned long long reference_ts; 96 - unsigned short frame_num; 97 - unsigned short pic_num; 98 - /* Note that field is indicated by v4l2_buffer.field */ 99 - int top_field_order_cnt; 100 - int bottom_field_order_cnt; 101 - unsigned int flags; /* V4L2_H264_DPB_ENTRY_FLAG_* */ 102 - }; 103 - 104 - /* 105 - * struct slice_api_h264_decode_param - parameters for decode. 106 - */ 107 - struct slice_api_h264_decode_param { 108 - struct slice_h264_dpb_entry dpb[16]; 109 - unsigned short num_slices; 110 - unsigned short nal_ref_idc; 111 - unsigned char ref_pic_list_p0[32]; 112 - unsigned char ref_pic_list_b0[32]; 113 - unsigned char ref_pic_list_b1[32]; 114 - int top_field_order_cnt; 115 - int bottom_field_order_cnt; 116 - unsigned int flags; /* V4L2_H264_DECODE_PARAM_FLAG_* */ 117 - }; 15 + #include "vdec_h264_req_common.h" 118 16 119 17 /* 120 18 * struct mtk_h264_dec_slice_param - parameters for decode current frame ··· 23 125 struct slice_api_h264_scaling_matrix scaling_matrix; 24 126 struct slice_api_h264_decode_param decode_params; 25 127 struct mtk_h264_dpb_info h264_dpb_info[16]; 26 - }; 27 - 28 - /** 29 - * struct h264_fb - h264 decode frame buffer information 30 - * @vdec_fb_va : virtual address of struct vdec_fb 31 - * @y_fb_dma : dma address of Y frame buffer (luma) 32 - * @c_fb_dma : dma address of C frame buffer (chroma) 33 - * @poc : picture order count of frame buffer 34 - * @reserved : for 8 bytes alignment 35 - */ 36 - struct h264_fb { 37 - u64 vdec_fb_va; 38 - u64 y_fb_dma; 39 - u64 c_fb_dma; 40 - s32 poc; 41 - u32 reserved; 42 128 }; 43 129 44 130 /** ··· 94 212 struct v4l2_h264_dpb_entry dpb[16]; 95 213 }; 96 214 97 - static void *get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id) 215 + static int get_vdec_decode_parameters(struct vdec_h264_slice_inst *inst) 98 216 { 99 - struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, id); 100 - 101 - return ctrl->p_cur.p; 102 - } 103 - 104 - static void get_h264_dpb_list(struct vdec_h264_slice_inst *inst, 105 - struct mtk_h264_dec_slice_param *slice_param) 106 - { 107 - struct vb2_queue *vq; 108 - struct vb2_buffer *vb; 109 - struct vb2_v4l2_buffer *vb2_v4l2; 110 - u64 index; 111 - 112 - vq = v4l2_m2m_get_vq(inst->ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 113 - 114 - for (index = 0; index < ARRAY_SIZE(slice_param->decode_params.dpb); index++) { 115 - const struct slice_h264_dpb_entry *dpb; 116 - int vb2_index; 117 - 118 - dpb = &slice_param->decode_params.dpb[index]; 119 - if (!(dpb->flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)) { 120 - slice_param->h264_dpb_info[index].reference_flag = 0; 121 - continue; 122 - } 123 - 124 - vb2_index = vb2_find_timestamp(vq, dpb->reference_ts, 0); 125 - if (vb2_index < 0) { 126 - mtk_vcodec_err(inst, "Reference invalid: dpb_index(%lld) reference_ts(%lld)", 127 - index, dpb->reference_ts); 128 - continue; 129 - } 130 - /* 1 for short term reference, 2 for long term reference */ 131 - if (!(dpb->flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)) 132 - slice_param->h264_dpb_info[index].reference_flag = 1; 133 - else 134 - slice_param->h264_dpb_info[index].reference_flag = 2; 135 - 136 - vb = vq->bufs[vb2_index]; 137 - vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); 138 - slice_param->h264_dpb_info[index].field = vb2_v4l2->field; 139 - 140 - slice_param->h264_dpb_info[index].y_dma_addr = 141 - vb2_dma_contig_plane_dma_addr(vb, 0); 142 - if (inst->ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) { 143 - slice_param->h264_dpb_info[index].c_dma_addr = 144 - vb2_dma_contig_plane_dma_addr(vb, 1); 145 - } 146 - } 147 - } 148 - 149 - static void get_h264_sps_parameters(struct mtk_h264_sps_param *dst_param, 150 - const struct v4l2_ctrl_h264_sps *src_param) 151 - { 152 - GET_MTK_VDEC_PARAM(chroma_format_idc); 153 - GET_MTK_VDEC_PARAM(bit_depth_luma_minus8); 154 - GET_MTK_VDEC_PARAM(bit_depth_chroma_minus8); 155 - GET_MTK_VDEC_PARAM(log2_max_frame_num_minus4); 156 - GET_MTK_VDEC_PARAM(pic_order_cnt_type); 157 - GET_MTK_VDEC_PARAM(log2_max_pic_order_cnt_lsb_minus4); 158 - GET_MTK_VDEC_PARAM(max_num_ref_frames); 159 - GET_MTK_VDEC_PARAM(pic_width_in_mbs_minus1); 160 - GET_MTK_VDEC_PARAM(pic_height_in_map_units_minus1); 161 - 162 - GET_MTK_VDEC_FLAG(separate_colour_plane_flag, 163 - V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE); 164 - GET_MTK_VDEC_FLAG(qpprime_y_zero_transform_bypass_flag, 165 - V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS); 166 - GET_MTK_VDEC_FLAG(delta_pic_order_always_zero_flag, 167 - V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO); 168 - GET_MTK_VDEC_FLAG(frame_mbs_only_flag, 169 - V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY); 170 - GET_MTK_VDEC_FLAG(mb_adaptive_frame_field_flag, 171 - V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD); 172 - GET_MTK_VDEC_FLAG(direct_8x8_inference_flag, 173 - V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE); 174 - } 175 - 176 - static void get_h264_pps_parameters(struct mtk_h264_pps_param *dst_param, 177 - const struct v4l2_ctrl_h264_pps *src_param) 178 - { 179 - GET_MTK_VDEC_PARAM(num_ref_idx_l0_default_active_minus1); 180 - GET_MTK_VDEC_PARAM(num_ref_idx_l1_default_active_minus1); 181 - GET_MTK_VDEC_PARAM(weighted_bipred_idc); 182 - GET_MTK_VDEC_PARAM(pic_init_qp_minus26); 183 - GET_MTK_VDEC_PARAM(chroma_qp_index_offset); 184 - GET_MTK_VDEC_PARAM(second_chroma_qp_index_offset); 185 - 186 - GET_MTK_VDEC_FLAG(entropy_coding_mode_flag, 187 - V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE); 188 - GET_MTK_VDEC_FLAG(pic_order_present_flag, 189 - V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT); 190 - GET_MTK_VDEC_FLAG(weighted_pred_flag, 191 - V4L2_H264_PPS_FLAG_WEIGHTED_PRED); 192 - GET_MTK_VDEC_FLAG(deblocking_filter_control_present_flag, 193 - V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT); 194 - GET_MTK_VDEC_FLAG(constrained_intra_pred_flag, 195 - V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED); 196 - GET_MTK_VDEC_FLAG(redundant_pic_cnt_present_flag, 197 - V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT); 198 - GET_MTK_VDEC_FLAG(transform_8x8_mode_flag, 199 - V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE); 200 - GET_MTK_VDEC_FLAG(scaling_matrix_present_flag, 201 - V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT); 202 - } 203 - 204 - static void 205 - get_h264_scaling_matrix(struct slice_api_h264_scaling_matrix *dst_matrix, 206 - const struct v4l2_ctrl_h264_scaling_matrix *src_matrix) 207 - { 208 - memcpy(dst_matrix->scaling_list_4x4, src_matrix->scaling_list_4x4, 209 - sizeof(dst_matrix->scaling_list_4x4)); 210 - 211 - memcpy(dst_matrix->scaling_list_8x8, src_matrix->scaling_list_8x8, 212 - sizeof(dst_matrix->scaling_list_8x8)); 213 - } 214 - 215 - static void 216 - get_h264_decode_parameters(struct slice_api_h264_decode_param *dst_params, 217 - const struct v4l2_ctrl_h264_decode_params *src_params, 218 - const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]) 219 - { 220 - int i; 221 - 222 - for (i = 0; i < ARRAY_SIZE(dst_params->dpb); i++) { 223 - struct slice_h264_dpb_entry *dst_entry = &dst_params->dpb[i]; 224 - const struct v4l2_h264_dpb_entry *src_entry = &dpb[i]; 225 - 226 - dst_entry->reference_ts = src_entry->reference_ts; 227 - dst_entry->frame_num = src_entry->frame_num; 228 - dst_entry->pic_num = src_entry->pic_num; 229 - dst_entry->top_field_order_cnt = src_entry->top_field_order_cnt; 230 - dst_entry->bottom_field_order_cnt = 231 - src_entry->bottom_field_order_cnt; 232 - dst_entry->flags = src_entry->flags; 233 - } 234 - 235 - /* 236 - * num_slices is a leftover from the old H.264 support and is ignored 237 - * by the firmware. 238 - */ 239 - dst_params->num_slices = 0; 240 - dst_params->nal_ref_idc = src_params->nal_ref_idc; 241 - dst_params->top_field_order_cnt = src_params->top_field_order_cnt; 242 - dst_params->bottom_field_order_cnt = src_params->bottom_field_order_cnt; 243 - dst_params->flags = src_params->flags; 244 - } 245 - 246 - static bool dpb_entry_match(const struct v4l2_h264_dpb_entry *a, 247 - const struct v4l2_h264_dpb_entry *b) 248 - { 249 - return a->top_field_order_cnt == b->top_field_order_cnt && 250 - a->bottom_field_order_cnt == b->bottom_field_order_cnt; 251 - } 252 - 253 - /* 254 - * Move DPB entries of dec_param that refer to a frame already existing in dpb 255 - * into the already existing slot in dpb, and move other entries into new slots. 256 - * 257 - * This function is an adaptation of the similarly-named function in 258 - * hantro_h264.c. 259 - */ 260 - static void update_dpb(const struct v4l2_ctrl_h264_decode_params *dec_param, 261 - struct v4l2_h264_dpb_entry *dpb) 262 - { 263 - DECLARE_BITMAP(new, ARRAY_SIZE(dec_param->dpb)) = { 0, }; 264 - DECLARE_BITMAP(in_use, ARRAY_SIZE(dec_param->dpb)) = { 0, }; 265 - DECLARE_BITMAP(used, ARRAY_SIZE(dec_param->dpb)) = { 0, }; 266 - unsigned int i, j; 267 - 268 - /* Disable all entries by default, and mark the ones in use. */ 269 - for (i = 0; i < ARRAY_SIZE(dec_param->dpb); i++) { 270 - if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE) 271 - set_bit(i, in_use); 272 - dpb[i].flags &= ~V4L2_H264_DPB_ENTRY_FLAG_ACTIVE; 273 - } 274 - 275 - /* Try to match new DPB entries with existing ones by their POCs. */ 276 - for (i = 0; i < ARRAY_SIZE(dec_param->dpb); i++) { 277 - const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; 278 - 279 - if (!(ndpb->flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)) 280 - continue; 281 - 282 - /* 283 - * To cut off some comparisons, iterate only on target DPB 284 - * entries were already used. 285 - */ 286 - for_each_set_bit(j, in_use, ARRAY_SIZE(dec_param->dpb)) { 287 - struct v4l2_h264_dpb_entry *cdpb; 288 - 289 - cdpb = &dpb[j]; 290 - if (!dpb_entry_match(cdpb, ndpb)) 291 - continue; 292 - 293 - *cdpb = *ndpb; 294 - set_bit(j, used); 295 - /* Don't reiterate on this one. */ 296 - clear_bit(j, in_use); 297 - break; 298 - } 299 - 300 - if (j == ARRAY_SIZE(dec_param->dpb)) 301 - set_bit(i, new); 302 - } 303 - 304 - /* For entries that could not be matched, use remaining free slots. */ 305 - for_each_set_bit(i, new, ARRAY_SIZE(dec_param->dpb)) { 306 - const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; 307 - struct v4l2_h264_dpb_entry *cdpb; 308 - 309 - /* 310 - * Both arrays are of the same sizes, so there is no way 311 - * we can end up with no space in target array, unless 312 - * something is buggy. 313 - */ 314 - j = find_first_zero_bit(used, ARRAY_SIZE(dec_param->dpb)); 315 - if (WARN_ON(j >= ARRAY_SIZE(dec_param->dpb))) 316 - return; 317 - 318 - cdpb = &dpb[j]; 319 - *cdpb = *ndpb; 320 - set_bit(j, used); 321 - } 322 - } 323 - 324 - /* 325 - * The firmware expects unused reflist entries to have the value 0x20. 326 - */ 327 - static void fixup_ref_list(u8 *ref_list, size_t num_valid) 328 - { 329 - memset(&ref_list[num_valid], 0x20, 32 - num_valid); 330 - } 331 - 332 - static void get_vdec_decode_parameters(struct vdec_h264_slice_inst *inst) 333 - { 334 - const struct v4l2_ctrl_h264_decode_params *dec_params = 335 - get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS); 336 - const struct v4l2_ctrl_h264_sps *sps = 337 - get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS); 338 - const struct v4l2_ctrl_h264_pps *pps = 339 - get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS); 340 - const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix = 341 - get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX); 217 + const struct v4l2_ctrl_h264_decode_params *dec_params; 218 + const struct v4l2_ctrl_h264_sps *sps; 219 + const struct v4l2_ctrl_h264_pps *pps; 220 + const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix; 342 221 struct mtk_h264_dec_slice_param *slice_param = &inst->h264_slice_param; 343 222 struct v4l2_h264_reflist_builder reflist_builder; 344 223 u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0; 345 224 u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0; 346 225 u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1; 347 226 348 - update_dpb(dec_params, inst->dpb); 227 + dec_params = 228 + mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS); 229 + if (IS_ERR(dec_params)) 230 + return PTR_ERR(dec_params); 349 231 350 - get_h264_sps_parameters(&slice_param->sps, sps); 351 - get_h264_pps_parameters(&slice_param->pps, pps); 352 - get_h264_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix); 353 - get_h264_decode_parameters(&slice_param->decode_params, dec_params, 354 - inst->dpb); 355 - get_h264_dpb_list(inst, slice_param); 232 + sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS); 233 + if (IS_ERR(sps)) 234 + return PTR_ERR(sps); 235 + 236 + pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS); 237 + if (IS_ERR(pps)) 238 + return PTR_ERR(pps); 239 + 240 + scaling_matrix = 241 + mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX); 242 + if (IS_ERR(scaling_matrix)) 243 + return PTR_ERR(scaling_matrix); 244 + 245 + mtk_vdec_h264_update_dpb(dec_params, inst->dpb); 246 + 247 + mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps); 248 + mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps); 249 + mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix); 250 + mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, 251 + dec_params, inst->dpb); 252 + mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params, 253 + slice_param->h264_dpb_info); 356 254 357 255 /* Build the reference lists */ 358 256 v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, ··· 140 478 v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist); 141 479 v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist); 142 480 /* Adapt the built lists to the firmware's expectations */ 143 - fixup_ref_list(p0_reflist, reflist_builder.num_valid); 144 - fixup_ref_list(b0_reflist, reflist_builder.num_valid); 145 - fixup_ref_list(b1_reflist, reflist_builder.num_valid); 481 + mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid); 482 + mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid); 483 + mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid); 146 484 147 485 memcpy(&inst->vsi_ctx.h264_slice_params, slice_param, 148 486 sizeof(inst->vsi_ctx.h264_slice_params)); 149 - } 150 487 151 - static unsigned int get_mv_buf_size(unsigned int width, unsigned int height) 152 - { 153 - int unit_size = (width / MB_UNIT_LEN) * (height / MB_UNIT_LEN) + 8; 154 - 155 - return HW_MB_STORE_SZ * unit_size; 488 + return 0; 156 489 } 157 490 158 491 static int allocate_predication_buf(struct vdec_h264_slice_inst *inst) ··· 182 525 int i; 183 526 int err; 184 527 struct mtk_vcodec_mem *mem = NULL; 185 - unsigned int buf_sz = get_mv_buf_size(pic->buf_w, pic->buf_h); 528 + unsigned int buf_sz = mtk_vdec_h264_get_mv_buf_size(pic->buf_w, pic->buf_h); 186 529 187 530 mtk_v4l2_debug(3, "size = 0x%x", buf_sz); 188 531 for (i = 0; i < H264_MAX_MV_NUM; i++) { ··· 331 674 { 332 675 struct vdec_h264_slice_inst *inst = h_vdec; 333 676 const struct v4l2_ctrl_h264_decode_params *dec_params = 334 - get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS); 677 + mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS); 335 678 struct vdec_vpu_inst *vpu = &inst->vpu; 336 679 struct mtk_video_dec_buf *src_buf_info; 337 680 struct mtk_video_dec_buf *dst_buf_info; ··· 341 684 u64 c_fb_dma; 342 685 int err; 343 686 687 + inst->num_nalu++; 344 688 /* bs NULL means flush decoder */ 345 689 if (!bs) 346 690 return vpu_dec_reset(vpu); ··· 354 696 c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0; 355 697 356 698 mtk_vcodec_debug(inst, "+ [%d] FB y_dma=%llx c_dma=%llx va=%p", 357 - ++inst->num_nalu, y_fb_dma, c_fb_dma, fb); 699 + inst->num_nalu, y_fb_dma, c_fb_dma, fb); 358 700 359 701 inst->vsi_ctx.dec.bs_dma = (uint64_t)bs->dma_addr; 360 702 inst->vsi_ctx.dec.y_fb_dma = y_fb_dma; ··· 363 705 364 706 v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, 365 707 &dst_buf_info->m2m_buf.vb, true); 366 - get_vdec_decode_parameters(inst); 708 + err = get_vdec_decode_parameters(inst); 709 + if (err) 710 + goto err_free_fb_out; 711 + 367 712 data[0] = bs->size; 368 713 /* 369 714 * Reconstruct the first byte of the NAL unit, as the firmware requests