dma-mapping.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2011 Tobias Klauser <[email protected]>
  3. * Copyright (C) 2009 Wind River Systems Inc
  4. * Implemented by [email protected] and [email protected]
  5. *
  6. * Based on DMA code from MIPS.
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/mm.h>
  14. #include <linux/string.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/io.h>
  17. #include <linux/cache.h>
  18. #include <asm/cacheflush.h>
  19. void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
  20. enum dma_data_direction dir)
  21. {
  22. void *vaddr = phys_to_virt(paddr);
  23. switch (dir) {
  24. case DMA_FROM_DEVICE:
  25. invalidate_dcache_range((unsigned long)vaddr,
  26. (unsigned long)(vaddr + size));
  27. break;
  28. case DMA_TO_DEVICE:
  29. /*
  30. * We just need to flush the caches here , but Nios2 flush
  31. * instruction will do both writeback and invalidate.
  32. */
  33. case DMA_BIDIRECTIONAL: /* flush and invalidate */
  34. flush_dcache_range((unsigned long)vaddr,
  35. (unsigned long)(vaddr + size));
  36. break;
  37. default:
  38. BUG();
  39. }
  40. }
  41. void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
  42. enum dma_data_direction dir)
  43. {
  44. void *vaddr = phys_to_virt(paddr);
  45. switch (dir) {
  46. case DMA_BIDIRECTIONAL:
  47. case DMA_FROM_DEVICE:
  48. invalidate_dcache_range((unsigned long)vaddr,
  49. (unsigned long)(vaddr + size));
  50. break;
  51. case DMA_TO_DEVICE:
  52. break;
  53. default:
  54. BUG();
  55. }
  56. }
  57. void arch_dma_prep_coherent(struct page *page, size_t size)
  58. {
  59. unsigned long start = (unsigned long)page_address(page);
  60. flush_dcache_range(start, start + size);
  61. }
  62. void *arch_dma_set_uncached(void *ptr, size_t size)
  63. {
  64. unsigned long addr = (unsigned long)ptr;
  65. addr |= CONFIG_NIOS2_IO_REGION_BASE;
  66. return (void *)ptr;
  67. }