Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004-2009 Analog Devices Inc. |
| 3 | * |
| 4 | * Licensed under the GPL-2 or later. |
| 5 | */ |
| 6 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 7 | #ifndef _BLACKFIN_DMA_MAPPING_H |
| 8 | #define _BLACKFIN_DMA_MAPPING_H |
| 9 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 10 | #include <asm/cacheflush.h> |
| 11 | struct scatterlist; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 12 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 13 | void *dma_alloc_coherent(struct device *dev, size_t size, |
| 14 | dma_addr_t *dma_handle, gfp_t gfp); |
| 15 | void dma_free_coherent(struct device *dev, size_t size, void *vaddr, |
| 16 | dma_addr_t dma_handle); |
| 17 | |
| 18 | /* |
| 19 | * Now for the API extensions over the pci_ one |
| 20 | */ |
| 21 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 22 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 23 | #define dma_supported(d, m) (1) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 24 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 25 | static inline int |
| 26 | dma_set_mask(struct device *dev, u64 dma_mask) |
| 27 | { |
| 28 | if (!dev->dma_mask || !dma_supported(dev, dma_mask)) |
| 29 | return -EIO; |
| 30 | |
| 31 | *dev->dma_mask = dma_mask; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static inline int |
| 37 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
Mike Frysinger | 62273ee | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 38 | { |
| 39 | return 0; |
| 40 | } |
Sonic Zhang | 334280f | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 41 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 42 | extern void |
| 43 | __dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir); |
| 44 | static inline void |
Sonic Zhang | a3a6a59 | 2009-12-16 07:52:52 +0000 | [diff] [blame] | 45 | __dma_sync_inline(dma_addr_t addr, size_t size, enum dma_data_direction dir) |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 46 | { |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 47 | switch (dir) { |
| 48 | case DMA_NONE: |
| 49 | BUG(); |
| 50 | case DMA_TO_DEVICE: /* writeback only */ |
| 51 | flush_dcache_range(addr, addr + size); |
| 52 | break; |
| 53 | case DMA_FROM_DEVICE: /* invalidate only */ |
| 54 | case DMA_BIDIRECTIONAL: /* flush and invalidate */ |
| 55 | /* Blackfin has no dedicated invalidate (it includes a flush) */ |
| 56 | invalidate_dcache_range(addr, addr + size); |
| 57 | break; |
| 58 | } |
| 59 | } |
Sonic Zhang | a3a6a59 | 2009-12-16 07:52:52 +0000 | [diff] [blame] | 60 | static inline void |
| 61 | _dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir) |
| 62 | { |
| 63 | if (__builtin_constant_p(dir)) |
| 64 | __dma_sync_inline(addr, size, dir); |
| 65 | else |
| 66 | __dma_sync(addr, size, dir); |
| 67 | } |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 68 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 69 | static inline dma_addr_t |
| 70 | dma_map_single(struct device *dev, void *ptr, size_t size, |
| 71 | enum dma_data_direction dir) |
| 72 | { |
| 73 | _dma_sync((dma_addr_t)ptr, size, dir); |
| 74 | return (dma_addr_t) ptr; |
| 75 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 76 | |
Bryan Wu | 9fcdc78 | 2008-04-23 07:41:52 +0800 | [diff] [blame] | 77 | static inline dma_addr_t |
| 78 | dma_map_page(struct device *dev, struct page *page, |
| 79 | unsigned long offset, size_t size, |
| 80 | enum dma_data_direction dir) |
| 81 | { |
| 82 | return dma_map_single(dev, page_address(page) + offset, size, dir); |
| 83 | } |
| 84 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 85 | static inline void |
| 86 | dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, |
| 87 | enum dma_data_direction dir) |
| 88 | { |
| 89 | BUG_ON(!valid_dma_direction(dir)); |
| 90 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 91 | |
Bryan Wu | 9fcdc78 | 2008-04-23 07:41:52 +0800 | [diff] [blame] | 92 | static inline void |
| 93 | dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, |
| 94 | enum dma_data_direction dir) |
| 95 | { |
| 96 | dma_unmap_single(dev, dma_addr, size, dir); |
| 97 | } |
| 98 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 99 | extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 100 | enum dma_data_direction dir); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 101 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 102 | static inline void |
| 103 | dma_unmap_sg(struct device *dev, struct scatterlist *sg, |
| 104 | int nhwentries, enum dma_data_direction dir) |
Bryan Wu | 31f3d4a | 2008-09-22 20:23:55 +0800 | [diff] [blame] | 105 | { |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 106 | BUG_ON(!valid_dma_direction(dir)); |
Bryan Wu | 31f3d4a | 2008-09-22 20:23:55 +0800 | [diff] [blame] | 107 | } |
| 108 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 109 | static inline void |
| 110 | dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t handle, |
| 111 | unsigned long offset, size_t size, |
| 112 | enum dma_data_direction dir) |
Bryan Wu | 31f3d4a | 2008-09-22 20:23:55 +0800 | [diff] [blame] | 113 | { |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 114 | BUG_ON(!valid_dma_direction(dir)); |
Bryan Wu | 31f3d4a | 2008-09-22 20:23:55 +0800 | [diff] [blame] | 115 | } |
FUJITA Tomonori | 42b86e0 | 2009-06-22 21:48:37 -0400 | [diff] [blame] | 116 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 117 | static inline void |
| 118 | dma_sync_single_range_for_device(struct device *dev, dma_addr_t handle, |
| 119 | unsigned long offset, size_t size, |
| 120 | enum dma_data_direction dir) |
FUJITA Tomonori | 42b86e0 | 2009-06-22 21:48:37 -0400 | [diff] [blame] | 121 | { |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 122 | _dma_sync(handle + offset, size, dir); |
FUJITA Tomonori | 42b86e0 | 2009-06-22 21:48:37 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 125 | static inline void |
| 126 | dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size, |
| 127 | enum dma_data_direction dir) |
FUJITA Tomonori | 42b86e0 | 2009-06-22 21:48:37 -0400 | [diff] [blame] | 128 | { |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 129 | dma_sync_single_range_for_cpu(dev, handle, 0, size, dir); |
| 130 | } |
| 131 | |
| 132 | static inline void |
| 133 | dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, |
| 134 | enum dma_data_direction dir) |
| 135 | { |
| 136 | dma_sync_single_range_for_device(dev, handle, 0, size, dir); |
| 137 | } |
| 138 | |
| 139 | static inline void |
| 140 | dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents, |
| 141 | enum dma_data_direction dir) |
| 142 | { |
| 143 | BUG_ON(!valid_dma_direction(dir)); |
| 144 | } |
| 145 | |
| 146 | extern void |
| 147 | dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, |
| 148 | int nents, enum dma_data_direction dir); |
| 149 | |
| 150 | static inline void |
| 151 | dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
| 152 | enum dma_data_direction dir) |
| 153 | { |
| 154 | _dma_sync((dma_addr_t)vaddr, size, dir); |
FUJITA Tomonori | 42b86e0 | 2009-06-22 21:48:37 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 157 | #endif /* _BLACKFIN_DMA_MAPPING_H */ |