ion: add apis to get client property.
authorJin-young Jeon <jy0.jeon@samsung.com>
Mon, 19 Dec 2016 04:57:47 +0000 (13:57 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Tue, 14 Feb 2017 04:26:33 +0000 (13:26 +0900)
This patch adds APIs to get ion client property.

Signed-off-by: Jin-young Jeon <jy0.jeon@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion.h

index f9077d39f052e6da2764a30832eccf48c7d8611f..6eab5e0c797b0fde38466bf96f96a85b87e08d1d 100644 (file)
@@ -852,28 +852,6 @@ int ion_phys(struct ion_client *client, struct ion_handle *handle,
 }
 EXPORT_SYMBOL(ion_phys);
 
-#ifdef CONFIG_DRM_TBM_GEM_ION
-int ion_set_client_ops(struct ion_client *client,
-               struct ion_handle *handle, void *client_ops, void *client_obj)
-{
-       if (!client_ops || !client_obj)
-               return -EINVAL;
-
-       mutex_lock(&client->lock);
-       if (!ion_handle_validate(client, handle)) {
-               mutex_unlock(&client->lock);
-               return -EINVAL;
-       }
-
-       handle->buffer->private_ops = client_ops;
-       handle->buffer->private_obj = client_obj;
-       mutex_unlock(&client->lock);
-
-       return 0;
-}
-EXPORT_SYMBOL(ion_set_client_ops);
-#endif
-
 static void *ion_buffer_kmap_get(struct ion_buffer *buffer)
 {
        void *vaddr;
@@ -1495,6 +1473,138 @@ static struct dma_buf_ops dma_buf_ops = {
        .kunmap = ion_dma_buf_kunmap,
 };
 
+#ifdef CONFIG_DRM_TBM_GEM_ION
+int ion_set_client_ops(struct ion_client *client,
+               struct ion_handle *handle, void *client_ops, void *client_obj)
+{
+       if (!client_ops || !client_obj)
+               return -EINVAL;
+
+       mutex_lock(&client->lock);
+       if (!ion_handle_validate(client, handle)) {
+               mutex_unlock(&client->lock);
+               return -EINVAL;
+       }
+
+       handle->buffer->private_ops = client_ops;
+       handle->buffer->private_obj = client_obj;
+       pr_debug("%s:ih[%p]obj[%p]\n", __func__, handle,
+               handle->buffer->private_obj);
+       mutex_unlock(&client->lock);
+
+       return 0;
+}
+EXPORT_SYMBOL(ion_set_client_ops);
+
+void *ion_get_client_object(struct ion_client *client,
+               struct ion_handle *handle)
+{
+       mutex_lock(&client->lock);
+       if (!ion_handle_validate(client, handle))
+               goto out;
+
+       if (handle && handle->buffer) {
+               pr_debug("%s:ih[%p]obj[%p]\n", __func__, handle,
+                       handle->buffer->private_obj);
+               mutex_unlock(&client->lock);
+               return handle->buffer->private_obj;
+       }
+
+out:
+       pr_err("%s:failed to get object:handle[%p]\n", __func__, handle);
+       mutex_unlock(&client->lock);
+       return NULL;
+}
+EXPORT_SYMBOL(ion_get_client_object);
+
+struct ion_handle *get_ion_handle_from_dmabuf(struct ion_client *client,
+               struct dma_buf *dmabuf)
+{
+       struct ion_buffer *buffer;
+       struct ion_handle *handle;
+       int ret;
+
+       /* if this memory came from ion */
+       if (dmabuf->ops != &dma_buf_ops) {
+               pr_err("%s: can not import dmabuf from another exporter\n",
+                       __func__);
+               return ERR_PTR(-EINVAL);
+       }
+       buffer = dmabuf->priv;
+
+       mutex_lock(&client->lock);
+       /* if a handle exists for this buffer just take a reference to it */
+       handle = ion_handle_lookup(client, buffer);
+       if (!IS_ERR(handle)) {
+               ion_handle_get(handle);
+               mutex_unlock(&client->lock);
+               goto end;
+       }
+       mutex_unlock(&client->lock);
+
+       handle = ion_handle_create(client, buffer);
+       if (IS_ERR(handle))
+               goto end;
+
+       mutex_lock(&client->lock);
+       ret = ion_handle_add(client, handle);
+       mutex_unlock(&client->lock);
+       if (ret) {
+               ion_handle_put(client, handle);
+               handle = ERR_PTR(ret);
+       }
+
+end:
+       return handle;
+}
+EXPORT_SYMBOL(get_ion_handle_from_dmabuf);
+
+int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
+                       unsigned long *size, unsigned int *heap_id)
+{
+       struct ion_buffer *buffer;
+       struct ion_heap *heap;
+
+       mutex_lock(&client->lock);
+       if (!ion_handle_validate(client, handle)) {
+               pr_err("%s: invalid handle passed to %s.\n",
+                       __func__, __func__);
+               mutex_unlock(&client->lock);
+               return -EINVAL;
+       }
+       buffer = handle->buffer;
+       mutex_lock(&buffer->lock);
+       heap = buffer->heap;
+       *heap_id = (1 << heap->id);
+       *size = buffer->size;
+       mutex_unlock(&buffer->lock);
+       mutex_unlock(&client->lock);
+
+       return 0;
+}
+EXPORT_SYMBOL(ion_handle_get_size);
+
+int ion_is_cached(struct ion_client *client, struct ion_handle *handle)
+{
+       struct ion_buffer *buffer;
+       int cached;
+
+       mutex_lock(&client->lock);
+       if (!ion_handle_validate(client, handle)) {
+               mutex_unlock(&client->lock);
+               return -EINVAL;
+       }
+
+       buffer = handle->buffer;
+
+       cached = ion_buffer_cached(buffer);
+       mutex_unlock(&client->lock);
+
+       return cached;
+}
+EXPORT_SYMBOL(ion_is_cached);
+#endif
+
 struct dma_buf *ion_share_dma_buf(struct ion_client *client,
                                                struct ion_handle *handle)
 {
index c05ea1f1a8afc1aff0f031cbd5669ba388c2c775..c076982f8beb12e6db7a7f4a740fd34ebcf1b4a7 100644 (file)
@@ -20,6 +20,9 @@
 #include <linux/types.h>
 
 #include <uapi/linux/ion.h>
+#ifdef CONFIG_DRM_TBM_GEM_ION
+#include <linux/dma-buf.h>
+#endif
 
 struct ion_handle;
 struct ion_device;
@@ -149,6 +152,17 @@ int ion_phys(struct ion_client *client, struct ion_handle *handle,
 #ifdef CONFIG_DRM_TBM_GEM_ION
 int ion_set_client_ops(struct ion_client *client,
                struct ion_handle *handle, void *client_ops, void *client_obj);
+
+void *ion_get_client_object(struct ion_client *client,
+               struct ion_handle *handle);
+
+struct ion_handle *get_ion_handle_from_dmabuf(struct ion_client *client,
+               struct dma_buf *dmabuf);
+
+int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
+               unsigned long *size, unsigned int *heap_id);
+
+int ion_is_cached(struct ion_client *client, struct ion_handle *handle);
 #endif
 /**
  * ion_map_dma - return an sg_table describing a handle