feat: tftf realm extension
This patch adds Realm payload management capabilities to TFTF
to act as a NS Host, it includes creation and destruction of a Realm,
mapping of protected data and creation of all needed RTT levels,
sharing of NS memory buffer from Host to Realm by mapping of
unprotected IPA, create REC and auxiliary granules, exit Realm
using RSI_HOST_CALL ABI.
Older realm_payload name is used now for only R-EL1 test cases,
RMI and SPM test cases have been moved to new file tests-rmi-spm.
New TFTF_MAX_IMAGE_SIZE argument added to FVP platform.mk,
as an offset from where R-EL1 payload memory resources start.
Signed-off-by: Nabil Kahlouche <nabil.kahlouche@arm.com>
Change-Id: Ida4cfd334795879d55924bb33b9b77182a3dcef7
diff --git a/realm/realm_debug.c b/realm/realm_debug.c
new file mode 100644
index 0000000..e9eb61e
--- /dev/null
+++ b/realm/realm_debug.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <arch_helpers.h>
+#include <host_shared_data.h>
+
+/*
+ * A printf formatted function used in the Realm world to log messages
+ * in the shared buffer.
+ * Locate the shared logging buffer and print its content
+ */
+void realm_printf(const char *fmt, ...)
+{
+ host_shared_data_t *guest_shared_data = realm_get_shared_structure();
+ char *log_buffer = (char *)guest_shared_data->log_buffer;
+ va_list args;
+
+ va_start(args, fmt);
+ spin_lock((spinlock_t *)&guest_shared_data->printf_lock);
+ if (strnlen((const char *)log_buffer, MAX_BUF_SIZE) == MAX_BUF_SIZE) {
+ (void)memset((char *)log_buffer, 0, MAX_BUF_SIZE);
+ }
+ (void)vsnprintf((char *)log_buffer +
+ strnlen((const char *)log_buffer, MAX_BUF_SIZE),
+ MAX_BUF_SIZE, fmt, args);
+ spin_unlock((spinlock_t *)&guest_shared_data->printf_lock);
+ va_end(args);
+}
+
+void __attribute__((__noreturn__)) do_panic(const char *file, int line)
+{
+ realm_printf("PANIC in file: %s line: %d\n", file, line);
+ while (true) {
+ continue;
+ }
+}
+
+/* This is used from printf() when crash dump is reached */
+int console_putc(int c)
+{
+ host_shared_data_t *guest_shared_data = realm_get_shared_structure();
+ char *log_buffer = (char *)guest_shared_data->log_buffer;
+
+ if ((c < 0) || (c > 127)) {
+ return -1;
+ }
+ spin_lock((spinlock_t *)&guest_shared_data->printf_lock);
+ if (strnlen((const char *)log_buffer, MAX_BUF_SIZE) == MAX_BUF_SIZE) {
+ (void)memset((char *)log_buffer, 0, MAX_BUF_SIZE);
+ }
+ *((char *)log_buffer + strnlen((const char *)log_buffer, MAX_BUF_SIZE)) = c;
+ spin_unlock((spinlock_t *)&guest_shared_data->printf_lock);
+
+ return c;
+}