@@ -4,6 +4,7 @@
#include "qom/object.h"
#include "exec/hwaddr.h"
#include "exec/cpu-common.h"
+#include <linux/iommufd.h>
#include "sysemu/host_iommu_device.h"
#define TYPE_IOMMUFD_BACKEND "iommufd"
@@ -47,4 +48,7 @@ typedef struct IOMMUFDDevice {
} IOMMUFDDevice;
void iommufd_device_init(IOMMUFDDevice *idev);
+int iommufd_device_get_info(IOMMUFDDevice *idev,
+ enum iommu_hw_info_type *type,
+ uint32_t len, void *data, Error **errp);
#endif
@@ -20,7 +20,6 @@
#include "monitor/monitor.h"
#include "trace.h"
#include <sys/ioctl.h>
-#include <linux/iommufd.h>
static void iommufd_backend_init(Object *obj)
{
@@ -237,3 +236,27 @@ void iommufd_device_init(IOMMUFDDevice *idev)
host_iommu_base_device_init(&idev->base, HID_IOMMUFD,
sizeof(IOMMUFDDevice));
}
+
+int iommufd_device_get_info(IOMMUFDDevice *idev,
+ enum iommu_hw_info_type *type,
+ uint32_t len, void *data, Error **errp)
+{
+ struct iommu_hw_info info = {
+ .size = sizeof(info),
+ .flags = 0,
+ .dev_id = idev->devid,
+ .data_len = len,
+ .__reserved = 0,
+ .data_uptr = (uintptr_t)data,
+ };
+ int ret;
+
+ ret = ioctl(idev->iommufd->fd, IOMMU_GET_HW_INFO, &info);
+ if (ret) {
+ error_setg_errno(errp, errno, "Failed to get hardware info");
+ } else {
+ *type = info.out_data_type;
+ }
+
+ return ret;
+}