dma-mapping.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef _ASM_S390_DMA_MAPPING_H
  2. #define _ASM_S390_DMA_MAPPING_H
  3. #include <linux/kernel.h>
  4. #include <linux/types.h>
  5. #include <linux/mm.h>
  6. #include <linux/scatterlist.h>
  7. #include <linux/dma-attrs.h>
  8. #include <linux/dma-debug.h>
  9. #include <linux/io.h>
  10. #define DMA_ERROR_CODE (~(dma_addr_t) 0x0)
  11. extern struct dma_map_ops s390_dma_ops;
  12. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  13. {
  14. return &s390_dma_ops;
  15. }
  16. extern int dma_set_mask(struct device *dev, u64 mask);
  17. extern int dma_is_consistent(struct device *dev, dma_addr_t dma_handle);
  18. extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  19. enum dma_data_direction direction);
  20. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  21. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  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 *dma_ops = get_dma_ops(dev);
  26. if (dma_ops->dma_supported == NULL)
  27. return 1;
  28. return dma_ops->dma_supported(dev, mask);
  29. }
  30. static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
  31. {
  32. if (!dev->dma_mask)
  33. return 0;
  34. return addr + size - 1 <= *dev->dma_mask;
  35. }
  36. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  37. {
  38. struct dma_map_ops *dma_ops = get_dma_ops(dev);
  39. if (dma_ops->mapping_error)
  40. return dma_ops->mapping_error(dev, dma_addr);
  41. return (dma_addr == 0UL);
  42. }
  43. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  44. dma_addr_t *dma_handle, gfp_t flag)
  45. {
  46. struct dma_map_ops *ops = get_dma_ops(dev);
  47. void *ret;
  48. ret = ops->alloc(dev, size, dma_handle, flag, NULL);
  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 *cpu_addr, dma_addr_t dma_handle)
  54. {
  55. struct dma_map_ops *dma_ops = get_dma_ops(dev);
  56. dma_ops->free(dev, size, cpu_addr, dma_handle, NULL);
  57. debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
  58. }
  59. #endif /* _ASM_S390_DMA_MAPPING_H */