101 lines
3.3 KiB
Diff
101 lines
3.3 KiB
Diff
|
|
From c66d22fa4ee9f6f38193256d7ce1494c32e10581 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Date: Wed, 5 Jun 2024 16:30:32 +0800
|
||
|
|
Subject: [PATCH] vfio/container: Implement HostIOMMUDeviceClass::realize()
|
||
|
|
handler
|
||
|
|
|
||
|
|
The realize function populates the capabilities. For now only the
|
||
|
|
aw_bits caps is computed for legacy backend.
|
||
|
|
|
||
|
|
Introduce a helper function vfio_device_get_aw_bits() which calls
|
||
|
|
range_get_last_bit() to get host aw_bits and package it in
|
||
|
|
HostIOMMUDeviceCaps for query with .get_cap(). This helper will
|
||
|
|
also be used by iommufd backend.
|
||
|
|
|
||
|
|
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/container.c | 20 +++++++++++++++++++-
|
||
|
|
hw/vfio/helpers.c | 17 +++++++++++++++++
|
||
|
|
include/hw/vfio/vfio-common.h | 1 +
|
||
|
|
3 files changed, 37 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
|
||
|
|
index dcf49af2d0..fbe2bc50d4 100644
|
||
|
|
--- a/hw/vfio/container.c
|
||
|
|
+++ b/hw/vfio/container.c
|
||
|
|
@@ -1250,6 +1250,24 @@ static void vfio_iommu_legacy_class_init(ObjectClass *klass, void *data)
|
||
|
|
vioc->pci_hot_reset = vfio_legacy_pci_hot_reset;
|
||
|
|
};
|
||
|
|
|
||
|
|
+static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
|
||
|
|
+ Error **errp)
|
||
|
|
+{
|
||
|
|
+ VFIODevice *vdev = opaque;
|
||
|
|
+
|
||
|
|
+ hiod->name = g_strdup(vdev->name);
|
||
|
|
+ hiod->caps.aw_bits = vfio_device_get_aw_bits(vdev);
|
||
|
|
+
|
||
|
|
+ return true;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data)
|
||
|
|
+{
|
||
|
|
+ HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc);
|
||
|
|
+
|
||
|
|
+ hioc->realize = hiod_legacy_vfio_realize;
|
||
|
|
+};
|
||
|
|
+
|
||
|
|
static const TypeInfo types[] = {
|
||
|
|
{
|
||
|
|
.name = TYPE_VFIO_IOMMU_LEGACY,
|
||
|
|
@@ -1258,8 +1276,8 @@ static const TypeInfo types[] = {
|
||
|
|
}, {
|
||
|
|
.name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
|
||
|
|
.parent = TYPE_HOST_IOMMU_DEVICE,
|
||
|
|
+ .class_init = hiod_legacy_vfio_class_init,
|
||
|
|
}
|
||
|
|
-
|
||
|
|
};
|
||
|
|
|
||
|
|
DEFINE_TYPES(types)
|
||
|
|
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
|
||
|
|
index 6789870802..35b8e42304 100644
|
||
|
|
--- a/hw/vfio/helpers.c
|
||
|
|
+++ b/hw/vfio/helpers.c
|
||
|
|
@@ -663,3 +663,20 @@ void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
|
||
|
|
|
||
|
|
vbasedev->ram_block_discard_allowed = ram_discard;
|
||
|
|
}
|
||
|
|
+
|
||
|
|
+int vfio_device_get_aw_bits(VFIODevice *vdev)
|
||
|
|
+{
|
||
|
|
+ /*
|
||
|
|
+ * iova_ranges is a sorted list. For old kernels that support
|
||
|
|
+ * VFIO but not support query of iova ranges, iova_ranges is NULL,
|
||
|
|
+ * in this case HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX(64) is returned.
|
||
|
|
+ */
|
||
|
|
+ GList *l = g_list_last(vdev->bcontainer->iova_ranges);
|
||
|
|
+
|
||
|
|
+ if (l) {
|
||
|
|
+ Range *range = l->data;
|
||
|
|
+ return range_get_last_bit(range) + 1;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX;
|
||
|
|
+}
|
||
|
|
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
|
||
|
|
index 2cfc8521cd..376b8350b9 100644
|
||
|
|
--- a/include/hw/vfio/vfio-common.h
|
||
|
|
+++ b/include/hw/vfio/vfio-common.h
|
||
|
|
@@ -277,4 +277,5 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
|
||
|
|
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
|
||
|
|
void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
|
||
|
|
DeviceState *dev, bool ram_discard);
|
||
|
|
+int vfio_device_get_aw_bits(VFIODevice *vdev);
|
||
|
|
#endif /* HW_VFIO_VFIO_COMMON_H */
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|