xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 955242d8fff132769c677d9a807ff47cd6828b7e)
13e4b8fdcSSoby Mathew /*
2*955242d8SJeenu Viswambharan  * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
33e4b8fdcSSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
53e4b8fdcSSoby Mathew  */
63e4b8fdcSSoby Mathew 
73e4b8fdcSSoby Mathew #include <arm_config.h>
83e4b8fdcSSoby Mathew #include <arm_def.h>
9*955242d8SJeenu Viswambharan #include <assert.h>
10*955242d8SJeenu Viswambharan #include <cci.h>
1171237876SSoby Mathew #include <ccn.h>
123e4b8fdcSSoby Mathew #include <debug.h>
133e4b8fdcSSoby Mathew #include <gicv2.h>
143e4b8fdcSSoby Mathew #include <mmio.h>
153e4b8fdcSSoby Mathew #include <plat_arm.h>
163e4b8fdcSSoby Mathew #include <v2m_def.h>
173e4b8fdcSSoby Mathew #include "../fvp_def.h"
183e4b8fdcSSoby Mathew 
193e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
203e4b8fdcSSoby Mathew #define FVP_GICV2		1
213e4b8fdcSSoby Mathew #define FVP_GICV3		2
223e4b8fdcSSoby Mathew #define FVP_GICV3_LEGACY	3
233e4b8fdcSSoby Mathew 
243e4b8fdcSSoby Mathew /*******************************************************************************
253e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
263e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
273e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
283e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
293e4b8fdcSSoby Mathew  * to allow independent operation.
303e4b8fdcSSoby Mathew  ******************************************************************************/
313e4b8fdcSSoby Mathew arm_config_t arm_config;
323e4b8fdcSSoby Mathew 
333e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
343e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
353e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
363e4b8fdcSSoby Mathew 
373e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
383e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
393e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
403e4b8fdcSSoby Mathew 
41284c3d67SSandrine Bailleux /*
42284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
43284c3d67SSandrine Bailleux  * counter value.
44284c3d67SSandrine Bailleux  */
453e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
463e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
47fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
483e4b8fdcSSoby Mathew 
493e4b8fdcSSoby Mathew 
503e4b8fdcSSoby Mathew /*
51b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
52b5fa6563SSandrine Bailleux  * This doesn't include Trusted SRAM as arm_setup_page_tables() already
53b5fa6563SSandrine Bailleux  * takes care of mapping it.
5491fad655SSandrine Bailleux  *
5591fad655SSandrine Bailleux  * The flash needs to be mapped as writable in order to erase the FIP's Table of
5691fad655SSandrine Bailleux  * Contents in case of unrecoverable error (see plat_error_handler()).
573e4b8fdcSSoby Mathew  */
583d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
593e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
603e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
613e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
623e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
633e4b8fdcSSoby Mathew 	MAP_DEVICE0,
643e4b8fdcSSoby Mathew 	MAP_DEVICE1,
653e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
66284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
67284c3d67SSandrine Bailleux 	MAP_DEVICE2,
68284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
693e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
703e4b8fdcSSoby Mathew #endif
713e4b8fdcSSoby Mathew 	{0}
723e4b8fdcSSoby Mathew };
733e4b8fdcSSoby Mathew #endif
743d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
753e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
763e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
773e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
783e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
793e4b8fdcSSoby Mathew 	MAP_DEVICE0,
803e4b8fdcSSoby Mathew 	MAP_DEVICE1,
813e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
823e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
83284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
84284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
85284c3d67SSandrine Bailleux 	MAP_DEVICE2,
86284c3d67SSandrine Bailleux #endif
873e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
883e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
893e4b8fdcSSoby Mathew #endif
903e4b8fdcSSoby Mathew 	{0}
913e4b8fdcSSoby Mathew };
923e4b8fdcSSoby Mathew #endif
933d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
943e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
953e4b8fdcSSoby Mathew 	MAP_DEVICE0,
963e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
973e4b8fdcSSoby Mathew 	{0}
983e4b8fdcSSoby Mathew };
993e4b8fdcSSoby Mathew #endif
1003d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
1013e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1023e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
1033e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1043e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1053e4b8fdcSSoby Mathew 	MAP_DEVICE1,
1063e4b8fdcSSoby Mathew 	{0}
1073e4b8fdcSSoby Mathew };
1083e4b8fdcSSoby Mathew #endif
1093d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
1103e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
111877cf3ffSSoby Mathew #ifdef AARCH32
112877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
113877cf3ffSSoby Mathew #endif
1143e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1153e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1163e4b8fdcSSoby Mathew 	MAP_DEVICE1,
1173e4b8fdcSSoby Mathew 	{0}
1183e4b8fdcSSoby Mathew };
1193e4b8fdcSSoby Mathew #endif
1203e4b8fdcSSoby Mathew 
1213e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
1223e4b8fdcSSoby Mathew 
123*955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN
124*955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = {
125*955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS0_SL_PORT,
126*955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS1_SL_PORT,
127*955242d8SJeenu Viswambharan };
128*955242d8SJeenu Viswambharan 
129*955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = {
130*955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
131*955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
132*955242d8SJeenu Viswambharan };
133*955242d8SJeenu Viswambharan 
134*955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void)
135*955242d8SJeenu Viswambharan {
136*955242d8SJeenu Viswambharan 	unsigned int master;
137*955242d8SJeenu Viswambharan 	u_register_t mpidr;
138*955242d8SJeenu Viswambharan 
139*955242d8SJeenu Viswambharan 	mpidr = read_mpidr_el1();
140*955242d8SJeenu Viswambharan 	master = (arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) ?
141*955242d8SJeenu Viswambharan 		MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
142*955242d8SJeenu Viswambharan 
143*955242d8SJeenu Viswambharan 	assert(master < FVP_CLUSTER_COUNT);
144*955242d8SJeenu Viswambharan 	return master;
145*955242d8SJeenu Viswambharan }
146*955242d8SJeenu Viswambharan #endif
1473e4b8fdcSSoby Mathew 
1483e4b8fdcSSoby Mathew /*******************************************************************************
1493e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
1503e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
1513e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
1523e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
1533e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
1543e4b8fdcSSoby Mathew  ******************************************************************************/
1553e4b8fdcSSoby Mathew void fvp_config_setup(void)
1563e4b8fdcSSoby Mathew {
1573e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
1583e4b8fdcSSoby Mathew 
1593e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
1603e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
1613e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
1623e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
1633e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
1643e4b8fdcSSoby Mathew 
1653e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
1663e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
1673e4b8fdcSSoby Mathew 		panic();
1683e4b8fdcSSoby Mathew 	}
1693e4b8fdcSSoby Mathew 
1703e4b8fdcSSoby Mathew 	/*
1713e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
1723e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
1733e4b8fdcSSoby Mathew 	 */
1743e4b8fdcSSoby Mathew 	switch (bld) {
1753e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
17621a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
17721a3973dSSoby Mathew 				" is not supported\n");
1783e4b8fdcSSoby Mathew 		panic();
1793e4b8fdcSSoby Mathew 		break;
1803e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
1813e4b8fdcSSoby Mathew 		break;
1823e4b8fdcSSoby Mathew 	default:
1833e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
1843e4b8fdcSSoby Mathew 		panic();
1853e4b8fdcSSoby Mathew 	}
1863e4b8fdcSSoby Mathew 
1873e4b8fdcSSoby Mathew 	/*
1883e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
1893e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
1903e4b8fdcSSoby Mathew 	 */
1913e4b8fdcSSoby Mathew 	switch (hbi) {
1923e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
1933e4b8fdcSSoby Mathew 		arm_config.flags = 0;
1943e4b8fdcSSoby Mathew 
1953e4b8fdcSSoby Mathew 		/*
1963e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
1973e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
1983e4b8fdcSSoby Mathew 		 */
1993e4b8fdcSSoby Mathew 		switch (rev) {
2003e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
2013e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
2023e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
2034faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
2043e4b8fdcSSoby Mathew 			break;
2053e4b8fdcSSoby Mathew 		default:
2063e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
2073e4b8fdcSSoby Mathew 			break;
2083e4b8fdcSSoby Mathew 		}
2093e4b8fdcSSoby Mathew 		break;
2103e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
211*955242d8SJeenu Viswambharan 		arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
2123e4b8fdcSSoby Mathew 
2133e4b8fdcSSoby Mathew 		/*
2143e4b8fdcSSoby Mathew 		 * Check for supported revisions
2153e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
2163e4b8fdcSSoby Mathew 		 */
2173e4b8fdcSSoby Mathew 		switch (rev) {
2183e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
219*955242d8SJeenu Viswambharan 			arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
220*955242d8SJeenu Viswambharan 			break;
221*955242d8SJeenu Viswambharan 		case REV_BASE_FVP_REVC:
222*955242d8SJeenu Viswambharan 			arm_config.flags |= (ARM_CONFIG_FVP_SHIFTED_AFF |
223*955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_SMMUV3 |
224*955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_CCI5XX);
2253e4b8fdcSSoby Mathew 			break;
2263e4b8fdcSSoby Mathew 		default:
2273e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
2283e4b8fdcSSoby Mathew 			break;
2293e4b8fdcSSoby Mathew 		}
2303e4b8fdcSSoby Mathew 		break;
2313e4b8fdcSSoby Mathew 	default:
2323e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
2333e4b8fdcSSoby Mathew 		panic();
2343e4b8fdcSSoby Mathew 	}
2353e4b8fdcSSoby Mathew }
2363e4b8fdcSSoby Mathew 
2373e4b8fdcSSoby Mathew 
2383e4b8fdcSSoby Mathew void fvp_interconnect_init(void)
2393e4b8fdcSSoby Mathew {
24071237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
24171237876SSoby Mathew 	if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
24271237876SSoby Mathew 		ERROR("Unrecognized CCN variant detected. Only CCN-502"
24371237876SSoby Mathew 				" is supported");
24471237876SSoby Mathew 		panic();
24571237876SSoby Mathew 	}
246*955242d8SJeenu Viswambharan 
2473e4b8fdcSSoby Mathew 	plat_arm_interconnect_init();
248*955242d8SJeenu Viswambharan #else
249*955242d8SJeenu Viswambharan 	uintptr_t cci_base = 0;
250*955242d8SJeenu Viswambharan 	const int *cci_map = 0;
251*955242d8SJeenu Viswambharan 	unsigned int map_size = 0;
252*955242d8SJeenu Viswambharan 
253*955242d8SJeenu Viswambharan 	if (!(arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
254*955242d8SJeenu Viswambharan 				ARM_CONFIG_FVP_HAS_CCI5XX))) {
255*955242d8SJeenu Viswambharan 		return;
2563e4b8fdcSSoby Mathew 	}
257*955242d8SJeenu Viswambharan 
258*955242d8SJeenu Viswambharan 	/* Initialize the right interconnect */
259*955242d8SJeenu Viswambharan 	if (arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) {
260*955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI5XX_BASE;
261*955242d8SJeenu Viswambharan 		cci_map = fvp_cci5xx_map;
262*955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci5xx_map);
263*955242d8SJeenu Viswambharan 	} else if (arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) {
264*955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI400_BASE;
265*955242d8SJeenu Viswambharan 		cci_map = fvp_cci400_map;
266*955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci400_map);
267*955242d8SJeenu Viswambharan 	}
268*955242d8SJeenu Viswambharan 
269*955242d8SJeenu Viswambharan 	assert(cci_base);
270*955242d8SJeenu Viswambharan 	assert(cci_map);
271*955242d8SJeenu Viswambharan 	cci_init(cci_base, cci_map, map_size);
272*955242d8SJeenu Viswambharan #endif
27371237876SSoby Mathew }
2743e4b8fdcSSoby Mathew 
2753e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
2763e4b8fdcSSoby Mathew {
277*955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
2783e4b8fdcSSoby Mathew 	plat_arm_interconnect_enter_coherency();
279*955242d8SJeenu Viswambharan #else
280*955242d8SJeenu Viswambharan 	unsigned int master;
281*955242d8SJeenu Viswambharan 
282*955242d8SJeenu Viswambharan 	if (arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
283*955242d8SJeenu Viswambharan 				ARM_CONFIG_FVP_HAS_CCI5XX)) {
284*955242d8SJeenu Viswambharan 		master = get_interconnect_master();
285*955242d8SJeenu Viswambharan 		cci_enable_snoop_dvm_reqs(master);
286*955242d8SJeenu Viswambharan 	}
287*955242d8SJeenu Viswambharan #endif
2883e4b8fdcSSoby Mathew }
2893e4b8fdcSSoby Mathew 
2903e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
2913e4b8fdcSSoby Mathew {
292*955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
2933e4b8fdcSSoby Mathew 	plat_arm_interconnect_exit_coherency();
294*955242d8SJeenu Viswambharan #else
295*955242d8SJeenu Viswambharan 	unsigned int master;
296*955242d8SJeenu Viswambharan 
297*955242d8SJeenu Viswambharan 	if (arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
298*955242d8SJeenu Viswambharan 				ARM_CONFIG_FVP_HAS_CCI5XX)) {
299*955242d8SJeenu Viswambharan 		master = get_interconnect_master();
300*955242d8SJeenu Viswambharan 		cci_disable_snoop_dvm_reqs(master);
301*955242d8SJeenu Viswambharan 	}
302*955242d8SJeenu Viswambharan #endif
3033e4b8fdcSSoby Mathew }
304