Skip to content

Commit 9a630a4

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Split struct iommu_ops
Move the domain specific operations out of struct iommu_ops into a new structure that only has domain specific operations. This solves the problem of needing to know if the method vector for a given operation needs to be retrieved from the device or the domain. Logically the domain ops are the ones that make sense for external subsystems and endpoint drivers to use, while device ops, with the sole exception of domain_alloc, are IOMMU API internals. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20220216025249.3459465-10-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 41bb23e commit 9a630a4

22 files changed

Lines changed: 256 additions & 200 deletions

drivers/iommu/amd/iommu.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,13 +2268,6 @@ static int amd_iommu_def_domain_type(struct device *dev)
22682268
const struct iommu_ops amd_iommu_ops = {
22692269
.capable = amd_iommu_capable,
22702270
.domain_alloc = amd_iommu_domain_alloc,
2271-
.domain_free = amd_iommu_domain_free,
2272-
.attach_dev = amd_iommu_attach_device,
2273-
.detach_dev = amd_iommu_detach_device,
2274-
.map = amd_iommu_map,
2275-
.iotlb_sync_map = amd_iommu_iotlb_sync_map,
2276-
.unmap = amd_iommu_unmap,
2277-
.iova_to_phys = amd_iommu_iova_to_phys,
22782271
.probe_device = amd_iommu_probe_device,
22792272
.release_device = amd_iommu_release_device,
22802273
.probe_finalize = amd_iommu_probe_finalize,
@@ -2283,9 +2276,18 @@ const struct iommu_ops amd_iommu_ops = {
22832276
.put_resv_regions = generic_iommu_put_resv_regions,
22842277
.is_attach_deferred = amd_iommu_is_attach_deferred,
22852278
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
2286-
.flush_iotlb_all = amd_iommu_flush_iotlb_all,
2287-
.iotlb_sync = amd_iommu_iotlb_sync,
22882279
.def_domain_type = amd_iommu_def_domain_type,
2280+
.default_domain_ops = &(const struct iommu_domain_ops) {
2281+
.attach_dev = amd_iommu_attach_device,
2282+
.detach_dev = amd_iommu_detach_device,
2283+
.map = amd_iommu_map,
2284+
.unmap = amd_iommu_unmap,
2285+
.iotlb_sync_map = amd_iommu_iotlb_sync_map,
2286+
.iova_to_phys = amd_iommu_iova_to_phys,
2287+
.flush_iotlb_all = amd_iommu_flush_iotlb_all,
2288+
.iotlb_sync = amd_iommu_iotlb_sync,
2289+
.free = amd_iommu_domain_free,
2290+
}
22892291
};
22902292

22912293
/*****************************************************************************

drivers/iommu/apple-dart.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -765,15 +765,6 @@ static void apple_dart_get_resv_regions(struct device *dev,
765765

766766
static const struct iommu_ops apple_dart_iommu_ops = {
767767
.domain_alloc = apple_dart_domain_alloc,
768-
.domain_free = apple_dart_domain_free,
769-
.attach_dev = apple_dart_attach_dev,
770-
.detach_dev = apple_dart_detach_dev,
771-
.map_pages = apple_dart_map_pages,
772-
.unmap_pages = apple_dart_unmap_pages,
773-
.flush_iotlb_all = apple_dart_flush_iotlb_all,
774-
.iotlb_sync = apple_dart_iotlb_sync,
775-
.iotlb_sync_map = apple_dart_iotlb_sync_map,
776-
.iova_to_phys = apple_dart_iova_to_phys,
777768
.probe_device = apple_dart_probe_device,
778769
.release_device = apple_dart_release_device,
779770
.device_group = apple_dart_device_group,
@@ -782,6 +773,17 @@ static const struct iommu_ops apple_dart_iommu_ops = {
782773
.get_resv_regions = apple_dart_get_resv_regions,
783774
.put_resv_regions = generic_iommu_put_resv_regions,
784775
.pgsize_bitmap = -1UL, /* Restricted during dart probe */
776+
.default_domain_ops = &(const struct iommu_domain_ops) {
777+
.attach_dev = apple_dart_attach_dev,
778+
.detach_dev = apple_dart_detach_dev,
779+
.map_pages = apple_dart_map_pages,
780+
.unmap_pages = apple_dart_unmap_pages,
781+
.flush_iotlb_all = apple_dart_flush_iotlb_all,
782+
.iotlb_sync = apple_dart_iotlb_sync,
783+
.iotlb_sync_map = apple_dart_iotlb_sync_map,
784+
.iova_to_phys = apple_dart_iova_to_phys,
785+
.free = apple_dart_domain_free,
786+
}
785787
};
786788

