Christoph Hellwig | ea8c64a | 2018-01-10 16:21:13 +0100 | [diff] [blame] | 1 | /* 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 |
| 10 | static 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 | |
| 17 | static 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 | |
| 24 | static 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 Hellwig | b49efd7 | 2018-01-09 22:11:31 +0100 | [diff] [blame] | 32 | |
| 33 | #ifdef CONFIG_ARCH_HAS_DMA_MARK_CLEAN |
| 34 | void dma_mark_clean(void *addr, size_t size); |
| 35 | #else |
| 36 | static inline void dma_mark_clean(void *addr, size_t size) |
| 37 | { |
| 38 | } |
| 39 | #endif /* CONFIG_ARCH_HAS_DMA_MARK_CLEAN */ |
| 40 | |
Christoph Hellwig | 19dca8c | 2017-12-23 13:46:06 +0100 | [diff] [blame] | 41 | void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, |
| 42 | gfp_t gfp, unsigned long attrs); |
| 43 | void dma_direct_free(struct device *dev, size_t size, void *cpu_addr, |
| 44 | dma_addr_t dma_addr, unsigned long attrs); |
Christoph Hellwig | 1a9777a | 2017-12-24 15:04:32 +0100 | [diff] [blame^] | 45 | int dma_direct_supported(struct device *dev, u64 mask); |
Christoph Hellwig | 19dca8c | 2017-12-23 13:46:06 +0100 | [diff] [blame] | 46 | |
Christoph Hellwig | ea8c64a | 2018-01-10 16:21:13 +0100 | [diff] [blame] | 47 | #endif /* _LINUX_DMA_DIRECT_H */ |