dma.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file COPYING in the main directory of this archive
  4. * for more details.
  5. */
  6. #undef DEBUG
  7. #include <linux/dma-map-ops.h>
  8. #include <linux/device.h>
  9. #include <linux/kernel.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/scatterlist.h>
  12. #include <linux/slab.h>
  13. #include <linux/vmalloc.h>
  14. #include <linux/export.h>
  15. #include <asm/cacheflush.h>
  16. #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
  17. void arch_dma_prep_coherent(struct page *page, size_t size)
  18. {
  19. cache_push(page_to_phys(page), size);
  20. }
  21. pgprot_t pgprot_dmacoherent(pgprot_t prot)
  22. {
  23. if (CPU_IS_040_OR_060) {
  24. pgprot_val(prot) &= ~_PAGE_CACHE040;
  25. pgprot_val(prot) |= _PAGE_GLOBAL040 | _PAGE_NOCACHE_S;
  26. } else {
  27. pgprot_val(prot) |= _PAGE_NOCACHE030;
  28. }
  29. return prot;
  30. }
  31. #else
  32. void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
  33. gfp_t gfp, unsigned long attrs)
  34. {
  35. void *ret;
  36. if (dev == NULL || (*dev->dma_mask < 0xffffffff))
  37. gfp |= GFP_DMA;
  38. ret = (void *)__get_free_pages(gfp, get_order(size));
  39. if (ret != NULL) {
  40. memset(ret, 0, size);
  41. *dma_handle = virt_to_phys(ret);
  42. }
  43. return ret;
  44. }
  45. void arch_dma_free(struct device *dev, size_t size, void *vaddr,
  46. dma_addr_t dma_handle, unsigned long attrs)
  47. {
  48. free_pages((unsigned long)vaddr, get_order(size));
  49. }
  50. #endif /* CONFIG_MMU && !CONFIG_COLDFIRE */
  51. void arch_sync_dma_for_device(phys_addr_t handle, size_t size,
  52. enum dma_data_direction dir)
  53. {
  54. switch (dir) {
  55. case DMA_BIDIRECTIONAL:
  56. case DMA_TO_DEVICE:
  57. cache_push(handle, size);
  58. break;
  59. case DMA_FROM_DEVICE:
  60. cache_clear(handle, size);
  61. break;
  62. default:
  63. pr_err_ratelimited("dma_sync_single_for_device: unsupported dir %u\n",
  64. dir);
  65. break;
  66. }
  67. }