1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (C) 2018 Marvell International Ltd. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu * https://spdx.org/licenses 6*91f16700Schasinglulu */ 7*91f16700Schasinglulu 8*91f16700Schasinglulu #include <assert.h> 9*91f16700Schasinglulu 10*91f16700Schasinglulu #include <arch.h> 11*91f16700Schasinglulu #include <common/bl_common.h> 12*91f16700Schasinglulu #include <common/debug.h> 13*91f16700Schasinglulu #ifdef USE_CCI 14*91f16700Schasinglulu #include <drivers/arm/cci.h> 15*91f16700Schasinglulu #endif 16*91f16700Schasinglulu #include <drivers/console.h> 17*91f16700Schasinglulu #include <plat/common/platform.h> 18*91f16700Schasinglulu 19*91f16700Schasinglulu #include <marvell_def.h> 20*91f16700Schasinglulu #include <marvell_plat_priv.h> 21*91f16700Schasinglulu #include <plat_marvell.h> 22*91f16700Schasinglulu 23*91f16700Schasinglulu /* 24*91f16700Schasinglulu * Placeholder variables for copying the arguments that have been passed to 25*91f16700Schasinglulu * BL31 from BL2. 26*91f16700Schasinglulu */ 27*91f16700Schasinglulu static entry_point_info_t bl32_image_ep_info; 28*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info; 29*91f16700Schasinglulu 30*91f16700Schasinglulu /* Weak definitions may be overridden in specific ARM standard platform */ 31*91f16700Schasinglulu #pragma weak bl31_early_platform_setup2 32*91f16700Schasinglulu #pragma weak bl31_platform_setup 33*91f16700Schasinglulu #pragma weak bl31_plat_arch_setup 34*91f16700Schasinglulu #pragma weak bl31_plat_get_next_image_ep_info 35*91f16700Schasinglulu #pragma weak plat_get_syscnt_freq2 36*91f16700Schasinglulu 37*91f16700Schasinglulu /***************************************************************************** 38*91f16700Schasinglulu * Return a pointer to the 'entry_point_info' structure of the next image for 39*91f16700Schasinglulu * the security state specified. BL33 corresponds to the non-secure image type 40*91f16700Schasinglulu * while BL32 corresponds to the secure image type. A NULL pointer is returned 41*91f16700Schasinglulu * if the image does not exist. 42*91f16700Schasinglulu ***************************************************************************** 43*91f16700Schasinglulu */ 44*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 45*91f16700Schasinglulu { 46*91f16700Schasinglulu entry_point_info_t *next_image_info; 47*91f16700Schasinglulu 48*91f16700Schasinglulu assert(sec_state_is_valid(type)); 49*91f16700Schasinglulu next_image_info = (type == NON_SECURE) 50*91f16700Schasinglulu ? &bl33_image_ep_info : &bl32_image_ep_info; 51*91f16700Schasinglulu 52*91f16700Schasinglulu return next_image_info; 53*91f16700Schasinglulu } 54*91f16700Schasinglulu 55*91f16700Schasinglulu /***************************************************************************** 56*91f16700Schasinglulu * Perform any BL31 early platform setup common to ARM standard platforms. 57*91f16700Schasinglulu * Here is an opportunity to copy parameters passed by the calling EL (S-EL1 58*91f16700Schasinglulu * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be 59*91f16700Schasinglulu * done before the MMU is initialized so that the memory layout can be used 60*91f16700Schasinglulu * while creating page tables. BL2 has flushed this information to memory, so 61*91f16700Schasinglulu * we are guaranteed to pick up good data. 62*91f16700Schasinglulu ***************************************************************************** 63*91f16700Schasinglulu */ 64*91f16700Schasinglulu void marvell_bl31_early_platform_setup(void *from_bl2, 65*91f16700Schasinglulu uintptr_t soc_fw_config, 66*91f16700Schasinglulu uintptr_t hw_config, 67*91f16700Schasinglulu void *plat_params_from_bl2) 68*91f16700Schasinglulu { 69*91f16700Schasinglulu /* Initialize the console to provide early debug support */ 70*91f16700Schasinglulu marvell_console_boot_init(); 71*91f16700Schasinglulu 72*91f16700Schasinglulu #if RESET_TO_BL31 73*91f16700Schasinglulu /* There are no parameters from BL2 if BL31 is a reset vector */ 74*91f16700Schasinglulu assert(from_bl2 == NULL); 75*91f16700Schasinglulu assert(plat_params_from_bl2 == NULL); 76*91f16700Schasinglulu 77*91f16700Schasinglulu #ifdef BL32_BASE 78*91f16700Schasinglulu /* Populate entry point information for BL32 */ 79*91f16700Schasinglulu SET_PARAM_HEAD(&bl32_image_ep_info, 80*91f16700Schasinglulu PARAM_EP, 81*91f16700Schasinglulu VERSION_1, 82*91f16700Schasinglulu 0); 83*91f16700Schasinglulu SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE); 84*91f16700Schasinglulu bl32_image_ep_info.pc = BL32_BASE; 85*91f16700Schasinglulu bl32_image_ep_info.spsr = marvell_get_spsr_for_bl32_entry(); 86*91f16700Schasinglulu #endif /* BL32_BASE */ 87*91f16700Schasinglulu 88*91f16700Schasinglulu /* Populate entry point information for BL33 */ 89*91f16700Schasinglulu SET_PARAM_HEAD(&bl33_image_ep_info, 90*91f16700Schasinglulu PARAM_EP, 91*91f16700Schasinglulu VERSION_1, 92*91f16700Schasinglulu 0); 93*91f16700Schasinglulu /* 94*91f16700Schasinglulu * Tell BL31 where the non-trusted software image 95*91f16700Schasinglulu * is located and the entry state information 96*91f16700Schasinglulu */ 97*91f16700Schasinglulu bl33_image_ep_info.pc = plat_get_ns_image_entrypoint(); 98*91f16700Schasinglulu bl33_image_ep_info.spsr = marvell_get_spsr_for_bl33_entry(); 99*91f16700Schasinglulu SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); 100*91f16700Schasinglulu 101*91f16700Schasinglulu #else 102*91f16700Schasinglulu /* 103*91f16700Schasinglulu * In debug builds, we pass a special value in 'plat_params_from_bl2' 104*91f16700Schasinglulu * to verify platform parameters from BL2 to BL31. 105*91f16700Schasinglulu * In release builds, it's not used. 106*91f16700Schasinglulu */ 107*91f16700Schasinglulu assert(((unsigned long long)plat_params_from_bl2) == 108*91f16700Schasinglulu MARVELL_BL31_PLAT_PARAM_VAL); 109*91f16700Schasinglulu 110*91f16700Schasinglulu /* 111*91f16700Schasinglulu * Check params passed from BL2 should not be NULL, 112*91f16700Schasinglulu */ 113*91f16700Schasinglulu bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2; 114*91f16700Schasinglulu assert(params_from_bl2 != NULL); 115*91f16700Schasinglulu assert(params_from_bl2->h.type == PARAM_BL_PARAMS); 116*91f16700Schasinglulu assert(params_from_bl2->h.version >= VERSION_2); 117*91f16700Schasinglulu 118*91f16700Schasinglulu bl_params_node_t *bl_params = params_from_bl2->head; 119*91f16700Schasinglulu 120*91f16700Schasinglulu /* 121*91f16700Schasinglulu * Copy BL33 and BL32 (if present), entry point information. 122*91f16700Schasinglulu * They are stored in Secure RAM, in BL2's address space. 123*91f16700Schasinglulu */ 124*91f16700Schasinglulu while (bl_params != NULL) { 125*91f16700Schasinglulu if (bl_params->image_id == BL32_IMAGE_ID) 126*91f16700Schasinglulu bl32_image_ep_info = *bl_params->ep_info; 127*91f16700Schasinglulu 128*91f16700Schasinglulu if (bl_params->image_id == BL33_IMAGE_ID) 129*91f16700Schasinglulu bl33_image_ep_info = *bl_params->ep_info; 130*91f16700Schasinglulu 131*91f16700Schasinglulu bl_params = bl_params->next_params_info; 132*91f16700Schasinglulu } 133*91f16700Schasinglulu #endif 134*91f16700Schasinglulu } 135*91f16700Schasinglulu 136*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 137*91f16700Schasinglulu u_register_t arg2, u_register_t arg3) 138*91f16700Schasinglulu 139*91f16700Schasinglulu { 140*91f16700Schasinglulu marvell_bl31_early_platform_setup((void *)arg0, arg1, arg2, 141*91f16700Schasinglulu (void *)arg3); 142*91f16700Schasinglulu 143*91f16700Schasinglulu #ifdef USE_CCI 144*91f16700Schasinglulu /* 145*91f16700Schasinglulu * Initialize CCI for this cluster during cold boot. 146*91f16700Schasinglulu * No need for locks as no other CPU is active. 147*91f16700Schasinglulu */ 148*91f16700Schasinglulu plat_marvell_interconnect_init(); 149*91f16700Schasinglulu 150*91f16700Schasinglulu /* 151*91f16700Schasinglulu * Enable CCI coherency for the primary CPU's cluster. 152*91f16700Schasinglulu * Platform specific PSCI code will enable coherency for other 153*91f16700Schasinglulu * clusters. 154*91f16700Schasinglulu */ 155*91f16700Schasinglulu plat_marvell_interconnect_enter_coherency(); 156*91f16700Schasinglulu #endif 157*91f16700Schasinglulu } 158*91f16700Schasinglulu 159*91f16700Schasinglulu /***************************************************************************** 160*91f16700Schasinglulu * Perform any BL31 platform setup common to ARM standard platforms 161*91f16700Schasinglulu ***************************************************************************** 162*91f16700Schasinglulu */ 163*91f16700Schasinglulu void marvell_bl31_platform_setup(void) 164*91f16700Schasinglulu { 165*91f16700Schasinglulu /* Initialize the GIC driver, cpu and distributor interfaces */ 166*91f16700Schasinglulu plat_marvell_gic_driver_init(); 167*91f16700Schasinglulu plat_marvell_gic_init(); 168*91f16700Schasinglulu 169*91f16700Schasinglulu /* For Armada-8k-plus family, the SoC includes more than 170*91f16700Schasinglulu * a single AP die, but the default die that boots is AP #0. 171*91f16700Schasinglulu * For other families there is only one die (#0). 172*91f16700Schasinglulu * Initialize psci arch from die 0 173*91f16700Schasinglulu */ 174*91f16700Schasinglulu marvell_psci_arch_init(0); 175*91f16700Schasinglulu } 176*91f16700Schasinglulu 177*91f16700Schasinglulu /***************************************************************************** 178*91f16700Schasinglulu * Perform any BL31 platform runtime setup prior to BL31 exit common to ARM 179*91f16700Schasinglulu * standard platforms 180*91f16700Schasinglulu ***************************************************************************** 181*91f16700Schasinglulu */ 182*91f16700Schasinglulu void marvell_bl31_plat_runtime_setup(void) 183*91f16700Schasinglulu { 184*91f16700Schasinglulu console_switch_state(CONSOLE_FLAG_RUNTIME); 185*91f16700Schasinglulu 186*91f16700Schasinglulu /* Initialize the runtime console */ 187*91f16700Schasinglulu marvell_console_runtime_init(); 188*91f16700Schasinglulu } 189*91f16700Schasinglulu 190*91f16700Schasinglulu void bl31_platform_setup(void) 191*91f16700Schasinglulu { 192*91f16700Schasinglulu marvell_bl31_platform_setup(); 193*91f16700Schasinglulu } 194*91f16700Schasinglulu 195*91f16700Schasinglulu void bl31_plat_runtime_setup(void) 196*91f16700Schasinglulu { 197*91f16700Schasinglulu marvell_bl31_plat_runtime_setup(); 198*91f16700Schasinglulu } 199*91f16700Schasinglulu 200*91f16700Schasinglulu /***************************************************************************** 201*91f16700Schasinglulu * Perform the very early platform specific architectural setup shared between 202*91f16700Schasinglulu * ARM standard platforms. This only does basic initialization. Later 203*91f16700Schasinglulu * architectural setup (bl31_arch_setup()) does not do anything platform 204*91f16700Schasinglulu * specific. 205*91f16700Schasinglulu ***************************************************************************** 206*91f16700Schasinglulu */ 207*91f16700Schasinglulu void marvell_bl31_plat_arch_setup(void) 208*91f16700Schasinglulu { 209*91f16700Schasinglulu marvell_setup_page_tables(BL31_BASE, 210*91f16700Schasinglulu BL31_END - BL31_BASE, 211*91f16700Schasinglulu BL_CODE_BASE, 212*91f16700Schasinglulu BL_CODE_END, 213*91f16700Schasinglulu BL_RO_DATA_BASE, 214*91f16700Schasinglulu BL_RO_DATA_END 215*91f16700Schasinglulu #if USE_COHERENT_MEM 216*91f16700Schasinglulu , BL_COHERENT_RAM_BASE, 217*91f16700Schasinglulu BL_COHERENT_RAM_END 218*91f16700Schasinglulu #endif 219*91f16700Schasinglulu ); 220*91f16700Schasinglulu 221*91f16700Schasinglulu #if BL31_CACHE_DISABLE 222*91f16700Schasinglulu enable_mmu_el3(DISABLE_DCACHE); 223*91f16700Schasinglulu INFO("Cache is disabled in BL3\n"); 224*91f16700Schasinglulu #else 225*91f16700Schasinglulu enable_mmu_el3(0); 226*91f16700Schasinglulu #endif 227*91f16700Schasinglulu } 228*91f16700Schasinglulu 229*91f16700Schasinglulu void bl31_plat_arch_setup(void) 230*91f16700Schasinglulu { 231*91f16700Schasinglulu marvell_bl31_plat_arch_setup(); 232*91f16700Schasinglulu } 233*91f16700Schasinglulu 234*91f16700Schasinglulu unsigned int plat_get_syscnt_freq2(void) 235*91f16700Schasinglulu { 236*91f16700Schasinglulu return PLAT_REF_CLK_IN_HZ; 237*91f16700Schasinglulu } 238