aarch64: Add PubSub events to capture security state transitions

Add events that trigger before entry to normal/secure world.  The
events trigger after the normal/secure context has been restored.

Similarly add events that trigger after leaving normal/secure world.
The events trigger after the normal/secure context has been saved.

Change-Id: I1b48a7ea005d56b1f25e2b5313d77e67d2f02bc5
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
diff --git a/lib/el3_runtime/aarch64/context_mgmt.c b/lib/el3_runtime/aarch64/context_mgmt.c
index 21e86de..c8232df 100644
--- a/lib/el3_runtime/aarch64/context_mgmt.c
+++ b/lib/el3_runtime/aarch64/context_mgmt.c
@@ -13,6 +13,7 @@
 #include <interrupt_mgmt.h>
 #include <platform.h>
 #include <platform_def.h>
+#include <pubsub_events.h>
 #include <smcc_helpers.h>
 #include <string.h>
 #include <utils.h>
@@ -421,9 +422,8 @@
 		}
 	}
 
-	el1_sysregs_context_restore(get_sysregs_ctx(ctx));
-
-	cm_set_next_context(ctx);
+	cm_el1_sysregs_context_restore(security_state);
+	cm_set_next_eret_context(security_state);
 }
 
 /*******************************************************************************
@@ -440,6 +440,13 @@
 
 	el1_sysregs_context_save(get_sysregs_ctx(ctx));
 	el1_sysregs_context_save_post_ops();
+
+#if IMAGE_BL31
+	if (security_state == SECURE)
+		PUBLISH_EVENT(cm_exited_secure_world);
+	else
+		PUBLISH_EVENT(cm_exited_normal_world);
+#endif
 }
 
 void cm_el1_sysregs_context_restore(uint32_t security_state)
@@ -450,6 +457,13 @@
 	assert(ctx);
 
 	el1_sysregs_context_restore(get_sysregs_ctx(ctx));
+
+#if IMAGE_BL31
+	if (security_state == SECURE)
+		PUBLISH_EVENT(cm_entering_secure_world);
+	else
+		PUBLISH_EVENT(cm_entering_normal_world);
+#endif
 }
 
 /*******************************************************************************