Lines Matching +full:rk3288 +full:- +full:vpu
1 // SPDX-License-Identifier: GPL-2.0
3 * Rockchip RK3288 VPU codec driver
6 * Hertz Wong <hertz.wong@rock-chips.com>
7 * Herman Chen <herman.chen@rock-chips.com>
14 #include <media/v4l2-h264.h>
15 #include <media/v4l2-mem2mem.h>
29 #define REF_BIT(i) BIT(32 - 1 - (i))
40 * From drivers/media/platform/rk3288-vpu/rk3288_vpu_hw_h264d.c
42 * chromeos-3.14 branch.
204 const struct hantro_h264_dec_ctrls *ctrls = &ctx->h264_dec.ctrls; in assemble_scaling_list()
205 const struct v4l2_ctrl_h264_scaling_matrix *scaling = ctrls->scaling; in assemble_scaling_list()
206 const struct v4l2_ctrl_h264_pps *pps = ctrls->pps; in assemble_scaling_list()
207 const size_t num_list_4x4 = ARRAY_SIZE(scaling->scaling_list_4x4); in assemble_scaling_list()
208 const size_t list_len_4x4 = ARRAY_SIZE(scaling->scaling_list_4x4[0]); in assemble_scaling_list()
209 const size_t list_len_8x8 = ARRAY_SIZE(scaling->scaling_list_8x8[0]); in assemble_scaling_list()
210 struct hantro_h264_dec_priv_tbl *tbl = ctx->h264_dec.priv.cpu; in assemble_scaling_list()
211 u32 *dst = (u32 *)tbl->scaling_list; in assemble_scaling_list()
215 if (!(pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT)) in assemble_scaling_list()
219 src = (u32 *)&scaling->scaling_list_4x4[i]; in assemble_scaling_list()
226 src = (u32 *)&scaling->scaling_list_8x8[i]; in assemble_scaling_list()
234 const struct hantro_h264_dec_ctrls *ctrls = &ctx->h264_dec.ctrls; in prepare_table()
235 const struct v4l2_ctrl_h264_decode_params *dec_param = ctrls->decode; in prepare_table()
236 const struct v4l2_ctrl_h264_sps *sps = ctrls->sps; in prepare_table()
237 struct hantro_h264_dec_priv_tbl *tbl = ctx->h264_dec.priv.cpu; in prepare_table()
238 const struct v4l2_h264_dpb_entry *dpb = ctx->h264_dec.dpb; in prepare_table()
244 tbl->poc[i * 2] = dpb[i].top_field_order_cnt; in prepare_table()
245 tbl->poc[i * 2 + 1] = dpb[i].bottom_field_order_cnt; in prepare_table()
257 if (dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC) { in prepare_table()
275 ctx->h264_dec.dpb_valid = dpb_valid; in prepare_table()
276 ctx->h264_dec.dpb_longterm = dpb_longterm; in prepare_table()
278 if ((dec_param->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC) || in prepare_table()
279 !(sps->flags & V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD)) { in prepare_table()
280 tbl->poc[32] = ctx->h264_dec.cur_poc; in prepare_table()
281 tbl->poc[33] = 0; in prepare_table()
283 tbl->poc[32] = dec_param->top_field_order_cnt; in prepare_table()
284 tbl->poc[33] = dec_param->bottom_field_order_cnt; in prepare_table()
293 return a->reference_ts == b->reference_ts; in dpb_entry_match()
299 DECLARE_BITMAP(new, ARRAY_SIZE(dec_param->dpb)) = { 0, }; in update_dpb()
300 DECLARE_BITMAP(used, ARRAY_SIZE(dec_param->dpb)) = { 0, }; in update_dpb()
303 dec_param = ctx->h264_dec.ctrls.decode; in update_dpb()
306 for (i = 0; i < ARRAY_SIZE(ctx->h264_dec.dpb); i++) in update_dpb()
307 ctx->h264_dec.dpb[i].flags = 0; in update_dpb()
310 for (i = 0; i < ARRAY_SIZE(dec_param->dpb); i++) { in update_dpb()
311 const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; in update_dpb()
313 if (!(ndpb->flags & V4L2_H264_DPB_ENTRY_FLAG_VALID)) in update_dpb()
320 for_each_clear_bit(j, used, ARRAY_SIZE(ctx->h264_dec.dpb)) { in update_dpb()
323 cdpb = &ctx->h264_dec.dpb[j]; in update_dpb()
332 if (j == ARRAY_SIZE(ctx->h264_dec.dpb)) in update_dpb()
337 for_each_set_bit(i, new, ARRAY_SIZE(dec_param->dpb)) { in update_dpb()
338 const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; in update_dpb()
346 j = find_first_zero_bit(used, ARRAY_SIZE(ctx->h264_dec.dpb)); in update_dpb()
347 if (WARN_ON(j >= ARRAY_SIZE(ctx->h264_dec.dpb))) in update_dpb()
350 cdpb = &ctx->h264_dec.dpb[j]; in update_dpb()
359 struct v4l2_h264_dpb_entry *dpb = ctx->h264_dec.dpb; in hantro_h264_get_ref_buf()
361 s32 cur_poc = ctx->h264_dec.cur_poc; in hantro_h264_get_ref_buf()
376 buf = &dst_buf->vb2_buf; in hantro_h264_get_ref_buf()
381 flags |= abs(dpb[dpb_idx].top_field_order_cnt - cur_poc) < in hantro_h264_get_ref_buf()
382 abs(dpb[dpb_idx].bottom_field_order_cnt - cur_poc) ? in hantro_h264_get_ref_buf()
390 const struct v4l2_h264_dpb_entry *dpb = &ctx->h264_dec.dpb[dpb_idx]; in hantro_h264_get_ref_nbr()
392 if (!(dpb->flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)) in hantro_h264_get_ref_nbr()
394 return dpb->frame_num; in hantro_h264_get_ref_nbr()
408 * to identify un-paired fields and avoid removing them.
416 if (b->cur_pic_fields == V4L2_H264_FRAME_REF) { in deduplicate_reflist()
417 write_idx = b->num_valid; in deduplicate_reflist()
421 for (i = 0; i < b->num_valid; i++) { in deduplicate_reflist()
422 if (!(b->cur_pic_fields == reflist[i].fields)) { in deduplicate_reflist()
440 struct hantro_h264_dec_hw_ctx *h264_ctx = &ctx->h264_dec; in hantro_h264_dec_prepare_run()
441 struct hantro_h264_dec_ctrls *ctrls = &h264_ctx->ctrls; in hantro_h264_dec_prepare_run()
446 ctrls->scaling = in hantro_h264_dec_prepare_run()
448 if (WARN_ON(!ctrls->scaling)) in hantro_h264_dec_prepare_run()
449 return -EINVAL; in hantro_h264_dec_prepare_run()
451 ctrls->decode = in hantro_h264_dec_prepare_run()
453 if (WARN_ON(!ctrls->decode)) in hantro_h264_dec_prepare_run()
454 return -EINVAL; in hantro_h264_dec_prepare_run()
456 ctrls->sps = in hantro_h264_dec_prepare_run()
458 if (WARN_ON(!ctrls->sps)) in hantro_h264_dec_prepare_run()
459 return -EINVAL; in hantro_h264_dec_prepare_run()
461 ctrls->pps = in hantro_h264_dec_prepare_run()
463 if (WARN_ON(!ctrls->pps)) in hantro_h264_dec_prepare_run()
464 return -EINVAL; in hantro_h264_dec_prepare_run()
470 v4l2_h264_init_reflist_builder(&reflist_builder, ctrls->decode, in hantro_h264_dec_prepare_run()
471 ctrls->sps, ctx->h264_dec.dpb); in hantro_h264_dec_prepare_run()
472 h264_ctx->cur_poc = reflist_builder.cur_pic_order_count; in hantro_h264_dec_prepare_run()
477 v4l2_h264_build_p_ref_list(&reflist_builder, h264_ctx->reflists.p); in hantro_h264_dec_prepare_run()
478 v4l2_h264_build_b_ref_lists(&reflist_builder, h264_ctx->reflists.b0, in hantro_h264_dec_prepare_run()
479 h264_ctx->reflists.b1); in hantro_h264_dec_prepare_run()
487 deduplicate_reflist(&reflist_builder, h264_ctx->reflists.p); in hantro_h264_dec_prepare_run()
488 deduplicate_reflist(&reflist_builder, h264_ctx->reflists.b0); in hantro_h264_dec_prepare_run()
489 deduplicate_reflist(&reflist_builder, h264_ctx->reflists.b1); in hantro_h264_dec_prepare_run()
497 struct hantro_dev *vpu = ctx->dev; in hantro_h264_dec_exit() local
498 struct hantro_h264_dec_hw_ctx *h264_dec = &ctx->h264_dec; in hantro_h264_dec_exit()
499 struct hantro_aux_buf *priv = &h264_dec->priv; in hantro_h264_dec_exit()
501 dma_free_coherent(vpu->dev, priv->size, priv->cpu, priv->dma); in hantro_h264_dec_exit()
506 struct hantro_dev *vpu = ctx->dev; in hantro_h264_dec_init() local
507 struct hantro_h264_dec_hw_ctx *h264_dec = &ctx->h264_dec; in hantro_h264_dec_init()
508 struct hantro_aux_buf *priv = &h264_dec->priv; in hantro_h264_dec_init()
511 priv->cpu = dma_alloc_coherent(vpu->dev, sizeof(*tbl), &priv->dma, in hantro_h264_dec_init()
513 if (!priv->cpu) in hantro_h264_dec_init()
514 return -ENOMEM; in hantro_h264_dec_init()
516 priv->size = sizeof(*tbl); in hantro_h264_dec_init()
517 tbl = priv->cpu; in hantro_h264_dec_init()
518 memcpy(tbl->cabac_table, h264_cabac_table, sizeof(tbl->cabac_table)); in hantro_h264_dec_init()