[PATCH 1/2] dma-mapping: add a arch_can_dma_alloc_coherent hook

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This hook allows an architecture to reject coherent DMA allocations
entirely if they can't be supported.  This will be useful to convert
parisc and m68knommu to the generic dma-direct code.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
 include/linux/dma-map-ops.h | 1 +
 kernel/dma/Kconfig          | 3 +++
 kernel/dma/direct.c         | 4 ++++
 3 files changed, 8 insertions(+)

diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index d678afeb8a13a..10272f95cdb64 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -344,6 +344,7 @@ static inline void arch_dma_mark_clean(phys_addr_t paddr, size_t size)
 }
 #endif /* ARCH_HAS_DMA_MARK_CLEAN */
 
+bool arch_can_dma_alloc_coherent(void);
 void *arch_dma_set_uncached(void *addr, size_t size);
 void arch_dma_clear_uncached(void *addr, size_t size);
 
diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig
index 56866aaa2ae1a..6fd4efe71d136 100644
--- a/kernel/dma/Kconfig
+++ b/kernel/dma/Kconfig
@@ -20,6 +20,9 @@ config DMA_OPS
 config DMA_OPS_BYPASS
 	bool
 
+config ARCH_HAS_CAN_DMA_ALLOC_COHERENT
+	bool
+
 # Lets platform IOMMU driver choose between bypass and IOMMU
 config ARCH_HAS_DMA_MAP_DIRECT
 	bool
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 63859a101ed83..03929482e92f7 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -232,6 +232,10 @@ void *dma_direct_alloc(struct device *dev, size_t size,
 			return arch_dma_alloc(dev, size, dma_handle, gfp,
 					      attrs);
 
+		if (IS_ENABLED(CONFIG_ARCH_HAS_CAN_DMA_ALLOC_COHERENT) &&
+		    !arch_can_dma_alloc_coherent())
+			return NULL;
+
 		/*
 		 * If there is a global pool, always allocate from it for
 		 * non-coherent devices.
-- 
2.30.2




[Index of Archives]     [Linux SoC]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux