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)
12static inline bool dev_is_dma_coherent(struct device *dev)
13{
14 return dev->dma_coherent;
15}
16#else
17static inline bool dev_is_dma_coherent(struct device *dev)
18{
19 return true;
20}
21#endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */
22
23void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
24 gfp_t gfp, unsigned long attrs);
25void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
26 dma_addr_t dma_addr, unsigned long attrs);
27long 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
31pgprot_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
38void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
39 enum dma_data_direction direction);
40#else
41static 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
48void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
49 size_t size, enum dma_data_direction dir);
50#else
51static 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
58void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
59 size_t size, enum dma_data_direction dir);
60#else
61static 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
68void arch_sync_dma_for_cpu_all(struct device *dev);
69#else
70static inline void arch_sync_dma_for_cpu_all(struct device *dev)
71{
72}
73#endif /* CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL */
74
75void arch_dma_prep_coherent(struct page *page, size_t size);
76
77#endif /* _LINUX_DMA_NONCOHERENT_H */
78