In VFIO core, we call iommufd_backend_get_device_info() to return vendor specific hardware information data, but it's not good to extract this raw data in VFIO core.
Introduce host_iommu_extract_vendor_caps() to help extracting the raw data and return a bitmap in iommufd.c because it's the place defining iommufd_backend_get_device_info(). The other choice is to put vendor data extracting code in vendor vIOMMU emulation file, but that will make those files mixed with vIOMMU emulation and host IOMMU extracting code, also need a new callback in PCIIOMMUOps. So we choose a simpler way as above. Suggested-by: Nicolin Chen <nicol...@nvidia.com> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com> --- include/hw/iommu.h | 5 +++++ include/system/host_iommu_device.h | 16 ++++++++++++++++ backends/iommufd.c | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/hw/iommu.h b/include/hw/iommu.h index 65d652950a..9b343e64b0 100644 --- a/include/hw/iommu.h +++ b/include/hw/iommu.h @@ -16,4 +16,9 @@ enum { VIOMMU_FLAG_WANT_NESTING_PARENT = BIT_ULL(0), }; +enum { + /* Nesting parent HWPT shouldn't have readonly mapping, due to errata */ + IOMMU_HW_NESTING_PARENT_BYPASS_RO = BIT_ULL(0), +}; + #endif /* HW_IOMMU_H */ diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h index ab849a4a82..41c9159605 100644 --- a/include/system/host_iommu_device.h +++ b/include/system/host_iommu_device.h @@ -39,6 +39,22 @@ typedef struct HostIOMMUDeviceCaps { uint64_t hw_caps; VendorCaps vendor_caps; } HostIOMMUDeviceCaps; + +/** + * host_iommu_extract_vendor_caps: Extract vendor capabilities + * + * This function converts @type specific hardware information data + * into a standard bitmap format. + * + * @type: IOMMU Hardware Info Types + * + * @VendorCaps: IOMMU @type specific hardware information data + * + * Returns: 64bit bitmap with each bit represents a capability of host + * IOMMU that we want to expose. See IOMMU_HW_* in include/hw/iommu.h + * for all possible capabilities currently exposed. + */ +uint64_t host_iommu_extract_vendor_caps(uint32_t type, VendorCaps *caps); #endif #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" diff --git a/backends/iommufd.c b/backends/iommufd.c index 2a33c7ab0b..0bb1ed40d3 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -19,6 +19,7 @@ #include "migration/cpr.h" #include "monitor/monitor.h" #include "trace.h" +#include "hw/iommu.h" #include "hw/vfio/vfio-device.h" #include <sys/ioctl.h> #include <linux/iommufd.h> @@ -410,6 +411,18 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, return true; } +uint64_t host_iommu_extract_vendor_caps(uint32_t type, VendorCaps *caps) +{ + uint64_t vendor_caps = 0; + + if (type == IOMMU_HW_INFO_TYPE_INTEL_VTD && + caps->vtd.flags & IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17) { + vendor_caps |= IOMMU_HW_NESTING_PARENT_BYPASS_RO; + } + + return vendor_caps; +} + bool iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t id, uint32_t data_type, uint32_t entry_len, uint32_t *entry_num, void *data, -- 2.47.1