Subject: 64 bit DMA tags for PCI
To: None <>
From: Frank van der Linden <>
List: tech-kern
Date: 05/11/2003 19:02:14

In order to avoid bounce buffers on machines with more than 4G of ram,
we need a way to specify that a platform is capable of doing DMA to/from
addresses that are 64 bits wide. The easiest way is to encode this in
the DMA tag. It's been suggested before to add a pa_dmat64 to the PCI
attach args, and I agree that this is a good way to do it, short of
more invasive changes to the bus_dma interface.

The above isn't hard to implement, but I'm undecided about some issues.
A device driver knows if a device is capable of 64bit DMA. Some devices
need to be explicitly told to do so, and use seperate data structures
for it. Others, like wm(4) and bge(4), simply always deal with 64bit
addresses. The driver must make a decision to use 64bit DMA addressing
or not; for a 32bit platform it may not be worth switching on because
of extra overhead.

The following are possible

	* Always have the 32bit and 64bit tag point to valid DMA tags,
	  but have them possibly be the same. This means that a device
	  driver can always pick the 64bit one, but may have some overhead
	  for using wider data structures, etc.

	* Define a PCI_DMA_NO_TAG value, assigned to the 64bit tag if
	  64bit PCI DMA is not available on this platform. Have the
	  driver check for it, and only use the 64bit tag if it's
	  != PCI_DMA_NO_TAG. Even then, you may still do a bit too
	  much work, as you may have a system that can do 64bit DMA
	  addressing, but has less than 4G of memory.

	* Define a function like pci_dma64_available(pa), that makes
	  a platform-specific decision about the use/need for
	  64bit DMA addressing. A default version would be:

	int pci_dma64_available(struct pci_attach_args *pa)
		if (sizeof(bus_addr_t) >= 8 &&
		    pa->pa_dmat64 != PCI_DMA_NO_TAG &&
		    (uint64_t)physmem > 0xffffffffULL)
			return 1;
		return 0;


- Frank

Frank van der Linden                          
---------------------- -------------------------
NetBSD development                                     Embedded, Storage, other