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