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: 2825642 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 C3E81C0AB2 for ; Wed, 10 Jul 2013 11:59:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBA5920172 for ; Wed, 10 Jul 2013 11:59:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C6F6201C1 for ; Wed, 10 Jul 2013 11:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754222Ab3GJL7C (ORCPT ); Wed, 10 Jul 2013 07:59:02 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:42519 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754427Ab3GJL67 (ORCPT ); Wed, 10 Jul 2013 07:58:59 -0400 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>; 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 Cc: maarten.lankhorst@canonical.com, daniel@ffwll.ch, robdclark@gmail.com, kyungmin.park@samsung.com, myungjoo.ham@samsung.com, yj44.cho@samsung.com, Inki Dae 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+Ai8SR1lfMXYwcQPsUJOZMsgExOQVcJZYd14C4yEXiytLnzCAjJQRO sUvcv/aOCWKMgMS3yYdYIFplJTYdYIa4WlLi4IobLBMYhRcwMqxiFE0tSC4oTkovMtQrTswt Ls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R9r7jL+1s1reDf5WffpK4eTLZ5LKAeLLQyp+HL6bPWNHFEL2S3r I68tzv53NSPVPm4ro+ytqS6TN+QcORwTozT7o8Mn09Irr+e9S0pW2el7rsp8sbZ/4dFMwWqx QIbZjgXff0RMEDuX8/6qEktxRqKhFnNRcSIAZFlQiAMDAAA= 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=-7.2 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 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, }; /*