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