From patchwork Tue Aug 13 09:19:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 2843519 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 37CC79F239 for ; Tue, 13 Aug 2013 09:22:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D01B202EC for ; Tue, 13 Aug 2013 09:22:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 30FA9202C6 for ; Tue, 13 Aug 2013 09:22:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 30F47E78F0 for ; Tue, 13 Aug 2013 02:22:19 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 03773E645A for ; Tue, 13 Aug 2013 02:19:40 -0700 (PDT) Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MRG003ZUPWQ00Q0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 13 Aug 2013 18:19:38 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.116]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id AF.B8.08825.A2AF9025; Tue, 13 Aug 2013 18:19:38 +0900 (KST) X-AuditID: cbfee68e-b7f276d000002279-35-5209fa2ae7a9 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B2.4F.32250.A2AF9025; Tue, 13 Aug 2013 18:19:38 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.252.75.62]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MRG003MLPWOEO50@mmp1.samsung.com>; Tue, 13 Aug 2013 18:19:38 +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 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> X-Mailer: git-send-email 1.7.5.4 In-reply-to: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> References: <1376385576-9039-1-git-send-email-inki.dae@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRmVeSWpSXmKPExsWyRsSkRFfrF2eQwbsN4hZXvr5ns5h0fwKL xdmmN+wW7w89Y7bY9Pgaq8WJvg+sFj0btrJaPH16gc3iduMKNotTdz+zO3B5zGroZfO4c20P m8f97uNMHpuX1Hvc/veY2aNvyypGj8+b5ALYo7hsUlJzMstSi/TtErgyrh3ew1RwVL6if+5y xgbGmZJdjJwcEgImEh8+vmOEsMUkLtxbz9bFyMUhJLCUUWL++gVMMEXnrl1kgkgsYpTYsPI/ I4TTzSQx+8pONpAqNgFViYkr7oO1iwgsZ5T4ePotO4jDLDCNUeJt0wYWkCphgWiJw18ngi1k Aeq4vXIXWDevgLPE44Z1UPsUJH4dWcUKYnMKuEgcO/qQGcQWAqp5+bCFHaLmELvEpM5AiDkC Et8mHwKazwEUl5XYdIAZokRS4uCKGywTGIUXMDKsYhRNLUguKE5KLzLSK07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tfCfzR4BdPnPxySaqUl0iFofPXzHOmn24vE1vfeXnXpdlyhl6ayV3TfSX3r1Ju1ePl f5glkR71rXfnPNnUktP/nysvUUmMkrCdv6Kcq9Ri4j2Xm2kfmZtPRVw/vSyb9eGG0D9XmVy8 bWf4K68sZPulxFKckWioxVxUnAgAAIzVlAEDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: kyungmin.park@samsung.com, myungjoo.ham@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 +++++++++++++++++++++++++++++++++++++++++++ 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