1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (C) 2015 Freescale Semiconductor, Inc. 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 #ifdef CONSOLE_UART_BASE 66 register_phys_mem(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE, CORE_MMU_DEVICE_SIZE); 67 #endif 68 #ifdef GIC_BASE 69 register_phys_mem(MEM_AREA_IO_SEC, GIC_BASE, CORE_MMU_DEVICE_SIZE); 70 #endif 71 #ifdef ANATOP_BASE 72 register_phys_mem(MEM_AREA_IO_SEC, ANATOP_BASE, CORE_MMU_DEVICE_SIZE); 73 #endif 74 #ifdef GICD_BASE 75 register_phys_mem(MEM_AREA_IO_SEC, GICD_BASE, 0x10000); 76 #endif 77 #ifdef AIPS1_BASE 78 register_phys_mem(MEM_AREA_IO_SEC, AIPS1_BASE, 79 ROUNDUP(AIPS1_SIZE, CORE_MMU_DEVICE_SIZE)); 80 #endif 81 #ifdef AIPS2_BASE 82 register_phys_mem(MEM_AREA_IO_SEC, AIPS2_BASE, 83 ROUNDUP(AIPS2_SIZE, CORE_MMU_DEVICE_SIZE)); 84 #endif 85 #ifdef AIPS3_BASE 86 register_phys_mem(MEM_AREA_IO_SEC, AIPS3_BASE, 87 ROUNDUP(AIPS3_SIZE, CORE_MMU_DEVICE_SIZE)); 88 #endif 89 #ifdef IRAM_BASE 90 register_phys_mem(MEM_AREA_TEE_COHERENT, 91 ROUNDDOWN(IRAM_BASE, CORE_MMU_DEVICE_SIZE), 92 CORE_MMU_DEVICE_SIZE); 93 #endif 94 #ifdef IRAM_S_BASE 95 register_phys_mem(MEM_AREA_TEE_COHERENT, 96 ROUNDDOWN(IRAM_S_BASE, CORE_MMU_DEVICE_SIZE), 97 CORE_MMU_DEVICE_SIZE); 98 #endif 99 100 #if defined(CFG_PL310) 101 register_phys_mem(MEM_AREA_IO_SEC, 102 ROUNDDOWN(PL310_BASE, CORE_MMU_DEVICE_SIZE), 103 CORE_MMU_DEVICE_SIZE); 104 #endif 105 106 const struct thread_handlers *generic_boot_get_handlers(void) 107 { 108 return &handlers; 109 } 110 111 static void main_fiq(void) 112 { 113 gic_it_handle(&gic_data); 114 } 115 116 void console_init(void) 117 { 118 imx_uart_init(&console_data, CONSOLE_UART_BASE); 119 register_serial_console(&console_data.chip); 120 } 121 122 void main_init_gic(void) 123 { 124 vaddr_t gicc_base; 125 vaddr_t gicd_base; 126 127 gicc_base = core_mmu_get_va(GIC_BASE + GICC_OFFSET, MEM_AREA_IO_SEC); 128 gicd_base = core_mmu_get_va(GIC_BASE + GICD_OFFSET, MEM_AREA_IO_SEC); 129 130 if (!gicc_base || !gicd_base) 131 panic(); 132 133 /* Initialize GIC */ 134 gic_init(&gic_data, gicc_base, gicd_base); 135 itr_init(&gic_data.chip); 136 } 137 138 #if defined(CFG_MX6Q) || defined(CFG_MX6D) || defined(CFG_MX6DL) || \ 139 defined(CFG_MX7) 140 void main_secondary_init_gic(void) 141 { 142 gic_cpu_init(&gic_data); 143 } 144 #endif 145