dma-buf: rk_heaps: rk-cma-heap add partital sync

Add partital sync for begain/end of cpu access.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
Change-Id: I5ba7dbe5aa99bfc64d6d9140826dba01964fc4d7
This commit is contained in:
Jianqun Xu
2022-03-09 10:35:46 +08:00
committed by Tao Huang
parent 925acfb272
commit c0669ce10d

View File

@@ -114,8 +114,11 @@ static void rk_cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
dma_unmap_sgtable(attachment->dev, table, direction, attrs);
}
static int rk_cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
enum dma_data_direction direction)
static int
rk_cma_heap_dma_buf_begin_cpu_access_partial(struct dma_buf *dmabuf,
enum dma_data_direction direction,
unsigned int offset,
unsigned int len)
{
struct rk_cma_heap_buffer *buffer = dmabuf->priv;
struct rk_dma_heap_attachment *a;
@@ -133,16 +136,19 @@ static int rk_cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
/* For userspace that not attach yet */
if (buffer->phys && !buffer->attached)
dma_sync_single_for_cpu(rk_dma_heap_get_dev(buffer->heap->heap),
buffer->phys,
buffer->pagecount * PAGE_SIZE,
buffer->phys + offset,
len,
direction);
mutex_unlock(&buffer->lock);
return 0;
}
static int rk_cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
enum dma_data_direction direction)
static int
rk_cma_heap_dma_buf_end_cpu_access_partial(struct dma_buf *dmabuf,
enum dma_data_direction direction,
unsigned int offset,
unsigned int len)
{
struct rk_cma_heap_buffer *buffer = dmabuf->priv;
struct rk_dma_heap_attachment *a;
@@ -160,14 +166,32 @@ static int rk_cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
/* For userspace that not attach yet */
if (buffer->phys && !buffer->attached)
dma_sync_single_for_device(rk_dma_heap_get_dev(buffer->heap->heap),
buffer->phys,
buffer->pagecount * PAGE_SIZE,
buffer->phys + offset,
len,
direction);
mutex_unlock(&buffer->lock);
return 0;
}
static int rk_cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
enum dma_data_direction dir)
{
struct rk_cma_heap_buffer *buffer = dmabuf->priv;
unsigned int len = buffer->pagecount * PAGE_SIZE;
return rk_cma_heap_dma_buf_begin_cpu_access_partial(dmabuf, dir, 0, len);
}
static int rk_cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
enum dma_data_direction dir)
{
struct rk_cma_heap_buffer *buffer = dmabuf->priv;
unsigned int len = buffer->pagecount * PAGE_SIZE;
return rk_cma_heap_dma_buf_end_cpu_access_partial(dmabuf, dir, 0, len);
}
static int rk_cma_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
{
struct rk_cma_heap_buffer *buffer = dmabuf->priv;
@@ -379,6 +403,8 @@ static const struct dma_buf_ops rk_cma_heap_buf_ops = {
.unmap_dma_buf = rk_cma_heap_unmap_dma_buf,
.begin_cpu_access = rk_cma_heap_dma_buf_begin_cpu_access,
.end_cpu_access = rk_cma_heap_dma_buf_end_cpu_access,
.begin_cpu_access_partial = rk_cma_heap_dma_buf_begin_cpu_access_partial,
.end_cpu_access_partial = rk_cma_heap_dma_buf_end_cpu_access_partial,
.mmap = rk_cma_heap_mmap,
.vmap = rk_cma_heap_vmap,
.vunmap = rk_cma_heap_vunmap,