Re: how to get virtual address from dma address

From: James Bottomley (James.Bottomley@HansenPartnership.com)
Date: Thu Oct 04 2001 - 10:37:37 EST


davem@redhat.com said:
> I know of hardware where doing the reverse mapping would not even be
> possible, the page tables are in hardware registers and are "write
> only". This means you can't even read the PTEs back, you'd have to
> keep track of them in software and that is totally unacceptable
> overhead when it won't even be used %99 of the time.

> The DMA API allows us to support such hardware cleanly and
> efficiently, but once we add this feature which "everyone absolutely
> needs" we have a problem with the above mentioned piece of hardware.

Walking the iommu page tables was only a suggestion of how it should be done.
I'm not advocating providing this as a generic feature of the iommu handling
software, but as an API.

What's wrong with implementing a separate API, like

pci_register_mapping(struct pci_dev *dev, void *virtualAddress, dma_addr_t
dmaAddress, size_t size);
void *pci_dma_to_virtual(struct pci_dev *dev, dma_addr_t dmaAddress);
pci_unregister_mapping(struct pci_dev *dev, void *virtualAddress, dma_addr_t
dmaAddress, size_t size);

?

That way, the driver will only ask for translations of addresses it knows its
going to have difficulty with, so there's no overhead in the general mapping
case where you don't request registration for a mapping lookup.

For an IOMMU with readable page tables, you can chose to implement the
register/unregister as nops and do the pci_dma_to_virtual as a PTE walk. For
the really recalcitrant iommu hardware, you only save the mapping tables (or
more likely just the mappings in a hash lookup table) when requested to.

This has the dual benefits of being completely backwards convertible from the
old bus_to_virt et al. scheme and requiring no overhead unless the driver
actually asks for it.

James Bottomley

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Oct 07 2001 - 21:00:32 EST