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()
191 static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx) in s5p_mfc_handle_frame_all_extracted() argument
194 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame_all_extracted()
196 ctx->state = MFCINST_FINISHED; in s5p_mfc_handle_frame_all_extracted()
197 ctx->sequence++; in s5p_mfc_handle_frame_all_extracted()
198 while (!list_empty(&ctx->dst_queue)) { in s5p_mfc_handle_frame_all_extracted()
199 dst_buf = list_entry(ctx->dst_queue.next, in s5p_mfc_handle_frame_all_extracted()
206 ctx->dst_queue_cnt--; in s5p_mfc_handle_frame_all_extracted()
207 dst_buf->b->v4l2_buf.sequence = (ctx->sequence++); in s5p_mfc_handle_frame_all_extracted()
209 if (s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_top, ctx) == in s5p_mfc_handle_frame_all_extracted()
210 s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_bot, ctx)) in s5p_mfc_handle_frame_all_extracted()
215 ctx->dec_dst_flag &= ~(1 << dst_buf->b->v4l2_buf.index); in s5p_mfc_handle_frame_all_extracted()
220 static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx) in s5p_mfc_handle_frame_copy_time() argument
222 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame_copy_time()
235 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list); in s5p_mfc_handle_frame_copy_time()
236 list_for_each_entry(dst_buf, &ctx->dst_queue, list) { in s5p_mfc_handle_frame_copy_time()
271 static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err) in s5p_mfc_handle_frame_new() argument
273 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame_new()
281 get_disp_frame_type, ctx); in s5p_mfc_handle_frame_new()
288 if (!ctx->after_packed_pb) in s5p_mfc_handle_frame_new()
289 ctx->sequence++; in s5p_mfc_handle_frame_new()
290 ctx->after_packed_pb = 0; in s5p_mfc_handle_frame_new()
293 ctx->sequence++; in s5p_mfc_handle_frame_new()
296 list_for_each_entry(dst_buf, &ctx->dst_queue, list) { in s5p_mfc_handle_frame_new()
300 ctx->dst_queue_cnt--; in s5p_mfc_handle_frame_new()
301 dst_buf->b->v4l2_buf.sequence = ctx->sequence; in s5p_mfc_handle_frame_new()
303 get_pic_type_top, ctx) == in s5p_mfc_handle_frame_new()
305 get_pic_type_bot, ctx)) in s5p_mfc_handle_frame_new()
310 vb2_set_plane_payload(dst_buf->b, 0, ctx->luma_size); in s5p_mfc_handle_frame_new()
311 vb2_set_plane_payload(dst_buf->b, 1, ctx->chroma_size); in s5p_mfc_handle_frame_new()
313 &ctx->dec_dst_flag); in s5p_mfc_handle_frame_new()
324 static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx, in s5p_mfc_handle_frame() argument
327 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_handle_frame()
342 if (ctx->state == MFCINST_RES_CHANGE_INIT) in s5p_mfc_handle_frame()
343 ctx->state = MFCINST_RES_CHANGE_FLUSH; in s5p_mfc_handle_frame()
346 ctx->state = MFCINST_RES_CHANGE_INIT; in s5p_mfc_handle_frame()
348 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_frame()
354 if (ctx->dpb_flush_flag) in s5p_mfc_handle_frame()
355 ctx->dpb_flush_flag = 0; in s5p_mfc_handle_frame()
360 if (ctx->state == MFCINST_RES_CHANGE_FLUSH) { in s5p_mfc_handle_frame()
367 s5p_mfc_handle_frame_all_extracted(ctx); in s5p_mfc_handle_frame()
368 ctx->state = MFCINST_RES_CHANGE_END; in s5p_mfc_handle_frame()
369 v4l2_event_queue_fh(&ctx->fh, &ev_src_ch); in s5p_mfc_handle_frame()
373 s5p_mfc_handle_frame_all_extracted(ctx); in s5p_mfc_handle_frame()
378 s5p_mfc_handle_frame_copy_time(ctx); in s5p_mfc_handle_frame()
383 s5p_mfc_handle_frame_new(ctx, err); in s5p_mfc_handle_frame()
389 && !list_empty(&ctx->src_queue)) { in s5p_mfc_handle_frame()
390 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, in s5p_mfc_handle_frame()
392 ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops, in s5p_mfc_handle_frame()
394 if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC && in s5p_mfc_handle_frame()
395 ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC && in s5p_mfc_handle_frame()
396 ctx->consumed_stream + STUFF_BYTE < in s5p_mfc_handle_frame()
400 ctx->after_packed_pb = 1; in s5p_mfc_handle_frame()
403 ctx->consumed_stream = 0; in s5p_mfc_handle_frame()
405 ctx->state = MFCINST_FINISHING; in s5p_mfc_handle_frame()
407 ctx->src_queue_cnt--; in s5p_mfc_handle_frame()
416 if ((ctx->src_queue_cnt == 0 && ctx->state != MFCINST_FINISHING) in s5p_mfc_handle_frame()
417 || ctx->dst_queue_cnt < ctx->pb_count) in s5p_mfc_handle_frame()
418 clear_work_bit(ctx); in s5p_mfc_handle_frame()
420 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_frame()
432 struct s5p_mfc_ctx *ctx, unsigned int reason, unsigned int err) in s5p_mfc_handle_error() argument
438 if (ctx != NULL) { in s5p_mfc_handle_error()
440 switch (ctx->state) { in s5p_mfc_handle_error()
449 clear_work_bit(ctx); in s5p_mfc_handle_error()
450 ctx->state = MFCINST_ERROR; in s5p_mfc_handle_error()
454 &ctx->dst_queue, &ctx->vq_dst); in s5p_mfc_handle_error()
457 &ctx->src_queue, &ctx->vq_src); in s5p_mfc_handle_error()
459 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_error()
462 clear_work_bit(ctx); in s5p_mfc_handle_error()
463 ctx->state = MFCINST_ERROR; in s5p_mfc_handle_error()
464 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_error()
476 static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx, in s5p_mfc_handle_seq_done() argument
481 if (ctx == NULL) in s5p_mfc_handle_seq_done()
483 dev = ctx->dev; in s5p_mfc_handle_seq_done()
484 if (ctx->c_ops->post_seq_start) { in s5p_mfc_handle_seq_done()
485 if (ctx->c_ops->post_seq_start(ctx)) in s5p_mfc_handle_seq_done()
488 ctx->img_width = s5p_mfc_hw_call(dev->mfc_ops, get_img_width, in s5p_mfc_handle_seq_done()
490 ctx->img_height = s5p_mfc_hw_call(dev->mfc_ops, get_img_height, in s5p_mfc_handle_seq_done()
493 s5p_mfc_hw_call_void(dev->mfc_ops, dec_calc_dpb_size, ctx); in s5p_mfc_handle_seq_done()
495 ctx->pb_count = s5p_mfc_hw_call(dev->mfc_ops, get_dpb_count, in s5p_mfc_handle_seq_done()
497 ctx->mv_count = s5p_mfc_hw_call(dev->mfc_ops, get_mv_count, in s5p_mfc_handle_seq_done()
499 if (ctx->img_width == 0 || ctx->img_height == 0) in s5p_mfc_handle_seq_done()
500 ctx->state = MFCINST_ERROR; in s5p_mfc_handle_seq_done()
502 ctx->state = MFCINST_HEAD_PARSED; in s5p_mfc_handle_seq_done()
504 if ((ctx->codec_mode == S5P_MFC_CODEC_H264_DEC || in s5p_mfc_handle_seq_done()
505 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) && in s5p_mfc_handle_seq_done()
506 !list_empty(&ctx->src_queue)) { in s5p_mfc_handle_seq_done()
508 src_buf = list_entry(ctx->src_queue.next, in s5p_mfc_handle_seq_done()
513 ctx->head_processed = 0; in s5p_mfc_handle_seq_done()
515 ctx->head_processed = 1; in s5p_mfc_handle_seq_done()
517 ctx->head_processed = 1; in s5p_mfc_handle_seq_done()
521 clear_work_bit(ctx); in s5p_mfc_handle_seq_done()
525 wake_up_ctx(ctx, reason, err); in s5p_mfc_handle_seq_done()
529 static void s5p_mfc_handle_init_buffers(struct s5p_mfc_ctx *ctx, in s5p_mfc_handle_init_buffers() argument
536 if (ctx == NULL) in s5p_mfc_handle_init_buffers()
538 dev = ctx->dev; in s5p_mfc_handle_init_buffers()
540 ctx->int_type = reason; in s5p_mfc_handle_init_buffers()
541 ctx->int_err = err; in s5p_mfc_handle_init_buffers()
542 ctx->int_cond = 1; in s5p_mfc_handle_init_buffers()
543 clear_work_bit(ctx); in s5p_mfc_handle_init_buffers()
545 ctx->state = MFCINST_RUNNING; in s5p_mfc_handle_init_buffers()
546 if (!ctx->dpb_flush_flag && ctx->head_processed) { in s5p_mfc_handle_init_buffers()
548 if (!list_empty(&ctx->src_queue)) { in s5p_mfc_handle_init_buffers()
549 src_buf = list_entry(ctx->src_queue.next, in s5p_mfc_handle_init_buffers()
552 ctx->src_queue_cnt--; in s5p_mfc_handle_init_buffers()
558 ctx->dpb_flush_flag = 0; in s5p_mfc_handle_init_buffers()
564 wake_up(&ctx->queue); in s5p_mfc_handle_init_buffers()
571 wake_up(&ctx->queue); in s5p_mfc_handle_init_buffers()
575 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()
584 ctx->int_type = reason; in s5p_mfc_handle_stream_complete()
585 ctx->int_err = err; in s5p_mfc_handle_stream_complete()
586 ctx->state = MFCINST_FINISHED; in s5p_mfc_handle_stream_complete()
589 if (!list_empty(&ctx->dst_queue)) { in s5p_mfc_handle_stream_complete()
590 mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, in s5p_mfc_handle_stream_complete()
593 ctx->dst_queue_cnt--; in s5p_mfc_handle_stream_complete()
599 clear_work_bit(ctx); in s5p_mfc_handle_stream_complete()
604 wake_up(&ctx->queue); in s5p_mfc_handle_stream_complete()
612 struct s5p_mfc_ctx *ctx; in s5p_mfc_irq() local
619 ctx = dev->ctx[dev->curr_ctx]; in s5p_mfc_irq()
627 if (ctx->state == MFCINST_RUNNING && in s5p_mfc_irq()
630 s5p_mfc_handle_frame(ctx, reason, err); in s5p_mfc_irq()
632 s5p_mfc_handle_error(dev, ctx, reason, err); in s5p_mfc_irq()
639 if (ctx->c_ops->post_frame_start) { in s5p_mfc_irq()
640 if (ctx->c_ops->post_frame_start(ctx)) in s5p_mfc_irq()
643 wake_up_ctx(ctx, reason, err); in s5p_mfc_irq()
648 s5p_mfc_handle_frame(ctx, reason, err); in s5p_mfc_irq()
653 s5p_mfc_handle_seq_done(ctx, reason, err); in s5p_mfc_irq()
657 ctx->inst_no = s5p_mfc_hw_call(dev->mfc_ops, get_inst_no, dev); in s5p_mfc_irq()
658 ctx->state = MFCINST_GOT_INST; in s5p_mfc_irq()
659 clear_work_bit(ctx); in s5p_mfc_irq()
660 wake_up(&ctx->queue); in s5p_mfc_irq()
664 clear_work_bit(ctx); in s5p_mfc_irq()
665 ctx->inst_no = MFC_NO_INSTANCE_SET; in s5p_mfc_irq()
666 ctx->state = MFCINST_FREE; in s5p_mfc_irq()
667 wake_up(&ctx->queue); in s5p_mfc_irq()
674 if (ctx) in s5p_mfc_irq()
675 clear_work_bit(ctx); in s5p_mfc_irq()
683 s5p_mfc_handle_init_buffers(ctx, reason, err); in s5p_mfc_irq()
687 s5p_mfc_handle_stream_complete(ctx, reason, err); in s5p_mfc_irq()
691 clear_work_bit(ctx); in s5p_mfc_irq()
692 ctx->state = MFCINST_RUNNING; in s5p_mfc_irq()
693 wake_up(&ctx->queue); in s5p_mfc_irq()
704 ctx->int_type = reason; in s5p_mfc_irq()
705 ctx->int_err = err; in s5p_mfc_irq()
706 ctx->int_cond = 1; in s5p_mfc_irq()
722 struct s5p_mfc_ctx *ctx = NULL; in s5p_mfc_open() local
731 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in s5p_mfc_open()
732 if (!ctx) { in s5p_mfc_open()
737 v4l2_fh_init(&ctx->fh, vdev); in s5p_mfc_open()
738 file->private_data = &ctx->fh; in s5p_mfc_open()
739 v4l2_fh_add(&ctx->fh); in s5p_mfc_open()
740 ctx->dev = dev; in s5p_mfc_open()
741 INIT_LIST_HEAD(&ctx->src_queue); in s5p_mfc_open()
742 INIT_LIST_HEAD(&ctx->dst_queue); in s5p_mfc_open()
743 ctx->src_queue_cnt = 0; in s5p_mfc_open()
744 ctx->dst_queue_cnt = 0; in s5p_mfc_open()
746 ctx->num = 0; in s5p_mfc_open()
747 while (dev->ctx[ctx->num]) { in s5p_mfc_open()
748 ctx->num++; in s5p_mfc_open()
749 if (ctx->num >= MFC_NUM_CONTEXTS) { in s5p_mfc_open()
756 clear_work_bit_irqsave(ctx); in s5p_mfc_open()
757 dev->ctx[ctx->num] = ctx; in s5p_mfc_open()
759 ctx->type = MFCINST_DECODER; in s5p_mfc_open()
760 ctx->c_ops = get_dec_codec_ops(); in s5p_mfc_open()
761 s5p_mfc_dec_init(ctx); in s5p_mfc_open()
763 ret = s5p_mfc_dec_ctrls_setup(ctx); in s5p_mfc_open()
769 ctx->type = MFCINST_ENCODER; in s5p_mfc_open()
770 ctx->c_ops = get_enc_codec_ops(); in s5p_mfc_open()
772 INIT_LIST_HEAD(&ctx->ref_queue); in s5p_mfc_open()
773 ctx->ref_queue_cnt = 0; in s5p_mfc_open()
774 s5p_mfc_enc_init(ctx); in s5p_mfc_open()
776 ret = s5p_mfc_enc_ctrls_setup(ctx); in s5p_mfc_open()
785 ctx->fh.ctrl_handler = &ctx->ctrl_handler; in s5p_mfc_open()
786 ctx->inst_no = MFC_NO_INSTANCE_SET; in s5p_mfc_open()
810 q = &ctx->vq_dst; in s5p_mfc_open()
812 q->drv_priv = &ctx->fh; in s5p_mfc_open()
832 q = &ctx->vq_src; in s5p_mfc_open()
835 q->drv_priv = &ctx->fh; in s5p_mfc_open()
861 init_waitqueue_head(&ctx->queue); in s5p_mfc_open()
878 s5p_mfc_dec_ctrls_delete(ctx); in s5p_mfc_open()
880 dev->ctx[ctx->num] = NULL; in s5p_mfc_open()
882 v4l2_fh_del(&ctx->fh); in s5p_mfc_open()
883 v4l2_fh_exit(&ctx->fh); in s5p_mfc_open()
884 kfree(ctx); in s5p_mfc_open()
895 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); in s5p_mfc_release() local
896 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_release()
901 vb2_queue_release(&ctx->vq_src); in s5p_mfc_release()
902 vb2_queue_release(&ctx->vq_dst); in s5p_mfc_release()
904 clear_work_bit_irqsave(ctx); in s5p_mfc_release()
907 if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) { in s5p_mfc_release()
909 s5p_mfc_close_mfc_inst(dev, ctx); in s5p_mfc_release()
912 if (dev->curr_ctx == ctx->num) in s5p_mfc_release()
924 dev->ctx[ctx->num] = NULL; in s5p_mfc_release()
925 s5p_mfc_dec_ctrls_delete(ctx); in s5p_mfc_release()
926 v4l2_fh_del(&ctx->fh); in s5p_mfc_release()
927 v4l2_fh_exit(&ctx->fh); in s5p_mfc_release()
928 kfree(ctx); in s5p_mfc_release()
938 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); in s5p_mfc_poll() local
939 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_poll()
946 src_q = &ctx->vq_src; in s5p_mfc_poll()
947 dst_q = &ctx->vq_dst; in s5p_mfc_poll()
959 poll_wait(file, &ctx->fh.wait, wait); in s5p_mfc_poll()
963 if (v4l2_event_pending(&ctx->fh)) in s5p_mfc_poll()
989 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); in s5p_mfc_mmap() local
990 struct s5p_mfc_dev *dev = ctx->dev; in s5p_mfc_mmap()
998 ret = vb2_mmap(&ctx->vq_src, vma); in s5p_mfc_mmap()
1002 ret = vb2_mmap(&ctx->vq_dst, vma); in s5p_mfc_mmap()