driver core: lift dma_default_coherent into common code
authorChristoph Hellwig <hch@lst.de>
Wed, 10 Feb 2021 09:56:39 +0000 (10:56 +0100)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Sat, 13 Feb 2021 08:51:45 +0000 (09:51 +0100)
Lift the dma_default_coherent variable from the mips architecture code
to the driver core.  This allows an architecture to sdefault all device
to be DMA coherent at run time, even if the kernel is build with support
for DMA noncoherent device.  By allowing device_initialize to set the
->dma_coherent field to this default the amount of arch hooks required
for this behavior can be greatly reduced.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
13 files changed:
arch/mips/Kconfig
arch/mips/alchemy/common/setup.c
arch/mips/include/asm/dma-coherence.h [deleted file]
arch/mips/kernel/setup.c
arch/mips/mm/c-r4k.c
arch/mips/mm/dma-noncoherent.c
arch/mips/mti-malta/malta-setup.c
arch/mips/pci/pci-alchemy.c
arch/mips/pistachio/init.c
drivers/base/core.c
include/linux/dma-map-ops.h
kernel/dma/Kconfig
kernel/dma/mapping.c

index 57b06798706cd44fe95c79bc6d00cebab51ae4d2..a6d73c763be1a7ede24933c03f50f873bc257741 100644 (file)
@@ -1163,7 +1163,6 @@ config ARCH_SUPPORTS_UPROBES
        bool
 
 config DMA_MAYBE_COHERENT
-       select ARCH_HAS_DMA_COHERENCE_H
        select DMA_NONCOHERENT
        bool
 
index 39e5b9cd882b10d43911cb4ab6623d8d03b6dc6f..2388d68786f4a7c40dcadfed78fd8ecfc91f4896 100644 (file)
@@ -28,8 +28,8 @@
 #include <linux/init.h>
 #include <linux/ioport.h>
 #include <linux/mm.h>
+#include <linux/dma-map-ops.h> /* for dma_default_coherent */
 
-#include <asm/dma-coherence.h>
 #include <asm/mipsregs.h>
 
 #include <au1000.h>
diff --git a/arch/mips/include/asm/dma-coherence.h b/arch/mips/include/asm/dma-coherence.h
deleted file mode 100644 (file)
index 846c5ad..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 2006  Ralf Baechle <ralf@linux-mips.org>
- *
- */
-#ifndef __ASM_DMA_COHERENCE_H
-#define __ASM_DMA_COHERENCE_H
-
-#ifdef CONFIG_DMA_MAYBE_COHERENT
-extern bool dma_default_coherent;
-static inline bool dev_is_dma_coherent(struct device *dev)
-{
-       return dma_default_coherent;
-}
-#else
-#define dma_default_coherent   (!IS_ENABLED(CONFIG_DMA_NONCOHERENT))
-#endif
-
-#endif
index 6008f45ad0818a852036737db6d5c587a4d0523e..f0f533294311bf30cfc4dcb4899e0891d555fb60 100644 (file)
@@ -36,7 +36,6 @@
 #include <asm/cdmm.h>
 #include <asm/cpu.h>
 #include <asm/debug.h>
-#include <asm/dma-coherence.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
 #include <asm/smp-ops.h>
@@ -803,9 +802,6 @@ arch_initcall(debugfs_mips);
 #endif
 
 #ifdef CONFIG_DMA_MAYBE_COHERENT
