From 95229618741fd983196783a615567f66bee1707f Mon Sep 17 00:00:00 2001 From: Cho KyongHo Date: Fri, 23 Mar 2018 17:33:16 +0900 Subject: [PATCH] android: ion: add buffer id Now buffer has its unique id within 0 and 2048. It will be used to identify a specific ION buffer exported to dma-buf. Change-Id: I69bc91207bef14a4711cb9c1b02b3c20caf5cd91 Signed-off-by: Cho KyongHo --- drivers/staging/android/ion/ion.h | 1 + drivers/staging/android/ion/ion_debug.c | 8 ++++---- drivers/staging/android/ion/ion_exynos.c | 26 +++++++++++++++++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 00f8902a0092..cd34c9cecc6c 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -83,6 +83,7 @@ struct ion_buffer { void *priv_virt; struct mutex lock; int kmap_cnt; + int id; void *vaddr; struct sg_table *sg_table; struct list_head iovas; diff --git a/drivers/staging/android/ion/ion_debug.c b/drivers/staging/android/ion/ion_debug.c index 484cb3bf8361..832c9c462a64 100644 --- a/drivers/staging/android/ion/ion_debug.c +++ b/drivers/staging/android/ion/ion_debug.c @@ -29,8 +29,8 @@ static size_t ion_print_buffer(struct ion_buffer *buffer, bool alive, struct ion_iovm_map *iovm; int count; - count = scnprintf(logbuf, buflen, "%15s %#5lx %8zu : ", - buffer->heap->name, buffer->flags, + count = scnprintf(logbuf, buflen, "[%4d] %15s %#5lx %8zu : ", + buffer->id, buffer->heap->name, buffer->flags, buffer->size / SZ_1K); buflen = max(0, buflen - count); /* @@ -65,7 +65,7 @@ static int ion_debug_buffers_show(struct seq_file *s, void *unused) char logbuf[ION_MAX_LOGBUF]; size_t total = 0; - seq_printf(s, "%15s %5s %8s : %s\n", + seq_printf(s, "[ id] %15s %5s %8s : %s\n", "heap", "flags", "size(kb)", "iommu_mapped..."); mutex_lock(&idev->buffer_lock); @@ -136,7 +136,7 @@ static int ion_oom_notifier_fn(struct notifier_block *nb, char logbuf[ION_MAX_LOGBUF]; size_t total = 0; - pr_info("%15s %5s %8s : %s\n", + pr_info("[ id] %15s %5s %8s : %s\n", "heap", "flags", "size(kb)", "iommu_mapped..."); mutex_lock(&idev->buffer_lock); diff --git a/drivers/staging/android/ion/ion_exynos.c b/drivers/staging/android/ion/ion_exynos.c index fa760e52411a..bd58dd202ea5 100644 --- a/drivers/staging/android/ion/ion_exynos.c +++ b/drivers/staging/android/ion/ion_exynos.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "ion.h" #include "ion_exynos.h" @@ -166,6 +167,10 @@ void ion_iovmm_unmap(struct dma_buf_attachment *attachment, dma_addr_t iova) &iova, dev_name(attachment->dev)); } +#define MAX_BUFFER_IDS 2048 +static DEFINE_IDA(ion_buffer_ida); +static int last_buffer_id; + /* * exynos_ion_fixup - do something to ion_device for the Exynos extensions */ @@ -189,7 +194,22 @@ void exynos_ion_fixup(struct ion_device *idev) int exynos_ion_alloc_fixup(struct ion_device *idev, struct ion_buffer *buffer) { struct sg_table *table = buffer->sg_table; - int nents; + int nents, id; + + id = ida_simple_get(&ion_buffer_ida, last_buffer_id, + MAX_BUFFER_IDS, GFP_KERNEL); + if (id < 0) + id = ida_simple_get(&ion_buffer_ida, 0, MAX_BUFFER_IDS, + GFP_KERNEL); + + if (id < 0) { + id = MAX_BUFFER_IDS; + last_buffer_id = 0; + } else { + last_buffer_id = id; + } + + buffer->id = id; /* assign dma_addresses to scatter-gather list */ nents = dma_map_sg_attrs(idev->dev.this_device, table->sgl, @@ -198,6 +218,8 @@ int exynos_ion_alloc_fixup(struct ion_device *idev, struct ion_buffer *buffer) if (nents < table->orig_nents) { pr_err("%s: failed dma_map_sg(nents %d)=nents %d\n", __func__, table->orig_nents, nents); + if (id < MAX_BUFFER_IDS) + ida_simple_remove(&ion_buffer_ida, id); return -ENOMEM; } @@ -219,6 +241,8 @@ void exynos_ion_free_fixup(struct ion_buffer *buffer) kfree(iovm_map); } + if (buffer->id < MAX_BUFFER_IDS) + ida_simple_remove(&ion_buffer_ida, buffer->id); } struct sg_table *ion_exynos_map_dma_buf(struct dma_buf_attachment *attachment, -- 2.20.1