Skip to content

Commit 342d3c1

Browse files
committed
Merge branch 'iommu/fwspec-ops-removal' into iommu/next
* iommu/fwspec-ops-removal: iommu: Remove iommu_fwspec ops OF: Simplify of_iommu_configure() ACPI: Retire acpi_iommu_fwspec_ops() iommu: Resolve fwspec ops automatically iommu/mediatek-v1: Clean up redundant fwspec checks [will: Fixed conflict in drivers/iommu/tegra-smmu.c between fwspec ops removal and fwspec driver fix as per Robin and Jon]
2 parents c2b2e5c + 3e36c15 commit 342d3c1

File tree

12 files changed

+67
-141
lines changed

12 files changed

+67
-141
lines changed

drivers/acpi/arm64/iort.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,30 +1221,21 @@ static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node)
12211221
static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
12221222
u32 streamid)
12231223
{
1224-
const struct iommu_ops *ops;
12251224
struct fwnode_handle *iort_fwnode;
12261225

1227-
if (!node)
1226+
/* If there's no SMMU driver at all, give up now */
1227+
if (!node || !iort_iommu_driver_enabled(node->type))
12281228
return -ENODEV;
12291229

12301230
iort_fwnode = iort_get_fwnode(node);
12311231
if (!iort_fwnode)
12321232
return -ENODEV;
12331233

12341234
/*
1235-
* If the ops look-up fails, this means that either
1236-
* the SMMU drivers have not been probed yet or that
1237-
* the SMMU drivers are not built in the kernel;
1238-
* Depending on whether the SMMU drivers are built-in
1239-
* in the kernel or not, defer the IOMMU configuration
1240-
* or just abort it.
1235+
* If the SMMU drivers are enabled but not loaded/probed
1236+
* yet, this will defer.
12411237
*/
1242-
ops = iommu_ops_from_fwnode(iort_fwnode);
1243-
if (!ops)
1244-
return iort_iommu_driver_enabled(node->type) ?
1245-
-EPROBE_DEFER : -ENODEV;
1246-
1247-
return acpi_iommu_fwspec_init(dev, streamid, iort_fwnode, ops);
1238+
return acpi_iommu_fwspec_init(dev, streamid, iort_fwnode);
12481239
}
12491240

12501241
struct iort_pci_alias_info {

drivers/acpi/scan.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,38 +1577,25 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
15771577

15781578
#ifdef CONFIG_IOMMU_API
15791579
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
1580-
struct fwnode_handle *fwnode,
1581-
const struct iommu_ops *ops)
1580+
struct fwnode_handle *fwnode)
15821581
{
15831582
int ret;
15841583

1585-
ret = iommu_fwspec_init(dev, fwnode, ops);
1584+
ret = iommu_fwspec_init(dev, fwnode);
15861585
if (ret)
15871586
return ret;
15881587

15891588
return iommu_fwspec_add_ids(dev, &id, 1);
15901589
}
15911590

1592-
static inline const struct iommu_ops *acpi_iommu_fwspec_ops(struct device *dev)
1593-
{
1594-
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1595-
1596-
return fwspec ? fwspec->ops : NULL;
1597-
}
1598-
15991591
static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
16001592
{
16011593
int err;
1602-
const struct iommu_ops *ops;
16031594

16041595
/* Serialise to make dev->iommu stable under our potential fwspec */
16051596
mutex_lock(&iommu_probe_device_lock);
1606-
/*
1607-
* If we already translated the fwspec there is nothing left to do,
1608-
* return the iommu_ops.
1609-
*/
1610-
ops = acpi_iommu_fwspec_ops(dev);
1611-
if (ops) {
1597+
/* If we already translated the fwspec there is nothing left to do */
1598+
if (dev_iommu_fwspec_get(dev)) {
16121599
mutex_unlock(&iommu_probe_device_lock);
16131600
return 0;
16141601
}
@@ -1625,22 +1612,13 @@ static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
16251612
if (!err && dev->bus)
16261613
err = iommu_probe_device(dev);
16271614

1628-
if (err == -EPROBE_DEFER)
1629-
return err;
1630-
if (err) {
1631-
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
1632-
return err;
1633-
}
1634-
if (!acpi_iommu_fwspec_ops(dev))
1635-
return -ENODEV;
1636-
return 0;
1615+
return err;
16371616
}
16381617

16391618
#else /* !CONFIG_IOMMU_API */
16401619

16411620
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
1642-
struct fwnode_handle *fwnode,
1643-
const struct iommu_ops *ops)
1621+
struct fwnode_handle *fwnode)
16441622
{
16451623
return -ENODEV;
16461624
}
@@ -1674,6 +1652,8 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
16741652
ret = acpi_iommu_configure_id(dev, input_id);
16751653
if (ret == -EPROBE_DEFER)
16761654
return -EPROBE_DEFER;
1655+
if (ret)
1656+
dev_dbg(dev, "Adding to IOMMU failed: %d\n", ret);
16771657

