dma-buf: add fcntl system call support
authorInki Dae <inki.dae@samsung.com>
Thu, 20 Nov 2014 13:30:18 +0000 (22:30 +0900)
committerChanho Park <chanho61.park@samsung.com>
Fri, 21 Nov 2014 10:13:44 +0000 (19:13 +0900)
This patch adds lock callback to dmabuf framework. And this callback
will be called by fcntl request.

With this patch, fcntl system call can be used by userspace application
for they can use dmabuf sync mechanism.

Change-Id: Id3631cbc21e84c986e2efe040881e401ade180e8
Signed-off-by: Inki Dae <inki.dae@samsung.com>
drivers/dma-buf/dma-buf.c

index 376bc6b..8bd6a2d 100644 (file)
@@ -33,6 +33,8 @@
 #include <linux/poll.h>
 #include <linux/reservation.h>
 
+#include <linux/dmabuf-sync.h>
+
 static inline int is_dma_buf_file(struct file *);
 
 struct dma_buf_list {
@@ -249,11 +251,38 @@ out:
        return events;
 }
 
+static int dma_buf_lock(struct file *file, int cmd, struct file_lock *fl)
+{
+       struct dma_buf *dmabuf;
+       unsigned int type;
+
+       if (!is_dma_buf_file(file) || !(fl->fl_flags & FL_SLEEP))
+               return -EPERM;
+
+       dmabuf = file->private_data;
+
+       if ((fl->fl_type & F_UNLCK) == F_UNLCK) {
+               dmabuf_sync_signal(dmabuf);
+               return 0;
+       }
+
+       /* convert flock type to dmabuf sync type. */
+       if ((fl->fl_type & F_WRLCK) == F_WRLCK)
+               type = DMA_BUF_ACCESS_W;
+       else if ((fl->fl_type & F_RDLCK) == F_RDLCK)
+               type = DMA_BUF_ACCESS_R;
+       else
+               return -EINVAL;
+
+       return dmabuf_sync_wait(dmabuf, (unsigned int)current, type);
+}
+
 static const struct file_operations dma_buf_fops = {
        .release        = dma_buf_release,
        .mmap           = dma_buf_mmap_internal,
        .llseek         = dma_buf_llseek,
        .poll           = dma_buf_poll,
+       .lock           = dma_buf_lock,
 };
 
 /*