Skip to content

Commit cefa0d5

Browse files
committed
iommu/arm-smmu: Convert to probe/release_device() call-backs
Convert the arm-smmu and arm-smmu-v3 drivers to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent e5d1841 commit cefa0d5

File tree

2 files changed

+25
-52
lines changed

2 files changed

+25
-52
lines changed

drivers/iommu/arm-smmu-v3.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,27 +2914,26 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid)
29142914

29152915
static struct iommu_ops arm_smmu_ops;
29162916

2917-
static int arm_smmu_add_device(struct device *dev)
2917+
static struct iommu_device *arm_smmu_probe_device(struct device *dev)
29182918
{
29192919
int i, ret;
29202920
struct arm_smmu_device *smmu;
29212921
struct arm_smmu_master *master;
29222922
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
2923-
struct iommu_group *group;
29242923

29252924
if (!fwspec || fwspec->ops != &arm_smmu_ops)
2926-
return -ENODEV;
2925+
return ERR_PTR(-ENODEV);
29272926

29282927
if (WARN_ON_ONCE(dev_iommu_priv_get(dev)))
2929-
return -EBUSY;
2928+
return ERR_PTR(-EBUSY);
29302929

29312930
smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
29322931
if (!smmu)
2933-
return -ENODEV;
2932+
return ERR_PTR(-ENODEV);
29342933

29352934
master = kzalloc(sizeof(*master), GFP_KERNEL);
29362935
if (!master)
2937-
return -ENOMEM;
2936+
return ERR_PTR(-ENOMEM);
29382937

29392938
master->dev = dev;
29402939
master->smmu = smmu;
@@ -2975,30 +2974,15 @@ static int arm_smmu_add_device(struct device *dev)
29752974
master->ssid_bits = min_t(u8, master->ssid_bits,
29762975
CTXDESC_LINEAR_CDMAX);
29772976

2978-
ret = iommu_device_link(&smmu->iommu, dev);
2979-
if (ret)
2980-
goto err_disable_pasid;
2977+
return &smmu->iommu;
29812978

2982-
group = iommu_group_get_for_dev(dev);
2983-
if (IS_ERR(group)) {
2984-
ret = PTR_ERR(group);
2985-
goto err_unlink;
2986-
}
2987-
2988-
iommu_group_put(group);
2989-
return 0;
2990-
2991-
err_unlink:
2992-
iommu_device_unlink(&smmu->iommu, dev);
2993-
err_disable_pasid:
2994-
arm_smmu_disable_pasid(master);
29952979
err_free_master:
29962980
kfree(master);
29972981
dev_iommu_priv_set(dev, NULL);
2998-
return ret;
2982+
return ERR_PTR(ret);
29992983
}
30002984

