Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
videobuf2-core.h
Go to the documentation of this file.
1 /*
2  * videobuf2-core.h - V4L2 driver helper framework
3  *
4  * Copyright (C) 2010 Samsung Electronics
5  *
6  * Author: Pawel Osciak <[email protected]>
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_CORE_H
13 #define _MEDIA_VIDEOBUF2_CORE_H
14 
15 #include <linux/mm_types.h>
16 #include <linux/mutex.h>
17 #include <linux/poll.h>
18 #include <linux/videodev2.h>
19 
20 struct vb2_alloc_ctx;
21 struct vb2_fileio_data;
22 
60 struct vb2_mem_ops {
61  void *(*alloc)(void *alloc_ctx, unsigned long size);
62  void (*put)(void *buf_priv);
63 
64  void *(*get_userptr)(void *alloc_ctx, unsigned long vaddr,
65  unsigned long size, int write);
66  void (*put_userptr)(void *buf_priv);
67 
68  void *(*vaddr)(void *buf_priv);
69  void *(*cookie)(void *buf_priv);
70 
71  unsigned int (*num_users)(void *buf_priv);
72 
73  int (*mmap)(void *buf_priv, struct vm_area_struct *vma);
74 };
75 
76 struct vb2_plane {
77  void *mem_priv;
78 };
79 
88  VB2_MMAP = (1 << 0),
89  VB2_USERPTR = (1 << 1),
90  VB2_READ = (1 << 2),
91  VB2_WRITE = (1 << 3),
92 };
93 
103 };
104 
125 };
126 
127 struct vb2_queue;
128 
152 struct vb2_buffer {
155 
157 
158  unsigned int num_planes;
159 
160 /* Private: internal use only */
162 
165 
167 };
168 
228 struct vb2_ops {
229  int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
230  unsigned int *num_buffers, unsigned int *num_planes,
231  unsigned int sizes[], void *alloc_ctxs[]);
232 
235 
236  int (*buf_init)(struct vb2_buffer *vb);
237  int (*buf_prepare)(struct vb2_buffer *vb);
238  int (*buf_finish)(struct vb2_buffer *vb);
239  void (*buf_cleanup)(struct vb2_buffer *vb);
240 
241  int (*start_streaming)(struct vb2_queue *q, unsigned int count);
243 
244  void (*buf_queue)(struct vb2_buffer *vb);
245 };
246 
247 struct v4l2_fh;
248 
283 struct vb2_queue {
285  unsigned int io_modes;
286  unsigned int io_flags;
287  struct mutex *lock;
288  struct v4l2_fh *owner;
289 
290  const struct vb2_ops *ops;
291  const struct vb2_mem_ops *mem_ops;
292  void *drv_priv;
293  unsigned int buf_struct_size;
294 
295 /* private: internal use only */
298  unsigned int num_buffers;
299 
301 
306 
309 
310  unsigned int streaming:1;
311 
313 };
314 
315 void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
316 void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
317 
318 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
320 
321 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
322 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
323 
325 int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
326 
328 
329 void vb2_queue_release(struct vb2_queue *q);
330 
331 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
332 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
333 
334 int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
335 int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
336 
337 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
338 #ifndef CONFIG_MMU
339 unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
340  unsigned long addr,
341  unsigned long len,
342  unsigned long pgoff,
343  unsigned long flags);
344 #endif
345 unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
346 size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
347  loff_t *ppos, int nonblock);
348 size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count,
349  loff_t *ppos, int nonblock);
350 
355 static inline bool vb2_is_streaming(struct vb2_queue *q)
356 {
357  return q->streaming;
358 }
359 
366 static inline bool vb2_is_busy(struct vb2_queue *q)
367 {
368  return (q->num_buffers > 0);
369 }
370 
375 static inline void *vb2_get_drv_priv(struct vb2_queue *q)
376 {
377  return q->drv_priv;
378 }
379 
386 static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
387  unsigned int plane_no, unsigned long size)
388 {
389  if (plane_no < vb->num_planes)
390  vb->v4l2_planes[plane_no].bytesused = size;
391 }
392 
399 static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
400  unsigned int plane_no)
401 {
402  if (plane_no < vb->num_planes)
403  return vb->v4l2_planes[plane_no].bytesused;
404  return 0;
405 }
406 
412 static inline unsigned long
413 vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
414 {
415  if (plane_no < vb->num_planes)
416  return vb->v4l2_planes[plane_no].length;
417  return 0;
418 }
419 
420 /*
421  * The following functions are not part of the vb2 core API, but are simple
422  * helper functions that you can use in your struct v4l2_file_operations,
423  * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock
424  * or video_device->lock is set, and they will set and test vb2_queue->owner
425  * to check if the calling filehandle is permitted to do the queuing operation.
426  */
427 
428 /* struct v4l2_ioctl_ops helpers */
429 
430 int vb2_ioctl_reqbufs(struct file *file, void *priv,
431  struct v4l2_requestbuffers *p);
432 int vb2_ioctl_create_bufs(struct file *file, void *priv,
433  struct v4l2_create_buffers *p);
434 int vb2_ioctl_prepare_buf(struct file *file, void *priv,
435  struct v4l2_buffer *p);
436 int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
437 int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
438 int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
439 int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
440 int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
441 
442 /* struct v4l2_file_operations helpers */
443 
444 int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
445 int vb2_fop_release(struct file *file);
446 ssize_t vb2_fop_write(struct file *file, char __user *buf,
447  size_t count, loff_t *ppos);
448 ssize_t vb2_fop_read(struct file *file, char __user *buf,
449  size_t count, loff_t *ppos);
450 unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
451 #ifndef CONFIG_MMU
452 unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
453  unsigned long len, unsigned long pgoff, unsigned long flags);
454 #endif
455 
456 /* struct vb2_ops helpers, only use if vq->lock is non-NULL. */
457 
458 void vb2_ops_wait_prepare(struct vb2_queue *vq);
459 void vb2_ops_wait_finish(struct vb2_queue *vq);
460 
461 #endif /* _MEDIA_VIDEOBUF2_CORE_H */