dma-mapping.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Copyright (C) 2004 IBM
  2. *
  3. * Implements the generic device dma API for ppc64. Handles
  4. * the pci and vio busses
  5. */
  6. #ifndef _ASM_DMA_MAPPING_H
  7. #define _ASM_DMA_MAPPING_H
  8. #include <linux/types.h>
  9. #include <linux/cache.h>
  10. /* need struct page definitions */
  11. #include <linux/mm.h>
  12. #include <asm/scatterlist.h>
  13. #include <asm/bug.h>
  14. #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
  15. extern int dma_supported(struct device *dev, u64 mask);
  16. extern int dma_set_mask(struct device *dev, u64 dma_mask);
  17. extern void *dma_alloc_coherent(struct device *dev, size_t size,
  18. dma_addr_t *dma_handle, unsigned int __nocast flag);
  19. extern void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  20. dma_addr_t dma_handle);
  21. extern dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
  22. size_t size, enum dma_data_direction direction);
  23. extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
  24. size_t size, enum dma_data_direction direction);
  25. extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
  26. unsigned long offset, size_t size,
  27. enum dma_data_direction direction);
  28. extern void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
  29. size_t size, enum dma_data_direction direction);
  30. extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  31. enum dma_data_direction direction);
  32. extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
  33. int nhwentries, enum dma_data_direction direction);
  34. static inline void
  35. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  36. enum dma_data_direction direction)
  37. {
  38. BUG_ON(direction == DMA_NONE);
  39. /* nothing to do */
  40. }
  41. static inline void
  42. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  43. enum dma_data_direction direction)
  44. {
  45. BUG_ON(direction == DMA_NONE);
  46. /* nothing to do */
  47. }
  48. static inline void
  49. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  50. enum dma_data_direction direction)
  51. {
  52. BUG_ON(direction == DMA_NONE);
  53. /* nothing to do */
  54. }
  55. static inline void
  56. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  57. enum dma_data_direction direction)
  58. {
  59. BUG_ON(direction == DMA_NONE);
  60. /* nothing to do */
  61. }
  62. static inline int dma_mapping_error(dma_addr_t dma_addr)
  63. {
  64. return (dma_addr == DMA_ERROR_CODE);
  65. }
  66. /* Now for the API extensions over the pci_ one */
  67. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  68. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  69. #define dma_is_consistent(d) (1)
  70. static inline int
  71. dma_get_cache_alignment(void)
  72. {
  73. /* no easy way to get cache size on all processors, so return
  74. * the maximum possible, to be safe */
  75. return (1 << L1_CACHE_SHIFT_MAX);
  76. }
  77. static inline void
  78. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  79. unsigned long offset, size_t size,
  80. enum dma_data_direction direction)
  81. {
  82. BUG_ON(direction == DMA_NONE);
  83. /* nothing to do */
  84. }
  85. static inline void
  86. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  87. unsigned long offset, size_t size,
  88. enum dma_data_direction direction)
  89. {
  90. BUG_ON(direction == DMA_NONE);
  91. /* nothing to do */
  92. }
  93. static inline void
  94. dma_cache_sync(void *vaddr, size_t size,
  95. enum dma_data_direction direction)
  96. {
  97. BUG_ON(direction == DMA_NONE);
  98. /* nothing to do */
  99. }
  100. /*
  101. * DMA operations are abstracted for G5 vs. i/pSeries, PCI vs. VIO
  102. */
  103. struct dma_mapping_ops {
  104. void * (*alloc_coherent)(struct device *dev, size_t size,
  105. dma_addr_t *dma_handle, unsigned int __nocast flag);
  106. void (*free_coherent)(struct device *dev, size_t size,
  107. void *vaddr, dma_addr_t dma_handle);
  108. dma_addr_t (*map_single)(struct device *dev, void *ptr,
  109. size_t size, enum dma_data_direction direction);
  110. void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
  111. size_t size, enum dma_data_direction direction);
  112. int (*map_sg)(struct device *dev, struct scatterlist *sg,
  113. int nents, enum dma_data_direction direction);
  114. void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
  115. int nents, enum dma_data_direction direction);
  116. int (*dma_supported)(struct device *dev, u64 mask);
  117. int (*dac_dma_supported)(struct device *dev, u64 mask);
  118. };
  119. #endif /* _ASM_DMA_MAPPING_H */