xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision e2e90fa1cd8ebe344b3552fa762d3fd3d63d5721)
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>
1790552c61SAlexeiFedorov #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 
4790552c61SAlexeiFedorov /* Defines for RMM PCIe ECAM */
4890552c61SAlexeiFedorov #define FVP_RMM_ECAM_BASE		PCIE_EXP_BASE
4990552c61SAlexeiFedorov #define FVP_RMM_ECAM_SEGMENT		UL(0x0)
5090552c61SAlexeiFedorov #define FVP_RMM_ECAM_BDF		UL(0x0)
5190552c61SAlexeiFedorov 
5290552c61SAlexeiFedorov /* Defines for RMM SMMUv3 */
5390552c61SAlexeiFedorov #define FVP_RMM_SMMU_BASE		PLAT_FVP_SMMUV3_BASE
5490552c61SAlexeiFedorov #define FVP_RMM_SMMU_COUNT		UL(1)
5590552c61SAlexeiFedorov 
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,			\
71*e2e90fa1SBoyan Karatotev 					MT_DEVICE | MT_RW | EL3_PAS)
72*e2e90fa1SBoyan Karatotev 
73*e2e90fa1SBoyan Karatotev #define MAP_CCN		MAP_REGION_FLAT(CCN_BASE,			\
74*e2e90fa1SBoyan Karatotev 					CCN_SIZE,			\
753e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
763e4b8fdcSSoby Mathew 
77f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
78f98630fbSManish V Badarkhe #define MAP_GICD_MEM	MAP_REGION_FLAT(BASE_GICD_BASE,			\
79f98630fbSManish V Badarkhe 					BASE_GICD_SIZE,			\
80f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RW | MT_SECURE)
81f98630fbSManish V Badarkhe 
82f98630fbSManish V Badarkhe /* Map all core's redistributor memory as read-only. After boots up,
83f98630fbSManish V Badarkhe  * per-core map its redistributor memory as read-write */
84f98630fbSManish V Badarkhe #define MAP_GICR_MEM	MAP_REGION_FLAT(BASE_GICR_BASE,			\
85f98630fbSManish V Badarkhe 					(BASE_GICR_SIZE * PLATFORM_CORE_COUNT),\
86f98630fbSManish V Badarkhe 					MT_DEVICE | MT_RO | MT_SECURE)
87f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
88f98630fbSManish V Badarkhe 
89284c3d67SSandrine Bailleux /*
90284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
91284c3d67SSandrine Bailleux  * counter value.
92284c3d67SSandrine Bailleux  */
933e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
943e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
95fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
963e4b8fdcSSoby Mathew 
9794c90ac8SHarrison Mutai #if TRANSFER_LIST
9894c90ac8SHarrison Mutai #ifdef FW_NS_HANDOFF_BASE
99a5566f65SHarrison Mutai #define MAP_FW_NS_HANDOFF                                             \
100a5566f65SHarrison Mutai 	MAP_REGION_FLAT(FW_NS_HANDOFF_BASE, PLAT_ARM_FW_HANDOFF_SIZE, \
10194c90ac8SHarrison Mutai 			MT_MEMORY | MT_RW | MT_NS)
10294c90ac8SHarrison Mutai #endif
103a5566f65SHarrison Mutai #ifdef PLAT_ARM_EL3_FW_HANDOFF_BASE
104a5566f65SHarrison Mutai #define MAP_EL3_FW_HANDOFF                            \
105a5566f65SHarrison Mutai 	MAP_REGION_FLAT(PLAT_ARM_EL3_FW_HANDOFF_BASE, \
106a5566f65SHarrison Mutai 			PLAT_ARM_FW_HANDOFF_SIZE, MT_MEMORY | MT_RW | EL3_PAS)
107a5566f65SHarrison Mutai #endif
10894c90ac8SHarrison Mutai #endif
10994c90ac8SHarrison Mutai 
1103e4b8fdcSSoby Mathew /*
111b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
1120916c38dSRoberto Vargas  * This doesn't include Trusted SRAM as setup_page_tables() already takes care
1130916c38dSRoberto Vargas  * of mapping it.
1143e4b8fdcSSoby Mathew  */
1153d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
1163e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1173e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
11879d8be3cSManish V Badarkhe 	V2M_MAP_FLASH0_RO,
1193e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1203e4b8fdcSSoby Mathew 	MAP_DEVICE0,
121e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
122*e2e90fa1SBoyan Karatotev 	MAP_CCN,
123e0cea783SManish V Badarkhe #endif
1243e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
125284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
126284c3d67SSandrine Bailleux 	MAP_DEVICE2,
127284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
1283e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
1293e4b8fdcSSoby Mathew #endif
1303e4b8fdcSSoby Mathew 	{0}
1313e4b8fdcSSoby Mathew };
1323e4b8fdcSSoby Mathew #endif
1333d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
1343e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1353e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
1363e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
1373e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1383e4b8fdcSSoby Mathew 	MAP_DEVICE0,
139e0cea783SManish V Badarkhe #if FVP_INTERCONNECT_DRIVER == FVP_CCN
140*e2e90fa1SBoyan Karatotev 	MAP_CCN,
141e0cea783SManish V Badarkhe #endif
1423e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
143402b3cf8SJulius Werner #ifdef __aarch64__
144b09ba056SRoberto Vargas 	ARM_MAP_DRAM2,
145b09ba056SRoberto Vargas #endif
14639f0b86aSManish V Badarkhe 	/*
14739f0b86aSManish V Badarkhe 	 * Required to load HW_CONFIG, SPMC and SPs to trusted DRAM.
14839f0b86aSManish V Badarkhe 	 */
14964758c97SAchin Gupta 	ARM_MAP_TRUSTED_DRAM,
1506b2e961fSManish V Badarkhe 
1516b2e961fSManish V Badarkhe 	/*
1526b2e961fSManish V Badarkhe 	 * Required to load Event Log in TZC secured memory
1536b2e961fSManish V Badarkhe 	 */
1546b2e961fSManish V Badarkhe #if MEASURED_BOOT && (defined(SPD_tspd) || defined(SPD_opteed) || \
1556b2e961fSManish V Badarkhe defined(SPD_spmd))
1566b2e961fSManish V Badarkhe 	ARM_MAP_EVENT_LOG_DRAM1,
1576b2e961fSManish V Badarkhe #endif /* MEASURED_BOOT && (SPD_tspd || SPD_opteed || SPD_spmd) */
1586b2e961fSManish V Badarkhe 
159c8720729SZelalem Aweke #if ENABLE_RME
160c8720729SZelalem Aweke 	ARM_MAP_RMM_DRAM,
161c8720729SZelalem Aweke 	ARM_MAP_GPT_L1_DRAM,
162c8720729SZelalem Aweke #endif /* ENABLE_RME */
1633eb2d672SSandrine Bailleux #ifdef SPD_tspd
1643e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
1653eb2d672SSandrine Bailleux #endif
166284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
167284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
168284c3d67SSandrine Bailleux 	MAP_DEVICE2,
169ba597da7SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */
17088c51c3fSManish V Badarkhe 
17142d4d3baSArvind Ram Prakash #if CRYPTO_SUPPORT && !RESET_TO_BL2
17288c51c3fSManish V Badarkhe 	/*
17388c51c3fSManish V Badarkhe 	 * To access shared the Mbed TLS heap while booting the
17488c51c3fSManish V Badarkhe 	 * system with Crypto support
17588c51c3fSManish V Badarkhe 	 */
17688c51c3fSManish V Badarkhe 	ARM_MAP_BL1_RW,
17742d4d3baSArvind Ram Prakash #endif /* CRYPTO_SUPPORT && !RESET_TO_BL2 */
17844639ab7SMarc Bonnici #if SPM_MM || SPMC_AT_EL3
179e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
180e29efeb1SAntonio Nino Diaz #endif
1813e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
1823e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
1833e4b8fdcSSoby Mathew #endif
184810d9213SJens Wiklander #ifdef SPD_opteed
185b3ba6fdaSSoby Mathew 	ARM_MAP_OPTEE_CORE_MEM,
186810d9213SJens Wiklander 	ARM_OPTEE_PAGEABLE_LOAD_MEM,
187810d9213SJens Wiklander #endif
188a5566f65SHarrison Mutai #ifdef MAP_EL3_FW_HANDOFF
189a5566f65SHarrison Mutai 	MAP_EL3_FW_HANDOFF,
190a5566f65SHarrison Mutai #endif
1913e4b8fdcSSoby Mathew 	{ 0 }
1923e4b8fdcSSoby Mathew };
1933e4b8fdcSSoby Mathew #endif
1943d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
1953e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1963e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1973e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1983e4b8fdcSSoby Mathew 	{0}
1993e4b8fdcSSoby Mathew };
2003e4b8fdcSSoby Mathew #endif
2013d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
2023e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
2033e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
204992f091bSAmbroise Vincent #if USE_DEBUGFS
205992f091bSAmbroise Vincent 	/* Required by devfip, can be removed if devfip is not used */
206992f091bSAmbroise Vincent 	V2M_MAP_FLASH0_RW,
207992f091bSAmbroise Vincent #endif /* USE_DEBUGFS */
208e35a3fb5SSoby Mathew 	ARM_MAP_EL3_TZC_DRAM,
2093e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
2103e4b8fdcSSoby Mathew 	MAP_DEVICE0,
211f98630fbSManish V Badarkhe #if FVP_GICR_REGION_PROTECTION
212f98630fbSManish V Badarkhe 	MAP_GICD_MEM,
213f98630fbSManish V Badarkhe 	MAP_GICR_MEM,
214f98630fbSManish V Badarkhe #else
215*e2e90fa1SBoyan Karatotev #if FVP_INTERCONNECT_DRIVER == FVP_CCN
216*e2e90fa1SBoyan Karatotev 	MAP_CCN,
217*e2e90fa1SBoyan Karatotev #endif
2183e4b8fdcSSoby Mathew 	MAP_DEVICE1,
219f98630fbSManish V Badarkhe #endif /* FVP_GICR_REGION_PROTECTION */
220f145403cSRoberto Vargas 	ARM_V2M_MAP_MEM_PROTECT,
2213f3c341aSPaul Beesley #if SPM_MM
222e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL3_MMAP,
223e29efeb1SAntonio Nino Diaz #endif
224c8720729SZelalem Aweke #if ENABLE_RME
225c8720729SZelalem Aweke 	ARM_MAP_GPT_L1_DRAM,
2268c980a4aSJavier Almansa Sobrino 	ARM_MAP_EL3_RMM_SHARED_MEM,
227c8720729SZelalem Aweke #endif
22894c90ac8SHarrison Mutai #ifdef MAP_FW_NS_HANDOFF
22994c90ac8SHarrison Mutai 	MAP_FW_NS_HANDOFF,
23094c90ac8SHarrison Mutai #endif
2311a0ebff7SHarrison Mutai #if defined(MAP_EL3_FW_HANDOFF) && !RESET_TO_BL31
232a5566f65SHarrison Mutai 	MAP_EL3_FW_HANDOFF,
233a5566f65SHarrison Mutai #endif
2343e4b8fdcSSoby Mathew 	{ 0 }
2353e4b8fdcSSoby Mathew };
236e29efeb1SAntonio Nino Diaz 
2373f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
238e29efeb1SAntonio Nino Diaz const mmap_region_t plat_arm_secure_partition_mmap[] = {
239e29efeb1SAntonio Nino Diaz 	V2M_MAP_IOFPGA_EL0, /* for the UART */
2409fb76763Slevi.yun 	V2M_MAP_SECURE_SYSTEMREG_EL0, /* for initializing flash */
2419fb76763Slevi.yun #if PSA_FWU_SUPPORT
2429fb76763Slevi.yun 	V2M_MAP_FLASH0_RW_EL0, /* for firmware update service in standalone mm */
2439fb76763Slevi.yun #endif
2449fb76763Slevi.yun 	V2M_MAP_FLASH1_RW_EL0, /* for secure variable service in standalone mm */
2459a90d720SElyes Haouas 	MAP_REGION_FLAT(DEVICE0_BASE,
2469a90d720SElyes Haouas 			DEVICE0_SIZE,
247c4fa1739SSandrine Bailleux 			MT_DEVICE | MT_RO | MT_SECURE | MT_USER),
248e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_MMAP,
249e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_NS_BUF_MMAP,
250e29efeb1SAntonio Nino Diaz 	ARM_SP_IMAGE_RW_MMAP,
251e29efeb1SAntonio Nino Diaz 	ARM_SPM_BUF_EL0_MMAP,
252e29efeb1SAntonio Nino Diaz 	{0}
253e29efeb1SAntonio Nino Diaz };
254e29efeb1SAntonio Nino Diaz #endif
2553e4b8fdcSSoby Mathew #endif
2563d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
2573e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
258402b3cf8SJulius Werner #ifndef __aarch64__
259877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
260950c6956SJoel Hutton 	ARM_V2M_MAP_MEM_PROTECT,
261877cf3ffSSoby Mathew #endif
2623e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
2633e4b8fdcSSoby Mathew 	MAP_DEVICE0,
264*e2e90fa1SBoyan Karatotev #if FVP_INTERCONNECT_DRIVER == FVP_CCN
265*e2e90fa1SBoyan Karatotev 	MAP_CCN,
266*e2e90fa1SBoyan Karatotev #endif
2673e4b8fdcSSoby Mathew 	MAP_DEVICE1,
2683e4b8fdcSSoby Mathew 	{0}
2693e4b8fdcSSoby Mathew };
2703e4b8fdcSSoby Mathew #endif
2713e4b8fdcSSoby Mathew 
2729d870b79SZelalem Aweke #ifdef IMAGE_RMM
2739d870b79SZelalem Aweke const mmap_region_t plat_arm_mmap[] = {
2749d870b79SZelalem Aweke 	V2M_MAP_IOFPGA,
2759d870b79SZelalem Aweke 	MAP_DEVICE0,
2769d870b79SZelalem Aweke 	MAP_DEVICE1,
2779d870b79SZelalem Aweke 	{0}
2789d870b79SZelalem Aweke };
2799d870b79SZelalem Aweke #endif
2809d870b79SZelalem Aweke 
2813e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
2823e4b8fdcSSoby Mathew 
283955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN
284955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = {
285955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS0_SL_PORT,
286955242d8SJeenu Viswambharan 	PLAT_FVP_CCI400_CLUS1_SL_PORT,
287955242d8SJeenu Viswambharan };
288955242d8SJeenu Viswambharan 
289955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = {
290955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
291955242d8SJeenu Viswambharan 	PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
292955242d8SJeenu Viswambharan };
293955242d8SJeenu Viswambharan 
294955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void)
295955242d8SJeenu Viswambharan {
296955242d8SJeenu Viswambharan 	unsigned int master;
297955242d8SJeenu Viswambharan 	u_register_t mpidr;
298955242d8SJeenu Viswambharan 
299955242d8SJeenu Viswambharan 	mpidr = read_mpidr_el1();
300583e0791SAntonio Nino Diaz 	master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
301955242d8SJeenu Viswambharan 		MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
302955242d8SJeenu Viswambharan 
303955242d8SJeenu Viswambharan 	assert(master < FVP_CLUSTER_COUNT);
304955242d8SJeenu Viswambharan 	return master;
305955242d8SJeenu Viswambharan }
306955242d8SJeenu Viswambharan #endif
3073e4b8fdcSSoby Mathew 
3083f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM
309e29efeb1SAntonio Nino Diaz /*
310e29efeb1SAntonio Nino Diaz  * Boot information passed to a secure partition during initialisation. Linear
311e29efeb1SAntonio Nino Diaz  * indices in MP information will be filled at runtime.
312e29efeb1SAntonio Nino Diaz  */
313aeaa225cSPaul Beesley static spm_mm_mp_info_t sp_mp_info[] = {
314e29efeb1SAntonio Nino Diaz 	[0] = {0x80000000, 0},
315e29efeb1SAntonio Nino Diaz 	[1] = {0x80000001, 0},
316e29efeb1SAntonio Nino Diaz 	[2] = {0x80000002, 0},
317e29efeb1SAntonio Nino Diaz 	[3] = {0x80000003, 0},
318e29efeb1SAntonio Nino Diaz 	[4] = {0x80000100, 0},
319e29efeb1SAntonio Nino Diaz 	[5] = {0x80000101, 0},
320e29efeb1SAntonio Nino Diaz 	[6] = {0x80000102, 0},
321e29efeb1SAntonio Nino Diaz 	[7] = {0x80000103, 0},
322e29efeb1SAntonio Nino Diaz };
323e29efeb1SAntonio Nino Diaz 
324aeaa225cSPaul Beesley const spm_mm_boot_info_t plat_arm_secure_partition_boot_info = {
325e29efeb1SAntonio Nino Diaz 	.h.type              = PARAM_SP_IMAGE_BOOT_INFO,
326e29efeb1SAntonio Nino Diaz 	.h.version           = VERSION_1,
327aeaa225cSPaul Beesley 	.h.size              = sizeof(spm_mm_boot_info_t),
328e29efeb1SAntonio Nino Diaz 	.h.attr              = 0,
329e29efeb1SAntonio Nino Diaz 	.sp_mem_base         = ARM_SP_IMAGE_BASE,
330e29efeb1SAntonio Nino Diaz 	.sp_mem_limit        = ARM_SP_IMAGE_LIMIT,
331e29efeb1SAntonio Nino Diaz 	.sp_image_base       = ARM_SP_IMAGE_BASE,
332e29efeb1SAntonio Nino Diaz 	.sp_stack_base       = PLAT_SP_IMAGE_STACK_BASE,
333e29efeb1SAntonio Nino Diaz 	.sp_heap_base        = ARM_SP_IMAGE_HEAP_BASE,
3340560efb9SArd Biesheuvel 	.sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE,
335e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_base  = PLAT_SPM_BUF_BASE,
336e29efeb1SAntonio Nino Diaz 	.sp_image_size       = ARM_SP_IMAGE_SIZE,
337e29efeb1SAntonio Nino Diaz 	.sp_pcpu_stack_size  = PLAT_SP_IMAGE_STACK_PCPU_SIZE,
338e29efeb1SAntonio Nino Diaz 	.sp_heap_size        = ARM_SP_IMAGE_HEAP_SIZE,
3390560efb9SArd Biesheuvel 	.sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE,
340e29efeb1SAntonio Nino Diaz 	.sp_shared_buf_size  = PLAT_SPM_BUF_SIZE,
341e29efeb1SAntonio Nino Diaz 	.num_sp_mem_regions  = ARM_SP_IMAGE_NUM_MEM_REGIONS,
342e29efeb1SAntonio Nino Diaz 	.num_cpus            = PLATFORM_CORE_COUNT,
343e29efeb1SAntonio Nino Diaz 	.mp_info             = &sp_mp_info[0],
344e29efeb1SAntonio Nino Diaz };
345e29efeb1SAntonio Nino Diaz 
346e29efeb1SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie)
347e29efeb1SAntonio Nino Diaz {
348e29efeb1SAntonio Nino Diaz 	return plat_arm_secure_partition_mmap;
349e29efeb1SAntonio Nino Diaz }
350e29efeb1SAntonio Nino Diaz 
351aeaa225cSPaul Beesley const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
352e29efeb1SAntonio Nino Diaz 		void *cookie)
353e29efeb1SAntonio Nino Diaz {
354e29efeb1SAntonio Nino Diaz 	return &plat_arm_secure_partition_boot_info;
355e29efeb1SAntonio Nino Diaz }
356e29efeb1SAntonio Nino Diaz #endif
357e29efeb1SAntonio Nino Diaz 
3583e4b8fdcSSoby Mathew /*******************************************************************************
3593e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
3603e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
3613e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
3623e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
3633e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
3643e4b8fdcSSoby Mathew  ******************************************************************************/
3654d010d0dSDaniel Boulby void __init fvp_config_setup(void)
3663e4b8fdcSSoby Mathew {
3673e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
3683e4b8fdcSSoby Mathew 
3693e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
3703e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
3713e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
3723e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
3733e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
3743e4b8fdcSSoby Mathew 
3753e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
3763e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
3773e4b8fdcSSoby Mathew 		panic();
3783e4b8fdcSSoby Mathew 	}
3793e4b8fdcSSoby Mathew 
3803e4b8fdcSSoby Mathew 	/*
3813e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
3823e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
3833e4b8fdcSSoby Mathew 	 */
3843e4b8fdcSSoby Mathew 	switch (bld) {
3853e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
38621a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
38721a3973dSSoby Mathew 				" is not supported\n");
3883e4b8fdcSSoby Mathew 		panic();
3893e4b8fdcSSoby Mathew 		break;
3903e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
3913e4b8fdcSSoby Mathew 		break;
3923e4b8fdcSSoby Mathew 	default:
3933e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
3943e4b8fdcSSoby Mathew 		panic();
3953e4b8fdcSSoby Mathew 	}
3963e4b8fdcSSoby Mathew 
3973e4b8fdcSSoby Mathew 	/*
3983e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
3993e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
4003e4b8fdcSSoby Mathew 	 */
4013e4b8fdcSSoby Mathew 	switch (hbi) {
4023e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
4033e4b8fdcSSoby Mathew 		arm_config.flags = 0;
4043e4b8fdcSSoby Mathew 
4053e4b8fdcSSoby Mathew 		/*
4063e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
4073e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
4083e4b8fdcSSoby Mathew 		 */
4093e4b8fdcSSoby Mathew 		switch (rev) {
4103e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
4113e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
4123e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
4134faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
4143e4b8fdcSSoby Mathew 			break;
4153e4b8fdcSSoby Mathew 		default:
4163e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
4173e4b8fdcSSoby Mathew 			break;
4183e4b8fdcSSoby Mathew 		}
4193e4b8fdcSSoby Mathew 		break;
4203e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
421955242d8SJeenu Viswambharan 		arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
4223e4b8fdcSSoby Mathew 
4233e4b8fdcSSoby Mathew 		/*
4243e4b8fdcSSoby Mathew 		 * Check for supported revisions
4253e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
4263e4b8fdcSSoby Mathew 		 */
4273e4b8fdcSSoby Mathew 		switch (rev) {
4283e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
429955242d8SJeenu Viswambharan 			arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
430955242d8SJeenu Viswambharan 			break;
431955242d8SJeenu Viswambharan 		case REV_BASE_FVP_REVC:
4328431635bSIsla Mitchell 			arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 |
433955242d8SJeenu Viswambharan 					ARM_CONFIG_FVP_HAS_CCI5XX);
4343e4b8fdcSSoby Mathew 			break;
4353e4b8fdcSSoby Mathew 		default:
4363e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
4373e4b8fdcSSoby Mathew 			break;
4383e4b8fdcSSoby Mathew 		}
4393e4b8fdcSSoby Mathew 		break;
4403e4b8fdcSSoby Mathew 	default:
4413e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
4423e4b8fdcSSoby Mathew 		panic();
4433e4b8fdcSSoby Mathew 	}
4448431635bSIsla Mitchell 
4458431635bSIsla Mitchell 	/*
4468431635bSIsla Mitchell 	 * We assume that the presence of MT bit, and therefore shifted
4478431635bSIsla Mitchell 	 * affinities, is uniform across the platform: either all CPUs, or no
4488431635bSIsla Mitchell 	 * CPUs implement it.
4498431635bSIsla Mitchell 	 */
450583e0791SAntonio Nino Diaz 	if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U)
4518431635bSIsla Mitchell 		arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
4523e4b8fdcSSoby Mathew }
4533e4b8fdcSSoby Mathew 
4543e4b8fdcSSoby Mathew 
4554d010d0dSDaniel Boulby void __init fvp_interconnect_init(void)
4563e4b8fdcSSoby Mathew {
45771237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
45871237876SSoby Mathew 	if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
459583e0791SAntonio Nino Diaz 		ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
46071237876SSoby Mathew 		panic();
46171237876SSoby Mathew 	}
462955242d8SJeenu Viswambharan 
4633e4b8fdcSSoby Mathew 	plat_arm_interconnect_init();
464955242d8SJeenu Viswambharan #else
465583e0791SAntonio Nino Diaz 	uintptr_t cci_base = 0U;
466583e0791SAntonio Nino Diaz 	const int *cci_map = NULL;
467583e0791SAntonio Nino Diaz 	unsigned int map_size = 0U;
468955242d8SJeenu Viswambharan 
469955242d8SJeenu Viswambharan 	/* Initialize the right interconnect */
470583e0791SAntonio Nino Diaz 	if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
471955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI5XX_BASE;
472955242d8SJeenu Viswambharan 		cci_map = fvp_cci5xx_map;
473955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci5xx_map);
474583e0791SAntonio Nino Diaz 	} else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
475955242d8SJeenu Viswambharan 		cci_base = PLAT_FVP_CCI400_BASE;
476955242d8SJeenu Viswambharan 		cci_map = fvp_cci400_map;
477955242d8SJeenu Viswambharan 		map_size = ARRAY_SIZE(fvp_cci400_map);
478583e0791SAntonio Nino Diaz 	} else {
479583e0791SAntonio Nino Diaz 		return;
480955242d8SJeenu Viswambharan 	}
481955242d8SJeenu Viswambharan 
482583e0791SAntonio Nino Diaz 	assert(cci_base != 0U);
483583e0791SAntonio Nino Diaz 	assert(cci_map != NULL);
484955242d8SJeenu Viswambharan 	cci_init(cci_base, cci_map, map_size);
485955242d8SJeenu Viswambharan #endif
48671237876SSoby Mathew }
4873e4b8fdcSSoby Mathew 
4883e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
4893e4b8fdcSSoby Mathew {
490955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
4913e4b8fdcSSoby Mathew 	plat_arm_interconnect_enter_coherency();
492955242d8SJeenu Viswambharan #else
493955242d8SJeenu Viswambharan 	unsigned int master;
494955242d8SJeenu Viswambharan 
495583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
496583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
497955242d8SJeenu Viswambharan 		master = get_interconnect_master();
498955242d8SJeenu Viswambharan 		cci_enable_snoop_dvm_reqs(master);
499955242d8SJeenu Viswambharan 	}
500955242d8SJeenu Viswambharan #endif
5013e4b8fdcSSoby Mathew }
5023e4b8fdcSSoby Mathew 
5033e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
5043e4b8fdcSSoby Mathew {
505955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN
5063e4b8fdcSSoby Mathew 	plat_arm_interconnect_exit_coherency();
507955242d8SJeenu Viswambharan #else
508955242d8SJeenu Viswambharan 	unsigned int master;
509955242d8SJeenu Viswambharan 
510583e0791SAntonio Nino Diaz 	if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
511583e0791SAntonio Nino Diaz 				 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
512955242d8SJeenu Viswambharan 		master = get_interconnect_master();
513955242d8SJeenu Viswambharan 		cci_disable_snoop_dvm_reqs(master);
514955242d8SJeenu Viswambharan 	}
515955242d8SJeenu Viswambharan #endif
5163e4b8fdcSSoby Mathew }
517ba597da7SJohn Tsichritzis 
51888c51c3fSManish V Badarkhe #if CRYPTO_SUPPORT
519ba597da7SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
520ba597da7SJohn Tsichritzis {
521ba597da7SJohn Tsichritzis 	assert(heap_addr != NULL);
522ba597da7SJohn Tsichritzis 	assert(heap_size != NULL);
523ba597da7SJohn Tsichritzis 
524ba597da7SJohn Tsichritzis 	return arm_get_mbedtls_heap(heap_addr, heap_size);
525ba597da7SJohn Tsichritzis }
52688c51c3fSManish V Badarkhe #endif /* CRYPTO_SUPPORT */
5271b597c22SAlexei Fedorov 
5281b597c22SAlexei Fedorov void fvp_timer_init(void)
5291b597c22SAlexei Fedorov {
530fddfb3baSMadhukar Pappireddy #if USE_SP804_TIMER
5311b597c22SAlexei Fedorov 	/* Enable the clock override for SP804 timer 0, which means that no
5321b597c22SAlexei Fedorov 	 * clock dividers are applied and the raw (35MHz) clock will be used.
5331b597c22SAlexei Fedorov 	 */
5341b597c22SAlexei Fedorov 	mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV);
5351b597c22SAlexei Fedorov 
5361b597c22SAlexei Fedorov 	/* Initialize delay timer driver using SP804 dual timer 0 */
5371b597c22SAlexei Fedorov 	sp804_timer_init(V2M_SP804_TIMER0_BASE,
5381b597c22SAlexei Fedorov 			SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
5391b597c22SAlexei Fedorov #else
5401b597c22SAlexei Fedorov 	generic_delay_timer_init();
5411b597c22SAlexei Fedorov 
5421b597c22SAlexei Fedorov 	/* Enable System level generic timer */
5431b597c22SAlexei Fedorov 	mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
5441b597c22SAlexei Fedorov 			CNTCR_FCREQ(0U) | CNTCR_EN);
545fddfb3baSMadhukar Pappireddy #endif /* USE_SP804_TIMER */
5461b597c22SAlexei Fedorov }
547ed9653ffSManish V Badarkhe 
548ed9653ffSManish V Badarkhe /*****************************************************************************
549ed9653ffSManish V Badarkhe  * plat_is_smccc_feature_available() - This function checks whether SMCCC
550ed9653ffSManish V Badarkhe  *                                     feature is availabile for platform.
551ed9653ffSManish V Badarkhe  * @fid: SMCCC function id
552ed9653ffSManish V Badarkhe  *
553ed9653ffSManish V Badarkhe  * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
554ed9653ffSManish V Badarkhe  * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
555ed9653ffSManish V Badarkhe  *****************************************************************************/
556ed9653ffSManish V Badarkhe int32_t plat_is_smccc_feature_available(u_register_t fid)
557ed9653ffSManish V Badarkhe {
558ed9653ffSManish V Badarkhe 	switch (fid) {
559ed9653ffSManish V Badarkhe 	case SMCCC_ARCH_SOC_ID:
560ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_SUCCESS;
561ed9653ffSManish V Badarkhe 	default:
562ed9653ffSManish V Badarkhe 		return SMC_ARCH_CALL_NOT_SUPPORTED;
563ed9653ffSManish V Badarkhe 	}
564ed9653ffSManish V Badarkhe }
565ed9653ffSManish V Badarkhe 
566ed9653ffSManish V Badarkhe /* Get SOC version */
567ed9653ffSManish V Badarkhe int32_t plat_get_soc_version(void)
568ed9653ffSManish V Badarkhe {
569ed9653ffSManish V Badarkhe 	return (int32_t)
570dfff4686SYann Gautier 		(SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
571dfff4686SYann Gautier 				    ARM_SOC_IDENTIFICATION_CODE) |
572dfff4686SYann Gautier 		 (FVP_SOC_ID & SOC_ID_IMPL_DEF_MASK));
573ed9653ffSManish V Badarkhe }
574ed9653ffSManish V Badarkhe 
575ed9653ffSManish V Badarkhe /* Get SOC revision */
576ed9653ffSManish V Badarkhe int32_t plat_get_soc_revision(void)
577ed9653ffSManish V Badarkhe {
578ed9653ffSManish V Badarkhe 	unsigned int sys_id;
579ed9653ffSManish V Badarkhe 
580ed9653ffSManish V Badarkhe 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
581dfff4686SYann Gautier 	return (int32_t)(((sys_id >> V2M_SYS_ID_REV_SHIFT) &
582dfff4686SYann Gautier 			  V2M_SYS_ID_REV_MASK) & SOC_ID_REV_MASK);
583ed9653ffSManish V Badarkhe }
5848c980a4aSJavier Almansa Sobrino 
5858c980a4aSJavier Almansa Sobrino #if ENABLE_RME
58690552c61SAlexeiFedorov 
58790552c61SAlexeiFedorov /* BDF mappings for RP0 RC0 */
58890552c61SAlexeiFedorov const struct bdf_mapping_info rc0rp0_bdf_data[] = {
58990552c61SAlexeiFedorov 	/* BDF0 */
59090552c61SAlexeiFedorov 	{0U,		/* mapping_base */
59190552c61SAlexeiFedorov 	 0x8000U,	/* mapping_top */
59290552c61SAlexeiFedorov 	 0U,		/* mapping_off */
59390552c61SAlexeiFedorov 	 0U		/* smmu_idx */
59490552c61SAlexeiFedorov 	}
59590552c61SAlexeiFedorov };
59690552c61SAlexeiFedorov 
59790552c61SAlexeiFedorov /* Root ports for RC0 */
59890552c61SAlexeiFedorov const struct root_port_info rc0rp_data[] = {
59990552c61SAlexeiFedorov 	/* RP0 */
60090552c61SAlexeiFedorov 	{0U,						/* root_port_id */
60190552c61SAlexeiFedorov 	 0U,						/* padding */
60290552c61SAlexeiFedorov 	 ARRAY_SIZE(rc0rp0_bdf_data),			/* num_bdf_mappings */
60390552c61SAlexeiFedorov 	 (struct bdf_mapping_info *)rc0rp0_bdf_data	/* bdf_mappings */
60490552c61SAlexeiFedorov 	}
60590552c61SAlexeiFedorov };
60690552c61SAlexeiFedorov 
60790552c61SAlexeiFedorov /* Root complexes */
60890552c61SAlexeiFedorov const struct root_complex_info rc_data[] = {
60990552c61SAlexeiFedorov 	/* RC0 */
61090552c61SAlexeiFedorov 	{PCIE_EXP_BASE,				/* ecam_base */
61190552c61SAlexeiFedorov 	 0U,					/* segment */
61290552c61SAlexeiFedorov 	 {0U, 0U, 0U},				/* padding */
61390552c61SAlexeiFedorov 	 ARRAY_SIZE(rc0rp_data),		/* num_root_ports */
61490552c61SAlexeiFedorov 	 (struct root_port_info *)rc0rp_data	/* root_ports */
61590552c61SAlexeiFedorov 	}
61690552c61SAlexeiFedorov };
61790552c61SAlexeiFedorov 
61890552c61SAlexeiFedorov /* Number of PCIe Root Complexes */
61990552c61SAlexeiFedorov #define FVP_RMM_RC_COUNT	ARRAY_SIZE(rc_data)
62090552c61SAlexeiFedorov 
6218c980a4aSJavier Almansa Sobrino /*
6228c980a4aSJavier Almansa Sobrino  * Get a pointer to the RMM-EL3 Shared buffer and return it
6238c980a4aSJavier Almansa Sobrino  * through the pointer passed as parameter.
6248c980a4aSJavier Almansa Sobrino  *
6258c980a4aSJavier Almansa Sobrino  * This function returns the size of the shared buffer.
6268c980a4aSJavier Almansa Sobrino  */
6278c980a4aSJavier Almansa Sobrino size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
6288c980a4aSJavier Almansa Sobrino {
6298c980a4aSJavier Almansa Sobrino 	*shared = (uintptr_t)RMM_SHARED_BASE;
6308c980a4aSJavier Almansa Sobrino 
6318c980a4aSJavier Almansa Sobrino 	return (size_t)RMM_SHARED_SIZE;
6328c980a4aSJavier Almansa Sobrino }
6331d0ca40eSJavier Almansa Sobrino 
634aa99881dSAlexeiFedorov /*
635aa99881dSAlexeiFedorov  * Calculate checksum of 64-bit words @buffer with @size length
636aa99881dSAlexeiFedorov  */
637aa99881dSAlexeiFedorov static uint64_t checksum_calc(uint64_t *buffer, size_t size)
638aa99881dSAlexeiFedorov {
639aa99881dSAlexeiFedorov 	uint64_t sum = 0UL;
640aa99881dSAlexeiFedorov 
641aa99881dSAlexeiFedorov 	assert(((uintptr_t)buffer & (sizeof(uint64_t) - 1UL)) == 0UL);
642aa99881dSAlexeiFedorov 	assert((size & (sizeof(uint64_t) - 1UL)) == 0UL);
643aa99881dSAlexeiFedorov 
644aa99881dSAlexeiFedorov 	for (unsigned long i = 0UL; i < (size / sizeof(uint64_t)); i++) {
645aa99881dSAlexeiFedorov 		sum += buffer[i];
646aa99881dSAlexeiFedorov 	}
647aa99881dSAlexeiFedorov 
648aa99881dSAlexeiFedorov 	return sum;
649aa99881dSAlexeiFedorov }
650bef44f60SAlexeiFedorov /*
65190552c61SAlexeiFedorov  * Boot Manifest v0.5 structure illustration, with two DRAM banks,
652bef44f60SAlexeiFedorov  * a single console and one device memory with two PCIe device
653bef44f60SAlexeiFedorov  * non-coherent address ranges.
654bef44f60SAlexeiFedorov  *
655bef44f60SAlexeiFedorov  * +--------------------------------------------------+
656bef44f60SAlexeiFedorov  * | offset |        field       |      comment       |
657bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
65890552c61SAlexeiFedorov  * |   0    |       version      |     0x00000005     |
659bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
660bef44f60SAlexeiFedorov  * |   4    |       padding      |     0x00000000     |
661bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
662bef44f60SAlexeiFedorov  * |   8    |      plat_data     |       NULL         |
663bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
664bef44f60SAlexeiFedorov  * |   16   |      num_banks     |                    |
665bef44f60SAlexeiFedorov  * +--------+--------------------+                    |
666bef44f60SAlexeiFedorov  * |   24   |       banks        |     plat_dram      +--+
667bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
668bef44f60SAlexeiFedorov  * |   32   |      checksum      |                    |  |
669bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |
670bef44f60SAlexeiFedorov  * |   40   |    num_consoles    |                    |  |
671bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
672bef44f60SAlexeiFedorov  * |   48   |      consoles      |    plat_console    +--|--+
673bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |
674bef44f60SAlexeiFedorov  * |   56   |      checksum      |                    |  |  |
675bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |
676bef44f60SAlexeiFedorov  * |   64   |      num_banks     |                    |  |  |
677bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |
678bef44f60SAlexeiFedorov  * |   72   |        banks       |  plat_ncoh_region  +--|--|--+
679bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
680bef44f60SAlexeiFedorov  * |   80   |      checksum      |                    |  |  |  |
681bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |
682bef44f60SAlexeiFedorov  * |   88   |      num_banks     |                    |  |  |  |
683bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
684bef44f60SAlexeiFedorov  * |   96   |       banks        |   plat_coh_region  |  |  |  |
685bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
686bef44f60SAlexeiFedorov  * |   104  |      checksum      |                    |  |  |  |
68790552c61SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |
68890552c61SAlexeiFedorov  * |   112  |     num_smmus      |                    |  |  |  |
68990552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |
69090552c61SAlexeiFedorov  * |   120  |       smmus        |     plat_smmu      +--|--|--|--+
69190552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |
69290552c61SAlexeiFedorov  * |   128  |      checksum      |                    |  |  |  |  |
69390552c61SAlexeiFedorov  * +--------+--------------------+--------------------+  |  |  |  |
69490552c61SAlexeiFedorov  * |   136  |  num_root_complex  |                    |  |  |  |  |
69590552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |
69690552c61SAlexeiFedorov  * |   144  |   rc_info_version  |                    |  |  |  |  |
69790552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |
69890552c61SAlexeiFedorov  * |   148  |      padding       | plat_root_complex  +--|--|--|--|--+
69990552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |  |
70090552c61SAlexeiFedorov  * |   152  |    root_complex    |                    |  |  |  |  |  |
70190552c61SAlexeiFedorov  * +--------+--------------------+                    |  |  |  |  |  |
70290552c61SAlexeiFedorov  * |   160  |      checksum      |                    |  |  |  |  |  |
70390552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-+  |  |  |  |
70490552c61SAlexeiFedorov  * |   168  |       base 0       |                    |     |  |  |  |
70590552c61SAlexeiFedorov  * +--------+--------------------+     mem_bank[0]    |     |  |  |  |
70690552c61SAlexeiFedorov  * |   176  |       size 0       |                    |     |  |  |  |
70790552c61SAlexeiFedorov  * +--------+--------------------+--------------------+     |  |  |  |
70890552c61SAlexeiFedorov  * |   184  |       base 1       |                    |     |  |  |  |
70990552c61SAlexeiFedorov  * +--------+--------------------+     mem_bank[1]    |     |  |  |  |
71090552c61SAlexeiFedorov  * |   192  |       size 1       |                    |     |  |  |  |
71190552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<----+  |  |  |
71290552c61SAlexeiFedorov  * |   200  |       base         |                    |        |  |  |
71390552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
71490552c61SAlexeiFedorov  * |   208  |      map_pages     |                    |        |  |  |
71590552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
71690552c61SAlexeiFedorov  * |   216  |       name         |                    |        |  |  |
71790552c61SAlexeiFedorov  * +--------+--------------------+     consoles[0]    |        |  |  |
71890552c61SAlexeiFedorov  * |   224  |     clk_in_hz      |                    |        |  |  |
71990552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
72090552c61SAlexeiFedorov  * |   232  |     baud_rate      |                    |        |  |  |
72190552c61SAlexeiFedorov  * +--------+--------------------+                    |        |  |  |
72290552c61SAlexeiFedorov  * |   240  |       flags        |                    |        |  |  |
72390552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-------+  |  |
72490552c61SAlexeiFedorov  * |   248  |       base 0       |                    |           |  |
72590552c61SAlexeiFedorov  * +--------+--------------------+    ncoh_region[0]  |           |  |
72690552c61SAlexeiFedorov  * |   256  |       size 0       |                    |           |  |
727bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+           |  |
72890552c61SAlexeiFedorov  * |   264  |       base 1       |                    |           |  |
72990552c61SAlexeiFedorov  * +--------+--------------------+    ncoh_region[1]  |           |  |
73090552c61SAlexeiFedorov  * |   272  |       size 1       |                    |           |  |
73190552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<----------+  |
73290552c61SAlexeiFedorov  * |   280  |     smmu_base      |                    |              |
73390552c61SAlexeiFedorov  * +--------+--------------------+      smmus[0]      |              |
73490552c61SAlexeiFedorov  * |   288  |     smmu_r_base    |                    |              |
73590552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-------------+
73690552c61SAlexeiFedorov  * |   296  |     ecam_base      |                    |
73790552c61SAlexeiFedorov  * +--------+--------------------+                    |
73890552c61SAlexeiFedorov  * |   304  |      segment       |                    |
73990552c61SAlexeiFedorov  * +--------+--------------------+                    |
74090552c61SAlexeiFedorov  * |   305  |      padding       |   root_complex[0]  +--+
741bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
74290552c61SAlexeiFedorov  * |   308  |   num_root_ports   |                    |  |
743bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
74490552c61SAlexeiFedorov  * |   312  |     root_ports     |                    |  |
74590552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-+
74690552c61SAlexeiFedorov  * |   320  |    root_port_id    |                    |
74790552c61SAlexeiFedorov  * +--------+--------------------+                    |
74890552c61SAlexeiFedorov  * |   322  |      padding       |                    |
74990552c61SAlexeiFedorov  * +--------+--------------------+   root_ports[0]    +--+
75090552c61SAlexeiFedorov  * |   324  |  num_bdf_mappings  |                    |  |
751bef44f60SAlexeiFedorov  * +--------+--------------------+                    |  |
75290552c61SAlexeiFedorov  * |   328  |    bdf_mappings    |                    |  |
75390552c61SAlexeiFedorov  * +--------+--------------------+--------------------+<-+
75490552c61SAlexeiFedorov  * |   336  |    mapping_base    |                    |
75590552c61SAlexeiFedorov  * +--------+--------------------+                    |
75690552c61SAlexeiFedorov  * |   338  |    mapping_top     |                    |
75790552c61SAlexeiFedorov  * +--------+--------------------+   bdf_mappings[0]  |
75890552c61SAlexeiFedorov  * |   340  |    mapping_off     |                    |
75990552c61SAlexeiFedorov  * +--------+--------------------+                    |
76090552c61SAlexeiFedorov  * |   342  |     smmu_idx       |                    |
761bef44f60SAlexeiFedorov  * +--------+--------------------+--------------------+
762bef44f60SAlexeiFedorov  */
763a97bfa5fSAlexeiFedorov int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
7641d0ca40eSJavier Almansa Sobrino {
76532904472SSoby Mathew 	uint64_t checksum, num_banks, num_consoles;
766bef44f60SAlexeiFedorov 	uint64_t num_ncoh_regions, num_coh_regions;
76790552c61SAlexeiFedorov 	uint64_t num_smmus, num_root_complex;
76890552c61SAlexeiFedorov 	unsigned int num_root_ports, num_bdf_mappings;
76990552c61SAlexeiFedorov 	uint32_t o_realm;
77090552c61SAlexeiFedorov 	struct memory_bank *bank_ptr, *ncoh_region_ptr, *coh_region_ptr;
77132904472SSoby Mathew 	struct console_info *console_ptr;
77290552c61SAlexeiFedorov 	struct smmu_info *smmu_ptr;
77390552c61SAlexeiFedorov 	struct root_complex_info *root_complex_ptr, *rc_ptr;
77490552c61SAlexeiFedorov 	struct root_port_info *root_port_ptr, *rp_ptr;
77590552c61SAlexeiFedorov 	struct bdf_mapping_info *bdf_mapping_ptr, *bdf_ptr;
776a97bfa5fSAlexeiFedorov 
7771d0ca40eSJavier Almansa Sobrino 	assert(manifest != NULL);
7781d0ca40eSJavier Almansa Sobrino 
77982685904SAlexeiFedorov 	/* Get number of DRAM banks */
78082685904SAlexeiFedorov 	num_banks = FCONF_GET_PROPERTY(hw_config, dram_layout, num_banks);
78182685904SAlexeiFedorov 	assert(num_banks <= ARM_DRAM_NUM_BANKS);
78282685904SAlexeiFedorov 
78332904472SSoby Mathew 	/* Set number of consoles */
78432904472SSoby Mathew 	num_consoles = FVP_RMM_CONSOLE_COUNT;
78532904472SSoby Mathew 
786bef44f60SAlexeiFedorov 	/* Set number of device non-coherent address ranges based on DT */
787bef44f60SAlexeiFedorov 	num_ncoh_regions = FCONF_GET_PROPERTY(hw_config, pci_props, num_ncoh_regions);
788bef44f60SAlexeiFedorov 
78990552c61SAlexeiFedorov 	/* Set number of SMMUs */
79090552c61SAlexeiFedorov 	num_smmus = FVP_RMM_SMMU_COUNT;
79190552c61SAlexeiFedorov 
79290552c61SAlexeiFedorov 	/* Set number of PCIe root complexes */
79390552c61SAlexeiFedorov 	num_root_complex = FVP_RMM_RC_COUNT;
79490552c61SAlexeiFedorov 
79590552c61SAlexeiFedorov 	/* Calculate and set number of all PCIe root ports and BDF mappings */
79690552c61SAlexeiFedorov 	num_root_ports = 0U;
79790552c61SAlexeiFedorov 	num_bdf_mappings = 0U;
79890552c61SAlexeiFedorov 
79990552c61SAlexeiFedorov 	/* Scan all root complex entries */
80090552c61SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_root_complex; i++) {
80190552c61SAlexeiFedorov 		num_root_ports += rc_data[i].num_root_ports;
80290552c61SAlexeiFedorov 
80390552c61SAlexeiFedorov 		/* Scan all root ports entries in root complex */
80490552c61SAlexeiFedorov 		for (unsigned int j = 0U; j < rc_data[i].num_root_ports; j++) {
80590552c61SAlexeiFedorov 			num_bdf_mappings += rc_data[i].root_ports[j].num_bdf_mappings;
80690552c61SAlexeiFedorov 		}
80790552c61SAlexeiFedorov 	}
80890552c61SAlexeiFedorov 
8091d0ca40eSJavier Almansa Sobrino 	manifest->version = RMMD_MANIFEST_VERSION;
810dc0ca64eSJavier Almansa Sobrino 	manifest->padding = 0U; /* RES0 */
811bef44f60SAlexeiFedorov 	manifest->plat_data = 0UL;
81282685904SAlexeiFedorov 	manifest->plat_dram.num_banks = num_banks;
81332904472SSoby Mathew 	manifest->plat_console.num_consoles = num_consoles;
814bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.num_banks = num_ncoh_regions;
81590552c61SAlexeiFedorov 	manifest->plat_smmu.num_smmus = num_smmus;
81690552c61SAlexeiFedorov 	manifest->plat_root_complex.num_root_complex = num_root_complex;
81790552c61SAlexeiFedorov 	manifest->plat_root_complex.rc_info_version = PCIE_RC_INFO_VERSION;
81890552c61SAlexeiFedorov 	manifest->plat_root_complex.padding = 0U; /* RES0 */
819a97bfa5fSAlexeiFedorov 
820bef44f60SAlexeiFedorov 	/* FVP does not support device coherent address ranges */
821bef44f60SAlexeiFedorov 	num_coh_regions = 0UL;
822bef44f60SAlexeiFedorov 	manifest->plat_coh_region.num_banks = num_coh_regions;
823bef44f60SAlexeiFedorov 	manifest->plat_coh_region.banks = NULL;
824bef44f60SAlexeiFedorov 	manifest->plat_coh_region.checksum = 0UL;
82532904472SSoby Mathew 
826bef44f60SAlexeiFedorov 	bank_ptr = (struct memory_bank *)
827bef44f60SAlexeiFedorov 			(((uintptr_t)manifest) + sizeof(struct rmm_manifest));
82832904472SSoby Mathew 	console_ptr = (struct console_info *)
829bef44f60SAlexeiFedorov 			((uintptr_t)bank_ptr + (num_banks *
830bef44f60SAlexeiFedorov 						sizeof(struct memory_bank)));
831bef44f60SAlexeiFedorov 	ncoh_region_ptr = (struct memory_bank *)
832bef44f60SAlexeiFedorov 			((uintptr_t)console_ptr + (num_consoles *
833bef44f60SAlexeiFedorov 						sizeof(struct console_info)));
83490552c61SAlexeiFedorov 	coh_region_ptr = (struct memory_bank *)
83590552c61SAlexeiFedorov 			((uintptr_t)ncoh_region_ptr + (num_ncoh_regions *
83690552c61SAlexeiFedorov 						sizeof(struct memory_bank)));
83790552c61SAlexeiFedorov 	smmu_ptr = (struct smmu_info *)
83890552c61SAlexeiFedorov 			((uintptr_t)coh_region_ptr + (num_coh_regions *
83990552c61SAlexeiFedorov 						sizeof(struct memory_bank)));
84090552c61SAlexeiFedorov 	root_complex_ptr = (struct root_complex_info *)
84190552c61SAlexeiFedorov 			((uintptr_t)smmu_ptr + (num_smmus *
84290552c61SAlexeiFedorov 						sizeof(struct smmu_info)));
84390552c61SAlexeiFedorov 	root_port_ptr = (struct	root_port_info *)
84490552c61SAlexeiFedorov 			((uintptr_t)root_complex_ptr + (num_root_complex *
84590552c61SAlexeiFedorov 						sizeof(struct root_complex_info)));
84690552c61SAlexeiFedorov 	bdf_mapping_ptr = (struct bdf_mapping_info *)
84790552c61SAlexeiFedorov 			((uintptr_t)root_port_ptr + (num_root_ports *
84890552c61SAlexeiFedorov 						sizeof(struct root_port_info)));
84990552c61SAlexeiFedorov 
85082685904SAlexeiFedorov 	manifest->plat_dram.banks = bank_ptr;
85132904472SSoby Mathew 	manifest->plat_console.consoles = console_ptr;
852bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.banks = ncoh_region_ptr;
85390552c61SAlexeiFedorov 	manifest->plat_smmu.smmus = smmu_ptr;
85490552c61SAlexeiFedorov 	manifest->plat_root_complex.root_complex = root_complex_ptr;
85532904472SSoby Mathew 
85632904472SSoby Mathew 	/* Ensure the manifest is not larger than the shared buffer */
85732904472SSoby Mathew 	assert((sizeof(struct rmm_manifest) +
858bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
859bef44f60SAlexeiFedorov 			manifest->plat_dram.num_banks) +
860bef44f60SAlexeiFedorov 		(sizeof(struct console_info) *
861bef44f60SAlexeiFedorov 			manifest->plat_console.num_consoles) +
862bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
863bef44f60SAlexeiFedorov 			manifest->plat_ncoh_region.num_banks) +
864bef44f60SAlexeiFedorov 		(sizeof(struct memory_bank) *
86590552c61SAlexeiFedorov 			manifest->plat_coh_region.num_banks) +
86690552c61SAlexeiFedorov 		(sizeof(struct smmu_info) *
86790552c61SAlexeiFedorov 			manifest->plat_smmu.num_smmus) +
86890552c61SAlexeiFedorov 		(sizeof(struct root_complex_info) *
86990552c61SAlexeiFedorov 			manifest->plat_root_complex.num_root_complex) +
87090552c61SAlexeiFedorov 		(sizeof(struct root_port_info) * num_root_ports) +
87190552c61SAlexeiFedorov 		(sizeof(struct bdf_mapping_info) * num_bdf_mappings))
872bef44f60SAlexeiFedorov 		<= ARM_EL3_RMM_SHARED_SIZE);
873a97bfa5fSAlexeiFedorov 
874a97bfa5fSAlexeiFedorov 	/* Calculate checksum of plat_dram structure */
87582685904SAlexeiFedorov 	checksum = num_banks + (uint64_t)bank_ptr;
876a97bfa5fSAlexeiFedorov 
87782685904SAlexeiFedorov 	/* Store FVP DRAM banks data in Boot Manifest */
87882685904SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_banks; i++) {
879aa99881dSAlexeiFedorov 		bank_ptr[i].base = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].base);
880aa99881dSAlexeiFedorov 		bank_ptr[i].size = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].size);
881aa99881dSAlexeiFedorov 	}
88282685904SAlexeiFedorov 
88382685904SAlexeiFedorov 	/* Update checksum */
884bef44f60SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)bank_ptr, sizeof(struct memory_bank) * num_banks);
885a97bfa5fSAlexeiFedorov 
886a97bfa5fSAlexeiFedorov 	/* Checksum must be 0 */
88782685904SAlexeiFedorov 	manifest->plat_dram.checksum = ~checksum + 1UL;
8881d0ca40eSJavier Almansa Sobrino 
889bef44f60SAlexeiFedorov 	/* Calculate the checksum of plat_consoles structure */
89032904472SSoby Mathew 	checksum = num_consoles + (uint64_t)console_ptr;
89132904472SSoby Mathew 
89232904472SSoby Mathew 	/* Zero out the console info struct */
893bef44f60SAlexeiFedorov 	(void)memset((void *)console_ptr, '\0',
894bef44f60SAlexeiFedorov 			sizeof(struct console_info) * num_consoles);
89532904472SSoby Mathew 
89632904472SSoby Mathew 	console_ptr[0].base = FVP_RMM_CONSOLE_BASE;
897aa99881dSAlexeiFedorov 	console_ptr[0].map_pages = 1UL;
89832904472SSoby Mathew 	console_ptr[0].clk_in_hz = FVP_RMM_CONSOLE_CLK_IN_HZ;
89932904472SSoby Mathew 	console_ptr[0].baud_rate = FVP_RMM_CONSOLE_BAUD;
90032904472SSoby Mathew 
901bef44f60SAlexeiFedorov 	(void)strlcpy(console_ptr[0].name, FVP_RMM_CONSOLE_NAME,
902bef44f60SAlexeiFedorov 						RMM_CONSOLE_MAX_NAME_LEN - 1UL);
90332904472SSoby Mathew 
90432904472SSoby Mathew 	/* Update checksum */
905aa99881dSAlexeiFedorov 	checksum += checksum_calc((uint64_t *)console_ptr,
906aa99881dSAlexeiFedorov 					sizeof(struct console_info) * num_consoles);
90732904472SSoby Mathew 	/* Checksum must be 0 */
90832904472SSoby Mathew 	manifest->plat_console.checksum = ~checksum + 1UL;
90932904472SSoby Mathew 
910bef44f60SAlexeiFedorov 	/*
911bef44f60SAlexeiFedorov 	 * Calculate the checksum of device non-coherent address ranges
912bef44f60SAlexeiFedorov 	 * info structure
913bef44f60SAlexeiFedorov 	 */
914bef44f60SAlexeiFedorov 	checksum = num_ncoh_regions + (uint64_t)ncoh_region_ptr;
915bef44f60SAlexeiFedorov 
916bef44f60SAlexeiFedorov 	/* Zero out the PCIe region info struct */
917bef44f60SAlexeiFedorov 	(void)memset((void *)ncoh_region_ptr, 0,
918bef44f60SAlexeiFedorov 			sizeof(struct memory_bank) * num_ncoh_regions);
919bef44f60SAlexeiFedorov 
920bef44f60SAlexeiFedorov 	for (unsigned long i = 0UL; i < num_ncoh_regions; i++) {
921bef44f60SAlexeiFedorov 		ncoh_region_ptr[i].base =
922bef44f60SAlexeiFedorov 			FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].base);
923bef44f60SAlexeiFedorov 		ncoh_region_ptr[i].size =
924bef44f60SAlexeiFedorov 			FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].size);
925bef44f60SAlexeiFedorov 	}
926bef44f60SAlexeiFedorov 
927bef44f60SAlexeiFedorov 	/* Update checksum */
928bef44f60SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)ncoh_region_ptr,
929bef44f60SAlexeiFedorov 			sizeof(struct memory_bank) * num_ncoh_regions);
930bef44f60SAlexeiFedorov 
931bef44f60SAlexeiFedorov 	/* Checksum must be 0 */
932bef44f60SAlexeiFedorov 	manifest->plat_ncoh_region.checksum = ~checksum + 1UL;
933bef44f60SAlexeiFedorov 
93490552c61SAlexeiFedorov 	/* Calculate the checksum of the plat_smmu structure */
93590552c61SAlexeiFedorov 	checksum = num_smmus + (uint64_t)smmu_ptr;
93690552c61SAlexeiFedorov 
93790552c61SAlexeiFedorov 	smmu_ptr[0].smmu_base = FVP_RMM_SMMU_BASE;
93890552c61SAlexeiFedorov 
93990552c61SAlexeiFedorov 	/* Read SMMU_ROOT_IDR0.BA_REALM[31:22] register field */
94090552c61SAlexeiFedorov 	o_realm = mmio_read_32(FVP_RMM_SMMU_BASE + SMMU_ROOT_IDR0) &
94190552c61SAlexeiFedorov 				SMMU_ROOT_IDR0_BA_REALM_MASK;
94290552c61SAlexeiFedorov 	/*
94390552c61SAlexeiFedorov 	 * Calculate the base address offset of Realm Register Page 0.
94490552c61SAlexeiFedorov 	 * O_REALM = 0x20000 + (BA_REALM * 0x10000)
94590552c61SAlexeiFedorov 	 * SMMU_REALM_BASE = SMMU_PAGE_0_BASE + O_REALM
94690552c61SAlexeiFedorov 	 */
94790552c61SAlexeiFedorov 	o_realm = 0x20000 + (o_realm >> (SMMU_ROOT_IDR0_BA_REALM_SHIFT - 16U));
94890552c61SAlexeiFedorov 
94990552c61SAlexeiFedorov 	smmu_ptr[0].smmu_r_base = FVP_RMM_SMMU_BASE + o_realm;
95090552c61SAlexeiFedorov 
95190552c61SAlexeiFedorov 	/* Update checksum */
95290552c61SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)smmu_ptr,
95390552c61SAlexeiFedorov 					sizeof(struct smmu_info) * num_smmus);
95490552c61SAlexeiFedorov 	/* Checksum must be 0 */
95590552c61SAlexeiFedorov 	manifest->plat_smmu.checksum = ~checksum + 1UL;
95690552c61SAlexeiFedorov 
95790552c61SAlexeiFedorov 	/* Calculate the checksum of the plat_root_complex structure */
95890552c61SAlexeiFedorov 	checksum = num_root_complex + (uint64_t)root_complex_ptr;
95990552c61SAlexeiFedorov 
96090552c61SAlexeiFedorov 	/* Zero out PCIe root complex info structures */
96190552c61SAlexeiFedorov 	(void)memset((void *)root_complex_ptr, 0,
96290552c61SAlexeiFedorov 			sizeof(struct root_complex_info) * num_root_complex);
96390552c61SAlexeiFedorov 
96490552c61SAlexeiFedorov 	/* Set pointers for data in manifest */
96590552c61SAlexeiFedorov 	rc_ptr = root_complex_ptr;
96690552c61SAlexeiFedorov 	rp_ptr = root_port_ptr;
96790552c61SAlexeiFedorov 	bdf_ptr = bdf_mapping_ptr;
96890552c61SAlexeiFedorov 
96990552c61SAlexeiFedorov 	/* Fill PCIe root complex info structures */
97090552c61SAlexeiFedorov 	for (unsigned long i = 0U; i < num_root_complex; i++) {
97190552c61SAlexeiFedorov 		const struct root_complex_info *rc_info = &rc_data[i];
97290552c61SAlexeiFedorov 		const struct root_port_info *rp_info = rc_info->root_ports;
97390552c61SAlexeiFedorov 
97490552c61SAlexeiFedorov 		/* Copy root complex data, except root_ports pointer */
97590552c61SAlexeiFedorov 		(void)memcpy((void *)rc_ptr, (void *)rc_info,
97690552c61SAlexeiFedorov 			sizeof(struct root_complex_info) - sizeof(struct root_port_info *));
97790552c61SAlexeiFedorov 
97890552c61SAlexeiFedorov 		/* Set root_ports for root complex */
97990552c61SAlexeiFedorov 		rc_ptr->root_ports = rp_ptr;
98090552c61SAlexeiFedorov 
98190552c61SAlexeiFedorov 		/* Scan root ports */
98290552c61SAlexeiFedorov 		for (unsigned int j = 0U; j < rc_ptr->num_root_ports; j++) {
98390552c61SAlexeiFedorov 			const struct bdf_mapping_info *bdf_info = rp_info->bdf_mappings;
98490552c61SAlexeiFedorov 
98590552c61SAlexeiFedorov 			/* Copy root port data, except bdf_mappings pointer */
98690552c61SAlexeiFedorov 			(void)memcpy((void *)rp_ptr, (void *)rp_info,
98790552c61SAlexeiFedorov 				sizeof(struct root_port_info) - sizeof(struct bdf_mapping_info *));
98890552c61SAlexeiFedorov 
98990552c61SAlexeiFedorov 			/* Set bdf_mappings for root port */
99090552c61SAlexeiFedorov 			rp_ptr->bdf_mappings = bdf_ptr;
99190552c61SAlexeiFedorov 
99290552c61SAlexeiFedorov 			/* Copy all BDF mappings for root port */
99390552c61SAlexeiFedorov 			(void)memcpy((void *)bdf_ptr, (void *)bdf_info,
99490552c61SAlexeiFedorov 				sizeof(struct bdf_mapping_info) * rp_ptr->num_bdf_mappings);
99590552c61SAlexeiFedorov 
99690552c61SAlexeiFedorov 			bdf_ptr += rp_ptr->num_bdf_mappings;
99790552c61SAlexeiFedorov 			rp_ptr++;
99890552c61SAlexeiFedorov 			rp_info++;
99990552c61SAlexeiFedorov 		}
100090552c61SAlexeiFedorov 		rc_ptr++;
100190552c61SAlexeiFedorov 	}
100290552c61SAlexeiFedorov 
100390552c61SAlexeiFedorov 	/* Check that all data are written in manifest */
100490552c61SAlexeiFedorov 	assert(rc_ptr == (root_complex_ptr + num_root_complex));
100590552c61SAlexeiFedorov 	assert(rp_ptr == (root_port_ptr + num_root_ports));
100690552c61SAlexeiFedorov 	assert(bdf_ptr == (bdf_mapping_ptr + num_bdf_mappings));
100790552c61SAlexeiFedorov 
100890552c61SAlexeiFedorov 	/* Update checksum for all PCIe data */
100990552c61SAlexeiFedorov 	checksum += checksum_calc((uint64_t *)root_complex_ptr,
101090552c61SAlexeiFedorov 				(uintptr_t)bdf_ptr - (uintptr_t)root_complex_ptr);
101190552c61SAlexeiFedorov 
101290552c61SAlexeiFedorov 	/* Checksum must be 0 */
101390552c61SAlexeiFedorov 	manifest->plat_root_complex.checksum = ~checksum + 1UL;
101490552c61SAlexeiFedorov 
10151d0ca40eSJavier Almansa Sobrino 	return 0;
10161d0ca40eSJavier Almansa Sobrino }
1017f801fdc2STushar Khandelwal 
1018f801fdc2STushar Khandelwal /*
1019f801fdc2STushar Khandelwal  * Update encryption key associated with @mecid.
1020f801fdc2STushar Khandelwal  */
1021f801fdc2STushar Khandelwal int plat_rmmd_mecid_key_update(uint16_t mecid)
1022f801fdc2STushar Khandelwal {
1023f801fdc2STushar Khandelwal 	/*
1024f801fdc2STushar Khandelwal 	 * FVP does not provide an interface to change the encryption key associated
1025f801fdc2STushar Khandelwal 	 * with MECID. Hence always return success.
1026f801fdc2STushar Khandelwal 	 */
1027f801fdc2STushar Khandelwal 	return 0;
1028f801fdc2STushar Khandelwal }
1029a97bfa5fSAlexeiFedorov #endif /* ENABLE_RME */
1030