dma-mapping.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if(!dev->dma_mask || !dma_supported(dev, mask))
  41. return -EIO;
  42. *dev->dma_mask = mask;
  43. return 0;
  44. }
  45. extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  46. enum dma_data_direction direction);
  47. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  48. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  49. dma_addr_t *dma_handle, gfp_t gfp,
  50. struct dma_attrs *attrs)
  51. {
  52. void *ret;
  53. struct dma_map_ops *ops = get_dma_ops(dev);
  54. ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  55. debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
  56. return ret;
  57. }
  58. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  59. static inline void dma_free_attrs(struct device *dev, size_t size,
  60. void *vaddr, dma_addr_t dma_handle,
  61. struct dma_attrs *attrs)
  62. {
  63. struct dma_map_ops *ops = get_dma_ops(dev);
  64. ops->free(dev, size, vaddr, dma_handle, attrs);
  65. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  66. }
  67. void *dma_alloc_noncoherent(struct device *dev, size_t size,
  68. dma_addr_t *dma_handle, gfp_t flag);
  69. void dma_free_noncoherent(struct device *dev, size_t size,
  70. void *vaddr, dma_addr_t dma_handle);
  71. #endif /* _ASM_DMA_MAPPING_H */