1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ASM_ARM_DMA_DIRECT_H
3 #define ASM_ARM_DMA_DIRECT_H 1
5 #include <asm/memory.h>
8 * dma_to_pfn/pfn_to_dma/virt_to_dma are architecture private
9 * functions used internally by the DMA-mapping API to provide DMA
10 * addresses. They must not be used by drivers.
12 static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
14 if (dev && dev->dma_range_map)
15 pfn = PFN_DOWN(translate_phys_to_dma(dev, PFN_PHYS(pfn)));
16 return (dma_addr_t)__pfn_to_bus(pfn);
19 static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
21 unsigned long pfn = __bus_to_pfn(addr);
23 if (dev && dev->dma_range_map)
24 pfn = PFN_DOWN(translate_dma_to_phys(dev, PFN_PHYS(pfn)));
28 static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
31 return pfn_to_dma(dev, virt_to_pfn(addr));
33 return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
36 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
38 unsigned int offset = paddr & ~PAGE_MASK;
39 return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
42 static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
44 unsigned int offset = dev_addr & ~PAGE_MASK;
45 return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
48 #endif /* ASM_ARM_DMA_DIRECT_H */