Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: Shameer Kolothum <[email protected]>
---
backends/iommufd.c | 23 ++++++++++++++++++-----
hw/i386/intel_iommu.c | 8 +++++---
hw/vfio/container-legacy.c | 8 ++++++--
include/system/host_iommu_device.h | 18 ++++++++++++------
4 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/backends/iommufd.c b/backends/iommufd.c
index 6381f9664b..718d63f5cf 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -523,19 +523,32 @@ bool
host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
return idevc->detach_hwpt(idev, errp);
}
-static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
+static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap_id,
+ uint64_t *out_cap, Error **errp)
{
HostIOMMUDeviceCaps *caps = &hiod->caps;
- switch (cap) {
+ g_assert(out_cap);
+
+ switch (cap_id) {
case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE:
- return caps->type;
+ *out_cap = caps->type;
+ break;
case HOST_IOMMU_DEVICE_CAP_AW_BITS:
- return vfio_device_get_aw_bits(hiod->agent);
+ *out_cap = vfio_device_get_aw_bits(hiod->agent);
+ break;
+ case HOST_IOMMU_DEVICE_CAP_GENERIC_HW:
+ *out_cap = caps->hw_caps;
+ break;
+ case HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2:
+ *out_cap = caps->max_pasid_log2;
+ break;
default:
- error_setg(errp, "%s: unsupported capability %x", hiod->name, cap);
+ *out_cap = 0;
+ error_setg(errp, "%s: unsupported capability %x", hiod->name, cap_id);
return -EINVAL;
}
+ return 0;
}
static void hiod_iommufd_class_init(ObjectClass *oc, const void *data)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 78b142ccea..d5c131a814 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -4605,6 +4605,7 @@ static bool vtd_check_hiod(IntelIOMMUState *s,
HostIOMMUDevice *hiod,
Error **errp)
{
HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_GET_CLASS(hiod);
+ uint64_t out_cap;
int ret;
if (!hiodc->get_cap) {
@@ -4613,12 +4614,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s,
HostIOMMUDevice *hiod,
}
/* Common checks */
- ret = hiodc->get_cap(hiod, HOST_IOMMU_DEVICE_CAP_AW_BITS, errp);
+ ret = hiodc->get_cap(hiod, HOST_IOMMU_DEVICE_CAP_AW_BITS, &out_cap, errp);
if (ret < 0) {
return false;
}
- if (s->aw_bits > ret) {
- error_setg(errp, "aw-bits %d > host aw-bits %d", s->aw_bits, ret);
+ if (s->aw_bits > out_cap) {
+ error_setg(errp, "aw-bits %d > host aw-bits 0x%" PRIx64, s->aw_bits,
+ out_cap);
return false;
}
diff --git a/hw/vfio/container-legacy.c b/hw/vfio/container-legacy.c
index 32c260b345..1acf063762 100644
--- a/hw/vfio/container-legacy.c
+++ b/hw/vfio/container-legacy.c
@@ -1203,15 +1203,19 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice
*hiod, void *opaque,
}
static int hiod_legacy_vfio_get_cap(HostIOMMUDevice *hiod, int cap,
- Error **errp)
+ uint64_t *out_cap, Error **errp)
{
+ g_assert(out_cap);
+
switch (cap) {
case HOST_IOMMU_DEVICE_CAP_AW_BITS:
- return vfio_device_get_aw_bits(hiod->agent);
+ *out_cap = vfio_device_get_aw_bits(hiod->agent);
+ break;
default:
error_setg(errp, "%s: unsupported capability %x", hiod->name, cap);
return -EINVAL;
}
+ return 0;
}
static GList *
diff --git a/include/system/host_iommu_device.h
b/include/system/host_iommu_device.h
index bfb2b60478..4e891e5225 100644
--- a/include/system/host_iommu_device.h
+++ b/include/system/host_iommu_device.h
@@ -88,19 +88,21 @@ struct HostIOMMUDeviceClass {
* @get_cap: check if a host IOMMU device capability is supported.
*
* Optional callback, if not implemented, hint not supporting query
- * of @cap.
+ * of @cap_id.
*
* @hiod: pointer to a host IOMMU device instance.
*
- * @cap: capability to check.
+ * @cap_id: capability to check.
+ *
+ * @out_cap: 0 if a @cap_id is unsupported or else the capability
+ * value for @cap_id.
*
* @errp: pass an Error out when fails to query capability.
*
- * Returns: <0 on failure, 0 if a @cap is unsupported, or else
- * 1 or some positive value for some special @cap,
- * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS.
+ * Returns: <0 if @cap_id is not supported, 0 on success.
*/
- int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp);
+ int (*get_cap)(HostIOMMUDevice *hiod, int cap_id, uint64_t *out_cap,
+ Error **errp);
/**
* @get_iova_ranges: Return the list of usable iova_ranges along with
* @hiod Host IOMMU device
@@ -123,6 +125,10 @@ struct HostIOMMUDeviceClass {
*/
#define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0
#define HOST_IOMMU_DEVICE_CAP_AW_BITS 1
+/* Generic IOMMU HW capability info */
+#define HOST_IOMMU_DEVICE_CAP_GENERIC_HW 2
+/* PASID width */
+#define HOST_IOMMU_DEVICE_CAP_MAX_PASID_LOG2 3
#define HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX 64
#endif