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