From 2c8ed1b960fb97c82ede5afc974329bfdb457f5f Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 5 Oct 2023 09:05:36 +0200 Subject: 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 Reviewed-by: Robin Murphy Reviewed-by: Greg Ungerer Tested-by: Greg Ungerer --- arch/m68k/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'arch/m68k') diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 3e318bf9504c..4f3e7dec2171 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -6,6 +6,7 @@ config M68K select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_CPU_FINALIZE_INIT if MMU select ARCH_HAS_CURRENT_STACK_POINTER + select ARCH_HAS_DMA_ALLOC if !MMU || COLDFIRE select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS -- cgit v1.2.3 From 9e28bf8bdf2177a88bd6648fc741bc0280e08af8 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Tue, 17 Oct 2023 16:04:42 +0200 Subject: m68k: use the coherent DMA code for coldfire without data cache Coldfire cores configured without a data cache are DMA coherent and should thus simply use the simple coherent version of dma-direct. Introduce a new COLDFIRE_COHERENT_DMA Kconfig symbol as a convenient short hand for such configurations, and a M68K_NONCOHERENT_DMA symbol for all cases where we need to build non-coherent DMA infrastructure to simplify the Kconfig and code conditionals. Not building the non-coherent DMA code slightly reduces the code size for such configurations. Numers for m5249evb_defconfig below: text data bss dec hex filename 2896158 401052 65392 3362602 334f2a vmlinux.before 2895166 400988 65392 3361546 334b0a vmlinux.after Signed-off-by: Christoph Hellwig Reviewed-by: Greg Ungerer Acked-by: Geert Uytterhoeven Tested-by: Greg Ungerer --- arch/m68k/Kconfig | 8 ++++---- arch/m68k/Kconfig.cpu | 12 ++++++++++++ arch/m68k/kernel/Makefile | 2 +- arch/m68k/kernel/dma.c | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) (limited to 'arch/m68k') diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 4f3e7dec2171..50ada24dfbba 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -6,16 +6,16 @@ config M68K select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_CPU_FINALIZE_INIT if MMU select ARCH_HAS_CURRENT_STACK_POINTER - select ARCH_HAS_DMA_ALLOC if !MMU || COLDFIRE - select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE - select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA + select ARCH_HAS_DMA_ALLOC if M68K_NONCOHERENT_DMA && COLDFIRE + select ARCH_HAS_DMA_PREP_COHERENT if M68K_NONCOHERENT_DMA && !COLDFIRE + select ARCH_HAS_SYNC_DMA_FOR_DEVICE if M68K_NONCOHERENT_DMA select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS select ARCH_MIGHT_HAVE_PC_PARPORT if ISA select ARCH_NO_PREEMPT if !COLDFIRE select ARCH_USE_MEMTEST if MMU_MOTOROLA select ARCH_WANT_IPC_PARSE_VERSION select BINFMT_FLAT_ARGVP_ENVP_ON_STACK - select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE + select DMA_DIRECT_REMAP if M68K_NONCOHERENT_DMA && !COLDFIRE select GENERIC_ATOMIC64 select GENERIC_CPU_DEVICES select GENERIC_IOMAP diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu index b826e9c677b2..ad69b466a08b 100644 --- a/arch/m68k/Kconfig.cpu +++ b/arch/m68k/Kconfig.cpu @@ -535,3 +535,15 @@ config CACHE_COPYBACK The ColdFire CPU cache is set into Copy-back mode. endchoice endif # HAVE_CACHE_CB + +# Coldfire cores that do not have a data cache configured can do coherent DMA. +config COLDFIRE_COHERENT_DMA + bool + default y + depends on COLDFIRE + depends on !HAVE_CACHE_CB && !CACHE_D && !CACHE_BOTH + +config M68K_NONCOHERENT_DMA + bool + default y + depends on HAS_DMA && !COLDFIRE_COHERENT_DMA diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile index af015447dfb4..01fb69a5095f 100644 --- a/arch/m68k/kernel/Makefile +++ b/arch/m68k/kernel/Makefile @@ -23,7 +23,7 @@ obj-$(CONFIG_MMU_MOTOROLA) += ints.o vectors.o obj-$(CONFIG_MMU_SUN3) += ints.o vectors.o obj-$(CONFIG_PCI) += pcibios.o -obj-$(CONFIG_HAS_DMA) += dma.o +obj-$(CONFIG_M68K_NONCOHERENT_DMA) += dma.o obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-$(CONFIG_BOOTINFO_PROC) += bootinfo_proc.o diff --git a/arch/m68k/kernel/dma.c b/arch/m68k/kernel/dma.c index 2e192a5df949..f83870cfa79b 100644 --- a/arch/m68k/kernel/dma.c +++ b/arch/m68k/kernel/dma.c @@ -17,7 +17,7 @@ #include -#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE) +#ifndef CONFIG_COLDFIRE void arch_dma_prep_coherent(struct page *page, size_t size) { cache_push(page_to_phys(page), size); -- cgit v1.2.3 From 7a360df941a4bd60847208de59f1ac8b166265a2 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 12 Oct 2023 09:52:27 +0200 Subject: m68k: don't provide arch_dma_alloc for nommu/coldfire Coldfire cores configured with a data cache can't provide coherent DMA allocations at all. Instead of returning non-coherent kernel memory in this case, return NULL and fail the allocation. The only driver that used to rely on the previous behavior (fec) has been switched to use non-coherent allocations for this case recently. Signed-off-by: Christoph Hellwig Reviewed-by: Greg Ungerer Tested-by: Greg Ungerer --- arch/m68k/Kconfig | 1 - arch/m68k/kernel/dma.c | 23 ----------------------- 2 files changed, 24 deletions(-) (limited to 'arch/m68k') diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 50ada24dfbba..c1c0faffb0d4 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -6,7 +6,6 @@ config M68K select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_CPU_FINALIZE_INIT if MMU select ARCH_HAS_CURRENT_STACK_POINTER - select ARCH_HAS_DMA_ALLOC if M68K_NONCOHERENT_DMA && COLDFIRE select ARCH_HAS_DMA_PREP_COHERENT if M68K_NONCOHERENT_DMA && !COLDFIRE select ARCH_HAS_SYNC_DMA_FOR_DEVICE if M68K_NONCOHERENT_DMA select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS diff --git a/arch/m68k/kernel/dma.c b/arch/m68k/kernel/dma.c index f83870cfa79b..eef63d032abb 100644 --- a/arch/m68k/kernel/dma.c +++ b/arch/m68k/kernel/dma.c @@ -33,29 +33,6 @@ pgprot_t pgprot_dmacoherent(pgprot_t prot) } return prot; } -#else -void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, - gfp_t gfp, unsigned long attrs) -{ - void *ret; - - if (dev == NULL || (*dev->dma_mask < 0xffffffff)) - gfp |= GFP_DMA; - ret = (void *)__get_free_pages(gfp, get_order(size)); - - if (ret != NULL) { - memset(ret, 0, size); - *dma_handle = virt_to_phys(ret); - } - return ret; -} - -void arch_dma_free(struct device *dev, size_t size, void *vaddr, - dma_addr_t dma_handle, unsigned long attrs) -{ - free_pages((unsigned long)vaddr, get_order(size)); -} - #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */ void arch_sync_dma_for_device(phys_addr_t handle, size_t size, -- cgit v1.2.3 From 8126cab004bab7b9d58b156435350379d88e8539 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 12 Oct 2023 09:58:29 +0200 Subject: m68k: remove unused includes from dma.c dma.c doesn't need most of the headers it includes. Also there is no point in undefining the DEBUG symbol given that it isn't used anywhere in this small file. Signed-off-by: Christoph Hellwig Reviewed-by: Geert Uytterhoeven Reviewed-by: Greg Ungerer Acked-by: Geert Uytterhoeven Tested-by: Greg Ungerer --- arch/m68k/kernel/dma.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'arch/m68k') diff --git a/arch/m68k/kernel/dma.c b/arch/m68k/kernel/dma.c index eef63d032abb..16063783aa80 100644 --- a/arch/m68k/kernel/dma.c +++ b/arch/m68k/kernel/dma.c @@ -4,17 +4,8 @@ * for more details. */ -#undef DEBUG - #include -#include #include -#include -#include -#include -#include -#include - #include #ifndef CONFIG_COLDFIRE -- cgit v1.2.3