1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_DMA_NONCOHERENT_H
3 #define _LINUX_DMA_NONCOHERENT_H 1
5 #include <linux/dma-mapping.h>
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)
14 return dev->dma_coherent;
17 static inline bool dev_is_dma_coherent(struct device *dev)
21 #endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */
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,
30 #ifdef CONFIG_ARCH_HAS_DMA_MMAP_PGPROT
31 pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
34 # define arch_dma_mmap_pgprot(dev, prot, attrs) pgprot_noncached(prot)
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);
41 static inline void arch_dma_cache_sync(struct device *dev, void *vaddr,
42 size_t size, enum dma_data_direction direction)
45 #endif /* CONFIG_DMA_NONCOHERENT_CACHE_SYNC */
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);
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)
55 #endif /* ARCH_HAS_SYNC_DMA_FOR_DEVICE */
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);
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)
65 #endif /* ARCH_HAS_SYNC_DMA_FOR_CPU */
67 #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
68 void arch_sync_dma_for_cpu_all(struct device *dev);
70 static inline void arch_sync_dma_for_cpu_all(struct device *dev)
73 #endif /* CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL */
75 void arch_dma_prep_coherent(struct page *page, size_t size);
77 #endif /* _LINUX_DMA_NONCOHERENT_H */