xref: /optee_os/core/arch/arm/plat-imx/main.c (revision 0014a941f0d7d8bd61fbe6dd9977b902529bf803)
1 /*
2  * Copyright (C) 2015 Freescale Semiconductor, Inc.
3  * All rights reserved.
4  * Copyright (c) 2016, Wind River Systems.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <arm32.h>
31 #include <console.h>
32 #include <drivers/gic.h>
33 #include <drivers/imx_uart.h>
34 #include <io.h>
35 #include <kernel/generic_boot.h>
36 #include <kernel/misc.h>
37 #include <kernel/panic.h>
38 #include <kernel/pm_stubs.h>
39 #include <mm/core_mmu.h>
40 #include <mm/core_memprot.h>
41 #include <platform_config.h>
42 #include <stdint.h>
43 #include <sm/optee_smc.h>
44 #include <tee/entry_fast.h>
45 #include <tee/entry_std.h>
46 
47 
48 static void main_fiq(void);
49 static struct gic_data gic_data;
50 
51 static const struct thread_handlers handlers = {
52 	.std_smc = tee_entry_std,
53 	.fast_smc = tee_entry_fast,
54 	.nintr = main_fiq,
55 	.cpu_on = pm_panic,
56 	.cpu_off = pm_panic,
57 	.cpu_suspend = pm_panic,
58 	.cpu_resume = pm_panic,
59 	.system_off = pm_panic,
60 	.system_reset = pm_panic,
61 };
62 
63 static struct imx_uart_data console_data;
64 
65 register_phys_mem(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE, CORE_MMU_DEVICE_SIZE);
66 register_phys_mem(MEM_AREA_IO_SEC, GIC_BASE, CORE_MMU_DEVICE_SIZE);
67 
68 const struct thread_handlers *generic_boot_get_handlers(void)
69 {
70 	return &handlers;
71 }
72 
73 static void main_fiq(void)
74 {
75 	gic_it_handle(&gic_data);
76 }
77 
78 void console_init(void)
79 {
80 	imx_uart_init(&console_data, CONSOLE_UART_BASE);
81 	register_serial_console(&console_data.chip);
82 }
83 
84 void main_init_gic(void)
85 {
86 	vaddr_t gicc_base;
87 	vaddr_t gicd_base;
88 
89 	gicc_base = core_mmu_get_va(GIC_BASE + GICC_OFFSET, MEM_AREA_IO_SEC);
90 	gicd_base = core_mmu_get_va(GIC_BASE + GICD_OFFSET, MEM_AREA_IO_SEC);
91 
92 	if (!gicc_base || !gicd_base)
93 		panic();
94 
95 	/* Initialize GIC */
96 	gic_init(&gic_data, gicc_base, gicd_base);
97 	itr_init(&gic_data.chip);
98 }
99 
100 #if defined(CFG_MX6Q) || defined(CFG_MX6D) || defined(CFG_MX6DL)
101 void main_secondary_init_gic(void)
102 {
103 	gic_cpu_init(&gic_data);
104 }
105 #endif
106