refactor(xilinx): register runtime console directly

Initialize runtime console early instead of deferred init.

Change-Id: Iae2f69ba4da27b62b69d640e3ccdc1303f549617
Signed-off-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Maheedhar Bollapalli <MaheedharSai.Bollapalli@amd.com>
diff --git a/plat/xilinx/common/include/plat_console.h b/plat/xilinx/common/include/plat_console.h
index 9f212ec..fa6021d 100644
--- a/plat/xilinx/common/include/plat_console.h
+++ b/plat/xilinx/common/include/plat_console.h
@@ -14,12 +14,12 @@
 /* Default console type is either CADENCE0 or CADENCE1 or PL011_0 or PL011_1
  * Debug console type is DCC
  */
-#define CONSOLE_CDNS	0
-#define CONSOLE_PL011   1
-#define CONSOLE_DCC	2
+#define CONSOLE_NONE	0
+#define CONSOLE_CDNS	1
+#define CONSOLE_PL011   2
+#define CONSOLE_DCC	3
 
 typedef struct console_hd {
-	uint8_t console_state;
 	uint32_t clk;
 	uint32_t baud_rate;
 	uintptr_t base;
@@ -31,14 +31,9 @@
 	char compatible[30];
 	uintptr_t base;
 	uint32_t baud_rate;
-	int32_t status;
 	uint8_t console_type;
 } dt_uart_info_t;
 
 void setup_console(void);
 
-#if defined(CONSOLE_RUNTIME)
-void console_runtime_init(void);
-#endif
-
 #endif /* PLAT_DT_UART_H */
diff --git a/plat/xilinx/common/plat_console.c b/plat/xilinx/common/plat_console.c
index 5192ac0..63b6042 100644
--- a/plat/xilinx/common/plat_console.c
+++ b/plat/xilinx/common/plat_console.c
@@ -246,63 +246,11 @@
 }
 #endif
 
-#if defined(CONSOLE_RUNTIME)
-/**
- * get_rt_console() - Retrieves console data for runtime console.
- *
- * Return: returns  0 if consoles differ else returns 1 if
- * dt node is disabled or consoles match.
- */
-static uint32_t get_rt_console(void)
-{
-	uint32_t rc = 0;
-
-#if (RT_CONSOLE_IS(dtb) && defined(XILINX_OF_BOARD_DTB_ADDR)) && \
-	(!defined(PLAT_zynqmp) || (defined(PLAT_zynqmp) && \
-				   !IS_TFA_IN_OCM(BL31_BASE)))
-	/* DT based runtime console */
-	if ((dt_uart_info.base != 0) && (dt_uart_info.status != 0)) {
-		rt_hd_console.base = dt_uart_info.base;
-		rt_hd_console.baud_rate = dt_uart_info.baud_rate;
-		rt_hd_console.console_state = dt_uart_info.status;
-		if (rt_hd_console.base == boot_console.base) {
-			rc = 1;
-		}
-	} else {
-		rc = 1;
-	}
-#else
-	rt_hd_console.base = (uintptr_t)RT_UART_BASE;
-	rt_hd_console.baud_rate = (uint32_t)UART_BAUDRATE;
-	if (rt_hd_console.base != boot_console.base) {
-		rt_hd_console.console_state = 1;
-	} else {
-		rt_hd_console.console_state = 0;
-		rc = 1;
-	}
-#endif
-	rt_hd_console.clk = get_uart_clk();
-	rt_hd_console.console_type = RT_UART_TYPE;
-	rt_hd_console.console_scope = CONSOLE_FLAG_RUNTIME;
-	return rc;
-}
-
-void console_runtime_init(void)
-{
-	/* skip console registration if runtime and boot console are same */
-	if (rt_hd_console.console_state) {
-		register_console(&rt_hd_console, &runtime_console);
-		INFO("Successfully initialized runtime console\n");
-	}
-}
-#endif
-
 void setup_console(void)
 {
 	/* This is hardcoded console setup just in case that DTB console fails */
 	boot_hd_console.base = (uintptr_t)UART_BASE;
 	boot_hd_console.baud_rate = (uint32_t)UART_BAUDRATE;
-	boot_hd_console.console_state = 1;
 	boot_hd_console.clk = get_uart_clk();
 	boot_hd_console.console_scope = CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH;
 	boot_hd_console.console_type = UART_TYPE;
@@ -328,15 +276,35 @@
 	/* Initialize the boot console */
 	register_console(&boot_hd_console, &boot_console);
 
+	INFO("BL31: Early console setup\n");
+
 #ifdef CONSOLE_RUNTIME
-	int32_t rc;
-	uint32_t console_scope;
+#if (RT_CONSOLE_IS(dtb) && defined(XILINX_OF_BOARD_DTB_ADDR)) && \
+	       (!defined(PLAT_zynqmp) || (defined(PLAT_zynqmp) && \
+					!IS_TFA_IN_OCM(BL31_BASE)))
+	/* DT based runtime console */
+	if (dt_uart_info.console_type != CONSOLE_NONE) {
+		rt_hd_console.base = dt_uart_info.base;
+		rt_hd_console.baud_rate = dt_uart_info.baud_rate;
+		rt_hd_console.console_type = dt_uart_info.console_type;
+	}
+#else
+	rt_hd_console.base = (uintptr_t)RT_UART_BASE;
+	rt_hd_console.baud_rate = (uint32_t)UART_BAUDRATE;
+	rt_hd_console.console_type = RT_UART_TYPE;
+#endif
 
-	rc = get_rt_console();
-	if (rc) {
-		console_scope = CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH | CONSOLE_FLAG_RUNTIME;
-		console_set_scope(&boot_console, console_scope);
+	if ((rt_hd_console.console_type == boot_hd_console.console_type) &&
+			(rt_hd_console.base == boot_hd_console.base)) {
+		console_set_scope(&boot_console,
+				CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH | CONSOLE_FLAG_RUNTIME);
+		INFO("Successfully initialized runtime console\n");
+	} else {
+		rt_hd_console.clk = get_uart_clk();
+		rt_hd_console.console_scope = CONSOLE_FLAG_RUNTIME;
+
+		register_console(&rt_hd_console, &runtime_console);
+		INFO("Successfully initialized new runtime console\n");
 	}
 #endif
-	INFO("BL31: Early console setup\n");
 }
diff --git a/plat/xilinx/zynqmp/bl31_zynqmp_setup.c b/plat/xilinx/zynqmp/bl31_zynqmp_setup.c
index a6d270c..50d4240 100644
--- a/plat/xilinx/zynqmp/bl31_zynqmp_setup.c
+++ b/plat/xilinx/zynqmp/bl31_zynqmp_setup.c
@@ -191,10 +191,6 @@
 #endif
 
 	custom_runtime_setup();
-
-#if defined(CONSOLE_RUNTIME)
-	console_runtime_init();
-#endif
 }
 
 /*