Subject: virt_to_phys() in drivers w/dma - MPC8xxx

From: "Russell McGuire" <[email-masked]>
Date: Fri, 22 Aug 2008 16:14:28 -0700

A style / function question. I have been seeing conflicting articles and
examples on what the proper method would be for some of the Freescale MPC
drivers. I am putting together an ATM driver, and 'might' be having some
erratic results due to this function. Not sure yet, but wanted to put this
out there for comments.

In many cases when dealing with TxBD or RxBD pointers a UCC or what not
driver will use the virt_to_phys() call to get what I assume is a physical
address that can be used for dma? Perhaps not in all cases, but a majority.
See ucc_geth.c for an example of the usage. I have also seen some prototype
drivers that use this call to get the physical address to place into the
QE_MURAM for the PRAM initialization.

I then ran across this link:

http://mirror.linux.org.au/linux.conf.au/2005/cdrom-beta-1/linux-mandocs-2.6
.12.6/virt_to_phys.html

Which states:

The returned physical address is the physical (CPU) mapping for the memory
address given. It is only valid to use this function on addresses directly
mapped or allocated via kmalloc.  This function does not give bus mappings
for DMA transfers. In almost all conceivable cases a device driver should
not be using this function.
-----------

So shouldn't we be using like dma_alloc_coherent, and then tracking the dma
address separately as a variable, and use it when necessary instead of
calling virt_to_phys()?

Or am I confused on what these are doing?

-Russ