1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. 4 */ 5 6 #include <linux/pm_runtime.h> 7 #include <media/v4l2-mem2mem.h> 8 9 #include "iris_instance.h" 10 #include "iris_utils.h" 11 12 bool iris_res_is_less_than(u32 width, u32 height, 13 u32 ref_width, u32 ref_height) 14 { 15 u32 num_mbs = NUM_MBS_PER_FRAME(height, width); 16 u32 max_side = max(ref_width, ref_height); 17 18 if (num_mbs < NUM_MBS_PER_FRAME(ref_height, ref_width) && 19 width < max_side && 20 height < max_side) 21 return true; 22 23 return false; 24 } 25 26 int iris_get_mbpf(struct iris_inst *inst) 27 { 28 struct v4l2_format *inp_f = inst->fmt_src; 29 u32 height = max(inp_f->fmt.pix_mp.height, inst->crop.height); 30 u32 width = max(inp_f->fmt.pix_mp.width, inst->crop.width); 31 32 return NUM_MBS_PER_FRAME(height, width); 33 } 34 35 bool iris_split_mode_enabled(struct iris_inst *inst) 36 { 37 return inst->fmt_dst->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_NV12; 38 } 39 40 void iris_helper_buffers_done(struct iris_inst *inst, unsigned int type, 41 enum vb2_buffer_state state) 42 { 43 struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx; 44 struct vb2_v4l2_buffer *buf; 45 46 if (V4L2_TYPE_IS_OUTPUT(type)) { 47 while ((buf = v4l2_m2m_src_buf_remove(m2m_ctx))) 48 v4l2_m2m_buf_done(buf, state); 49 } else if (V4L2_TYPE_IS_CAPTURE(type)) { 50 while ((buf = v4l2_m2m_dst_buf_remove(m2m_ctx))) 51 v4l2_m2m_buf_done(buf, state); 52 } 53 } 54 55 int iris_wait_for_session_response(struct iris_inst *inst, bool is_flush) 56 { 57 struct iris_core *core = inst->core; 58 u32 hw_response_timeout_val; 59 struct completion *done; 60 int ret; 61 62 hw_response_timeout_val = core->iris_platform_data->hw_response_timeout; 63 done = is_flush ? &inst->flush_completion : &inst->completion; 64 65 mutex_unlock(&inst->lock); 66 ret = wait_for_completion_timeout(done, msecs_to_jiffies(hw_response_timeout_val)); 67 mutex_lock(&inst->lock); 68 if (!ret) { 69 iris_inst_change_state(inst, IRIS_INST_ERROR); 70 return -ETIMEDOUT; 71 } 72 73 return 0; 74 } 75 76 struct iris_inst *iris_get_instance(struct iris_core *core, u32 session_id) 77 { 78 struct iris_inst *inst; 79 80 mutex_lock(&core->lock); 81 list_for_each_entry(inst, &core->instances, list) { 82 if (inst->session_id == session_id) { 83 mutex_unlock(&core->lock); 84 return inst; 85 } 86 } 87 88 mutex_unlock(&core->lock); 89 return NULL; 90 } 91