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 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/slab.h>
20 #include <linux/interrupt.h>
22 #include <media/videobuf-core.h>
24 #define MAGIC_BUFFER 0x20070728
25 #define MAGIC_CHECK(is, should) do { \
26 if (unlikely((is) != (should))) { \
27 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", is, should); \
31 module_param(debug, int, 0644);
33 MODULE_DESCRIPTION("helper module to manage video4linux buffers");
34 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
35 MODULE_LICENSE("GPL");
37 #define dprintk(level, fmt, arg...) do { \
39 printk(KERN_DEBUG "vbuf: " fmt , ## arg); } while (0)
41 /* --------------------------------------------------------------------- */
43 #define CALL(q, f, arg...) \
44 ((q->int_ops->f) ? q->int_ops->f(arg) : 0)
46 void *videobuf_alloc(struct videobuf_queue *q)
48 struct videobuf_buffer *vb;
50 BUG_ON(q->msize < sizeof(*vb));
52 if (!q->int_ops || !q->int_ops->alloc) {
53 printk(KERN_ERR "No specific ops defined!\n");
57 vb = q->int_ops->alloc(q->msize);
60 init_waitqueue_head(&vb->done);
61 vb->magic = MAGIC_BUFFER;
67 #define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
68 vb->state != VIDEOBUF_QUEUED)
69 int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
71 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
81 return wait_event_interruptible(vb->done, WAITON_CONDITION);
83 wait_event(vb->done, WAITON_CONDITION);
88 int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
89 struct v4l2_framebuffer *fbuf)
91 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
92 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
94 /* This is required to avoid OOPS on some cases,
95 since mmap_mapper() method should be called before _iolock.
96 On some cases, the mmap_mapper() is called only after scheduling.
98 if (vb->memory == V4L2_MEMORY_MMAP) {
99 wait_event_timeout(vb->done, q->is_mmapped,
100 msecs_to_jiffies(100));
101 if (!q->is_mmapped) {
103 "Error: mmap_mapper() never called!\n");
108 return CALL(q, iolock, q, vb, fbuf);
111 /* --------------------------------------------------------------------- */
114 void videobuf_queue_core_init(struct videobuf_queue *q,
115 struct videobuf_queue_ops *ops,
118 enum v4l2_buf_type type,
119 enum v4l2_field field,
122 struct videobuf_qtype_ops *int_ops)
124 memset(q, 0, sizeof(*q));
125 q->irqlock = irqlock;
132 q->int_ops = int_ops;
134 /* All buffer operations are mandatory */
135 BUG_ON(!q->ops->buf_setup);
136 BUG_ON(!q->ops->buf_prepare);
137 BUG_ON(!q->ops->buf_queue);
138 BUG_ON(!q->ops->buf_release);
140 /* Having implementations for abstract methods are mandatory */
143 mutex_init(&q->vb_lock);
144 init_waitqueue_head(&q->wait);
145 INIT_LIST_HEAD(&q->stream);
148 /* Locking: Only usage in bttv unsafe find way to remove */
149 int videobuf_queue_is_busy(struct videobuf_queue *q)
153 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
156 dprintk(1, "busy: streaming active\n");
160 dprintk(1, "busy: pending read #1\n");
164 dprintk(1, "busy: pending read #2\n");
167 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
168 if (NULL == q->bufs[i])
170 if (q->bufs[i]->map) {
171 dprintk(1, "busy: buffer #%d mapped\n", i);
174 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
175 dprintk(1, "busy: buffer #%d queued\n", i);
178 if (q->bufs[i]->state == VIDEOBUF_ACTIVE) {
179 dprintk(1, "busy: buffer #%d avtive\n", i);
186 /* Locking: Caller holds q->vb_lock */
187 void videobuf_queue_cancel(struct videobuf_queue *q)
189 unsigned long flags = 0;
194 wake_up_interruptible_sync(&q->wait);
196 /* remove queued buffers from list */
198 spin_lock_irqsave(q->irqlock, flags);
199 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
200 if (NULL == q->bufs[i])
202 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
203 list_del(&q->bufs[i]->queue);
204 q->bufs[i]->state = VIDEOBUF_ERROR;
205 wake_up_all(&q->bufs[i]->done);
209 spin_unlock_irqrestore(q->irqlock, flags);
211 /* free all buffers + clear queue */
212 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
213 if (NULL == q->bufs[i])
215 q->ops->buf_release(q, q->bufs[i]);
217 INIT_LIST_HEAD(&q->stream);
220 /* --------------------------------------------------------------------- */
222 /* Locking: Caller holds q->vb_lock */
223 enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
225 enum v4l2_field field = q->field;
227 BUG_ON(V4L2_FIELD_ANY == field);
229 if (V4L2_FIELD_ALTERNATE == field) {
230 if (V4L2_FIELD_TOP == q->last) {
231 field = V4L2_FIELD_BOTTOM;
232 q->last = V4L2_FIELD_BOTTOM;
234 field = V4L2_FIELD_TOP;
235 q->last = V4L2_FIELD_TOP;
241 /* Locking: Caller holds q->vb_lock */
242 static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
243 struct videobuf_buffer *vb, enum v4l2_buf_type type)
245 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
246 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
251 b->memory = vb->memory;
253 case V4L2_MEMORY_MMAP:
254 b->m.offset = vb->boff;
255 b->length = vb->bsize;
257 case V4L2_MEMORY_USERPTR:
258 b->m.userptr = vb->baddr;
259 b->length = vb->bsize;
261 case V4L2_MEMORY_OVERLAY:
262 b->m.offset = vb->boff;
268 b->flags |= V4L2_BUF_FLAG_MAPPED;
271 case VIDEOBUF_PREPARED:
272 case VIDEOBUF_QUEUED:
273 case VIDEOBUF_ACTIVE:
274 b->flags |= V4L2_BUF_FLAG_QUEUED;
278 b->flags |= V4L2_BUF_FLAG_DONE;
280 case VIDEOBUF_NEEDS_INIT:
286 if (vb->input != UNSET) {
287 b->flags |= V4L2_BUF_FLAG_INPUT;
288 b->input = vb->input;
291 b->field = vb->field;
292 b->timestamp = vb->ts;
293 b->bytesused = vb->size;
294 b->sequence = vb->field_count >> 1;
297 /* Locking: Caller holds q->vb_lock */
298 static int __videobuf_mmap_free(struct videobuf_queue *q)
306 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
309 rc = CALL(q, mmap_free, q);
316 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
317 if (NULL == q->bufs[i])
319 q->ops->buf_release(q, q->bufs[i]);
327 int videobuf_mmap_free(struct videobuf_queue *q)
330 mutex_lock(&q->vb_lock);
331 ret = __videobuf_mmap_free(q);
332 mutex_unlock(&q->vb_lock);
336 /* Locking: Caller holds q->vb_lock */
337 static int __videobuf_mmap_setup(struct videobuf_queue *q,
338 unsigned int bcount, unsigned int bsize,
339 enum v4l2_memory memory)
344 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
346 err = __videobuf_mmap_free(q);
350 /* Allocate and initialize buffers */
351 for (i = 0; i < bcount; i++) {
352 q->bufs[i] = videobuf_alloc(q);
354 if (q->bufs[i] == NULL)
358 q->bufs[i]->input = UNSET;
359 q->bufs[i]->memory = memory;
360 q->bufs[i]->bsize = bsize;
362 case V4L2_MEMORY_MMAP:
363 q->bufs[i]->boff = bsize * i;
365 case V4L2_MEMORY_USERPTR:
366 case V4L2_MEMORY_OVERLAY:
375 dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
381 int videobuf_mmap_setup(struct videobuf_queue *q,
382 unsigned int bcount, unsigned int bsize,
383 enum v4l2_memory memory)
386 mutex_lock(&q->vb_lock);
387 ret = __videobuf_mmap_setup(q, bcount, bsize, memory);
388 mutex_unlock(&q->vb_lock);
392 int videobuf_reqbufs(struct videobuf_queue *q,
393 struct v4l2_requestbuffers *req)
395 unsigned int size, count;
398 if (req->count < 1) {
399 dprintk(1, "reqbufs: count invalid (%d)\n", req->count);
403 if (req->memory != V4L2_MEMORY_MMAP &&
404 req->memory != V4L2_MEMORY_USERPTR &&
405 req->memory != V4L2_MEMORY_OVERLAY) {
406 dprintk(1, "reqbufs: memory type invalid\n");
410 mutex_lock(&q->vb_lock);
411 if (req->type != q->type) {
412 dprintk(1, "reqbufs: queue type invalid\n");
418 dprintk(1, "reqbufs: streaming already exists\n");
422 if (!list_empty(&q->stream)) {
423 dprintk(1, "reqbufs: stream running\n");
429 if (count > VIDEO_MAX_FRAME)
430 count = VIDEO_MAX_FRAME;
432 q->ops->buf_setup(q, &count, &size);
433 size = PAGE_ALIGN(size);
434 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
435 count, size, (count*size)>>PAGE_SHIFT);
437 retval = __videobuf_mmap_setup(q, count, size, req->memory);
439 dprintk(1, "reqbufs: mmap setup returned %d\n", retval);
446 mutex_unlock(&q->vb_lock);
450 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
454 mutex_lock(&q->vb_lock);
455 if (unlikely(b->type != q->type)) {
456 dprintk(1, "querybuf: Wrong type.\n");
459 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
460 dprintk(1, "querybuf: index out of range.\n");
463 if (unlikely(NULL == q->bufs[b->index])) {
464 dprintk(1, "querybuf: buffer is null.\n");
468 videobuf_status(q, b, q->bufs[b->index], q->type);
472 mutex_unlock(&q->vb_lock);
476 int videobuf_qbuf(struct videobuf_queue *q,
477 struct v4l2_buffer *b)
479 struct videobuf_buffer *buf;
480 enum v4l2_field field;
481 unsigned long flags = 0;
484 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
486 if (b->memory == V4L2_MEMORY_MMAP)
487 down_read(¤t->mm->mmap_sem);
489 mutex_lock(&q->vb_lock);
492 dprintk(1, "qbuf: Reading running...\n");
496 if (b->type != q->type) {
497 dprintk(1, "qbuf: Wrong type.\n");
500 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
501 dprintk(1, "qbuf: index out of range.\n");
504 buf = q->bufs[b->index];
506 dprintk(1, "qbuf: buffer is null.\n");
509 MAGIC_CHECK(buf->magic, MAGIC_BUFFER);
510 if (buf->memory != b->memory) {
511 dprintk(1, "qbuf: memory type is wrong.\n");
514 if (buf->state != VIDEOBUF_NEEDS_INIT && buf->state != VIDEOBUF_IDLE) {
515 dprintk(1, "qbuf: buffer is already queued or active.\n");
519 if (b->flags & V4L2_BUF_FLAG_INPUT) {
520 if (b->input >= q->inputs) {
521 dprintk(1, "qbuf: wrong input.\n");
524 buf->input = b->input;
530 case V4L2_MEMORY_MMAP:
531 if (0 == buf->baddr) {
532 dprintk(1, "qbuf: mmap requested "
533 "but buffer addr is zero!\n");
537 case V4L2_MEMORY_USERPTR:
538 if (b->length < buf->bsize) {
539 dprintk(1, "qbuf: buffer length is not enough\n");
542 if (VIDEOBUF_NEEDS_INIT != buf->state &&
543 buf->baddr != b->m.userptr)
544 q->ops->buf_release(q, buf);
545 buf->baddr = b->m.userptr;
547 case V4L2_MEMORY_OVERLAY:
548 buf->boff = b->m.offset;
551 dprintk(1, "qbuf: wrong memory type\n");
555 dprintk(1, "qbuf: requesting next field\n");
556 field = videobuf_next_field(q);
557 retval = q->ops->buf_prepare(q, buf, field);
559 dprintk(1, "qbuf: buffer_prepare returned %d\n", retval);
563 list_add_tail(&buf->stream, &q->stream);
566 spin_lock_irqsave(q->irqlock, flags);
567 q->ops->buf_queue(q, buf);
569 spin_unlock_irqrestore(q->irqlock, flags);
571 dprintk(1, "qbuf: succeded\n");
573 wake_up_interruptible_sync(&q->wait);
576 mutex_unlock(&q->vb_lock);
578 if (b->memory == V4L2_MEMORY_MMAP)
579 up_read(¤t->mm->mmap_sem);
585 /* Locking: Caller holds q->vb_lock */
586 static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
592 dprintk(1, "next_buffer: Not streaming\n");
597 if (list_empty(&q->stream)) {
600 dprintk(2, "next_buffer: no buffers to dequeue\n");
603 dprintk(2, "next_buffer: waiting on buffer\n");
605 /* Drop lock to avoid deadlock with qbuf */
606 mutex_unlock(&q->vb_lock);
608 /* Checking list_empty and streaming is safe without
609 * locks because we goto checks to validate while
610 * holding locks before proceeding */
611 retval = wait_event_interruptible(q->wait,
612 !list_empty(&q->stream) || !q->streaming);
613 mutex_lock(&q->vb_lock);
629 /* Locking: Caller holds q->vb_lock */
630 static int stream_next_buffer(struct videobuf_queue *q,
631 struct videobuf_buffer **vb, int nonblocking)
634 struct videobuf_buffer *buf = NULL;
636 retval = stream_next_buffer_check_queue(q, nonblocking);
640 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
641 retval = videobuf_waiton(buf, nonblocking, 1);
650 int videobuf_dqbuf(struct videobuf_queue *q,
651 struct v4l2_buffer *b, int nonblocking)
653 struct videobuf_buffer *buf = NULL;
656 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
658 mutex_lock(&q->vb_lock);
660 retval = stream_next_buffer(q, &buf, nonblocking);
662 dprintk(1, "dqbuf: next_buffer error: %i\n", retval);
666 switch (buf->state) {
668 dprintk(1, "dqbuf: state is error\n");
670 CALL(q, sync, q, buf);
671 buf->state = VIDEOBUF_IDLE;
674 dprintk(1, "dqbuf: state is done\n");
675 CALL(q, sync, q, buf);
676 buf->state = VIDEOBUF_IDLE;
679 dprintk(1, "dqbuf: state invalid\n");
683 list_del(&buf->stream);
684 memset(b, 0, sizeof(*b));
685 videobuf_status(q, b, buf, q->type);
688 mutex_unlock(&q->vb_lock);
692 int videobuf_streamon(struct videobuf_queue *q)
694 struct videobuf_buffer *buf;
695 unsigned long flags = 0;
698 mutex_lock(&q->vb_lock);
707 spin_lock_irqsave(q->irqlock, flags);
708 list_for_each_entry(buf, &q->stream, stream)
709 if (buf->state == VIDEOBUF_PREPARED)
710 q->ops->buf_queue(q, buf);
712 spin_unlock_irqrestore(q->irqlock, flags);
714 wake_up_interruptible_sync(&q->wait);
716 mutex_unlock(&q->vb_lock);
720 /* Locking: Caller holds q->vb_lock */
721 static int __videobuf_streamoff(struct videobuf_queue *q)
726 videobuf_queue_cancel(q);
731 int videobuf_streamoff(struct videobuf_queue *q)
735 mutex_lock(&q->vb_lock);
736 retval = __videobuf_streamoff(q);
737 mutex_unlock(&q->vb_lock);
742 /* Locking: Caller holds q->vb_lock */
743 static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
745 size_t count, loff_t *ppos)
747 enum v4l2_field field;
748 unsigned long flags = 0;
751 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
754 q->read_buf = videobuf_alloc(q);
755 if (NULL == q->read_buf)
758 q->read_buf->memory = V4L2_MEMORY_USERPTR;
759 q->read_buf->baddr = (unsigned long)data;
760 q->read_buf->bsize = count;
762 field = videobuf_next_field(q);
763 retval = q->ops->buf_prepare(q, q->read_buf, field);
767 /* start capture & wait */
769 spin_lock_irqsave(q->irqlock, flags);
770 q->ops->buf_queue(q, q->read_buf);
772 spin_unlock_irqrestore(q->irqlock, flags);
773 retval = videobuf_waiton(q->read_buf, 0, 0);
775 CALL(q, sync, q, q->read_buf);
776 if (VIDEOBUF_ERROR == q->read_buf->state)
779 retval = q->read_buf->size;
784 q->ops->buf_release(q, q->read_buf);
790 ssize_t videobuf_read_one(struct videobuf_queue *q,
791 char __user *data, size_t count, loff_t *ppos,
794 enum v4l2_field field;
795 unsigned long flags = 0;
796 unsigned size = 0, nbufs = 1;
799 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
801 mutex_lock(&q->vb_lock);
803 q->ops->buf_setup(q, &nbufs, &size);
805 if (NULL == q->read_buf &&
808 retval = videobuf_read_zerocopy(q, data, count, ppos);
809 if (retval >= 0 || retval == -EIO)
812 /* fallback to kernel bounce buffer on failures */
815 if (NULL == q->read_buf) {
816 /* need to capture a new frame */
818 q->read_buf = videobuf_alloc(q);
820 dprintk(1, "video alloc=0x%p\n", q->read_buf);
821 if (NULL == q->read_buf)
823 q->read_buf->memory = V4L2_MEMORY_USERPTR;
824 q->read_buf->bsize = count; /* preferred size */
825 field = videobuf_next_field(q);
826 retval = q->ops->buf_prepare(q, q->read_buf, field);
834 spin_lock_irqsave(q->irqlock, flags);
836 q->ops->buf_queue(q, q->read_buf);
838 spin_unlock_irqrestore(q->irqlock, flags);
842 /* wait until capture is done */
843 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
847 CALL(q, sync, q, q->read_buf);
849 if (VIDEOBUF_ERROR == q->read_buf->state) {
850 /* catch I/O errors */
851 q->ops->buf_release(q, q->read_buf);
858 /* Copy to userspace */
859 retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
863 q->read_off += retval;
864 if (q->read_off == q->read_buf->size) {
865 /* all data copied, cleanup */
866 q->ops->buf_release(q, q->read_buf);
872 mutex_unlock(&q->vb_lock);
876 /* Locking: Caller holds q->vb_lock */
877 static int __videobuf_read_start(struct videobuf_queue *q)
879 enum v4l2_field field;
880 unsigned long flags = 0;
881 unsigned int count = 0, size = 0;
884 q->ops->buf_setup(q, &count, &size);
887 if (count > VIDEO_MAX_FRAME)
888 count = VIDEO_MAX_FRAME;
889 size = PAGE_ALIGN(size);
891 err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
897 for (i = 0; i < count; i++) {
898 field = videobuf_next_field(q);
899 err = q->ops->buf_prepare(q, q->bufs[i], field);
902 list_add_tail(&q->bufs[i]->stream, &q->stream);
905 spin_lock_irqsave(q->irqlock, flags);
906 for (i = 0; i < count; i++)
907 q->ops->buf_queue(q, q->bufs[i]);
909 spin_unlock_irqrestore(q->irqlock, flags);
914 static void __videobuf_read_stop(struct videobuf_queue *q)
919 videobuf_queue_cancel(q);
920 __videobuf_mmap_free(q);
921 INIT_LIST_HEAD(&q->stream);
922 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
923 if (NULL == q->bufs[i])
932 int videobuf_read_start(struct videobuf_queue *q)
936 mutex_lock(&q->vb_lock);
937 rc = __videobuf_read_start(q);
938 mutex_unlock(&q->vb_lock);
943 void videobuf_read_stop(struct videobuf_queue *q)
945 mutex_lock(&q->vb_lock);
946 __videobuf_read_stop(q);
947 mutex_unlock(&q->vb_lock);
950 void videobuf_stop(struct videobuf_queue *q)
952 mutex_lock(&q->vb_lock);
955 __videobuf_streamoff(q);
958 __videobuf_read_stop(q);
960 mutex_unlock(&q->vb_lock);
964 ssize_t videobuf_read_stream(struct videobuf_queue *q,
965 char __user *data, size_t count, loff_t *ppos,
966 int vbihack, int nonblocking)
969 unsigned long flags = 0;
971 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
973 dprintk(2, "%s\n", __FUNCTION__);
974 mutex_lock(&q->vb_lock);
979 retval = __videobuf_read_start(q);
986 /* get / wait for data */
987 if (NULL == q->read_buf) {
988 q->read_buf = list_entry(q->stream.next,
989 struct videobuf_buffer,
991 list_del(&q->read_buf->stream);
994 rc = videobuf_waiton(q->read_buf, nonblocking, 1);
1001 if (q->read_buf->state == VIDEOBUF_DONE) {
1002 rc = CALL(q, copy_stream, q, data + retval, count,
1003 retval, vbihack, nonblocking);
1013 q->read_off = q->read_buf->size;
1018 /* requeue buffer when done with copying */
1019 if (q->read_off == q->read_buf->size) {
1020 list_add_tail(&q->read_buf->stream,
1023 spin_lock_irqsave(q->irqlock, flags);
1024 q->ops->buf_queue(q, q->read_buf);
1026 spin_unlock_irqrestore(q->irqlock, flags);
1034 mutex_unlock(&q->vb_lock);
1038 unsigned int videobuf_poll_stream(struct file *file,
1039 struct videobuf_queue *q,
1042 struct videobuf_buffer *buf = NULL;
1043 unsigned int rc = 0;
1045 mutex_lock(&q->vb_lock);
1047 if (!list_empty(&q->stream))
1048 buf = list_entry(q->stream.next,
1049 struct videobuf_buffer, stream);
1052 __videobuf_read_start(q);
1055 } else if (NULL == q->read_buf) {
1056 q->read_buf = list_entry(q->stream.next,
1057 struct videobuf_buffer,
1059 list_del(&q->read_buf->stream);
1068 poll_wait(file, &buf->done, wait);
1069 if (buf->state == VIDEOBUF_DONE ||
1070 buf->state == VIDEOBUF_ERROR)
1071 rc = POLLIN|POLLRDNORM;
1073 mutex_unlock(&q->vb_lock);
1077 int videobuf_mmap_mapper(struct videobuf_queue *q,
1078 struct vm_area_struct *vma)
1082 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1084 mutex_lock(&q->vb_lock);
1085 retval = CALL(q, mmap_mapper, q, vma);
1087 mutex_unlock(&q->vb_lock);
1092 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1093 int videobuf_cgmbuf(struct videobuf_queue *q,
1094 struct video_mbuf *mbuf, int count)
1096 struct v4l2_requestbuffers req;
1099 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1101 memset(&req, 0, sizeof(req));
1104 req.memory = V4L2_MEMORY_MMAP;
1105 rc = videobuf_reqbufs(q, &req);
1109 mbuf->frames = req.count;
1111 for (i = 0; i < mbuf->frames; i++) {
1112 mbuf->offsets[i] = q->bufs[i]->boff;
1113 mbuf->size += q->bufs[i]->bsize;
1118 EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
1121 /* --------------------------------------------------------------------- */
1123 EXPORT_SYMBOL_GPL(videobuf_waiton);
1124 EXPORT_SYMBOL_GPL(videobuf_iolock);
1126 EXPORT_SYMBOL_GPL(videobuf_alloc);
1128 EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
1129 EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
1130 EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
1132 EXPORT_SYMBOL_GPL(videobuf_next_field);
1133 EXPORT_SYMBOL_GPL(videobuf_reqbufs);
1134 EXPORT_SYMBOL_GPL(videobuf_querybuf);
1135 EXPORT_SYMBOL_GPL(videobuf_qbuf);
1136 EXPORT_SYMBOL_GPL(videobuf_dqbuf);
1137 EXPORT_SYMBOL_GPL(videobuf_streamon);
1138 EXPORT_SYMBOL_GPL(videobuf_streamoff);
1140 EXPORT_SYMBOL_GPL(videobuf_read_start);
1141 EXPORT_SYMBOL_GPL(videobuf_read_stop);
1142 EXPORT_SYMBOL_GPL(videobuf_stop);
1143 EXPORT_SYMBOL_GPL(videobuf_read_stream);
1144 EXPORT_SYMBOL_GPL(videobuf_read_one);
1145 EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1147 EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1148 EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1149 EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);