Lines Matching refs:inst

27 void vpu_inst_lock(struct vpu_inst *inst)  in vpu_inst_lock()  argument
29 mutex_lock(&inst->lock); in vpu_inst_lock()
32 void vpu_inst_unlock(struct vpu_inst *inst) in vpu_inst_unlock() argument
34 mutex_unlock(&inst->lock); in vpu_inst_unlock()
66 void vpu_v4l2_set_error(struct vpu_inst *inst) in vpu_v4l2_set_error() argument
68 vpu_inst_lock(inst); in vpu_v4l2_set_error()
69 dev_err(inst->dev, "some error occurs in codec\n"); in vpu_v4l2_set_error()
70 if (inst->fh.m2m_ctx) { in vpu_v4l2_set_error()
71 vb2_queue_error(v4l2_m2m_get_src_vq(inst->fh.m2m_ctx)); in vpu_v4l2_set_error()
72 vb2_queue_error(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx)); in vpu_v4l2_set_error()
74 vpu_inst_unlock(inst); in vpu_v4l2_set_error()
77 int vpu_notify_eos(struct vpu_inst *inst) in vpu_notify_eos() argument
84 vpu_trace(inst->dev, "[%d]\n", inst->id); in vpu_notify_eos()
85 v4l2_event_queue_fh(&inst->fh, &ev); in vpu_notify_eos()
90 int vpu_notify_source_change(struct vpu_inst *inst) in vpu_notify_source_change() argument
98 vpu_trace(inst->dev, "[%d]\n", inst->id); in vpu_notify_source_change()
99 v4l2_event_queue_fh(&inst->fh, &ev); in vpu_notify_source_change()
103 int vpu_set_last_buffer_dequeued(struct vpu_inst *inst, bool eos) in vpu_set_last_buffer_dequeued() argument
107 if (!inst || !inst->fh.m2m_ctx) in vpu_set_last_buffer_dequeued()
110 q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); in vpu_set_last_buffer_dequeued()
116 vpu_trace(inst->dev, "last buffer dequeued\n"); in vpu_set_last_buffer_dequeued()
120 vpu_notify_eos(inst); in vpu_set_last_buffer_dequeued()
124 bool vpu_is_source_empty(struct vpu_inst *inst) in vpu_is_source_empty() argument
128 if (!inst->fh.m2m_ctx) in vpu_is_source_empty()
130 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_is_source_empty()
137 static int vpu_init_format(struct vpu_inst *inst, struct vpu_format *fmt) in vpu_init_format() argument
141 info = vpu_helper_find_format(inst, fmt->type, fmt->pixfmt); in vpu_init_format()
143 info = vpu_helper_enum_format(inst, fmt->type, 0); in vpu_init_format()
179 static int vpu_calc_fmt_sizeimage(struct vpu_inst *inst, struct vpu_format *fmt) in vpu_calc_fmt_sizeimage() argument
185 const struct vpu_core_resources *res = vpu_get_resource(inst); in vpu_calc_fmt_sizeimage()
229 int vpu_try_fmt_common(struct vpu_inst *inst, struct v4l2_format *f, struct vpu_format *fmt) in vpu_try_fmt_common() argument
237 ret = vpu_init_format(inst, fmt); in vpu_try_fmt_common()
244 fmt->width = vpu_helper_valid_frame_width(inst, fmt->width); in vpu_try_fmt_common()
246 fmt->height = vpu_helper_valid_frame_height(inst, fmt->height); in vpu_try_fmt_common()
249 vpu_calc_fmt_sizeimage(inst, fmt); in vpu_try_fmt_common()
269 static bool vpu_check_ready(struct vpu_inst *inst, u32 type) in vpu_check_ready() argument
271 if (!inst) in vpu_check_ready()
273 if (inst->state == VPU_CODEC_STATE_DEINIT || inst->id < 0) in vpu_check_ready()
275 if (!inst->ops->check_ready) in vpu_check_ready()
277 return call_vop(inst, check_ready, type); in vpu_check_ready()
280 int vpu_process_output_buffer(struct vpu_inst *inst) in vpu_process_output_buffer() argument
285 if (!inst || !inst->fh.m2m_ctx) in vpu_process_output_buffer()
288 if (!vpu_check_ready(inst, inst->out_format.type)) in vpu_process_output_buffer()
291 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_process_output_buffer()
301 dev_dbg(inst->dev, "[%d]frame id = %d / %d\n", in vpu_process_output_buffer()
302 inst->id, vbuf->sequence, inst->sequence); in vpu_process_output_buffer()
303 return call_vop(inst, process_output, &vbuf->vb2_buf); in vpu_process_output_buffer()
306 int vpu_process_capture_buffer(struct vpu_inst *inst) in vpu_process_capture_buffer() argument
311 if (!inst || !inst->fh.m2m_ctx) in vpu_process_capture_buffer()
314 if (!vpu_check_ready(inst, inst->cap_format.type)) in vpu_process_capture_buffer()
317 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) { in vpu_process_capture_buffer()
326 return call_vop(inst, process_capture, &vbuf->vb2_buf); in vpu_process_capture_buffer()
329 struct vb2_v4l2_buffer *vpu_next_src_buf(struct vpu_inst *inst) in vpu_next_src_buf() argument
333 if (!inst->fh.m2m_ctx) in vpu_next_src_buf()
336 src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx); in vpu_next_src_buf()
341 v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx); in vpu_next_src_buf()
345 src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx); in vpu_next_src_buf()
353 void vpu_skip_frame(struct vpu_inst *inst, int count) in vpu_skip_frame() argument
359 if (count <= 0 || !inst->fh.m2m_ctx) in vpu_skip_frame()
363 src_buf = v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx); in vpu_skip_frame()
376 struct vb2_v4l2_buffer *vpu_find_buf_by_sequence(struct vpu_inst *inst, u32 type, u32 sequence) in vpu_find_buf_by_sequence() argument
381 if (!inst || !inst->fh.m2m_ctx) in vpu_find_buf_by_sequence()
385 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_sequence()
392 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_sequence()
403 struct vb2_v4l2_buffer *vpu_find_buf_by_idx(struct vpu_inst *inst, u32 type, u32 idx) in vpu_find_buf_by_idx() argument
408 if (!inst || !inst->fh.m2m_ctx) in vpu_find_buf_by_idx()
412 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_idx()
419 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_idx()
430 int vpu_get_num_buffers(struct vpu_inst *inst, u32 type) in vpu_get_num_buffers() argument
434 if (!inst || !inst->fh.m2m_ctx) in vpu_get_num_buffers()
438 q = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); in vpu_get_num_buffers()
440 q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); in vpu_get_num_buffers()
451 struct vpu_inst *inst = priv; in vpu_m2m_job_abort() local
452 struct v4l2_m2m_ctx *m2m_ctx = inst->fh.m2m_ctx; in vpu_m2m_job_abort()
468 struct vpu_inst *inst = vb2_get_drv_priv(vq); in vpu_vb2_queue_setup() local
472 cur_fmt = vpu_get_format(inst, vq->type); in vpu_vb2_queue_setup()
485 *buf_count = max_t(unsigned int, *buf_count, inst->min_buffer_out); in vpu_vb2_queue_setup()
487 *buf_count = max_t(unsigned int, *buf_count, inst->min_buffer_cap); in vpu_vb2_queue_setup()
492 if (V4L2_TYPE_IS_OUTPUT(vq->type) && inst->state == VPU_CODEC_STATE_SEEK) { in vpu_vb2_queue_setup()
493 vpu_trace(inst->dev, "reinit when VIDIOC_REQBUFS(OUTPUT, 0)\n"); in vpu_vb2_queue_setup()
494 call_void_vop(inst, release); in vpu_vb2_queue_setup()
519 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vpu_vb2_buf_prepare() local
524 cur_fmt = vpu_get_format(inst, vb->type); in vpu_vb2_buf_prepare()
527 dev_dbg(inst->dev, "[%d] %s buf[%d] is invalid\n", in vpu_vb2_buf_prepare()
528 inst->id, vpu_type_name(vb->type), vb->index); in vpu_vb2_buf_prepare()
539 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vpu_vb2_buf_finish() local
543 vpu_notify_eos(inst); in vpu_vb2_buf_finish()
546 call_void_vop(inst, on_queue_empty, q->type); in vpu_vb2_buf_finish()
549 void vpu_vb2_buffers_return(struct vpu_inst *inst, unsigned int type, enum vb2_buffer_state state) in vpu_vb2_buffers_return() argument
554 while ((buf = v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx))) { in vpu_vb2_buffers_return()
559 while ((buf = v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx))) { in vpu_vb2_buffers_return()
568 struct vpu_inst *inst = vb2_get_drv_priv(q); in vpu_vb2_start_streaming() local
569 struct vpu_format *fmt = vpu_get_format(inst, q->type); in vpu_vb2_start_streaming()
572 vpu_inst_unlock(inst); in vpu_vb2_start_streaming()
573 ret = vpu_inst_register(inst); in vpu_vb2_start_streaming()
574 vpu_inst_lock(inst); in vpu_vb2_start_streaming()
576 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_QUEUED); in vpu_vb2_start_streaming()
580 vpu_trace(inst->dev, "[%d] %s %c%c%c%c %dx%d %u(%u) %u(%u) %u(%u) %d\n", in vpu_vb2_start_streaming()
581 inst->id, vpu_type_name(q->type), in vpu_vb2_start_streaming()
592 ret = call_vop(inst, start, q->type); in vpu_vb2_start_streaming()
594 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_QUEUED); in vpu_vb2_start_streaming()
601 struct vpu_inst *inst = vb2_get_drv_priv(q); in vpu_vb2_stop_streaming() local
603 vpu_trace(inst->dev, "[%d] %s\n", inst->id, vpu_type_name(q->type)); in vpu_vb2_stop_streaming()
605 call_void_vop(inst, stop, q->type); in vpu_vb2_stop_streaming()
606 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_ERROR); in vpu_vb2_stop_streaming()
608 inst->sequence = 0; in vpu_vb2_stop_streaming()
614 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vpu_vb2_buf_queue() local
617 vbuf->sequence = inst->sequence++; in vpu_vb2_buf_queue()
619 v4l2_m2m_buf_queue(inst->fh.m2m_ctx, vbuf); in vpu_vb2_buf_queue()
620 vpu_process_output_buffer(inst); in vpu_vb2_buf_queue()
621 vpu_process_capture_buffer(inst); in vpu_vb2_buf_queue()
639 struct vpu_inst *inst = priv; in vpu_m2m_queue_init() local
643 inst->out_format.type = src_vq->type; in vpu_m2m_queue_init()
648 if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer) in vpu_m2m_queue_init()
650 src_vq->drv_priv = inst; in vpu_m2m_queue_init()
653 src_vq->dev = inst->vpu->dev; in vpu_m2m_queue_init()
654 src_vq->lock = &inst->lock; in vpu_m2m_queue_init()
660 inst->cap_format.type = dst_vq->type; in vpu_m2m_queue_init()
665 if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer) in vpu_m2m_queue_init()
667 dst_vq->drv_priv = inst; in vpu_m2m_queue_init()
670 dst_vq->dev = inst->vpu->dev; in vpu_m2m_queue_init()
671 dst_vq->lock = &inst->lock; in vpu_m2m_queue_init()
681 static int vpu_v4l2_release(struct vpu_inst *inst) in vpu_v4l2_release() argument
683 vpu_trace(inst->vpu->dev, "%p\n", inst); in vpu_v4l2_release()
685 vpu_release_core(inst->core); in vpu_v4l2_release()
686 put_device(inst->dev); in vpu_v4l2_release()
688 if (inst->workqueue) { in vpu_v4l2_release()
689 cancel_work_sync(&inst->msg_work); in vpu_v4l2_release()
690 destroy_workqueue(inst->workqueue); in vpu_v4l2_release()
691 inst->workqueue = NULL; in vpu_v4l2_release()
694 v4l2_ctrl_handler_free(&inst->ctrl_handler); in vpu_v4l2_release()
695 mutex_destroy(&inst->lock); in vpu_v4l2_release()
696 v4l2_fh_del(&inst->fh); in vpu_v4l2_release()
697 v4l2_fh_exit(&inst->fh); in vpu_v4l2_release()
699 call_void_vop(inst, cleanup); in vpu_v4l2_release()
704 int vpu_v4l2_open(struct file *file, struct vpu_inst *inst) in vpu_v4l2_open() argument
710 if (!inst || !inst->ops) in vpu_v4l2_open()
713 if (inst->type == VPU_CORE_TYPE_ENC) in vpu_v4l2_open()
718 atomic_set(&inst->ref_count, 0); in vpu_v4l2_open()
719 atomic_long_set(&inst->last_response_cmd, 0); in vpu_v4l2_open()
720 vpu_inst_get(inst); in vpu_v4l2_open()
721 inst->vpu = vpu; in vpu_v4l2_open()
722 inst->core = vpu_request_core(vpu, inst->type); in vpu_v4l2_open()
723 if (inst->core) in vpu_v4l2_open()
724 inst->dev = get_device(inst->core->dev); in vpu_v4l2_open()
725 mutex_init(&inst->lock); in vpu_v4l2_open()
726 INIT_LIST_HEAD(&inst->cmd_q); in vpu_v4l2_open()
727 inst->id = VPU_INST_NULL_ID; in vpu_v4l2_open()
728 inst->release = vpu_v4l2_release; in vpu_v4l2_open()
729 inst->pid = current->pid; in vpu_v4l2_open()
730 inst->tgid = current->tgid; in vpu_v4l2_open()
731 inst->min_buffer_cap = 2; in vpu_v4l2_open()
732 inst->min_buffer_out = 2; in vpu_v4l2_open()
733 v4l2_fh_init(&inst->fh, func->vfd); in vpu_v4l2_open()
734 v4l2_fh_add(&inst->fh); in vpu_v4l2_open()
736 ret = call_vop(inst, ctrl_init); in vpu_v4l2_open()
740 inst->fh.m2m_ctx = v4l2_m2m_ctx_init(func->m2m_dev, inst, vpu_m2m_queue_init); in vpu_v4l2_open()
741 if (IS_ERR(inst->fh.m2m_ctx)) { in vpu_v4l2_open()
743 ret = PTR_ERR(inst->fh.m2m_ctx); in vpu_v4l2_open()
747 inst->fh.ctrl_handler = &inst->ctrl_handler; in vpu_v4l2_open()
748 file->private_data = &inst->fh; in vpu_v4l2_open()
749 inst->state = VPU_CODEC_STATE_DEINIT; in vpu_v4l2_open()
750 inst->workqueue = alloc_ordered_workqueue("vpu_inst", WQ_MEM_RECLAIM); in vpu_v4l2_open()
751 if (inst->workqueue) { in vpu_v4l2_open()
752 INIT_WORK(&inst->msg_work, vpu_inst_run_work); in vpu_v4l2_open()
753 ret = kfifo_init(&inst->msg_fifo, in vpu_v4l2_open()
754 inst->msg_buffer, in vpu_v4l2_open()
755 rounddown_pow_of_two(sizeof(inst->msg_buffer))); in vpu_v4l2_open()
757 destroy_workqueue(inst->workqueue); in vpu_v4l2_open()
758 inst->workqueue = NULL; in vpu_v4l2_open()
762 inst->tgid, inst->pid, vpu_core_type_desc(inst->type), inst); in vpu_v4l2_open()
766 vpu_inst_put(inst); in vpu_v4l2_open()
773 struct vpu_inst *inst = to_inst(file); in vpu_v4l2_close() local
775 vpu_trace(vpu->dev, "tgid = %d, pid = %d, inst = %p\n", inst->tgid, inst->pid, inst); in vpu_v4l2_close()
777 vpu_inst_lock(inst); in vpu_v4l2_close()
778 if (inst->fh.m2m_ctx) { in vpu_v4l2_close()
779 v4l2_m2m_ctx_release(inst->fh.m2m_ctx); in vpu_v4l2_close()
780 inst->fh.m2m_ctx = NULL; in vpu_v4l2_close()
782 call_void_vop(inst, release); in vpu_v4l2_close()
783 vpu_inst_unlock(inst); in vpu_v4l2_close()
785 vpu_inst_unregister(inst); in vpu_v4l2_close()
786 vpu_inst_put(inst); in vpu_v4l2_close()