dma-mapping.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  46. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  47. dma_addr_t *dma_handle, gfp_t gfp,
  48. struct dma_attrs *attrs)
  49. {
  50. void *ret;
  51. struct dma_map_ops *ops = get_dma_ops(dev);
  52. ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
  53. debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
  54. return ret;
  55. }
  56. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  57. static inline void dma_free_attrs(struct device *dev, size_t size,
  58. void *vaddr, dma_addr_t dma_handle,
  59. struct dma_attrs *attrs)
  60. {
  61. struct dma_map_ops *ops = get_dma_ops(dev);
  62. ops->free(dev, size, vaddr, dma_handle, attrs);
  63. debug_dma_free_coherent(dev, size, vaddr, dma_handle);
  64. }
  65. void *dma_alloc_noncoherent(struct device *dev, size_t size,
  66. dma_addr_t *dma_handle, gfp_t flag);
  67. void dma_free_noncoherent(struct device *dev, size_t size,
  68. void *vaddr, dma_addr_t dma_handle);
  69. #endif /* _ASM_DMA_MAPPING_H */