feat(rme): add register definitions and helper functions for FEAT_RME

This patch adds new register and bit definitions for the Armv9-A
Realm Management Extension (RME) as described in the Arm
document DDI0615 (https://developer.arm.com/documentation/ddi0615/latest).

The patch also adds TLB maintenance functions and a function to
detect the presence of RME feature.

Signed-off-by: Zelalem Aweke <zelalem.aweke@arm.com>
Change-Id: I03d2af7ea41a20a9e8a362a36b8099e3b4d18a11
diff --git a/include/arch/aarch64/arch.h b/include/arch/aarch64/arch.h
index 1b3ae02..1053006 100644
--- a/include/arch/aarch64/arch.h
+++ b/include/arch/aarch64/arch.h
@@ -182,6 +182,11 @@
 #define ID_AA64PFR0_CSV2_SHIFT	U(56)
 #define ID_AA64PFR0_CSV2_MASK	ULL(0xf)
 #define ID_AA64PFR0_CSV2_LENGTH	U(4)
+#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)
 
 /* Exception level handling */
 #define EL_IMPL_NONE		ULL(0)
@@ -432,6 +437,9 @@
 
 /* SCR definitions */
 #define SCR_RES1_BITS		((U(1) << 4) | (U(1) << 5))
+#define SCR_NSE_SHIFT		U(62)
+#define SCR_NSE_BIT		(ULL(1) << SCR_NSE_SHIFT)
+#define SCR_GPF_BIT		(UL(1) << 48)
 #define SCR_TWEDEL_SHIFT	U(30)
 #define SCR_TWEDEL_MASK		ULL(0xf)
 #define SCR_HXEn_BIT            (UL(1) << 38)
@@ -1093,6 +1101,90 @@
 #define AMEVCNTVOFF1F_EL2	S3_4_C13_C11_7
 
 /*******************************************************************************
+ * Realm management extension register definitions
+ ******************************************************************************/
+
+/* GPCCR_EL3 definitions */
+#define GPCCR_EL3			S3_6_C2_C1_6
+
+/* Least significant address bits protected by each entry in level 0 GPT */
+#define GPCCR_L0GPTSZ_SHIFT		U(20)
+#define GPCCR_L0GPTSZ_MASK		U(0xF)
+#define GPCCR_L0GPTSZ_30BITS		U(0x0)
+#define GPCCR_L0GPTSZ_34BITS		U(0x4)
+#define GPCCR_L0GPTSZ_36BITS		U(0x6)
+#define GPCCR_L0GPTSZ_39BITS		U(0x9)
+#define SET_GPCCR_L0GPTSZ(x)		\
+	((x & GPCCR_L0GPTSZ_MASK) << GPCCR_L0GPTSZ_SHIFT)
+
+/* Granule protection check priority bit definitions */
+#define GPCCR_GPCP_SHIFT		U(17)
+#define GPCCR_GPCP_BIT			(ULL(1) << GPCCR_EL3_GPCP_SHIFT)
+
+/* Granule protection check bit definitions */
+#define GPCCR_GPC_SHIFT			U(16)
+#define GPCCR_GPC_BIT			(ULL(1) << GPCCR_GPC_SHIFT)
+
+/* Physical granule size bit definitions */
+#define GPCCR_PGS_SHIFT			U(14)
+#define GPCCR_PGS_MASK			U(0x3)
+#define GPCCR_PGS_4K			U(0x0)
+#define GPCCR_PGS_16K			U(0x2)
+#define GPCCR_PGS_64K			U(0x1)
+#define SET_GPCCR_PGS(x)		\
+	((x & GPCCR_PGS_MASK) << GPCCR_PGS_SHIFT)
+
+/* GPT fetch shareability attribute bit definitions */
+#define GPCCR_SH_SHIFT			U(12)
+#define GPCCR_SH_MASK			U(0x3)
+#define GPCCR_SH_NS			U(0x0)
+#define GPCCR_SH_OS			U(0x2)
+#define GPCCR_SH_IS			U(0x3)
+#define SET_GPCCR_SH(x)			\
+	((x & GPCCR_SH_MASK) << GPCCR_SH_SHIFT)
+
+/* GPT fetch outer cacheability attribute bit definitions */
+#define GPCCR_ORGN_SHIFT		U(10)
+#define GPCCR_ORGN_MASK			U(0x3)
+#define GPCCR_ORGN_NC			U(0x0)
+#define GPCCR_ORGN_WB_RA_WA		U(0x1)
+#define GPCCR_ORGN_WT_RA_NWA		U(0x2)
+#define GPCCR_ORGN_WB_RA_NWA		U(0x3)
+#define SET_GPCCR_ORGN(x)		\
+	((x & GPCCR_ORGN_MASK) << GPCCR_ORGN_SHIFT)
+
+/* GPT fetch inner cacheability attribute bit definitions */
+#define GPCCR_IRGN_SHIFT		U(8)
+#define GPCCR_IRGN_MASK			U(0x3)
+#define GPCCR_IRGN_NC			U(0x0)
+#define GPCCR_IRGN_WB_RA_WA		U(0x1)
+#define GPCCR_IRGN_WT_RA_NWA		U(0x2)
+#define GPCCR_IRGN_WB_RA_NWA		U(0x3)
+#define SET_GPCCR_IRGN(x)		\
+	((x & GPCCR_IRGN_MASK) << GPCCR_IRGN_SHIFT)
+
+/* Protected physical address size bit definitions */
+#define GPCCR_PPS_SHIFT			U(0)
+#define GPCCR_PPS_MASK			U(0x7)
+#define GPCCR_PPS_4GB			U(0x0)
+#define GPCCR_PPS_64GB			U(0x1)
+#define GPCCR_PPS_1TB			U(0x2)
+#define GPCCR_PPS_4TB			U(0x3)
+#define GPCCR_PPS_16TB			U(0x4)
+#define GPCCR_PPS_256TB			U(0x5)
+#define GPCCR_PPS_4PB			U(0x6)
+#define SET_GPCCR_PPS(x)		\
+	((x & GPCCR_PPS_MASK) << GPCCR_PPS_SHIFT)
+
+/* GPTBR_EL3 definitions */
+#define GPTBR_EL3			S3_6_C2_C1_4
+
+/* Base Address for the GPT bit definitions */
+#define GPTBR_BADDR_SHIFT		U(0)
+#define GPTBR_BADDR_VAL_SHIFT		U(12)
+#define GPTBR_BADDR_MASK		ULL(0xffffffffff)
+
+/*******************************************************************************
  * RAS system registers
  ******************************************************************************/
 #define DISR_EL1		S3_0_C12_C1_1