History log of /drivers/media/video/videobuf-core.c
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
08af245de0cf6ab5f4ed008ee2bb99273774fce0 24-Dec-2010 Hans Verkuil <hverkuil@xs4all.nl> [media] V4L: remove V4L1 compatibility mode

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
0e0809a58869e3e422985f868ad5e0da1fc0ba85 26-Sep-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: videobuf: add queue argument to videobuf_waiton()

videobuf_waiton() must unlock and relock ext_lock if it has to wait.
For that to happen it needs the videobuf_queue pointer.

Don't attempt to unlock/relock q->ext_lock unless it was locked in the
first place.

vb->state has to be protected by a spinlock to be safe.

This patch is based on code from Mauro Carvalho Chehab <mchehab@redhat.com>.

[mchehab@redhat.com: add extra argument to a few missing places]
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
08bff03ed697a583612b62a6ac566bd5bce98012 20-Sep-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: videobuf: add ext_lock argument to the queue init functions

Add an ext_lock argument to the videobuf init functions. This allows
drivers to pass the vdev->lock pointer (or any other externally held lock)
to videobuf. For now all drivers just pass NULL.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
97397687886aa8ecd4ec603fab9e70e970c11597 20-Sep-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: videobuf: prepare to make locking optional in videobuf

Currently videobuf uses the vb_lock mutex to lock its data structures.
But this locking will (optionally) move into the v4l2 core, which means
that in that case vb_lock shouldn't be used since the external lock is already
held.

Prepare for this by adding a pointer to such an external mutex and
don't lock if that pointer is set.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
a438d6da52b991b6896742a0f9aed80c2f82da87 11-May-2010 Pawel Osciak <p.osciak@samsung.com> V4L/DVB: videobuf: rename videobuf_mmap_free and add sanity checks

This function is not specific to mmap, hence the rename.
Add a check whether we are not streaming or reading (for read mode that
uses the stream queue) before freeing anything.

Signed-off-by: Pawel Osciak <p.osciak@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
33c38283f03d8ea0358229fc03c1beebe67aed0e 11-May-2010 Pawel Osciak <p.osciak@samsung.com> V4L/DVB: videobuf: rename videobuf_alloc to videobuf_alloc_vb

These functions allocate videobuf_buffer structures only. Renaming in order
to prevent confusion with functions allocating actual video buffer memory.

Rename the functions in videobuf-core.h videobuf-dma-sg.c as well.

Signed-off-by: Pawel Osciak <p.osciak@samsung.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
9b558434136138edc79710385aaf613cb4b30459 29-Mar-2010 Pawel Osciak <p.osciak@samsung.com> V4L/DVB: videobuf: make poll() report proper flags for output video devices

According to the V4L2 specification, poll() should set POLLOUT | POLLWRNORM
flags for output devices after the frame has been displayed.

Signed-off-by: Pawel Osciak <p.osciak@samsung.com>
Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
b2dfd1a45f014e24f0eecc50a7edc954425c348a 28-Apr-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: videobuf: Add support for V4L2_BUF_FLAG_ERROR

For recoverable stream errors dqbuf() now returns 0 and the error flag
is set instead of returning EIO.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
96f2ec67b8d4761471409e1df0adfe4da5262f84 21-Apr-2010 Pawel Osciak <p.osciak@samsung.com> V4L/DVB: v4l: videobuf: qbuf now uses relevant v4l2_buffer fields for OUTPUT types

According to the V4L2 specification, applications set bytesused, field and
timestamp fields of struct v4l2_buffer when the buffer is intended for
output and memory type is MMAP. This adds proper copying of those values
to videobuf_buffer so drivers can use them.

Signed-off-by: Pawel Osciak <p.osciak@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
0b62b73778554cd47480ea465f0b255cc63b4336 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: add videobuf_buffer *buf as argument to mmap_mapper

mmap_mapper should operate on a buffer, not on a complete queue. So let
the videobuf-core find the correct buffer instead of duplicating that
code in each mmap_mapper implementation.

