staging/ion: Add support to get ion handle from dma buf
authorRohit kumar <rohit.kr@samsung.com>
Tue, 22 Dec 2015 04:14:51 +0000 (09:44 +0530)
committerJoonyoung Shim <jy0922.shim@samsung.com>
Wed, 13 Jan 2016 01:29:24 +0000 (10:29 +0900)
Currently we can only import dma buf fd's to get ion_handle.
Adding support to import dma buf handles to support kernel
use cases.

Change-Id: I85b6027b6b142e3f91bce51b717e408530d5523c
Signed-off-by: Rohit kumar <rohit.kr@samsung.com>
drivers/staging/android/ion/ion.c
include/linux/ion.h

index c8b4e4d..54337be 100644 (file)
@@ -1302,24 +1302,16 @@ int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *get_ion_handle_from_dmabuf(struct ion_client *client, struct dma_buf *dmabuf)
 {
-       struct dma_buf *dmabuf;
        struct ion_buffer *buffer;
        struct ion_handle *handle;
        int ret;
 
-       dmabuf = dma_buf_get(fd);
-       if (IS_ERR(dmabuf)) {
-               pr_err("ion_import_dma_buf() dmabuf=0x%lx, fd:%d, dma_buf_get error!\n",
-                       (unsigned long)dmabuf, fd);
-               return ERR_PTR(PTR_ERR(dmabuf));
-       }
        /* if this memory came from ion */
-
        if (dmabuf->ops != &dma_buf_ops) {
                pr_err("%s: can not import dmabuf from another exporter\n",
-                      __func__);
+                               __func__);
                dma_buf_put(dmabuf);
                return ERR_PTR(-EINVAL);
        }
@@ -1351,6 +1343,20 @@ end:
        dma_buf_put(dmabuf);
        return handle;
 }
+EXPORT_SYMBOL(get_ion_handle_from_dmabuf);
+
+struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+{
+       struct dma_buf *dmabuf;
+
+       dmabuf = dma_buf_get(fd);
+       if (IS_ERR(dmabuf)) {
+               pr_err("ion_import_dma_buf() dmabuf=0x%lx, fd:%d, dma_buf_get error!\n",
+                               (unsigned long)dmabuf, fd);
+               return ERR_PTR(PTR_ERR(dmabuf));
+       }
+       return get_ion_handle_from_dmabuf(client, dmabuf);
+}
 EXPORT_SYMBOL(ion_import_dma_buf);
 
 static int ion_invalidate_for_cpu(struct ion_client *client, int fd)
index 7081a34..0d622aa 100644 (file)
@@ -212,13 +212,23 @@ struct dma_buf *ion_share_dma_buf(struct ion_client *client,
 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
 
 /**
+ * get_ion_handle_from_dmabuf() - given an dma-buf from the ion exporter get handle
+ * @client:    the client
+ * @dma_buf:   the dma-buf
+ *
+ * Given an dma-buf that was allocated through ion via ion_share_dma_buf,
+ * import that dma-buf and return a handle representing it.  If a dma-buf from
+ * another exporter is passed in this function will return ERR_PTR(-EINVAL)
+ */
+struct ion_handle *get_ion_handle_from_dmabuf(struct ion_client *client, struct dma_buf *dma_buf);
+
+/**
  * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
  * @client:    the client
  * @fd:                the dma-buf fd
  *
- * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
- * import that fd and return a handle representing it.  If a dma-buf from
- * another exporter is passed in this function will return ERR_PTR(-EINVAL)
+ * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
+ * import that fd and return a handle representing it.
  */
 struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);