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: 11933 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 DE78B1A52FC for ; Tue, 2 Oct 2012 14:29:26 +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 9122DA18672 for ; Tue, 2 Oct 2012 14:29:26 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so14258231iej.11 for ; Tue, 02 Oct 2012 07:29:26 -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=PdpHnsK0O698jICYrtHQMl/K6cqIE4ATsi0DQPgRTDM=; b=EwJn1N8vrpTDvSuewvkBBMmOFRpkyI8w8rkgPYExUjZJRC+xSpsVqu8J0g63wY+VOR vARICxrmGNZlSZXQYjQOCHdjR1KGwMTBe4kk6SfbeZ4SFEztUlbLIlEjhZdCHxT+RSW5 eSXGvMxc0NbZirUGUmO1YsxEIBnVn8MS4W8RzX0Oz5scOWW5Z+k4PKCx6ChEG5c5XgCY 2KOke3+bslYP/k5RJ3SsBblD3JactqOPYbv3gFzoNiclJGpuK8efPk+tfAR/ch+GJ58v yw5dv4h/8fi5t2h9mnYoKpFkMPHPwdqAWtFoXAPqvRInqSedU8lqwYhVc17/Bxlp3QcO feNA== Received: by 10.50.194.136 with SMTP id hw8mr9028029igc.28.1349188166336; Tue, 02 Oct 2012 07:29:26 -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.232 with SMTP id ex8csp84988igc; Tue, 2 Oct 2012 07:29:25 -0700 (PDT) Received: by 10.204.129.213 with SMTP id p21mr2335624bks.115.1349188164701; Tue, 02 Oct 2012 07:29:24 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id im3si1700214bkc.84.2012.10.02.07.29.22; Tue, 02 Oct 2012 07:29:24 -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 1TJ3TN-0004iG-Q7; Tue, 02 Oct 2012 14:29:21 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TJ3TM-0004hi-Se for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 14:29:21 +0000 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 <0MB900FNZS8A6O90@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:29:19 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-14-506afa3fc8b5 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id DB.91.03860.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 linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:29:19 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org 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+t9jQV37X1kBBv9X61l8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGbMufmYu+CxcsfzhAaYGxjMCXYycHBICJhLd026yQthiEhfu rWfrYuTiEBKYzihxdN8RFghnLZPE/O1/GUGq2IA6ji35DGaLCDhInL47ixmkiFlgDbPEi5U3 2EASwgLeEq1vvoHZLAKqEi92PWABsXkFPCQOLuxhgVgnL/H0fh9YDSdQ/OeTC2BxIQF3iT3L m9gmMPIuYGRYxSiaWpBcUJyUnmukV5yYW1yal66XnJ+7iRHs92fSOxhXNVgcYhTgYFTi4d11 MjNAiDWxrLgy9xCjBAezkgiv9f2sACHelMTKqtSi/Pii0pzU4kOM0hwsSuK8zR4pAUIC6Ykl qdmpqQWpRTBZJg5OqQbGOrbvqq5s6lslLMO/KZ36nNMvKxFue/JN8urKJ0oaCeI3FVfNVI/7 k5T7t03YUc6iJlaZLzrjpODkFbIa3/n8C6/bPtE8svJNrrRam4lVNIdedVDd+6L2o/LW6WVr 7nu6siW+2PpuieRXpk3PngoYdcwu2K6/6GSELdvuoMvpmXb93HPtDJVYijMSDbWYi4oTAfTg AsT3AQAA 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] [PATCHv9 12/25] 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: ALoCoQmDgmQ6GqIHYqthM7uZovrGJc7d6wTUqPkyMYijPMOoJl0hhwrLFsEOO8fhl9vGW1ikvxUg 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,