Lines Matching refs:ctx

47 void clear_work_bit(struct s5p_mfc_ctx *ctx)  in clear_work_bit()  argument
49 struct s5p_mfc_dev *dev = ctx->dev; in clear_work_bit()
52 __clear_bit(ctx->num, &dev->ctx_work_bits); in clear_work_bit()
57 void set_work_bit(struct s5p_mfc_ctx *ctx) in set_work_bit() argument
59 struct s5p_mfc_dev *dev = ctx->dev; in set_work_bit()
62 __set_bit(ctx->num, &dev->ctx_work_bits); in set_work_bit()
67 void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx) in clear_work_bit_irqsave() argument
69 struct s5p_mfc_dev *dev = ctx->dev; in clear_work_bit_irqsave()
73 __clear_bit(ctx->num, &dev->ctx_work_bits); in clear_work_bit_irqsave()
78 void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx) in set_work_bit_irqsave() argument
80 struct s5p_mfc_dev *dev = ctx->dev; in set_work_bit_irqsave()
84 __set_bit(ctx->num, &dev->ctx_work_bits); in set_work_bit_irqsave()
89 static void wake_up_ctx(struct s5p_mfc_ctx *ctx, unsigned int reason, in wake_up_ctx() argument
92 ctx->int_cond = 1; in wake_up_ctx()
93 ctx->int_type = reason; in wake_up_ctx()
94 ctx->int_err = err; in wake_up_ctx()
95 wake_up(&ctx->queue); in wake_up_ctx()
131 struct s5p_mfc_ctx *ctx; in s5p_mfc_watchdog_worker() local
149 ctx = dev->ctx[i]; in s5p_mfc_watchdog_worker()
150 if (!ctx) in s5p_mfc_watchdog_worker()
152 ctx->state = MFCINST_ERROR; in s5p_mfc_watchdog_worker()
154 &ctx->dst_queue, &ctx->vq_dst); in s5p_mfc_watchdog_worker()
156 &ctx->src_queue, &ctx->vq_src); in s5p_mfc_watchdog_worker()
157 clear_work_bit(ctx); in s5p_mfc_watchdog_worker()
158 wake_up_ctx(ctx, S5P_MFC_R2H_CMD_ERR_RET, 0); in s5p_mfc_watchdog_worker()
184 static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx) in s5p_mfc_handle_frame_all_extracted() argument
187 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame_all_extracted()
189 ctx->state = MFCINST_FINISHED; in s5p_mfc_handle_frame_all_extracted()
190 ctx->sequence++; in s5p_mfc_handle_frame_all_extracted()
191 while (!list_empty(&ctx->dst_queue)) { in s5p_mfc_handle_frame_all_extracted()
192 dst_buf = list_entry(ctx->dst_queue.next, in s5p_mfc_handle_frame_all_extracted()
200 ctx->dst_queue_cnt--; in s5p_mfc_handle_frame_all_extracted()
201 dst_buf->b->sequence = (ctx->sequence++); in s5p_mfc_handle_frame_all_extracted()
203 if (s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_top, ctx) == in s5p_mfc_handle_frame_all_extracted()
204 s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_bot, ctx)) in s5p_mfc_handle_frame_all_extracted()
210 ctx->dec_dst_flag &= ~(1 << dst_buf->b->vb2_buf.index); in s5p_mfc_handle_frame_all_extracted()
215 static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx) in s5p_mfc_handle_frame_copy_time() argument
217 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame_copy_time()
230 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list); in s5p_mfc_handle_frame_copy_time()
231 list_for_each_entry(dst_buf, &ctx->dst_queue, list) { in s5p_mfc_handle_frame_copy_time()
267 static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err) in s5p_mfc_handle_frame_new() argument
269 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame_new()
277 get_disp_frame_type, ctx); in s5p_mfc_handle_frame_new()
284 if (!ctx->after_packed_pb) in s5p_mfc_handle_frame_new()
285 ctx->sequence++; in s5p_mfc_handle_frame_new()
286 ctx->after_packed_pb = 0; in s5p_mfc_handle_frame_new()
289 ctx->sequence++; in s5p_mfc_handle_frame_new()
292 list_for_each_entry(dst_buf, &ctx->dst_queue, list) { in s5p_mfc_handle_frame_new()
297 ctx->dst_queue_cnt--; in s5p_mfc_handle_frame_new()
298 dst_buf->b->sequence = ctx->sequence; in s5p_mfc_handle_frame_new()
300 get_pic_type_top, ctx) == in s5p_mfc_handle_frame_new()
302 get_pic_type_bot, ctx)) in s5p_mfc_handle_frame_new()
308 ctx->luma_size); in s5p_mfc_handle_frame_new()
310 ctx->chroma_size); in s5p_mfc_handle_frame_new()
312 &ctx->dec_dst_flag); in s5p_mfc_handle_frame_new()
323 static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx, in s5p_mfc_handle_frame() argument
326 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame()
341 if (ctx->state == MFCINST_RES_CHANGE_INIT) in s5p_mfc_handle_frame()
342 ctx->state = MFCINST_RES_CHANGE_FLUSH; in s5p_mfc_handle_frame()
345 ctx->state = MFCINST_RES_CHANGE_INIT; in s5p_mfc_handle_frame()
347 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_frame()
353 if (ctx->dpb_flush_flag) in s5p_mfc_handle_frame()
354 ctx->dpb_flush_flag = 0; in s5p_mfc_handle_frame()
359 if (ctx->state == MFCINST_RES_CHANGE_FLUSH) { in s5p_mfc_handle_frame()
366 s5p_mfc_handle_frame_all_extracted(ctx); in s5p_mfc_handle_frame()
367 ctx->state = MFCINST_RES_CHANGE_END; in s5p_mfc_handle_frame()
368 v4l2_event_queue_fh(&ctx->fh, &ev_src_ch); in s5p_mfc_handle_frame()
372 s5p_mfc_handle_frame_all_extracted(ctx); in s5p_mfc_handle_frame()
377 s5p_mfc_handle_frame_copy_time(ctx); in s5p_mfc_handle_frame()
382 s5p_mfc_handle_frame_new(ctx, err); in s5p_mfc_handle_frame()
388 && !list_empty(&ctx->src_queue)) { in s5p_mfc_handle_frame()
389 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, in s5p_mfc_handle_frame()
391 ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops, in s5p_mfc_handle_frame()
393 if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC && in s5p_mfc_handle_frame()
394 ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC && in s5p_mfc_handle_frame()
395 ctx->consumed_stream + STUFF_BYTE < in s5p_mfc_handle_frame()
399 ctx->after_packed_pb = 1; in s5p_mfc_handle_frame()
402 ctx->consumed_stream = 0; in s5p_mfc_handle_frame()
404 ctx->state = MFCINST_FINISHING; in s5p_mfc_handle_frame()
406 ctx->src_queue_cnt--; in s5p_mfc_handle_frame()
417 if ((ctx->src_queue_cnt == 0 && ctx->state != MFCINST_FINISHING) in s5p_mfc_handle_frame()
418 || ctx->dst_queue_cnt < ctx->pb_count) in s5p_mfc_handle_frame()
419 clear_work_bit(ctx); in s5p_mfc_handle_frame()
421 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_frame()
433 struct s5p_mfc_ctx *ctx, unsigned int reason, unsigned int err) in s5p_mfc_handle_error() argument
439 if (ctx != NULL) { in s5p_mfc_handle_error()
441 switch (ctx->state) { in s5p_mfc_handle_error()
450 clear_work_bit(ctx); in s5p_mfc_handle_error()
451 ctx->state = MFCINST_ERROR; in s5p_mfc_handle_error()
455 &ctx->dst_queue, &ctx->vq_dst); in s5p_mfc_handle_error()
458 &ctx->src_queue, &ctx->vq_src); in s5p_mfc_handle_error()
460 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_error()
463 clear_work_bit(ctx); in s5p_mfc_handle_error()
464 ctx->state = MFCINST_ERROR; in s5p_mfc_handle_error()
465 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_error()
477 static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx, in s5p_mfc_handle_seq_done() argument
482 if (ctx == NULL) in s5p_mfc_handle_seq_done()
484 dev = ctx->dev; in s5p_mfc_handle_seq_done()
485 if (ctx->c_ops->post_seq_start) { in s5p_mfc_handle_seq_done()
486 if (ctx->c_ops->post_seq_start(ctx)) in s5p_mfc_handle_seq_done()
489 ctx->img_width = s5p_mfc_hw_call(dev->mfc_ops, get_img_width, in s5p_mfc_handle_seq_done()
491 ctx->img_height = s5p_mfc_hw_call(dev->mfc_ops, get_img_height, in s5p_mfc_handle_seq_done()
494 s5p_mfc_hw_call_void(dev->mfc_ops, dec_calc_dpb_size, ctx); in s5p_mfc_handle_seq_done()
496 ctx->pb_count = s5p_mfc_hw_call(dev->mfc_ops, get_dpb_count, in s5p_mfc_handle_seq_done()
498 ctx->mv_count = s5p_mfc_hw_call(dev->mfc_ops, get_mv_count, in s5p_mfc_handle_seq_done()
500 if (ctx->img_width == 0 || ctx->img_height == 0) in s5p_mfc_handle_seq_done()
501 ctx->state = MFCINST_ERROR; in s5p_mfc_handle_seq_done()
503 ctx->state = MFCINST_HEAD_PARSED; in s5p_mfc_handle_seq_done()
505 if ((ctx->codec_mode == S5P_MFC_CODEC_H264_DEC || in s5p_mfc_handle_seq_done()
506 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) && in s5p_mfc_handle_seq_done()
507 !list_empty(&ctx->src_queue)) { in s5p_mfc_handle_seq_done()
509 src_buf = list_entry(ctx->src_queue.next, in s5p_mfc_handle_seq_done()
514 ctx->head_processed = 0; in s5p_mfc_handle_seq_done()
516 ctx->head_processed = 1; in s5p_mfc_handle_seq_done()
518 ctx->head_processed = 1; in s5p_mfc_handle_seq_done()
522 clear_work_bit(ctx); in s5p_mfc_handle_seq_done()
526 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_seq_done()
530 static void s5p_mfc_handle_init_buffers(struct s5p_mfc_ctx *ctx, in s5p_mfc_handle_init_buffers() argument
537 if (ctx == NULL) in s5p_mfc_handle_init_buffers()
539 dev = ctx->dev; in s5p_mfc_handle_init_buffers()
541 ctx->int_type = reason; in s5p_mfc_handle_init_buffers()
542 ctx->int_err = err; in s5p_mfc_handle_init_buffers()
543 ctx->int_cond = 1; in s5p_mfc_handle_init_buffers()
544 clear_work_bit(ctx); in s5p_mfc_handle_init_buffers()
546 ctx->state = MFCINST_RUNNING; in s5p_mfc_handle_init_buffers()
547 if (!ctx->dpb_flush_flag && ctx->head_processed) { in s5p_mfc_handle_init_buffers()
549 if (!list_empty(&ctx->src_queue)) { in s5p_mfc_handle_init_buffers()
550 src_buf = list_entry(ctx->src_queue.next, in s5p_mfc_handle_init_buffers()
553 ctx->src_queue_cnt--; in s5p_mfc_handle_init_buffers()
559 ctx->dpb_flush_flag = 0; in s5p_mfc_handle_init_buffers()
565 wake_up(&ctx->queue); in s5p_mfc_handle_init_buffers()
572 wake_up(&ctx->queue); in s5p_mfc_handle_init_buffers()
576 static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx) in s5p_mfc_handle_stream_complete() argument
578 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_stream_complete()
583 ctx->state = MFCINST_FINISHED; in s5p_mfc_handle_stream_complete()
586 if (!list_empty(&ctx->dst_queue)) { in s5p_mfc_handle_stream_complete()
587 mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, in s5p_mfc_handle_stream_complete()
590 ctx->dst_queue_cnt--; in s5p_mfc_handle_stream_complete()
596 clear_work_bit(ctx); in s5p_mfc_handle_stream_complete()
601 wake_up(&ctx->queue); in s5p_mfc_handle_stream_complete()
609 struct s5p_mfc_ctx *ctx; in s5p_mfc_irq() local
616 ctx = dev->ctx[dev->curr_ctx]; in s5p_mfc_irq()
624 if (ctx->state == MFCINST_RUNNING && in s5p_mfc_irq()
627 s5p_mfc_handle_frame(ctx, reason, err); in s5p_mfc_irq()
629 s5p_mfc_handle_error(dev, ctx, reason, err); in s5p_mfc_irq()
636 if (ctx->c_ops->post_frame_start) { in s5p_mfc_irq()
637 if (ctx->c_ops->post_frame_start(ctx)) in s5p_mfc_irq()
640 if (ctx->state == MFCINST_FINISHING && in s5p_mfc_irq()
641 list_empty(&ctx->ref_queue)) { in s5p_mfc_irq()
643 s5p_mfc_handle_stream_complete(ctx); in s5p_mfc_irq()
647 wake_up_ctx(ctx, reason, err); in s5p_mfc_irq()
652 s5p_mfc_handle_frame(ctx, reason, err); in s5p_mfc_irq()
657 s5p_mfc_handle_seq_done(ctx, reason, err); in s5p_mfc_irq()
661 ctx->inst_no = s5p_mfc_hw_call(dev->mfc_ops, get_inst_no, dev); in s5p_mfc_irq()
662 ctx->state = MFCINST_GOT_INST; in s5p_mfc_irq()
663 clear_work_bit(ctx); in s5p_mfc_irq()
664 wake_up(&ctx->queue); in s5p_mfc_irq()
668 clear_work_bit(ctx); in s5p_mfc_irq()
669 ctx->inst_no = MFC_NO_INSTANCE_SET; in s5p_mfc_irq()
670 ctx->state = MFCINST_FREE; in s5p_mfc_irq()
671 wake_up(&ctx->queue); in s5p_mfc_irq()
678 if (ctx) in s5p_mfc_irq()
679 clear_work_bit(ctx); in s5p_mfc_irq()
687 s5p_mfc_handle_init_buffers(ctx, reason, err); in s5p_mfc_irq()
692 ctx->int_type = reason; in s5p_mfc_irq()
693 ctx->int_err = err; in s5p_mfc_irq()
694 s5p_mfc_handle_stream_complete(ctx); in s5p_mfc_irq()
698 clear_work_bit(ctx); in s5p_mfc_irq()
699 ctx->state = MFCINST_RUNNING; in s5p_mfc_irq()
700 wake_up(&ctx->queue); in s5p_mfc_irq()
711 ctx->int_type = reason; in s5p_mfc_irq()
712 ctx->int_err = err; in s5p_mfc_irq()
713 ctx->int_cond = 1; in s5p_mfc_irq()
729 struct s5p_mfc_ctx *ctx = NULL; in s5p_mfc_open() local
738 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in s5p_mfc_open()
739 if (!ctx) { in s5p_mfc_open()
744 v4l2_fh_init(&ctx->fh, vdev); in s5p_mfc_open()
745 file->private_data = &ctx->fh; in s5p_mfc_open()
746 v4l2_fh_add(&ctx->fh); in s5p_mfc_open()
747 ctx->dev = dev; in s5p_mfc_open()
748 INIT_LIST_HEAD(&ctx->src_queue); in s5p_mfc_open()
749 INIT_LIST_HEAD(&ctx->dst_queue); in s5p_mfc_open()
750 ctx->src_queue_cnt = 0; in s5p_mfc_open()
751 ctx->dst_queue_cnt = 0; in s5p_mfc_open()
753 ctx->num = 0; in s5p_mfc_open()
754 while (dev->ctx[ctx->num]) { in s5p_mfc_open()
755 ctx->num++; in s5p_mfc_open()
756 if (ctx->num >= MFC_NUM_CONTEXTS) { in s5p_mfc_open()
763 clear_work_bit_irqsave(ctx); in s5p_mfc_open()
764 dev->ctx[ctx->num] = ctx; in s5p_mfc_open()
766 ctx->type = MFCINST_DECODER; in s5p_mfc_open()
767 ctx->c_ops = get_dec_codec_ops(); in s5p_mfc_open()
768 s5p_mfc_dec_init(ctx); in s5p_mfc_open()
770 ret = s5p_mfc_dec_ctrls_setup(ctx); in s5p_mfc_open()
776 ctx->type = MFCINST_ENCODER; in s5p_mfc_open()
777 ctx->c_ops = get_enc_codec_ops(); in s5p_mfc_open()
779 INIT_LIST_HEAD(&ctx->ref_queue); in s5p_mfc_open()
780 ctx->ref_queue_cnt = 0; in s5p_mfc_open()
781 s5p_mfc_enc_init(ctx); in s5p_mfc_open()
783 ret = s5p_mfc_enc_ctrls_setup(ctx); in s5p_mfc_open()
792 ctx->fh.ctrl_handler = &ctx->ctrl_handler; in s5p_mfc_open()
793 ctx->inst_no = MFC_NO_INSTANCE_SET; in s5p_mfc_open()
817 q = &ctx->vq_dst; in s5p_mfc_open()
819 q->drv_priv = &ctx->fh; in s5p_mfc_open()
839 q = &ctx->vq_src; in s5p_mfc_open()
842 q->drv_priv = &ctx->fh; in s5p_mfc_open()
868 init_waitqueue_head(&ctx->queue); in s5p_mfc_open()
885 s5p_mfc_dec_ctrls_delete(ctx); in s5p_mfc_open()
887 dev->ctx[ctx->num] = NULL; in s5p_mfc_open()
889 v4l2_fh_del(&ctx->fh); in s5p_mfc_open()
890 v4l2_fh_exit(&ctx->fh); in s5p_mfc_open()
891 kfree(ctx); in s5p_mfc_open()
902 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); in s5p_mfc_release() local
903 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_release()
908 vb2_queue_release(&ctx->vq_src); in s5p_mfc_release()
909 vb2_queue_release(&ctx->vq_dst); in s5p_mfc_release()
911 clear_work_bit_irqsave(ctx); in s5p_mfc_release()
914 if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) { in s5p_mfc_release()
916 s5p_mfc_close_mfc_inst(dev, ctx); in s5p_mfc_release()
919 if (dev->curr_ctx == ctx->num) in s5p_mfc_release()
931 dev->ctx[ctx->num] = NULL; in s5p_mfc_release()
932 s5p_mfc_dec_ctrls_delete(ctx); in s5p_mfc_release()
933 v4l2_fh_del(&ctx->fh); in s5p_mfc_release()
934 v4l2_fh_exit(&ctx->fh); in s5p_mfc_release()
935 kfree(ctx); in s5p_mfc_release()
945 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); in s5p_mfc_poll() local
946 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_poll()
953 src_q = &ctx->vq_src; in s5p_mfc_poll()
954 dst_q = &ctx->vq_dst; in s5p_mfc_poll()
966 poll_wait(file, &ctx->fh.wait, wait); in s5p_mfc_poll()
970 if (v4l2_event_pending(&ctx->fh)) in s5p_mfc_poll()
996 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); in s5p_mfc_mmap() local
997 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_mmap()
1005 ret = vb2_mmap(&ctx->vq_src, vma); in s5p_mfc_mmap()
1009 ret = vb2_mmap(&ctx->vq_dst, vma); in s5p_mfc_mmap()