1 /* 2 * Copyright (c) 2020, MediaTek Inc. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /* System Includes */ 8 #include <assert.h> 9 10 /* Project Includes */ 11 #include <common/bl_common.h> 12 #include <common/debug.h> 13 #include <common/desc_image_load.h> 14 #include <drivers/generic_delay_timer.h> 15 #include <drivers/ti/uart/uart_16550.h> 16 #include <lib/coreboot.h> 17 18 /* Platform Includes */ 19 #include <devapc/devapc.h> 20 #include <emi_mpu/emi_mpu.h> 21 #include <gpio/mtgpio.h> 22 #include <mt_gic_v3.h> 23 #include <mt_spm.h> 24 #include <mt_timer.h> 25 #include <mtk_dcm.h> 26 #include <plat_params.h> 27 #include <plat_private.h> 28 29 static entry_point_info_t bl32_ep_info; 30 static entry_point_info_t bl33_ep_info; 31 32 /******************************************************************************* 33 * Return a pointer to the 'entry_point_info' structure of the next image for 34 * the security state specified. BL33 corresponds to the non-secure image type 35 * while BL32 corresponds to the secure image type. A NULL pointer is returned 36 * if the image does not exist. 37 ******************************************************************************/ 38 entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 39 { 40 entry_point_info_t *next_image_info; 41 42 next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; 43 assert(next_image_info->h.type == PARAM_EP); 44 45 /* None of the images on this platform can have 0x0 as the entrypoint */ 46 if (next_image_info->pc) { 47 return next_image_info; 48 } else { 49 return NULL; 50 } 51 } 52 53 /******************************************************************************* 54 * Perform any BL31 early platform setup. Here is an opportunity to copy 55 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they 56 * are lost (potentially). This needs to be done before the MMU is initialized 57 * so that the memory layout can be used while creating page tables. 58 * BL2 has flushed this information to memory, so we are guaranteed to pick up 59 * good data. 60 ******************************************************************************/ 61 void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 62 u_register_t arg2, u_register_t arg3) 63 { 64 static console_t console; 65 66 params_early_setup(arg1); 67 68 #if COREBOOT 69 if (coreboot_serial.type) { 70 console_16550_register(coreboot_serial.baseaddr, 71 coreboot_serial.input_hertz, 72 coreboot_serial.baud, 73 &console); 74 } 75 #else 76 console_16550_register(UART0_BASE, UART_CLOCK, UART_BAUDRATE, &console); 77 #endif 78 79 NOTICE("MT8192 bl31_setup\n"); 80 81 bl31_params_parse_helper(arg0, &bl32_ep_info, &bl33_ep_info); 82 } 83 84 85 /******************************************************************************* 86 * Perform any BL31 platform setup code 87 ******************************************************************************/ 88 void bl31_platform_setup(void) 89 { 90 /* Set dcm on */ 91 if (!dcm_set_default()) { 92 ERROR("Failed to set default dcm on!!\n"); 93 } 94 95 /* MPU Init */ 96 emi_mpu_init(); 97 98 /* DAPC Init */ 99 devapc_init(); 100 101 /* Initialize the GIC driver, CPU and distributor interfaces */ 102 mt_gic_driver_init(); 103 mt_gic_init(); 104 105 mt_gpio_init(); 106 mt_systimer_init(); 107 generic_delay_timer_init(); 108 spm_boot_init(); 109 } 110 111 /******************************************************************************* 112 * Perform the very early platform specific architectural setup here. At the 113 * moment this is only intializes the mmu in a quick and dirty way. 114 ******************************************************************************/ 115 void bl31_plat_arch_setup(void) 116 { 117 plat_configure_mmu_el3(BL31_START, 118 BL31_END - BL31_START, 119 BL_CODE_BASE, 120 BL_CODE_END); 121 } 122