xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 992f091b5de3b0837c95a338a4e739f6ca2f254f)
13e4b8fdcSSoby Mathew /*
28855e52eSAntonio Nino Diaz  * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
33e4b8fdcSSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
53e4b8fdcSSoby Mathew  */
63e4b8fdcSSoby Mathew 
709d40e0eSAntonio Nino Diaz #include <assert.h>
809d40e0eSAntonio Nino Diaz 
909d40e0eSAntonio Nino Diaz #include <common/debug.h>
1009d40e0eSAntonio Nino Diaz #include <drivers/arm/cci.h>
1109d40e0eSAntonio Nino Diaz #include <drivers/arm/ccn.h>
1209d40e0eSAntonio Nino Diaz #include <drivers/arm/gicv2.h>
131b597c22SAlexei Fedorov #include <drivers/arm/sp804_delay_timer.h>
141b597c22SAlexei Fedorov #include <drivers/generic_delay_timer.h>
1509d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
1609d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h>
17bd9344f6SAntonio Nino Diaz #include <plat/arm/common/arm_config.h>
18bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h>
1909d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
20234bc7f8SAntonio Nino Diaz #include <platform_def.h>
2109d40e0eSAntonio Nino Diaz #include <services/secure_partition.h>
2209d40e0eSAntonio Nino Diaz 
231af540efSRoberto Vargas #include "fvp_private.h"
243e4b8fdcSSoby Mathew 
253e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
263e4b8fdcSSoby Mathew #define FVP_GICV2		1
273e4b8fdcSSoby Mathew #define FVP_GICV3		2
283e4b8fdcSSoby Mathew 
293e4b8fdcSSoby Mathew /*******************************************************************************
303e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
313e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
323e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
333e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
343e4b8fdcSSoby Mathew  * to allow independent operation.
353e4b8fdcSSoby Mathew  ******************************************************************************/
363e4b8fdcSSoby Mathew arm_config_t arm_config;
373e4b8fdcSSoby Mathew 
383e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
393e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
403e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
413e4b8fdcSSoby Mathew 
423e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
433e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
443e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
453e4b8fdcSSoby Mathew 
46284c3d67SSandrine Bailleux /*
47284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
48284c3d67SSandrine Bailleux  * counter value.
49284c3d67SSandrine Bailleux  */
503e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
513e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
52fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
533e4b8fdcSSoby Mathew 
543e4b8fdcSSoby Mathew /*
55b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
560916c38dSRoberto Vargas  * This doesn't include Trusted SRAM as setup_page_tables() already takes care
570916c38dSRoberto Vargas  * of mapping it.
5891fad655SSandrine Bailleux  *
5991fad655SSandrine Bailleux  * The flash needs to be mapped as writable in order to erase the FIP's Table of
6091fad655SSandrine Bailleux  * Contents in case of unrecoverable error (see plat_error_handler()).
613e4b8fdcSSoby Mathew  */
623d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
633e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
643e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
653e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
663e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
673e4b8fdcSSoby Mathew 	MAP_DEVICE0,
683e4b8fdcSSoby Mathew 	MAP_DEVICE1,
693e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
70284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
71284c3d67SSandrine Bailleux 	MAP_DEVICE2,
72284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
733e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
743e4b8fdcSSoby Mathew #endif
753e4b8fdcSSoby Mathew 	{0}
763e4b8fdcSSoby Mathew };
773e4b8fdcSSoby Mathew #endif
783d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
793e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
803e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
813e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
823e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
833e4b8fdcSSoby Mathew 	MAP_DEVICE0,
843e4b8fdcSSoby Mathew 	MAP_DEVICE1,
853e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
86402b3cf8SJulius Werner #ifdef __aarch64__
87b09ba056SRoberto Vargas 	ARM_MAP_DRAM2,
88b09ba056SRoberto Vargas #endif
893eb2d672SSandrine Bailleux #ifdef SPD_tspd
903e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
913eb2d672SSandrine Bailleux #endif
92284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
93284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
94284c3d67SSandrine Bailleux 	MAP_DEVICE2,
9560e19f57SAntonio Nino Diaz #if !BL2_AT_EL3
96ba597da7SJohn Tsichritzis 	ARM_MAP_BL1_RW,
9760e19f57SAntonio Nino Diaz #endif
98ba597da7SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */
998855e52eSAntonio Nino Diaz #if ENABLE_SPM && SPM_MM
100e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
101e29efeb1SAntonio Nino Diaz #endif
1028855e52eSAntonio Nino Diaz #if ENABLE_SPM && !SPM_MM
103680389a6SAntonio Nino Diaz 	PLAT_MAP_SP_PACKAGE_MEM_RW,
104680389a6SAntonio Nino Diaz #endif
1053e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
1063e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
1073e4b8fdcSSoby Mathew #endif
108810d9213SJens Wiklander #ifdef SPD_opteed
109b3ba6fdaSSoby Mathew 	ARM_MAP_OPTEE_CORE_MEM,
110810d9213SJens Wiklander 	ARM_OPTEE_PAGEABLE_LOAD_MEM,
111810d9213SJens Wiklander #endif
1123e4b8fdcSSoby Mathew 	{0}
1133e4b8fdcSSoby Mathew };
1143e4b8fdcSSoby Mathew #endif
1153d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
1163e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1173e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1183e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1193e4b8fdcSSoby Mathew 	{0}
1203e4b8fdcSSoby Mathew };
1213e4b8fdcSSoby Mathew #endif
1223d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
1233e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1243e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
125*992f091bSAmbroise Vincent #if USE_DEBUGFS
126*992f091bSAmbroise Vincent 	/* Required by devfip, can be removed if devfip is not used */
127*992f091bSAmbroise Vincent 	V2M_MAP_FLASH0_RW,
128*992f091bSAmbroise Vincent #endif /* USE_DEBUGFS */
129e35a3fb5SSoby Mathew 	ARM_MAP_EL3_TZC_DRAM,
1303e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1313e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1323e4b8fdcSSoby Mathew 	MAP_DEVICE1,
133f145403cSRoberto Vargas 	ARM_V2M_MAP_MEM_PROTECT,
1348855e52eSAntonio Nino Diaz #if ENABLE_SPM && SPM_MM
135e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL3_MMAP,
136e29efeb1SAntonio Nino Diaz #endif
1378855e52eSAntonio Nino Diaz #if ENABLE_SPM && !SPM_MM
138680389a6SAntonio Nino Diaz 	PLAT_MAP_SP_PACKAGE_MEM_RO,
139680389a6SAntonio Nino Diaz #endif
1403e4b8fdcSSoby Mathew 	{0}
1413e4b8fdcSSoby Mathew };
142e29efeb1SAntonio Nino Diaz 
1438855e52eSAntonio Nino Diaz #if ENABLE_SPM && defined(IMAGE_BL31) && SPM_MM
144e29efeb1SAntonio Nino Diaz const mmap_region_t plat_arm_secure_partition_mmap[] = {
145e29efeb1SAntonio Nino Diaz 	V2M_MAP_IOFPGA_EL0, /* for the UART */
146c4fa1739SSandrine Bailleux 	MAP_REGION_FLAT(DEVICE0_BASE,				\
147c4fa1739SSandrine Bailleux 			DEVICE0_SIZE,				\
148c4fa1739SSandrine Bailleux 			MT_DEVICE | MT_RO | MT_SECURE | MT_USER),
149e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
150e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_NS_BUF_MMAP,
151e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_RW_MMAP,
152e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL0_MMAP,
153e29efeb1SAntonio Nino Diaz 	{0}
154e29efeb1SAntonio Nino Diaz };
155e29efeb1SAntonio Nino Diaz #endif
1563e4b8fdcSSoby Mathew #endif
1573d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
1583e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
159402b3cf8SJulius Werner #ifndef __aarch64__
160877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
161950c6956SJoel Hutton 	ARM_V2M_MAP_MEM_PROTECT,
162877cf3ffSSoby Mathew #endif
1633e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1643e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1653e4b8fdcSSoby Mathew 	MAP_DEVICE1,
1663e4b8fdcSSoby Mathew 	{0}
1673e4b8fdcSSoby Mathew };
1683e4b8fdcSSoby Mathew #endif
1693e4b8fdcSSoby Mathew 
1703e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
1713e4b8fdcSSoby Mathew 
172955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN
173955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = {
174955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS0_SL_PORT,
175955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS1_SL_PORT,
176955242d8SJeenu Viswambharan };
177955242d8SJeenu Viswambharan 
178955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = {
179955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
180955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
181955242d8SJeenu Viswambharan };
182955242d8SJeenu Viswambharan 
183955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void)
184955242d8SJeenu Viswambharan {
185955242d8SJeenu Viswambharan 	unsigned int master;
186955242d8SJeenu Viswambharan 	u_register_t mpidr;
187955242d8SJeenu Viswambharan 
188955242d8SJeenu Viswambharan 	mpidr = read_mpidr_el1();
189583e0791SAntonio Nino Diaz 	master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
190955242d8SJeenu Viswambharan 		MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
191955242d8SJeenu Viswambharan 
192955242d8SJeenu Viswambharan 	assert(master < FVP_CLUSTER_COUNT);
193955242d8SJeenu Viswambharan 	return master;
194955242d8SJeenu Viswambharan }
195955242d8SJeenu Viswambharan #endif
1963e4b8fdcSSoby Mathew 
1978855e52eSAntonio Nino Diaz #if ENABLE_SPM && defined(IMAGE_BL31) && SPM_MM
198e29efeb1SAntonio Nino Diaz /*
199e29efeb1SAntonio Nino Diaz  * Boot information passed to a secure partition during initialisation. Linear
200e29efeb1SAntonio Nino Diaz  * indices in MP information will be filled at runtime.
201e29efeb1SAntonio Nino Diaz  */
202e29efeb1SAntonio Nino Diaz static secure_partition_mp_info_t sp_mp_info[] = {
203e29efeb1SAntonio Nino Diaz 	[0] = {0x80000000, 0},
204e29efeb1SAntonio Nino Diaz 	[1] = {0x80000001, 0},
205e29efeb1SAntonio Nino Diaz 	[2] = {0x80000002, 0},
206e29efeb1SAntonio Nino Diaz 	[3] = {0x80000003, 0},
207e29efeb1SAntonio Nino Diaz 	[4] = {0x80000100, 0},
208e29efeb1SAntonio Nino Diaz 	[5] = {0x80000101, 0},
209e29efeb1SAntonio Nino Diaz 	[6] = {0x80000102, 0},
210e29efeb1SAntonio Nino Diaz 	[7] = {0x80000103, 0},
211e29efeb1SAntonio Nino Diaz };
212e29efeb1SAntonio Nino Diaz 
213e29efeb1SAntonio Nino Diaz const secure_partition_boot_info_t plat_arm_secure_partition_boot_info = {
214e29efeb1SAntonio Nino Diaz 	.h.type              = PARAM_SP_IMAGE_BOOT_INFO,
215e29efeb1SAntonio Nino Diaz 	.h.version           = VERSION_1,
216e29efeb1SAntonio Nino Diaz 	.h.size              = sizeof(secure_partition_boot_info_t),
217e29efeb1SAntonio Nino Diaz 	.h.attr              = 0,
218e29efeb1SAntonio Nino Diaz 	.sp_mem_base         = ARM_SP_IMAGE_BASE,
219e29efeb1SAntonio Nino Diaz 	.sp_mem_limit        = ARM_SP_IMAGE_LIMIT,
220e29efeb1SAntonio Nino Diaz 	.sp_image_base       = ARM_SP_IMAGE_BASE,
221e29efeb1SAntonio Nino Diaz 	.sp_stack_base       = PLAT_SP_IMAGE_STACK_BASE,
222e29efeb1SAntonio Nino Diaz 	.sp_heap_base        = ARM_SP_IMAGE_HEAP_BASE,
2230560efb9SArd Biesheuvel 	.sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE,
224e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_base  = PLAT_SPM_BUF_BASE,
225e29efeb1SAntonio Nino Diaz 	.sp_image_size       = ARM_SP_IMAGE_SIZE,
226e29efeb1SAntonio Nino Diaz 	.sp_pcpu_stack_size  = PLAT_SP_IMAGE_STACK_PCPU_SIZE,
227e29efeb1SAntonio Nino Diaz 	.sp_heap_size        = ARM_SP_IMAGE_HEAP_SIZE,
2280560efb9SArd Biesheuvel 	.sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE,
229e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_size  = PLAT_SPM_BUF_SIZE,
230e29efeb1SAntonio Nino Diaz 	.num_sp_mem_regions  = ARM_SP_IMAGE_NUM_MEM_REGIONS,
231e29efeb1SAntonio Nino Diaz 	.num_cpus            = PLATFORM_CORE_COUNT,
232e29efeb1SAntonio Nino Diaz 	.mp_info             = &sp_mp_info[0],
233e29efeb1SAntonio Nino Diaz };
234e29efeb1SAntonio Nino Diaz 
235e29efeb1SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie)
236e29efeb1SAntonio Nino Diaz {
237e29efeb1SAntonio Nino Diaz 	return plat_arm_secure_partition_mmap;
238e29efeb1SAntonio Nino Diaz }
239e29efeb1SAntonio Nino Diaz 
240e29efeb1SAntonio Nino Diaz const struct secure_partition_boot_info *plat_get_secure_partition_boot_info(
241e29efeb1SAntonio Nino Diaz 		void *cookie)
242e29efeb1SAntonio Nino Diaz {
243e29efeb1SAntonio Nino Diaz 	return &plat_arm_secure_partition_boot_info;
244e29efeb1SAntonio Nino Diaz }
245e29efeb1SAntonio Nino Diaz #endif
246e29efeb1SAntonio Nino Diaz 
2473e4b8fdcSSoby Mathew /*******************************************************************************
2483e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
2493e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
2503e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
2513e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
2523e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
2533e4b8fdcSSoby Mathew  ******************************************************************************/
2544d010d0dSDaniel Boulby void __init fvp_config_setup(void)
2553e4b8fdcSSoby Mathew {
2563e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
2573e4b8fdcSSoby Mathew 
2583e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
2593e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
2603e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
2613e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
2623e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
2633e4b8fdcSSoby Mathew 
2643e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
2653e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
2663e4b8fdcSSoby Mathew 		panic();
2673e4b8fdcSSoby Mathew 	}
2683e4b8fdcSSoby Mathew 
2693e4b8fdcSSoby Mathew 	/*
2703e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
2713e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
2723e4b8fdcSSoby Mathew 	 */
2733e4b8fdcSSoby Mathew 	switch (bld) {
2743e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
27521a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
27621a3973dSSoby Mathew 				" is not supported\n");
2773e4b8fdcSSoby Mathew 		panic();
2783e4b8fdcSSoby Mathew 		break;
2793e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
2803e4b8fdcSSoby Mathew 		break;
2813e4b8fdcSSoby Mathew 	default:
2823e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
2833e4b8fdcSSoby Mathew 		panic();
2843e4b8fdcSSoby Mathew 	}
2853e4b8fdcSSoby Mathew 
2863e4b8fdcSSoby Mathew 	/*
2873e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
2883e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
2893e4b8fdcSSoby Mathew 	 */
2903e4b8fdcSSoby Mathew 	switch (hbi) {
2913e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
2923e4b8fdcSSoby Mathew 		arm_config.flags = 0;
2933e4b8fdcSSoby Mathew 
2943e4b8fdcSSoby Mathew 		/*
2953e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
2963e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
2973e4b8fdcSSoby Mathew 		 */
2983e4b8fdcSSoby Mathew 		switch (rev) {
2993e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
3003e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
3013e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
3024faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
3033e4b8fdcSSoby Mathew 			break;
3043e4b8fdcSSoby Mathew 		default:
3053e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
3063e4b8fdcSSoby Mathew 			break;
3073e4b8fdcSSoby Mathew 		}
3083e4b8fdcSSoby Mathew 		break;
3093e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
310955242d8SJeenu Viswambharan 		arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
3113e4b8fdcSSoby Mathew 
3123e4b8fdcSSoby Mathew 		/*
3133e4b8fdcSSoby Mathew 		 * Check for supported revisions
3143e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
3153e4b8fdcSSoby Mathew 		 */
3163e4b8fdcSSoby Mathew 		switch (rev) {
3173e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
318955242d8SJeenu Viswambharan 			arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
319955242d8SJeenu Viswambharan 			break;
320955242d8SJeenu Viswambharan 		case REV_BASE_FVP_REVC:
3218431635bSIsla Mitchell 			arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 |
322955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_CCI5XX);
3233e4b8fdcSSoby Mathew 			break;
3243e4b8fdcSSoby Mathew 		default:
3253e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
3263e4b8fdcSSoby Mathew 			break;
3273e4b8fdcSSoby Mathew 		}
3283e4b8fdcSSoby Mathew 		break;
3293e4b8fdcSSoby Mathew 	default:
3303e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
3313e4b8fdcSSoby Mathew 		panic();
3323e4b8fdcSSoby Mathew 	}
3338431635bSIsla Mitchell 
3348431635bSIsla Mitchell 	/*
3358431635bSIsla Mitchell 	 * We assume that the presence of MT bit, and therefore shifted
3368431635bSIsla Mitchell 	 * affinities, is uniform across the platform: either all CPUs, or no
3378431635bSIsla Mitchell 	 * CPUs implement it.
3388431635bSIsla Mitchell 	 */
339583e0791SAntonio Nino Diaz 	if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U)
3408431635bSIsla Mitchell 		arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
3413e4b8fdcSSoby Mathew }
3423e4b8fdcSSoby Mathew 
3433e4b8fdcSSoby Mathew 
3444d010d0dSDaniel Boulby void __init fvp_interconnect_init(void)
3453e4b8fdcSSoby Mathew {
34671237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
34771237876SSoby Mathew 	if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
348583e0791SAntonio Nino Diaz 		ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
34971237876SSoby Mathew 		panic();
35071237876SSoby Mathew 	}
351955242d8SJeenu Viswambharan 
3523e4b8fdcSSoby Mathew 	plat_arm_interconnect_init();
353955242d8SJeenu Viswambharan #else
354583e0791SAntonio Nino Diaz 	uintptr_t cci_base = 0U;
355583e0791SAntonio Nino Diaz 	const int *cci_map = NULL;
356583e0791SAntonio Nino Diaz 	unsigned int map_size = 0U;
357955242d8SJeenu Viswambharan 
358955242d8SJeenu Viswambharan 	/* Initialize the right interconnect */
359583e0791SAntonio Nino Diaz 	if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
360955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI5XX_BASE;
361955242d8SJeenu Viswambharan 		cci_map = fvp_cci5xx_map;
362955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci5xx_map);
363583e0791SAntonio Nino Diaz 	} else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
364955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI400_BASE;
365955242d8SJeenu Viswambharan 		cci_map = fvp_cci400_map;
366955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci400_map);
367583e0791SAntonio Nino Diaz 	} else {
368583e0791SAntonio Nino Diaz 		return;
369955242d8SJeenu Viswambharan 	}
370955242d8SJeenu Viswambharan 
371583e0791SAntonio Nino Diaz 	assert(cci_base != 0U);
372583e0791SAntonio Nino Diaz 	assert(cci_map != NULL);
373955242d8SJeenu Viswambharan 	cci_init(cci_base, cci_map, map_size);
374955242d8SJeenu Viswambharan #endif
37571237876SSoby Mathew }
3763e4b8fdcSSoby Mathew 
3773e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
3783e4b8fdcSSoby Mathew {
379955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
3803e4b8fdcSSoby Mathew 	plat_arm_interconnect_enter_coherency();
381955242d8SJeenu Viswambharan #else
382955242d8SJeenu Viswambharan 	unsigned int master;
383955242d8SJeenu Viswambharan 
384583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
385583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
386955242d8SJeenu Viswambharan 		master = get_interconnect_master();
387955242d8SJeenu Viswambharan 		cci_enable_snoop_dvm_reqs(master);
388955242d8SJeenu Viswambharan 	}
389955242d8SJeenu Viswambharan #endif
3903e4b8fdcSSoby Mathew }
3913e4b8fdcSSoby Mathew 
3923e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
3933e4b8fdcSSoby Mathew {
394955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
3953e4b8fdcSSoby Mathew 	plat_arm_interconnect_exit_coherency();
396955242d8SJeenu Viswambharan #else
397955242d8SJeenu Viswambharan 	unsigned int master;
398955242d8SJeenu Viswambharan 
399583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
400583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
401955242d8SJeenu Viswambharan 		master = get_interconnect_master();
402955242d8SJeenu Viswambharan 		cci_disable_snoop_dvm_reqs(master);
403955242d8SJeenu Viswambharan 	}
404955242d8SJeenu Viswambharan #endif
4053e4b8fdcSSoby Mathew }
406ba597da7SJohn Tsichritzis 
40760e19f57SAntonio Nino Diaz #if TRUSTED_BOARD_BOOT
408ba597da7SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
409ba597da7SJohn Tsichritzis {
410ba597da7SJohn Tsichritzis 	assert(heap_addr != NULL);
411ba597da7SJohn Tsichritzis 	assert(heap_size != NULL);
412ba597da7SJohn Tsichritzis 
413ba597da7SJohn Tsichritzis 	return arm_get_mbedtls_heap(heap_addr, heap_size);
414ba597da7SJohn Tsichritzis }
415ba597da7SJohn Tsichritzis #endif
4161b597c22SAlexei Fedorov 
4171b597c22SAlexei Fedorov void fvp_timer_init(void)
4181b597c22SAlexei Fedorov {
4191b597c22SAlexei Fedorov #if FVP_USE_SP804_TIMER
4201b597c22SAlexei Fedorov 	/* Enable the clock override for SP804 timer 0, which means that no
4211b597c22SAlexei Fedorov 	 * clock dividers are applied and the raw (35MHz) clock will be used.
4221b597c22SAlexei Fedorov 	 */
4231b597c22SAlexei Fedorov 	mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV);
4241b597c22SAlexei Fedorov 
4251b597c22SAlexei Fedorov 	/* Initialize delay timer driver using SP804 dual timer 0 */
4261b597c22SAlexei Fedorov 	sp804_timer_init(V2M_SP804_TIMER0_BASE,
4271b597c22SAlexei Fedorov 			SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
4281b597c22SAlexei Fedorov #else
4291b597c22SAlexei Fedorov 	generic_delay_timer_init();
4301b597c22SAlexei Fedorov 
4311b597c22SAlexei Fedorov 	/* Enable System level generic timer */
4321b597c22SAlexei Fedorov 	mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
4331b597c22SAlexei Fedorov 			CNTCR_FCREQ(0U) | CNTCR_EN);
4341b597c22SAlexei Fedorov #endif /* FVP_USE_SP804_TIMER */
4351b597c22SAlexei Fedorov }
436