Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_DMA_MAPPING_H |
| 2 | #define __ASM_SH_DMA_MAPPING_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/mm.h> |
| 5 | #include <asm/scatterlist.h> |
| 6 | #include <asm/io.h> |
| 7 | |
| 8 | struct pci_dev; |
| 9 | extern void *consistent_alloc(struct pci_dev *hwdev, size_t size, |
| 10 | dma_addr_t *dma_handle); |
| 11 | extern void consistent_free(struct pci_dev *hwdev, size_t size, |
| 12 | void *vaddr, dma_addr_t dma_handle); |
| 13 | |
| 14 | #define dma_supported(dev, mask) (1) |
| 15 | |
| 16 | static inline int dma_set_mask(struct device *dev, u64 mask) |
| 17 | { |
| 18 | if (!dev->dma_mask || !dma_supported(dev, mask)) |
| 19 | return -EIO; |
| 20 | |
| 21 | *dev->dma_mask = mask; |
| 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | static inline void *dma_alloc_coherent(struct device *dev, size_t size, |
Al Viro | 970a9e7 | 2005-10-21 03:21:53 -0400 | [diff] [blame] | 27 | dma_addr_t *dma_handle, gfp_t flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | return consistent_alloc(NULL, size, dma_handle); |
| 30 | } |
| 31 | |
| 32 | static inline void dma_free_coherent(struct device *dev, size_t size, |
| 33 | void *vaddr, dma_addr_t dma_handle) |
| 34 | { |
| 35 | consistent_free(NULL, size, vaddr, dma_handle); |
| 36 | } |
| 37 | |
Paul Mundt | 599c26d | 2007-05-14 09:10:46 +0900 | [diff] [blame] | 38 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 39 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
| 40 | #define dma_is_consistent(d, h) (1) |
| 41 | |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 42 | static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | enum dma_data_direction dir) |
| 44 | { |
| 45 | dma_cache_wback_inv((unsigned long)vaddr, size); |
| 46 | } |
| 47 | |
| 48 | static inline dma_addr_t dma_map_single(struct device *dev, |
| 49 | void *ptr, size_t size, |
| 50 | enum dma_data_direction dir) |
| 51 | { |
| 52 | #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT) |
| 53 | if (dev->bus == &pci_bus_type) |
Paul Mundt | 75c4616 | 2007-07-31 13:11:25 +0900 | [diff] [blame] | 54 | return virt_to_phys(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #endif |
Paul Mundt | 599c26d | 2007-05-14 09:10:46 +0900 | [diff] [blame] | 56 | dma_cache_sync(dev, ptr, size, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Paul Mundt | 75c4616 | 2007-07-31 13:11:25 +0900 | [diff] [blame] | 58 | return virt_to_phys(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | #define dma_unmap_single(dev, addr, size, dir) do { } while (0) |
| 62 | |
| 63 | static inline int dma_map_sg(struct device *dev, struct scatterlist *sg, |
| 64 | int nents, enum dma_data_direction dir) |
| 65 | { |
| 66 | int i; |
| 67 | |
| 68 | for (i = 0; i < nents; i++) { |
| 69 | #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT) |
Paul Mundt | 599c26d | 2007-05-14 09:10:46 +0900 | [diff] [blame] | 70 | dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | sg[i].length, dir); |
| 72 | #endif |
| 73 | sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset; |
| 74 | } |
| 75 | |
| 76 | return nents; |
| 77 | } |
| 78 | |
| 79 | #define dma_unmap_sg(dev, sg, nents, dir) do { } while (0) |
| 80 | |
| 81 | static inline dma_addr_t dma_map_page(struct device *dev, struct page *page, |
| 82 | unsigned long offset, size_t size, |
| 83 | enum dma_data_direction dir) |
| 84 | { |
| 85 | return dma_map_single(dev, page_address(page) + offset, size, dir); |
| 86 | } |
| 87 | |
| 88 | static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address, |
| 89 | size_t size, enum dma_data_direction dir) |
| 90 | { |
| 91 | dma_unmap_single(dev, dma_address, size, dir); |
| 92 | } |
| 93 | |
| 94 | static inline void dma_sync_single(struct device *dev, dma_addr_t dma_handle, |
| 95 | size_t size, enum dma_data_direction dir) |
| 96 | { |
| 97 | #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT) |
| 98 | if (dev->bus == &pci_bus_type) |
| 99 | return; |
| 100 | #endif |
Paul Mundt | 75c4616 | 2007-07-31 13:11:25 +0900 | [diff] [blame] | 101 | dma_cache_sync(dev, phys_to_virt(dma_handle), size, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static inline void dma_sync_single_range(struct device *dev, |
| 105 | dma_addr_t dma_handle, |
| 106 | unsigned long offset, size_t size, |
| 107 | enum dma_data_direction dir) |
| 108 | { |
| 109 | #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT) |
| 110 | if (dev->bus == &pci_bus_type) |
| 111 | return; |
| 112 | #endif |
Paul Mundt | 75c4616 | 2007-07-31 13:11:25 +0900 | [diff] [blame] | 113 | dma_cache_sync(dev, phys_to_virt(dma_handle) + offset, size, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg, |
| 117 | int nelems, enum dma_data_direction dir) |
| 118 | { |
| 119 | int i; |
| 120 | |
| 121 | for (i = 0; i < nelems; i++) { |
| 122 | #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT) |
Paul Mundt | 599c26d | 2007-05-14 09:10:46 +0900 | [diff] [blame] | 123 | dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | sg[i].length, dir); |
| 125 | #endif |
| 126 | sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | static inline void dma_sync_single_for_cpu(struct device *dev, |
| 131 | dma_addr_t dma_handle, size_t size, |
| 132 | enum dma_data_direction dir) |
Paul Mundt | 2126413 | 2006-09-12 14:36:46 +0900 | [diff] [blame] | 133 | { |
| 134 | dma_sync_single(dev, dma_handle, size, dir); |
| 135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | static inline void dma_sync_single_for_device(struct device *dev, |
| 138 | dma_addr_t dma_handle, size_t size, |
| 139 | enum dma_data_direction dir) |
Paul Mundt | 2126413 | 2006-09-12 14:36:46 +0900 | [diff] [blame] | 140 | { |
| 141 | dma_sync_single(dev, dma_handle, size, dir); |
| 142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Paul Mundt | 757e2d6 | 2007-08-10 02:47:31 +0900 | [diff] [blame] | 144 | static inline void dma_sync_single_range_for_cpu(struct device *dev, |
| 145 | dma_addr_t dma_handle, |
| 146 | unsigned long offset, |
| 147 | size_t size, |
| 148 | enum dma_data_direction direction) |
| 149 | { |
| 150 | dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction); |
| 151 | } |
| 152 | |
| 153 | static inline void dma_sync_single_range_for_device(struct device *dev, |
| 154 | dma_addr_t dma_handle, |
| 155 | unsigned long offset, |
| 156 | size_t size, |
| 157 | enum dma_data_direction direction) |
| 158 | { |
| 159 | dma_sync_single_for_device(dev, dma_handle+offset, size, direction); |
| 160 | } |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | static inline void dma_sync_sg_for_cpu(struct device *dev, |
| 163 | struct scatterlist *sg, int nelems, |
| 164 | enum dma_data_direction dir) |
Paul Mundt | 2126413 | 2006-09-12 14:36:46 +0900 | [diff] [blame] | 165 | { |
| 166 | dma_sync_sg(dev, sg, nelems, dir); |
| 167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | static inline void dma_sync_sg_for_device(struct device *dev, |
| 170 | struct scatterlist *sg, int nelems, |
| 171 | enum dma_data_direction dir) |
Paul Mundt | 2126413 | 2006-09-12 14:36:46 +0900 | [diff] [blame] | 172 | { |
| 173 | dma_sync_sg(dev, sg, nelems, dir); |
| 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | static inline int dma_get_cache_alignment(void) |
| 177 | { |
| 178 | /* |
| 179 | * Each processor family will define its own L1_CACHE_SHIFT, |
| 180 | * L1_CACHE_BYTES wraps to this, so this is always safe. |
| 181 | */ |
| 182 | return L1_CACHE_BYTES; |
| 183 | } |
| 184 | |
| 185 | static inline int dma_mapping_error(dma_addr_t dma_addr) |
| 186 | { |
| 187 | return dma_addr == 0; |
| 188 | } |
| 189 | |
| 190 | #endif /* __ASM_SH_DMA_MAPPING_H */ |
| 191 | |