dma-mapping.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  33. {
  34. struct dma_map_ops *ops = get_dma_ops(dev);
  35. debug_dma_mapping_error(dev, dma_addr);
  36. if (ops->mapping_error)
  37. return ops->mapping_error(dev, dma_addr);
  38. return dma_addr == 0;
  39. }
  40. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  41. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  42. dma_addr_t *dma_handle, gfp_t gfp,
  43. struct dma_attrs *attrs)
  44. {
  45. struct dma_map_ops *ops = get_dma_ops(dev);
  46. void *memory;
  47. if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
  48. return memory;
  49. if (!ops->alloc)
  50. return NULL;
  51. memory = ops->alloc(dev, size, dma_handle, gfp, attrs);
  52. debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
  53. return memory;
  54. }
  55. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  56. static inline void dma_free_attrs(struct device *dev, size_t size,
  57. void *vaddr, dma_addr_t dma_handle,
  58. struct dma_attrs *attrs)
  59. {
  60. struct dma_map_ops *ops = get_dma_ops(dev);
  61. if (dma_release_from_coherent(dev, get_order(size), vaddr))
  62. return;
  63. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  64. if (ops->free)
  65. ops->free(dev, size, vaddr, dma_handle, attrs);
  66. }
  67. /* arch/sh/mm/consistent.c */
  68. extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
  69. dma_addr_t *dma_addr, gfp_t flag,
  70. struct dma_attrs *attrs);
  71. extern void dma_generic_free_coherent(struct device *dev, size_t size,
  72. void *vaddr, dma_addr_t dma_handle,
  73. struct dma_attrs *attrs);
  74. #endif /* __ASM_SH_DMA_MAPPING_H */