linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question regarding DMA xfer to user space directly
@ 2003-07-08 14:50 Alan Shih
  2003-07-08 15:22 ` Alan Cox
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Shih @ 2003-07-08 14:50 UTC (permalink / raw)
  To: linux-kernel

Is there a provision in MM for DMA transfer to user space directly without
allocating a kernel buffer?

TIA

Alan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question regarding DMA xfer to user space directly
  2003-07-08 14:50 Question regarding DMA xfer to user space directly Alan Shih
@ 2003-07-08 15:22 ` Alan Cox
  2003-07-09 17:35   ` Alan Shih
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2003-07-08 15:22 UTC (permalink / raw)
  To: Alan Shih; +Cc: Linux Kernel Mailing List

On Maw, 2003-07-08 at 15:50, Alan Shih wrote:
> Is there a provision in MM for DMA transfer to user space directly without
> allocating a kernel buffer?

Yes. Its used both for O_DIRECT I/O (direct to disk I/O from userspace)
and for things like tv capture cards. The kernel allows a driver to pin
user pages and obtain mappings for them. Note that for large systems 
user pages may be above the 32bit boundary so you need DAC capable
hardware to get the best results


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Question regarding DMA xfer to user space directly
  2003-07-08 15:22 ` Alan Cox
@ 2003-07-09 17:35   ` Alan Shih
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Shih @ 2003-07-09 17:35 UTC (permalink / raw)
  To: Alan Cox; +Cc: Linux Kernel Mailing List

Next question would be what are the steps that the driver need to ping user
pages before setting up the xfer?

Thanks.

-----Original Message-----
From: Alan Cox [mailto:alan@lxorguk.ukuu.org.uk]
Sent: Tuesday, July 08, 2003 8:22 AM
To: Alan Shih
Cc: Linux Kernel Mailing List
Subject: Re: Question regarding DMA xfer to user space directly


On Maw, 2003-07-08 at 15:50, Alan Shih wrote:
> Is there a provision in MM for DMA transfer to user space directly without
> allocating a kernel buffer?

Yes. Its used both for O_DIRECT I/O (direct to disk I/O from userspace)
and for things like tv capture cards. The kernel allows a driver to pin
user pages and obtain mappings for them. Note that for large systems
user pages may be above the 32bit boundary so you need DAC capable
hardware to get the best results


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Question regarding DMA xfer to user space directly
@ 2003-07-10 20:55 Lee, Shuyu
  0 siblings, 0 replies; 6+ messages in thread
From: Lee, Shuyu @ 2003-07-10 20:55 UTC (permalink / raw)
  To: Linux Kernel Mailing List, 'Alan Shih'

Alan(Shih),

I have also struggled with the same issue - how to DMA data to a user buffer
directly. The following is my solution. Hopefully it will make your life
easier. Based on the inquiries I received privately since I posted my
questions, you are not the only one who is stuck on this issue. 

Here is the pseudo code:

User code:
  pUsrVirt = malloc(bufSize);
  pass pUsrVirt and bufSize to driver via an ioctl call;

Driver code;
  receive pUsrVirt and bufSize from user via an ioctl call;
  alloc_kiovec(1, &iobuf);
  map_user_kiobuf(READ, iobuf, (unsigned long)pUsrVirt, bufSize);
  physAddr = page_to_bus(iobuf->maplist[idx]) 
    + ((unsigned long)pUsrVirt & OFFMASK);
Once you get the physical address, physAddr, for a particular memory page,
you can then construct the DMA chain.

A few things you should be aware of:
1) If you use RedHat7.2 or RedHat8.0, make sure that you compile your driver
using the gcc comes with them (gcc2.96 and gcc3.2 respectively). gcc2.95 and
gcc3.2.1 will NOT work. 
2) If you use RedHat7.2, add the following define in your code.
#if (__GNUC__ == 2 && __GNUC_MINOR__ == 96)
#define page_to_bus(page) \
        (ULONG)(((page) - mem_map) << PAGE_SHIFT)
#endif

Hope that helps.
Shuyu
PS. I'd like to take this opportunity to thank everyone who helped me
solving this problem.

 -----Original Message-----
From: 	Alan Shih [mailto:alan@storlinksemi.com] 
Sent:	Wednesday, July 09, 2003 1:35 PM
To:	Alan Cox
Cc:	Linux Kernel Mailing List
Subject:	RE: Question regarding DMA xfer to user space directly

Next question would be what are the steps that the driver need to ping user
pages before setting up the xfer?

Thanks.

-----Original Message-----
From: Alan Cox [mailto:alan@lxorguk.ukuu.org.uk]
Sent: Tuesday, July 08, 2003 8:22 AM
To: Alan Shih
Cc: Linux Kernel Mailing List
Subject: Re: Question regarding DMA xfer to user space directly


On Maw, 2003-07-08 at 15:50, Alan Shih wrote:
> Is there a provision in MM for DMA transfer to user space directly without
> allocating a kernel buffer?

Yes. Its used both for O_DIRECT I/O (direct to disk I/O from userspace)
and for things like tv capture cards. The kernel allows a driver to pin
user pages and obtain mappings for them. Note that for large systems
user pages may be above the 32bit boundary so you need DAC capable
hardware to get the best results

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question regarding DMA xfer to user space directly
  2003-07-10  5:22 ` Mikael Starvik
