views:

79

answers:

2

hi everybody, i am writing a device driver on linux-2.6.26. I want to have a dma buffer mapped into userspace for sending data from driver to userspace application. Please suggest some good tutorial on it.

Thanks

+1  A: 

Well, if you have LDD, you can have a look at chapter 15, and more precisely page 435, where Direct I/O operations are described.

The kernel call that will help you achieve this is get_user_pages. In your case since you want to send data from kernel to userspace, you should set the write flag to 1.

Be also aware that the asynchronous I/O may allow you to achieve the same results but with your userspace application not having to wait for the read to finish which can be better.

Longfield
A: 

Take a good look at the Infiniband drivers. They go to much effort to make zero-copy DMA and RDMA to user-space work.

I forgot to add this before saving:

Doing DMA directly to user-space memory mappings is full of problems, so unless you have very high performance requirements like Infiniband or 10 Gb Ethernet, don't do it. Instead, copy the DMA'd data into the userspace buffers. It will save you much grief.

For just one example, what if the user's program exits before the DMA is complete? What if the user memory is reallocated to another process after exit but the hardware is still set to DMA into that page? Disaster!

Zan Lynx