From: Nathan Chen <nathanc@nvidia.com>
Introduce smmuv3_accel_auto_finalise() to resolve properties that are
set to 'auto' for accelerated SMMUv3. This helper function allows
properties such as ats, ril, ssidsize, and oas support to be resolved
from host IOMMU capabilities via IOMMU_GET_HW_INFO.
Auto mode requires at least one cold-plugged device to retrieve and
finalise these properties. Register a machine_init_done notifier to
verify this requirement and fail boot if it is not met.
Hot-plugged devices into an accel SMMUv3-associated bus will re-use
the resolved host values from the initial cold-plug.
Subsequent patches will make use of this helper to resolve 'auto' to
what is reported by host IOMMU capabilities.
Suggested-by: Shameer Kolothum <skolothumtho@nvidia.com>
Signed-off-by: Nathan Chen <nathanc@nvidia.com>
---
hw/arm/smmuv3-accel.c | 14 ++++++++++++++
hw/arm/smmuv3-accel.h | 2 ++
hw/arm/smmuv3.c | 20 ++++++++++++++++++++
include/hw/arm/smmuv3.h | 2 ++
4 files changed, 38 insertions(+)
diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
index 65c2f44880..a0146c8d31 100644
--- a/hw/arm/smmuv3-accel.c
+++ b/hw/arm/smmuv3-accel.c
@@ -35,11 +35,25 @@ static int smmuv3_oas_bits(uint32_t oas)
return map[oas];
}
+static void smmuv3_accel_auto_finalise(SMMUv3State *s,
+ struct iommu_hw_info_arm_smmuv3 *info) {
+ SMMUv3AccelState *accel = s->s_accel;
+
+ /* Return if no auto for any or finalised already */
+ if (!accel->auto_mode || accel->auto_finalised) {
+ return;
+ }
+
+ accel->auto_finalised = true;
+}
+
static bool
smmuv3_accel_check_hw_compatible(SMMUv3State *s,
struct iommu_hw_info_arm_smmuv3 *info,
Error **errp)
{
+ smmuv3_accel_auto_finalise(s, info);
+
/* QEMU SMMUv3 supports both linear and 2-level stream tables */
if (FIELD_EX32(info->idr[0], IDR0, STLEVEL) !=
FIELD_EX32(s->idr[0], IDR0, STLEVEL)) {
diff --git a/hw/arm/smmuv3-accel.h b/hw/arm/smmuv3-accel.h
index dba6c71de5..3c1cd55714 100644
--- a/hw/arm/smmuv3-accel.h
+++ b/hw/arm/smmuv3-accel.h
@@ -26,6 +26,8 @@ typedef struct SMMUv3AccelState {
uint32_t bypass_hwpt_id;
uint32_t abort_hwpt_id;
QLIST_HEAD(, SMMUv3AccelDevice) device_list;
+ bool auto_mode;
+ bool auto_finalised;
} SMMUv3AccelState;
typedef struct SMMUS1Hwpt {
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 7fead1c3cf..09ea08eb18 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -37,6 +37,7 @@
#include "smmuv3-accel.h"
#include "smmuv3-internal.h"
#include "smmu-internal.h"
+#include "system/system.h"
#define PTW_RECORD_FAULT(ptw_info, cfg) (((ptw_info).stage == SMMU_STAGE_1 && \
(cfg)->record_faults) || \
@@ -2020,6 +2021,22 @@ static bool smmu_validate_property(SMMUv3State *s, Error **errp)
return true;
}
+static void smmuv3_machine_done(Notifier *notifier, void *data)
+{
+ SMMUv3State *s = container_of(notifier, SMMUv3State, machine_done);
+ SMMUv3AccelState *accel = s->s_accel;
+
+ if (!s->accel) {
+ return;
+ }
+
+ if (accel->auto_mode && !accel->auto_finalised) {
+ error_report("arm-smmuv3 accel=on with 'auto' properties requires "
+ "at least one cold-plugged VFIO device");
+ exit(1);
+ }
+}
+
static void smmu_realize(DeviceState *d, Error **errp)
{
SMMUState *sys = ARM_SMMU(d);
@@ -2058,6 +2075,9 @@ static void smmu_realize(DeviceState *d, Error **errp)
smmu_init_irq(s, dev);
smmuv3_init_id_regs(s);
+
+ s->machine_done.notify = smmuv3_machine_done;
+ qemu_add_machine_init_done_notifier(&s->machine_done);
}
static const VMStateDescription vmstate_smmuv3_queue = {
diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h
index 82f18eb090..fe0493c1aa 100644
--- a/include/hw/arm/smmuv3.h
+++ b/include/hw/arm/smmuv3.h
@@ -74,6 +74,8 @@ struct SMMUv3State {
OnOffAuto ats;
OasMode oas;
SsidSizeMode ssidsize;
+
+ Notifier machine_done;
};
typedef enum {
--
2.43.0