[RAMEN9610-12171] ion: support dma_buf_[un]map_attachment_area
authorhyesoo.yu <hyesoo.yu@samsung.com>
Fri, 31 Aug 2018 01:18:41 +0000 (10:18 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:23:16 +0000 (20:23 +0300)
ion support to synchronize the buffer with as much
as the payload.

Change-Id: Ib7fb028d5372d528ae448215ff73704c84befa67
Signed-off-by: hyesoo.yu <hyesoo.yu@samsung.com>
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion_exynos.c
drivers/staging/android/ion/ion_exynos.h

index 3316a3431e57ac4ce4a974bbe6820422de5ca89b..47f07a0b0f971a63179524d91f1fabd0fcbc8b94 100644 (file)
@@ -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
index a56855cc4794196e9d5de09a22b313b80a4d9519..700ad51ff37f402e83664e801e251d3a0c5168a2 100644 (file)
@@ -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)
 {
index 05872136fa00929422c2b0b72021cae7b2bab40f..c226eed5681615f99a7fecd6235c20276b53c55a 100644 (file)
@@ -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,