16781658
arch_setup_dma_ops(dev, attr == DEV_DMA_COHERENT);
16791659

drivers/acpi/viot.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,14 @@ void __init acpi_viot_init(void)
307307
static int viot_dev_iommu_init(struct device *dev, struct viot_iommu *viommu,
308308
u32 epid)
309309
{
310-
const struct iommu_ops *ops;
311-
312-
if (!viommu)
310+
if (!viommu || !IS_ENABLED(CONFIG_VIRTIO_IOMMU))
313311
return -ENODEV;
314312

315313
/* We're not translating ourself */
316314
if (device_match_fwnode(dev, viommu->fwnode))
317315
return -EINVAL;
318316

319-
ops = iommu_ops_from_fwnode(viommu->fwnode);
320-
if (!ops)
321-
return IS_ENABLED(CONFIG_VIRTIO_IOMMU) ?
322-
-EPROBE_DEFER : -ENODEV;
323-
324-
return acpi_iommu_fwspec_init(dev, epid, viommu->fwnode, ops);
317+
return acpi_iommu_fwspec_init(dev, epid, viommu->fwnode);
325318
}
326319

327320
static int viot_pci_dev_iommu_init(struct pci_dev *pdev, u16 dev_id, void *data)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ static int arm_smmu_register_legacy_master(struct device *dev,
178178
it.cur_count = 1;
179179
}
180180

181-
err = iommu_fwspec_init(dev, &smmu_dev->of_node->fwnode,
182-
&arm_smmu_ops);
181+
err = iommu_fwspec_init(dev, NULL);
183182
if (err)
184183
return err;
185184

drivers/iommu/iommu-priv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ static inline const struct iommu_ops *dev_iommu_ops(struct device *dev)
1717
return dev->iommu->iommu_dev->ops;
1818
}
1919

20+
const struct iommu_ops *iommu_ops_from_fwnode(const struct fwnode_handle *fwnode);
21+
22+
static inline const struct iommu_ops *iommu_fwspec_ops(struct iommu_fwspec *fwspec)
23+
{
24+
return iommu_ops_from_fwnode(fwspec ? fwspec->iommu_fwnode : NULL);
25+
}
26+
2027
int iommu_group_replace_domain(struct iommu_group *group,
2128
struct iommu_domain *new_domain);
2229

