From 33b98bf612bd33ed58516a0ed2ac01ff9ef2fc9c Mon Sep 17 00:00:00 2001 From: Jianqun Xu Date: Thu, 12 May 2022 14:58:06 +0800 Subject: [PATCH] dma-buf: system_heap: do force sync only if attachment list empty When the dmabuf attachment list is empty, do force sync with the heap device, it is useful for partial access for cpu. Fixes: 21f2fd663ea7 ("dma-buf: system_heap: support cpu access partial dma-buf") Signed-off-by: Jianqun Xu Change-Id: Ie266767aeb03a361e1541ba9e84f3dd027350a75 --- drivers/dma-buf/heaps/system_heap.c | 47 ++++++++++++----------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index f639e7d49cfa..1130aa82969b 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -26,8 +26,6 @@ #include "page_pool.h" #include "deferred-free-helper.h" -#define CONFIG_SYSTEM_HEAP_FORCE_DMA_SYNC - static struct dma_heap *sys_heap; static struct dma_heap *sys_dma32_heap; static struct dma_heap *sys_uncached_heap; @@ -241,7 +239,7 @@ static int system_heap_sgl_sync_range(struct device *dev, for_each_sg(sgl, sg, nents, i) { unsigned int sg_offset, sg_left, size = 0; - sg_dma_addr = sg_dma_address(sg); + sg_dma_addr = sg_phys(sg); len += sg->length; if (len <= offset) @@ -282,18 +280,6 @@ system_heap_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, return 0; mutex_lock(&buffer->lock); - if (IS_ENABLED(CONFIG_SYSTEM_HEAP_FORCE_DMA_SYNC)) { - struct dma_heap *heap = buffer->heap; - struct sg_table *table = &buffer->sg_table; - - ret = system_heap_sgl_sync_range(dma_heap_get_dev(heap), - table->sgl, - table->nents, - offset, len, - direction, true); - goto unlock; - } - if (buffer->vmap_cnt) invalidate_kernel_vmap_range(buffer->vaddr, buffer->len); @@ -309,7 +295,16 @@ system_heap_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf, offset, len, direction, true); } + if (list_empty(&buffer->attachments)) { + struct dma_heap *heap = buffer->heap; + struct sg_table *table = &buffer->sg_table; + ret = system_heap_sgl_sync_range(dma_heap_get_dev(heap), + table->sgl, + table->nents, + offset, len, + direction, true); + } unlock: mutex_unlock(&buffer->lock); @@ -327,18 +322,6 @@ system_heap_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, int ret = 0; mutex_lock(&buffer->lock); - if (IS_ENABLED(CONFIG_SYSTEM_HEAP_FORCE_DMA_SYNC)) { - struct dma_heap *heap = buffer->heap; - struct sg_table *table = &buffer->sg_table; - - ret = system_heap_sgl_sync_range(dma_heap_get_dev(heap), - table->sgl, - table->nents, - offset, len, - direction, false); - goto unlock; - } - if (buffer->vmap_cnt) flush_kernel_vmap_range(buffer->vaddr, buffer->len); @@ -354,6 +337,16 @@ system_heap_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf, offset, len, direction, false); } + if (list_empty(&buffer->attachments)) { + struct dma_heap *heap = buffer->heap; + struct sg_table *table = &buffer->sg_table; + + ret = system_heap_sgl_sync_range(dma_heap_get_dev(heap), + table->sgl, + table->nents, + offset, len, + direction, false); + } unlock: mutex_unlock(&buffer->lock);