Also have a look at arch/sparc64/kernel/{iommu,pci_iommu}.c for an algorithm which coalesces all possible cases. It is not pretty code but I fully verified it with a userland simulator so it works. Later, David S. Miller davem@redhat.com