[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH rfcv1 03/23] backends/iommufd_device: introduce IOMMUFDDevice tar
From: |
Zhenzhong Duan |
Subject: |
[PATCH rfcv1 03/23] backends/iommufd_device: introduce IOMMUFDDevice targeted interface |
Date: |
Mon, 15 Jan 2024 18:37:15 +0800 |
With IOMMUFDDevice passed to vIOMMU, we can query hw IOMMU information
and allocate hwpt for a device, but still need an extensible interface
for vIOMMU usage.
This introduces an IOMMUFDDevice targeted interface for vIOMMU.
Currently this interface includes two callbacks attach_hwpt/detach_hwpt
for vIOMMU to attach to or detach from hwpt on host side.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
include/sysemu/iommufd_device.h | 11 ++++++++++-
backends/iommufd_device.c | 16 +++++++++++++++-
hw/vfio/iommufd.c | 3 ++-
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/include/sysemu/iommufd_device.h b/include/sysemu/iommufd_device.h
index 795630324b..799c1345fd 100644
--- a/include/sysemu/iommufd_device.h
+++ b/include/sysemu/iommufd_device.h
@@ -17,15 +17,24 @@
typedef struct IOMMUFDDevice IOMMUFDDevice;
+typedef struct IOMMUFDDeviceOps {
+ int (*attach_hwpt)(IOMMUFDDevice *idev, uint32_t hwpt_id);
+ int (*detach_hwpt)(IOMMUFDDevice *idev);
+} IOMMUFDDeviceOps;
+
/* This is an abstraction of host IOMMUFD device */
struct IOMMUFDDevice {
IOMMUFDBackend *iommufd;
uint32_t dev_id;
+ IOMMUFDDeviceOps *ops;
};
+int iommufd_device_attach_hwpt(IOMMUFDDevice *idev, uint32_t hwpt_id);
+int iommufd_device_detach_hwpt(IOMMUFDDevice *idev);
int iommufd_device_get_info(IOMMUFDDevice *idev,
enum iommu_hw_info_type *type,
uint32_t len, void *data);
void iommufd_device_init(void *_idev, size_t instance_size,
- IOMMUFDBackend *iommufd, uint32_t dev_id);
+ IOMMUFDBackend *iommufd, uint32_t dev_id,
+ IOMMUFDDeviceOps *ops);
#endif
diff --git a/backends/iommufd_device.c b/backends/iommufd_device.c
index f6e7ca1dbf..26f69252d2 100644
--- a/backends/iommufd_device.c
+++ b/backends/iommufd_device.c
@@ -14,6 +14,18 @@
#include "qemu/error-report.h"
#include "sysemu/iommufd_device.h"
+int iommufd_device_attach_hwpt(IOMMUFDDevice *idev, uint32_t hwpt_id)
+{
+ g_assert(idev->ops->attach_hwpt);
+ return idev->ops->attach_hwpt(idev, hwpt_id);
+}
+
+int iommufd_device_detach_hwpt(IOMMUFDDevice *idev)
+{
+ g_assert(idev->ops->detach_hwpt);
+ return idev->ops->detach_hwpt(idev);
+}
+
int iommufd_device_get_info(IOMMUFDDevice *idev,
enum iommu_hw_info_type *type,
uint32_t len, void *data)
@@ -39,7 +51,8 @@ int iommufd_device_get_info(IOMMUFDDevice *idev,
}
void iommufd_device_init(void *_idev, size_t instance_size,
- IOMMUFDBackend *iommufd, uint32_t dev_id)
+ IOMMUFDBackend *iommufd, uint32_t dev_id,
+ IOMMUFDDeviceOps *ops)
{
IOMMUFDDevice *idev = (IOMMUFDDevice *)_idev;
@@ -47,4 +60,5 @@ void iommufd_device_init(void *_idev, size_t instance_size,
idev->iommufd = iommufd;
idev->dev_id = dev_id;
+ idev->ops = ops;
}
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index cbd035f148..1b174b71ee 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -429,7 +429,8 @@ found_container:
QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
- iommufd_device_init(idev, sizeof(*idev), container->be, vbasedev->devid);
+ iommufd_device_init(idev, sizeof(*idev), container->be, vbasedev->devid,
+ NULL);
trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_irqs,
vbasedev->num_regions, vbasedev->flags);
return 0;
--
2.34.1
- [PATCH rfcv1 00/23] intel_iommu: Enable stage-1 translation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 02/23] backends/iommufd: add helpers for allocating user-managed HWPT, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 01/23] Update linux header to support nested hwpt alloc, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 03/23] backends/iommufd_device: introduce IOMMUFDDevice targeted interface,
Zhenzhong Duan <=
- [PATCH rfcv1 04/23] vfio: implement IOMMUFDDevice interface callbacks, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 05/23] intel_iommu: add a placeholder variable for scalable modern mode, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 06/23] intel_iommu: check and sync host IOMMU cap/ecap in scalable modern mode, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 07/23] intel_iommu: process PASID cache invalidation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 08/23] intel_iommu: add PASID cache management infrastructure, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 09/23] vfio/iommufd_device: Add ioas_id in IOMMUFDDevice and pass to vIOMMU, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 10/23] intel_iommu: bind/unbind guest page table to host, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 11/23] intel_iommu: ERRATA_772415 workaround, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 12/23] intel_iommu: replay pasid binds after context cache invalidation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 13/23] intel_iommu: process PASID-based iotlb invalidation, Zhenzhong Duan, 2024/01/15