vfio/pci: Use the new device life cycle helpers
ANBZ: #10925
commit 63d7c77989
upstream.
Also introduce two pci core helpers as @init/@release for pci drivers:
- vfio_pci_core_init_dev()
- vfio_pci_core_release_dev()
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link:
https://lore.kernel.org/r/20220921104401.38898-3-kevin.tian@intel.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com>
Reviewed-by: Guanghui Feng <guanghuifeng@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/5474
This commit is contained in:
parent
a15af39fd9
commit
2eb10dcc63
|
@ -10,6 +10,7 @@
|
|||
* Author: Tom Lyon, pugs@cisco.com
|
||||
*/
|
||||
|
||||
#include "linux/vfio.h"
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <linux/device.h>
|
||||
|
@ -155,6 +156,8 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
|
|||
|
||||
static const struct vfio_device_ops vfio_pci_ops = {
|
||||
.name = "vfio-pci",
|
||||
.init = vfio_pci_core_init_dev,
|
||||
.release = vfio_pci_core_release_dev,
|
||||
.open_device = vfio_pci_open_device,
|
||||
.close_device = vfio_pci_core_close_device,
|
||||
.ioctl = vfio_pci_core_ioctl,
|
||||
|
@ -174,20 +177,19 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|||
if (vfio_pci_is_denylisted(pdev))
|
||||
return -EINVAL;
|
||||
|
||||
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
|
||||
if (!vdev)
|
||||
return -ENOMEM;
|
||||
vfio_pci_core_init_device(vdev, pdev, &vfio_pci_ops);
|
||||
vdev = vfio_alloc_device(vfio_pci_core_device, vdev, &pdev->dev,
|
||||
&vfio_pci_ops);
|
||||
if (IS_ERR(vdev))
|
||||
return PTR_ERR(vdev);
|
||||
|
||||
ret = vfio_pci_core_register_device(vdev);
|
||||
if (ret)
|
||||
goto out_free;
|
||||
goto out_put_vdev;
|
||||
dev_set_drvdata(&pdev->dev, vdev);
|
||||
return 0;
|
||||
|
||||
out_free:
|
||||
vfio_pci_core_uninit_device(vdev);
|
||||
kfree(vdev);
|
||||
out_put_vdev:
|
||||
vfio_put_device(&vdev->vdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -196,8 +198,7 @@ static void vfio_pci_remove(struct pci_dev *pdev)
|
|||
struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev);
|
||||
|
||||
vfio_pci_core_unregister_device(vdev);
|
||||
vfio_pci_core_uninit_device(vdev);
|
||||
kfree(vdev);
|
||||
vfio_put_device(&vdev->vdev);
|
||||
}
|
||||
|
||||
static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn)
|
||||
|
|
|
@ -2128,6 +2128,41 @@ static void vfio_pci_vga_uninit(struct vfio_pci_core_device *vdev)
|
|||
VGA_RSRC_LEGACY_MEM);
|
||||
}
|
||||
|
||||
int vfio_pci_core_init_dev(struct vfio_device *core_vdev)
|
||||
{
|
||||
struct vfio_pci_core_device *vdev =
|
||||
container_of(core_vdev, struct vfio_pci_core_device, vdev);
|
||||
|
||||
vdev->pdev = to_pci_dev(core_vdev->dev);
|
||||
vdev->irq_type = VFIO_PCI_NUM_IRQS;
|
||||
mutex_init(&vdev->igate);
|
||||
spin_lock_init(&vdev->irqlock);
|
||||
mutex_init(&vdev->ioeventfds_lock);
|
||||
INIT_LIST_HEAD(&vdev->dummy_resources_list);
|
||||
INIT_LIST_HEAD(&vdev->ioeventfds_list);
|
||||
mutex_init(&vdev->vma_lock);
|
||||
INIT_LIST_HEAD(&vdev->vma_list);
|
||||
INIT_LIST_HEAD(&vdev->sriov_pfs_item);
|
||||
init_rwsem(&vdev->memory_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vfio_pci_core_init_dev);
|
||||
|
||||
void vfio_pci_core_release_dev(struct vfio_device *core_vdev)
|
||||
{
|
||||
struct vfio_pci_core_device *vdev =
|
||||
container_of(core_vdev, struct vfio_pci_core_device, vdev);
|
||||
|
||||
mutex_destroy(&vdev->igate);
|
||||
mutex_destroy(&vdev->ioeventfds_lock);
|
||||
mutex_destroy(&vdev->vma_lock);
|
||||
kfree(vdev->region);
|
||||
kfree(vdev->pm_save);
|
||||
vfio_free_device(core_vdev);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vfio_pci_core_release_dev);
|
||||
|
||||
void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev,
|
||||
struct pci_dev *pdev,
|
||||
const struct vfio_device_ops *vfio_pci_ops)
|
||||
|
|
|
@ -268,6 +268,8 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev);
|
|||
void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev,
|
||||
struct pci_dev *pdev,
|
||||
const struct vfio_device_ops *vfio_pci_ops);
|
||||
int vfio_pci_core_init_dev(struct vfio_device *core_vdev);
|
||||
void vfio_pci_core_release_dev(struct vfio_device *core_vdev);
|
||||
int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev);
|
||||
void vfio_pci_core_uninit_device(struct vfio_pci_core_device *vdev);
|
||||
void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev);
|
||||
|
|
Loading…
Reference in New Issue