The dma-sg implementation has backwards compatibility code for handling
the V4L1_COMPAT layer. This code is now under the v4L1_COMPAT config option.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
37111039c9521c751ce0597c129fe6d45ba72818 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: move video_copy_to_user and copy_stream to core

The video_copy_to_user and copy_stream ops are almost identical for all
videobuf memtype variants. All that is needed is to use the new vaddr
op and these functions can be moved into the core, ensuring we have just
one single implementation instead of three.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
f4fce60e8b1559306fa1112287bc8765f6977de3 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: rename videobuf_queue_to_vmalloc to videobuf_queue_to_vaddr

Ths function returns the virtual kernel address of the buffer and has
nothing to do with allocation.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
037c75eb14cd6adb837f81f0c2b2a52c31c91e69 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: rename .vmalloc to .vaddr

Rename the .vmalloc op in struct videobuf_qtype_ops to .vaddr. This op returns
the virtual kernel address of a buffer. vaddr is a lot less confusing than
vmalloc since this callback does do any allocations.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
a4cf4cac2979a828e7cd0a3cd02d7a5308a44a7f 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: use struct videobuf_buffer * instead of void * for videobuf_alloc

videobuf_alloc() returned a void *. Change to struct videobuf_buffer *
to get better type checking.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
63e424856b4ab0652c58f75a2d2ecb9c1f95db27 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: remove unused is_mmapped field

Thanks to Pawel Osciak for noticing this.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
53aaf07637baae8f53c33b803bbc96047d8da1c4 28-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: v4l videobuf: remove mmap_free callback

Remove the mmap_free callback from struct videobuf_qtype_ops.

All implementations of this callback do the same trivial check: return
-EBUSY if any buffer is mmapped. That can also be tested in the
videobuf core.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
7a02264ca9ec5409e22b9d41f32b431d08eadbce 17-Mar-2010 Pawel Osciak <p.osciak@samsung.com> V4L/DVB: v4l: videobuf: code cleanup

Make videobuf pass checkpatch; minor code cleanups.

Signed-off-by: Pawel Osciak <p.osciak@samsung.com>
Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
771075bb4667078687ae3c570a17c274f389e01e 13-Mar-2010 Hans Verkuil <hverkuil@xs4all.nl> V4L/DVB: videobuf-core: fix spelling mistake in debug message

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
296372e3b04a41853df1be6623a5bd634051458c 22-Nov-2009 Márton Németh <nm127@freemail.hu> V4L/DVB (13415): videobuf-core: explicitly cast page count

Explicitly cast page count in the debug message.

Signed-off-by: Márton Németh <nm127@freemail.hu>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
38a54f35a0a90c0b62b111dd4de24248b22616b9 17-Nov-2009 Jonathan Corbet <corbet@lwn.net> V4L/DVB (13377): make struct videobuf_queue_ops constant

The videobuf_queue_ops function vector is not declared constant, but
there's no need for the videobuf layer to ever change it. Make it const
so that videobuf users can make their operations const without warnings.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
7cbefad085c9112d0b1814db18423e5da072f5c8 23-Jul-2009 Tuukka Toivonen <tuukka.o.toivonen@nokia.com> V4L/DVB (13165): videobuf do not force buffer size to be multiple of PAGE_SIZE

When the image size (bytesperline*height) is not multiple
of PAGE_SIZE, v4l2 rounded the required buffer size to
be multiple of PAGE_SIZE. This prevented user space
to store images directly into userptr buffers which were
not multiple of PAGE_SIZE. This constraint is removed.

The start address is still assumed to be required
page-aligned, ie., when v4l2 allocates mmap buffers,
the offset between different buffers is page-aligned.

Signed-off-by: Tuukka Toivonen <tuukka.o.toivonen@nokia.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
d43c36dc6b357fa1806800f18aa30123c747a6d1 07-Oct-2009 Alexey Dobriyan <adobriyan@gmail.com> headers: remove sched.h from interrupt.h

