xref: /optee_os/core/arch/arm/plat-synquacer/main.c (revision 5b60351fd02a7b17ccff8c897154491258891ffb)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2018, Linaro Limited
4  */
5 
6 #include <arm.h>
7 #include <console.h>
8 #include <drivers/gic.h>
9 #include <drivers/pl011.h>
10 #include <io.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 <kernel/thread.h>
16 #include <kernel/timer.h>
17 #include <mm/core_memprot.h>
18 #include <platform_config.h>
19 #include <sm/optee_smc.h>
20 #include <tee/entry_fast.h>
21 #include <tee/entry_std.h>
22 
23 static void main_fiq(void);
24 
25 static const struct thread_handlers handlers = {
26 	.std_smc = tee_entry_std,
27 	.fast_smc = tee_entry_fast,
28 	.nintr = main_fiq,
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 };
36 
37 static struct gic_data gic_data;
38 static struct pl011_data console_data;
39 
40 register_phys_mem(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE, CORE_MMU_DEVICE_SIZE);
41 register_phys_mem(MEM_AREA_IO_SEC, GIC_BASE, CORE_MMU_DEVICE_SIZE);
42 
43 const struct thread_handlers *generic_boot_get_handlers(void)
44 {
45 	return &handlers;
46 }
47 
48 static void main_fiq(void)
49 {
50 	gic_it_handle(&gic_data);
51 }
52 
53 void console_init(void)
54 {
55 	pl011_init(&console_data, CONSOLE_UART_BASE, CONSOLE_UART_CLK_IN_HZ,
56 		   CONSOLE_BAUDRATE);
57 	register_serial_console(&console_data.chip);
58 }
59 
60 void main_init_gic(void)
61 {
62 	vaddr_t gicd_base;
63 
64 	gicd_base = (vaddr_t)phys_to_virt(GIC_BASE + GICD_OFFSET,
65 					  MEM_AREA_IO_SEC);
66 
67 	if (!gicd_base)
68 		panic();
69 
70 	/* On ARMv8-A, GIC configuration is initialized in TF-A */
71 	gic_init_base_addr(&gic_data, 0, gicd_base);
72 
73 	itr_init(&gic_data.chip);
74 }
75 
76 static enum itr_return timer_itr_cb(struct itr_handler *h __unused)
77 {
78 	/* Reset timer for next FIQ */
79 	generic_timer_handler(TIMER_PERIOD_MS);
80 
81 	return ITRR_HANDLED;
82 }
83 
84 static struct itr_handler timer_itr = {
85 	.it = IT_SEC_TIMER,
86 	.flags = ITRF_TRIGGER_LEVEL,
87 	.handler = timer_itr_cb,
88 };
89 
90 static TEE_Result init_timer_itr(void)
91 {
92 	itr_add(&timer_itr);
93 	itr_enable(IT_SEC_TIMER);
94 
95 	return TEE_SUCCESS;
96 }
97 driver_init(init_timer_itr);
98