refactor(cm): move EL3 registers to global context

Currently, EL3 context registers are duplicated per-world per-cpu.
Some registers have the same value across all CPUs, so this patch
moves these registers out into a per-world context to reduce
memory usage.

Change-Id: I91294e3d5f4af21a58c23599af2bdbd2a747c54a
Signed-off-by: Elizabeth Ho <elizabeth.ho@arm.com>
Signed-off-by: Jayanth Dodderi Chidanand <jayanthdodderi.chidanand@arm.com>
diff --git a/services/std_svc/rmmd/rmmd_main.c b/services/std_svc/rmmd/rmmd_main.c
index fa24a91..d6d25d8 100644
--- a/services/std_svc/rmmd/rmmd_main.c
+++ b/services/std_svc/rmmd/rmmd_main.c
@@ -17,6 +17,7 @@
 #include <common/runtime_svc.h>
 #include <context.h>
 #include <lib/el3_runtime/context_mgmt.h>
+#include <lib/el3_runtime/cpu_data.h>
 #include <lib/el3_runtime/pubsub.h>
 #include <lib/extensions/pmuv3.h>
 #include <lib/extensions/sys_reg_trace.h>
@@ -118,22 +119,9 @@
 /*******************************************************************************
  * Enable architecture extensions on first entry to Realm world.
  ******************************************************************************/
+
 static void manage_extensions_realm(cpu_context_t *ctx)
 {
-	if (is_feat_sve_supported()) {
-	/*
-	 * Enable SVE and FPU in realm context when it is enabled for NS.
-	 * Realm manager must ensure that the SVE and FPU register
-	 * contexts are properly managed.
-	 */
-		sve_enable(ctx);
-	}
-
-	/* NS can access this but Realm shouldn't */
-	if (is_feat_sys_reg_trace_supported()) {
-		sys_reg_trace_disable(ctx);
-	}
-
 	pmuv3_enable(ctx);
 
 	/*
@@ -147,6 +135,26 @@
 	}
 }
 
+#if IMAGE_BL31
+static void manage_extensions_realm_per_world(void)
+{
+	if (is_feat_sve_supported()) {
+	/*
+	 * Enable SVE and FPU in realm context when it is enabled for NS.
+	 * Realm manager must ensure that the SVE and FPU register
+	 * contexts are properly managed.
+	 */
+		sve_enable_per_world(&per_world_context[CPU_CONTEXT_REALM]);
+	}
+
+	/* NS can access this but Realm shouldn't */
+	if (is_feat_sys_reg_trace_supported()) {
+		sys_reg_trace_disable_per_world(&per_world_context[CPU_CONTEXT_REALM]);
+	}
+
+}
+#endif /* IMAGE_BL31 */
+
 /*******************************************************************************
  * Jump to the RMM for the first time.
  ******************************************************************************/
@@ -160,6 +168,8 @@
 	/* Enable architecture extensions */
 	manage_extensions_realm(&ctx->cpu_ctx);
 
+	manage_extensions_realm_per_world();
+
 	/* Initialize RMM EL2 context. */
 	rmm_el2_context_init(&ctx->cpu_ctx.el2_sysregs_ctx);