MIPS: only select ARCH_HAS_UNCACHED_SEGMENT for non-coherent platforms
[linux-2.6-block.git] / include / linux / dma-noncoherent.h
CommitLineData
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)
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
4b85faed
CH
23/*
24 * Check if an allocation needs to be marked uncached to be coherent.
25 */
26static inline bool dma_alloc_need_uncached(struct device *dev,
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
39void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
40 gfp_t gfp, unsigned long attrs);
41void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
42 dma_addr_t dma_addr, unsigned long attrs);
58b04406
CH
43long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
44 dma_addr_t dma_addr);
45
46#ifdef CONFIG_ARCH_HAS_DMA_MMAP_PGPROT
47pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
782e6769 48 unsigned long attrs);
58b04406
CH
49#else
50# define arch_dma_mmap_pgprot(dev, prot, attrs) pgprot_noncached(prot)
51#endif
782e6769
CH
52
53#ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC
54void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
55 enum dma_data_direction direction);
56#else
356da6d0
CH
57static inline void arch_dma_cache_sync(struct device *dev, void *vaddr,
58 size_t size, enum dma_data_direction direction)
59{
60}
782e6769
CH
61#endif /* CONFIG_DMA_NONCOHERENT_CACHE_SYNC */
62
63#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE
64void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
65 size_t size, enum dma_data_direction dir);
66#else
67static inline void arch_sync_dma_for_device(struct device *dev,
68 phys_addr_t paddr, size_t size, enum dma_data_direction dir)
69{
70}
71#endif /* ARCH_HAS_SYNC_DMA_FOR_DEVICE */
72
73#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU
74void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
75 size_t size, enum dma_data_direction dir);
76#else
77static inline void arch_sync_dma_for_cpu(struct device *dev,
78 phys_addr_t paddr, size_t size, enum dma_data_direction dir)
79{
80}
81#endif /* ARCH_HAS_SYNC_DMA_FOR_CPU */
82
faef8772
CH
83#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
84void arch_sync_dma_for_cpu_all(struct device *dev);
85#else
86static inline void arch_sync_dma_for_cpu_all(struct device *dev)
87{
88}
89#endif /* CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL */
90
13bf5ced 91#ifdef CONFIG_ARCH_HAS_DMA_PREP_COHERENT
0c3b3171 92void arch_dma_prep_coherent(struct page *page, size_t size);
13bf5ced
CH
93#else
94static inline void arch_dma_prep_coherent(struct page *page, size_t size)
95{
96}
97#endif /* CONFIG_ARCH_HAS_DMA_PREP_COHERENT */
0c3b3171 98
c30700db
CH
99void *uncached_kernel_address(void *addr);
100void *cached_kernel_address(void *addr);
101
782e6769 102#endif /* _LINUX_DMA_NONCOHERENT_H */