dma-mapping.h 2.3 KB

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