From 4f6b83015e2304f3e7560ef33d04de6131df3b0c Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 13 Oct 2008 10:09:09 +0100 Subject: [PATCH] vtd: move some x86-dependent functions into x86-specific directory. Signed-off-by: Anthony Xu Signed-off-by: Dexuan Cui --- xen/drivers/passthrough/vtd/iommu.c | 9 ++++----- xen/drivers/passthrough/vtd/vtd.h | 5 ++++- xen/drivers/passthrough/vtd/x86/vtd.c | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index c16d084776..48c7463663 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -123,7 +123,7 @@ static void __iommu_flush_cache(void *addr, int size) return; for ( i = 0; i < size; i += clflush_size ) - clflush((char *)addr + i); + cacheline_flush((char *)addr + i); } void iommu_flush_cache_entry(void *addr) @@ -525,7 +525,7 @@ void iommu_flush_all(void) struct acpi_drhd_unit *drhd; struct iommu *iommu; - wbinvd(); + flush_all_cache(); for_each_drhd_unit ( drhd ) { iommu = drhd->iommu; @@ -962,8 +962,7 @@ static int iommu_alloc(struct acpi_drhd_unit *drhd) return -ENOMEM; } - set_fixmap_nocache(FIX_IOMMU_REGS_BASE_0 + nr_iommus, drhd->address); - iommu->reg = (void *)fix_to_virt(FIX_IOMMU_REGS_BASE_0 + nr_iommus); + iommu->reg = map_to_nocache_virt(nr_iommus, drhd->address); iommu->index = nr_iommus++; iommu->cap = dmar_readq(iommu->reg, DMAR_CAP_REG); @@ -1768,7 +1767,7 @@ int intel_vtd_setup(void) return -ENODEV; spin_lock_init(&domid_bitmap_lock); - clflush_size = get_clflush_size(); + clflush_size = get_cache_line_size(); for_each_drhd_unit ( drhd ) if ( iommu_alloc(drhd) != 0 ) diff --git a/xen/drivers/passthrough/vtd/vtd.h b/xen/drivers/passthrough/vtd/vtd.h index 6aa8cf59cc..84cd2e5f8a 100644 --- a/xen/drivers/passthrough/vtd/vtd.h +++ b/xen/drivers/passthrough/vtd/vtd.h @@ -97,7 +97,10 @@ struct msi_msg_remap_entry { u32 data; /* msi message data */ }; -unsigned int get_clflush_size(void); +unsigned int get_cache_line_size(void); +void cacheline_flush(char *); +void flush_all_cache(void); +void *map_to_nocache_virt(int nr_iommus, u64 maddr); u64 alloc_pgtable_maddr(void); void free_pgtable_maddr(u64 maddr); void *map_vtd_domain_page(u64 maddr); diff --git a/xen/drivers/passthrough/vtd/x86/vtd.c b/xen/drivers/passthrough/vtd/x86/vtd.c index c1cea80325..2c931eb64c 100644 --- a/xen/drivers/passthrough/vtd/x86/vtd.c +++ b/xen/drivers/passthrough/vtd/x86/vtd.c @@ -60,11 +60,27 @@ void free_pgtable_maddr(u64 maddr) free_domheap_page(maddr_to_page(maddr)); } -unsigned int get_clflush_size(void) +unsigned int get_cache_line_size(void) { return ((cpuid_ebx(1) >> 8) & 0xff) * 8; } +void cacheline_flush(char * addr) +{ + clflush(addr); +} + +void flush_all_cache() +{ + wbinvd(); +} + +void *map_to_nocache_virt(int nr_iommus, u64 maddr) +{ + set_fixmap_nocache(FIX_IOMMU_REGS_BASE_0 + nr_iommus, maddr); + return (void *)fix_to_virt(FIX_IOMMU_REGS_BASE_0 + nr_iommus); +} + struct hvm_irq_dpci *domain_get_irq_dpci(struct domain *domain) { if ( !domain ) -- 2.30.2