From patchwork Tue Apr 10 13:10: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: 7718 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 A17FF23E1D for ; Tue, 10 Apr 2012 13:11:16 +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 6A537A186FA for ; Tue, 10 Apr 2012 13:11:16 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so10265911iag.11 for ; Tue, 10 Apr 2012 06:11:16 -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=h0ZZ8xKKMGiA3RHgpf2OK7EI/JggGaD0+Gd9Ta0VxsY=; b=nl0atjcRZOwsWlAyKr87ntxAmIWksVXqseAZjl6uhjuwzsOlBJ/NfyoFvTwp1BQz6U Qs3XC2X1uc68lVcIi/qGCP5QMO41xxZS552IrJaYiZyviKdyNn9q/4Qvg6VPT2GXSCGL DsIeYG6hfKzMl4lK92HVnPDfhD/1Y1R8xwFjdZAjB/nYXeVMWq1y9eJKKcuEa64RB4rh 9OgE/K3agWrdeE+94rxvDhfTCEKmZNUzqvPa7a+63WclRxdNf2Y3AyBTdJqBbFBqn2sY At3pre75AmmgflNHWgNLZXvQIxE9qln7yZWensHQ3HyMZvjSBD669oY0YFI6gCSzr+PR PeBA== Received: by 10.42.155.9 with SMTP id s9mr6570626icw.51.1334063476200; Tue, 10 Apr 2012 06:11:16 -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 f25csp20430iby; Tue, 10 Apr 2012 06:11:14 -0700 (PDT) Received: by 10.180.95.74 with SMTP id di10mr153430wib.1.1334063473424; 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 l6si14529406wic.12.2012.04.10.06.10.59; 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 1SHaqY-0004TX-Ps; Tue, 10 Apr 2012 13:10:58 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SHaqT-0004PD-H1 for linaro-mm-sig@lists.linaro.org; Tue, 10 Apr 2012 13:10:53 +0000 Received: from euspt2 (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 <0M2900LOJLWHUU@mailout1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 10 Apr 2012 14:09:54 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M2900G9JLY1GU@spt2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 10 Apr 2012 14:10:49 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id D836A27005F; Tue, 10 Apr 2012 15:19:55 +0200 (CEST) Date: Tue, 10 Apr 2012 15:10:42 +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-9-git-send-email-t.stanislaws@samsung.com> MIME-version: 1.0 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 08/13] v4l: vb2-dma-contig: change map/unmap behaviour for exporters 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: ALoCoQlxtj4ypCEnAizbDjz3BRcByWlopopQ5yab/TmqUSXo2iuVekiKIYaeb1ziaNLjeVMox299 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 | 42 ++++++--------------------- 1 files changed, 10 insertions(+), 32 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index 7f4a58a..a6676bd 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -312,11 +312,6 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) /* DMABUF ops for exporters */ /*********************************************/ -struct vb2_dc_attachment { - struct sg_table sgt; - enum dma_data_direction dir; -}; - static int vb2_dc_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev, struct dma_buf_attachment *dbuf_attach) { @@ -327,17 +322,13 @@ static int vb2_dc_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev, static void vb2_dc_dmabuf_ops_detach(struct dma_buf *dbuf, struct dma_buf_attachment *db_attach) { - struct vb2_dc_attachment *attach = db_attach->priv; - struct sg_table *sgt; + struct sg_table *sgt = db_attach->priv; - if (!attach) + if (!sgt) return; - sgt = &attach->sgt; - - dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->nents, attach->dir); sg_free_table(sgt); - kfree(attach); + kfree(sgt); db_attach->priv = NULL; } @@ -346,26 +337,22 @@ static struct sg_table *vb2_dc_dmabuf_ops_map( { struct dma_buf *dbuf = db_attach->dmabuf; struct vb2_dc_buf *buf = dbuf->priv; - struct vb2_dc_attachment *attach = db_attach->priv; - struct sg_table *sgt; + struct sg_table *sgt = db_attach->priv; struct scatterlist *rd, *wr; int i, ret; /* return previously mapped sg table */ - if (attach) - return &attach->sgt; + if (sgt) + return sgt; - attach = kzalloc(sizeof *attach, GFP_KERNEL); - if (!attach) + sgt = kzalloc(sizeof *sgt, GFP_KERNEL); + if (!sgt) return ERR_PTR(-ENOMEM); - sgt = &attach->sgt; - attach->dir = dir; - /* copying the buf->base_sgt to attachment */ ret = sg_alloc_table(sgt, buf->sgt_base->orig_nents, GFP_KERNEL); if (ret) { - kfree(attach); + kfree(sgt); return ERR_PTR(-ENOMEM); } @@ -377,16 +364,7 @@ static struct sg_table *vb2_dc_dmabuf_ops_map( wr = sg_next(wr); } - /* mapping new sglist to the client */ - ret = dma_map_sg(db_attach->dev, sgt->sgl, sgt->orig_nents, dir); - if (ret <= 0) { - printk(KERN_ERR "failed to map scatterlist\n"); - sg_free_table(sgt); - kfree(attach); - return ERR_PTR(-EIO); - } - - db_attach->priv = attach; + db_attach->priv = sgt; return sgt; }