On Feb 4, 2011, at 4:14 PM, Timur Tabi wrote:
Is there any official statement on what the minimum alignment is for memory returned by dma_alloc_coherent?
This is dependent upon the particular implementation. There have been several over the history of this API, and some would work out of a DMA pool that would only provide word alignment.
Would anyone have a complaint if I did this: vaddr = dma_alloc_coherent(dev, ssize, &paddr, GFP_DMA | __GFP_ZERO); BUG_ON(paddr & (alignment - 1));
Well, the usual design for anything that requires alignment is that you never assume you get it unless it can be specified, so over allocate as you are doing currently, and then adjust the base address. Or, you could allocate exactly what you want, if it aligns properly you are good to go, and if not release, over allocate, and adjust. The problem with the suggested implementation is the results aren't predictable. Even if the API doesn't guarantee your alignment, you may get it most of the time, but once in a while this may fail. You could test and all looks good, ship something and it fails. Today, this may work fine, but it would be nice to ensure it continues to work in the future. :-)
On a side note, do I really need to pass GFP_DMA ....
The GFP_DMA is architecture dependent. Are you writing a driver to be used across multiple architectures? If it's necessary, I'd document why you are using it (an ISA device on x86 for example) and then let other architectures determine if it's necessary for them. Thanks. -- Dan _______________________________________________ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev