From patchwork Wed Aug 21 10:33:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 2847668 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 026A9BF547 for ; Wed, 21 Aug 2013 10:33:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A16F120576 for ; Wed, 21 Aug 2013 10:33:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B240820573 for ; Wed, 21 Aug 2013 10:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751698Ab3HUKdn (ORCPT ); Wed, 21 Aug 2013 06:33:43 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:48319 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751641Ab3HUKdl (ORCPT ); Wed, 21 Aug 2013 06:33:41 -0400 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MRV00IOHMO1V400@mailout4.samsung.com>; Wed, 21 Aug 2013 19:33:37 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.115]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 2F.A3.08825.18794125; Wed, 21 Aug 2013 19:33:37 +0900 (KST) X-AuditID: cbfee68e-b7f276d000002279-88-521497819945 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 1E.E8.32250.08794125; Wed, 21 Aug 2013 19:33:37 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.252.75.62]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MRV00G9RMNZVM30@mmp2.samsung.com>; Wed, 21 Aug 2013 19:33:36 +0900 (KST) 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 v2 2/2] dma-buf: Add user interfaces for dmabuf sync support Date: Wed, 21 Aug 2013 19:33:35 +0900 Message-id: <1377081215-5948-3-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.5.4 In-reply-to: <1377081215-5948-1-git-send-email-inki.dae@samsung.com> References: <1377081215-5948-1-git-send-email-inki.dae@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeLIzCtJLcpLzFFi42JZI2JSrNs4XSTIYO5pbosrX9+zWUy6P4HF 4mzTG3aL94eeMVtsenyN1eJE3wdWi54NW1ktnj69wGZxu3EFm8Wpu5/ZHbg8ZjX0snncubaH zeN+93Emj81L6j1u/3vM7NG3ZRWjx+dNcgHsUVw2Kak5mWWpRfp2CVwZfzvmMRU8lKk42LqC tYHxg1gXIweHhICJROsz7y5GTiBTTOLCvfVsXYxcHEICSxklpv6dxgKRMJFYvnUrVGI6o8TL 29eYIJxuJol5P+eygVSxCahKTFxxH6xKRGA5o8TH02/ZQRxmgWmMEm+bNoDNEhbwkTj57Ccr iM0C1PGzZT87yB28As4Sy785Q6xTkPh1ZBVYCaeAi8SFlXOYQWwhoJJpyz+ygsyUENjHLjFh 6TYmiDkCEt8mH2KB+EdWYtMBZog5khIHV9xgmcAovICRYRWjaGpBckFxUnqRkV5xYm5xaV66 XnJ+7i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kIqy6cwP11H2PHLmvcVtewOD1W3N73xX9XN YGygXbPiUVvMxV9O+x/H9KX/eh6zJvjoW0elq2kmsSdT2cvtzzPcWthgGLA+Iu+21GShD8u1 21zurP6txFKckWioxVxUnAgAF3usrAADAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 81 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, }; /*