From patchwork Wed May 23 13:07:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 8928 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 5217A23F04 for ; Wed, 23 May 2012 13:08:07 +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 24BDDA181B9 for ; Wed, 23 May 2012 13:08:07 +0000 (UTC) Received: by mail-qc0-f180.google.com with SMTP id v28so5823929qcm.11 for ; Wed, 23 May 2012 06:08:07 -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=1RvrnxPcRamaZZz+ve5MAIxotbV+mC165fcnuBil7eM=; b=A3TLNOBbnYEWiaLF+th19ZpJCJsWiANLzRpVp047DAtSfrv+Fuebu5EeyOgKywlyNk 7+GyzMsT2GqUX63yY/JW2RzTKBW2dVowm/ey8+R6JBz7+cd73Hrfq1RqwDcNIkJ8CnUS aNQwwbxelCT7SpRRJMhs4qdic+lo6IARMdapWpvbKbCNX7KOjAgr7bWF2sZRuzNCN36J +3AP2vhMM8qKkbeMReuKCw//Knir2ANER4pFA2seddHy7sFKL2uq1383B/TDfOrbpN3C ThjGLTgWEneVljiZPeH4UjSy8yckpZ7H1GRWbLasUIvdrmADozMf3rpCQJeZ8zCU7NNo +85Q== Received: by 10.50.40.193 with SMTP id z1mr13145230igk.0.1337778486619; Wed, 23 May 2012 06:08:06 -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.35.72 with SMTP id o8csp443477ibd; Wed, 23 May 2012 06:08:00 -0700 (PDT) Received: by 10.180.24.193 with SMTP id w1mr46281730wif.5.1337778479710; Wed, 23 May 2012 06:07:59 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id eb4si20456511wib.38.2012.05.23.06.07.58; Wed, 23 May 2012 06:07:59 -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 1SXBID-0006Yp-Nf; Wed, 23 May 2012 13:07:57 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SXBI4-0006Tv-CV for linaro-mm-sig@lists.linaro.org; Wed, 23 May 2012 13:07:48 +0000 Received: from euspt2 (mailout2.w1.samsung.com [210.118.77.12]) by mailout2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0M4H00LK88GM72@mailout2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 23 May 2012 14:07:36 +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 <0M4H00DE68GVYM@spt2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 23 May 2012 14:07:44 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id 6A62B27004C; Wed, 23 May 2012 15:19:02 +0200 (CEST) Date: Wed, 23 May 2012 15:07:35 +0200 From: Tomasz Stanislawski In-reply-to: <1337778455-27912-1-git-send-email-t.stanislaws@samsung.com> To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Message-id: <1337778455-27912-13-git-send-email-t.stanislaws@samsung.com> MIME-version: 1.0 X-Mailer: git-send-email 1.7.10 References: <1337778455-27912-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, g.liakhovetski@gmx.de Subject: [Linaro-mm-sig] [PATCH 12/12] v4l: vb2-dma-contig: Move allocation of dbuf attachment to attach cb 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: ALoCoQlOfS97WVMPQxKJGR1Np3V11tcb0CHLgPm4MczyByz5ex0TbkZ8LruS59qPRdNjokJhBeWd The allocation of dma_buf_attachment is moved to attach callback. The initialization is left in map callback. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park --- drivers/media/video/videobuf2-dma-contig.c | 39 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index b5caf1d..3bf7c45 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -285,7 +285,15 @@ struct vb2_dc_attachment { static int vb2_dc_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev, struct dma_buf_attachment *dbuf_attach) { - /* nothing to be done */ + struct vb2_dc_attachment *attach; + + attach = kzalloc(sizeof *attach, GFP_KERNEL); + if (!attach) + return -ENOMEM; + + attach->dir = DMA_NONE; + dbuf_attach->priv = attach; + return 0; } @@ -300,7 +308,9 @@ static void vb2_dc_dmabuf_ops_detach(struct dma_buf *dbuf, sgt = &attach->sgt; - dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->nents, attach->dir); + /* checking if scaterlist was ever mapped */ + if (attach->dir != DMA_NONE) + dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->nents, attach->dir); sg_free_table(sgt); kfree(attach); db_attach->priv = NULL; @@ -314,25 +324,28 @@ static struct sg_table *vb2_dc_dmabuf_ops_map( struct vb2_dc_attachment *attach = db_attach->priv; struct sg_table *sgt; struct scatterlist *rd, *wr; - int i, ret; + int ret; + unsigned int i; + + if (WARN_ON(dir == DMA_NONE)) + return ERR_PTR(-EINVAL); /* return previously mapped sg table */ - if (attach) + if (attach->dir == dir) return &attach->sgt; - attach = kzalloc(sizeof *attach, GFP_KERNEL); - if (!attach) - return ERR_PTR(-ENOMEM); + /* reattaching is not allowed */ + if (WARN_ON(attach->dir != DMA_NONE)) + return ERR_PTR(-EBUSY); sgt = &attach->sgt; - attach->dir = dir; - /* copying the buf->base_sgt to attachment */ + /* Copy the buf->base_sgt scatter list to the attachment, as we can't + * map the same scatter list to multiple attachments at the same time. + */ ret = sg_alloc_table(sgt, buf->sgt_base.orig_nents, GFP_KERNEL); - if (ret) { - kfree(attach); + if (ret) return ERR_PTR(-ENOMEM); - } rd = buf->sgt_base.sgl; wr = sgt->sgl; @@ -347,10 +360,10 @@ static struct sg_table *vb2_dc_dmabuf_ops_map( if (ret <= 0) { printk(KERN_ERR "failed to map scatterlist\n"); sg_free_table(sgt); - kfree(attach); return ERR_PTR(-EIO); } + attach->dir = dir; db_attach->priv = attach; return sgt;