dma-mapping.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #ifndef _BLACKFIN_DMA_MAPPING_H
  7. #define _BLACKFIN_DMA_MAPPING_H
  8. #include <asm/scatterlist.h>
  9. void dma_alloc_init(unsigned long start, unsigned long end);
  10. void *dma_alloc_coherent(struct device *dev, size_t size,
  11. dma_addr_t *dma_handle, gfp_t gfp);
  12. void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
  13. dma_addr_t dma_handle);
  14. /*
  15. * Now for the API extensions over the pci_ one
  16. */
  17. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  18. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  19. static inline
  20. int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  21. {
  22. return 0;
  23. }
  24. /*
  25. * Map a single buffer of the indicated size for DMA in streaming mode.
  26. * The 32-bit bus address to use is returned.
  27. *
  28. * Once the device is given the dma address, the device owns this memory
  29. * until either pci_unmap_single or pci_dma_sync_single is performed.
  30. */
  31. extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
  32. enum dma_data_direction direction);
  33. static inline dma_addr_t
  34. dma_map_page(struct device *dev, struct page *page,
  35. unsigned long offset, size_t size,
  36. enum dma_data_direction dir)
  37. {
  38. return dma_map_single(dev, page_address(page) + offset, size, dir);
  39. }
  40. /*
  41. * Unmap a single streaming mode DMA translation. The dma_addr and size
  42. * must match what was provided for in a previous pci_map_single call. All
  43. * other usages are undefined.
  44. *
  45. * After this call, reads by the cpu to the buffer are guarenteed to see
  46. * whatever the device wrote there.
  47. */
  48. extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  49. enum dma_data_direction direction);
  50. static inline void
  51. dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
  52. enum dma_data_direction dir)
  53. {
  54. dma_unmap_single(dev, dma_addr, size, dir);
  55. }
  56. /*
  57. * Map a set of buffers described by scatterlist in streaming
  58. * mode for DMA. This is the scather-gather version of the
  59. * above pci_map_single interface. Here the scatter gather list
  60. * elements are each tagged with the appropriate dma address
  61. * and length. They are obtained via sg_dma_{address,length}(SG).
  62. *
  63. * NOTE: An implementation may be able to use a smaller number of
  64. * DMA address/length pairs than there are SG table elements.
  65. * (for example via virtual mapping capabilities)
  66. * The routine returns the number of addr/length pairs actually
  67. * used, at most nents.
  68. *
  69. * Device ownership issues as mentioned above for pci_map_single are
  70. * the same here.
  71. */
  72. extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  73. enum dma_data_direction direction);
  74. /*
  75. * Unmap a set of streaming mode DMA translations.
  76. * Again, cpu read rules concerning calls here are the same as for
  77. * pci_unmap_single() above.
  78. */
  79. extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  80. int nhwentries, enum dma_data_direction direction);
  81. static inline void dma_sync_single_for_cpu(struct device *dev,
  82. dma_addr_t handle, size_t size,
  83. enum dma_data_direction dir)
  84. {
  85. }
  86. static inline void dma_sync_single_for_device(struct device *dev,
  87. dma_addr_t handle, size_t size,
  88. enum dma_data_direction dir)
  89. {
  90. }
  91. static inline void dma_sync_sg_for_cpu(struct device *dev,
  92. struct scatterlist *sg,
  93. int nents, enum dma_data_direction dir)
  94. {
  95. }
  96. static inline void dma_sync_sg_for_device(struct device *dev,
  97. struct scatterlist *sg,
  98. int nents, enum dma_data_direction dir)
  99. {
  100. }
  101. #endif /* _BLACKFIN_DMA_MAPPING_H */