127132f13SRex-BC Chen /* 227132f13SRex-BC Chen * Copyright (c) 2021, MediaTek Inc. All rights reserved. 327132f13SRex-BC Chen * 427132f13SRex-BC Chen * SPDX-License-Identifier: BSD-3-Clause 527132f13SRex-BC Chen */ 627132f13SRex-BC Chen 727132f13SRex-BC Chen /* System Includes */ 827132f13SRex-BC Chen #include <assert.h> 927132f13SRex-BC Chen 1027132f13SRex-BC Chen /* Project Includes */ 1127132f13SRex-BC Chen #include <common/bl_common.h> 1227132f13SRex-BC Chen #include <common/debug.h> 1327132f13SRex-BC Chen #include <common/desc_image_load.h> 14*d73e15e6SRex-BC Chen #include <drivers/generic_delay_timer.h> 1527132f13SRex-BC Chen #include <drivers/ti/uart/uart_16550.h> 1627132f13SRex-BC Chen #include <lib/coreboot.h> 1727132f13SRex-BC Chen 1827132f13SRex-BC Chen /* Platform Includes */ 191b17e34cSPenny Jan #include <emi_mpu.h> 20a6a0af57SRex-BC Chen #include <mt_timer.h> 2127132f13SRex-BC Chen #include <plat_params.h> 2227132f13SRex-BC Chen #include <plat_private.h> 2327132f13SRex-BC Chen 2427132f13SRex-BC Chen static entry_point_info_t bl32_ep_info; 2527132f13SRex-BC Chen static entry_point_info_t bl33_ep_info; 2627132f13SRex-BC Chen 2727132f13SRex-BC Chen /******************************************************************************* 2827132f13SRex-BC Chen * Return a pointer to the 'entry_point_info' structure of the next image for 2927132f13SRex-BC Chen * the security state specified. BL33 corresponds to the non-secure image type 3027132f13SRex-BC Chen * while BL32 corresponds to the secure image type. A NULL pointer is returned 3127132f13SRex-BC Chen * if the image does not exist. 3227132f13SRex-BC Chen ******************************************************************************/ 3327132f13SRex-BC Chen entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 3427132f13SRex-BC Chen { 3527132f13SRex-BC Chen entry_point_info_t *next_image_info; 3627132f13SRex-BC Chen 3727132f13SRex-BC Chen next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; 3827132f13SRex-BC Chen assert(next_image_info->h.type == PARAM_EP); 3927132f13SRex-BC Chen 4027132f13SRex-BC Chen /* None of the images on this platform can have 0x0 as the entrypoint */ 4127132f13SRex-BC Chen if (next_image_info->pc) { 4227132f13SRex-BC Chen return next_image_info; 4327132f13SRex-BC Chen } else { 4427132f13SRex-BC Chen return NULL; 4527132f13SRex-BC Chen } 4627132f13SRex-BC Chen } 4727132f13SRex-BC Chen 4827132f13SRex-BC Chen /******************************************************************************* 4927132f13SRex-BC Chen * Perform any BL31 early platform setup. Here is an opportunity to copy 5027132f13SRex-BC Chen * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they 5127132f13SRex-BC Chen * are lost (potentially). This needs to be done before the MMU is initialized 5227132f13SRex-BC Chen * so that the memory layout can be used while creating page tables. 5327132f13SRex-BC Chen * BL2 has flushed this information to memory, so we are guaranteed to pick up 5427132f13SRex-BC Chen * good data. 5527132f13SRex-BC Chen ******************************************************************************/ 5627132f13SRex-BC Chen void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 5727132f13SRex-BC Chen u_register_t arg2, u_register_t arg3) 5827132f13SRex-BC Chen { 5927132f13SRex-BC Chen static console_t console; 6027132f13SRex-BC Chen 6127132f13SRex-BC Chen params_early_setup(arg1); 6227132f13SRex-BC Chen 6327132f13SRex-BC Chen #if COREBOOT 6427132f13SRex-BC Chen if (coreboot_serial.type) { 6527132f13SRex-BC Chen console_16550_register(coreboot_serial.baseaddr, 6627132f13SRex-BC Chen coreboot_serial.input_hertz, 6727132f13SRex-BC Chen coreboot_serial.baud, 6827132f13SRex-BC Chen &console); 6927132f13SRex-BC Chen } 7027132f13SRex-BC Chen #else 7127132f13SRex-BC Chen console_16550_register(UART0_BASE, UART_CLOCK, UART_BAUDRATE, &console); 7227132f13SRex-BC Chen #endif 7327132f13SRex-BC Chen 7427132f13SRex-BC Chen INFO("MT8186 bl31_setup\n"); 7527132f13SRex-BC Chen 7627132f13SRex-BC Chen bl31_params_parse_helper(arg0, &bl32_ep_info, &bl33_ep_info); 7727132f13SRex-BC Chen } 7827132f13SRex-BC Chen 7927132f13SRex-BC Chen 8027132f13SRex-BC Chen /******************************************************************************* 8127132f13SRex-BC Chen * Perform any BL31 platform setup code 8227132f13SRex-BC Chen ******************************************************************************/ 8327132f13SRex-BC Chen void bl31_platform_setup(void) 8427132f13SRex-BC Chen { 85a6a0af57SRex-BC Chen mt_systimer_init(); 86*d73e15e6SRex-BC Chen generic_delay_timer_init(); 87*d73e15e6SRex-BC Chen 881b17e34cSPenny Jan emi_mpu_init(); 8927132f13SRex-BC Chen } 9027132f13SRex-BC Chen 9127132f13SRex-BC Chen /******************************************************************************* 9227132f13SRex-BC Chen * Perform the very early platform specific architectural setup here. At the 9327132f13SRex-BC Chen * moment this is only intializes the mmu in a quick and dirty way. 9427132f13SRex-BC Chen ******************************************************************************/ 9527132f13SRex-BC Chen void bl31_plat_arch_setup(void) 9627132f13SRex-BC Chen { 9727132f13SRex-BC Chen plat_configure_mmu_el3(BL31_START, 9827132f13SRex-BC Chen BL31_END - BL31_START, 9927132f13SRex-BC Chen BL_CODE_BASE, 10027132f13SRex-BC Chen BL_CODE_END); 10127132f13SRex-BC Chen } 102