dma-mapping.h 2.0 KB

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