[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/26] vfio: add vfio_attach_device_by_iommu_type()
From: |
John Levon |
Subject: |
[PATCH 04/26] vfio: add vfio_attach_device_by_iommu_type() |
Date: |
Wed, 8 Jan 2025 11:50:10 +0000 |
Allow attachment by explicitly passing a TYPE_VFIO_IOMMU_* string;
vfio-user will use this later.
Signed-off-by: John Levon <john.levon@nutanix.com>
---
hw/vfio/common.c | 30 +++++++++++++++++++-----------
include/hw/vfio/vfio-common.h | 3 +++
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 49e3543c89..cb299fc3bf 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1551,25 +1551,20 @@ retry:
return info;
}
-bool vfio_attach_device(char *name, VFIODevice *vbasedev,
- AddressSpace *as, Error **errp)
+bool vfio_attach_device_by_iommu_type(const char *iommu_type, char *name,
+ VFIODevice *vbasedev, AddressSpace *as,
+ Error **errp)
{
- const VFIOIOMMUClass *ops =
- VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
HostIOMMUDevice *hiod = NULL;
-
- if (vbasedev->iommufd) {
- ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
- }
-
- assert(ops);
-
+ const VFIOIOMMUClass *ops =
+ VFIO_IOMMU_CLASS(object_class_by_name(iommu_type));
if (!vbasedev->mdev) {
hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
vbasedev->hiod = hiod;
}
+
if (!ops->attach_device(name, vbasedev, as, errp)) {
object_unref(hiod);
vbasedev->hiod = NULL;
@@ -1579,6 +1574,19 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
return true;
}
+bool vfio_attach_device(char *name, VFIODevice *vbasedev,
+ AddressSpace *as, Error **errp)
+{
+ const char *iommu_type = TYPE_VFIO_IOMMU_LEGACY;
+
+ if (vbasedev->iommufd) {
+ iommu_type = TYPE_VFIO_IOMMU_IOMMUFD;
+ }
+
+ return vfio_attach_device_by_iommu_type(iommu_type, name, vbasedev,
+ as, errp);
+}
+
void vfio_detach_device(VFIODevice *vbasedev)
{
if (!vbasedev->bcontainer) {
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 13c67d25cb..387854cb0b 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -252,6 +252,9 @@ bool vfio_device_is_mdev(VFIODevice *vbasedev);
bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
bool vfio_attach_device(char *name, VFIODevice *vbasedev,
AddressSpace *as, Error **errp);
+bool vfio_attach_device_by_iommu_type(const char *iommu_type, char *name,
+ VFIODevice *vbasedev, AddressSpace *as,
+ Error **errp);
void vfio_detach_device(VFIODevice *vbasedev);
int vfio_kvm_device_add_fd(int fd, Error **errp);
--
2.34.1
- [v7 00/26] vfio-user client, John Levon, 2025/01/08
- [PATCH 10/26] vfio-user: add vfio-user class and container, John Levon, 2025/01/08
- [PATCH 02/26] vfio/container: pass listener_begin/commit callbacks, John Levon, 2025/01/08
- [PATCH 08/26] vfio: add device IO ops vector, John Levon, 2025/01/08
- [PATCH 04/26] vfio: add vfio_attach_device_by_iommu_type(),
John Levon <=
- [PATCH 05/26] vfio: add vfio_prepare_device(), John Levon, 2025/01/08
- [PATCH 09/26] vfio-user: introduce vfio-user protocol specification, John Levon, 2025/01/08
- [PATCH 11/26] vfio-user: connect vfio proxy to remote server, John Levon, 2025/01/08
- [PATCH 14/26] vfio-user: get device info, John Levon, 2025/01/08
- [PATCH 12/26] vfio-user: define socket receive functions, John Levon, 2025/01/08
- [PATCH 07/26] vfio: add VFIO base abstract class, John Levon, 2025/01/08
- [PATCH 13/26] vfio-user: define socket send functions, John Levon, 2025/01/08
- [PATCH 17/26] vfio-user: pci_user_realize PCI setup, John Levon, 2025/01/08
- [PATCH 15/26] vfio-user: get region info, John Levon, 2025/01/08
- [PATCH 20/26] vfio-user: proxy container connect/disconnect, John Levon, 2025/01/08