[PATCH 2/3] x86: set gfp flag properly for swiotlb_alloc_coherent

From: FUJITA Tomonori
Date: Wed Sep 03 2008 - 14:15:33 EST


This tries to avoid GFP_DMA zone unless absolutely needed (and set gfp
flag to use GFP_DMA zone properly if necessary).

Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx>
---
arch/x86/kernel/pci-swiotlb_64.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/pci-swiotlb_64.c b/arch/x86/kernel/pci-swiotlb_64.c
index f3d8d0e..3f4d9b4 100644
--- a/arch/x86/kernel/pci-swiotlb_64.c
+++ b/arch/x86/kernel/pci-swiotlb_64.c
@@ -23,11 +23,29 @@ swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size,
static void *x86_swiotlb_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp)
{
+ unsigned long dma_mask;
+
+ gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
+
if (!dev) {
dev = &x86_dma_fallback_dev;
gfp |= GFP_DMA;
}

+ if (!dev->dma_mask)
+ return NULL;
+
+ dma_mask = dev->coherent_dma_mask;
+ if (!dma_mask)
+ dma_mask = gfp & GFP_DMA ? DMA_24BIT_MASK : DMA_32BIT_MASK;
+
+ if (!(gfp & GFP_DMA)) {
+ if (dma_mask <= DMA_24BIT_MASK)
+ gfp |= GFP_DMA;
+ else if (dma_mask <= DMA_32BIT_MASK)
+ gfp |= GFP_DMA32;
+ }
+
return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
}

--
1.5.5.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/