xref: /linux/arch/powerpc/include/asm/dma-direct.h (revision e9f0878c4b2004ac19581274c1ae4c61ae3ca70e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ASM_POWERPC_DMA_DIRECT_H
3 #define ASM_POWERPC_DMA_DIRECT_H 1
4 
5 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
6 {
7 #ifdef CONFIG_SWIOTLB
8 	struct dev_archdata *sd = &dev->archdata;
9 
10 	if (sd->max_direct_dma_addr && addr + size > sd->max_direct_dma_addr)
11 		return false;
12 #endif
13 
14 	if (!dev->dma_mask)
15 		return false;
16 
17 	return addr + size - 1 <= *dev->dma_mask;
18 }
19 
20 static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
21 {
22 	return paddr + get_dma_offset(dev);
23 }
24 
25 static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
26 {
27 	return daddr - get_dma_offset(dev);
28 }
29 #endif /* ASM_POWERPC_DMA_DIRECT_H */
30