Skip to contentSkip to conversation

powerpc/iommu: Support "hybrid" iommu/direct DMA ops for coherent_mask < dma_mask

PATCH Applied Benjamin Herrenschmidt 3 participants 4 messages Jun 24, 2015 – Jul 25, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 powerpc/iommu: Support "hybrid" iommu/direct DMA ops for coherent_mask < dma_mask

This patch adds the ability to the DMA direct ops to fallback to the IOMMU ops for coherent alloc/free if the coherent mask of the device isn't suitable for accessing the direct DMA space and the device also happens to have an active IOMMU table.

---
 arch/powerpc/Kconfig                   |   4 ++
 arch/powerpc/include/asm/dma-mapping.h |  10 +--
 arch/powerpc/kernel/dma-iommu.c        |   2 +-
 arch/powerpc/kernel/dma-swiotlb.c      |   4 +-
 arch/powerpc/kernel/dma.c              | 111 +++++++++++++++++++++++++++------
 5 files changed, 105 insertions(+), 26 deletions(-)
arch/powerpc/Kconfig +4 -0
index 190cc48..72302fa 100644
@@ -82,6 +82,9 @@ config GENERIC_HWEIGHT
 	bool
 	default y
 
+config ARCH_HAS_DMA_SET_COHERENT_MASK
+        bool
+
 config PPC
 	bool
 	default y
@@ -153,6 +156,7 @@ config PPC
 	select NO_BOOTMEM
 	select HAVE_GENERIC_RCU_GUP
 	select HAVE_PERF_EVENTS_NMI if PPC64
+	select ARCH_HAS_DMA_SET_COHERENT_MASK
 
 config GENERIC_CSUM
 	def_bool CPU_LITTLE_ENDIAN
arch/powerpc/include/asm/dma-mapping.h +5 -5
index 9cbbc9e..710f60e 100644
@@ -21,12 +21,12 @@
 #define DMA_ERROR_CODE		(~(dma_addr_t)0x0)
 
 /* Some dma direct funcs must be visible for use in other dma_ops */
-extern void *dma_direct_alloc_coherent(struct device *dev, size_t size,
-				       dma_addr_t *dma_handle, gfp_t flag,
+extern void *__dma_direct_alloc_coherent(struct device *dev, size_t size,
+					 dma_addr_t *dma_handle, gfp_t flag,
+					 struct dma_attrs *attrs);
+extern void __dma_direct_free_coherent(struct device *dev, size_t size,
+				       void *vaddr, dma_addr_t dma_handle,
 				       struct dma_attrs *attrs);
-extern void dma_direct_free_coherent(struct device *dev, size_t size,
-				     void *vaddr, dma_addr_t dma_handle,
-				     struct dma_attrs *attrs);
 extern int dma_direct_mmap_coherent(struct device *dev,
 				    struct vm_area_struct *vma,
 				    void *cpu_addr, dma_addr_t handle,
arch/powerpc/kernel/dma-iommu.c +1 -1
index 4c68bfe..41a7d9d 100644
@@ -73,7 +73,7 @@ static void dma_iommu_unmap_sg(struct device *dev, struct scatterlist *sglist,
 }
 
 /* We support DMA to/from any memory page via the iommu */
-static int dma_iommu_dma_supported(struct device *dev, u64 mask)
+int dma_iommu_dma_supported(struct device *dev, u64 mask)
 {
 	struct iommu_table *tbl = get_iommu_table_base(dev);
 
arch/powerpc/kernel/dma-swiotlb.c +2 -2
index 6e8d764..c6689f6 100644
@@ -47,8 +47,8 @@ static u64 swiotlb_powerpc_get_required(struct device *dev)
  * for everything else.
  */
 struct dma_map_ops swiotlb_dma_ops = {
-	.alloc = dma_direct_alloc_coherent,
-	.free = dma_direct_free_coherent,
+	.alloc = __dma_direct_alloc_coherent,
+	.free = __dma_direct_free_coherent,
 	.mmap = dma_direct_mmap_coherent,
 	.map_sg = swiotlb_map_sg_attrs,
 	.unmap_sg = swiotlb_unmap_sg_attrs,
arch/powerpc/kernel/dma.c +93 -18

147 lines not on this page · raw message

#1 lore raw

Ben,

It looks like this patch has bit rot. I have a system now where I can test the latest version. Any chance you can rediff and resend and I can test?

Thanks,

Brian

#3 lore raw
In reply to Brian King
Quoted 4 lines · Brian King

Ben,

It looks like this patch has bit rot. I have a system now where I can test the latest version. Any chance you can rediff and resend and I can test?

Hrm, Michael didn't upstream it ? Ok, I'll have a look on monday.

(ping me if I don't).

Cheers,
Ben.