* UIO DMA to userspace question @ 2010-08-07 18:38 Leon Woestenberg 2010-08-09 11:11 ` Hans J. Koch 2010-08-15 11:33 ` Avi Kivity 0 siblings, 2 replies; 6+ messages in thread From: Leon Woestenberg @ 2010-08-07 18:38 UTC (permalink / raw) To: Tom Lyon, mst, hjk, gregkh, chrisw, joro, avi, linux-kernel Hello all, can I use the UIO framework for the following? The userspace portion of the driver allocates memory in user-space using malloc() - usually resulting in a scatter pages in physical memory. The UIO kernel portion of the driver maps those using pci_map_sg(). Is this possible, or does the UIO framework assume memory for DMA is allocated in kernel space? Thanks, -- Leon ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: UIO DMA to userspace question 2010-08-07 18:38 UIO DMA to userspace question Leon Woestenberg @ 2010-08-09 11:11 ` Hans J. Koch 2010-08-10 0:12 ` Hans J. Koch 2010-08-15 11:33 ` Avi Kivity 1 sibling, 1 reply; 6+ messages in thread From: Hans J. Koch @ 2010-08-09 11:11 UTC (permalink / raw) To: Leon Woestenberg Cc: Tom Lyon, mst, hjk, gregkh, chrisw, joro, avi, linux-kernel On Sat, Aug 07, 2010 at 08:38:30PM +0200, Leon Woestenberg wrote: > Hello all, > > can I use the UIO framework for the following? > > The userspace portion of the driver allocates memory in user-space > using malloc() - usually resulting in a scatter pages in physical > memory. > The UIO kernel portion of the driver maps those using pci_map_sg(). > > Is this possible, or does the UIO framework assume memory for DMA is > allocated in kernel space? You would have to write your own mmap() function and and set the pointer to it in struct uio_info->mmap. Have a look at uio_mmap() in drivers/uio/uio.c to see when your function will be called, and what is checked before that call. If that works, we might invent a new UIO_MEM_* type, and move your function over to the UIO core, if this is interesting for other people. Anyway, sooner or later we should have a generic way of handling DMA in UIO. The topic comes up every few month, but nobody came up with an acceptable solution yet. It should probably be a separate uio_dma device, e.g. for a /dev/uio0 you'll get a /dev/uio_dma0 if the driver sets a flag indicating it needs DMA support. This new uio_dma device should then have an API (to be defined, without ioctl if possible) that provides the necessary functionality. But that's just a thought ATM. Ideas/patches are welcome. Thanks, Hans ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: UIO DMA to userspace question 2010-08-09 11:11 ` Hans J. Koch @ 2010-08-10 0:12 ` Hans J. Koch 2010-08-11 18:42 ` Leon Woestenberg 0 siblings, 1 reply; 6+ messages in thread From: Hans J. Koch @ 2010-08-10 0:12 UTC (permalink / raw) To: Hans J. Koch Cc: Leon Woestenberg, Tom Lyon, mst, gregkh, chrisw, joro, avi, linux-kernel On Mon, Aug 09, 2010 at 01:11:56PM +0200, Hans J. Koch wrote: > On Sat, Aug 07, 2010 at 08:38:30PM +0200, Leon Woestenberg wrote: > > Hello all, > > > > can I use the UIO framework for the following? > > > > The userspace portion of the driver allocates memory in user-space > > using malloc() - usually resulting in a scatter pages in physical > > memory. > > The UIO kernel portion of the driver maps those using pci_map_sg(). > > > > Is this possible, or does the UIO framework assume memory for DMA is > > allocated in kernel space? > > You would have to write your own mmap() function and and set the pointer > to it in struct uio_info->mmap. Have a look at uio_mmap() in A few more thoughts about that: The UIO core currently doesn't support dynamically allocated memory. That means, even if you manage to mmap your memory allocated in userspace, it won't show up in sysfs. ATM, all UIO supports is memory allocated at device creation time in kernel space. So, what your trying to do is something that could probably work. The uio_info->mmap pointer was made for unusual mappings. But it still causes me some headaches. I'm not sure if this can be considered a clean solution. An extension that makes UIO deal properly with dynamically allocated (DMA-) memory would certainly be preferable. Hans ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: UIO DMA to userspace question 2010-08-10 0:12 ` Hans J. Koch @ 2010-08-11 18:42 ` Leon Woestenberg 2010-08-12 0:14 ` Hans J. Koch 0 siblings, 1 reply; 6+ messages in thread From: Leon Woestenberg @ 2010-08-11 18:42 UTC (permalink / raw) To: Hans J. Koch; +Cc: Tom Lyon, mst, gregkh, chrisw, joro, avi, linux-kernel Hello Hans, On Tue, Aug 10, 2010 at 2:12 AM, Hans J. Koch <hjk@linutronix.de> wrote: > On Mon, Aug 09, 2010 at 01:11:56PM +0200, Hans J. Koch wrote: >> On Sat, Aug 07, 2010 at 08:38:30PM +0200, Leon Woestenberg wrote: >> > Hello all, >> > >> > can I use the UIO framework for the following? >> > >> > The userspace portion of the driver allocates memory in user-space >> > using malloc() - usually resulting in a scatter pages in physical >> > memory. >> > The UIO kernel portion of the driver maps those using pci_map_sg(). >> > >> > Is this possible, or does the UIO framework assume memory for DMA is >> > allocated in kernel space? >> >> You would have to write your own mmap() function and and set the pointer >> to it in struct uio_info->mmap. Have a look at uio_mmap() in > Why would I need to mmap() the user space memory into kernel space? Looking from a traditional device driver perspective the kernel space only needs to know the virtual address and the length of the buffer, and can then make up a scatter list. After DMA finished, it needs to synchronize caches. In fact, from my simplistic view, the kernel provides a few internal house keeping tools, and we need to export this functionality into UIO API's. SGDMA to from user memory would be one of the uses. In fact, when UIO started, I also expected the kernel buffers to be user application managed, like the driver steering code. > uio_info->mmap pointer was made for unusual mappings. But it still causes > me some headaches. I'm not sure if this can be considered a clean solution. > An extension that makes UIO deal properly with dynamically allocated (DMA-) > memory would certainly be preferable. > Thanks for thinking along. I am currently refraining from using UIO, as I don't like the head ache feature :-) Regards, -- Leon ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: UIO DMA to userspace question 2010-08-11 18:42 ` Leon Woestenberg @ 2010-08-12 0:14 ` Hans J. Koch 0 siblings, 0 replies; 6+ messages in thread From: Hans J. Koch @ 2010-08-12 0:14 UTC (permalink / raw) To: Leon Woestenberg Cc: Hans J. Koch, Tom Lyon, mst, gregkh, chrisw, joro, avi, linux-kernel On Wed, Aug 11, 2010 at 08:42:35PM +0200, Leon Woestenberg wrote: [...] > > I am currently refraining from using UIO, as I don't like the head > ache feature :-) Well, if you need feature X, capability Y, or usecase Z, feel free to send patches. I (and several of my colleagues) wrote quite a lot of UIO drivers for various chips in the last 4 years. I never had a device that needed DMA on my desk yet, otherwise support for it would be in mainline now. UIO was mainly invented to prevent people from writing large character device drivers that will never make it to mainline, and then having to maintain them off-tree. It is not a general purpose driver interface but a small framework to handle a special class of hardware that doesn't fit into any other subsystem. If you've got such hardware, and you need a certain feature, think about how it can be done, and let us know. Thanks, Hans > > Regards, > -- > Leon ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: UIO DMA to userspace question 2010-08-07 18:38 UIO DMA to userspace question Leon Woestenberg 2010-08-09 11:11 ` Hans J. Koch @ 2010-08-15 11:33 ` Avi Kivity 1 sibling, 0 replies; 6+ messages in thread From: Avi Kivity @ 2010-08-15 11:33 UTC (permalink / raw) To: Leon Woestenberg; +Cc: Tom Lyon, mst, hjk, gregkh, chrisw, joro, linux-kernel On 08/07/2010 09:38 PM, Leon Woestenberg wrote: > Hello all, > > can I use the UIO framework for the following? > > The userspace portion of the driver allocates memory in user-space > using malloc() - usually resulting in a scatter pages in physical > memory. > The UIO kernel portion of the driver maps those using pci_map_sg(). > > Is this possible, or does the UIO framework assume memory for DMA is > allocated in kernel space? Look at the new VFIO driver, which can do DMA if you have an IOMMU. -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-08-15 15:36 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-08-07 18:38 UIO DMA to userspace question Leon Woestenberg 2010-08-09 11:11 ` Hans J. Koch 2010-08-10 0:12 ` Hans J. Koch 2010-08-11 18:42 ` Leon Woestenberg 2010-08-12 0:14 ` Hans J. Koch 2010-08-15 11:33 ` Avi Kivity
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox