public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb
@ 2008-09-03 15:03 Joerg Roedel
  2008-09-03 18:04 ` [PATCH 0/3] fix swiotlb allocation gfp flag FUJITA Tomonori
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Joerg Roedel @ 2008-09-03 15:03 UTC (permalink / raw)
  To: mingo, tglx, hpa
  Cc: linux-kernel, iommu, Joerg Roedel, KAMEZAWA Hiroyuki, tony.luck

The SWIOTLB version of dma_alloc_coherent allocates all memory with
GFP_DMA unconditionally. This leads sometimes unnecessary to allocation
failures. This patch makes the allocation strategy to use the DMA32 zone
first if this is possible. The changes are boot tested on AMD64 and
compile tested for i386 and IA64.

Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: tony.luck@intel.com
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 lib/swiotlb.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 977edbd..6ba077f 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -466,13 +466,24 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 	dma_addr_t dev_addr;
 	void *ret;
 	int order = get_order(size);
+	unsigned long dma_mask;
 
-	/*
-	 * XXX fix me: the DMA API should pass us an explicit DMA mask
-	 * instead, or use ZONE_DMA32 (ia64 overloads ZONE_DMA to be a ~32
-	 * bit range instead of a 16MB one).
-	 */
-	flags |= GFP_DMA;
+	if (hwdev->dma_mask == NULL)
+		return NULL;
+
+	flags &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
+	flags |= __GFP_ZERO;
+
+	dma_mask = hwdev->coherent_dma_mask;
+	if (!dma_mask)
+		dma_mask = *(hwdev->dma_mask);
+
+	if (dma_mask <= ISA_DMA_THRESHOLD)
+		flags |= GFP_DMA;
+#ifdef CONFIG_X86_64
+	else if (dma_mask <= DMA_32BIT_MASK)
+		flags |= GFP_DMA32;
+#endif
 
 	ret = (void *)__get_free_pages(flags, order);
 	if (ret && address_needs_mapping(hwdev, virt_to_bus(ret))) {
-- 
1.5.3.7



^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2008-09-04 12:52 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-03 15:03 [PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb Joerg Roedel
2008-09-03 18:04 ` [PATCH 0/3] fix swiotlb allocation gfp flag FUJITA Tomonori
2008-09-03 18:04   ` [PATCH 1/3] x86: remove the NULL device hack in dma-mapping.h FUJITA Tomonori
2008-09-03 18:04     ` [PATCH 2/3] x86: set gfp flag properly for swiotlb_alloc_coherent FUJITA Tomonori
2008-09-03 18:04       ` [PATCH 3/3] swiotlb: use GFP_DMA32 instead of GFP_DMA in swiotlb_alloc_coherent FUJITA Tomonori
2008-09-03 20:05         ` Joerg Roedel
2008-09-04  4:11           ` FUJITA Tomonori
2008-09-03 18:54     ` [PATCH 1/3] x86: remove the NULL device hack in dma-mapping.h FUJITA Tomonori
2008-09-03 20:01     ` Joerg Roedel
2008-09-04  4:11       ` FUJITA Tomonori
2008-09-04 10:00         ` Joerg Roedel
2008-09-04 12:50           ` FUJITA Tomonori
2008-09-03 18:05 ` [PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb FUJITA Tomonori
2008-09-03 19:54   ` Joerg Roedel
2008-09-03 20:11     ` Joerg Roedel
2008-09-04  4:11     ` FUJITA Tomonori
2008-09-03 22:09 ` Andi Kleen
2008-09-04  4:11   ` FUJITA Tomonori
2008-09-04  7:44     ` Andi Kleen
2008-09-04  7:58       ` FUJITA Tomonori
2008-09-04  8:05         ` Andi Kleen
2008-09-04  8:18           ` FUJITA Tomonori
2008-09-04  8:31             ` Andi Kleen
2008-09-04  9:49               ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox