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);