android: ion: add vmap/vunmap ops to dma-buf
authorCho KyongHo <pullip.cho@samsung.com>
Fri, 2 Feb 2018 13:47:34 +0000 (22:47 +0900)
committerSangwook Ju <sw.ju@samsung.com>
Mon, 14 May 2018 10:45:22 +0000 (19:45 +0900)
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 <pullip.cho@samsung.com>
drivers/staging/android/ion/ion.c

index 83dc3292e9ab1dd2fef1e85d898448cba7444c11..3c3c5ffcbad80c5e093cbb3245a7c2168420efee 100644 (file)
@@ -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)