Skip to content

Commit 6785eb9

Browse files
committed
iommu/omap: Convert to probe/release_device() call-backs
Convert the OMAP IOMMU driver 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 c822b37 commit 6785eb9

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

drivers/iommu/omap-iommu.c

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,15 +1640,13 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
16401640
return ret;
16411641
}
16421642

1643-
static int omap_iommu_add_device(struct device *dev)
1643+
static struct iommu_device *omap_iommu_probe_device(struct device *dev)
16441644
{
16451645
struct omap_iommu_arch_data *arch_data, *tmp;
1646+
struct platform_device *pdev;
16461647
struct omap_iommu *oiommu;
1647-
struct iommu_group *group;
16481648
struct device_node *np;
1649-
struct platform_device *pdev;
16501649
int num_iommus, i;
1651-
int ret;
16521650

16531651
/*
16541652
* Allocate the archdata iommu structure for DT-based devices.
@@ -1657,7 +1655,7 @@ static int omap_iommu_add_device(struct device *dev)
16571655
* IOMMU users.
16581656
*/
16591657
if (!dev->of_node)
1660-
return 0;
1658+
return ERR_PTR(-ENODEV);
16611659

16621660
/*
16631661
* retrieve the count of IOMMU nodes using phandle size as element size
@@ -1670,27 +1668,27 @@ static int omap_iommu_add_device(struct device *dev)
16701668

16711669
arch_data = kcalloc(num_iommus + 1, sizeof(*arch_data), GFP_KERNEL);
16721670
if (!arch_data)
1673-
return -ENOMEM;
1671+
return ERR_PTR(-ENOMEM);
16741672

16751673
for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) {
16761674
np = of_parse_phandle(dev->of_node, "iommus", i);
16771675
if (!np) {
16781676
kfree(arch_data);
1679-
return -EINVAL;
1677+
return ERR_PTR(-EINVAL);
16801678
}
16811679

16821680
pdev = of_find_device_by_node(np);
16831681
if (!pdev) {
16841682
of_node_put(np);
16851683
kfree(arch_data);
1686-
return -ENODEV;
1684+
return ERR_PTR(-ENODEV);
16871685
}
16881686

16891687
oiommu = platform_get_drvdata(pdev);
16901688
if (!oiommu) {
16911689
of_node_put(np);
16921690
kfree(arch_data);
1693-
return -EINVAL;
1691+
return ERR_PTR(-EINVAL);
16941692
}
16951693

16961694
tmp->iommu_dev = oiommu;
@@ -1699,46 +1697,25 @@ static int omap_iommu_add_device(struct device *dev)
16991697
of_node_put(np);
17001698
}
17011699

1700+
dev->archdata.iommu = arch_data;
1701+
17021702
/*
17031703
* use the first IOMMU alone for the sysfs device linking.
17041704
* TODO: Evaluate if a single iommu_group needs to be
17051705
* maintained for both IOMMUs
17061706
*/
17071707
oiommu = arch_data->iommu_dev;
1708-
ret = iommu_device_link(&oiommu->iommu, dev);
1709-
if (ret) {
1710-
kfree(arch_data);
1711-
return ret;
1712-
}
1713-
1714-
dev->archdata.iommu = arch_data;
1715-
1716-
/*
1717-
* IOMMU group initialization calls into omap_iommu_device_group, which
1718-
* needs a valid dev->archdata.iommu pointer
1719-
*/
1720-
group = iommu_group_get_for_dev(dev);
1721-
if (IS_ERR(group)) {
1722-
iommu_device_unlink(&oiommu->iommu, dev);
1723-
dev->archdata.iommu = NULL;
1724-
kfree(arch_data);
1725-
return PTR_ERR(group);
1726-
}
1727-
iommu_group_put(group);
17281708

1729-
return 0;
1709+
return &oiommu->iommu;
17301710
}
17311711

1732-
static void omap_iommu_remove_device(struct device *dev)
1712+
static void omap_iommu_release_device(struct device *dev)
17331713
{
17341714
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
17351715

17361716
if (!dev->of_node || !arch_data)
17371717
return;
17381718

1739-
iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
1740-
iommu_group_remove_device(dev);
1741-
17421719
dev->archdata.iommu = NULL;
17431720
kfree(arch_data);
17441721

@@ -1763,8 +1740,8 @@ static const struct iommu_ops omap_iommu_ops = {
17631740
.map = omap_iommu_map,
17641741
.unmap = omap_iommu_unmap,
17651742
.iova_to_phys = omap_iommu_iova_to_phys,
1766-
.add_device = omap_iommu_add_device,
1767-
.remove_device = omap_iommu_remove_device,
1743+
.probe_device = omap_iommu_probe_device,
1744+
.release_device = omap_iommu_release_device,
17681745
.device_group = omap_iommu_device_group,
17691746
.pgsize_bitmap = OMAP_IOMMU_PGSIZES,
17701747
};

0 commit comments

Comments
 (0)