1*7d116dccSCC Ma /* 2*7d116dccSCC Ma * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. 3*7d116dccSCC Ma * 4*7d116dccSCC Ma * Redistribution and use in source and binary forms, with or without 5*7d116dccSCC Ma * modification, are permitted provided that the following conditions are met: 6*7d116dccSCC Ma * 7*7d116dccSCC Ma * Redistributions of source code must retain the above copyright notice, this 8*7d116dccSCC Ma * list of conditions and the following disclaimer. 9*7d116dccSCC Ma * 10*7d116dccSCC Ma * Redistributions in binary form must reproduce the above copyright notice, 11*7d116dccSCC Ma * this list of conditions and the following disclaimer in the documentation 12*7d116dccSCC Ma * and/or other materials provided with the distribution. 13*7d116dccSCC Ma * 14*7d116dccSCC Ma * Neither the name of ARM nor the names of its contributors may be used 15*7d116dccSCC Ma * to endorse or promote products derived from this software without specific 16*7d116dccSCC Ma * prior written permission. 17*7d116dccSCC Ma * 18*7d116dccSCC Ma * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*7d116dccSCC Ma * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*7d116dccSCC Ma * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*7d116dccSCC Ma * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*7d116dccSCC Ma * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*7d116dccSCC Ma * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*7d116dccSCC Ma * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*7d116dccSCC Ma * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*7d116dccSCC Ma * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*7d116dccSCC Ma * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*7d116dccSCC Ma * POSSIBILITY OF SUCH DAMAGE. 29*7d116dccSCC Ma */ 30*7d116dccSCC Ma #include <arm_gic.h> 31*7d116dccSCC Ma #include <assert.h> 32*7d116dccSCC Ma #include <bl_common.h> 33*7d116dccSCC Ma #include <console.h> 34*7d116dccSCC Ma #include <debug.h> 35*7d116dccSCC Ma #include <mcucfg.h> 36*7d116dccSCC Ma #include <mmio.h> 37*7d116dccSCC Ma #include <mtcmos.h> 38*7d116dccSCC Ma #include <plat_private.h> 39*7d116dccSCC Ma #include <platform.h> 40*7d116dccSCC Ma #include <spm.h> 41*7d116dccSCC Ma 42*7d116dccSCC Ma /******************************************************************************* 43*7d116dccSCC Ma * Declarations of linker defined symbols which will help us find the layout 44*7d116dccSCC Ma * of trusted SRAM 45*7d116dccSCC Ma ******************************************************************************/ 46*7d116dccSCC Ma unsigned long __RO_START__; 47*7d116dccSCC Ma unsigned long __RO_END__; 48*7d116dccSCC Ma 49*7d116dccSCC Ma unsigned long __COHERENT_RAM_START__; 50*7d116dccSCC Ma unsigned long __COHERENT_RAM_END__; 51*7d116dccSCC Ma 52*7d116dccSCC Ma /* 53*7d116dccSCC Ma * The next 2 constants identify the extents of the code & RO data region. 54*7d116dccSCC Ma * These addresses are used by the MMU setup code and therefore they must be 55*7d116dccSCC Ma * page-aligned. It is the responsibility of the linker script to ensure that 56*7d116dccSCC Ma * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. 57*7d116dccSCC Ma */ 58*7d116dccSCC Ma #define BL31_RO_BASE (unsigned long)(&__RO_START__) 59*7d116dccSCC Ma #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) 60*7d116dccSCC Ma 61*7d116dccSCC Ma /* 62*7d116dccSCC Ma * The next 2 constants identify the extents of the coherent memory region. 63*7d116dccSCC Ma * These addresses are used by the MMU setup code and therefore they must be 64*7d116dccSCC Ma * page-aligned. It is the responsibility of the linker script to ensure that 65*7d116dccSCC Ma * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols 66*7d116dccSCC Ma * refer to page-aligned addresses. 67*7d116dccSCC Ma */ 68*7d116dccSCC Ma #define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) 69*7d116dccSCC Ma #define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) 70*7d116dccSCC Ma 71*7d116dccSCC Ma static entry_point_info_t bl32_ep_info; 72*7d116dccSCC Ma static entry_point_info_t bl33_ep_info; 73*7d116dccSCC Ma 74*7d116dccSCC Ma static void platform_setup_cpu(void) 75*7d116dccSCC Ma { 76*7d116dccSCC Ma /* turn off all the little core's power except cpu 0 */ 77*7d116dccSCC Ma mtcmos_little_cpu_off(); 78*7d116dccSCC Ma 79*7d116dccSCC Ma /* setup big cores */ 80*7d116dccSCC Ma mmio_write_32((uintptr_t)&mt8173_mcucfg->mp1_config_res, 81*7d116dccSCC Ma MP1_DIS_RGU0_WAIT_PD_CPUS_L1_ACK | 82*7d116dccSCC Ma MP1_DIS_RGU1_WAIT_PD_CPUS_L1_ACK | 83*7d116dccSCC Ma MP1_DIS_RGU2_WAIT_PD_CPUS_L1_ACK | 84*7d116dccSCC Ma MP1_DIS_RGU3_WAIT_PD_CPUS_L1_ACK | 85*7d116dccSCC Ma MP1_DIS_RGU_NOCPU_WAIT_PD_CPUS_L1_ACK); 86*7d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_miscdbg, MP1_AINACTS); 87*7d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_clkenm_div, 88*7d116dccSCC Ma MP1_SW_CG_GEN); 89*7d116dccSCC Ma mmio_clrbits_32((uintptr_t)&mt8173_mcucfg->mp1_rst_ctl, 90*7d116dccSCC Ma MP1_L2RSTDISABLE); 91*7d116dccSCC Ma 92*7d116dccSCC Ma /* set big cores arm64 boot mode */ 93*7d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_cpucfg, 94*7d116dccSCC Ma MP1_CPUCFG_64BIT); 95*7d116dccSCC Ma 96*7d116dccSCC Ma /* set LITTLE cores arm64 boot mode */ 97*7d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp0_rv_addr[0].rv_addr_hw, 98*7d116dccSCC Ma MP0_CPUCFG_64BIT); 99*7d116dccSCC Ma } 100*7d116dccSCC Ma 101*7d116dccSCC Ma /******************************************************************************* 102*7d116dccSCC Ma * Return a pointer to the 'entry_point_info' structure of the next image for 103*7d116dccSCC Ma * the security state specified. BL33 corresponds to the non-secure image type 104*7d116dccSCC Ma * while BL32 corresponds to the secure image type. A NULL pointer is returned 105*7d116dccSCC Ma * if the image does not exist. 106*7d116dccSCC Ma ******************************************************************************/ 107*7d116dccSCC Ma entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 108*7d116dccSCC Ma { 109*7d116dccSCC Ma entry_point_info_t *next_image_info; 110*7d116dccSCC Ma 111*7d116dccSCC Ma next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; 112*7d116dccSCC Ma 113*7d116dccSCC Ma /* None of the images on this platform can have 0x0 as the entrypoint */ 114*7d116dccSCC Ma if (next_image_info->pc) 115*7d116dccSCC Ma return next_image_info; 116*7d116dccSCC Ma else 117*7d116dccSCC Ma return NULL; 118*7d116dccSCC Ma } 119*7d116dccSCC Ma 120*7d116dccSCC Ma /******************************************************************************* 121*7d116dccSCC Ma * Perform any BL3-1 early platform setup. Here is an opportunity to copy 122*7d116dccSCC Ma * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they 123*7d116dccSCC Ma * are lost (potentially). This needs to be done before the MMU is initialized 124*7d116dccSCC Ma * so that the memory layout can be used while creating page tables. 125*7d116dccSCC Ma * BL2 has flushed this information to memory, so we are guaranteed to pick up 126*7d116dccSCC Ma * good data. 127*7d116dccSCC Ma ******************************************************************************/ 128*7d116dccSCC Ma void bl31_early_platform_setup(bl31_params_t *from_bl2, 129*7d116dccSCC Ma void *plat_params_from_bl2) 130*7d116dccSCC Ma { 131*7d116dccSCC Ma console_init(MT8173_UART0_BASE, MT8173_UART_CLOCK, MT8173_BAUDRATE); 132*7d116dccSCC Ma 133*7d116dccSCC Ma VERBOSE("bl31_setup\n"); 134*7d116dccSCC Ma 135*7d116dccSCC Ma assert(from_bl2 != NULL); 136*7d116dccSCC Ma assert(from_bl2->h.type == PARAM_BL31); 137*7d116dccSCC Ma assert(from_bl2->h.version >= VERSION_1); 138*7d116dccSCC Ma 139*7d116dccSCC Ma assert(((unsigned long)plat_params_from_bl2) == MT_BL31_PLAT_PARAM_VAL); 140*7d116dccSCC Ma 141*7d116dccSCC Ma bl32_ep_info = *from_bl2->bl32_ep_info; 142*7d116dccSCC Ma bl33_ep_info = *from_bl2->bl33_ep_info; 143*7d116dccSCC Ma } 144*7d116dccSCC Ma 145*7d116dccSCC Ma /******************************************************************************* 146*7d116dccSCC Ma * Perform any BL3-1 platform setup code 147*7d116dccSCC Ma ******************************************************************************/ 148*7d116dccSCC Ma void bl31_platform_setup(void) 149*7d116dccSCC Ma { 150*7d116dccSCC Ma platform_setup_cpu(); 151*7d116dccSCC Ma 152*7d116dccSCC Ma plat_delay_timer_init(); 153*7d116dccSCC Ma 154*7d116dccSCC Ma /* Initialize the gic cpu and distributor interfaces */ 155*7d116dccSCC Ma plat_mt_gic_init(); 156*7d116dccSCC Ma arm_gic_setup(); 157*7d116dccSCC Ma 158*7d116dccSCC Ma /* Topologies are best known to the platform. */ 159*7d116dccSCC Ma mt_setup_topology(); 160*7d116dccSCC Ma 161*7d116dccSCC Ma /* Initialize spm at boot time */ 162*7d116dccSCC Ma spm_boot_init(); 163*7d116dccSCC Ma } 164*7d116dccSCC Ma 165*7d116dccSCC Ma /******************************************************************************* 166*7d116dccSCC Ma * Perform the very early platform specific architectural setup here. At the 167*7d116dccSCC Ma * moment this is only intializes the mmu in a quick and dirty way. 168*7d116dccSCC Ma ******************************************************************************/ 169*7d116dccSCC Ma void bl31_plat_arch_setup(void) 170*7d116dccSCC Ma { 171*7d116dccSCC Ma plat_cci_init(); 172*7d116dccSCC Ma plat_cci_enable(); 173*7d116dccSCC Ma 174*7d116dccSCC Ma plat_configure_mmu_el3(BL31_RO_BASE, 175*7d116dccSCC Ma (BL31_COHERENT_RAM_LIMIT - BL31_RO_BASE), 176*7d116dccSCC Ma BL31_RO_BASE, 177*7d116dccSCC Ma BL31_RO_LIMIT, 178*7d116dccSCC Ma BL31_COHERENT_RAM_BASE, 179*7d116dccSCC Ma BL31_COHERENT_RAM_LIMIT); 180*7d116dccSCC Ma } 181*7d116dccSCC Ma 182