Re: [discuss] Re: 32-bit dma allocations on 64-bit platforms

From: Takashi Iwai
Date: Fri Jun 25 2004 - 10:53:36 EST


At Thu, 24 Jun 2004 20:44:47 +0200,
Andrea Arcangeli wrote:
>
> On Thu, Jun 24, 2004 at 08:33:02PM +0200, Takashi Iwai wrote:
> > Sure, in extreme cases, it can't work. But at least, it _may_ work
> > better than using only GFP_DMA. And indeed it should (still) work
> > on most of consumer PC boxes. The addition of another zone would help
> > much better, though.
>
> of course agreed.

The below is the new patch to follow your advice.


thanks,

Takashi

--- linux-2.6.7/arch/i386/kernel/pci-dma.c-dist 2004-06-24 15:56:46.017473544 +0200
+++ linux-2.6.7/arch/i386/kernel/pci-dma.c 2004-06-25 17:43:42.509366917 +0200
@@ -23,11 +23,22 @@ void *dma_alloc_coherent(struct device *
if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
gfp |= GFP_DMA;

+ again:
ret = (void *)__get_free_pages(gfp, get_order(size));

- if (ret != NULL) {
+ if (ret == NULL) {
+ if (dev && (gfp & GFP_DMA)) {
+ gfp &= ~GFP_DMA;
+ goto again;
+ }
+ } else {
memset(ret, 0, size);
*dma_handle = virt_to_phys(ret);
+ if (!(gfp & GFP_DMA) &&
+ (((unsigned long)*dma_handle + size - 1) & ~(unsigned long)dev->coherent_dma_mask)) {
+ free_pages((unsigned long)ret, get_order(size));
+ return NULL;
+ }
}
return ret;
}
-
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/