Lines Matching refs:ctx

224 static int s5p_mfc_ctx_ready(struct s5p_mfc_ctx *ctx)  in s5p_mfc_ctx_ready()  argument
227 if (ctx->src_queue_cnt >= 1 && ctx->state == MFCINST_GOT_INST) in s5p_mfc_ctx_ready()
230 if (ctx->src_queue_cnt >= 1 && in s5p_mfc_ctx_ready()
231 ctx->state == MFCINST_RUNNING && in s5p_mfc_ctx_ready()
232 ctx->dst_queue_cnt >= ctx->pb_count) in s5p_mfc_ctx_ready()
235 if (ctx->state == MFCINST_FINISHING && in s5p_mfc_ctx_ready()
236 ctx->dst_queue_cnt >= ctx->pb_count) in s5p_mfc_ctx_ready()
239 if (ctx->src_queue_cnt >= 1 && in s5p_mfc_ctx_ready()
240 ctx->state == MFCINST_HEAD_PARSED && in s5p_mfc_ctx_ready()
241 ctx->capture_state == QUEUE_BUFS_MMAPED) in s5p_mfc_ctx_ready()
244 if ((ctx->state == MFCINST_RES_CHANGE_INIT || in s5p_mfc_ctx_ready()
245 ctx->state == MFCINST_RES_CHANGE_FLUSH) && in s5p_mfc_ctx_ready()
246 ctx->dst_queue_cnt >= ctx->pb_count) in s5p_mfc_ctx_ready()
248 if (ctx->state == MFCINST_RES_CHANGE_END && in s5p_mfc_ctx_ready()
249 ctx->src_queue_cnt >= 1) in s5p_mfc_ctx_ready()
324 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_g_fmt() local
330 (ctx->state == MFCINST_GOT_INST || ctx->state == in vidioc_g_fmt()
334 s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_SEQ_DONE_RET, in vidioc_g_fmt()
338 ctx->state >= MFCINST_HEAD_PARSED && in vidioc_g_fmt()
339 ctx->state < MFCINST_ABORT) { in vidioc_g_fmt()
345 pix_mp->width = ctx->buf_width; in vidioc_g_fmt()
346 pix_mp->height = ctx->buf_height; in vidioc_g_fmt()
351 pix_mp->pixelformat = ctx->dst_fmt->fourcc; in vidioc_g_fmt()
352 pix_mp->plane_fmt[0].bytesperline = ctx->buf_width; in vidioc_g_fmt()
353 pix_mp->plane_fmt[0].sizeimage = ctx->luma_size; in vidioc_g_fmt()
354 pix_mp->plane_fmt[1].bytesperline = ctx->buf_width; in vidioc_g_fmt()
355 pix_mp->plane_fmt[1].sizeimage = ctx->chroma_size; in vidioc_g_fmt()
363 pix_mp->plane_fmt[0].bytesperline = ctx->dec_src_buf_size; in vidioc_g_fmt()
364 pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size; in vidioc_g_fmt()
365 pix_mp->pixelformat = ctx->src_fmt->fourcc; in vidioc_g_fmt()
366 pix_mp->num_planes = ctx->src_fmt->num_planes; in vidioc_g_fmt()
416 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_s_fmt() local
426 if (ctx->vq_src.streaming || ctx->vq_dst.streaming) { in vidioc_s_fmt()
433 ctx->dst_fmt = find_format(f, MFC_FMT_RAW); in vidioc_s_fmt()
438 ctx->src_fmt = find_format(f, MFC_FMT_DEC); in vidioc_s_fmt()
439 ctx->codec_mode = ctx->src_fmt->codec_mode; in vidioc_s_fmt()
440 mfc_debug(2, "The codec number is: %d\n", ctx->codec_mode); in vidioc_s_fmt()
444 pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size = in vidioc_s_fmt()
447 ctx->dec_src_buf_size = buf_size->cpb; in vidioc_s_fmt()
449 ctx->dec_src_buf_size = pix_mp->plane_fmt[0].sizeimage; in vidioc_s_fmt()
451 ctx->state = MFCINST_INIT; in vidioc_s_fmt()
465 static int reqbufs_output(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx, in reqbufs_output() argument
474 ret = vb2_reqbufs(&ctx->vq_src, reqbufs); in reqbufs_output()
477 s5p_mfc_close_mfc_inst(dev, ctx); in reqbufs_output()
478 ctx->src_bufs_cnt = 0; in reqbufs_output()
479 ctx->output_state = QUEUE_FREE; in reqbufs_output()
480 } else if (ctx->output_state == QUEUE_FREE) { in reqbufs_output()
482 WARN_ON(ctx->src_bufs_cnt != 0); in reqbufs_output()
483 if (ctx->state != MFCINST_INIT) { in reqbufs_output()
491 ret = vb2_reqbufs(&ctx->vq_src, reqbufs); in reqbufs_output()
495 ret = s5p_mfc_open_mfc_inst(dev, ctx); in reqbufs_output()
498 vb2_reqbufs(&ctx->vq_src, reqbufs); in reqbufs_output()
502 ctx->output_state = QUEUE_BUFS_REQUESTED; in reqbufs_output()
514 static int reqbufs_capture(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx, in reqbufs_capture() argument
523 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); in reqbufs_capture()
526 s5p_mfc_hw_call_void(dev->mfc_ops, release_codec_buffers, ctx); in reqbufs_capture()
527 ctx->dst_bufs_cnt = 0; in reqbufs_capture()
528 } else if (ctx->capture_state == QUEUE_FREE) { in reqbufs_capture()
529 WARN_ON(ctx->dst_bufs_cnt != 0); in reqbufs_capture()
532 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); in reqbufs_capture()
536 ctx->capture_state = QUEUE_BUFS_REQUESTED; in reqbufs_capture()
537 ctx->total_dpb_count = reqbufs->count; in reqbufs_capture()
539 ret = s5p_mfc_hw_call(dev->mfc_ops, alloc_codec_buffers, ctx); in reqbufs_capture()
543 vb2_reqbufs(&ctx->vq_dst, reqbufs); in reqbufs_capture()
545 ctx->capture_state = QUEUE_FREE; in reqbufs_capture()
549 WARN_ON(ctx->dst_bufs_cnt != ctx->total_dpb_count); in reqbufs_capture()
550 ctx->capture_state = QUEUE_BUFS_MMAPED; in reqbufs_capture()
552 if (s5p_mfc_ctx_ready(ctx)) in reqbufs_capture()
553 set_work_bit_irqsave(ctx); in reqbufs_capture()
555 s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_INIT_BUFFERS_RET, in reqbufs_capture()
573 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_reqbufs() local
581 return reqbufs_output(dev, ctx, reqbufs); in vidioc_reqbufs()
583 return reqbufs_capture(dev, ctx, reqbufs); in vidioc_reqbufs()
594 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_querybuf() local
602 mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type); in vidioc_querybuf()
603 if (ctx->state == MFCINST_GOT_INST && in vidioc_querybuf()
605 ret = vb2_querybuf(&ctx->vq_src, buf); in vidioc_querybuf()
606 } else if (ctx->state == MFCINST_RUNNING && in vidioc_querybuf()
608 ret = vb2_querybuf(&ctx->vq_dst, buf); in vidioc_querybuf()
622 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_qbuf() local
624 if (ctx->state == MFCINST_ERROR) { in vidioc_qbuf()
629 return vb2_qbuf(&ctx->vq_src, buf); in vidioc_qbuf()
631 return vb2_qbuf(&ctx->vq_dst, buf); in vidioc_qbuf()
641 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_dqbuf() local
644 if (ctx->state == MFCINST_ERROR) { in vidioc_dqbuf()
649 ret = vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK); in vidioc_dqbuf()
651 ret = vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK); in vidioc_dqbuf()
652 if (ret == 0 && ctx->state == MFCINST_FINISHED && in vidioc_dqbuf()
653 list_empty(&ctx->vq_dst.done_list)) in vidioc_dqbuf()
654 v4l2_event_queue_fh(&ctx->fh, &ev); in vidioc_dqbuf()
665 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_expbuf() local
668 return vb2_expbuf(&ctx->vq_src, eb); in vidioc_expbuf()
670 return vb2_expbuf(&ctx->vq_dst, eb); in vidioc_expbuf()
678 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_streamon() local
683 ret = vb2_streamon(&ctx->vq_src, type); in vidioc_streamon()
685 ret = vb2_streamon(&ctx->vq_dst, type); in vidioc_streamon()
694 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_streamoff() local
697 return vb2_streamoff(&ctx->vq_src, type); in vidioc_streamoff()
699 return vb2_streamoff(&ctx->vq_dst, type); in vidioc_streamoff()
706 struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl); in s5p_mfc_dec_s_ctrl() local
710 ctx->display_delay = ctrl->val; in s5p_mfc_dec_s_ctrl()
713 ctx->display_delay_enable = ctrl->val; in s5p_mfc_dec_s_ctrl()
716 ctx->loop_filter_mpeg4 = ctrl->val; in s5p_mfc_dec_s_ctrl()
719 ctx->slice_interface = ctrl->val; in s5p_mfc_dec_s_ctrl()
730 struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl); in s5p_mfc_dec_g_v_ctrl() local
731 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_dec_g_v_ctrl()
735 if (ctx->state >= MFCINST_HEAD_PARSED && in s5p_mfc_dec_g_v_ctrl()
736 ctx->state < MFCINST_ABORT) { in s5p_mfc_dec_g_v_ctrl()
737 ctrl->val = ctx->pb_count; in s5p_mfc_dec_g_v_ctrl()
739 } else if (ctx->state != MFCINST_INIT && in s5p_mfc_dec_g_v_ctrl()
740 ctx->state != MFCINST_RES_CHANGE_END) { in s5p_mfc_dec_g_v_ctrl()
745 s5p_mfc_wait_for_done_ctx(ctx, in s5p_mfc_dec_g_v_ctrl()
747 if (ctx->state >= MFCINST_HEAD_PARSED && in s5p_mfc_dec_g_v_ctrl()
748 ctx->state < MFCINST_ABORT) { in s5p_mfc_dec_g_v_ctrl()
749 ctrl->val = ctx->pb_count; in s5p_mfc_dec_g_v_ctrl()
769 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_g_crop() local
770 struct s5p_mfc_dev *dev = ctx->dev; in vidioc_g_crop()
773 if (ctx->state != MFCINST_HEAD_PARSED && in vidioc_g_crop()
774 ctx->state != MFCINST_RUNNING && ctx->state != MFCINST_FINISHING in vidioc_g_crop()
775 && ctx->state != MFCINST_FINISHED) { in vidioc_g_crop()
779 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_H264) { in vidioc_g_crop()
780 left = s5p_mfc_hw_call(dev->mfc_ops, get_crop_info_h, ctx); in vidioc_g_crop()
783 top = s5p_mfc_hw_call(dev->mfc_ops, get_crop_info_v, ctx); in vidioc_g_crop()
788 cr->c.width = ctx->img_width - left - right; in vidioc_g_crop()
789 cr->c.height = ctx->img_height - top - bottom; in vidioc_g_crop()
793 ctx->buf_width, ctx->buf_height); in vidioc_g_crop()
797 cr->c.width = ctx->img_width; in vidioc_g_crop()
798 cr->c.height = ctx->img_height; in vidioc_g_crop()
800 "fh=%d\n", cr->c.width, cr->c.height, ctx->buf_width, in vidioc_g_crop()
801 ctx->buf_height); in vidioc_g_crop()
809 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); in vidioc_decoder_cmd() local
810 struct s5p_mfc_dev *dev = ctx->dev; in vidioc_decoder_cmd()
819 if (!ctx->vq_src.streaming) in vidioc_decoder_cmd()
823 if (list_empty(&ctx->src_queue)) { in vidioc_decoder_cmd()
825 ctx->state = MFCINST_FINISHING; in vidioc_decoder_cmd()
826 if (s5p_mfc_ctx_ready(ctx)) in vidioc_decoder_cmd()
827 set_work_bit_irqsave(ctx); in vidioc_decoder_cmd()
832 buf = list_entry(ctx->src_queue.prev, in vidioc_decoder_cmd()
835 ctx->state = MFCINST_FINISHING; in vidioc_decoder_cmd()
890 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv); in s5p_mfc_queue_setup() local
891 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_queue_setup()
895 if (ctx->state == MFCINST_INIT && in s5p_mfc_queue_setup()
905 } else if (ctx->state == MFCINST_HEAD_PARSED && in s5p_mfc_queue_setup()
910 if (*buf_count < ctx->pb_count) in s5p_mfc_queue_setup()
911 *buf_count = ctx->pb_count; in s5p_mfc_queue_setup()
912 if (*buf_count > ctx->pb_count + MFC_MAX_EXTRA_DPB) in s5p_mfc_queue_setup()
913 *buf_count = ctx->pb_count + MFC_MAX_EXTRA_DPB; in s5p_mfc_queue_setup()
918 ctx->state, vq->type); in s5p_mfc_queue_setup()
923 if (ctx->state == MFCINST_HEAD_PARSED && in s5p_mfc_queue_setup()
925 psize[0] = ctx->luma_size; in s5p_mfc_queue_setup()
926 psize[1] = ctx->chroma_size; in s5p_mfc_queue_setup()
930 ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX]; in s5p_mfc_queue_setup()
933 ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX]; in s5p_mfc_queue_setup()
934 allocators[1] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX]; in s5p_mfc_queue_setup()
936 ctx->state == MFCINST_INIT) { in s5p_mfc_queue_setup()
937 psize[0] = ctx->dec_src_buf_size; in s5p_mfc_queue_setup()
938 allocators[0] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX]; in s5p_mfc_queue_setup()
949 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv); in s5p_mfc_buf_init() local
953 if (ctx->capture_state == QUEUE_BUFS_MMAPED) in s5p_mfc_buf_init()
955 for (i = 0; i < ctx->dst_fmt->num_planes; i++) { in s5p_mfc_buf_init()
962 if (vb2_plane_size(vb, 0) < ctx->luma_size || in s5p_mfc_buf_init()
963 vb2_plane_size(vb, 1) < ctx->chroma_size) { in s5p_mfc_buf_init()
968 ctx->dst_bufs[i].b = vb; in s5p_mfc_buf_init()
969 ctx->dst_bufs[i].cookie.raw.luma = in s5p_mfc_buf_init()
971 ctx->dst_bufs[i].cookie.raw.chroma = in s5p_mfc_buf_init()
973 ctx->dst_bufs_cnt++; in s5p_mfc_buf_init()
980 if (vb2_plane_size(vb, 0) < ctx->dec_src_buf_size) { in s5p_mfc_buf_init()
986 ctx->src_bufs[i].b = vb; in s5p_mfc_buf_init()
987 ctx->src_bufs[i].cookie.stream = in s5p_mfc_buf_init()
989 ctx->src_bufs_cnt++; in s5p_mfc_buf_init()
999 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv); in s5p_mfc_start_streaming() local
1000 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_start_streaming()
1002 v4l2_ctrl_handler_setup(&ctx->ctrl_handler); in s5p_mfc_start_streaming()
1003 if (ctx->state == MFCINST_FINISHING || in s5p_mfc_start_streaming()
1004 ctx->state == MFCINST_FINISHED) in s5p_mfc_start_streaming()
1005 ctx->state = MFCINST_RUNNING; in s5p_mfc_start_streaming()
1007 if (s5p_mfc_ctx_ready(ctx)) in s5p_mfc_start_streaming()
1008 set_work_bit_irqsave(ctx); in s5p_mfc_start_streaming()
1016 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv); in s5p_mfc_stop_streaming() local
1017 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_stop_streaming()
1020 if ((ctx->state == MFCINST_FINISHING || in s5p_mfc_stop_streaming()
1021 ctx->state == MFCINST_RUNNING) && in s5p_mfc_stop_streaming()
1022 dev->curr_ctx == ctx->num && dev->hw_lock) { in s5p_mfc_stop_streaming()
1023 ctx->state = MFCINST_ABORT; in s5p_mfc_stop_streaming()
1024 s5p_mfc_wait_for_done_ctx(ctx, in s5p_mfc_stop_streaming()
1031 &ctx->dst_queue, &ctx->vq_dst); in s5p_mfc_stop_streaming()
1032 INIT_LIST_HEAD(&ctx->dst_queue); in s5p_mfc_stop_streaming()
1033 ctx->dst_queue_cnt = 0; in s5p_mfc_stop_streaming()
1034 ctx->dpb_flush_flag = 1; in s5p_mfc_stop_streaming()
1035 ctx->dec_dst_flag = 0; in s5p_mfc_stop_streaming()
1037 if (IS_MFCV6_PLUS(dev) && (ctx->state == MFCINST_RUNNING)) { in s5p_mfc_stop_streaming()
1038 ctx->state = MFCINST_FLUSH; in s5p_mfc_stop_streaming()
1039 set_work_bit_irqsave(ctx); in s5p_mfc_stop_streaming()
1041 if (s5p_mfc_wait_for_done_ctx(ctx, in s5p_mfc_stop_streaming()
1049 &ctx->src_queue, &ctx->vq_src); in s5p_mfc_stop_streaming()
1050 INIT_LIST_HEAD(&ctx->src_queue); in s5p_mfc_stop_streaming()
1051 ctx->src_queue_cnt = 0; in s5p_mfc_stop_streaming()
1055 ctx->state = MFCINST_RUNNING; in s5p_mfc_stop_streaming()
1062 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv); in s5p_mfc_buf_queue() local
1063 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_buf_queue()
1068 mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index]; in s5p_mfc_buf_queue()
1071 list_add_tail(&mfc_buf->list, &ctx->src_queue); in s5p_mfc_buf_queue()
1072 ctx->src_queue_cnt++; in s5p_mfc_buf_queue()
1075 mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index]; in s5p_mfc_buf_queue()
1079 set_bit(vb->v4l2_buf.index, &ctx->dec_dst_flag); in s5p_mfc_buf_queue()
1080 list_add_tail(&mfc_buf->list, &ctx->dst_queue); in s5p_mfc_buf_queue()
1081 ctx->dst_queue_cnt++; in s5p_mfc_buf_queue()
1086 if (s5p_mfc_ctx_ready(ctx)) in s5p_mfc_buf_queue()
1087 set_work_bit_irqsave(ctx); in s5p_mfc_buf_queue()
1119 int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx) in s5p_mfc_dec_ctrls_setup() argument
1124 v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS); in s5p_mfc_dec_ctrls_setup()
1125 if (ctx->ctrl_handler.error) { in s5p_mfc_dec_ctrls_setup()
1127 return ctx->ctrl_handler.error; in s5p_mfc_dec_ctrls_setup()
1144 ctx->ctrls[i] = v4l2_ctrl_new_custom(&ctx->ctrl_handler, in s5p_mfc_dec_ctrls_setup()
1147 ctx->ctrls[i] = v4l2_ctrl_new_std(&ctx->ctrl_handler, in s5p_mfc_dec_ctrls_setup()
1153 if (ctx->ctrl_handler.error) { in s5p_mfc_dec_ctrls_setup()
1155 return ctx->ctrl_handler.error; in s5p_mfc_dec_ctrls_setup()
1157 if (controls[i].is_volatile && ctx->ctrls[i]) in s5p_mfc_dec_ctrls_setup()
1158 ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE; in s5p_mfc_dec_ctrls_setup()
1163 void s5p_mfc_dec_ctrls_delete(struct s5p_mfc_ctx *ctx) in s5p_mfc_dec_ctrls_delete() argument
1167 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in s5p_mfc_dec_ctrls_delete()
1169 ctx->ctrls[i] = NULL; in s5p_mfc_dec_ctrls_delete()
1172 void s5p_mfc_dec_init(struct s5p_mfc_ctx *ctx) in s5p_mfc_dec_init() argument
1176 ctx->src_fmt = find_format(&f, MFC_FMT_DEC); in s5p_mfc_dec_init()
1177 if (IS_MFCV8(ctx->dev)) in s5p_mfc_dec_init()
1179 else if (IS_MFCV6_PLUS(ctx->dev)) in s5p_mfc_dec_init()
1183 ctx->dst_fmt = find_format(&f, MFC_FMT_RAW); in s5p_mfc_dec_init()
1185 ctx->src_fmt, ctx->dst_fmt); in s5p_mfc_dec_init()