dma-mapping_32.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef _ASM_I386_DMA_MAPPING_H
  2. #define _ASM_I386_DMA_MAPPING_H
  3. #include <linux/mm.h>
  4. #include <linux/scatterlist.h>
  5. #include <asm/cache.h>
  6. #include <asm/io.h>
  7. #include <asm/bug.h>
  8. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  9. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  10. void *dma_alloc_coherent(struct device *dev, size_t size,
  11. dma_addr_t *dma_handle, gfp_t flag);
  12. void dma_free_coherent(struct device *dev, size_t size,
  13. void *vaddr, dma_addr_t dma_handle);
  14. static inline int
  15. dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
  16. enum dma_data_direction direction)
  17. {
  18. struct scatterlist *sg;
  19. int i;
  20. BUG_ON(!valid_dma_direction(direction));
  21. WARN_ON(nents == 0 || sglist[0].length == 0);
  22. for_each_sg(sglist, sg, nents, i) {
  23. BUG_ON(!sg_page(sg));
  24. sg->dma_address = sg_phys(sg);
  25. }
  26. flush_write_buffers();
  27. return nents;
  28. }
  29. static inline dma_addr_t
  30. dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  31. size_t size, enum dma_data_direction direction)
  32. {
  33. BUG_ON(!valid_dma_direction(direction));
  34. return page_to_phys(page) + offset;
  35. }
  36. static inline void
  37. dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  38. enum dma_data_direction direction)
  39. {
  40. BUG_ON(!valid_dma_direction(direction));
  41. }
  42. static inline void
  43. dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  44. enum dma_data_direction direction)
  45. {
  46. BUG_ON(!valid_dma_direction(direction));
  47. }
  48. static inline void
  49. dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
  50. enum dma_data_direction direction)
  51. {
  52. }
  53. static inline void
  54. dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
  55. enum dma_data_direction direction)
  56. {
  57. flush_write_buffers();
  58. }
  59. static inline void
  60. dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
  61. unsigned long offset, size_t size,
  62. enum dma_data_direction direction)
  63. {
  64. }
  65. static inline void
  66. dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
  67. unsigned long offset, size_t size,
  68. enum dma_data_direction direction)
  69. {
  70. flush_write_buffers();
  71. }
  72. static inline void
  73. dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
  74. enum dma_data_direction direction)
  75. {
  76. }
  77. static inline void
  78. dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
  79. enum dma_data_direction direction)
  80. {
  81. flush_write_buffers();
  82. }
  83. static inline int
  84. dma_mapping_error(dma_addr_t dma_addr)
  85. {
  86. return 0;
  87. }
  88. extern int forbid_dac;
  89. static inline int
  90. dma_supported(struct device *dev, u64 mask)
  91. {
  92. /*
  93. * we fall back to GFP_DMA when the mask isn't all 1s,
  94. * so we can't guarantee allocations that must be
  95. * within a tighter range than GFP_DMA..
  96. */
  97. if(mask < 0x00ffffff)
  98. return 0;
  99. /* Work around chipset bugs */
  100. if (forbid_dac > 0 && mask > 0xffffffffULL)
  101. return 0;
  102. return 1;
  103. }
  104. static inline int
  105. dma_set_mask(struct device *dev, u64 mask)
  106. {
  107. if(!dev->dma_mask || !dma_supported(dev, mask))
  108. return -EIO;
  109. *dev->dma_mask = mask;
  110. return 0;
  111. }
  112. static inline int
  113. dma_get_cache_alignment(void)
  114. {
  115. /* no easy way to get cache size on all x86, so return the
  116. * maximum possible, to be safe */
  117. return (1 << INTERNODE_CACHE_SHIFT);
  118. }
  119. #define dma_is_consistent(d, h) (1)
  120. static inline void
  121. dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  122. enum dma_data_direction direction)
  123. {
  124. flush_write_buffers();
  125. }
  126. #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
  127. extern int
  128. dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
  129. dma_addr_t device_addr, size_t size, int flags);
  130. extern void
  131. dma_release_declared_memory(struct device *dev);
  132. extern void *
  133. dma_mark_declared_memory_occupied(struct device *dev,
  134. dma_addr_t device_addr, size_t size);
  135. #endif