After m68k's task_thread_info() doesn't refer to current,
it's possible to remove sched.h from interrupt.h and not break m68k!
Many thanks to Heiko Carstens for allowing this.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
/drivers/media/video/videobuf-core.c
96ceea2734d922d07000e98606231f3d675e09f8 03-Jun-2009 Figo.zhang <figo1802@gmail.com> V4L/DVB (11991): buf-core.c: add pointer check

add poiter check for videobuf_queue_core_init().

any guys who write a v4l driver, pass a NULL pointer or a non-inintial
pointer to the first parameter such as videobuf_queue_sg_init() , it
would be crashed.

Signed-off-by: Figo.zhang <figo1802@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
223ffe5f8270ba9d069f1cbff9acec095a6f58b1 02-May-2009 Roel Kluin <roel.kluin@gmail.com> V4L/DVB: cleanup redundant tests on unsigned

Remove redundant tests on unsigned.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
925d74ae717c9a12d3618eb4b36b9fb632e2cef3 29-Apr-2009 Németh Márton <nm127@freemail.hu> V4L/DVB (11736): videobuf: modify return value of VIDIOC_REQBUFS ioctl

The V4L2 ioctls usually return 0 when the operation was successful
and -1 in case of error. Currently VIDIOC_REQBUFS returns the
number of buffers which is redundant because this information is
available in count field of struct v4l2_requestbuffers. The
V4L2 API specification, revision 0.24 [1] explicitly specifies for
VIDIOC_REQBUFS that the return value shall be 0 on success.

The patch was tested with v4l-test 0.13 [2] with vivi driver.

References:
[1] V4L2 API specification, revision 0.24
http://v4l2spec.bytesex.org/spec/r13696.htm

[2] v4l-test: Test environment for Video For Linux Two API
http://v4l-test.sourceforge.net/

Signed-off-by: Márton Németh <nm127@freemail.hu>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
/drivers/media/video/videobuf-core.c
27ac792ca0b0a1e7e65f20342260650516c95864 24-Jul-2008 Andrea Righi <righi.andrea@gmail.com> PAGE_ALIGN(): correctly handle 64-bit values on 32-bit architectures

On 32-bit architectures PAGE_ALIGN() truncates 64-bit values to the 32-bit
boundary. For example:

u64 val = PAGE_ALIGN(size);

always returns a value < 4GB even if size is greater than 4GB.

The problem resides in PAGE_MASK definition (from include/asm-x86/page.h for
example):

#define PAGE_SHIFT 12
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
...
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)

The "~" is performed on a 32-bit value, so everything in "and" with
PAGE_MASK greater than 4GB will be truncated to the 32-bit boundary.
Using the ALIGN() macro seems to be the right way, because it uses
typeof(addr) for the mask.

Also move the PAGE_ALIGN() definitions out of include/asm-*/page.h in
include/linux/mm.h.

See also lkml discussion: http://lkml.org/lkml/2008/6/11/237

[akpm@linux-foundation.org: fix drivers/media/video/uvc/uvc_queue.c]
[akpm@linux-foundation.org: fix v850]
[akpm@linux-foundation.org: fix powerpc]
[akpm@linux-foundation.org: fix arm]
[akpm@linux-foundation.org: fix mips]
[akpm@linux-foundation.org: fix drivers/media/video/pvrusb2/pvrusb2-dvb.c]
[akpm@linux-foundation.org: fix drivers/mtd/maps/uclinux.c]
[akpm@linux-foundation.org: fix powerpc]
Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
/drivers/media/video/videobuf-core.c
81b2dbcad86732ffc02bad87aa25c4651199fc77 20-May-2008 Arjan van de Ven <arjan@linux.intel.com> Fix a deadlock in the bttv driver

vidiocgmbuf() does this:
mutex_lock(&fh->cap.vb_lock);
retval = videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize,
V4L2_MEMORY_MMAP);

