Skip to content

Commit 2c8ed1b

Browse files
author
Christoph Hellwig
committed
dma-direct: add a CONFIG_ARCH_HAS_DMA_ALLOC symbol
Instead of using arch_dma_alloc if none of the generic coherent allocators are used, require the architectures to explicitly opt into providing it. This will used to deal with the case of m68knommu and coldfire where we can't do any coherent allocations whatsoever, and also makes it clear that arch_dma_alloc is a last resort. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Greg Ungerer <gerg@linux-m68k.org> Tested-by: Greg Ungerer <gerg@linux-m68k.org>
1 parent da323d4 commit 2c8ed1b

5 files changed

Lines changed: 14 additions & 10 deletions

File tree

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config ARM
88
select ARCH_HAS_CPU_FINALIZE_INIT if MMU
99
select ARCH_HAS_CURRENT_STACK_POINTER
1010
select ARCH_HAS_DEBUG_VIRTUAL if MMU
11+
select ARCH_HAS_DMA_ALLOC if MMU
1112
select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE
1213
select ARCH_HAS_ELF_RANDOMIZE
1314
select ARCH_HAS_FORTIFY_SOURCE

arch/m68k/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ config M68K
66
select ARCH_HAS_BINFMT_FLAT
77
select ARCH_HAS_CPU_FINALIZE_INIT if MMU
88
select ARCH_HAS_CURRENT_STACK_POINTER
9+
select ARCH_HAS_DMA_ALLOC if !MMU || COLDFIRE
910
select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE
1011
select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA
1112
select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS

arch/parisc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config PARISC
88
select HAVE_FUNCTION_GRAPH_TRACER
99
select HAVE_SYSCALL_TRACEPOINTS
1010
select ARCH_WANT_FRAME_POINTERS
11+
select ARCH_HAS_DMA_ALLOC if PA11
1112
select ARCH_HAS_ELF_RANDOMIZE
1213
select ARCH_HAS_STRICT_KERNEL_RWX
1314
select ARCH_HAS_STRICT_MODULE_RWX

kernel/dma/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ config DMA_DIRECT_REMAP
144144
select DMA_COHERENT_POOL
145145
select DMA_NONCOHERENT_MMAP
146146

147+
#
148+
# Fallback to arch code for DMA allocations. This should eventually go away.
149+
#
150+
config ARCH_HAS_DMA_ALLOC
151+
depends on !ARCH_HAS_DMA_SET_UNCACHED
152+
depends on !DMA_DIRECT_REMAP
153+
depends on !DMA_GLOBAL_POOL
154+
bool
155+
147156
config DMA_CMA
148157
bool "DMA Contiguous Memory Allocator"
149158
depends on HAVE_DMA_CONTIGUOUS && CMA

kernel/dma/direct.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,7 @@ void *dma_direct_alloc(struct device *dev, size_t size,
220220
return dma_direct_alloc_no_mapping(dev, size, dma_handle, gfp);
221221

222222
if (!dev_is_dma_coherent(dev)) {
223-
/*
224-
* Fallback to the arch handler if it exists. This should
225-
* eventually go away.
226-
*/
227-
if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
228-
!IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
229-
!IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) &&
223+
if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_ALLOC) &&
230224
!is_swiotlb_for_alloc(dev))
231225
return arch_dma_alloc(dev, size, dma_handle, gfp,
232226
attrs);
@@ -330,9 +324,7 @@ void dma_direct_free(struct device *dev, size_t size,
330324
return;
331325
}
332326

333-
if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) &&
334-
!IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
335-
!IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) &&
327+
if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_ALLOC) &&
336328
!dev_is_dma_coherent(dev) &&
337329
!is_swiotlb_for_alloc(dev)) {
338330
arch_dma_free(dev, size, cpu_addr, dma_addr, attrs);

0 commit comments

Comments
 (0)