blob: be39a12901c6c33563b2abedf3a7698caf76ed4c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_DMA_MAPPING_H
2#define _ASM_DMA_MAPPING_H
3
4#include <asm/scatterlist.h>
5#include <asm/cache.h>
Yoichi Yuasaf8ac0422009-06-04 00:16:04 +09006#include <asm-generic/dma-coherent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Ralf Baechlea5602a32011-05-18 13:14:36 +01008#ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */
David Daney48e1fd52010-10-01 13:27:32 -07009#include <dma-coherence.h>
Ralf Baechlea5602a32011-05-18 13:14:36 +010010#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
David Daney48e1fd52010-10-01 13:27:32 -070012extern struct dma_map_ops *mips_dma_map_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
David Daney48e1fd52010-10-01 13:27:32 -070014static inline struct dma_map_ops *get_dma_ops(struct device *dev)
Atsushi Nemoto4f29c052009-01-23 00:42:11 +090015{
David Daney48e1fd52010-10-01 13:27:32 -070016 if (dev && dev->archdata.dma_ops)
17 return dev->archdata.dma_ops;
18 else
19 return mips_dma_map_ops;
Atsushi Nemoto4f29c052009-01-23 00:42:11 +090020}
21
David Daney48e1fd52010-10-01 13:27:32 -070022static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
23{
24 if (!dev->dma_mask)
25 return 0;
26
27 return addr + size <= *dev->dma_mask;
28}
29
30static inline void dma_mark_clean(void *addr, size_t size) {}
31
32#include <asm-generic/dma-mapping-common.h>
33
34static inline int dma_supported(struct device *dev, u64 mask)
35{
36 struct dma_map_ops *ops = get_dma_ops(dev);
37 return ops->dma_supported(dev, mask);
38}
39
40static inline int dma_mapping_error(struct device *dev, u64 mask)
41{
42 struct dma_map_ops *ops = get_dma_ops(dev);
43 return ops->mapping_error(dev, mask);
44}
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46static inline int
47dma_set_mask(struct device *dev, u64 mask)
48{
49 if(!dev->dma_mask || !dma_supported(dev, mask))
50 return -EIO;
51
52 *dev->dma_mask = mask;
53
54 return 0;
55}
56
Ralf Baechled3fa72e2006-12-06 20:38:56 -080057extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 enum dma_data_direction direction);
59
Andrzej Pietrasiewicze8d51e52012-03-27 14:32:21 +020060#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
61
62static inline void *dma_alloc_attrs(struct device *dev, size_t size,
63 dma_addr_t *dma_handle, gfp_t gfp,
64 struct dma_attrs *attrs)
David Daney48e1fd52010-10-01 13:27:32 -070065{
66 void *ret;
67 struct dma_map_ops *ops = get_dma_ops(dev);
68
Andrzej Pietrasiewicze8d51e52012-03-27 14:32:21 +020069 ret = ops->alloc(dev, size, dma_handle, gfp, attrs);
David Daney48e1fd52010-10-01 13:27:32 -070070
71 debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
72
73 return ret;
74}
75
Andrzej Pietrasiewicze8d51e52012-03-27 14:32:21 +020076#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
77
78static inline void dma_free_attrs(struct device *dev, size_t size,
79 void *vaddr, dma_addr_t dma_handle,
80 struct dma_attrs *attrs)
David Daney48e1fd52010-10-01 13:27:32 -070081{
82 struct dma_map_ops *ops = get_dma_ops(dev);
83
Andrzej Pietrasiewicze8d51e52012-03-27 14:32:21 +020084 ops->free(dev, size, vaddr, dma_handle, attrs);
David Daney48e1fd52010-10-01 13:27:32 -070085
86 debug_dma_free_coherent(dev, size, vaddr, dma_handle);
87}
88
89
90void *dma_alloc_noncoherent(struct device *dev, size_t size,
91 dma_addr_t *dma_handle, gfp_t flag);
92
93void dma_free_noncoherent(struct device *dev, size_t size,
94 void *vaddr, dma_addr_t dma_handle);
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#endif /* _ASM_DMA_MAPPING_H */