driver replacements for kmalloc and __pa()
Hello,
We have inherited an older driver that uses kmalloc() and vtophys (which resolves to the __pa() macro) to create memory accessible by an external PCI device doing bus master read/writes. The driver works Ok on several x86 machines, but is failing on a PPC board (MPC7447/8) running Gentoo Linux 2.6.9. After looking at PCI bus analyzer captures, it seems the physical address the driver is giving to the PCI device is invalid, so the device ends up reading/writing incorrect memory areas.
What are the up-to-date APIs we should be using for DMA memory allocation and virtual-to-physical address translation? We have another driver for another device that's working fine on this board and it uses pci_alloc_consistent(). What about bus_space_vaddr()? I'm hoping to get a recommendation for what's currently appropriate and most future-proof for drivers that depend on external PCI DMA.
Any suggestions welcome. Thanks.
-Jeff
Quoted 5 lines · Jeff Brower
What are the up-to-date APIs we should be using for DMA memory allocation and virtual-to-physical address translation? We have another driver for another device that's working fine on this board and it uses
pci_alloc_consistent(). What aboutbus_space_vaddr()? I'm hoping to get a recommendation for what's currently appropriate and most future-proof for drivers that depend on external PCI DMA.
Documentation/DMA-API.txt.
-Scott
Scott-
Quoted 7 lines
Quoted 5 lines
What are the up-to-date APIs we should be using for DMA memory allocation and virtual-to-physical address translation? We have another driver for another device that's working fine on this board and it uses
pci_alloc_consistent(). What aboutbus_space_vaddr()? I'm hoping to get a recommendation for what's currently appropriate and most future-proof for drivers that depend on external PCI DMA.
Documentation/DMA-API.txt.
Thanks very much Scott. It appears that dma_alloc_coherent() is the recommended path. Is there a good reason to use this instead of pci_alloc_consistent()? I can find comments about using the GFP_KERNEL flag with dma_alloc_coherent(), which is supposed to help when the system is low on memory. But we wouldn't expect that to occur in a situation where the driver is loaded/initialized at boot-time.
-Jeff