73 lines
2.2 KiB
Diff
73 lines
2.2 KiB
Diff
|
|
From c9f1b73eb36a84347c3720ce2a93f72ea47f5daa Mon Sep 17 00:00:00 2001
|
||
|
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Date: Wed, 5 Jun 2024 16:30:34 +0800
|
||
|
|
Subject: [PATCH] vfio/iommufd: Implement HostIOMMUDeviceClass::realize()
|
||
|
|
handler
|
||
|
|
|
||
|
|
It calls iommufd_backend_get_device_info() to get host IOMMU
|
||
|
|
related information and translate it into HostIOMMUDeviceCaps
|
||
|
|
for query with .get_cap().
|
||
|
|
|
||
|
|
For aw_bits, use the same way as legacy backend by calling
|
||
|
|
vfio_device_get_aw_bits() which is common for different vendor
|
||
|
|
IOMMU.
|
||
|
|
|
||
|
|
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Reviewed-by: Eric Auger <eric.auger@redhat.com>
|
||
|
|
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
---
|
||
|
|
hw/vfio/iommufd.c | 30 ++++++++++++++++++++++++++++++
|
||
|
|
1 file changed, 30 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
|
||
|
|
index 7a4b818830..2efdba5565 100644
|
||
|
|
--- a/hw/vfio/iommufd.c
|
||
|
|
+++ b/hw/vfio/iommufd.c
|
||
|
|
@@ -636,6 +636,35 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *klass, void *data)
|
||
|
|
vioc->pci_hot_reset = iommufd_cdev_pci_hot_reset;
|
||
|
|
};
|
||
|
|
|
||
|
|
+static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
|
||
|
|
+ Error **errp)
|
||
|
|
+{
|
||
|
|
+ VFIODevice *vdev = opaque;
|
||
|
|
+ HostIOMMUDeviceCaps *caps = &hiod->caps;
|
||
|
|
+ enum iommu_hw_info_type type;
|
||
|
|
+ union {
|
||
|
|
+ struct iommu_hw_info_vtd vtd;
|
||
|
|
+ } data;
|
||
|
|
+
|
||
|
|
+ if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid,
|
||
|
|
+ &type, &data, sizeof(data), errp)) {
|
||
|
|
+ return false;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ hiod->name = g_strdup(vdev->name);
|
||
|
|
+ caps->type = type;
|
||
|
|
+ caps->aw_bits = vfio_device_get_aw_bits(vdev);
|
||
|
|
+
|
||
|
|
+ return true;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data)
|
||
|
|
+{
|
||
|
|
+ HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_CLASS(oc);
|
||
|
|
+
|
||
|
|
+ hiodc->realize = hiod_iommufd_vfio_realize;
|
||
|
|
+};
|
||
|
|
+
|
||
|
|
static const TypeInfo types[] = {
|
||
|
|
{
|
||
|
|
.name = TYPE_VFIO_IOMMU_IOMMUFD,
|
||
|
|
@@ -644,6 +673,7 @@ static const TypeInfo types[] = {
|
||
|
|
}, {
|
||
|
|
.name = TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO,
|
||
|
|
.parent = TYPE_HOST_IOMMU_DEVICE_IOMMUFD,
|
||
|
|
+ .class_init = hiod_iommufd_vfio_class_init,
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|