3001-
static void arm_smmu_remove_device(struct device *dev)
2985+
static void arm_smmu_release_device(struct device *dev)
30022986
{
30032987
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
30042988
struct arm_smmu_master *master;
@@ -3010,8 +2994,6 @@ static void arm_smmu_remove_device(struct device *dev)
30102994
master = dev_iommu_priv_get(dev);
30112995
smmu = master->smmu;
30122996
arm_smmu_detach_dev(master);
3013-
iommu_group_remove_device(dev);
3014-
iommu_device_unlink(&smmu->iommu, dev);
30152997
arm_smmu_disable_pasid(master);
30162998
kfree(master);
30172999
iommu_fwspec_free(dev);
@@ -3138,8 +3120,8 @@ static struct iommu_ops arm_smmu_ops = {
31383120
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
31393121
.iotlb_sync = arm_smmu_iotlb_sync,
31403122
.iova_to_phys = arm_smmu_iova_to_phys,
3141-
.add_device = arm_smmu_add_device,
3142-
.remove_device = arm_smmu_remove_device,
3123+
.probe_device = arm_smmu_probe_device,
3124+
.release_device = arm_smmu_release_device,
31433125
.device_group = arm_smmu_device_group,
31443126
.domain_get_attr = arm_smmu_domain_get_attr,
31453127
.domain_set_attr = arm_smmu_domain_set_attr,

drivers/iommu/arm-smmu.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int arm_smmu_register_legacy_master(struct device *dev,
220220
* With the legacy DT binding in play, we have no guarantees about
221221
* probe order, but then we're also not doing default domains, so we can
222222
* delay setting bus ops until we're sure every possible SMMU is ready,
223-
* and that way ensure that no add_device() calls get missed.
223+
* and that way ensure that no probe_device() calls get missed.
224224
*/
225225
static int arm_smmu_legacy_bus_init(void)
226226
{
@@ -1062,7 +1062,6 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
10621062
struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev);
10631063
struct arm_smmu_device *smmu = cfg->smmu;
10641064
struct arm_smmu_smr *smrs = smmu->smrs;
1065-
struct iommu_group *group;
10661065
int i, idx, ret;
10671066

10681067
mutex_lock(&smmu->stream_map_mutex);
@@ -1090,18 +1089,9 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
10901089
cfg->smendx[i] = (s16)idx;
10911090
}
10921091

1093-
group = iommu_group_get_for_dev(dev);
1094-
if (IS_ERR(group)) {
1095-
ret = PTR_ERR(group);
1096-
goto out_err;
1097-
}
1098-
iommu_group_put(group);
1099-
11001092
/* It worked! Now, poke the actual hardware */
1101-
for_each_cfg_sme(cfg, fwspec, i, idx) {
1093+
for_each_cfg_sme(cfg, fwspec, i, idx)
11021094
arm_smmu_write_sme(smmu, idx);
1103-
smmu->s2crs[idx].group = group;
1104-
}
11051095

11061096
mutex_unlock(&smmu->stream_map_mutex);
11071097
return 0;
@@ -1172,7 +1162,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11721162

11731163
/*
11741164
* FIXME: The arch/arm DMA API code tries to attach devices to its own
1175-
* domains between of_xlate() and add_device() - we have no way to cope
1165+
* domains between of_xlate() and probe_device() - we have no way to cope
11761166
* with that, so until ARM gets converted to rely on groups and default
11771167
* domains, just say no (but more politely than by dereferencing NULL).
11781168
* This should be at least a WARN_ON once that's sorted.
@@ -1382,7 +1372,7 @@ struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
13821372
return dev ? dev_get_drvdata(dev) : NULL;
13831373
}
13841374

1385-
static int arm_smmu_add_device(struct device *dev)
1375+
static struct iommu_device *arm_smmu_probe_device(struct device *dev)
13861376
{
13871377
struct arm_smmu_device *smmu = NULL;
13881378
struct arm_smmu_master_cfg *cfg;
@@ -1403,7 +1393,7 @@ static int arm_smmu_add_device(struct device *dev)
14031393
} else if (fwspec && fwspec->ops == &arm_smmu_ops) {
14041394
smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
14051395
} else {
1406-
return -ENODEV;
1396+
return ERR_PTR(-ENODEV);
14071397
}
14081398

14091399
ret = -EINVAL;
@@ -1444,21 +1434,19 @@ static int arm_smmu_add_device(struct device *dev)
14441434
if (ret)
14451435
goto out_cfg_free;
14461436

1447-
iommu_device_link(&smmu->iommu, dev);
1448-
14491437
device_link_add(dev, smmu->dev,
14501438
DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_SUPPLIER);
14511439

1452-
return 0;
1440+
return &smmu->iommu;
14531441

14541442
out_cfg_free:
14551443
kfree(cfg);
14561444
out_free:
14571445
iommu_fwspec_free(dev);
1458-
return ret;
1446+
return ERR_PTR(ret);
14591447
}
14601448

1461-
static void arm_smmu_remove_device(struct device *dev)
1449+
static void arm_smmu_release_device(struct device *dev)
14621450
{
14631451
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
14641452
struct arm_smmu_master_cfg *cfg;
@@ -1475,13 +1463,11 @@ static void arm_smmu_remove_device(struct device *dev)
14751463
if (ret < 0)
14761464
return;
14771465

1478-
iommu_device_unlink(&smmu->iommu, dev);
14791466
arm_smmu_master_free_smes(cfg, fwspec);
14801467

14811468
arm_smmu_rpm_put(smmu);
14821469

14831470
dev_iommu_priv_set(dev, NULL);
1484-
iommu_group_remove_device(dev);
14851471
kfree(cfg);
14861472
iommu_fwspec_free(dev);
14871473
}
@@ -1512,6 +1498,11 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
15121498
else
15131499
group = generic_device_group(dev);
15141500

1501+
/* Remember group for faster lookups */
1502+
if (!IS_ERR(group))
1503+
for_each_cfg_sme(cfg, fwspec, i, idx)
1504+
smmu->s2crs[idx].group = group;
1505+
15151506
return group;
15161507
}
15171508

@@ -1628,8 +1619,8 @@ static struct iommu_ops arm_smmu_ops = {
16281619
.flush_iotlb_all = arm_smmu_flush_iotlb_all,
16291620
.iotlb_sync = arm_smmu_iotlb_sync,
16301621
.iova_to_phys = arm_smmu_iova_to_phys,
1631-
.add_device = arm_smmu_add_device,
1632-
.remove_device = arm_smmu_remove_device,
1622+
.probe_device = arm_smmu_probe_device,
1623+
.release_device = arm_smmu_release_device,
16331624
.device_group = arm_smmu_device_group,
16341625
.domain_get_attr = arm_smmu_domain_get_attr,
16351626
.domain_set_attr = arm_smmu_domain_set_attr,

0 commit comments

Comments
 (0)