[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1516758426-8127-3-git-send-email-f.fainelli@gmail.com>
Date: Tue, 23 Jan 2018 17:47:02 -0800
From: Florian Fainelli <f.fainelli@...il.com>
To: linux-mips@...ux-mips.org
Cc: Florian Fainelli <florian.fainelli@...adcom.com>,
Florian Fainelli <f.fainelli@...il.com>,
Ralf Baechle <ralf@...ux-mips.org>,
Kevin Cernekee <cernekee@...il.com>,
James Hogan <jhogan@...nel.org>,
Paul Burton <paul.burton@...s.com>,
Matt Redfearn <matt.redfearn@...s.com>,
"Maciej W. Rozycki" <macro@...s.com>,
Huacai Chen <chenhc@...ote.com>,
Kate Stewart <kstewart@...uxfoundation.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Marcin Nowakowski <marcin.nowakowski@...s.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Ingo Molnar <mingo@...nel.org>,
David Howells <dhowells@...hat.com>,
Kees Cook <keescook@...omium.org>,
Thomas Meyer <thomas@...3r.de>,
"Bryan O'Donoghue" <pure.logic@...us-software.ie>,
Robin Murphy <robin.murphy@....com>,
Michal Hocko <mhocko@...e.com>,
Lucas Stach <l.stach@...gutronix.de>,
Vladimir Murzin <vladimir.murzin@....com>,
Bart Van Assche <bart.vanassche@...disk.com>,
linux-kernel@...r.kernel.org (open list)
Subject: [PATCH RFC 2/6] MIPS: Allow platforms to override mapping/unmapping coherent
From: Florian Fainelli <florian.fainelli@...adcom.com>
In preparation for allowing support for Broadcom's eXtended Kseg0/1
feature, allow platforms to override how coherent DMA mappings are done
by providing plat_map_coherent() and plat_unmap_coherent() hooks, which
default to the current implementation with CAC/UNCAC unless changed.
Signed-off-by: Florian Fainelli <f.fainelli@...il.com>
---
arch/mips/include/asm/mach-generic/dma-coherence.h | 16 ++++++++++++++++
arch/mips/mm/dma-default.c | 10 +++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/arch/mips/include/asm/mach-generic/dma-coherence.h b/arch/mips/include/asm/mach-generic/dma-coherence.h
index e6e7dfa15801..42a1546e7d10 100644
--- a/arch/mips/include/asm/mach-generic/dma-coherence.h
+++ b/arch/mips/include/asm/mach-generic/dma-coherence.h
@@ -98,4 +98,20 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
#endif
#endif /* CONFIG_SWIOTLB */
+#ifndef plat_map_coherent
+static inline int plat_map_coherent(dma_addr_t handle, void *cac_va, size_t size,
+ void **uncac_va, gfp_t gfp)
+{
+ *uncac_va = UNCAC_ADDR(cac_va);
+ return 0;
+}
+#endif
+
+#ifndef plat_unmap_coherent
+static inline void *plat_unmap_coherent(void *addr)
+{
+ return CAC_ADDR(addr);
+}
+#endif
+
#endif /* __ASM_MACH_GENERIC_DMA_COHERENCE_H */
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index e3e94d05f0fd..f82f00dcc841 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -151,7 +151,11 @@ static void *mips_dma_alloc_coherent(struct device *dev, size_t size,
if (!(attrs & DMA_ATTR_NON_CONSISTENT) &&
!plat_device_is_coherent(dev)) {
dma_cache_wback_inv((unsigned long) ret, size);
- ret = UNCAC_ADDR(ret);
+ if (plat_map_coherent(*dma_handle, ret, PFN_ALIGN(size),
+ &ret, gfp)) {
+ free_pages((unsigned long)ret, size);
+ ret = NULL;
+ }
}
return ret;
@@ -167,7 +171,7 @@ static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
plat_unmap_dma_mem(dev, dma_handle, size, DMA_BIDIRECTIONAL);
if (!(attrs & DMA_ATTR_NON_CONSISTENT) && !plat_device_is_coherent(dev))
- addr = CAC_ADDR(addr);
+ addr = (unsigned long)plat_unmap_coherent(vaddr);
page = virt_to_page((void *) addr);
@@ -187,7 +191,7 @@ static int mips_dma_mmap(struct device *dev, struct vm_area_struct *vma,
int ret = -ENXIO;
if (!plat_device_is_coherent(dev))
- addr = CAC_ADDR(addr);
+ addr = (unsigned long)plat_unmap_coherent((void *)addr);
pfn = page_to_pfn(virt_to_page((void *)addr));
--
2.7.4
Powered by blists - more mailing lists