xref: /optee_os/core/arch/arm/plat-stm32mp1/main.c (revision 0323f7b87dd12c496d6fc23ea637442f8b5c20a7)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2017-2018, STMicroelectronics
4  * Copyright (c) 2016-2018, Linaro Limited
5  */
6 
7 #include <boot_api.h>
8 #include <console.h>
9 #include <drivers/gic.h>
10 #include <drivers/stm32_uart.h>
11 #include <kernel/generic_boot.h>
12 #include <kernel/misc.h>
13 #include <kernel/panic.h>
14 #include <kernel/pm_stubs.h>
15 #include <mm/core_memprot.h>
16 #include <platform_config.h>
17 #include <sm/psci.h>
18 #include <tee/entry_std.h>
19 #include <tee/entry_fast.h>
20 #include <trace.h>
21 
22 register_phys_mem(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE, CONSOLE_UART_SIZE);
23 
24 register_phys_mem(MEM_AREA_IO_SEC, GIC_BASE, GIC_SIZE);
25 register_phys_mem(MEM_AREA_IO_SEC, BKP_REGS_BASE, SMALL_PAGE_SIZE);
26 
27 static struct gic_data gic_data;
28 static struct console_pdata console_data;
29 
30 static void main_fiq(void)
31 {
32 	gic_it_handle(&gic_data);
33 }
34 
35 static const struct thread_handlers handlers = {
36 	.std_smc = tee_entry_std,
37 	.fast_smc = tee_entry_fast,
38 	.nintr = main_fiq,
39 	.cpu_on = pm_panic,
40 	.cpu_off = pm_panic,
41 	.cpu_suspend = pm_panic,
42 	.cpu_resume = pm_panic,
43 	.system_off = pm_panic,
44 	.system_reset = pm_panic,
45 };
46 
47 const struct thread_handlers *generic_boot_get_handlers(void)
48 {
49 	return &handlers;
50 }
51 
52 #define _ID2STR(id)		(#id)
53 #define ID2STR(id)		_ID2STR(id)
54 
55 static TEE_Result platform_banner(void)
56 {
57 #ifdef CFG_EMBED_DTB
58 	IMSG("Platform stm32mp1: flavor %s - DT %s",
59 		ID2STR(PLATFORM_FLAVOR),
60 		ID2STR(CFG_EMBED_DTB_SOURCE_FILE));
61 #else
62 	IMSG("Platform stm32mp1: flavor %s - no device tree",
63 		ID2STR(PLATFORM_FLAVOR));
64 #endif
65 
66 	return TEE_SUCCESS;
67 }
68 service_init(platform_banner);
69 
70 void console_init(void)
71 {
72 	stm32_uart_init(&console_data, CONSOLE_UART_BASE);
73 	register_serial_console(&console_data.chip);
74 }
75 
76 void main_init_gic(void)
77 {
78 	void *gicc_base;
79 	void *gicd_base;
80 
81 	gicc_base = phys_to_virt(GIC_BASE + GICC_OFFSET, MEM_AREA_IO_SEC);
82 	gicd_base = phys_to_virt(GIC_BASE + GICD_OFFSET, MEM_AREA_IO_SEC);
83 	if (!gicc_base || !gicd_base)
84 		panic();
85 
86 	gic_init(&gic_data, (vaddr_t)gicc_base, (vaddr_t)gicd_base);
87 	itr_init(&gic_data.chip);
88 }
89 
90 void main_secondary_init_gic(void)
91 {
92 	gic_cpu_init(&gic_data);
93 }
94