feat(rme): add SVE Realm tests
Verifies Realm with SVE support. Below tests are added
- Check whether RMI features reports proper SVE VL
- Create SVE Realm and check rdvl result
- Create SVE Realm with invalid VL and check if it fails
- Create SVE Realm and test ID registers
- Create non SVE Realm and test ID registers
- Create SVE Realm and probe all supported VLs
- Check RMM preserves NS ZCR_EL2 register
Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: I98a20f34ce72c7c1a353ed13678870168fa27c48
diff --git a/realm/realm_sve.c b/realm/realm_sve.c
new file mode 100644
index 0000000..349b8d7
--- /dev/null
+++ b/realm/realm_sve.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <arch_features.h>
+#include <arch_helpers.h>
+#include <assert.h>
+#include <debug.h>
+#include <lib/extensions/sve.h>
+
+#include <host_realm_sve.h>
+#include <host_shared_data.h>
+
+/* Returns the maximum supported VL. This test is called only by sve Realm */
+bool test_realm_sve_rdvl(void)
+{
+ host_shared_data_t *sd = realm_get_shared_structure();
+ struct sve_cmd_rdvl *output;
+
+ assert(is_armv8_2_sve_present());
+
+ output = (struct sve_cmd_rdvl *)sd->realm_cmd_output_buffer;
+ memset((void *)output, 0, sizeof(struct sve_cmd_rdvl));
+
+ sve_config_vq(SVE_VQ_ARCH_MAX);
+ output->rdvl = sve_vector_length_get();
+
+ return true;
+}
+
+/*
+ * Reads and returns the ID_AA64PFR0_EL1 and ID_AA64ZFR0_EL1 registers
+ * This test could be called from sve or non-sve Realm
+ */
+bool test_realm_sve_read_id_registers(void)
+{
+ host_shared_data_t *sd = realm_get_shared_structure();
+ struct sve_cmd_id_regs *output;
+
+ output = (struct sve_cmd_id_regs *)sd->realm_cmd_output_buffer;
+ memset((void *)output, 0, sizeof(struct sve_cmd_id_regs));
+
+ realm_printf("Realm: reading ID registers: ID_AA64PFR0_EL1, "
+ " ID_AA64ZFR0_EL1\n");
+ output->id_aa64pfr0_el1 = read_id_aa64pfr0_el1();
+ output->id_aa64zfr0_el1 = read_id_aa64zfr0_el1();
+
+ return true;
+}
+
+/*
+ * Probes all VLs and return the bitmap with the bit set for each corresponding
+ * valid VQ. This test is called only by sve Realm
+ */
+bool test_realm_sve_probe_vl(void)
+{
+ host_shared_data_t *sd = realm_get_shared_structure();
+ struct sve_cmd_probe_vl *output;
+
+ assert(is_armv8_2_sve_present());
+
+ output = (struct sve_cmd_probe_vl *)&sd->realm_cmd_output_buffer;
+ memset((void *)output, 0, sizeof(struct sve_cmd_probe_vl));
+
+ /* Probe all VLs */
+ output->vl_bitmap = sve_probe_vl(SVE_VQ_ARCH_MAX);
+
+ return true;
+}