xref: /rk3399_ARM-atf/plat/mediatek/mt8173/bl31_plat_setup.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
17d116dccSCC Ma /*
29f85f9e3SJoel Hutton  * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
37d116dccSCC Ma  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
57d116dccSCC Ma  */
6*09d40e0eSAntonio Nino Diaz 
77d116dccSCC Ma #include <assert.h>
8*09d40e0eSAntonio Nino Diaz 
9*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
10*09d40e0eSAntonio Nino Diaz #include <common/debug.h>
11*09d40e0eSAntonio Nino Diaz #include <drivers/console.h>
12*09d40e0eSAntonio Nino Diaz #include <drivers/generic_delay_timer.h>
13*09d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
14*09d40e0eSAntonio Nino Diaz #include <plat/common/common_def.h>
15*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
16*09d40e0eSAntonio Nino Diaz 
177d116dccSCC Ma #include <mcucfg.h>
187d116dccSCC Ma #include <mtcmos.h>
19b8424642SAntonio Nino Diaz #include <mtk_plat_common.h>
208bc20038SKoan-Sin Tan #include <plat_arm.h>
217d116dccSCC Ma #include <plat_private.h>
227d116dccSCC Ma #include <spm.h>
237d116dccSCC Ma 
247d116dccSCC Ma static entry_point_info_t bl32_ep_info;
257d116dccSCC Ma static entry_point_info_t bl33_ep_info;
267d116dccSCC Ma 
277d116dccSCC Ma static void platform_setup_cpu(void)
287d116dccSCC Ma {
297d116dccSCC Ma 	/* turn off all the little core's power except cpu 0 */
307d116dccSCC Ma 	mtcmos_little_cpu_off();
317d116dccSCC Ma 
327d116dccSCC Ma 	/* setup big cores */
337d116dccSCC Ma 	mmio_write_32((uintptr_t)&mt8173_mcucfg->mp1_config_res,
347d116dccSCC Ma 		MP1_DIS_RGU0_WAIT_PD_CPUS_L1_ACK |
357d116dccSCC Ma 		MP1_DIS_RGU1_WAIT_PD_CPUS_L1_ACK |
367d116dccSCC Ma 		MP1_DIS_RGU2_WAIT_PD_CPUS_L1_ACK |
377d116dccSCC Ma 		MP1_DIS_RGU3_WAIT_PD_CPUS_L1_ACK |
387d116dccSCC Ma 		MP1_DIS_RGU_NOCPU_WAIT_PD_CPUS_L1_ACK);
397d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_miscdbg, MP1_AINACTS);
407d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_clkenm_div,
417d116dccSCC Ma 		MP1_SW_CG_GEN);
427d116dccSCC Ma 	mmio_clrbits_32((uintptr_t)&mt8173_mcucfg->mp1_rst_ctl,
437d116dccSCC Ma 		MP1_L2RSTDISABLE);
447d116dccSCC Ma 
457d116dccSCC Ma 	/* set big cores arm64 boot mode */
467d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_cpucfg,
477d116dccSCC Ma 		MP1_CPUCFG_64BIT);
487d116dccSCC Ma 
497d116dccSCC Ma 	/* set LITTLE cores arm64 boot mode */
507d116dccSCC Ma 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp0_rv_addr[0].rv_addr_hw,
517d116dccSCC Ma 		MP0_CPUCFG_64BIT);
52ac3986efSJimmy Huang 
53ac3986efSJimmy Huang 	/* enable dcm control */
54ac3986efSJimmy Huang 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->bus_fabric_dcm_ctrl,
55ac3986efSJimmy Huang 		ADB400_GRP_DCM_EN | CCI400_GRP_DCM_EN | ADBCLK_GRP_DCM_EN |
56ac3986efSJimmy Huang 		EMICLK_GRP_DCM_EN | ACLK_GRP_DCM_EN | L2C_IDLE_DCM_EN |
57ac3986efSJimmy Huang 		INFRACLK_PSYS_DYNAMIC_CG_EN);
58ac3986efSJimmy Huang 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->l2c_sram_ctrl,
59ac3986efSJimmy Huang 		L2C_SRAM_DCM_EN);
60ac3986efSJimmy Huang 	mmio_setbits_32((uintptr_t)&mt8173_mcucfg->cci_clk_ctrl,
61ac3986efSJimmy Huang 		MCU_BUS_DCM_EN);
627d116dccSCC Ma }
637d116dccSCC Ma 
64a1e0c01fSJimmy Huang static void platform_setup_sram(void)
65a1e0c01fSJimmy Huang {
66a1e0c01fSJimmy Huang 	/* protect BL31 memory from non-secure read/write access */
67a1e0c01fSJimmy Huang 	mmio_write_32(SRAMROM_SEC_ADDR, (uint32_t)(BL31_END + 0x3ff) & 0x3fc00);
68a1e0c01fSJimmy Huang 	mmio_write_32(SRAMROM_SEC_CTRL, 0x10000ff9);
69a1e0c01fSJimmy Huang }
70a1e0c01fSJimmy Huang 
717d116dccSCC Ma /*******************************************************************************
727d116dccSCC Ma  * Return a pointer to the 'entry_point_info' structure of the next image for
737d116dccSCC Ma  * the security state specified. BL33 corresponds to the non-secure image type
747d116dccSCC Ma  * while BL32 corresponds to the secure image type. A NULL pointer is returned
757d116dccSCC Ma  * if the image does not exist.
767d116dccSCC Ma  ******************************************************************************/
777d116dccSCC Ma entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
787d116dccSCC Ma {
797d116dccSCC Ma 	entry_point_info_t *next_image_info;
807d116dccSCC Ma 
817d116dccSCC Ma 	next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;
827d116dccSCC Ma 
837d116dccSCC Ma 	/* None of the images on this platform can have 0x0 as the entrypoint */
847d116dccSCC Ma 	if (next_image_info->pc)
857d116dccSCC Ma 		return next_image_info;
867d116dccSCC Ma 	else
877d116dccSCC Ma 		return NULL;
887d116dccSCC Ma }
897d116dccSCC Ma 
907d116dccSCC Ma /*******************************************************************************
917d116dccSCC Ma  * Perform any BL3-1 early platform setup. Here is an opportunity to copy
92a6238326SJohn Tsichritzis  * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before they
937d116dccSCC Ma  * are lost (potentially). This needs to be done before the MMU is initialized
947d116dccSCC Ma  * so that the memory layout can be used while creating page tables.
957d116dccSCC Ma  * BL2 has flushed this information to memory, so we are guaranteed to pick up
967d116dccSCC Ma  * good data.
977d116dccSCC Ma  ******************************************************************************/
98b8424642SAntonio Nino Diaz void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
99b8424642SAntonio Nino Diaz 				u_register_t arg2, u_register_t arg3)
1007d116dccSCC Ma {
101b8424642SAntonio Nino Diaz 	struct mtk_bl31_params *arg_from_bl2 = (struct mtk_bl31_params *)arg0;
102b8424642SAntonio Nino Diaz 
1037d116dccSCC Ma 	console_init(MT8173_UART0_BASE, MT8173_UART_CLOCK, MT8173_BAUDRATE);
1047d116dccSCC Ma 
1057d116dccSCC Ma 	VERBOSE("bl31_setup\n");
1067d116dccSCC Ma 
107b8424642SAntonio Nino Diaz 	assert(arg_from_bl2 != NULL);
108b8424642SAntonio Nino Diaz 	assert(arg_from_bl2->h.type == PARAM_BL31);
109b8424642SAntonio Nino Diaz 	assert(arg_from_bl2->h.version >= VERSION_1);
1107d116dccSCC Ma 
111b8424642SAntonio Nino Diaz 	bl32_ep_info = *arg_from_bl2->bl32_ep_info;
112b8424642SAntonio Nino Diaz 	bl33_ep_info = *arg_from_bl2->bl33_ep_info;
1137d116dccSCC Ma }
1147d116dccSCC Ma 
1157d116dccSCC Ma /*******************************************************************************
1167d116dccSCC Ma  * Perform any BL3-1 platform setup code
1177d116dccSCC Ma  ******************************************************************************/
1187d116dccSCC Ma void bl31_platform_setup(void)
1197d116dccSCC Ma {
1207d116dccSCC Ma 	platform_setup_cpu();
121a1e0c01fSJimmy Huang 	platform_setup_sram();
1227d116dccSCC Ma 
1231d0b990eSAntonio Nino Diaz 	generic_delay_timer_init();
1247d116dccSCC Ma 
1257d116dccSCC Ma 	/* Initialize the gic cpu and distributor interfaces */
1268bc20038SKoan-Sin Tan 	plat_arm_gic_driver_init();
1278bc20038SKoan-Sin Tan 	plat_arm_gic_init();
1287d116dccSCC Ma 
1297d116dccSCC Ma 	/* Initialize spm at boot time */
1307d116dccSCC Ma 	spm_boot_init();
1317d116dccSCC Ma }
1327d116dccSCC Ma 
1337d116dccSCC Ma /*******************************************************************************
1347d116dccSCC Ma  * Perform the very early platform specific architectural setup here. At the
1357d116dccSCC Ma  * moment this is only intializes the mmu in a quick and dirty way.
1367d116dccSCC Ma  ******************************************************************************/
1377d116dccSCC Ma void bl31_plat_arch_setup(void)
1387d116dccSCC Ma {
1397d116dccSCC Ma 	plat_cci_init();
1407d116dccSCC Ma 	plat_cci_enable();
1417d116dccSCC Ma 
1429f85f9e3SJoel Hutton 	plat_configure_mmu_el3(BL_CODE_BASE,
1439f85f9e3SJoel Hutton 			       BL_COHERENT_RAM_END - BL_CODE_BASE,
1449f85f9e3SJoel Hutton 			       BL_CODE_BASE,
1459f85f9e3SJoel Hutton 			       BL_CODE_END,
14647497053SMasahiro Yamada 			       BL_COHERENT_RAM_BASE,
14747497053SMasahiro Yamada 			       BL_COHERENT_RAM_END);
1487d116dccSCC Ma }
1497d116dccSCC Ma 
150