and videobuf_mmap_setup() then just does
mutex_lock(&q->vb_lock);
ret = __videobuf_mmap_setup(q, bcount, bsize, memory);
mutex_unlock(&q->vb_lock);

which is an obvious double-take deadlock.

This patch fixes this by having vidiocgmbuf() just call the
__videobuf_mmap_setup function instead.

Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Reported-by: Koos Vriezen <koos.vriezen@gmail.com>
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
/drivers/media/video/videobuf-core.c
a6a3a17b7fdaf824e6d73e8e4a94c9d149302f74 29-Apr-2008 Harvey Harrison <harvey.harrison@gmail.com> media: fix integer as NULL pointer warnings

drivers/media/video/v4l2-common.c:719:16: warning: Using plain integer as NULL pointer
drivers/media/video/au0828/au0828-dvb.c:122:19: warning: Using plain integer as NULL pointer
drivers/media/video/ivtv/ivtv-yuv.c:1101:22: warning: Using plain integer as NULL pointer
drivers/media/video/ivtv/ivtv-yuv.c:1102:23: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-audio.c:78:39: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-video-v4l.c:84:39: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-v4l2.c:1264:9: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-context.c:197:28: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c:126:39: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-dvb.c:133:32: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-dvb.c:145:31: warning: Using plain integer as NULL pointer
drivers/media/video/pvrusb2/pvrusb2-dvb.c:177:55: warning: Using plain integer as NULL pointer
drivers/media/video/videobuf-core.c:100:9: warning: Using plain integer as NULL pointer

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
/drivers/media/video/videobuf-core.c
59d3448995a4c0ca98cbe82f6dac9460323377c1 13-Apr-2008 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (7566): videobuf-dvb: allow its usage with videobuf-vmalloc

videobuf-dvb were still using a function that were videobuf-dma-sg
dependent. This patch creates a generic handler for this function. This
way, videobuf-dvb can now work with all videobuf implementations.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
0cf4daee31d88086cf3508d1d8d1f4e451c27906 28-Mar-2008 Brandon Philips <bphilips@suse.de> V4L/DVB (7562): videobuf: Require spinlocks for all videobuf users

A spinlock is necessary for queue_cancel to work with every driver in the tree.
Otherwise a race exists between IRQ handlers removing buffers from the queue
and queue_cancel invalidating the queue.

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
aa9479ed508d78dcd06479dc6274c9b02d1398df 13-Apr-2008 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (7561): videobuf-vmalloc: stop streaming before unmap

Before the patch, there were a risk of freeing and unmapping userspace memory,
while there were pending requests.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
968ced78a53509a996708a14e8b9269d1dc6a61c 13-Apr-2008 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (7552): videbuf-vmalloc: Corrects mmap code

There were some bugs on videobuf-vmalloc.

Basically, remap were called with a wrong parameter. Due to that, a later remap
were needed, generating the need of some hacks on videobuf-vmalloc and
videobuf-core.

This patch fixes the remap and removes the hacks.

TODO:

- V4L2_MEMORY_USERPTR is not implemented yet. This method should be
properly implemented, in order to work with a few userspace applications.

- The driver also doesn't implement V4L2_MEMORY_OVERLAY. This method is used
only by a few applications, and are becaming obsolete, due to the increment
of cpu performance. So, most apps prefer to retrieve data to an internal
buffer, doing some processing like de-interlacing.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
7e28adb2497f6b873516163e2d29210c11777613 09-Apr-2008 Harvey Harrison <harvey.harrison@gmail.com> V4L/DVB (7518): media/video/ replace remaining __FUNCTION__ occurrences

__FUNCTION__ is gcc-specific, use __func__

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
137d1cb19d9da163ce6cb57a6fa1e6a3468af6a4 02-Apr-2008 Brandon Philips <brandon@ifup.org> V4L/DVB (7493): videobuf: Avoid deadlock with QBUF and bring up to spec for empty queue

