aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/dma-mapping.c
diff options
context:
space:
mode:
authorMarek Szyprowski <m.szyprowski@samsung.com>2012-06-13 04:05:52 -0400
committerMarek Szyprowski <m.szyprowski@samsung.com>2012-07-30 06:25:46 -0400
commitd2b7428eb0caa7c66e34b6ac869a43915b294123 (patch)
treead30d28a2078d1d9429c8f19815378c5da2c54f5 /drivers/base/dma-mapping.c
parent955c757e090f41188764a0e488ba7036f7dbb215 (diff)
common: dma-mapping: introduce dma_get_sgtable() function
This patch adds dma_get_sgtable() function which is required to let drivers to share the buffers allocated by DMA-mapping subsystem. Right now the driver gets a dma address of the allocated buffer and the kernel virtual mapping for it. If it wants to share it with other device (= map into its dma address space) it usually hacks around kernel virtual addresses to get pointers to pages or assumes that both devices share the DMA address space. Both solutions are just hacks for the special cases, which should be avoided in the final version of buffer sharing. To solve this issue in a generic way, a new call to DMA mapping has been introduced - dma_get_sgtable(). It allocates a scatter-list which describes the allocated buffer and lets the driver(s) to use it with other device(s) by calling dma_map_sg() on it. This patch provides a generic implementation based on virt_to_page() call. Architectures which require more sophisticated translation might provide their own get_sgtable() methods. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/base/dma-mapping.c')
-rw-r--r--drivers/base/dma-mapping.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
index db5db02e885f..3fbedc75e7c5 100644
--- a/drivers/base/dma-mapping.c
+++ b/drivers/base/dma-mapping.c
@@ -218,6 +218,24 @@ void dmam_release_declared_memory(struct device *dev)
218} 218}
219EXPORT_SYMBOL(dmam_release_declared_memory); 219EXPORT_SYMBOL(dmam_release_declared_memory);
220 220
221/*
222 * Create scatter-list for the already allocated DMA buffer.
223 */
224int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
225 void *cpu_addr, dma_addr_t handle, size_t size)
226{
227 struct page *page = virt_to_page(cpu_addr);
228 int ret;
229
230 ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
231 if (unlikely(ret))
232 return ret;
233
234 sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0);
235 return 0;
236}
237EXPORT_SYMBOL(dma_common_get_sgtable);
238
221#endif 239#endif
222 240
223/* 241/*