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 /* --------------------------------------------------------------------- */
100 void videobuf_queue_core_init(struct videobuf_queue *q,
101 struct videobuf_queue_ops *ops,
104 enum v4l2_buf_type type,
105 enum v4l2_field field,
108 struct videobuf_qtype_ops *int_ops)
110 memset(q, 0, sizeof(*q));
111 q->irqlock = irqlock;
118 q->int_ops = int_ops;
120 /* All buffer operations are mandatory */
121 BUG_ON(!q->ops->buf_setup);
122 BUG_ON(!q->ops->buf_prepare);
123 BUG_ON(!q->ops->buf_queue);
124 BUG_ON(!q->ops->buf_release);
126 /* Lock is mandatory for queue_cancel to work */
129 /* Having implementations for abstract methods are mandatory */
132 mutex_init(&q->vb_lock);
133 init_waitqueue_head(&q->wait);
134 INIT_LIST_HEAD(&q->stream);
137 /* Locking: Only usage in bttv unsafe find way to remove */
138 int videobuf_queue_is_busy(struct videobuf_queue *q)
142 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
145 dprintk(1, "busy: streaming active\n");
149 dprintk(1, "busy: pending read #1\n");
153 dprintk(1, "busy: pending read #2\n");
156 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
157 if (NULL == q->bufs[i])
159 if (q->bufs[i]->map) {
160 dprintk(1, "busy: buffer #%d mapped\n", i);
163 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
164 dprintk(1, "busy: buffer #%d queued\n", i);
167 if (q->bufs[i]->state == VIDEOBUF_ACTIVE) {
168 dprintk(1, "busy: buffer #%d avtive\n", i);
175 /* Locking: Caller holds q->vb_lock */
176 void videobuf_queue_cancel(struct videobuf_queue *q)
178 unsigned long flags = 0;
183 wake_up_interruptible_sync(&q->wait);
185 /* remove queued buffers from list */
186 spin_lock_irqsave(q->irqlock, flags);
187 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
188 if (NULL == q->bufs[i])
190 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
191 list_del(&q->bufs[i]->queue);
192 q->bufs[i]->state = VIDEOBUF_ERROR;
193 wake_up_all(&q->bufs[i]->done);
196 spin_unlock_irqrestore(q->irqlock, flags);
198 /* free all buffers + clear queue */
199 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
200 if (NULL == q->bufs[i])
202 q->ops->buf_release(q, q->bufs[i]);
204 INIT_LIST_HEAD(&q->stream);
207 /* --------------------------------------------------------------------- */
209 /* Locking: Caller holds q->vb_lock */
210 enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
212 enum v4l2_field field = q->field;
214 BUG_ON(V4L2_FIELD_ANY == field);
216 if (V4L2_FIELD_ALTERNATE == field) {
217 if (V4L2_FIELD_TOP == q->last) {
218 field = V4L2_FIELD_BOTTOM;
219 q->last = V4L2_FIELD_BOTTOM;
221 field = V4L2_FIELD_TOP;
222 q->last = V4L2_FIELD_TOP;
228 /* Locking: Caller holds q->vb_lock */
229 static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
230 struct videobuf_buffer *vb, enum v4l2_buf_type type)
232 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
233 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
238 b->memory = vb->memory;
240 case V4L2_MEMORY_MMAP:
241 b->m.offset = vb->boff;
242 b->length = vb->bsize;
244 case V4L2_MEMORY_USERPTR:
245 b->m.userptr = vb->baddr;
246 b->length = vb->bsize;
248 case V4L2_MEMORY_OVERLAY:
249 b->m.offset = vb->boff;
255 b->flags |= V4L2_BUF_FLAG_MAPPED;
258 case VIDEOBUF_PREPARED:
259 case VIDEOBUF_QUEUED:
260 case VIDEOBUF_ACTIVE:
261 b->flags |= V4L2_BUF_FLAG_QUEUED;
265 b->flags |= V4L2_BUF_FLAG_DONE;
267 case VIDEOBUF_NEEDS_INIT:
273 if (vb->input != UNSET) {
274 b->flags |= V4L2_BUF_FLAG_INPUT;
275 b->input = vb->input;
278 b->field = vb->field;
279 b->timestamp = vb->ts;
280 b->bytesused = vb->size;
281 b->sequence = vb->field_count >> 1;
284 /* Locking: Caller holds q->vb_lock */
285 static int __videobuf_mmap_free(struct videobuf_queue *q)
293 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
296 rc = CALL(q, mmap_free, q);
303 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
304 if (NULL == q->bufs[i])
306 q->ops->buf_release(q, q->bufs[i]);
314 int videobuf_mmap_free(struct videobuf_queue *q)
317 mutex_lock(&q->vb_lock);
318 ret = __videobuf_mmap_free(q);
319 mutex_unlock(&q->vb_lock);
323 /* Locking: Caller holds q->vb_lock */
324 static int __videobuf_mmap_setup(struct videobuf_queue *q,
325 unsigned int bcount, unsigned int bsize,
326 enum v4l2_memory memory)
331 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
333 err = __videobuf_mmap_free(q);
337 /* Allocate and initialize buffers */
338 for (i = 0; i < bcount; i++) {
339 q->bufs[i] = videobuf_alloc(q);
341 if (q->bufs[i] == NULL)
345 q->bufs[i]->input = UNSET;
346 q->bufs[i]->memory = memory;
347 q->bufs[i]->bsize = bsize;
349 case V4L2_MEMORY_MMAP:
350 q->bufs[i]->boff = bsize * i;
352 case V4L2_MEMORY_USERPTR:
353 case V4L2_MEMORY_OVERLAY:
362 dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
368 int videobuf_mmap_setup(struct videobuf_queue *q,
369 unsigned int bcount, unsigned int bsize,
370 enum v4l2_memory memory)
373 mutex_lock(&q->vb_lock);
374 ret = __videobuf_mmap_setup(q, bcount, bsize, memory);
375 mutex_unlock(&q->vb_lock);
379 int videobuf_reqbufs(struct videobuf_queue *q,
380 struct v4l2_requestbuffers *req)
382 unsigned int size, count;
385 if (req->count < 1) {
386 dprintk(1, "reqbufs: count invalid (%d)\n", req->count);
390 if (req->memory != V4L2_MEMORY_MMAP &&
391 req->memory != V4L2_MEMORY_USERPTR &&
392 req->memory != V4L2_MEMORY_OVERLAY) {
393 dprintk(1, "reqbufs: memory type invalid\n");
397 mutex_lock(&q->vb_lock);
398 if (req->type != q->type) {
399 dprintk(1, "reqbufs: queue type invalid\n");
405 dprintk(1, "reqbufs: streaming already exists\n");
409 if (!list_empty(&q->stream)) {
410 dprintk(1, "reqbufs: stream running\n");
416 if (count > VIDEO_MAX_FRAME)
417 count = VIDEO_MAX_FRAME;
419 q->ops->buf_setup(q, &count, &size);
420 size = PAGE_ALIGN(size);
421 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
422 count, size, (count*size)>>PAGE_SHIFT);
424 retval = __videobuf_mmap_setup(q, count, size, req->memory);
426 dprintk(1, "reqbufs: mmap setup returned %d\n", retval);
433 mutex_unlock(&q->vb_lock);
437 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
441 mutex_lock(&q->vb_lock);
442 if (unlikely(b->type != q->type)) {
443 dprintk(1, "querybuf: Wrong type.\n");
446 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
447 dprintk(1, "querybuf: index out of range.\n");
450 if (unlikely(NULL == q->bufs[b->index])) {
451 dprintk(1, "querybuf: buffer is null.\n");
455 videobuf_status(q, b, q->bufs[b->index], q->type);
459 mutex_unlock(&q->vb_lock);
463 int videobuf_qbuf(struct videobuf_queue *q,
464 struct v4l2_buffer *b)
466 struct videobuf_buffer *buf;
467 enum v4l2_field field;
468 unsigned long flags = 0;
471 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
473 if (b->memory == V4L2_MEMORY_MMAP)
474 down_read(¤t->mm->mmap_sem);
476 mutex_lock(&q->vb_lock);
479 dprintk(1, "qbuf: Reading running...\n");
483 if (b->type != q->type) {
484 dprintk(1, "qbuf: Wrong type.\n");
487 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
488 dprintk(1, "qbuf: index out of range.\n");
491 buf = q->bufs[b->index];
493 dprintk(1, "qbuf: buffer is null.\n");
496 MAGIC_CHECK(buf->magic, MAGIC_BUFFER);
497 if (buf->memory != b->memory) {
498 dprintk(1, "qbuf: memory type is wrong.\n");
501 if (buf->state != VIDEOBUF_NEEDS_INIT && buf->state != VIDEOBUF_IDLE) {
502 dprintk(1, "qbuf: buffer is already queued or active.\n");
506 if (b->flags & V4L2_BUF_FLAG_INPUT) {
507 if (b->input >= q->inputs) {
508 dprintk(1, "qbuf: wrong input.\n");
511 buf->input = b->input;
517 case V4L2_MEMORY_MMAP:
518 if (0 == buf->baddr) {
519 dprintk(1, "qbuf: mmap requested "
520 "but buffer addr is zero!\n");
524 case V4L2_MEMORY_USERPTR:
525 if (b->length < buf->bsize) {
526 dprintk(1, "qbuf: buffer length is not enough\n");
529 if (VIDEOBUF_NEEDS_INIT != buf->state &&
530 buf->baddr != b->m.userptr)
531 q->ops->buf_release(q, buf);
532 buf->baddr = b->m.userptr;
534 case V4L2_MEMORY_OVERLAY:
535 buf->boff = b->m.offset;
538 dprintk(1, "qbuf: wrong memory type\n");
542 dprintk(1, "qbuf: requesting next field\n");
543 field = videobuf_next_field(q);
544 retval = q->ops->buf_prepare(q, buf, field);
546 dprintk(1, "qbuf: buffer_prepare returned %d\n", retval);
550 list_add_tail(&buf->stream, &q->stream);
552 spin_lock_irqsave(q->irqlock, flags);
553 q->ops->buf_queue(q, buf);
554 spin_unlock_irqrestore(q->irqlock, flags);
556 dprintk(1, "qbuf: succeded\n");
558 wake_up_interruptible_sync(&q->wait);
561 mutex_unlock(&q->vb_lock);
563 if (b->memory == V4L2_MEMORY_MMAP)
564 up_read(¤t->mm->mmap_sem);
570 /* Locking: Caller holds q->vb_lock */
571 static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
577 dprintk(1, "next_buffer: Not streaming\n");
582 if (list_empty(&q->stream)) {
585 dprintk(2, "next_buffer: no buffers to dequeue\n");
588 dprintk(2, "next_buffer: waiting on buffer\n");
590 /* Drop lock to avoid deadlock with qbuf */
591 mutex_unlock(&q->vb_lock);
593 /* Checking list_empty and streaming is safe without
594 * locks because we goto checks to validate while
595 * holding locks before proceeding */
596 retval = wait_event_interruptible(q->wait,
597 !list_empty(&q->stream) || !q->streaming);
598 mutex_lock(&q->vb_lock);
614 /* Locking: Caller holds q->vb_lock */
615 static int stream_next_buffer(struct videobuf_queue *q,
616 struct videobuf_buffer **vb, int nonblocking)
619 struct videobuf_buffer *buf = NULL;
621 retval = stream_next_buffer_check_queue(q, nonblocking);
625 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
626 retval = videobuf_waiton(buf, nonblocking, 1);
635 int videobuf_dqbuf(struct videobuf_queue *q,
636 struct v4l2_buffer *b, int nonblocking)
638 struct videobuf_buffer *buf = NULL;
641 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
643 mutex_lock(&q->vb_lock);
645 retval = stream_next_buffer(q, &buf, nonblocking);
647 dprintk(1, "dqbuf: next_buffer error: %i\n", retval);
651 switch (buf->state) {
653 dprintk(1, "dqbuf: state is error\n");
655 CALL(q, sync, q, buf);
656 buf->state = VIDEOBUF_IDLE;
659 dprintk(1, "dqbuf: state is done\n");
660 CALL(q, sync, q, buf);
661 buf->state = VIDEOBUF_IDLE;
664 dprintk(1, "dqbuf: state invalid\n");
668 list_del(&buf->stream);
669 memset(b, 0, sizeof(*b));
670 videobuf_status(q, b, buf, q->type);
673 mutex_unlock(&q->vb_lock);
677 int videobuf_streamon(struct videobuf_queue *q)
679 struct videobuf_buffer *buf;
680 unsigned long flags = 0;
683 mutex_lock(&q->vb_lock);
691 spin_lock_irqsave(q->irqlock, flags);
692 list_for_each_entry(buf, &q->stream, stream)
693 if (buf->state == VIDEOBUF_PREPARED)
694 q->ops->buf_queue(q, buf);
695 spin_unlock_irqrestore(q->irqlock, flags);
697 wake_up_interruptible_sync(&q->wait);
699 mutex_unlock(&q->vb_lock);
703 /* Locking: Caller holds q->vb_lock */
704 static int __videobuf_streamoff(struct videobuf_queue *q)
709 videobuf_queue_cancel(q);
714 int videobuf_streamoff(struct videobuf_queue *q)
718 mutex_lock(&q->vb_lock);
719 retval = __videobuf_streamoff(q);
720 mutex_unlock(&q->vb_lock);
725 /* Locking: Caller holds q->vb_lock */
726 static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
728 size_t count, loff_t *ppos)
730 enum v4l2_field field;
731 unsigned long flags = 0;
734 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
737 q->read_buf = videobuf_alloc(q);
738 if (NULL == q->read_buf)
741 q->read_buf->memory = V4L2_MEMORY_USERPTR;
742 q->read_buf->baddr = (unsigned long)data;
743 q->read_buf->bsize = count;
745 field = videobuf_next_field(q);
746 retval = q->ops->buf_prepare(q, q->read_buf, field);
750 /* start capture & wait */
751 spin_lock_irqsave(q->irqlock, flags);
752 q->ops->buf_queue(q, q->read_buf);
753 spin_unlock_irqrestore(q->irqlock, flags);
754 retval = videobuf_waiton(q->read_buf, 0, 0);
756 CALL(q, sync, q, q->read_buf);
757 if (VIDEOBUF_ERROR == q->read_buf->state)
760 retval = q->read_buf->size;
765 q->ops->buf_release(q, q->read_buf);
771 ssize_t videobuf_read_one(struct videobuf_queue *q,
772 char __user *data, size_t count, loff_t *ppos,
775 enum v4l2_field field;
776 unsigned long flags = 0;
777 unsigned size = 0, nbufs = 1;
780 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
782 mutex_lock(&q->vb_lock);
784 q->ops->buf_setup(q, &nbufs, &size);
786 if (NULL == q->read_buf &&
789 retval = videobuf_read_zerocopy(q, data, count, ppos);
790 if (retval >= 0 || retval == -EIO)
793 /* fallback to kernel bounce buffer on failures */
796 if (NULL == q->read_buf) {
797 /* need to capture a new frame */
799 q->read_buf = videobuf_alloc(q);
801 dprintk(1, "video alloc=0x%p\n", q->read_buf);
802 if (NULL == q->read_buf)
804 q->read_buf->memory = V4L2_MEMORY_USERPTR;
805 q->read_buf->bsize = count; /* preferred size */
806 field = videobuf_next_field(q);
807 retval = q->ops->buf_prepare(q, q->read_buf, field);
815 spin_lock_irqsave(q->irqlock, flags);
816 q->ops->buf_queue(q, q->read_buf);
817 spin_unlock_irqrestore(q->irqlock, flags);
822 /* wait until capture is done */
823 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
827 CALL(q, sync, q, q->read_buf);
829 if (VIDEOBUF_ERROR == q->read_buf->state) {
830 /* catch I/O errors */
831 q->ops->buf_release(q, q->read_buf);
838 /* Copy to userspace */
839 retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
843 q->read_off += retval;
844 if (q->read_off == q->read_buf->size) {
845 /* all data copied, cleanup */
846 q->ops->buf_release(q, q->read_buf);
852 mutex_unlock(&q->vb_lock);
856 /* Locking: Caller holds q->vb_lock */
857 static int __videobuf_read_start(struct videobuf_queue *q)
859 enum v4l2_field field;
860 unsigned long flags = 0;
861 unsigned int count = 0, size = 0;
864 q->ops->buf_setup(q, &count, &size);
867 if (count > VIDEO_MAX_FRAME)
868 count = VIDEO_MAX_FRAME;
869 size = PAGE_ALIGN(size);
871 err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
877 for (i = 0; i < count; i++) {
878 field = videobuf_next_field(q);
879 err = q->ops->buf_prepare(q, q->bufs[i], field);
882 list_add_tail(&q->bufs[i]->stream, &q->stream);
884 spin_lock_irqsave(q->irqlock, flags);
885 for (i = 0; i < count; i++)
886 q->ops->buf_queue(q, q->bufs[i]);
887 spin_unlock_irqrestore(q->irqlock, flags);
892 static void __videobuf_read_stop(struct videobuf_queue *q)
896 videobuf_queue_cancel(q);
897 __videobuf_mmap_free(q);
898 INIT_LIST_HEAD(&q->stream);
899 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
900 if (NULL == q->bufs[i])
909 int videobuf_read_start(struct videobuf_queue *q)
913 mutex_lock(&q->vb_lock);
914 rc = __videobuf_read_start(q);
915 mutex_unlock(&q->vb_lock);
920 void videobuf_read_stop(struct videobuf_queue *q)
922 mutex_lock(&q->vb_lock);
923 __videobuf_read_stop(q);
924 mutex_unlock(&q->vb_lock);
927 void videobuf_stop(struct videobuf_queue *q)
929 mutex_lock(&q->vb_lock);
932 __videobuf_streamoff(q);
935 __videobuf_read_stop(q);
937 mutex_unlock(&q->vb_lock);
941 ssize_t videobuf_read_stream(struct videobuf_queue *q,
942 char __user *data, size_t count, loff_t *ppos,
943 int vbihack, int nonblocking)
946 unsigned long flags = 0;
948 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
950 dprintk(2, "%s\n", __func__);
951 mutex_lock(&q->vb_lock);
956 retval = __videobuf_read_start(q);
963 /* get / wait for data */
964 if (NULL == q->read_buf) {
965 q->read_buf = list_entry(q->stream.next,
966 struct videobuf_buffer,
968 list_del(&q->read_buf->stream);
971 rc = videobuf_waiton(q->read_buf, nonblocking, 1);
978 if (q->read_buf->state == VIDEOBUF_DONE) {
979 rc = CALL(q, copy_stream, q, data + retval, count,
980 retval, vbihack, nonblocking);
990 q->read_off = q->read_buf->size;
995 /* requeue buffer when done with copying */
996 if (q->read_off == q->read_buf->size) {
997 list_add_tail(&q->read_buf->stream,
999 spin_lock_irqsave(q->irqlock, flags);
1000 q->ops->buf_queue(q, q->read_buf);
1001 spin_unlock_irqrestore(q->irqlock, flags);
1009 mutex_unlock(&q->vb_lock);
1013 unsigned int videobuf_poll_stream(struct file *file,
1014 struct videobuf_queue *q,
1017 struct videobuf_buffer *buf = NULL;
1018 unsigned int rc = 0;
1020 mutex_lock(&q->vb_lock);
1022 if (!list_empty(&q->stream))
1023 buf = list_entry(q->stream.next,
1024 struct videobuf_buffer, stream);
1027 __videobuf_read_start(q);
1030 } else if (NULL == q->read_buf) {
1031 q->read_buf = list_entry(q->stream.next,
1032 struct videobuf_buffer,
1034 list_del(&q->read_buf->stream);
1043 poll_wait(file, &buf->done, wait);
1044 if (buf->state == VIDEOBUF_DONE ||
1045 buf->state == VIDEOBUF_ERROR)
1046 rc = POLLIN|POLLRDNORM;
1048 mutex_unlock(&q->vb_lock);
1052 int videobuf_mmap_mapper(struct videobuf_queue *q,
1053 struct vm_area_struct *vma)
1057 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1059 mutex_lock(&q->vb_lock);
1060 retval = CALL(q, mmap_mapper, q, vma);
1062 mutex_unlock(&q->vb_lock);
1067 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1068 int videobuf_cgmbuf(struct videobuf_queue *q,
1069 struct video_mbuf *mbuf, int count)
1071 struct v4l2_requestbuffers req;
1074 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1076 memset(&req, 0, sizeof(req));
1079 req.memory = V4L2_MEMORY_MMAP;
1080 rc = videobuf_reqbufs(q, &req);
1084 mbuf->frames = req.count;
1086 for (i = 0; i < mbuf->frames; i++) {
1087 mbuf->offsets[i] = q->bufs[i]->boff;
1088 mbuf->size += q->bufs[i]->bsize;
1093 EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
1096 /* --------------------------------------------------------------------- */
1098 EXPORT_SYMBOL_GPL(videobuf_waiton);
1099 EXPORT_SYMBOL_GPL(videobuf_iolock);
1101 EXPORT_SYMBOL_GPL(videobuf_alloc);
1103 EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
1104 EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
1105 EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
1107 EXPORT_SYMBOL_GPL(videobuf_next_field);
1108 EXPORT_SYMBOL_GPL(videobuf_reqbufs);
1109 EXPORT_SYMBOL_GPL(videobuf_querybuf);
1110 EXPORT_SYMBOL_GPL(videobuf_qbuf);
1111 EXPORT_SYMBOL_GPL(videobuf_dqbuf);
1112 EXPORT_SYMBOL_GPL(videobuf_streamon);
1113 EXPORT_SYMBOL_GPL(videobuf_streamoff);
1115 EXPORT_SYMBOL_GPL(videobuf_read_start);
1116 EXPORT_SYMBOL_GPL(videobuf_read_stop);
1117 EXPORT_SYMBOL_GPL(videobuf_stop);
1118 EXPORT_SYMBOL_GPL(videobuf_read_stream);
1119 EXPORT_SYMBOL_GPL(videobuf_read_one);
1120 EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1122 EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1123 EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1124 EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);