From 940557cb336a0bd110b2c11c9dc6ef3daad1654c Mon Sep 17 00:00:00 2001 From: Tao Huang Date: Sat, 24 Sep 2022 09:16:42 +0800 Subject: [PATCH] Revert "dma-buf: system_heap: do force sync only if attachment list empty" This reverts commit 33b98bf612bd33ed58516a0ed2ac01ff9ef2fc9c. Use rk_system_heap.c instead of system_heap.c now, reverts all changes. Signed-off-by: Tao Huang Change-Id: Id265fd16b1531708478f07187f50fe23e74e427e --- drivers/dma-buf/heaps/system_heap.c | 47 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index aabda43a534c..2e46028f498f 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -26,6 +26,8 @@ #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; @@ -239,7 +241,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_phys(sg); + sg_dma_addr = sg_dma_address(sg); len += sg->length; if (len <= offset) @@ -280,6 +282,18 @@ 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); @@ -295,16 +309,7 @@ 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); @@ -322,6 +327,18 @@ 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); @@ -337,16 +354,6 @@ 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);