Add unit tests for Pointer Authentication

Add unit tests to:
    Test access to the key registers.
    Use the pointer authentication instructions.
    Call psci version and check the EL3 pointer authentication keys
    aren't leaked.
    Make a tsp call and check the secure world keys aren't leaked.

Change-Id: Ic7940757e6f9fc905ccef8c035e0c22b47b35cd7
Signed-off-by: Joel Hutton <Joel.Hutton@Arm.com>
diff --git a/include/common/test_helpers.h b/include/common/test_helpers.h
index 983aed3..2cf6e83 100644
--- a/include/common/test_helpers.h
+++ b/include/common/test_helpers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -7,6 +7,7 @@
 #ifndef __TEST_HELPERS_H__
 #define __TEST_HELPERS_H__
 
+#include <arch_features.h>
 #include <plat_topology.h>
 #include <psci.h>
 #include <spci_svc.h>
@@ -25,6 +26,16 @@
 
 typedef test_result_t (*test_function_arg_t)(void *arg);
 
+#ifdef AARCH32
+#define SKIP_TEST_IF_AARCH32()							\
+	do {									\
+		tftf_testcase_printf("Test not supported on aarch32\n");	\
+		return TEST_RESULT_SKIPPED;					\
+	} while (0)
+#else
+#define SKIP_TEST_IF_AARCH32()
+#endif
+
 #define SKIP_TEST_IF_LESS_THAN_N_CLUSTERS(n)					\
 	do {									\
 		unsigned int clusters_cnt;					\
@@ -77,6 +88,15 @@
 		}								\
 	} while (0)
 
+#define SKIP_TEST_IF_PAUTH_NOT_SUPPORTED()					\
+	do {									\
+		if (!is_armv8_3_pauth_present()) {				\
+			tftf_testcase_printf(					\
+				"Pointer Authentication not supported\n");	\
+			return TEST_RESULT_SKIPPED;				\
+		}								\
+	} while (0)
+
 #define SKIP_TEST_IF_MM_NOT_PRESENT()						\
 	do {									\
 		smc_args version_smc = { MM_VERSION_AARCH32 };			\
diff --git a/include/lib/aarch64/arch_features.h b/include/lib/aarch64/arch_features.h
index c5cdc3e..5891c7a 100644
--- a/include/lib/aarch64/arch_features.h
+++ b/include/lib/aarch64/arch_features.h
@@ -48,6 +48,14 @@
 	return (read_id_aa64isar1_el1() & mask) != 0U;
 }
 
+static inline bool is_armv8_3_pauth_gpa_gpi_present(void)
+{
+	uint64_t mask = (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) |
+		(ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT);
+
+	return (read_id_aa64isar1_el1() & mask) != 0U;
+}
+
 static inline bool is_armv8_4_ttst_present(void)
 {
 	return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h
index b6afdd2..151e5be 100644
--- a/include/lib/aarch64/arch_helpers.h
+++ b/include/lib/aarch64/arch_helpers.h
@@ -445,9 +445,24 @@
 DEFINE_RENAME_SYSREG_READ_FUNC(id_aa64mmfr2_el1, ID_AA64MMFR2_EL1)
 
 /* Armv8.3 Pointer Authentication Registers */
+/* Instruction keys A and B */
 DEFINE_RENAME_SYSREG_RW_FUNCS(apiakeyhi_el1, APIAKeyHi_EL1)
 DEFINE_RENAME_SYSREG_RW_FUNCS(apiakeylo_el1, APIAKeyLo_EL1)
 
+DEFINE_RENAME_SYSREG_RW_FUNCS(apibkeyhi_el1, APIBKeyHi_EL1)
+DEFINE_RENAME_SYSREG_RW_FUNCS(apibkeylo_el1, APIBKeyLo_EL1)
+
+/* Data keys A and B */
+DEFINE_RENAME_SYSREG_RW_FUNCS(apdakeyhi_el1, APDAKeyHi_EL1)
+DEFINE_RENAME_SYSREG_RW_FUNCS(apdakeylo_el1, APDAKeyLo_EL1)
+
+DEFINE_RENAME_SYSREG_RW_FUNCS(apdbkeyhi_el1, APDBKeyHi_EL1)
+DEFINE_RENAME_SYSREG_RW_FUNCS(apdbkeylo_el1, APDBKeyLo_EL1)
+
+/* Generic key */
+DEFINE_RENAME_SYSREG_RW_FUNCS(apgakeyhi_el1, APGAKeyHi_EL1)
+DEFINE_RENAME_SYSREG_RW_FUNCS(apgakeylo_el1, APGAKeyLo_EL1)
+
 #define IS_IN_EL(x) \
 	(GET_EL(read_CurrentEl()) == MODE_EL##x)