From: Peter Zijlstra <peterz@infradead.org> To: "Hans J. Koch" <hjk@linutronix.de> Cc: edward_estabrook@agilent.com, linux-kernel@vger.kernel.org, gregkh@suse.de, edward.estabrook@gmail.com, hugh <hugh@veritas.com>, linux-mm <linux-mm@kvack.org>, Thomas Gleixner <tglx@linutronix.de> Subject: Re: [PATCH 1/1] Userspace I/O (UIO): Add support for userspace DMA Date: Fri, 05 Dec 2008 08:10:59 +0100 [thread overview] Message-ID: <1228461060.18899.8.camel@twins> (raw) In-Reply-To: <20081204180809.GB3079@local> On Thu, 2008-12-04 at 19:08 +0100, Hans J. Koch wrote: > On Thu, Dec 04, 2008 at 09:39:02AM +0100, Peter Zijlstra wrote: > > On Wed, 2008-12-03 at 14:39 -0700, edward_estabrook@agilent.com wrote: > > > From: Edward Estabrook <Edward_Estabrook@agilent.com> > > > > > > Here is a patch that adds the ability to dynamically allocate (and > > > use) coherent DMA from userspace by extending the userspace IO driver. > > > This patch applies against 2.6.28-rc6. > > > > > > The gist of this implementation is to overload uio's mmap > > > functionality to allocate and map a new DMA region on demand. The > > > bus-specific DMA address as returned by dma_alloc_coherent is made > > > available to userspace in the 1st long word of the newly created > > > region (as well as through the conventional 'addr' file in sysfs). > > > > > > To allocate a DMA region you use the following: > > > /* Pass this magic number to mmap as offset to dynamically allocate a > > > chunk of memory */ #define DMA_MEM_ALLOCATE_MMAP_OFFSET 0xFFFFF000UL > > > > > > void* memory = mmap (NULL, size, PROT_READ | PROT_WRITE , MAP_SHARED, > > > fd, DMA_MEM_ALLOCATE_MMAP_OFFSET); u_int64_t *addr = *(u_int64_t *) > > > memory; > > > > > > where 'size' is the size in bytes of the region you want and fd is the > > > opened /dev/uioN file. > > > > > > Allocation occurs in page sized pieces by design to ensure that > > > buffers are page-aligned. > > > > > > Memory is released when uio_unregister_device() is called. > > > > > > I have used this extensively on a 2.6.21-based kernel and ported it to > > > 2.6.28-rc6 for review / submission here. > > > > > > Comments appreciated! > > > > Yuck! > > > > Why not create another special device that will give you DMA memory when > > you mmap it? That would also allow you to obtain the physical address > > without this utter horrid hack of writing it in the mmap'ed memory. > > > > /dev/uioN-dma would seem like a fine name for that. > > I don't like to have a separate device for DMA memory. It would completely > break the current concept of userspace drivers if you had to get normal > memory from one device and DMA memory from another. Note that one driver > can have both. How would that break anything, the one driver can simply open both files. > But I agree that it's confusing if the physical address is stored somewhere > in the mapped memory. That should simply be omitted, we have that information > in sysfs anyway - like for any other memory mappings. But I guess we need > some kind of "type" or "flags" attribute for the mappings so that userspace > can find out if a mapping is DMA capable or not. We have that, different file. I'll NAK any attempt that rapes the mmap interface like proposed - that is just not an option.
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org> To: "Hans J. Koch" <hjk@linutronix.de> Cc: edward_estabrook@agilent.com, linux-kernel@vger.kernel.org, gregkh@suse.de, edward.estabrook@gmail.com, hugh <hugh@veritas.com>, linux-mm <linux-mm@kvack.org>, Thomas Gleixner <tglx@linutronix.de> Subject: Re: [PATCH 1/1] Userspace I/O (UIO): Add support for userspace DMA Date: Fri, 05 Dec 2008 08:10:59 +0100 [thread overview] Message-ID: <1228461060.18899.8.camel@twins> (raw) In-Reply-To: <20081204180809.GB3079@local> On Thu, 2008-12-04 at 19:08 +0100, Hans J. Koch wrote: > On Thu, Dec 04, 2008 at 09:39:02AM +0100, Peter Zijlstra wrote: > > On Wed, 2008-12-03 at 14:39 -0700, edward_estabrook@agilent.com wrote: > > > From: Edward Estabrook <Edward_Estabrook@agilent.com> > > > > > > Here is a patch that adds the ability to dynamically allocate (and > > > use) coherent DMA from userspace by extending the userspace IO driver. > > > This patch applies against 2.6.28-rc6. > > > > > > The gist of this implementation is to overload uio's mmap > > > functionality to allocate and map a new DMA region on demand. The > > > bus-specific DMA address as returned by dma_alloc_coherent is made > > > available to userspace in the 1st long word of the newly created > > > region (as well as through the conventional 'addr' file in sysfs). > > > > > > To allocate a DMA region you use the following: > > > /* Pass this magic number to mmap as offset to dynamically allocate a > > > chunk of memory */ #define DMA_MEM_ALLOCATE_MMAP_OFFSET 0xFFFFF000UL > > > > > > void* memory = mmap (NULL, size, PROT_READ | PROT_WRITE , MAP_SHARED, > > > fd, DMA_MEM_ALLOCATE_MMAP_OFFSET); u_int64_t *addr = *(u_int64_t *) > > > memory; > > > > > > where 'size' is the size in bytes of the region you want and fd is the > > > opened /dev/uioN file. > > > > > > Allocation occurs in page sized pieces by design to ensure that > > > buffers are page-aligned. > > > > > > Memory is released when uio_unregister_device() is called. > > > > > > I have used this extensively on a 2.6.21-based kernel and ported it to > > > 2.6.28-rc6 for review / submission here. > > > > > > Comments appreciated! > > > > Yuck! > > > > Why not create another special device that will give you DMA memory when > > you mmap it? That would also allow you to obtain the physical address > > without this utter horrid hack of writing it in the mmap'ed memory. > > > > /dev/uioN-dma would seem like a fine name for that. > > I don't like to have a separate device for DMA memory. It would completely > break the current concept of userspace drivers if you had to get normal > memory from one device and DMA memory from another. Note that one driver > can have both. How would that break anything, the one driver can simply open both files. > But I agree that it's confusing if the physical address is stored somewhere > in the mapped memory. That should simply be omitted, we have that information > in sysfs anyway - like for any other memory mappings. But I guess we need > some kind of "type" or "flags" attribute for the mappings so that userspace > can find out if a mapping is DMA capable or not. We have that, different file. I'll NAK any attempt that rapes the mmap interface like proposed - that is just not an option. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2008-12-05 7:11 UTC|newest] Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-12-03 21:39 [PATCH 1/1] Userspace I/O (UIO): Add support for userspace DMA edward_estabrook 2008-12-03 22:00 ` Leon Woestenberg 2008-12-04 2:44 ` Edward Estabrook 2008-12-04 0:49 ` Greg KH 2008-12-04 0:50 ` Greg KH 2008-12-04 1:49 ` Edward Estabrook 2008-12-04 8:39 ` Peter Zijlstra 2008-12-04 8:39 ` Peter Zijlstra 2008-12-04 10:27 ` Hugh Dickins 2008-12-04 10:27 ` Hugh Dickins 2008-12-23 21:32 ` Max Krasnyansky 2008-12-23 21:32 ` Max Krasnyansky 2008-12-04 18:08 ` Hans J. Koch 2008-12-04 18:08 ` Hans J. Koch 2008-12-05 7:10 ` Peter Zijlstra [this message] 2008-12-05 7:10 ` Peter Zijlstra 2008-12-05 9:44 ` Hans J. Koch 2008-12-05 9:44 ` Hans J. Koch 2008-12-06 0:32 ` Edward Estabrook 2008-12-06 0:32 ` Edward Estabrook 2008-12-12 17:25 ` Peter Zijlstra 2008-12-13 0:29 ` Hans J. Koch 2009-12-12 0:02 ` Earl Chew 2009-12-12 0:02 ` Earl Chew 2009-12-14 19:23 ` Hans J. Koch 2009-12-14 19:23 ` Hans J. Koch 2009-12-15 13:34 ` Earl Chew 2009-12-15 13:34 ` Earl Chew 2009-12-15 17:47 ` Earl Chew 2009-12-15 17:47 ` Earl Chew 2009-12-15 21:33 ` Hans J. Koch 2009-12-15 21:33 ` Hans J. Koch 2009-12-15 21:00 ` Hans J. Koch 2009-12-15 21:00 ` Hans J. Koch 2009-12-15 21:47 ` Earl Chew 2009-12-15 21:47 ` Earl Chew 2009-12-15 22:28 ` Hans J. Koch 2009-12-15 22:28 ` Hans J. Koch 2009-12-16 0:20 ` Earl Chew 2009-12-16 0:20 ` Earl Chew 2009-12-16 1:23 ` Hans J. Koch 2009-12-16 1:23 ` Hans J. Koch 2009-12-16 1:45 ` Earl Chew 2009-12-16 1:45 ` Earl Chew
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1228461060.18899.8.camel@twins \ --to=peterz@infradead.org \ --cc=edward.estabrook@gmail.com \ --cc=edward_estabrook@agilent.com \ --cc=gregkh@suse.de \ --cc=hjk@linutronix.de \ --cc=hugh@veritas.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=tglx@linutronix.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.