Some device information returned by ioctl(IOMMU_GET_HW_INFO) are vendor specific. Save them all in a new defined structure mirroring that vendor IOMMU's structure, then get_cap() can query those information for capability.
We can't use the vendor IOMMU's structure directly because they are in linux/iommufd.h which breaks build on windows. Suggested-by: Eric Auger <eric.au...@redhat.com> Suggested-by: Nicolin Chen <nicol...@nvidia.com> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com> --- include/system/host_iommu_device.h | 12 ++++++++++++ hw/vfio/iommufd.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h index 809cced4ba..908bfe32c7 100644 --- a/include/system/host_iommu_device.h +++ b/include/system/host_iommu_device.h @@ -15,6 +15,17 @@ #include "qom/object.h" #include "qapi/error.h" +/* This is mirror of struct iommu_hw_info_vtd */ +typedef struct Vtd_Caps { + uint32_t flags; + uint64_t cap_reg; + uint64_t ecap_reg; +} Vtd_Caps; + +typedef union VendorCaps { + Vtd_Caps vtd; +} VendorCaps; + /** * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. * @@ -26,6 +37,7 @@ typedef struct HostIOMMUDeviceCaps { uint32_t type; uint64_t hw_caps; + VendorCaps vendor_caps; } HostIOMMUDeviceCaps; #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index d661737c17..5c740222e5 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -834,6 +834,7 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, VFIODevice *vdev = opaque; HostIOMMUDeviceIOMMUFD *idev; HostIOMMUDeviceCaps *caps = &hiod->caps; + VendorCaps *vendor_caps = &caps->vendor_caps; enum iommu_hw_info_type type; union { struct iommu_hw_info_vtd vtd; @@ -852,6 +853,17 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, caps->type = type; caps->hw_caps = hw_caps; + switch (type) { + case IOMMU_HW_INFO_TYPE_INTEL_VTD: + vendor_caps->vtd.flags = data.vtd.flags; + vendor_caps->vtd.cap_reg = data.vtd.cap_reg; + vendor_caps->vtd.ecap_reg = data.vtd.ecap_reg; + break; + case IOMMU_HW_INFO_TYPE_ARM_SMMUV3: + case IOMMU_HW_INFO_TYPE_NONE: + break; + } + idev = HOST_IOMMU_DEVICE_IOMMUFD(hiod); idev->iommufd = vdev->iommufd; idev->devid = vdev->devid; -- 2.34.1