Howto use PPC4xx memory to memory DMA

Alexis Berlemont berlemont.hauw at free.fr
Sat Jan 20 09:32:04 EST 2007


Hi,

I would like to add some comments on this topic, I am very interested by more 
details.

> Here are a few things to check:
>
> 1. Your memory destination and source addresses are contiguous. You can get
> this using something like:
>
> mem = (void*)__get_free_pages(GFP_KERNEL | GFP_DMA, get_order(size));
>
> 2. Your source and dest addresses are _bus_ addresses. You can get these
> by:
>
> source = virt_to_bus((u32 *)mem);

But you must check that your src and dst addresses does not point to 
a "vmallocated" buffer (unless you allocated less than PAGE_SIZE and you know 
how to convert a virtual kernel address into a physical address, for example 
thanks to the function iopa() ). 
Consequently, with a 2.6 kernel, the function virt_to_bus() will not work 
properly on a virtual address.

Consequently, if the dst or the src address belongs to a buffer allocated with 
vmalloc() or ioremap(), you will have to use the function iopa() to perform 
the translation.

Besides, I have a question : I do not understand why the 2.6 implementation of 
the function virt_to_bus() is different from the 2.4 version; 
->on 2.4, virt_to_bus() calls iopa() (if CONFIG_PPC4xx is defined),therefore 
it works with virtual addresses (vmallocated or ioremapped);
->on 2.6, virt_to_bus works with logical address (kmallocated or 
get_free_pages);

Do you know why ?

> Ooh - and the 3d thing - cache coherence. I.e.:
>
>       dma_cache_inv((u32)mem, (u32)nBytes);
>

I just add a little precision:

With PPC405 (no cache coherency integrated), you have to invalidate the cache 
of the destination buffer (with dma_cache_inv() )and you have to write back 
the cache of the source buffer (with dma_cache_wback() ). But if you do not 
want to care about the direction point, you can use dma_cache_inv_wback() 
which does both operations.

Of course, if you work with an "ioremapped" area (either as source or 
destination buffer), this functions are useless for this buffer (ioremap() 
maps the address range with the flag "PAGE_NO_CACHE").

>
>
> Also, we had some trouble with the ppc4xx_ functions using 440 - it seems
> these functions are specific to the PLB4. So if you are trying to do DMA on
> say the PLB peripheral bus on a memory mapped device, you definitely have
> some trouble.

I do not understand, I would be very interested by what kind of trouble you 
had to cope with.

Alexis.



More information about the Linuxppc-embedded mailing list