xref: /optee_os/core/arch/arm/plat-synquacer/main.c (revision 336e32995d9c419d9fc2a6fd5974f99761285415)
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 #include <rng_pta.h>
23 
24 static void main_fiq(void);
25 
26 static const struct thread_handlers handlers = {
27 	.std_smc = tee_entry_std,
28 	.fast_smc = tee_entry_fast,
29 	.nintr = main_fiq,
30 	.cpu_on = cpu_on_handler,
31 	.cpu_off = pm_do_nothing,
32 	.cpu_suspend = pm_do_nothing,
33 	.cpu_resume = pm_do_nothing,
34 	.system_off = pm_do_nothing,
35 	.system_reset = pm_do_nothing,
36 };
37 
38 static struct gic_data gic_data;
39 static struct pl011_data console_data;
40 
41 register_phys_mem(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE, CORE_MMU_DEVICE_SIZE);
42 register_phys_mem(MEM_AREA_IO_SEC, GIC_BASE, CORE_MMU_DEVICE_SIZE);
43 register_phys_mem(MEM_AREA_IO_SEC, THERMAL_SENSOR_BASE, CORE_MMU_DEVICE_SIZE);
44 
45 const struct thread_handlers *generic_boot_get_handlers(void)
46 {
47 	return &handlers;
48 }
49 
50 static void main_fiq(void)
51 {
52 	gic_it_handle(&gic_data);
53 }
54 
55 void console_init(void)
56 {
57 	pl011_init(&console_data, CONSOLE_UART_BASE, CONSOLE_UART_CLK_IN_HZ,
58 		   CONSOLE_BAUDRATE);
59 	register_serial_console(&console_data.chip);
60 }
61 
62 void main_init_gic(void)
63 {
64 	vaddr_t gicd_base;
65 
66 	gicd_base = (vaddr_t)phys_to_virt(GIC_BASE + GICD_OFFSET,
67 					  MEM_AREA_IO_SEC);
68 
69 	if (!gicd_base)
70 		panic();
71 
72 	/* On ARMv8-A, GIC configuration is initialized in TF-A */
73 	gic_init_base_addr(&gic_data, 0, gicd_base);
74 
75 	itr_init(&gic_data.chip);
76 }
77 
78 static enum itr_return timer_itr_cb(struct itr_handler *h __unused)
79 {
80 	/* Reset timer for next FIQ */
81 	generic_timer_handler(TIMER_PERIOD_MS);
82 
83 	/* Collect entropy on each timer FIQ */
84 	rng_collect_entropy();
85 
86 	return ITRR_HANDLED;
87 }
88 
89 static struct itr_handler timer_itr = {
90 	.it = IT_SEC_TIMER,
91 	.flags = ITRF_TRIGGER_LEVEL,
92 	.handler = timer_itr_cb,
93 };
94 
95 static TEE_Result init_timer_itr(void)
96 {
97 	itr_add(&timer_itr);
98 	itr_enable(IT_SEC_TIMER);
99 
100 	/* Enable timer FIQ to fetch entropy required during boot */
101 	generic_timer_start(TIMER_PERIOD_MS);
102 
103 	return TEE_SUCCESS;
104 }
105 driver_init(init_timer_itr);
106