dma.c 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2009-2010 PetaLogix
  4. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corporation
  5. *
  6. * Provide default implementations of the DMA mapping callbacks for
  7. * directly mapped busses.
  8. */
  9. #include <linux/device.h>
  10. #include <linux/dma-map-ops.h>
  11. #include <linux/gfp.h>
  12. #include <linux/export.h>
  13. #include <linux/bug.h>
  14. #include <asm/cacheflush.h>
  15. static void __dma_sync(phys_addr_t paddr, size_t size,
  16. enum dma_data_direction direction)
  17. {
  18. switch (direction) {
  19. case DMA_TO_DEVICE:
  20. case DMA_BIDIRECTIONAL:
  21. flush_dcache_range(paddr, paddr + size);
  22. break;
  23. case DMA_FROM_DEVICE:
  24. invalidate_dcache_range(paddr, paddr + size);
  25. break;
  26. default:
  27. BUG();
  28. }
  29. }
  30. void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
  31. enum dma_data_direction dir)
  32. {
  33. __dma_sync(paddr, size, dir);
  34. }
  35. void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
  36. enum dma_data_direction dir)
  37. {
  38. __dma_sync(paddr, size, dir);
  39. }