From eb3761e409046af64d824f4587f45ebaadd8efc0 Mon Sep 17 00:00:00 2001 From: Randy Li Date: Thu, 12 Oct 2017 10:43:57 +0800 Subject: [PATCH] staging: ion: implement the vmap() and vunmap() Comparing to the latest the ion driver, the vmap() or vunmap() are not supported yet, but at least it would be more easy to implement the sync function. I didn't remove those legacy iommu code this time, I just add this patch to make the functions I want work. Change-Id: Id7731fd44b729338c0a0059a1517bfe1333391e8 Signed-off-by: Randy Li --- drivers/staging/android/ion/ion.c | 45 ++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 5083289504ab..8bd1396db2fe 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -1397,40 +1397,53 @@ static void ion_dma_buf_release(struct dma_buf *dmabuf) static void *ion_dma_buf_kmap(struct dma_buf *dmabuf, unsigned long offset) { struct ion_buffer *buffer = dmabuf->priv; + void *vaddr = NULL; - return buffer->vaddr + offset * PAGE_SIZE; + if (!buffer) + return ERR_PTR(-EINVAL); + + mutex_lock(&buffer->lock); + vaddr = ion_buffer_kmap_get(buffer); + mutex_unlock(&buffer->lock); + + return vaddr + offset * PAGE_SIZE; } static void ion_dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long offset, void *ptr) { + struct ion_buffer *buffer = dmabuf->priv; + + if (!buffer) + return; + + 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, size_t start, - size_t len, - enum dma_data_direction direction) +static void *ion_dma_buf_vmap(struct dma_buf *dmabuf) { struct ion_buffer *buffer = dmabuf->priv; - void *vaddr; + void *vaddr = NULL; - if (!buffer->heap->ops->map_kernel) { - pr_err("%s: map kernel is not implemented by this heap.\n", - __func__); - return -ENODEV; - } + if (!buffer) + return ERR_PTR(-EINVAL); mutex_lock(&buffer->lock); vaddr = ion_buffer_kmap_get(buffer); mutex_unlock(&buffer->lock); - return PTR_ERR_OR_ZERO(vaddr); + + return vaddr; } -static void ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, size_t start, - size_t len, - enum dma_data_direction direction) +static void ion_dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) { struct ion_buffer *buffer = dmabuf->priv; + if (!buffer) + return; + mutex_lock(&buffer->lock); ion_buffer_kmap_put(buffer); mutex_unlock(&buffer->lock); @@ -1441,12 +1454,12 @@ static struct dma_buf_ops dma_buf_ops = { .unmap_dma_buf = ion_unmap_dma_buf, .mmap = ion_mmap, .release = ion_dma_buf_release, - .begin_cpu_access = ion_dma_buf_begin_cpu_access, - .end_cpu_access = ion_dma_buf_end_cpu_access, .kmap_atomic = ion_dma_buf_kmap, .kunmap_atomic = ion_dma_buf_kunmap, .kmap = ion_dma_buf_kmap, .kunmap = ion_dma_buf_kunmap, + .vmap = ion_dma_buf_vmap, + .vunmap = ion_dma_buf_vunmap, }; struct dma_buf *ion_share_dma_buf(struct ion_client *client,