1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (C) 2017, Fuzhou Rockchip Electronics Co., Ltd.
4  * Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH
5  */
6 
7 #include <console.h>
8 #include <drivers/gic.h>
9 #include <drivers/serial8250_uart.h>
10 #include <io.h>
11 #include <kernel/boot.h>
12 #include <kernel/panic.h>
13 #include <mm/core_memprot.h>
14 #include <platform_config.h>
15 #include <stdint.h>
16 
17 static struct gic_data gic_data;
18 
19 #if defined(CFG_EARLY_CONSOLE)
20 static struct serial8250_uart_data early_console_data;
21 register_phys_mem_pgdir(MEM_AREA_IO_NSEC,
22 			CFG_EARLY_CONSOLE_BASE, CFG_EARLY_CONSOLE_SIZE);
23 #endif
24 
25 register_phys_mem_pgdir(MEM_AREA_IO_SEC, GIC_BASE, GIC_SIZE);
26 
main_init_gic(void)27 void main_init_gic(void)
28 {
29 	gic_init(&gic_data, GICC_BASE, GICD_BASE);
30 	itr_init(&gic_data.chip);
31 }
32 
main_secondary_init_gic(void)33 void main_secondary_init_gic(void)
34 {
35 	gic_cpu_init(&gic_data);
36 }
37 
console_init(void)38 void console_init(void)
39 {
40 #if defined(CFG_EARLY_CONSOLE)
41 	/*
42 	 * Console devices can vary a lot between devices and
43 	 * OP-TEE will switch to the DT-based real console later,
44 	 * based on DT-devices and the systems chosen node.
45 	 * So early console is only needed for early debugging.
46 	 */
47 	serial8250_uart_init(&early_console_data,
48 			     CFG_EARLY_CONSOLE_BASE,
49 			     CFG_EARLY_CONSOLE_CLK_IN_HZ,
50 			     CFG_EARLY_CONSOLE_BAUDRATE);
51 	register_serial_console(&early_console_data.chip);
52 #endif
53 }
54