From 8086d8dbbe4b8e39f99bccb458e863ab9219fe28 Mon Sep 17 00:00:00 2001 From: Jianqun Xu Date: Wed, 16 Dec 2020 19:54:01 +0800 Subject: [PATCH] android: ion: add vmap/vunmap operations Change-Id: I90e2bcdd4526409194917609deb791e7badaf4f4 Signed-off-by: Jianqun Xu --- drivers/staging/android/ion/ion.c | 46 +++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 886ce52b2d42..77ebb7e2f3a4 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -328,16 +328,56 @@ static void ion_dma_buf_release(struct dma_buf *dmabuf) _ion_buffer_destroy(buffer); } -static void *ion_dma_buf_kmap(struct dma_buf *dmabuf, unsigned long offset) +static void *ion_dma_buf_vmap(struct dma_buf *dmabuf) +{ + struct ion_buffer *buffer = dmabuf->priv; + void *vaddr = ERR_PTR(-EINVAL); + + if (buffer->heap->ops->map_kernel) { + mutex_lock(&buffer->lock); + vaddr = ion_buffer_kmap_get(buffer); + mutex_unlock(&buffer->lock); + } else { + pr_warn_ratelimited("heap %s doesn't support map_kernel\n", + buffer->heap->name); + } + + return vaddr; +} + +static void ion_dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) { struct ion_buffer *buffer = dmabuf->priv; - return buffer->vaddr + offset * PAGE_SIZE; + if (buffer->heap->ops->map_kernel) { + mutex_lock(&buffer->lock); + ion_buffer_kmap_put(buffer); + mutex_unlock(&buffer->lock); + } +} + +static void *ion_dma_buf_kmap(struct dma_buf *dmabuf, unsigned long offset) +{ + /* + * TODO: Once clients remove their hacks where they assume kmap(ed) + * addresses are virtually contiguous implement this properly + */ + void *vaddr = ion_dma_buf_vmap(dmabuf); + + if (IS_ERR(vaddr)) + return vaddr; + + return vaddr + offset * PAGE_SIZE; } static void ion_dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long offset, void *ptr) { + /* + * TODO: Once clients remove their hacks where they assume kmap(ed) + * addresses are virtually contiguous implement this properly + */ + ion_dma_buf_vunmap(dmabuf, ptr); } static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, @@ -409,6 +449,8 @@ static const struct dma_buf_ops dma_buf_ops = { .end_cpu_access = ion_dma_buf_end_cpu_access, .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)