Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 1 | /* |
Uwe Zeisberger | f30c226 | 2006-10-03 23:01:26 +0200 | [diff] [blame] | 2 | * include/asm-xtensa/dma-mapping.h |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
| 8 | * Copyright (C) 2003 - 2005 Tensilica Inc. |
| 9 | */ |
| 10 | |
| 11 | #ifndef _XTENSA_DMA_MAPPING_H |
| 12 | #define _XTENSA_DMA_MAPPING_H |
| 13 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 14 | #include <asm/cache.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <linux/mm.h> |
Jens Axboe | 8c7837c | 2007-10-24 13:28:40 +0200 | [diff] [blame] | 17 | #include <linux/scatterlist.h> |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 18 | |
Max Filippov | 35b16a9 | 2012-11-01 18:38:27 +0400 | [diff] [blame] | 19 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) |
| 20 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 21 | /* |
| 22 | * DMA-consistent mapping functions. |
| 23 | */ |
| 24 | |
| 25 | extern void *consistent_alloc(int, size_t, dma_addr_t, unsigned long); |
| 26 | extern void consistent_free(void*, size_t, dma_addr_t); |
| 27 | extern void consistent_sync(void*, size_t, int); |
| 28 | |
| 29 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 30 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
| 31 | |
| 32 | void *dma_alloc_coherent(struct device *dev, size_t size, |
Al Viro | 5fb5cbe | 2005-10-21 03:21:48 -0400 | [diff] [blame] | 33 | dma_addr_t *dma_handle, gfp_t flag); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 34 | |
| 35 | void dma_free_coherent(struct device *dev, size_t size, |
| 36 | void *vaddr, dma_addr_t dma_handle); |
| 37 | |
| 38 | static inline dma_addr_t |
| 39 | dma_map_single(struct device *dev, void *ptr, size_t size, |
| 40 | enum dma_data_direction direction) |
| 41 | { |
| 42 | BUG_ON(direction == DMA_NONE); |
| 43 | consistent_sync(ptr, size, direction); |
| 44 | return virt_to_phys(ptr); |
| 45 | } |
| 46 | |
| 47 | static inline void |
| 48 | dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, |
| 49 | enum dma_data_direction direction) |
| 50 | { |
| 51 | BUG_ON(direction == DMA_NONE); |
| 52 | } |
| 53 | |
| 54 | static inline int |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 55 | dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents, |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 56 | enum dma_data_direction direction) |
| 57 | { |
| 58 | int i; |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 59 | struct scatterlist *sg; |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 60 | |
| 61 | BUG_ON(direction == DMA_NONE); |
| 62 | |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 63 | for_each_sg(sglist, sg, nents, i) { |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 64 | BUG_ON(!sg_page(sg)); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 65 | |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 66 | sg->dma_address = sg_phys(sg); |
| 67 | consistent_sync(sg_virt(sg), sg->length, direction); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | return nents; |
| 71 | } |
| 72 | |
| 73 | static inline dma_addr_t |
| 74 | dma_map_page(struct device *dev, struct page *page, unsigned long offset, |
| 75 | size_t size, enum dma_data_direction direction) |
| 76 | { |
| 77 | BUG_ON(direction == DMA_NONE); |
| 78 | return (dma_addr_t)(page_to_pfn(page)) * PAGE_SIZE + offset; |
| 79 | } |
| 80 | |
| 81 | static inline void |
| 82 | dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, |
| 83 | enum dma_data_direction direction) |
| 84 | { |
| 85 | BUG_ON(direction == DMA_NONE); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static inline void |
| 90 | dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries, |
| 91 | enum dma_data_direction direction) |
| 92 | { |
| 93 | BUG_ON(direction == DMA_NONE); |
| 94 | } |
| 95 | |
| 96 | static inline void |
| 97 | dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, |
| 98 | enum dma_data_direction direction) |
| 99 | { |
| 100 | consistent_sync((void *)bus_to_virt(dma_handle), size, direction); |
| 101 | } |
| 102 | |
| 103 | static inline void |
Chris Zankel | c4c4594 | 2012-11-28 16:53:51 -0800 | [diff] [blame] | 104 | dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, |
| 105 | size_t size, enum dma_data_direction direction) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 106 | { |
| 107 | consistent_sync((void *)bus_to_virt(dma_handle), size, direction); |
| 108 | } |
| 109 | |
| 110 | static inline void |
| 111 | dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle, |
| 112 | unsigned long offset, size_t size, |
| 113 | enum dma_data_direction direction) |
| 114 | { |
| 115 | |
| 116 | consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction); |
| 117 | } |
| 118 | |
| 119 | static inline void |
| 120 | dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle, |
| 121 | unsigned long offset, size_t size, |
| 122 | enum dma_data_direction direction) |
| 123 | { |
| 124 | |
| 125 | consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction); |
| 126 | } |
| 127 | static inline void |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 128 | dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist, int nelems, |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 129 | enum dma_data_direction dir) |
| 130 | { |
| 131 | int i; |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 132 | struct scatterlist *sg; |
| 133 | |
| 134 | for_each_sg(sglist, sg, nelems, i) |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 135 | consistent_sync(sg_virt(sg), sg->length, dir); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static inline void |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 139 | dma_sync_sg_for_device(struct device *dev, struct scatterlist *sglist, |
| 140 | int nelems, enum dma_data_direction dir) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 141 | { |
| 142 | int i; |
Akinobu Mita | 3693a84 | 2015-06-24 16:55:51 -0700 | [diff] [blame] | 143 | struct scatterlist *sg; |
| 144 | |
| 145 | for_each_sg(sglist, sg, nelems, i) |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 146 | consistent_sync(sg_virt(sg), sg->length, dir); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 147 | } |
| 148 | static inline int |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 149 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 150 | { |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static inline int |
| 155 | dma_supported(struct device *dev, u64 mask) |
| 156 | { |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | static inline int |
| 161 | dma_set_mask(struct device *dev, u64 mask) |
| 162 | { |
| 163 | if(!dev->dma_mask || !dma_supported(dev, mask)) |
| 164 | return -EIO; |
| 165 | |
| 166 | *dev->dma_mask = mask; |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 171 | static inline void |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 172 | dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 173 | enum dma_data_direction direction) |
| 174 | { |
| 175 | consistent_sync(vaddr, size, direction); |
| 176 | } |
| 177 | |
Geert Uytterhoeven | da57b93 | 2013-01-27 09:33:28 +0000 | [diff] [blame] | 178 | /* Not supported for now */ |
| 179 | static inline int dma_mmap_coherent(struct device *dev, |
| 180 | struct vm_area_struct *vma, void *cpu_addr, |
| 181 | dma_addr_t dma_addr, size_t size) |
| 182 | { |
| 183 | return -EINVAL; |
| 184 | } |
| 185 | |
| 186 | static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt, |
| 187 | void *cpu_addr, dma_addr_t dma_addr, |
| 188 | size_t size) |
| 189 | { |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
Guenter Roeck | e74993a | 2015-05-04 15:30:47 -0700 | [diff] [blame] | 193 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, |
| 194 | dma_addr_t *dma_handle, gfp_t flag, |
| 195 | struct dma_attrs *attrs) |
| 196 | { |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | static inline void dma_free_attrs(struct device *dev, size_t size, |
| 201 | void *vaddr, dma_addr_t dma_handle, |
| 202 | struct dma_attrs *attrs) |
| 203 | { |
| 204 | } |
| 205 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 206 | #endif /* _XTENSA_DMA_MAPPING_H */ |