dma-mapping.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #define dma_is_consistent(d, h) (1)
  33. static inline int dma_get_cache_alignment(void)
  34. {
  35. /*
  36. * Each processor family will define its own L1_CACHE_SHIFT,
  37. * L1_CACHE_BYTES wraps to this, so this is always safe.
  38. */
  39. return L1_CACHE_BYTES;
  40. }
  41. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  42. {
  43. struct dma_map_ops *ops = get_dma_ops(dev);
  44. if (ops->mapping_error)
  45. return ops->mapping_error(dev, dma_addr);
  46. return dma_addr == 0;
  47. }
  48. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  49. dma_addr_t *dma_handle, gfp_t gfp)
  50. {
  51. struct dma_map_ops *ops = get_dma_ops(dev);
  52. void *memory;
  53. if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
  54. return memory;
  55. if (!ops->alloc_coherent)
  56. return NULL;
  57. memory = ops->alloc_coherent(dev, size, dma_handle, gfp);
  58. debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
  59. return memory;
  60. }
  61. static inline void dma_free_coherent(struct device *dev, size_t size,
  62. void *vaddr, dma_addr_t dma_handle)
  63. {
  64. struct dma_map_ops *ops = get_dma_ops(dev);
  65. WARN_ON(irqs_disabled()); /* for portability */
  66. if (dma_release_from_coherent(dev, get_order(size), vaddr))
  67. return;
  68. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  69. if (ops->free_coherent)
  70. ops->free_coherent(dev, size, vaddr, dma_handle);
  71. }
  72. /* arch/sh/mm/consistent.c */
  73. extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
  74. dma_addr_t *dma_addr, gfp_t flag);
  75. extern void dma_generic_free_coherent(struct device *dev, size_t size,
  76. void *vaddr, dma_addr_t dma_handle);
  77. #endif /* __ASM_SH_DMA_MAPPING_H */