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_debug.c b/realm/realm_debug.c
index 1c4ee03..6bf8adf 100644
--- a/realm/realm_debug.c
+++ b/realm/realm_debug.c
@@ -11,6 +11,8 @@
 
 #include <arch_helpers.h>
 #include <host_shared_data.h>
+#include <realm_helpers.h>
+#include <realm_psi.h>
 #include <realm_rsi.h>
 
 /*
@@ -23,6 +25,7 @@
 	host_shared_data_t *guest_shared_data = realm_get_my_shared_structure();
 	char *log_buffer = (char *)guest_shared_data->log_buffer;
 	va_list args;
+	u_register_t ret;
 
 	va_start(args, fmt);
 	if (strnlen((const char *)log_buffer, MAX_BUF_SIZE) == MAX_BUF_SIZE) {
@@ -32,7 +35,15 @@
 			strnlen((const char *)log_buffer, MAX_BUF_SIZE),
 			MAX_BUF_SIZE, fmt, args);
 	va_end(args);
-	rsi_exit_to_host(HOST_CALL_EXIT_PRINT_CMD);
+	ret = rsi_exit_to_host(HOST_CALL_EXIT_PRINT_CMD);
+
+	/*
+	 * Retry with PSI call for secondary planes
+	 * Note - RSI_HOST_CALL will fail if test in P0 sets trap_hc flag in plane_enter
+	 */
+	if ((ret != RSI_SUCCESS && !realm_is_plane0())) {
+		psi_exit_to_plane0(PSI_CALL_EXIT_PRINT_CMD, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL);
+	}
 }
 
 void __attribute__((__noreturn__)) do_panic(const char *file, int line)