dma.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Dynamic DMA mapping support.
  3. *
  4. * On cris there is no hardware dynamic DMA address translation,
  5. * so consistent alloc/free are merely page allocation/freeing.
  6. * The rest of the dynamic DMA mapping interface is implemented
  7. * in asm/pci.h.
  8. *
  9. * Borrowed from i386.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/mm.h>
  13. #include <linux/string.h>
  14. #include <linux/pci.h>
  15. #include <linux/gfp.h>
  16. #include <asm/io.h>
  17. static void *v32_dma_alloc(struct device *dev, size_t size,
  18. dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
  19. {
  20. void *ret;
  21. /* ignore region specifiers */
  22. gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
  23. if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
  24. gfp |= GFP_DMA;
  25. ret = (void *)__get_free_pages(gfp, get_order(size));
  26. if (ret != NULL) {
  27. memset(ret, 0, size);
  28. *dma_handle = virt_to_phys(ret);
  29. }
  30. return ret;
  31. }
  32. static void v32_dma_free(struct device *dev, size_t size, void *vaddr,
  33. dma_addr_t dma_handle, unsigned long attrs)
  34. {
  35. free_pages((unsigned long)vaddr, get_order(size));
  36. }
  37. static inline dma_addr_t v32_dma_map_page(struct device *dev,
  38. struct page *page, unsigned long offset, size_t size,
  39. enum dma_data_direction direction, unsigned long attrs)
  40. {
  41. return page_to_phys(page) + offset;
  42. }
  43. static inline int v32_dma_map_sg(struct device *dev, struct scatterlist *sg,
  44. int nents, enum dma_data_direction direction,
  45. unsigned long attrs)
  46. {
  47. printk("Map sg\n");
  48. return nents;
  49. }
  50. static inline int v32_dma_supported(struct device *dev, u64 mask)
  51. {
  52. /*
  53. * we fall back to GFP_DMA when the mask isn't all 1s,
  54. * so we can't guarantee allocations that must be
  55. * within a tighter range than GFP_DMA..
  56. */
  57. if (mask < 0x00ffffff)
  58. return 0;
  59. return 1;
  60. }
  61. struct dma_map_ops v32_dma_ops = {
  62. .alloc = v32_dma_alloc,
  63. .free = v32_dma_free,
  64. .map_page = v32_dma_map_page,
  65. .map_sg = v32_dma_map_sg,
  66. .dma_supported = v32_dma_supported,
  67. };
  68. EXPORT_SYMBOL(v32_dma_ops);