Lines Matching refs:inst

91 find_format(struct venus_inst *inst, u32 pixfmt, u32 type)  in find_format()  argument
106 !venus_helper_check_codec(inst, fmt[i].pixfmt)) in find_format()
113 find_format_by_index(struct venus_inst *inst, unsigned int index, u32 type) in find_format_by_index() argument
128 venus_helper_check_codec(inst, fmt[i].pixfmt); in find_format_by_index()
142 vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) in vdec_try_fmt_common() argument
152 fmt = find_format(inst, pixmp->pixelformat, f->type); in vdec_try_fmt_common()
160 fmt = find_format(inst, pixmp->pixelformat, f->type); in vdec_try_fmt_common()
163 pixmp->width = clamp(pixmp->width, frame_width_min(inst), in vdec_try_fmt_common()
164 frame_width_max(inst)); in vdec_try_fmt_common()
165 pixmp->height = clamp(pixmp->height, frame_height_min(inst), in vdec_try_fmt_common()
166 frame_height_max(inst)); in vdec_try_fmt_common()
193 struct venus_inst *inst = to_inst(file); in vdec_try_fmt() local
195 vdec_try_fmt_common(inst, f); in vdec_try_fmt()
200 static int vdec_check_src_change(struct venus_inst *inst) in vdec_check_src_change() argument
204 if (inst->subscriptions & V4L2_EVENT_SOURCE_CHANGE && in vdec_check_src_change()
205 inst->codec_state == VENUS_DEC_STATE_INIT && in vdec_check_src_change()
206 !inst->reconfig) in vdec_check_src_change()
209 if (inst->subscriptions & V4L2_EVENT_SOURCE_CHANGE) in vdec_check_src_change()
218 if (inst->codec_state != VENUS_DEC_STATE_INIT) in vdec_check_src_change()
221 ret = wait_event_timeout(inst->reconf_wait, inst->reconfig, in vdec_check_src_change()
226 if (!(inst->codec_state == VENUS_DEC_STATE_CAPTURE_SETUP) || in vdec_check_src_change()
227 !inst->reconfig) in vdec_check_src_change()
228 dev_dbg(inst->core->dev, VDBGH "wrong state\n"); in vdec_check_src_change()
236 struct venus_inst *inst = to_inst(file); in vdec_g_fmt() local
242 fmt = inst->fmt_cap; in vdec_g_fmt()
244 fmt = inst->fmt_out; in vdec_g_fmt()
247 ret = vdec_check_src_change(inst); in vdec_g_fmt()
255 pixmp->width = inst->width; in vdec_g_fmt()
256 pixmp->height = inst->height; in vdec_g_fmt()
257 pixmp->colorspace = inst->colorspace; in vdec_g_fmt()
258 pixmp->ycbcr_enc = inst->ycbcr_enc; in vdec_g_fmt()
259 pixmp->quantization = inst->quantization; in vdec_g_fmt()
260 pixmp->xfer_func = inst->xfer_func; in vdec_g_fmt()
262 pixmp->width = inst->out_width; in vdec_g_fmt()
263 pixmp->height = inst->out_height; in vdec_g_fmt()
266 vdec_try_fmt_common(inst, f); in vdec_g_fmt()
273 struct venus_inst *inst = to_inst(file); in vdec_s_fmt() local
281 q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type); in vdec_s_fmt()
290 fmt = vdec_try_fmt_common(inst, f); in vdec_s_fmt()
294 pixfmt_cap = inst->fmt_cap->pixfmt; in vdec_s_fmt()
297 pixfmt_out = inst->fmt_out->pixfmt; in vdec_s_fmt()
306 vdec_try_fmt_common(inst, &format); in vdec_s_fmt()
309 inst->out_width = format.fmt.pix_mp.width; in vdec_s_fmt()
310 inst->out_height = format.fmt.pix_mp.height; in vdec_s_fmt()
311 inst->colorspace = pixmp->colorspace; in vdec_s_fmt()
312 inst->ycbcr_enc = pixmp->ycbcr_enc; in vdec_s_fmt()
313 inst->quantization = pixmp->quantization; in vdec_s_fmt()
314 inst->xfer_func = pixmp->xfer_func; in vdec_s_fmt()
315 inst->input_buf_size = pixmp->plane_fmt[0].sizeimage; in vdec_s_fmt()
324 vdec_try_fmt_common(inst, &format); in vdec_s_fmt()
326 inst->width = format.fmt.pix_mp.width; in vdec_s_fmt()
327 inst->height = format.fmt.pix_mp.height; in vdec_s_fmt()
328 inst->crop.top = 0; in vdec_s_fmt()
329 inst->crop.left = 0; in vdec_s_fmt()
330 inst->crop.width = inst->width; in vdec_s_fmt()
331 inst->crop.height = inst->height; in vdec_s_fmt()
334 inst->fmt_out = fmt; in vdec_s_fmt()
336 inst->fmt_cap = fmt; in vdec_s_fmt()
337 inst->output2_buf_size = in vdec_s_fmt()
347 struct venus_inst *inst = to_inst(file); in vdec_g_selection() local
362 s->r.width = inst->out_width; in vdec_g_selection()
363 s->r.height = inst->out_height; in vdec_g_selection()
369 s->r.width = inst->width; in vdec_g_selection()
370 s->r.height = inst->height; in vdec_g_selection()
376 s->r = inst->crop; in vdec_g_selection()
397 struct venus_inst *inst = to_inst(file); in vdec_enum_fmt() local
402 fmt = find_format_by_index(inst, f->index, f->type); in vdec_enum_fmt()
414 struct venus_inst *inst = to_inst(file); in vdec_s_parm() local
425 timeperframe->denominator = inst->timeperframe.denominator; in vdec_s_parm()
427 timeperframe->numerator = inst->timeperframe.numerator; in vdec_s_parm()
440 inst->fps = fps; in vdec_s_parm()
441 inst->timeperframe = *timeperframe; in vdec_s_parm()
449 struct venus_inst *inst = to_inst(file); in vdec_enum_framesizes() local
452 fmt = find_format(inst, fsize->pixel_format, in vdec_enum_framesizes()
455 fmt = find_format(inst, fsize->pixel_format, in vdec_enum_framesizes()
466 fsize->stepwise.min_width = frame_width_min(inst); in vdec_enum_framesizes()
467 fsize->stepwise.max_width = frame_width_max(inst); in vdec_enum_framesizes()
468 fsize->stepwise.step_width = frame_width_step(inst); in vdec_enum_framesizes()
469 fsize->stepwise.min_height = frame_height_min(inst); in vdec_enum_framesizes()
470 fsize->stepwise.max_height = frame_height_max(inst); in vdec_enum_framesizes()
471 fsize->stepwise.step_height = frame_height_step(inst); in vdec_enum_framesizes()
479 struct venus_inst *inst = container_of(fh, struct venus_inst, fh); in vdec_subscribe_event() local
489 inst->subscriptions |= V4L2_EVENT_SOURCE_CHANGE; in vdec_subscribe_event()
501 struct venus_inst *inst = to_inst(file); in vdec_decoder_cmd() local
509 mutex_lock(&inst->lock); in vdec_decoder_cmd()
516 if (!(inst->streamon_out && inst->streamon_cap)) in vdec_decoder_cmd()
521 if (IS_V6(inst->core)) in vdec_decoder_cmd()
526 ret = hfi_session_process_buf(inst, &fdata); in vdec_decoder_cmd()
528 if (!ret && inst->codec_state == VENUS_DEC_STATE_DECODING) { in vdec_decoder_cmd()
529 inst->codec_state = VENUS_DEC_STATE_DRAIN; in vdec_decoder_cmd()
530 inst->drain_active = true; in vdec_decoder_cmd()
535 mutex_unlock(&inst->lock); in vdec_decoder_cmd()
567 static int vdec_pm_get(struct venus_inst *inst) in vdec_pm_get() argument
569 struct venus_core *core = inst->core; in vdec_pm_get()
580 static int vdec_pm_put(struct venus_inst *inst, bool autosuspend) in vdec_pm_put() argument
582 struct venus_core *core = inst->core; in vdec_pm_put()
598 static int vdec_pm_get_put(struct venus_inst *inst) in vdec_pm_get_put() argument
600 struct venus_core *core = inst->core; in vdec_pm_get_put()
620 static void vdec_pm_touch(struct venus_inst *inst) in vdec_pm_touch() argument
622 pm_runtime_mark_last_busy(inst->core->dev_dec); in vdec_pm_touch()
625 static int vdec_set_properties(struct venus_inst *inst) in vdec_set_properties() argument
627 struct vdec_controls *ctr = &inst->controls.dec; in vdec_set_properties()
634 ret = hfi_session_set_property(inst, ptype, &en); in vdec_set_properties()
642 ret = hfi_session_set_property(inst, ptype, &decode_order); in vdec_set_properties()
652 ret = hfi_session_set_property(inst, ptype, &conceal); in vdec_set_properties()
659 static int vdec_set_work_route(struct venus_inst *inst) in vdec_set_work_route() argument
664 if (!IS_V6(inst->core)) in vdec_set_work_route()
667 wr.video_work_route = inst->core->res->num_vpp_pipes; in vdec_set_work_route()
669 return hfi_session_set_property(inst, ptype, &wr); in vdec_set_work_route()
674 static int vdec_output_conf(struct venus_inst *inst) in vdec_output_conf() argument
676 struct venus_core *core = inst->core; in vdec_output_conf()
679 u32 width = inst->out_width; in vdec_output_conf()
680 u32 height = inst->out_height; in vdec_output_conf()
686 ret = venus_helper_set_work_mode(inst); in vdec_output_conf()
692 ret = hfi_session_set_property(inst, ptype, &en); in vdec_output_conf()
705 ret = venus_helper_get_out_fmts(inst, inst->fmt_cap->pixfmt, &out_fmt, in vdec_output_conf()
710 inst->output_buf_size = in vdec_output_conf()
712 inst->output2_buf_size = in vdec_output_conf()
716 inst->opb_buftype = HFI_BUFFER_OUTPUT2; in vdec_output_conf()
717 inst->opb_fmt = out2_fmt; in vdec_output_conf()
718 inst->dpb_buftype = HFI_BUFFER_OUTPUT; in vdec_output_conf()
719 inst->dpb_fmt = out_fmt; in vdec_output_conf()
721 inst->opb_buftype = HFI_BUFFER_OUTPUT; in vdec_output_conf()
722 inst->opb_fmt = out_fmt; in vdec_output_conf()
723 inst->dpb_buftype = HFI_BUFFER_OUTPUT2; in vdec_output_conf()
724 inst->dpb_fmt = out2_fmt; in vdec_output_conf()
726 inst->opb_buftype = HFI_BUFFER_OUTPUT; in vdec_output_conf()
727 inst->opb_fmt = out_fmt; in vdec_output_conf()
728 inst->dpb_buftype = 0; in vdec_output_conf()
729 inst->dpb_fmt = 0; in vdec_output_conf()
732 ret = venus_helper_set_raw_format(inst, inst->opb_fmt, in vdec_output_conf()
733 inst->opb_buftype); in vdec_output_conf()
737 ret = venus_helper_set_format_constraints(inst); in vdec_output_conf()
741 if (inst->dpb_fmt) { in vdec_output_conf()
742 ret = venus_helper_set_multistream(inst, false, true); in vdec_output_conf()
746 ret = venus_helper_set_raw_format(inst, inst->dpb_fmt, in vdec_output_conf()
747 inst->dpb_buftype); in vdec_output_conf()
751 ret = venus_helper_set_output_resolution(inst, width, height, in vdec_output_conf()
758 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_OUTPUT, &bufreq); in vdec_output_conf()
762 if (bufreq.size > inst->output_buf_size) in vdec_output_conf()
765 if (inst->dpb_fmt) { in vdec_output_conf()
766 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_OUTPUT2, in vdec_output_conf()
771 if (bufreq.size > inst->output2_buf_size) in vdec_output_conf()
775 if (inst->output2_buf_size) { in vdec_output_conf()
776 ret = venus_helper_set_bufsize(inst, in vdec_output_conf()
777 inst->output2_buf_size, in vdec_output_conf()
783 if (inst->output_buf_size) { in vdec_output_conf()
784 ret = venus_helper_set_bufsize(inst, in vdec_output_conf()
785 inst->output_buf_size, in vdec_output_conf()
792 ret = venus_helper_set_dyn_bufmode(inst); in vdec_output_conf()
799 static int vdec_session_init(struct venus_inst *inst) in vdec_session_init() argument
803 ret = venus_helper_session_init(inst); in vdec_session_init()
809 ret = venus_helper_set_input_resolution(inst, frame_width_min(inst), in vdec_session_init()
810 frame_height_min(inst)); in vdec_session_init()
816 hfi_session_deinit(inst); in vdec_session_init()
820 static int vdec_num_buffers(struct venus_inst *inst, unsigned int *in_num, in vdec_num_buffers() argument
823 enum hfi_version ver = inst->core->res->hfi_version; in vdec_num_buffers()
829 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); in vdec_num_buffers()
835 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_OUTPUT, &bufreq); in vdec_num_buffers()
848 struct venus_inst *inst = vb2_get_drv_priv(q); in vdec_queue_setup() local
849 struct venus_core *core = inst->core; in vdec_queue_setup()
854 unsigned int output_buf_size = venus_helper_get_opb_size(inst); in vdec_queue_setup()
857 *num_planes != inst->fmt_out->num_planes) in vdec_queue_setup()
861 *num_planes != inst->fmt_cap->num_planes) in vdec_queue_setup()
865 sizes[0] < inst->input_buf_size) in vdec_queue_setup()
876 if (inst->nonblock) in vdec_queue_setup()
885 ret = vdec_pm_get(inst); in vdec_queue_setup()
889 ret = vdec_session_init(inst); in vdec_queue_setup()
893 ret = vdec_num_buffers(inst, &in_num, &out_num); in vdec_queue_setup()
897 ret = vdec_pm_put(inst, false); in vdec_queue_setup()
903 *num_planes = inst->fmt_out->num_planes; in vdec_queue_setup()
904 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, in vdec_queue_setup()
905 inst->out_width, in vdec_queue_setup()
906 inst->out_height); in vdec_queue_setup()
907 sizes[0] = max(sizes[0], inst->input_buf_size); in vdec_queue_setup()
908 inst->input_buf_size = sizes[0]; in vdec_queue_setup()
910 inst->num_input_bufs = *num_buffers; in vdec_queue_setup()
911 inst->num_output_bufs = out_num; in vdec_queue_setup()
914 *num_planes = inst->fmt_cap->num_planes; in vdec_queue_setup()
915 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, in vdec_queue_setup()
916 inst->width, in vdec_queue_setup()
917 inst->height); in vdec_queue_setup()
918 inst->output_buf_size = sizes[0]; in vdec_queue_setup()
920 inst->num_output_bufs = *num_buffers; in vdec_queue_setup()
922 mutex_lock(&inst->lock); in vdec_queue_setup()
923 if (inst->codec_state == VENUS_DEC_STATE_CAPTURE_SETUP) in vdec_queue_setup()
924 inst->codec_state = VENUS_DEC_STATE_STOPPED; in vdec_queue_setup()
925 mutex_unlock(&inst->lock); in vdec_queue_setup()
935 vdec_pm_put(inst, false); in vdec_queue_setup()
939 static int vdec_verify_conf(struct venus_inst *inst) in vdec_verify_conf() argument
941 enum hfi_version ver = inst->core->res->hfi_version; in vdec_verify_conf()
945 if (!inst->num_input_bufs || !inst->num_output_bufs) in vdec_verify_conf()
948 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_OUTPUT, &bufreq); in vdec_verify_conf()
952 if (inst->num_output_bufs < bufreq.count_actual || in vdec_verify_conf()
953 inst->num_output_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in vdec_verify_conf()
956 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); in vdec_verify_conf()
960 if (inst->num_input_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in vdec_verify_conf()
966 static int vdec_start_capture(struct venus_inst *inst) in vdec_start_capture() argument
970 if (!inst->streamon_out) in vdec_start_capture()
973 if (inst->codec_state == VENUS_DEC_STATE_DECODING) { in vdec_start_capture()
974 if (inst->reconfig) in vdec_start_capture()
977 venus_helper_queue_dpb_bufs(inst); in vdec_start_capture()
978 venus_helper_process_initial_cap_bufs(inst); in vdec_start_capture()
979 inst->streamon_cap = 1; in vdec_start_capture()
983 if (inst->codec_state != VENUS_DEC_STATE_STOPPED) in vdec_start_capture()
987 ret = vdec_output_conf(inst); in vdec_start_capture()
991 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in vdec_start_capture()
996 ret = venus_helper_intbufs_realloc(inst); in vdec_start_capture()
1000 venus_pm_load_scale(inst); in vdec_start_capture()
1002 inst->next_buf_last = false; in vdec_start_capture()
1004 ret = venus_helper_alloc_dpb_bufs(inst); in vdec_start_capture()
1008 ret = hfi_session_continue(inst); in vdec_start_capture()
1012 ret = venus_helper_queue_dpb_bufs(inst); in vdec_start_capture()
1016 ret = venus_helper_process_initial_cap_bufs(inst); in vdec_start_capture()
1020 inst->codec_state = VENUS_DEC_STATE_DECODING; in vdec_start_capture()
1022 if (inst->drain_active) in vdec_start_capture()
1023 inst->codec_state = VENUS_DEC_STATE_DRAIN; in vdec_start_capture()
1025 inst->streamon_cap = 1; in vdec_start_capture()
1026 inst->sequence_cap = 0; in vdec_start_capture()
1027 inst->reconfig = false; in vdec_start_capture()
1028 inst->drain_active = false; in vdec_start_capture()
1033 venus_helper_free_dpb_bufs(inst); in vdec_start_capture()
1038 static int vdec_start_output(struct venus_inst *inst) in vdec_start_output() argument
1042 if (inst->codec_state == VENUS_DEC_STATE_SEEK) { in vdec_start_output()
1043 ret = venus_helper_process_initial_out_bufs(inst); in vdec_start_output()
1044 if (inst->next_buf_last) in vdec_start_output()
1045 inst->codec_state = VENUS_DEC_STATE_DRC; in vdec_start_output()
1047 inst->codec_state = VENUS_DEC_STATE_DECODING; in vdec_start_output()
1051 if (inst->codec_state == VENUS_DEC_STATE_INIT || in vdec_start_output()
1052 inst->codec_state == VENUS_DEC_STATE_CAPTURE_SETUP) { in vdec_start_output()
1053 ret = venus_helper_process_initial_out_bufs(inst); in vdec_start_output()
1057 if (inst->codec_state != VENUS_DEC_STATE_DEINIT) in vdec_start_output()
1060 venus_helper_init_instance(inst); in vdec_start_output()
1061 inst->sequence_out = 0; in vdec_start_output()
1062 inst->reconfig = false; in vdec_start_output()
1063 inst->next_buf_last = false; in vdec_start_output()
1065 ret = vdec_set_properties(inst); in vdec_start_output()
1069 ret = vdec_set_work_route(inst); in vdec_start_output()
1073 ret = vdec_output_conf(inst); in vdec_start_output()
1077 ret = vdec_verify_conf(inst); in vdec_start_output()
1081 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in vdec_start_output()
1086 ret = venus_helper_vb2_start_streaming(inst); in vdec_start_output()
1090 ret = venus_helper_process_initial_out_bufs(inst); in vdec_start_output()
1094 inst->codec_state = VENUS_DEC_STATE_INIT; in vdec_start_output()
1097 inst->streamon_out = 1; in vdec_start_output()
1103 struct venus_inst *inst = vb2_get_drv_priv(q); in vdec_start_streaming() local
1106 mutex_lock(&inst->lock); in vdec_start_streaming()
1109 ret = vdec_start_capture(inst); in vdec_start_streaming()
1111 ret = vdec_pm_get(inst); in vdec_start_streaming()
1115 ret = venus_pm_acquire_core(inst); in vdec_start_streaming()
1119 ret = vdec_pm_put(inst, true); in vdec_start_streaming()
1123 ret = vdec_start_output(inst); in vdec_start_streaming()
1129 mutex_unlock(&inst->lock); in vdec_start_streaming()
1133 vdec_pm_put(inst, false); in vdec_start_streaming()
1135 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); in vdec_start_streaming()
1136 mutex_unlock(&inst->lock); in vdec_start_streaming()
1140 static void vdec_cancel_dst_buffers(struct venus_inst *inst) in vdec_cancel_dst_buffers() argument
1144 while ((buf = v4l2_m2m_dst_buf_remove(inst->m2m_ctx))) in vdec_cancel_dst_buffers()
1148 static int vdec_stop_capture(struct venus_inst *inst) in vdec_stop_capture() argument
1152 switch (inst->codec_state) { in vdec_stop_capture()
1154 ret = hfi_session_flush(inst, HFI_FLUSH_ALL, true); in vdec_stop_capture()
1157 inst->codec_state = VENUS_DEC_STATE_STOPPED; in vdec_stop_capture()
1158 inst->drain_active = false; in vdec_stop_capture()
1161 vdec_cancel_dst_buffers(inst); in vdec_stop_capture()
1164 ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, true); in vdec_stop_capture()
1165 inst->codec_state = VENUS_DEC_STATE_CAPTURE_SETUP; in vdec_stop_capture()
1166 venus_helper_free_dpb_bufs(inst); in vdec_stop_capture()
1175 static int vdec_stop_output(struct venus_inst *inst) in vdec_stop_output() argument
1179 switch (inst->codec_state) { in vdec_stop_output()
1184 ret = hfi_session_flush(inst, HFI_FLUSH_ALL, true); in vdec_stop_output()
1185 inst->codec_state = VENUS_DEC_STATE_SEEK; in vdec_stop_output()
1189 ret = hfi_session_flush(inst, HFI_FLUSH_INPUT, true); in vdec_stop_output()
1200 struct venus_inst *inst = vb2_get_drv_priv(q); in vdec_stop_streaming() local
1203 mutex_lock(&inst->lock); in vdec_stop_streaming()
1206 ret = vdec_stop_capture(inst); in vdec_stop_streaming()
1208 ret = vdec_stop_output(inst); in vdec_stop_streaming()
1210 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_ERROR); in vdec_stop_streaming()
1212 inst->session_error = 0; in vdec_stop_streaming()
1218 inst->streamon_out = 0; in vdec_stop_streaming()
1220 inst->streamon_cap = 0; in vdec_stop_streaming()
1223 mutex_unlock(&inst->lock); in vdec_stop_streaming()
1226 static void vdec_session_release(struct venus_inst *inst) in vdec_session_release() argument
1228 struct venus_core *core = inst->core; in vdec_session_release()
1231 vdec_pm_get(inst); in vdec_session_release()
1233 mutex_lock(&inst->lock); in vdec_session_release()
1234 inst->codec_state = VENUS_DEC_STATE_DEINIT; in vdec_session_release()
1236 ret = hfi_session_stop(inst); in vdec_session_release()
1238 ret = hfi_session_unload_res(inst); in vdec_session_release()
1240 ret = venus_helper_unregister_bufs(inst); in vdec_session_release()
1242 ret = venus_helper_intbufs_free(inst); in vdec_session_release()
1244 ret = hfi_session_deinit(inst); in vdec_session_release()
1247 if (inst->session_error || test_bit(0, &core->sys_error)) in vdec_session_release()
1251 hfi_session_abort(inst); in vdec_session_release()
1253 venus_helper_free_dpb_bufs(inst); in vdec_session_release()
1254 venus_pm_load_scale(inst); in vdec_session_release()
1255 INIT_LIST_HEAD(&inst->registeredbufs); in vdec_session_release()
1256 mutex_unlock(&inst->lock); in vdec_session_release()
1258 venus_pm_release_core(inst); in vdec_session_release()
1259 vdec_pm_put(inst, false); in vdec_session_release()
1264 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vdec_buf_init() local
1266 inst->buf_count++; in vdec_buf_init()
1273 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vdec_buf_cleanup() local
1277 mutex_lock(&inst->lock); in vdec_buf_cleanup()
1279 if (!list_empty(&inst->registeredbufs)) in vdec_buf_cleanup()
1281 mutex_unlock(&inst->lock); in vdec_buf_cleanup()
1283 inst->buf_count--; in vdec_buf_cleanup()
1284 if (!inst->buf_count) in vdec_buf_cleanup()
1285 vdec_session_release(inst); in vdec_buf_cleanup()
1290 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in vdec_vb2_buf_queue() local
1294 vdec_pm_get_put(inst); in vdec_vb2_buf_queue()
1296 mutex_lock(&inst->lock); in vdec_vb2_buf_queue()
1298 if (inst->next_buf_last && V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) && in vdec_vb2_buf_queue()
1299 inst->codec_state == VENUS_DEC_STATE_DRC) { in vdec_vb2_buf_queue()
1301 vbuf->sequence = inst->sequence_cap++; in vdec_vb2_buf_queue()
1305 v4l2_event_queue_fh(&inst->fh, &eos); in vdec_vb2_buf_queue()
1306 inst->next_buf_last = false; in vdec_vb2_buf_queue()
1307 mutex_unlock(&inst->lock); in vdec_vb2_buf_queue()
1312 mutex_unlock(&inst->lock); in vdec_vb2_buf_queue()
1325 static void vdec_buf_done(struct venus_inst *inst, unsigned int buf_type, in vdec_buf_done() argument
1334 vdec_pm_touch(inst); in vdec_buf_done()
1341 vbuf = venus_helper_find_buf(inst, type, tag); in vdec_buf_done()
1343 venus_helper_change_dpb_owner(inst, vbuf, type, buf_type, tag); in vdec_buf_done()
1355 vbuf->sequence = inst->sequence_cap++; in vdec_buf_done()
1360 v4l2_event_queue_fh(&inst->fh, &ev); in vdec_buf_done()
1362 if (inst->codec_state == VENUS_DEC_STATE_DRAIN) { in vdec_buf_done()
1363 inst->drain_active = false; in vdec_buf_done()
1364 inst->codec_state = VENUS_DEC_STATE_STOPPED; in vdec_buf_done()
1371 vbuf->sequence = inst->sequence_out++; in vdec_buf_done()
1374 venus_helper_get_ts_metadata(inst, timestamp_us, vbuf); in vdec_buf_done()
1391 static void vdec_event_change(struct venus_inst *inst, in vdec_event_change() argument
1397 struct device *dev = inst->core->dev_dec; in vdec_event_change()
1400 mutex_lock(&inst->lock); in vdec_event_change()
1403 format.fmt.pix_mp.pixelformat = inst->fmt_cap->pixfmt; in vdec_event_change()
1407 vdec_try_fmt_common(inst, &format); in vdec_event_change()
1409 inst->width = format.fmt.pix_mp.width; in vdec_event_change()
1410 inst->height = format.fmt.pix_mp.height; in vdec_event_change()
1416 inst->crop.left = ev_data->input_crop.left; in vdec_event_change()
1417 inst->crop.top = ev_data->input_crop.top; in vdec_event_change()
1418 inst->crop.width = ev_data->input_crop.width; in vdec_event_change()
1419 inst->crop.height = ev_data->input_crop.height; in vdec_event_change()
1421 inst->crop.left = 0; in vdec_event_change()
1422 inst->crop.top = 0; in vdec_event_change()
1423 inst->crop.width = ev_data->width; in vdec_event_change()
1424 inst->crop.height = ev_data->height; in vdec_event_change()
1427 inst->fw_min_cnt = ev_data->buf_count; in vdec_event_change()
1429 if (inst->hfi_codec == HFI_VIDEO_CODEC_VP9) in vdec_event_change()
1430 inst->fw_min_cnt = 11; in vdec_event_change()
1432 inst->out_width = ev_data->width; in vdec_event_change()
1433 inst->out_height = ev_data->height; in vdec_event_change()
1435 if (inst->bit_depth != ev_data->bit_depth) in vdec_event_change()
1436 inst->bit_depth = ev_data->bit_depth; in vdec_event_change()
1438 if (inst->pic_struct != ev_data->pic_struct) in vdec_event_change()
1439 inst->pic_struct = ev_data->pic_struct; in vdec_event_change()
1444 switch (inst->codec_state) { in vdec_event_change()
1446 inst->codec_state = VENUS_DEC_STATE_CAPTURE_SETUP; in vdec_event_change()
1450 inst->codec_state = VENUS_DEC_STATE_DRC; in vdec_event_change()
1462 if (inst->codec_state == VENUS_DEC_STATE_DRC) { in vdec_event_change()
1465 inst->next_buf_last = true; in vdec_event_change()
1467 ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, false); in vdec_event_change()
1472 inst->next_buf_last = true; in vdec_event_change()
1473 inst->reconfig = true; in vdec_event_change()
1474 v4l2_event_queue_fh(&inst->fh, &ev); in vdec_event_change()
1475 wake_up(&inst->reconf_wait); in vdec_event_change()
1477 mutex_unlock(&inst->lock); in vdec_event_change()
1480 static void vdec_event_notify(struct venus_inst *inst, u32 event, in vdec_event_notify() argument
1483 struct venus_core *core = inst->core; in vdec_event_notify()
1486 vdec_pm_touch(inst); in vdec_event_notify()
1490 inst->session_error = true; in vdec_event_notify()
1491 venus_helper_vb2_queue_error(inst); in vdec_event_notify()
1492 dev_err(dev, "dec: event session error %x\n", inst->error); in vdec_event_notify()
1497 vdec_event_change(inst, data, true); in vdec_event_notify()
1500 vdec_event_change(inst, data, false); in vdec_event_notify()
1503 venus_helper_release_buf_ref(inst, data->tag); in vdec_event_notify()
1514 static void vdec_flush_done(struct venus_inst *inst) in vdec_flush_done() argument
1516 dev_dbg(inst->core->dev_dec, VDBGH "flush done\n"); in vdec_flush_done()
1525 static void vdec_inst_init(struct venus_inst *inst) in vdec_inst_init() argument
1527 inst->hfi_codec = HFI_VIDEO_CODEC_H264; in vdec_inst_init()
1528 inst->fmt_out = &vdec_formats[6]; in vdec_inst_init()
1529 inst->fmt_cap = &vdec_formats[0]; in vdec_inst_init()
1530 inst->width = frame_width_min(inst); in vdec_inst_init()
1531 inst->height = ALIGN(frame_height_min(inst), 32); in vdec_inst_init()
1532 inst->crop.left = 0; in vdec_inst_init()
1533 inst->crop.top = 0; in vdec_inst_init()
1534 inst->crop.width = inst->width; in vdec_inst_init()
1535 inst->crop.height = inst->height; in vdec_inst_init()
1536 inst->fw_min_cnt = 8; in vdec_inst_init()
1537 inst->out_width = frame_width_min(inst); in vdec_inst_init()
1538 inst->out_height = frame_height_min(inst); in vdec_inst_init()
1539 inst->fps = 30; in vdec_inst_init()
1540 inst->timeperframe.numerator = 1; in vdec_inst_init()
1541 inst->timeperframe.denominator = 30; in vdec_inst_init()
1542 inst->opb_buftype = HFI_BUFFER_OUTPUT; in vdec_inst_init()
1557 struct venus_inst *inst = priv; in m2m_queue_init() local
1565 src_vq->drv_priv = inst; in m2m_queue_init()
1569 src_vq->dev = inst->core->dev; in m2m_queue_init()
1579 dst_vq->drv_priv = inst; in m2m_queue_init()
1583 dst_vq->dev = inst->core->dev; in m2m_queue_init()
1590 struct venus_inst *inst; in vdec_open() local
1593 inst = kzalloc(sizeof(*inst), GFP_KERNEL); in vdec_open()
1594 if (!inst) in vdec_open()
1597 INIT_LIST_HEAD(&inst->dpbbufs); in vdec_open()
1598 INIT_LIST_HEAD(&inst->registeredbufs); in vdec_open()
1599 INIT_LIST_HEAD(&inst->internalbufs); in vdec_open()
1600 INIT_LIST_HEAD(&inst->list); in vdec_open()
1601 mutex_init(&inst->lock); in vdec_open()
1603 inst->core = core; in vdec_open()
1604 inst->session_type = VIDC_SESSION_TYPE_DEC; in vdec_open()
1605 inst->num_output_bufs = 1; in vdec_open()
1606 inst->codec_state = VENUS_DEC_STATE_DEINIT; in vdec_open()
1607 inst->buf_count = 0; in vdec_open()
1608 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; in vdec_open()
1609 inst->core_acquired = false; in vdec_open()
1610 inst->bit_depth = VIDC_BITDEPTH_8; in vdec_open()
1611 inst->pic_struct = HFI_INTERLACE_FRAME_PROGRESSIVE; in vdec_open()
1612 init_waitqueue_head(&inst->reconf_wait); in vdec_open()
1613 inst->nonblock = file->f_flags & O_NONBLOCK; in vdec_open()
1615 venus_helper_init_instance(inst); in vdec_open()
1617 ret = vdec_ctrl_init(inst); in vdec_open()
1621 ret = hfi_session_create(inst, &vdec_hfi_ops); in vdec_open()
1625 vdec_inst_init(inst); in vdec_open()
1627 ida_init(&inst->dpb_ids); in vdec_open()
1633 inst->m2m_dev = v4l2_m2m_init(&vdec_m2m_ops); in vdec_open()
1634 if (IS_ERR(inst->m2m_dev)) { in vdec_open()
1635 ret = PTR_ERR(inst->m2m_dev); in vdec_open()
1639 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); in vdec_open()
1640 if (IS_ERR(inst->m2m_ctx)) { in vdec_open()
1641 ret = PTR_ERR(inst->m2m_ctx); in vdec_open()
1645 v4l2_fh_init(&inst->fh, core->vdev_dec); in vdec_open()
1647 inst->fh.ctrl_handler = &inst->ctrl_handler; in vdec_open()
1648 v4l2_fh_add(&inst->fh); in vdec_open()
1649 inst->fh.m2m_ctx = inst->m2m_ctx; in vdec_open()
1650 file->private_data = &inst->fh; in vdec_open()
1655 v4l2_m2m_release(inst->m2m_dev); in vdec_open()
1657 hfi_session_destroy(inst); in vdec_open()
1659 vdec_ctrl_deinit(inst); in vdec_open()
1661 kfree(inst); in vdec_open()
1667 struct venus_inst *inst = to_inst(file); in vdec_close() local
1669 vdec_pm_get(inst); in vdec_close()
1671 v4l2_m2m_ctx_release(inst->m2m_ctx); in vdec_close()
1672 v4l2_m2m_release(inst->m2m_dev); in vdec_close()
1673 vdec_ctrl_deinit(inst); in vdec_close()
1674 ida_destroy(&inst->dpb_ids); in vdec_close()
1675 hfi_session_destroy(inst); in vdec_close()
1676 mutex_destroy(&inst->lock); in vdec_close()
1677 v4l2_fh_del(&inst->fh); in vdec_close()
1678 v4l2_fh_exit(&inst->fh); in vdec_close()
1680 vdec_pm_put(inst, false); in vdec_close()
1682 kfree(inst); in vdec_close()