@@ -116,5 +116,11 @@ static inline u32 get_cntfrq(void)
return read_sysreg(cntfrq_el0);
}
+static inline bool vhe_enabled(void)
+{
+ unsigned long hcr = read_sysreg(hcr_el2);
+ return (hcr & HCR_EL2_E2H) && (hcr & HCR_EL2_TGE);
+}
+
#endif /* !__ASSEMBLY__ */
#endif /* _ASMARM64_PROCESSOR_H_ */
@@ -223,6 +223,11 @@ static void check_pabt(void)
test_exception("ldr r2, =" xstr(PABT_ADDR), "bx r2", "");
__builtin_unreachable();
}
+
+static void check_el2(void)
+{
+ report(false, "EL2 only available on arm64");
+}
#elif defined(__aarch64__)
static unsigned long expected_level;
@@ -402,6 +407,31 @@ static void user_psci_system_off(struct pt_regs *regs, unsigned int esr)
{
__user_psci_system_off();
}
+
+#define ID_AA64MMFR1_VHE_MASK (0xf << 8)
+#define ID_AA64MMFR1_VHE_SUPPORTED (1 << 8)
+static bool vhe_supported(void)
+{
+ u64 aa64mmfr1 = read_sysreg(id_aa64mmfr1_el1);
+
+ return (aa64mmfr1 & ID_AA64MMFR1_VHE_MASK) == ID_AA64MMFR1_VHE_SUPPORTED;
+}
+
+static void check_el2_cpu(void *data __unused)
+{
+ int cpu = smp_processor_id();
+
+ report(current_level() == CurrentEL_EL2, "CPU(%3d) Running at EL2", cpu);
+ report(vhe_supported() && vhe_enabled(),
+ "CPU(%3d) VHE supported and enabled", cpu);
+}
+
+static bool psci_check(void);
+static void check_el2(void)
+{
+ report(psci_check(), "PSCI conduit");
+ on_cpus(check_el2_cpu, NULL);
+}
#endif
static void check_vectors(void *arg __unused)
@@ -453,7 +483,6 @@ static bool psci_check(void)
printf("psci method must be smc\n");
return false;
}
-
if (current_level() == CurrentEL_EL1 &&
strcmp(method->data, "hvc") != 0) {
printf("psci method must be hvc\n");
@@ -516,6 +545,10 @@ int main(int argc, char **argv)
report(cpumask_full(&valid), "MPIDR test on all CPUs");
report_info("%d CPUs reported back", nr_cpus);
+ } else if (strcmp(argv[1], "el2") == 0) {
+
+ check_el2();
+
} else {
printf("Unknown subtest\n");
abort();
@@ -55,6 +55,14 @@ smp = $MAX_SMP
extra_params = -append 'smp'
groups = selftest
+# Test EL2 support
+[selftest-el2]
+file = selftest.flat
+smp = 2
+extra_params = -append 'el2'
+groups = selftest
+arch = arm64
+
# Test PCI emulation
[pci-test]
file = pci-test.flat
Add a rudimentary test for EL2 that checks that we are indeed running with VHE enabled and that we are using SMC for issuing PSCI calls. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> --- lib/arm64/asm/processor.h | 6 ++++++ arm/selftest.c | 35 ++++++++++++++++++++++++++++++++++- arm/unittests.cfg | 8 ++++++++ 3 files changed, 48 insertions(+), 1 deletion(-)