[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/42] vfio/container: Implement HostIOMMUDeviceClass::realize() h
From: |
Cédric Le Goater |
Subject: |
[PULL 06/42] vfio/container: Implement HostIOMMUDeviceClass::realize() handler |
Date: |
Mon, 24 Jun 2024 23:24:20 +0200 |
From: Zhenzhong Duan <[email protected]>
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 <[email protected]>
Reviewed-by: Eric Auger <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
---
include/hw/vfio/vfio-common.h | 1 +
hw/vfio/container.c | 19 +++++++++++++++++++
hw/vfio/helpers.c | 17 +++++++++++++++++
3 files changed, 37 insertions(+)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index
56d171721164991b408073488330bf1d79104970..105b8b7e804d3de43868d447e21eb9bedc50808f
100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -289,4 +289,5 @@ bool 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 */
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index
c4fca2dfcab32781fb301181a1ef67238015a76f..2f62c13214412618b412240b61efcbe1b1c79ed5
100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -1136,6 +1136,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,
@@ -1144,6 +1162,7 @@ static const TypeInfo types[] = {
}, {
.name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
.parent = TYPE_HOST_IOMMU_DEVICE,
+ .class_init = hiod_legacy_vfio_class_init,
}
};
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index
27ea26aa48f67e6518f871ac651ab8d2703cc611..b14edd46edc9069bb148359a1b419253ff4e5ef0
100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -658,3 +658,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;
+}
--
2.45.2
- [PULL 00/42] vfio queue, Cédric Le Goater, 2024/06/24
- [PULL 01/42] backends: Introduce HostIOMMUDevice abstract, Cédric Le Goater, 2024/06/24
- [PULL 02/42] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps, Cédric Le Goater, 2024/06/24
- [PULL 04/42] backends/iommufd: Introduce TYPE_HOST_IOMMU_DEVICE_IOMMUFD[_VFIO] devices, Cédric Le Goater, 2024/06/24
- [PULL 03/42] vfio/container: Introduce TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO device, Cédric Le Goater, 2024/06/24
- [PULL 05/42] range: Introduce range_get_last_bit(), Cédric Le Goater, 2024/06/24
- [PULL 06/42] vfio/container: Implement HostIOMMUDeviceClass::realize() handler,
Cédric Le Goater <=
- [PULL 07/42] backends/iommufd: Introduce helper function iommufd_backend_get_device_info(), Cédric Le Goater, 2024/06/24
- [PULL 08/42] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler, Cédric Le Goater, 2024/06/24
- [PULL 09/42] vfio/container: Implement HostIOMMUDeviceClass::get_cap() handler, Cédric Le Goater, 2024/06/24
- [PULL 10/42] backends/iommufd: Implement HostIOMMUDeviceClass::get_cap() handler, Cédric Le Goater, 2024/06/24
- [PULL 11/42] vfio: Create host IOMMU device instance, Cédric Le Goater, 2024/06/24
- [PULL 12/42] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn(), Cédric Le Goater, 2024/06/24
- [PULL 13/42] hw/pci: Introduce pci_device_[set|unset]_iommu_device(), Cédric Le Goater, 2024/06/24
- [PULL 14/42] vfio/pci: Pass HostIOMMUDevice to vIOMMU, Cédric Le Goater, 2024/06/24
- [PULL 15/42] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap, Cédric Le Goater, 2024/06/24
- [PULL 16/42] intel_iommu: Implement [set|unset]_iommu_device() callbacks, Cédric Le Goater, 2024/06/24