rk: ion: support shared buffer between processes without Binder
authorCMY <cmy@rock-chips.com>
Tue, 25 Feb 2014 07:31:10 +0000 (15:31 +0800)
committerCMY <cmy@rock-chips.com>
Tue, 25 Feb 2014 07:32:13 +0000 (15:32 +0800)
drivers/staging/android/ion/rockchip/rockchip_ion.c
include/linux/rockchip_ion.h

index 553134b83a9c5d85353f6d972e38c2d653977326..c3b6148ab178e1067595ef0854cd14916a4b3638 100755 (executable)
@@ -20,6 +20,7 @@
 #include <linux/rockchip_ion.h>
 #include <linux/uaccess.h>
 #include "../ion_priv.h"
+#include <linux/dma-buf.h>
 
 #ifdef CONFIG_OF
 #include <linux/of.h>
@@ -194,6 +195,47 @@ static long rockchip_custom_ioctl (struct ion_client *client, unsigned int cmd,
                        return -EFAULT;
                break;
        }
+       case ION_IOC_GET_SHARE:
+       {
+               struct ion_share_obj_data data;
+               struct dma_buf *dmabuf = NULL;
+
+               if (copy_from_user(&data, (void __user *)arg,
+                                       sizeof(struct ion_share_obj_data)))
+                       return -EFAULT;
+
+               dmabuf = dma_buf_get(data.fd);
+               if (IS_ERR(dmabuf))
+                       return PTR_ERR(dmabuf);
+
+               data.obj = (void*)dmabuf;
+               dma_buf_put(dmabuf);
+
+               if (copy_to_user((void __user *)arg, &data, sizeof(struct ion_share_obj_data)))
+                       return -EFAULT;
+
+               break;
+       }
+       case ION_IOC_SET_SHARE:
+       {
+               struct ion_share_obj_data data;
+               int fd = 0;
+
+               if (copy_from_user(&data, (void __user *)arg,
+                                       sizeof(struct ion_share_obj_data)))
+                       return -EFAULT;
+
+               fd = dma_buf_fd((struct dma_buf*)data.obj, O_CLOEXEC);
+               if (fd < 0)
+                       return fd;
+
+               data.fd = fd;
+
+               if (copy_to_user((void __user *)arg, &data, sizeof(struct ion_share_obj_data)))
+                       return -EFAULT;
+
+               break;
+       }
        default:
                return -ENOTTY;
        }
index e9341a5a65d27e5d5c41d78e22c83d9eb4566dd7..4e78235cba31adaa69211ef0788f350920a02ea5 100644 (file)
@@ -70,6 +70,11 @@ struct ion_phys_data {
        unsigned long size;
 };
 
+struct ion_share_obj_data {
+       int fd;
+       void *obj;
+};
+
 #define ION_IOC_ROCKCHIP_MAGIC 'R'
 
 /**
@@ -94,4 +99,16 @@ struct ion_phys_data {
 #define ION_IOC_GET_PHYS       _IOWR(ION_IOC_ROCKCHIP_MAGIC, 3, \
                                                struct ion_phys_data)
 
+/**
+ * Get share object of the fd specified.
+ */
+#define ION_IOC_GET_SHARE      _IOWR(ION_IOC_ROCKCHIP_MAGIC, 4, \
+                                               struct ion_share_obj_data)
+
+/**
+ * Set share object and associate new fd.
+ */
+#define ION_IOC_SET_SHARE      _IOWR(ION_IOC_ROCKCHIP_MAGIC, 5, \
+                                               struct ion_share_obj_data)
+
 #endif