blob: b197595134ba0848299717828527af3a32dedb53 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_DMA_MAPPING_H
2#define _ASM_DMA_MAPPING_H
3
Christoph Hellwig84be4562015-05-01 12:46:15 +02004#include <linux/scatterlist.h>
Steven J. Hillb6d92b42013-03-25 13:47:29 -05005#include <asm/dma-coherence.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/cache.h>
7
Ralf Baechle70342282013-01-22 12:59:30 +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)
Joe Perches3db27422015-03-30 16:46:03 -070025 return false;
David Daney48e1fd52010-10-01 13:27:32 -070026
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);
Shuah Khan9c83b07c2012-11-23 14:34:56 -070043
44 debug_dma_mapping_error(dev, mask);
David Daney48e1fd52010-10-01 13:27:32 -070045 return ops->mapping_error(dev, mask);
46}
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48static inline int
49dma_set_mask(struct device *dev, u64 mask)
50{
Huacai Chen1299b0e2014-03-21 18:44:06 +080051 struct dma_map_ops *ops = get_dma_ops(dev);
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 if(!dev->dma_mask || !dma_supported(dev, mask))
54 return -EIO;
55
Huacai Chen1299b0e2014-03-21 18:44:06 +080056 if (ops->set_dma_mask)
57 return ops->set_dma_mask(dev, mask);
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 *dev->dma_mask = mask;
60
61 return 0;
62}
63
Ralf Baechled3fa72e2006-12-06 20:38:56 -080064extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 enum dma_data_direction direction);
66
David Daney48e1fd52010-10-01 13:27:32 -070067void *dma_alloc_noncoherent(struct device *dev, size_t size,
68 dma_addr_t *dma_handle, gfp_t flag);
69
70void dma_free_noncoherent(struct device *dev, size_t size,
71 void *vaddr, dma_addr_t dma_handle);
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#endif /* _ASM_DMA_MAPPING_H */