Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-mapping: move the dma_coherent flag to struct device

Various architectures support both coherent and non-coherent dma on a
per-device basis. Move the dma_noncoherent flag from the mips archdata
field to struct device proper to prepare the infrastructure for reuse on
other architectures.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Paul Burton <paul.burton@mips.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+41 -46
+1
arch/mips/Kconfig
··· 1106 1106 bool 1107 1107 1108 1108 config DMA_MAYBE_COHERENT 1109 + select ARCH_HAS_DMA_COHERENCE_H 1109 1110 select DMA_NONCOHERENT 1110 1111 bool 1111 1112
+1
arch/mips/include/asm/Kbuild
··· 1 1 # MIPS headers 2 2 generic-(CONFIG_GENERIC_CSUM) += checksum.h 3 3 generic-y += current.h 4 + generic-y += device.h 4 5 generic-y += dma-contiguous.h 5 6 generic-y += emergency-restart.h 6 7 generic-y += export.h
-19
arch/mips/include/asm/device.h
··· 1 - /* 2 - * Arch specific extensions to struct device 3 - * 4 - * This file is released under the GPLv2 5 - */ 6 - #ifndef _ASM_MIPS_DEVICE_H 7 - #define _ASM_MIPS_DEVICE_H 8 - 9 - struct dev_archdata { 10 - #ifdef CONFIG_DMA_PERDEV_COHERENT 11 - /* Non-zero if DMA is coherent with CPU caches */ 12 - bool dma_coherent; 13 - #endif 14 - }; 15 - 16 - struct pdev_archdata { 17 - }; 18 - 19 - #endif /* _ASM_MIPS_DEVICE_H*/
+6
arch/mips/include/asm/dma-coherence.h
··· 20 20 #elif defined(CONFIG_DMA_MAYBE_COHERENT) 21 21 extern enum coherent_io_user_state coherentio; 22 22 extern int hw_coherentio; 23 + 24 + static inline bool dev_is_dma_coherent(struct device *dev) 25 + { 26 + return coherentio == IO_COHERENCE_ENABLED || 27 + (coherentio == IO_COHERENCE_DEFAULT && hw_coherentio); 28 + } 23 29 #else 24 30 #ifdef CONFIG_DMA_NONCOHERENT 25 31 #define coherentio IO_COHERENCE_DISABLED
+1 -1
arch/mips/include/asm/dma-mapping.h
··· 25 25 bool coherent) 26 26 { 27 27 #ifdef CONFIG_DMA_PERDEV_COHERENT 28 - dev->archdata.dma_coherent = coherent; 28 + dev->dma_coherent = coherent; 29 29 #endif 30 30 } 31 31
+6 -26
arch/mips/mm/dma-noncoherent.c
··· 14 14 #include <asm/dma-coherence.h> 15 15 #include <asm/io.h> 16 16 17 - #ifdef CONFIG_DMA_PERDEV_COHERENT 18 - static inline int dev_is_coherent(struct device *dev) 19 - { 20 - return dev->archdata.dma_coherent; 21 - } 22 - #else 23 - static inline int dev_is_coherent(struct device *dev) 24 - { 25 - switch (coherentio) { 26 - default: 27 - case IO_COHERENCE_DEFAULT: 28 - return hw_coherentio; 29 - case IO_COHERENCE_ENABLED: 30 - return 1; 31 - case IO_COHERENCE_DISABLED: 32 - return 0; 33 - } 34 - } 35 - #endif /* CONFIG_DMA_PERDEV_COHERENT */ 36 - 37 17 /* 38 18 * The affected CPUs below in 'cpu_needs_post_dma_flush()' can speculatively 39 19 * fill random cachelines with stale data at any time, requiring an extra ··· 29 49 */ 30 50 static inline bool cpu_needs_post_dma_flush(struct device *dev) 31 51 { 32 - if (dev_is_coherent(dev)) 52 + if (dev_is_dma_coherent(dev)) 33 53 return false; 34 54 35 55 switch (boot_cpu_type()) { ··· 56 76 if (!ret) 57 77 return NULL; 58 78 59 - if (!dev_is_coherent(dev) && !(attrs & DMA_ATTR_NON_CONSISTENT)) { 79 + if (!dev_is_dma_coherent(dev) && !(attrs & DMA_ATTR_NON_CONSISTENT)) { 60 80 dma_cache_wback_inv((unsigned long) ret, size); 61 81 ret = (void *)UNCAC_ADDR(ret); 62 82 } ··· 67 87 void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, 68 88 dma_addr_t dma_addr, unsigned long attrs) 69 89 { 70 - if (!(attrs & DMA_ATTR_NON_CONSISTENT) && !dev_is_coherent(dev)) 90 + if (!(attrs & DMA_ATTR_NON_CONSISTENT) && !dev_is_dma_coherent(dev)) 71 91 cpu_addr = (void *)CAC_ADDR((unsigned long)cpu_addr); 72 92 dma_direct_free(dev, size, cpu_addr, dma_addr, attrs); 73 93 } ··· 83 103 unsigned long pfn; 84 104 int ret = -ENXIO; 85 105 86 - if (!dev_is_coherent(dev)) 106 + if (!dev_is_dma_coherent(dev)) 87 107 addr = CAC_ADDR(addr); 88 108 89 109 pfn = page_to_pfn(virt_to_page((void *)addr)); ··· 167 187 void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, 168 188 size_t size, enum dma_data_direction dir) 169 189 { 170 - if (!dev_is_coherent(dev)) 190 + if (!dev_is_dma_coherent(dev)) 171 191 dma_sync_phys(paddr, size, dir); 172 192 } 173 193 ··· 183 203 { 184 204 BUG_ON(direction == DMA_NONE); 185 205 186 - if (!dev_is_coherent(dev)) 206 + if (!dev_is_dma_coherent(dev)) 187 207 dma_sync_virt(vaddr, size, direction); 188 208 }
+7
include/linux/device.h
··· 927 927 * @offline: Set after successful invocation of bus type's .offline(). 928 928 * @of_node_reused: Set if the device-tree node is shared with an ancestor 929 929 * device. 930 + * @dma_coherent: this particular device is dma coherent, even if the 931 + * architecture supports non-coherent devices. 930 932 * 931 933 * At the lowest level, every device in a Linux system is represented by an 932 934 * instance of struct device. The device structure contains the information ··· 1018 1016 bool offline_disabled:1; 1019 1017 bool offline:1; 1020 1018 bool of_node_reused:1; 1019 + #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ 1020 + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ 1021 + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) 1022 + bool dma_coherent:1; 1023 + #endif 1021 1024 }; 1022 1025 1023 1026 static inline struct device *kobj_to_dev(struct kobject *kobj)
+16
include/linux/dma-noncoherent.h
··· 4 4 5 5 #include <linux/dma-mapping.h> 6 6 7 + #ifdef CONFIG_ARCH_HAS_DMA_COHERENCE_H 8 + #include <asm/dma-coherence.h> 9 + #elif defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ 10 + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ 11 + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) 12 + static inline bool dev_is_dma_coherent(struct device *dev) 13 + { 14 + return dev->dma_coherent; 15 + } 16 + #else 17 + static inline bool dev_is_dma_coherent(struct device *dev) 18 + { 19 + return true; 20 + } 21 + #endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */ 22 + 7 23 void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, 8 24 gfp_t gfp, unsigned long attrs); 9 25 void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
+3
kernel/dma/Kconfig
··· 13 13 config ARCH_DMA_ADDR_T_64BIT 14 14 def_bool 64BIT || PHYS_ADDR_T_64BIT 15 15 16 + config ARCH_HAS_DMA_COHERENCE_H 17 + bool 18 + 16 19 config HAVE_GENERIC_DMA_COHERENT 17 20 bool 18 21