1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_DMA_MAPPING_H
3 #define _LINUX_DMA_MAPPING_H
5 #include <linux/dma-direction.h>
6 #include <linux/types.h>
7 #include <asm/dma-mapping.h>
10 #define dma_mapping_error(x, y) 0
13 * Map a buffer to make it available to the DMA device
15 * Linux-like DMA API that is intended to be used from drivers. This hides the
16 * underlying cache operation from drivers. Call this before starting the DMA
17 * transfer. In most of architectures in U-Boot, the virtual address matches to
18 * the physical address (but we have exceptions like sandbox). U-Boot does not
19 * support iommu at the driver level, so it also matches to the DMA address.
20 * Hence, this helper currently just performs the cache operation, then returns
21 * straight-mapped dma_address, which is intended to be set to the register of
24 * @vaddr: address of the buffer
25 * @len: length of the buffer
26 * @dir: the direction of DMA
28 static inline dma_addr_t dma_map_single(void *vaddr, size_t len,
29 enum dma_data_direction dir)
31 unsigned long addr = (unsigned long)vaddr;
33 len = ALIGN(len, ARCH_DMA_MINALIGN);
35 if (dir == DMA_FROM_DEVICE)
36 invalidate_dcache_range(addr, addr + len);
38 flush_dcache_range(addr, addr + len);
44 * Unmap a buffer to make it available to CPU
46 * Linux-like DMA API that is intended to be used from drivers. This hides the
47 * underlying cache operation from drivers. Call this after finishin the DMA
51 * @len: length of the buffer
52 * @dir: the direction of DMA
54 static inline void dma_unmap_single(dma_addr_t addr, size_t len,
55 enum dma_data_direction dir)
57 len = ALIGN(len, ARCH_DMA_MINALIGN);
59 if (dir != DMA_TO_DEVICE)
60 invalidate_dcache_range(addr, addr + len);