linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Eugene Surovegin <ebs@ebshome.net>
To: Alexis Berlemont <berlemont.hauw@free.fr>
Cc: linuxppc-embedded@ozlabs.org
Subject: Re: Howto use PPC4xx memory to memory DMA
Date: Sun, 21 Jan 2007 11:47:40 -0800	[thread overview]
Message-ID: <20070121194740.GA6339@gate.ebshome.net> (raw)
In-Reply-To: <200701192332.05156.berlemont.hauw@free.fr>

On Fri, Jan 19, 2007 at 11:32:04PM +0100, Alexis Berlemont wrote:
> 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 ?

virt_to_bus was never supposed to work on anything else except for 
directly mapped kernel address. 2.6 version just fixes this for 4xx. 
And yes, virt_to_bus is deprecated.


> 
> > 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").

Guys, please stop reinventing the wheel. There is a documented kernel 
API which takes care of coherency issues and it should be used for any 
sort of DMA (be it general purpose DMA controller or external 
DMA-capable device).

PLEASE, read Documentation/DMA-API.txt and use it to obtain DMA-able 
address for your buffer.

-- 
Eugene

  reply	other threads:[~2007-01-21 19:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-19 22:32 Howto use PPC4xx memory to memory DMA Alexis Berlemont
2007-01-21 19:47 ` Eugene Surovegin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-01-07 10:57 padmanabha
2007-01-19  9:35 - Reyneke
2007-01-19 20:47 ` Niklaus Giger
2007-01-19  8:49 - Reyneke
2007-01-19 19:48 ` T Ziomek
2007-01-21 21:28   ` - Reyneke
2007-01-22 17:18     ` Eugene Surovegin
2007-01-18 22:16 Niklaus Giger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070121194740.GA6339@gate.ebshome.net \
    --to=ebs@ebshome.net \
    --cc=berlemont.hauw@free.fr \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).