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
22 #include <linux/videodev.h>
24 #include <linux/videodev2.h>
29 struct videobuf_buffer
;
30 struct videobuf_queue
;
32 /* --------------------------------------------------------------------- */
35 * A small set of helper functions to manage video4linux buffers.
37 * struct videobuf_buffer holds the data structures used by the helper
38 * functions, additionally some commonly used fields for v4l buffers
39 * (width, height, lists, waitqueue) are in there. That struct should
40 * be used as first element in the drivers buffer struct.
42 * about the mmap helpers (videobuf_mmap_*):
44 * The mmaper function allows to map any subset of contingous buffers.
45 * This includes one mmap() call for all buffers (which the original
46 * video4linux API uses) as well as one mmap() for every single buffer
49 * If there is a valid mapping for a buffer, buffer->baddr/bsize holds
50 * userspace address + size which can be feeded into the
51 * videobuf_dma_init_user function listed above.
55 struct videobuf_mapping
{
59 struct videobuf_queue
*q
;
63 VIDEOBUF_NEEDS_INIT
= 0,
64 VIDEOBUF_PREPARED
= 1,
72 struct videobuf_buffer
{
76 /* info about the buffer */
79 unsigned int bytesperline
; /* use only if != 0 */
82 enum v4l2_field field
;
83 enum videobuf_state state
;
84 struct list_head stream
; /* QBUF/DQBUF list */
86 /* touched by irq handler */
87 struct list_head queue
;
88 wait_queue_head_t done
;
89 unsigned int field_count
;
93 enum v4l2_memory memory
;
98 /* buffer offset (mmap + overlay) */
101 /* buffer addr (userland ptr!) */
104 /* for mmap'ed buffers */
105 struct videobuf_mapping
*map
;
107 /* Private pointer to allow specific methods to store their data */
112 struct videobuf_queue_ops
{
113 int (*buf_setup
)(struct videobuf_queue
*q
,
114 unsigned int *count
, unsigned int *size
);
115 int (*buf_prepare
)(struct videobuf_queue
*q
,
116 struct videobuf_buffer
*vb
,
117 enum v4l2_field field
);
118 void (*buf_queue
)(struct videobuf_queue
*q
,
119 struct videobuf_buffer
*vb
);
120 void (*buf_release
)(struct videobuf_queue
*q
,
121 struct videobuf_buffer
*vb
);
124 #define MAGIC_QTYPE_OPS 0x12261003
126 /* Helper operations - device type dependent */
127 struct videobuf_qtype_ops
{
130 struct videobuf_buffer
*(*alloc
)(size_t size
);
131 void *(*vaddr
) (struct videobuf_buffer
*buf
);
132 int (*iolock
) (struct videobuf_queue
*q
,
133 struct videobuf_buffer
*vb
,
134 struct v4l2_framebuffer
*fbuf
);
135 int (*sync
) (struct videobuf_queue
*q
,
136 struct videobuf_buffer
*buf
);
137 int (*mmap_mapper
) (struct videobuf_queue
*q
,
138 struct vm_area_struct
*vma
);
141 struct videobuf_queue
{
142 struct mutex vb_lock
;
146 wait_queue_head_t wait
; /* wait if queue is empty */
148 enum v4l2_buf_type type
;
149 unsigned int inputs
; /* for V4L2_BUF_FLAG_INPUT */
151 enum v4l2_field field
;
152 enum v4l2_field last
; /* for field=V4L2_FIELD_ALTERNATE */
153 struct videobuf_buffer
*bufs
[VIDEO_MAX_FRAME
];
154 const struct videobuf_queue_ops
*ops
;
155 struct videobuf_qtype_ops
*int_ops
;
157 unsigned int streaming
:1;
158 unsigned int reading
:1;
160 /* capture via mmap() + ioctl(QBUF/DQBUF) */
161 struct list_head stream
;
163 /* capture via read() */
164 unsigned int read_off
;
165 struct videobuf_buffer
*read_buf
;
167 /* driver private data */
171 int videobuf_waiton(struct videobuf_buffer
*vb
, int non_blocking
, int intr
);
172 int videobuf_iolock(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
173 struct v4l2_framebuffer
*fbuf
);
175 struct videobuf_buffer
*videobuf_alloc(struct videobuf_queue
*q
);
177 /* Used on videobuf-dvb */
178 void *videobuf_queue_to_vaddr(struct videobuf_queue
*q
,
179 struct videobuf_buffer
*buf
);
181 void videobuf_queue_core_init(struct videobuf_queue
*q
,
182 const struct videobuf_queue_ops
*ops
,
185 enum v4l2_buf_type type
,
186 enum v4l2_field field
,
189 struct videobuf_qtype_ops
*int_ops
);
190 int videobuf_queue_is_busy(struct videobuf_queue
*q
);
191 void videobuf_queue_cancel(struct videobuf_queue
*q
);
193 enum v4l2_field
videobuf_next_field(struct videobuf_queue
*q
);
194 int videobuf_reqbufs(struct videobuf_queue
*q
,
195 struct v4l2_requestbuffers
*req
);
196 int videobuf_querybuf(struct videobuf_queue
*q
, struct v4l2_buffer
*b
);
197 int videobuf_qbuf(struct videobuf_queue
*q
,
198 struct v4l2_buffer
*b
);
199 int videobuf_dqbuf(struct videobuf_queue
*q
,
200 struct v4l2_buffer
*b
, int nonblocking
);
201 #ifdef CONFIG_VIDEO_V4L1_COMPAT
202 int videobuf_cgmbuf(struct videobuf_queue
*q
,
203 struct video_mbuf
*mbuf
, int count
);
205 int videobuf_streamon(struct videobuf_queue
*q
);
206 int videobuf_streamoff(struct videobuf_queue
*q
);
208 void videobuf_stop(struct videobuf_queue
*q
);
210 int videobuf_read_start(struct videobuf_queue
*q
);
211 void videobuf_read_stop(struct videobuf_queue
*q
);
212 ssize_t
videobuf_read_stream(struct videobuf_queue
*q
,
213 char __user
*data
, size_t count
, loff_t
*ppos
,
214 int vbihack
, int nonblocking
);
215 ssize_t
videobuf_read_one(struct videobuf_queue
*q
,
216 char __user
*data
, size_t count
, loff_t
*ppos
,
218 unsigned int videobuf_poll_stream(struct file
*file
,
219 struct videobuf_queue
*q
,
222 int videobuf_mmap_setup(struct videobuf_queue
*q
,
223 unsigned int bcount
, unsigned int bsize
,
224 enum v4l2_memory memory
);
225 int __videobuf_mmap_setup(struct videobuf_queue
*q
,
226 unsigned int bcount
, unsigned int bsize
,
227 enum v4l2_memory memory
);
228 int videobuf_mmap_free(struct videobuf_queue
*q
);
229 int videobuf_mmap_mapper(struct videobuf_queue
*q
,
230 struct vm_area_struct
*vma
);