From patchwork Tue Aug 14 15:34:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 10741 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 A923023F34 for ; Tue, 14 Aug 2012 15:36:59 +0000 (UTC) Received: from mail-qc0-f180.google.com (mail-qc0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id 66613A18A2E for ; Tue, 14 Aug 2012 15:36:59 +0000 (UTC) Received: by qcmv28 with SMTP id v28so405233qcm.11 for ; Tue, 14 Aug 2012 08:36:59 -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:x-tm-as-mml: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=YOHSfOq2Any6Uf1p0nuznI65ZQYe61HkSps/OhPqiS4=; b=DMLZDX5RU+qJ1qdyRBueW/uX+Ib0ZwgEDiJHroiRHMZO2qIhu0+NxpLVbxdQ94i5B/ /ZaXFM7O+sKmOx2pt8Wrkx8fdr2+tZ/KbBnR0fdPvGuM0ERiavz6c26g4I2DJDihKlfo 7ipmUYoMKTaeU/Y2b5TjDzl0JRWkt+a+asMDFeH45pJN0UBayKBr6A2u0vwx/oYaWShP cW8S52sqmGFU9uZRjE5td7gZvFojix7ddah6GkCFnOZvnutjF4aTY3ajXy/OlpphWxRu bQhNwZLS1hV8ibNjkXNJKPkZtqHzfKzSdb0K9ANy15SWYK71e49oXqTWpkCep3X4HdcZ FmcQ== Received: by 10.50.57.168 with SMTP id j8mr12369365igq.16.1344958618609; Tue, 14 Aug 2012 08:36:58 -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.184.200 with SMTP id ew8csp20620igc; Tue, 14 Aug 2012 08:36:57 -0700 (PDT) Received: by 10.180.103.4 with SMTP id fs4mr28836333wib.16.1344958617301; Tue, 14 Aug 2012 08:36:57 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id q52si3115427wea.149.2012.08.14.08.36.50; Tue, 14 Aug 2012 08:36:57 -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 1T1JAn-0008Cj-Tr; Tue, 14 Aug 2012 15:36:49 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T1JAl-0008CY-O5 for linaro-mm-sig@lists.linaro.org; Tue, 14 Aug 2012 15:36:48 +0000 Received: from epcpsbgm2.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8R000FF4PA3Z20@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 15 Aug 2012 00:36:46 +0900 (KST) X-AuditID: cbfee61b-b7faf6d00000476a-60-502a708ef3b2 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 22.F9.18282.E807A205; Wed, 15 Aug 2012 00:36:46 +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 <0M8R004J44MBC810@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 15 Aug 2012 00:36:46 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 14 Aug 2012 17:34:42 +0200 Message-id: <1344958496-9373-13-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1344958496-9373-1-git-send-email-t.stanislaws@samsung.com> References: <1344958496-9373-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jAd2+Aq0Ag5mnOC2+XHnI5MDocfvf Y+YAxigum5TUnMyy1CJ9uwSujJZDMxgLNgtXfO56wd7AOFGgi5GTQ0LAROLJjG9MELaYxIV7 69m6GLk4hAQWMUq8nH2QEcJZyyRx9vFKdpAqNqCOY0s+M4LYIgIOEqfvzmIGKWIWOMQssb/3 NVARB4ewgLfE5D98IDUsAqoSn67uYAGxeQU8JGa8/MUOsU1e4un9PjYQmxMo/nJTNyNIq5CA u8TCn/4TGHkXMDKsYhRNLUguKE5KzzXSK07MLS7NS9dLzs/dxAj2+TPpHYyrGiwOMQpwMCrx 8BYmagYIsSaWFVfmHmKU4GBWEuEtCtIKEOJNSaysSi3Kjy8qzUktPsQozcGiJM5r4v3VX0gg PbEkNTs1tSC1CCbLxMEp1cCYM0/nnISrqclUBq/nr798q+V9MH+/zA6N18zScx27rxjan+Zh 1hV3nH9fqv9M5DSh2Mik74nlPwxl7P4XnT98ueacQN0JH85ET+93fWeVfXcqfT2ttfmEY+d0 jdW3nsxZx3SUh22d0NSg4w9n6N5lEYj6x/NL0ECOK6azeu2Pyz52O+SfdeQrsRRnJBpqMRcV JwIAYpyifvUBAAA= X-TM-AS-MML: No Cc: k.debski@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, dmitriyz@google.com, laurent.pinchart@ideasonboard.com, s.nawrocki@samsung.com, airlied@redhat.com, remi@remlab.net, g.liakhovetski@gmx.de Subject: [Linaro-mm-sig] [PATCHv8 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: ALoCoQmSupQKto0dm2Q334saeOvoX+EeigV7RH6ZX8ReNEyCEI0DLQjakQ/EUnTQkRXG4SVojm4Q 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 94efa04..a47fd4f 100644 --- a/drivers/media/video/videobuf2-vmalloc.c +++ b/drivers/media/video/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,