mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
vfio/amba: Use the new device life cycle helpers
Implement amba's own vfio_device_ops. Remove vfio_platform_probe/remove_common() given no user now. Signed-off-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Link: https://lore.kernel.org/r/20220921104401.38898-13-kevin.tian@intel.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
5f6c7e0831
commit
ac1237912f
3 changed files with 55 additions and 80 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/vfio.h>
|
#include <linux/vfio.h>
|
||||||
|
#include <linux/pm_runtime.h>
|
||||||
#include <linux/amba/bus.h>
|
#include <linux/amba/bus.h>
|
||||||
|
|
||||||
#include "vfio_platform_private.h"
|
#include "vfio_platform_private.h"
|
||||||
|
@ -40,20 +41,16 @@ static int get_amba_irq(struct vfio_platform_device *vdev, int i)
|
||||||
return ret ? ret : -ENXIO;
|
return ret ? ret : -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
|
static int vfio_amba_init_dev(struct vfio_device *core_vdev)
|
||||||
{
|
{
|
||||||
struct vfio_platform_device *vdev;
|
struct vfio_platform_device *vdev =
|
||||||
|
container_of(core_vdev, struct vfio_platform_device, vdev);
|
||||||
|
struct amba_device *adev = to_amba_device(core_vdev->dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
|
|
||||||
if (!vdev)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
vdev->name = kasprintf(GFP_KERNEL, "vfio-amba-%08x", adev->periphid);
|
vdev->name = kasprintf(GFP_KERNEL, "vfio-amba-%08x", adev->periphid);
|
||||||
if (!vdev->name) {
|
if (!vdev->name)
|
||||||
kfree(vdev);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
vdev->opaque = (void *) adev;
|
vdev->opaque = (void *) adev;
|
||||||
vdev->flags = VFIO_DEVICE_FLAGS_AMBA;
|
vdev->flags = VFIO_DEVICE_FLAGS_AMBA;
|
||||||
|
@ -61,26 +58,67 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
|
||||||
vdev->get_irq = get_amba_irq;
|
vdev->get_irq = get_amba_irq;
|
||||||
vdev->reset_required = false;
|
vdev->reset_required = false;
|
||||||
|
|
||||||
ret = vfio_platform_probe_common(vdev, &adev->dev);
|
ret = vfio_platform_init_common(vdev);
|
||||||
if (ret) {
|
if (ret)
|
||||||
kfree(vdev->name);
|
kfree(vdev->name);
|
||||||
kfree(vdev);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct vfio_device_ops vfio_amba_ops;
|
||||||
|
static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
|
||||||
|
{
|
||||||
|
struct vfio_platform_device *vdev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
vdev = vfio_alloc_device(vfio_platform_device, vdev, &adev->dev,
|
||||||
|
&vfio_amba_ops);
|
||||||
|
if (IS_ERR(vdev))
|
||||||
|
return PTR_ERR(vdev);
|
||||||
|
|
||||||
|
ret = vfio_register_group_dev(&vdev->vdev);
|
||||||
|
if (ret)
|
||||||
|
goto out_put_vdev;
|
||||||
|
|
||||||
|
pm_runtime_enable(&adev->dev);
|
||||||
dev_set_drvdata(&adev->dev, vdev);
|
dev_set_drvdata(&adev->dev, vdev);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_put_vdev:
|
||||||
|
vfio_put_device(&vdev->vdev);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vfio_amba_release_dev(struct vfio_device *core_vdev)
|
||||||
|
{
|
||||||
|
struct vfio_platform_device *vdev =
|
||||||
|
container_of(core_vdev, struct vfio_platform_device, vdev);
|
||||||
|
|
||||||
|
vfio_platform_release_common(vdev);
|
||||||
|
kfree(vdev->name);
|
||||||
|
vfio_free_device(core_vdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vfio_amba_remove(struct amba_device *adev)
|
static void vfio_amba_remove(struct amba_device *adev)
|
||||||
{
|
{
|
||||||
struct vfio_platform_device *vdev = dev_get_drvdata(&adev->dev);
|
struct vfio_platform_device *vdev = dev_get_drvdata(&adev->dev);
|
||||||
|
|
||||||
vfio_platform_remove_common(vdev);
|
vfio_unregister_group_dev(&vdev->vdev);
|
||||||
kfree(vdev->name);
|
pm_runtime_disable(vdev->device);
|
||||||
kfree(vdev);
|
vfio_put_device(&vdev->vdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct vfio_device_ops vfio_amba_ops = {
|
||||||
|
.name = "vfio-amba",
|
||||||
|
.init = vfio_amba_init_dev,
|
||||||
|
.release = vfio_amba_release_dev,
|
||||||
|
.open_device = vfio_platform_open_device,
|
||||||
|
.close_device = vfio_platform_close_device,
|
||||||
|
.ioctl = vfio_platform_ioctl,
|
||||||
|
.read = vfio_platform_read,
|
||||||
|
.write = vfio_platform_write,
|
||||||
|
.mmap = vfio_platform_mmap,
|
||||||
|
};
|
||||||
|
|
||||||
static const struct amba_id pl330_ids[] = {
|
static const struct amba_id pl330_ids[] = {
|
||||||
{ 0, 0 },
|
{ 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
|
@ -605,16 +605,6 @@ int vfio_platform_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(vfio_platform_mmap);
|
EXPORT_SYMBOL_GPL(vfio_platform_mmap);
|
||||||
|
|
||||||
static const struct vfio_device_ops vfio_platform_ops = {
|
|
||||||
.name = "vfio-platform",
|
|
||||||
.open_device = vfio_platform_open_device,
|
|
||||||
.close_device = vfio_platform_close_device,
|
|
||||||
.ioctl = vfio_platform_ioctl,
|
|
||||||
.read = vfio_platform_read,
|
|
||||||
.write = vfio_platform_write,
|
|
||||||
.mmap = vfio_platform_mmap,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int vfio_platform_of_probe(struct vfio_platform_device *vdev,
|
static int vfio_platform_of_probe(struct vfio_platform_device *vdev,
|
||||||
struct device *dev)
|
struct device *dev)
|
||||||
{
|
{
|
||||||
|
@ -674,56 +664,6 @@ void vfio_platform_release_common(struct vfio_platform_device *vdev)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(vfio_platform_release_common);
|
EXPORT_SYMBOL_GPL(vfio_platform_release_common);
|
||||||
|
|
||||||
int vfio_platform_probe_common(struct vfio_platform_device *vdev,
|
|
||||||
struct device *dev)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
vfio_init_group_dev(&vdev->vdev, dev, &vfio_platform_ops);
|
|
||||||
|
|
||||||
ret = vfio_platform_acpi_probe(vdev, dev);
|
|
||||||
if (ret)
|
|
||||||
ret = vfio_platform_of_probe(vdev, dev);
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
goto out_uninit;
|
|
||||||
|
|
||||||
vdev->device = dev;
|
|
||||||
|
|
||||||
ret = vfio_platform_get_reset(vdev);
|
|
||||||
if (ret && vdev->reset_required) {
|
|
||||||
dev_err(dev, "No reset function found for device %s\n",
|
|
||||||
vdev->name);
|
|
||||||
goto out_uninit;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = vfio_register_group_dev(&vdev->vdev);
|
|
||||||
if (ret)
|
|
||||||
goto put_reset;
|
|
||||||
|
|
||||||
mutex_init(&vdev->igate);
|
|
||||||
|
|
||||||
pm_runtime_enable(dev);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
put_reset:
|
|
||||||
vfio_platform_put_reset(vdev);
|
|
||||||
out_uninit:
|
|
||||||
vfio_uninit_group_dev(&vdev->vdev);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(vfio_platform_probe_common);
|
|
||||||
|
|
||||||
void vfio_platform_remove_common(struct vfio_platform_device *vdev)
|
|
||||||
{
|
|
||||||
vfio_unregister_group_dev(&vdev->vdev);
|
|
||||||
|
|
||||||
pm_runtime_disable(vdev->device);
|
|
||||||
vfio_platform_put_reset(vdev);
|
|
||||||
vfio_uninit_group_dev(&vdev->vdev);
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(vfio_platform_remove_common);
|
|
||||||
|
|
||||||
void __vfio_platform_register_reset(struct vfio_platform_reset_node *node)
|
void __vfio_platform_register_reset(struct vfio_platform_reset_node *node)
|
||||||
{
|
{
|
||||||
mutex_lock(&driver_lock);
|
mutex_lock(&driver_lock);
|
||||||
|
|
|
@ -78,9 +78,6 @@ struct vfio_platform_reset_node {
|
||||||
vfio_platform_reset_fn_t of_reset;
|
vfio_platform_reset_fn_t of_reset;
|
||||||
};
|
};
|
||||||
|
|
||||||
int vfio_platform_probe_common(struct vfio_platform_device *vdev,
|
|
||||||
struct device *dev);
|
|
||||||
void vfio_platform_remove_common(struct vfio_platform_device *vdev);
|
|
||||||
int vfio_platform_init_common(struct vfio_platform_device *vdev);
|
int vfio_platform_init_common(struct vfio_platform_device *vdev);
|
||||||
void vfio_platform_release_common(struct vfio_platform_device *vdev);
|
void vfio_platform_release_common(struct vfio_platform_device *vdev);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue