xref: /arm-trusted-firmware/plat/arm/common/arm_console.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2018-2022, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <assert.h>
8*91f16700Schasinglulu 
9*91f16700Schasinglulu #include <platform_def.h>
10*91f16700Schasinglulu 
11*91f16700Schasinglulu #include <common/debug.h>
12*91f16700Schasinglulu #include <drivers/arm/pl011.h>
13*91f16700Schasinglulu #include <drivers/console.h>
14*91f16700Schasinglulu #include <plat/arm/common/plat_arm.h>
15*91f16700Schasinglulu 
16*91f16700Schasinglulu #pragma weak arm_console_runtime_init
17*91f16700Schasinglulu #pragma weak arm_console_runtime_end
18*91f16700Schasinglulu 
19*91f16700Schasinglulu /*******************************************************************************
20*91f16700Schasinglulu  * Functions that set up the console
21*91f16700Schasinglulu  ******************************************************************************/
22*91f16700Schasinglulu static console_t arm_boot_console;
23*91f16700Schasinglulu static console_t arm_runtime_console;
24*91f16700Schasinglulu 
25*91f16700Schasinglulu /* Initialize the console to provide early debug support */
26*91f16700Schasinglulu void __init arm_console_boot_init(void)
27*91f16700Schasinglulu {
28*91f16700Schasinglulu 	/* If the console was initialized already, don't initialize again */
29*91f16700Schasinglulu 	if (arm_boot_console.base == PLAT_ARM_BOOT_UART_BASE) {
30*91f16700Schasinglulu 		return;
31*91f16700Schasinglulu 	}
32*91f16700Schasinglulu 
33*91f16700Schasinglulu 	int rc = console_pl011_register(PLAT_ARM_BOOT_UART_BASE,
34*91f16700Schasinglulu 					PLAT_ARM_BOOT_UART_CLK_IN_HZ,
35*91f16700Schasinglulu 					ARM_CONSOLE_BAUDRATE,
36*91f16700Schasinglulu 					&arm_boot_console);
37*91f16700Schasinglulu 	if (rc == 0) {
38*91f16700Schasinglulu 		/*
39*91f16700Schasinglulu 		 * The crash console doesn't use the multi console API, it uses
40*91f16700Schasinglulu 		 * the core console functions directly. It is safe to call panic
41*91f16700Schasinglulu 		 * and let it print debug information.
42*91f16700Schasinglulu 		 */
43*91f16700Schasinglulu 		panic();
44*91f16700Schasinglulu 	}
45*91f16700Schasinglulu 
46*91f16700Schasinglulu 	console_set_scope(&arm_boot_console, CONSOLE_FLAG_BOOT);
47*91f16700Schasinglulu }
48*91f16700Schasinglulu 
49*91f16700Schasinglulu void arm_console_boot_end(void)
50*91f16700Schasinglulu {
51*91f16700Schasinglulu 	console_flush();
52*91f16700Schasinglulu 	(void)console_unregister(&arm_boot_console);
53*91f16700Schasinglulu }
54*91f16700Schasinglulu 
55*91f16700Schasinglulu /* Initialize the runtime console */
56*91f16700Schasinglulu void arm_console_runtime_init(void)
57*91f16700Schasinglulu {
58*91f16700Schasinglulu 	int rc = console_pl011_register(PLAT_ARM_RUN_UART_BASE,
59*91f16700Schasinglulu 					PLAT_ARM_RUN_UART_CLK_IN_HZ,
60*91f16700Schasinglulu 					ARM_CONSOLE_BAUDRATE,
61*91f16700Schasinglulu 					&arm_runtime_console);
62*91f16700Schasinglulu 	if (rc == 0)
63*91f16700Schasinglulu 		panic();
64*91f16700Schasinglulu 
65*91f16700Schasinglulu 	console_set_scope(&arm_runtime_console, CONSOLE_FLAG_RUNTIME);
66*91f16700Schasinglulu }
67*91f16700Schasinglulu 
68*91f16700Schasinglulu void arm_console_runtime_end(void)
69*91f16700Schasinglulu {
70*91f16700Schasinglulu 	console_flush();
71*91f16700Schasinglulu }
72