Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[sfrench/cifs-2.6.git] / include / linux / dma-noncoherent.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_DMA_NONCOHERENT_H
3 #define _LINUX_DMA_NONCOHERENT_H 1
4
5 #include <linux/dma-mapping.h>
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
23 void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
24                 gfp_t gfp, unsigned long attrs);
25 void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
26                 dma_addr_t dma_addr, unsigned long attrs);
27 long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
28                 dma_addr_t dma_addr);
29
30 #ifdef CONFIG_ARCH_HAS_DMA_MMAP_PGPROT
31 pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
32                 unsigned long attrs);
33 #else
34 # define arch_dma_mmap_pgprot(dev, prot, attrs) pgprot_noncached(prot)
35 #endif
36
37 #ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC
38 void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
39                 enum dma_data_direction direction);
40 #else
41 static inline void arch_dma_cache_sync(struct device *dev, void *vaddr,
42                 size_t size, enum dma_data_direction direction)
43 {
44 }
45 #endif /* CONFIG_DMA_NONCOHERENT_CACHE_SYNC */
46
47 #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE
48 void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
49                 size_t size, enum dma_data_direction dir);
50 #else
51 static inline void arch_sync_dma_for_device(struct device *dev,
52                 phys_addr_t paddr, size_t size, enum dma_data_direction dir)
53 {
54 }
55 #endif /* ARCH_HAS_SYNC_DMA_FOR_DEVICE */
56
57 #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU
58 void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
59                 size_t size, enum dma_data_direction dir);
60 #else
61 static inline void arch_sync_dma_for_cpu(struct device *dev,
62                 phys_addr_t paddr, size_t size, enum dma_data_direction dir)
63 {
64 }
65 #endif /* ARCH_HAS_SYNC_DMA_FOR_CPU */
66
67 #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
68 void arch_sync_dma_for_cpu_all(struct device *dev);
69 #else
70 static inline void arch_sync_dma_for_cpu_all(struct device *dev)
71 {
72 }
73 #endif /* CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL */
74
75 void arch_dma_prep_coherent(struct page *page, size_t size);
76
77 #endif /* _LINUX_DMA_NONCOHERENT_H */