Skip to content

Commit 4db6c41

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API
Introduce init function for setting up DMA domain for DMA-API with the IOMMU v2 page table. Co-developed-by: Vasant Hegde <[email protected]> Signed-off-by: Vasant Hegde <[email protected]> Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 643feb0 commit 4db6c41

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,10 @@ static void do_attach(struct iommu_dev_data *dev_data,
16531653
domain->dev_iommu[iommu->index] += 1;
16541654
domain->dev_cnt += 1;
16551655

1656+
/* Override supported page sizes */
1657+
if (domain->flags & PD_GIOV_MASK)
1658+
domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
1659+
16561660
/* Update device table */
16571661
set_dte_entry(iommu, dev_data->devid, domain,
16581662
ats, dev_data->iommu_v2);
@@ -2032,6 +2036,24 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode)
20322036
return 0;
20332037
}
20342038

2039+
static int protection_domain_init_v2(struct protection_domain *domain)
2040+
{
2041+
spin_lock_init(&domain->lock);
2042+
domain->id = domain_id_alloc();
2043+
if (!domain->id)
2044+
return -ENOMEM;
2045+
INIT_LIST_HEAD(&domain->dev_list);
2046+
2047+
domain->flags |= PD_GIOV_MASK;
2048+
2049+
if (domain_enable_v2(domain, 1)) {
2050+
domain_id_free(domain->id);
2051+
return -ENOMEM;
2052+
}
2053+
2054+
return 0;
2055+
}
2056+
20352057
static struct protection_domain *protection_domain_alloc(unsigned int type)
20362058
{
20372059
struct io_pgtable_ops *pgtbl_ops;
@@ -2059,6 +2081,9 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
20592081
case AMD_IOMMU_V1:
20602082
ret = protection_domain_init_v1(domain, mode);
20612083
break;
2084+
case AMD_IOMMU_V2:
2085+
ret = protection_domain_init_v2(domain);
2086+
break;
20622087
default:
20632088
ret = -EINVAL;
20642089
}

0 commit comments

Comments
 (0)