mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@hp.com>
To: dwmw2@infradead.org
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, alex.williamson@hp.com
Subject: [PATCH 1/5] dma: create dma_generic_alloc/free_coherent()
Date: Mon, 26 Oct 2009 17:24:58 -0600	[thread overview]
Message-ID: <20091026232458.9646.36818.stgit@nehalem.aw> (raw)
In-Reply-To: <20091026232401.9646.90540.stgit@nehalem.aw>

Move dma_generic_alloc_coherent() out of x86 code and create
corresponding dma_generic_free_coherent() for symmetry.  These
can then be used by IOMMU drivers attempting to implement
passthrough mode.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
---

 arch/x86/include/asm/dma-mapping.h |    3 --
 arch/x86/kernel/pci-dma.c          |   31 -------------------------
 arch/x86/kernel/pci-nommu.c        |   10 +++++++-
 include/linux/dma-mapping.h        |   44 ++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 0ee770d..e6d2c9f 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -52,9 +52,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 extern int dma_supported(struct device *hwdev, u64 mask);
 extern int dma_set_mask(struct device *dev, u64 mask);
 
-extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
-					dma_addr_t *dma_addr, gfp_t flag);
-
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
 {
 	if (!dev->dma_mask)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index b2a71dc..ecd9df0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -144,37 +144,6 @@ void __init pci_iommu_alloc(void)
 	pci_swiotlb_init();
 }
 
-void *dma_generic_alloc_coherent(struct device *dev, size_t size,
-				 dma_addr_t *dma_addr, gfp_t flag)
-{
-	unsigned long dma_mask;
-	struct page *page;
-	dma_addr_t addr;
-
-	dma_mask = dma_alloc_coherent_mask(dev, flag);
-
-	flag |= __GFP_ZERO;
-again:
-	page = alloc_pages_node(dev_to_node(dev), flag, get_order(size));
-	if (!page)
-		return NULL;
-
-	addr = page_to_phys(page);
-	if (addr + size > dma_mask) {
-		__free_pages(page, get_order(size));
-
-		if (dma_mask < DMA_BIT_MASK(32) && !(flag & GFP_DMA)) {
-			flag = (flag & ~GFP_DMA32) | GFP_DMA;
-			goto again;
-		}
-
-		return NULL;
-	}
-
-	*dma_addr = addr;
-	return page_address(page);
-}
-
 /*
  * See <Documentation/x86_64/boot-options.txt> for the iommu kernel parameter
  * documentation.
diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
index a3933d4..ed9e12e 100644
--- a/arch/x86/kernel/pci-nommu.c
+++ b/arch/x86/kernel/pci-nommu.c
@@ -73,10 +73,16 @@ static int nommu_map_sg(struct device *hwdev, struct scatterlist *sg,
 	return nents;
 }
 
+static void *nommu_alloc_coherent(struct device *dev, size_t size,
+				  dma_addr_t *dma_addr, gfp_t flag)
+{
+	return dma_generic_alloc_coherent(dev, size, dma_addr, flag);
+}
+
 static void nommu_free_coherent(struct device *dev, size_t size, void *vaddr,
 				dma_addr_t dma_addr)
 {
-	free_pages((unsigned long)vaddr, get_order(size));
+	dma_generic_free_coherent(dev, size, vaddr, dma_addr);
 }
 
 static void nommu_sync_single_for_device(struct device *dev,
@@ -95,7 +101,7 @@ static void nommu_sync_sg_for_device(struct device *dev,
 }
 
 struct dma_map_ops nommu_dma_ops = {
-	.alloc_coherent		= dma_generic_alloc_coherent,
+	.alloc_coherent		= nommu_alloc_coherent,
 	.free_coherent		= nommu_free_coherent,
 	.map_sg			= nommu_map_sg,
 	.map_page		= nommu_map_page,
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 91b7618..285043c 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -232,4 +232,48 @@ struct dma_attrs;
 
 #endif /* CONFIG_HAVE_DMA_ATTRS */
 
+static inline void *dma_generic_alloc_coherent(struct device *dev, size_t size,
+					       dma_addr_t *dma_addr, gfp_t flag)
+{
+	unsigned long dma_mask;
+	struct page *page;
+	dma_addr_t addr;
+
+	dma_mask = dev->coherent_dma_mask;
+	if (!dma_mask) {
+#ifdef CONFIG_ISA
+		dma_mask = (flag & GFP_DMA) ? DMA_BIT_MASK(24)
+		                            : DMA_BIT_MASK(32);
+#else
+		dma_mask = DMA_BIT_MASK(32);
+#endif
+	}
+
+	flag |= __GFP_ZERO;
+again:
+	page = alloc_pages_node(dev_to_node(dev), flag, get_order(size));
+	if (!page)
+		return NULL;
+
+	addr = page_to_phys(page);
+	if (addr + size > dma_mask) {
+		__free_pages(page, get_order(size));
+
+		if (dma_mask < DMA_BIT_MASK(32) && !(flag & GFP_DMA)) {
+			flag = (flag & ~GFP_DMA32) | GFP_DMA;
+			goto again;
+		}
+
+		return NULL;
+	}
+
+	*dma_addr = addr;
+	return page_address(page);
+}
+
+static inline void dma_generic_free_coherent(struct device *dev, size_t size,
+					     void *vaddr, dma_addr_t dma_addr)
+{
+	free_pages((unsigned long)vaddr, get_order(size));
+}
 #endif


  reply	other threads:[~2009-10-26 23:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26 23:24 [PATCH 0/5] intel-iommu fixes Alex Williamson
2009-10-26 23:24 ` Alex Williamson [this message]
2009-10-27  0:57   ` [PATCH 1/5] dma: create dma_generic_alloc/free_coherent() Paul Mundt
2009-10-27  2:26     ` Alex Williamson
2009-10-27  1:47   ` FUJITA Tomonori
2009-10-26 23:25 ` [PATCH 2/5] intel-iommu: Use dma_generic_alloc_coherent() for passthrough mappings Alex Williamson
2009-10-27  3:24   ` [PATCH v2 2/5] intel-iommu: Obey coherent_dma_mask for alloc_coherent on passthrough Alex Williamson
2009-10-26 23:25 ` [PATCH 3/5] intel-iommu: Use max_pfn to determine whether a device can passthrough Alex Williamson
2009-10-26 23:25 ` [PATCH 4/5] intel-iommu: Reinstate RMRRs if a device is removed from passthrough domain Alex Williamson
2009-10-27  8:15   ` David Woodhouse
2009-10-27 15:50     ` Alex Williamson
2009-10-28 14:36       ` David Woodhouse
2009-10-28 16:06         ` Alex Williamson
2009-10-28 20:35           ` Alex Williamson
2009-10-26 23:25 ` [PATCH 5/5] intel-iommu: Quiet unnecessary output Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091026232458.9646.36818.stgit@nehalem.aw \
    --to=alex.williamson@hp.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome