From patchwork Wed Jun 13 11:50:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9266 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 98D7423E53 for ; Wed, 13 Jun 2012 11:51:25 +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 67E66A18478 for ; Wed, 13 Jun 2012 11:51:25 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so293612ghb.11 for ; Wed, 13 Jun 2012 04:51:25 -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=3wR6O55XA19GMGVjS9/OEs6o2s3tqLGbdm3WPRrBcGM=; b=RtdjkjvF1KDRGYnLShBNBbmusJBYrytY/8LkGlbUrzK+nWz8UOvY7LJxlR6AuJCTct YwwYR9q09X6sIyfm+T5ZvFUbkWhnUaf2xzirLRHvFSRiFdWdLqAmppKlal5nwSTsVELZ 27JO2qzVdt2mJLUwd+Y7nNxt/R9PGjeMS1yj8TnmStx2u22hkB/gUxvlfnbOpxLFcRYy HE6BWS9fV6a5ZO9jAaDdp1IcZOLUNR74lO/gdnWJLmNaenPTIkGebcfj1jXWvlh+6Vn/ /Jsdf7Js570YyVJ68s/NU92UF1Wiy2hODIM5anMVXvaNDX/WbyIHPlPsVIBkE1ZaB2Oj pAKQ== Received: by 10.50.203.39 with SMTP id kn7mr10167197igc.53.1339588282691; Wed, 13 Jun 2012 04:51:22 -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 v20csp18070ibb; Wed, 13 Jun 2012 04:51:21 -0700 (PDT) Received: by 10.204.136.197 with SMTP id s5mr13780767bkt.21.1339588281377; Wed, 13 Jun 2012 04:51:21 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id go20si1339894bkc.145.2012.06.13.04.51.19; Wed, 13 Jun 2012 04:51:21 -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 1Sem6Y-0000F4-SO; Wed, 13 Jun 2012 11:51:18 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Sem6X-0000Dj-1F for linaro-mm-sig@lists.linaro.org; Wed, 13 Jun 2012 11:51:17 +0000 Received: from epcpsbgm1.samsung.com (mailout2.samsung.com [203.254.224.25]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M5K006RT0WJQY80@mailout2.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 13 Jun 2012 20:51:07 +0900 (KST) X-AuditID: cbfee61a-b7f9f6d0000016a8-b4-4fd87eaa6fc9 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 89.59.05800.AAE78DF4; Wed, 13 Jun 2012 20:51:07 +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:06 +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:15 +0200 Message-id: <1339588218-24398-4-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+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jAd3VdTf8DV6dY7P4cuUhkwOjx+1/ j5kDGKO4bFJSczLLUov07RK4MlpXv2QrOCZXsevJGtYGxuWSXYycHBICJhJ9++czQ9hiEhfu rWcDsYUEFjFKfFxt08XIBWSvZZK4f2cGE0iCTcBQouttF1iRiMAMRoldfWkgRcwC+1gkOjef YOxi5OAQFgiQaDrHClLDIqAqsfrHb7B6XgEPieWfdrNDLJOXeHq/DyzOKeAp8fvZPiaIxR4S v6cdZp7AyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRrDPn0ntYFzZYHGIUYCDUYmH d0PRDX8h1sSy4srcQ4wSHMxKIrzPsoFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeZusL/gLCaQn lqRmp6YWpBbBZJk4OKUaGAvmS+nEte+42MeVuFLc+u2TiNRFpx6/dDz9QCj4+aS891lyP+ft rTmTYy1zXM7+67G3TkffVt9beynOWNndLWJTpb7rmWaPi9c4uB9XXE+s27hD6u+VH3FBgQwb rDxOPcmp85rudefdj7DAVc+KJ9Sd4JW8dSFAucNHjqOP+f3Z6knzTsjNUFFiKc5INNRiLipO BAAg1e7f9QEAAA== 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 3/6] common: dma-mapping: introduce dma_get_sgtable() function 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: ALoCoQkIukwI9T9QnuiFshk6+RlHidJLXxEsvbKnhY/7fH82EZbWYY0grs6oS8MeQ+FqfB8C5mGL This patch adds dma_get_sgtable() function which is required to let drivers to share the buffers allocated by DMA-mapping subsystem. Right now the driver gets a dma address of the allocated buffer and the kernel virtual mapping for it. If it wants to share it with other device (= map into its dma address space) it usually hacks around kernel virtual addresses to get pointers to pages or assumes that both devices share the DMA address space. Both solutions are just hacks for the special cases, which should be avoided in the final version of buffer sharing. To solve this issue in a generic way, a new call to DMA mapping has been introduced - dma_get_sgtable(). It allocates a scatter-list which describes the allocated buffer and lets the driver(s) to use it with other device(s) by calling dma_map_sg() on it. This patch provides a generic implementation based on virt_to_page() call. Architectures which require more sophisticated translation might provide their own get_sgtable() methods. Signed-off-by: Marek Szyprowski Reviewed-by: Kyungmin Park Reviewed-by: Daniel Vetter --- drivers/base/dma-mapping.c | 18 ++++++++++++++++++ include/asm-generic/dma-mapping-common.h | 18 ++++++++++++++++++ include/linux/dma-mapping.h | 3 +++ 3 files changed, 39 insertions(+), 0 deletions(-) diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 6f3676f..49785c1 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -217,4 +217,22 @@ void dmam_release_declared_memory(struct device *dev) } EXPORT_SYMBOL(dmam_release_declared_memory); +/* + * Create scatter-list for the already allocated DMA buffer. + */ +int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t handle, size_t size) +{ + struct page *page = virt_to_page(cpu_addr); + 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; +} +EXPORT_SYMBOL(dma_common_get_sgtable); + #endif diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h index 2e248d8..34841c6 100644 --- a/include/asm-generic/dma-mapping-common.h +++ b/include/asm-generic/dma-mapping-common.h @@ -176,4 +176,22 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL) #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL) +int +dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t dma_addr, size_t size); + +static inline int +dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr, + dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs) +{ + struct dma_map_ops *ops = get_dma_ops(dev); + BUG_ON(!ops); + if (ops->get_sgtable) + return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size, + attrs); + return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size); +} + +#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL) + #endif diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index dfc099e..94af418 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -18,6 +18,9 @@ struct dma_map_ops { int (*mmap)(struct device *, struct vm_area_struct *, void *, dma_addr_t, size_t, struct dma_attrs *attrs); + int (*get_sgtable)(struct device *dev, struct sg_table *sgt, void *, + dma_addr_t, size_t, struct dma_attrs *attrs); + dma_addr_t (*map_page)(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir,