Commit | Line | Data |
---|---|---|
c139990e JS |
1 | /* |
2 | * videobuf2-v4l2.h - V4L2 driver helper framework | |
3 | * | |
4 | * Copyright (C) 2010 Samsung Electronics | |
5 | * | |
6 | * Author: Pawel Osciak <pawel@osciak.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation. | |
11 | */ | |
12 | #ifndef _MEDIA_VIDEOBUF2_V4L2_H | |
13 | #define _MEDIA_VIDEOBUF2_V4L2_H | |
14 | ||
2d700715 | 15 | #include <linux/videodev2.h> |
c139990e JS |
16 | #include <media/videobuf2-core.h> |
17 | ||
bed04f93 JS |
18 | #if VB2_MAX_FRAME != VIDEO_MAX_FRAME |
19 | #error VB2_MAX_FRAME != VIDEO_MAX_FRAME | |
20 | #endif | |
21 | ||
22 | #if VB2_MAX_PLANES != VIDEO_MAX_PLANES | |
23 | #error VB2_MAX_PLANES != VIDEO_MAX_PLANES | |
24 | #endif | |
25 | ||
2d700715 | 26 | /** |
9fbe71b4 | 27 | * struct vb2_v4l2_buffer - video buffer information for v4l2. |
bf4404b4 | 28 | * |
9fbe71b4 MCC |
29 | * @vb2_buf: embedded struct &vb2_buffer. |
30 | * @flags: buffer informational flags. | |
31 | * @field: field order of the image in the buffer, as defined by | |
32 | * &enum v4l2_field. | |
33 | * @timecode: frame timecode. | |
34 | * @sequence: sequence count of this frame. | |
db6e8d57 | 35 | * @planes: plane information (userptr/fd, length, bytesused, data_offset). |
bf4404b4 | 36 | * |
2d700715 | 37 | * Should contain enough information to be able to cover all the fields |
9fbe71b4 | 38 | * of &struct v4l2_buffer at ``videodev2.h``. |
2d700715 JS |
39 | */ |
40 | struct vb2_v4l2_buffer { | |
41 | struct vb2_buffer vb2_buf; | |
42 | ||
43 | __u32 flags; | |
44 | __u32 field; | |
2d700715 JS |
45 | struct v4l2_timecode timecode; |
46 | __u32 sequence; | |
db6e8d57 | 47 | struct vb2_plane planes[VB2_MAX_PLANES]; |
2d700715 JS |
48 | }; |
49 | ||
d383b579 | 50 | /* |
2d700715 JS |
51 | * to_vb2_v4l2_buffer() - cast struct vb2_buffer * to struct vb2_v4l2_buffer * |
52 | */ | |
53 | #define to_vb2_v4l2_buffer(vb) \ | |
d383b579 | 54 | container_of(vb, struct vb2_v4l2_buffer, vb2_buf) |
2d700715 | 55 | |
3c5be988 | 56 | int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b); |
24ade5b6 MCC |
57 | |
58 | /** | |
59 | * vb2_reqbufs() - Wrapper for vb2_core_reqbufs() that also verifies | |
60 | * the memory and type values. | |
bf4404b4 | 61 | * |
9fbe71b4 MCC |
62 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
63 | * @req: &struct v4l2_requestbuffers passed from userspace to | |
64 | * &v4l2_ioctl_ops->vidioc_reqbufs handler in driver. | |
24ade5b6 | 65 | */ |
3c5be988 JS |
66 | int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req); |
67 | ||
24ade5b6 MCC |
68 | /** |
69 | * vb2_create_bufs() - Wrapper for vb2_core_create_bufs() that also verifies | |
70 | * the memory and type values. | |
bf4404b4 | 71 | * |
9fbe71b4 MCC |
72 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
73 | * @create: creation parameters, passed from userspace to | |
74 | * &v4l2_ioctl_ops->vidioc_create_bufs handler in driver | |
24ade5b6 | 75 | */ |
3c5be988 | 76 | int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create); |
24ade5b6 MCC |
77 | |
78 | /** | |
79 | * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel | |
bf4404b4 | 80 | * |
9fbe71b4 MCC |
81 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
82 | * @b: buffer structure passed from userspace to | |
83 | * &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver | |
84 | * | |
85 | * Should be called from &v4l2_ioctl_ops->vidioc_prepare_buf ioctl handler | |
86 | * of a driver. | |
24ade5b6 | 87 | * |
24ade5b6 | 88 | * This function: |
bf4404b4 MCC |
89 | * |
90 | * #) verifies the passed buffer, | |
9fbe71b4 MCC |
91 | * #) calls &vb2_ops->buf_prepare callback in the driver (if provided), |
92 | * in which driver-specific buffer initialization can be performed. | |
24ade5b6 MCC |
93 | * |
94 | * The return values from this function are intended to be directly returned | |
9fbe71b4 | 95 | * from &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver. |
24ade5b6 | 96 | */ |
3c5be988 JS |
97 | int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b); |
98 | ||
24ade5b6 MCC |
99 | /** |
100 | * vb2_qbuf() - Queue a buffer from userspace | |
9fbe71b4 MCC |
101 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
102 | * @b: buffer structure passed from userspace to | |
103 | * &v4l2_ioctl_ops->vidioc_qbuf handler in driver | |
24ade5b6 | 104 | * |
9fbe71b4 | 105 | * Should be called from &v4l2_ioctl_ops->vidioc_qbuf handler of a driver. |
bf4404b4 | 106 | * |
24ade5b6 | 107 | * This function: |
bf4404b4 | 108 | * |
9fbe71b4 MCC |
109 | * #) verifies the passed buffer; |
110 | * #) if necessary, calls &vb2_ops->buf_prepare callback in the driver | |
111 | * (if provided), in which driver-specific buffer initialization can | |
112 | * be performed; | |
113 | * #) if streaming is on, queues the buffer in driver by the means of | |
114 | * &vb2_ops->buf_queue callback for processing. | |
24ade5b6 MCC |
115 | * |
116 | * The return values from this function are intended to be directly returned | |
9fbe71b4 | 117 | * from &v4l2_ioctl_ops->vidioc_qbuf handler in driver. |
24ade5b6 | 118 | */ |
3c5be988 | 119 | int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); |
24ade5b6 MCC |
120 | |
121 | /** | |
122 | * vb2_expbuf() - Export a buffer as a file descriptor | |
9fbe71b4 MCC |
123 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
124 | * @eb: export buffer structure passed from userspace to | |
125 | * &v4l2_ioctl_ops->vidioc_expbuf handler in driver | |
24ade5b6 MCC |
126 | * |
127 | * The return values from this function are intended to be directly returned | |
9fbe71b4 | 128 | * from &v4l2_ioctl_ops->vidioc_expbuf handler in driver. |
24ade5b6 | 129 | */ |
3c5be988 | 130 | int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb); |
24ade5b6 MCC |
131 | |
132 | /** | |
133 | * vb2_dqbuf() - Dequeue a buffer to the userspace | |
9fbe71b4 MCC |
134 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
135 | * @b: buffer structure passed from userspace to | |
136 | * &v4l2_ioctl_ops->vidioc_dqbuf handler in driver | |
24ade5b6 MCC |
137 | * @nonblocking: if true, this call will not sleep waiting for a buffer if no |
138 | * buffers ready for dequeuing are present. Normally the driver | |
9fbe71b4 | 139 | * would be passing (&file->f_flags & %O_NONBLOCK) here |
24ade5b6 | 140 | * |
9fbe71b4 MCC |
141 | * Should be called from &v4l2_ioctl_ops->vidioc_dqbuf ioctl handler |
142 | * of a driver. | |
bf4404b4 | 143 | * |
24ade5b6 | 144 | * This function: |
bf4404b4 | 145 | * |
9fbe71b4 MCC |
146 | * #) verifies the passed buffer; |
147 | * #) calls &vb2_ops->buf_finish callback in the driver (if provided), in which | |
24ade5b6 | 148 | * driver can perform any additional operations that may be required before |
9fbe71b4 | 149 | * returning the buffer to userspace, such as cache sync; |
bf4404b4 | 150 | * #) the buffer struct members are filled with relevant information for |
24ade5b6 MCC |
151 | * the userspace. |
152 | * | |
153 | * The return values from this function are intended to be directly returned | |
9fbe71b4 | 154 | * from &v4l2_ioctl_ops->vidioc_dqbuf handler in driver. |
24ade5b6 | 155 | */ |
3c5be988 JS |
156 | int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking); |
157 | ||
24ade5b6 MCC |
158 | /** |
159 | * vb2_streamon - start streaming | |
9fbe71b4 MCC |
160 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
161 | * @type: type argument passed from userspace to vidioc_streamon handler, | |
162 | * as defined by &enum v4l2_buf_type. | |
24ade5b6 | 163 | * |
9fbe71b4 | 164 | * Should be called from &v4l2_ioctl_ops->vidioc_streamon handler of a driver. |
bf4404b4 | 165 | * |
24ade5b6 | 166 | * This function: |
bf4404b4 | 167 | * |
24ade5b6 MCC |
168 | * 1) verifies current state |
169 | * 2) passes any previously queued buffers to the driver and starts streaming | |
170 | * | |
171 | * The return values from this function are intended to be directly returned | |
9fbe71b4 | 172 | * from &v4l2_ioctl_ops->vidioc_streamon handler in the driver. |
24ade5b6 | 173 | */ |
3c5be988 | 174 | int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type); |
24ade5b6 MCC |
175 | |
176 | /** | |
177 | * vb2_streamoff - stop streaming | |
9fbe71b4 | 178 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
24ade5b6 MCC |
179 | * @type: type argument passed from userspace to vidioc_streamoff handler |
180 | * | |
181 | * Should be called from vidioc_streamoff handler of a driver. | |
bf4404b4 | 182 | * |
24ade5b6 | 183 | * This function: |
bf4404b4 MCC |
184 | * |
185 | * #) verifies current state, | |
186 | * #) stop streaming and dequeues any queued buffers, including those previously | |
24ade5b6 MCC |
187 | * passed to the driver (after waiting for the driver to finish). |
188 | * | |
189 | * This call can be used for pausing playback. | |
190 | * The return values from this function are intended to be directly returned | |
191 | * from vidioc_streamoff handler in the driver | |
192 | */ | |
3c5be988 JS |
193 | int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type); |
194 | ||
24ade5b6 MCC |
195 | /** |
196 | * vb2_queue_init() - initialize a videobuf2 queue | |
9fbe71b4 | 197 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
24ade5b6 MCC |
198 | * |
199 | * The vb2_queue structure should be allocated by the driver. The driver is | |
200 | * responsible of clearing it's content and setting initial values for some | |
201 | * required entries before calling this function. | |
202 | * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer | |
203 | * to the struct vb2_queue description in include/media/videobuf2-core.h | |
204 | * for more information. | |
205 | */ | |
3c5be988 | 206 | int __must_check vb2_queue_init(struct vb2_queue *q); |
24ade5b6 MCC |
207 | |
208 | /** | |
209 | * vb2_queue_release() - stop streaming, release the queue and free memory | |
9fbe71b4 | 210 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
24ade5b6 MCC |
211 | * |
212 | * This function stops streaming and performs necessary clean ups, including | |
213 | * freeing video buffer memory. The driver is responsible for freeing | |
214 | * the vb2_queue structure itself. | |
215 | */ | |
3c5be988 | 216 | void vb2_queue_release(struct vb2_queue *q); |
24ade5b6 MCC |
217 | |
218 | /** | |
219 | * vb2_poll() - implements poll userspace operation | |
9fbe71b4 | 220 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
24ade5b6 MCC |
221 | * @file: file argument passed to the poll file operation handler |
222 | * @wait: wait argument passed to the poll file operation handler | |
223 | * | |
224 | * This function implements poll file operation handler for a driver. | |
225 | * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will | |
226 | * be informed that the file descriptor of a video device is available for | |
227 | * reading. | |
228 | * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor | |
229 | * will be reported as available for writing. | |
230 | * | |
231 | * If the driver uses struct v4l2_fh, then vb2_poll() will also check for any | |
232 | * pending events. | |
233 | * | |
234 | * The return values from this function are intended to be directly returned | |
235 | * from poll handler in driver. | |
236 | */ | |
c23e0cb8 | 237 | __poll_t vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait); |
3c5be988 JS |
238 | |
239 | /* | |
240 | * The following functions are not part of the vb2 core API, but are simple | |
241 | * helper functions that you can use in your struct v4l2_file_operations, | |
242 | * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock | |
243 | * or video_device->lock is set, and they will set and test vb2_queue->owner | |
244 | * to check if the calling filehandle is permitted to do the queuing operation. | |
245 | */ | |
246 | ||
247 | /* struct v4l2_ioctl_ops helpers */ | |
248 | ||
249 | int vb2_ioctl_reqbufs(struct file *file, void *priv, | |
250 | struct v4l2_requestbuffers *p); | |
251 | int vb2_ioctl_create_bufs(struct file *file, void *priv, | |
252 | struct v4l2_create_buffers *p); | |
253 | int vb2_ioctl_prepare_buf(struct file *file, void *priv, | |
254 | struct v4l2_buffer *p); | |
255 | int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p); | |
256 | int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p); | |
257 | int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p); | |
258 | int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i); | |
259 | int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i); | |
260 | int vb2_ioctl_expbuf(struct file *file, void *priv, | |
261 | struct v4l2_exportbuffer *p); | |
262 | ||
263 | /* struct v4l2_file_operations helpers */ | |
264 | ||
265 | int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma); | |
266 | int vb2_fop_release(struct file *file); | |
267 | int _vb2_fop_release(struct file *file, struct mutex *lock); | |
268 | ssize_t vb2_fop_write(struct file *file, const char __user *buf, | |
269 | size_t count, loff_t *ppos); | |
270 | ssize_t vb2_fop_read(struct file *file, char __user *buf, | |
271 | size_t count, loff_t *ppos); | |
c23e0cb8 | 272 | __poll_t vb2_fop_poll(struct file *file, poll_table *wait); |
3c5be988 JS |
273 | #ifndef CONFIG_MMU |
274 | unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr, | |
275 | unsigned long len, unsigned long pgoff, unsigned long flags); | |
276 | #endif | |
277 | ||
dba2d12a MCC |
278 | /** |
279 | * vb2_ops_wait_prepare - helper function to lock a struct &vb2_queue | |
280 | * | |
9fbe71b4 | 281 | * @vq: pointer to &struct vb2_queue |
dba2d12a MCC |
282 | * |
283 | * ..note:: only use if vq->lock is non-NULL. | |
284 | */ | |
3c5be988 | 285 | void vb2_ops_wait_prepare(struct vb2_queue *vq); |
dba2d12a MCC |
286 | |
287 | /** | |
288 | * vb2_ops_wait_finish - helper function to unlock a struct &vb2_queue | |
289 | * | |
9fbe71b4 | 290 | * @vq: pointer to &struct vb2_queue |
dba2d12a MCC |
291 | * |
292 | * ..note:: only use if vq->lock is non-NULL. | |
293 | */ | |
3c5be988 JS |
294 | void vb2_ops_wait_finish(struct vb2_queue *vq); |
295 | ||
c139990e | 296 | #endif /* _MEDIA_VIDEOBUF2_V4L2_H */ |