diff options
author | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-06-14 07:03:04 -0400 |
---|---|---|
committer | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-07-30 06:25:46 -0400 |
commit | 64ccc9c033c6089b2d426dad3c56477ab066c999 (patch) | |
tree | ffaec86ca326dfc83b78ce4005bf46c3ad98ceb9 /include/asm-generic | |
parent | 9fa8af91f0679f2abbebe1382b937264f3a8b981 (diff) |
common: dma-mapping: add support for generic dma_mmap_* calls
Commit 9adc5374 ('common: dma-mapping: introduce mmap method') added a
generic method for implementing mmap user call to dma_map_ops structure.
This patch converts ARM and PowerPC architectures (the only providers of
dma_mmap_coherent/dma_mmap_writecombine calls) to use this generic
dma_map_ops based call and adds a generic cross architecture
definition for dma_mmap_attrs, dma_mmap_coherent, dma_mmap_writecombine
functions.
The generic mmap virt_to_page-based fallback implementation is provided for
architectures which don't provide their own implementation for mmap method.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
Diffstat (limited to 'include/asm-generic')
-rw-r--r-- | include/asm-generic/dma-coherent.h | 1 | ||||
-rw-r--r-- | include/asm-generic/dma-mapping-common.h | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/include/asm-generic/dma-coherent.h b/include/asm-generic/dma-coherent.h index abfb2682de7f..2be8a2dbc868 100644 --- a/include/asm-generic/dma-coherent.h +++ b/include/asm-generic/dma-coherent.h | |||
@@ -29,6 +29,7 @@ dma_mark_declared_memory_occupied(struct device *dev, | |||
29 | #else | 29 | #else |
30 | #define dma_alloc_from_coherent(dev, size, handle, ret) (0) | 30 | #define dma_alloc_from_coherent(dev, size, handle, ret) (0) |
31 | #define dma_release_from_coherent(dev, order, vaddr) (0) | 31 | #define dma_release_from_coherent(dev, order, vaddr) (0) |
32 | #define dma_mmap_from_coherent(dev, vma, vaddr, order, ret) (0) | ||
32 | #endif | 33 | #endif |
33 | 34 | ||
34 | #endif | 35 | #endif |
diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h index 2e248d8924dc..9073aeb3bb1a 100644 --- a/include/asm-generic/dma-mapping-common.h +++ b/include/asm-generic/dma-mapping-common.h | |||
@@ -176,4 +176,41 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, | |||
176 | #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL) | 176 | #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL) |
177 | #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL) | 177 | #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL) |
178 | 178 | ||
179 | extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, | ||
180 | void *cpu_addr, dma_addr_t dma_addr, size_t size); | ||
181 | |||
182 | /** | ||
183 | * dma_mmap_attrs - map a coherent DMA allocation into user space | ||
184 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices | ||
185 | * @vma: vm_area_struct describing requested user mapping | ||
186 | * @cpu_addr: kernel CPU-view address returned from dma_alloc_attrs | ||
187 | * @handle: device-view address returned from dma_alloc_attrs | ||
188 | * @size: size of memory originally requested in dma_alloc_attrs | ||
189 | * @attrs: attributes of mapping properties requested in dma_alloc_attrs | ||
190 | * | ||
191 | * Map a coherent DMA buffer previously allocated by dma_alloc_attrs | ||
192 | * into user space. The coherent DMA buffer must not be freed by the | ||
193 | * driver until the user space mapping has been released. | ||
194 | */ | ||
195 | static inline int | ||
196 | dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, | ||
197 | dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs) | ||
198 | { | ||
199 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
200 | BUG_ON(!ops); | ||
201 | if (ops->mmap) | ||
202 | return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs); | ||
203 | return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size); | ||
204 | } | ||
205 | |||
206 | #define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL) | ||
207 | |||
208 | static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma, | ||
209 | void *cpu_addr, dma_addr_t dma_addr, size_t size) | ||
210 | { | ||
211 | DEFINE_DMA_ATTRS(attrs); | ||
212 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); | ||
213 | return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs); | ||
214 | } | ||
215 | |||
179 | #endif | 216 | #endif |