787789
static irqreturn_t apple_dart_irq(int irq, void *dev)

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,17 +2841,9 @@ static int arm_smmu_dev_disable_feature(struct device *dev,
28412841
static struct iommu_ops arm_smmu_ops = {
28422842
.capable = arm_smmu_capable,
28432843
.domain_alloc = arm_smmu_domain_alloc,
2844-
.domain_free = arm_smmu_domain_free,
2845-
.attach_dev = arm_smmu_attach_dev,
2846-
.map_pages = arm_smmu_map_pages,
2847-
.unmap_pages = arm_smmu_unmap_pages,
2848-
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
2849-
.iotlb_sync = arm_smmu_iotlb_sync,
2850-
.iova_to_phys = arm_smmu_iova_to_phys,
28512844
.probe_device = arm_smmu_probe_device,
28522845
.release_device = arm_smmu_release_device,
28532846
.device_group = arm_smmu_device_group,
2854-
.enable_nesting = arm_smmu_enable_nesting,
28552847
.of_xlate = arm_smmu_of_xlate,
28562848
.get_resv_regions = arm_smmu_get_resv_regions,
28572849
.put_resv_regions = generic_iommu_put_resv_regions,
@@ -2865,6 +2857,16 @@ static struct iommu_ops arm_smmu_ops = {
28652857
.page_response = arm_smmu_page_response,
28662858
.pgsize_bitmap = -1UL, /* Restricted during device attach */
28672859
.owner = THIS_MODULE,
2860+
.default_domain_ops = &(const struct iommu_domain_ops) {
2861+
.attach_dev = arm_smmu_attach_dev,
2862+
.map_pages = arm_smmu_map_pages,
2863+
.unmap_pages = arm_smmu_unmap_pages,
2864+
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
2865+
.iotlb_sync = arm_smmu_iotlb_sync,
2866+
.iova_to_phys = arm_smmu_iova_to_phys,
2867+
.enable_nesting = arm_smmu_enable_nesting,
2868+
.free = arm_smmu_domain_free,
2869+
}
28682870
};
28692871

28702872
/* Probing and initialisation functions */

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,25 +1583,27 @@ static int arm_smmu_def_domain_type(struct device *dev)
15831583
static struct iommu_ops arm_smmu_ops = {
15841584
.capable = arm_smmu_capable,
15851585
.domain_alloc = arm_smmu_domain_alloc,
1586-
.domain_free = arm_smmu_domain_free,
1587-
.attach_dev = arm_smmu_attach_dev,
1588-
.map_pages = arm_smmu_map_pages,
1589-
.unmap_pages = arm_smmu_unmap_pages,
1590-
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
1591-
.iotlb_sync = arm_smmu_iotlb_sync,
1592-
.iova_to_phys = arm_smmu_iova_to_phys,
15931586
.probe_device = arm_smmu_probe_device,
15941587
.release_device = arm_smmu_release_device,
15951588
.probe_finalize = arm_smmu_probe_finalize,
15961589
.device_group = arm_smmu_device_group,
1597-
.enable_nesting = arm_smmu_enable_nesting,
1598-
.set_pgtable_quirks = arm_smmu_set_pgtable_quirks,
15991590
.of_xlate = arm_smmu_of_xlate,
16001591
.get_resv_regions = arm_smmu_get_resv_regions,
16011592
.put_resv_regions = generic_iommu_put_resv_regions,
16021593
.def_domain_type = arm_smmu_def_domain_type,
16031594
.pgsize_bitmap = -1UL, /* Restricted during device attach */
16041595
.owner = THIS_MODULE,
1596+
.default_domain_ops = &(const struct iommu_domain_ops) {
1597+
.attach_dev = arm_smmu_attach_dev,
1598+
.map_pages = arm_smmu_map_pages,
1599+
.unmap_pages = arm_smmu_unmap_pages,
1600+
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
1601+
.iotlb_sync = arm_smmu_iotlb_sync,
1602+
.iova_to_phys = arm_smmu_iova_to_phys,
1603+
.enable_nesting = arm_smmu_enable_nesting,
1604+
.set_pgtable_quirks = arm_smmu_set_pgtable_quirks,
1605+
.free = arm_smmu_domain_free,
1606+
}
16051607
};
16061608

16071609
static void arm_smmu_device_reset(struct arm_smmu_device *smmu)

drivers/iommu/arm/arm-smmu/qcom_iommu.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,19 +590,21 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
590590
static const struct iommu_ops qcom_iommu_ops = {
591591
.capable = qcom_iommu_capable,
592592
.domain_alloc = qcom_iommu_domain_alloc,
593-
.domain_free = qcom_iommu_domain_free,
594-
.attach_dev = qcom_iommu_attach_dev,
595-
.detach_dev = qcom_iommu_detach_dev,
596-
.map = qcom_iommu_map,
597-
.unmap = qcom_iommu_unmap,
598-
.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
599-
.iotlb_sync = qcom_iommu_iotlb_sync,
600-
.iova_to_phys = qcom_iommu_iova_to_phys,
601593
.probe_device = qcom_iommu_probe_device,
602594
.release_device = qcom_iommu_release_device,
603595
.device_group = generic_device_group,
604596
.of_xlate = qcom_iommu_of_xlate,
605597
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
598+
.default_domain_ops = &(const struct iommu_domain_ops) {
599+
.attach_dev = qcom_iommu_attach_dev,
600+
.detach_dev = qcom_iommu_detach_dev,
601+
.map = qcom_iommu_map,
602+
.unmap = qcom_iommu_unmap,
603+
.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
604+
.iotlb_sync = qcom_iommu_iotlb_sync,
605+
.iova_to_phys = qcom_iommu_iova_to_phys,
606+
.free = qcom_iommu_domain_free,
607+
}
606608
};
607609

608610
static int qcom_iommu_sec_ptbl_init(struct device *dev)

drivers/iommu/exynos-iommu.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,17 +1309,19 @@ static int exynos_iommu_of_xlate(struct device *dev,
13091309

13101310
static const struct iommu_ops exynos_iommu_ops = {
13111311
.domain_alloc = exynos_iommu_domain_alloc,
1312-
.domain_free = exynos_iommu_domain_free,
1313-
.attach_dev = exynos_iommu_attach_device,
1314-
.detach_dev = exynos_iommu_detach_device,
1315-
.map = exynos_iommu_map,
1316-
.unmap = exynos_iommu_unmap,
1317-
.iova_to_phys = exynos_iommu_iova_to_phys,
13181312
.device_group = generic_device_group,
13191313
.probe_device = exynos_iommu_probe_device,
13201314
.release_device = exynos_iommu_release_device,
13211315
.pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,
13221316
.of_xlate = exynos_iommu_of_xlate,
1317+
.default_domain_ops = &(const struct iommu_domain_ops) {
1318+
.attach_dev = exynos_iommu_attach_device,
1319+
.detach_dev = exynos_iommu_detach_device,
1320+
.map = exynos_iommu_map,
1321+
.unmap = exynos_iommu_unmap,
1322+
.iova_to_phys = exynos_iommu_iova_to_phys,
1323+
.free = exynos_iommu_domain_free,
1324+
}
13231325
};
13241326

13251327
static int __init exynos_iommu_init(void)

drivers/iommu/fsl_pamu_domain.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,15 @@ static void fsl_pamu_release_device(struct device *dev)
453453
static const struct iommu_ops fsl_pamu_ops = {
454454
.capable = fsl_pamu_capable,
455455
.domain_alloc = fsl_pamu_domain_alloc,
456-
.domain_free = fsl_pamu_domain_free,
457-
.attach_dev = fsl_pamu_attach_device,
458-
.detach_dev = fsl_pamu_detach_device,
459-
.iova_to_phys = fsl_pamu_iova_to_phys,
460456
.probe_device = fsl_pamu_probe_device,
461457
.release_device = fsl_pamu_release_device,
462458
.device_group = fsl_pamu_device_group,
459+
.default_domain_ops = &(const struct iommu_domain_ops) {
460+
.attach_dev = fsl_pamu_attach_device,
461+
.detach_dev = fsl_pamu_detach_device,
462+
.iova_to_phys = fsl_pamu_iova_to_phys,
463+
.free = fsl_pamu_domain_free,
464+
}
463465
};
464466

465467
int __init pamu_domain_init(void)

drivers/iommu/intel/iommu.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5092,15 +5092,6 @@ static void intel_iommu_iotlb_sync_map(struct iommu_domain *domain,
50925092
const struct iommu_ops intel_iommu_ops = {
50935093
.capable = intel_iommu_capable,
50945094
.domain_alloc = intel_iommu_domain_alloc,
5095-
.domain_free = intel_iommu_domain_free,
5096-
.attach_dev = intel_iommu_attach_device,
5097-
.detach_dev = intel_iommu_detach_device,
5098-
.map_pages = intel_iommu_map_pages,
5099-
.unmap_pages = intel_iommu_unmap_pages,
5100-
.iotlb_sync_map = intel_iommu_iotlb_sync_map,
5101-
.flush_iotlb_all = intel_flush_iotlb_all,
5102-
.iotlb_sync = intel_iommu_tlb_sync,
5103-
.iova_to_phys = intel_iommu_iova_to_phys,
51045095
.probe_device = intel_iommu_probe_device,
51055096
.probe_finalize = intel_iommu_probe_finalize,
51065097
.release_device = intel_iommu_release_device,
@@ -5118,6 +5109,17 @@ const struct iommu_ops intel_iommu_ops = {
51185109
.sva_get_pasid = intel_svm_get_pasid,
51195110
.page_response = intel_svm_page_response,
51205111
#endif
5112+
.default_domain_ops = &(const struct iommu_domain_ops) {
5113+
.attach_dev = intel_iommu_attach_device,
5114+
.detach_dev = intel_iommu_detach_device,
5115+
.map_pages = intel_iommu_map_pages,
5116+
.unmap_pages = intel_iommu_unmap_pages,
5117+
.iotlb_sync_map = intel_iommu_iotlb_sync_map,
5118+
.flush_iotlb_all = intel_flush_iotlb_all,
5119+
.iotlb_sync = intel_iommu_tlb_sync,
5120+
.iova_to_phys = intel_iommu_iova_to_phys,
5121+
.free = intel_iommu_domain_free,
5122+
}
51215123
};
51225124

51235125
static void quirk_iommu_igfx(struct pci_dev *dev)

drivers/iommu/iommu.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,10 +1950,11 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
19501950
if (!domain)
19511951
return NULL;
19521952

1953-
domain->ops = bus->iommu_ops;
19541953
domain->type = type;
19551954
/* Assume all sizes by default; the driver may override this later */
1956-
domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
1955+
domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
1956+
if (!domain->ops)
1957+
domain->ops = bus->iommu_ops->default_domain_ops;
19571958

19581959
if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) {
19591960
iommu_domain_free(domain);
@@ -1971,7 +1972,7 @@ EXPORT_SYMBOL_GPL(iommu_domain_alloc);
19711972
void iommu_domain_free(struct iommu_domain *domain)
19721973
{
19731974
iommu_put_dma_cookie(domain);
1974-
domain->ops->domain_free(domain);
1975+
domain->ops->free(domain);
19751976
}
19761977
EXPORT_SYMBOL_GPL(iommu_domain_free);
19771978

@@ -2242,7 +2243,7 @@ static int __iommu_map_pages(struct iommu_domain *domain, unsigned long iova,
22422243
phys_addr_t paddr, size_t size, int prot,
22432244
gfp_t gfp, size_t *mapped)
22442245
{
2245-
const struct iommu_ops *ops = domain->ops;
2246+
const struct iommu_domain_ops *ops = domain->ops;
22462247
size_t pgsize, count;
22472248
int ret;
22482249

@@ -2265,7 +2266,7 @@ static int __iommu_map_pages(struct iommu_domain *domain, unsigned long iova,
22652266
static int __iommu_map(struct iommu_domain *domain, unsigned long iova,
22662267
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
22672268
{
2268-
const struct iommu_ops *ops = domain->ops;
2269+
const struct iommu_domain_ops *ops = domain->ops;
22692270
unsigned long orig_iova = iova;
22702271
unsigned int min_pagesz;
22712272
size_t orig_size = size;
@@ -2325,7 +2326,7 @@ static int __iommu_map(struct iommu_domain *domain, unsigned long iova,
23252326
static int _iommu_map(struct iommu_domain *domain, unsigned long iova,
23262327
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
23272328
{
2328-
const struct iommu_ops *ops = domain->ops;
2329+
const struct iommu_domain_ops *ops = domain->ops;
23292330
int ret;
23302331

23312332
ret = __iommu_map(domain, iova, paddr, size, prot, gfp);
@@ -2354,7 +2355,7 @@ static size_t __iommu_unmap_pages(struct iommu_domain *domain,
23542355
unsigned long iova, size_t size,
23552356
struct iommu_iotlb_gather *iotlb_gather)
23562357
{
2357-
const struct iommu_ops *ops = domain->ops;
2358+
const struct iommu_domain_ops *ops = domain->ops;
23582359
size_t pgsize, count;
23592360

23602361
pgsize = iommu_pgsize(domain, iova, iova, size, &count);
@@ -2367,7 +2368,7 @@ static size_t __iommu_unmap(struct iommu_domain *domain,
23672368
unsigned long iova, size_t size,
23682369
struct iommu_iotlb_gather *iotlb_gather)
23692370
{
2370-
const struct iommu_ops *ops = domain->ops;
2371+
const struct iommu_domain_ops *ops = domain->ops;
23712372
size_t unmapped_page, unmapped = 0;
23722373
unsigned long orig_iova = iova;
23732374
unsigned int min_pagesz;
@@ -2443,7 +2444,7 @@ static ssize_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
24432444
struct scatterlist *sg, unsigned int nents, int prot,
24442445
gfp_t gfp)
24452446
{
2446-
const struct iommu_ops *ops = domain->ops;
2447+
const struct iommu_domain_ops *ops = domain->ops;
24472448
size_t len = 0, mapped = 0;
24482449
phys_addr_t start;
24492450
unsigned int i = 0;

drivers/iommu/ipmmu-vmsa.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,21 +868,23 @@ static struct iommu_group *ipmmu_find_group(struct device *dev)
868868

869869
static const struct iommu_ops ipmmu_ops = {
870870
.domain_alloc = ipmmu_domain_alloc,
871-
.domain_free = ipmmu_domain_free,
872-
.attach_dev = ipmmu_attach_device,
873-
.detach_dev = ipmmu_detach_device,
874-
.map = ipmmu_map,
875-
.unmap = ipmmu_unmap,
876-
.flush_iotlb_all = ipmmu_flush_iotlb_all,
877-
.iotlb_sync = ipmmu_iotlb_sync,
878-
.iova_to_phys = ipmmu_iova_to_phys,
879871
.probe_device = ipmmu_probe_device,
880872
.release_device = ipmmu_release_device,
881873
.probe_finalize = ipmmu_probe_finalize,
882874
.device_group = IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)
883875
? generic_device_group : ipmmu_find_group,
884876
.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
885877
.of_xlate = ipmmu_of_xlate,
878+
.default_domain_ops = &(const struct iommu_domain_ops) {
879+
.attach_dev = ipmmu_attach_device,
880+
.detach_dev = ipmmu_detach_device,
881+
.map = ipmmu_map,
882+
.unmap = ipmmu_unmap,
883+
.flush_iotlb_all = ipmmu_flush_iotlb_all,
884+
.iotlb_sync = ipmmu_iotlb_sync,
885+
.iova_to_phys = ipmmu_iova_to_phys,
886+
.free = ipmmu_domain_free,
887+
}
886888
};
887889

888890
/* -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)