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 |
| 55 | dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, |
| 56 | enum dma_data_direction direction) |
| 57 | { |
| 58 | int i; |
| 59 | |
| 60 | BUG_ON(direction == DMA_NONE); |
| 61 | |
| 62 | for (i = 0; i < nents; i++, sg++ ) { |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 63 | BUG_ON(!sg_page(sg)); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 64 | |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 65 | sg->dma_address = sg_phys(sg); |
| 66 | consistent_sync(sg_virt(sg), sg->length, direction); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | return nents; |
| 70 | } |
| 71 | |
| 72 | static inline dma_addr_t |
| 73 | dma_map_page(struct device *dev, struct page *page, unsigned long offset, |
| 74 | size_t size, enum dma_data_direction direction) |
| 75 | { |
| 76 | BUG_ON(direction == DMA_NONE); |
| 77 | return (dma_addr_t)(page_to_pfn(page)) * PAGE_SIZE + offset; |
| 78 | } |
| 79 | |
| 80 | static inline void |
| 81 | dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, |
| 82 | enum dma_data_direction direction) |
| 83 | { |
| 84 | BUG_ON(direction == DMA_NONE); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | static inline void |
| 89 | dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries, |
| 90 | enum dma_data_direction direction) |
| 91 | { |
| 92 | BUG_ON(direction == DMA_NONE); |
| 93 | } |
| 94 | |
| 95 | static inline void |
| 96 | dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, |
| 97 | enum dma_data_direction direction) |
| 98 | { |
| 99 | consistent_sync((void *)bus_to_virt(dma_handle), size, direction); |
| 100 | } |
| 101 | |
| 102 | static inline void |
Chris Zankel | c4c4594 | 2012-11-28 16:53:51 -0800 | [diff] [blame] | 103 | dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, |
| 104 | size_t size, enum dma_data_direction direction) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 105 | { |
| 106 | consistent_sync((void *)bus_to_virt(dma_handle), size, direction); |
| 107 | } |
| 108 | |
| 109 | static inline void |
| 110 | dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle, |
| 111 | unsigned long offset, size_t size, |
| 112 | enum dma_data_direction direction) |
| 113 | { |
| 114 | |
| 115 | consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction); |
| 116 | } |
| 117 | |
| 118 | static inline void |
| 119 | dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle, |
| 120 | unsigned long offset, size_t size, |
| 121 | enum dma_data_direction direction) |
| 122 | { |
| 123 | |
| 124 | consistent_sync((void *)bus_to_virt(dma_handle)+offset,size,direction); |
| 125 | } |
| 126 | static inline void |
| 127 | dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems, |
| 128 | enum dma_data_direction dir) |
| 129 | { |
| 130 | int i; |
| 131 | for (i = 0; i < nelems; i++, sg++) |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 132 | consistent_sync(sg_virt(sg), sg->length, dir); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static inline void |
| 136 | dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, |
| 137 | enum dma_data_direction dir) |
| 138 | { |
| 139 | int i; |
| 140 | for (i = 0; i < nelems; i++, sg++) |
Emil Medve | 891039a | 2007-10-23 20:38:41 +0200 | [diff] [blame] | 141 | consistent_sync(sg_virt(sg), sg->length, dir); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 142 | } |
| 143 | static inline int |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 144 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 145 | { |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static inline int |
| 150 | dma_supported(struct device *dev, u64 mask) |
| 151 | { |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | static inline int |
| 156 | dma_set_mask(struct device *dev, u64 mask) |
| 157 | { |
| 158 | if(!dev->dma_mask || !dma_supported(dev, mask)) |
| 159 | return -EIO; |
| 160 | |
| 161 | *dev->dma_mask = mask; |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 166 | static inline void |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 167 | dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 168 | enum dma_data_direction direction) |
| 169 | { |
| 170 | consistent_sync(vaddr, size, direction); |
| 171 | } |
| 172 | |
Geert Uytterhoeven | da57b93 | 2013-01-27 09:33:28 +0000 | [diff] [blame] | 173 | /* Not supported for now */ |
| 174 | static inline int dma_mmap_coherent(struct device *dev, |
| 175 | struct vm_area_struct *vma, void *cpu_addr, |
| 176 | dma_addr_t dma_addr, size_t size) |
| 177 | { |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt, |
| 182 | void *cpu_addr, dma_addr_t dma_addr, |
| 183 | size_t size) |
| 184 | { |
| 185 | return -EINVAL; |
| 186 | } |
| 187 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 188 | #endif /* _XTENSA_DMA_MAPPING_H */ |