]>
Commit | Line | Data |
---|---|---|
782e6769 CH |
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 | ||
f3ecc0ff CH |
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 | ||
4b85faed CH |
23 | /* |
24 | * Check if an allocation needs to be marked uncached to be coherent. | |
25 | */ | |
15ffe5e1 | 26 | static __always_inline bool dma_alloc_need_uncached(struct device *dev, |
4b85faed CH |
27 | unsigned long attrs) |
28 | { | |
29 | if (dev_is_dma_coherent(dev)) | |
30 | return false; | |
d98849af CH |
31 | if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) |
32 | return false; | |
4b85faed CH |
33 | if (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) && |
34 | (attrs & DMA_ATTR_NON_CONSISTENT)) | |
35 | return false; | |
36 | return true; | |
37 | } | |
38 | ||
782e6769 CH |
39 | void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, |
40 | gfp_t gfp, unsigned long attrs); | |
41 | void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, | |
42 | dma_addr_t dma_addr, unsigned long attrs); | |
58b04406 CH |
43 | long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr, |
44 | dma_addr_t dma_addr); | |
58b04406 | 45 | pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot, |
782e6769 | 46 | unsigned long attrs); |
33dcb37c CH |
47 | |
48 | #ifdef CONFIG_MMU | |
49 | pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs); | |
58b04406 | 50 | #else |
33dcb37c CH |
51 | static inline pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, |
52 | unsigned long attrs) | |
53 | { | |
54 | return prot; /* no protection bits supported without page tables */ | |
55 | } | |
56 | #endif /* CONFIG_MMU */ | |
782e6769 CH |
57 | |
58 | #ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC | |
59 | void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size, | |
60 | enum dma_data_direction direction); | |
61 | #else | |
356da6d0 CH |
62 | static inline void arch_dma_cache_sync(struct device *dev, void *vaddr, |
63 | size_t size, enum dma_data_direction direction) | |
64 | { | |
65 | } | |
782e6769 CH |
66 | #endif /* CONFIG_DMA_NONCOHERENT_CACHE_SYNC */ |
67 | ||
68 | #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE | |
69 | void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, | |
70 | size_t size, enum dma_data_direction dir); | |
71 | #else | |
72 | static inline void arch_sync_dma_for_device(struct device *dev, | |
73 | phys_addr_t paddr, size_t size, enum dma_data_direction dir) | |
74 | { | |
75 | } | |
76 | #endif /* ARCH_HAS_SYNC_DMA_FOR_DEVICE */ | |
77 | ||
78 | #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU | |
79 | void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr, | |
80 | size_t size, enum dma_data_direction dir); | |
81 | #else | |
82 | static inline void arch_sync_dma_for_cpu(struct device *dev, | |
83 | phys_addr_t paddr, size_t size, enum dma_data_direction dir) | |
84 | { | |
85 | } | |
86 | #endif /* ARCH_HAS_SYNC_DMA_FOR_CPU */ | |
87 | ||
faef8772 CH |
88 | #ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL |
89 | void arch_sync_dma_for_cpu_all(struct device *dev); | |
90 | #else | |
91 | static inline void arch_sync_dma_for_cpu_all(struct device *dev) | |
92 | { | |
93 | } | |
94 | #endif /* CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL */ | |
95 | ||
13bf5ced | 96 | #ifdef CONFIG_ARCH_HAS_DMA_PREP_COHERENT |
0c3b3171 | 97 | void arch_dma_prep_coherent(struct page *page, size_t size); |
13bf5ced CH |
98 | #else |
99 | static inline void arch_dma_prep_coherent(struct page *page, size_t size) | |
100 | { | |
101 | } | |
102 | #endif /* CONFIG_ARCH_HAS_DMA_PREP_COHERENT */ | |
0c3b3171 | 103 | |
c30700db CH |
104 | void *uncached_kernel_address(void *addr); |
105 | void *cached_kernel_address(void *addr); | |
106 | ||
782e6769 | 107 | #endif /* _LINUX_DMA_NONCOHERENT_H */ |