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
71 vpu_inst_lock(inst); in vpu_v4l2_set_error()
72 dev_err(inst->dev, "some error occurs in codec\n"); in vpu_v4l2_set_error()
73 if (inst->fh.m2m_ctx) { in vpu_v4l2_set_error()
74 src_q = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); in vpu_v4l2_set_error()
75 dst_q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); in vpu_v4l2_set_error()
81 vpu_inst_unlock(inst); in vpu_v4l2_set_error()
84 int vpu_notify_eos(struct vpu_inst *inst) in vpu_notify_eos() argument
91 vpu_trace(inst->dev, "[%d]\n", inst->id); in vpu_notify_eos()
92 v4l2_event_queue_fh(&inst->fh, &ev); in vpu_notify_eos()
97 int vpu_notify_source_change(struct vpu_inst *inst) in vpu_notify_source_change() argument
105 vpu_trace(inst->dev, "[%d]\n", inst->id); in vpu_notify_source_change()
106 v4l2_event_queue_fh(&inst->fh, &ev); in vpu_notify_source_change()
110 int vpu_set_last_buffer_dequeued(struct vpu_inst *inst) in vpu_set_last_buffer_dequeued() argument
114 if (!inst || !inst->fh.m2m_ctx) in vpu_set_last_buffer_dequeued()
117 q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); in vpu_set_last_buffer_dequeued()
123 vpu_trace(inst->dev, "last buffer dequeued\n"); in vpu_set_last_buffer_dequeued()
126 vpu_notify_eos(inst); in vpu_set_last_buffer_dequeued()
130 bool vpu_is_source_empty(struct vpu_inst *inst) in vpu_is_source_empty() argument
134 if (!inst->fh.m2m_ctx) in vpu_is_source_empty()
136 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_is_source_empty()
143 const struct vpu_format *vpu_try_fmt_common(struct vpu_inst *inst, struct v4l2_format *f) in vpu_try_fmt_common() argument
154 fmt = vpu_helper_find_format(inst, type, pixmp->pixelformat); in vpu_try_fmt_common()
156 fmt = vpu_helper_enum_format(inst, type, 0); in vpu_try_fmt_common()
162 res = vpu_get_resource(inst); in vpu_try_fmt_common()
166 pixmp->width = vpu_helper_valid_frame_width(inst, pixmp->width); in vpu_try_fmt_common()
168 pixmp->height = vpu_helper_valid_frame_height(inst, pixmp->height); in vpu_try_fmt_common()
190 static bool vpu_check_ready(struct vpu_inst *inst, u32 type) in vpu_check_ready() argument
192 if (!inst) in vpu_check_ready()
194 if (inst->state == VPU_CODEC_STATE_DEINIT || inst->id < 0) in vpu_check_ready()
196 if (!inst->ops->check_ready) in vpu_check_ready()
198 return call_vop(inst, check_ready, type); in vpu_check_ready()
201 int vpu_process_output_buffer(struct vpu_inst *inst) in vpu_process_output_buffer() argument
206 if (!inst || !inst->fh.m2m_ctx) in vpu_process_output_buffer()
209 if (!vpu_check_ready(inst, inst->out_format.type)) in vpu_process_output_buffer()
212 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_process_output_buffer()
222 dev_dbg(inst->dev, "[%d]frame id = %d / %d\n", in vpu_process_output_buffer()
223 inst->id, vbuf->sequence, inst->sequence); in vpu_process_output_buffer()
224 return call_vop(inst, process_output, &vbuf->vb2_buf); in vpu_process_output_buffer()
227 int vpu_process_capture_buffer(struct vpu_inst *inst) in vpu_process_capture_buffer() argument
232 if (!inst || !inst->fh.m2m_ctx) in vpu_process_capture_buffer()
235 if (!vpu_check_ready(inst, inst->cap_format.type)) in vpu_process_capture_buffer()
238 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) { in vpu_process_capture_buffer()
247 return call_vop(inst, process_capture, &vbuf->vb2_buf); in vpu_process_capture_buffer()
250 struct vb2_v4l2_buffer *vpu_next_src_buf(struct vpu_inst *inst) in vpu_next_src_buf() argument
252 struct vb2_v4l2_buffer *src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx); in vpu_next_src_buf()
258 v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx); in vpu_next_src_buf()
262 src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx); in vpu_next_src_buf()
270 void vpu_skip_frame(struct vpu_inst *inst, int count) in vpu_skip_frame() argument
280 src_buf = v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx); in vpu_skip_frame()
293 struct vb2_v4l2_buffer *vpu_find_buf_by_sequence(struct vpu_inst *inst, u32 type, u32 sequence) in vpu_find_buf_by_sequence() argument
298 if (!inst || !inst->fh.m2m_ctx) in vpu_find_buf_by_sequence()
302 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_sequence()
309 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_sequence()
320 struct vb2_v4l2_buffer *vpu_find_buf_by_idx(struct vpu_inst *inst, u32 type, u32 idx) in vpu_find_buf_by_idx() argument
325 if (!inst || !inst->fh.m2m_ctx) in vpu_find_buf_by_idx()
329 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_idx()
336 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) { in vpu_find_buf_by_idx()
347 int vpu_get_num_buffers(struct vpu_inst *inst, u32 type) in vpu_get_num_buffers() argument
351 if (!inst || !inst->fh.m2m_ctx) in vpu_get_num_buffers()
355 q = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); in vpu_get_num_buffers()
357 q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); in vpu_get_num_buffers()
368 struct vpu_inst *inst = priv; in vpu_m2m_job_abort() local
369 struct v4l2_m2m_ctx *m2m_ctx = inst->fh.m2m_ctx; in vpu_m2m_job_abort()
385 struct vpu_inst *inst = vb2_get_drv_priv(vq); in vpu_vb2_queue_setup() local
389 cur_fmt = vpu_get_format(inst, vq->type); in vpu_vb2_queue_setup()
402 *buf_count = max_t(unsigned int, *buf_count, inst->min_buffer_out); in vpu_vb2_queue_setup()
404 *buf_count = max_t(unsigned int, *buf_count, inst->min_buffer_cap); in vpu_vb2_queue_setup()
431 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vpu_vb2_buf_prepare() local
436 cur_fmt = vpu_get_format(inst, vb->type); in vpu_vb2_buf_prepare()
439 dev_dbg(inst->dev, "[%d] %s buf[%d] is invalid\n", in vpu_vb2_buf_prepare()
440 inst->id, vpu_type_name(vb->type), vb->index); in vpu_vb2_buf_prepare()
451 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vpu_vb2_buf_finish() local
455 vpu_notify_eos(inst); in vpu_vb2_buf_finish()
458 call_void_vop(inst, on_queue_empty, q->type); in vpu_vb2_buf_finish()
461 void vpu_vb2_buffers_return(struct vpu_inst *inst, unsigned int type, enum vb2_buffer_state state) in vpu_vb2_buffers_return() argument
466 while ((buf = v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx))) { in vpu_vb2_buffers_return()
471 while ((buf = v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx))) { in vpu_vb2_buffers_return()
480 struct vpu_inst *inst = vb2_get_drv_priv(q); in vpu_vb2_start_streaming() local
481 struct vpu_format *fmt = vpu_get_format(inst, q->type); in vpu_vb2_start_streaming()
484 vpu_inst_unlock(inst); in vpu_vb2_start_streaming()
485 ret = vpu_inst_register(inst); in vpu_vb2_start_streaming()
486 vpu_inst_lock(inst); in vpu_vb2_start_streaming()
488 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_QUEUED); in vpu_vb2_start_streaming()
492 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()
493 inst->id, vpu_type_name(q->type), in vpu_vb2_start_streaming()
504 ret = call_vop(inst, start, q->type); in vpu_vb2_start_streaming()
506 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_QUEUED); in vpu_vb2_start_streaming()
513 struct vpu_inst *inst = vb2_get_drv_priv(q); in vpu_vb2_stop_streaming() local
515 vpu_trace(inst->dev, "[%d] %s\n", inst->id, vpu_type_name(q->type)); in vpu_vb2_stop_streaming()
517 call_void_vop(inst, stop, q->type); in vpu_vb2_stop_streaming()
518 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_ERROR); in vpu_vb2_stop_streaming()
520 inst->sequence = 0; in vpu_vb2_stop_streaming()
526 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vpu_vb2_buf_queue() local
529 vbuf->sequence = inst->sequence++; in vpu_vb2_buf_queue()
531 v4l2_m2m_buf_queue(inst->fh.m2m_ctx, vbuf); in vpu_vb2_buf_queue()
532 vpu_process_output_buffer(inst); in vpu_vb2_buf_queue()
533 vpu_process_capture_buffer(inst); in vpu_vb2_buf_queue()
551 struct vpu_inst *inst = priv; in vpu_m2m_queue_init() local
555 inst->out_format.type = src_vq->type; in vpu_m2m_queue_init()
560 if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer) in vpu_m2m_queue_init()
562 src_vq->drv_priv = inst; in vpu_m2m_queue_init()
565 src_vq->dev = inst->vpu->dev; in vpu_m2m_queue_init()
566 src_vq->lock = &inst->lock; in vpu_m2m_queue_init()
572 inst->cap_format.type = dst_vq->type; in vpu_m2m_queue_init()
577 if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer) in vpu_m2m_queue_init()
579 dst_vq->drv_priv = inst; in vpu_m2m_queue_init()
582 dst_vq->dev = inst->vpu->dev; in vpu_m2m_queue_init()
583 dst_vq->lock = &inst->lock; in vpu_m2m_queue_init()
593 static int vpu_v4l2_release(struct vpu_inst *inst) in vpu_v4l2_release() argument
595 vpu_trace(inst->vpu->dev, "%p\n", inst); in vpu_v4l2_release()
597 vpu_release_core(inst->core); in vpu_v4l2_release()
598 put_device(inst->dev); in vpu_v4l2_release()
600 if (inst->workqueue) { in vpu_v4l2_release()
601 cancel_work_sync(&inst->msg_work); in vpu_v4l2_release()
602 destroy_workqueue(inst->workqueue); in vpu_v4l2_release()
603 inst->workqueue = NULL; in vpu_v4l2_release()
606 if (inst->fh.m2m_ctx) { in vpu_v4l2_release()
607 v4l2_m2m_ctx_release(inst->fh.m2m_ctx); in vpu_v4l2_release()
608 inst->fh.m2m_ctx = NULL; in vpu_v4l2_release()
610 v4l2_ctrl_handler_free(&inst->ctrl_handler); in vpu_v4l2_release()
611 mutex_destroy(&inst->lock); in vpu_v4l2_release()
612 v4l2_fh_del(&inst->fh); in vpu_v4l2_release()
613 v4l2_fh_exit(&inst->fh); in vpu_v4l2_release()
615 call_void_vop(inst, cleanup); in vpu_v4l2_release()
620 int vpu_v4l2_open(struct file *file, struct vpu_inst *inst) in vpu_v4l2_open() argument
626 if (!inst || !inst->ops) in vpu_v4l2_open()
629 if (inst->type == VPU_CORE_TYPE_ENC) in vpu_v4l2_open()
634 atomic_set(&inst->ref_count, 0); in vpu_v4l2_open()
635 vpu_inst_get(inst); in vpu_v4l2_open()
636 inst->vpu = vpu; in vpu_v4l2_open()
637 inst->core = vpu_request_core(vpu, inst->type); in vpu_v4l2_open()
638 if (inst->core) in vpu_v4l2_open()
639 inst->dev = get_device(inst->core->dev); in vpu_v4l2_open()
640 mutex_init(&inst->lock); in vpu_v4l2_open()
641 INIT_LIST_HEAD(&inst->cmd_q); in vpu_v4l2_open()
642 inst->id = VPU_INST_NULL_ID; in vpu_v4l2_open()
643 inst->release = vpu_v4l2_release; in vpu_v4l2_open()
644 inst->pid = current->pid; in vpu_v4l2_open()
645 inst->tgid = current->tgid; in vpu_v4l2_open()
646 inst->min_buffer_cap = 2; in vpu_v4l2_open()
647 inst->min_buffer_out = 2; in vpu_v4l2_open()
648 v4l2_fh_init(&inst->fh, func->vfd); in vpu_v4l2_open()
649 v4l2_fh_add(&inst->fh); in vpu_v4l2_open()
651 ret = call_vop(inst, ctrl_init); in vpu_v4l2_open()
655 inst->fh.m2m_ctx = v4l2_m2m_ctx_init(func->m2m_dev, inst, vpu_m2m_queue_init); in vpu_v4l2_open()
656 if (IS_ERR(inst->fh.m2m_ctx)) { in vpu_v4l2_open()
658 ret = PTR_ERR(inst->fh.m2m_ctx); in vpu_v4l2_open()
662 inst->fh.ctrl_handler = &inst->ctrl_handler; in vpu_v4l2_open()
663 file->private_data = &inst->fh; in vpu_v4l2_open()
664 inst->state = VPU_CODEC_STATE_DEINIT; in vpu_v4l2_open()
665 inst->workqueue = alloc_workqueue("vpu_inst", WQ_UNBOUND | WQ_MEM_RECLAIM, 1); in vpu_v4l2_open()
666 if (inst->workqueue) { in vpu_v4l2_open()
667 INIT_WORK(&inst->msg_work, vpu_inst_run_work); in vpu_v4l2_open()
668 ret = kfifo_init(&inst->msg_fifo, in vpu_v4l2_open()
669 inst->msg_buffer, in vpu_v4l2_open()
670 rounddown_pow_of_two(sizeof(inst->msg_buffer))); in vpu_v4l2_open()
672 destroy_workqueue(inst->workqueue); in vpu_v4l2_open()
673 inst->workqueue = NULL; in vpu_v4l2_open()
677 inst->tgid, inst->pid, vpu_core_type_desc(inst->type), inst); in vpu_v4l2_open()
681 vpu_inst_put(inst); in vpu_v4l2_open()
688 struct vpu_inst *inst = to_inst(file); in vpu_v4l2_close() local
690 vpu_trace(vpu->dev, "tgid = %d, pid = %d, inst = %p\n", inst->tgid, inst->pid, inst); in vpu_v4l2_close()
692 call_void_vop(inst, release); in vpu_v4l2_close()
693 vpu_inst_unregister(inst); in vpu_v4l2_close()
694 vpu_inst_put(inst); in vpu_v4l2_close()