From patchwork Wed Jul 10 11:58:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 2825647 Return-Path: X-Original-To: patchwork-linux-arm@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 6AAE3C0AB2 for ; Wed, 10 Jul 2013 12:02:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4B5120178 for ; Wed, 10 Jul 2013 12:02:10 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 70A4820172 for ; Wed, 10 Jul 2013 12:02:05 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uwt45-0007sn-A2; Wed, 10 Jul 2013 12:00:11 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uwt3g-0001gz-Iw; Wed, 10 Jul 2013 11:59:44 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uwt3P-0001du-9D for linux-arm-kernel@lists.infradead.org; Wed, 10 Jul 2013 11:59:28 +0000 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MPP00D0QYLRQM00@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 10 Jul 2013 20:58:56 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.114]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 02.25.17404.08C4DD15; Wed, 10 Jul 2013 20:58:56 +0900 (KST) X-AuditID: cbfee68d-b7f096d0000043fc-e8-51dd4c80d98a Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 5B.08.28381.08C4DD15; Wed, 10 Jul 2013 20:58:56 +0900 (KST) Received: from localhost.localdomain ([10.252.81.149]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MPP000XNYM3IX30@mmp2.samsung.com>; Wed, 10 Jul 2013 20:58:56 +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 Subject: [RFC PATCH v1 2/2] dma-buf: add lock callback for fcntl system call. Date: Wed, 10 Jul 2013 20:58:47 +0900 Message-id: <1373457527-28263-3-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1373457527-28263-1-git-send-email-inki.dae@samsung.com> References: <1373457527-28263-1-git-send-email-inki.dae@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprEIsWRmVeSWpSXmKPExsWyRsSkSLfB526gwZfrshb/t01ktrjy9T2b xaT7E1gszja9YbfY9Pgaq8WJvg+sFj0btrJaPH16gc3iduMKNovnC38wW+zdOZnRgdtjVkMv m8febwtYPHbOusvucb/7OJPH5iX1Hn1bVjF6fN4kF8AexWWTkpqTWZZapG+XwJXx69NMloJW /orH6/MaGGfzdDFyckgImEj8n3qXHcIWk7hwbz0biC0ksJRRonV6PUzNlA2dTF2MXEDx6YwS F9buZYdw2pgkOs8/ZAWpYhNQlZi44j4bSEJEoJVRYveDbSwgDrPATkaJs39XMoFUCQv4Svzb 0Am2jwWo48CV1SwgNq+Ai8SR1lfMXYw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1+BBjMtBNE5mlRJPzgakhryTe 0NjEzMjSyNzQwsjYnDRhJXHeA63WgUIC6YklqdmpqQWpRTBbmDg4pRoY22wMevfohDNrry58 cd1RiemfVZiNR32PQt9F3R9r7jL+1s1reDf5WffpK4eTLZ5LKAeLLQyp+HL6bPWNHFEL2S3r I68tzv53NSPVPm4ro+ytqS6TN+QcORwTozT7o8Mn09Irr+e9S0pW2el7rsp8sbZ/4dFMwWqx QIbZjgXff0RMEDuX8/6qEktxRqKhFnNRcSIAZFlQiAMDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130710_075927_599266_CC81A960 X-CRM114-Status: GOOD ( 13.60 ) X-Spam-Score: -7.2 (-------) Cc: kyungmin.park@samsung.com, yj44.cho@samsung.com, Inki Dae , robdclark@gmail.com, myungjoo.ham@samsung.com, daniel@ffwll.ch, maarten.lankhorst@canonical.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 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 callback to dma buf file operations, and this callback will be called by fcntl system call. With this patch, fcntl system call can be used for buffer synchronization between CPU and CPU, and CPU and DMA in user mode. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/base/dma-buf.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index fe39120..cd71447 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -31,6 +31,7 @@ #include #include #include +#include static inline int is_dma_buf_file(struct file *); @@ -82,9 +83,42 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) return dmabuf->ops->mmap(dmabuf, vma); } +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, + .lock = dma_buf_lock, }; /*