From 4a3fe820ac44b17d6b8adddc5464bf2b7445fb0b Mon Sep 17 00:00:00 2001 From: "hyesoo.yu" Date: Fri, 31 Aug 2018 10:18:41 +0900 Subject: [PATCH] [RAMEN9610-12171] ion: support dma_buf_[un]map_attachment_area ion support to synchronize the buffer with as much as the payload. Change-Id: Ib7fb028d5372d528ae448215ff73704c84befa67 Signed-off-by: hyesoo.yu --- drivers/staging/android/ion/ion.c | 2 + drivers/staging/android/ion/ion_exynos.c | 63 ++++++++++++++++++++++++ drivers/staging/android/ion/ion_exynos.h | 8 +++ 3 files changed, 73 insertions(+) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 3316a3431e57..47f07a0b0f97 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -434,6 +434,8 @@ const struct dma_buf_ops ion_dma_buf_ops = { #ifdef CONFIG_ION_EXYNOS .map_dma_buf = ion_exynos_map_dma_buf, .unmap_dma_buf = ion_exynos_unmap_dma_buf, + .map_dma_buf_area = ion_exynos_map_dma_buf_area, + .unmap_dma_buf_area = ion_exynos_unmap_dma_buf_area, .begin_cpu_access = ion_exynos_dma_buf_begin_cpu_access, .end_cpu_access = ion_exynos_dma_buf_end_cpu_access, #else diff --git a/drivers/staging/android/ion/ion_exynos.c b/drivers/staging/android/ion/ion_exynos.c index a56855cc4794..700ad51ff37f 100644 --- a/drivers/staging/android/ion/ion_exynos.c +++ b/drivers/staging/android/ion/ion_exynos.c @@ -249,6 +249,69 @@ void exynos_ion_free_fixup(struct ion_buffer *buffer) ida_simple_remove(&ion_buffer_ida, buffer->id); } +struct sg_table *ion_exynos_map_dma_buf_area( + struct dma_buf_attachment *attachment, + enum dma_data_direction direction, size_t size) +{ + struct ion_buffer *buffer = attachment->dmabuf->priv; + + if (ion_buffer_cached(buffer) && direction != DMA_NONE) { + struct scatterlist *sg; + int i; + + ion_event_begin(); + + for_each_sg(buffer->sg_table->sgl, sg, + buffer->sg_table->nents, i) { + size_t sg_len = min_t(size_t, size, sg->length); + + dma_sync_single_for_device(attachment->dev, + sg->dma_address, + sg_len, direction); + + size -= sg_len; + + if (!size) + break; + } + + ion_event_end(ION_EVENT_TYPE_MAP_DMA_BUF, buffer); + } + + return buffer->sg_table; +} + +void ion_exynos_unmap_dma_buf_area(struct dma_buf_attachment *attachment, + struct sg_table *table, + enum dma_data_direction direction, + size_t size) +{ + struct ion_buffer *buffer = attachment->dmabuf->priv; + + if (ion_buffer_cached(buffer) && direction != DMA_NONE) { + struct scatterlist *sg; + int i; + + ion_event_begin(); + + for_each_sg(buffer->sg_table->sgl, sg, + buffer->sg_table->nents, i) { + size_t sg_len = min_t(size_t, size, sg->length); + + dma_sync_single_for_cpu(attachment->dev, + sg->dma_address, + sg_len, direction); + + size -= sg_len; + + if (!size) + break; + } + + ion_event_end(ION_EVENT_TYPE_UNMAP_DMA_BUF, buffer); + } +} + struct sg_table *ion_exynos_map_dma_buf(struct dma_buf_attachment *attachment, enum dma_data_direction direction) { diff --git a/drivers/staging/android/ion/ion_exynos.h b/drivers/staging/android/ion/ion_exynos.h index 05872136fa00..c226eed56816 100644 --- a/drivers/staging/android/ion/ion_exynos.h +++ b/drivers/staging/android/ion/ion_exynos.h @@ -97,6 +97,14 @@ void ion_buffer_unprotect(void *priv); void exynos_ion_fixup(struct ion_device *idev); int exynos_ion_alloc_fixup(struct ion_device *idev, struct ion_buffer *buffer); void exynos_ion_free_fixup(struct ion_buffer *buffer); +struct sg_table *ion_exynos_map_dma_buf_area( + struct dma_buf_attachment *attachment, + enum dma_data_direction direction, + size_t size); +void ion_exynos_unmap_dma_buf_area(struct dma_buf_attachment *attachment, + struct sg_table *table, + enum dma_data_direction direction, + size_t size); struct sg_table *ion_exynos_map_dma_buf(struct dma_buf_attachment *attachment, enum dma_data_direction direction); void ion_exynos_unmap_dma_buf(struct dma_buf_attachment *attachment, -- 2.20.1