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 vaddr_t gicc_base = 0;
30 vaddr_t gicd_base = 0;
31
32 #if !defined(CFG_ARM_GICV3)
33 gicc_base = (vaddr_t)phys_to_virt(GICC_BASE, MEM_AREA_IO_SEC, 1);
34 if (!gicc_base)
35 panic();
36 #endif
37
38 gicd_base = (vaddr_t)phys_to_virt(GICD_BASE, MEM_AREA_IO_SEC, 1);
39 if (!gicd_base)
40 panic();
41
42 /* Initialize GIC */
43 gic_init(&gic_data, gicc_base, gicd_base);
44 itr_init(&gic_data.chip);
45 }
46
main_secondary_init_gic(void)47 void main_secondary_init_gic(void)
48 {
49 gic_cpu_init(&gic_data);
50 }
51
console_init(void)52 void console_init(void)
53 {
54 #if defined(CFG_EARLY_CONSOLE)
55 /*
56 * Console devices can vary a lot between devices and
57 * OP-TEE will switch to the DT-based real console later,
58 * based on DT-devices and the systems chosen node.
59 * So early console is only needed for early debugging.
60 */
61 serial8250_uart_init(&early_console_data,
62 CFG_EARLY_CONSOLE_BASE,
63 CFG_EARLY_CONSOLE_CLK_IN_HZ,
64 CFG_EARLY_CONSOLE_BAUDRATE);
65 register_serial_console(&early_console_data.chip);
66 #endif
67 }
68