Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 1 | #ifndef _ASM_S390_DMA_MAPPING_H |
| 2 | #define _ASM_S390_DMA_MAPPING_H |
| 3 | |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/scatterlist.h> |
| 8 | #include <linux/dma-attrs.h> |
| 9 | #include <linux/dma-debug.h> |
| 10 | #include <linux/io.h> |
| 11 | |
| 12 | #define DMA_ERROR_CODE (~(dma_addr_t) 0x0) |
| 13 | |
| 14 | extern struct dma_map_ops s390_dma_ops; |
| 15 | |
| 16 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) |
| 17 | { |
| 18 | return &s390_dma_ops; |
| 19 | } |
| 20 | |
| 21 | extern int dma_set_mask(struct device *dev, u64 mask); |
Heiko Carstens | e978948 | 2013-01-30 14:16:02 +0100 | [diff] [blame] | 22 | |
| 23 | static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
| 24 | enum dma_data_direction direction) |
| 25 | { |
| 26 | } |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 27 | |
| 28 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 29 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
| 30 | |
| 31 | #include <asm-generic/dma-mapping-common.h> |
| 32 | |
| 33 | static inline int dma_supported(struct device *dev, u64 mask) |
| 34 | { |
| 35 | struct dma_map_ops *dma_ops = get_dma_ops(dev); |
| 36 | |
| 37 | if (dma_ops->dma_supported == NULL) |
| 38 | return 1; |
| 39 | return dma_ops->dma_supported(dev, mask); |
| 40 | } |
| 41 | |
| 42 | static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) |
| 43 | { |
| 44 | if (!dev->dma_mask) |
Joe Perches | 1c6e4b1 | 2015-03-30 16:46:05 -0700 | [diff] [blame] | 45 | return false; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 46 | return addr + size - 1 <= *dev->dma_mask; |
| 47 | } |
| 48 | |
| 49 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
| 50 | { |
| 51 | struct dma_map_ops *dma_ops = get_dma_ops(dev); |
| 52 | |
Sebastian Ott | 4026099 | 2013-06-18 17:38:31 +0200 | [diff] [blame] | 53 | debug_dma_mapping_error(dev, dma_addr); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 54 | if (dma_ops->mapping_error) |
| 55 | return dma_ops->mapping_error(dev, dma_addr); |
Sebastian Ott | a9a5250cc | 2013-06-21 19:00:27 +0200 | [diff] [blame] | 56 | return dma_addr == DMA_ERROR_CODE; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Thierry Reding | 90114d6 | 2014-08-25 13:02:52 +0200 | [diff] [blame] | 59 | #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL) |
| 60 | |
| 61 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, |
| 62 | dma_addr_t *dma_handle, gfp_t flags, |
| 63 | struct dma_attrs *attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 64 | { |
| 65 | struct dma_map_ops *ops = get_dma_ops(dev); |
Thierry Reding | 90114d6 | 2014-08-25 13:02:52 +0200 | [diff] [blame] | 66 | void *cpu_addr; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 67 | |
Thierry Reding | 90114d6 | 2014-08-25 13:02:52 +0200 | [diff] [blame] | 68 | BUG_ON(!ops); |
| 69 | |
| 70 | cpu_addr = ops->alloc(dev, size, dma_handle, flags, attrs); |
| 71 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); |
| 72 | |
| 73 | return cpu_addr; |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Thierry Reding | 90114d6 | 2014-08-25 13:02:52 +0200 | [diff] [blame] | 76 | #define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL) |
| 77 | |
| 78 | static inline void dma_free_attrs(struct device *dev, size_t size, |
| 79 | void *cpu_addr, dma_addr_t dma_handle, |
| 80 | struct dma_attrs *attrs) |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 81 | { |
Thierry Reding | 90114d6 | 2014-08-25 13:02:52 +0200 | [diff] [blame] | 82 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 83 | |
| 84 | BUG_ON(!ops); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 85 | |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 86 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); |
Thierry Reding | 90114d6 | 2014-08-25 13:02:52 +0200 | [diff] [blame] | 87 | ops->free(dev, size, cpu_addr, dma_handle, attrs); |
Jan Glauber | 828b35f | 2012-11-29 14:33:30 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | #endif /* _ASM_S390_DMA_MAPPING_H */ |