cactus: select different stdout device at runtime
cactus is used as both primary and secondary VM and for debug logging
primary VM can access to UART while secodary VM's use hypervisor call to
SPM.
Based on VM id it will be decided whether to use UART or hypervisor call
for debug logging.
Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: I97786b893c0156815969692582b4de62c1b568fd
diff --git a/spm/cactus/cactus_debug.c b/spm/cactus/cactus_debug.c
new file mode 100644
index 0000000..cce0973
--- /dev/null
+++ b/spm/cactus/cactus_debug.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <drivers/arm/pl011.h>
+#include <drivers/console.h>
+
+#include "cactus.h"
+#include "spci_helpers.h"
+
+static int (*putc_impl)(int);
+
+static int putc_hypcall(int c)
+{
+ spm_debug_log((char)c);
+
+ return c;
+}
+
+static int putc_uart(int c)
+{
+ console_pl011_putc(c);
+
+ return c;
+}
+
+void set_putc_impl(enum stdout_route route)
+{
+ switch (route) {
+
+ case HVC_CALL_AS_STDOUT:
+ putc_impl = putc_hypcall;
+ return;
+
+ case PL011_AS_STDOUT:
+ default:
+ break;
+ }
+
+ putc_impl = putc_uart;
+}
+
+int console_putc(int c)
+{
+ if (!putc_impl) {
+ return -1;
+ }
+
+ return putc_impl(c);
+}