pl011: allow alternate stdout to be used

Till now only pl011 UART is available stdout but there is a usecase to
redirect it to other channel.

This patch decouples console_putc implementation from pl011.

Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: I38e8c5c90421fad2425228f407e6f29bdf6b08c7
diff --git a/drivers/arm/pl011/aarch32/pl011_console.S b/drivers/arm/pl011/aarch32/pl011_console.S
index c65c4f6..b201f04 100644
--- a/drivers/arm/pl011/aarch32/pl011_console.S
+++ b/drivers/arm/pl011/aarch32/pl011_console.S
@@ -10,7 +10,7 @@
 #include <drivers/console.h>
 
 	.globl	console_init
-	.globl	console_putc
+	.globl	console_pl011_putc
 	.globl	console_getc
 	.globl	console_try_getc
 	.globl	console_flush
@@ -97,17 +97,19 @@
 	bx	lr
 endfunc console_core_init
 
-	/* ---------------------------------------------
-	 * int console_putc(int c)
+	/* -------------------------------------------------
+	 * To allow alternate implementation of putc, pl011
+	 * is appended in the function name.
+	 * int console_pl011_putc(int c)
 	 *
 	 * Clobber list : r1, r2
-	 * ---------------------------------------------
+	 * -------------------------------------------------
 	 */
-func console_putc
+func console_pl011_putc
 	ldr	r1, =console_base
 	ldr	r1, [r1]
 	b	console_core_putc
-endfunc console_putc
+endfunc console_pl011_putc
 
 	/* --------------------------------------------------------
 	 * int console_core_putc(int c, uintptr_t base_addr)
diff --git a/drivers/arm/pl011/aarch64/pl011_console.S b/drivers/arm/pl011/aarch64/pl011_console.S
index 8b1e062..0d607b9 100644
--- a/drivers/arm/pl011/aarch64/pl011_console.S
+++ b/drivers/arm/pl011/aarch64/pl011_console.S
@@ -10,7 +10,7 @@
 #include <drivers/console.h>
 
 	.globl	console_init
-	.globl	console_putc
+	.globl	console_pl011_putc
 	.globl	console_getc
 	.globl	console_try_getc
 	.globl	console_flush
@@ -93,17 +93,20 @@
 	ret
 endfunc console_core_init
 
-	/* ---------------------------------------------
-	 * int console_putc(int c)
+	/* -------------------------------------------------
+	 * To allow alternate implementation of putc, pl011
+	 * is appended in the function name.
+	 *
+	 * int console_pl011_putc(int c)
 	 *
 	 * Clobber list : x1, x2
-	 * ---------------------------------------------
+	 * -------------------------------------------------
 	 */
-func console_putc
+func console_pl011_putc
 	adrp	x1, console_base
 	ldr	x1, [x1, :lo12:console_base]
 	b	console_core_putc
-endfunc console_putc
+endfunc console_pl011_putc
 
 	/* ---------------------------------------------
 	 * int console_core_putc(int c, uintptr_t base_addr)
diff --git a/drivers/console/console.c b/drivers/console/console.c
new file mode 100644
index 0000000..b2bae28
--- /dev/null
+++ b/drivers/console/console.c
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <drivers/arm/pl011.h>
+
+int console_putc(int c)
+{
+	return console_pl011_putc(c);
+}
diff --git a/include/drivers/arm/pl011.h b/include/drivers/arm/pl011.h
index cba325d..3e19ee8 100644
--- a/include/drivers/arm/pl011.h
+++ b/include/drivers/arm/pl011.h
@@ -75,4 +75,13 @@
 /* Constants */
 #define PL011_BAUDRATE		115200
 
+#ifndef __ASSEMBLER__
+#include <stdint.h>
+
+/* Functions */
+
+int console_pl011_putc(int);
+
+#endif /* __ASSEMBLER__ */
+
 #endif	/* __PL011_H__ */
diff --git a/plat/arm/common/arm_common.mk b/plat/arm/common/arm_common.mk
index 73b4690..b146654 100644
--- a/plat/arm/common/arm_common.mk
+++ b/plat/arm/common/arm_common.mk
@@ -8,6 +8,7 @@
 
 PLAT_SOURCES	+=	drivers/arm/gic/gic_common.c			\
 			drivers/arm/pl011/${ARCH}/pl011_console.S	\
+			drivers/console/console.c			\
 			plat/arm/common/arm_setup.c			\
 			plat/arm/common/arm_timers.c
 
diff --git a/plat/hisilicon/hikey960/platform.mk b/plat/hisilicon/hikey960/platform.mk
index 4bc1626..20b42df 100644
--- a/plat/hisilicon/hikey960/platform.mk
+++ b/plat/hisilicon/hikey960/platform.mk
@@ -17,6 +17,7 @@
 			drivers/arm/gic/arm_gic_v2.c			\
 			drivers/arm/timer/system_timer.c		\
 			drivers/arm/timer/private_timer.c		\
+			drivers/console/console.c			\
 			plat/arm/common/arm_timers.c
 
 TFTF_CFLAGS		+= -Wno-maybe-uninitialized
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index d89a4bd..ccb85b9 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -37,6 +37,7 @@
 	tftf/framework/${ARCH}/asm_debug.S
 
 CACTUS_SOURCES	+= 	drivers/arm/pl011/${ARCH}/pl011_console.S	\
+			drivers/console/console.c			\
 			lib/${ARCH}/cache_helpers.S			\
 			lib/${ARCH}/misc_helpers.S			\
 			lib/smc/${ARCH}/asm_smc.S			\
diff --git a/spm/cactus_mm/cactus_mm.mk b/spm/cactus_mm/cactus_mm.mk
index c76890d..b96580c 100644
--- a/spm/cactus_mm/cactus_mm.mk
+++ b/spm/cactus_mm/cactus_mm.mk
@@ -39,6 +39,7 @@
 
 CACTUS_MM_SOURCES	+=				\
 	drivers/arm/pl011/${ARCH}/pl011_console.S	\
+	drivers/console/console.c			\
 	lib/${ARCH}/cache_helpers.S			\
 	lib/${ARCH}/misc_helpers.S			\
 
diff --git a/spm/ivy/ivy.mk b/spm/ivy/ivy.mk
index 16f62ad..8d5475a 100644
--- a/spm/ivy/ivy.mk
+++ b/spm/ivy/ivy.mk
@@ -39,6 +39,7 @@
 	tftf/framework/${ARCH}/asm_debug.S
 
 IVY_SOURCES	+= 	drivers/arm/pl011/${ARCH}/pl011_console.S	\
+			drivers/console/console.c			\
 			lib/${ARCH}/cache_helpers.S			\
 			lib/${ARCH}/misc_helpers.S			\
 			lib/locks/${ARCH}/spinlock.S			\