From: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>

Introduce init function for setting up DMA domain for DMA-API with
the IOMMU v2 page table.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
Signed-off-by: Vasant Hegde <vasant.he...@amd.com>
---
 drivers/iommu/amd/iommu.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index f2d939b7cc4d..e5aef845f01c 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2029,6 +2029,24 @@ static int protection_domain_init_v1(struct 
protection_domain *domain, int mode)
        return 0;
 }
 
+static int protection_domain_init_v2(struct protection_domain *domain)
+{
+       spin_lock_init(&domain->lock);
+       domain->id = domain_id_alloc();
+       if (!domain->id)
+               return -ENOMEM;
+       INIT_LIST_HEAD(&domain->dev_list);
+
+       domain->flags |= PD_GIOV_MASK;
+
+       if (domain_enable_v2(domain, 1, false)) {
+               domain_id_free(domain->id);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
 static struct protection_domain *protection_domain_alloc(unsigned int type)
 {
        struct io_pgtable_ops *pgtbl_ops;
@@ -2056,6 +2074,9 @@ static struct protection_domain 
*protection_domain_alloc(unsigned int type)
        case AMD_IOMMU_V1:
                ret = protection_domain_init_v1(domain, mode);
                break;
+       case AMD_IOMMU_V2:
+               ret = protection_domain_init_v2(domain);
+               break;
        default:
                ret = -EINVAL;
        }
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to