From patchwork Thu Jun 14 14:32:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 9303 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 A9D8223E53 for ; Thu, 14 Jun 2012 14:32:57 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7907CA185E4 for ; Thu, 14 Jun 2012 14:32:57 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id f1so1523957ggn.11 for ; Thu, 14 Jun 2012 07:32:57 -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:x-mailer:references:x-tm-as-mml: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=p2QJfQbeynkqIlcxr0Rqx7lRDY0gJdtOUgDCRxB5PHA=; b=hEbzzys7UKmM7pqHsurcyrWzfzJCJrN7XiYBLhpqG35feuWxouSSutLk0i11LWFEJM SZL94dQFZmUpWodNLA5s12gphebnWP4m5F5MDqJgrNM/flfBvneRFeoM3xvT4698E3iO IEcKWqdFgWVkwHs25keEBhcPD9x+zEbs1ObFjf3lAjO5ZJ+XZcGS223v4nFb1bkdbXEJ 8aRhFYQgD/oQBKK945EUq5ka786+m2FNgeiTciflOzR0omJaEMOvRGJGDIARQLvzntDH xaGILQ2jcL51qRWv2VHUHo7HFWJQx35e4goCVKrxzhBCBNcNiw3hUiKdBnnuHKCJ4I2N Mb4A== Received: by 10.50.46.232 with SMTP id y8mr918884igm.57.1339684376695; Thu, 14 Jun 2012 07:32:56 -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.24.148 with SMTP id v20csp88226ibb; Thu, 14 Jun 2012 07:32:52 -0700 (PDT) Received: by 10.204.152.75 with SMTP id f11mr1238525bkw.103.1339684371462; Thu, 14 Jun 2012 07:32:51 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id hq18si5174020bkc.88.2012.06.14.07.32.49; Thu, 14 Jun 2012 07:32:51 -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 1SfB6O-00080B-MC; Thu, 14 Jun 2012 14:32:48 +0000 Received: from mailout3.w1.samsung.com ([210.118.77.13]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SfB6G-0007ty-6k for linaro-mm-sig@lists.linaro.org; Thu, 14 Jun 2012 14:32:40 +0000 Received: from euspt1 (mailout3.w1.samsung.com [210.118.77.13]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M5M006VS33FVP70@mailout3.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 14 Jun 2012 15:33:15 +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 <0M5M00I7V32DBI@spt1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 14 Jun 2012 15:32:38 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id 550D827016D; Thu, 14 Jun 2012 16:37:07 +0200 (CEST) Date: Thu, 14 Jun 2012 16:32:29 +0200 From: Tomasz Stanislawski In-reply-to: <1339684349-28882-1-git-send-email-t.stanislaws@samsung.com> To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Message-id: <1339684349-28882-10-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 References: <1339684349-28882-1-git-send-email-t.stanislaws@samsung.com> X-TM-AS-MML: No Cc: 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, g.liakhovetski@gmx.de Subject: [Linaro-mm-sig] [PATCHv2 9/9] v4l: vb2-dma-contig: use dma_get_sgtable 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: ALoCoQkCqYWYlDWTvgYgLtaWfMfrHsVs/ArKPcpyPea9omM0cATyvc92T81cJVnEKwHpQFyMHbHr This patch removes a workaround for extraction of struct pages from DMA buffer. The method of using follow_pfn for artificial VMA is dropped in favour of dma_get_sgtable function. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park --- drivers/media/video/videobuf2-dma-contig.c | 60 ++-------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index a845ff7..73297b7 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -361,73 +361,21 @@ static struct dma_buf_ops vb2_dc_dmabuf_ops = { .release = vb2_dc_dmabuf_ops_release, }; -/** - * vb2_dc_kaddr_to_pages() - extract list of struct pages from a kernel - * pointer. This function is a workaround to extract pages from a pointer - * returned by dma_alloc_coherent. The pages are obtained by creating an - * artificial vma and using follow_pfn to do a page walk to find a PFN - */ -static int vb2_dc_kaddr_to_pages(unsigned long kaddr, - struct page **pages, unsigned int n_pages) -{ - unsigned int i; - unsigned long pfn; - /* create an artificial VMA */ - struct vm_area_struct vma = { - .vm_flags = VM_IO | VM_PFNMAP, - .vm_mm = &init_mm, - }; - - for (i = 0; i < n_pages; ++i, kaddr += PAGE_SIZE) { - if (follow_pfn(&vma, kaddr, &pfn)) - break; - pages[i] = pfn_to_page(pfn); - } - - return i; -} - static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf) { - int n_pages; - struct page **pages = NULL; int ret; struct sg_table *sgt; - n_pages = PAGE_ALIGN(buf->size) >> PAGE_SHIFT; - - pages = kmalloc(n_pages * sizeof pages[0], GFP_KERNEL); - if (!pages) { - dev_err(buf->dev, "failed to alloc page table\n"); - return ERR_PTR(-ENOMEM); - } - - ret = vb2_dc_kaddr_to_pages((unsigned long)buf->vaddr, pages, n_pages); - if (ret < 0) { - dev_err(buf->dev, "failed to get buffer pages from DMA API\n"); - kfree(pages); - return ERR_PTR(ret); - } - if (ret != n_pages) { - dev_err(buf->dev, "got only %d of %d pages from DMA API\n", - ret, n_pages); - kfree(pages); - return ERR_PTR(-EFAULT); - } - sgt = kmalloc(sizeof *sgt, GFP_KERNEL); if (!sgt) { dev_err(buf->dev, "failed to alloc sg table\n"); - kfree(pages); return ERR_PTR(-ENOMEM); } - ret = sg_alloc_table_from_pages(sgt, pages, n_pages, 0, - buf->size, GFP_KERNEL); - /* failure or not, pages are no longer needed */ - kfree(pages); - if (ret) { - dev_err(buf->dev, "failed to covert pages to sg table\n"); + ret = dma_get_sgtable(buf->dev, sgt, buf->vaddr, buf->dma_addr, + buf->size, NULL); + if (ret < 0) { + dev_err(buf->dev, "failed to get scatterlist from DMA API\n"); kfree(sgt); return ERR_PTR(ret); }