xref: /rk3399_ARM-atf/plat/mediatek/mt8173/bl31_plat_setup.c (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
17d116dccSCC Ma /*
21d0b990eSAntonio Nino Diaz  * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
37d116dccSCC Ma  *
4*82cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
57d116dccSCC Ma  */
67d116dccSCC Ma #include <assert.h>
77d116dccSCC Ma #include <bl_common.h>
847497053SMasahiro Yamada #include <common_def.h>
97d116dccSCC Ma #include <console.h>
107d116dccSCC Ma #include <debug.h>
111d0b990eSAntonio Nino Diaz #include <generic_delay_timer.h>
127d116dccSCC Ma #include <mcucfg.h>
137d116dccSCC Ma #include <mmio.h>
147d116dccSCC Ma #include <mtcmos.h>
158bc20038SKoan-Sin Tan #include <plat_arm.h>
167d116dccSCC Ma #include <plat_private.h>
177d116dccSCC Ma #include <platform.h>
187d116dccSCC Ma #include <spm.h>
197d116dccSCC Ma 
207d116dccSCC Ma /*******************************************************************************
217d116dccSCC Ma  * Declarations of linker defined symbols which will help us find the layout
227d116dccSCC Ma  * of trusted SRAM
237d116dccSCC Ma  ******************************************************************************/
247d116dccSCC Ma unsigned long __RO_START__;
257d116dccSCC Ma unsigned long __RO_END__;
267d116dccSCC Ma 
277d116dccSCC Ma /*
28a1e0c01fSJimmy Huang  * The next 3 constants identify the extents of the code, RO data region and the
29a1e0c01fSJimmy Huang  * limit of the BL31 image.  These addresses are used by the MMU setup code and
30a1e0c01fSJimmy Huang  * therefore they must be page-aligned.  It is the responsibility of the linker
31a1e0c01fSJimmy Huang  * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
32a1e0c01fSJimmy Huang  * refer to page-aligned addresses.
337d116dccSCC Ma  */
347d116dccSCC Ma #define BL31_RO_BASE (unsigned long)(&__RO_START__)
357d116dccSCC Ma #define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
36a1e0c01fSJimmy Huang #define BL31_END (unsigned long)(&__BL31_END__)
377d116dccSCC Ma 
387d116dccSCC Ma static entry_point_info_t bl32_ep_info;
397d116dccSCC Ma static entry_point_info_t bl33_ep_info;
407d116dccSCC Ma 
417d116dccSCC Ma static void platform_setup_cpu(void)
427d116dccSCC Ma {
437d116dccSCC Ma 	/* turn off all the little core's power except cpu 0 */
447d116dccSCC Ma 	mtcmos_little_cpu_off();
457d116dccSCC Ma 
467d116dccSCC Ma 	/* setup big cores */
477d116dccSCC Ma 	mmio_write_32((uintptr_t)&mt8173_mcucfg->mp1_config_res,
487d116dccSCC Ma 		MP1_DIS_RGU0_WAIT_PD_CPUS_L1_ACK |
497d116dccSCC Ma 		MP1_DIS_RGU1_WAIT_PD_CPUS_L1_ACK |
507d116dccSCC Ma 		MP1_DIS_RGU2_WAIT_PD_CPUS_L1_ACK |
517d116dccSCC Ma 		MP1_DIS_RGU3_WAIT_PD_CPUS_L1_ACK |
527d116dccSCC Ma 		MP1_DIS_RGU_NOCPU_WAIT_PD_CPUS_L1_ACK);
537d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_miscdbg, MP1_AINACTS);
547d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_clkenm_div,
557d116dccSCC Ma 		MP1_SW_CG_GEN);
567d116dccSCC Ma 	mmio_clrbits_32((uintptr_t)&mt8173_mcucfg->mp1_rst_ctl,
577d116dccSCC Ma 		MP1_L2RSTDISABLE);
587d116dccSCC Ma 
597d116dccSCC Ma 	/* set big cores arm64 boot mode */
607d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_cpucfg,
617d116dccSCC Ma 		MP1_CPUCFG_64BIT);
627d116dccSCC Ma 
637d116dccSCC Ma 	/* set LITTLE cores arm64 boot mode */
647d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp0_rv_addr[0].rv_addr_hw,
657d116dccSCC Ma 		MP0_CPUCFG_64BIT);
66ac3986efSJimmy Huang 
67ac3986efSJimmy Huang 	/* enable dcm control */
68ac3986efSJimmy Huang 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->bus_fabric_dcm_ctrl,
69ac3986efSJimmy Huang 		ADB400_GRP_DCM_EN | CCI400_GRP_DCM_EN | ADBCLK_GRP_DCM_EN |
70ac3986efSJimmy Huang 		EMICLK_GRP_DCM_EN | ACLK_GRP_DCM_EN | L2C_IDLE_DCM_EN |
71ac3986efSJimmy Huang 		INFRACLK_PSYS_DYNAMIC_CG_EN);
72ac3986efSJimmy Huang 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->l2c_sram_ctrl,
73ac3986efSJimmy Huang 		L2C_SRAM_DCM_EN);
74ac3986efSJimmy Huang 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->cci_clk_ctrl,
75ac3986efSJimmy Huang 		MCU_BUS_DCM_EN);
767d116dccSCC Ma }
777d116dccSCC Ma 
78a1e0c01fSJimmy Huang static void platform_setup_sram(void)
79a1e0c01fSJimmy Huang {
80a1e0c01fSJimmy Huang 	/* protect BL31 memory from non-secure read/write access */
81a1e0c01fSJimmy Huang 	mmio_write_32(SRAMROM_SEC_ADDR, (uint32_t)(BL31_END + 0x3ff) & 0x3fc00);
82a1e0c01fSJimmy Huang 	mmio_write_32(SRAMROM_SEC_CTRL, 0x10000ff9);
83a1e0c01fSJimmy Huang }
84a1e0c01fSJimmy Huang 
857d116dccSCC Ma /*******************************************************************************
867d116dccSCC Ma  * Return a pointer to the 'entry_point_info' structure of the next image for
877d116dccSCC Ma  * the security state specified. BL33 corresponds to the non-secure image type
887d116dccSCC Ma  * while BL32 corresponds to the secure image type. A NULL pointer is returned
897d116dccSCC Ma  * if the image does not exist.
907d116dccSCC Ma  ******************************************************************************/
917d116dccSCC Ma entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
927d116dccSCC Ma {
937d116dccSCC Ma 	entry_point_info_t *next_image_info;
947d116dccSCC Ma 
957d116dccSCC Ma 	next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;
967d116dccSCC Ma 
977d116dccSCC Ma 	/* None of the images on this platform can have 0x0 as the entrypoint */
987d116dccSCC Ma 	if (next_image_info->pc)
997d116dccSCC Ma 		return next_image_info;
1007d116dccSCC Ma 	else
1017d116dccSCC Ma 		return NULL;
1027d116dccSCC Ma }
1037d116dccSCC Ma 
1047d116dccSCC Ma /*******************************************************************************
1057d116dccSCC Ma  * Perform any BL3-1 early platform setup. Here is an opportunity to copy
1067d116dccSCC Ma  * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they
1077d116dccSCC Ma  * are lost (potentially). This needs to be done before the MMU is initialized
1087d116dccSCC Ma  * so that the memory layout can be used while creating page tables.
1097d116dccSCC Ma  * BL2 has flushed this information to memory, so we are guaranteed to pick up
1107d116dccSCC Ma  * good data.
1117d116dccSCC Ma  ******************************************************************************/
1127d116dccSCC Ma void bl31_early_platform_setup(bl31_params_t *from_bl2,
1137d116dccSCC Ma 			       void *plat_params_from_bl2)
1147d116dccSCC Ma {
1157d116dccSCC Ma 	console_init(MT8173_UART0_BASE, MT8173_UART_CLOCK, MT8173_BAUDRATE);
1167d116dccSCC Ma 
1177d116dccSCC Ma 	VERBOSE("bl31_setup\n");
1187d116dccSCC Ma 
1197d116dccSCC Ma 	assert(from_bl2 != NULL);
1207d116dccSCC Ma 	assert(from_bl2->h.type == PARAM_BL31);
1217d116dccSCC Ma 	assert(from_bl2->h.version >= VERSION_1);
1227d116dccSCC Ma 
1237d116dccSCC Ma 	bl32_ep_info = *from_bl2->bl32_ep_info;
1247d116dccSCC Ma 	bl33_ep_info = *from_bl2->bl33_ep_info;
1257d116dccSCC Ma }
1267d116dccSCC Ma 
1277d116dccSCC Ma /*******************************************************************************
1287d116dccSCC Ma  * Perform any BL3-1 platform setup code
1297d116dccSCC Ma  ******************************************************************************/
1307d116dccSCC Ma void bl31_platform_setup(void)
1317d116dccSCC Ma {
1327d116dccSCC Ma 	platform_setup_cpu();
133a1e0c01fSJimmy Huang 	platform_setup_sram();
1347d116dccSCC Ma 
1351d0b990eSAntonio Nino Diaz 	generic_delay_timer_init();
1367d116dccSCC Ma 
1377d116dccSCC Ma 	/* Initialize the gic cpu and distributor interfaces */
1388bc20038SKoan-Sin Tan 	plat_arm_gic_driver_init();
1398bc20038SKoan-Sin Tan 	plat_arm_gic_init();
1407d116dccSCC Ma 
1413fc26aa0SKoan-Sin Tan #if ENABLE_PLAT_COMPAT
1427d116dccSCC Ma 	/* Topologies are best known to the platform. */
1437d116dccSCC Ma 	mt_setup_topology();
1443fc26aa0SKoan-Sin Tan #endif
1457d116dccSCC Ma 
1467d116dccSCC Ma 	/* Initialize spm at boot time */
1477d116dccSCC Ma 	spm_boot_init();
1487d116dccSCC Ma }
1497d116dccSCC Ma 
1507d116dccSCC Ma /*******************************************************************************
1517d116dccSCC Ma  * Perform the very early platform specific architectural setup here. At the
1527d116dccSCC Ma  * moment this is only intializes the mmu in a quick and dirty way.
1537d116dccSCC Ma  ******************************************************************************/
1547d116dccSCC Ma void bl31_plat_arch_setup(void)
1557d116dccSCC Ma {
1567d116dccSCC Ma 	plat_cci_init();
1577d116dccSCC Ma 	plat_cci_enable();
1587d116dccSCC Ma 
1597d116dccSCC Ma 	plat_configure_mmu_el3(BL31_RO_BASE,
16047497053SMasahiro Yamada 			       BL_COHERENT_RAM_END - BL31_RO_BASE,
1617d116dccSCC Ma 			       BL31_RO_BASE,
1627d116dccSCC Ma 			       BL31_RO_LIMIT,
16347497053SMasahiro Yamada 			       BL_COHERENT_RAM_BASE,
16447497053SMasahiro Yamada 			       BL_COHERENT_RAM_END);
1657d116dccSCC Ma }
1667d116dccSCC Ma 
167