From patchwork Fri Apr 13 15:47:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 7803 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 F37DD23E42 for ; Fri, 13 Apr 2012 15:48:53 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id B6946A183CE for ; Fri, 13 Apr 2012 15:48:53 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so6011978iag.11 for ; Fri, 13 Apr 2012 08:48:53 -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:date:from :in-reply-to:to:message-id:mime-version:x-mailer:references:cc :subject:x-beenthere:x-mailman-version:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:content-transfer-encoding:sender:errors-to :x-gm-message-state; bh=wan0wg4YtFxcm8kYc1Yw7kaV4E8+WZyni8nAcS2tUjY=; b=iTwRxHt/ySqBYx8mQJ9pZbQYJNkO33Cz2l9QIqOLrQZHAFKigBqWCuoT1l76fk/6nw jlWKWMScBe1ZNYmeuJ7FORgFa5CW+iNj44rOiXWxy9u8pmhE04NjQkgKKcTovq1g4Brk KvuvvqIoAy3LjArvXppVQaBV69cMCvKXnejqGm/D4I4M7W1UmvA6XNrQyfoWvEao7z6a Hes1LjGREDMV6n1SvzxLwIVt/UJwOKZMq+xcVLf+l2R5E81PTnwqtIyUfBEXYZxhb+ZX olXIWepcSCp88jfJBcWNbXs+g9pAgPwWEU4gON1jIg0+xQVYzGXWR37sdBDur+aX3NB6 AOUg== Received: by 10.50.189.232 with SMTP id gl8mr2027439igc.50.1334332133482; Fri, 13 Apr 2012 08:48:53 -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.231.70.69 with SMTP id c5csp38536ibj; Fri, 13 Apr 2012 08:48:52 -0700 (PDT) Received: by 10.180.8.231 with SMTP id u7mr5070370wia.9.1334332127562; Fri, 13 Apr 2012 08:48:47 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id cf5si2740420wib.22.2012.04.13.08.48.16; Fri, 13 Apr 2012 08:48:47 -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 1SIijQ-0006Ld-Hz; Fri, 13 Apr 2012 15:48:16 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SIijH-0006GS-FR for linaro-mm-sig@lists.linaro.org; Fri, 13 Apr 2012 15:48:07 +0000 Received: from euspt1 (mailout1.w1.samsung.com [210.118.77.11]) by mailout1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0M2F0077WD6DVT@mailout1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 13 Apr 2012 16:47:01 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M2F00A2HD84YO@spt1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 13 Apr 2012 16:48:05 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id ABA55270085; Fri, 13 Apr 2012 17:58:32 +0200 (CEST) Date: Fri, 13 Apr 2012 17:47:54 +0200 From: Tomasz Stanislawski In-reply-to: <1334332076-28489-1-git-send-email-t.stanislaws@samsung.com> To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Message-id: <1334332076-28489-13-git-send-email-t.stanislaws@samsung.com> MIME-version: 1.0 X-Mailer: git-send-email 1.7.9.1 References: <1334332076-28489-1-git-send-email-t.stanislaws@samsung.com> Cc: pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, airlied@redhat.com, remi@remlab.net Subject: [Linaro-mm-sig] [PATCH v4 12/14] v4l: vb2-dma-contig: change map/unmap behaviour for importers 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: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkmCcnSCiqU1ugAAEd58AWKczKE8/JE8BBgMHPe4x1IroNaq2zw3k5juspY5F5/tnq5mOB2 The DMABUF documentation says that the map_dma_buf callback should return scatterlist that is mapped into a caller's address space. In practice, almost none of existing implementations of DMABUF exporter does it. This patch breaks the DMABUF specification in order to allow exchange DMABUF buffers between other APIs like DRM. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park --- drivers/media/video/videobuf2-dma-contig.c | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index a829e7d..0ea3fcd 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -442,6 +442,7 @@ static int vb2_dc_map_dmabuf(void *mem_priv) struct vb2_dc_buf *buf = mem_priv; struct sg_table *sgt; unsigned long contig_size; + int ret = -EFAULT; if (WARN_ON(!buf->db_attach)) { printk(KERN_ERR "trying to pin a non attached buffer\n"); @@ -460,19 +461,34 @@ static int vb2_dc_map_dmabuf(void *mem_priv) return -EINVAL; } + /* mapping new sglist to the client */ + sgt->nents = dma_map_sg(buf->dev, sgt->sgl, sgt->orig_nents, + buf->dma_dir); + if (sgt->nents <= 0) { + printk(KERN_ERR "failed to map scatterlist\n"); + goto fail_map_attachment; + } + /* checking if dmabuf is big enough to store contiguous chunk */ contig_size = vb2_dc_get_contiguous_size(sgt); if (contig_size < buf->size) { printk(KERN_ERR "contiguous chunk is too small %lu/%lu b\n", contig_size, buf->size); - dma_buf_unmap_attachment(buf->db_attach, sgt, buf->dma_dir); - return -EFAULT; + goto fail_map_sg; } buf->dma_addr = sg_dma_address(sgt->sgl); buf->dma_sgt = sgt; return 0; + +fail_map_sg: + dma_unmap_sg(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + +fail_map_attachment: + dma_buf_unmap_attachment(buf->db_attach, sgt, buf->dma_dir); + + return ret; } static void vb2_dc_unmap_dmabuf(void *mem_priv) @@ -490,6 +506,7 @@ static void vb2_dc_unmap_dmabuf(void *mem_priv) return; } + dma_unmap_sg(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); dma_buf_unmap_attachment(buf->db_attach, sgt, buf->dma_dir); buf->dma_addr = 0;