From patchwork Wed Jun 13 11:50:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9265 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 7424A23E53 for ; Wed, 13 Jun 2012 11:51:24 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 445FBA18031 for ; Wed, 13 Jun 2012 11:51:24 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so293612ghb.11 for ; Wed, 13 Jun 2012 04:51:24 -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:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker: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=DFW3EWj4BXnFImFNFEWrJiSZU837nq113ADC20XEPPw=; b=fnYbYL6aSZmnxP/y3ml0Afg23w7RYH2Qg2VOCZ2//qC/9hTr/bpWf0SC9sg1dr4gPc ovFE4d/IC21Y2I0uhcMWxB28K72xkQDeS4SBel+zsn7bCdH+oeVHNoPhFcOAltI4b4Gd gcJPYw2c9SEYyYl1nI3fiMbVOSQrkvcnSPyj5UKFeJGjzwydumBQGHAXzNfWj9Mx2njo lokh8cQOyLZyId0WEZU5VZkyTRAMyFkvm7wb6uL54HTqB/mLtHqt0Js+Rfr2bKQvBcuS EfJAWWIcHuivSl8y1wPHvpNjulD5/cH6nPUwBqJjYSHVdK6l1gZvS37DGnbSWsCRfHJH QOUQ== Received: by 10.50.195.234 with SMTP id ih10mr10322523igc.0.1339588281535; Wed, 13 Jun 2012 04:51:21 -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 v20csp18063ibb; Wed, 13 Jun 2012 04:51:19 -0700 (PDT) Received: by 10.180.95.137 with SMTP id dk9mr37230843wib.1.1339588279007; Wed, 13 Jun 2012 04:51:19 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id i63si3799008wem.16.2012.06.13.04.51.17; Wed, 13 Jun 2012 04:51:18 -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 1Sem6W-0000Dk-Hd; Wed, 13 Jun 2012 11:51:16 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Sem6V-0000D3-Be for linaro-mm-sig@lists.linaro.org; Wed, 13 Jun 2012 11:51:16 +0000 Received: from epcpsbgm2.samsung.com (mailout1.samsung.com [203.254.224.24]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M5K003L40X7KH70@mailout1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 13 Jun 2012 20:51:14 +0900 (KST) X-AuditID: cbfee61b-b7fcc6d000003a7a-24-4fd87eb22745 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id BD.95.14970.2BE78DF4; Wed, 13 Jun 2012 20:51:14 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M5K00JMG0WB4X70@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 13 Jun 2012 20:51:14 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 13 Jun 2012 13:50:16 +0200 Message-id: <1339588218-24398-5-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1339588218-24398-1-git-send-email-m.szyprowski@samsung.com> References: <1339588218-24398-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jAd1NdTf8DT5P5bT4cuUhkwOjx+1/ j5kDGKO4bFJSczLLUov07RK4Mr60z2UtOCFbsXHHXLYGxi0SXYwcHBICJhIHLvl2MXICmWIS F+6tZ+ti5OIQEljEKHFgz0NWCGctk0THv7tsIFVsAoYSXW+7wGwRgRmMErv60kCKmAX2sUh0 bj7BCJIQFvCSOHD6HwuIzSKgKtG0+ThYnFfAQ2LpznVMEOvkJZ7e7wMbxCngKfH72T6wuBBQ ze9ph5knMPIuYGRYxSiaWpBcUJyUnmukV5yYW1yal66XnJ+7iRHs9WfSOxhXNVgcYhTgYFTi 4c0ABoMQa2JZcWXuIUYJDmYlEd5n2UAh3pTEyqrUovz4otKc1OJDjNIcLErivE3WF/yFBNIT S1KzU1MLUotgskwcnFINjCG/Nx+raf7xnL+1Y+7NjJi9i4R3MtTskfl0XPjxPYmy5Zs6pVSO 1vubx3T5TZZ3qutdKtTs5P3xiG3F7D8NprFpR2zkK5TLPz6ZEts2cdou6djHW2YuWSXlllpX 8W3/bnZhm2npAT+kVy7fsl5w1o5ZX4vvV2V1v5UKW1+zem3YrAD71kPq3UosxRmJhlrMRcWJ ACodiuf2AQAA X-TM-AS-MML: No Cc: Abhinav Kochhar , Russell King - ARM Linux , Arnd Bergmann , Konrad Rzeszutek Wilk , Benjamin Herrenschmidt , Kyungmin Park , Subash Patel Subject: [Linaro-mm-sig] [PATCHv2 4/6] ARM: dma-mapping: add support for 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: ALoCoQnoVMpeyt1xPQjfPALBkkg7wkW6/SSNkz26R5d3saFbCxJ3ebJ0zEMSoeEboMEarvfFlgPK This patch adds support for dma_get_sgtable() function which is required to let drivers to share the buffers allocated by DMA-mapping subsystem. Generic implementation based on virt_to_page() is not suitable for ARM dma-mapping subsystem. Signed-off-by: Marek Szyprowski Reviewed-by: Kyungmin Park --- arch/arm/common/dmabounce.c | 1 + arch/arm/include/asm/dma-mapping.h | 3 +++ arch/arm/mm/dma-mapping.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 0 deletions(-) diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c index 9d7eb53..1486124 100644 --- a/arch/arm/common/dmabounce.c +++ b/arch/arm/common/dmabounce.c @@ -452,6 +452,7 @@ static struct dma_map_ops dmabounce_ops = { .alloc = arm_dma_alloc, .free = arm_dma_free, .mmap = arm_dma_mmap, + .get_sgtable = arm_dma_get_sgtable, .map_page = dmabounce_map_page, .unmap_page = dmabounce_unmap_page, .sync_single_for_cpu = dmabounce_sync_for_cpu, diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index 80777d87..804bf65 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -280,6 +280,9 @@ extern void arm_dma_sync_sg_for_cpu(struct device *, struct scatterlist *, int, enum dma_data_direction); extern void arm_dma_sync_sg_for_device(struct device *, struct scatterlist *, int, enum dma_data_direction); +extern int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t dma_addr, size_t size, + struct dma_attrs *attrs); #endif /* __KERNEL__ */ #endif diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 5d8b8b2..3840997 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -125,6 +125,7 @@ struct dma_map_ops arm_dma_ops = { .alloc = arm_dma_alloc, .free = arm_dma_free, .mmap = arm_dma_mmap, + .get_sgtable = arm_dma_get_sgtable, .map_page = arm_dma_map_page, .unmap_page = arm_dma_unmap_page, .map_sg = arm_dma_map_sg, @@ -659,6 +660,21 @@ void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, } } +int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t handle, size_t size, + struct dma_attrs *attrs) +{ + struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); + int ret; + + ret = sg_alloc_table(sgt, 1, GFP_KERNEL); + if (unlikely(ret)) + return ret; + + sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0); + return 0; +} + static void dma_cache_maint_page(struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, void (*op)(const void *, size_t, int)) @@ -1171,6 +1187,20 @@ void arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, __iommu_free_buffer(dev, pages, size); } +static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t dma_addr, + size_t size, struct dma_attrs *attrs) +{ + unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; + struct page **pages = __iommu_get_pages(cpu_addr, attrs); + + if (!pages) + return -ENXIO; + + return sg_alloc_table_from_pages(sgt, pages, count, 0, size, + GFP_KERNEL); +} + /* * Map a part of the scatter-gather list into contiguous io address space */ @@ -1430,6 +1460,7 @@ struct dma_map_ops iommu_ops = { .alloc = arm_iommu_alloc_attrs, .free = arm_iommu_free_attrs, .mmap = arm_iommu_mmap_attrs, + .get_sgtable = arm_iommu_get_sgtable, .map_page = arm_iommu_map_page, .unmap_page = arm_iommu_unmap_page,