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 return CALL(q, iolock, q, vb, fbuf);
97 void *videobuf_queue_to_vmalloc (struct videobuf_queue *q,
98 struct videobuf_buffer *buf)
100 return CALL(q, vmalloc, buf);
102 EXPORT_SYMBOL_GPL(videobuf_queue_to_vmalloc);
104 /* --------------------------------------------------------------------- */
107 void videobuf_queue_core_init(struct videobuf_queue *q,
108 struct videobuf_queue_ops *ops,
111 enum v4l2_buf_type type,
112 enum v4l2_field field,
115 struct videobuf_qtype_ops *int_ops)
117 memset(q, 0, sizeof(*q));
118 q->irqlock = irqlock;
125 q->int_ops = int_ops;
127 /* All buffer operations are mandatory */
128 BUG_ON(!q->ops->buf_setup);
129 BUG_ON(!q->ops->buf_prepare);
130 BUG_ON(!q->ops->buf_queue);
131 BUG_ON(!q->ops->buf_release);
133 /* Lock is mandatory for queue_cancel to work */
136 /* Having implementations for abstract methods are mandatory */
139 mutex_init(&q->vb_lock);
140 init_waitqueue_head(&q->wait);
141 INIT_LIST_HEAD(&q->stream);
144 /* Locking: Only usage in bttv unsafe find way to remove */
145 int videobuf_queue_is_busy(struct videobuf_queue *q)
149 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
152 dprintk(1, "busy: streaming active\n");
156 dprintk(1, "busy: pending read #1\n");
160 dprintk(1, "busy: pending read #2\n");
163 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
164 if (NULL == q->bufs[i])
166 if (q->bufs[i]->map) {
167 dprintk(1, "busy: buffer #%d mapped\n", i);
170 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
171 dprintk(1, "busy: buffer #%d queued\n", i);
174 if (q->bufs[i]->state == VIDEOBUF_ACTIVE) {
175 dprintk(1, "busy: buffer #%d avtive\n", i);
182 /* Locking: Caller holds q->vb_lock */
183 void videobuf_queue_cancel(struct videobuf_queue *q)
185 unsigned long flags = 0;
190 wake_up_interruptible_sync(&q->wait);
192 /* remove queued buffers from list */
193 spin_lock_irqsave(q->irqlock, flags);
194 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
195 if (NULL == q->bufs[i])
197 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
198 list_del(&q->bufs[i]->queue);
199 q->bufs[i]->state = VIDEOBUF_ERROR;
200 wake_up_all(&q->bufs[i]->done);
203 spin_unlock_irqrestore(q->irqlock, flags);
205 /* free all buffers + clear queue */
206 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
207 if (NULL == q->bufs[i])
209 q->ops->buf_release(q, q->bufs[i]);
211 INIT_LIST_HEAD(&q->stream);
214 /* --------------------------------------------------------------------- */
216 /* Locking: Caller holds q->vb_lock */
217 enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
219 enum v4l2_field field = q->field;
221 BUG_ON(V4L2_FIELD_ANY == field);
223 if (V4L2_FIELD_ALTERNATE == field) {
224 if (V4L2_FIELD_TOP == q->last) {
225 field = V4L2_FIELD_BOTTOM;
226 q->last = V4L2_FIELD_BOTTOM;
228 field = V4L2_FIELD_TOP;
229 q->last = V4L2_FIELD_TOP;
235 /* Locking: Caller holds q->vb_lock */
236 static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
237 struct videobuf_buffer *vb, enum v4l2_buf_type type)
239 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
240 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
245 b->memory = vb->memory;
247 case V4L2_MEMORY_MMAP:
248 b->m.offset = vb->boff;
249 b->length = vb->bsize;
251 case V4L2_MEMORY_USERPTR:
252 b->m.userptr = vb->baddr;
253 b->length = vb->bsize;
255 case V4L2_MEMORY_OVERLAY:
256 b->m.offset = vb->boff;
262 b->flags |= V4L2_BUF_FLAG_MAPPED;
265 case VIDEOBUF_PREPARED:
266 case VIDEOBUF_QUEUED:
267 case VIDEOBUF_ACTIVE:
268 b->flags |= V4L2_BUF_FLAG_QUEUED;
272 b->flags |= V4L2_BUF_FLAG_DONE;
274 case VIDEOBUF_NEEDS_INIT:
280 if (vb->input != UNSET) {
281 b->flags |= V4L2_BUF_FLAG_INPUT;
282 b->input = vb->input;
285 b->field = vb->field;
286 b->timestamp = vb->ts;
287 b->bytesused = vb->size;
288 b->sequence = vb->field_count >> 1;
291 /* Locking: Caller holds q->vb_lock */
292 static int __videobuf_mmap_free(struct videobuf_queue *q)
300 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
303 rc = CALL(q, mmap_free, q);
310 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
311 if (NULL == q->bufs[i])
313 q->ops->buf_release(q, q->bufs[i]);
321 int videobuf_mmap_free(struct videobuf_queue *q)
324 mutex_lock(&q->vb_lock);
325 ret = __videobuf_mmap_free(q);
326 mutex_unlock(&q->vb_lock);
330 /* Locking: Caller holds q->vb_lock */
331 static int __videobuf_mmap_setup(struct videobuf_queue *q,
332 unsigned int bcount, unsigned int bsize,
333 enum v4l2_memory memory)
338 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
340 err = __videobuf_mmap_free(q);
344 /* Allocate and initialize buffers */
345 for (i = 0; i < bcount; i++) {
346 q->bufs[i] = videobuf_alloc(q);
348 if (q->bufs[i] == NULL)
352 q->bufs[i]->input = UNSET;
353 q->bufs[i]->memory = memory;
354 q->bufs[i]->bsize = bsize;
356 case V4L2_MEMORY_MMAP:
357 q->bufs[i]->boff = bsize * i;
359 case V4L2_MEMORY_USERPTR:
360 case V4L2_MEMORY_OVERLAY:
369 dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
375 int videobuf_mmap_setup(struct videobuf_queue *q,
376 unsigned int bcount, unsigned int bsize,
377 enum v4l2_memory memory)
380 mutex_lock(&q->vb_lock);
381 ret = __videobuf_mmap_setup(q, bcount, bsize, memory);
382 mutex_unlock(&q->vb_lock);
386 int videobuf_reqbufs(struct videobuf_queue *q,
387 struct v4l2_requestbuffers *req)
389 unsigned int size, count;
392 if (req->count < 1) {
393 dprintk(1, "reqbufs: count invalid (%d)\n", req->count);
397 if (req->memory != V4L2_MEMORY_MMAP &&
398 req->memory != V4L2_MEMORY_USERPTR &&
399 req->memory != V4L2_MEMORY_OVERLAY) {
400 dprintk(1, "reqbufs: memory type invalid\n");
404 mutex_lock(&q->vb_lock);
405 if (req->type != q->type) {
406 dprintk(1, "reqbufs: queue type invalid\n");
412 dprintk(1, "reqbufs: streaming already exists\n");
416 if (!list_empty(&q->stream)) {
417 dprintk(1, "reqbufs: stream running\n");
423 if (count > VIDEO_MAX_FRAME)
424 count = VIDEO_MAX_FRAME;
426 q->ops->buf_setup(q, &count, &size);
427 size = PAGE_ALIGN(size);
428 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
429 count, size, (count*size)>>PAGE_SHIFT);
431 retval = __videobuf_mmap_setup(q, count, size, req->memory);
433 dprintk(1, "reqbufs: mmap setup returned %d\n", retval);
440 mutex_unlock(&q->vb_lock);
444 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
448 mutex_lock(&q->vb_lock);
449 if (unlikely(b->type != q->type)) {
450 dprintk(1, "querybuf: Wrong type.\n");
453 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
454 dprintk(1, "querybuf: index out of range.\n");
457 if (unlikely(NULL == q->bufs[b->index])) {
458 dprintk(1, "querybuf: buffer is null.\n");
462 videobuf_status(q, b, q->bufs[b->index], q->type);
466 mutex_unlock(&q->vb_lock);
470 int videobuf_qbuf(struct videobuf_queue *q,
471 struct v4l2_buffer *b)
473 struct videobuf_buffer *buf;
474 enum v4l2_field field;
475 unsigned long flags = 0;
478 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
480 if (b->memory == V4L2_MEMORY_MMAP)
481 down_read(¤t->mm->mmap_sem);
483 mutex_lock(&q->vb_lock);
486 dprintk(1, "qbuf: Reading running...\n");
490 if (b->type != q->type) {
491 dprintk(1, "qbuf: Wrong type.\n");
494 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
495 dprintk(1, "qbuf: index out of range.\n");
498 buf = q->bufs[b->index];
500 dprintk(1, "qbuf: buffer is null.\n");
503 MAGIC_CHECK(buf->magic, MAGIC_BUFFER);
504 if (buf->memory != b->memory) {
505 dprintk(1, "qbuf: memory type is wrong.\n");
508 if (buf->state != VIDEOBUF_NEEDS_INIT && buf->state != VIDEOBUF_IDLE) {
509 dprintk(1, "qbuf: buffer is already queued or active.\n");
513 if (b->flags & V4L2_BUF_FLAG_INPUT) {
514 if (b->input >= q->inputs) {
515 dprintk(1, "qbuf: wrong input.\n");
518 buf->input = b->input;
524 case V4L2_MEMORY_MMAP:
525 if (0 == buf->baddr) {
526 dprintk(1, "qbuf: mmap requested "
527 "but buffer addr is zero!\n");
531 case V4L2_MEMORY_USERPTR:
532 if (b->length < buf->bsize) {
533 dprintk(1, "qbuf: buffer length is not enough\n");
536 if (VIDEOBUF_NEEDS_INIT != buf->state &&
537 buf->baddr != b->m.userptr)
538 q->ops->buf_release(q, buf);
539 buf->baddr = b->m.userptr;
541 case V4L2_MEMORY_OVERLAY:
542 buf->boff = b->m.offset;
545 dprintk(1, "qbuf: wrong memory type\n");
549 dprintk(1, "qbuf: requesting next field\n");
550 field = videobuf_next_field(q);
551 retval = q->ops->buf_prepare(q, buf, field);
553 dprintk(1, "qbuf: buffer_prepare returned %d\n", retval);
557 list_add_tail(&buf->stream, &q->stream);
559 spin_lock_irqsave(q->irqlock, flags);
560 q->ops->buf_queue(q, buf);
561 spin_unlock_irqrestore(q->irqlock, flags);
563 dprintk(1, "qbuf: succeded\n");
565 wake_up_interruptible_sync(&q->wait);
568 mutex_unlock(&q->vb_lock);
570 if (b->memory == V4L2_MEMORY_MMAP)
571 up_read(¤t->mm->mmap_sem);
577 /* Locking: Caller holds q->vb_lock */
578 static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
584 dprintk(1, "next_buffer: Not streaming\n");
589 if (list_empty(&q->stream)) {
592 dprintk(2, "next_buffer: no buffers to dequeue\n");
595 dprintk(2, "next_buffer: waiting on buffer\n");
597 /* Drop lock to avoid deadlock with qbuf */
598 mutex_unlock(&q->vb_lock);
600 /* Checking list_empty and streaming is safe without
601 * locks because we goto checks to validate while
602 * holding locks before proceeding */
603 retval = wait_event_interruptible(q->wait,
604 !list_empty(&q->stream) || !q->streaming);
605 mutex_lock(&q->vb_lock);
621 /* Locking: Caller holds q->vb_lock */
622 static int stream_next_buffer(struct videobuf_queue *q,
623 struct videobuf_buffer **vb, int nonblocking)
626 struct videobuf_buffer *buf = NULL;
628 retval = stream_next_buffer_check_queue(q, nonblocking);
632 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
633 retval = videobuf_waiton(buf, nonblocking, 1);
642 int videobuf_dqbuf(struct videobuf_queue *q,
643 struct v4l2_buffer *b, int nonblocking)
645 struct videobuf_buffer *buf = NULL;
648 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
650 mutex_lock(&q->vb_lock);
652 retval = stream_next_buffer(q, &buf, nonblocking);
654 dprintk(1, "dqbuf: next_buffer error: %i\n", retval);
658 switch (buf->state) {
660 dprintk(1, "dqbuf: state is error\n");
662 CALL(q, sync, q, buf);
663 buf->state = VIDEOBUF_IDLE;
666 dprintk(1, "dqbuf: state is done\n");
667 CALL(q, sync, q, buf);
668 buf->state = VIDEOBUF_IDLE;
671 dprintk(1, "dqbuf: state invalid\n");
675 list_del(&buf->stream);
676 memset(b, 0, sizeof(*b));
677 videobuf_status(q, b, buf, q->type);
680 mutex_unlock(&q->vb_lock);
684 int videobuf_streamon(struct videobuf_queue *q)
686 struct videobuf_buffer *buf;
687 unsigned long flags = 0;
690 mutex_lock(&q->vb_lock);
698 spin_lock_irqsave(q->irqlock, flags);
699 list_for_each_entry(buf, &q->stream, stream)
700 if (buf->state == VIDEOBUF_PREPARED)
701 q->ops->buf_queue(q, buf);
702 spin_unlock_irqrestore(q->irqlock, flags);
704 wake_up_interruptible_sync(&q->wait);
706 mutex_unlock(&q->vb_lock);
710 /* Locking: Caller holds q->vb_lock */
711 static int __videobuf_streamoff(struct videobuf_queue *q)
716 videobuf_queue_cancel(q);
721 int videobuf_streamoff(struct videobuf_queue *q)
725 mutex_lock(&q->vb_lock);
726 retval = __videobuf_streamoff(q);
727 mutex_unlock(&q->vb_lock);
732 /* Locking: Caller holds q->vb_lock */
733 static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
735 size_t count, loff_t *ppos)
737 enum v4l2_field field;
738 unsigned long flags = 0;
741 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
744 q->read_buf = videobuf_alloc(q);
745 if (NULL == q->read_buf)
748 q->read_buf->memory = V4L2_MEMORY_USERPTR;
749 q->read_buf->baddr = (unsigned long)data;
750 q->read_buf->bsize = count;
752 field = videobuf_next_field(q);
753 retval = q->ops->buf_prepare(q, q->read_buf, field);
757 /* start capture & wait */
758 spin_lock_irqsave(q->irqlock, flags);
759 q->ops->buf_queue(q, q->read_buf);
760 spin_unlock_irqrestore(q->irqlock, flags);
761 retval = videobuf_waiton(q->read_buf, 0, 0);
763 CALL(q, sync, q, q->read_buf);
764 if (VIDEOBUF_ERROR == q->read_buf->state)
767 retval = q->read_buf->size;
772 q->ops->buf_release(q, q->read_buf);
778 ssize_t videobuf_read_one(struct videobuf_queue *q,
779 char __user *data, size_t count, loff_t *ppos,
782 enum v4l2_field field;
783 unsigned long flags = 0;
784 unsigned size = 0, nbufs = 1;
787 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
789 mutex_lock(&q->vb_lock);
791 q->ops->buf_setup(q, &nbufs, &size);
793 if (NULL == q->read_buf &&
796 retval = videobuf_read_zerocopy(q, data, count, ppos);
797 if (retval >= 0 || retval == -EIO)
800 /* fallback to kernel bounce buffer on failures */
803 if (NULL == q->read_buf) {
804 /* need to capture a new frame */
806 q->read_buf = videobuf_alloc(q);
808 dprintk(1, "video alloc=0x%p\n", q->read_buf);
809 if (NULL == q->read_buf)
811 q->read_buf->memory = V4L2_MEMORY_USERPTR;
812 q->read_buf->bsize = count; /* preferred size */
813 field = videobuf_next_field(q);
814 retval = q->ops->buf_prepare(q, q->read_buf, field);
822 spin_lock_irqsave(q->irqlock, flags);
823 q->ops->buf_queue(q, q->read_buf);
824 spin_unlock_irqrestore(q->irqlock, flags);
829 /* wait until capture is done */
830 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
834 CALL(q, sync, q, q->read_buf);
836 if (VIDEOBUF_ERROR == q->read_buf->state) {
837 /* catch I/O errors */
838 q->ops->buf_release(q, q->read_buf);
845 /* Copy to userspace */
846 retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
850 q->read_off += retval;
851 if (q->read_off == q->read_buf->size) {
852 /* all data copied, cleanup */
853 q->ops->buf_release(q, q->read_buf);
859 mutex_unlock(&q->vb_lock);
863 /* Locking: Caller holds q->vb_lock */
864 static int __videobuf_read_start(struct videobuf_queue *q)
866 enum v4l2_field field;
867 unsigned long flags = 0;
868 unsigned int count = 0, size = 0;
871 q->ops->buf_setup(q, &count, &size);
874 if (count > VIDEO_MAX_FRAME)
875 count = VIDEO_MAX_FRAME;
876 size = PAGE_ALIGN(size);
878 err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
884 for (i = 0; i < count; i++) {
885 field = videobuf_next_field(q);
886 err = q->ops->buf_prepare(q, q->bufs[i], field);
889 list_add_tail(&q->bufs[i]->stream, &q->stream);
891 spin_lock_irqsave(q->irqlock, flags);
892 for (i = 0; i < count; i++)
893 q->ops->buf_queue(q, q->bufs[i]);
894 spin_unlock_irqrestore(q->irqlock, flags);
899 static void __videobuf_read_stop(struct videobuf_queue *q)
903 videobuf_queue_cancel(q);
904 __videobuf_mmap_free(q);
905 INIT_LIST_HEAD(&q->stream);
906 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
907 if (NULL == q->bufs[i])
916 int videobuf_read_start(struct videobuf_queue *q)
920 mutex_lock(&q->vb_lock);
921 rc = __videobuf_read_start(q);
922 mutex_unlock(&q->vb_lock);
927 void videobuf_read_stop(struct videobuf_queue *q)
929 mutex_lock(&q->vb_lock);
930 __videobuf_read_stop(q);
931 mutex_unlock(&q->vb_lock);
934 void videobuf_stop(struct videobuf_queue *q)
936 mutex_lock(&q->vb_lock);
939 __videobuf_streamoff(q);
942 __videobuf_read_stop(q);
944 mutex_unlock(&q->vb_lock);
948 ssize_t videobuf_read_stream(struct videobuf_queue *q,
949 char __user *data, size_t count, loff_t *ppos,
950 int vbihack, int nonblocking)
953 unsigned long flags = 0;
955 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
957 dprintk(2, "%s\n", __func__);
958 mutex_lock(&q->vb_lock);
963 retval = __videobuf_read_start(q);
970 /* get / wait for data */
971 if (NULL == q->read_buf) {
972 q->read_buf = list_entry(q->stream.next,
973 struct videobuf_buffer,
975 list_del(&q->read_buf->stream);
978 rc = videobuf_waiton(q->read_buf, nonblocking, 1);
985 if (q->read_buf->state == VIDEOBUF_DONE) {
986 rc = CALL(q, copy_stream, q, data + retval, count,
987 retval, vbihack, nonblocking);
997 q->read_off = q->read_buf->size;
1002 /* requeue buffer when done with copying */
1003 if (q->read_off == q->read_buf->size) {
1004 list_add_tail(&q->read_buf->stream,
1006 spin_lock_irqsave(q->irqlock, flags);
1007 q->ops->buf_queue(q, q->read_buf);
1008 spin_unlock_irqrestore(q->irqlock, flags);
1016 mutex_unlock(&q->vb_lock);
1020 unsigned int videobuf_poll_stream(struct file *file,
1021 struct videobuf_queue *q,
1024 struct videobuf_buffer *buf = NULL;
1025 unsigned int rc = 0;
1027 mutex_lock(&q->vb_lock);
1029 if (!list_empty(&q->stream))
1030 buf = list_entry(q->stream.next,
1031 struct videobuf_buffer, stream);
1034 __videobuf_read_start(q);
1037 } else if (NULL == q->read_buf) {
1038 q->read_buf = list_entry(q->stream.next,
1039 struct videobuf_buffer,
1041 list_del(&q->read_buf->stream);
1050 poll_wait(file, &buf->done, wait);
1051 if (buf->state == VIDEOBUF_DONE ||
1052 buf->state == VIDEOBUF_ERROR)
1053 rc = POLLIN|POLLRDNORM;
1055 mutex_unlock(&q->vb_lock);
1059 int videobuf_mmap_mapper(struct videobuf_queue *q,
1060 struct vm_area_struct *vma)
1064 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1066 mutex_lock(&q->vb_lock);
1067 retval = CALL(q, mmap_mapper, q, vma);
1069 mutex_unlock(&q->vb_lock);
1074 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1075 int videobuf_cgmbuf(struct videobuf_queue *q,
1076 struct video_mbuf *mbuf, int count)
1078 struct v4l2_requestbuffers req;
1081 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1083 memset(&req, 0, sizeof(req));
1086 req.memory = V4L2_MEMORY_MMAP;
1087 rc = videobuf_reqbufs(q, &req);
1091 mbuf->frames = req.count;
1093 for (i = 0; i < mbuf->frames; i++) {
1094 mbuf->offsets[i] = q->bufs[i]->boff;
1095 mbuf->size += q->bufs[i]->bsize;
1100 EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
1103 /* --------------------------------------------------------------------- */
1105 EXPORT_SYMBOL_GPL(videobuf_waiton);
1106 EXPORT_SYMBOL_GPL(videobuf_iolock);
1108 EXPORT_SYMBOL_GPL(videobuf_alloc);
1110 EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
1111 EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
1112 EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
1114 EXPORT_SYMBOL_GPL(videobuf_next_field);
1115 EXPORT_SYMBOL_GPL(videobuf_reqbufs);
1116 EXPORT_SYMBOL_GPL(videobuf_querybuf);
1117 EXPORT_SYMBOL_GPL(videobuf_qbuf);
1118 EXPORT_SYMBOL_GPL(videobuf_dqbuf);
1119 EXPORT_SYMBOL_GPL(videobuf_streamon);
1120 EXPORT_SYMBOL_GPL(videobuf_streamoff);
1122 EXPORT_SYMBOL_GPL(videobuf_read_start);
1123 EXPORT_SYMBOL_GPL(videobuf_read_stop);
1124 EXPORT_SYMBOL_GPL(videobuf_stop);
1125 EXPORT_SYMBOL_GPL(videobuf_read_stream);
1126 EXPORT_SYMBOL_GPL(videobuf_read_one);
1127 EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1129 EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1130 EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1131 EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);