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: 12121 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id F2CCA23EFB for ; Wed, 10 Oct 2012 14:56:19 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 77581A190B9 for ; Wed, 10 Oct 2012 14:56:18 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so1009390iej.11 for ; Wed, 10 Oct 2012 07:56:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=IjntT+SA+Cw2ph12PRLkUffnZbXGhF8rt0qZ6sfWUDI=; b=RM5rNAYO8D0/dm9Kn9WSLbHmQGJJvaJLoprHS1dleYhek+TXCsAdRA8MU1ZKX2CKQx yUD20H5R5i/MurWVtCiQqZCRKIWOC6Oo98P8166vDv0QB2KLyEDBHeW+8mWxKGxr93xD Is3XR6du/VHgPwoS4cFuwbdQn83v+BXdj8AzdQp4Kpgl0L7Tlh7A5jZPzNgDUgGzi3mY 23DMd7EAlWS+DmQqFac+6y6Ssw7/ybhlLa6GtHGDnEfCpoOEZJ5T0DqCxTJNBhbu7JBR ft6QBewrNFVgqVUXir6XTyaqdDekUk7rbgBlIoGnkH+5mTUHKhTF65hUtfTp6V/Z4ixm M+lA== Received: by 10.50.87.134 with SMTP id ay6mr5456480igb.70.1349880977928; Wed, 10 Oct 2012 07:56:17 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp236585igt; Wed, 10 Oct 2012 07:56:17 -0700 (PDT) Received: by 10.204.148.12 with SMTP id n12mr8017591bkv.62.1349880976427; Wed, 10 Oct 2012 07:56:16 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id b10si2859928bka.27.2012.10.10.07.56.15; Wed, 10 Oct 2012 07:56:16 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxhm-0001pt-4Z; Wed, 10 Oct 2012 14:56:14 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxhj-0001po-Vh for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 14:56:12 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO00KBKMTIQ870@mailout2.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:56:10 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-25-50758c8abb2d Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id BF.0A.03783.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 linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:56:10 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org 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+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jAd2untIAg4mbJSy+XHnI5MDocfvf Y+YAxigum5TUnMyy1CJ9uwSujKf/igtuiVf8fzuFpYHxmXAXIyeHhICJxOmZE9khbDGJC/fW s3UxcnEICSxilNjdvZYFwlnLJNF/aDIrSBUbUMexJZ8ZQWwRAQeJ03dnMYMUMQusYZZ4sfIG UDsHh7CAj8TiSx4gNSwCqhIbrvQxg9i8Ap4Szy//ZYLYJi/x9H4fG4jNCRS/MG86WI2QgIfE //WbmSYw8i5gZFjFKJpakFxQnJSea6hXnJhbXJqXrpecn7uJEezzZ1I7GFc2WBxiFOBgVOLh zYgqCRBiTSwrrsw9xCjBwawkwmvqUxogxJuSWFmVWpQfX1Sak1p8iFGag0VJnLfZIyVASCA9 sSQ1OzW1ILUIJsvEwSnVwGhewc4Y4HvK9PycV/qzZ5e57o7//uD2veXnP7vm80+beCv4+AHT RZncFnP6Oa45i2Tvf36zcNaR3qmP/gi55Dyyypjd3nw+Odj2zsfr/Aviyhte119m+7sslGfu oV/a/4s1dItiz13X2+/SITPfxcFR0tuOt+JjufSZrrboJ16bPbeJ6qVcLlRiKc5INNRiLipO BADbMas79QEAAA== Cc: k.debski@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, airlied@redhat.com, remi@remlab.net Subject: [Linaro-mm-sig] [PATCHv10 12/26] v4l: vb2-vmalloc: add support for dmabuf importing X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQmOLG6IBqlfpOjlPAleat4nrJolMMdcc+CwO4phvR979Mk6rLUYIWZDCe1Brmu46eKtol9F 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,