1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef _MEDIA_V4L2_MEM2MEM_H
18#define _MEDIA_V4L2_MEM2MEM_H
19
20#include <media/videobuf2-core.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44struct v4l2_m2m_ops {
45 void (*device_run)(void *priv);
46 int (*job_ready)(void *priv);
47 void (*job_abort)(void *priv);
48 void (*lock)(void *priv);
49 void (*unlock)(void *priv);
50};
51
52struct v4l2_m2m_dev;
53
54struct v4l2_m2m_queue_ctx {
55
56 struct vb2_queue q;
57
58
59
60 struct list_head rdy_queue;
61 spinlock_t rdy_spinlock;
62 u8 num_rdy;
63 bool buffered;
64};
65
66struct v4l2_m2m_ctx {
67
68 struct mutex *q_lock;
69
70
71 struct v4l2_m2m_dev *m2m_dev;
72
73
74 struct v4l2_m2m_queue_ctx cap_q_ctx;
75
76
77 struct v4l2_m2m_queue_ctx out_q_ctx;
78
79
80 struct list_head queue;
81 unsigned long job_flags;
82 wait_queue_head_t finished;
83
84
85 void *priv;
86};
87
88struct v4l2_m2m_buffer {
89 struct vb2_buffer vb;
90 struct list_head list;
91};
92
93void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
94
95struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
96 enum v4l2_buf_type type);
97
98void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx);
99
100void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
101 struct v4l2_m2m_ctx *m2m_ctx);
102
103static inline void
104v4l2_m2m_buf_done(struct vb2_buffer *buf, enum vb2_buffer_state state)
105{
106 vb2_buffer_done(buf, state);
107}
108
109int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
110 struct v4l2_requestbuffers *reqbufs);
111
112int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
113 struct v4l2_buffer *buf);
114
115int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
116 struct v4l2_buffer *buf);
117int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
118 struct v4l2_buffer *buf);
119int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
120 struct v4l2_buffer *buf);
121int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
122 struct v4l2_create_buffers *create);
123
124int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
125 struct v4l2_exportbuffer *eb);
126
127int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
128 enum v4l2_buf_type type);
129int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
130 enum v4l2_buf_type type);
131
132unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
133 struct poll_table_struct *wait);
134
135int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
136 struct vm_area_struct *vma);
137
138struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops);
139void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev);
140
141struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
142 void *drv_priv,
143 int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq));
144
145static inline void v4l2_m2m_set_src_buffered(struct v4l2_m2m_ctx *m2m_ctx,
146 bool buffered)
147{
148 m2m_ctx->out_q_ctx.buffered = buffered;
149}
150
151static inline void v4l2_m2m_set_dst_buffered(struct v4l2_m2m_ctx *m2m_ctx,
152 bool buffered)
153{
154 m2m_ctx->cap_q_ctx.buffered = buffered;
155}
156
157void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx);
158
159void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_buffer *vb);
160
161
162
163
164
165static inline
166unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
167{
168 return m2m_ctx->out_q_ctx.num_rdy;
169}
170
171
172
173
174
175static inline
176unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
177{
178 return m2m_ctx->cap_q_ctx.num_rdy;
179}
180
181void *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx);
182
183
184
185
186
187static inline void *v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx)
188{
189 return v4l2_m2m_next_buf(&m2m_ctx->out_q_ctx);
190}
191
192
193
194
195
196static inline void *v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx)
197{
198 return v4l2_m2m_next_buf(&m2m_ctx->cap_q_ctx);
199}
200
201
202
203
204static inline
205struct vb2_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx)
206{
207 return &m2m_ctx->out_q_ctx.q;
208}
209
210
211
212
213static inline
214struct vb2_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx)
215{
216 return &m2m_ctx->cap_q_ctx.q;
217}
218
219void *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx);
220
221
222
223
224
225static inline void *v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
226{
227 return v4l2_m2m_buf_remove(&m2m_ctx->out_q_ctx);
228}
229
230
231
232
233
234static inline void *v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
235{
236 return v4l2_m2m_buf_remove(&m2m_ctx->cap_q_ctx);
237}
238
239
240
241int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv,
242 struct v4l2_requestbuffers *rb);
243int v4l2_m2m_ioctl_create_bufs(struct file *file, void *fh,
244 struct v4l2_create_buffers *create);
245int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh,
246 struct v4l2_buffer *buf);
247int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh,
248 struct v4l2_exportbuffer *eb);
249int v4l2_m2m_ioctl_qbuf(struct file *file, void *fh,
250 struct v4l2_buffer *buf);
251int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh,
252 struct v4l2_buffer *buf);
253int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *fh,
254 struct v4l2_buffer *buf);
255int v4l2_m2m_ioctl_streamon(struct file *file, void *fh,
256 enum v4l2_buf_type type);
257int v4l2_m2m_ioctl_streamoff(struct file *file, void *fh,
258 enum v4l2_buf_type type);
259int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma);
260unsigned int v4l2_m2m_fop_poll(struct file *file, poll_table *wait);
261
262#endif
263
264