[RFC PATCH 2/3] vfio/hisilicon: register the driver to vfio

From: Longfang Liu
Date: Mon Apr 12 2021 - 05:12:23 EST


Register the live migration driver of the accelerator module to vfio

Signed-off-by: Longfang Liu <liulongfang@xxxxxxxxxx>
Reviewed-by: Zengtao <prime.zeng@xxxxxxxxxxxxx>
---
drivers/vfio/pci/vfio_pci.c | 11 +++++++++++
drivers/vfio/pci/vfio_pci_private.h | 10 ++++++++++
2 files changed, 21 insertions(+)

diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index f041b1a..50d1138 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -293,6 +293,17 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
}
}

+ if (pdev->vendor == PCI_VENDOR_ID_HUAWEI &&
+ IS_ENABLED(CONFIG_VFIO_PCI_HISI_MIGRATION)) {
+ ret = vfio_pci_hisilicon_acc_init(vdev);
+ if (ret && ret != -ENODEV) {
+ dev_warn(&vdev->pdev->dev,
+ "Failed to setup Hisilicon ACC region\n");
+ vfio_pci_disable(vdev);
+ return ret;
+ }
+ }
+
vfio_pci_probe_mmaps(vdev);

return 0;
diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
index f561ac1..74bb611 100644
--- a/drivers/vfio/pci/vfio_pci_private.h
+++ b/drivers/vfio/pci/vfio_pci_private.h
@@ -138,4 +138,14 @@ static inline int vfio_pci_igd_init(struct vfio_pci_device *vdev)
return -ENODEV;
}
#endif
+
+#ifdef CONFIG_VFIO_PCI_HISI_MIGRATION
+extern int vfio_pci_hisilicon_acc_init(struct vfio_pci_device *vdev);
+#else
+static inline int vfio_pci_hisilicon_acc_init(struct vfio_pci_device *vdev)
+{
+ return -ENODEV;
+}
+#endif
+
#endif /* VFIO_PCI_PRIVATE_H */
--
2.8.1