From patchwork Tue Apr 10 13:10:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 7723 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 CBE8D23E1D for ; Tue, 10 Apr 2012 13:11:23 +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 93F95A18701 for ; Tue, 10 Apr 2012 13:11:23 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so10265911iag.11 for ; Tue, 10 Apr 2012 06:11:23 -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 :mime-version:date:from:in-reply-to:to:message-id: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=xDlg2P/FJjFjY2vg8EG3FoswKQGACmh81zl/7+CKtEs=; b=f4oXzh+t0ajKNJ8wQKKdUrOJ+2CIv/kHYBUVfbyfM/u65iozVA8C5mcP/fixy8BTFt +5IdgfkIhs9lRIQGq3KoL4Y456JCjYpYMLwgeNua+HxlAsiRNEFUHaasu1HFD4ASNlDs 0Dz7PuYptLHGCj20Dn3Zj80GMOinHU4767Wc+Q4QBAxq7VMoyOio8gwIu6ai9TgM/IEE vIfvUYcWR34jFJIJHpFMm+YzfACm5fcVHRjJFAhfWrnBo6RVq8Cxurb62O8L65s/jGBS uP6/OjoRmDCfwwIclM6BoDb3+rwtSz8E9iFBwkOl639n8mMnHqPM9YfWyl1kk4O0P10q Y3lg== Received: by 10.50.168.67 with SMTP id zu3mr2302179igb.28.1334063483339; Tue, 10 Apr 2012 06:11:23 -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.164.217 with SMTP id f25csp20447iby; Tue, 10 Apr 2012 06:11:19 -0700 (PDT) Received: by 10.14.28.65 with SMTP id f41mr1349631eea.23.1334063473443; Tue, 10 Apr 2012 06:11:13 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id m49si18174667wed.140.2012.04.10.06.11.02; Tue, 10 Apr 2012 06:11:13 -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 1SHaqb-00052c-3l; Tue, 10 Apr 2012 13:11:01 +0000 Received: from mailout3.w1.samsung.com ([210.118.77.13]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SHaqT-0004PB-IV for linaro-mm-sig@lists.linaro.org; Tue, 10 Apr 2012 13:10:53 +0000 MIME-version: 1.0 Received: from euspt1 ([210.118.77.13]) by mailout3.w1.samsung.com (Sun Java(tm) System Messaging Server 6.3-8.04 (built Jul 29 2009; 32bit)) with ESMTP id <0M29005YFLXJAR60@mailout3.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 10 Apr 2012 14:10:31 +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 <0M2900ENBLY3XY@spt1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 10 Apr 2012 14:10:51 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id C64D527005E; Tue, 10 Apr 2012 15:19:55 +0200 (CEST) Date: Tue, 10 Apr 2012 15:10:41 +0200 From: Tomasz Stanislawski In-reply-to: <1334063447-16824-1-git-send-email-t.stanislaws@samsung.com> To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Message-id: <1334063447-16824-8-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.9.1 References: <1334063447-16824-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 Subject: [Linaro-mm-sig] [RFC 07/13] 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: ALoCoQlyiw2UIZs9LODSCYqOlGel3MvI1/6JXATlTZCF2Seh+0vp0+rYGambE0JxevWRIuHv+PK4 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 | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index 537926b..7f4a58a 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -652,7 +652,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 = 0; + int ret = -EFAULT; if (WARN_ON(!buf->db_attach)) { printk(KERN_ERR "trying to pin a non attached buffer\n"); @@ -671,12 +671,20 @@ 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 of dmabuf is too small\n"); - ret = -EFAULT; - goto fail_map; + printk(KERN_ERR "contiguous chunk is too small %lu/%lu b\n", + contig_size, buf->size); + goto fail_map_sg; } buf->dma_addr = sg_dma_address(sgt->sgl); @@ -684,7 +692,10 @@ static int vb2_dc_map_dmabuf(void *mem_priv) return 0; -fail_map: +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; @@ -705,6 +716,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;