1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (C) 2017, Fuzhou Rockchip Electronics Co., Ltd. 4 * Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH 5 */ 6 7 #include <console.h> 8 #include <drivers/gic.h> 9 #include <drivers/serial8250_uart.h> 10 #include <io.h> 11 #include <kernel/generic_boot.h> 12 #include <kernel/panic.h> 13 #include <kernel/pm_stubs.h> 14 #include <mm/core_memprot.h> 15 #include <platform_config.h> 16 #include <stdint.h> 17 #include <tee/entry_std.h> 18 #include <tee/entry_fast.h> 19 20 static struct gic_data gic_data; 21 22 #if defined(CFG_EARLY_CONSOLE) 23 static struct serial8250_uart_data early_console_data; 24 register_phys_mem_pgdir(MEM_AREA_IO_NSEC, 25 CFG_EARLY_CONSOLE_BASE, CFG_EARLY_CONSOLE_SIZE); 26 #endif 27 28 register_phys_mem_pgdir(MEM_AREA_IO_SEC, GIC_BASE, GIC_SIZE); 29 30 static const struct thread_handlers handlers = { 31 #if defined(CFG_WITH_ARM_TRUSTED_FW) 32 .cpu_on = cpu_on_handler, 33 .cpu_off = pm_do_nothing, 34 .cpu_suspend = pm_do_nothing, 35 .cpu_resume = pm_do_nothing, 36 .system_off = pm_do_nothing, 37 .system_reset = pm_do_nothing, 38 #else 39 .cpu_on = pm_do_nothing, 40 .cpu_off = pm_do_nothing, 41 .cpu_suspend = pm_do_nothing, 42 .cpu_resume = pm_do_nothing, 43 .system_off = pm_do_nothing, 44 .system_reset = pm_do_nothing, 45 #endif 46 }; 47 48 void main_init_gic(void) 49 { 50 vaddr_t gicc_base = 0; 51 vaddr_t gicd_base = 0; 52 53 #if !defined(CFG_ARM_GICV3) 54 gicc_base = (vaddr_t)phys_to_virt(GICC_BASE, MEM_AREA_IO_SEC); 55 if (!gicc_base) 56 panic(); 57 #endif 58 59 gicd_base = (vaddr_t)phys_to_virt(GICD_BASE, MEM_AREA_IO_SEC); 60 if (!gicd_base) 61 panic(); 62 63 /* Initialize GIC */ 64 gic_init(&gic_data, gicc_base, gicd_base); 65 itr_init(&gic_data.chip); 66 } 67 68 void main_secondary_init_gic(void) 69 { 70 gic_cpu_init(&gic_data); 71 } 72 73 const struct thread_handlers *generic_boot_get_handlers(void) 74 { 75 return &handlers; 76 } 77 78 void console_init(void) 79 { 80 #if defined(CFG_EARLY_CONSOLE) 81 /* 82 * Console devices can vary a lot between devices and 83 * OP-TEE will switch to the DT-based real console later, 84 * based on DT-devices and the systems chosen node. 85 * So early console is only needed for early debugging. 86 */ 87 serial8250_uart_init(&early_console_data, 88 CFG_EARLY_CONSOLE_BASE, 89 CFG_EARLY_CONSOLE_CLK_IN_HZ, 90 CFG_EARLY_CONSOLE_BAUDRATE); 91 register_serial_console(&early_console_data.chip); 92 #endif 93 } 94