Add a has_gcie QOM property to the CPU which allows the board code to
enable FEAT_GCIE, the GICv5 CPU interface.
Enabling the GICv5 CPU interface comes with a significant
restriction: because the GICv5 architecture is Armv9, it assumes the
Armv9 requirement that only EL0 (userspace) may be in AArch32. So
there are no GIC control system registers defined for AArch32. We
force AArch32 at ELs 1, 2 and 3 to disabled, to avoid a guest being
able to get into an EL where interrupts are completely broken.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
---
target/arm/cpu-features.h | 5 +++++
target/arm/cpu.c | 45 +++++++++++++++++++++++++++++++++++++++
target/arm/cpu.h | 2 ++
3 files changed, 52 insertions(+)
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
index e391b394ba..c0ba56f244 100644
--- a/target/arm/cpu-features.h
+++ b/target/arm/cpu-features.h
@@ -1072,6 +1072,11 @@ static inline bool isar_feature_aa64_aa32_el2(const ARMISARegisters *id)
return FIELD_EX64_IDREG(id, ID_AA64PFR0, EL2) >= 2;
}
+static inline bool isar_feature_aa64_aa32_el3(const ARMISARegisters *id)
+{
+ return FIELD_EX64_IDREG(id, ID_AA64PFR0, EL3) >= 2;
+}
+
static inline bool isar_feature_aa64_ras(const ARMISARegisters *id)
{
return FIELD_EX64_IDREG(id, ID_AA64PFR0, RAS) != 0;
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index ceb303a55a..21c2953501 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1197,6 +1197,9 @@ static const Property arm_cpu_has_el2_property =
static const Property arm_cpu_has_el3_property =
DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, true);
+
+static const Property arm_cpu_has_gcie_property =
+ DEFINE_PROP_BOOL("has_gcie", ARMCPU, has_gcie, false);
#endif
static const Property arm_cpu_cfgend_property =
@@ -1425,6 +1428,11 @@ static void arm_cpu_post_init(Object *obj)
object_property_add_uint64_ptr(obj, "rvbar",
&cpu->rvbar_prop,
OBJ_PROP_FLAG_READWRITE);
+
+ /* We only allow GICv5 on a 64-bit v8 CPU */
+ if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+ qdev_property_add_static(DEVICE(obj), &arm_cpu_has_gcie_property);
+ }
}
if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
@@ -1699,6 +1707,12 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
current_accel_name());
return;
}
+ if (cpu->has_gcie) {
+ error_setg(errp,
+ "Cannot enable %s when guest CPU has GICv5 enabled",
+ current_accel_name());
+ return;
+ }
}
#endif
@@ -2022,6 +2036,37 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
FIELD_DP32_IDREG(isar, ID_PFR1, VIRTUALIZATION, 0);
}
+ /* Report FEAT_GCIE in our ID registers if property was set */
+ FIELD_DP64_IDREG(isar, ID_AA64PFR2, GCIE, cpu->has_gcie);
+ if (cpu_isar_feature(aa64_gcie, cpu)) {
+ if (!arm_feature(env, ARM_FEATURE_AARCH64)) {
+ /*
+ * We only create the have_gcie property for AArch64 CPUs,
+ * but the user might have tried aarch64=off with has_gcie=on.
+ */
+ error_setg(errp, "Cannot both enable has_gcie and disable aarch64");
+ return;
+ }
+
+ /*
+ * FEAT_GCIE implies Armv9, which implies no AArch32 above EL0.
+ * Usually we don't strictly insist on this kind of feature
+ * dependency, but in this case we enforce it, because the
+ * GICv5 CPU interface has no AArch32 versions of its system
+ * registers, so interrupts wouldn't work if we allowed AArch32
+ * in EL1 or above. Downgrade "AArch32 and AArch64" to "AArch64".
+ */
+ if (cpu_isar_feature(aa64_aa32_el3, cpu)) {
+ FIELD_DP64_IDREG(isar, ID_AA64PFR0, EL3, 1);
+ }
+ if (cpu_isar_feature(aa64_aa32_el2, cpu)) {
+ FIELD_DP64_IDREG(isar, ID_AA64PFR0, EL2, 1);
+ }
+ if (cpu_isar_feature(aa64_aa32_el1, cpu)) {
+ FIELD_DP64_IDREG(isar, ID_AA64PFR0, EL1, 1);
+ }
+ }
+
if (cpu_isar_feature(aa64_mte, cpu)) {
/*
* The architectural range of GM blocksize is 2-6, however qemu
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 651fccd59b..a5f27dfe0f 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1032,6 +1032,8 @@ struct ArchCPU {
bool has_neon;
/* CPU has M-profile DSP extension */
bool has_dsp;
+ /* CPU has FEAT_GCIE GICv5 CPU interface */
+ bool has_gcie;
/* CPU has memory protection unit */
bool has_mpu;
--
2.43.0