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