2 * generic helper functions for handling video4linux capture buffers
4 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
6 * Highly based on video-buf written originally by:
7 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
8 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
9 * (c) 2006 Ted Walther and John Sokol
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2
16 #ifndef _VIDEOBUF_CORE_H
17 #define _VIDEOBUF_CORE_H
19 #include <linux/poll.h>
20 #ifdef CONFIG_VIDEO_V4L1_COMPAT
21 #include <linux/videodev.h>
23 #include <linux/videodev2.h>
28 struct videobuf_buffer
;
29 struct videobuf_queue
;
31 /* --------------------------------------------------------------------- */
34 * A small set of helper functions to manage video4linux buffers.
36 * struct videobuf_buffer holds the data structures used by the helper
37 * functions, additionally some commonly used fields for v4l buffers
38 * (width, height, lists, waitqueue) are in there. That struct should
39 * be used as first element in the drivers buffer struct.
41 * about the mmap helpers (videobuf_mmap_*):
43 * The mmaper function allows to map any subset of contingous buffers.
44 * This includes one mmap() call for all buffers (which the original
45 * video4linux API uses) as well as one mmap() for every single buffer
48 * If there is a valid mapping for a buffer, buffer->baddr/bsize holds
49 * userspace address + size which can be feeded into the
50 * videobuf_dma_init_user function listed above.
54 struct videobuf_mapping
{
58 struct videobuf_queue
*q
;
62 VIDEOBUF_NEEDS_INIT
= 0,
63 VIDEOBUF_PREPARED
= 1,
71 struct videobuf_buffer
{
75 /* info about the buffer */
78 unsigned int bytesperline
; /* use only if != 0 */
81 enum v4l2_field field
;
82 enum videobuf_state state
;
83 struct list_head stream
; /* QBUF/DQBUF list */
85 /* touched by irq handler */
86 struct list_head queue
;
87 wait_queue_head_t done
;
88 unsigned int field_count
;
92 enum v4l2_memory memory
;
97 /* buffer offset (mmap + overlay) */
100 /* buffer addr (userland ptr!) */
103 /* for mmap'ed buffers */
104 struct videobuf_mapping
*map
;
106 /* Private pointer to allow specific methods to store their data */
111 struct videobuf_queue_ops
{
112 int (*buf_setup
)(struct videobuf_queue
*q
,
113 unsigned int *count
, unsigned int *size
);
114 int (*buf_prepare
)(struct videobuf_queue
*q
,
115 struct videobuf_buffer
*vb
,
116 enum v4l2_field field
);
117 void (*buf_queue
)(struct videobuf_queue
*q
,
118 struct videobuf_buffer
*vb
);
119 void (*buf_release
)(struct videobuf_queue
*q
,
120 struct videobuf_buffer
*vb
);
123 #define MAGIC_QTYPE_OPS 0x12261003
125 /* Helper operations - device type dependent */
126 struct videobuf_qtype_ops
{
129 void *(*alloc
) (size_t size
);
130 void *(*vmalloc
) (struct videobuf_buffer
*buf
);
131 int (*iolock
) (struct videobuf_queue
* q
,
132 struct videobuf_buffer
*vb
,
133 struct v4l2_framebuffer
*fbuf
);
134 int (*mmap
) (struct videobuf_queue
*q
,
137 enum v4l2_memory memory
);
138 int (*sync
) (struct videobuf_queue
* q
,
139 struct videobuf_buffer
*buf
);
140 int (*video_copy_to_user
)(struct videobuf_queue
*q
,
144 int (*copy_stream
) (struct videobuf_queue
*q
,
150 int (*mmap_free
) (struct videobuf_queue
*q
);
151 int (*mmap_mapper
) (struct videobuf_queue
*q
,
152 struct vm_area_struct
*vma
);
155 struct videobuf_queue
{
156 struct mutex vb_lock
;
160 wait_queue_head_t wait
; /* wait if queue is empty */
162 enum v4l2_buf_type type
;
163 unsigned int inputs
; /* for V4L2_BUF_FLAG_INPUT */
165 enum v4l2_field field
;
166 enum v4l2_field last
; /* for field=V4L2_FIELD_ALTERNATE */
167 struct videobuf_buffer
*bufs
[VIDEO_MAX_FRAME
];
168 struct videobuf_queue_ops
*ops
;
169 struct videobuf_qtype_ops
*int_ops
;
171 unsigned int streaming
:1;
172 unsigned int reading
:1;
173 unsigned int is_mmapped
:1;
175 /* capture via mmap() + ioctl(QBUF/DQBUF) */
176 struct list_head stream
;
178 /* capture via read() */
179 unsigned int read_off
;
180 struct videobuf_buffer
*read_buf
;
182 /* driver private data */
186 int videobuf_waiton(struct videobuf_buffer
*vb
, int non_blocking
, int intr
);
187 int videobuf_iolock(struct videobuf_queue
* q
, struct videobuf_buffer
*vb
,
188 struct v4l2_framebuffer
*fbuf
);
190 void *videobuf_alloc(struct videobuf_queue
* q
);
192 /* Used on videobuf-dvb */
193 void *videobuf_queue_to_vmalloc (struct videobuf_queue
* q
,
194 struct videobuf_buffer
*buf
);
196 void videobuf_queue_core_init(struct videobuf_queue
*q
,
197 struct videobuf_queue_ops
*ops
,
200 enum v4l2_buf_type type
,
201 enum v4l2_field field
,
204 struct videobuf_qtype_ops
*int_ops
);
205 int videobuf_queue_is_busy(struct videobuf_queue
*q
);
206 void videobuf_queue_cancel(struct videobuf_queue
*q
);
208 enum v4l2_field
videobuf_next_field(struct videobuf_queue
*q
);
209 int videobuf_reqbufs(struct videobuf_queue
*q
,
210 struct v4l2_requestbuffers
*req
);
211 int videobuf_querybuf(struct videobuf_queue
*q
, struct v4l2_buffer
*b
);
212 int videobuf_qbuf(struct videobuf_queue
*q
,
213 struct v4l2_buffer
*b
);
214 int videobuf_dqbuf(struct videobuf_queue
*q
,
215 struct v4l2_buffer
*b
, int nonblocking
);
216 #ifdef CONFIG_VIDEO_V4L1_COMPAT
217 int videobuf_cgmbuf(struct videobuf_queue
*q
,
218 struct video_mbuf
*mbuf
, int count
);
220 int videobuf_streamon(struct videobuf_queue
*q
);
221 int videobuf_streamoff(struct videobuf_queue
*q
);
223 void videobuf_stop(struct videobuf_queue
*q
);
225 int videobuf_read_start(struct videobuf_queue
*q
);
226 void videobuf_read_stop(struct videobuf_queue
*q
);
227 ssize_t
videobuf_read_stream(struct videobuf_queue
*q
,
228 char __user
*data
, size_t count
, loff_t
*ppos
,
229 int vbihack
, int nonblocking
);
230 ssize_t
videobuf_read_one(struct videobuf_queue
*q
,
231 char __user
*data
, size_t count
, loff_t
*ppos
,
233 unsigned int videobuf_poll_stream(struct file
*file
,
234 struct videobuf_queue
*q
,
237 int videobuf_mmap_setup(struct videobuf_queue
*q
,
238 unsigned int bcount
, unsigned int bsize
,
239 enum v4l2_memory memory
);
240 int videobuf_mmap_free(struct videobuf_queue
*q
);
241 int videobuf_mmap_mapper(struct videobuf_queue
*q
,
242 struct vm_area_struct
*vma
);