Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_DMA_MAPPING_H |
| 2 | #define _ASM_DMA_MAPPING_H |
| 3 | |
| 4 | #include <asm/scatterlist.h> |
Steven J. Hill | b6d92b4 | 2013-03-25 13:47:29 -0500 | [diff] [blame] | 5 | #include <asm/dma-coherence.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/cache.h> |
Yoichi Yuasa | f8ac0425 | 2009-06-04 00:16:04 +0900 | [diff] [blame] | 7 | #include <asm-generic/dma-coherent.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 9 | #ifndef CONFIG_SGI_IP27 /* Kludge to fix 2.6.39 build for IP27 */ |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 10 | #include <dma-coherence.h> |
Ralf Baechle | a5602a3 | 2011-05-18 13:14:36 +0100 | [diff] [blame] | 11 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 13 | extern struct dma_map_ops *mips_dma_map_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 15 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) |
Atsushi Nemoto | 4f29c05 | 2009-01-23 00:42:11 +0900 | [diff] [blame] | 16 | { |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 17 | if (dev && dev->archdata.dma_ops) |
| 18 | return dev->archdata.dma_ops; |
| 19 | else |
| 20 | return mips_dma_map_ops; |
Atsushi Nemoto | 4f29c05 | 2009-01-23 00:42:11 +0900 | [diff] [blame] | 21 | } |
| 22 | |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 23 | static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) |
| 24 | { |
| 25 | if (!dev->dma_mask) |
Joe Perches | 3db2742 | 2015-03-30 16:46:03 -0700 | [diff] [blame] | 26 | return false; |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 27 | |
| 28 | return addr + size <= *dev->dma_mask; |
| 29 | } |
| 30 | |
| 31 | static inline void dma_mark_clean(void *addr, size_t size) {} |
| 32 | |
| 33 | #include <asm-generic/dma-mapping-common.h> |
| 34 | |
| 35 | static inline int dma_supported(struct device *dev, u64 mask) |
| 36 | { |
| 37 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 38 | return ops->dma_supported(dev, mask); |
| 39 | } |
| 40 | |
| 41 | static inline int dma_mapping_error(struct device *dev, u64 mask) |
| 42 | { |
| 43 | struct dma_map_ops *ops = get_dma_ops(dev); |
Shuah Khan | 9c83b07c | 2012-11-23 14:34:56 -0700 | [diff] [blame] | 44 | |
| 45 | debug_dma_mapping_error(dev, mask); |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 46 | return ops->mapping_error(dev, mask); |
| 47 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | static inline int |
| 50 | dma_set_mask(struct device *dev, u64 mask) |
| 51 | { |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 52 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if(!dev->dma_mask || !dma_supported(dev, mask)) |
| 55 | return -EIO; |
| 56 | |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 57 | if (ops->set_dma_mask) |
| 58 | return ops->set_dma_mask(dev, mask); |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | *dev->dma_mask = mask; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 65 | extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | enum dma_data_direction direction); |
| 67 | |
Andrzej Pietrasiewicz | e8d51e5 | 2012-03-27 14:32:21 +0200 | [diff] [blame] | 68 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) |
| 69 | |
| 70 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, |
| 71 | dma_addr_t *dma_handle, gfp_t gfp, |
| 72 | struct dma_attrs *attrs) |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 73 | { |
| 74 | void *ret; |
| 75 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 76 | |
Andrzej Pietrasiewicz | e8d51e5 | 2012-03-27 14:32:21 +0200 | [diff] [blame] | 77 | ret = ops->alloc(dev, size, dma_handle, gfp, attrs); |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 78 | |
| 79 | debug_dma_alloc_coherent(dev, size, *dma_handle, ret); |
| 80 | |
| 81 | return ret; |
| 82 | } |
| 83 | |
Andrzej Pietrasiewicz | e8d51e5 | 2012-03-27 14:32:21 +0200 | [diff] [blame] | 84 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) |
| 85 | |
| 86 | static inline void dma_free_attrs(struct device *dev, size_t size, |
| 87 | void *vaddr, dma_addr_t dma_handle, |
| 88 | struct dma_attrs *attrs) |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 89 | { |
| 90 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 91 | |
Andrzej Pietrasiewicz | e8d51e5 | 2012-03-27 14:32:21 +0200 | [diff] [blame] | 92 | ops->free(dev, size, vaddr, dma_handle, attrs); |
David Daney | 48e1fd5 | 2010-10-01 13:27:32 -0700 | [diff] [blame] | 93 | |
| 94 | debug_dma_free_coherent(dev, size, vaddr, dma_handle); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | void *dma_alloc_noncoherent(struct device *dev, size_t size, |
| 99 | dma_addr_t *dma_handle, gfp_t flag); |
| 100 | |
| 101 | void dma_free_noncoherent(struct device *dev, size_t size, |
| 102 | void *vaddr, dma_addr_t dma_handle); |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #endif /* _ASM_DMA_MAPPING_H */ |