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