xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 90552c612e31ba88c6a7ad47c4081bc89d09c9c5)
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 
10f801fdc2STushar Khandelwal #include <arch.h>
11f801fdc2STushar 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>
17*90552c61SAlexeiFedorov #include <drivers/arm/smmu_v3.h>
181b597c22SAlexei Fedorov #include <drivers/generic_delay_timer.h>
1982685904SAlexeiFedorov #include <fconf_hw_config_getter.h>
2009d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
21ed9653ffSManish V Badarkhe #include <lib/smccc.h>
2209d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h>
23234bc7f8SAntonio Nino Diaz #include <platform_def.h>
24ed9653ffSManish V Badarkhe #include <services/arm_arch_svc.h>
251d0ca40eSJavier Almansa Sobrino #include <services/rmm_core_manifest.h>
269d9ae976SOlivier Deprez #if SPM_MM
27aeaa225cSPaul Beesley #include <services/spm_mm_partition.h>
289d9ae976SOlivier Deprez #endif
2909d40e0eSAntonio Nino Diaz 
30ed9653ffSManish V Badarkhe #include <plat/arm/common/arm_config.h>
31ed9653ffSManish V Badarkhe #include <plat/arm/common/plat_arm.h>
32ed9653ffSManish V Badarkhe #include <plat/common/platform.h>
33ed9653ffSManish V Badarkhe 
341af540efSRoberto Vargas #include "fvp_private.h"
353e4b8fdcSSoby Mathew 
363e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
373e4b8fdcSSoby Mathew #define FVP_GICV2		1
383e4b8fdcSSoby Mathew #define FVP_GICV3		2
393e4b8fdcSSoby Mathew 
4032904472SSoby Mathew /* Defines for RMM Console */
4132904472SSoby Mathew #define FVP_RMM_CONSOLE_BASE		UL(0x1c0c0000)
4232904472SSoby Mathew #define FVP_RMM_CONSOLE_BAUD		UL(115200)
4332904472SSoby Mathew #define FVP_RMM_CONSOLE_CLK_IN_HZ	UL(14745600)
4432904472SSoby Mathew #define FVP_RMM_CONSOLE_NAME		"pl011"
4532904472SSoby Mathew #define FVP_RMM_CONSOLE_COUNT		UL(1)
4632904472SSoby Mathew 
47*90552c61SAlexeiFedorov /* Defines for RMM PCIe ECAM */
48*90552c61SAlexeiFedorov #define FVP_RMM_ECAM_BASE		PCIE_EXP_BASE
49*90552c61SAlexeiFedorov #define FVP_RMM_ECAM_SEGMENT		UL(0x0)
50*90552c61SAlexeiFedorov #define FVP_RMM_ECAM_BDF		UL(0x0)
51*90552c61SAlexeiFedorov 
52*90552c61SAlexeiFedorov /* Defines for RMM SMMUv3 */
53*90552c61SAlexeiFedorov #define FVP_RMM_SMMU_BASE		PLAT_FVP_SMMUV3_BASE
54*90552c61SAlexeiFedorov #define FVP_RMM_SMMU_COUNT		UL(1)
55*90552c61SAlexeiFedorov 
563e4b8fdcSSoby Mathew /*******************************************************************************
573e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
583e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
593e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
603e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
613e4b8fdcSSoby Mathew  * to allow independent operation.
623e4b8fdcSSoby Mathew  ******************************************************************************/
633e4b8fdcSSoby Mathew arm_config_t arm_config;
643e4b8fdcSSoby Mathew 
653e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
663e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
67b5772480SAlexeiFedorov 					MT_DEVICE | MT_RW | EL3_PAS)
683e4b8fdcSSoby Mathew 
693e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
703e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
713e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
723e4b8fdcSSoby Mathew 
73f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
74f98630fbSManish V Badarkhe #define MAP_GICD_MEM	MAP_REGION_FLAT(BASE_GICD_BASE,			\
75f98630fbSManish V Badarkhe 					BASE_GICD_SIZE,			\
76f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RW | MT_SECURE)
77f98630fbSManish V Badarkhe 
78f98630fbSManish V Badarkhe /* Map all core's redistributor memory as read-only. After boots up,
79f98630fbSManish V Badarkhe  * per-core map its redistributor memory as read-write */
80f98630fbSManish V Badarkhe #define MAP_GICR_MEM	MAP_REGION_FLAT(BASE_GICR_BASE,			\
81f98630fbSManish V Badarkhe 					(BASE_GICR_SIZE * PLATFORM_CORE_COUNT),\
82f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RO | MT_SECURE)
83f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
84f98630fbSManish V Badarkhe 
85284c3d67SSandrine Bailleux /*
86284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
87284c3d67SSandrine Bailleux  * counter value.
88284c3d67SSandrine Bailleux  */
893e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
903e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
91fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
923e4b8fdcSSoby Mathew 
9394c90ac8SHarrison Mutai #if TRANSFER_LIST
9494c90ac8SHarrison Mutai #ifdef FW_NS_HANDOFF_BASE
95a5566f65SHarrison Mutai #define MAP_FW_NS_HANDOFF                                             \
96a5566f65SHarrison Mutai 	MAP_REGION_FLAT(FW_NS_HANDOFF_BASE, PLAT_ARM_FW_HANDOFF_SIZE, \
9794c90ac8SHarrison Mutai 			MT_MEMORY | MT_RW | MT_NS)
9894c90ac8SHarrison Mutai #endif
99a5566f65SHarrison Mutai #ifdef PLAT_ARM_EL3_FW_HANDOFF_BASE
100a5566f65SHarrison Mutai #define MAP_EL3_FW_HANDOFF                            \
101a5566f65SHarrison Mutai 	MAP_REGION_FLAT(PLAT_ARM_EL3_FW_HANDOFF_BASE, \
102a5566f65SHarrison Mutai 			PLAT_ARM_FW_HANDOFF_SIZE, MT_MEMORY | MT_RW | EL3_PAS)
103a5566f65SHarrison Mutai #endif
10494c90ac8SHarrison Mutai #endif
10594c90ac8SHarrison Mutai 
1063e4b8fdcSSoby Mathew /*
107b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
1080916c38dSRoberto Vargas  * This doesn't include Trusted SRAM as setup_page_tables() already takes care
1090916c38dSRoberto Vargas  * of mapping it.
1103e4b8fdcSSoby Mathew  */
1113d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
1123e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1133e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
11479d8be3cSManish V Badarkhe 	V2M_MAP_FLASH0_RO,
1153e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1163e4b8fdcSSoby Mathew 	MAP_DEVICE0,
117e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
1183e4b8fdcSSoby Mathew 	MAP_DEVICE1,
119e0cea783SManish V Badarkhe #endif
1203e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
121284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
122284c3d67SSandrine Bailleux 	MAP_DEVICE2,
123284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
1243e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
1253e4b8fdcSSoby Mathew #endif
1263e4b8fdcSSoby Mathew 	{0}
1273e4b8fdcSSoby Mathew };
1283e4b8fdcSSoby Mathew #endif
1293d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
1303e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1313e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
1323e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
1333e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1343e4b8fdcSSoby Mathew 	MAP_DEVICE0,
135e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
1363e4b8fdcSSoby Mathew 	MAP_DEVICE1,
137e0cea783SManish V Badarkhe #endif
1383e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
139402b3cf8SJulius Werner #ifdef __aarch64__
140b09ba056SRoberto Vargas 	ARM_MAP_DRAM2,
141b09ba056SRoberto Vargas #endif
14239f0b86aSManish V Badarkhe 	/*
14339f0b86aSManish V Badarkhe 	 * Required to load HW_CONFIG, SPMC and SPs to trusted DRAM.
14439f0b86aSManish V Badarkhe 	 */
14564758c97SAchin Gupta 	ARM_MAP_TRUSTED_DRAM,
1466b2e961fSManish V Badarkhe 
1476b2e961fSManish V Badarkhe 	/*
1486b2e961fSManish V Badarkhe 	 * Required to load Event Log in TZC secured memory
1496b2e961fSManish V Badarkhe 	 */
1506b2e961fSManish V Badarkhe #if MEASURED_BOOT && (defined(SPD_tspd) || defined(SPD_opteed) || \
1516b2e961fSManish V Badarkhe defined(SPD_spmd))
1526b2e961fSManish V Badarkhe 	ARM_MAP_EVENT_LOG_DRAM1,
1536b2e961fSManish V Badarkhe #endif /* MEASURED_BOOT && (SPD_tspd || SPD_opteed || SPD_spmd) */
1546b2e961fSManish V Badarkhe 
155c8720729SZelalem Aweke #if ENABLE_RME
156c8720729SZelalem Aweke 	ARM_MAP_RMM_DRAM,
157c8720729SZelalem Aweke 	ARM_MAP_GPT_L1_DRAM,
158c8720729SZelalem Aweke #endif /* ENABLE_RME */
1593eb2d672SSandrine Bailleux #ifdef SPD_tspd
1603e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
1613eb2d672SSandrine Bailleux #endif
162284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
163284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
164284c3d67SSandrine Bailleux 	MAP_DEVICE2,
165ba597da7SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */
16688c51c3fSManish V Badarkhe 
16742d4d3baSArvind Ram Prakash #if CRYPTO_SUPPORT && !RESET_TO_BL2
16888c51c3fSManish V Badarkhe 	/*
16988c51c3fSManish V Badarkhe 	 * To access shared the Mbed TLS heap while booting the
17088c51c3fSManish V Badarkhe 	 * system with Crypto support
17188c51c3fSManish V Badarkhe 	 */
17288c51c3fSManish V Badarkhe 	ARM_MAP_BL1_RW,
17342d4d3baSArvind Ram Prakash #endif /* CRYPTO_SUPPORT && !RESET_TO_BL2 */
17444639ab7SMarc Bonnici #if SPM_MM || SPMC_AT_EL3
175e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
176e29efeb1SAntonio Nino Diaz #endif
1773e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
1783e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
1793e4b8fdcSSoby Mathew #endif
180810d9213SJens Wiklander #ifdef SPD_opteed
181b3ba6fdaSSoby Mathew 	ARM_MAP_OPTEE_CORE_MEM,
182810d9213SJens Wiklander 	ARM_OPTEE_PAGEABLE_LOAD_MEM,
183810d9213SJens Wiklander #endif
184a5566f65SHarrison Mutai #ifdef MAP_EL3_FW_HANDOFF
185a5566f65SHarrison Mutai 	MAP_EL3_FW_HANDOFF,
186a5566f65SHarrison Mutai #endif
1873e4b8fdcSSoby Mathew 	{ 0 }
1883e4b8fdcSSoby Mathew };
1893e4b8fdcSSoby Mathew #endif
1903d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
1913e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1923e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1933e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1943e4b8fdcSSoby Mathew 	{0}
1953e4b8fdcSSoby Mathew };
1963e4b8fdcSSoby Mathew #endif
1973d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
1983e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1993e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
200992f091bSAmbroise Vincent #if USE_DEBUGFS
201992f091bSAmbroise Vincent 	/* Required by devfip, can be removed if devfip is not used */
202992f091bSAmbroise Vincent 	V2M_MAP_FLASH0_RW,
203992f091bSAmbroise Vincent #endif /* USE_DEBUGFS */
204e35a3fb5SSoby Mathew 	ARM_MAP_EL3_TZC_DRAM,
2053e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
2063e4b8fdcSSoby Mathew 	MAP_DEVICE0,
207f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
208f98630fbSManish V Badarkhe 	MAP_GICD_MEM,
209f98630fbSManish V Badarkhe 	MAP_GICR_MEM,
210f98630fbSManish V Badarkhe #else
2113e4b8fdcSSoby Mathew 	MAP_DEVICE1,
212f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
213f145403cSRoberto Vargas 	ARM_V2M_MAP_MEM_PROTECT,
2143f3c341aSPaul Beesley #if SPM_MM
215e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL3_MMAP,
216e29efeb1SAntonio Nino Diaz #endif
217c8720729SZelalem Aweke #if ENABLE_RME
218c8720729SZelalem Aweke 	ARM_MAP_GPT_L1_DRAM,
2198c980a4aSJavier Almansa Sobrino 	ARM_MAP_EL3_RMM_SHARED_MEM,
220c8720729SZelalem Aweke #endif
22194c90ac8SHarrison Mutai #ifdef MAP_FW_NS_HANDOFF
22294c90ac8SHarrison Mutai 	MAP_FW_NS_HANDOFF,
22394c90ac8SHarrison Mutai #endif
2241a0ebff7SHarrison Mutai #if defined(MAP_EL3_FW_HANDOFF) && !RESET_TO_BL31
225a5566f65SHarrison Mutai 	MAP_EL3_FW_HANDOFF,
226a5566f65SHarrison Mutai #endif
2273e4b8fdcSSoby Mathew 	{ 0 }
2283e4b8fdcSSoby Mathew };
229e29efeb1SAntonio Nino Diaz 
2303f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
231e29efeb1SAntonio Nino Diaz const mmap_region_t plat_arm_secure_partition_mmap[] = {
232e29efeb1SAntonio Nino Diaz 	V2M_MAP_IOFPGA_EL0, /* for the UART */
2339fb76763Slevi.yun 	V2M_MAP_SECURE_SYSTEMREG_EL0, /* for initializing flash */
2349fb76763Slevi.yun #if PSA_FWU_SUPPORT
2359fb76763Slevi.yun 	V2M_MAP_FLASH0_RW_EL0, /* for firmware update service in standalone mm */
2369fb76763Slevi.yun #endif
2379fb76763Slevi.yun 	V2M_MAP_FLASH1_RW_EL0, /* for secure variable service in standalone mm */
2389a90d720SElyes Haouas 	MAP_REGION_FLAT(DEVICE0_BASE,
2399a90d720SElyes Haouas 			DEVICE0_SIZE,
240c4fa1739SSandrine Bailleux 			MT_DEVICE | MT_RO | MT_SECURE | MT_USER),
241e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
242e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_NS_BUF_MMAP,
243e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_RW_MMAP,
244e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL0_MMAP,
245e29efeb1SAntonio Nino Diaz 	{0}
246e29efeb1SAntonio Nino Diaz };
247e29efeb1SAntonio Nino Diaz #endif
2483e4b8fdcSSoby Mathew #endif
2493d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
2503e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
251402b3cf8SJulius Werner #ifndef __aarch64__
252877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
253950c6956SJoel Hutton 	ARM_V2M_MAP_MEM_PROTECT,
254877cf3ffSSoby Mathew #endif
2553e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
2563e4b8fdcSSoby Mathew 	MAP_DEVICE0,
2573e4b8fdcSSoby Mathew 	MAP_DEVICE1,
2583e4b8fdcSSoby Mathew 	{0}
2593e4b8fdcSSoby Mathew };
2603e4b8fdcSSoby Mathew #endif
2613e4b8fdcSSoby Mathew 
2629d870b79SZelalem Aweke #ifdef IMAGE_RMM
2639d870b79SZelalem Aweke const mmap_region_t plat_arm_mmap[] = {
2649d870b79SZelalem Aweke 	V2M_MAP_IOFPGA,
2659d870b79SZelalem Aweke 	MAP_DEVICE0,
2669d870b79SZelalem Aweke 	MAP_DEVICE1,
2679d870b79SZelalem Aweke 	{0}
2689d870b79SZelalem Aweke };
2699d870b79SZelalem Aweke #endif
2709d870b79SZelalem Aweke 
2713e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
2723e4b8fdcSSoby Mathew 
273955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN
274955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = {
275955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS0_SL_PORT,
276955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS1_SL_PORT,
277955242d8SJeenu Viswambharan };
278955242d8SJeenu Viswambharan 
279955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = {
280955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
281955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
282955242d8SJeenu Viswambharan };
283955242d8SJeenu Viswambharan 
284955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void)
285955242d8SJeenu Viswambharan {
286955242d8SJeenu Viswambharan 	unsigned int master;
287955242d8SJeenu Viswambharan 	u_register_t mpidr;
288955242d8SJeenu Viswambharan 
289955242d8SJeenu Viswambharan 	mpidr = read_mpidr_el1();
290583e0791SAntonio Nino Diaz 	master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
291955242d8SJeenu Viswambharan 		MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
292955242d8SJeenu Viswambharan 
293955242d8SJeenu Viswambharan 	assert(master < FVP_CLUSTER_COUNT);
294955242d8SJeenu Viswambharan 	return master;
295955242d8SJeenu Viswambharan }
296955242d8SJeenu Viswambharan #endif
2973e4b8fdcSSoby Mathew 
2983f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
299e29efeb1SAntonio Nino Diaz /*
300e29efeb1SAntonio Nino Diaz  * Boot information passed to a secure partition during initialisation. Linear
301e29efeb1SAntonio Nino Diaz  * indices in MP information will be filled at runtime.
302e29efeb1SAntonio Nino Diaz  */
303aeaa225cSPaul Beesley static spm_mm_mp_info_t sp_mp_info[] = {
304e29efeb1SAntonio Nino Diaz 	[0] = {0x80000000, 0},
305e29efeb1SAntonio Nino Diaz 	[1] = {0x80000001, 0},
306e29efeb1SAntonio Nino Diaz 	[2] = {0x80000002, 0},
307e29efeb1SAntonio Nino Diaz 	[3] = {0x80000003, 0},
308e29efeb1SAntonio Nino Diaz 	[4] = {0x80000100, 0},
309e29efeb1SAntonio Nino Diaz 	[5] = {0x80000101, 0},
310e29efeb1SAntonio Nino Diaz 	[6] = {0x80000102, 0},
311e29efeb1SAntonio Nino Diaz 	[7] = {0x80000103, 0},
312e29efeb1SAntonio Nino Diaz };
313e29efeb1SAntonio Nino Diaz 
314aeaa225cSPaul Beesley const spm_mm_boot_info_t plat_arm_secure_partition_boot_info = {
315e29efeb1SAntonio Nino Diaz 	.h.type              = PARAM_SP_IMAGE_BOOT_INFO,
316e29efeb1SAntonio Nino Diaz 	.h.version           = VERSION_1,
317aeaa225cSPaul Beesley 	.h.size              = sizeof(spm_mm_boot_info_t),
318e29efeb1SAntonio Nino Diaz 	.h.attr              = 0,
319e29efeb1SAntonio Nino Diaz 	.sp_mem_base         = ARM_SP_IMAGE_BASE,
320e29efeb1SAntonio Nino Diaz 	.sp_mem_limit        = ARM_SP_IMAGE_LIMIT,
321e29efeb1SAntonio Nino Diaz 	.sp_image_base       = ARM_SP_IMAGE_BASE,
322e29efeb1SAntonio Nino Diaz 	.sp_stack_base       = PLAT_SP_IMAGE_STACK_BASE,
323e29efeb1SAntonio Nino Diaz 	.sp_heap_base        = ARM_SP_IMAGE_HEAP_BASE,
3240560efb9SArd Biesheuvel 	.sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE,
325e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_base  = PLAT_SPM_BUF_BASE,
326e29efeb1SAntonio Nino Diaz 	.sp_image_size       = ARM_SP_IMAGE_SIZE,
327e29efeb1SAntonio Nino Diaz 	.sp_pcpu_stack_size  = PLAT_SP_IMAGE_STACK_PCPU_SIZE,
328e29efeb1SAntonio Nino Diaz 	.sp_heap_size        = ARM_SP_IMAGE_HEAP_SIZE,
3290560efb9SArd Biesheuvel 	.sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE,
330e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_size  = PLAT_SPM_BUF_SIZE,
331e29efeb1SAntonio Nino Diaz 	.num_sp_mem_regions  = ARM_SP_IMAGE_NUM_MEM_REGIONS,
332e29efeb1SAntonio Nino Diaz 	.num_cpus            = PLATFORM_CORE_COUNT,
333e29efeb1SAntonio Nino Diaz 	.mp_info             = &sp_mp_info[0],
334e29efeb1SAntonio Nino Diaz };
335e29efeb1SAntonio Nino Diaz 
336e29efeb1SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie)
337e29efeb1SAntonio Nino Diaz {
338e29efeb1SAntonio Nino Diaz 	return plat_arm_secure_partition_mmap;
339e29efeb1SAntonio Nino Diaz }
340e29efeb1SAntonio Nino Diaz 
341aeaa225cSPaul Beesley const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
342e29efeb1SAntonio Nino Diaz 		void *cookie)
343e29efeb1SAntonio Nino Diaz {
344e29efeb1SAntonio Nino Diaz 	return &plat_arm_secure_partition_boot_info;
345e29efeb1SAntonio Nino Diaz }
346e29efeb1SAntonio Nino Diaz #endif
347e29efeb1SAntonio Nino Diaz 
3483e4b8fdcSSoby Mathew /*******************************************************************************
3493e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
3503e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
3513e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
3523e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
3533e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
3543e4b8fdcSSoby Mathew  ******************************************************************************/
3554d010d0dSDaniel Boulby void __init fvp_config_setup(void)
3563e4b8fdcSSoby Mathew {
3573e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
3583e4b8fdcSSoby Mathew 
3593e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
3603e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
3613e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
3623e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
3633e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
3643e4b8fdcSSoby Mathew 
3653e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
3663e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
3673e4b8fdcSSoby Mathew 		panic();
3683e4b8fdcSSoby Mathew 	}
3693e4b8fdcSSoby Mathew 
3703e4b8fdcSSoby Mathew 	/*
3713e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
3723e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
3733e4b8fdcSSoby Mathew 	 */
3743e4b8fdcSSoby Mathew 	switch (bld) {
3753e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
37621a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
37721a3973dSSoby Mathew 				" is not supported\n");
3783e4b8fdcSSoby Mathew 		panic();
3793e4b8fdcSSoby Mathew 		break;
3803e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
3813e4b8fdcSSoby Mathew 		break;
3823e4b8fdcSSoby Mathew 	default:
3833e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
3843e4b8fdcSSoby Mathew 		panic();
3853e4b8fdcSSoby Mathew 	}
3863e4b8fdcSSoby Mathew 
3873e4b8fdcSSoby Mathew 	/*
3883e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
3893e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
3903e4b8fdcSSoby Mathew 	 */
3913e4b8fdcSSoby Mathew 	switch (hbi) {
3923e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
3933e4b8fdcSSoby Mathew 		arm_config.flags = 0;
3943e4b8fdcSSoby Mathew 
3953e4b8fdcSSoby Mathew 		/*
3963e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
3973e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
3983e4b8fdcSSoby Mathew 		 */
3993e4b8fdcSSoby Mathew 		switch (rev) {
4003e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
4013e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
4023e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
4034faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
4043e4b8fdcSSoby Mathew 			break;
4053e4b8fdcSSoby Mathew 		default:
4063e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
4073e4b8fdcSSoby Mathew 			break;
4083e4b8fdcSSoby Mathew 		}
4093e4b8fdcSSoby Mathew 		break;
4103e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
411955242d8SJeenu Viswambharan 		arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
4123e4b8fdcSSoby Mathew 
4133e4b8fdcSSoby Mathew 		/*
4143e4b8fdcSSoby Mathew 		 * Check for supported revisions
4153e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
4163e4b8fdcSSoby Mathew 		 */
4173e4b8fdcSSoby Mathew 		switch (rev) {
4183e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
419955242d8SJeenu Viswambharan 			arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
420955242d8SJeenu Viswambharan 			break;
421955242d8SJeenu Viswambharan 		case REV_BASE_FVP_REVC:
4228431635bSIsla Mitchell 			arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 |
423955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_CCI5XX);
4243e4b8fdcSSoby Mathew 			break;
4253e4b8fdcSSoby Mathew 		default:
4263e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
4273e4b8fdcSSoby Mathew 			break;
4283e4b8fdcSSoby Mathew 		}
4293e4b8fdcSSoby Mathew 		break;
4303e4b8fdcSSoby Mathew 	default:
4313e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
4323e4b8fdcSSoby Mathew 		panic();
4333e4b8fdcSSoby Mathew 	}
4348431635bSIsla Mitchell 
4358431635bSIsla Mitchell 	/*
4368431635bSIsla Mitchell 	 * We assume that the presence of MT bit, and therefore shifted
4378431635bSIsla Mitchell 	 * affinities, is uniform across the platform: either all CPUs, or no
4388431635bSIsla Mitchell 	 * CPUs implement it.
4398431635bSIsla Mitchell 	 */
440583e0791SAntonio Nino Diaz 	if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U)
4418431635bSIsla Mitchell 		arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
4423e4b8fdcSSoby Mathew }
4433e4b8fdcSSoby Mathew 
4443e4b8fdcSSoby Mathew 
4454d010d0dSDaniel Boulby void __init fvp_interconnect_init(void)
4463e4b8fdcSSoby Mathew {
44771237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
44871237876SSoby Mathew 	if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
449583e0791SAntonio Nino Diaz 		ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
45071237876SSoby Mathew 		panic();
45171237876SSoby Mathew 	}
452955242d8SJeenu Viswambharan 
4533e4b8fdcSSoby Mathew 	plat_arm_interconnect_init();
454955242d8SJeenu Viswambharan #else
455583e0791SAntonio Nino Diaz 	uintptr_t cci_base = 0U;
456583e0791SAntonio Nino Diaz 	const int *cci_map = NULL;
457583e0791SAntonio Nino Diaz 	unsigned int map_size = 0U;
458955242d8SJeenu Viswambharan 
459955242d8SJeenu Viswambharan 	/* Initialize the right interconnect */
460583e0791SAntonio Nino Diaz 	if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
461955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI5XX_BASE;
462955242d8SJeenu Viswambharan 		cci_map = fvp_cci5xx_map;
463955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci5xx_map);
464583e0791SAntonio Nino Diaz 	} else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
465955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI400_BASE;
466955242d8SJeenu Viswambharan 		cci_map = fvp_cci400_map;
467955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci400_map);
468583e0791SAntonio Nino Diaz 	} else {
469583e0791SAntonio Nino Diaz 		return;
470955242d8SJeenu Viswambharan 	}
471955242d8SJeenu Viswambharan 
472583e0791SAntonio Nino Diaz 	assert(cci_base != 0U);
473583e0791SAntonio Nino Diaz 	assert(cci_map != NULL);
474955242d8SJeenu Viswambharan 	cci_init(cci_base, cci_map, map_size);
475955242d8SJeenu Viswambharan #endif
47671237876SSoby Mathew }
4773e4b8fdcSSoby Mathew 
4783e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
4793e4b8fdcSSoby Mathew {
480955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4813e4b8fdcSSoby Mathew 	plat_arm_interconnect_enter_coherency();
482955242d8SJeenu Viswambharan #else
483955242d8SJeenu Viswambharan 	unsigned int master;
484955242d8SJeenu Viswambharan 
485583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
486583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
487955242d8SJeenu Viswambharan 		master = get_interconnect_master();
488955242d8SJeenu Viswambharan 		cci_enable_snoop_dvm_reqs(master);
489955242d8SJeenu Viswambharan 	}
490955242d8SJeenu Viswambharan #endif
4913e4b8fdcSSoby Mathew }
4923e4b8fdcSSoby Mathew 
4933e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
4943e4b8fdcSSoby Mathew {
495955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4963e4b8fdcSSoby Mathew 	plat_arm_interconnect_exit_coherency();
497955242d8SJeenu Viswambharan #else
498955242d8SJeenu Viswambharan 	unsigned int master;
499955242d8SJeenu Viswambharan 
500583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
501583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
502955242d8SJeenu Viswambharan 		master = get_interconnect_master();
503955242d8SJeenu Viswambharan 		cci_disable_snoop_dvm_reqs(master);
504955242d8SJeenu Viswambharan 	}
505955242d8SJeenu Viswambharan #endif
5063e4b8fdcSSoby Mathew }
507ba597da7SJohn Tsichritzis 
50888c51c3fSManish V Badarkhe #if CRYPTO_SUPPORT
509ba597da7SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
510ba597da7SJohn Tsichritzis {
511ba597da7SJohn Tsichritzis 	assert(heap_addr != NULL);
512ba597da7SJohn Tsichritzis 	assert(heap_size != NULL);
513ba597da7SJohn Tsichritzis 
514ba597da7SJohn Tsichritzis 	return arm_get_mbedtls_heap(heap_addr, heap_size);
515ba597da7SJohn Tsichritzis }
51688c51c3fSManish V Badarkhe #endif /* CRYPTO_SUPPORT */
5171b597c22SAlexei Fedorov 
5181b597c22SAlexei Fedorov void fvp_timer_init(void)
5191b597c22SAlexei Fedorov {
520fddfb3baSMadhukar Pappireddy #if USE_SP804_TIMER
5211b597c22SAlexei Fedorov 	/* Enable the clock override for SP804 timer 0, which means that no
5221b597c22SAlexei Fedorov 	 * clock dividers are applied and the raw (35MHz) clock will be used.
5231b597c22SAlexei Fedorov 	 */
5241b597c22SAlexei Fedorov 	mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV);
5251b597c22SAlexei Fedorov 
5261b597c22SAlexei Fedorov 	/* Initialize delay timer driver using SP804 dual timer 0 */
5271b597c22SAlexei Fedorov 	sp804_timer_init(V2M_SP804_TIMER0_BASE,
5281b597c22SAlexei Fedorov 			SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
5291b597c22SAlexei Fedorov #else
5301b597c22SAlexei Fedorov 	generic_delay_timer_init();
5311b597c22SAlexei Fedorov 
5321b597c22SAlexei Fedorov 	/* Enable System level generic timer */
5331b597c22SAlexei Fedorov 	mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
5341b597c22SAlexei Fedorov 			CNTCR_FCREQ(0U) | CNTCR_EN);
535fddfb3baSMadhukar Pappireddy #endif /* USE_SP804_TIMER */
5361b597c22SAlexei Fedorov }
537ed9653ffSManish V Badarkhe 
538ed9653ffSManish V Badarkhe /*****************************************************************************
539ed9653ffSManish V Badarkhe  * plat_is_smccc_feature_available() - This function checks whether SMCCC
540ed9653ffSManish V Badarkhe  *                                     feature is availabile for platform.
541ed9653ffSManish V Badarkhe  * @fid: SMCCC function id
542ed9653ffSManish V Badarkhe  *
543ed9653ffSManish V Badarkhe  * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
544ed9653ffSManish V Badarkhe  * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
545ed9653ffSManish V Badarkhe  *****************************************************************************/
546ed9653ffSManish V Badarkhe int32_t plat_is_smccc_feature_available(u_register_t fid)
547ed9653ffSManish V Badarkhe {
548ed9653ffSManish V Badarkhe 	switch (fid) {
549ed9653ffSManish V Badarkhe 	case SMCCC_ARCH_SOC_ID:
550ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_SUCCESS;
551ed9653ffSManish V Badarkhe 	default:
552ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_NOT_SUPPORTED;
553ed9653ffSManish V Badarkhe 	}
554ed9653ffSManish V Badarkhe }
555ed9653ffSManish V Badarkhe 
556ed9653ffSManish V Badarkhe /* Get SOC version */
557ed9653ffSManish V Badarkhe int32_t plat_get_soc_version(void)
558ed9653ffSManish V Badarkhe {
559ed9653ffSManish V Badarkhe 	return (int32_t)
560dfff4686SYann Gautier 		(SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
561dfff4686SYann Gautier 				    ARM_SOC_IDENTIFICATION_CODE) |
562dfff4686SYann Gautier 		 (FVP_SOC_ID & SOC_ID_IMPL_DEF_MASK));
563ed9653ffSManish V Badarkhe }
564ed9653ffSManish V Badarkhe 
565ed9653ffSManish V Badarkhe /* Get SOC revision */
566ed9653ffSManish V Badarkhe int32_t plat_get_soc_revision(void)
567ed9653ffSManish V Badarkhe {
568ed9653ffSManish V Badarkhe 	unsigned int sys_id;
569ed9653ffSManish V Badarkhe 
570ed9653ffSManish V Badarkhe 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
571dfff4686SYann Gautier 	return (int32_t)(((sys_id >> V2M_SYS_ID_REV_SHIFT) &
572dfff4686SYann Gautier 			  V2M_SYS_ID_REV_MASK) & SOC_ID_REV_MASK);
573ed9653ffSManish V Badarkhe }
5748c980a4aSJavier Almansa Sobrino 
5758c980a4aSJavier Almansa Sobrino #if ENABLE_RME
576*90552c61SAlexeiFedorov 
577*90552c61SAlexeiFedorov /* BDF mappings for RP0 RC0 */
578*90552c61SAlexeiFedorov const struct bdf_mapping_info rc0rp0_bdf_data[] = {
579*90552c61SAlexeiFedorov 	/* BDF0 */
580*90552c61SAlexeiFedorov 	{0U,		/* mapping_base */
581*90552c61SAlexeiFedorov 	 0x8000U,	/* mapping_top */
582*90552c61SAlexeiFedorov 	 0U,		/* mapping_off */
583*90552c61SAlexeiFedorov 	 0U		/* smmu_idx */
584*90552c61SAlexeiFedorov 	}
585*90552c61SAlexeiFedorov };
586*90552c61SAlexeiFedorov 
587*90552c61SAlexeiFedorov /* Root ports for RC0 */
588*90552c61SAlexeiFedorov const struct root_port_info rc0rp_data[] = {
589*90552c61SAlexeiFedorov 	/* RP0 */
590*90552c61SAlexeiFedorov 	{0U,						/* root_port_id */
591*90552c61SAlexeiFedorov 	 0U,						/* padding */
592*90552c61SAlexeiFedorov 	 ARRAY_SIZE(rc0rp0_bdf_data),			/* num_bdf_mappings */
593*90552c61SAlexeiFedorov 	 (struct bdf_mapping_info *)rc0rp0_bdf_data	/* bdf_mappings */
594*90552c61SAlexeiFedorov 	}
595*90552c61SAlexeiFedorov };
596*90552c61SAlexeiFedorov 
597*90552c61SAlexeiFedorov /* Root complexes */
598*90552c61SAlexeiFedorov const struct root_complex_info rc_data[] = {
599*90552c61SAlexeiFedorov 	/* RC0 */
600*90552c61SAlexeiFedorov 	{PCIE_EXP_BASE,				/* ecam_base */
601*90552c61SAlexeiFedorov 	 0U,					/* segment */
602*90552c61SAlexeiFedorov 	 {0U, 0U, 0U},				/* padding */
603*90552c61SAlexeiFedorov 	 ARRAY_SIZE(rc0rp_data),		/* num_root_ports */
604*90552c61SAlexeiFedorov 	 (struct root_port_info *)rc0rp_data	/* root_ports */
605*90552c61SAlexeiFedorov 	}
606*90552c61SAlexeiFedorov };
607*90552c61SAlexeiFedorov 
608*90552c61SAlexeiFedorov /* Number of PCIe Root Complexes */
609*90552c61SAlexeiFedorov #define FVP_RMM_RC_COUNT	ARRAY_SIZE(rc_data)
610*90552c61SAlexeiFedorov 
6118c980a4aSJavier Almansa Sobrino /*
6128c980a4aSJavier Almansa Sobrino  * Get a pointer to the RMM-EL3 Shared buffer and return it
6138c980a4aSJavier Almansa Sobrino  * through the pointer passed as parameter.
6148c980a4aSJavier Almansa Sobrino  *
6158c980a4aSJavier Almansa Sobrino  * This function returns the size of the shared buffer.
6168c980a4aSJavier Almansa Sobrino  */
6178c980a4aSJavier Almansa Sobrino size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
6188c980a4aSJavier Almansa Sobrino {
6198c980a4aSJavier Almansa Sobrino 	*shared = (uintptr_t)RMM_SHARED_BASE;
6208c980a4aSJavier Almansa Sobrino 
6218c980a4aSJavier Almansa Sobrino 	return (size_t)RMM_SHARED_SIZE;
6228c980a4aSJavier Almansa Sobrino }
6231d0ca40eSJavier Almansa Sobrino 
624aa99881dSAlexeiFedorov /*
625aa99881dSAlexeiFedorov  * Calculate checksum of 64-bit words @buffer with @size length
626aa99881dSAlexeiFedorov  */
627aa99881dSAlexeiFedorov static uint64_t checksum_calc(uint64_t *buffer, size_t size)
628aa99881dSAlexeiFedorov {
629aa99881dSAlexeiFedorov 	uint64_t sum = 0UL;
630aa99881dSAlexeiFedorov 
631aa99881dSAlexeiFedorov 	assert(((uintptr_t)buffer & (sizeof(uint64_t) - 1UL)) == 0UL);
632aa99881dSAlexeiFedorov 	assert((size & (sizeof(uint64_t) - 1UL)) == 0UL);
633aa99881dSAlexeiFedorov 
634aa99881dSAlexeiFedorov 	for (unsigned long i = 0UL; i < (size / sizeof(uint64_t)); i++) {
635aa99881dSAlexeiFedorov 		sum += buffer[i];
636aa99881dSAlexeiFedorov 	}
637aa99881dSAlexeiFedorov 
638aa99881dSAlexeiFedorov 	return sum;
639aa99881dSAlexeiFedorov }
640bef44f60SAlexeiFedorov /*
641*90552c61SAlexeiFedorov  * Boot Manifest v0.5 structure illustration, with two DRAM banks,
642bef44f60SAlexeiFedorov  * a single console and one device memory with two PCIe device
643bef44f60SAlexeiFedorov  * non-coherent address ranges.
644bef44f60SAlexeiFedorov  *
645bef44f60SAlexeiFedorov  * +--------------------------------------------------+
646bef44f60SAlexeiFedorov  * | offset |        field       |      comment       |
647bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
648*90552c61SAlexeiFedorov  * |   0    |       version      |     0x00000005     |
649bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
650bef44f60SAlexeiFedorov  * |   4    |       padding      |     0x00000000     |
651bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
652bef44f60SAlexeiFedorov  * |   8    |      plat_data     |       NULL         |
653bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
654bef44f60SAlexeiFedorov  * |   16   |      num_banks     |                    |
655bef44f60SAlexeiFedorov  * +--------+--------------------+                    |
656bef44f60SAlexeiFedorov  * |   24   |       banks        |     plat_dram      +--+
657bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
658bef44f60SAlexeiFedorov  * |   32   |      checksum      |                    |  |
659bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |
660bef44f60SAlexeiFedorov  * |   40   |    num_consoles    |                    |  |
661bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
662bef44f60SAlexeiFedorov  * |   48   |      consoles      |    plat_console    +--|--+
663bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |
664bef44f60SAlexeiFedorov  * |   56   |      checksum      |                    |  |  |
665bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |
666bef44f60SAlexeiFedorov  * |   64   |      num_banks     |                    |  |  |
667bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |
668bef44f60SAlexeiFedorov  * |   72   |        banks       |  plat_ncoh_region  +--|--|--+
669bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
670bef44f60SAlexeiFedorov  * |   80   |      checksum      |                    |  |  |  |
671bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |
672bef44f60SAlexeiFedorov  * |   88   |      num_banks     |                    |  |  |  |
673bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
674bef44f60SAlexeiFedorov  * |   96   |       banks        |   plat_coh_region  |  |  |  |
675bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
676bef44f60SAlexeiFedorov  * |   104  |      checksum      |                    |  |  |  |
677*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |
678*90552c61SAlexeiFedorov  * |   112  |     num_smmus      |                    |  |  |  |
679*90552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
680*90552c61SAlexeiFedorov  * |   120  |       smmus        |     plat_smmu      +--|--|--|--+
681*90552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |
682*90552c61SAlexeiFedorov  * |   128  |      checksum      |                    |  |  |  |  |
683*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |  |
684*90552c61SAlexeiFedorov  * |   136  |  num_root_complex  |                    |  |  |  |  |
685*90552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |
686*90552c61SAlexeiFedorov  * |   144  |   rc_info_version  |                    |  |  |  |  |
687*90552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |
688*90552c61SAlexeiFedorov  * |   148  |      padding       | plat_root_complex  +--|--|--|--|--+
689*90552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |  |
690*90552c61SAlexeiFedorov  * |   152  |    root_complex    |                    |  |  |  |  |  |
691*90552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |  |
692*90552c61SAlexeiFedorov  * |   160  |      checksum      |                    |  |  |  |  |  |
693*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-+  |  |  |  |
694*90552c61SAlexeiFedorov  * |   168  |       base 0       |                    |     |  |  |  |
695*90552c61SAlexeiFedorov  * +--------+--------------------+     mem_bank[0]    |     |  |  |  |
696*90552c61SAlexeiFedorov  * |   176  |       size 0       |                    |     |  |  |  |
697*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+     |  |  |  |
698*90552c61SAlexeiFedorov  * |   184  |       base 1       |                    |     |  |  |  |
699*90552c61SAlexeiFedorov  * +--------+--------------------+     mem_bank[1]    |     |  |  |  |
700*90552c61SAlexeiFedorov  * |   192  |       size 1       |                    |     |  |  |  |
701*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<----+  |  |  |
702*90552c61SAlexeiFedorov  * |   200  |       base         |                    |        |  |  |
703*90552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
704*90552c61SAlexeiFedorov  * |   208  |      map_pages     |                    |        |  |  |
705*90552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
706*90552c61SAlexeiFedorov  * |   216  |       name         |                    |        |  |  |
707*90552c61SAlexeiFedorov  * +--------+--------------------+     consoles[0]    |        |  |  |
708*90552c61SAlexeiFedorov  * |   224  |     clk_in_hz      |                    |        |  |  |
709*90552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
710*90552c61SAlexeiFedorov  * |   232  |     baud_rate      |                    |        |  |  |
711*90552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
712*90552c61SAlexeiFedorov  * |   240  |       flags        |                    |        |  |  |
713*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-------+  |  |
714*90552c61SAlexeiFedorov  * |   248  |       base 0       |                    |           |  |
715*90552c61SAlexeiFedorov  * +--------+--------------------+    ncoh_region[0]  |           |  |
716*90552c61SAlexeiFedorov  * |   256  |       size 0       |                    |           |  |
717bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+           |  |
718*90552c61SAlexeiFedorov  * |   264  |       base 1       |                    |           |  |
719*90552c61SAlexeiFedorov  * +--------+--------------------+    ncoh_region[1]  |           |  |
720*90552c61SAlexeiFedorov  * |   272  |       size 1       |                    |           |  |
721*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<----------+  |
722*90552c61SAlexeiFedorov  * |   280  |     smmu_base      |                    |              |
723*90552c61SAlexeiFedorov  * +--------+--------------------+      smmus[0]      |              |
724*90552c61SAlexeiFedorov  * |   288  |     smmu_r_base    |                    |              |
725*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-------------+
726*90552c61SAlexeiFedorov  * |   296  |     ecam_base      |                    |
727*90552c61SAlexeiFedorov  * +--------+--------------------+                    |
728*90552c61SAlexeiFedorov  * |   304  |      segment       |                    |
729*90552c61SAlexeiFedorov  * +--------+--------------------+                    |
730*90552c61SAlexeiFedorov  * |   305  |      padding       |   root_complex[0]  +--+
731bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
732*90552c61SAlexeiFedorov  * |   308  |   num_root_ports   |                    |  |
733bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
734*90552c61SAlexeiFedorov  * |   312  |     root_ports     |                    |  |
735*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-+
736*90552c61SAlexeiFedorov  * |   320  |    root_port_id    |                    |
737*90552c61SAlexeiFedorov  * +--------+--------------------+                    |
738*90552c61SAlexeiFedorov  * |   322  |      padding       |                    |
739*90552c61SAlexeiFedorov  * +--------+--------------------+   root_ports[0]    +--+
740*90552c61SAlexeiFedorov  * |   324  |  num_bdf_mappings  |                    |  |
741bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
742*90552c61SAlexeiFedorov  * |   328  |    bdf_mappings    |                    |  |
743*90552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-+
744*90552c61SAlexeiFedorov  * |   336  |    mapping_base    |                    |
745*90552c61SAlexeiFedorov  * +--------+--------------------+                    |
746*90552c61SAlexeiFedorov  * |   338  |    mapping_top     |                    |
747*90552c61SAlexeiFedorov  * +--------+--------------------+   bdf_mappings[0]  |
748*90552c61SAlexeiFedorov  * |   340  |    mapping_off     |                    |
749*90552c61SAlexeiFedorov  * +--------+--------------------+                    |
750*90552c61SAlexeiFedorov  * |   342  |     smmu_idx       |                    |
751bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
752bef44f60SAlexeiFedorov  */
753a97bfa5fSAlexeiFedorov int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
7541d0ca40eSJavier Almansa Sobrino {
75532904472SSoby Mathew 	uint64_t checksum, num_banks, num_consoles;
756bef44f60SAlexeiFedorov 	uint64_t num_ncoh_regions, num_coh_regions;
757*90552c61SAlexeiFedorov 	uint64_t num_smmus, num_root_complex;
758*90552c61SAlexeiFedorov 	unsigned int num_root_ports, num_bdf_mappings;
759*90552c61SAlexeiFedorov 	uint32_t o_realm;
760*90552c61SAlexeiFedorov 	struct memory_bank *bank_ptr, *ncoh_region_ptr, *coh_region_ptr;
76132904472SSoby Mathew 	struct console_info *console_ptr;
762*90552c61SAlexeiFedorov 	struct smmu_info *smmu_ptr;
763*90552c61SAlexeiFedorov 	struct root_complex_info *root_complex_ptr, *rc_ptr;
764*90552c61SAlexeiFedorov 	struct root_port_info *root_port_ptr, *rp_ptr;
765*90552c61SAlexeiFedorov 	struct bdf_mapping_info *bdf_mapping_ptr, *bdf_ptr;
766a97bfa5fSAlexeiFedorov 
7671d0ca40eSJavier Almansa Sobrino 	assert(manifest != NULL);
7681d0ca40eSJavier Almansa Sobrino 
76982685904SAlexeiFedorov 	/* Get number of DRAM banks */
77082685904SAlexeiFedorov 	num_banks = FCONF_GET_PROPERTY(hw_config, dram_layout, num_banks);
77182685904SAlexeiFedorov 	assert(num_banks <= ARM_DRAM_NUM_BANKS);
77282685904SAlexeiFedorov 
77332904472SSoby Mathew 	/* Set number of consoles */
77432904472SSoby Mathew 	num_consoles = FVP_RMM_CONSOLE_COUNT;
77532904472SSoby Mathew 
776bef44f60SAlexeiFedorov 	/* Set number of device non-coherent address ranges based on DT */
777bef44f60SAlexeiFedorov 	num_ncoh_regions = FCONF_GET_PROPERTY(hw_config, pci_props, num_ncoh_regions);
778bef44f60SAlexeiFedorov 
779*90552c61SAlexeiFedorov 	/* Set number of SMMUs */
780*90552c61SAlexeiFedorov 	num_smmus = FVP_RMM_SMMU_COUNT;
781*90552c61SAlexeiFedorov 
782*90552c61SAlexeiFedorov 	/* Set number of PCIe root complexes */
783*90552c61SAlexeiFedorov 	num_root_complex = FVP_RMM_RC_COUNT;
784*90552c61SAlexeiFedorov 
785*90552c61SAlexeiFedorov 	/* Calculate and set number of all PCIe root ports and BDF mappings */
786*90552c61SAlexeiFedorov 	num_root_ports = 0U;
787*90552c61SAlexeiFedorov 	num_bdf_mappings = 0U;
788*90552c61SAlexeiFedorov 
789*90552c61SAlexeiFedorov 	/* Scan all root complex entries */
790*90552c61SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_root_complex; i++) {
791*90552c61SAlexeiFedorov 		num_root_ports += rc_data[i].num_root_ports;
792*90552c61SAlexeiFedorov 
793*90552c61SAlexeiFedorov 		/* Scan all root ports entries in root complex */
794*90552c61SAlexeiFedorov 		for (unsigned int j = 0U; j < rc_data[i].num_root_ports; j++) {
795*90552c61SAlexeiFedorov 			num_bdf_mappings += rc_data[i].root_ports[j].num_bdf_mappings;
796*90552c61SAlexeiFedorov 		}
797*90552c61SAlexeiFedorov 	}
798*90552c61SAlexeiFedorov 
7991d0ca40eSJavier Almansa Sobrino 	manifest->version = RMMD_MANIFEST_VERSION;
800dc0ca64eSJavier Almansa Sobrino 	manifest->padding = 0U; /* RES0 */
801bef44f60SAlexeiFedorov 	manifest->plat_data = 0UL;
80282685904SAlexeiFedorov 	manifest->plat_dram.num_banks = num_banks;
80332904472SSoby Mathew 	manifest->plat_console.num_consoles = num_consoles;
804bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.num_banks = num_ncoh_regions;
805*90552c61SAlexeiFedorov 	manifest->plat_smmu.num_smmus = num_smmus;
806*90552c61SAlexeiFedorov 	manifest->plat_root_complex.num_root_complex = num_root_complex;
807*90552c61SAlexeiFedorov 	manifest->plat_root_complex.rc_info_version = PCIE_RC_INFO_VERSION;
808*90552c61SAlexeiFedorov 	manifest->plat_root_complex.padding = 0U; /* RES0 */
809a97bfa5fSAlexeiFedorov 
810bef44f60SAlexeiFedorov 	/* FVP does not support device coherent address ranges */
811bef44f60SAlexeiFedorov 	num_coh_regions = 0UL;
812bef44f60SAlexeiFedorov 	manifest->plat_coh_region.num_banks = num_coh_regions;
813bef44f60SAlexeiFedorov 	manifest->plat_coh_region.banks = NULL;
814bef44f60SAlexeiFedorov 	manifest->plat_coh_region.checksum = 0UL;
81532904472SSoby Mathew 
816bef44f60SAlexeiFedorov 	bank_ptr = (struct memory_bank *)
817bef44f60SAlexeiFedorov 			(((uintptr_t)manifest) + sizeof(struct rmm_manifest));
81832904472SSoby Mathew 	console_ptr = (struct console_info *)
819bef44f60SAlexeiFedorov 			((uintptr_t)bank_ptr + (num_banks *
820bef44f60SAlexeiFedorov 						sizeof(struct memory_bank)));
821bef44f60SAlexeiFedorov 	ncoh_region_ptr = (struct memory_bank *)
822bef44f60SAlexeiFedorov 			((uintptr_t)console_ptr + (num_consoles *
823bef44f60SAlexeiFedorov 						sizeof(struct console_info)));
824*90552c61SAlexeiFedorov 	coh_region_ptr = (struct memory_bank *)
825*90552c61SAlexeiFedorov 			((uintptr_t)ncoh_region_ptr + (num_ncoh_regions *
826*90552c61SAlexeiFedorov 						sizeof(struct memory_bank)));
827*90552c61SAlexeiFedorov 	smmu_ptr = (struct smmu_info *)
828*90552c61SAlexeiFedorov 			((uintptr_t)coh_region_ptr + (num_coh_regions *
829*90552c61SAlexeiFedorov 						sizeof(struct memory_bank)));
830*90552c61SAlexeiFedorov 	root_complex_ptr = (struct root_complex_info *)
831*90552c61SAlexeiFedorov 			((uintptr_t)smmu_ptr + (num_smmus *
832*90552c61SAlexeiFedorov 						sizeof(struct smmu_info)));
833*90552c61SAlexeiFedorov 	root_port_ptr = (struct	root_port_info *)
834*90552c61SAlexeiFedorov 			((uintptr_t)root_complex_ptr + (num_root_complex *
835*90552c61SAlexeiFedorov 						sizeof(struct root_complex_info)));
836*90552c61SAlexeiFedorov 	bdf_mapping_ptr = (struct bdf_mapping_info *)
837*90552c61SAlexeiFedorov 			((uintptr_t)root_port_ptr + (num_root_ports *
838*90552c61SAlexeiFedorov 						sizeof(struct root_port_info)));
839*90552c61SAlexeiFedorov 
84082685904SAlexeiFedorov 	manifest->plat_dram.banks = bank_ptr;
84132904472SSoby Mathew 	manifest->plat_console.consoles = console_ptr;
842bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.banks = ncoh_region_ptr;
843*90552c61SAlexeiFedorov 	manifest->plat_smmu.smmus = smmu_ptr;
844*90552c61SAlexeiFedorov 	manifest->plat_root_complex.root_complex = root_complex_ptr;
84532904472SSoby Mathew 
84632904472SSoby Mathew 	/* Ensure the manifest is not larger than the shared buffer */
84732904472SSoby Mathew 	assert((sizeof(struct rmm_manifest) +
848bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
849bef44f60SAlexeiFedorov 			manifest->plat_dram.num_banks) +
850bef44f60SAlexeiFedorov 		(sizeof(struct console_info) *
851bef44f60SAlexeiFedorov 			manifest->plat_console.num_consoles) +
852bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
853bef44f60SAlexeiFedorov 			manifest->plat_ncoh_region.num_banks) +
854bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
855*90552c61SAlexeiFedorov 			manifest->plat_coh_region.num_banks) +
856*90552c61SAlexeiFedorov 		(sizeof(struct smmu_info) *
857*90552c61SAlexeiFedorov 			manifest->plat_smmu.num_smmus) +
858*90552c61SAlexeiFedorov 		(sizeof(struct root_complex_info) *
859*90552c61SAlexeiFedorov 			manifest->plat_root_complex.num_root_complex) +
860*90552c61SAlexeiFedorov 		(sizeof(struct root_port_info) * num_root_ports) +
861*90552c61SAlexeiFedorov 		(sizeof(struct bdf_mapping_info) * num_bdf_mappings))
862bef44f60SAlexeiFedorov 		<= ARM_EL3_RMM_SHARED_SIZE);
863a97bfa5fSAlexeiFedorov 
864a97bfa5fSAlexeiFedorov 	/* Calculate checksum of plat_dram structure */
86582685904SAlexeiFedorov 	checksum = num_banks + (uint64_t)bank_ptr;
866a97bfa5fSAlexeiFedorov 
86782685904SAlexeiFedorov 	/* Store FVP DRAM banks data in Boot Manifest */
86882685904SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_banks; i++) {
869aa99881dSAlexeiFedorov 		bank_ptr[i].base = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].base);
870aa99881dSAlexeiFedorov 		bank_ptr[i].size = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].size);
871aa99881dSAlexeiFedorov 	}
87282685904SAlexeiFedorov 
87382685904SAlexeiFedorov 	/* Update checksum */
874bef44f60SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)bank_ptr, sizeof(struct memory_bank) * num_banks);
875a97bfa5fSAlexeiFedorov 
876a97bfa5fSAlexeiFedorov 	/* Checksum must be 0 */
87782685904SAlexeiFedorov 	manifest->plat_dram.checksum = ~checksum + 1UL;
8781d0ca40eSJavier Almansa Sobrino 
879bef44f60SAlexeiFedorov 	/* Calculate the checksum of plat_consoles structure */
88032904472SSoby Mathew 	checksum = num_consoles + (uint64_t)console_ptr;
88132904472SSoby Mathew 
88232904472SSoby Mathew 	/* Zero out the console info struct */
883bef44f60SAlexeiFedorov 	(void)memset((void *)console_ptr, '\0',
884bef44f60SAlexeiFedorov 			sizeof(struct console_info) * num_consoles);
88532904472SSoby Mathew 
88632904472SSoby Mathew 	console_ptr[0].base = FVP_RMM_CONSOLE_BASE;
887aa99881dSAlexeiFedorov 	console_ptr[0].map_pages = 1UL;
88832904472SSoby Mathew 	console_ptr[0].clk_in_hz = FVP_RMM_CONSOLE_CLK_IN_HZ;
88932904472SSoby Mathew 	console_ptr[0].baud_rate = FVP_RMM_CONSOLE_BAUD;
89032904472SSoby Mathew 
891bef44f60SAlexeiFedorov 	(void)strlcpy(console_ptr[0].name, FVP_RMM_CONSOLE_NAME,
892bef44f60SAlexeiFedorov 						RMM_CONSOLE_MAX_NAME_LEN - 1UL);
89332904472SSoby Mathew 
89432904472SSoby Mathew 	/* Update checksum */
895aa99881dSAlexeiFedorov 	checksum += checksum_calc((uint64_t *)console_ptr,
896aa99881dSAlexeiFedorov 					sizeof(struct console_info) * num_consoles);
89732904472SSoby Mathew 	/* Checksum must be 0 */
89832904472SSoby Mathew 	manifest->plat_console.checksum = ~checksum + 1UL;
89932904472SSoby Mathew 
900bef44f60SAlexeiFedorov 	/*
901bef44f60SAlexeiFedorov 	 * Calculate the checksum of device non-coherent address ranges
902bef44f60SAlexeiFedorov 	 * info structure
903bef44f60SAlexeiFedorov 	 */
904bef44f60SAlexeiFedorov 	checksum = num_ncoh_regions + (uint64_t)ncoh_region_ptr;
905bef44f60SAlexeiFedorov 
906bef44f60SAlexeiFedorov 	/* Zero out the PCIe region info struct */
907bef44f60SAlexeiFedorov 	(void)memset((void *)ncoh_region_ptr, 0,
908bef44f60SAlexeiFedorov 			sizeof(struct memory_bank) * num_ncoh_regions);
909bef44f60SAlexeiFedorov 
910bef44f60SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_ncoh_regions; i++) {
911bef44f60SAlexeiFedorov 		ncoh_region_ptr[i].base =
912bef44f60SAlexeiFedorov 			FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].base);
913bef44f60SAlexeiFedorov 		ncoh_region_ptr[i].size =
914bef44f60SAlexeiFedorov 			FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].size);
915bef44f60SAlexeiFedorov 	}
916bef44f60SAlexeiFedorov 
917bef44f60SAlexeiFedorov 	/* Update checksum */
918bef44f60SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)ncoh_region_ptr,
919bef44f60SAlexeiFedorov 			sizeof(struct memory_bank) * num_ncoh_regions);
920bef44f60SAlexeiFedorov 
921bef44f60SAlexeiFedorov 	/* Checksum must be 0 */
922bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.checksum = ~checksum + 1UL;
923bef44f60SAlexeiFedorov 
924*90552c61SAlexeiFedorov 	/* Calculate the checksum of the plat_smmu structure */
925*90552c61SAlexeiFedorov 	checksum = num_smmus + (uint64_t)smmu_ptr;
926*90552c61SAlexeiFedorov 
927*90552c61SAlexeiFedorov 	smmu_ptr[0].smmu_base = FVP_RMM_SMMU_BASE;
928*90552c61SAlexeiFedorov 
929*90552c61SAlexeiFedorov 	/* Read SMMU_ROOT_IDR0.BA_REALM[31:22] register field */
930*90552c61SAlexeiFedorov 	o_realm = mmio_read_32(FVP_RMM_SMMU_BASE + SMMU_ROOT_IDR0) &
931*90552c61SAlexeiFedorov 				SMMU_ROOT_IDR0_BA_REALM_MASK;
932*90552c61SAlexeiFedorov 	/*
933*90552c61SAlexeiFedorov 	 * Calculate the base address offset of Realm Register Page 0.
934*90552c61SAlexeiFedorov 	 * O_REALM = 0x20000 + (BA_REALM * 0x10000)
935*90552c61SAlexeiFedorov 	 * SMMU_REALM_BASE = SMMU_PAGE_0_BASE + O_REALM
936*90552c61SAlexeiFedorov 	 */
937*90552c61SAlexeiFedorov 	o_realm = 0x20000 + (o_realm >> (SMMU_ROOT_IDR0_BA_REALM_SHIFT - 16U));
938*90552c61SAlexeiFedorov 
939*90552c61SAlexeiFedorov 	smmu_ptr[0].smmu_r_base = FVP_RMM_SMMU_BASE + o_realm;
940*90552c61SAlexeiFedorov 
941*90552c61SAlexeiFedorov 	/* Update checksum */
942*90552c61SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)smmu_ptr,
943*90552c61SAlexeiFedorov 					sizeof(struct smmu_info) * num_smmus);
944*90552c61SAlexeiFedorov 	/* Checksum must be 0 */
945*90552c61SAlexeiFedorov 	manifest->plat_smmu.checksum = ~checksum + 1UL;
946*90552c61SAlexeiFedorov 
947*90552c61SAlexeiFedorov 	/* Calculate the checksum of the plat_root_complex structure */
948*90552c61SAlexeiFedorov 	checksum = num_root_complex + (uint64_t)root_complex_ptr;
949*90552c61SAlexeiFedorov 
950*90552c61SAlexeiFedorov 	/* Zero out PCIe root complex info structures */
951*90552c61SAlexeiFedorov 	(void)memset((void *)root_complex_ptr, 0,
952*90552c61SAlexeiFedorov 			sizeof(struct root_complex_info) * num_root_complex);
953*90552c61SAlexeiFedorov 
954*90552c61SAlexeiFedorov 	/* Set pointers for data in manifest */
955*90552c61SAlexeiFedorov 	rc_ptr = root_complex_ptr;
956*90552c61SAlexeiFedorov 	rp_ptr = root_port_ptr;
957*90552c61SAlexeiFedorov 	bdf_ptr = bdf_mapping_ptr;
958*90552c61SAlexeiFedorov 
959*90552c61SAlexeiFedorov 	/* Fill PCIe root complex info structures */
960*90552c61SAlexeiFedorov 	for (unsigned long i = 0U; i < num_root_complex; i++) {
961*90552c61SAlexeiFedorov 		const struct root_complex_info *rc_info = &rc_data[i];
962*90552c61SAlexeiFedorov 		const struct root_port_info *rp_info = rc_info->root_ports;
963*90552c61SAlexeiFedorov 
964*90552c61SAlexeiFedorov 		/* Copy root complex data, except root_ports pointer */
965*90552c61SAlexeiFedorov 		(void)memcpy((void *)rc_ptr, (void *)rc_info,
966*90552c61SAlexeiFedorov 			sizeof(struct root_complex_info) - sizeof(struct root_port_info *));
967*90552c61SAlexeiFedorov 
968*90552c61SAlexeiFedorov 		/* Set root_ports for root complex */
969*90552c61SAlexeiFedorov 		rc_ptr->root_ports = rp_ptr;
970*90552c61SAlexeiFedorov 
971*90552c61SAlexeiFedorov 		/* Scan root ports */
972*90552c61SAlexeiFedorov 		for (unsigned int j = 0U; j < rc_ptr->num_root_ports; j++) {
973*90552c61SAlexeiFedorov 			const struct bdf_mapping_info *bdf_info = rp_info->bdf_mappings;
974*90552c61SAlexeiFedorov 
975*90552c61SAlexeiFedorov 			/* Copy root port data, except bdf_mappings pointer */
976*90552c61SAlexeiFedorov 			(void)memcpy((void *)rp_ptr, (void *)rp_info,
977*90552c61SAlexeiFedorov 				sizeof(struct root_port_info) - sizeof(struct bdf_mapping_info *));
978*90552c61SAlexeiFedorov 
979*90552c61SAlexeiFedorov 			/* Set bdf_mappings for root port */
980*90552c61SAlexeiFedorov 			rp_ptr->bdf_mappings = bdf_ptr;
981*90552c61SAlexeiFedorov 
982*90552c61SAlexeiFedorov 			/* Copy all BDF mappings for root port */
983*90552c61SAlexeiFedorov 			(void)memcpy((void *)bdf_ptr, (void *)bdf_info,
984*90552c61SAlexeiFedorov 				sizeof(struct bdf_mapping_info) * rp_ptr->num_bdf_mappings);
985*90552c61SAlexeiFedorov 
986*90552c61SAlexeiFedorov 			bdf_ptr += rp_ptr->num_bdf_mappings;
987*90552c61SAlexeiFedorov 			rp_ptr++;
988*90552c61SAlexeiFedorov 			rp_info++;
989*90552c61SAlexeiFedorov 		}
990*90552c61SAlexeiFedorov 		rc_ptr++;
991*90552c61SAlexeiFedorov 	}
992*90552c61SAlexeiFedorov 
993*90552c61SAlexeiFedorov 	/* Check that all data are written in manifest */
994*90552c61SAlexeiFedorov 	assert(rc_ptr == (root_complex_ptr + num_root_complex));
995*90552c61SAlexeiFedorov 	assert(rp_ptr == (root_port_ptr + num_root_ports));
996*90552c61SAlexeiFedorov 	assert(bdf_ptr == (bdf_mapping_ptr + num_bdf_mappings));
997*90552c61SAlexeiFedorov 
998*90552c61SAlexeiFedorov 	/* Update checksum for all PCIe data */
999*90552c61SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)root_complex_ptr,
1000*90552c61SAlexeiFedorov 				(uintptr_t)bdf_ptr - (uintptr_t)root_complex_ptr);
1001*90552c61SAlexeiFedorov 
1002*90552c61SAlexeiFedorov 	/* Checksum must be 0 */
1003*90552c61SAlexeiFedorov 	manifest->plat_root_complex.checksum = ~checksum + 1UL;
1004*90552c61SAlexeiFedorov 
10051d0ca40eSJavier Almansa Sobrino 	return 0;
10061d0ca40eSJavier Almansa Sobrino }
1007f801fdc2STushar Khandelwal 
1008f801fdc2STushar Khandelwal /*
1009f801fdc2STushar Khandelwal  * Update encryption key associated with @mecid.
1010f801fdc2STushar Khandelwal  */
1011f801fdc2STushar Khandelwal int plat_rmmd_mecid_key_update(uint16_t mecid)
1012f801fdc2STushar Khandelwal {
1013f801fdc2STushar Khandelwal 	/*
1014f801fdc2STushar Khandelwal 	 * FVP does not provide an interface to change the encryption key associated
1015f801fdc2STushar Khandelwal 	 * with MECID. Hence always return success.
1016f801fdc2STushar Khandelwal 	 */
1017f801fdc2STushar Khandelwal 	return 0;
1018f801fdc2STushar Khandelwal }
1019a97bfa5fSAlexeiFedorov #endif /* ENABLE_RME */
1020