@@ -45,6 +45,7 @@
#include <asm/hvm/support.h>
#include <asm/hvm/io.h>
#include <asm/hvm/emulate.h>
+#include <asm/hvm/svm/amd-iommu-proto.h>
#include <asm/hvm/svm/asid.h>
#include <asm/hvm/svm/svm.h>
#include <asm/hvm/svm/vmcb.h>
@@ -1176,11 +1177,20 @@ void svm_host_osvw_init()
static int svm_domain_initialise(struct domain *d)
{
+ if ( is_hvm_domain(d) )
+ /*
+ * This requires the hvm domain to be
+ * initialized first.
+ */
+ return guest_iommu_init(d);
+
return 0;
}
static void svm_domain_destroy(struct domain *d)
{
+ if ( is_hvm_domain(d) )
+ guest_iommu_destroy(d);
}
static int svm_vcpu_initialise(struct vcpu *v)
@@ -891,6 +891,12 @@ int guest_iommu_init(struct domain* d)
!has_viommu(d) )
return 0;
+ if ( d->arch.hvm_domain.io_handler == NULL )
+ {
+ AMD_IOMMU_DEBUG("Error: uninitalized hvm io handler\n");
+ return 1;
+ }
+
iommu = xzalloc(struct guest_iommu);
if ( !iommu )
{
@@ -274,9 +274,6 @@ static int amd_iommu_domain_init(struct domain *d)
hd->arch.paging_mode = is_hvm_domain(d) ?
IOMMU_PAGING_MODE_LEVEL_2 :
get_paging_mode(max_page);
-
- guest_iommu_init(d);
-
return 0;
}
@@ -476,7 +473,6 @@ static void deallocate_iommu_page_tables(struct domain *d)
static void amd_iommu_domain_destroy(struct domain *d)
{
- guest_iommu_destroy(d);
deallocate_iommu_page_tables(d);
amd_iommu_flush_all_pages(d);
}