Skip to contentSkip to conversation

use dev DMA masks in dma_alloc_coherent

PATCH New Siddha, Suresh B 1 participant 1 message Aug 18, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use dev DMA masks in dma_alloc_coherent

64bit devices (whose dma_mask and coherent_dma_mask are set to 64bits) can use MEMZONE_DOM while creating contiguous_region for coherent mappings.

Please apply the appended patch.

linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c +8 -2
diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c
@@ -129,6 +129,7 @@
 	struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
 	unsigned int order = get_order(size);
 	unsigned long vstart;
+	unsigned long dma_mask = 0;
 	/* ignore region specifiers */
 	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
 
@@ -145,13 +146,18 @@
 			return NULL;
 	}
 
-	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
-		gfp |= GFP_DMA;
+	if (!dev)
+		dma_mask = 0xffffffff;
+	else
+		/* Kludge to make it bug-to-bug compatible with i386. i386
+		   uses the normal dma_mask for alloc_coherent. */
+		dma_mask = dev->coherent_dma_mask & *dev->dma_mask;
 
 	vstart = __get_free_pages(gfp, order);
 	ret = (void *)vstart;
 
 	if (ret != NULL) {
+		order |= (dma_mask <= 0xffffffff) ? (32 << 8) : 0;
 		xen_create_contiguous_region(vstart, order);
 
 		memset(ret, 0, size);
linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c +1 -1
diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c
@@ -131,7 +131,7 @@
 
 	xen_create_contiguous_region(
 		(unsigned long)io_tlb_start, 
-		get_order(io_tlb_nslabs * (1 << IO_TLB_SHIFT)));
+		get_order(io_tlb_nslabs * (1 << IO_TLB_SHIFT)) | (32 << 8));
 
 	io_tlb_end = io_tlb_start + io_tlb_nslabs * (1 << IO_TLB_SHIFT);
 
linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c +1 -1
diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c
@@ -294,7 +294,7 @@
 
     /* 2. Get a new contiguous memory extent. */
     BUG_ON(HYPERVISOR_dom_mem_op(
-	       MEMOP_increase_reservation, &mfn, 1, order | (32<<8)) != 1);
+	       MEMOP_increase_reservation, &mfn, 1, order) != 1);
 
     /* 3. Map the new extent in place of old pages. */
     for (i = 0; i < (1<<order); i++) {
linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c +1 -1
diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c
@@ -277,7 +277,7 @@
 
 #ifdef CONFIG_X86_PAE
 	/* this gives us a page below 4GB */
-	xen_create_contiguous_region((unsigned long)pgd, 0);
+	xen_create_contiguous_region((unsigned long)pgd, 0 | (32 << 8));
 #endif
 
 	if (!HAVE_SHARED_KERNEL_PMD)