xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 9d870b79c16ef09b0c4a9db18e071c2fa235d1ad)
13e4b8fdcSSoby Mathew /*
2e0cea783SManish V Badarkhe  * Copyright (c) 2013-2021, 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>
16ed9653ffSManish V Badarkhe #include <lib/smccc.h>
1709d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h>
18234bc7f8SAntonio Nino Diaz #include <platform_def.h>
19ed9653ffSManish V Badarkhe #include <services/arm_arch_svc.h>
209d9ae976SOlivier Deprez #if SPM_MM
21aeaa225cSPaul Beesley #include <services/spm_mm_partition.h>
229d9ae976SOlivier Deprez #endif
2309d40e0eSAntonio Nino Diaz 
24ed9653ffSManish V Badarkhe #include <plat/arm/common/arm_config.h>
25ed9653ffSManish V Badarkhe #include <plat/arm/common/plat_arm.h>
26ed9653ffSManish V Badarkhe #include <plat/common/platform.h>
27ed9653ffSManish V Badarkhe 
281af540efSRoberto Vargas #include "fvp_private.h"
293e4b8fdcSSoby Mathew 
303e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
313e4b8fdcSSoby Mathew #define FVP_GICV2		1
323e4b8fdcSSoby Mathew #define FVP_GICV3		2
333e4b8fdcSSoby Mathew 
343e4b8fdcSSoby Mathew /*******************************************************************************
353e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
363e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
373e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
383e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
393e4b8fdcSSoby Mathew  * to allow independent operation.
403e4b8fdcSSoby Mathew  ******************************************************************************/
413e4b8fdcSSoby Mathew arm_config_t arm_config;
423e4b8fdcSSoby Mathew 
433e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
443e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
453e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
463e4b8fdcSSoby Mathew 
473e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
483e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
493e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
503e4b8fdcSSoby Mathew 
51f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
52f98630fbSManish V Badarkhe #define MAP_GICD_MEM	MAP_REGION_FLAT(BASE_GICD_BASE,			\
53f98630fbSManish V Badarkhe 					BASE_GICD_SIZE,			\
54f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RW | MT_SECURE)
55f98630fbSManish V Badarkhe 
56f98630fbSManish V Badarkhe /* Map all core's redistributor memory as read-only. After boots up,
57f98630fbSManish V Badarkhe  * per-core map its redistributor memory as read-write */
58f98630fbSManish V Badarkhe #define MAP_GICR_MEM	MAP_REGION_FLAT(BASE_GICR_BASE,			\
59f98630fbSManish V Badarkhe 					(BASE_GICR_SIZE * PLATFORM_CORE_COUNT),\
60f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RO | MT_SECURE)
61f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
62f98630fbSManish V Badarkhe 
63284c3d67SSandrine Bailleux /*
64284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
65284c3d67SSandrine Bailleux  * counter value.
66284c3d67SSandrine Bailleux  */
673e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
683e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
69fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
703e4b8fdcSSoby Mathew 
713e4b8fdcSSoby Mathew /*
72b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
730916c38dSRoberto Vargas  * This doesn't include Trusted SRAM as setup_page_tables() already takes care
740916c38dSRoberto Vargas  * of mapping it.
753e4b8fdcSSoby Mathew  */
763d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
773e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
783e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
7979d8be3cSManish V Badarkhe 	V2M_MAP_FLASH0_RO,
803e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
813e4b8fdcSSoby Mathew 	MAP_DEVICE0,
82e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
833e4b8fdcSSoby Mathew 	MAP_DEVICE1,
84e0cea783SManish V Badarkhe #endif
853e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
86284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
87284c3d67SSandrine Bailleux 	MAP_DEVICE2,
88284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
893e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
903e4b8fdcSSoby Mathew #endif
913e4b8fdcSSoby Mathew 	{0}
923e4b8fdcSSoby Mathew };
933e4b8fdcSSoby Mathew #endif
943d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
953e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
963e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
973e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
983e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
993e4b8fdcSSoby Mathew 	MAP_DEVICE0,
100e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
1013e4b8fdcSSoby Mathew 	MAP_DEVICE1,
102e0cea783SManish V Badarkhe #endif
1033e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
104402b3cf8SJulius Werner #ifdef __aarch64__
105b09ba056SRoberto Vargas 	ARM_MAP_DRAM2,
106b09ba056SRoberto Vargas #endif
10764758c97SAchin Gupta #if defined(SPD_spmd)
10864758c97SAchin Gupta 	ARM_MAP_TRUSTED_DRAM,
10964758c97SAchin Gupta #endif
1103eb2d672SSandrine Bailleux #ifdef SPD_tspd
1113e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
1123eb2d672SSandrine Bailleux #endif
113284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
114284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
115284c3d67SSandrine Bailleux 	MAP_DEVICE2,
11660e19f57SAntonio Nino Diaz #if !BL2_AT_EL3
117ba597da7SJohn Tsichritzis 	ARM_MAP_BL1_RW,
11860e19f57SAntonio Nino Diaz #endif
119ba597da7SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */
1203f3c341aSPaul Beesley #if SPM_MM
121e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
122e29efeb1SAntonio Nino Diaz #endif
1233e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
1243e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
1253e4b8fdcSSoby Mathew #endif
126810d9213SJens Wiklander #ifdef SPD_opteed
127b3ba6fdaSSoby Mathew 	ARM_MAP_OPTEE_CORE_MEM,
128810d9213SJens Wiklander 	ARM_OPTEE_PAGEABLE_LOAD_MEM,
129810d9213SJens Wiklander #endif
1303e4b8fdcSSoby Mathew 	{0}
1313e4b8fdcSSoby Mathew };
1323e4b8fdcSSoby Mathew #endif
1333d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
1343e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1353e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1363e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1373e4b8fdcSSoby Mathew 	{0}
1383e4b8fdcSSoby Mathew };
1393e4b8fdcSSoby Mathew #endif
1403d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
1413e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1423e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
143992f091bSAmbroise Vincent #if USE_DEBUGFS
144992f091bSAmbroise Vincent 	/* Required by devfip, can be removed if devfip is not used */
145992f091bSAmbroise Vincent 	V2M_MAP_FLASH0_RW,
146992f091bSAmbroise Vincent #endif /* USE_DEBUGFS */
147e35a3fb5SSoby Mathew 	ARM_MAP_EL3_TZC_DRAM,
1483e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1493e4b8fdcSSoby Mathew 	MAP_DEVICE0,
150f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
151f98630fbSManish V Badarkhe 	MAP_GICD_MEM,
152f98630fbSManish V Badarkhe 	MAP_GICR_MEM,
153f98630fbSManish V Badarkhe #else
1543e4b8fdcSSoby Mathew 	MAP_DEVICE1,
155f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
156f145403cSRoberto Vargas 	ARM_V2M_MAP_MEM_PROTECT,
1573f3c341aSPaul Beesley #if SPM_MM
158e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL3_MMAP,
159e29efeb1SAntonio Nino Diaz #endif
16026d1e0c3SMadhukar Pappireddy 	/* Required by fconf APIs to read HW_CONFIG dtb loaded into DRAM */
161493545b3SMadhukar Pappireddy 	ARM_DTB_DRAM_NS,
1623e4b8fdcSSoby Mathew 	{0}
1633e4b8fdcSSoby Mathew };
164e29efeb1SAntonio Nino Diaz 
1653f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
166e29efeb1SAntonio Nino Diaz const mmap_region_t plat_arm_secure_partition_mmap[] = {
167e29efeb1SAntonio Nino Diaz 	V2M_MAP_IOFPGA_EL0, /* for the UART */
168c4fa1739SSandrine Bailleux 	MAP_REGION_FLAT(DEVICE0_BASE,				\
169c4fa1739SSandrine Bailleux 			DEVICE0_SIZE,				\
170c4fa1739SSandrine Bailleux 			MT_DEVICE | MT_RO | MT_SECURE | MT_USER),
171e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
172e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_NS_BUF_MMAP,
173e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_RW_MMAP,
174e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL0_MMAP,
175e29efeb1SAntonio Nino Diaz 	{0}
176e29efeb1SAntonio Nino Diaz };
177e29efeb1SAntonio Nino Diaz #endif
1783e4b8fdcSSoby Mathew #endif
1793d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
1803e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
181402b3cf8SJulius Werner #ifndef __aarch64__
182877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
183950c6956SJoel Hutton 	ARM_V2M_MAP_MEM_PROTECT,
184877cf3ffSSoby Mathew #endif
1853e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1863e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1873e4b8fdcSSoby Mathew 	MAP_DEVICE1,
18826d1e0c3SMadhukar Pappireddy 	/* Required by fconf APIs to read HW_CONFIG dtb loaded into DRAM */
189493545b3SMadhukar Pappireddy 	ARM_DTB_DRAM_NS,
1903e4b8fdcSSoby Mathew 	{0}
1913e4b8fdcSSoby Mathew };
1923e4b8fdcSSoby Mathew #endif
1933e4b8fdcSSoby Mathew 
194*9d870b79SZelalem Aweke #ifdef IMAGE_RMM
195*9d870b79SZelalem Aweke const mmap_region_t plat_arm_mmap[] = {
196*9d870b79SZelalem Aweke 	V2M_MAP_IOFPGA,
197*9d870b79SZelalem Aweke 	MAP_DEVICE0,
198*9d870b79SZelalem Aweke 	MAP_DEVICE1,
199*9d870b79SZelalem Aweke 	{0}
200*9d870b79SZelalem Aweke };
201*9d870b79SZelalem Aweke #endif
202*9d870b79SZelalem Aweke 
2033e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
2043e4b8fdcSSoby Mathew 
205955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN
206955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = {
207955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS0_SL_PORT,
208955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS1_SL_PORT,
209955242d8SJeenu Viswambharan };
210955242d8SJeenu Viswambharan 
211955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = {
212955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
213955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
214955242d8SJeenu Viswambharan };
215955242d8SJeenu Viswambharan 
216955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void)
217955242d8SJeenu Viswambharan {
218955242d8SJeenu Viswambharan 	unsigned int master;
219955242d8SJeenu Viswambharan 	u_register_t mpidr;
220955242d8SJeenu Viswambharan 
221955242d8SJeenu Viswambharan 	mpidr = read_mpidr_el1();
222583e0791SAntonio Nino Diaz 	master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
223955242d8SJeenu Viswambharan 		MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
224955242d8SJeenu Viswambharan 
225955242d8SJeenu Viswambharan 	assert(master < FVP_CLUSTER_COUNT);
226955242d8SJeenu Viswambharan 	return master;
227955242d8SJeenu Viswambharan }
228955242d8SJeenu Viswambharan #endif
2293e4b8fdcSSoby Mathew 
2303f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
231e29efeb1SAntonio Nino Diaz /*
232e29efeb1SAntonio Nino Diaz  * Boot information passed to a secure partition during initialisation. Linear
233e29efeb1SAntonio Nino Diaz  * indices in MP information will be filled at runtime.
234e29efeb1SAntonio Nino Diaz  */
235aeaa225cSPaul Beesley static spm_mm_mp_info_t sp_mp_info[] = {
236e29efeb1SAntonio Nino Diaz 	[0] = {0x80000000, 0},
237e29efeb1SAntonio Nino Diaz 	[1] = {0x80000001, 0},
238e29efeb1SAntonio Nino Diaz 	[2] = {0x80000002, 0},
239e29efeb1SAntonio Nino Diaz 	[3] = {0x80000003, 0},
240e29efeb1SAntonio Nino Diaz 	[4] = {0x80000100, 0},
241e29efeb1SAntonio Nino Diaz 	[5] = {0x80000101, 0},
242e29efeb1SAntonio Nino Diaz 	[6] = {0x80000102, 0},
243e29efeb1SAntonio Nino Diaz 	[7] = {0x80000103, 0},
244e29efeb1SAntonio Nino Diaz };
245e29efeb1SAntonio Nino Diaz 
246aeaa225cSPaul Beesley const spm_mm_boot_info_t plat_arm_secure_partition_boot_info = {
247e29efeb1SAntonio Nino Diaz 	.h.type              = PARAM_SP_IMAGE_BOOT_INFO,
248e29efeb1SAntonio Nino Diaz 	.h.version           = VERSION_1,
249aeaa225cSPaul Beesley 	.h.size              = sizeof(spm_mm_boot_info_t),
250e29efeb1SAntonio Nino Diaz 	.h.attr              = 0,
251e29efeb1SAntonio Nino Diaz 	.sp_mem_base         = ARM_SP_IMAGE_BASE,
252e29efeb1SAntonio Nino Diaz 	.sp_mem_limit        = ARM_SP_IMAGE_LIMIT,
253e29efeb1SAntonio Nino Diaz 	.sp_image_base       = ARM_SP_IMAGE_BASE,
254e29efeb1SAntonio Nino Diaz 	.sp_stack_base       = PLAT_SP_IMAGE_STACK_BASE,
255e29efeb1SAntonio Nino Diaz 	.sp_heap_base        = ARM_SP_IMAGE_HEAP_BASE,
2560560efb9SArd Biesheuvel 	.sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE,
257e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_base  = PLAT_SPM_BUF_BASE,
258e29efeb1SAntonio Nino Diaz 	.sp_image_size       = ARM_SP_IMAGE_SIZE,
259e29efeb1SAntonio Nino Diaz 	.sp_pcpu_stack_size  = PLAT_SP_IMAGE_STACK_PCPU_SIZE,
260e29efeb1SAntonio Nino Diaz 	.sp_heap_size        = ARM_SP_IMAGE_HEAP_SIZE,
2610560efb9SArd Biesheuvel 	.sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE,
262e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_size  = PLAT_SPM_BUF_SIZE,
263e29efeb1SAntonio Nino Diaz 	.num_sp_mem_regions  = ARM_SP_IMAGE_NUM_MEM_REGIONS,
264e29efeb1SAntonio Nino Diaz 	.num_cpus            = PLATFORM_CORE_COUNT,
265e29efeb1SAntonio Nino Diaz 	.mp_info             = &sp_mp_info[0],
266e29efeb1SAntonio Nino Diaz };
267e29efeb1SAntonio Nino Diaz 
268e29efeb1SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie)
269e29efeb1SAntonio Nino Diaz {
270e29efeb1SAntonio Nino Diaz 	return plat_arm_secure_partition_mmap;
271e29efeb1SAntonio Nino Diaz }
272e29efeb1SAntonio Nino Diaz 
273aeaa225cSPaul Beesley const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
274e29efeb1SAntonio Nino Diaz 		void *cookie)
275e29efeb1SAntonio Nino Diaz {
276e29efeb1SAntonio Nino Diaz 	return &plat_arm_secure_partition_boot_info;
277e29efeb1SAntonio Nino Diaz }
278e29efeb1SAntonio Nino Diaz #endif
279e29efeb1SAntonio Nino Diaz 
2803e4b8fdcSSoby Mathew /*******************************************************************************
2813e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
2823e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
2833e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
2843e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
2853e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
2863e4b8fdcSSoby Mathew  ******************************************************************************/
2874d010d0dSDaniel Boulby void __init fvp_config_setup(void)
2883e4b8fdcSSoby Mathew {
2893e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
2903e4b8fdcSSoby Mathew 
2913e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
2923e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
2933e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
2943e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
2953e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
2963e4b8fdcSSoby Mathew 
2973e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
2983e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
2993e4b8fdcSSoby Mathew 		panic();
3003e4b8fdcSSoby Mathew 	}
3013e4b8fdcSSoby Mathew 
3023e4b8fdcSSoby Mathew 	/*
3033e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
3043e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
3053e4b8fdcSSoby Mathew 	 */
3063e4b8fdcSSoby Mathew 	switch (bld) {
3073e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
30821a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
30921a3973dSSoby Mathew 				" is not supported\n");
3103e4b8fdcSSoby Mathew 		panic();
3113e4b8fdcSSoby Mathew 		break;
3123e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
3133e4b8fdcSSoby Mathew 		break;
3143e4b8fdcSSoby Mathew 	default:
3153e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
3163e4b8fdcSSoby Mathew 		panic();
3173e4b8fdcSSoby Mathew 	}
3183e4b8fdcSSoby Mathew 
3193e4b8fdcSSoby Mathew 	/*
3203e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
3213e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
3223e4b8fdcSSoby Mathew 	 */
3233e4b8fdcSSoby Mathew 	switch (hbi) {
3243e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
3253e4b8fdcSSoby Mathew 		arm_config.flags = 0;
3263e4b8fdcSSoby Mathew 
3273e4b8fdcSSoby Mathew 		/*
3283e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
3293e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
3303e4b8fdcSSoby Mathew 		 */
3313e4b8fdcSSoby Mathew 		switch (rev) {
3323e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
3333e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
3343e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
3354faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
3363e4b8fdcSSoby Mathew 			break;
3373e4b8fdcSSoby Mathew 		default:
3383e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
3393e4b8fdcSSoby Mathew 			break;
3403e4b8fdcSSoby Mathew 		}
3413e4b8fdcSSoby Mathew 		break;
3423e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
343955242d8SJeenu Viswambharan 		arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
3443e4b8fdcSSoby Mathew 
3453e4b8fdcSSoby Mathew 		/*
3463e4b8fdcSSoby Mathew 		 * Check for supported revisions
3473e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
3483e4b8fdcSSoby Mathew 		 */
3493e4b8fdcSSoby Mathew 		switch (rev) {
3503e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
351955242d8SJeenu Viswambharan 			arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
352955242d8SJeenu Viswambharan 			break;
353955242d8SJeenu Viswambharan 		case REV_BASE_FVP_REVC:
3548431635bSIsla Mitchell 			arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 |
355955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_CCI5XX);
3563e4b8fdcSSoby Mathew 			break;
3573e4b8fdcSSoby Mathew 		default:
3583e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
3593e4b8fdcSSoby Mathew 			break;
3603e4b8fdcSSoby Mathew 		}
3613e4b8fdcSSoby Mathew 		break;
3623e4b8fdcSSoby Mathew 	default:
3633e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
3643e4b8fdcSSoby Mathew 		panic();
3653e4b8fdcSSoby Mathew 	}
3668431635bSIsla Mitchell 
3678431635bSIsla Mitchell 	/*
3688431635bSIsla Mitchell 	 * We assume that the presence of MT bit, and therefore shifted
3698431635bSIsla Mitchell 	 * affinities, is uniform across the platform: either all CPUs, or no
3708431635bSIsla Mitchell 	 * CPUs implement it.
3718431635bSIsla Mitchell 	 */
372583e0791SAntonio Nino Diaz 	if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U)
3738431635bSIsla Mitchell 		arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
3743e4b8fdcSSoby Mathew }
3753e4b8fdcSSoby Mathew 
3763e4b8fdcSSoby Mathew 
3774d010d0dSDaniel Boulby void __init fvp_interconnect_init(void)
3783e4b8fdcSSoby Mathew {
37971237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
38071237876SSoby Mathew 	if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
381583e0791SAntonio Nino Diaz 		ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
38271237876SSoby Mathew 		panic();
38371237876SSoby Mathew 	}
384955242d8SJeenu Viswambharan 
3853e4b8fdcSSoby Mathew 	plat_arm_interconnect_init();
386955242d8SJeenu Viswambharan #else
387583e0791SAntonio Nino Diaz 	uintptr_t cci_base = 0U;
388583e0791SAntonio Nino Diaz 	const int *cci_map = NULL;
389583e0791SAntonio Nino Diaz 	unsigned int map_size = 0U;
390955242d8SJeenu Viswambharan 
391955242d8SJeenu Viswambharan 	/* Initialize the right interconnect */
392583e0791SAntonio Nino Diaz 	if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
393955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI5XX_BASE;
394955242d8SJeenu Viswambharan 		cci_map = fvp_cci5xx_map;
395955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci5xx_map);
396583e0791SAntonio Nino Diaz 	} else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
397955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI400_BASE;
398955242d8SJeenu Viswambharan 		cci_map = fvp_cci400_map;
399955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci400_map);
400583e0791SAntonio Nino Diaz 	} else {
401583e0791SAntonio Nino Diaz 		return;
402955242d8SJeenu Viswambharan 	}
403955242d8SJeenu Viswambharan 
404583e0791SAntonio Nino Diaz 	assert(cci_base != 0U);
405583e0791SAntonio Nino Diaz 	assert(cci_map != NULL);
406955242d8SJeenu Viswambharan 	cci_init(cci_base, cci_map, map_size);
407955242d8SJeenu Viswambharan #endif
40871237876SSoby Mathew }
4093e4b8fdcSSoby Mathew 
4103e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
4113e4b8fdcSSoby Mathew {
412955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4133e4b8fdcSSoby Mathew 	plat_arm_interconnect_enter_coherency();
414955242d8SJeenu Viswambharan #else
415955242d8SJeenu Viswambharan 	unsigned int master;
416955242d8SJeenu Viswambharan 
417583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
418583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
419955242d8SJeenu Viswambharan 		master = get_interconnect_master();
420955242d8SJeenu Viswambharan 		cci_enable_snoop_dvm_reqs(master);
421955242d8SJeenu Viswambharan 	}
422955242d8SJeenu Viswambharan #endif
4233e4b8fdcSSoby Mathew }
4243e4b8fdcSSoby Mathew 
4253e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
4263e4b8fdcSSoby Mathew {
427955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4283e4b8fdcSSoby Mathew 	plat_arm_interconnect_exit_coherency();
429955242d8SJeenu Viswambharan #else
430955242d8SJeenu Viswambharan 	unsigned int master;
431955242d8SJeenu Viswambharan 
432583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
433583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
434955242d8SJeenu Viswambharan 		master = get_interconnect_master();
435955242d8SJeenu Viswambharan 		cci_disable_snoop_dvm_reqs(master);
436955242d8SJeenu Viswambharan 	}
437955242d8SJeenu Viswambharan #endif
4383e4b8fdcSSoby Mathew }
439ba597da7SJohn Tsichritzis 
44060e19f57SAntonio Nino Diaz #if TRUSTED_BOARD_BOOT
441ba597da7SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
442ba597da7SJohn Tsichritzis {
443ba597da7SJohn Tsichritzis 	assert(heap_addr != NULL);
444ba597da7SJohn Tsichritzis 	assert(heap_size != NULL);
445ba597da7SJohn Tsichritzis 
446ba597da7SJohn Tsichritzis 	return arm_get_mbedtls_heap(heap_addr, heap_size);
447ba597da7SJohn Tsichritzis }
448ba597da7SJohn Tsichritzis #endif
4491b597c22SAlexei Fedorov 
4501b597c22SAlexei Fedorov void fvp_timer_init(void)
4511b597c22SAlexei Fedorov {
452fddfb3baSMadhukar Pappireddy #if USE_SP804_TIMER
4531b597c22SAlexei Fedorov 	/* Enable the clock override for SP804 timer 0, which means that no
4541b597c22SAlexei Fedorov 	 * clock dividers are applied and the raw (35MHz) clock will be used.
4551b597c22SAlexei Fedorov 	 */
4561b597c22SAlexei Fedorov 	mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV);
4571b597c22SAlexei Fedorov 
4581b597c22SAlexei Fedorov 	/* Initialize delay timer driver using SP804 dual timer 0 */
4591b597c22SAlexei Fedorov 	sp804_timer_init(V2M_SP804_TIMER0_BASE,
4601b597c22SAlexei Fedorov 			SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
4611b597c22SAlexei Fedorov #else
4621b597c22SAlexei Fedorov 	generic_delay_timer_init();
4631b597c22SAlexei Fedorov 
4641b597c22SAlexei Fedorov 	/* Enable System level generic timer */
4651b597c22SAlexei Fedorov 	mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
4661b597c22SAlexei Fedorov 			CNTCR_FCREQ(0U) | CNTCR_EN);
467fddfb3baSMadhukar Pappireddy #endif /* USE_SP804_TIMER */
4681b597c22SAlexei Fedorov }
469ed9653ffSManish V Badarkhe 
470ed9653ffSManish V Badarkhe /*****************************************************************************
471ed9653ffSManish V Badarkhe  * plat_is_smccc_feature_available() - This function checks whether SMCCC
472ed9653ffSManish V Badarkhe  *                                     feature is availabile for platform.
473ed9653ffSManish V Badarkhe  * @fid: SMCCC function id
474ed9653ffSManish V Badarkhe  *
475ed9653ffSManish V Badarkhe  * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
476ed9653ffSManish V Badarkhe  * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
477ed9653ffSManish V Badarkhe  *****************************************************************************/
478ed9653ffSManish V Badarkhe int32_t plat_is_smccc_feature_available(u_register_t fid)
479ed9653ffSManish V Badarkhe {
480ed9653ffSManish V Badarkhe 	switch (fid) {
481ed9653ffSManish V Badarkhe 	case SMCCC_ARCH_SOC_ID:
482ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_SUCCESS;
483ed9653ffSManish V Badarkhe 	default:
484ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_NOT_SUPPORTED;
485ed9653ffSManish V Badarkhe 	}
486ed9653ffSManish V Badarkhe }
487ed9653ffSManish V Badarkhe 
488ed9653ffSManish V Badarkhe /* Get SOC version */
489ed9653ffSManish V Badarkhe int32_t plat_get_soc_version(void)
490ed9653ffSManish V Badarkhe {
491ed9653ffSManish V Badarkhe 	return (int32_t)
492dfff4686SYann Gautier 		(SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
493dfff4686SYann Gautier 				    ARM_SOC_IDENTIFICATION_CODE) |
494dfff4686SYann Gautier 		 (FVP_SOC_ID & SOC_ID_IMPL_DEF_MASK));
495ed9653ffSManish V Badarkhe }
496ed9653ffSManish V Badarkhe 
497ed9653ffSManish V Badarkhe /* Get SOC revision */
498ed9653ffSManish V Badarkhe int32_t plat_get_soc_revision(void)
499ed9653ffSManish V Badarkhe {
500ed9653ffSManish V Badarkhe 	unsigned int sys_id;
501ed9653ffSManish V Badarkhe 
502ed9653ffSManish V Badarkhe 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
503dfff4686SYann Gautier 	return (int32_t)(((sys_id >> V2M_SYS_ID_REV_SHIFT) &
504dfff4686SYann Gautier 			  V2M_SYS_ID_REV_MASK) & SOC_ID_REV_MASK);
505ed9653ffSManish V Badarkhe }
506