dma-mapping.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef _ASM_DMA_MAPPING_H
  2. #define _ASM_DMA_MAPPING_H
  3. #include <asm/scatterlist.h>
  4. #include <asm/dma-coherence.h>
  5. #include <asm/cache.h>
  6. #include <asm-generic/dma-coherent.h>
  7. #ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */
  8. #include <dma-coherence.h>
  9. #endif
  10. extern struct dma_map_ops *mips_dma_map_ops;
  11. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  12. {
  13. if (dev && dev->archdata.dma_ops)
  14. return dev->archdata.dma_ops;
  15. else
  16. return mips_dma_map_ops;
  17. }
  18. static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
  19. {
  20. if (!dev->dma_mask)
  21. return 0;
  22. return addr + size <= *dev->dma_mask;
  23. }
  24. static inline void dma_mark_clean(void *addr, size_t size) {}
  25. #include <asm-generic/dma-mapping-common.h>
  26. static inline int dma_supported(struct device *dev, u64 mask)
  27. {
  28. struct dma_map_ops *ops = get_dma_ops(dev);
  29. return ops->dma_supported(dev, mask);
  30. }
  31. static inline int dma_mapping_error(struct device *dev, u64 mask)
  32. {
  33. struct dma_map_ops *ops = get_dma_ops(dev);
  34. debug_dma_mapping_error(dev, mask);
  35. return ops->mapping_error(dev, mask);
  36. }
  37. static inline int
  38. dma_set_mask(struct device *dev, u64 mask)
  39. {
  40. struct dma_map_ops *ops = get_dma_ops(dev);
  41. if(!dev->dma_mask || !dma_supported(dev, mask))
  42. return -EIO;
  43. if (ops->set_dma_mask)
  44. return ops->set_dma_mask(dev, mask);
  45. *dev->dma_mask = mask;
  46. return 0;
  47. }
  48. extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  49. enum dma_data_direction direction);
  50. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  51. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  52. dma_addr_t *dma_handle, gfp_t gfp,
  53. struct dma_attrs *attrs)
  54. {
  55. void *ret;
  56. struct dma_map_ops *ops = get_dma_ops(dev);
  57. ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  58. debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
  59. return ret;
  60. }
  61. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  62. static inline void dma_free_attrs(struct device *dev, size_t size,
  63. void *vaddr, dma_addr_t dma_handle,
  64. struct dma_attrs *attrs)
  65. {
  66. struct dma_map_ops *ops = get_dma_ops(dev);
  67. ops->free(dev, size, vaddr, dma_handle, attrs);
  68. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  69. }
  70. void *dma_alloc_noncoherent(struct device *dev, size_t size,
  71. dma_addr_t *dma_handle, gfp_t flag);
  72. void dma_free_noncoherent(struct device *dev, size_t size,
  73. void *vaddr, dma_addr_t dma_handle);
  74. #endif /* _ASM_DMA_MAPPING_H */