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 * Copyright 2019 NXP 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright notice, 15 * this list of conditions and the following disclaimer in the documentation 16 * and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include <arm.h> 32 #include <console.h> 33 #include <drivers/gic.h> 34 #include <drivers/imx_uart.h> 35 #include <imx.h> 36 #include <io.h> 37 #include <kernel/boot.h> 38 #include <kernel/interrupt.h> 39 #include <mm/core_memprot.h> 40 #include <mm/core_mmu.h> 41 #include <platform_config.h> 42 #include <stdint.h> 43 44 static struct gic_data gic_data __nex_bss; 45 46 static struct imx_uart_data console_data __nex_bss; 47 48 #ifdef CONSOLE_UART_BASE 49 register_phys_mem_pgdir(MEM_AREA_IO_NSEC, CONSOLE_UART_BASE, 50 CORE_MMU_PGDIR_SIZE); 51 #endif 52 #ifdef GIC_BASE 53 register_phys_mem_pgdir(MEM_AREA_IO_SEC, GIC_BASE, CORE_MMU_PGDIR_SIZE); 54 #endif 55 #ifdef ANATOP_BASE 56 register_phys_mem_pgdir(MEM_AREA_IO_SEC, ANATOP_BASE, CORE_MMU_PGDIR_SIZE); 57 #endif 58 #ifdef GICD_BASE 59 register_phys_mem_pgdir(MEM_AREA_IO_SEC, GICD_BASE, 0x10000); 60 #endif 61 #ifdef AIPS0_BASE 62 register_phys_mem_pgdir(MEM_AREA_IO_SEC, AIPS0_BASE, 63 ROUNDUP(AIPS0_SIZE, CORE_MMU_PGDIR_SIZE)); 64 #endif 65 #ifdef AIPS1_BASE 66 register_phys_mem_pgdir(MEM_AREA_IO_SEC, AIPS1_BASE, 67 ROUNDUP(AIPS1_SIZE, CORE_MMU_PGDIR_SIZE)); 68 #endif 69 #ifdef AIPS2_BASE 70 register_phys_mem_pgdir(MEM_AREA_IO_SEC, AIPS2_BASE, 71 ROUNDUP(AIPS2_SIZE, CORE_MMU_PGDIR_SIZE)); 72 #endif 73 #ifdef AIPS3_BASE 74 register_phys_mem_pgdir(MEM_AREA_IO_SEC, AIPS3_BASE, 75 ROUNDUP(AIPS3_SIZE, CORE_MMU_PGDIR_SIZE)); 76 #endif 77 #ifdef IRAM_BASE 78 register_phys_mem(MEM_AREA_TEE_COHERENT, 79 ROUNDDOWN(IRAM_BASE, CORE_MMU_PGDIR_SIZE), 80 CORE_MMU_PGDIR_SIZE); 81 #endif 82 #ifdef M4_AIPS_BASE 83 register_phys_mem(MEM_AREA_IO_SEC, M4_AIPS_BASE, M4_AIPS_SIZE); 84 #endif 85 #ifdef IRAM_S_BASE 86 register_phys_mem(MEM_AREA_TEE_COHERENT, 87 ROUNDDOWN(IRAM_S_BASE, CORE_MMU_PGDIR_SIZE), 88 CORE_MMU_PGDIR_SIZE); 89 #endif 90 91 #if defined(CFG_PL310) 92 register_phys_mem_pgdir(MEM_AREA_IO_SEC, 93 ROUNDDOWN(PL310_BASE, CORE_MMU_PGDIR_SIZE), 94 CORE_MMU_PGDIR_SIZE); 95 #endif 96 97 register_dynamic_shm(CFG_NSEC_DDR_0_BASE, CFG_NSEC_DDR_0_SIZE); 98 #if defined(CFG_NSEC_DDR_1_BASE) && defined(CFG_NSEC_DDR_1_SIZE) 99 register_dynamic_shm(CFG_NSEC_DDR_1_BASE, CFG_NSEC_DDR_1_SIZE); 100 #endif 101 102 void itr_core_handler(void) 103 { 104 gic_it_handle(&gic_data); 105 } 106 107 void console_init(void) 108 { 109 #ifdef CONSOLE_UART_BASE 110 imx_uart_init(&console_data, CONSOLE_UART_BASE); 111 register_serial_console(&console_data.chip); 112 #endif 113 } 114 115 void main_init_gic(void) 116 { 117 #ifdef GICD_BASE 118 gic_init(&gic_data, 0, GICD_BASE); 119 #else 120 gic_init(&gic_data, GIC_BASE + GICC_OFFSET, GIC_BASE + GICD_OFFSET); 121 #endif 122 itr_init(&gic_data.chip); 123 } 124 125 #if CFG_TEE_CORE_NB_CORE > 1 126 void main_secondary_init_gic(void) 127 { 128 gic_cpu_init(&gic_data); 129 } 130 #endif 131