-bool dma_default_coherent;
-EXPORT_SYMBOL_GPL(dma_default_coherent);
-
 static int __init setcoherentio(char *str)
 {
        dma_default_coherent = true;
index bbfab94194b93c5e09bacbafd8e09e48b2bb4d8c..74b09e801c3aea2cfeee076a47dd7cbcf1c42081 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/mm.h>
 #include <linux/export.h>
 #include <linux/bitops.h>
+#include <linux/dma-map-ops.h> /* for dma_default_coherent */
 
 #include <asm/bcache.h>
 #include <asm/bootinfo.h>
@@ -35,7 +36,6 @@
 #include <asm/war.h>
 #include <asm/cacheflush.h> /* for run_uncached() */
 #include <asm/traps.h>
-#include <asm/dma-coherence.h>
 #include <asm/mips-cps.h>
 
 /*
index 38d3d9143b47fbc88de62bdb2bcb614ac703db37..90b562753eb892e6a3a3d4e320a046b61311d073 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <asm/cache.h>
 #include <asm/cpu-type.h>
-#include <asm/dma-coherence.h>
 #include <asm/io.h>
 
 /*
index 1cdcb76d393ed174b0b51a8c8ad42e12c6cfcb15..21cb3ac1237b76c6d354b530127eca11806d6ad0 100644 (file)
@@ -13,8 +13,8 @@
 #include <linux/pci.h>
 #include <linux/screen_info.h>
 #include <linux/time.h>
+#include <linux/dma-map-ops.h> /* for dma_default_coherent */
 
-#include <asm/dma-coherence.h>
 #include <asm/fw/fw.h>
 #include <asm/mips-cps.h>
 #include <asm/mips-boards/generic.h>
index 54c86b40d30498a61fa499ba6503087a040275fb..1c722dd0c1302d00abb0e8820ba0d23f1870caff 100644 (file)
@@ -17,8 +17,8 @@
 #include <linux/init.h>
 #include <linux/syscore_ops.h>
 #include <linux/vmalloc.h>
+#include <linux/dma-map-ops.h> /* for dma_default_coherent */
 
-#include <asm/dma-coherence.h>
 #include <asm/mach-au1x00/au1000.h>
 #include <asm/tlbmisc.h>
 
index 8e83262e9da85bd894a96b1e5183e3af62e2c883..e0bacfc3c6b4e1ee4f12d13eec39f23968df24bb 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/of_fdt.h>
 
 #include <asm/cacheflush.h>
-#include <asm/dma-coherence.h>
 #include <asm/fw/fw.h>
 #include <asm/mips-boards/generic.h>
 #include <asm/mips-cps.h>
index 25e08e5f40bd93afe735379abfd04ec9ed160ce6..fb2988f955cb61c5d9072b127912e4fdc522292c 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/sched/signal.h>
 #include <linux/sched/mm.h>
 #include <linux/sysfs.h>
+#include <linux/dma-map-ops.h> /* for dma_default_coherent */
 
 #include "base.h"
 #include "power/power.h"
@@ -2585,6 +2586,11 @@ void device_initialize(struct device *dev)
        INIT_LIST_HEAD(&dev->links.suppliers);
        INIT_LIST_HEAD(&dev->links.defer_sync);
        dev->links.status = DL_DEV_NO_DRIVER;
+#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
+    defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
+    defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
+       dev->dma_coherent = dma_default_coherent;
+#endif
 }
 EXPORT_SYMBOL_GPL(device_initialize);
 
index 70fcd0f610ea482570ca4eda9c7dcef77d365cda..1e98b8c1e055a946b7e9b018fd158e8d361a7d7f 100644 (file)
@@ -229,11 +229,10 @@ bool dma_free_from_pool(struct device *dev, void *start, size_t size);
 int dma_direct_set_offset(struct device *dev, phys_addr_t cpu_start,
                dma_addr_t dma_start, u64 size);
 
-#ifdef CONFIG_ARCH_HAS_DMA_COHERENCE_H
-#include <asm/dma-coherence.h>
-#elif defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
+#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
        defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
        defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
+extern bool dma_default_coherent;
 static inline bool dev_is_dma_coherent(struct device *dev)
 {
        return dev->dma_coherent;
index 479fc145acfc160c5e292bc41572d10b12f32cc9..77b4055087430cfd9949ebc093db26761f314cca 100644 (file)
@@ -33,9 +33,6 @@ config NEED_DMA_MAP_STATE
 config ARCH_DMA_ADDR_T_64BIT
        def_bool 64BIT || PHYS_ADDR_T_64BIT
 
-config ARCH_HAS_DMA_COHERENCE_H
-       bool
-
 config ARCH_HAS_DMA_SET_MASK
        bool
 
index f87a89d086544b863b9635c07334dfc8530dd3d4..84de6b1c5fab4917869c8c865ea42c301dae93ff 100644 (file)
@@ -16,6 +16,8 @@
 #include "debug.h"
 #include "direct.h"
 
+bool dma_default_coherent;
+
 /*
  * Managed DMA API
  */