dma-mapping.h 3.2 KB

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