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 "iris_instance.h"
7 #include "iris_vb2.h"
8 
9 int iris_vb2_queue_setup(struct vb2_queue *q,
10 			 unsigned int *num_buffers, unsigned int *num_planes,
11 			 unsigned int sizes[], struct device *alloc_devs[])
12 {
13 	struct iris_inst *inst;
14 	struct iris_core *core;
15 	struct v4l2_format *f;
16 	int ret = 0;
17 
18 	inst = vb2_get_drv_priv(q);
19 
20 	mutex_lock(&inst->lock);
21 
22 	core = inst->core;
23 	f = V4L2_TYPE_IS_OUTPUT(q->type) ? inst->fmt_src : inst->fmt_dst;
24 
25 	if (*num_planes) {
26 		if (*num_planes != f->fmt.pix_mp.num_planes ||
27 		    sizes[0] < f->fmt.pix_mp.plane_fmt[0].sizeimage)
28 			ret = -EINVAL;
29 		goto unlock;
30 	}
31 
32 	if (!inst->once_per_session_set) {
33 		inst->once_per_session_set = true;
34 
35 		ret = core->hfi_ops->session_open(inst);
36 		if (ret) {
37 			ret = -EINVAL;
38 			dev_err(core->dev, "session open failed\n");
39 			goto unlock;
40 		}
41 	}
42 
43 	*num_planes = 1;
44 	sizes[0] = f->fmt.pix_mp.plane_fmt[0].sizeimage;
45 
46 unlock:
47 	mutex_unlock(&inst->lock);
48 
49 	return ret;
50 }
51