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