blob: 2f8c1abeb086999ada3a2938973b8054f112625e [file] [log] [blame]
Jan Glauber828b35f2012-11-29 14:33:30 +01001#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
14extern struct dma_map_ops s390_dma_ops;
15
16static inline struct dma_map_ops *get_dma_ops(struct device *dev)
17{
18 return &s390_dma_ops;
19}
20
21extern int dma_set_mask(struct device *dev, u64 mask);
Heiko Carstense9789482013-01-30 14:16:02 +010022
23static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
24 enum dma_data_direction direction)
25{
26}
Jan Glauber828b35f2012-11-29 14:33:30 +010027
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
33static 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
42static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
43{
44 if (!dev->dma_mask)
45 return 0;
46 return addr + size - 1 <= *dev->dma_mask;
47}
48
49static 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 Ott40260992013-06-18 17:38:31 +020053 debug_dma_mapping_error(dev, dma_addr);
Jan Glauber828b35f2012-11-29 14:33:30 +010054 if (dma_ops->mapping_error)
55 return dma_ops->mapping_error(dev, dma_addr);
Sebastian Ott73e5a842013-06-18 17:32:26 +020056 return (dma_addr == DMA_ERROR_CODE);
Jan Glauber828b35f2012-11-29 14:33:30 +010057}
58
59static inline void *dma_alloc_coherent(struct device *dev, size_t size,
60 dma_addr_t *dma_handle, gfp_t flag)
61{
62 struct dma_map_ops *ops = get_dma_ops(dev);
63 void *ret;
64
65 ret = ops->alloc(dev, size, dma_handle, flag, NULL);
66 debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
67 return ret;
68}
69
70static inline void dma_free_coherent(struct device *dev, size_t size,
71 void *cpu_addr, dma_addr_t dma_handle)
72{
73 struct dma_map_ops *dma_ops = get_dma_ops(dev);
74
Jan Glauber828b35f2012-11-29 14:33:30 +010075 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
Sebastian Ottabd9a0c2013-05-17 16:37:59 +020076 dma_ops->free(dev, size, cpu_addr, dma_handle, NULL);
Jan Glauber828b35f2012-11-29 14:33:30 +010077}
78
79#endif /* _ASM_S390_DMA_MAPPING_H */