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, \ 71e2e90fa1SBoyan Karatotev MT_DEVICE | MT_RW | EL3_PAS) 72e2e90fa1SBoyan Karatotev 73e2e90fa1SBoyan Karatotev #define MAP_CCN MAP_REGION_FLAT(CCN_BASE, \ 74e2e90fa1SBoyan 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 122e2e90fa1SBoyan 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 140e2e90fa1SBoyan 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 215e2e90fa1SBoyan Karatotev #if FVP_INTERCONNECT_DRIVER == FVP_CCN 216e2e90fa1SBoyan Karatotev MAP_CCN, 217e2e90fa1SBoyan 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, 252*235d9754SYeoreum Yun ARM_SP_PSEUDO_NS_CRB_MMAP, 253*235d9754SYeoreum Yun ARM_SP_PSEUDO_S_CRB_MMAP, 254e29efeb1SAntonio Nino Diaz {0} 255e29efeb1SAntonio Nino Diaz }; 256e29efeb1SAntonio Nino Diaz #endif 2573e4b8fdcSSoby Mathew #endif 2583d8256b2SMasahiro Yamada #ifdef IMAGE_BL32 2593e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 260402b3cf8SJulius Werner #ifndef __aarch64__ 261877cf3ffSSoby Mathew ARM_MAP_SHARED_RAM, 262950c6956SJoel Hutton ARM_V2M_MAP_MEM_PROTECT, 263877cf3ffSSoby Mathew #endif 2643e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 2653e4b8fdcSSoby Mathew MAP_DEVICE0, 266e2e90fa1SBoyan Karatotev #if FVP_INTERCONNECT_DRIVER == FVP_CCN 267e2e90fa1SBoyan Karatotev MAP_CCN, 268e2e90fa1SBoyan Karatotev #endif 2693e4b8fdcSSoby Mathew MAP_DEVICE1, 2703e4b8fdcSSoby Mathew {0} 2713e4b8fdcSSoby Mathew }; 2723e4b8fdcSSoby Mathew #endif 2733e4b8fdcSSoby Mathew 2749d870b79SZelalem Aweke #ifdef IMAGE_RMM 2759d870b79SZelalem Aweke const mmap_region_t plat_arm_mmap[] = { 2769d870b79SZelalem Aweke V2M_MAP_IOFPGA, 2779d870b79SZelalem Aweke MAP_DEVICE0, 2789d870b79SZelalem Aweke MAP_DEVICE1, 2799d870b79SZelalem Aweke {0} 2809d870b79SZelalem Aweke }; 2819d870b79SZelalem Aweke #endif 2829d870b79SZelalem Aweke 2833e4b8fdcSSoby Mathew ARM_CASSERT_MMAP 2843e4b8fdcSSoby Mathew 285955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER != FVP_CCN 286955242d8SJeenu Viswambharan static const int fvp_cci400_map[] = { 287955242d8SJeenu Viswambharan PLAT_FVP_CCI400_CLUS0_SL_PORT, 288955242d8SJeenu Viswambharan PLAT_FVP_CCI400_CLUS1_SL_PORT, 289955242d8SJeenu Viswambharan }; 290955242d8SJeenu Viswambharan 291955242d8SJeenu Viswambharan static const int fvp_cci5xx_map[] = { 292955242d8SJeenu Viswambharan PLAT_FVP_CCI5XX_CLUS0_SL_PORT, 293955242d8SJeenu Viswambharan PLAT_FVP_CCI5XX_CLUS1_SL_PORT, 294955242d8SJeenu Viswambharan }; 295955242d8SJeenu Viswambharan 296955242d8SJeenu Viswambharan static unsigned int get_interconnect_master(void) 297955242d8SJeenu Viswambharan { 298955242d8SJeenu Viswambharan unsigned int master; 299955242d8SJeenu Viswambharan u_register_t mpidr; 300955242d8SJeenu Viswambharan 301955242d8SJeenu Viswambharan mpidr = read_mpidr_el1(); 302583e0791SAntonio Nino Diaz master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ? 303955242d8SJeenu Viswambharan MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr); 304955242d8SJeenu Viswambharan 305955242d8SJeenu Viswambharan assert(master < FVP_CLUSTER_COUNT); 306955242d8SJeenu Viswambharan return master; 307955242d8SJeenu Viswambharan } 308955242d8SJeenu Viswambharan #endif 3093e4b8fdcSSoby Mathew 3103f3c341aSPaul Beesley #if defined(IMAGE_BL31) && SPM_MM 311e29efeb1SAntonio Nino Diaz /* 312e29efeb1SAntonio Nino Diaz * Boot information passed to a secure partition during initialisation. Linear 313e29efeb1SAntonio Nino Diaz * indices in MP information will be filled at runtime. 314e29efeb1SAntonio Nino Diaz */ 315aeaa225cSPaul Beesley static spm_mm_mp_info_t sp_mp_info[] = { 316e29efeb1SAntonio Nino Diaz [0] = {0x80000000, 0}, 317e29efeb1SAntonio Nino Diaz [1] = {0x80000001, 0}, 318e29efeb1SAntonio Nino Diaz [2] = {0x80000002, 0}, 319e29efeb1SAntonio Nino Diaz [3] = {0x80000003, 0}, 320e29efeb1SAntonio Nino Diaz [4] = {0x80000100, 0}, 321e29efeb1SAntonio Nino Diaz [5] = {0x80000101, 0}, 322e29efeb1SAntonio Nino Diaz [6] = {0x80000102, 0}, 323e29efeb1SAntonio Nino Diaz [7] = {0x80000103, 0}, 324e29efeb1SAntonio Nino Diaz }; 325e29efeb1SAntonio Nino Diaz 326aeaa225cSPaul Beesley const spm_mm_boot_info_t plat_arm_secure_partition_boot_info = { 327e29efeb1SAntonio Nino Diaz .h.type = PARAM_SP_IMAGE_BOOT_INFO, 328e29efeb1SAntonio Nino Diaz .h.version = VERSION_1, 329aeaa225cSPaul Beesley .h.size = sizeof(spm_mm_boot_info_t), 330e29efeb1SAntonio Nino Diaz .h.attr = 0, 331e29efeb1SAntonio Nino Diaz .sp_mem_base = ARM_SP_IMAGE_BASE, 332e29efeb1SAntonio Nino Diaz .sp_mem_limit = ARM_SP_IMAGE_LIMIT, 333e29efeb1SAntonio Nino Diaz .sp_image_base = ARM_SP_IMAGE_BASE, 334e29efeb1SAntonio Nino Diaz .sp_stack_base = PLAT_SP_IMAGE_STACK_BASE, 335e29efeb1SAntonio Nino Diaz .sp_heap_base = ARM_SP_IMAGE_HEAP_BASE, 3360560efb9SArd Biesheuvel .sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE, 337e29efeb1SAntonio Nino Diaz .sp_shared_buf_base = PLAT_SPM_BUF_BASE, 338e29efeb1SAntonio Nino Diaz .sp_image_size = ARM_SP_IMAGE_SIZE, 339e29efeb1SAntonio Nino Diaz .sp_pcpu_stack_size = PLAT_SP_IMAGE_STACK_PCPU_SIZE, 340e29efeb1SAntonio Nino Diaz .sp_heap_size = ARM_SP_IMAGE_HEAP_SIZE, 3410560efb9SArd Biesheuvel .sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE, 342e29efeb1SAntonio Nino Diaz .sp_shared_buf_size = PLAT_SPM_BUF_SIZE, 343e29efeb1SAntonio Nino Diaz .num_sp_mem_regions = ARM_SP_IMAGE_NUM_MEM_REGIONS, 344e29efeb1SAntonio Nino Diaz .num_cpus = PLATFORM_CORE_COUNT, 345e29efeb1SAntonio Nino Diaz .mp_info = &sp_mp_info[0], 346e29efeb1SAntonio Nino Diaz }; 347e29efeb1SAntonio Nino Diaz 348e29efeb1SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie) 349e29efeb1SAntonio Nino Diaz { 350e29efeb1SAntonio Nino Diaz return plat_arm_secure_partition_mmap; 351e29efeb1SAntonio Nino Diaz } 352e29efeb1SAntonio Nino Diaz 353aeaa225cSPaul Beesley const struct spm_mm_boot_info *plat_get_secure_partition_boot_info( 354e29efeb1SAntonio Nino Diaz void *cookie) 355e29efeb1SAntonio Nino Diaz { 356e29efeb1SAntonio Nino Diaz return &plat_arm_secure_partition_boot_info; 357e29efeb1SAntonio Nino Diaz } 358e29efeb1SAntonio Nino Diaz #endif 359e29efeb1SAntonio Nino Diaz 3603e4b8fdcSSoby Mathew /******************************************************************************* 3613e4b8fdcSSoby Mathew * A single boot loader stack is expected to work on both the Foundation FVP 3623e4b8fdcSSoby Mathew * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The 3633e4b8fdcSSoby Mathew * SYS_ID register provides a mechanism for detecting the differences between 3643e4b8fdcSSoby Mathew * these platforms. This information is stored in a per-BL array to allow the 3653e4b8fdcSSoby Mathew * code to take the correct path.Per BL platform configuration. 3663e4b8fdcSSoby Mathew ******************************************************************************/ 3674d010d0dSDaniel Boulby void __init fvp_config_setup(void) 3683e4b8fdcSSoby Mathew { 3693e4b8fdcSSoby Mathew unsigned int rev, hbi, bld, arch, sys_id; 3703e4b8fdcSSoby Mathew 3713e4b8fdcSSoby Mathew sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID); 3723e4b8fdcSSoby Mathew rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK; 3733e4b8fdcSSoby Mathew hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK; 3743e4b8fdcSSoby Mathew bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK; 3753e4b8fdcSSoby Mathew arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK; 3763e4b8fdcSSoby Mathew 3773e4b8fdcSSoby Mathew if (arch != ARCH_MODEL) { 3783e4b8fdcSSoby Mathew ERROR("This firmware is for FVP models\n"); 3793e4b8fdcSSoby Mathew panic(); 3803e4b8fdcSSoby Mathew } 3813e4b8fdcSSoby Mathew 3823e4b8fdcSSoby Mathew /* 3833e4b8fdcSSoby Mathew * The build field in the SYS_ID tells which variant of the GIC 3843e4b8fdcSSoby Mathew * memory is implemented by the model. 3853e4b8fdcSSoby Mathew */ 3863e4b8fdcSSoby Mathew switch (bld) { 3873e4b8fdcSSoby Mathew case BLD_GIC_VE_MMAP: 38821a3973dSSoby Mathew ERROR("Legacy Versatile Express memory map for GIC peripheral" 38921a3973dSSoby Mathew " is not supported\n"); 3903e4b8fdcSSoby Mathew panic(); 3913e4b8fdcSSoby Mathew break; 3923e4b8fdcSSoby Mathew case BLD_GIC_A53A57_MMAP: 3933e4b8fdcSSoby Mathew break; 3943e4b8fdcSSoby Mathew default: 3953e4b8fdcSSoby Mathew ERROR("Unsupported board build %x\n", bld); 3963e4b8fdcSSoby Mathew panic(); 3973e4b8fdcSSoby Mathew } 3983e4b8fdcSSoby Mathew 3993e4b8fdcSSoby Mathew /* 4003e4b8fdcSSoby Mathew * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010 4013e4b8fdcSSoby Mathew * for the Foundation FVP. 4023e4b8fdcSSoby Mathew */ 4033e4b8fdcSSoby Mathew switch (hbi) { 4043e4b8fdcSSoby Mathew case HBI_FOUNDATION_FVP: 4053e4b8fdcSSoby Mathew arm_config.flags = 0; 4063e4b8fdcSSoby Mathew 4073e4b8fdcSSoby Mathew /* 4083e4b8fdcSSoby Mathew * Check for supported revisions of Foundation FVP 4093e4b8fdcSSoby Mathew * Allow future revisions to run but emit warning diagnostic 4103e4b8fdcSSoby Mathew */ 4113e4b8fdcSSoby Mathew switch (rev) { 4123e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_V2_0: 4133e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_V2_1: 4143e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_v9_1: 4154faa4a1dSSandrine Bailleux case REV_FOUNDATION_FVP_v9_6: 4163e4b8fdcSSoby Mathew break; 4173e4b8fdcSSoby Mathew default: 4183e4b8fdcSSoby Mathew WARN("Unrecognized Foundation FVP revision %x\n", rev); 4193e4b8fdcSSoby Mathew break; 4203e4b8fdcSSoby Mathew } 4213e4b8fdcSSoby Mathew break; 4223e4b8fdcSSoby Mathew case HBI_BASE_FVP: 423955242d8SJeenu Viswambharan arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC); 4243e4b8fdcSSoby Mathew 4253e4b8fdcSSoby Mathew /* 4263e4b8fdcSSoby Mathew * Check for supported revisions 4273e4b8fdcSSoby Mathew * Allow future revisions to run but emit warning diagnostic 4283e4b8fdcSSoby Mathew */ 4293e4b8fdcSSoby Mathew switch (rev) { 4303e4b8fdcSSoby Mathew case REV_BASE_FVP_V0: 431955242d8SJeenu Viswambharan arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400; 432955242d8SJeenu Viswambharan break; 433955242d8SJeenu Viswambharan case REV_BASE_FVP_REVC: 4348431635bSIsla Mitchell arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 | 435955242d8SJeenu Viswambharan ARM_CONFIG_FVP_HAS_CCI5XX); 4363e4b8fdcSSoby Mathew break; 4373e4b8fdcSSoby Mathew default: 4383e4b8fdcSSoby Mathew WARN("Unrecognized Base FVP revision %x\n", rev); 4393e4b8fdcSSoby Mathew break; 4403e4b8fdcSSoby Mathew } 4413e4b8fdcSSoby Mathew break; 4423e4b8fdcSSoby Mathew default: 4433e4b8fdcSSoby Mathew ERROR("Unsupported board HBI number 0x%x\n", hbi); 4443e4b8fdcSSoby Mathew panic(); 4453e4b8fdcSSoby Mathew } 4468431635bSIsla Mitchell 4478431635bSIsla Mitchell /* 4488431635bSIsla Mitchell * We assume that the presence of MT bit, and therefore shifted 4498431635bSIsla Mitchell * affinities, is uniform across the platform: either all CPUs, or no 4508431635bSIsla Mitchell * CPUs implement it. 4518431635bSIsla Mitchell */ 452583e0791SAntonio Nino Diaz if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U) 4538431635bSIsla Mitchell arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF; 4543e4b8fdcSSoby Mathew } 4553e4b8fdcSSoby Mathew 4563e4b8fdcSSoby Mathew 4574d010d0dSDaniel Boulby void __init fvp_interconnect_init(void) 4583e4b8fdcSSoby Mathew { 45971237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN 46071237876SSoby Mathew if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) { 461583e0791SAntonio Nino Diaz ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported"); 46271237876SSoby Mathew panic(); 46371237876SSoby Mathew } 464955242d8SJeenu Viswambharan 4653e4b8fdcSSoby Mathew plat_arm_interconnect_init(); 466955242d8SJeenu Viswambharan #else 467583e0791SAntonio Nino Diaz uintptr_t cci_base = 0U; 468583e0791SAntonio Nino Diaz const int *cci_map = NULL; 469583e0791SAntonio Nino Diaz unsigned int map_size = 0U; 470955242d8SJeenu Viswambharan 471955242d8SJeenu Viswambharan /* Initialize the right interconnect */ 472583e0791SAntonio Nino Diaz if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) { 473955242d8SJeenu Viswambharan cci_base = PLAT_FVP_CCI5XX_BASE; 474955242d8SJeenu Viswambharan cci_map = fvp_cci5xx_map; 475955242d8SJeenu Viswambharan map_size = ARRAY_SIZE(fvp_cci5xx_map); 476583e0791SAntonio Nino Diaz } else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) { 477955242d8SJeenu Viswambharan cci_base = PLAT_FVP_CCI400_BASE; 478955242d8SJeenu Viswambharan cci_map = fvp_cci400_map; 479955242d8SJeenu Viswambharan map_size = ARRAY_SIZE(fvp_cci400_map); 480583e0791SAntonio Nino Diaz } else { 481583e0791SAntonio Nino Diaz return; 482955242d8SJeenu Viswambharan } 483955242d8SJeenu Viswambharan 484583e0791SAntonio Nino Diaz assert(cci_base != 0U); 485583e0791SAntonio Nino Diaz assert(cci_map != NULL); 486955242d8SJeenu Viswambharan cci_init(cci_base, cci_map, map_size); 487955242d8SJeenu Viswambharan #endif 48871237876SSoby Mathew } 4893e4b8fdcSSoby Mathew 4903e4b8fdcSSoby Mathew void fvp_interconnect_enable(void) 4913e4b8fdcSSoby Mathew { 492955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN 4933e4b8fdcSSoby Mathew plat_arm_interconnect_enter_coherency(); 494955242d8SJeenu Viswambharan #else 495955242d8SJeenu Viswambharan unsigned int master; 496955242d8SJeenu Viswambharan 497583e0791SAntonio Nino Diaz if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 | 498583e0791SAntonio Nino Diaz ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) { 499955242d8SJeenu Viswambharan master = get_interconnect_master(); 500955242d8SJeenu Viswambharan cci_enable_snoop_dvm_reqs(master); 501955242d8SJeenu Viswambharan } 502955242d8SJeenu Viswambharan #endif 5033e4b8fdcSSoby Mathew } 5043e4b8fdcSSoby Mathew 5053e4b8fdcSSoby Mathew void fvp_interconnect_disable(void) 5063e4b8fdcSSoby Mathew { 507955242d8SJeenu Viswambharan #if FVP_INTERCONNECT_DRIVER == FVP_CCN 5083e4b8fdcSSoby Mathew plat_arm_interconnect_exit_coherency(); 509955242d8SJeenu Viswambharan #else 510955242d8SJeenu Viswambharan unsigned int master; 511955242d8SJeenu Viswambharan 512583e0791SAntonio Nino Diaz if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 | 513583e0791SAntonio Nino Diaz ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) { 514955242d8SJeenu Viswambharan master = get_interconnect_master(); 515955242d8SJeenu Viswambharan cci_disable_snoop_dvm_reqs(master); 516955242d8SJeenu Viswambharan } 517955242d8SJeenu Viswambharan #endif 5183e4b8fdcSSoby Mathew } 519ba597da7SJohn Tsichritzis 52088c51c3fSManish V Badarkhe #if CRYPTO_SUPPORT 521ba597da7SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size) 522ba597da7SJohn Tsichritzis { 523ba597da7SJohn Tsichritzis assert(heap_addr != NULL); 524ba597da7SJohn Tsichritzis assert(heap_size != NULL); 525ba597da7SJohn Tsichritzis 526ba597da7SJohn Tsichritzis return arm_get_mbedtls_heap(heap_addr, heap_size); 527ba597da7SJohn Tsichritzis } 52888c51c3fSManish V Badarkhe #endif /* CRYPTO_SUPPORT */ 5291b597c22SAlexei Fedorov 5301b597c22SAlexei Fedorov void fvp_timer_init(void) 5311b597c22SAlexei Fedorov { 532fddfb3baSMadhukar Pappireddy #if USE_SP804_TIMER 5331b597c22SAlexei Fedorov /* Enable the clock override for SP804 timer 0, which means that no 5341b597c22SAlexei Fedorov * clock dividers are applied and the raw (35MHz) clock will be used. 5351b597c22SAlexei Fedorov */ 5361b597c22SAlexei Fedorov mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV); 5371b597c22SAlexei Fedorov 5381b597c22SAlexei Fedorov /* Initialize delay timer driver using SP804 dual timer 0 */ 5391b597c22SAlexei Fedorov sp804_timer_init(V2M_SP804_TIMER0_BASE, 5401b597c22SAlexei Fedorov SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV); 5411b597c22SAlexei Fedorov #else 5421b597c22SAlexei Fedorov generic_delay_timer_init(); 5431b597c22SAlexei Fedorov 5441b597c22SAlexei Fedorov /* Enable System level generic timer */ 5451b597c22SAlexei Fedorov mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF, 5461b597c22SAlexei Fedorov CNTCR_FCREQ(0U) | CNTCR_EN); 547fddfb3baSMadhukar Pappireddy #endif /* USE_SP804_TIMER */ 5481b597c22SAlexei Fedorov } 549ed9653ffSManish V Badarkhe 550ed9653ffSManish V Badarkhe /***************************************************************************** 551ed9653ffSManish V Badarkhe * plat_is_smccc_feature_available() - This function checks whether SMCCC 552ed9653ffSManish V Badarkhe * feature is availabile for platform. 553ed9653ffSManish V Badarkhe * @fid: SMCCC function id 554ed9653ffSManish V Badarkhe * 555ed9653ffSManish V Badarkhe * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and 556ed9653ffSManish V Badarkhe * SMC_ARCH_CALL_NOT_SUPPORTED otherwise. 557ed9653ffSManish V Badarkhe *****************************************************************************/ 558ed9653ffSManish V Badarkhe int32_t plat_is_smccc_feature_available(u_register_t fid) 559ed9653ffSManish V Badarkhe { 560ed9653ffSManish V Badarkhe switch (fid) { 561ed9653ffSManish V Badarkhe case SMCCC_ARCH_SOC_ID: 562ed9653ffSManish V Badarkhe return SMC_ARCH_CALL_SUCCESS; 563ed9653ffSManish V Badarkhe default: 564ed9653ffSManish V Badarkhe return SMC_ARCH_CALL_NOT_SUPPORTED; 565ed9653ffSManish V Badarkhe } 566ed9653ffSManish V Badarkhe } 567ed9653ffSManish V Badarkhe 568ed9653ffSManish V Badarkhe /* Get SOC version */ 569ed9653ffSManish V Badarkhe int32_t plat_get_soc_version(void) 570ed9653ffSManish V Badarkhe { 571ed9653ffSManish V Badarkhe return (int32_t) 572dfff4686SYann Gautier (SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE, 573dfff4686SYann Gautier ARM_SOC_IDENTIFICATION_CODE) | 574dfff4686SYann Gautier (FVP_SOC_ID & SOC_ID_IMPL_DEF_MASK)); 575ed9653ffSManish V Badarkhe } 576ed9653ffSManish V Badarkhe 577ed9653ffSManish V Badarkhe /* Get SOC revision */ 578ed9653ffSManish V Badarkhe int32_t plat_get_soc_revision(void) 579ed9653ffSManish V Badarkhe { 580ed9653ffSManish V Badarkhe unsigned int sys_id; 581ed9653ffSManish V Badarkhe 582ed9653ffSManish V Badarkhe sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID); 583dfff4686SYann Gautier return (int32_t)(((sys_id >> V2M_SYS_ID_REV_SHIFT) & 584dfff4686SYann Gautier V2M_SYS_ID_REV_MASK) & SOC_ID_REV_MASK); 585ed9653ffSManish V Badarkhe } 5868c980a4aSJavier Almansa Sobrino 587cd802c29SArvind Ram Prakash /* Get SoC name */ 588cd802c29SArvind Ram Prakash int32_t plat_get_soc_name(char *soc_name) 589cd802c29SArvind Ram Prakash { 590cd802c29SArvind Ram Prakash snprintf(soc_name, SMCCC_SOC_NAME_LEN, "Arm Platform Revision %d", 591cd802c29SArvind Ram Prakash plat_get_soc_revision()); 592cd802c29SArvind Ram Prakash return SMC_ARCH_CALL_SUCCESS; 593cd802c29SArvind Ram Prakash } 5948c980a4aSJavier Almansa Sobrino #if ENABLE_RME 59590552c61SAlexeiFedorov 59690552c61SAlexeiFedorov /* BDF mappings for RP0 RC0 */ 59790552c61SAlexeiFedorov const struct bdf_mapping_info rc0rp0_bdf_data[] = { 59890552c61SAlexeiFedorov /* BDF0 */ 59990552c61SAlexeiFedorov {0U, /* mapping_base */ 60090552c61SAlexeiFedorov 0x8000U, /* mapping_top */ 60190552c61SAlexeiFedorov 0U, /* mapping_off */ 60290552c61SAlexeiFedorov 0U /* smmu_idx */ 60390552c61SAlexeiFedorov } 60490552c61SAlexeiFedorov }; 60590552c61SAlexeiFedorov 60690552c61SAlexeiFedorov /* Root ports for RC0 */ 60790552c61SAlexeiFedorov const struct root_port_info rc0rp_data[] = { 60890552c61SAlexeiFedorov /* RP0 */ 60990552c61SAlexeiFedorov {0U, /* root_port_id */ 61090552c61SAlexeiFedorov 0U, /* padding */ 61190552c61SAlexeiFedorov ARRAY_SIZE(rc0rp0_bdf_data), /* num_bdf_mappings */ 61290552c61SAlexeiFedorov (struct bdf_mapping_info *)rc0rp0_bdf_data /* bdf_mappings */ 61390552c61SAlexeiFedorov } 61490552c61SAlexeiFedorov }; 61590552c61SAlexeiFedorov 61690552c61SAlexeiFedorov /* Root complexes */ 61790552c61SAlexeiFedorov const struct root_complex_info rc_data[] = { 61890552c61SAlexeiFedorov /* RC0 */ 61990552c61SAlexeiFedorov {PCIE_EXP_BASE, /* ecam_base */ 62090552c61SAlexeiFedorov 0U, /* segment */ 62190552c61SAlexeiFedorov {0U, 0U, 0U}, /* padding */ 62290552c61SAlexeiFedorov ARRAY_SIZE(rc0rp_data), /* num_root_ports */ 62390552c61SAlexeiFedorov (struct root_port_info *)rc0rp_data /* root_ports */ 62490552c61SAlexeiFedorov } 62590552c61SAlexeiFedorov }; 62690552c61SAlexeiFedorov 62790552c61SAlexeiFedorov /* Number of PCIe Root Complexes */ 62890552c61SAlexeiFedorov #define FVP_RMM_RC_COUNT ARRAY_SIZE(rc_data) 62990552c61SAlexeiFedorov 6308c980a4aSJavier Almansa Sobrino /* 6318c980a4aSJavier Almansa Sobrino * Get a pointer to the RMM-EL3 Shared buffer and return it 6328c980a4aSJavier Almansa Sobrino * through the pointer passed as parameter. 6338c980a4aSJavier Almansa Sobrino * 6348c980a4aSJavier Almansa Sobrino * This function returns the size of the shared buffer. 6358c980a4aSJavier Almansa Sobrino */ 6368c980a4aSJavier Almansa Sobrino size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared) 6378c980a4aSJavier Almansa Sobrino { 6388c980a4aSJavier Almansa Sobrino *shared = (uintptr_t)RMM_SHARED_BASE; 6398c980a4aSJavier Almansa Sobrino 6408c980a4aSJavier Almansa Sobrino return (size_t)RMM_SHARED_SIZE; 6418c980a4aSJavier Almansa Sobrino } 6421d0ca40eSJavier Almansa Sobrino 643aa99881dSAlexeiFedorov /* 644aa99881dSAlexeiFedorov * Calculate checksum of 64-bit words @buffer with @size length 645aa99881dSAlexeiFedorov */ 646aa99881dSAlexeiFedorov static uint64_t checksum_calc(uint64_t *buffer, size_t size) 647aa99881dSAlexeiFedorov { 648aa99881dSAlexeiFedorov uint64_t sum = 0UL; 649aa99881dSAlexeiFedorov 650aa99881dSAlexeiFedorov assert(((uintptr_t)buffer & (sizeof(uint64_t) - 1UL)) == 0UL); 651aa99881dSAlexeiFedorov assert((size & (sizeof(uint64_t) - 1UL)) == 0UL); 652aa99881dSAlexeiFedorov 653aa99881dSAlexeiFedorov for (unsigned long i = 0UL; i < (size / sizeof(uint64_t)); i++) { 654aa99881dSAlexeiFedorov sum += buffer[i]; 655aa99881dSAlexeiFedorov } 656aa99881dSAlexeiFedorov 657aa99881dSAlexeiFedorov return sum; 658aa99881dSAlexeiFedorov } 659bef44f60SAlexeiFedorov /* 66090552c61SAlexeiFedorov * Boot Manifest v0.5 structure illustration, with two DRAM banks, 661bef44f60SAlexeiFedorov * a single console and one device memory with two PCIe device 662bef44f60SAlexeiFedorov * non-coherent address ranges. 663bef44f60SAlexeiFedorov * 664bef44f60SAlexeiFedorov * +--------------------------------------------------+ 665bef44f60SAlexeiFedorov * | offset | field | comment | 666bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ 66790552c61SAlexeiFedorov * | 0 | version | 0x00000005 | 668bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ 669bef44f60SAlexeiFedorov * | 4 | padding | 0x00000000 | 670bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ 671bef44f60SAlexeiFedorov * | 8 | plat_data | NULL | 672bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ 673bef44f60SAlexeiFedorov * | 16 | num_banks | | 674bef44f60SAlexeiFedorov * +--------+--------------------+ | 675bef44f60SAlexeiFedorov * | 24 | banks | plat_dram +--+ 676bef44f60SAlexeiFedorov * +--------+--------------------+ | | 677bef44f60SAlexeiFedorov * | 32 | checksum | | | 678bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ | 679bef44f60SAlexeiFedorov * | 40 | num_consoles | | | 680bef44f60SAlexeiFedorov * +--------+--------------------+ | | 681bef44f60SAlexeiFedorov * | 48 | consoles | plat_console +--|--+ 682bef44f60SAlexeiFedorov * +--------+--------------------+ | | | 683bef44f60SAlexeiFedorov * | 56 | checksum | | | | 684bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ | | 685bef44f60SAlexeiFedorov * | 64 | num_banks | | | | 686bef44f60SAlexeiFedorov * +--------+--------------------+ | | | 687bef44f60SAlexeiFedorov * | 72 | banks | plat_ncoh_region +--|--|--+ 688bef44f60SAlexeiFedorov * +--------+--------------------+ | | | | 689bef44f60SAlexeiFedorov * | 80 | checksum | | | | | 690bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ | | | 691bef44f60SAlexeiFedorov * | 88 | num_banks | | | | | 692bef44f60SAlexeiFedorov * +--------+--------------------+ | | | | 693bef44f60SAlexeiFedorov * | 96 | banks | plat_coh_region | | | | 694bef44f60SAlexeiFedorov * +--------+--------------------+ | | | | 695bef44f60SAlexeiFedorov * | 104 | checksum | | | | | 69690552c61SAlexeiFedorov * +--------+--------------------+--------------------+ | | | 69790552c61SAlexeiFedorov * | 112 | num_smmus | | | | | 69890552c61SAlexeiFedorov * +--------+--------------------+ | | | | 69990552c61SAlexeiFedorov * | 120 | smmus | plat_smmu +--|--|--|--+ 70090552c61SAlexeiFedorov * +--------+--------------------+ | | | | | 70190552c61SAlexeiFedorov * | 128 | checksum | | | | | | 70290552c61SAlexeiFedorov * +--------+--------------------+--------------------+ | | | | 70390552c61SAlexeiFedorov * | 136 | num_root_complex | | | | | | 70490552c61SAlexeiFedorov * +--------+--------------------+ | | | | | 70590552c61SAlexeiFedorov * | 144 | rc_info_version | | | | | | 70690552c61SAlexeiFedorov * +--------+--------------------+ | | | | | 70790552c61SAlexeiFedorov * | 148 | padding | plat_root_complex +--|--|--|--|--+ 70890552c61SAlexeiFedorov * +--------+--------------------+ | | | | | | 70990552c61SAlexeiFedorov * | 152 | root_complex | | | | | | | 71090552c61SAlexeiFedorov * +--------+--------------------+ | | | | | | 71190552c61SAlexeiFedorov * | 160 | checksum | | | | | | | 71290552c61SAlexeiFedorov * +--------+--------------------+--------------------+<-+ | | | | 71390552c61SAlexeiFedorov * | 168 | base 0 | | | | | | 71490552c61SAlexeiFedorov * +--------+--------------------+ mem_bank[0] | | | | | 71590552c61SAlexeiFedorov * | 176 | size 0 | | | | | | 71690552c61SAlexeiFedorov * +--------+--------------------+--------------------+ | | | | 71790552c61SAlexeiFedorov * | 184 | base 1 | | | | | | 71890552c61SAlexeiFedorov * +--------+--------------------+ mem_bank[1] | | | | | 71990552c61SAlexeiFedorov * | 192 | size 1 | | | | | | 72090552c61SAlexeiFedorov * +--------+--------------------+--------------------+<----+ | | | 72190552c61SAlexeiFedorov * | 200 | base | | | | | 72290552c61SAlexeiFedorov * +--------+--------------------+ | | | | 72390552c61SAlexeiFedorov * | 208 | map_pages | | | | | 72490552c61SAlexeiFedorov * +--------+--------------------+ | | | | 72590552c61SAlexeiFedorov * | 216 | name | | | | | 72690552c61SAlexeiFedorov * +--------+--------------------+ consoles[0] | | | | 72790552c61SAlexeiFedorov * | 224 | clk_in_hz | | | | | 72890552c61SAlexeiFedorov * +--------+--------------------+ | | | | 72990552c61SAlexeiFedorov * | 232 | baud_rate | | | | | 73090552c61SAlexeiFedorov * +--------+--------------------+ | | | | 73190552c61SAlexeiFedorov * | 240 | flags | | | | | 73290552c61SAlexeiFedorov * +--------+--------------------+--------------------+<-------+ | | 73390552c61SAlexeiFedorov * | 248 | base 0 | | | | 73490552c61SAlexeiFedorov * +--------+--------------------+ ncoh_region[0] | | | 73590552c61SAlexeiFedorov * | 256 | size 0 | | | | 736bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ | | 73790552c61SAlexeiFedorov * | 264 | base 1 | | | | 73890552c61SAlexeiFedorov * +--------+--------------------+ ncoh_region[1] | | | 73990552c61SAlexeiFedorov * | 272 | size 1 | | | | 74090552c61SAlexeiFedorov * +--------+--------------------+--------------------+<----------+ | 74190552c61SAlexeiFedorov * | 280 | smmu_base | | | 74290552c61SAlexeiFedorov * +--------+--------------------+ smmus[0] | | 74390552c61SAlexeiFedorov * | 288 | smmu_r_base | | | 74490552c61SAlexeiFedorov * +--------+--------------------+--------------------+<-------------+ 74590552c61SAlexeiFedorov * | 296 | ecam_base | | 74690552c61SAlexeiFedorov * +--------+--------------------+ | 74790552c61SAlexeiFedorov * | 304 | segment | | 74890552c61SAlexeiFedorov * +--------+--------------------+ | 74990552c61SAlexeiFedorov * | 305 | padding | root_complex[0] +--+ 750bef44f60SAlexeiFedorov * +--------+--------------------+ | | 75190552c61SAlexeiFedorov * | 308 | num_root_ports | | | 752bef44f60SAlexeiFedorov * +--------+--------------------+ | | 75390552c61SAlexeiFedorov * | 312 | root_ports | | | 75490552c61SAlexeiFedorov * +--------+--------------------+--------------------+<-+ 75590552c61SAlexeiFedorov * | 320 | root_port_id | | 75690552c61SAlexeiFedorov * +--------+--------------------+ | 75790552c61SAlexeiFedorov * | 322 | padding | | 75890552c61SAlexeiFedorov * +--------+--------------------+ root_ports[0] +--+ 75990552c61SAlexeiFedorov * | 324 | num_bdf_mappings | | | 760bef44f60SAlexeiFedorov * +--------+--------------------+ | | 76190552c61SAlexeiFedorov * | 328 | bdf_mappings | | | 76290552c61SAlexeiFedorov * +--------+--------------------+--------------------+<-+ 76390552c61SAlexeiFedorov * | 336 | mapping_base | | 76490552c61SAlexeiFedorov * +--------+--------------------+ | 76590552c61SAlexeiFedorov * | 338 | mapping_top | | 76690552c61SAlexeiFedorov * +--------+--------------------+ bdf_mappings[0] | 76790552c61SAlexeiFedorov * | 340 | mapping_off | | 76890552c61SAlexeiFedorov * +--------+--------------------+ | 76990552c61SAlexeiFedorov * | 342 | smmu_idx | | 770bef44f60SAlexeiFedorov * +--------+--------------------+--------------------+ 771bef44f60SAlexeiFedorov */ 772a97bfa5fSAlexeiFedorov int plat_rmmd_load_manifest(struct rmm_manifest *manifest) 7731d0ca40eSJavier Almansa Sobrino { 77432904472SSoby Mathew uint64_t checksum, num_banks, num_consoles; 775bef44f60SAlexeiFedorov uint64_t num_ncoh_regions, num_coh_regions; 77690552c61SAlexeiFedorov uint64_t num_smmus, num_root_complex; 77790552c61SAlexeiFedorov unsigned int num_root_ports, num_bdf_mappings; 77890552c61SAlexeiFedorov uint32_t o_realm; 77990552c61SAlexeiFedorov struct memory_bank *bank_ptr, *ncoh_region_ptr, *coh_region_ptr; 78032904472SSoby Mathew struct console_info *console_ptr; 78190552c61SAlexeiFedorov struct smmu_info *smmu_ptr; 78290552c61SAlexeiFedorov struct root_complex_info *root_complex_ptr, *rc_ptr; 78390552c61SAlexeiFedorov struct root_port_info *root_port_ptr, *rp_ptr; 78490552c61SAlexeiFedorov struct bdf_mapping_info *bdf_mapping_ptr, *bdf_ptr; 785a97bfa5fSAlexeiFedorov 7861d0ca40eSJavier Almansa Sobrino assert(manifest != NULL); 7871d0ca40eSJavier Almansa Sobrino 78882685904SAlexeiFedorov /* Get number of DRAM banks */ 78982685904SAlexeiFedorov num_banks = FCONF_GET_PROPERTY(hw_config, dram_layout, num_banks); 79082685904SAlexeiFedorov assert(num_banks <= ARM_DRAM_NUM_BANKS); 79182685904SAlexeiFedorov 79232904472SSoby Mathew /* Set number of consoles */ 79332904472SSoby Mathew num_consoles = FVP_RMM_CONSOLE_COUNT; 79432904472SSoby Mathew 7952cbea163SSoby Mathew /* Set number of device non-coherent address ranges for FVP RevC */ 7962cbea163SSoby Mathew num_ncoh_regions = 2; 797bef44f60SAlexeiFedorov 79890552c61SAlexeiFedorov /* Set number of SMMUs */ 79990552c61SAlexeiFedorov num_smmus = FVP_RMM_SMMU_COUNT; 80090552c61SAlexeiFedorov 80190552c61SAlexeiFedorov /* Set number of PCIe root complexes */ 80290552c61SAlexeiFedorov num_root_complex = FVP_RMM_RC_COUNT; 80390552c61SAlexeiFedorov 80490552c61SAlexeiFedorov /* Calculate and set number of all PCIe root ports and BDF mappings */ 80590552c61SAlexeiFedorov num_root_ports = 0U; 80690552c61SAlexeiFedorov num_bdf_mappings = 0U; 80790552c61SAlexeiFedorov 80890552c61SAlexeiFedorov /* Scan all root complex entries */ 80990552c61SAlexeiFedorov for (unsigned long i = 0UL; i < num_root_complex; i++) { 81090552c61SAlexeiFedorov num_root_ports += rc_data[i].num_root_ports; 81190552c61SAlexeiFedorov 81290552c61SAlexeiFedorov /* Scan all root ports entries in root complex */ 81390552c61SAlexeiFedorov for (unsigned int j = 0U; j < rc_data[i].num_root_ports; j++) { 81490552c61SAlexeiFedorov num_bdf_mappings += rc_data[i].root_ports[j].num_bdf_mappings; 81590552c61SAlexeiFedorov } 81690552c61SAlexeiFedorov } 81790552c61SAlexeiFedorov 8181d0ca40eSJavier Almansa Sobrino manifest->version = RMMD_MANIFEST_VERSION; 819dc0ca64eSJavier Almansa Sobrino manifest->padding = 0U; /* RES0 */ 820bef44f60SAlexeiFedorov manifest->plat_data = 0UL; 82182685904SAlexeiFedorov manifest->plat_dram.num_banks = num_banks; 82232904472SSoby Mathew manifest->plat_console.num_consoles = num_consoles; 823bef44f60SAlexeiFedorov manifest->plat_ncoh_region.num_banks = num_ncoh_regions; 82490552c61SAlexeiFedorov manifest->plat_smmu.num_smmus = num_smmus; 82590552c61SAlexeiFedorov manifest->plat_root_complex.num_root_complex = num_root_complex; 82690552c61SAlexeiFedorov manifest->plat_root_complex.rc_info_version = PCIE_RC_INFO_VERSION; 82790552c61SAlexeiFedorov manifest->plat_root_complex.padding = 0U; /* RES0 */ 828a97bfa5fSAlexeiFedorov 829bef44f60SAlexeiFedorov /* FVP does not support device coherent address ranges */ 830bef44f60SAlexeiFedorov num_coh_regions = 0UL; 831bef44f60SAlexeiFedorov manifest->plat_coh_region.num_banks = num_coh_regions; 832bef44f60SAlexeiFedorov manifest->plat_coh_region.banks = NULL; 833bef44f60SAlexeiFedorov manifest->plat_coh_region.checksum = 0UL; 83432904472SSoby Mathew 835bef44f60SAlexeiFedorov bank_ptr = (struct memory_bank *) 836bef44f60SAlexeiFedorov (((uintptr_t)manifest) + sizeof(struct rmm_manifest)); 83732904472SSoby Mathew console_ptr = (struct console_info *) 838bef44f60SAlexeiFedorov ((uintptr_t)bank_ptr + (num_banks * 839bef44f60SAlexeiFedorov sizeof(struct memory_bank))); 840bef44f60SAlexeiFedorov ncoh_region_ptr = (struct memory_bank *) 841bef44f60SAlexeiFedorov ((uintptr_t)console_ptr + (num_consoles * 842bef44f60SAlexeiFedorov sizeof(struct console_info))); 84390552c61SAlexeiFedorov coh_region_ptr = (struct memory_bank *) 84490552c61SAlexeiFedorov ((uintptr_t)ncoh_region_ptr + (num_ncoh_regions * 84590552c61SAlexeiFedorov sizeof(struct memory_bank))); 84690552c61SAlexeiFedorov smmu_ptr = (struct smmu_info *) 84790552c61SAlexeiFedorov ((uintptr_t)coh_region_ptr + (num_coh_regions * 84890552c61SAlexeiFedorov sizeof(struct memory_bank))); 84990552c61SAlexeiFedorov root_complex_ptr = (struct root_complex_info *) 85090552c61SAlexeiFedorov ((uintptr_t)smmu_ptr + (num_smmus * 85190552c61SAlexeiFedorov sizeof(struct smmu_info))); 85290552c61SAlexeiFedorov root_port_ptr = (struct root_port_info *) 85390552c61SAlexeiFedorov ((uintptr_t)root_complex_ptr + (num_root_complex * 85490552c61SAlexeiFedorov sizeof(struct root_complex_info))); 85590552c61SAlexeiFedorov bdf_mapping_ptr = (struct bdf_mapping_info *) 85690552c61SAlexeiFedorov ((uintptr_t)root_port_ptr + (num_root_ports * 85790552c61SAlexeiFedorov sizeof(struct root_port_info))); 85890552c61SAlexeiFedorov 85982685904SAlexeiFedorov manifest->plat_dram.banks = bank_ptr; 86032904472SSoby Mathew manifest->plat_console.consoles = console_ptr; 861bef44f60SAlexeiFedorov manifest->plat_ncoh_region.banks = ncoh_region_ptr; 86290552c61SAlexeiFedorov manifest->plat_smmu.smmus = smmu_ptr; 86390552c61SAlexeiFedorov manifest->plat_root_complex.root_complex = root_complex_ptr; 86432904472SSoby Mathew 86532904472SSoby Mathew /* Ensure the manifest is not larger than the shared buffer */ 86632904472SSoby Mathew assert((sizeof(struct rmm_manifest) + 867bef44f60SAlexeiFedorov (sizeof(struct memory_bank) * 868bef44f60SAlexeiFedorov manifest->plat_dram.num_banks) + 869bef44f60SAlexeiFedorov (sizeof(struct console_info) * 870bef44f60SAlexeiFedorov manifest->plat_console.num_consoles) + 871bef44f60SAlexeiFedorov (sizeof(struct memory_bank) * 872bef44f60SAlexeiFedorov manifest->plat_ncoh_region.num_banks) + 873bef44f60SAlexeiFedorov (sizeof(struct memory_bank) * 87490552c61SAlexeiFedorov manifest->plat_coh_region.num_banks) + 87590552c61SAlexeiFedorov (sizeof(struct smmu_info) * 87690552c61SAlexeiFedorov manifest->plat_smmu.num_smmus) + 87790552c61SAlexeiFedorov (sizeof(struct root_complex_info) * 87890552c61SAlexeiFedorov manifest->plat_root_complex.num_root_complex) + 87990552c61SAlexeiFedorov (sizeof(struct root_port_info) * num_root_ports) + 88090552c61SAlexeiFedorov (sizeof(struct bdf_mapping_info) * num_bdf_mappings)) 881bef44f60SAlexeiFedorov <= ARM_EL3_RMM_SHARED_SIZE); 882a97bfa5fSAlexeiFedorov 883a97bfa5fSAlexeiFedorov /* Calculate checksum of plat_dram structure */ 88482685904SAlexeiFedorov checksum = num_banks + (uint64_t)bank_ptr; 885a97bfa5fSAlexeiFedorov 88682685904SAlexeiFedorov /* Store FVP DRAM banks data in Boot Manifest */ 88782685904SAlexeiFedorov for (unsigned long i = 0UL; i < num_banks; i++) { 888aa99881dSAlexeiFedorov bank_ptr[i].base = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].base); 889aa99881dSAlexeiFedorov bank_ptr[i].size = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].size); 890aa99881dSAlexeiFedorov } 89182685904SAlexeiFedorov 89282685904SAlexeiFedorov /* Update checksum */ 893bef44f60SAlexeiFedorov checksum += checksum_calc((uint64_t *)bank_ptr, sizeof(struct memory_bank) * num_banks); 894a97bfa5fSAlexeiFedorov 895a97bfa5fSAlexeiFedorov /* Checksum must be 0 */ 89682685904SAlexeiFedorov manifest->plat_dram.checksum = ~checksum + 1UL; 8971d0ca40eSJavier Almansa Sobrino 898bef44f60SAlexeiFedorov /* Calculate the checksum of plat_consoles structure */ 89932904472SSoby Mathew checksum = num_consoles + (uint64_t)console_ptr; 90032904472SSoby Mathew 90132904472SSoby Mathew /* Zero out the console info struct */ 902bef44f60SAlexeiFedorov (void)memset((void *)console_ptr, '\0', 903bef44f60SAlexeiFedorov sizeof(struct console_info) * num_consoles); 90432904472SSoby Mathew 90532904472SSoby Mathew console_ptr[0].base = FVP_RMM_CONSOLE_BASE; 906aa99881dSAlexeiFedorov console_ptr[0].map_pages = 1UL; 90732904472SSoby Mathew console_ptr[0].clk_in_hz = FVP_RMM_CONSOLE_CLK_IN_HZ; 90832904472SSoby Mathew console_ptr[0].baud_rate = FVP_RMM_CONSOLE_BAUD; 90932904472SSoby Mathew 910bef44f60SAlexeiFedorov (void)strlcpy(console_ptr[0].name, FVP_RMM_CONSOLE_NAME, 911bef44f60SAlexeiFedorov RMM_CONSOLE_MAX_NAME_LEN - 1UL); 91232904472SSoby Mathew 91332904472SSoby Mathew /* Update checksum */ 914aa99881dSAlexeiFedorov checksum += checksum_calc((uint64_t *)console_ptr, 915aa99881dSAlexeiFedorov sizeof(struct console_info) * num_consoles); 91632904472SSoby Mathew /* Checksum must be 0 */ 91732904472SSoby Mathew manifest->plat_console.checksum = ~checksum + 1UL; 91832904472SSoby Mathew 919bef44f60SAlexeiFedorov /* 920bef44f60SAlexeiFedorov * Calculate the checksum of device non-coherent address ranges 921bef44f60SAlexeiFedorov * info structure 922bef44f60SAlexeiFedorov */ 923bef44f60SAlexeiFedorov checksum = num_ncoh_regions + (uint64_t)ncoh_region_ptr; 924bef44f60SAlexeiFedorov 925bef44f60SAlexeiFedorov /* Zero out the PCIe region info struct */ 926bef44f60SAlexeiFedorov (void)memset((void *)ncoh_region_ptr, 0, 927bef44f60SAlexeiFedorov sizeof(struct memory_bank) * num_ncoh_regions); 928bef44f60SAlexeiFedorov 9292cbea163SSoby Mathew /* Set number of device non-coherent address ranges based on DT */ 9302cbea163SSoby Mathew num_ncoh_regions = FCONF_GET_PROPERTY(hw_config, pci_props, num_ncoh_regions); 9312cbea163SSoby Mathew /* At least 1 PCIe region need to be described in DT */ 9322cbea163SSoby Mathew assert((num_ncoh_regions > 0) && (num_ncoh_regions <= 2)); 9332cbea163SSoby Mathew 934bef44f60SAlexeiFedorov for (unsigned long i = 0UL; i < num_ncoh_regions; i++) { 935bef44f60SAlexeiFedorov ncoh_region_ptr[i].base = 936bef44f60SAlexeiFedorov FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].base); 937bef44f60SAlexeiFedorov ncoh_region_ptr[i].size = 938bef44f60SAlexeiFedorov FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].size); 939bef44f60SAlexeiFedorov } 940bef44f60SAlexeiFedorov 9412cbea163SSoby Mathew /* 9422cbea163SSoby Mathew * Workaround if the DT does not specify the 2nd PCIe region. This code can be 9432cbea163SSoby Mathew * removed when upstream DT is updated to have 2nd PCIe region. 9442cbea163SSoby Mathew */ 9452cbea163SSoby Mathew if (num_ncoh_regions == 1) { 9462cbea163SSoby Mathew num_ncoh_regions++; 9472cbea163SSoby Mathew /* Add 3GB of 2nd PCIe region */ 9482cbea163SSoby Mathew ncoh_region_ptr[1].base = 0x4000000000; 9492cbea163SSoby Mathew ncoh_region_ptr[1].size = 0xc0000000; 9502cbea163SSoby Mathew } 9512cbea163SSoby Mathew 952bef44f60SAlexeiFedorov /* Update checksum */ 953bef44f60SAlexeiFedorov checksum += checksum_calc((uint64_t *)ncoh_region_ptr, 954bef44f60SAlexeiFedorov sizeof(struct memory_bank) * num_ncoh_regions); 955bef44f60SAlexeiFedorov 956bef44f60SAlexeiFedorov /* Checksum must be 0 */ 957bef44f60SAlexeiFedorov manifest->plat_ncoh_region.checksum = ~checksum + 1UL; 958bef44f60SAlexeiFedorov 95990552c61SAlexeiFedorov /* Calculate the checksum of the plat_smmu structure */ 96090552c61SAlexeiFedorov checksum = num_smmus + (uint64_t)smmu_ptr; 96190552c61SAlexeiFedorov 96290552c61SAlexeiFedorov smmu_ptr[0].smmu_base = FVP_RMM_SMMU_BASE; 96390552c61SAlexeiFedorov 96490552c61SAlexeiFedorov /* Read SMMU_ROOT_IDR0.BA_REALM[31:22] register field */ 96590552c61SAlexeiFedorov o_realm = mmio_read_32(FVP_RMM_SMMU_BASE + SMMU_ROOT_IDR0) & 96690552c61SAlexeiFedorov SMMU_ROOT_IDR0_BA_REALM_MASK; 96790552c61SAlexeiFedorov /* 96890552c61SAlexeiFedorov * Calculate the base address offset of Realm Register Page 0. 96990552c61SAlexeiFedorov * O_REALM = 0x20000 + (BA_REALM * 0x10000) 97090552c61SAlexeiFedorov * SMMU_REALM_BASE = SMMU_PAGE_0_BASE + O_REALM 97190552c61SAlexeiFedorov */ 97290552c61SAlexeiFedorov o_realm = 0x20000 + (o_realm >> (SMMU_ROOT_IDR0_BA_REALM_SHIFT - 16U)); 97390552c61SAlexeiFedorov 97490552c61SAlexeiFedorov smmu_ptr[0].smmu_r_base = FVP_RMM_SMMU_BASE + o_realm; 97590552c61SAlexeiFedorov 97690552c61SAlexeiFedorov /* Update checksum */ 97790552c61SAlexeiFedorov checksum += checksum_calc((uint64_t *)smmu_ptr, 97890552c61SAlexeiFedorov sizeof(struct smmu_info) * num_smmus); 97990552c61SAlexeiFedorov /* Checksum must be 0 */ 98090552c61SAlexeiFedorov manifest->plat_smmu.checksum = ~checksum + 1UL; 98190552c61SAlexeiFedorov 98290552c61SAlexeiFedorov /* Calculate the checksum of the plat_root_complex structure */ 98390552c61SAlexeiFedorov checksum = num_root_complex + (uint64_t)root_complex_ptr; 98490552c61SAlexeiFedorov 98590552c61SAlexeiFedorov /* Zero out PCIe root complex info structures */ 98690552c61SAlexeiFedorov (void)memset((void *)root_complex_ptr, 0, 98790552c61SAlexeiFedorov sizeof(struct root_complex_info) * num_root_complex); 98890552c61SAlexeiFedorov 98990552c61SAlexeiFedorov /* Set pointers for data in manifest */ 99090552c61SAlexeiFedorov rc_ptr = root_complex_ptr; 99190552c61SAlexeiFedorov rp_ptr = root_port_ptr; 99290552c61SAlexeiFedorov bdf_ptr = bdf_mapping_ptr; 99390552c61SAlexeiFedorov 99490552c61SAlexeiFedorov /* Fill PCIe root complex info structures */ 99590552c61SAlexeiFedorov for (unsigned long i = 0U; i < num_root_complex; i++) { 99690552c61SAlexeiFedorov const struct root_complex_info *rc_info = &rc_data[i]; 99790552c61SAlexeiFedorov const struct root_port_info *rp_info = rc_info->root_ports; 99890552c61SAlexeiFedorov 99990552c61SAlexeiFedorov /* Copy root complex data, except root_ports pointer */ 100090552c61SAlexeiFedorov (void)memcpy((void *)rc_ptr, (void *)rc_info, 100190552c61SAlexeiFedorov sizeof(struct root_complex_info) - sizeof(struct root_port_info *)); 100290552c61SAlexeiFedorov 100390552c61SAlexeiFedorov /* Set root_ports for root complex */ 100490552c61SAlexeiFedorov rc_ptr->root_ports = rp_ptr; 100590552c61SAlexeiFedorov 100690552c61SAlexeiFedorov /* Scan root ports */ 100790552c61SAlexeiFedorov for (unsigned int j = 0U; j < rc_ptr->num_root_ports; j++) { 100890552c61SAlexeiFedorov const struct bdf_mapping_info *bdf_info = rp_info->bdf_mappings; 100990552c61SAlexeiFedorov 101090552c61SAlexeiFedorov /* Copy root port data, except bdf_mappings pointer */ 101190552c61SAlexeiFedorov (void)memcpy((void *)rp_ptr, (void *)rp_info, 101290552c61SAlexeiFedorov sizeof(struct root_port_info) - sizeof(struct bdf_mapping_info *)); 101390552c61SAlexeiFedorov 101490552c61SAlexeiFedorov /* Set bdf_mappings for root port */ 101590552c61SAlexeiFedorov rp_ptr->bdf_mappings = bdf_ptr; 101690552c61SAlexeiFedorov 101790552c61SAlexeiFedorov /* Copy all BDF mappings for root port */ 101890552c61SAlexeiFedorov (void)memcpy((void *)bdf_ptr, (void *)bdf_info, 101990552c61SAlexeiFedorov sizeof(struct bdf_mapping_info) * rp_ptr->num_bdf_mappings); 102090552c61SAlexeiFedorov 102190552c61SAlexeiFedorov bdf_ptr += rp_ptr->num_bdf_mappings; 102290552c61SAlexeiFedorov rp_ptr++; 102390552c61SAlexeiFedorov rp_info++; 102490552c61SAlexeiFedorov } 102590552c61SAlexeiFedorov rc_ptr++; 102690552c61SAlexeiFedorov } 102790552c61SAlexeiFedorov 102890552c61SAlexeiFedorov /* Check that all data are written in manifest */ 102990552c61SAlexeiFedorov assert(rc_ptr == (root_complex_ptr + num_root_complex)); 103090552c61SAlexeiFedorov assert(rp_ptr == (root_port_ptr + num_root_ports)); 103190552c61SAlexeiFedorov assert(bdf_ptr == (bdf_mapping_ptr + num_bdf_mappings)); 103290552c61SAlexeiFedorov 103390552c61SAlexeiFedorov /* Update checksum for all PCIe data */ 103490552c61SAlexeiFedorov checksum += checksum_calc((uint64_t *)root_complex_ptr, 103590552c61SAlexeiFedorov (uintptr_t)bdf_ptr - (uintptr_t)root_complex_ptr); 103690552c61SAlexeiFedorov 103790552c61SAlexeiFedorov /* Checksum must be 0 */ 103890552c61SAlexeiFedorov manifest->plat_root_complex.checksum = ~checksum + 1UL; 103990552c61SAlexeiFedorov 10401d0ca40eSJavier Almansa Sobrino return 0; 10411d0ca40eSJavier Almansa Sobrino } 1042f801fdc2STushar Khandelwal 1043f801fdc2STushar Khandelwal /* 1044f801fdc2STushar Khandelwal * Update encryption key associated with @mecid. 1045f801fdc2STushar Khandelwal */ 1046f801fdc2STushar Khandelwal int plat_rmmd_mecid_key_update(uint16_t mecid) 1047f801fdc2STushar Khandelwal { 1048f801fdc2STushar Khandelwal /* 1049f801fdc2STushar Khandelwal * FVP does not provide an interface to change the encryption key associated 1050f801fdc2STushar Khandelwal * with MECID. Hence always return success. 1051f801fdc2STushar Khandelwal */ 1052f801fdc2STushar Khandelwal return 0; 1053f801fdc2STushar Khandelwal } 1054a97bfa5fSAlexeiFedorov #endif /* ENABLE_RME */ 1055