test(SMCCC): test SMCCC_ARCH_FEATURE_AVAILABILITY

This test calls the function with each valid argument and checks that
every bit is set if its relevant feature is present in the system. It
also fails the test if any set bit in the return value has not been
checked. This should serve as a reminder to update this test for every
new feature that is implemented.

Only feature that tfa supports are tested with the expectation that new
ones will be added in the future.

Co-developed-by: Charlie Bareham <charlie.bareham@arm.com>
Signed-off-by: Boyan Karatotev <boyan.karatotev@arm.com>
Change-Id: I801326a49810bb76bfc3b9d06780d416dcc32a40
diff --git a/include/common/test_helpers.h b/include/common/test_helpers.h
index fc557ae..124cc4e 100644
--- a/include/common/test_helpers.h
+++ b/include/common/test_helpers.h
@@ -102,6 +102,20 @@
 		}								\
 	} while (0)
 
+#define SKIP_TEST_IF_SMCCC_FUNC_NOT_SUPPORTED(func)				\
+	do {									\
+		smc_ret_values ret;						\
+		smc_args args = {0};						\
+		args.fid = SMCCC_ARCH_FEATURES;					\
+		args.arg1 = func;						\
+		ret = tftf_smc(&args);						\
+		if ((int)ret.ret0 == SMC_ARCH_CALL_NOT_SUPPORTED) {		\
+			tftf_testcase_printf(					\
+				#func " is not implemented\n");			\
+			return TEST_RESULT_SKIPPED;				\
+		}								\
+	} while (0)
+
 #define SKIP_TEST_IF_DIT_NOT_SUPPORTED()					\
 	do {									\
 		if (!is_armv8_4_dit_present()) {				\
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index 62cf470..c640fc7 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -625,6 +625,7 @@
 #define SCR_PFAREn_BIT		(UL(1) << 53)
 #define SCR_TWERR_BIT		(UL(1) << 52)
 #define SCR_TMEA_BIT		(UL(1) << 51)
+#define SCR_EnFPM_BIT		(UL(1) << 50)
 #define SCR_MECEn_BIT		(UL(1) << 49)
 #define SCR_GPF_BIT		(UL(1) << 48)
 #define SCR_D128En_BIT		(UL(1) << 47)
diff --git a/include/runtime_services/arm_arch_svc.h b/include/runtime_services/arm_arch_svc.h
index 0d2eb38..0b4e2ad 100644
--- a/include/runtime_services/arm_arch_svc.h
+++ b/include/runtime_services/arm_arch_svc.h
@@ -13,5 +13,6 @@
 #define SMCCC_ARCH_WORKAROUND_1	0x80008000
 #define SMCCC_ARCH_WORKAROUND_2	0x80007FFF
 #define SMCCC_ARCH_WORKAROUND_3	0x80003FFF
+#define SMCCC_ARCH_FEATURE_AVAILABILITY		U(0x80000003)
 
 #endif /* __ARM_ARCH_SVC_H__ */
diff --git a/include/runtime_services/smccc.h b/include/runtime_services/smccc.h
index b898138..513ec8f 100644
--- a/include/runtime_services/smccc.h
+++ b/include/runtime_services/smccc.h
@@ -80,4 +80,9 @@
 #define SMC_GET_SOC_VERSION		0
 #define SMC_GET_SOC_REVISION		1
 
+#define SCR_EL3_OPCODE			U(0x1E1100)
+#define CPTR_EL3_OPCODE			U(0x1E1140)
+#define MDCR_EL3_OPCODE			U(0x1E1320)
+#define MPAM3_EL3_OPCODE		U(0x1EA500)
+
 #endif /* __SMCCC_H__ */