Commit 21acf659 authored by Joerg Roedel's avatar Joerg Roedel

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: default avatarJoerg Roedel <jroedel@suse.de>
Link: https://lore.kernel.org/r/20200429133712.31431-21-joro@8bytes.orgSigned-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 522af649
...@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode) ...@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
return dev ? dev_to_virtio(dev)->priv : NULL; return dev ? dev_to_virtio(dev)->priv : NULL;
} }
static int viommu_add_device(struct device *dev) static struct iommu_device *viommu_probe_device(struct device *dev)
{ {
int ret; int ret;
struct iommu_group *group;
struct viommu_endpoint *vdev; struct viommu_endpoint *vdev;
struct viommu_dev *viommu = NULL; struct viommu_dev *viommu = NULL;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
if (!fwspec || fwspec->ops != &viommu_ops) if (!fwspec || fwspec->ops != &viommu_ops)
return -ENODEV; return ERR_PTR(-ENODEV);
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode); viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
if (!viommu) if (!viommu)
return -ENODEV; return ERR_PTR(-ENODEV);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev) if (!vdev)
return -ENOMEM; return ERR_PTR(-ENOMEM);
vdev->dev = dev; vdev->dev = dev;
vdev->viommu = viommu; vdev->viommu = viommu;
...@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev) ...@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
goto err_free_dev; goto err_free_dev;
} }
ret = iommu_device_link(&viommu->iommu, dev); return &viommu->iommu;
if (ret)
goto err_free_dev;
/*
* Last step creates a default domain and attaches to it. Everything
* must be ready.
*/
group = iommu_group_get_for_dev(dev);
if (IS_ERR(group)) {
ret = PTR_ERR(group);
goto err_unlink_dev;
}
iommu_group_put(group);
return PTR_ERR_OR_ZERO(group);
err_unlink_dev:
iommu_device_unlink(&viommu->iommu, dev);
err_free_dev: err_free_dev:
generic_iommu_put_resv_regions(dev, &vdev->resv_regions); generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev); kfree(vdev);
return ret; return ERR_PTR(ret);
} }
static void viommu_remove_device(struct device *dev) static void viommu_release_device(struct device *dev)
{ {
struct viommu_endpoint *vdev;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct viommu_endpoint *vdev;
if (!fwspec || fwspec->ops != &viommu_ops) if (!fwspec || fwspec->ops != &viommu_ops)
return; return;
vdev = dev_iommu_priv_get(dev); vdev = dev_iommu_priv_get(dev);
iommu_group_remove_device(dev);
iommu_device_unlink(&vdev->viommu->iommu, dev);
generic_iommu_put_resv_regions(dev, &vdev->resv_regions); generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev); kfree(vdev);
} }
...@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = { ...@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
.unmap = viommu_unmap, .unmap = viommu_unmap,
.iova_to_phys = viommu_iova_to_phys, .iova_to_phys = viommu_iova_to_phys,
.iotlb_sync = viommu_iotlb_sync, .iotlb_sync = viommu_iotlb_sync,
.add_device = viommu_add_device, .probe_device = viommu_probe_device,
.remove_device = viommu_remove_device, .release_device = viommu_release_device,
.device_group = viommu_device_group, .device_group = viommu_device_group,
.get_resv_regions = viommu_get_resv_regions, .get_resv_regions = viommu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment