Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 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. |
Pawel Osciak | 9507208 | 2011-03-13 15:23:32 -0300 | [diff] [blame] | 9 | * Pawel Osciak, <pawel@osciak.com> |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 10 | * Marek Szyprowski, <m.szyprowski@samsung.com> |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef _MEDIA_V4L2_MEM2MEM_H |
| 14 | #define _MEDIA_V4L2_MEM2MEM_H |
| 15 | |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 16 | #include <media/videobuf2-v4l2.h> |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 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, |
Hans Verkuil | f8cca8c | 2019-10-11 06:32:41 -0300 | [diff] [blame] | 24 | * v4l2_m2m_job_finish() or v4l2_m2m_buf_done_and_job_finish() |
| 25 | * has to be called. |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 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. |
Ezequiel Garcia | 5525b83 | 2018-06-18 00:38:52 -0400 | [diff] [blame] | 32 | * @job_abort: optional. Informs the driver that it has to abort the currently |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 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 |
Hans Verkuil | f8cca8c | 2019-10-11 06:32:41 -0300 | [diff] [blame] | 37 | * v4l2_m2m_job_finish() or v4l2_m2m_buf_done_and_job_finish() as |
| 38 | * if the transaction ended normally. |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 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 | |
Ezequiel Garcia | be2fff6 | 2018-07-02 11:36:05 -0400 | [diff] [blame] | 48 | struct video_device; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 49 | struct v4l2_m2m_dev; |
| 50 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 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 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 65 | struct v4l2_m2m_queue_ctx { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 66 | struct vb2_queue q; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 67 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 68 | struct list_head rdy_queue; |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 69 | spinlock_t rdy_spinlock; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 70 | u8 num_rdy; |
Philipp Zabel | 33bdd5a | 2013-06-03 04:23:48 -0300 | [diff] [blame] | 71 | bool buffered; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 72 | }; |
| 73 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 74 | /** |
| 75 | * struct v4l2_m2m_ctx - Memory to memory context structure |
| 76 | * |
| 77 | * @q_lock: struct &mutex lock |
Hans Verkuil | f07602a | 2019-10-11 06:32:44 -0300 | [diff] [blame] | 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. |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 83 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 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 |
Sakari Ailus | 708f48e | 2016-10-18 11:15:32 -0200 | [diff] [blame] | 91 | * |
| 92 | * The memory to memory context is specific to a file handle, NOT to e.g. |
| 93 | * a device. |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 94 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 95 | struct v4l2_m2m_ctx { |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 96 | /* optional cap/out vb2 queues lock */ |
| 97 | struct mutex *q_lock; |
| 98 | |
Hans Verkuil | f07602a | 2019-10-11 06:32:44 -0300 | [diff] [blame] | 99 | bool new_frame; |
| 100 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 101 | /* internal use only */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 102 | struct v4l2_m2m_dev *m2m_dev; |
| 103 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 104 | struct v4l2_m2m_queue_ctx cap_q_ctx; |
| 105 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 106 | struct v4l2_m2m_queue_ctx out_q_ctx; |
| 107 | |
| 108 | /* For device job queue */ |
| 109 | struct list_head queue; |
| 110 | unsigned long job_flags; |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 111 | wait_queue_head_t finished; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 112 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 113 | void *priv; |
| 114 | }; |
| 115 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 116 | /** |
| 117 | * struct v4l2_m2m_buffer - Memory to memory buffer |
| 118 | * |
| 119 | * @vb: pointer to struct &vb2_v4l2_buffer |
| 120 | * @list: list of m2m buffers |
| 121 | */ |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 122 | struct v4l2_m2m_buffer { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 123 | struct vb2_v4l2_buffer vb; |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 124 | struct list_head list; |
| 125 | }; |
| 126 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 127 | /** |
| 128 | * v4l2_m2m_get_curr_priv() - return driver private data for the currently |
| 129 | * running instance or NULL if no instance is running |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 130 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 131 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 132 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 133 | void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev); |
| 134 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 135 | /** |
| 136 | * v4l2_m2m_get_vq() - return vb2_queue for the given type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 137 | * |
| 138 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 139 | * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 140 | */ |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 141 | struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx, |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 142 | enum v4l2_buf_type type); |
| 143 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 144 | /** |
| 145 | * v4l2_m2m_try_schedule() - check whether an instance is ready to be added to |
| 146 | * the pending job queue and add it if so. |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 147 | * |
| 148 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 149 | * |
| 150 | * There are three basic requirements an instance has to meet to be able to run: |
| 151 | * 1) at least one source buffer has to be queued, |
| 152 | * 2) at least one destination buffer has to be queued, |
| 153 | * 3) streaming has to be on. |
| 154 | * |
| 155 | * If a queue is buffered (for example a decoder hardware ringbuffer that has |
| 156 | * to be drained before doing streamoff), allow scheduling without v4l2 buffers |
| 157 | * on that queue. |
| 158 | * |
| 159 | * There may also be additional, custom requirements. In such case the driver |
| 160 | * should supply a custom callback (job_ready in v4l2_m2m_ops) that should |
| 161 | * return 1 if the instance is ready. |
| 162 | * An example of the above could be an instance that requires more than one |
| 163 | * src/dst buffer per transaction. |
| 164 | */ |
Michael Olbrich | 1190a41 | 2014-07-22 09:36:04 -0300 | [diff] [blame] | 165 | void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx); |
| 166 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 167 | /** |
| 168 | * v4l2_m2m_job_finish() - inform the framework that a job has been finished |
| 169 | * and have it clean up |
| 170 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 171 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 172 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 173 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 174 | * Called by a driver to yield back the device after it has finished with it. |
| 175 | * Should be called as soon as possible after reaching a state which allows |
| 176 | * other instances to take control of the device. |
| 177 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 178 | * This function has to be called only after &v4l2_m2m_ops->device_run |
| 179 | * callback has been called on the driver. To prevent recursion, it should |
| 180 | * not be called directly from the &v4l2_m2m_ops->device_run callback though. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 181 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 182 | void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev, |
| 183 | struct v4l2_m2m_ctx *m2m_ctx); |
| 184 | |
Hans Verkuil | f8cca8c | 2019-10-11 06:32:41 -0300 | [diff] [blame] | 185 | /** |
| 186 | * v4l2_m2m_buf_done_and_job_finish() - return source/destination buffers with |
| 187 | * state and inform the framework that a job has been finished and have it |
| 188 | * clean up |
| 189 | * |
| 190 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
| 191 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 192 | * @state: vb2 buffer state passed to v4l2_m2m_buf_done(). |
| 193 | * |
| 194 | * Drivers that set V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF must use this |
| 195 | * function instead of job_finish() to take held buffers into account. It is |
| 196 | * optional for other drivers. |
| 197 | * |
| 198 | * This function removes the source buffer from the ready list and returns |
| 199 | * it with the given state. The same is done for the destination buffer, unless |
| 200 | * it is marked 'held'. In that case the buffer is kept on the ready list. |
| 201 | * |
| 202 | * After that the job is finished (see job_finish()). |
| 203 | * |
| 204 | * This allows for multiple output buffers to be used to fill in a single |
| 205 | * capture buffer. This is typically used by stateless decoders where |
| 206 | * multiple e.g. H.264 slices contribute to a single decoded frame. |
| 207 | */ |
| 208 | void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev, |
| 209 | struct v4l2_m2m_ctx *m2m_ctx, |
| 210 | enum vb2_buffer_state state); |
| 211 | |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 212 | static inline void |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 213 | v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state) |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 214 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 215 | vb2_buffer_done(&buf->vb2_buf, state); |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 216 | } |
| 217 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 218 | /** |
| 219 | * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 220 | * |
| 221 | * @file: pointer to struct &file |
| 222 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 223 | * @reqbufs: pointer to struct &v4l2_requestbuffers |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 224 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 225 | int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 226 | struct v4l2_requestbuffers *reqbufs); |
| 227 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 228 | /** |
| 229 | * v4l2_m2m_querybuf() - multi-queue-aware QUERYBUF multiplexer |
| 230 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 231 | * @file: pointer to struct &file |
| 232 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 233 | * @buf: pointer to struct &v4l2_buffer |
| 234 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 235 | * See v4l2_m2m_mmap() documentation for details. |
| 236 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 237 | int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 238 | struct v4l2_buffer *buf); |
| 239 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 240 | /** |
| 241 | * v4l2_m2m_qbuf() - enqueue a source or destination buffer, depending on |
| 242 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 243 | * |
| 244 | * @file: pointer to struct &file |
| 245 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 246 | * @buf: pointer to struct &v4l2_buffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 247 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 248 | int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 249 | struct v4l2_buffer *buf); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 250 | |
| 251 | /** |
| 252 | * v4l2_m2m_dqbuf() - dequeue a source or destination buffer, depending on |
| 253 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 254 | * |
| 255 | * @file: pointer to struct &file |
| 256 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 257 | * @buf: pointer to struct &v4l2_buffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 258 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 259 | int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 260 | struct v4l2_buffer *buf); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 261 | |
| 262 | /** |
| 263 | * v4l2_m2m_prepare_buf() - prepare a source or destination buffer, depending on |
| 264 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 265 | * |
| 266 | * @file: pointer to struct &file |
| 267 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 268 | * @buf: pointer to struct &v4l2_buffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 269 | */ |
Hans Verkuil | e68cf47 | 2015-06-05 11:28:50 -0300 | [diff] [blame] | 270 | int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 271 | struct v4l2_buffer *buf); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * v4l2_m2m_create_bufs() - create a source or destination buffer, depending |
| 275 | * on the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 276 | * |
| 277 | * @file: pointer to struct &file |
| 278 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 279 | * @create: pointer to struct &v4l2_create_buffers |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 280 | */ |
Philipp Zabel | 8b94ca6 | 2013-05-21 04:16:28 -0300 | [diff] [blame] | 281 | int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 282 | struct v4l2_create_buffers *create); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 283 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 284 | /** |
| 285 | * v4l2_m2m_expbuf() - export a source or destination buffer, depending on |
| 286 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 287 | * |
| 288 | * @file: pointer to struct &file |
| 289 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 290 | * @eb: pointer to struct &v4l2_exportbuffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 291 | */ |
Tomasz Stanislawski | 83ae7c5 | 2012-06-14 11:32:24 -0300 | [diff] [blame] | 292 | int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 293 | struct v4l2_exportbuffer *eb); |
| 294 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 295 | /** |
| 296 | * v4l2_m2m_streamon() - turn on streaming for a video queue |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 297 | * |
| 298 | * @file: pointer to struct &file |
| 299 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 300 | * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 301 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 302 | int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 303 | enum v4l2_buf_type type); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * v4l2_m2m_streamoff() - turn off streaming for a video queue |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 307 | * |
| 308 | * @file: pointer to struct &file |
| 309 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 310 | * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 311 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 312 | int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 313 | enum v4l2_buf_type type); |
| 314 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 315 | /** |
| 316 | * v4l2_m2m_poll() - poll replacement, for destination buffers only |
| 317 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 318 | * @file: pointer to struct &file |
| 319 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 320 | * @wait: pointer to struct &poll_table_struct |
| 321 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 322 | * Call from the driver's poll() function. Will poll both queues. If a buffer |
| 323 | * is available to dequeue (with dqbuf) from the source queue, this will |
| 324 | * indicate that a non-blocking write can be performed, while read will be |
| 325 | * returned in case of the destination queue. |
| 326 | */ |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 327 | __poll_t v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 328 | struct poll_table_struct *wait); |
| 329 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 330 | /** |
| 331 | * v4l2_m2m_mmap() - source and destination queues-aware mmap multiplexer |
| 332 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 333 | * @file: pointer to struct &file |
| 334 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 335 | * @vma: pointer to struct &vm_area_struct |
| 336 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 337 | * Call from driver's mmap() function. Will handle mmap() for both queues |
| 338 | * seamlessly for videobuffer, which will receive normal per-queue offsets and |
| 339 | * proper videobuf queue pointers. The differentiation is made outside videobuf |
| 340 | * by adding a predefined offset to buffers from one of the queues and |
| 341 | * subtracting it before passing it back to videobuf. Only drivers (and |
| 342 | * thus applications) receive modified offsets. |
| 343 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 344 | int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 345 | struct vm_area_struct *vma); |
| 346 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 347 | /** |
| 348 | * v4l2_m2m_init() - initialize per-driver m2m data |
| 349 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 350 | * @m2m_ops: pointer to struct v4l2_m2m_ops |
| 351 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 352 | * Usually called from driver's ``probe()`` function. |
| 353 | * |
| 354 | * Return: returns an opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 355 | */ |
Guennadi Liakhovetski | b1252eb | 2012-09-11 06:32:17 -0300 | [diff] [blame] | 356 | struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 357 | |
Ezequiel Garcia | be2fff6 | 2018-07-02 11:36:05 -0400 | [diff] [blame] | 358 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 359 | void v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev); |
| 360 | int v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev, |
| 361 | struct video_device *vdev, int function); |
| 362 | #else |
| 363 | static inline void |
| 364 | v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev) |
| 365 | { |
| 366 | } |
| 367 | |
| 368 | static inline int |
| 369 | v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev, |
| 370 | struct video_device *vdev, int function) |
| 371 | { |
| 372 | return 0; |
| 373 | } |
| 374 | #endif |
| 375 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 376 | /** |
| 377 | * v4l2_m2m_release() - cleans up and frees a m2m_dev structure |
| 378 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 379 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 380 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 381 | * Usually called from driver's ``remove()`` function. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 382 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 383 | void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev); |
| 384 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 385 | /** |
| 386 | * v4l2_m2m_ctx_init() - allocate and initialize a m2m context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 387 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 388 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 389 | * @drv_priv: driver's instance private data |
| 390 | * @queue_init: a callback for queue type-specific initialization function |
| 391 | * to be used for initializing videobuf_queues |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 392 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 393 | * Usually called from driver's ``open()`` function. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 394 | */ |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 395 | struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev, |
| 396 | void *drv_priv, |
| 397 | int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)); |
| 398 | |
Philipp Zabel | 33bdd5a | 2013-06-03 04:23:48 -0300 | [diff] [blame] | 399 | static inline void v4l2_m2m_set_src_buffered(struct v4l2_m2m_ctx *m2m_ctx, |
| 400 | bool buffered) |
| 401 | { |
| 402 | m2m_ctx->out_q_ctx.buffered = buffered; |
| 403 | } |
| 404 | |
| 405 | static inline void v4l2_m2m_set_dst_buffered(struct v4l2_m2m_ctx *m2m_ctx, |
| 406 | bool buffered) |
| 407 | { |
| 408 | m2m_ctx->cap_q_ctx.buffered = buffered; |
| 409 | } |
| 410 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 411 | /** |
| 412 | * v4l2_m2m_ctx_release() - release m2m context |
| 413 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 414 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 415 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 416 | * Usually called from driver's release() function. |
| 417 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 418 | void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx); |
| 419 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 420 | /** |
| 421 | * v4l2_m2m_buf_queue() - add a buffer to the proper ready buffers list. |
| 422 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 423 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 424 | * @vbuf: pointer to struct &vb2_v4l2_buffer |
| 425 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 426 | * Call from videobuf_queue_ops->ops->buf_queue, videobuf_queue_ops callback. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 427 | */ |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 428 | void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, |
| 429 | struct vb2_v4l2_buffer *vbuf); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 430 | |
| 431 | /** |
| 432 | * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for |
| 433 | * use |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 434 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 435 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 436 | */ |
| 437 | static inline |
| 438 | unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) |
| 439 | { |
Sascha Hauer | 961ae44 | 2012-08-31 09:18:04 -0300 | [diff] [blame] | 440 | return m2m_ctx->out_q_ctx.num_rdy; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 444 | * v4l2_m2m_num_dst_bufs_ready() - return the number of destination buffers |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 445 | * ready for use |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 446 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 447 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 448 | */ |
| 449 | static inline |
| 450 | unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) |
| 451 | { |
Sascha Hauer | 961ae44 | 2012-08-31 09:18:04 -0300 | [diff] [blame] | 452 | return m2m_ctx->cap_q_ctx.num_rdy; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 453 | } |
| 454 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 455 | /** |
| 456 | * v4l2_m2m_next_buf() - return next buffer from the list of ready buffers |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 457 | * |
| 458 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 459 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 460 | struct vb2_v4l2_buffer *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 461 | |
| 462 | /** |
| 463 | * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready |
| 464 | * buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 465 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 466 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 467 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 468 | static inline struct vb2_v4l2_buffer * |
| 469 | v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 470 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 471 | return v4l2_m2m_next_buf(&m2m_ctx->out_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
| 475 | * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of |
| 476 | * ready buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 477 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 478 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 479 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 480 | static inline struct vb2_v4l2_buffer * |
| 481 | v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 482 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 483 | return v4l2_m2m_next_buf(&m2m_ctx->cap_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 487 | * v4l2_m2m_last_buf() - return last buffer from the list of ready buffers |
| 488 | * |
| 489 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
| 490 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 491 | struct vb2_v4l2_buffer *v4l2_m2m_last_buf(struct v4l2_m2m_queue_ctx *q_ctx); |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 492 | |
| 493 | /** |
| 494 | * v4l2_m2m_last_src_buf() - return last destination buffer from the list of |
| 495 | * ready buffers |
| 496 | * |
| 497 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 498 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 499 | static inline struct vb2_v4l2_buffer * |
| 500 | v4l2_m2m_last_src_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 501 | { |
| 502 | return v4l2_m2m_last_buf(&m2m_ctx->out_q_ctx); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * v4l2_m2m_last_dst_buf() - return last destination buffer from the list of |
| 507 | * ready buffers |
| 508 | * |
| 509 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 510 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 511 | static inline struct vb2_v4l2_buffer * |
| 512 | v4l2_m2m_last_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 513 | { |
| 514 | return v4l2_m2m_last_buf(&m2m_ctx->cap_q_ctx); |
| 515 | } |
| 516 | |
| 517 | /** |
Stanimir Varbanov | d498756 | 2017-06-15 13:31:42 -0300 | [diff] [blame] | 518 | * v4l2_m2m_for_each_dst_buf() - iterate over a list of destination ready |
| 519 | * buffers |
| 520 | * |
| 521 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 522 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 523 | */ |
| 524 | #define v4l2_m2m_for_each_dst_buf(m2m_ctx, b) \ |
| 525 | list_for_each_entry(b, &m2m_ctx->cap_q_ctx.rdy_queue, list) |
| 526 | |
| 527 | /** |
| 528 | * v4l2_m2m_for_each_src_buf() - iterate over a list of source ready buffers |
| 529 | * |
| 530 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 531 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 532 | */ |
| 533 | #define v4l2_m2m_for_each_src_buf(m2m_ctx, b) \ |
| 534 | list_for_each_entry(b, &m2m_ctx->out_q_ctx.rdy_queue, list) |
| 535 | |
| 536 | /** |
| 537 | * v4l2_m2m_for_each_dst_buf_safe() - iterate over a list of destination ready |
| 538 | * buffers safely |
| 539 | * |
| 540 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 541 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 542 | * @n: used as temporary storage |
| 543 | */ |
| 544 | #define v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, b, n) \ |
| 545 | list_for_each_entry_safe(b, n, &m2m_ctx->cap_q_ctx.rdy_queue, list) |
| 546 | |
| 547 | /** |
| 548 | * v4l2_m2m_for_each_src_buf_safe() - iterate over a list of source ready |
| 549 | * buffers safely |
| 550 | * |
| 551 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 552 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 553 | * @n: used as temporary storage |
| 554 | */ |
| 555 | #define v4l2_m2m_for_each_src_buf_safe(m2m_ctx, b, n) \ |
| 556 | list_for_each_entry_safe(b, n, &m2m_ctx->out_q_ctx.rdy_queue, list) |
| 557 | |
| 558 | /** |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 559 | * v4l2_m2m_get_src_vq() - return vb2_queue for source buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 560 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 561 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 562 | */ |
| 563 | static inline |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 564 | struct vb2_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 565 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 566 | return &m2m_ctx->out_q_ctx.q; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /** |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 570 | * v4l2_m2m_get_dst_vq() - return vb2_queue for destination buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 571 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 572 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 573 | */ |
| 574 | static inline |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 575 | struct vb2_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 576 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 577 | return &m2m_ctx->cap_q_ctx.q; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 578 | } |
| 579 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 580 | /** |
| 581 | * v4l2_m2m_buf_remove() - take off a buffer from the list of ready buffers and |
| 582 | * return it |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 583 | * |
| 584 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 585 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 586 | struct vb2_v4l2_buffer *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 587 | |
| 588 | /** |
| 589 | * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready |
| 590 | * buffers and return it |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 591 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 592 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 593 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 594 | static inline struct vb2_v4l2_buffer * |
| 595 | v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 596 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 597 | return v4l2_m2m_buf_remove(&m2m_ctx->out_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /** |
| 601 | * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of |
| 602 | * ready buffers and return it |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 603 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 604 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 605 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame] | 606 | static inline struct vb2_v4l2_buffer * |
| 607 | v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 608 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 609 | return v4l2_m2m_buf_remove(&m2m_ctx->cap_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 610 | } |
| 611 | |
Stanimir Varbanov | d498756 | 2017-06-15 13:31:42 -0300 | [diff] [blame] | 612 | /** |
| 613 | * v4l2_m2m_buf_remove_by_buf() - take off exact buffer from the list of ready |
| 614 | * buffers |
| 615 | * |
| 616 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
| 617 | * @vbuf: the buffer to be removed |
| 618 | */ |
| 619 | void v4l2_m2m_buf_remove_by_buf(struct v4l2_m2m_queue_ctx *q_ctx, |
| 620 | struct vb2_v4l2_buffer *vbuf); |
| 621 | |
| 622 | /** |
| 623 | * v4l2_m2m_src_buf_remove_by_buf() - take off exact source buffer from the list |
| 624 | * of ready buffers |
| 625 | * |
| 626 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 627 | * @vbuf: the buffer to be removed |
| 628 | */ |
| 629 | static inline void v4l2_m2m_src_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx, |
| 630 | struct vb2_v4l2_buffer *vbuf) |
| 631 | { |
| 632 | v4l2_m2m_buf_remove_by_buf(&m2m_ctx->out_q_ctx, vbuf); |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * v4l2_m2m_dst_buf_remove_by_buf() - take off exact destination buffer from the |
| 637 | * list of ready buffers |
| 638 | * |
| 639 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 640 | * @vbuf: the buffer to be removed |
| 641 | */ |
| 642 | static inline void v4l2_m2m_dst_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx, |
| 643 | struct vb2_v4l2_buffer *vbuf) |
| 644 | { |
| 645 | v4l2_m2m_buf_remove_by_buf(&m2m_ctx->cap_q_ctx, vbuf); |
| 646 | } |
| 647 | |
| 648 | struct vb2_v4l2_buffer * |
| 649 | v4l2_m2m_buf_remove_by_idx(struct v4l2_m2m_queue_ctx *q_ctx, unsigned int idx); |
| 650 | |
| 651 | static inline struct vb2_v4l2_buffer * |
| 652 | v4l2_m2m_src_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) |
| 653 | { |
| 654 | return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->out_q_ctx, idx); |
| 655 | } |
| 656 | |
| 657 | static inline struct vb2_v4l2_buffer * |
| 658 | v4l2_m2m_dst_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) |
| 659 | { |
| 660 | return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->cap_q_ctx, idx); |
| 661 | } |
| 662 | |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 663 | /** |
Ezequiel Garcia | a4d3d61 | 2019-02-05 16:20:33 -0500 | [diff] [blame] | 664 | * v4l2_m2m_buf_copy_metadata() - copy buffer metadata from |
| 665 | * the output buffer to the capture buffer |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 666 | * |
Ezequiel Garcia | a4d3d61 | 2019-02-05 16:20:33 -0500 | [diff] [blame] | 667 | * @out_vb: the output buffer that is the source of the metadata. |
| 668 | * @cap_vb: the capture buffer that will receive the metadata. |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 669 | * @copy_frame_flags: copy the KEY/B/PFRAME flags as well. |
| 670 | * |
| 671 | * This helper function copies the timestamp, timecode (if the TIMECODE |
| 672 | * buffer flag was set), field and the TIMECODE, KEYFRAME, BFRAME, PFRAME |
| 673 | * and TSTAMP_SRC_MASK flags from @out_vb to @cap_vb. |
| 674 | * |
| 675 | * If @copy_frame_flags is false, then the KEYFRAME, BFRAME and PFRAME |
| 676 | * flags are not copied. This is typically needed for encoders that |
| 677 | * set this bits explicitly. |
| 678 | */ |
Ezequiel Garcia | a4d3d61 | 2019-02-05 16:20:33 -0500 | [diff] [blame] | 679 | void v4l2_m2m_buf_copy_metadata(const struct vb2_v4l2_buffer *out_vb, |
| 680 | struct vb2_v4l2_buffer *cap_vb, |
| 681 | bool copy_frame_flags); |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 682 | |
Hans Verkuil | 803a7ab | 2018-05-21 04:54:53 -0400 | [diff] [blame] | 683 | /* v4l2 request helper */ |
| 684 | |
Ezequiel Garcia | ef86eaf | 2018-10-18 14:54:29 -0400 | [diff] [blame] | 685 | void v4l2_m2m_request_queue(struct media_request *req); |
Hans Verkuil | 803a7ab | 2018-05-21 04:54:53 -0400 | [diff] [blame] | 686 | |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 687 | /* v4l2 ioctl helpers */ |
| 688 | |
| 689 | int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv, |
| 690 | struct v4l2_requestbuffers *rb); |
| 691 | int v4l2_m2m_ioctl_create_bufs(struct file *file, void *fh, |
| 692 | struct v4l2_create_buffers *create); |
| 693 | int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh, |
| 694 | struct v4l2_buffer *buf); |
| 695 | int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh, |
| 696 | struct v4l2_exportbuffer *eb); |
| 697 | int v4l2_m2m_ioctl_qbuf(struct file *file, void *fh, |
| 698 | struct v4l2_buffer *buf); |
| 699 | int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh, |
| 700 | struct v4l2_buffer *buf); |
Hans Verkuil | e68cf47 | 2015-06-05 11:28:50 -0300 | [diff] [blame] | 701 | int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *fh, |
| 702 | struct v4l2_buffer *buf); |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 703 | int v4l2_m2m_ioctl_streamon(struct file *file, void *fh, |
| 704 | enum v4l2_buf_type type); |
| 705 | int v4l2_m2m_ioctl_streamoff(struct file *file, void *fh, |
| 706 | enum v4l2_buf_type type); |
Hans Verkuil | ef732d5 | 2019-05-29 02:45:59 -0400 | [diff] [blame] | 707 | int v4l2_m2m_ioctl_try_encoder_cmd(struct file *file, void *fh, |
| 708 | struct v4l2_encoder_cmd *ec); |
| 709 | int v4l2_m2m_ioctl_try_decoder_cmd(struct file *file, void *fh, |
| 710 | struct v4l2_decoder_cmd *dc); |
Jernej Skrabec | bef41d9 | 2019-10-11 06:32:43 -0300 | [diff] [blame] | 711 | int v4l2_m2m_ioctl_stateless_try_decoder_cmd(struct file *file, void *fh, |
| 712 | struct v4l2_decoder_cmd *dc); |
| 713 | int v4l2_m2m_ioctl_stateless_decoder_cmd(struct file *file, void *priv, |
| 714 | struct v4l2_decoder_cmd *dc); |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 715 | int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma); |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 716 | __poll_t v4l2_m2m_fop_poll(struct file *file, poll_table *wait); |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 717 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 718 | #endif /* _MEDIA_V4L2_MEM2MEM_H */ |
| 719 | |