mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-10 15:58:47 +00:00
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 <jroedel@suse.de> Link: https://lore.kernel.org/r/20200429133712.31431-21-joro@8bytes.org Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
522af649e5
commit
21acf6599c
@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
|
||||
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;
|
||||
struct iommu_group *group;
|
||||
struct viommu_endpoint *vdev;
|
||||
struct viommu_dev *viommu = NULL;
|
||||
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
|
||||
|
||||
if (!fwspec || fwspec->ops != &viommu_ops)
|
||||
return -ENODEV;
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
|
||||
if (!viommu)
|
||||
return -ENODEV;
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
|
||||
if (!vdev)
|
||||
return -ENOMEM;
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
vdev->dev = dev;
|
||||
vdev->viommu = viommu;
|
||||
@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
|
||||
goto err_free_dev;
|
||||
}
|
||||
|
||||
ret = iommu_device_link(&viommu->iommu, dev);
|
||||
if (ret)
|
||||
goto err_free_dev;
|
||||
return &viommu->iommu;
|
||||
|
||||
/*
|
||||
* 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:
|
||||
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
|
||||
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 viommu_endpoint *vdev;
|
||||
|
||||
if (!fwspec || fwspec->ops != &viommu_ops)
|
||||
return;
|
||||
|
||||
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);
|
||||
kfree(vdev);
|
||||
}
|
||||
@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
|
||||
.unmap = viommu_unmap,
|
||||
.iova_to_phys = viommu_iova_to_phys,
|
||||
.iotlb_sync = viommu_iotlb_sync,
|
||||
.add_device = viommu_add_device,
|
||||
.remove_device = viommu_remove_device,
|
||||
.probe_device = viommu_probe_device,
|
||||
.release_device = viommu_release_device,
|
||||
.device_group = viommu_device_group,
|
||||
.get_resv_regions = viommu_get_resv_regions,
|
||||
.put_resv_regions = generic_iommu_put_resv_regions,
|
||||
|
Loading…
x
Reference in New Issue
Block a user