dma-mapping.h 1.8 KB

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