dma-mapping.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef __ASM_SH_DMA_MAPPING_H
  2. #define __ASM_SH_DMA_MAPPING_H
  3. extern struct dma_map_ops *dma_ops;
  4. extern void no_iommu_init(void);
  5. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  6. {
  7. return dma_ops;
  8. }
  9. #include <asm-generic/dma-coherent.h>
  10. #include <asm-generic/dma-mapping-common.h>
  11. static inline int dma_supported(struct device *dev, u64 mask)
  12. {
  13. struct dma_map_ops *ops = get_dma_ops(dev);
  14. if (ops->dma_supported)
  15. return ops->dma_supported(dev, mask);
  16. return 1;
  17. }
  18. static inline int dma_set_mask(struct device *dev, u64 mask)
  19. {
  20. struct dma_map_ops *ops = get_dma_ops(dev);
  21. if (!dev->dma_mask || !dma_supported(dev, mask))
  22. return -EIO;
  23. if (ops->set_dma_mask)
  24. return ops->set_dma_mask(dev, mask);
  25. *dev->dma_mask = mask;
  26. return 0;
  27. }
  28. void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  29. enum dma_data_direction dir);
  30. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  31. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  32. #ifdef CONFIG_DMA_COHERENT
  33. #define dma_is_consistent(d, h) (1)
  34. #else
  35. #define dma_is_consistent(d, h) (0)
  36. #endif
  37. static inline int dma_get_cache_alignment(void)
  38. {
  39. /*
  40. * Each processor family will define its own L1_CACHE_SHIFT,
  41. * L1_CACHE_BYTES wraps to this, so this is always safe.
  42. */
  43. return L1_CACHE_BYTES;
  44. }
  45. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  46. {
  47. struct dma_map_ops *ops = get_dma_ops(dev);
  48. if (ops->mapping_error)
  49. return ops->mapping_error(dev, dma_addr);
  50. return dma_addr == 0;
  51. }
  52. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  53. dma_addr_t *dma_handle, gfp_t gfp)
  54. {
  55. struct dma_map_ops *ops = get_dma_ops(dev);
  56. void *memory;
  57. if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
  58. return memory;
  59. if (!ops->alloc_coherent)
  60. return NULL;
  61. memory = ops->alloc_coherent(dev, size, dma_handle, gfp);
  62. debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
  63. return memory;
  64. }
  65. static inline void dma_free_coherent(struct device *dev, size_t size,
  66. void *vaddr, dma_addr_t dma_handle)
  67. {
  68. struct dma_map_ops *ops = get_dma_ops(dev);
  69. if (dma_release_from_coherent(dev, get_order(size), vaddr))
  70. return;
  71. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  72. if (ops->free_coherent)
  73. ops->free_coherent(dev, size, vaddr, dma_handle);
  74. }
  75. /* arch/sh/mm/consistent.c */
  76. extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
  77. dma_addr_t *dma_addr, gfp_t flag);
  78. extern void dma_generic_free_coherent(struct device *dev, size_t size,
  79. void *vaddr, dma_addr_t dma_handle);
  80. #endif /* __ASM_SH_DMA_MAPPING_H */