test(realm): add plane PSI interface

Add Plane service routine interface.
Aux plane can communicate with primary plane using PSI
PSI uses hvc conduit from aux plane.
Add initial printf support for planes

Signed-off-by: Shruti Gupta <shruti.gupta@arm.com>
Change-Id: I484cbd32791970c6e22c5d63e13b43807f4f3c06
diff --git a/realm/realm_payload_main.c b/realm/realm_payload_main.c
index 3339b9a..eb4c9aa 100644
--- a/realm/realm_payload_main.c
+++ b/realm/realm_payload_main.c
@@ -14,6 +14,8 @@
 #include <host_shared_data.h>
 #include <pauth.h>
 #include "realm_def.h"
+#include <realm_helpers.h>
+#include <realm_psi.h>
 #include <realm_rsi.h>
 #include <realm_tests.h>
 #include <serror.h>
@@ -184,18 +186,20 @@
 
 static bool realm_exception_handler(void)
 {
-	u_register_t base, far, esr;
+	u_register_t base, far, esr, elr;
 
 	base = realm_shared_data_get_my_host_val(HOST_ARG1_INDEX);
 	far = read_far_el1();
 	esr = read_esr_el1();
+	elr = read_elr_el1();
 
 	if (far == base) {
 		/* Return ESR to Host */
 		realm_shared_data_set_my_realm_val(HOST_ARG2_INDEX, esr);
 		rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
 	}
-	realm_printf("Realm Abort fail incorrect FAR=0x%lx ESR=0x%lx\n", far, esr);
+	realm_printf("Realm Abort fail incorrect FAR=0x%lx ESR=0x%lx ELR=0x%lx\n",
+			far, esr, elr);
 	rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
 
 	/* Should not return */
@@ -266,7 +270,7 @@
 	/* No serror handler registered by default */
 	unregister_custom_serror_handler();
 
-	realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer());
+	realm_set_shared_structure((host_shared_data_t *)realm_get_ns_buffer());
 
 	if (realm_get_my_shared_structure() != NULL) {
 		uint8_t cmd = realm_shared_data_get_my_realm_cmd();
@@ -381,8 +385,18 @@
 	}
 
 	if (test_succeed) {
-		rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
+		if (realm_is_plane0()) {
+			rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
+		} else {
+			psi_exit_to_plane0(PSI_CALL_EXIT_SUCCESS_CMD,
+					0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL);
+		}
 	} else {
-		rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
+		if (realm_is_plane0()) {
+			rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
+		} else {
+			psi_exit_to_plane0(PSI_CALL_EXIT_FAILED_CMD,
+					0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL);
+		}
 	}
 }