From b1aa7deaa8c0d44a13a33965dcfcc366fee8b78b Mon Sep 17 00:00:00 2001 From: Cho KyongHo Date: Fri, 2 Feb 2018 22:47:34 +0900 Subject: [PATCH] android: ion: add vmap/vunmap ops to dma-buf Kernel drivers that allocate buffers from ION sometimes requires kernel address of the buffers. The drivers tend to access the whole buffer instead of accessing several pages from the large buffers in megabytes. Therefore dma_buf_vmap() is proper for the drivers than dma_buf_kmap(). Change-Id: Ie5edf4c325a34c8ed419291b4490b917b755b551 Signed-off-by: Cho KyongHo --- drivers/staging/android/ion/ion.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 83dc3292e9ab..3c3c5ffcbad8 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -329,6 +329,30 @@ static void ion_dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long offset, { } +static void *ion_dma_buf_vmap(struct dma_buf *dmabuf) +{ + struct ion_buffer *buffer = dmabuf->priv; + + if (buffer->heap->ops->map_kernel) { + mutex_lock(&buffer->lock); + ion_buffer_kmap_get(buffer); + mutex_unlock(&buffer->lock); + } + + return buffer->vaddr; +} + +static void ion_dma_buf_vunmap(struct dma_buf *dmabuf, void *ptr) +{ + struct ion_buffer *buffer = dmabuf->priv; + + if (buffer->heap->ops->map_kernel) { + mutex_lock(&buffer->lock); + ion_buffer_kmap_put(buffer); + mutex_unlock(&buffer->lock); + } +} + static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, enum dma_data_direction direction) { @@ -390,6 +414,8 @@ static const struct dma_buf_ops dma_buf_ops = { .unmap_atomic = ion_dma_buf_kunmap, .map = ion_dma_buf_kmap, .unmap = ion_dma_buf_kunmap, + .vmap = ion_dma_buf_vmap, + .vunmap = ion_dma_buf_vunmap, }; int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) -- 2.20.1