xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision f801fdc22ef4fce3cc24fd1cbccde5772c15b633)
13e4b8fdcSSoby Mathew /*
2bef44f60SAlexeiFedorov  * Copyright (c) 2013-2025, 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>
832904472SSoby Mathew #include <string.h>
909d40e0eSAntonio Nino Diaz 
10*f801fdc2STushar Khandelwal #include <arch.h>
11*f801fdc2STushar Khandelwal #include <arch_helpers.h>
1209d40e0eSAntonio Nino Diaz #include <common/debug.h>
1309d40e0eSAntonio Nino Diaz #include <drivers/arm/cci.h>
1409d40e0eSAntonio Nino Diaz #include <drivers/arm/ccn.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/arm/gicv2.h>
161b597c22SAlexei Fedorov #include <drivers/arm/sp804_delay_timer.h>
171b597c22SAlexei Fedorov #include <drivers/generic_delay_timer.h>
1882685904SAlexeiFedorov #include <fconf_hw_config_getter.h>
1909d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
20ed9653ffSManish V Badarkhe #include <lib/smccc.h>
2109d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h>
22234bc7f8SAntonio Nino Diaz #include <platform_def.h>
23ed9653ffSManish V Badarkhe #include <services/arm_arch_svc.h>
241d0ca40eSJavier Almansa Sobrino #include <services/rmm_core_manifest.h>
259d9ae976SOlivier Deprez #if SPM_MM
26aeaa225cSPaul Beesley #include <services/spm_mm_partition.h>
279d9ae976SOlivier Deprez #endif
2809d40e0eSAntonio Nino Diaz 
29ed9653ffSManish V Badarkhe #include <plat/arm/common/arm_config.h>
30ed9653ffSManish V Badarkhe #include <plat/arm/common/plat_arm.h>
31ed9653ffSManish V Badarkhe #include <plat/common/platform.h>
32ed9653ffSManish V Badarkhe 
331af540efSRoberto Vargas #include "fvp_private.h"
343e4b8fdcSSoby Mathew 
353e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
363e4b8fdcSSoby Mathew #define FVP_GICV2		1
373e4b8fdcSSoby Mathew #define FVP_GICV3		2
383e4b8fdcSSoby Mathew 
3932904472SSoby Mathew /* Defines for RMM Console */
4032904472SSoby Mathew #define FVP_RMM_CONSOLE_BASE		UL(0x1c0c0000)
4132904472SSoby Mathew #define FVP_RMM_CONSOLE_BAUD		UL(115200)
4232904472SSoby Mathew #define FVP_RMM_CONSOLE_CLK_IN_HZ	UL(14745600)
4332904472SSoby Mathew #define FVP_RMM_CONSOLE_NAME		"pl011"
4432904472SSoby Mathew #define FVP_RMM_CONSOLE_COUNT		UL(1)
4532904472SSoby Mathew 
463e4b8fdcSSoby Mathew /*******************************************************************************
473e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
483e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
493e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
503e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
513e4b8fdcSSoby Mathew  * to allow independent operation.
523e4b8fdcSSoby Mathew  ******************************************************************************/
533e4b8fdcSSoby Mathew arm_config_t arm_config;
543e4b8fdcSSoby Mathew 
553e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
563e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
57b5772480SAlexeiFedorov 					MT_DEVICE | MT_RW | EL3_PAS)
583e4b8fdcSSoby Mathew 
593e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
603e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
613e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
623e4b8fdcSSoby Mathew 
63f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
64f98630fbSManish V Badarkhe #define MAP_GICD_MEM	MAP_REGION_FLAT(BASE_GICD_BASE,			\
65f98630fbSManish V Badarkhe 					BASE_GICD_SIZE,			\
66f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RW | MT_SECURE)
67f98630fbSManish V Badarkhe 
68f98630fbSManish V Badarkhe /* Map all core's redistributor memory as read-only. After boots up,
69f98630fbSManish V Badarkhe  * per-core map its redistributor memory as read-write */
70f98630fbSManish V Badarkhe #define MAP_GICR_MEM	MAP_REGION_FLAT(BASE_GICR_BASE,			\
71f98630fbSManish V Badarkhe 					(BASE_GICR_SIZE * PLATFORM_CORE_COUNT),\
72f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RO | MT_SECURE)
73f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
74f98630fbSManish V Badarkhe 
75284c3d67SSandrine Bailleux /*
76284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
77284c3d67SSandrine Bailleux  * counter value.
78284c3d67SSandrine Bailleux  */
793e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
803e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
81fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
823e4b8fdcSSoby Mathew 
8394c90ac8SHarrison Mutai #if TRANSFER_LIST
8494c90ac8SHarrison Mutai #ifdef FW_NS_HANDOFF_BASE
85a5566f65SHarrison Mutai #define MAP_FW_NS_HANDOFF                                             \
86a5566f65SHarrison Mutai 	MAP_REGION_FLAT(FW_NS_HANDOFF_BASE, PLAT_ARM_FW_HANDOFF_SIZE, \
8794c90ac8SHarrison Mutai 			MT_MEMORY | MT_RW | MT_NS)
8894c90ac8SHarrison Mutai #endif
89a5566f65SHarrison Mutai #ifdef PLAT_ARM_EL3_FW_HANDOFF_BASE
90a5566f65SHarrison Mutai #define MAP_EL3_FW_HANDOFF                            \
91a5566f65SHarrison Mutai 	MAP_REGION_FLAT(PLAT_ARM_EL3_FW_HANDOFF_BASE, \
92a5566f65SHarrison Mutai 			PLAT_ARM_FW_HANDOFF_SIZE, MT_MEMORY | MT_RW | EL3_PAS)
93a5566f65SHarrison Mutai #endif
9494c90ac8SHarrison Mutai #endif
9594c90ac8SHarrison Mutai 
963e4b8fdcSSoby Mathew /*
97b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
980916c38dSRoberto Vargas  * This doesn't include Trusted SRAM as setup_page_tables() already takes care
990916c38dSRoberto Vargas  * of mapping it.
1003e4b8fdcSSoby Mathew  */
1013d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
1023e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1033e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
10479d8be3cSManish V Badarkhe 	V2M_MAP_FLASH0_RO,
1053e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1063e4b8fdcSSoby Mathew 	MAP_DEVICE0,
107e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
1083e4b8fdcSSoby Mathew 	MAP_DEVICE1,
109e0cea783SManish V Badarkhe #endif
1103e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
111284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
112284c3d67SSandrine Bailleux 	MAP_DEVICE2,
113284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
1143e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
1153e4b8fdcSSoby Mathew #endif
1163e4b8fdcSSoby Mathew 	{0}
1173e4b8fdcSSoby Mathew };
1183e4b8fdcSSoby Mathew #endif
1193d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
1203e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1213e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
1223e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
1233e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1243e4b8fdcSSoby Mathew 	MAP_DEVICE0,
125e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
1263e4b8fdcSSoby Mathew 	MAP_DEVICE1,
127e0cea783SManish V Badarkhe #endif
1283e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
129402b3cf8SJulius Werner #ifdef __aarch64__
130b09ba056SRoberto Vargas 	ARM_MAP_DRAM2,
131b09ba056SRoberto Vargas #endif
13239f0b86aSManish V Badarkhe 	/*
13339f0b86aSManish V Badarkhe 	 * Required to load HW_CONFIG, SPMC and SPs to trusted DRAM.
13439f0b86aSManish V Badarkhe 	 */
13564758c97SAchin Gupta 	ARM_MAP_TRUSTED_DRAM,
1366b2e961fSManish V Badarkhe 
1376b2e961fSManish V Badarkhe 	/*
1386b2e961fSManish V Badarkhe 	 * Required to load Event Log in TZC secured memory
1396b2e961fSManish V Badarkhe 	 */
1406b2e961fSManish V Badarkhe #if MEASURED_BOOT && (defined(SPD_tspd) || defined(SPD_opteed) || \
1416b2e961fSManish V Badarkhe defined(SPD_spmd))
1426b2e961fSManish V Badarkhe 	ARM_MAP_EVENT_LOG_DRAM1,
1436b2e961fSManish V Badarkhe #endif /* MEASURED_BOOT && (SPD_tspd || SPD_opteed || SPD_spmd) */
1446b2e961fSManish V Badarkhe 
145c8720729SZelalem Aweke #if ENABLE_RME
146c8720729SZelalem Aweke 	ARM_MAP_RMM_DRAM,
147c8720729SZelalem Aweke 	ARM_MAP_GPT_L1_DRAM,
148c8720729SZelalem Aweke #endif /* ENABLE_RME */
1493eb2d672SSandrine Bailleux #ifdef SPD_tspd
1503e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
1513eb2d672SSandrine Bailleux #endif
152284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
153284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
154284c3d67SSandrine Bailleux 	MAP_DEVICE2,
155ba597da7SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */
15688c51c3fSManish V Badarkhe 
15742d4d3baSArvind Ram Prakash #if CRYPTO_SUPPORT && !RESET_TO_BL2
15888c51c3fSManish V Badarkhe 	/*
15988c51c3fSManish V Badarkhe 	 * To access shared the Mbed TLS heap while booting the
16088c51c3fSManish V Badarkhe 	 * system with Crypto support
16188c51c3fSManish V Badarkhe 	 */
16288c51c3fSManish V Badarkhe 	ARM_MAP_BL1_RW,
16342d4d3baSArvind Ram Prakash #endif /* CRYPTO_SUPPORT && !RESET_TO_BL2 */
16444639ab7SMarc Bonnici #if SPM_MM || SPMC_AT_EL3
165e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
166e29efeb1SAntonio Nino Diaz #endif
1673e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
1683e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
1693e4b8fdcSSoby Mathew #endif
170810d9213SJens Wiklander #ifdef SPD_opteed
171b3ba6fdaSSoby Mathew 	ARM_MAP_OPTEE_CORE_MEM,
172810d9213SJens Wiklander 	ARM_OPTEE_PAGEABLE_LOAD_MEM,
173810d9213SJens Wiklander #endif
174a5566f65SHarrison Mutai #ifdef MAP_EL3_FW_HANDOFF
175a5566f65SHarrison Mutai 	MAP_EL3_FW_HANDOFF,
176a5566f65SHarrison Mutai #endif
1773e4b8fdcSSoby Mathew 	{ 0 }
1783e4b8fdcSSoby Mathew };
1793e4b8fdcSSoby Mathew #endif
1803d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
1813e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1823e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1833e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1843e4b8fdcSSoby Mathew 	{0}
1853e4b8fdcSSoby Mathew };
1863e4b8fdcSSoby Mathew #endif
1873d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
1883e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1893e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
190992f091bSAmbroise Vincent #if USE_DEBUGFS
191992f091bSAmbroise Vincent 	/* Required by devfip, can be removed if devfip is not used */
192992f091bSAmbroise Vincent 	V2M_MAP_FLASH0_RW,
193992f091bSAmbroise Vincent #endif /* USE_DEBUGFS */
194e35a3fb5SSoby Mathew 	ARM_MAP_EL3_TZC_DRAM,
1953e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1963e4b8fdcSSoby Mathew 	MAP_DEVICE0,
197f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
198f98630fbSManish V Badarkhe 	MAP_GICD_MEM,
199f98630fbSManish V Badarkhe 	MAP_GICR_MEM,
200f98630fbSManish V Badarkhe #else
2013e4b8fdcSSoby Mathew 	MAP_DEVICE1,
202f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
203f145403cSRoberto Vargas 	ARM_V2M_MAP_MEM_PROTECT,
2043f3c341aSPaul Beesley #if SPM_MM
205e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL3_MMAP,
206e29efeb1SAntonio Nino Diaz #endif
207c8720729SZelalem Aweke #if ENABLE_RME
208c8720729SZelalem Aweke 	ARM_MAP_GPT_L1_DRAM,
2098c980a4aSJavier Almansa Sobrino 	ARM_MAP_EL3_RMM_SHARED_MEM,
210c8720729SZelalem Aweke #endif
21194c90ac8SHarrison Mutai #ifdef MAP_FW_NS_HANDOFF
21294c90ac8SHarrison Mutai 	MAP_FW_NS_HANDOFF,
21394c90ac8SHarrison Mutai #endif
2141a0ebff7SHarrison Mutai #if defined(MAP_EL3_FW_HANDOFF) && !RESET_TO_BL31
215a5566f65SHarrison Mutai 	MAP_EL3_FW_HANDOFF,
216a5566f65SHarrison Mutai #endif
2173e4b8fdcSSoby Mathew 	{ 0 }
2183e4b8fdcSSoby Mathew };
219e29efeb1SAntonio Nino Diaz 
2203f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
221e29efeb1SAntonio Nino Diaz const mmap_region_t plat_arm_secure_partition_mmap[] = {
222e29efeb1SAntonio Nino Diaz 	V2M_MAP_IOFPGA_EL0, /* for the UART */
2239fb76763Slevi.yun 	V2M_MAP_SECURE_SYSTEMREG_EL0, /* for initializing flash */
2249fb76763Slevi.yun #if PSA_FWU_SUPPORT
2259fb76763Slevi.yun 	V2M_MAP_FLASH0_RW_EL0, /* for firmware update service in standalone mm */
2269fb76763Slevi.yun #endif
2279fb76763Slevi.yun 	V2M_MAP_FLASH1_RW_EL0, /* for secure variable service in standalone mm */
2289a90d720SElyes Haouas 	MAP_REGION_FLAT(DEVICE0_BASE,
2299a90d720SElyes Haouas 			DEVICE0_SIZE,
230c4fa1739SSandrine Bailleux 			MT_DEVICE | MT_RO | MT_SECURE | MT_USER),
231e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
232e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_NS_BUF_MMAP,
233e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_RW_MMAP,
234e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL0_MMAP,
235e29efeb1SAntonio Nino Diaz 	{0}
236e29efeb1SAntonio Nino Diaz };
237e29efeb1SAntonio Nino Diaz #endif
2383e4b8fdcSSoby Mathew #endif
2393d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
2403e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
241402b3cf8SJulius Werner #ifndef __aarch64__
242877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
243950c6956SJoel Hutton 	ARM_V2M_MAP_MEM_PROTECT,
244877cf3ffSSoby Mathew #endif
2453e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
2463e4b8fdcSSoby Mathew 	MAP_DEVICE0,
2473e4b8fdcSSoby Mathew 	MAP_DEVICE1,
2483e4b8fdcSSoby Mathew 	{0}
2493e4b8fdcSSoby Mathew };
2503e4b8fdcSSoby Mathew #endif
2513e4b8fdcSSoby Mathew 
2529d870b79SZelalem Aweke #ifdef IMAGE_RMM
2539d870b79SZelalem Aweke const mmap_region_t plat_arm_mmap[] = {
2549d870b79SZelalem Aweke 	V2M_MAP_IOFPGA,
2559d870b79SZelalem Aweke 	MAP_DEVICE0,
2569d870b79SZelalem Aweke 	MAP_DEVICE1,
2579d870b79SZelalem Aweke 	{0}
2589d870b79SZelalem Aweke };
2599d870b79SZelalem Aweke #endif
2609d870b79SZelalem Aweke 
2613e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
2623e4b8fdcSSoby Mathew 
263955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN
264955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = {
265955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS0_SL_PORT,
266955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS1_SL_PORT,
267955242d8SJeenu Viswambharan };
268955242d8SJeenu Viswambharan 
269955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = {
270955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
271955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
272955242d8SJeenu Viswambharan };
273955242d8SJeenu Viswambharan 
274955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void)
275955242d8SJeenu Viswambharan {
276955242d8SJeenu Viswambharan 	unsigned int master;
277955242d8SJeenu Viswambharan 	u_register_t mpidr;
278955242d8SJeenu Viswambharan 
279955242d8SJeenu Viswambharan 	mpidr = read_mpidr_el1();
280583e0791SAntonio Nino Diaz 	master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
281955242d8SJeenu Viswambharan 		MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
282955242d8SJeenu Viswambharan 
283955242d8SJeenu Viswambharan 	assert(master < FVP_CLUSTER_COUNT);
284955242d8SJeenu Viswambharan 	return master;
285955242d8SJeenu Viswambharan }
286955242d8SJeenu Viswambharan #endif
2873e4b8fdcSSoby Mathew 
2883f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
289e29efeb1SAntonio Nino Diaz /*
290e29efeb1SAntonio Nino Diaz  * Boot information passed to a secure partition during initialisation. Linear
291e29efeb1SAntonio Nino Diaz  * indices in MP information will be filled at runtime.
292e29efeb1SAntonio Nino Diaz  */
293aeaa225cSPaul Beesley static spm_mm_mp_info_t sp_mp_info[] = {
294e29efeb1SAntonio Nino Diaz 	[0] = {0x80000000, 0},
295e29efeb1SAntonio Nino Diaz 	[1] = {0x80000001, 0},
296e29efeb1SAntonio Nino Diaz 	[2] = {0x80000002, 0},
297e29efeb1SAntonio Nino Diaz 	[3] = {0x80000003, 0},
298e29efeb1SAntonio Nino Diaz 	[4] = {0x80000100, 0},
299e29efeb1SAntonio Nino Diaz 	[5] = {0x80000101, 0},
300e29efeb1SAntonio Nino Diaz 	[6] = {0x80000102, 0},
301e29efeb1SAntonio Nino Diaz 	[7] = {0x80000103, 0},
302e29efeb1SAntonio Nino Diaz };
303e29efeb1SAntonio Nino Diaz 
304aeaa225cSPaul Beesley const spm_mm_boot_info_t plat_arm_secure_partition_boot_info = {
305e29efeb1SAntonio Nino Diaz 	.h.type              = PARAM_SP_IMAGE_BOOT_INFO,
306e29efeb1SAntonio Nino Diaz 	.h.version           = VERSION_1,
307aeaa225cSPaul Beesley 	.h.size              = sizeof(spm_mm_boot_info_t),
308e29efeb1SAntonio Nino Diaz 	.h.attr              = 0,
309e29efeb1SAntonio Nino Diaz 	.sp_mem_base         = ARM_SP_IMAGE_BASE,
310e29efeb1SAntonio Nino Diaz 	.sp_mem_limit        = ARM_SP_IMAGE_LIMIT,
311e29efeb1SAntonio Nino Diaz 	.sp_image_base       = ARM_SP_IMAGE_BASE,
312e29efeb1SAntonio Nino Diaz 	.sp_stack_base       = PLAT_SP_IMAGE_STACK_BASE,
313e29efeb1SAntonio Nino Diaz 	.sp_heap_base        = ARM_SP_IMAGE_HEAP_BASE,
3140560efb9SArd Biesheuvel 	.sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE,
315e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_base  = PLAT_SPM_BUF_BASE,
316e29efeb1SAntonio Nino Diaz 	.sp_image_size       = ARM_SP_IMAGE_SIZE,
317e29efeb1SAntonio Nino Diaz 	.sp_pcpu_stack_size  = PLAT_SP_IMAGE_STACK_PCPU_SIZE,
318e29efeb1SAntonio Nino Diaz 	.sp_heap_size        = ARM_SP_IMAGE_HEAP_SIZE,
3190560efb9SArd Biesheuvel 	.sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE,
320e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_size  = PLAT_SPM_BUF_SIZE,
321e29efeb1SAntonio Nino Diaz 	.num_sp_mem_regions  = ARM_SP_IMAGE_NUM_MEM_REGIONS,
322e29efeb1SAntonio Nino Diaz 	.num_cpus            = PLATFORM_CORE_COUNT,
323e29efeb1SAntonio Nino Diaz 	.mp_info             = &sp_mp_info[0],
324e29efeb1SAntonio Nino Diaz };
325e29efeb1SAntonio Nino Diaz 
326e29efeb1SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie)
327e29efeb1SAntonio Nino Diaz {
328e29efeb1SAntonio Nino Diaz 	return plat_arm_secure_partition_mmap;
329e29efeb1SAntonio Nino Diaz }
330e29efeb1SAntonio Nino Diaz 
331aeaa225cSPaul Beesley const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
332e29efeb1SAntonio Nino Diaz 		void *cookie)
333e29efeb1SAntonio Nino Diaz {
334e29efeb1SAntonio Nino Diaz 	return &plat_arm_secure_partition_boot_info;
335e29efeb1SAntonio Nino Diaz }
336e29efeb1SAntonio Nino Diaz #endif
337e29efeb1SAntonio Nino Diaz 
3383e4b8fdcSSoby Mathew /*******************************************************************************
3393e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
3403e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
3413e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
3423e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
3433e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
3443e4b8fdcSSoby Mathew  ******************************************************************************/
3454d010d0dSDaniel Boulby void __init fvp_config_setup(void)
3463e4b8fdcSSoby Mathew {
3473e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
3483e4b8fdcSSoby Mathew 
3493e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
3503e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
3513e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
3523e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
3533e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
3543e4b8fdcSSoby Mathew 
3553e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
3563e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
3573e4b8fdcSSoby Mathew 		panic();
3583e4b8fdcSSoby Mathew 	}
3593e4b8fdcSSoby Mathew 
3603e4b8fdcSSoby Mathew 	/*
3613e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
3623e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
3633e4b8fdcSSoby Mathew 	 */
3643e4b8fdcSSoby Mathew 	switch (bld) {
3653e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
36621a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
36721a3973dSSoby Mathew 				" is not supported\n");
3683e4b8fdcSSoby Mathew 		panic();
3693e4b8fdcSSoby Mathew 		break;
3703e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
3713e4b8fdcSSoby Mathew 		break;
3723e4b8fdcSSoby Mathew 	default:
3733e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
3743e4b8fdcSSoby Mathew 		panic();
3753e4b8fdcSSoby Mathew 	}
3763e4b8fdcSSoby Mathew 
3773e4b8fdcSSoby Mathew 	/*
3783e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
3793e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
3803e4b8fdcSSoby Mathew 	 */
3813e4b8fdcSSoby Mathew 	switch (hbi) {
3823e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
3833e4b8fdcSSoby Mathew 		arm_config.flags = 0;
3843e4b8fdcSSoby Mathew 
3853e4b8fdcSSoby Mathew 		/*
3863e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
3873e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
3883e4b8fdcSSoby Mathew 		 */
3893e4b8fdcSSoby Mathew 		switch (rev) {
3903e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
3913e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
3923e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
3934faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
3943e4b8fdcSSoby Mathew 			break;
3953e4b8fdcSSoby Mathew 		default:
3963e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
3973e4b8fdcSSoby Mathew 			break;
3983e4b8fdcSSoby Mathew 		}
3993e4b8fdcSSoby Mathew 		break;
4003e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
401955242d8SJeenu Viswambharan 		arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
4023e4b8fdcSSoby Mathew 
4033e4b8fdcSSoby Mathew 		/*
4043e4b8fdcSSoby Mathew 		 * Check for supported revisions
4053e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
4063e4b8fdcSSoby Mathew 		 */
4073e4b8fdcSSoby Mathew 		switch (rev) {
4083e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
409955242d8SJeenu Viswambharan 			arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
410955242d8SJeenu Viswambharan 			break;
411955242d8SJeenu Viswambharan 		case REV_BASE_FVP_REVC:
4128431635bSIsla Mitchell 			arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 |
413955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_CCI5XX);
4143e4b8fdcSSoby Mathew 			break;
4153e4b8fdcSSoby Mathew 		default:
4163e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
4173e4b8fdcSSoby Mathew 			break;
4183e4b8fdcSSoby Mathew 		}
4193e4b8fdcSSoby Mathew 		break;
4203e4b8fdcSSoby Mathew 	default:
4213e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
4223e4b8fdcSSoby Mathew 		panic();
4233e4b8fdcSSoby Mathew 	}
4248431635bSIsla Mitchell 
4258431635bSIsla Mitchell 	/*
4268431635bSIsla Mitchell 	 * We assume that the presence of MT bit, and therefore shifted
4278431635bSIsla Mitchell 	 * affinities, is uniform across the platform: either all CPUs, or no
4288431635bSIsla Mitchell 	 * CPUs implement it.
4298431635bSIsla Mitchell 	 */
430583e0791SAntonio Nino Diaz 	if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U)
4318431635bSIsla Mitchell 		arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
4323e4b8fdcSSoby Mathew }
4333e4b8fdcSSoby Mathew 
4343e4b8fdcSSoby Mathew 
4354d010d0dSDaniel Boulby void __init fvp_interconnect_init(void)
4363e4b8fdcSSoby Mathew {
43771237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
43871237876SSoby Mathew 	if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
439583e0791SAntonio Nino Diaz 		ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
44071237876SSoby Mathew 		panic();
44171237876SSoby Mathew 	}
442955242d8SJeenu Viswambharan 
4433e4b8fdcSSoby Mathew 	plat_arm_interconnect_init();
444955242d8SJeenu Viswambharan #else
445583e0791SAntonio Nino Diaz 	uintptr_t cci_base = 0U;
446583e0791SAntonio Nino Diaz 	const int *cci_map = NULL;
447583e0791SAntonio Nino Diaz 	unsigned int map_size = 0U;
448955242d8SJeenu Viswambharan 
449955242d8SJeenu Viswambharan 	/* Initialize the right interconnect */
450583e0791SAntonio Nino Diaz 	if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
451955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI5XX_BASE;
452955242d8SJeenu Viswambharan 		cci_map = fvp_cci5xx_map;
453955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci5xx_map);
454583e0791SAntonio Nino Diaz 	} else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
455955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI400_BASE;
456955242d8SJeenu Viswambharan 		cci_map = fvp_cci400_map;
457955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci400_map);
458583e0791SAntonio Nino Diaz 	} else {
459583e0791SAntonio Nino Diaz 		return;
460955242d8SJeenu Viswambharan 	}
461955242d8SJeenu Viswambharan 
462583e0791SAntonio Nino Diaz 	assert(cci_base != 0U);
463583e0791SAntonio Nino Diaz 	assert(cci_map != NULL);
464955242d8SJeenu Viswambharan 	cci_init(cci_base, cci_map, map_size);
465955242d8SJeenu Viswambharan #endif
46671237876SSoby Mathew }
4673e4b8fdcSSoby Mathew 
4683e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
4693e4b8fdcSSoby Mathew {
470955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4713e4b8fdcSSoby Mathew 	plat_arm_interconnect_enter_coherency();
472955242d8SJeenu Viswambharan #else
473955242d8SJeenu Viswambharan 	unsigned int master;
474955242d8SJeenu Viswambharan 
475583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
476583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
477955242d8SJeenu Viswambharan 		master = get_interconnect_master();
478955242d8SJeenu Viswambharan 		cci_enable_snoop_dvm_reqs(master);
479955242d8SJeenu Viswambharan 	}
480955242d8SJeenu Viswambharan #endif
4813e4b8fdcSSoby Mathew }
4823e4b8fdcSSoby Mathew 
4833e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
4843e4b8fdcSSoby Mathew {
485955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4863e4b8fdcSSoby Mathew 	plat_arm_interconnect_exit_coherency();
487955242d8SJeenu Viswambharan #else
488955242d8SJeenu Viswambharan 	unsigned int master;
489955242d8SJeenu Viswambharan 
490583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
491583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
492955242d8SJeenu Viswambharan 		master = get_interconnect_master();
493955242d8SJeenu Viswambharan 		cci_disable_snoop_dvm_reqs(master);
494955242d8SJeenu Viswambharan 	}
495955242d8SJeenu Viswambharan #endif
4963e4b8fdcSSoby Mathew }
497ba597da7SJohn Tsichritzis 
49888c51c3fSManish V Badarkhe #if CRYPTO_SUPPORT
499ba597da7SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
500ba597da7SJohn Tsichritzis {
501ba597da7SJohn Tsichritzis 	assert(heap_addr != NULL);
502ba597da7SJohn Tsichritzis 	assert(heap_size != NULL);
503ba597da7SJohn Tsichritzis 
504ba597da7SJohn Tsichritzis 	return arm_get_mbedtls_heap(heap_addr, heap_size);
505ba597da7SJohn Tsichritzis }
50688c51c3fSManish V Badarkhe #endif /* CRYPTO_SUPPORT */
5071b597c22SAlexei Fedorov 
5081b597c22SAlexei Fedorov void fvp_timer_init(void)
5091b597c22SAlexei Fedorov {
510fddfb3baSMadhukar Pappireddy #if USE_SP804_TIMER
5111b597c22SAlexei Fedorov 	/* Enable the clock override for SP804 timer 0, which means that no
5121b597c22SAlexei Fedorov 	 * clock dividers are applied and the raw (35MHz) clock will be used.
5131b597c22SAlexei Fedorov 	 */
5141b597c22SAlexei Fedorov 	mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV);
5151b597c22SAlexei Fedorov 
5161b597c22SAlexei Fedorov 	/* Initialize delay timer driver using SP804 dual timer 0 */
5171b597c22SAlexei Fedorov 	sp804_timer_init(V2M_SP804_TIMER0_BASE,
5181b597c22SAlexei Fedorov 			SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
5191b597c22SAlexei Fedorov #else
5201b597c22SAlexei Fedorov 	generic_delay_timer_init();
5211b597c22SAlexei Fedorov 
5221b597c22SAlexei Fedorov 	/* Enable System level generic timer */
5231b597c22SAlexei Fedorov 	mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
5241b597c22SAlexei Fedorov 			CNTCR_FCREQ(0U) | CNTCR_EN);
525fddfb3baSMadhukar Pappireddy #endif /* USE_SP804_TIMER */
5261b597c22SAlexei Fedorov }
527ed9653ffSManish V Badarkhe 
528ed9653ffSManish V Badarkhe /*****************************************************************************
529ed9653ffSManish V Badarkhe  * plat_is_smccc_feature_available() - This function checks whether SMCCC
530ed9653ffSManish V Badarkhe  *                                     feature is availabile for platform.
531ed9653ffSManish V Badarkhe  * @fid: SMCCC function id
532ed9653ffSManish V Badarkhe  *
533ed9653ffSManish V Badarkhe  * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
534ed9653ffSManish V Badarkhe  * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
535ed9653ffSManish V Badarkhe  *****************************************************************************/
536ed9653ffSManish V Badarkhe int32_t plat_is_smccc_feature_available(u_register_t fid)
537ed9653ffSManish V Badarkhe {
538ed9653ffSManish V Badarkhe 	switch (fid) {
539ed9653ffSManish V Badarkhe 	case SMCCC_ARCH_SOC_ID:
540ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_SUCCESS;
541ed9653ffSManish V Badarkhe 	default:
542ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_NOT_SUPPORTED;
543ed9653ffSManish V Badarkhe 	}
544ed9653ffSManish V Badarkhe }
545ed9653ffSManish V Badarkhe 
546ed9653ffSManish V Badarkhe /* Get SOC version */
547ed9653ffSManish V Badarkhe int32_t plat_get_soc_version(void)
548ed9653ffSManish V Badarkhe {
549ed9653ffSManish V Badarkhe 	return (int32_t)
550dfff4686SYann Gautier 		(SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
551dfff4686SYann Gautier 				    ARM_SOC_IDENTIFICATION_CODE) |
552dfff4686SYann Gautier 		 (FVP_SOC_ID & SOC_ID_IMPL_DEF_MASK));
553ed9653ffSManish V Badarkhe }
554ed9653ffSManish V Badarkhe 
555ed9653ffSManish V Badarkhe /* Get SOC revision */
556ed9653ffSManish V Badarkhe int32_t plat_get_soc_revision(void)
557ed9653ffSManish V Badarkhe {
558ed9653ffSManish V Badarkhe 	unsigned int sys_id;
559ed9653ffSManish V Badarkhe 
560ed9653ffSManish V Badarkhe 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
561dfff4686SYann Gautier 	return (int32_t)(((sys_id >> V2M_SYS_ID_REV_SHIFT) &
562dfff4686SYann Gautier 			  V2M_SYS_ID_REV_MASK) & SOC_ID_REV_MASK);
563ed9653ffSManish V Badarkhe }
5648c980a4aSJavier Almansa Sobrino 
5658c980a4aSJavier Almansa Sobrino #if ENABLE_RME
5668c980a4aSJavier Almansa Sobrino /*
5678c980a4aSJavier Almansa Sobrino  * Get a pointer to the RMM-EL3 Shared buffer and return it
5688c980a4aSJavier Almansa Sobrino  * through the pointer passed as parameter.
5698c980a4aSJavier Almansa Sobrino  *
5708c980a4aSJavier Almansa Sobrino  * This function returns the size of the shared buffer.
5718c980a4aSJavier Almansa Sobrino  */
5728c980a4aSJavier Almansa Sobrino size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
5738c980a4aSJavier Almansa Sobrino {
5748c980a4aSJavier Almansa Sobrino 	*shared = (uintptr_t)RMM_SHARED_BASE;
5758c980a4aSJavier Almansa Sobrino 
5768c980a4aSJavier Almansa Sobrino 	return (size_t)RMM_SHARED_SIZE;
5778c980a4aSJavier Almansa Sobrino }
5781d0ca40eSJavier Almansa Sobrino 
579aa99881dSAlexeiFedorov /*
580aa99881dSAlexeiFedorov  * Calculate checksum of 64-bit words @buffer with @size length
581aa99881dSAlexeiFedorov  */
582aa99881dSAlexeiFedorov static uint64_t checksum_calc(uint64_t *buffer, size_t size)
583aa99881dSAlexeiFedorov {
584aa99881dSAlexeiFedorov 	uint64_t sum = 0UL;
585aa99881dSAlexeiFedorov 
586aa99881dSAlexeiFedorov 	assert(((uintptr_t)buffer & (sizeof(uint64_t) - 1UL)) == 0UL);
587aa99881dSAlexeiFedorov 	assert((size & (sizeof(uint64_t) - 1UL)) == 0UL);
588aa99881dSAlexeiFedorov 
589aa99881dSAlexeiFedorov 	for (unsigned long i = 0UL; i < (size / sizeof(uint64_t)); i++) {
590aa99881dSAlexeiFedorov 		sum += buffer[i];
591aa99881dSAlexeiFedorov 	}
592aa99881dSAlexeiFedorov 
593aa99881dSAlexeiFedorov 	return sum;
594aa99881dSAlexeiFedorov }
595bef44f60SAlexeiFedorov /*
596bef44f60SAlexeiFedorov  * Boot Manifest structure illustration, with two DRAM banks,
597bef44f60SAlexeiFedorov  * a single console and one device memory with two PCIe device
598bef44f60SAlexeiFedorov  * non-coherent address ranges.
599bef44f60SAlexeiFedorov  *
600bef44f60SAlexeiFedorov  * +--------------------------------------------------+
601bef44f60SAlexeiFedorov  * | offset |        field       |      comment       |
602bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
603bef44f60SAlexeiFedorov  * |   0    |       version      |     0x00000004     |
604bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
605bef44f60SAlexeiFedorov  * |   4    |       padding      |     0x00000000     |
606bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
607bef44f60SAlexeiFedorov  * |   8    |      plat_data     |       NULL         |
608bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
609bef44f60SAlexeiFedorov  * |   16   |      num_banks     |                    |
610bef44f60SAlexeiFedorov  * +--------+--------------------+                    |
611bef44f60SAlexeiFedorov  * |   24   |       banks        |     plat_dram      +--+
612bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
613bef44f60SAlexeiFedorov  * |   32   |      checksum      |                    |  |
614bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |
615bef44f60SAlexeiFedorov  * |   40   |    num_consoles    |                    |  |
616bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
617bef44f60SAlexeiFedorov  * |   48   |      consoles      |    plat_console    +--|--+
618bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |
619bef44f60SAlexeiFedorov  * |   56   |      checksum      |                    |  |  |
620bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |
621bef44f60SAlexeiFedorov  * |   64   |      num_banks     |                    |  |  |
622bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |
623bef44f60SAlexeiFedorov  * |   72   |        banks       |  plat_ncoh_region  +--|--|--+
624bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
625bef44f60SAlexeiFedorov  * |   80   |      checksum      |                    |  |  |  |
626bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |
627bef44f60SAlexeiFedorov  * |   88   |      num_banks     |                    |  |  |  |
628bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
629bef44f60SAlexeiFedorov  * |   96   |       banks        |   plat_coh_region  |  |  |  |
630bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
631bef44f60SAlexeiFedorov  * |   104  |      checksum      |                    |  |  |  |
632bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+<-+  |  |
633bef44f60SAlexeiFedorov  * |   112  |       base 0       |                    |     |  |
634bef44f60SAlexeiFedorov  * +--------+--------------------+     mem_bank[0]    |     |  |
635bef44f60SAlexeiFedorov  * |   120  |       size 0       |                    |     |  |
636bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+     |  |
637bef44f60SAlexeiFedorov  * |   128  |       base 1       |                    |     |  |
638bef44f60SAlexeiFedorov  * +--------+--------------------+     mem_bank[1]    |     |  |
639bef44f60SAlexeiFedorov  * |   136  |       size 1       |                    |     |  |
640bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+<----+  |
641bef44f60SAlexeiFedorov  * |   144  |       base         |                    |        |
642bef44f60SAlexeiFedorov  * +--------+--------------------+                    |        |
643bef44f60SAlexeiFedorov  * |   152  |      map_pages     |                    |        |
644bef44f60SAlexeiFedorov  * +--------+--------------------+                    |        |
645bef44f60SAlexeiFedorov  * |   160  |       name         |                    |        |
646bef44f60SAlexeiFedorov  * +--------+--------------------+     consoles[0]    |        |
647bef44f60SAlexeiFedorov  * |   168  |     clk_in_hz      |                    |        |
648bef44f60SAlexeiFedorov  * +--------+--------------------+                    |        |
649bef44f60SAlexeiFedorov  * |   176  |     baud_rate      |                    |        |
650bef44f60SAlexeiFedorov  * +--------+--------------------+                    |        |
651bef44f60SAlexeiFedorov  * |   184  |       flags        |                    |        |
652bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+<-------+
653bef44f60SAlexeiFedorov  * |   192  |       base 0       |                    |
654bef44f60SAlexeiFedorov  * +--------+--------------------+   ncoh_region[0]   |
655bef44f60SAlexeiFedorov  * |   200  |       size 0       |                    |
656bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
657bef44f60SAlexeiFedorov  * |   208  |       base 1       |                    |
658bef44f60SAlexeiFedorov  * +--------+--------------------+   ncoh_region[1]   |
659bef44f60SAlexeiFedorov  * |   216  |       size 1       |                    |
660bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
661bef44f60SAlexeiFedorov  */
662a97bfa5fSAlexeiFedorov int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
6631d0ca40eSJavier Almansa Sobrino {
66432904472SSoby Mathew 	uint64_t checksum, num_banks, num_consoles;
665bef44f60SAlexeiFedorov 	uint64_t num_ncoh_regions, num_coh_regions;
666bef44f60SAlexeiFedorov 	struct memory_bank *bank_ptr, *ncoh_region_ptr;
66732904472SSoby Mathew 	struct console_info *console_ptr;
668a97bfa5fSAlexeiFedorov 
6691d0ca40eSJavier Almansa Sobrino 	assert(manifest != NULL);
6701d0ca40eSJavier Almansa Sobrino 
67182685904SAlexeiFedorov 	/* Get number of DRAM banks */
67282685904SAlexeiFedorov 	num_banks = FCONF_GET_PROPERTY(hw_config, dram_layout, num_banks);
67382685904SAlexeiFedorov 	assert(num_banks <= ARM_DRAM_NUM_BANKS);
67482685904SAlexeiFedorov 
67532904472SSoby Mathew 	/* Set number of consoles */
67632904472SSoby Mathew 	num_consoles = FVP_RMM_CONSOLE_COUNT;
67732904472SSoby Mathew 
678bef44f60SAlexeiFedorov 	/* Set number of device non-coherent address ranges based on DT */
679bef44f60SAlexeiFedorov 	num_ncoh_regions = FCONF_GET_PROPERTY(hw_config, pci_props, num_ncoh_regions);
680bef44f60SAlexeiFedorov 
6811d0ca40eSJavier Almansa Sobrino 	manifest->version = RMMD_MANIFEST_VERSION;
682dc0ca64eSJavier Almansa Sobrino 	manifest->padding = 0U; /* RES0 */
683bef44f60SAlexeiFedorov 	manifest->plat_data = 0UL;
68482685904SAlexeiFedorov 	manifest->plat_dram.num_banks = num_banks;
68532904472SSoby Mathew 	manifest->plat_console.num_consoles = num_consoles;
686bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.num_banks = num_ncoh_regions;
687a97bfa5fSAlexeiFedorov 
688bef44f60SAlexeiFedorov 	/* FVP does not support device coherent address ranges */
689bef44f60SAlexeiFedorov 	num_coh_regions = 0UL;
690bef44f60SAlexeiFedorov 	manifest->plat_coh_region.num_banks = num_coh_regions;
691bef44f60SAlexeiFedorov 	manifest->plat_coh_region.banks = NULL;
692bef44f60SAlexeiFedorov 	manifest->plat_coh_region.checksum = 0UL;
69332904472SSoby Mathew 
694bef44f60SAlexeiFedorov 	bank_ptr = (struct memory_bank *)
695bef44f60SAlexeiFedorov 			(((uintptr_t)manifest) + sizeof(struct rmm_manifest));
69632904472SSoby Mathew 	console_ptr = (struct console_info *)
697bef44f60SAlexeiFedorov 			((uintptr_t)bank_ptr + (num_banks *
698bef44f60SAlexeiFedorov 						sizeof(struct memory_bank)));
699bef44f60SAlexeiFedorov 	ncoh_region_ptr = (struct memory_bank *)
700bef44f60SAlexeiFedorov 			((uintptr_t)console_ptr + (num_consoles *
701bef44f60SAlexeiFedorov 						sizeof(struct console_info)));
70282685904SAlexeiFedorov 	manifest->plat_dram.banks = bank_ptr;
70332904472SSoby Mathew 	manifest->plat_console.consoles = console_ptr;
704bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.banks = ncoh_region_ptr;
70532904472SSoby Mathew 
70632904472SSoby Mathew 	/* Ensure the manifest is not larger than the shared buffer */
70732904472SSoby Mathew 	assert((sizeof(struct rmm_manifest) +
708bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
709bef44f60SAlexeiFedorov 			manifest->plat_dram.num_banks) +
710bef44f60SAlexeiFedorov 		(sizeof(struct console_info) *
711bef44f60SAlexeiFedorov 			manifest->plat_console.num_consoles) +
712bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
713bef44f60SAlexeiFedorov 			manifest->plat_ncoh_region.num_banks) +
714bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
715bef44f60SAlexeiFedorov 			manifest->plat_coh_region.num_banks))
716bef44f60SAlexeiFedorov 		<= ARM_EL3_RMM_SHARED_SIZE);
717a97bfa5fSAlexeiFedorov 
718a97bfa5fSAlexeiFedorov 	/* Calculate checksum of plat_dram structure */
71982685904SAlexeiFedorov 	checksum = num_banks + (uint64_t)bank_ptr;
720a97bfa5fSAlexeiFedorov 
72182685904SAlexeiFedorov 	/* Store FVP DRAM banks data in Boot Manifest */
72282685904SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_banks; i++) {
723aa99881dSAlexeiFedorov 		bank_ptr[i].base = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].base);
724aa99881dSAlexeiFedorov 		bank_ptr[i].size = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].size);
725aa99881dSAlexeiFedorov 	}
72682685904SAlexeiFedorov 
72782685904SAlexeiFedorov 	/* Update checksum */
728bef44f60SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)bank_ptr, sizeof(struct memory_bank) * num_banks);
729a97bfa5fSAlexeiFedorov 
730a97bfa5fSAlexeiFedorov 	/* Checksum must be 0 */
73182685904SAlexeiFedorov 	manifest->plat_dram.checksum = ~checksum + 1UL;
7321d0ca40eSJavier Almansa Sobrino 
733bef44f60SAlexeiFedorov 	/* Calculate the checksum of plat_consoles structure */
73432904472SSoby Mathew 	checksum = num_consoles + (uint64_t)console_ptr;
73532904472SSoby Mathew 
73632904472SSoby Mathew 	/* Zero out the console info struct */
737bef44f60SAlexeiFedorov 	(void)memset((void *)console_ptr, '\0',
738bef44f60SAlexeiFedorov 			sizeof(struct console_info) * num_consoles);
73932904472SSoby Mathew 
74032904472SSoby Mathew 	console_ptr[0].base = FVP_RMM_CONSOLE_BASE;
741aa99881dSAlexeiFedorov 	console_ptr[0].map_pages = 1UL;
74232904472SSoby Mathew 	console_ptr[0].clk_in_hz = FVP_RMM_CONSOLE_CLK_IN_HZ;
74332904472SSoby Mathew 	console_ptr[0].baud_rate = FVP_RMM_CONSOLE_BAUD;
74432904472SSoby Mathew 
745bef44f60SAlexeiFedorov 	(void)strlcpy(console_ptr[0].name, FVP_RMM_CONSOLE_NAME,
746bef44f60SAlexeiFedorov 						RMM_CONSOLE_MAX_NAME_LEN - 1UL);
74732904472SSoby Mathew 
74832904472SSoby Mathew 	/* Update checksum */
749aa99881dSAlexeiFedorov 	checksum += checksum_calc((uint64_t *)console_ptr,
750aa99881dSAlexeiFedorov 					sizeof(struct console_info) * num_consoles);
75132904472SSoby Mathew 	/* Checksum must be 0 */
75232904472SSoby Mathew 	manifest->plat_console.checksum = ~checksum + 1UL;
75332904472SSoby Mathew 
754bef44f60SAlexeiFedorov 	/*
755bef44f60SAlexeiFedorov 	 * Calculate the checksum of device non-coherent address ranges
756bef44f60SAlexeiFedorov 	 * info structure
757bef44f60SAlexeiFedorov 	 */
758bef44f60SAlexeiFedorov 	checksum = num_ncoh_regions + (uint64_t)ncoh_region_ptr;
759bef44f60SAlexeiFedorov 
760bef44f60SAlexeiFedorov 	/* Zero out the PCIe region info struct */
761bef44f60SAlexeiFedorov 	(void)memset((void *)ncoh_region_ptr, 0,
762bef44f60SAlexeiFedorov 			sizeof(struct memory_bank) * num_ncoh_regions);
763bef44f60SAlexeiFedorov 
764bef44f60SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_ncoh_regions; i++) {
765bef44f60SAlexeiFedorov 		ncoh_region_ptr[i].base =
766bef44f60SAlexeiFedorov 			FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].base);
767bef44f60SAlexeiFedorov 		ncoh_region_ptr[i].size =
768bef44f60SAlexeiFedorov 			FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].size);
769bef44f60SAlexeiFedorov 	}
770bef44f60SAlexeiFedorov 
771bef44f60SAlexeiFedorov 	/* Update checksum */
772bef44f60SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)ncoh_region_ptr,
773bef44f60SAlexeiFedorov 			sizeof(struct memory_bank) * num_ncoh_regions);
774bef44f60SAlexeiFedorov 
775bef44f60SAlexeiFedorov 	/* Checksum must be 0 */
776bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.checksum = ~checksum + 1UL;
777bef44f60SAlexeiFedorov 
7781d0ca40eSJavier Almansa Sobrino 	return 0;
7791d0ca40eSJavier Almansa Sobrino }
780*f801fdc2STushar Khandelwal 
781*f801fdc2STushar Khandelwal /*
782*f801fdc2STushar Khandelwal  * Update encryption key associated with @mecid.
783*f801fdc2STushar Khandelwal  */
784*f801fdc2STushar Khandelwal int plat_rmmd_mecid_key_update(uint16_t mecid)
785*f801fdc2STushar Khandelwal {
786*f801fdc2STushar Khandelwal 	/*
787*f801fdc2STushar Khandelwal 	 * FVP does not provide an interface to change the encryption key associated
788*f801fdc2STushar Khandelwal 	 * with MECID. Hence always return success.
789*f801fdc2STushar Khandelwal 	 */
790*f801fdc2STushar Khandelwal 	return 0;
791*f801fdc2STushar Khandelwal }
792a97bfa5fSAlexeiFedorov #endif	/* ENABLE_RME */
793