Add a waitqueue to wait on when there are no buffers in the buffer queue.
DQBUF waits on this queue without holding vb_lock to allow a QBUF to happen.
Once a buffer has been queued we recheck that the queue is still streaming and
wait on the new buffer's waitqueue while holding the vb_lock. The driver
should come along in a timely manner and put the buffer into its next state
finishing the DQBUF.

By implementing this waitqueue it also brings the videobuf DQBUF up to spec and
it now blocks on O_NONBLOCK even when no buffers have been queued via QBUF:

"By default VIDIOC_DQBUF blocks when no buffer is in the outgoing queue."
- V4L2 spec

Signed-off-by: Brandon Philips <bphilips@suse.de>
CC: Trent Piepho <xyzzy@speakeasy.org>
CC: Carl Karsten <carl@personnelware.com>
CC: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
009a90597e177320e47154dd0817d201f52bcd46 02-Apr-2008 Brandon Philips <brandon@ifup.org> V4L/DVB (7488): videobuf: Simplify videobuf_waiton logic and possibly avoid missed wakeup

Possible missed wakeup- use kernel helpers for wait queues
http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg27983.html

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
b608f4323a0e0440d18fa13aea3db98351137487 02-Apr-2008 Brandon Philips <brandon@ifup.org> V4L/DVB (7487): videobuf: Wakeup queues after changing the state to ERROR

The waitqueues must be woken up every time state changes.

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
7daa4a8897e79911f524ddac065adea05c7e9b16 22-Apr-2008 Guennadi Liakhovetski <g.liakhovetski@pengutronix.de> V4L/DVB (7378): cleanup variable initialization

flags used for spinlocks don't need to be initialized, except where the
compiler has no way to see, that the spin_unlock_irqrestore is only called
if the spin_lock_irqsave has been called before. Local variable
initialization doesn't have to be protected.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
e9bcf6675d6da1a1e9925b2bdfc21f8d2330a1c5 22-Apr-2008 Guennadi Liakhovetski <g.liakhovetski@pengutronix.de> V4L/DVB (7376): Improve compile-time type-checking in videobuf

Make the dev member of the struct videobuf_queue of type "struct device *"
to avoid future problems. Also change the prototype of the
videobuf_queue_core_init() function.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
e43d76b40d3fda146b9cd1192c5504a257603b70 22-Apr-2008 Brandon Philips <brandon@ifup.org> V4L/DVB (7281): v4l: Deadlock in videobuf-core for DQBUF waiting on QBUF

Avoid a deadlock where DQBUF is holding the vb_lock while waiting on a QBUF
which also needs the vb_lock. Reported by Hans Verkuil <hverkuil@xs4all.nl>.

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
64f9477f95bf5d4ba49dc3988d47a15bc06bb5da 31-Jan-2008 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (7121): Renames videobuf lock to vb_lock

This helps to identify where vb_lock is being used, and find missusages of the
locks.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
1f8d30083abc17897b897787c39d446eb9d99fe0 13-Jan-2008 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (7023): Fix a regresion left by changeset 7e65d6e8f6df

Changeset 7e65d6e8f6df removed a very bad hack on mmap(). However, the fixes
weren't considering usermap and overlay memory models. This were breaking
direct reading from /dev/video?, used mostly by mpeg aware drivers.

Thanks to Steven Toth <stoth@linuxtv.org> for reporting the issue and
bissecting it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
d05051c82e0e8ff748e9c9a06a061bda3ad656e5 10-Jan-2008 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6997): Replace a very dirty hack on videobuf for a clean wait_event

In order to videobuf_iolock to work, mmap_mapper should be called first.
Otherwise, an OOPS is generated.

On some cases, .mmap file handler used to took some time to be called. On those
situations, mmap_mmapper() were called after iolock.

This patch properly waits for mmap_mapper to be called, otherwise generating an
error.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
225ba900886f6d2d3447dd5bfdb95217f0619755 13-Dec-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6804): __videobuf_read_start is static

