32bit pointer in 64bit kernel code

Todd Inglett tinglett at vnet.ibm.com
Sat Aug 3 01:52:39 EST 2002


On Fri, 2002-08-02 at 04:28, Armin Schindler wrote:
> I want to port a PCI card driver to be 64bit compatible and my current
> problem is how to tell the cross gcc to produce 32bit pointers.

Well, by "pointer" I assume you really mean a PCI bus address (or "DMA
address").  Remember that system memory addresses (what I would call a
"pointer") and PCI bus addresses are two different address spaces.  What
confuses the issue is that 32-bit machines (mainly PCs) have a
one-to-one mapping between these spaces, so you may be working with a
driver that has made this mistake.

In Linux you should use the "dma_addr_t"  as your data type for these
addresses (it is a 32-bit value by PCI definition).  You will need to
use the pci mapping functions to map between system memory addresses
(i.e. "pointers") and dma_addr_t.  These are declared in <linux/pci.h>.

The simplest such function is pci_alloc_consistent(dev, size, &bus_addr)
which will allocate "size" bytes of system memory and return its address
and it will also create the mapping for the given PCI device and return
the bus_addr (dma_addr_t).

If you are doing this on the fly with memory you have already allocated
you can use other pci mapping functions.  See
Documentation/DMA-mapping.txt for all the details.

Finally, note that bus_to_virt() and virt_to_bus() are not implemented
on ppc64 (nor on sparc64).  These functions are gone in the 2.5 kernel
anyway.  If you need to translate system addresses vs. bus addresses for
mappings you have made, you need to keep track of the address pairs.
This is rare in existing drivers but, if I recall, the SCSI middle layer
does it.

-todd


** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list