aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Wang <wei.wang2@amd.com>2011-01-27 16:11:37 +0000
committerWei Wang <wei.wang2@amd.com>2011-01-27 16:11:37 +0000
commit78805ca0e399899bcd201f7cba52887406dc8a4e (patch)
tree2ef9eecb46e3cef5f748f353d5fa4e5f2e075d9a
parent24c3ed18af8a89d0066f5668ad91a0c38c98f7a2 (diff)
downloadxen-78805ca0e399899bcd201f7cba52887406dc8a4e.tar.gz
xen-78805ca0e399899bcd201f7cba52887406dc8a4e.tar.bz2
xen-78805ca0e399899bcd201f7cba52887406dc8a4e.zip
amd iommu: reduce io page level for hvm guest (2/3)
Clean up amd_iommu_reserve_domain_unity_map function to reduce code duplication. Signed-off-by: Wei Wang <wei.wang2@amd.com>
-rw-r--r--xen/drivers/passthrough/amd/iommu_map.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthrough/amd/iommu_map.c
index d973a123ea..062895518b 100644
--- a/xen/drivers/passthrough/amd/iommu_map.c
+++ b/xen/drivers/passthrough/amd/iommu_map.c
@@ -518,38 +518,26 @@ int amd_iommu_unmap_page(struct domain *d, unsigned long gfn)
return 0;
}
-int amd_iommu_reserve_domain_unity_map(
- struct domain *domain,
- unsigned long phys_addr,
- unsigned long size, int iw, int ir)
+int amd_iommu_reserve_domain_unity_map(struct domain *domain,
+ u64 phys_addr,
+ unsigned long size, int iw, int ir)
{
- u64 iommu_l2e;
unsigned long npages, i;
- struct hvm_iommu *hd = domain_hvm_iommu(domain);
+ unsigned long gfn;
+ unsigned int flags = !!ir;
+ int rt = 0;
- npages = region_to_pages(phys_addr, size);
+ if ( iw )
+ flags |= IOMMUF_writable;
- spin_lock(&hd->mapping_lock);
- for ( i = 0; i < npages; ++i )
+ npages = region_to_pages(phys_addr, size);
+ gfn = phys_addr >> PAGE_SHIFT;
+ for ( i = 0; i < npages; i++ )
{
- iommu_l2e = iommu_l2e_from_pfn(
- hd->root_table, hd->paging_mode, phys_addr >> PAGE_SHIFT);
-
- if ( iommu_l2e == 0 )
- {
- spin_unlock(&hd->mapping_lock);
- AMD_IOMMU_DEBUG("Invalid IO pagetable entry phys_addr = %lx\n",
- phys_addr);
- domain_crash(domain);
- return -EFAULT;
- }
-
- set_iommu_l1e_present(iommu_l2e,
- (phys_addr >> PAGE_SHIFT), phys_addr, iw, ir);
-
- phys_addr += PAGE_SIZE;
+ rt = amd_iommu_map_page(domain, gfn +i, gfn +i, flags);
+ if ( rt != 0 )
+ return rt;
}
- spin_unlock(&hd->mapping_lock);
return 0;
}