memoryCall.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef __ASM_AVR32_DMA_MAPPING_H
  2. #define __ASM_AVR32_DMA_MAPPING_H
  3. #include <linux/mm.h>
  4. #include <linux/device.h>
  5. #include <linux/scatterlist.h>
  6. #include <asm/processor.h>
  7. #include <asm/cacheflush.h>
  8. #include <asm/io.h>
  9. extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  10. int direction);
  11. /*
  12. * Return whether the given device DMA address mask can be supported
  13. * properly. For example, if your device can only drive the low 24-bits
  14. * during bus mastering, then you would pass 0x00ffffff as the mask
  15. * to this function.
  16. */
  17. static inline int dma_supported(struct device *dev, u64 mask)
  18. {
  19. /* Fix when needed. I really don't know of any limitations */
  20. return 1;
  21. }
  22. static inline int dma_set_mask(struct device *dev, u64 dma_mask)
  23. {
  24. if (!dev->dma_mask || !dma_supported(dev, dma_mask))
  25. return -EIO;
  26. *dev->dma_mask = dma_mask;
  27. return 0;
  28. }
  29. /*
  30. * dma_map_single can't fail as it is implemented now.
  31. */
  32. static inline int dma_mapping_error(struct device *dev, dma_addr_t addr)
  33. {
  34. return 0;
  35. }
  36. /**
  37. * dma_alloc_coherent - allocate consistent memory for DMA
  38. * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  39. * @size: required memory size
  40. * @handle: bus-specific DMA address
  41. *
  42. * Allocate some uncached, unbuffered memory for a device for
  43. * performing DMA. This function allocates pages, and will
  44. * return the CPU-viewed address, and sets @handle to be the
  45. * device-viewed address.
  46. */
  47. extern void *dma_alloc_coherent(struct device *dev, size_t size,
  48. dma_addr_t *handle, gfp_t gfp);
  49. /**
  50. * dma_free_coherent - free memory allocated by dma_alloc_coherent
  51. * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  52. * @size: size of memory originally requested in dma_alloc_coherent
  53. * @cpu_addr: CPU-view address returned from dma_alloc_coherent
  54. * @handle: device-view address returned from dma_alloc_coherent
  55. *
  56. * Free (and unmap) a DMA buffer previously allocated by
  57. * dma_alloc_coherent().
  58. *
  59. * References to memory and mappings associated with cpu_addr/handle
  60. * during and after this call executing are illegal.
  61. */
  62. extern void dma_free_coherent(struct device *dev, size_t size,
  63. void *cpu_addr, dma_addr_t handle);
  64. /**
  65. * dma_alloc_writecombine - allocate write-combining memory for DMA
  66. * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  67. * @size: required memory size
  68. * @handle: bus-specific DMA address
  69. *
  70. * Allocate some uncached, buffered memory for a device for
  71. * performing DMA. This function allocates pages, and will
  72. * return the CPU-viewed address, and sets @handle to be the
  73. * device-viewed address.
  74. */
  75. extern void *dma_alloc_writecombine(struct device *dev, size_t size,
  76. dma_addr_t *handle, gfp_t gfp);
  77. /**
  78. * dma_free_coherent - free memory allocated by dma_alloc_writecombine
  79. * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  80. * @size: size of memory originally requested in dma_alloc_writecombine
  81. * @cpu_addr: CPU-view address returned from dma_alloc_writecombine
  82. * @handle: device-view address returned from dma_alloc_writecombine
  83. *
  84. * Free (and unmap) a DMA buffer previously allocated by
  85. * dma_alloc_writecombine().
  86. *
  87. * References to memory and mappings associated with cpu_addr/handle
  88. * during and after this call executing are illegal.
  89. */
  90. extern void dma_free_writecombine(struct device *dev, size_t size,
  91. void *cpu_addr, dma_addr_t handle);
  92. /**
  93. * dma_map_single - map a single buffer for streaming DMA
  94. * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  95. * @cpu_addr: CPU direct mapped address of buffer
  96. * @size: size of buffer to map
  97. * @dir: DMA transfer direction
  98. *
  99. * Ensure that any data held in the cache is appropriately discarded
  100. * or written back.
  101. *
  102. * The device owns this memory once this call has completed. The CPU
  103. * can regain ownership by calling dma_unmap_single() or dma_sync_single().
  104. */
  105. static inline dma_addr_t
  106. dma_map_single(struct device *dev, void *cpu_addr, size_t size,
  107. enum dma_data_direction direction)
  108. {
  109. dma_cache_sync(dev, cpu_addr, size, direction);
  110. return virt_to_bus(cpu_addr);
  111. }
  112. /**
  113. * dma_unmap_single - unmap a single buffer previously mapped
  114. * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  115. * @handle: DMA address of buffer
  116. * @size: size of buffer to map
  117. * @dir: DMA transfer direction
  118. *
  119. * Unmap a single streaming mode DMA translation. The handle and size
  120. * must match what was provided in the previous dma_map_single() call.