drivers/iommu/iommu.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ DEFINE_MUTEX(iommu_probe_device_lock);
510510
static int __iommu_probe_device(struct device *dev, struct list_head *group_list)
511511
{
512512
const struct iommu_ops *ops;
513-
struct iommu_fwspec *fwspec;
514513
struct iommu_group *group;
515514
struct group_device *gdev;
516515
int ret;
@@ -523,12 +522,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
523522
* be present, and that any of their registered instances has suitable
524523
* ops for probing, and thus cheekily co-opt the same mechanism.
525524
*/
526-
fwspec = dev_iommu_fwspec_get(dev);
527-
if (fwspec && fwspec->ops)
528-
ops = fwspec->ops;
529-
else
530-
ops = iommu_ops_from_fwnode(NULL);
531-
525+
ops = iommu_fwspec_ops(dev_iommu_fwspec_get(dev));
532526
if (!ops)
533527
return -ENODEV;
534528
/*
@@ -2822,13 +2816,16 @@ const struct iommu_ops *iommu_ops_from_fwnode(const struct fwnode_handle *fwnode
28222816
return ops;
28232817
}
28242818

2825-
int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
2826-
const struct iommu_ops *ops)
2819+
int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode)
28272820
{
2821+
const struct iommu_ops *ops = iommu_ops_from_fwnode(iommu_fwnode);
28282822
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
28292823

2824+
if (!ops)
2825+
return -EPROBE_DEFER;
2826+
28302827
if (fwspec)
2831-
return ops == fwspec->ops ? 0 : -EINVAL;
2828+
return ops == iommu_fwspec_ops(fwspec) ? 0 : -EINVAL;
28322829

28332830
if (!dev_iommu_get(dev))
28342831
return -ENOMEM;
@@ -2838,9 +2835,8 @@ int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
28382835
if (!fwspec)
28392836
return -ENOMEM;
28402837

2841-
of_node_get(to_of_node(iommu_fwnode));
2838+
fwnode_handle_get(iommu_fwnode);
28422839
fwspec->iommu_fwnode = iommu_fwnode;
2843-
fwspec->ops = ops;
28442840
dev_iommu_fwspec_set(dev, fwspec);
28452841
return 0;
28462842
}

drivers/iommu/mtk_iommu_v1.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ static const struct iommu_ops mtk_iommu_v1_ops;
401401
static int mtk_iommu_v1_create_mapping(struct device *dev,
402402
const struct of_phandle_args *args)
403403
{
404-
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
405404
struct mtk_iommu_v1_data *data;
406405
struct platform_device *m4updev;
407406
struct dma_iommu_mapping *mtk_mapping;
@@ -413,14 +412,9 @@ static int mtk_iommu_v1_create_mapping(struct device *dev,
413412
return -EINVAL;
414413
}
415414

416-
if (!fwspec) {
417-
ret = iommu_fwspec_init(dev, &args->np->fwnode, &mtk_iommu_v1_ops);
418-
if (ret)
419-
return ret;
420-
fwspec = dev_iommu_fwspec_get(dev);
421-
} else if (dev_iommu_fwspec_get(dev)->ops != &mtk_iommu_v1_ops) {
422-
return -EINVAL;
423-
}
415+
ret = iommu_fwspec_init(dev, of_fwnode_handle(args->np));
416+
if (ret)
417+
return ret;
424418

425419
if (!dev_iommu_priv_get(dev)) {
426420
/* Get the m4u device */

drivers/iommu/of_iommu.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,25 @@
1717
#include <linux/slab.h>
1818
#include <linux/fsl/mc.h>
1919

20+
#include "iommu-priv.h"
21+
2022
static int of_iommu_xlate(struct device *dev,
2123
struct of_phandle_args *iommu_spec)
2224
{
2325
const struct iommu_ops *ops;
24-
struct fwnode_handle *fwnode = &iommu_spec->np->fwnode;
2526
int ret;
2627

27-
ops = iommu_ops_from_fwnode(fwnode);
28-
if ((ops && !ops->of_xlate) ||
29-
!of_device_is_available(iommu_spec->np))
28+
if (!of_device_is_available(iommu_spec->np))
3029
return -ENODEV;
3130

32-
ret = iommu_fwspec_init(dev, fwnode, ops);
31+
ret = iommu_fwspec_init(dev, of_fwnode_handle(iommu_spec->np));
32+
if (ret == -EPROBE_DEFER)
33+
return driver_deferred_probe_check_state(dev);
3334
if (ret)
3435
return ret;
35-
/*
36-
* The otherwise-empty fwspec handily serves to indicate the specific
37-
* IOMMU device we're waiting for, which will be useful if we ever get
38-
* a proper probe-ordering dependency mechanism in future.
39-
*/
40-
if (!ops)
41-
return driver_deferred_probe_check_state(dev);
4236

43-
if (!try_module_get(ops->owner))
37+
ops = iommu_ops_from_fwnode(&iommu_spec->np->fwnode);
38+
if (!ops->of_xlate || !try_module_get(ops->owner))
4439
return -ENODEV;
4540

4641
ret = ops->of_xlate(dev, iommu_spec);
@@ -115,22 +110,16 @@ static int of_iommu_configure_device(struct device_node *master_np,
115110
int of_iommu_configure(struct device *dev, struct device_node *master_np,
116111
const u32 *id)
117112
{
118-
struct iommu_fwspec *fwspec;
119113
int err;
120114

121115
if (!master_np)
122116
return -ENODEV;
123117

124118
/* Serialise to make dev->iommu stable under our potential fwspec */
125119
mutex_lock(&iommu_probe_device_lock);
126-
fwspec = dev_iommu_fwspec_get(dev);
127-
if (fwspec) {
128-
if (fwspec->ops) {
129-
mutex_unlock(&iommu_probe_device_lock);
130-
return 0;
131-
}
132-
/* In the deferred case, start again from scratch */
133-
iommu_fwspec_free(dev);
120+
if (dev_iommu_fwspec_get(dev)) {
121+
mutex_unlock(&iommu_probe_device_lock);
122+
return 0;
134123
}
135124

136125
/*
@@ -150,20 +139,17 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
150139
} else {
151140
err = of_iommu_configure_device(master_np, dev, id);
152141
}
153-
mutex_unlock(&iommu_probe_device_lock);
154142

155-
if (err == -ENODEV || err == -EPROBE_DEFER)
156-
return err;
157143
if (err)
158-
goto err_log;
144+
iommu_fwspec_free(dev);
145+
mutex_unlock(&iommu_probe_device_lock);
159146

160-
err = iommu_probe_device(dev);
161-
if (err)
162-
goto err_log;
163-
return 0;
147+
if (!err && dev->bus)
148+
err = iommu_probe_device(dev);
149+
150+
if (err && err != -EPROBE_DEFER)
151+
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
164152

165-
err_log:
166-
dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
167153
return err;
168154
}
169155

drivers/iommu/tegra-smmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
837837
const struct iommu_ops *ops = smmu->iommu.ops;
838838
int err;
839839

840-
err = iommu_fwspec_init(dev, &smmu->dev->of_node->fwnode, ops);
840+
err = iommu_fwspec_init(dev, dev_fwnode(smmu->dev));
841841
if (err < 0) {
842842
dev_err(dev, "failed to initialize fwspec: %d\n", err);
843843
return err;

0 commit comments

Comments
 (0)