test(spm): check processor feature regs
For cactus secure partitions, check ID registers report:
-FPU/Adv. SIMD supported.
-SVE/SME not supported.
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: Iba3508d57a8bcb1f554adddef97c4c83f4118a03
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index 3c30c9d..c45358e 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -132,46 +132,52 @@
#define ID_AA64PFR0_EL1_SHIFT U(4)
#define ID_AA64PFR0_EL2_SHIFT U(8)
#define ID_AA64PFR0_EL3_SHIFT U(12)
-#define ID_AA64PFR0_AMU_SHIFT U(44)
-#define ID_AA64PFR0_AMU_LENGTH U(4)
-#define ID_AA64PFR0_AMU_MASK ULL(0xf)
-#define ID_AA64PFR0_AMU_NOT_SUPPORTED U(0x0)
-#define ID_AA64PFR0_AMU_V1 U(0x1)
-#define ID_AA64PFR0_AMU_V1P1 U(0x2)
#define ID_AA64PFR0_ELX_MASK ULL(0xf)
-#define ID_AA64PFR0_SVE_SHIFT U(32)
-#define ID_AA64PFR0_SVE_WIDTH U(4)
-#define ID_AA64PFR0_SVE_MASK ULL(0xf)
-#define ID_AA64PFR0_SVE_LENGTH U(4)
-#define ID_AA64PFR0_MPAM_SHIFT U(40)
-#define ID_AA64PFR0_MPAM_MASK ULL(0xf)
-#define ID_AA64PFR0_DIT_SHIFT U(48)
-#define ID_AA64PFR0_DIT_MASK ULL(0xf)
-#define ID_AA64PFR0_DIT_LENGTH U(4)
-#define ID_AA64PFR0_DIT_SUPPORTED U(1)
-#define ID_AA64PFR0_CSV2_SHIFT U(56)
-#define ID_AA64PFR0_CSV2_MASK ULL(0xf)
-#define ID_AA64PFR0_CSV2_WIDTH U(4)
-#define ID_AA64PFR0_CSV2_NOT_SUPPORTED ULL(0x0)
-#define ID_AA64PFR0_CSV2_SUPPORTED ULL(0x1)
-#define ID_AA64PFR0_CSV2_2_SUPPORTED ULL(0x2)
-#define ID_AA64PFR0_FEAT_RME_SHIFT U(52)
-#define ID_AA64PFR0_FEAT_RME_MASK ULL(0xf)
-#define ID_AA64PFR0_FEAT_RME_LENGTH U(4)
-#define ID_AA64PFR0_FEAT_RME_NOT_SUPPORTED U(0)
-#define ID_AA64PFR0_FEAT_RME_V1 U(1)
-#define ID_AA64PFR0_RAS_MASK ULL(0xf)
-#define ID_AA64PFR0_RAS_SHIFT U(28)
-#define ID_AA64PFR0_RAS_WIDTH U(4)
-#define ID_AA64PFR0_RAS_NOT_SUPPORTED ULL(0x0)
-#define ID_AA64PFR0_RAS_SUPPORTED ULL(0x1)
-#define ID_AA64PFR0_RASV1P1_SUPPORTED ULL(0x2)
+#define ID_AA64PFR0_FP_SHIFT U(16)
+#define ID_AA64PFR0_FP_WIDTH U(4)
+#define ID_AA64PFR0_FP_MASK U(0xf)
+#define ID_AA64PFR0_ADVSIMD_SHIFT U(20)
+#define ID_AA64PFR0_ADVSIMD_WIDTH U(4)
+#define ID_AA64PFR0_ADVSIMD_MASK U(0xf)
#define ID_AA64PFR0_GIC_SHIFT U(24)
#define ID_AA64PFR0_GIC_WIDTH U(4)
#define ID_AA64PFR0_GIC_MASK ULL(0xf)
#define ID_AA64PFR0_GIC_NOT_SUPPORTED ULL(0x0)
#define ID_AA64PFR0_GICV3_GICV4_SUPPORTED ULL(0x1)
#define ID_AA64PFR0_GICV4_1_SUPPORTED ULL(0x2)
+#define ID_AA64PFR0_RAS_MASK ULL(0xf)
+#define ID_AA64PFR0_RAS_SHIFT U(28)
+#define ID_AA64PFR0_RAS_WIDTH U(4)
+#define ID_AA64PFR0_RAS_NOT_SUPPORTED ULL(0x0)
+#define ID_AA64PFR0_RAS_SUPPORTED ULL(0x1)
+#define ID_AA64PFR0_RASV1P1_SUPPORTED ULL(0x2)
+#define ID_AA64PFR0_SVE_SHIFT U(32)
+#define ID_AA64PFR0_SVE_WIDTH U(4)
+#define ID_AA64PFR0_SVE_MASK ULL(0xf)
+#define ID_AA64PFR0_SVE_LENGTH U(4)
+#define ID_AA64PFR0_MPAM_SHIFT U(40)
+#define ID_AA64PFR0_MPAM_MASK ULL(0xf)
+#define ID_AA64PFR0_AMU_SHIFT U(44)
+#define ID_AA64PFR0_AMU_LENGTH U(4)
+#define ID_AA64PFR0_AMU_MASK ULL(0xf)
+#define ID_AA64PFR0_AMU_NOT_SUPPORTED U(0x0)
+#define ID_AA64PFR0_AMU_V1 U(0x1)
+#define ID_AA64PFR0_AMU_V1P1 U(0x2)
+#define ID_AA64PFR0_DIT_SHIFT U(48)
+#define ID_AA64PFR0_DIT_MASK ULL(0xf)
+#define ID_AA64PFR0_DIT_LENGTH U(4)
+#define ID_AA64PFR0_DIT_SUPPORTED U(1)
+#define ID_AA64PFR0_FEAT_RME_SHIFT U(52)
+#define ID_AA64PFR0_FEAT_RME_MASK ULL(0xf)
+#define ID_AA64PFR0_FEAT_RME_LENGTH U(4)
+#define ID_AA64PFR0_FEAT_RME_NOT_SUPPORTED U(0)
+#define ID_AA64PFR0_FEAT_RME_V1 U(1)
+#define ID_AA64PFR0_CSV2_SHIFT U(56)
+#define ID_AA64PFR0_CSV2_MASK ULL(0xf)
+#define ID_AA64PFR0_CSV2_WIDTH U(4)
+#define ID_AA64PFR0_CSV2_NOT_SUPPORTED ULL(0x0)
+#define ID_AA64PFR0_CSV2_SUPPORTED ULL(0x1)
+#define ID_AA64PFR0_CSV2_2_SUPPORTED ULL(0x2)
/* ID_AA64DFR0_EL1.PMS definitions (for ARMv8.2+) */
#define ID_AA64DFR0_PMS_SHIFT U(32)
diff --git a/include/lib/aarch64/arch_features.h b/include/lib/aarch64/arch_features.h
index c59e405..a2ed5be 100644
--- a/include/lib/aarch64/arch_features.h
+++ b/include/lib/aarch64/arch_features.h
@@ -42,6 +42,20 @@
ID_AA64PFR0_SVE_MASK) == 1U;
}
+static inline bool is_feat_advsimd_present(void)
+{
+ u_register_t id_aa64pfr0_advsimd =
+ EXTRACT(ID_AA64PFR0_ADVSIMD, read_id_aa64pfr0_el1());
+ return (id_aa64pfr0_advsimd == 0 || id_aa64pfr0_advsimd == 1);
+}
+
+static inline bool is_feat_fp_present(void)
+{
+ u_register_t id_aa64pfr0_fp =
+ EXTRACT(ID_AA64PFR0_FP, read_id_aa64pfr0_el1());
+ return (id_aa64pfr0_fp == 0 || id_aa64pfr0_fp == 1);
+}
+
static inline bool is_armv8_2_ttcnp_present(void)
{
return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_CNP_SHIFT) &
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index 0755749..9557745 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2018-2023, Arm Limited. All rights reserved.
+# Copyright (c) 2018-2024, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -46,6 +46,7 @@
) \
$(addprefix spm/common/sp_tests/, \
sp_test_ffa.c \
+ sp_test_cpu.c \
) \
$(addprefix spm/cactus/cactus_tests/, \
cactus_message_loop.c \
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index b39f138..1d5cd97 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2023, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -327,8 +327,9 @@
discover_managed_exit_interrupt_id();
register_maintenance_interrupt_handlers();
- /* Invoking Tests */
+ /* Invoking self tests */
ffa_tests(&mb);
+ cpu_feature_tests();
msg_loop:
/* End up to message loop */
diff --git a/spm/common/sp_helpers.h b/spm/common/sp_helpers.h
index e0e749d..776cc75 100644
--- a/spm/common/sp_helpers.h
+++ b/spm/common/sp_helpers.h
@@ -8,6 +8,8 @@
#define SP_HELPERS_H
#include <stdint.h>
+
+#include <debug.h>
#include <tftf_lib.h>
#include <spm_common.h>
#include <spinlock.h>
diff --git a/spm/common/sp_tests/sp_test_cpu.c b/spm/common/sp_tests/sp_test_cpu.c
new file mode 100644
index 0000000..a05dbf3
--- /dev/null
+++ b/spm/common/sp_tests/sp_test_cpu.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <sp_helpers.h>
+
+#include <arch_features.h>
+
+static void cpu_check_id_regs(void)
+{
+ /* ID_AA64PFR0_EL1 */
+ EXPECT(is_feat_advsimd_present(), true);
+ EXPECT(is_feat_fp_present(), true);
+ EXPECT(is_armv8_2_sve_present(), false);
+
+ /* ID_AA64PFR1_EL1 */
+ EXPECT(is_feat_sme_supported(), false);
+}
+
+void cpu_feature_tests(void)
+{
+ const char *test_cpu_str = "CPU tests";
+
+ announce_test_section_start(test_cpu_str);
+ cpu_check_id_regs();
+ announce_test_section_end(test_cpu_str);
+}
diff --git a/spm/common/sp_tests/sp_test_ffa.c b/spm/common/sp_tests/sp_test_ffa.c
index c3774f9..ba63a0e 100644
--- a/spm/common/sp_tests/sp_test_ffa.c
+++ b/spm/common/sp_tests/sp_test_ffa.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -195,7 +195,7 @@
ffa_partition_info_wrong_test();
}
-void ffa_version_test(void)
+static void ffa_version_test(void)
{
struct ffa_value ret = ffa_version(FFA_VERSION_COMPILED);
@@ -212,7 +212,7 @@
EXPECT((int)compatible, (int)true);
}
-void ffa_spm_id_get_test(void)
+static void ffa_spm_id_get_test(void)
{
if (spm_version >= FFA_VERSION_1_1) {
struct ffa_value ret = ffa_spm_id_get();
@@ -236,9 +236,9 @@
void ffa_tests(struct mailbox_buffers *mb)
{
- const char *test_ffa = "FF-A setup and discovery";
+ const char *test_ffa_str = "FF-A setup and discovery";
- announce_test_section_start(test_ffa);
+ announce_test_section_start(test_ffa_str);
ffa_features_test();
ffa_version_test();
@@ -246,5 +246,5 @@
ffa_partition_info_get_test(mb);
ffa_partition_info_get_regs_test();
- announce_test_section_end(test_ffa);
+ announce_test_section_end(test_ffa_str);
}
diff --git a/spm/common/sp_tests/sp_tests.h b/spm/common/sp_tests/sp_tests.h
index 10d3b9b..007c2ca 100644
--- a/spm/common/sp_tests/sp_tests.h
+++ b/spm/common/sp_tests/sp_tests.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -10,9 +10,10 @@
#include <spm_common.h>
/*
- * Test functions
+ * Self test functions
*/
void ffa_tests(struct mailbox_buffers *mb);
+void cpu_feature_tests(void);
#endif /* CACTUS_TESTS_H */