Problems with dma_alloc_coherent()
John Whitney
jwhitney-linuxppc at sands-edge.com
Fri Apr 2 01:59:56 EST 2004
In the process of reworking my Generic DMA core for the 2.6 kernel, I
noticed that dma_alloc_coherent() returns NULL in all cases on a
cache-coherent platform. Instead, I think it would be better if this
routine returned a block of contiguous memory (not cache-inhibited), as
pci_alloc_consistent() does.
To that end, I am submitting the attached patch which modifies
dma_alloc_coherent() and dma_free_coherent() to do just this for
cache-coherent platforms.
I was going to add a check for dev->dma_mask in dma_alloc_coherent()
(to add GFP_DMA to the flags), but the dma_supported() macro always
returns 1, which would indicate that this is superfluous.
John
--- dma-mapping.h.orig 2004-04-01 10:38:33.000000000 -0500
+++ dma-mapping.h 2004-04-01 10:49:32.000000000 -0500
@@ -35,7 +35,18 @@
return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
#endif
- return consistent_alloc(flag, size, dma_handle);
+#ifdef CONFIG_NOT_COHERENT_CACHE
+ return consistent_alloc(flag, size, dma_handle);
+#else
+ void *ret;
+
+ ret = (void *)__get_free_pages(flag, get_order(size));
+ if (ret != NULL) {
+ *dma_handle = virt_to_bus(ret);
+ }
+
+ return ret;
+#endif /* CONFIG_NOT_COHERENT_CACHE */
}
static inline void
@@ -49,7 +60,11 @@
}
#endif
- consistent_free(vaddr);
+#ifdef CONFIG_NOT_COHERENT_CACHE
+ consistent_free(vaddr, size);
+#else
+ free_pages((unsigned long)vaddr, get_order(size));
+#endif
}
static inline dma_addr_t
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dma-mapping.h.patch
Type: application/octet-stream
Size: 791 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20040401/a369a1fb/attachment.obj>
More information about the Linuxppc-dev
mailing list