On Thu, Mar 19, 2009 at 02:47:10PM +0800, Priya Suryanarayanan wrote: > > Thanks, Shawn. I did look at the SCSI st and sg drivers briefly and will > continue to do so. I guess I did not understand the purpose of the > nopage handler. > > You said: --start quote-- > I should also mention that get_user_pages() does not map a user-mode > > buffer into the kernel address space. It only returns a page locked > array of the physical pages from the user-mode buffer. That is OK > because you normally don't need the buffer mapped to the kernel address > space when performing direct I/O. > --end quote-- > > Would it then be possible for my driver to submit the user buffer > addresses for DMA? Basically, I am asking is get_user_pages() the right > way to go for my problem? I think it depends on if your device supports scatter/gather DMA. If your device does support scatter/gather DMA then the user application would allocate a buffer, and pass that buffer to the kernel in an ioctl. The kernel would then call get_user_pages() on the buffer to find and page lock the physical pages of the buffer. Once you have the physical pages you can use the scatter/gather APIs (dma_map_sg(), sg_dma_address(), ...) to get the bus addresses to send to your device. For an example take a look at: drivers/media/video/ivtv/ivtv-udma.c Note none of this maps the memory into the kernel address space, because 99% of the time the kernel doesn't care about the data in the buffer when performing zero copy DMA. If the kernel does care about the data in the buffer you can use kmap() and kmap_atomic() to map one of the pages returned from get_user_pages(). If your device does not support scatter/gather DMA then you will have to allocate a physically contiguous buffer in the kernel with something like dma_alloc_coherent(), or perhaps kmalloc() + dma_map_single(). You could then map that buffer to user-mode with mmap(). Normally I would think that if you are performing zero copy DMA you would use get_user_pages() and the scatter/gather APIs. -- Shawn -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