blob: bcdb1a3e4b1f78dc2afb94bde11629fddedd08c3 [file] [log] [blame]
Christoph Hellwigea8c64a2018-01-10 16:21:13 +01001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_DMA_DIRECT_H
3#define _LINUX_DMA_DIRECT_H 1
4
5#include <linux/dma-mapping.h>
6
7#ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA
8#include <asm/dma-direct.h>
9#else
10static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
11{
12 dma_addr_t dev_addr = (dma_addr_t)paddr;
13
14 return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
15}
16
17static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
18{
19 phys_addr_t paddr = (phys_addr_t)dev_addr;
20
21 return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
22}
23
24static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
25{
26 if (!dev->dma_mask)
27 return false;
28
29 return addr + size - 1 <= *dev->dma_mask;
30}
31#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
Christoph Hellwigb49efd72018-01-09 22:11:31 +010032
33#ifdef CONFIG_ARCH_HAS_DMA_MARK_CLEAN
34void dma_mark_clean(void *addr, size_t size);
35#else
36static inline void dma_mark_clean(void *addr, size_t size)
37{
38}
39#endif /* CONFIG_ARCH_HAS_DMA_MARK_CLEAN */
40
Christoph Hellwig19dca8c2017-12-23 13:46:06 +010041void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
42 gfp_t gfp, unsigned long attrs);
43void dma_direct_free(struct device *dev, size_t size, void *cpu_addr,
44 dma_addr_t dma_addr, unsigned long attrs);
Christoph Hellwig1a9777a2017-12-24 15:04:32 +010045int dma_direct_supported(struct device *dev, u64 mask);
Christoph Hellwig19dca8c2017-12-23 13:46:06 +010046
Christoph Hellwigea8c64a2018-01-10 16:21:13 +010047#endif /* _LINUX_DMA_DIRECT_H */