dma-mapping-nommu.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Based on linux/arch/arm/mm/dma-mapping.c
  4. *
  5. * Copyright (C) 2000-2004 Russell King
  6. */
  7. #include <linux/dma-map-ops.h>
  8. #include <asm/cachetype.h>
  9. #include <asm/cacheflush.h>
  10. #include <asm/outercache.h>
  11. #include <asm/cp15.h>
  12. #include "dma.h"
  13. void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
  14. enum dma_data_direction dir)
  15. {
  16. dmac_map_area(__va(paddr), size, dir);
  17. if (dir == DMA_FROM_DEVICE)
  18. outer_inv_range(paddr, paddr + size);
  19. else
  20. outer_clean_range(paddr, paddr + size);
  21. }
  22. void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
  23. enum dma_data_direction dir)
  24. {
  25. if (dir != DMA_TO_DEVICE) {
  26. outer_inv_range(paddr, paddr + size);
  27. dmac_unmap_area(__va(paddr), size, dir);
  28. }
  29. }
  30. void arch_setup_dma_ops(struct device *dev, bool coherent)
  31. {
  32. if (IS_ENABLED(CONFIG_CPU_V7M)) {
  33. /*
  34. * Cache support for v7m is optional, so can be treated as
  35. * coherent if no cache has been detected. Note that it is not
  36. * enough to check if MPU is in use or not since in absence of
  37. * MPU system memory map is used.
  38. */
  39. dev->dma_coherent = cacheid ? coherent : true;
  40. } else {
  41. /*
  42. * Assume coherent DMA in case MMU/MPU has not been set up.
  43. */
  44. dev->dma_coherent = (get_cr() & CR_M) ? coherent : true;
  45. }
  46. }