// SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2014-2016, STMicroelectronics International N.V. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include register_phys_mem_pgdir(MEM_AREA_IO_SEC, CPU_IOMEM_BASE, CPU_IOMEM_SIZE); register_phys_mem_pgdir(MEM_AREA_IO_SEC, RNG_BASE, RNG_SIZE); register_phys_mem_pgdir(MEM_AREA_IO_NSEC, UART_CONSOLE_BASE, STIH_ASC_REG_SIZE); #ifdef DRAM0_BASE register_ddr(DRAM0_BASE, DRAM0_SIZE); #endif #ifdef DRAM1_BASE register_ddr(DRAM1_BASE, DRAM1_SIZE); #endif static struct gic_data gic_data; static struct stih_asc_pd console_data; static void main_fiq(void); #if defined(PLATFORM_FLAVOR_b2260) #define stm_tee_entry_std tee_entry_std static bool ns_resources_ready(void) { return true; } #else /* some nonsecure resource might not be ready (uart) */ static int boot_is_completed; static bool ns_resources_ready(void) { return !!boot_is_completed; } static void stm_tee_entry_std(struct thread_smc_args *smc_args) { boot_is_completed = 1; tee_entry_std(smc_args); } #endif static const struct thread_handlers handlers = { .std_smc = stm_tee_entry_std, .fast_smc = tee_entry_fast, .nintr = main_fiq, .cpu_on = pm_panic, .cpu_off = pm_panic, .cpu_suspend = pm_panic, .cpu_resume = pm_panic, .system_off = pm_panic, .system_reset = pm_panic, }; const struct thread_handlers *generic_boot_get_handlers(void) { return &handlers; } void console_init(void) { stih_asc_init(&console_data, UART_CONSOLE_BASE); } void console_putc(int ch) { if (ns_resources_ready()) { struct serial_chip *cons = &console_data.chip; if (ch == '\n') cons->ops->putc(cons, '\r'); cons->ops->putc(cons, ch); } } void console_flush(void) { if (ns_resources_ready()) { struct serial_chip *cons = &console_data.chip; cons->ops->flush(cons); } } vaddr_t pl310_base(void) { static void *va; if (cpu_mmu_enabled()) { if (!va) va = phys_to_virt(PL310_BASE, MEM_AREA_IO_SEC); return (vaddr_t)va; } return PL310_BASE; } void arm_cl2_config(vaddr_t pl310) { /* pl310 off */ io_write32(pl310 + PL310_CTRL, 0); /* config PL310 */ io_write32(pl310 + PL310_TAG_RAM_CTRL, PL310_TAG_RAM_CTRL_INIT); io_write32(pl310 + PL310_DATA_RAM_CTRL, PL310_DATA_RAM_CTRL_INIT); io_write32(pl310 + PL310_AUX_CTRL, PL310_AUX_CTRL_INIT); io_write32(pl310 + PL310_PREFETCH_CTRL, PL310_PREFETCH_CTRL_INIT); io_write32(pl310 + PL310_POWER_CTRL, PL310_POWER_CTRL_INIT); /* invalidate all pl310 cache ways */ arm_cl2_invbyway(pl310); } void plat_cpu_reset_late(void) { int i; assert(!cpu_mmu_enabled()); /* Allow NSec to Imprecise abort */ write_scr(SCR_AW); if (get_core_pos()) return; io_write32(SCU_BASE + SCU_SAC, SCU_SAC_INIT); io_write32(SCU_BASE + SCU_NSAC, SCU_NSAC_INIT); io_write32(SCU_BASE + SCU_FILT_EA, CPU_PORT_FILT_END); io_write32(SCU_BASE + SCU_FILT_SA, CPU_PORT_FILT_START); io_write32(SCU_BASE + SCU_CTRL, SCU_CTRL_INIT); io_write32(pl310_base() + PL310_ADDR_FILT_END, CPU_PORT_FILT_END); io_write32(pl310_base() + PL310_ADDR_FILT_START, CPU_PORT_FILT_START | PL310_CTRL_ENABLE_BIT); /* TODO: gic_init scan fails, pre-init all SPIs are nonsecure */ for (i = 0; i < (31 * 4); i += 4) io_write32(GIC_DIST_BASE + GIC_DIST_ISR1 + i, 0xFFFFFFFF); } void main_init_gic(void) { vaddr_t gicc_base; vaddr_t gicd_base; gicc_base = (vaddr_t)phys_to_virt(GIC_CPU_BASE, MEM_AREA_IO_SEC); gicd_base = (vaddr_t)phys_to_virt(GIC_DIST_BASE, MEM_AREA_IO_SEC); if (!gicc_base || !gicd_base) panic(); gic_init(&gic_data, gicc_base, gicd_base); itr_init(&gic_data.chip); } void main_secondary_init_gic(void) { gic_cpu_init(&gic_data); } static void main_fiq(void) { gic_it_handle(&gic_data); }