AMD IOMMU: add domain address lookup function for IOMMU API
authorJoerg Roedel <joerg.roedel@amd.com>
Tue, 2 Dec 2008 19:05:50 +0000 (20:05 +0100)
committerJoerg Roedel <joerg.roedel@amd.com>
Sat, 3 Jan 2009 13:11:56 +0000 (14:11 +0100)
Impact: add a generic function to lockup addresses in protection domains

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
arch/x86/kernel/amd_iommu.c

index d8a0abf423bab7c111d6c0575afb936068bd2bff..b599e80051fc5df8c159b114889ba8ae4dedb55e 100644 (file)
@@ -1788,4 +1788,35 @@ static void amd_iommu_unmap_range(struct iommu_domain *dom,
        iommu_flush_domain(domain->id);
 }
 
+static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
+                                         unsigned long iova)
+{
+       struct protection_domain *domain = dom->priv;
+       unsigned long offset = iova & ~PAGE_MASK;
+       phys_addr_t paddr;
+       u64 *pte;
+
+       pte = &domain->pt_root[IOMMU_PTE_L2_INDEX(iova)];
+
+       if (!IOMMU_PTE_PRESENT(*pte))
+               return 0;
+
+       pte = IOMMU_PTE_PAGE(*pte);
+       pte = &pte[IOMMU_PTE_L1_INDEX(iova)];
+
+       if (!IOMMU_PTE_PRESENT(*pte))
+               return 0;
+
+       pte = IOMMU_PTE_PAGE(*pte);
+       pte = &pte[IOMMU_PTE_L0_INDEX(iova)];
+
+       if (!IOMMU_PTE_PRESENT(*pte))
+               return 0;
+
+       paddr  = *pte & IOMMU_PAGE_MASK;
+       paddr |= offset;
+
+       return paddr;
+}
+
 #endif