dma-mapping.h 2.1 KB

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