> Because as DaveM pointed out, some hardware can't do it, and as I said
> earlier, it's a lot cheaper and easier for driver writers to just
> store the extra pointer in their data structures than it is to
> implement a database to maintain it.
For some devices yes, for others storing the extra pointer doesn't
help all that much. Devices which can complete requests out of order
and which tell you the DMA addresses of the requests they have
completed would be in the second class, and that includes the OHCI USB
controller, and some intelligent SCSI controllers I believe.
So you end up having to map the DMA address back to the pointer to the
data structure for the request. At the moment the drivers that need
this each have their own implementation, using a hash table or
The argument for supplying this functionality in the PCI DMA code
would be that if it was done there it could be done once, and in a
sophisticated and efficient (and SMP-safe :) fashion, rather than
ad-hoc in each driver.
It may also be possible for the PCI DMA code to take advantage of its
knowledge of a particular platform, for example if the platform only
has a small range of possible DMA addresses then it could use a simple
and fast lookup table. Or it may be possible to read the IOMMU tables
on some platforms and do the reverse mapping quickly that way - this
would certainly be the case for the IBM RS/6000 machines since the
IOMMU tables are in system RAM.
> Remember you often need this address in the hot path (say TX interrupt
> handler) so you don't want to introduce any unnecessary function calls.
The drivers that need this would already be doing internal function
calls to do the reverse mapping anyway. Of course we would not want
this functionality to add extra overhead at the point where we set up
the mapping (at least in the cases where we won't need the reverse
There is a question though as to whether a reverse mapping from DMA
address to virtual address is sufficient for these drivers, or whether
they would need a mapping from DMA address to something else such as a
pointer to a request structure. The usb-ohci driver looks like it
would be sufficient to get back to the virtual address.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to firstname.lastname@example.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/