[RFC,04/21] iommu/amd: Modify domain_enable_v2() to add giov parameter

Message ID 20230621235508.113949-5-suravee.suthikulpanit@amd.com
State New
Headers
Series iommu/amd: Introduce support for HW accelerated vIOMMU w/ nested page table |

Commit Message

Suravee Suthikulpanit June 21, 2023, 11:54 p.m. UTC
  To preparation for subsequent changes. There is no functional change.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 drivers/iommu/amd/amd_iommu.h |  2 +-
 drivers/iommu/amd/iommu.c     | 14 +++++++-------
 drivers/iommu/amd/iommu_v2.c  |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)
  

Patch

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index 827d065bbe8e..5d2eed07a1fa 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -70,7 +70,7 @@  extern int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr,
 extern int amd_iommu_register_ppr_notifier(struct notifier_block *nb);
 extern int amd_iommu_unregister_ppr_notifier(struct notifier_block *nb);
 extern void amd_iommu_domain_direct_map(struct iommu_domain *dom);
-extern int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids);
+extern int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids, bool giov);
 extern int amd_iommu_flush_page(struct iommu_domain *dom, u32 pasid,
 				u64 address);
 extern void amd_iommu_update_and_flush_device_table(struct protection_domain *domain);
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 356e52f478f1..6017fce8d7fd 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -79,7 +79,7 @@  struct iommu_cmd {
 struct kmem_cache *amd_iommu_irq_cache;
 
 static void detach_device(struct device *dev);
-static int domain_enable_v2(struct protection_domain *domain, int pasids);
+static int domain_enable_v2(struct protection_domain *domain, int pasids, bool giov);
 
 /****************************************************************************
  *
@@ -2051,11 +2051,9 @@  static int protection_domain_init_v2(struct protection_domain *domain)
 		return -ENOMEM;
 	INIT_LIST_HEAD(&domain->dev_list);
 
-	domain->flags |= PD_GIOV_MASK;
-
 	domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
 
-	if (domain_enable_v2(domain, 1)) {
+	if (domain_enable_v2(domain, 1, true)) {
 		domain_id_free(domain->id);
 		return -ENOMEM;
 	}
@@ -2484,7 +2482,7 @@  void amd_iommu_domain_direct_map(struct iommu_domain *dom)
 EXPORT_SYMBOL(amd_iommu_domain_direct_map);
 
 /* Note: This function expects iommu_domain->lock to be held prior calling the function. */
-static int domain_enable_v2(struct protection_domain *domain, int pasids)
+static int domain_enable_v2(struct protection_domain *domain, int pasids, bool giov)
 {
 	int levels;
 
@@ -2501,13 +2499,15 @@  static int domain_enable_v2(struct protection_domain *domain, int pasids)
 
 	domain->glx      = levels;
 	domain->flags   |= PD_IOMMUV2_MASK;
+	if (giov)
+		domain->flags |= PD_GIOV_MASK;
 
 	amd_iommu_domain_update(domain);
 
 	return 0;
 }
 
-int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids)
+int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids, bool giov)
 {
 	struct protection_domain *pdom = to_pdomain(dom);
 	unsigned long flags;
@@ -2525,7 +2525,7 @@  int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids)
 		goto out;
 
 	if (!pdom->gcr3_tbl)
-		ret = domain_enable_v2(pdom, pasids);
+		ret = domain_enable_v2(pdom, pasids, giov);
 
 out:
 	spin_unlock_irqrestore(&pdom->lock, flags);
diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c
index 864e4ffb6aa9..0ddd10953d41 100644
--- a/drivers/iommu/amd/iommu_v2.c
+++ b/drivers/iommu/amd/iommu_v2.c
@@ -784,7 +784,7 @@  int amd_iommu_init_device(struct pci_dev *pdev, int pasids)
 	dev_state->domain->type = IOMMU_DOMAIN_IDENTITY;
 	amd_iommu_domain_direct_map(dev_state->domain);
 
-	ret = amd_iommu_domain_enable_v2(dev_state->domain, pasids);
+	ret = amd_iommu_domain_enable_v2(dev_state->domain, pasids, false);
 	if (ret)
 		goto out_free_domain;