Fix IRQ flag handling naming
[linux-2.6/cjktty.git] / include / media / videobuf-core.h
blobf2c41cebf453a65abbe4fc281f20103287e5fea0
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 #define __MIN_V4L1
22 #include <linux/videodev.h>
23 #endif
24 #include <linux/videodev2.h>
26 #define UNSET (-1U)
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
47 * (which v4l2 uses).
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 {
56 unsigned int count;
57 struct videobuf_queue *q;
60 enum videobuf_state {
61 VIDEOBUF_NEEDS_INIT = 0,
62 VIDEOBUF_PREPARED = 1,
63 VIDEOBUF_QUEUED = 2,
64 VIDEOBUF_ACTIVE = 3,
65 VIDEOBUF_DONE = 4,
66 VIDEOBUF_ERROR = 5,
67 VIDEOBUF_IDLE = 6,
70 struct videobuf_buffer {
71 unsigned int i;
72 u32 magic;
74 /* info about the buffer */
75 unsigned int width;
76 unsigned int height;
77 unsigned int bytesperline; /* use only if != 0 */
78 unsigned long size;
79 unsigned int input;
80 enum v4l2_field field;
81 enum videobuf_state state;
82 struct list_head stream; /* QBUF/DQBUF list */
84 /* touched by irq handler */
85 struct list_head queue;
86 wait_queue_head_t done;
87 unsigned int field_count;
88 struct timeval ts;
90 /* Memory type */
91 enum v4l2_memory memory;
93 /* buffer size */
94 size_t bsize;
96 /* buffer offset (mmap + overlay) */
97 size_t boff;
99 /* buffer addr (userland ptr!) */
100 unsigned long baddr;
102 /* for mmap'ed buffers */
103 struct videobuf_mapping *map;
105 /* Private pointer to allow specific methods to store their data */
106 int privsize;
107 void *priv;
110 struct videobuf_queue_ops {
111 int (*buf_setup)(struct videobuf_queue *q,
112 unsigned int *count, unsigned int *size);
113 int (*buf_prepare)(struct videobuf_queue *q,
114 struct videobuf_buffer *vb,
115 enum v4l2_field field);
116 void (*buf_queue)(struct videobuf_queue *q,
117 struct videobuf_buffer *vb);
118 void (*buf_release)(struct videobuf_queue *q,
119 struct videobuf_buffer *vb);
122 #define MAGIC_QTYPE_OPS 0x12261003
124 /* Helper operations - device type dependent */
125 struct videobuf_qtype_ops {
126 u32 magic;
128 struct videobuf_buffer *(*alloc_vb)(size_t size);
129 void *(*vaddr) (struct videobuf_buffer *buf);
130 int (*iolock) (struct videobuf_queue *q,
131 struct videobuf_buffer *vb,
132 struct v4l2_framebuffer *fbuf);
133 int (*sync) (struct videobuf_queue *q,
134 struct videobuf_buffer *buf);
135 int (*mmap_mapper) (struct videobuf_queue *q,
136 struct videobuf_buffer *buf,
137 struct vm_area_struct *vma);
140 struct videobuf_queue {
141 struct mutex vb_lock;
142 spinlock_t *irqlock;
143 struct device *dev;
145 wait_queue_head_t wait; /* wait if queue is empty */
147 enum v4l2_buf_type type;
148 unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */
149 unsigned int msize;
150 enum v4l2_field field;
151 enum v4l2_field last; /* for field=V4L2_FIELD_ALTERNATE */
152 struct videobuf_buffer *bufs[VIDEO_MAX_FRAME];
153 const struct videobuf_queue_ops *ops;
154 struct videobuf_qtype_ops *int_ops;
156 unsigned int streaming:1;
157 unsigned int reading:1;
159 /* capture via mmap() + ioctl(QBUF/DQBUF) */
160 struct list_head stream;
162 /* capture via read() */
163 unsigned int read_off;
164 struct videobuf_buffer *read_buf;
166 /* driver private data */
167 void *priv_data;
170 int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr);
171 int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
172 struct v4l2_framebuffer *fbuf);
174 struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q);
176 /* Used on videobuf-dvb */
177 void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
178 struct videobuf_buffer *buf);
180 void videobuf_queue_core_init(struct videobuf_queue *q,
181 const struct videobuf_queue_ops *ops,
182 struct device *dev,
183 spinlock_t *irqlock,
184 enum v4l2_buf_type type,
185 enum v4l2_field field,
186 unsigned int msize,
187 void *priv,
188 struct videobuf_qtype_ops *int_ops);
189 int videobuf_queue_is_busy(struct videobuf_queue *q);
190 void videobuf_queue_cancel(struct videobuf_queue *q);
192 enum v4l2_field videobuf_next_field(struct videobuf_queue *q);
193 int videobuf_reqbufs(struct videobuf_queue *q,
194 struct v4l2_requestbuffers *req);
195 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
196 int videobuf_qbuf(struct videobuf_queue *q,
197 struct v4l2_buffer *b);
198 int videobuf_dqbuf(struct videobuf_queue *q,
199 struct v4l2_buffer *b, int nonblocking);
200 #ifdef CONFIG_VIDEO_V4L1_COMPAT
201 int videobuf_cgmbuf(struct videobuf_queue *q,
202 struct video_mbuf *mbuf, int count);
203 #endif
204 int videobuf_streamon(struct videobuf_queue *q);
205 int videobuf_streamoff(struct videobuf_queue *q);
207 void videobuf_stop(struct videobuf_queue *q);
209 int videobuf_read_start(struct videobuf_queue *q);
210 void videobuf_read_stop(struct videobuf_queue *q);
211 ssize_t videobuf_read_stream(struct videobuf_queue *q,
212 char __user *data, size_t count, loff_t *ppos,
213 int vbihack, int nonblocking);
214 ssize_t videobuf_read_one(struct videobuf_queue *q,
215 char __user *data, size_t count, loff_t *ppos,
216 int nonblocking);
217 unsigned int videobuf_poll_stream(struct file *file,
218 struct videobuf_queue *q,
219 poll_table *wait);
221 int videobuf_mmap_setup(struct videobuf_queue *q,
222 unsigned int bcount, unsigned int bsize,
223 enum v4l2_memory memory);
224 int __videobuf_mmap_setup(struct videobuf_queue *q,
225 unsigned int bcount, unsigned int bsize,
226 enum v4l2_memory memory);
227 int videobuf_mmap_free(struct videobuf_queue *q);
228 int videobuf_mmap_mapper(struct videobuf_queue *q,
229 struct vm_area_struct *vma);
231 #endif