Skip to content

Commit 21acf65

Browse files
committed
iommu/virtio: Convert to probe/release_device() call-backs
Convert the VirtIO 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 522af64 commit 21acf65

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

drivers/iommu/virtio-iommu.c

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
865865
return dev ? dev_to_virtio(dev)->priv : NULL;
866866
}
867867

868-
static int viommu_add_device(struct device *dev)
868+
static struct iommu_device *viommu_probe_device(struct device *dev)
869869
{
870870
int ret;
871-
struct iommu_group *group;
872871
struct viommu_endpoint *vdev;
873872
struct viommu_dev *viommu = NULL;
874873
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
875874

876875
if (!fwspec || fwspec->ops != &viommu_ops)
877-
return -ENODEV;
876+
return ERR_PTR(-ENODEV);
878877

879878
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
880879
if (!viommu)
881-
return -ENODEV;
880+
return ERR_PTR(-ENODEV);
882881

883882
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
884883
if (!vdev)
885-
return -ENOMEM;
884+
return ERR_PTR(-ENOMEM);
886885

887886
vdev->dev = dev;
888887
vdev->viommu = viommu;
@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
896895
goto err_free_dev;
897896
}
898897

899-
ret = iommu_device_link(&viommu->iommu, dev);
900-
if (ret)
901-
goto err_free_dev;
898+
return &viommu->iommu;
902899

903-
/*
904-
* Last step creates a default domain and attaches to it. Everything
905-
* must be ready.
906-
*/
907-
group = iommu_group_get_for_dev(dev);
908-
if (IS_ERR(group)) {
909-
ret = PTR_ERR(group);
910-
goto err_unlink_dev;
911-
}
912-
913-
iommu_group_put(group);
914-
915-
return PTR_ERR_OR_ZERO(group);
916-
917-
err_unlink_dev:
918-
iommu_device_unlink(&viommu->iommu, dev);
919900
err_free_dev:
920901
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
921902
kfree(vdev);
922903

923-
return ret;
904+
return ERR_PTR(ret);
924905
}
925906

926-
static void viommu_remove_device(struct device *dev)
907+
static void viommu_release_device(struct device *dev)
927908
{
928-
struct viommu_endpoint *vdev;
929909
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
910+
struct viommu_endpoint *vdev;
930911

931912
if (!fwspec || fwspec->ops != &viommu_ops)
932913
return;
933914

934915
vdev = dev_iommu_priv_get(dev);
935916

936-
iommu_group_remove_device(dev);
937-
iommu_device_unlink(&vdev->viommu->iommu, dev);
938917
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
939918
kfree(vdev);
940919
}
@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
960939
.unmap = viommu_unmap,
961940
.iova_to_phys = viommu_iova_to_phys,
962941
.iotlb_sync = viommu_iotlb_sync,
963-
.add_device = viommu_add_device,
964-
.remove_device = viommu_remove_device,
942+
.probe_device = viommu_probe_device,
943+
.release_device = viommu_release_device,
965944
.device_group = viommu_device_group,
966945
.get_resv_regions = viommu_get_resv_regions,
967946
.put_resv_regions = generic_iommu_put_resv_regions,

0 commit comments

Comments
 (0)