USB: remove warn() macro from usb drivers
[linux/fpc-iii.git] / include / media / videobuf-core.h
blob874f1340d0493d9f8f1e66a5186ae984e9e93a51
1 /*
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>
22 #endif
23 #include <linux/videodev2.h>
25 #define UNSET (-1U)
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
46 * (which v4l2 uses).
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 {
55 unsigned int count;
56 unsigned long start;
57 unsigned long end;
58 struct videobuf_queue *q;
61 enum videobuf_state {
62 VIDEOBUF_NEEDS_INIT = 0,
63 VIDEOBUF_PREPARED = 1,
64 VIDEOBUF_QUEUED = 2,
65 VIDEOBUF_ACTIVE = 3,
66 VIDEOBUF_DONE = 4,
67 VIDEOBUF_ERROR = 5,
68 VIDEOBUF_IDLE = 6,
71 struct videobuf_buffer {
72 unsigned int i;
73 u32 magic;
75 /* info about the buffer */
76 unsigned int width;
77 unsigned int height;
78 unsigned int bytesperline; /* use only if != 0 */
79 unsigned long size;
80 unsigned int input;
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;
89 struct timeval ts;
91 /* Memory type */
92 enum v4l2_memory memory;
94 /* buffer size */
95 size_t bsize;
97 /* buffer offset (mmap + overlay) */
98 size_t boff;
100 /* buffer addr (userland ptr!) */
101 unsigned long baddr;
103 /* for mmap'ed buffers */
104 struct videobuf_mapping *map;
106 /* Private pointer to allow specific methods to store their data */
107 int privsize;
108 void *priv;
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 {
127 u32 magic;
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,
135 unsigned int *count,
136 unsigned int *size,
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,
141 char __user *data,
142 size_t count,
143 int nonblocking);
144 int (*copy_stream) (struct videobuf_queue *q,
145 char __user *data,
146 size_t count,
147 size_t pos,
148 int vbihack,
149 int nonblocking);
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;
157 spinlock_t *irqlock;
158 struct device *dev;
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 */
164 unsigned int msize;
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 */
183 void *priv_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,
198 struct device *dev,
199 spinlock_t *irqlock,
200 enum v4l2_buf_type type,
201 enum v4l2_field field,
202 unsigned int msize,
203 void *priv,
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);
219 #endif
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,
232 int nonblocking);
233 unsigned int videobuf_poll_stream(struct file *file,
234 struct videobuf_queue *q,
235 poll_table *wait);
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_setup(struct videobuf_queue *q,
241 unsigned int bcount, unsigned int bsize,
242 enum v4l2_memory memory);
243 int videobuf_mmap_free(struct videobuf_queue *q);
244 int videobuf_mmap_mapper(struct videobuf_queue *q,
245 struct vm_area_struct *vma);
247 #endif