Thanks to Jean Delvare <khali@linux-fr.org> for pointing this.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
e2c77314c9444c994087c96eb370b333d57657a7 10-Dec-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6759): CodingStyle fixes

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
0fc0686e64d21a6abded96af2b1a895dfa8b2530 07-Nov-2007 Brandon Philips <brandon@ifup.org> V4L/DVB (6600): V4L: videobuf: don't chew up namespace STATE_.*, convert to VIDEOBUF_

s/STATE_NEEDS_INIT/VIDEOBUF_NEEDS_INIT/g
s/STATE_PREPARED/VIDEOBUF_PREPARED/g
s/STATE_QUEUED/VIDEOBUF_QUEUED/g
s/STATE_ACTIVE/VIDEOBUF_ACTIVE/g
s/STATE_DONE/VIDEOBUF_DONE/g
s/STATE_ERROR/VIDEOBUF_ERROR/g
s/STATE_IDLE/VIDEOBUF_IDLE/g

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
3f84307a10b4d9039c5c8f718bcdd0928c9994c1 12-Dec-2007 Adrian Bunk <bunk@stusta.de> V4L/DVB (6803): buf-core.c locking fixes

After commit 19fb1457990b6b7e15586ec7331541a184233acc the callers in
videobuf-core.c that already hold the lock must call
__videobuf_read_start() instead of videobuf_read_start().

Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
19fb1457990b6b7e15586ec7331541a184233acc 16-Nov-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6609): Re-adds lock safe videobuf_read_start

videobuf_dvb needs videobuf_read_start. The EXPORT_SYMBOL_GPL() were removed by
a previous patch. However, videobuf_dvb needs this.

This patch re-adds videobuf_read_start, doing the proper lock.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
19bc5133dae9562e8824ef101464061f9854c1d8 14-Nov-2007 Brandon Philips <brandon@ifup.org> V4L/DVB (6601): V4L: videobuf-core locking fixes and comments

- Add comments to functions that require that caller hold q->lock
- Add __videobuf_mmap_free that doesn't hold q->lock for use within videobuf
- Add locking to videobuf_mmap_free
- Fix linux/drivers/media/common/saa7146_video.c which was holding lock around
videobuf_read_stop
- Add locking to functions that operate on a queue
- Add videobuf_stop to take care of stopping in both the read and stream case

TODO: bttv still has an unsafe call to videobuf_queue_is_busy

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
a13625c518ca6fd3ff7cb3b66d8023f843a745a3 13-Oct-2007 Pekka Enberg <penberg@cs.helsinki.fi> V4L/DVB (6324): fix videobuf_cgmbuf export

As videobuf_cgmbuf is defined only if CONFIG_VIDEO_V4L1_COMPAT is enabled,
move the EXPORT_SYMBOL_GPL declaration inside the #ifdef block. Fixes
compilation for x86_64 defconfig.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
13bcd5d0e21e3ca726965371ada8ff6c64af288f 13-Oct-2007 Al Viro <viro@ftp.linux.org.uk> v4l: copy_to_user() is not a good method name

Breaks on any target that has copy_to_user() defined as a non-trivial
macro.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
/drivers/media/video/videobuf-core.c
a991f44b79fa49b281eb078eed4a76a42101012a 10-Oct-2007 Trent Piepho <xyzzy@speakeasy.org> V4L/DVB (6316): Change list_for_each+list_entry to list_for_each_entry

The rest of V4L files.

There is one list_for_each+list_entry in cpia_pp.c that
wasn't changed because it expects the loop iterator to remain NULL if
the list is empty.

A bug in vivi is fixed; the 'safe' version needs to be used because the loop
deletes the list entries.

Simplify a second loop in vivi and get rid if an un-used variable in that loop.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
49ee718ef51f4d938f80f67207e1bfa2a38897a4 05-Oct-2007 Brandon Philips <bphilips@suse.de> V4L/DVB (6305): V4L: videobuf-core.c avoid NULL dereferences in videobuf-core

