From: Cho KyongHo Date: Fri, 2 Feb 2018 13:47:34 +0000 (+0900) Subject: android: ion: add vmap/vunmap ops to dma-buf X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b1aa7deaa8c0d44a13a33965dcfcc366fee8b78b;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 --- 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)