dma-mapping.h 1.8 KB

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