The return value of videobuf_alloc() is unchecked but this function will
return NULL on an error. Check for NULL and make videobuf_reqbufs()
return the number of successfully allocated buffers.

Also, fix saa7146_video.c and bttv-driver.c to use this returned
buffer count.

Tested against the vivi driver. Not tested against saa7146 or bt8xx
devices.

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
d4cae5a50021271b9ef4e5e39e71e177d12fa8cb 08-Oct-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6292): videobuf_core init always require callback implementation

In the past, videobuf_queue_init were used to initialize PCI DMA videobuffers.
This patch renames it, to avoid confusion with the previous kernel API, doing:
s/videobuf_queue_init/void videobuf_queue_core_init/

Also, the operations is now part of the function parameter. The function will
also add a test if this is defined, otherwise producing BUG.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
d5f1b01644b6fd5e9eb480a4762cd6b569cb1246 08-Oct-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6291): Fix: avoid oops on some SMP machines

This workaround fix a bug that happens on some SMP machines. On those machines,
videobuf_iolock is called too soon, before file .mmap handler. This patch calls
the scheduler before iolocking, allowing it to properly call the pending mmap.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
d00cd2985e0e796621adf0f782af1563d990b0b5 02-Oct-2007 Maxim Levitsky <maximlevitsky@gmail.com> V4L/DVB (6278): Buf: fix typo that caused data loss when readng streams from device

If videobuf_read_stream reads two or more buffers it was overwriting the first one

Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
/drivers/media/video/videobuf-core.c
00f98d0804c88c29bef81cb98c861f13c9b33f30 28-Sep-2007 Brandon Philips <bphilips@suse.de> V4L/DVB (6276): V4L: videobuf-core.c lock before streaming check

The reading/streaming fields are used for mutual exclusion of the queue and
should be protected by the queue lock.

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
/drivers/media/video/videobuf-core.c
9900132f3437e9373aa030cdb5bd2d5db15566e3 28-Sep-2007 Maxim Levitsky <maximlevitsky@gmail.com> V4L/DVB (6268): V4L: Fix a lock inversion in generic videobuf code

videobuf_qbuf takes q->lock, and then calls
q->ops->buf_prepare which by design in all drivers calls
videobuf_iolock which calls videobuf_dma_init_user and this
takes current->mm->mmap_sem

on the other hand if user calls mumap from other thread, sys_munmap
takes current->mm->mmap_sem and videobuf_vm_close takes q->lock

Since this can occur only for V4L2_MEMORY_MMAP buffers, take
current->mm->mmap_sem in qbuf, before q->lock, and don't take
current->mm->mmap_sem videobuf_dma_init_user for those buffers

Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
/drivers/media/video/videobuf-core.c
851c0c96b2212f48fe51afc1589541b5eae3a544 27-Sep-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6266): videobuf cleanup: mmap check is common to all videobuf. Make it at core

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
/drivers/media/video/videobuf-core.c
cd4765efdd816ac14075fc7d5adf489502e75e1e 25-Sep-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6265): Prevent for calling mmap_free without an allocated buffer

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
/drivers/media/video/videobuf-core.c
7a7d9a89d0307b1743d782197e2c5fc5ddf183f3 23-Aug-2007 Mauro Carvalho Chehab <mchehab@infradead.org> V4L/DVB (6251): Replace video-buf to a more generic approach

video-buf currently does two different tasks:

- Manages video buffers with a common code that allows
implementing all the V4L2 different modes of buffering;

- Controls memory allocations

While the first task is generic, the second were written to support PCI DMA
Scatter/Gather needs. The original approach can't even work for those
video capture hardware that don't support scatter/gather.

I did one approach to make it more generic. While the approach worked
fine for vivi driver, it were not generic enough to handle USB needs.

This patch creates two different modules, one containing the generic
video buffer handling (videobuf-core) and another with PCI DMA S/G.
After this patch, it would be simpler to write an USB video-buf and a
non-SG DMA module.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
/drivers/media/video/videobuf-core.c