1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2022, MediaTek Inc. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #include <assert.h> 8*91f16700Schasinglulu #include <arch.h> 9*91f16700Schasinglulu #include <common/bl_common.h> 10*91f16700Schasinglulu #include <common/debug.h> 11*91f16700Schasinglulu #include <drivers/delay_timer.h> 12*91f16700Schasinglulu #include <drivers/generic_delay_timer.h> 13*91f16700Schasinglulu #if XLAT_TABLES_LIB_V2 && PLAT_XLAT_TABLES_DYNAMIC 14*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_v2.h> 15*91f16700Schasinglulu #endif 16*91f16700Schasinglulu #include <plat/common/platform.h> 17*91f16700Schasinglulu 18*91f16700Schasinglulu #if COREBOOT 19*91f16700Schasinglulu #include <common/desc_image_load.h> 20*91f16700Schasinglulu 21*91f16700Schasinglulu #include <drivers/ti/uart/uart_16550.h> 22*91f16700Schasinglulu #include <lib/coreboot.h> 23*91f16700Schasinglulu #include <plat_params.h> 24*91f16700Schasinglulu #endif 25*91f16700Schasinglulu 26*91f16700Schasinglulu /* MTK headers */ 27*91f16700Schasinglulu #if MTK_SIP_KERNEL_BOOT_ENABLE 28*91f16700Schasinglulu #include <cold_boot.h> 29*91f16700Schasinglulu #endif 30*91f16700Schasinglulu #include <lib/mtk_init/mtk_init.h> 31*91f16700Schasinglulu #include <mtk_mmap_pool.h> 32*91f16700Schasinglulu 33*91f16700Schasinglulu IMPORT_SYM(uintptr_t, __RW_START__, RW_START); 34*91f16700Schasinglulu IMPORT_SYM(uintptr_t, __DATA_START__, DATA_START); 35*91f16700Schasinglulu 36*91f16700Schasinglulu #if COREBOOT 37*91f16700Schasinglulu static entry_point_info_t bl32_ep_info; 38*91f16700Schasinglulu static entry_point_info_t bl33_ep_info; 39*91f16700Schasinglulu 40*91f16700Schasinglulu /******************************************************************************* 41*91f16700Schasinglulu * Return a pointer to the 'entry_point_info' structure of the next image for 42*91f16700Schasinglulu * the security state specified. BL33 corresponds to the non-secure image type 43*91f16700Schasinglulu * while BL32 corresponds to the secure image type. A NULL pointer is returned 44*91f16700Schasinglulu * if the image does not exist. 45*91f16700Schasinglulu ******************************************************************************/ 46*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 47*91f16700Schasinglulu { 48*91f16700Schasinglulu entry_point_info_t *next_image_info; 49*91f16700Schasinglulu 50*91f16700Schasinglulu next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; 51*91f16700Schasinglulu assert(next_image_info->h.type == PARAM_EP); 52*91f16700Schasinglulu 53*91f16700Schasinglulu /* None of the images on this platform can have 0x0 as the entrypoint */ 54*91f16700Schasinglulu if (next_image_info->pc) { 55*91f16700Schasinglulu return next_image_info; 56*91f16700Schasinglulu } else { 57*91f16700Schasinglulu return NULL; 58*91f16700Schasinglulu } 59*91f16700Schasinglulu } 60*91f16700Schasinglulu #else 61*91f16700Schasinglulu #ifndef MTK_BL31_AS_BL2 62*91f16700Schasinglulu static struct mtk_bl31_fw_config bl31_fw_config; 63*91f16700Schasinglulu #else 64*91f16700Schasinglulu struct mtk_bl31_fw_config bl31_fw_config; 65*91f16700Schasinglulu #endif 66*91f16700Schasinglulu /* In order to be accessed after MMU enable */ 67*91f16700Schasinglulu static struct mtk_bl_param_t bl_param_clone; 68*91f16700Schasinglulu 69*91f16700Schasinglulu void *get_mtk_bl31_fw_config(int index) 70*91f16700Schasinglulu { 71*91f16700Schasinglulu void *arg = NULL; 72*91f16700Schasinglulu 73*91f16700Schasinglulu switch (index) { 74*91f16700Schasinglulu case BOOT_ARG_FROM_BL2: 75*91f16700Schasinglulu arg = bl31_fw_config.from_bl2; 76*91f16700Schasinglulu break; 77*91f16700Schasinglulu case BOOT_ARG_SOC_FW_CONFIG: 78*91f16700Schasinglulu arg = bl31_fw_config.soc_fw_config; 79*91f16700Schasinglulu break; 80*91f16700Schasinglulu case BOOT_ARG_HW_CONFIG: 81*91f16700Schasinglulu arg = bl31_fw_config.hw_config; 82*91f16700Schasinglulu break; 83*91f16700Schasinglulu case BOOT_ARG_RESERVED: 84*91f16700Schasinglulu arg = bl31_fw_config.reserved; 85*91f16700Schasinglulu break; 86*91f16700Schasinglulu default: 87*91f16700Schasinglulu WARN("Fail to get boot arg, index:%d", index); 88*91f16700Schasinglulu break; 89*91f16700Schasinglulu } 90*91f16700Schasinglulu return arg; 91*91f16700Schasinglulu } 92*91f16700Schasinglulu #endif 93*91f16700Schasinglulu /***************************************************************************** 94*91f16700Schasinglulu * Perform the very early platform specific architectural setup shared between 95*91f16700Schasinglulu * ARM standard platforms. This only does basic initialization. Later 96*91f16700Schasinglulu * architectural setup (bl31_arch_setup()) does not do anything platform 97*91f16700Schasinglulu * specific. 98*91f16700Schasinglulu ******************************************************************************/ 99*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t from_bl2, 100*91f16700Schasinglulu u_register_t soc_fw_config, 101*91f16700Schasinglulu u_register_t hw_config, u_register_t plat_params_from_bl2) 102*91f16700Schasinglulu 103*91f16700Schasinglulu { 104*91f16700Schasinglulu #if COREBOOT 105*91f16700Schasinglulu static console_t console; 106*91f16700Schasinglulu 107*91f16700Schasinglulu params_early_setup(soc_fw_config); 108*91f16700Schasinglulu if (coreboot_serial.type) { 109*91f16700Schasinglulu console_16550_register(coreboot_serial.baseaddr, 110*91f16700Schasinglulu coreboot_serial.input_hertz, 111*91f16700Schasinglulu coreboot_serial.baud, 112*91f16700Schasinglulu &console); 113*91f16700Schasinglulu } 114*91f16700Schasinglulu bl31_params_parse_helper(from_bl2, &bl32_ep_info, &bl33_ep_info); 115*91f16700Schasinglulu #else 116*91f16700Schasinglulu struct mtk_bl_param_t *p_mtk_bl_param = (struct mtk_bl_param_t *)from_bl2; 117*91f16700Schasinglulu 118*91f16700Schasinglulu if (p_mtk_bl_param == NULL) { 119*91f16700Schasinglulu ERROR("from_bl2 should not be NULL\n"); 120*91f16700Schasinglulu panic(); 121*91f16700Schasinglulu } 122*91f16700Schasinglulu memcpy(&bl_param_clone, p_mtk_bl_param, sizeof(struct mtk_bl_param_t)); 123*91f16700Schasinglulu bl31_fw_config.from_bl2 = (void *)&bl_param_clone; 124*91f16700Schasinglulu bl31_fw_config.soc_fw_config = (void *)soc_fw_config; 125*91f16700Schasinglulu bl31_fw_config.hw_config = (void *)hw_config; 126*91f16700Schasinglulu bl31_fw_config.reserved = (void *)plat_params_from_bl2; 127*91f16700Schasinglulu #endif 128*91f16700Schasinglulu 129*91f16700Schasinglulu INFO("MTK BL31 start\n"); 130*91f16700Schasinglulu /* Init delay function */ 131*91f16700Schasinglulu generic_delay_timer_init(); 132*91f16700Schasinglulu /* Initialize module initcall */ 133*91f16700Schasinglulu mtk_init_one_level(MTK_INIT_LVL_EARLY_PLAT); 134*91f16700Schasinglulu } 135*91f16700Schasinglulu 136*91f16700Schasinglulu void bl31_plat_arch_setup(void) 137*91f16700Schasinglulu { 138*91f16700Schasinglulu const mmap_region_t bl_regions[] = { 139*91f16700Schasinglulu MAP_BL_RO, 140*91f16700Schasinglulu MAP_BL_RW, 141*91f16700Schasinglulu #if USE_COHERENT_MEM 142*91f16700Schasinglulu MAP_BL_COHERENT_RAM, 143*91f16700Schasinglulu #endif 144*91f16700Schasinglulu {0}, 145*91f16700Schasinglulu }; 146*91f16700Schasinglulu 147*91f16700Schasinglulu mtk_xlat_init(bl_regions); 148*91f16700Schasinglulu /* Initialize module initcall */ 149*91f16700Schasinglulu mtk_init_one_level(MTK_INIT_LVL_ARCH); 150*91f16700Schasinglulu } 151*91f16700Schasinglulu 152*91f16700Schasinglulu /***************************************************************************** 153*91f16700Schasinglulu * Perform any BL31 platform setup common to ARM standard platforms 154*91f16700Schasinglulu ******************************************************************************/ 155*91f16700Schasinglulu 156*91f16700Schasinglulu void bl31_platform_setup(void) 157*91f16700Schasinglulu { 158*91f16700Schasinglulu mtk_init_one_level(MTK_INIT_LVL_PLAT_SETUP_0); 159*91f16700Schasinglulu mtk_init_one_level(MTK_INIT_LVL_PLAT_SETUP_1); 160*91f16700Schasinglulu } 161*91f16700Schasinglulu 162*91f16700Schasinglulu /******************************************************************************* 163*91f16700Schasinglulu * Operations before cold CPU leave BL31. 164*91f16700Schasinglulu * Switch console to runtime state. 165*91f16700Schasinglulu ******************************************************************************/ 166*91f16700Schasinglulu void bl31_plat_runtime_setup(void) 167*91f16700Schasinglulu { 168*91f16700Schasinglulu mtk_init_one_level(MTK_INIT_LVL_PLAT_RUNTIME); 169*91f16700Schasinglulu console_switch_state(CONSOLE_FLAG_RUNTIME); 170*91f16700Schasinglulu } 171*91f16700Schasinglulu 172*91f16700Schasinglulu unsigned int plat_get_syscnt_freq2(void) 173*91f16700Schasinglulu { 174*91f16700Schasinglulu return SYS_COUNTER_FREQ_IN_HZ; 175*91f16700Schasinglulu } 176