From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mailout3.samsung.com ([203.254.224.33]:62060 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756513Ab3HMJTo (ORCPT ); Tue, 13 Aug 2013 05:19:44 -0400 From: Inki Dae To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linaro-kernel@lists.linaro.org Cc: maarten.lankhorst@canonical.com, sumit.semwal@linaro.org, kyungmin.park@samsung.com, myungjoo.ham@samsung.com, Inki Dae Subject: [PATCH 2/2] [RFC PATCH v2] dma-buf: Add user interfaces for dmabuf sync support. Date: Tue, 13 Aug 2013 18:19:36 +0900 Message-id: <1376385576-9039-3-git-send-email-inki.dae@samsung.com> In-reply-to: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> References: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> Sender: linux-media-owner@vger.kernel.org List-ID: This patch adds lock and poll callbacks to dma buf file operations, and these callbacks will be called by fcntl and select system calls. fcntl and select system calls can be used to wait for the completion of DMA or CPU access to a shared dmabuf. The difference of them is fcntl system call takes a lock after the completion but select system call doesn't. So in case of fcntl system call, it's useful when a task wants to access a shared dmabuf without any broken. On the other hand, it's useful when a task wants to just wait for the completion. Changelog v2: - Add select system call support. . The purpose of this feature is to wait for the completion of DMA or CPU access to a dmabuf without that caller locks the dmabuf again after the completion. That is useful when caller wants to be aware of the completion of DMA access to the dmabuf, and the caller doesn't use intefaces for the DMA device driver. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/base/dma-buf.c | 81 +++++++++++++++++++++++++++++++++++++++++++ include/linux/dmabuf-sync.h | 1 + 2 files changed, 82 insertions(+), 0 deletions(-) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 4aca57a..f16a396 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -29,6 +29,7 @@ #include #include #include +#include #include static inline int is_dma_buf_file(struct file *); @@ -80,9 +81,89 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) return dmabuf->ops->mmap(dmabuf, vma); } +static unsigned int dma_buf_poll(struct file *filp, + struct poll_table_struct *poll) +{ + struct dma_buf *dmabuf; + struct dmabuf_sync_reservation *robj; + int ret = 0; + + if (!is_dma_buf_file(filp)) + return POLLERR; + + dmabuf = filp->private_data; + if (!dmabuf || !dmabuf->sync) + return POLLERR; + + robj = dmabuf->sync; + + mutex_lock(&robj->lock); + + robj->polled = true; + + /* + * CPU or DMA access to this buffer has been completed, and + * the blocked task has been waked up. Return poll event + * so that the task can get out of select(). + */ + if (robj->poll_event) { + robj->poll_event = false; + mutex_unlock(&robj->lock); + return POLLIN | POLLOUT; + } + + /* + * There is no anyone accessing this buffer so just return. + */ + if (!robj->locked) { + mutex_unlock(&robj->lock); + return POLLIN | POLLOUT; + } + + poll_wait(filp, &robj->poll_wait, poll); + + mutex_unlock(&robj->lock); + + return ret; +} + +static int dma_buf_lock(struct file *file, int cmd, struct file_lock *fl) +{ + struct dma_buf *dmabuf; + unsigned int type; + bool wait = false; + + if (!is_dma_buf_file(file)) + return -EINVAL; + + dmabuf = file->private_data; + + if ((fl->fl_type & F_UNLCK) == F_UNLCK) { + dmabuf_sync_single_unlock(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; + + if (fl->fl_flags & FL_SLEEP) + wait = true; + + /* TODO. the locking to certain region should also be considered. */ + + return dmabuf_sync_single_lock(dmabuf, type, wait); +} + static const struct file_operations dma_buf_fops = { .release = dma_buf_release, .mmap = dma_buf_mmap_internal, + .poll = dma_buf_poll, + .lock = dma_buf_lock, }; /* diff --git a/include/linux/dmabuf-sync.h b/include/linux/dmabuf-sync.h index 9a3afc4..0316f68 100644 --- a/include/linux/dmabuf-sync.h +++ b/include/linux/dmabuf-sync.h @@ -11,6 +11,7 @@ */ #include +#include #include #include -- 1.7.5.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Inki Dae Date: Tue, 13 Aug 2013 09:19:36 +0000 Subject: [PATCH 2/2] [RFC PATCH v2] dma-buf: Add user interfaces for dmabuf sync support. Message-Id: <1376385576-9039-3-git-send-email-inki.dae@samsung.com> List-Id: References: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> In-Reply-To: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linaro-kernel@lists.linaro.org Cc: maarten.lankhorst@canonical.com, sumit.semwal@linaro.org, kyungmin.park@samsung.com, myungjoo.ham@samsung.com, Inki Dae This patch adds lock and poll callbacks to dma buf file operations, and these callbacks will be called by fcntl and select system calls. fcntl and select system calls can be used to wait for the completion of DMA or CPU access to a shared dmabuf. The difference of them is fcntl system call takes a lock after the completion but select system call doesn't. So in case of fcntl system call, it's useful when a task wants to access a shared dmabuf without any broken. On the other hand, it's useful when a task wants to just wait for the completion. Changelog v2: - Add select system call support. . The purpose of this feature is to wait for the completion of DMA or CPU access to a dmabuf without that caller locks the dmabuf again after the completion. That is useful when caller wants to be aware of the completion of DMA access to the dmabuf, and the caller doesn't use intefaces for the DMA device driver. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/base/dma-buf.c | 81 +++++++++++++++++++++++++++++++++++++++++++ include/linux/dmabuf-sync.h | 1 + 2 files changed, 82 insertions(+), 0 deletions(-) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 4aca57a..f16a396 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -29,6 +29,7 @@ #include #include #include +#include #include static inline int is_dma_buf_file(struct file *); @@ -80,9 +81,89 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) return dmabuf->ops->mmap(dmabuf, vma); } +static unsigned int dma_buf_poll(struct file *filp, + struct poll_table_struct *poll) +{ + struct dma_buf *dmabuf; + struct dmabuf_sync_reservation *robj; + int ret = 0; + + if (!is_dma_buf_file(filp)) + return POLLERR; + + dmabuf = filp->private_data; + if (!dmabuf || !dmabuf->sync) + return POLLERR; + + robj = dmabuf->sync; + + mutex_lock(&robj->lock); + + robj->polled = true; + + /* + * CPU or DMA access to this buffer has been completed, and + * the blocked task has been waked up. Return poll event + * so that the task can get out of select(). + */ + if (robj->poll_event) { + robj->poll_event = false; + mutex_unlock(&robj->lock); + return POLLIN | POLLOUT; + } + + /* + * There is no anyone accessing this buffer so just return. + */ + if (!robj->locked) { + mutex_unlock(&robj->lock); + return POLLIN | POLLOUT; + } + + poll_wait(filp, &robj->poll_wait, poll); + + mutex_unlock(&robj->lock); + + return ret; +} + +static int dma_buf_lock(struct file *file, int cmd, struct file_lock *fl) +{ + struct dma_buf *dmabuf; + unsigned int type; + bool wait = false; + + if (!is_dma_buf_file(file)) + return -EINVAL; + + dmabuf = file->private_data; + + if ((fl->fl_type & F_UNLCK) = F_UNLCK) { + dmabuf_sync_single_unlock(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; + + if (fl->fl_flags & FL_SLEEP) + wait = true; + + /* TODO. the locking to certain region should also be considered. */ + + return dmabuf_sync_single_lock(dmabuf, type, wait); +} + static const struct file_operations dma_buf_fops = { .release = dma_buf_release, .mmap = dma_buf_mmap_internal, + .poll = dma_buf_poll, + .lock = dma_buf_lock, }; /* diff --git a/include/linux/dmabuf-sync.h b/include/linux/dmabuf-sync.h index 9a3afc4..0316f68 100644 --- a/include/linux/dmabuf-sync.h +++ b/include/linux/dmabuf-sync.h @@ -11,6 +11,7 @@ */ #include +#include #include #include -- 1.7.5.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: inki.dae@samsung.com (Inki Dae) Date: Tue, 13 Aug 2013 18:19:36 +0900 Subject: [PATCH 2/2] [RFC PATCH v2] dma-buf: Add user interfaces for dmabuf sync support. In-Reply-To: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> References: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> Message-ID: <1376385576-9039-3-git-send-email-inki.dae@samsung.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org This patch adds lock and poll callbacks to dma buf file operations, and these callbacks will be called by fcntl and select system calls. fcntl and select system calls can be used to wait for the completion of DMA or CPU access to a shared dmabuf. The difference of them is fcntl system call takes a lock after the completion but select system call doesn't. So in case of fcntl system call, it's useful when a task wants to access a shared dmabuf without any broken. On the other hand, it's useful when a task wants to just wait for the completion. Changelog v2: - Add select system call support. . The purpose of this feature is to wait for the completion of DMA or CPU access to a dmabuf without that caller locks the dmabuf again after the completion. That is useful when caller wants to be aware of the completion of DMA access to the dmabuf, and the caller doesn't use intefaces for the DMA device driver. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/base/dma-buf.c | 81 +++++++++++++++++++++++++++++++++++++++++++ include/linux/dmabuf-sync.h | 1 + 2 files changed, 82 insertions(+), 0 deletions(-) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 4aca57a..f16a396 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -29,6 +29,7 @@ #include #include #include +#include #include static inline int is_dma_buf_file(struct file *); @@ -80,9 +81,89 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) return dmabuf->ops->mmap(dmabuf, vma); } +static unsigned int dma_buf_poll(struct file *filp, + struct poll_table_struct *poll) +{ + struct dma_buf *dmabuf; + struct dmabuf_sync_reservation *robj; + int ret = 0; + + if (!is_dma_buf_file(filp)) + return POLLERR; + + dmabuf = filp->private_data; + if (!dmabuf || !dmabuf->sync) + return POLLERR; + + robj = dmabuf->sync; + + mutex_lock(&robj->lock); + + robj->polled = true; + + /* + * CPU or DMA access to this buffer has been completed, and + * the blocked task has been waked up. Return poll event + * so that the task can get out of select(). + */ + if (robj->poll_event) { + robj->poll_event = false; + mutex_unlock(&robj->lock); + return POLLIN | POLLOUT; + } + + /* + * There is no anyone accessing this buffer so just return. + */ + if (!robj->locked) { + mutex_unlock(&robj->lock); + return POLLIN | POLLOUT; + } + + poll_wait(filp, &robj->poll_wait, poll); + + mutex_unlock(&robj->lock); + + return ret; +} + +static int dma_buf_lock(struct file *file, int cmd, struct file_lock *fl) +{ + struct dma_buf *dmabuf; + unsigned int type; + bool wait = false; + + if (!is_dma_buf_file(file)) + return -EINVAL; + + dmabuf = file->private_data; + + if ((fl->fl_type & F_UNLCK) == F_UNLCK) { + dmabuf_sync_single_unlock(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; + + if (fl->fl_flags & FL_SLEEP) + wait = true; + + /* TODO. the locking to certain region should also be considered. */ + + return dmabuf_sync_single_lock(dmabuf, type, wait); +} + static const struct file_operations dma_buf_fops = { .release = dma_buf_release, .mmap = dma_buf_mmap_internal, + .poll = dma_buf_poll, + .lock = dma_buf_lock, }; /* diff --git a/include/linux/dmabuf-sync.h b/include/linux/dmabuf-sync.h index 9a3afc4..0316f68 100644 --- a/include/linux/dmabuf-sync.h +++ b/include/linux/dmabuf-sync.h @@ -11,6 +11,7 @@ */ #include +#include #include #include -- 1.7.5.4