gpu: ion: omap: add apis to register and export ion buffers from a pvr fd
authorSundar Raman <a0393242@ti.com>
Fri, 5 Apr 2013 20:08:53 +0000 (15:08 -0500)
committerPraneeth Bajjuri <praneeth@ti.com>
Fri, 12 Jul 2013 22:19:47 +0000 (17:19 -0500)
Exporting omap_ion_register_pvr_export through ion. This is needed since
PVR is built as a module as the abstraction uses an exported function
pointer.

omap_ion_share_fd_to_buffers api is added which retrieves the ion handles
from the pvr fd and calls ion_share on the ion handles to return the
shared buffers. The requestor can then call ion_import using its own ion
client to get its own ion handles.

Note that this functionality is intended to be reworked majorly as part of
gralloc's migration to dma buf functionality in new ION framework.

Change-Id: I89fd1aedadd26c3c6561f784cfd3316afd4fe389
Signed-off-by: Sundar Raman <a0393242@ti.com>
drivers/gpu/ion/omap/omap_ion.c
include/linux/omap_ion.h

index d76f70ddb5ee1553cf2146a9824a26f994baa806..4578484225e33071f5f5469cf1d8c69456b3b96e 100644 (file)
@@ -152,6 +152,52 @@ static int omap_ion_remove(struct platform_device *pdev)
        return 0;
 }
 
+static void (*export_fd_to_ion_handles)(int fd,
+               struct ion_client **client,
+               struct ion_handle **handles,
+               int *num_handles);
+
+void omap_ion_register_pvr_export(void *pvr_export_fd)
+{
+       export_fd_to_ion_handles = pvr_export_fd;
+}
+EXPORT_SYMBOL(omap_ion_register_pvr_export);
+
+int omap_ion_share_fd_to_buffers(int fd, struct ion_buffer **buffers,
+               int *num_handles)
+{
+       struct ion_handle **handles;
+       struct ion_client *client;
+       int i = 0, ret = 0;
+
+       handles = kzalloc(*num_handles * sizeof(struct ion_handle *),
+                         GFP_KERNEL);
+       if (!handles)
+               return -ENOMEM;
+
+       if (export_fd_to_ion_handles) {
+               export_fd_to_ion_handles(fd,
+                               &client,
+                               handles,
+                               num_handles);
+       } else {
+               pr_err("%s: export_fd_to_ion_handles not initialized",
+                               __func__);
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       for (i = 0; i < *num_handles; i++) {
+               if (handles[i])
+                       buffers[i] = ion_share_dma_buf(client, handles[i]);
+       }
+
+exit:
+       kfree(handles);
+       return ret;
+}
+EXPORT_SYMBOL(omap_ion_share_fd_to_buffers);
+
 static struct platform_driver ion_driver = {
        .probe = omap_ion_probe,
        .remove = omap_ion_remove,
index 2ec6e7fb8b716aaf3b3e84d860676c1bc95e37f2..2a51a05520d9e39214b6f1725d3b2e7a8543f64b 100644 (file)
@@ -58,6 +58,9 @@ int omap_tiler_vinfo(struct ion_client *client,
                        struct ion_handle *handle, unsigned int *vstride,
                        unsigned int *vsize);
 
+int omap_ion_share_fd_to_buffers(int fd, struct ion_buffer **buffers,
+                                       int *num_handles);
+
 extern struct ion_device *omap_ion_device;
 #endif /* __KERNEL__ */