1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2023, ARM Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #include <assert.h> 8*91f16700Schasinglulu 9*91f16700Schasinglulu #include <platform_def.h> 10*91f16700Schasinglulu #include <sigi_def.h> 11*91f16700Schasinglulu 12*91f16700Schasinglulu #include <common/bl_common.h> 13*91f16700Schasinglulu #include <common/debug.h> 14*91f16700Schasinglulu #include <common/desc_image_load.h> 15*91f16700Schasinglulu #include <drivers/console.h> 16*91f16700Schasinglulu #include <drivers/generic_delay_timer.h> 17*91f16700Schasinglulu #include <drivers/ti/uart/uart_16550.h> 18*91f16700Schasinglulu #include <lib/mmio.h> 19*91f16700Schasinglulu #include <plat/common/platform.h> 20*91f16700Schasinglulu #include <plat/arm/common/plat_arm.h> 21*91f16700Schasinglulu 22*91f16700Schasinglulu static entry_point_info_t bl32_image_ep_info; 23*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info; 24*91f16700Schasinglulu 25*91f16700Schasinglulu /* 26*91f16700Schasinglulu * Table of regions to map using the MMU. 27*91f16700Schasinglulu * This doesn't include TZRAM as the 'mem_layout' argument passed to 28*91f16700Schasinglulu * configure_mmu_elx() will give the available subset of that, 29*91f16700Schasinglulu */ 30*91f16700Schasinglulu const mmap_region_t plat_sigi_mmap[] = { 31*91f16700Schasinglulu MAP_REGION_FLAT(DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE), 32*91f16700Schasinglulu MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE), 33*91f16700Schasinglulu { 0 } 34*91f16700Schasinglulu }; 35*91f16700Schasinglulu 36*91f16700Schasinglulu const mmap_region_t *plat_sigi_get_mmap(void) 37*91f16700Schasinglulu { 38*91f16700Schasinglulu return plat_sigi_mmap; 39*91f16700Schasinglulu } 40*91f16700Schasinglulu 41*91f16700Schasinglulu unsigned int plat_get_syscnt_freq2(void) 42*91f16700Schasinglulu { 43*91f16700Schasinglulu return SIGI_OSC24M_CLK_IN_HZ; 44*91f16700Schasinglulu } 45*91f16700Schasinglulu 46*91f16700Schasinglulu /******************************************************************************* 47*91f16700Schasinglulu * Return a pointer to the 'entry_point_info' structure of the next image for 48*91f16700Schasinglulu * the security state specified. BL33 corresponds to the non-secure image type 49*91f16700Schasinglulu * while BL32 corresponds to the secure image type. A NULL pointer is returned 50*91f16700Schasinglulu * if the image does not exist. 51*91f16700Schasinglulu ******************************************************************************/ 52*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 53*91f16700Schasinglulu { 54*91f16700Schasinglulu entry_point_info_t *next_image_info; 55*91f16700Schasinglulu 56*91f16700Schasinglulu //assert(sec_state_is_valid(type)); 57*91f16700Schasinglulu next_image_info = (type == NON_SECURE) ? \ 58*91f16700Schasinglulu &bl33_image_ep_info : &bl32_image_ep_info; 59*91f16700Schasinglulu 60*91f16700Schasinglulu /* None of the images on this platform can have 0x0 as the entrypoint */ 61*91f16700Schasinglulu if (next_image_info->pc) 62*91f16700Schasinglulu return next_image_info; 63*91f16700Schasinglulu else 64*91f16700Schasinglulu return NULL; 65*91f16700Schasinglulu } 66*91f16700Schasinglulu 67*91f16700Schasinglulu /* 68*91f16700Schasinglulu * Set the build time defaults,if we can't find any config data. 69*91f16700Schasinglulu */ 70*91f16700Schasinglulu static inline void bl31_set_default_config(void) 71*91f16700Schasinglulu { 72*91f16700Schasinglulu bl32_image_ep_info.pc = (uintptr_t)BL32_BASE; 73*91f16700Schasinglulu bl32_image_ep_info.spsr = (uint32_t)arm_get_spsr_for_bl32_entry(); 74*91f16700Schasinglulu bl33_image_ep_info.pc = (uintptr_t)plat_get_ns_image_entrypoint(); 75*91f16700Schasinglulu bl33_image_ep_info.spsr = (uint32_t)SPSR_64(MODE_EL2, MODE_SP_ELX, 76*91f16700Schasinglulu DISABLE_ALL_EXCEPTIONS); 77*91f16700Schasinglulu } 78*91f16700Schasinglulu 79*91f16700Schasinglulu static void sigi_print_platform_name(void) 80*91f16700Schasinglulu { 81*91f16700Schasinglulu NOTICE("ATF running on %s\n", PLATFORM_NAME); 82*91f16700Schasinglulu } 83*91f16700Schasinglulu 84*91f16700Schasinglulu void sigi_config_setup(void) 85*91f16700Schasinglulu { 86*91f16700Schasinglulu sigi_print_platform_name(); 87*91f16700Schasinglulu 88*91f16700Schasinglulu generic_delay_timer_init(); 89*91f16700Schasinglulu } 90*91f16700Schasinglulu 91*91f16700Schasinglulu /******************************************************************************* 92*91f16700Schasinglulu * Perform any BL3-1 early platform setup. Here is an opportunity to copy 93*91f16700Schasinglulu * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before they 94*91f16700Schasinglulu * are lost (potentially). This needs to be done before the MMU is initialized 95*91f16700Schasinglulu * so that the memory layout can be used while creating page tables. 96*91f16700Schasinglulu * BL2 has flushed this information to memory, so we are guaranteed to pick up 97*91f16700Schasinglulu * good data. 98*91f16700Schasinglulu ******************************************************************************/ 99*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 100*91f16700Schasinglulu u_register_t arg2, u_register_t arg3) 101*91f16700Schasinglulu { 102*91f16700Schasinglulu sigi_console_init(); 103*91f16700Schasinglulu 104*91f16700Schasinglulu /* Initialize the platform config for future decision making */ 105*91f16700Schasinglulu sigi_config_setup(); 106*91f16700Schasinglulu /* There are no parameters from BL2 if BL31 is a reset vector */ 107*91f16700Schasinglulu assert(arg0 == 0U); 108*91f16700Schasinglulu assert(arg1 == 0U); 109*91f16700Schasinglulu 110*91f16700Schasinglulu /* 111*91f16700Schasinglulu * Do initial security configuration to allow DRAM/device access. On 112*91f16700Schasinglulu * Base Sigi only DRAM security is programmable (via TrustZone), but 113*91f16700Schasinglulu * other platforms might have more programmable security devices 114*91f16700Schasinglulu * present. 115*91f16700Schasinglulu */ 116*91f16700Schasinglulu 117*91f16700Schasinglulu /* Populate common information for BL32 and BL33 */ 118*91f16700Schasinglulu SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0); 119*91f16700Schasinglulu SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE); 120*91f16700Schasinglulu SET_PARAM_HEAD(&bl33_image_ep_info, PARAM_EP, VERSION_1, 0); 121*91f16700Schasinglulu SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); 122*91f16700Schasinglulu 123*91f16700Schasinglulu bl31_set_default_config(); 124*91f16700Schasinglulu 125*91f16700Schasinglulu VERBOSE("BL31: early platform setup\n"); 126*91f16700Schasinglulu NOTICE("BL31: Secure code at 0x%08lx\n", bl32_image_ep_info.pc); 127*91f16700Schasinglulu NOTICE("BL31: Non secure code at 0x%08lx\n", bl33_image_ep_info.pc); 128*91f16700Schasinglulu } 129*91f16700Schasinglulu 130*91f16700Schasinglulu /******************************************************************************* 131*91f16700Schasinglulu * Perform any BL3-1 platform setup code 132*91f16700Schasinglulu ******************************************************************************/ 133*91f16700Schasinglulu void bl31_platform_setup(void) 134*91f16700Schasinglulu { 135*91f16700Schasinglulu /* Initialize the gic cpu and distributor interfaces */ 136*91f16700Schasinglulu plat_sigi_gic_init(); 137*91f16700Schasinglulu } 138*91f16700Schasinglulu 139*91f16700Schasinglulu /******************************************************************************* 140*91f16700Schasinglulu * Perform the very early platform specific architectural setup here. At the 141*91f16700Schasinglulu * moment this is only intializes the mmu in a quick and dirty way. 142*91f16700Schasinglulu ******************************************************************************/ 143*91f16700Schasinglulu void bl31_plat_arch_setup(void) 144*91f16700Schasinglulu { 145*91f16700Schasinglulu const mmap_region_t bl_regions[] = { 146*91f16700Schasinglulu MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE, 147*91f16700Schasinglulu MT_MEMORY | MT_RW | MT_SECURE), 148*91f16700Schasinglulu MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE, 149*91f16700Schasinglulu MT_CODE | MT_SECURE), 150*91f16700Schasinglulu MAP_REGION_FLAT(BL_RO_DATA_BASE, BL_RO_DATA_END - BL_RO_DATA_BASE, MT_RO_DATA| MT_SECURE), 151*91f16700Schasinglulu MAP_REGION_FLAT(SHARED_RAM_BASE, SHARED_RAM_SIZE, MT_MEMORY | MT_RW | MT_SECURE), 152*91f16700Schasinglulu {0} 153*91f16700Schasinglulu }; 154*91f16700Schasinglulu setup_page_tables(bl_regions, plat_sigi_get_mmap()); 155*91f16700Schasinglulu enable_mmu_el3(0); 156*91f16700Schasinglulu } 157