From 32ed3d1a76afdfbaa49b0aa8d5f66f19f5b4dfbe Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Thu, 8 Nov 2018 13:42:07 +0800 Subject: [PATCH] hv: vtd: move public API to the bottom part of the file Move move public API to the bottom part of the file. Tracked-On: #1855 Signed-off-by: Binbin Wu Acked-by: Eddie Dong --- hypervisor/arch/x86/vtd.c | 89 +++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index 04fcf0278..cf9b69e58 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -796,51 +796,6 @@ static void dmar_disable(struct dmar_drhd_rt *dmar_unit) dmar_fault_event_mask(dmar_unit); } -struct iommu_domain *create_iommu_domain(uint16_t vm_id, uint64_t translation_table, uint32_t addr_width) -{ - struct iommu_domain *domain; - - /* TODO: check if a domain with the vm_id exists */ - - if (translation_table == 0UL) { - pr_err("translation table is NULL"); - return NULL; - } - - /* - * A hypercall is called to create an iommu domain for a valid VM, - * and hv code limit the VM number to CONFIG_MAX_VM_NUM. - * So the array iommu_domains will not be accessed out of range. - */ - domain = &iommu_domains[vmid_to_domainid(vm_id)]; - - domain->is_host = false; - domain->vm_id = vm_id; - domain->trans_table_ptr = translation_table; - domain->addr_width = addr_width; - domain->is_tt_ept = true; - domain->iommu_snoop = true; - - dev_dbg(ACRN_DBG_IOMMU, "create domain [%d]: vm_id = %hu, ept@0x%x", - vmid_to_domainid(domain->vm_id), domain->vm_id, domain->trans_table_ptr); - - return domain; -} - -/** - * @pre domain != NULL - */ -void destroy_iommu_domain(struct iommu_domain *domain) -{ - /* currently only support ept */ - if (!domain->is_tt_ept) { - ASSERT(false, "translation_table is not EPT!"); - } - - /* TODO: check if any device assigned to this domain */ - (void)memset(domain, 0U, sizeof(*domain)); -} - static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, uint8_t bus, uint8_t devfun) { struct dmar_drhd_rt *dmar_unit; @@ -994,6 +949,50 @@ static int remove_iommu_device(const struct iommu_domain *domain, uint16_t segme return 0; } +struct iommu_domain *create_iommu_domain(uint16_t vm_id, uint64_t translation_table, uint32_t addr_width) +{ + struct iommu_domain *domain; + + /* TODO: check if a domain with the vm_id exists */ + + if (translation_table == 0UL) { + pr_err("translation table is NULL"); + return NULL; + } + + /* + * A hypercall is called to create an iommu domain for a valid VM, + * and hv code limit the VM number to CONFIG_MAX_VM_NUM. + * So the array iommu_domains will not be accessed out of range. + */ + domain = &iommu_domains[vmid_to_domainid(vm_id)]; + + domain->is_host = false; + domain->vm_id = vm_id; + domain->trans_table_ptr = translation_table; + domain->addr_width = addr_width; + domain->is_tt_ept = true; + + dev_dbg(ACRN_DBG_IOMMU, "create domain [%d]: vm_id = %hu, ept@0x%x", + vmid_to_domainid(domain->vm_id), domain->vm_id, domain->trans_table_ptr); + + return domain; +} + +/** + * @pre domain != NULL + */ +void destroy_iommu_domain(struct iommu_domain *domain) +{ + /* currently only support ept */ + if (!domain->is_tt_ept) { + ASSERT(false, "translation_table is not EPT!"); + } + + /* TODO: check if any device assigned to this domain */ + (void)memset(domain, 0U, sizeof(*domain)); +} + int assign_iommu_device(struct iommu_domain *domain, uint8_t bus, uint8_t devfun) { /* TODO: check if the device assigned */