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 /* Having implementations for abstract methods are mandatory */
129 mutex_init(&q->vb_lock);
130 init_waitqueue_head(&q->wait);
131 INIT_LIST_HEAD(&q->stream);
134 /* Locking: Only usage in bttv unsafe find way to remove */
135 int videobuf_queue_is_busy(struct videobuf_queue *q)
139 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
142 dprintk(1, "busy: streaming active\n");
146 dprintk(1, "busy: pending read #1\n");
150 dprintk(1, "busy: pending read #2\n");
153 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
154 if (NULL == q->bufs[i])
156 if (q->bufs[i]->map) {
157 dprintk(1, "busy: buffer #%d mapped\n", i);
160 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
161 dprintk(1, "busy: buffer #%d queued\n", i);
164 if (q->bufs[i]->state == VIDEOBUF_ACTIVE) {
165 dprintk(1, "busy: buffer #%d avtive\n", i);
172 /* Locking: Caller holds q->vb_lock */
173 void videobuf_queue_cancel(struct videobuf_queue *q)
175 unsigned long flags = 0;
180 wake_up_interruptible_sync(&q->wait);
182 /* remove queued buffers from list */
184 spin_lock_irqsave(q->irqlock, flags);
185 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
186 if (NULL == q->bufs[i])
188 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
189 list_del(&q->bufs[i]->queue);
190 q->bufs[i]->state = VIDEOBUF_ERROR;
191 wake_up_all(&q->bufs[i]->done);
195 spin_unlock_irqrestore(q->irqlock, flags);
197 /* free all buffers + clear queue */
198 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
199 if (NULL == q->bufs[i])
201 q->ops->buf_release(q, q->bufs[i]);
203 INIT_LIST_HEAD(&q->stream);
206 /* --------------------------------------------------------------------- */
208 /* Locking: Caller holds q->vb_lock */
209 enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
211 enum v4l2_field field = q->field;
213 BUG_ON(V4L2_FIELD_ANY == field);
215 if (V4L2_FIELD_ALTERNATE == field) {
216 if (V4L2_FIELD_TOP == q->last) {
217 field = V4L2_FIELD_BOTTOM;
218 q->last = V4L2_FIELD_BOTTOM;
220 field = V4L2_FIELD_TOP;
221 q->last = V4L2_FIELD_TOP;
227 /* Locking: Caller holds q->vb_lock */
228 static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
229 struct videobuf_buffer *vb, enum v4l2_buf_type type)
231 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
232 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
237 b->memory = vb->memory;
239 case V4L2_MEMORY_MMAP:
240 b->m.offset = vb->boff;
241 b->length = vb->bsize;
243 case V4L2_MEMORY_USERPTR:
244 b->m.userptr = vb->baddr;
245 b->length = vb->bsize;
247 case V4L2_MEMORY_OVERLAY:
248 b->m.offset = vb->boff;
254 b->flags |= V4L2_BUF_FLAG_MAPPED;
257 case VIDEOBUF_PREPARED:
258 case VIDEOBUF_QUEUED:
259 case VIDEOBUF_ACTIVE:
260 b->flags |= V4L2_BUF_FLAG_QUEUED;
264 b->flags |= V4L2_BUF_FLAG_DONE;
266 case VIDEOBUF_NEEDS_INIT:
272 if (vb->input != UNSET) {
273 b->flags |= V4L2_BUF_FLAG_INPUT;
274 b->input = vb->input;
277 b->field = vb->field;
278 b->timestamp = vb->ts;
279 b->bytesused = vb->size;
280 b->sequence = vb->field_count >> 1;
283 /* Locking: Caller holds q->vb_lock */
284 static int __videobuf_mmap_free(struct videobuf_queue *q)
292 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
295 rc = CALL(q, mmap_free, q);
302 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
303 if (NULL == q->bufs[i])
305 q->ops->buf_release(q, q->bufs[i]);
313 int videobuf_mmap_free(struct videobuf_queue *q)
316 mutex_lock(&q->vb_lock);
317 ret = __videobuf_mmap_free(q);
318 mutex_unlock(&q->vb_lock);
322 /* Locking: Caller holds q->vb_lock */
323 static int __videobuf_mmap_setup(struct videobuf_queue *q,
324 unsigned int bcount, unsigned int bsize,
325 enum v4l2_memory memory)
330 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
332 err = __videobuf_mmap_free(q);
336 /* Allocate and initialize buffers */
337 for (i = 0; i < bcount; i++) {
338 q->bufs[i] = videobuf_alloc(q);
340 if (q->bufs[i] == NULL)
344 q->bufs[i]->input = UNSET;
345 q->bufs[i]->memory = memory;
346 q->bufs[i]->bsize = bsize;
348 case V4L2_MEMORY_MMAP:
349 q->bufs[i]->boff = bsize * i;
351 case V4L2_MEMORY_USERPTR:
352 case V4L2_MEMORY_OVERLAY:
361 dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
367 int videobuf_mmap_setup(struct videobuf_queue *q,
368 unsigned int bcount, unsigned int bsize,
369 enum v4l2_memory memory)
372 mutex_lock(&q->vb_lock);
373 ret = __videobuf_mmap_setup(q, bcount, bsize, memory);
374 mutex_unlock(&q->vb_lock);
378 int videobuf_reqbufs(struct videobuf_queue *q,
379 struct v4l2_requestbuffers *req)
381 unsigned int size, count;
384 if (req->count < 1) {
385 dprintk(1, "reqbufs: count invalid (%d)\n", req->count);
389 if (req->memory != V4L2_MEMORY_MMAP &&
390 req->memory != V4L2_MEMORY_USERPTR &&
391 req->memory != V4L2_MEMORY_OVERLAY) {
392 dprintk(1, "reqbufs: memory type invalid\n");
396 mutex_lock(&q->vb_lock);
397 if (req->type != q->type) {
398 dprintk(1, "reqbufs: queue type invalid\n");
404 dprintk(1, "reqbufs: streaming already exists\n");
408 if (!list_empty(&q->stream)) {
409 dprintk(1, "reqbufs: stream running\n");
415 if (count > VIDEO_MAX_FRAME)
416 count = VIDEO_MAX_FRAME;
418 q->ops->buf_setup(q, &count, &size);
419 size = PAGE_ALIGN(size);
420 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
421 count, size, (count*size)>>PAGE_SHIFT);
423 retval = __videobuf_mmap_setup(q, count, size, req->memory);
425 dprintk(1, "reqbufs: mmap setup returned %d\n", retval);
432 mutex_unlock(&q->vb_lock);
436 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
440 mutex_lock(&q->vb_lock);
441 if (unlikely(b->type != q->type)) {
442 dprintk(1, "querybuf: Wrong type.\n");
445 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
446 dprintk(1, "querybuf: index out of range.\n");
449 if (unlikely(NULL == q->bufs[b->index])) {
450 dprintk(1, "querybuf: buffer is null.\n");
454 videobuf_status(q, b, q->bufs[b->index], q->type);
458 mutex_unlock(&q->vb_lock);
462 int videobuf_qbuf(struct videobuf_queue *q,
463 struct v4l2_buffer *b)
465 struct videobuf_buffer *buf;
466 enum v4l2_field field;
467 unsigned long flags = 0;
470 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
472 if (b->memory == V4L2_MEMORY_MMAP)
473 down_read(¤t->mm->mmap_sem);
475 mutex_lock(&q->vb_lock);
478 dprintk(1, "qbuf: Reading running...\n");
482 if (b->type != q->type) {
483 dprintk(1, "qbuf: Wrong type.\n");
486 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
487 dprintk(1, "qbuf: index out of range.\n");
490 buf = q->bufs[b->index];
492 dprintk(1, "qbuf: buffer is null.\n");
495 MAGIC_CHECK(buf->magic, MAGIC_BUFFER);
496 if (buf->memory != b->memory) {
497 dprintk(1, "qbuf: memory type is wrong.\n");
500 if (buf->state != VIDEOBUF_NEEDS_INIT && buf->state != VIDEOBUF_IDLE) {
501 dprintk(1, "qbuf: buffer is already queued or active.\n");
505 if (b->flags & V4L2_BUF_FLAG_INPUT) {
506 if (b->input >= q->inputs) {
507 dprintk(1, "qbuf: wrong input.\n");
510 buf->input = b->input;
516 case V4L2_MEMORY_MMAP:
517 if (0 == buf->baddr) {
518 dprintk(1, "qbuf: mmap requested "
519 "but buffer addr is zero!\n");
523 case V4L2_MEMORY_USERPTR:
524 if (b->length < buf->bsize) {
525 dprintk(1, "qbuf: buffer length is not enough\n");
528 if (VIDEOBUF_NEEDS_INIT != buf->state &&
529 buf->baddr != b->m.userptr)
530 q->ops->buf_release(q, buf);
531 buf->baddr = b->m.userptr;
533 case V4L2_MEMORY_OVERLAY:
534 buf->boff = b->m.offset;
537 dprintk(1, "qbuf: wrong memory type\n");
541 dprintk(1, "qbuf: requesting next field\n");
542 field = videobuf_next_field(q);
543 retval = q->ops->buf_prepare(q, buf, field);
545 dprintk(1, "qbuf: buffer_prepare returned %d\n", retval);
549 list_add_tail(&buf->stream, &q->stream);
552 spin_lock_irqsave(q->irqlock, flags);
553 q->ops->buf_queue(q, buf);
555 spin_unlock_irqrestore(q->irqlock, flags);
557 dprintk(1, "qbuf: succeded\n");
559 wake_up_interruptible_sync(&q->wait);
562 mutex_unlock(&q->vb_lock);
564 if (b->memory == V4L2_MEMORY_MMAP)
565 up_read(¤t->mm->mmap_sem);
571 /* Locking: Caller holds q->vb_lock */
572 static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
578 dprintk(1, "next_buffer: Not streaming\n");
583 if (list_empty(&q->stream)) {
586 dprintk(2, "next_buffer: no buffers to dequeue\n");
589 dprintk(2, "next_buffer: waiting on buffer\n");
591 /* Drop lock to avoid deadlock with qbuf */
592 mutex_unlock(&q->vb_lock);
594 /* Checking list_empty and streaming is safe without
595 * locks because we goto checks to validate while
596 * holding locks before proceeding */
597 retval = wait_event_interruptible(q->wait,
598 !list_empty(&q->stream) || !q->streaming);
599 mutex_lock(&q->vb_lock);
615 /* Locking: Caller holds q->vb_lock */
616 static int stream_next_buffer(struct videobuf_queue *q,
617 struct videobuf_buffer **vb, int nonblocking)
620 struct videobuf_buffer *buf = NULL;
622 retval = stream_next_buffer_check_queue(q, nonblocking);
626 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
627 retval = videobuf_waiton(buf, nonblocking, 1);
636 int videobuf_dqbuf(struct videobuf_queue *q,
637 struct v4l2_buffer *b, int nonblocking)
639 struct videobuf_buffer *buf = NULL;
642 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
644 mutex_lock(&q->vb_lock);
646 retval = stream_next_buffer(q, &buf, nonblocking);
648 dprintk(1, "dqbuf: next_buffer error: %i\n", retval);
652 switch (buf->state) {
654 dprintk(1, "dqbuf: state is error\n");
656 CALL(q, sync, q, buf);
657 buf->state = VIDEOBUF_IDLE;
660 dprintk(1, "dqbuf: state is done\n");
661 CALL(q, sync, q, buf);
662 buf->state = VIDEOBUF_IDLE;
665 dprintk(1, "dqbuf: state invalid\n");
669 list_del(&buf->stream);
670 memset(b, 0, sizeof(*b));
671 videobuf_status(q, b, buf, q->type);
674 mutex_unlock(&q->vb_lock);
678 int videobuf_streamon(struct videobuf_queue *q)
680 struct videobuf_buffer *buf;
681 unsigned long flags = 0;
684 mutex_lock(&q->vb_lock);
693 spin_lock_irqsave(q->irqlock, flags);
694 list_for_each_entry(buf, &q->stream, stream)
695 if (buf->state == VIDEOBUF_PREPARED)
696 q->ops->buf_queue(q, buf);
698 spin_unlock_irqrestore(q->irqlock, flags);
700 wake_up_interruptible_sync(&q->wait);
702 mutex_unlock(&q->vb_lock);
706 /* Locking: Caller holds q->vb_lock */
707 static int __videobuf_streamoff(struct videobuf_queue *q)
712 videobuf_queue_cancel(q);
717 int videobuf_streamoff(struct videobuf_queue *q)
721 mutex_lock(&q->vb_lock);
722 retval = __videobuf_streamoff(q);
723 mutex_unlock(&q->vb_lock);
728 /* Locking: Caller holds q->vb_lock */
729 static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
731 size_t count, loff_t *ppos)
733 enum v4l2_field field;
734 unsigned long flags = 0;
737 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
740 q->read_buf = videobuf_alloc(q);
741 if (NULL == q->read_buf)
744 q->read_buf->memory = V4L2_MEMORY_USERPTR;
745 q->read_buf->baddr = (unsigned long)data;
746 q->read_buf->bsize = count;
748 field = videobuf_next_field(q);
749 retval = q->ops->buf_prepare(q, q->read_buf, field);
753 /* start capture & wait */
755 spin_lock_irqsave(q->irqlock, flags);
756 q->ops->buf_queue(q, q->read_buf);
758 spin_unlock_irqrestore(q->irqlock, flags);
759 retval = videobuf_waiton(q->read_buf, 0, 0);
761 CALL(q, sync, q, q->read_buf);
762 if (VIDEOBUF_ERROR == q->read_buf->state)
765 retval = q->read_buf->size;
770 q->ops->buf_release(q, q->read_buf);
776 ssize_t videobuf_read_one(struct videobuf_queue *q,
777 char __user *data, size_t count, loff_t *ppos,
780 enum v4l2_field field;
781 unsigned long flags = 0;
782 unsigned size = 0, nbufs = 1;
785 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
787 mutex_lock(&q->vb_lock);
789 q->ops->buf_setup(q, &nbufs, &size);
791 if (NULL == q->read_buf &&
794 retval = videobuf_read_zerocopy(q, data, count, ppos);
795 if (retval >= 0 || retval == -EIO)
798 /* fallback to kernel bounce buffer on failures */
801 if (NULL == q->read_buf) {
802 /* need to capture a new frame */
804 q->read_buf = videobuf_alloc(q);
806 dprintk(1, "video alloc=0x%p\n", q->read_buf);
807 if (NULL == q->read_buf)
809 q->read_buf->memory = V4L2_MEMORY_USERPTR;
810 q->read_buf->bsize = count; /* preferred size */
811 field = videobuf_next_field(q);
812 retval = q->ops->buf_prepare(q, q->read_buf, field);
820 spin_lock_irqsave(q->irqlock, flags);
822 q->ops->buf_queue(q, q->read_buf);
824 spin_unlock_irqrestore(q->irqlock, flags);
828 /* wait until capture is done */
829 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
833 CALL(q, sync, q, q->read_buf);
835 if (VIDEOBUF_ERROR == q->read_buf->state) {
836 /* catch I/O errors */
837 q->ops->buf_release(q, q->read_buf);
844 /* Copy to userspace */
845 retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
849 q->read_off += retval;
850 if (q->read_off == q->read_buf->size) {
851 /* all data copied, cleanup */
852 q->ops->buf_release(q, q->read_buf);
858 mutex_unlock(&q->vb_lock);
862 /* Locking: Caller holds q->vb_lock */
863 static int __videobuf_read_start(struct videobuf_queue *q)
865 enum v4l2_field field;
866 unsigned long flags = 0;
867 unsigned int count = 0, size = 0;
870 q->ops->buf_setup(q, &count, &size);
873 if (count > VIDEO_MAX_FRAME)
874 count = VIDEO_MAX_FRAME;
875 size = PAGE_ALIGN(size);
877 err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
883 for (i = 0; i < count; i++) {
884 field = videobuf_next_field(q);
885 err = q->ops->buf_prepare(q, q->bufs[i], field);
888 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]);
895 spin_unlock_irqrestore(q->irqlock, flags);
900 static void __videobuf_read_stop(struct videobuf_queue *q)
905 videobuf_queue_cancel(q);
906 __videobuf_mmap_free(q);
907 INIT_LIST_HEAD(&q->stream);
908 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
909 if (NULL == q->bufs[i])
918 int videobuf_read_start(struct videobuf_queue *q)
922 mutex_lock(&q->vb_lock);
923 rc = __videobuf_read_start(q);
924 mutex_unlock(&q->vb_lock);
929 void videobuf_read_stop(struct videobuf_queue *q)
931 mutex_lock(&q->vb_lock);
932 __videobuf_read_stop(q);
933 mutex_unlock(&q->vb_lock);
936 void videobuf_stop(struct videobuf_queue *q)
938 mutex_lock(&q->vb_lock);
941 __videobuf_streamoff(q);
944 __videobuf_read_stop(q);
946 mutex_unlock(&q->vb_lock);
950 ssize_t videobuf_read_stream(struct videobuf_queue *q,
951 char __user *data, size_t count, loff_t *ppos,
952 int vbihack, int nonblocking)
955 unsigned long flags = 0;
957 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
959 dprintk(2, "%s\n", __func__);
960 mutex_lock(&q->vb_lock);
965 retval = __videobuf_read_start(q);
972 /* get / wait for data */
973 if (NULL == q->read_buf) {
974 q->read_buf = list_entry(q->stream.next,
975 struct videobuf_buffer,
977 list_del(&q->read_buf->stream);
980 rc = videobuf_waiton(q->read_buf, nonblocking, 1);
987 if (q->read_buf->state == VIDEOBUF_DONE) {
988 rc = CALL(q, copy_stream, q, data + retval, count,
989 retval, vbihack, nonblocking);
999 q->read_off = q->read_buf->size;
1004 /* requeue buffer when done with copying */
1005 if (q->read_off == q->read_buf->size) {
1006 list_add_tail(&q->read_buf->stream,
1009 spin_lock_irqsave(q->irqlock, flags);
1010 q->ops->buf_queue(q, q->read_buf);
1012 spin_unlock_irqrestore(q->irqlock, flags);
1020 mutex_unlock(&q->vb_lock);
1024 unsigned int videobuf_poll_stream(struct file *file,
1025 struct videobuf_queue *q,
1028 struct videobuf_buffer *buf = NULL;
1029 unsigned int rc = 0;
1031 mutex_lock(&q->vb_lock);
1033 if (!list_empty(&q->stream))
1034 buf = list_entry(q->stream.next,
1035 struct videobuf_buffer, stream);
1038 __videobuf_read_start(q);
1041 } else if (NULL == q->read_buf) {
1042 q->read_buf = list_entry(q->stream.next,
1043 struct videobuf_buffer,
1045 list_del(&q->read_buf->stream);
1054 poll_wait(file, &buf->done, wait);
1055 if (buf->state == VIDEOBUF_DONE ||
1056 buf->state == VIDEOBUF_ERROR)
1057 rc = POLLIN|POLLRDNORM;
1059 mutex_unlock(&q->vb_lock);
1063 int videobuf_mmap_mapper(struct videobuf_queue *q,
1064 struct vm_area_struct *vma)
1068 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1070 mutex_lock(&q->vb_lock);
1071 retval = CALL(q, mmap_mapper, q, vma);
1073 mutex_unlock(&q->vb_lock);
1078 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1079 int videobuf_cgmbuf(struct videobuf_queue *q,
1080 struct video_mbuf *mbuf, int count)
1082 struct v4l2_requestbuffers req;
1085 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1087 memset(&req, 0, sizeof(req));
1090 req.memory = V4L2_MEMORY_MMAP;
1091 rc = videobuf_reqbufs(q, &req);
1095 mbuf->frames = req.count;
1097 for (i = 0; i < mbuf->frames; i++) {
1098 mbuf->offsets[i] = q->bufs[i]->boff;
1099 mbuf->size += q->bufs[i]->bsize;
1104 EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
1107 /* --------------------------------------------------------------------- */
1109 EXPORT_SYMBOL_GPL(videobuf_waiton);
1110 EXPORT_SYMBOL_GPL(videobuf_iolock);
1112 EXPORT_SYMBOL_GPL(videobuf_alloc);
1114 EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
1115 EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
1116 EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
1118 EXPORT_SYMBOL_GPL(videobuf_next_field);
1119 EXPORT_SYMBOL_GPL(videobuf_reqbufs);
1120 EXPORT_SYMBOL_GPL(videobuf_querybuf);
1121 EXPORT_SYMBOL_GPL(videobuf_qbuf);
1122 EXPORT_SYMBOL_GPL(videobuf_dqbuf);
1123 EXPORT_SYMBOL_GPL(videobuf_streamon);
1124 EXPORT_SYMBOL_GPL(videobuf_streamoff);
1126 EXPORT_SYMBOL_GPL(videobuf_read_start);
1127 EXPORT_SYMBOL_GPL(videobuf_read_stop);
1128 EXPORT_SYMBOL_GPL(videobuf_stop);
1129 EXPORT_SYMBOL_GPL(videobuf_read_stream);
1130 EXPORT_SYMBOL_GPL(videobuf_read_one);
1131 EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1133 EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1134 EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1135 EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);