[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/26] vfio: add vfio_prepare_device()
From: |
John Levon |
Subject: |
[PATCH 05/26] vfio: add vfio_prepare_device() |
Date: |
Wed, 29 May 2024 17:22:58 +0100 |
From: John Levon <john.levon@nutanix.com>
Commonize some initialization code shared by the legacy and iommufd vfio
implementations (and later by vfio-user).
Signed-off-by: John Levon <john.levon@nutanix.com>
---
hw/vfio/common.c | 19 +++++++++++++++++++
hw/vfio/container.c | 14 +-------------
hw/vfio/iommufd.c | 9 +--------
include/hw/vfio/vfio-common.h | 2 ++
4 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 8c3b6ad75a..81f4c88f2d 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1542,6 +1542,25 @@ retry:
return info;
}
+void vfio_prepare_device(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
+ VFIOGroup *group, struct vfio_device_info *info)
+{
+ vbasedev->group = group;
+
+ vbasedev->num_irqs = info->num_irqs;
+ vbasedev->num_regions = info->num_regions;
+ vbasedev->flags = info->flags;
+ vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
+
+ vbasedev->bcontainer = bcontainer;
+ QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
+ if (group) {
+ QLIST_INSERT_HEAD(&group->device_list, vbasedev, next);
+ }
+
+ QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
+}
+
bool vfio_attach_device_by_iommu_type(const char *iommu_type, char *name,
VFIODevice *vbasedev, AddressSpace *as,
Error **errp)
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 27ddb894e9..1bbcbaa874 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -881,17 +881,11 @@ static bool vfio_get_device(VFIOGroup *group, const char
*name,
}
vbasedev->fd = fd;
- vbasedev->group = group;
- QLIST_INSERT_HEAD(&group->device_list, vbasedev, next);
- vbasedev->num_irqs = info->num_irqs;
- vbasedev->num_regions = info->num_regions;
- vbasedev->flags = info->flags;
+ vfio_prepare_device(vbasedev, &group->container->bcontainer, group, info);
trace_vfio_get_device(name, info->flags, info->num_regions,
info->num_irqs);
- vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
-
return true;
}
@@ -944,7 +938,6 @@ static bool vfio_legacy_attach_device(const char *name,
VFIODevice *vbasedev,
int groupid = vfio_device_groupid(vbasedev, errp);
VFIODevice *vbasedev_iter;
VFIOGroup *group;
- VFIOContainerBase *bcontainer;
if (groupid < 0) {
return false;
@@ -969,11 +962,6 @@ static bool vfio_legacy_attach_device(const char *name,
VFIODevice *vbasedev,
return false;
}
- bcontainer = &group->container->bcontainer;
- vbasedev->bcontainer = bcontainer;
- QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
- QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
-
return true;
}
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 7bcadacd0b..dad83e45d7 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -425,14 +425,7 @@ found_container:
iommufd_cdev_ram_block_discard_disable(false);
}
- vbasedev->group = 0;
- vbasedev->num_irqs = dev_info.num_irqs;
- vbasedev->num_regions = dev_info.num_regions;
- vbasedev->flags = dev_info.flags;
- vbasedev->reset_works = !!(dev_info.flags & VFIO_DEVICE_FLAGS_RESET);
- vbasedev->bcontainer = bcontainer;
- QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
- QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
+ vfio_prepare_device(vbasedev, bcontainer, NULL, &dev_info);
trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_irqs,
vbasedev->num_regions, vbasedev->flags);
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 8e13d30d2c..ee022c9cbd 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -223,6 +223,8 @@ void vfio_region_exit(VFIORegion *region);
void vfio_region_finalize(VFIORegion *region);
void vfio_reset_handler(void *opaque);
struct vfio_device_info *vfio_get_device_info(int fd);
+void vfio_prepare_device(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
+ VFIOGroup *group, struct vfio_device_info *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,
--
2.34.1
- [PATCH 11/26] vfio-user: connect vfio proxy to remote server, (continued)
- [PATCH 11/26] vfio-user: connect vfio proxy to remote server, John Levon, 2024/05/29
- [PATCH 13/26] vfio-user: define socket send functions, John Levon, 2024/05/29
- [PATCH 04/26] vfio: add vfio_attach_device_by_iommu_type(), John Levon, 2024/05/29
- [PATCH 14/26] vfio-user: get device info, John Levon, 2024/05/29
- [PATCH 01/26] vfio/container: pass MemoryRegion to DMA operations, John Levon, 2024/05/29
- [PATCH 08/26] vfio: add device IO ops vector, John Levon, 2024/05/29
- [PATCH 12/26] vfio-user: define socket receive functions, John Levon, 2024/05/29
- [PATCH 03/26] vfio/container: support VFIO_DMA_UNMAP_FLAG_ALL, John Levon, 2024/05/29
- [PATCH 07/26] vfio: add VFIO base abstract class, John Levon, 2024/05/29
- [PATCH 10/26] vfio-user: add vfio-user class and container, John Levon, 2024/05/29
- [PATCH 05/26] vfio: add vfio_prepare_device(),
John Levon <=
- [PATCH 09/26] vfio-user: introduce vfio-user protocol specification, John Levon, 2024/05/29
- [PATCH 18/26] vfio-user: get and set IRQs, John Levon, 2024/05/29
- [PATCH 20/26] vfio-user: proxy container connect/disconnect, John Levon, 2024/05/29
- [PATCH 24/26] vfio-user: pci reset, John Levon, 2024/05/29
- [PATCH 26/26] vfio-user: add coalesced posted writes, John Levon, 2024/05/29
- [PATCH 17/26] vfio-user: pci_user_realize PCI setup, John Levon, 2024/05/29
- [PATCH 19/26] vfio-user: forward msix BAR accesses to server, John Levon, 2024/05/29
- [PATCH 16/26] vfio-user: region read/write, John Levon, 2024/05/29
- [PATCH 25/26] vfio-user: add 'x-msg-timeout' option that specifies msg wait times, John Levon, 2024/05/29
- [PATCH 02/26] vfio/container: pass listener_begin/commit callbacks, John Levon, 2024/05/29