* Question about V4L2_MEMORY_USERPTR
@ 2012-03-23 7:19 Hans Petter Selasky
2012-07-01 14:00 ` Sakari Ailus
0 siblings, 1 reply; 5+ messages in thread
From: Hans Petter Selasky @ 2012-03-23 7:19 UTC (permalink / raw)
To: linux-media
Hi,
I have a question about V4L2_MEMORY_USERPTR:
>From which context are the kernel's "copy_to_user()" functions called in
relation to V4L2_MEMORY_USERPTR ? Can this be a USB callback function or is it
only syscalls, like read/write/ioctl that are allowed to call "copy_to_user()"
?
The reason for asking is that I am maintaining a userland port of the media
tree's USB drivers for FreeBSD. At the present moment it is not allowed to
call copy_to_user() or copy_from_user() unless the backtrace shows a syscall,
so the V4L2_MEMORY_USERPTR feature is simply removed and disabled. I'm
currently thinking how I can enable this feature.
--HPS
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question about V4L2_MEMORY_USERPTR
2012-03-23 7:19 Question about V4L2_MEMORY_USERPTR Hans Petter Selasky
@ 2012-07-01 14:00 ` Sakari Ailus
2012-07-02 9:24 ` Laurent Pinchart
0 siblings, 1 reply; 5+ messages in thread
From: Sakari Ailus @ 2012-07-01 14:00 UTC (permalink / raw)
To: Hans Petter Selasky; +Cc: linux-media
Hi Hans,
On Fri, Mar 23, 2012 at 08:19:45AM +0100, Hans Petter Selasky wrote:
> Hi,
>
> I have a question about V4L2_MEMORY_USERPTR:
>
> From which context are the kernel's "copy_to_user()" functions called in
> relation to V4L2_MEMORY_USERPTR ? Can this be a USB callback function or is it
> only syscalls, like read/write/ioctl that are allowed to call "copy_to_user()"
> ?
>
> The reason for asking is that I am maintaining a userland port of the media
> tree's USB drivers for FreeBSD. At the present moment it is not allowed to
> call copy_to_user() or copy_from_user() unless the backtrace shows a syscall,
> so the V4L2_MEMORY_USERPTR feature is simply removed and disabled. I'm
> currently thinking how I can enable this feature.
I hope this is still relevant --- I just read your message the first time.
I don't know how V4L2 is being used in FreeBSD userland, but the intent of
copy_to_user() function is to copy the contents of kernel memory to
somewhere the user space has a mapping to (and the other way around for
copy_from_user()).
Are your video buffers allocated by the kernel or not? How is USB accessed
when you don't have the Linux kernel USB framework around?
Kind regards,
--
Sakari Ailus
e-mail: sakari.ailus@iki.fi jabber/XMPP/Gmail: sailus@retiisi.org.uk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question about V4L2_MEMORY_USERPTR
2012-07-01 14:00 ` Sakari Ailus
@ 2012-07-02 9:24 ` Laurent Pinchart
2012-07-02 19:07 ` Hans Petter Selasky
0 siblings, 1 reply; 5+ messages in thread
From: Laurent Pinchart @ 2012-07-02 9:24 UTC (permalink / raw)
To: Sakari Ailus; +Cc: Hans Petter Selasky, linux-media
On Sunday 01 July 2012 17:00:58 Sakari Ailus wrote:
> On Fri, Mar 23, 2012 at 08:19:45AM +0100, Hans Petter Selasky wrote:
> > Hi,
> >
> > I have a question about V4L2_MEMORY_USERPTR:
> >
> > From which context are the kernel's "copy_to_user()" functions called in
> > relation to V4L2_MEMORY_USERPTR ? Can this be a USB callback function or
> > is it only syscalls, like read/write/ioctl that are allowed to call
> > "copy_to_user()" ?
> >
> > The reason for asking is that I am maintaining a userland port of the
> > media tree's USB drivers for FreeBSD. At the present moment it is not
> > allowed to call copy_to_user() or copy_from_user() unless the backtrace
> > shows a syscall, so the V4L2_MEMORY_USERPTR feature is simply removed and
> > disabled. I'm currently thinking how I can enable this feature.
>
> I hope this is still relevant --- I just read your message the first time.
>
> I don't know how V4L2 is being used in FreeBSD userland, but the intent of
> copy_to_user() function is to copy the contents of kernel memory to
> somewhere the user space has a mapping to (and the other way around for
> copy_from_user()).
copy_(to|from)_user(), by definition, require a userspace memory context to
perform the copy operation. They can't be called from interrupt context,
kernel threads, or any other context where no userspace memory context is
present.
> Are your video buffers allocated by the kernel or not? How is USB accessed
> when you don't have the Linux kernel USB framework around?
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question about V4L2_MEMORY_USERPTR
2012-07-02 9:24 ` Laurent Pinchart
@ 2012-07-02 19:07 ` Hans Petter Selasky
2012-07-05 17:24 ` Laurent Pinchart
0 siblings, 1 reply; 5+ messages in thread
From: Hans Petter Selasky @ 2012-07-02 19:07 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Sakari Ailus, linux-media
Hi Laurent and Sakari,
For the sake of the matter, here is the driver in question:
http://www.freshports.org/multimedia/webcamd/
Under native-Linux (kernel mode):
I've looked at the linux-media code a bit and it appears that video data is
copied directly from the USB callback functions to the destination process in
userspace. This works because the userspace buffer is mapped into kernel
memory it appears. Correct me if I'm wrong:
video/videobuf-core.c:
err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
Under FreeBSD where the Linux kernel code is running in user-space as a driver
daemon, this part cannot be done exactly like this, so I've just patched out
the V4L2_MEMORY_USERPTR feature until further.
Am I clear?
--HPS
On Monday 02 July 2012 11:24:15 Laurent Pinchart wrote:
> On Sunday 01 July 2012 17:00:58 Sakari Ailus wrote:
> > On Fri, Mar 23, 2012 at 08:19:45AM +0100, Hans Petter Selasky wrote:
> > > Hi,
> > >
> > > I have a question about V4L2_MEMORY_USERPTR:
> > >
> > > From which context are the kernel's "copy_to_user()" functions called
> > > in relation to V4L2_MEMORY_USERPTR ? Can this be a USB callback
> > > function or is it only syscalls, like read/write/ioctl that are
> > > allowed to call "copy_to_user()" ?
> > >
> > > The reason for asking is that I am maintaining a userland port of the
> > > media tree's USB drivers for FreeBSD. At the present moment it is not
> > > allowed to call copy_to_user() or copy_from_user() unless the backtrace
> > > shows a syscall, so the V4L2_MEMORY_USERPTR feature is simply removed
> > > and disabled. I'm currently thinking how I can enable this feature.
> >
> > I hope this is still relevant --- I just read your message the first
> > time.
> >
> > I don't know how V4L2 is being used in FreeBSD userland, but the intent
> > of copy_to_user() function is to copy the contents of kernel memory to
> > somewhere the user space has a mapping to (and the other way around for
> > copy_from_user()).
>
> copy_(to|from)_user(), by definition, require a userspace memory context to
> perform the copy operation. They can't be called from interrupt context,
> kernel threads, or any other context where no userspace memory context is
> present.
>
> > Are your video buffers allocated by the kernel or not? How is USB
> > accessed when you don't have the Linux kernel USB framework around?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question about V4L2_MEMORY_USERPTR
2012-07-02 19:07 ` Hans Petter Selasky
@ 2012-07-05 17:24 ` Laurent Pinchart
0 siblings, 0 replies; 5+ messages in thread
From: Laurent Pinchart @ 2012-07-05 17:24 UTC (permalink / raw)
To: Hans Petter Selasky; +Cc: Sakari Ailus, linux-media
Hi Hans-Petter,
On Monday 02 July 2012 21:07:56 Hans Petter Selasky wrote:
> Hi Laurent and Sakari,
>
> For the sake of the matter, here is the driver in question:
> http://www.freshports.org/multimedia/webcamd/
>
> Under native-Linux (kernel mode):
>
> I've looked at the linux-media code a bit and it appears that video data is
> copied directly from the USB callback functions to the destination process
> in userspace. This works because the userspace buffer is mapped into kernel
> memory it appears. Correct me if I'm wrong:
>
> video/videobuf-core.c:
>
> err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
It's hard to tell from that line only. V4L2_MEMORY_USERPTR takes a memory
pointer from userspace and uses it in the kernel. How the memory is used
depends on the driver, it can be converted to a scatter list of physical
memory and passed to the hardware, mapped to the kernel, be accessed using
copy_from_user/copy_to_user, ...
BTW videobuf1 is outdated, drivers will eventually be ported to videobuf2.
> Under FreeBSD where the Linux kernel code is running in user-space as a
> driver daemon, this part cannot be done exactly like this, so I've just
> patched out the V4L2_MEMORY_USERPTR feature until further.
>
> Am I clear?
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-07-05 17:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-23 7:19 Question about V4L2_MEMORY_USERPTR Hans Petter Selasky
2012-07-01 14:00 ` Sakari Ailus
2012-07-02 9:24 ` Laurent Pinchart
2012-07-02 19:07 ` Hans Petter Selasky
2012-07-05 17:24 ` Laurent Pinchart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).