xref: /optee_os/core/arch/arm/plat-rockchip/main.c (revision 08ede0258e33f4ad2a6f1f890e5f165e138ad219)
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/generic_boot.h>
12 #include <kernel/panic.h>
13 #include <kernel/pm_stubs.h>
14 #include <mm/core_memprot.h>
15 #include <platform_config.h>
16 #include <stdint.h>
17 #include <tee/entry_std.h>
18 #include <tee/entry_fast.h>
19 
20 static struct gic_data gic_data;
21 static struct serial8250_uart_data console_data;
22 
23 register_phys_mem_pgdir(MEM_AREA_IO_SEC, GIC_BASE, GIC_SIZE);
24 register_phys_mem_pgdir(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE,
25 			CONSOLE_UART_SIZE);
26 
27 static const struct thread_handlers handlers = {
28 #if defined(CFG_WITH_ARM_TRUSTED_FW)
29 	.cpu_on = cpu_on_handler,
30 	.cpu_off = pm_do_nothing,
31 	.cpu_suspend = pm_do_nothing,
32 	.cpu_resume = pm_do_nothing,
33 	.system_off = pm_do_nothing,
34 	.system_reset = pm_do_nothing,
35 #else
36 	.cpu_on = pm_do_nothing,
37 	.cpu_off = pm_do_nothing,
38 	.cpu_suspend = pm_do_nothing,
39 	.cpu_resume = pm_do_nothing,
40 	.system_off = pm_do_nothing,
41 	.system_reset = pm_do_nothing,
42 #endif
43 };
44 
45 void main_init_gic(void)
46 {
47 	vaddr_t gicc_base = 0;
48 	vaddr_t gicd_base = 0;
49 
50 #if !defined(CFG_ARM_GICV3)
51 	gicc_base = (vaddr_t)phys_to_virt(GICC_BASE, MEM_AREA_IO_SEC);
52 	if (!gicc_base)
53 		panic();
54 #endif
55 
56 	gicd_base = (vaddr_t)phys_to_virt(GICD_BASE, MEM_AREA_IO_SEC);
57 	if (!gicd_base)
58 		panic();
59 
60 	/* Initialize GIC */
61 	gic_init(&gic_data, gicc_base, gicd_base);
62 	itr_init(&gic_data.chip);
63 }
64 
65 void main_secondary_init_gic(void)
66 {
67 	gic_cpu_init(&gic_data);
68 }
69 
70 const struct thread_handlers *generic_boot_get_handlers(void)
71 {
72 	return &handlers;
73 }
74 
75 void console_init(void)
76 {
77 	serial8250_uart_init(&console_data, CONSOLE_UART_BASE,
78 			     CONSOLE_UART_CLK_IN_HZ, CONSOLE_BAUDRATE);
79 	register_serial_console(&console_data.chip);
80 }
81