Branch data Line data Source code
1 : : /* SPDX-License-Identifier: GPL-2.0-or-later */
2 : : /*
3 : : * Memory-to-memory device framework for Video for Linux 2.
4 : : *
5 : : * Helper functions for devices that use memory buffers for both source
6 : : * and destination.
7 : : *
8 : : * Copyright (c) 2009 Samsung Electronics Co., Ltd.
9 : : * Pawel Osciak, <pawel@osciak.com>
10 : : * Marek Szyprowski, <m.szyprowski@samsung.com>
11 : : */
12 : :
13 : : #ifndef _MEDIA_V4L2_MEM2MEM_H
14 : : #define _MEDIA_V4L2_MEM2MEM_H
15 : :
16 : : #include <media/videobuf2-v4l2.h>
17 : :
18 : : /**
19 : : * struct v4l2_m2m_ops - mem-to-mem device driver callbacks
20 : : * @device_run: required. Begin the actual job (transaction) inside this
21 : : * callback.
22 : : * The job does NOT have to end before this callback returns
23 : : * (and it will be the usual case). When the job finishes,
24 : : * v4l2_m2m_job_finish() or v4l2_m2m_buf_done_and_job_finish()
25 : : * has to be called.
26 : : * @job_ready: optional. Should return 0 if the driver does not have a job
27 : : * fully prepared to run yet (i.e. it will not be able to finish a
28 : : * transaction without sleeping). If not provided, it will be
29 : : * assumed that one source and one destination buffer are all
30 : : * that is required for the driver to perform one full transaction.
31 : : * This method may not sleep.
32 : : * @job_abort: optional. Informs the driver that it has to abort the currently
33 : : * running transaction as soon as possible (i.e. as soon as it can
34 : : * stop the device safely; e.g. in the next interrupt handler),
35 : : * even if the transaction would not have been finished by then.
36 : : * After the driver performs the necessary steps, it has to call
37 : : * v4l2_m2m_job_finish() or v4l2_m2m_buf_done_and_job_finish() as
38 : : * if the transaction ended normally.
39 : : * This function does not have to (and will usually not) wait
40 : : * until the device enters a state when it can be stopped.
41 : : */
42 : : struct v4l2_m2m_ops {
43 : : void (*device_run)(void *priv);
44 : : int (*job_ready)(void *priv);
45 : : void (*job_abort)(void *priv);
46 : : };
47 : :
48 : : struct video_device;
49 : : struct v4l2_m2m_dev;
50 : :
51 : : /**
52 : : * struct v4l2_m2m_queue_ctx - represents a queue for buffers ready to be
53 : : * processed
54 : : *
55 : : * @q: pointer to struct &vb2_queue
56 : : * @rdy_queue: List of V4L2 mem-to-mem queues
57 : : * @rdy_spinlock: spin lock to protect the struct usage
58 : : * @num_rdy: number of buffers ready to be processed
59 : : * @buffered: is the queue buffered?
60 : : *
61 : : * Queue for buffers ready to be processed as soon as this
62 : : * instance receives access to the device.
63 : : */
64 : :
65 : : struct v4l2_m2m_queue_ctx {
66 : : struct vb2_queue q;
67 : :
68 : : struct list_head rdy_queue;
69 : : spinlock_t rdy_spinlock;
70 : : u8 num_rdy;
71 : : bool buffered;
72 : : };
73 : :
74 : : /**
75 : : * struct v4l2_m2m_ctx - Memory to memory context structure
76 : : *
77 : : * @q_lock: struct &mutex lock
78 : : * @new_frame: valid in the device_run callback: if true, then this
79 : : * starts a new frame; if false, then this is a new slice
80 : : * for an existing frame. This is always true unless
81 : : * V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF is set, which
82 : : * indicates slicing support.
83 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
84 : : * @cap_q_ctx: Capture (output to memory) queue context
85 : : * @out_q_ctx: Output (input from memory) queue context
86 : : * @queue: List of memory to memory contexts
87 : : * @job_flags: Job queue flags, used internally by v4l2-mem2mem.c:
88 : : * %TRANS_QUEUED, %TRANS_RUNNING and %TRANS_ABORT.
89 : : * @finished: Wait queue used to signalize when a job queue finished.
90 : : * @priv: Instance private data
91 : : * @cap_detached: Current job's capture buffer has been detached
92 : : * @det_list: List of detached (post-job but still in flight) capture buffers
93 : : * @det_empty: Wait queue signalled when det_list goes empty
94 : : *
95 : : * The memory to memory context is specific to a file handle, NOT to e.g.
96 : : * a device.
97 : : */
98 : : struct v4l2_m2m_ctx {
99 : : /* optional cap/out vb2 queues lock */
100 : : struct mutex *q_lock;
101 : :
102 : : bool new_frame;
103 : :
104 : : /* internal use only */
105 : : struct v4l2_m2m_dev *m2m_dev;
106 : :
107 : : struct v4l2_m2m_queue_ctx cap_q_ctx;
108 : :
109 : : struct v4l2_m2m_queue_ctx out_q_ctx;
110 : :
111 : : /* For device job queue */
112 : : struct list_head queue;
113 : : unsigned long job_flags;
114 : : wait_queue_head_t finished;
115 : :
116 : : void *priv;
117 : :
118 : : /* Detached buffer handling */
119 : : bool cap_detached;
120 : : struct list_head det_list;
121 : : wait_queue_head_t det_empty;
122 : : };
123 : :
124 : : /**
125 : : * struct v4l2_m2m_buffer - Memory to memory buffer
126 : : *
127 : : * @vb: pointer to struct &vb2_v4l2_buffer
128 : : * @list: list of m2m buffers
129 : : */
130 : : struct v4l2_m2m_buffer {
131 : : struct vb2_v4l2_buffer vb;
132 : : struct list_head list;
133 : : };
134 : :
135 : : /**
136 : : * v4l2_m2m_get_curr_priv() - return driver private data for the currently
137 : : * running instance or NULL if no instance is running
138 : : *
139 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
140 : : */
141 : : void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
142 : :
143 : : /**
144 : : * v4l2_m2m_get_vq() - return vb2_queue for the given type
145 : : *
146 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
147 : : * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
148 : : */
149 : : struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
150 : : enum v4l2_buf_type type);
151 : :
152 : : /**
153 : : * v4l2_m2m_try_schedule() - check whether an instance is ready to be added to
154 : : * the pending job queue and add it if so.
155 : : *
156 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
157 : : *
158 : : * There are three basic requirements an instance has to meet to be able to run:
159 : : * 1) at least one source buffer has to be queued,
160 : : * 2) at least one destination buffer has to be queued,
161 : : * 3) streaming has to be on.
162 : : *
163 : : * If a queue is buffered (for example a decoder hardware ringbuffer that has
164 : : * to be drained before doing streamoff), allow scheduling without v4l2 buffers
165 : : * on that queue.
166 : : *
167 : : * There may also be additional, custom requirements. In such case the driver
168 : : * should supply a custom callback (job_ready in v4l2_m2m_ops) that should
169 : : * return 1 if the instance is ready.
170 : : * An example of the above could be an instance that requires more than one
171 : : * src/dst buffer per transaction.
172 : : */
173 : : void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx);
174 : :
175 : : /**
176 : : * v4l2_m2m_job_finish() - inform the framework that a job has been finished
177 : : * and have it clean up
178 : : *
179 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
180 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
181 : : *
182 : : * Called by a driver to yield back the device after it has finished with it.
183 : : * Should be called as soon as possible after reaching a state which allows
184 : : * other instances to take control of the device.
185 : : *
186 : : * This function has to be called only after &v4l2_m2m_ops->device_run
187 : : * callback has been called on the driver. To prevent recursion, it should
188 : : * not be called directly from the &v4l2_m2m_ops->device_run callback though.
189 : : */
190 : : void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
191 : : struct v4l2_m2m_ctx *m2m_ctx);
192 : :
193 : : /**
194 : : * v4l2_m2m_buf_done_and_job_finish() - return source/destination buffers with
195 : : * state and inform the framework that a job has been finished and have it
196 : : * clean up
197 : : *
198 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
199 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
200 : : * @state: vb2 buffer state passed to v4l2_m2m_buf_done().
201 : : *
202 : : * Drivers that set V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF must use this
203 : : * function instead of job_finish() to take held buffers into account. It is
204 : : * optional for other drivers.
205 : : *
206 : : * This function removes the source buffer from the ready list and returns
207 : : * it with the given state. The same is done for the destination buffer, unless
208 : : * it is marked 'held'. In that case the buffer is kept on the ready list.
209 : : *
210 : : * After that the job is finished (see job_finish()).
211 : : *
212 : : * This allows for multiple output buffers to be used to fill in a single
213 : : * capture buffer. This is typically used by stateless decoders where
214 : : * multiple e.g. H.264 slices contribute to a single decoded frame.
215 : : */
216 : : void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev,
217 : : struct v4l2_m2m_ctx *m2m_ctx,
218 : : enum vb2_buffer_state state);
219 : :
220 : : static inline void
221 : : v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state)
222 : : {
223 : 0 : vb2_buffer_done(&buf->vb2_buf, state);
224 : : }
225 : :
226 : : /**
227 : : * v4l2_m2m_cap_buf_detach() - detach the capture buffer from the job and
228 : : * return it.
229 : : *
230 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
231 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
232 : : *
233 : : * This function is designed to be used in conjunction with
234 : : * v4l2_m2m_buf_done_and_job_finish(). It allows the next job to start
235 : : * execution before the capture buffer is returned to the user which can be
236 : : * important if the underlying processing has multiple phases that are more
237 : : * efficiently executed in parallel.
238 : : *
239 : : * If used then it must be called before v4l2_m2m_buf_done_and_job_finish()
240 : : * as otherwise the buffer will have already gone.
241 : : *
242 : : * It is the callers reponsibilty to ensure that all detached buffers are
243 : : * returned.
244 : : */
245 : : struct vb2_v4l2_buffer *v4l2_m2m_cap_buf_detach(struct v4l2_m2m_dev *m2m_dev,
246 : : struct v4l2_m2m_ctx *m2m_ctx);
247 : :
248 : : /**
249 : : * v4l2_m2m_cap_buf_return() - return a capture buffer, previously detached
250 : : * with v4l2_m2m_cap_buf_detach() to the user.
251 : : *
252 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
253 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
254 : : * @buf: the buffer to return
255 : : * @state: vb2 buffer state passed to v4l2_m2m_buf_done().
256 : : *
257 : : * Buffers returned by this function will be returned to the user in the order
258 : : * of the original jobs rather than the order in which this function is called.
259 : : */
260 : : void v4l2_m2m_cap_buf_return(struct v4l2_m2m_dev *m2m_dev,
261 : : struct v4l2_m2m_ctx *m2m_ctx,
262 : : struct vb2_v4l2_buffer *buf,
263 : : enum vb2_buffer_state state);
264 : :
265 : : /**
266 : : * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer
267 : : *
268 : : * @file: pointer to struct &file
269 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
270 : : * @reqbufs: pointer to struct &v4l2_requestbuffers
271 : : */
272 : : int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
273 : : struct v4l2_requestbuffers *reqbufs);
274 : :
275 : : /**
276 : : * v4l2_m2m_querybuf() - multi-queue-aware QUERYBUF multiplexer
277 : : *
278 : : * @file: pointer to struct &file
279 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
280 : : * @buf: pointer to struct &v4l2_buffer
281 : : *
282 : : * See v4l2_m2m_mmap() documentation for details.
283 : : */
284 : : int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
285 : : struct v4l2_buffer *buf);
286 : :
287 : : /**
288 : : * v4l2_m2m_qbuf() - enqueue a source or destination buffer, depending on
289 : : * the type
290 : : *
291 : : * @file: pointer to struct &file
292 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
293 : : * @buf: pointer to struct &v4l2_buffer
294 : : */
295 : : int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
296 : : struct v4l2_buffer *buf);
297 : :
298 : : /**
299 : : * v4l2_m2m_dqbuf() - dequeue a source or destination buffer, depending on
300 : : * the type
301 : : *
302 : : * @file: pointer to struct &file
303 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
304 : : * @buf: pointer to struct &v4l2_buffer
305 : : */
306 : : int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
307 : : struct v4l2_buffer *buf);
308 : :
309 : : /**
310 : : * v4l2_m2m_prepare_buf() - prepare a source or destination buffer, depending on
311 : : * the type
312 : : *
313 : : * @file: pointer to struct &file
314 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
315 : : * @buf: pointer to struct &v4l2_buffer
316 : : */
317 : : int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
318 : : struct v4l2_buffer *buf);
319 : :
320 : : /**
321 : : * v4l2_m2m_create_bufs() - create a source or destination buffer, depending
322 : : * on the type
323 : : *
324 : : * @file: pointer to struct &file
325 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
326 : : * @create: pointer to struct &v4l2_create_buffers
327 : : */
328 : : int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
329 : : struct v4l2_create_buffers *create);
330 : :
331 : : /**
332 : : * v4l2_m2m_expbuf() - export a source or destination buffer, depending on
333 : : * the type
334 : : *
335 : : * @file: pointer to struct &file
336 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
337 : : * @eb: pointer to struct &v4l2_exportbuffer
338 : : */
339 : : int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
340 : : struct v4l2_exportbuffer *eb);
341 : :
342 : : /**
343 : : * v4l2_m2m_streamon() - turn on streaming for a video queue
344 : : *
345 : : * @file: pointer to struct &file
346 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
347 : : * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
348 : : */
349 : : int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
350 : : enum v4l2_buf_type type);
351 : :
352 : : /**
353 : : * v4l2_m2m_streamoff() - turn off streaming for a video queue
354 : : *
355 : : * @file: pointer to struct &file
356 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
357 : : * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
358 : : */
359 : : int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
360 : : enum v4l2_buf_type type);
361 : :
362 : : /**
363 : : * v4l2_m2m_poll() - poll replacement, for destination buffers only
364 : : *
365 : : * @file: pointer to struct &file
366 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
367 : : * @wait: pointer to struct &poll_table_struct
368 : : *
369 : : * Call from the driver's poll() function. Will poll both queues. If a buffer
370 : : * is available to dequeue (with dqbuf) from the source queue, this will
371 : : * indicate that a non-blocking write can be performed, while read will be
372 : : * returned in case of the destination queue.
373 : : */
374 : : __poll_t v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
375 : : struct poll_table_struct *wait);
376 : :
377 : : /**
378 : : * v4l2_m2m_mmap() - source and destination queues-aware mmap multiplexer
379 : : *
380 : : * @file: pointer to struct &file
381 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
382 : : * @vma: pointer to struct &vm_area_struct
383 : : *
384 : : * Call from driver's mmap() function. Will handle mmap() for both queues
385 : : * seamlessly for videobuffer, which will receive normal per-queue offsets and
386 : : * proper videobuf queue pointers. The differentiation is made outside videobuf
387 : : * by adding a predefined offset to buffers from one of the queues and
388 : : * subtracting it before passing it back to videobuf. Only drivers (and
389 : : * thus applications) receive modified offsets.
390 : : */
391 : : int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
392 : : struct vm_area_struct *vma);
393 : :
394 : : /**
395 : : * v4l2_m2m_init() - initialize per-driver m2m data
396 : : *
397 : : * @m2m_ops: pointer to struct v4l2_m2m_ops
398 : : *
399 : : * Usually called from driver's ``probe()`` function.
400 : : *
401 : : * Return: returns an opaque pointer to the internal data to handle M2M context
402 : : */
403 : : struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops);
404 : :
405 : : #if defined(CONFIG_MEDIA_CONTROLLER)
406 : : void v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev);
407 : : int v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev,
408 : : struct video_device *vdev, int function);
409 : : #else
410 : : static inline void
411 : : v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev)
412 : : {
413 : : }
414 : :
415 : : static inline int
416 : : v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev,
417 : : struct video_device *vdev, int function)
418 : : {
419 : : return 0;
420 : : }
421 : : #endif
422 : :
423 : : /**
424 : : * v4l2_m2m_release() - cleans up and frees a m2m_dev structure
425 : : *
426 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
427 : : *
428 : : * Usually called from driver's ``remove()`` function.
429 : : */
430 : : void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev);
431 : :
432 : : /**
433 : : * v4l2_m2m_ctx_init() - allocate and initialize a m2m context
434 : : *
435 : : * @m2m_dev: opaque pointer to the internal data to handle M2M context
436 : : * @drv_priv: driver's instance private data
437 : : * @queue_init: a callback for queue type-specific initialization function
438 : : * to be used for initializing videobuf_queues
439 : : *
440 : : * Usually called from driver's ``open()`` function.
441 : : */
442 : : struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
443 : : void *drv_priv,
444 : : int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq));
445 : :
446 : : static inline void v4l2_m2m_set_src_buffered(struct v4l2_m2m_ctx *m2m_ctx,
447 : : bool buffered)
448 : : {
449 : 3 : m2m_ctx->out_q_ctx.buffered = buffered;
450 : : }
451 : :
452 : : static inline void v4l2_m2m_set_dst_buffered(struct v4l2_m2m_ctx *m2m_ctx,
453 : : bool buffered)
454 : : {
455 : 3 : m2m_ctx->cap_q_ctx.buffered = buffered;
456 : : }
457 : :
458 : : /**
459 : : * v4l2_m2m_ctx_release() - release m2m context
460 : : *
461 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
462 : : *
463 : : * Usually called from driver's release() function.
464 : : */
465 : : void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx);
466 : :
467 : : /**
468 : : * v4l2_m2m_buf_queue() - add a buffer to the proper ready buffers list.
469 : : *
470 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
471 : : * @vbuf: pointer to struct &vb2_v4l2_buffer
472 : : *
473 : : * Call from videobuf_queue_ops->ops->buf_queue, videobuf_queue_ops callback.
474 : : */
475 : : void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx,
476 : : struct vb2_v4l2_buffer *vbuf);
477 : :
478 : : /**
479 : : * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for
480 : : * use
481 : : *
482 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
483 : : */
484 : : static inline
485 : : unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
486 : : {
487 : 0 : return m2m_ctx->out_q_ctx.num_rdy;
488 : : }
489 : :
490 : : /**
491 : : * v4l2_m2m_num_dst_bufs_ready() - return the number of destination buffers
492 : : * ready for use
493 : : *
494 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
495 : : */
496 : : static inline
497 : : unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
498 : : {
499 : 0 : return m2m_ctx->cap_q_ctx.num_rdy;
500 : : }
501 : :
502 : : /**
503 : : * v4l2_m2m_next_buf() - return next buffer from the list of ready buffers
504 : : *
505 : : * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
506 : : */
507 : : struct vb2_v4l2_buffer *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx);
508 : :
509 : : /**
510 : : * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready
511 : : * buffers
512 : : *
513 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
514 : : */
515 : : static inline struct vb2_v4l2_buffer *
516 : : v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx)
517 : : {
518 : 0 : return v4l2_m2m_next_buf(&m2m_ctx->out_q_ctx);
519 : : }
520 : :
521 : : /**
522 : : * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of
523 : : * ready buffers
524 : : *
525 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
526 : : */
527 : : static inline struct vb2_v4l2_buffer *
528 : : v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx)
529 : : {
530 : 0 : return v4l2_m2m_next_buf(&m2m_ctx->cap_q_ctx);
531 : : }
532 : :
533 : : /**
534 : : * v4l2_m2m_last_buf() - return last buffer from the list of ready buffers
535 : : *
536 : : * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
537 : : */
538 : : struct vb2_v4l2_buffer *v4l2_m2m_last_buf(struct v4l2_m2m_queue_ctx *q_ctx);
539 : :
540 : : /**
541 : : * v4l2_m2m_last_src_buf() - return last destination buffer from the list of
542 : : * ready buffers
543 : : *
544 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
545 : : */
546 : : static inline struct vb2_v4l2_buffer *
547 : : v4l2_m2m_last_src_buf(struct v4l2_m2m_ctx *m2m_ctx)
548 : : {
549 : 0 : return v4l2_m2m_last_buf(&m2m_ctx->out_q_ctx);
550 : : }
551 : :
552 : : /**
553 : : * v4l2_m2m_last_dst_buf() - return last destination buffer from the list of
554 : : * ready buffers
555 : : *
556 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
557 : : */
558 : : static inline struct vb2_v4l2_buffer *
559 : : v4l2_m2m_last_dst_buf(struct v4l2_m2m_ctx *m2m_ctx)
560 : : {
561 : 0 : return v4l2_m2m_last_buf(&m2m_ctx->cap_q_ctx);
562 : : }
563 : :
564 : : /**
565 : : * v4l2_m2m_for_each_dst_buf() - iterate over a list of destination ready
566 : : * buffers
567 : : *
568 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
569 : : * @b: current buffer of type struct v4l2_m2m_buffer
570 : : */
571 : : #define v4l2_m2m_for_each_dst_buf(m2m_ctx, b) \
572 : : list_for_each_entry(b, &m2m_ctx->cap_q_ctx.rdy_queue, list)
573 : :
574 : : /**
575 : : * v4l2_m2m_for_each_src_buf() - iterate over a list of source ready buffers
576 : : *
577 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
578 : : * @b: current buffer of type struct v4l2_m2m_buffer
579 : : */
580 : : #define v4l2_m2m_for_each_src_buf(m2m_ctx, b) \
581 : : list_for_each_entry(b, &m2m_ctx->out_q_ctx.rdy_queue, list)
582 : :
583 : : /**
584 : : * v4l2_m2m_for_each_dst_buf_safe() - iterate over a list of destination ready
585 : : * buffers safely
586 : : *
587 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
588 : : * @b: current buffer of type struct v4l2_m2m_buffer
589 : : * @n: used as temporary storage
590 : : */
591 : : #define v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, b, n) \
592 : : list_for_each_entry_safe(b, n, &m2m_ctx->cap_q_ctx.rdy_queue, list)
593 : :
594 : : /**
595 : : * v4l2_m2m_for_each_src_buf_safe() - iterate over a list of source ready
596 : : * buffers safely
597 : : *
598 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
599 : : * @b: current buffer of type struct v4l2_m2m_buffer
600 : : * @n: used as temporary storage
601 : : */
602 : : #define v4l2_m2m_for_each_src_buf_safe(m2m_ctx, b, n) \
603 : : list_for_each_entry_safe(b, n, &m2m_ctx->out_q_ctx.rdy_queue, list)
604 : :
605 : : /**
606 : : * v4l2_m2m_get_src_vq() - return vb2_queue for source buffers
607 : : *
608 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
609 : : */
610 : : static inline
611 : : struct vb2_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx)
612 : : {
613 : 0 : return &m2m_ctx->out_q_ctx.q;
614 : : }
615 : :
616 : : /**
617 : : * v4l2_m2m_get_dst_vq() - return vb2_queue for destination buffers
618 : : *
619 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
620 : : */
621 : : static inline
622 : : struct vb2_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx)
623 : : {
624 : 0 : return &m2m_ctx->cap_q_ctx.q;
625 : : }
626 : :
627 : : /**
628 : : * v4l2_m2m_buf_remove() - take off a buffer from the list of ready buffers and
629 : : * return it
630 : : *
631 : : * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
632 : : */
633 : : struct vb2_v4l2_buffer *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx);
634 : :
635 : : /**
636 : : * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready
637 : : * buffers and return it
638 : : *
639 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
640 : : */
641 : : static inline struct vb2_v4l2_buffer *
642 : : v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
643 : : {
644 : 0 : return v4l2_m2m_buf_remove(&m2m_ctx->out_q_ctx);
645 : : }
646 : :
647 : : /**
648 : : * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of
649 : : * ready buffers and return it
650 : : *
651 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
652 : : */
653 : : static inline struct vb2_v4l2_buffer *
654 : : v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
655 : : {
656 : 0 : return v4l2_m2m_buf_remove(&m2m_ctx->cap_q_ctx);
657 : : }
658 : :
659 : : /**
660 : : * v4l2_m2m_buf_remove_by_buf() - take off exact buffer from the list of ready
661 : : * buffers
662 : : *
663 : : * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
664 : : * @vbuf: the buffer to be removed
665 : : */
666 : : void v4l2_m2m_buf_remove_by_buf(struct v4l2_m2m_queue_ctx *q_ctx,
667 : : struct vb2_v4l2_buffer *vbuf);
668 : :
669 : : /**
670 : : * v4l2_m2m_src_buf_remove_by_buf() - take off exact source buffer from the list
671 : : * of ready buffers
672 : : *
673 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
674 : : * @vbuf: the buffer to be removed
675 : : */
676 : : static inline void v4l2_m2m_src_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx,
677 : : struct vb2_v4l2_buffer *vbuf)
678 : : {
679 : : v4l2_m2m_buf_remove_by_buf(&m2m_ctx->out_q_ctx, vbuf);
680 : : }
681 : :
682 : : /**
683 : : * v4l2_m2m_dst_buf_remove_by_buf() - take off exact destination buffer from the
684 : : * list of ready buffers
685 : : *
686 : : * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
687 : : * @vbuf: the buffer to be removed
688 : : */
689 : : static inline void v4l2_m2m_dst_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx,
690 : : struct vb2_v4l2_buffer *vbuf)
691 : : {
692 : : v4l2_m2m_buf_remove_by_buf(&m2m_ctx->cap_q_ctx, vbuf);
693 : : }
694 : :
695 : : struct vb2_v4l2_buffer *
696 : : v4l2_m2m_buf_remove_by_idx(struct v4l2_m2m_queue_ctx *q_ctx, unsigned int idx);
697 : :
698 : : static inline struct vb2_v4l2_buffer *
699 : : v4l2_m2m_src_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx)
700 : : {
701 : : return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->out_q_ctx, idx);
702 : : }
703 : :
704 : : static inline struct vb2_v4l2_buffer *
705 : : v4l2_m2m_dst_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx)
706 : : {
707 : : return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->cap_q_ctx, idx);
708 : : }
709 : :
710 : : /**
711 : : * v4l2_m2m_buf_copy_metadata() - copy buffer metadata from
712 : : * the output buffer to the capture buffer
713 : : *
714 : : * @out_vb: the output buffer that is the source of the metadata.
715 : : * @cap_vb: the capture buffer that will receive the metadata.
716 : : * @copy_frame_flags: copy the KEY/B/PFRAME flags as well.
717 : : *
718 : : * This helper function copies the timestamp, timecode (if the TIMECODE
719 : : * buffer flag was set), field and the TIMECODE, KEYFRAME, BFRAME, PFRAME
720 : : * and TSTAMP_SRC_MASK flags from @out_vb to @cap_vb.
721 : : *
722 : : * If @copy_frame_flags is false, then the KEYFRAME, BFRAME and PFRAME
723 : : * flags are not copied. This is typically needed for encoders that
724 : : * set this bits explicitly.
725 : : */
726 : : void v4l2_m2m_buf_copy_metadata(const struct vb2_v4l2_buffer *out_vb,
727 : : struct vb2_v4l2_buffer *cap_vb,
728 : : bool copy_frame_flags);
729 : :
730 : : /* v4l2 request helper */
731 : :
732 : : void v4l2_m2m_request_queue(struct media_request *req);
733 : :
734 : : /* v4l2 ioctl helpers */
735 : :
736 : : int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv,
737 : : struct v4l2_requestbuffers *rb);
738 : : int v4l2_m2m_ioctl_create_bufs(struct file *file, void *fh,
739 : : struct v4l2_create_buffers *create);
740 : : int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh,
741 : : struct v4l2_buffer *buf);
742 : : int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh,
743 : : struct v4l2_exportbuffer *eb);
744 : : int v4l2_m2m_ioctl_qbuf(struct file *file, void *fh,
745 : : struct v4l2_buffer *buf);
746 : : int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh,
747 : : struct v4l2_buffer *buf);
748 : : int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *fh,
749 : : struct v4l2_buffer *buf);
750 : : int v4l2_m2m_ioctl_streamon(struct file *file, void *fh,
751 : : enum v4l2_buf_type type);
752 : : int v4l2_m2m_ioctl_streamoff(struct file *file, void *fh,
753 : : enum v4l2_buf_type type);
754 : : int v4l2_m2m_ioctl_try_encoder_cmd(struct file *file, void *fh,
755 : : struct v4l2_encoder_cmd *ec);
756 : : int v4l2_m2m_ioctl_try_decoder_cmd(struct file *file, void *fh,
757 : : struct v4l2_decoder_cmd *dc);
758 : : int v4l2_m2m_ioctl_stateless_try_decoder_cmd(struct file *file, void *fh,
759 : : struct v4l2_decoder_cmd *dc);
760 : : int v4l2_m2m_ioctl_stateless_decoder_cmd(struct file *file, void *priv,
761 : : struct v4l2_decoder_cmd *dc);
762 : : int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma);
763 : : __poll_t v4l2_m2m_fop_poll(struct file *file, poll_table *wait);
764 : :
765 : : #endif /* _MEDIA_V4L2_MEM2MEM_H */
766 : :
|