From patchwork Wed Oct 10 14:46:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1574211 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 351F93FE36 for ; Wed, 10 Oct 2012 14:56:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755073Ab2JJO4M (ORCPT ); Wed, 10 Oct 2012 10:56:12 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:45257 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754637Ab2JJO4L (ORCPT ); Wed, 10 Oct 2012 10:56:11 -0400 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO006HTMTMQC11@mailout3.samsung.com> for linux-media@vger.kernel.org; Wed, 10 Oct 2012 23:56:10 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-7d-50758c8aea79 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id C6.BB.03860.A8C85705; Wed, 10 Oct 2012 23:56:10 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MBO002YDME0EC70@mmp1.samsung.com> for linux-media@vger.kernel.org; Wed, 10 Oct 2012 23:56:10 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: airlied@redhat.com, m.szyprowski@samsung.com, t.stanislaws@samsung.com, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, sumit.semwal@ti.com, daeinki@gmail.com, daniel.vetter@ffwll.ch, robdclark@gmail.com, pawel@osciak.com, linaro-mm-sig@lists.linaro.org, hverkuil@xs4all.nl, remi@remlab.net, subashrp@gmail.com, mchehab@redhat.com, zhangfei.gao@gmail.com, s.nawrocki@samsung.com, k.debski@samsung.com Subject: [PATCHv10 12/26] v4l: vb2-vmalloc: add support for dmabuf importing Date: Wed, 10 Oct 2012 16:46:31 +0200 Message-id: <1349880405-26049-13-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> References: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrIJMWRmVeSWpSXmKPExsVy+t9jAd2untIAg+dv5C16NmxldWD0+LxJ LoAxissmJTUnsyy1SN8ugSvj6b/iglviFf/fTmFpYHwm3MXIySEhYCLxcfsZFghbTOLCvfVs XYxcHEICixglznTeYYFwVjFJ3LrTDVbFBtRxbMlnRhBbRMBB4vTdWcwgRcwCa5glXqy8AdTO wSEs4COx+JIHSA2LgKrEhit9zCA2r4CnxPPLf5kgtslLPL3fxwZicwLFL8ybDlYjJOAh8X/9 ZqYJjLwLGBlWMYqmFiQXFCel5xrpFSfmFpfmpesl5+duYgR7/Jn0DsZVDRaHGAU4GJV4eCsy SgKEWBPLiitzDzFKcDArifCa+pQGCPGmJFZWpRblxxeV5qQWH2KU5mBREudt9kgJEBJITyxJ zU5NLUgtgskycXBKNTBOVPy+2n7pprun3CfeTOm7cvGa3geeF9M9V+7mNqo12dZdmXz60FJr +WUhbr7cs2d2P4nrXHReZuP+Lbt5IuK/FDrP3Hj6fd/7Wmeu0xrt3546vin2lkuYHjPLqlBx /+bkjWzZC3S8J7mnP+22MIu4mV9tErc0gTNe4tUl/dKvN9QvNV4SM3qnxFKckWioxVxUnAgA 6r4TnPQBAAA= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch adds support for importing DMABUF files for vmalloc allocator in Videobuf2. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park Acked-by: Laurent Pinchart Acked-by: Hans Verkuil --- drivers/media/v4l2-core/Kconfig | 1 + drivers/media/v4l2-core/videobuf2-vmalloc.c | 56 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig index e30583b..65875c3 100644 --- a/drivers/media/v4l2-core/Kconfig +++ b/drivers/media/v4l2-core/Kconfig @@ -75,6 +75,7 @@ config VIDEOBUF2_VMALLOC tristate select VIDEOBUF2_CORE select VIDEOBUF2_MEMOPS + select DMA_SHARED_BUFFER config VIDEOBUF2_DMA_SG tristate diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c index 94efa04..a47fd4f 100644 --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c @@ -30,6 +30,7 @@ struct vb2_vmalloc_buf { unsigned int n_pages; atomic_t refcount; struct vb2_vmarea_handler handler; + struct dma_buf *dbuf; }; static void vb2_vmalloc_put(void *buf_priv); @@ -207,11 +208,66 @@ static int vb2_vmalloc_mmap(void *buf_priv, struct vm_area_struct *vma) return 0; } +/*********************************************/ +/* callbacks for DMABUF buffers */ +/*********************************************/ + +static int vb2_vmalloc_map_dmabuf(void *mem_priv) +{ + struct vb2_vmalloc_buf *buf = mem_priv; + + buf->vaddr = dma_buf_vmap(buf->dbuf); + + return buf->vaddr ? 0 : -EFAULT; +} + +static void vb2_vmalloc_unmap_dmabuf(void *mem_priv) +{ + struct vb2_vmalloc_buf *buf = mem_priv; + + dma_buf_vunmap(buf->dbuf, buf->vaddr); + buf->vaddr = NULL; +} + +static void vb2_vmalloc_detach_dmabuf(void *mem_priv) +{ + struct vb2_vmalloc_buf *buf = mem_priv; + + if (buf->vaddr) + dma_buf_vunmap(buf->dbuf, buf->vaddr); + + kfree(buf); +} + +static void *vb2_vmalloc_attach_dmabuf(void *alloc_ctx, struct dma_buf *dbuf, + unsigned long size, int write) +{ + struct vb2_vmalloc_buf *buf; + + if (dbuf->size < size) + return ERR_PTR(-EFAULT); + + buf = kzalloc(sizeof(*buf), GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + + buf->dbuf = dbuf; + buf->write = write; + buf->size = size; + + return buf; +} + + const struct vb2_mem_ops vb2_vmalloc_memops = { .alloc = vb2_vmalloc_alloc, .put = vb2_vmalloc_put, .get_userptr = vb2_vmalloc_get_userptr, .put_userptr = vb2_vmalloc_put_userptr, + .map_dmabuf = vb2_vmalloc_map_dmabuf, + .unmap_dmabuf = vb2_vmalloc_unmap_dmabuf, + .attach_dmabuf = vb2_vmalloc_attach_dmabuf, + .detach_dmabuf = vb2_vmalloc_detach_dmabuf, .vaddr = vb2_vmalloc_vaddr, .mmap = vb2_vmalloc_mmap, .num_users = vb2_vmalloc_num_users,