17d116dccSCC Ma /* 27d116dccSCC Ma * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. 37d116dccSCC Ma * 47d116dccSCC Ma * Redistribution and use in source and binary forms, with or without 57d116dccSCC Ma * modification, are permitted provided that the following conditions are met: 67d116dccSCC Ma * 77d116dccSCC Ma * Redistributions of source code must retain the above copyright notice, this 87d116dccSCC Ma * list of conditions and the following disclaimer. 97d116dccSCC Ma * 107d116dccSCC Ma * Redistributions in binary form must reproduce the above copyright notice, 117d116dccSCC Ma * this list of conditions and the following disclaimer in the documentation 127d116dccSCC Ma * and/or other materials provided with the distribution. 137d116dccSCC Ma * 147d116dccSCC Ma * Neither the name of ARM nor the names of its contributors may be used 157d116dccSCC Ma * to endorse or promote products derived from this software without specific 167d116dccSCC Ma * prior written permission. 177d116dccSCC Ma * 187d116dccSCC Ma * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 197d116dccSCC Ma * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 207d116dccSCC Ma * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 217d116dccSCC Ma * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 227d116dccSCC Ma * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 237d116dccSCC Ma * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 247d116dccSCC Ma * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 257d116dccSCC Ma * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 267d116dccSCC Ma * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 277d116dccSCC Ma * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 287d116dccSCC Ma * POSSIBILITY OF SUCH DAMAGE. 297d116dccSCC Ma */ 307d116dccSCC Ma #include <arm_gic.h> 317d116dccSCC Ma #include <assert.h> 327d116dccSCC Ma #include <bl_common.h> 337d116dccSCC Ma #include <console.h> 347d116dccSCC Ma #include <debug.h> 357d116dccSCC Ma #include <mcucfg.h> 367d116dccSCC Ma #include <mmio.h> 377d116dccSCC Ma #include <mtcmos.h> 387d116dccSCC Ma #include <plat_private.h> 397d116dccSCC Ma #include <platform.h> 407d116dccSCC Ma #include <spm.h> 417d116dccSCC Ma 427d116dccSCC Ma /******************************************************************************* 437d116dccSCC Ma * Declarations of linker defined symbols which will help us find the layout 447d116dccSCC Ma * of trusted SRAM 457d116dccSCC Ma ******************************************************************************/ 467d116dccSCC Ma unsigned long __RO_START__; 477d116dccSCC Ma unsigned long __RO_END__; 487d116dccSCC Ma 497d116dccSCC Ma unsigned long __COHERENT_RAM_START__; 507d116dccSCC Ma unsigned long __COHERENT_RAM_END__; 517d116dccSCC Ma 527d116dccSCC Ma /* 537d116dccSCC Ma * The next 2 constants identify the extents of the code & RO data region. 547d116dccSCC Ma * These addresses are used by the MMU setup code and therefore they must be 557d116dccSCC Ma * page-aligned. It is the responsibility of the linker script to ensure that 567d116dccSCC Ma * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. 577d116dccSCC Ma */ 587d116dccSCC Ma #define BL31_RO_BASE (unsigned long)(&__RO_START__) 597d116dccSCC Ma #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) 607d116dccSCC Ma 617d116dccSCC Ma /* 627d116dccSCC Ma * The next 2 constants identify the extents of the coherent memory region. 637d116dccSCC Ma * These addresses are used by the MMU setup code and therefore they must be 647d116dccSCC Ma * page-aligned. It is the responsibility of the linker script to ensure that 657d116dccSCC Ma * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols 667d116dccSCC Ma * refer to page-aligned addresses. 677d116dccSCC Ma */ 687d116dccSCC Ma #define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) 697d116dccSCC Ma #define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) 707d116dccSCC Ma 717d116dccSCC Ma static entry_point_info_t bl32_ep_info; 727d116dccSCC Ma static entry_point_info_t bl33_ep_info; 737d116dccSCC Ma 747d116dccSCC Ma static void platform_setup_cpu(void) 757d116dccSCC Ma { 767d116dccSCC Ma /* turn off all the little core's power except cpu 0 */ 777d116dccSCC Ma mtcmos_little_cpu_off(); 787d116dccSCC Ma 797d116dccSCC Ma /* setup big cores */ 807d116dccSCC Ma mmio_write_32((uintptr_t)&mt8173_mcucfg->mp1_config_res, 817d116dccSCC Ma MP1_DIS_RGU0_WAIT_PD_CPUS_L1_ACK | 827d116dccSCC Ma MP1_DIS_RGU1_WAIT_PD_CPUS_L1_ACK | 837d116dccSCC Ma MP1_DIS_RGU2_WAIT_PD_CPUS_L1_ACK | 847d116dccSCC Ma MP1_DIS_RGU3_WAIT_PD_CPUS_L1_ACK | 857d116dccSCC Ma MP1_DIS_RGU_NOCPU_WAIT_PD_CPUS_L1_ACK); 867d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_miscdbg, MP1_AINACTS); 877d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_clkenm_div, 887d116dccSCC Ma MP1_SW_CG_GEN); 897d116dccSCC Ma mmio_clrbits_32((uintptr_t)&mt8173_mcucfg->mp1_rst_ctl, 907d116dccSCC Ma MP1_L2RSTDISABLE); 917d116dccSCC Ma 927d116dccSCC Ma /* set big cores arm64 boot mode */ 937d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_cpucfg, 947d116dccSCC Ma MP1_CPUCFG_64BIT); 957d116dccSCC Ma 967d116dccSCC Ma /* set LITTLE cores arm64 boot mode */ 977d116dccSCC Ma mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp0_rv_addr[0].rv_addr_hw, 987d116dccSCC Ma MP0_CPUCFG_64BIT); 99*ac3986efSJimmy Huang 100*ac3986efSJimmy Huang /* enable dcm control */ 101*ac3986efSJimmy Huang mmio_setbits_32((uintptr_t)&mt8173_mcucfg->bus_fabric_dcm_ctrl, 102*ac3986efSJimmy Huang ADB400_GRP_DCM_EN | CCI400_GRP_DCM_EN | ADBCLK_GRP_DCM_EN | 103*ac3986efSJimmy Huang EMICLK_GRP_DCM_EN | ACLK_GRP_DCM_EN | L2C_IDLE_DCM_EN | 104*ac3986efSJimmy Huang INFRACLK_PSYS_DYNAMIC_CG_EN); 105*ac3986efSJimmy Huang mmio_setbits_32((uintptr_t)&mt8173_mcucfg->l2c_sram_ctrl, 106*ac3986efSJimmy Huang L2C_SRAM_DCM_EN); 107*ac3986efSJimmy Huang mmio_setbits_32((uintptr_t)&mt8173_mcucfg->cci_clk_ctrl, 108*ac3986efSJimmy Huang MCU_BUS_DCM_EN); 1097d116dccSCC Ma } 1107d116dccSCC Ma 1117d116dccSCC Ma /******************************************************************************* 1127d116dccSCC Ma * Return a pointer to the 'entry_point_info' structure of the next image for 1137d116dccSCC Ma * the security state specified. BL33 corresponds to the non-secure image type 1147d116dccSCC Ma * while BL32 corresponds to the secure image type. A NULL pointer is returned 1157d116dccSCC Ma * if the image does not exist. 1167d116dccSCC Ma ******************************************************************************/ 1177d116dccSCC Ma entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 1187d116dccSCC Ma { 1197d116dccSCC Ma entry_point_info_t *next_image_info; 1207d116dccSCC Ma 1217d116dccSCC Ma next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; 1227d116dccSCC Ma 1237d116dccSCC Ma /* None of the images on this platform can have 0x0 as the entrypoint */ 1247d116dccSCC Ma if (next_image_info->pc) 1257d116dccSCC Ma return next_image_info; 1267d116dccSCC Ma else 1277d116dccSCC Ma return NULL; 1287d116dccSCC Ma } 1297d116dccSCC Ma 1307d116dccSCC Ma /******************************************************************************* 1317d116dccSCC Ma * Perform any BL3-1 early platform setup. Here is an opportunity to copy 1327d116dccSCC Ma * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they 1337d116dccSCC Ma * are lost (potentially). This needs to be done before the MMU is initialized 1347d116dccSCC Ma * so that the memory layout can be used while creating page tables. 1357d116dccSCC Ma * BL2 has flushed this information to memory, so we are guaranteed to pick up 1367d116dccSCC Ma * good data. 1377d116dccSCC Ma ******************************************************************************/ 1387d116dccSCC Ma void bl31_early_platform_setup(bl31_params_t *from_bl2, 1397d116dccSCC Ma void *plat_params_from_bl2) 1407d116dccSCC Ma { 1417d116dccSCC Ma console_init(MT8173_UART0_BASE, MT8173_UART_CLOCK, MT8173_BAUDRATE); 1427d116dccSCC Ma 1437d116dccSCC Ma VERBOSE("bl31_setup\n"); 1447d116dccSCC Ma 1457d116dccSCC Ma assert(from_bl2 != NULL); 1467d116dccSCC Ma assert(from_bl2->h.type == PARAM_BL31); 1477d116dccSCC Ma assert(from_bl2->h.version >= VERSION_1); 1487d116dccSCC Ma 1497d116dccSCC Ma assert(((unsigned long)plat_params_from_bl2) == MT_BL31_PLAT_PARAM_VAL); 1507d116dccSCC Ma 1517d116dccSCC Ma bl32_ep_info = *from_bl2->bl32_ep_info; 1527d116dccSCC Ma bl33_ep_info = *from_bl2->bl33_ep_info; 1537d116dccSCC Ma } 1547d116dccSCC Ma 1557d116dccSCC Ma /******************************************************************************* 1567d116dccSCC Ma * Perform any BL3-1 platform setup code 1577d116dccSCC Ma ******************************************************************************/ 1587d116dccSCC Ma void bl31_platform_setup(void) 1597d116dccSCC Ma { 1607d116dccSCC Ma platform_setup_cpu(); 1617d116dccSCC Ma 1627d116dccSCC Ma plat_delay_timer_init(); 1637d116dccSCC Ma 1647d116dccSCC Ma /* Initialize the gic cpu and distributor interfaces */ 1657d116dccSCC Ma plat_mt_gic_init(); 1667d116dccSCC Ma arm_gic_setup(); 1677d116dccSCC Ma 1687d116dccSCC Ma /* Topologies are best known to the platform. */ 1697d116dccSCC Ma mt_setup_topology(); 1707d116dccSCC Ma 1717d116dccSCC Ma /* Initialize spm at boot time */ 1727d116dccSCC Ma spm_boot_init(); 1737d116dccSCC Ma } 1747d116dccSCC Ma 1757d116dccSCC Ma /******************************************************************************* 1767d116dccSCC Ma * Perform the very early platform specific architectural setup here. At the 1777d116dccSCC Ma * moment this is only intializes the mmu in a quick and dirty way. 1787d116dccSCC Ma ******************************************************************************/ 1797d116dccSCC Ma void bl31_plat_arch_setup(void) 1807d116dccSCC Ma { 1817d116dccSCC Ma plat_cci_init(); 1827d116dccSCC Ma plat_cci_enable(); 1837d116dccSCC Ma 1847d116dccSCC Ma plat_configure_mmu_el3(BL31_RO_BASE, 1857d116dccSCC Ma (BL31_COHERENT_RAM_LIMIT - BL31_RO_BASE), 1867d116dccSCC Ma BL31_RO_BASE, 1877d116dccSCC Ma BL31_RO_LIMIT, 1887d116dccSCC Ma BL31_COHERENT_RAM_BASE, 1897d116dccSCC Ma BL31_COHERENT_RAM_LIMIT); 1907d116dccSCC Ma } 1917d116dccSCC Ma 192