From: Christoph Hellwig <hch@lst.de> To: Vineet Gupta <vgupta@synopsys.com> Cc: Jonas Bonn <jonas@southpole.se>, linux-xtensa@linux-xtensa.org, Vladimir Murzin <vladimir.murzin@arm.com>, linux-parisc@vger.kernel.org, Helge Deller <deller@gmx.de>, linux-kernel@vger.kernel.org, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>, iommu@lists.linux-foundation.org, openrisc@lists.librecores.org, Stafford Horne <shorne@gmail.com>, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/7] dma-direct: handle DMA_ATTR_NON_CONSISTENT in common code Date: Fri, 14 Jun 2019 16:44:29 +0200 [thread overview] Message-ID: <20190614144431.21760-6-hch@lst.de> (raw) In-Reply-To: <20190614144431.21760-1-hch@lst.de> Only call into arch_dma_alloc if we require an uncached mapping, and remove the parisc code manually doing normal cached DMA_ATTR_NON_CONSISTENT allocations. Signed-off-by: Christoph Hellwig <hch@lst.de> --- arch/parisc/kernel/pci-dma.c | 48 ++++++++++-------------------------- kernel/dma/direct.c | 4 +-- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/arch/parisc/kernel/pci-dma.c b/arch/parisc/kernel/pci-dma.c index 239162355b58..ca35d9a76e50 100644 --- a/arch/parisc/kernel/pci-dma.c +++ b/arch/parisc/kernel/pci-dma.c @@ -394,17 +394,20 @@ pcxl_dma_init(void) __initcall(pcxl_dma_init); -static void *pcxl_dma_alloc(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) +void *arch_dma_alloc(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { unsigned long vaddr; unsigned long paddr; int order; + if (boot_cpu_data.cpu_type != pcxl2 && boot_cpu_data.cpu_type != pcxl) + return NULL; + order = get_order(size); size = 1 << (order + PAGE_SHIFT); vaddr = pcxl_alloc_range(size); - paddr = __get_free_pages(flag | __GFP_ZERO, order); + paddr = __get_free_pages(gfp | __GFP_ZERO, order); flush_kernel_dcache_range(paddr, size); paddr = __pa(paddr); map_uncached_pages(vaddr, size, paddr); @@ -421,44 +424,19 @@ static void *pcxl_dma_alloc(struct device *dev, size_t size, return (void *)vaddr; } -static void *pcx_dma_alloc(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) -{ - void *addr; - - if ((attrs & DMA_ATTR_NON_CONSISTENT) == 0) - return NULL; - - addr = (void *)__get_free_pages(flag | __GFP_ZERO, get_order(size)); - if (addr) - *dma_handle = (dma_addr_t)virt_to_phys(addr); - - return addr; -} - -void *arch_dma_alloc(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) -{ - - if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) - return pcxl_dma_alloc(dev, size, dma_handle, gfp, attrs); - else - return pcx_dma_alloc(dev, size, dma_handle, gfp, attrs); -} - void arch_dma_free(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, unsigned long attrs) { int order = get_order(size); - if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) { - size = 1 << (order + PAGE_SHIFT); - unmap_uncached_pages((unsigned long)vaddr, size); - pcxl_free_range((unsigned long)vaddr, size); + WARN_ON_ONCE(boot_cpu_data.cpu_type != pcxl2 && + boot_cpu_data.cpu_type != pcxl); - vaddr = __va(dma_handle); - } - free_pages((unsigned long)vaddr, get_order(size)); + size = 1 << (order + PAGE_SHIFT); + unmap_uncached_pages((unsigned long)vaddr, size); + pcxl_free_range((unsigned long)vaddr, size); + + free_pages((unsigned long)__va(dma_handle), order); } void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index c2893713bf80..fc354f4f490b 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -191,7 +191,7 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { if (!IS_ENABLED(CONFIG_ARCH_HAS_UNCACHED_SEGMENT) && - !dev_is_dma_coherent(dev)) + dma_alloc_need_uncached(dev, attrs)) return arch_dma_alloc(dev, size, dma_handle, gfp, attrs); return dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs); } @@ -200,7 +200,7 @@ void dma_direct_free(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_addr, unsigned long attrs) { if (!IS_ENABLED(CONFIG_ARCH_HAS_UNCACHED_SEGMENT) && - !dev_is_dma_coherent(dev)) + dma_alloc_need_uncached(dev, attrs)) arch_dma_free(dev, size, cpu_addr, dma_addr, attrs); else dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs); -- 2.20.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
WARNING: multiple messages have this Message-ID (diff)
From: Hillf Danton <hdanton@sina.com> To: Christoph Hellwig <hch@lst.de> Cc: Jonas Bonn <jonas@southpole.se>, linux-xtensa@linux-xtensa.org, Vladimir Murzin <vladimir.murzin@arm.com>, linux-parisc@vger.kernel.org, Vineet Gupta <vgupta@synopsys.com>, Helge Deller <deller@gmx.de>, linux-kernel@vger.kernel.org, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>, iommu@lists.linux-foundation.org, openrisc@lists.librecores.org, Stafford Horne <shorne@gmail.com>, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 5/7] dma-direct: handle DMA_ATTR_NON_CONSISTENT in common code Date: Sun, 16 Jun 2019 18:08:40 +0800 [thread overview] Message-ID: <20190614144431.21760-6-hch@lst.de> (raw) Message-ID: <20190616100840.JIOzJbU3hza80xiyDoD42GucwpSxw0lsU7Y1eHzJAWo@z> (raw) In-Reply-To: <20190614144431.21760-1-hch@lst.de> Hello Christoph On Fri, 14 Jun 2019 16:44:29 +0200 Christoph Hellwig wrote: > Only call into arch_dma_alloc if we require an uncached mapping, > and remove the parisc code manually doing normal cached > DMA_ATTR_NON_CONSISTENT allocations. > > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > arch/parisc/kernel/pci-dma.c | 48 ++++++++++-------------------------- > kernel/dma/direct.c | 4 +-- > 2 files changed, 15 insertions(+), 37 deletions(-) > > diff --git a/arch/parisc/kernel/pci-dma.c b/arch/parisc/kernel/pci-dma.c > index 239162355b58..ca35d9a76e50 100644 > --- a/arch/parisc/kernel/pci-dma.c > +++ b/arch/parisc/kernel/pci-dma.c > @@ -394,17 +394,20 @@ pcxl_dma_init(void) > > __initcall(pcxl_dma_init); > > -static void *pcxl_dma_alloc(struct device *dev, size_t size, > - dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) > +void *arch_dma_alloc(struct device *dev, size_t size, > + dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) > { > unsigned long vaddr; > unsigned long paddr; > int order; > > + if (boot_cpu_data.cpu_type != pcxl2 && boot_cpu_data.cpu_type != pcxl) > + return NULL; > + Literally, any cpu (call it cpuW) other than pcx12 and pcx1 will no longer do dma alloc for any device with this patch applied. On the other hand, !dev_is_dma_coherent(dev) && !(attrs & DMA_ATTR_NON_CONSISTENT) will ask any cpu to do dma alloc, regardless of pcx1. This patch works imo unless cpuW plays games only with devices that are dma coherent. I doubt it is true. -- Hillf > order = get_order(size); > size = 1 << (order + PAGE_SHIFT); > vaddr = pcxl_alloc_range(size); > - paddr = __get_free_pages(flag | __GFP_ZERO, order); > + paddr = __get_free_pages(gfp | __GFP_ZERO, order); > flush_kernel_dcache_range(paddr, size); > paddr = __pa(paddr); > map_uncached_pages(vaddr, size, paddr); > @@ -421,44 +424,19 @@ static void *pcxl_dma_alloc(struct device *dev, size_t size, > return (void *)vaddr; > } > > -static void *pcx_dma_alloc(struct device *dev, size_t size, > - dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) > -{ > - void *addr; > - > - if ((attrs & DMA_ATTR_NON_CONSISTENT) == 0) > - return NULL; > - > - addr = (void *)__get_free_pages(flag | __GFP_ZERO, get_order(size)); > - if (addr) > - *dma_handle = (dma_addr_t)virt_to_phys(addr); > - > - return addr; > -} > - > -void *arch_dma_alloc(struct device *dev, size_t size, > - dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) > -{ > - > - if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) > - return pcxl_dma_alloc(dev, size, dma_handle, gfp, attrs); > - else > - return pcx_dma_alloc(dev, size, dma_handle, gfp, attrs); > -} > - > void arch_dma_free(struct device *dev, size_t size, void *vaddr, > dma_addr_t dma_handle, unsigned long attrs) > { > int order = get_order(size); > > - if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) { > - size = 1 << (order + PAGE_SHIFT); > - unmap_uncached_pages((unsigned long)vaddr, size); > - pcxl_free_range((unsigned long)vaddr, size); > + WARN_ON_ONCE(boot_cpu_data.cpu_type != pcxl2 && > + boot_cpu_data.cpu_type != pcxl); > > - vaddr = __va(dma_handle); > - } > - free_pages((unsigned long)vaddr, get_order(size)); > + size = 1 << (order + PAGE_SHIFT); > + unmap_uncached_pages((unsigned long)vaddr, size); > + pcxl_free_range((unsigned long)vaddr, size); > + > + free_pages((unsigned long)__va(dma_handle), order); > } > > void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index c2893713bf80..fc354f4f490b 100644 > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -191,7 +191,7 @@ void *dma_direct_alloc(struct device *dev, size_t size, > dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) > { > if (!IS_ENABLED(CONFIG_ARCH_HAS_UNCACHED_SEGMENT) && > - !dev_is_dma_coherent(dev)) > + dma_alloc_need_uncached(dev, attrs)) > return arch_dma_alloc(dev, size, dma_handle, gfp, attrs); > return dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs); > } > @@ -200,7 +200,7 @@ void dma_direct_free(struct device *dev, size_t size, > void *cpu_addr, dma_addr_t dma_addr, unsigned long attrs) > { > if (!IS_ENABLED(CONFIG_ARCH_HAS_UNCACHED_SEGMENT) && > - !dev_is_dma_coherent(dev)) > + dma_alloc_need_uncached(dev, attrs)) > arch_dma_free(dev, size, cpu_addr, dma_addr, attrs); > else > dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs); > -- > 2.20.1 > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2019-06-14 14:45 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-14 14:44 handle "special" dma allocation in common code Christoph Hellwig 2019-06-14 14:44 ` [PATCH 1/7] arm-nommu: remove the partial DMA_ATTR_NON_CONSISTENT support Christoph Hellwig 2019-06-24 14:23 ` Vladimir Murzin 2019-06-25 6:13 ` Christoph Hellwig 2019-06-14 14:44 ` [PATCH 2/7] arc: " Christoph Hellwig 2019-06-14 14:44 ` [PATCH 3/7] openrisc: " Christoph Hellwig 2019-06-16 9:17 ` Stafford Horne 2019-06-14 14:44 ` [PATCH 4/7] dma-mapping: add a dma_alloc_need_uncached helper Christoph Hellwig 2019-06-14 14:44 ` Christoph Hellwig [this message] 2019-06-16 10:08 ` [PATCH 5/7] dma-direct: handle DMA_ATTR_NON_CONSISTENT in common code Hillf Danton 2019-06-25 6:11 ` Christoph Hellwig 2019-06-25 12:23 ` Helge Deller 2019-06-25 12:28 ` Christoph Hellwig 2019-06-14 14:44 ` [PATCH 6/7] dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING " Christoph Hellwig 2019-06-29 15:09 ` Guenter Roeck 2019-06-14 14:44 ` [PATCH 7/7] arc: use the generic remapping allocator for coherent DMA allocations Christoph Hellwig 2019-06-14 18:05 ` Eugeniy Paltsev 2019-06-15 8:35 ` hch
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=20190614144431.21760-6-hch@lst.de \ --to=hch@lst.de \ --cc=deller@gmx.de \ --cc=iommu@lists.linux-foundation.org \ --cc=jonas@southpole.se \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-parisc@vger.kernel.org \ --cc=linux-snps-arc@lists.infradead.org \ --cc=linux-xtensa@linux-xtensa.org \ --cc=openrisc@lists.librecores.org \ --cc=shorne@gmail.com \ --cc=stefan.kristiansson@saunalahti.fi \ --cc=vgupta@synopsys.com \ --cc=vladimir.murzin@arm.com \ /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 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).