From patchwork Tue Oct 2 14:27:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1537481 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 6BB8440135 for ; Tue, 2 Oct 2012 14:39:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A95B9F5F9 for ; Tue, 2 Oct 2012 07:39:35 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 57B319F5EC for ; Tue, 2 Oct 2012 07:29:20 -0700 (PDT) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MB9009UJS8V3500@mailout1.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 02 Oct 2012 23:29:19 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-40-506afa3f7e15 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id E8.9E.03783.F3AFA605; Tue, 02 Oct 2012 23:29:19 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MB9005A7S65K790@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 02 Oct 2012 23:29:19 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCHv9 12/25] v4l: vb2-vmalloc: add support for dmabuf importing Date: Tue, 02 Oct 2012 16:27:23 +0200 Message-id: <1349188056-4886-13-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> References: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCJMWRmVeSWpSXmKPExsVy+t9jQV37X1kBBu926Vpc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujFkXPzMXfBauWP7wAFMD4xmBLkZODgkBE4nvk1+zQdhiEhfu rQeyuTiEBKYzSiw6N48dwlnHJHF23kYmkCo2oI5jSz4zgtgiAg4Sp+/OYgYpYhZYwyzxYuUN sFHCAt4SrW++gdksAqoSL3Y9YAGxeQU8JA4u7GGBWCcv8fR+H1gNJ1D855MLYHEhAXeJPcub 2CYw8i5gZFjFKJpakFxQnJSea6hXnJhbXJqXrpecn7uJEez3Z1I7GFc2WBxiFOBgVOLh3Xky M0CINbGsuDL3EKMEB7OSCK/1/awAId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rzNHikBQgLpiSWp 2ampBalFMFkmDk6pBkYVf5c56p8FV86VYV/yIJ37YfK6J9Nquq6+uDQ3uGqG0etvH6OX1/uE V22tkGBbfOXytOnhP9VS7t75Xvs3afrm3ZOdeDr9j0W/9VJgOHzWoELwY7Kg6Yq47gPSkZFV nUd8/OZYz1ZPZ31WyMG2Zc6zvTaB1vPl9LYsY2Z1X5euVRUrYHqmVVmJpTgj0VCLuag4EQDo umUI9wEAAA== Cc: t.stanislaws@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, mchehab@redhat.com, daniel.vetter@ffwll.ch, subashrp@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, zhangfei.gao@gmail.com, airlied@redhat.com, remi@remlab.net, m.szyprowski@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 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 --- drivers/media/video/videobuf2-vmalloc.c | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/media/video/videobuf2-vmalloc.c b/drivers/media/video/videobuf2-vmalloc.c index 6b5ca6c..e91449c 100644 --- a/drivers/media/video/videobuf2-vmalloc.c +++ b/drivers/media/video/videobuf2-vmalloc.c @@ -29,6 +29,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); @@ -206,11 +207,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,