@ 2003-07-10 10:26   ` Jens Axboe
  0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2003-07-10 10:26 UTC (permalink / raw)
  To: Mikael Starvik
  Cc: 'Alan Shih', 'Alan Cox',
	'Linux Kernel Mailing List'

On Thu, Jul 10 2003, Mikael Starvik wrote:
> Hi,
> 
> Use map_user_kiobuf to do this. There are several examples
> in the kernel tree. One of the simplest may be 
> arch/cris/drivers/examples/kiobuftest.c.

get_user_pages() is a much better idea, considering 2.5/6 has no concept
of kiobufs.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Question regarding DMA xfer to user space directly
       [not found] <3C6BEE8B5E1BAC42905A93F13004E8AB034C5623@mailse01.axis.se>
@ 2003-07-10  5:22 ` Mikael Starvik
  2003-07-10 10:26   ` Jens Axboe
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Starvik @ 2003-07-10  5:22 UTC (permalink / raw)
  To: 'Alan Shih', 'Alan Cox'
  Cc: 'Linux Kernel Mailing List'

Hi,

Use map_user_kiobuf to do this. There are several examples
in the kernel tree. One of the simplest may be 
arch/cris/drivers/examples/kiobuftest.c.

/Mikael

-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of Alan Shih
Sent: Wednesday, July 09, 2003 7:35 PM
To: Alan Cox
Cc: Linux Kernel Mailing List
Subject: RE: Question regarding DMA xfer to user space directly


Next question would be what are the steps that the driver need to ping user
pages before setting up the xfer?

Thanks.

-----Original Message-----
From: Alan Cox [mailto:alan@lxorguk.ukuu.org.uk]
Sent: Tuesday, July 08, 2003 8:22 AM
To: Alan Shih
Cc: Linux Kernel Mailing List
Subject: Re: Question regarding DMA xfer to user space directly


On Maw, 2003-07-08 at 15:50, Alan Shih wrote:
> Is there a provision in MM for DMA transfer to user space directly 
> without allocating a kernel buffer?

Yes. Its used both for O_DIRECT I/O (direct to disk I/O from userspace) and
for things like tv capture cards. The kernel allows a driver to pin user
pages and obtain mappings for them. Note that for large systems user pages
may be above the 32bit boundary so you need DAC capable hardware to get the
best results

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-07-10 20:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-08 14:50 Question regarding DMA xfer to user space directly Alan Shih
2003-07-08 15:22 ` Alan Cox
2003-07-09 17:35   ` Alan Shih
     [not found] <3C6BEE8B5E1BAC42905A93F13004E8AB034C5623@mailse01.axis.se>
2003-07-10  5:22 ` Mikael Starvik
2003-07-10 10:26   ` Jens Axboe
2003-07-10 20:55 Lee, Shuyu

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).