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 int videobuf_waiton(struct videobuf_buffer
*vb
, int non_blocking
, int intr
)
70 DECLARE_WAITQUEUE(wait
, current
);
72 MAGIC_CHECK(vb
->magic
, MAGIC_BUFFER
);
73 add_wait_queue(&vb
->done
, &wait
);
74 while (vb
->state
== VIDEOBUF_ACTIVE
|| vb
->state
== VIDEOBUF_QUEUED
) {
79 set_current_state(intr
? TASK_INTERRUPTIBLE
80 : TASK_UNINTERRUPTIBLE
);
81 if (vb
->state
== VIDEOBUF_ACTIVE
||
82 vb
->state
== VIDEOBUF_QUEUED
)
84 set_current_state(TASK_RUNNING
);
85 if (intr
&& signal_pending(current
)) {
86 dprintk(1, "buffer waiton: -EINTR\n");
91 remove_wait_queue(&vb
->done
, &wait
);
95 int videobuf_iolock(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
96 struct v4l2_framebuffer
*fbuf
)
98 MAGIC_CHECK(vb
->magic
, MAGIC_BUFFER
);
99 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
101 /* This is required to avoid OOPS on some cases,
102 since mmap_mapper() method should be called before _iolock.
103 On some cases, the mmap_mapper() is called only after scheduling.
105 if (vb
->memory
== V4L2_MEMORY_MMAP
) {
106 wait_event_timeout(vb
->done
, q
->is_mmapped
,
107 msecs_to_jiffies(100));
108 if (!q
->is_mmapped
) {
110 "Error: mmap_mapper() never called!\n");
115 return CALL(q
, iolock
, q
, vb
, fbuf
);
118 /* --------------------------------------------------------------------- */
121 void videobuf_queue_core_init(struct videobuf_queue
*q
,
122 struct videobuf_queue_ops
*ops
,
125 enum v4l2_buf_type type
,
126 enum v4l2_field field
,
129 struct videobuf_qtype_ops
*int_ops
)
131 memset(q
, 0, sizeof(*q
));
132 q
->irqlock
= irqlock
;
139 q
->int_ops
= int_ops
;
141 /* All buffer operations are mandatory */
142 BUG_ON(!q
->ops
->buf_setup
);
143 BUG_ON(!q
->ops
->buf_prepare
);
144 BUG_ON(!q
->ops
->buf_queue
);
145 BUG_ON(!q
->ops
->buf_release
);
147 /* Having implementations for abstract methods are mandatory */
150 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
151 mutex_init(&q
->lock
);
153 mutex_init(&q
->vb_lock
);
154 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
155 INIT_LIST_HEAD(&q
->stream
);
158 /* Locking: Only usage in bttv unsafe find way to remove */
159 int videobuf_queue_is_busy(struct videobuf_queue
*q
)
163 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
166 dprintk(1, "busy: streaming active\n");
170 dprintk(1, "busy: pending read #1\n");
174 dprintk(1, "busy: pending read #2\n");
177 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
178 if (NULL
== q
->bufs
[i
])
180 if (q
->bufs
[i
]->map
) {
181 dprintk(1, "busy: buffer #%d mapped\n", i
);
184 if (q
->bufs
[i
]->state
== VIDEOBUF_QUEUED
) {
185 dprintk(1, "busy: buffer #%d queued\n", i
);
188 if (q
->bufs
[i
]->state
== VIDEOBUF_ACTIVE
) {
189 dprintk(1, "busy: buffer #%d avtive\n", i
);
196 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
197 /* Locking: Caller holds q->lock */
199 /* Locking: Caller holds q->vb_lock */
200 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
201 void videobuf_queue_cancel(struct videobuf_queue
*q
)
203 unsigned long flags
= 0;
206 /* remove queued buffers from list */
208 spin_lock_irqsave(q
->irqlock
, flags
);
209 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
210 if (NULL
== q
->bufs
[i
])
212 if (q
->bufs
[i
]->state
== VIDEOBUF_QUEUED
) {
213 list_del(&q
->bufs
[i
]->queue
);
214 q
->bufs
[i
]->state
= VIDEOBUF_ERROR
;
218 spin_unlock_irqrestore(q
->irqlock
, flags
);
220 /* free all buffers + clear queue */
221 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
222 if (NULL
== q
->bufs
[i
])
224 q
->ops
->buf_release(q
, q
->bufs
[i
]);
226 INIT_LIST_HEAD(&q
->stream
);
229 /* --------------------------------------------------------------------- */
231 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
232 /* Locking: Caller holds q->lock */
234 /* Locking: Caller holds q->vb_lock */
235 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
236 enum v4l2_field
videobuf_next_field(struct videobuf_queue
*q
)
238 enum v4l2_field field
= q
->field
;
240 BUG_ON(V4L2_FIELD_ANY
== field
);
242 if (V4L2_FIELD_ALTERNATE
== field
) {
243 if (V4L2_FIELD_TOP
== q
->last
) {
244 field
= V4L2_FIELD_BOTTOM
;
245 q
->last
= V4L2_FIELD_BOTTOM
;
247 field
= V4L2_FIELD_TOP
;
248 q
->last
= V4L2_FIELD_TOP
;
254 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
255 /* Locking: Caller holds q->lock */
257 /* Locking: Caller holds q->vb_lock */
258 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
259 static void videobuf_status(struct videobuf_queue
*q
, struct v4l2_buffer
*b
,
260 struct videobuf_buffer
*vb
, enum v4l2_buf_type type
)
262 MAGIC_CHECK(vb
->magic
, MAGIC_BUFFER
);
263 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
268 b
->memory
= vb
->memory
;
270 case V4L2_MEMORY_MMAP
:
271 b
->m
.offset
= vb
->boff
;
272 b
->length
= vb
->bsize
;
274 case V4L2_MEMORY_USERPTR
:
275 b
->m
.userptr
= vb
->baddr
;
276 b
->length
= vb
->bsize
;
278 case V4L2_MEMORY_OVERLAY
:
279 b
->m
.offset
= vb
->boff
;
285 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
288 case VIDEOBUF_PREPARED
:
289 case VIDEOBUF_QUEUED
:
290 case VIDEOBUF_ACTIVE
:
291 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
295 b
->flags
|= V4L2_BUF_FLAG_DONE
;
297 case VIDEOBUF_NEEDS_INIT
:
303 if (vb
->input
!= UNSET
) {
304 b
->flags
|= V4L2_BUF_FLAG_INPUT
;
305 b
->input
= vb
->input
;
308 b
->field
= vb
->field
;
309 b
->timestamp
= vb
->ts
;
310 b
->bytesused
= vb
->size
;
311 b
->sequence
= vb
->field_count
>> 1;
314 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
315 /* Locking: Caller holds q->lock */
317 /* Locking: Caller holds q->vb_lock */
318 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
319 static int __videobuf_mmap_free(struct videobuf_queue
*q
)
327 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
330 rc
= CALL(q
, mmap_free
, q
);
337 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
338 if (NULL
== q
->bufs
[i
])
340 q
->ops
->buf_release(q
, q
->bufs
[i
]);
348 int videobuf_mmap_free(struct videobuf_queue
*q
)
351 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
352 mutex_lock(&q
->lock
);
354 mutex_lock(&q
->vb_lock
);
355 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
356 ret
= __videobuf_mmap_free(q
);
357 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
358 mutex_unlock(&q
->lock
);
360 mutex_unlock(&q
->vb_lock
);
361 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
365 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
366 /* Locking: Caller holds q->lock */
368 /* Locking: Caller holds q->vb_lock */
369 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
370 static int __videobuf_mmap_setup(struct videobuf_queue
*q
,
371 unsigned int bcount
, unsigned int bsize
,
372 enum v4l2_memory memory
)
377 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
379 err
= __videobuf_mmap_free(q
);
383 /* Allocate and initialize buffers */
384 for (i
= 0; i
< bcount
; i
++) {
385 q
->bufs
[i
] = videobuf_alloc(q
);
387 if (q
->bufs
[i
] == NULL
)
391 q
->bufs
[i
]->input
= UNSET
;
392 q
->bufs
[i
]->memory
= memory
;
393 q
->bufs
[i
]->bsize
= bsize
;
395 case V4L2_MEMORY_MMAP
:
396 q
->bufs
[i
]->boff
= bsize
* i
;
398 case V4L2_MEMORY_USERPTR
:
399 case V4L2_MEMORY_OVERLAY
:
408 dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
414 int videobuf_mmap_setup(struct videobuf_queue
*q
,
415 unsigned int bcount
, unsigned int bsize
,
416 enum v4l2_memory memory
)
419 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
420 mutex_lock(&q
->lock
);
422 mutex_lock(&q
->vb_lock
);
423 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
424 ret
= __videobuf_mmap_setup(q
, bcount
, bsize
, memory
);
425 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
426 mutex_unlock(&q
->lock
);
428 mutex_unlock(&q
->vb_lock
);
429 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
433 int videobuf_reqbufs(struct videobuf_queue
*q
,
434 struct v4l2_requestbuffers
*req
)
436 unsigned int size
, count
;
439 if (req
->count
< 1) {
440 dprintk(1, "reqbufs: count invalid (%d)\n", req
->count
);
444 if (req
->memory
!= V4L2_MEMORY_MMAP
&&
445 req
->memory
!= V4L2_MEMORY_USERPTR
&&
446 req
->memory
!= V4L2_MEMORY_OVERLAY
) {
447 dprintk(1, "reqbufs: memory type invalid\n");
451 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
452 mutex_lock(&q
->lock
);
454 mutex_lock(&q
->vb_lock
);
455 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
456 if (req
->type
!= q
->type
) {
457 dprintk(1, "reqbufs: queue type invalid\n");
463 dprintk(1, "reqbufs: streaming already exists\n");
467 if (!list_empty(&q
->stream
)) {
468 dprintk(1, "reqbufs: stream running\n");
474 if (count
> VIDEO_MAX_FRAME
)
475 count
= VIDEO_MAX_FRAME
;
477 q
->ops
->buf_setup(q
, &count
, &size
);
478 size
= PAGE_ALIGN(size
);
479 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
480 count
, size
, (count
*size
)>>PAGE_SHIFT
);
482 retval
= __videobuf_mmap_setup(q
, count
, size
, req
->memory
);
484 dprintk(1, "reqbufs: mmap setup returned %d\n", retval
);
491 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
492 mutex_unlock(&q
->lock
);
494 mutex_unlock(&q
->vb_lock
);
495 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
499 int videobuf_querybuf(struct videobuf_queue
*q
, struct v4l2_buffer
*b
)
503 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
504 mutex_lock(&q
->lock
);
506 mutex_lock(&q
->vb_lock
);
507 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
508 if (unlikely(b
->type
!= q
->type
)) {
509 dprintk(1, "querybuf: Wrong type.\n");
512 if (unlikely(b
->index
< 0 || b
->index
>= VIDEO_MAX_FRAME
)) {
513 dprintk(1, "querybuf: index out of range.\n");
516 if (unlikely(NULL
== q
->bufs
[b
->index
])) {
517 dprintk(1, "querybuf: buffer is null.\n");
521 videobuf_status(q
, b
, q
->bufs
[b
->index
], q
->type
);
525 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
526 mutex_unlock(&q
->lock
);
528 mutex_unlock(&q
->vb_lock
);
529 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
533 int videobuf_qbuf(struct videobuf_queue
*q
,
534 struct v4l2_buffer
*b
)
536 struct videobuf_buffer
*buf
;
537 enum v4l2_field field
;
538 unsigned long flags
= 0;
541 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
543 if (b
->memory
== V4L2_MEMORY_MMAP
)
544 down_read(¤t
->mm
->mmap_sem
);
546 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
547 mutex_lock(&q
->lock
);
549 mutex_lock(&q
->vb_lock
);
550 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
553 dprintk(1, "qbuf: Reading running...\n");
557 if (b
->type
!= q
->type
) {
558 dprintk(1, "qbuf: Wrong type.\n");
561 if (b
->index
< 0 || b
->index
>= VIDEO_MAX_FRAME
) {
562 dprintk(1, "qbuf: index out of range.\n");
565 buf
= q
->bufs
[b
->index
];
567 dprintk(1, "qbuf: buffer is null.\n");
570 MAGIC_CHECK(buf
->magic
, MAGIC_BUFFER
);
571 if (buf
->memory
!= b
->memory
) {
572 dprintk(1, "qbuf: memory type is wrong.\n");
575 if (buf
->state
!= VIDEOBUF_NEEDS_INIT
&& buf
->state
!= VIDEOBUF_IDLE
) {
576 dprintk(1, "qbuf: buffer is already queued or active.\n");
580 if (b
->flags
& V4L2_BUF_FLAG_INPUT
) {
581 if (b
->input
>= q
->inputs
) {
582 dprintk(1, "qbuf: wrong input.\n");
585 buf
->input
= b
->input
;
591 case V4L2_MEMORY_MMAP
:
592 if (0 == buf
->baddr
) {
593 dprintk(1, "qbuf: mmap requested "
594 "but buffer addr is zero!\n");
598 case V4L2_MEMORY_USERPTR
:
599 if (b
->length
< buf
->bsize
) {
600 dprintk(1, "qbuf: buffer length is not enough\n");
603 if (VIDEOBUF_NEEDS_INIT
!= buf
->state
&&
604 buf
->baddr
!= b
->m
.userptr
)
605 q
->ops
->buf_release(q
, buf
);
606 buf
->baddr
= b
->m
.userptr
;
608 case V4L2_MEMORY_OVERLAY
:
609 buf
->boff
= b
->m
.offset
;
612 dprintk(1, "qbuf: wrong memory type\n");
616 dprintk(1, "qbuf: requesting next field\n");
617 field
= videobuf_next_field(q
);
618 retval
= q
->ops
->buf_prepare(q
, buf
, field
);
620 dprintk(1, "qbuf: buffer_prepare returned %d\n", retval
);
624 list_add_tail(&buf
->stream
, &q
->stream
);
627 spin_lock_irqsave(q
->irqlock
, flags
);
628 q
->ops
->buf_queue(q
, buf
);
630 spin_unlock_irqrestore(q
->irqlock
, flags
);
632 dprintk(1, "qbuf: succeded\n");
636 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
637 mutex_unlock(&q
->lock
);
639 mutex_unlock(&q
->vb_lock
);
640 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
642 if (b
->memory
== V4L2_MEMORY_MMAP
)
643 up_read(¤t
->mm
->mmap_sem
);
648 int videobuf_dqbuf(struct videobuf_queue
*q
,
649 struct v4l2_buffer
*b
, int nonblocking
)
651 struct videobuf_buffer
*buf
;
654 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
656 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
657 mutex_lock(&q
->lock
);
659 mutex_lock(&q
->vb_lock
);
660 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
663 dprintk(1, "dqbuf: Reading running...\n");
667 if (b
->type
!= q
->type
) {
668 dprintk(1, "dqbuf: Wrong type.\n");
671 if (list_empty(&q
->stream
)) {
672 dprintk(1, "dqbuf: stream running\n");
675 buf
= list_entry(q
->stream
.next
, struct videobuf_buffer
, stream
);
676 retval
= videobuf_waiton(buf
, nonblocking
, 1);
678 dprintk(1, "dqbuf: waiton returned %d\n", retval
);
681 switch (buf
->state
) {
683 dprintk(1, "dqbuf: state is error\n");
685 CALL(q
, sync
, q
, buf
);
686 buf
->state
= VIDEOBUF_IDLE
;
689 dprintk(1, "dqbuf: state is done\n");
690 CALL(q
, sync
, q
, buf
);
691 buf
->state
= VIDEOBUF_IDLE
;
694 dprintk(1, "dqbuf: state invalid\n");
698 list_del(&buf
->stream
);
699 memset(b
, 0, sizeof(*b
));
700 videobuf_status(q
, b
, buf
, q
->type
);
703 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
704 mutex_unlock(&q
->lock
);
706 mutex_unlock(&q
->vb_lock
);
707 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
711 int videobuf_streamon(struct videobuf_queue
*q
)
713 struct videobuf_buffer
*buf
;
714 unsigned long flags
= 0;
717 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
718 mutex_lock(&q
->lock
);
720 mutex_lock(&q
->vb_lock
);
721 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
730 spin_lock_irqsave(q
->irqlock
, flags
);
731 list_for_each_entry(buf
, &q
->stream
, stream
)
732 if (buf
->state
== VIDEOBUF_PREPARED
)
733 q
->ops
->buf_queue(q
, buf
);
735 spin_unlock_irqrestore(q
->irqlock
, flags
);
738 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
739 mutex_unlock(&q
->lock
);
741 mutex_unlock(&q
->vb_lock
);
742 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
746 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
747 /* Locking: Caller holds q->lock */
749 /* Locking: Caller holds q->vb_lock */
750 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
751 static int __videobuf_streamoff(struct videobuf_queue
*q
)
756 videobuf_queue_cancel(q
);
762 int videobuf_streamoff(struct videobuf_queue
*q
)
766 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
767 mutex_lock(&q
->lock
);
769 mutex_lock(&q
->vb_lock
);
770 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
771 retval
= __videobuf_streamoff(q
);
772 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
773 mutex_unlock(&q
->lock
);
775 mutex_unlock(&q
->vb_lock
);
776 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
781 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
782 /* Locking: Caller holds q->lock */
784 /* Locking: Caller holds q->vb_lock */
785 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
786 static ssize_t
videobuf_read_zerocopy(struct videobuf_queue
*q
,
788 size_t count
, loff_t
*ppos
)
790 enum v4l2_field field
;
791 unsigned long flags
= 0;
794 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
797 q
->read_buf
= videobuf_alloc(q
);
798 if (NULL
== q
->read_buf
)
801 q
->read_buf
->memory
= V4L2_MEMORY_USERPTR
;
802 q
->read_buf
->baddr
= (unsigned long)data
;
803 q
->read_buf
->bsize
= count
;
805 field
= videobuf_next_field(q
);
806 retval
= q
->ops
->buf_prepare(q
, q
->read_buf
, field
);
810 /* start capture & wait */
812 spin_lock_irqsave(q
->irqlock
, flags
);
813 q
->ops
->buf_queue(q
, q
->read_buf
);
815 spin_unlock_irqrestore(q
->irqlock
, flags
);
816 retval
= videobuf_waiton(q
->read_buf
, 0, 0);
818 CALL(q
, sync
, q
, q
->read_buf
);
819 if (VIDEOBUF_ERROR
== q
->read_buf
->state
)
822 retval
= q
->read_buf
->size
;
827 q
->ops
->buf_release(q
, q
->read_buf
);
833 ssize_t
videobuf_read_one(struct videobuf_queue
*q
,
834 char __user
*data
, size_t count
, loff_t
*ppos
,
837 enum v4l2_field field
;
838 unsigned long flags
= 0;
839 unsigned size
, nbufs
;
842 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
844 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
845 mutex_lock(&q
->lock
);
847 mutex_lock(&q
->vb_lock
);
848 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
851 q
->ops
->buf_setup(q
, &nbufs
, &size
);
853 if (NULL
== q
->read_buf
&&
856 retval
= videobuf_read_zerocopy(q
, data
, count
, ppos
);
857 if (retval
>= 0 || retval
== -EIO
)
860 /* fallback to kernel bounce buffer on failures */
863 if (NULL
== q
->read_buf
) {
864 /* need to capture a new frame */
866 q
->read_buf
= videobuf_alloc(q
);
868 dprintk(1, "video alloc=0x%p\n", q
->read_buf
);
869 if (NULL
== q
->read_buf
)
871 q
->read_buf
->memory
= V4L2_MEMORY_USERPTR
;
872 q
->read_buf
->bsize
= count
; /* preferred size */
873 field
= videobuf_next_field(q
);
874 retval
= q
->ops
->buf_prepare(q
, q
->read_buf
, field
);
882 spin_lock_irqsave(q
->irqlock
, flags
);
884 q
->ops
->buf_queue(q
, q
->read_buf
);
886 spin_unlock_irqrestore(q
->irqlock
, flags
);
890 /* wait until capture is done */
891 retval
= videobuf_waiton(q
->read_buf
, nonblocking
, 1);
895 CALL(q
, sync
, q
, q
->read_buf
);
897 if (VIDEOBUF_ERROR
== q
->read_buf
->state
) {
898 /* catch I/O errors */
899 q
->ops
->buf_release(q
, q
->read_buf
);
906 /* Copy to userspace */
907 retval
= CALL(q
, video_copy_to_user
, q
, data
, count
, nonblocking
);
911 q
->read_off
+= retval
;
912 if (q
->read_off
== q
->read_buf
->size
) {
913 /* all data copied, cleanup */
914 q
->ops
->buf_release(q
, q
->read_buf
);
920 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
921 mutex_unlock(&q
->lock
);
923 mutex_unlock(&q
->vb_lock
);
924 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
928 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
929 /* Locking: Caller holds q->lock */
931 /* Locking: Caller holds q->vb_lock */
932 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
933 static int __videobuf_read_start(struct videobuf_queue
*q
)
935 enum v4l2_field field
;
936 unsigned long flags
= 0;
937 unsigned int count
= 0, size
= 0;
940 q
->ops
->buf_setup(q
, &count
, &size
);
943 if (count
> VIDEO_MAX_FRAME
)
944 count
= VIDEO_MAX_FRAME
;
945 size
= PAGE_ALIGN(size
);
947 err
= __videobuf_mmap_setup(q
, count
, size
, V4L2_MEMORY_USERPTR
);
953 for (i
= 0; i
< count
; i
++) {
954 field
= videobuf_next_field(q
);
955 err
= q
->ops
->buf_prepare(q
, q
->bufs
[i
], field
);
958 list_add_tail(&q
->bufs
[i
]->stream
, &q
->stream
);
961 spin_lock_irqsave(q
->irqlock
, flags
);
962 for (i
= 0; i
< count
; i
++)
963 q
->ops
->buf_queue(q
, q
->bufs
[i
]);
965 spin_unlock_irqrestore(q
->irqlock
, flags
);
970 static void __videobuf_read_stop(struct videobuf_queue
*q
)
975 videobuf_queue_cancel(q
);
976 __videobuf_mmap_free(q
);
977 INIT_LIST_HEAD(&q
->stream
);
978 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
979 if (NULL
== q
->bufs
[i
])
989 int videobuf_read_start(struct videobuf_queue
*q
)
993 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
994 mutex_lock(&q
->lock
);
996 mutex_lock(&q
->vb_lock
);
997 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
998 rc
= __videobuf_read_start(q
);
999 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1000 mutex_unlock(&q
->lock
);
1002 mutex_unlock(&q
->vb_lock
);
1003 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1008 void videobuf_read_stop(struct videobuf_queue
*q
)
1010 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1011 mutex_lock(&q
->lock
);
1013 mutex_lock(&q
->vb_lock
);
1014 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1015 __videobuf_read_stop(q
);
1016 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1017 mutex_unlock(&q
->lock
);
1019 mutex_unlock(&q
->vb_lock
);
1020 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1023 void videobuf_stop(struct videobuf_queue
*q
)
1025 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1026 mutex_lock(&q
->lock
);
1028 mutex_lock(&q
->vb_lock
);
1029 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1032 __videobuf_streamoff(q
);
1035 __videobuf_read_stop(q
);
1037 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1038 mutex_unlock(&q
->lock
);
1040 mutex_unlock(&q
->vb_lock
);
1041 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1045 ssize_t
videobuf_read_stream(struct videobuf_queue
*q
,
1046 char __user
*data
, size_t count
, loff_t
*ppos
,
1047 int vbihack
, int nonblocking
)
1050 unsigned long flags
= 0;
1052 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
1054 dprintk(2, "%s\n", __FUNCTION__
);
1055 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1056 mutex_lock(&q
->lock
);
1058 mutex_lock(&q
->vb_lock
);
1059 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1064 retval
= __videobuf_read_start(q
);
1071 /* get / wait for data */
1072 if (NULL
== q
->read_buf
) {
1073 q
->read_buf
= list_entry(q
->stream
.next
,
1074 struct videobuf_buffer
,
1076 list_del(&q
->read_buf
->stream
);
1079 rc
= videobuf_waiton(q
->read_buf
, nonblocking
, 1);
1086 if (q
->read_buf
->state
== VIDEOBUF_DONE
) {
1087 rc
= CALL(q
, copy_stream
, q
, data
+ retval
, count
,
1088 retval
, vbihack
, nonblocking
);
1098 q
->read_off
= q
->read_buf
->size
;
1103 /* requeue buffer when done with copying */
1104 if (q
->read_off
== q
->read_buf
->size
) {
1105 list_add_tail(&q
->read_buf
->stream
,
1108 spin_lock_irqsave(q
->irqlock
, flags
);
1109 q
->ops
->buf_queue(q
, q
->read_buf
);
1111 spin_unlock_irqrestore(q
->irqlock
, flags
);
1119 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1120 mutex_unlock(&q
->lock
);
1122 mutex_unlock(&q
->vb_lock
);
1123 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1127 unsigned int videobuf_poll_stream(struct file
*file
,
1128 struct videobuf_queue
*q
,
1131 struct videobuf_buffer
*buf
= NULL
;
1132 unsigned int rc
= 0;
1134 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1135 mutex_lock(&q
->lock
);
1137 mutex_lock(&q
->vb_lock
);
1138 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1140 if (!list_empty(&q
->stream
))
1141 buf
= list_entry(q
->stream
.next
,
1142 struct videobuf_buffer
, stream
);
1145 __videobuf_read_start(q
);
1148 } else if (NULL
== q
->read_buf
) {
1149 q
->read_buf
= list_entry(q
->stream
.next
,
1150 struct videobuf_buffer
,
1152 list_del(&q
->read_buf
->stream
);
1161 poll_wait(file
, &buf
->done
, wait
);
1162 if (buf
->state
== VIDEOBUF_DONE
||
1163 buf
->state
== VIDEOBUF_ERROR
)
1164 rc
= POLLIN
|POLLRDNORM
;
1166 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1167 mutex_unlock(&q
->lock
);
1169 mutex_unlock(&q
->vb_lock
);
1170 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1174 int videobuf_mmap_mapper(struct videobuf_queue
*q
,
1175 struct vm_area_struct
*vma
)
1179 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
1181 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1182 mutex_lock(&q
->lock
);
1184 mutex_lock(&q
->vb_lock
);
1185 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1186 retval
= CALL(q
, mmap_mapper
, q
, vma
);
1188 <<<<<<< HEAD
:drivers
/media
/video
/videobuf
-core
.c
1189 mutex_unlock(&q
->lock
);
1191 mutex_unlock(&q
->vb_lock
);
1192 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/media
/video
/videobuf
-core
.c
1197 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1198 int videobuf_cgmbuf(struct videobuf_queue
*q
,
1199 struct video_mbuf
*mbuf
, int count
)
1201 struct v4l2_requestbuffers req
;
1204 MAGIC_CHECK(q
->int_ops
->magic
, MAGIC_QTYPE_OPS
);
1206 memset(&req
, 0, sizeof(req
));
1209 req
.memory
= V4L2_MEMORY_MMAP
;
1210 rc
= videobuf_reqbufs(q
, &req
);
1214 mbuf
->frames
= req
.count
;
1216 for (i
= 0; i
< mbuf
->frames
; i
++) {
1217 mbuf
->offsets
[i
] = q
->bufs
[i
]->boff
;
1218 mbuf
->size
+= q
->bufs
[i
]->bsize
;
1223 EXPORT_SYMBOL_GPL(videobuf_cgmbuf
);
1226 /* --------------------------------------------------------------------- */
1228 EXPORT_SYMBOL_GPL(videobuf_waiton
);
1229 EXPORT_SYMBOL_GPL(videobuf_iolock
);
1231 EXPORT_SYMBOL_GPL(videobuf_alloc
);
1233 EXPORT_SYMBOL_GPL(videobuf_queue_core_init
);
1234 EXPORT_SYMBOL_GPL(videobuf_queue_cancel
);
1235 EXPORT_SYMBOL_GPL(videobuf_queue_is_busy
);
1237 EXPORT_SYMBOL_GPL(videobuf_next_field
);
1238 EXPORT_SYMBOL_GPL(videobuf_reqbufs
);
1239 EXPORT_SYMBOL_GPL(videobuf_querybuf
);
1240 EXPORT_SYMBOL_GPL(videobuf_qbuf
);
1241 EXPORT_SYMBOL_GPL(videobuf_dqbuf
);
1242 EXPORT_SYMBOL_GPL(videobuf_streamon
);
1243 EXPORT_SYMBOL_GPL(videobuf_streamoff
);
1245 EXPORT_SYMBOL_GPL(videobuf_read_start
);
1246 EXPORT_SYMBOL_GPL(videobuf_read_stop
);
1247 EXPORT_SYMBOL_GPL(videobuf_stop
);
1248 EXPORT_SYMBOL_GPL(videobuf_read_stream
);
1249 EXPORT_SYMBOL_GPL(videobuf_read_one
);
1250 EXPORT_SYMBOL_GPL(videobuf_poll_stream
);
1252 EXPORT_SYMBOL_GPL(videobuf_mmap_setup
);
1253 EXPORT_SYMBOL_GPL(videobuf_mmap_free
);
1254 EXPORT_SYMBOL_GPL(videobuf_mmap_mapper
);