blob: 9d0463dbba8c009fb50dba64da71e3098542c369 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
AlexeiFedorovbef44f62024-10-14 15:23:34 +01002 * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00007#include <assert.h>
Soby Mathew32904472024-03-26 17:16:00 +00008#include <string.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00009
Tushar Khandelwalf801fdc2024-04-22 15:35:40 +010010#include <arch.h>
11#include <arch_helpers.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000012#include <common/debug.h>
13#include <drivers/arm/cci.h>
14#include <drivers/arm/ccn.h>
15#include <drivers/arm/gicv2.h>
Alexei Fedorov1b597c22019-08-16 14:15:59 +010016#include <drivers/arm/sp804_delay_timer.h>
AlexeiFedorov90552c62025-01-30 14:56:47 +000017#include <drivers/arm/smmu_v3.h>
Alexei Fedorov1b597c22019-08-16 14:15:59 +010018#include <drivers/generic_delay_timer.h>
AlexeiFedorov82685902022-12-29 15:57:40 +000019#include <fconf_hw_config_getter.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000020#include <lib/mmio.h>
Manish V Badarkheed9653f2020-08-04 17:09:10 +010021#include <lib/smccc.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000022#include <lib/xlat_tables/xlat_tables_compat.h>
Antonio Nino Diaz234bc7f2019-01-15 14:19:50 +000023#include <platform_def.h>
Manish V Badarkheed9653f2020-08-04 17:09:10 +010024#include <services/arm_arch_svc.h>
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +010025#include <services/rmm_core_manifest.h>
Olivier Deprez9d9ae972020-07-30 17:18:33 +020026#if SPM_MM
Paul Beesleyaeaa2252019-10-15 10:57:42 +000027#include <services/spm_mm_partition.h>
Olivier Deprez9d9ae972020-07-30 17:18:33 +020028#endif
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000029
Manish V Badarkheed9653f2020-08-04 17:09:10 +010030#include <plat/arm/common/arm_config.h>
31#include <plat/arm/common/plat_arm.h>
32#include <plat/common/platform.h>
33
Roberto Vargas1af540e2018-02-12 12:36:17 +000034#include "fvp_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010035
Achin Gupta27573c52015-11-03 14:18:34 +000036/* Defines for GIC Driver build time selection */
37#define FVP_GICV2 1
38#define FVP_GICV3 2
Achin Gupta27573c52015-11-03 14:18:34 +000039
AlexeiFedorovbef44f62024-10-14 15:23:34 +010040/* Defines for RMM Console */
Soby Mathew32904472024-03-26 17:16:00 +000041#define FVP_RMM_CONSOLE_BASE UL(0x1c0c0000)
42#define FVP_RMM_CONSOLE_BAUD UL(115200)
43#define FVP_RMM_CONSOLE_CLK_IN_HZ UL(14745600)
44#define FVP_RMM_CONSOLE_NAME "pl011"
Soby Mathew32904472024-03-26 17:16:00 +000045#define FVP_RMM_CONSOLE_COUNT UL(1)
46
AlexeiFedorov90552c62025-01-30 14:56:47 +000047/* Defines for RMM PCIe ECAM */
48#define FVP_RMM_ECAM_BASE PCIE_EXP_BASE
49#define FVP_RMM_ECAM_SEGMENT UL(0x0)
50#define FVP_RMM_ECAM_BDF UL(0x0)
51
52/* Defines for RMM SMMUv3 */
53#define FVP_RMM_SMMU_BASE PLAT_FVP_SMMUV3_BASE
54#define FVP_RMM_SMMU_COUNT UL(1)
55
Achin Gupta4f6ad662013-10-25 09:08:21 +010056/*******************************************************************************
Dan Handley60eea552015-03-19 19:17:53 +000057 * arm_config holds the characteristics of the differences between the three FVP
58 * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
Vikram Kanigiri6355f232016-02-15 11:54:14 +000059 * at each boot stage by the primary before enabling the MMU (to allow
60 * interconnect configuration) & used thereafter. Each BL will have its own copy
61 * to allow independent operation.
Achin Gupta4f6ad662013-10-25 09:08:21 +010062 ******************************************************************************/
Dan Handley60eea552015-03-19 19:17:53 +000063arm_config_t arm_config;
Soby Mathewd0ecd972014-09-03 17:48:44 +010064
65#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
66 DEVICE0_SIZE, \
AlexeiFedorovb5772482025-02-13 13:14:34 +000067 MT_DEVICE | MT_RW | EL3_PAS)
Soby Mathewd0ecd972014-09-03 17:48:44 +010068
69#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
70 DEVICE1_SIZE, \
71 MT_DEVICE | MT_RW | MT_SECURE)
72
Manish V Badarkhef98630f2021-01-24 03:26:50 +000073#if FVP_GICR_REGION_PROTECTION
74#define MAP_GICD_MEM MAP_REGION_FLAT(BASE_GICD_BASE, \
75 BASE_GICD_SIZE, \
76 MT_DEVICE | MT_RW | MT_SECURE)
77
78/* Map all core's redistributor memory as read-only. After boots up,
79 * per-core map its redistributor memory as read-write */
80#define MAP_GICR_MEM MAP_REGION_FLAT(BASE_GICR_BASE, \
81 (BASE_GICR_SIZE * PLATFORM_CORE_COUNT),\
82 MT_DEVICE | MT_RO | MT_SECURE)
83#endif /* FVP_GICR_REGION_PROTECTION */
84
Sandrine Bailleux284c3d62017-05-26 15:48:10 +010085/*
86 * Need to be mapped with write permissions in order to set a new non-volatile
87 * counter value.
88 */
Juan Castillo95cfd4a2015-04-14 12:49:03 +010089#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
90 DEVICE2_SIZE, \
Antonio Nino Diazfe7de032016-05-20 14:14:16 +010091 MT_DEVICE | MT_RW | MT_SECURE)
Juan Castillo95cfd4a2015-04-14 12:49:03 +010092
Harrison Mutai94c90ac2023-08-08 15:10:07 +010093#if TRANSFER_LIST
94#ifdef FW_NS_HANDOFF_BASE
Harrison Mutaia5566f62023-12-01 15:50:00 +000095#define MAP_FW_NS_HANDOFF \
96 MAP_REGION_FLAT(FW_NS_HANDOFF_BASE, PLAT_ARM_FW_HANDOFF_SIZE, \
97 MT_MEMORY | MT_RW | MT_NS)
98#endif
99#ifdef PLAT_ARM_EL3_FW_HANDOFF_BASE
100#define MAP_EL3_FW_HANDOFF \
101 MAP_REGION_FLAT(PLAT_ARM_EL3_FW_HANDOFF_BASE, \
102 PLAT_ARM_FW_HANDOFF_SIZE, MT_MEMORY | MT_RW | EL3_PAS)
Harrison Mutai94c90ac2023-08-08 15:10:07 +0100103#endif
104#endif
105
Jon Medhurst38aa76a2014-02-26 16:27:53 +0000106/*
Sandrine Bailleuxb5fa6562016-05-18 16:11:47 +0100107 * Table of memory regions for various BL stages to map using the MMU.
Roberto Vargas0916c382018-10-19 16:44:18 +0100108 * This doesn't include Trusted SRAM as setup_page_tables() already takes care
109 * of mapping it.
Jon Medhurst38aa76a2014-02-26 16:27:53 +0000110 */
Masahiro Yamada3d8256b2016-12-25 23:36:24 +0900111#ifdef IMAGE_BL1
Dan Handley60eea552015-03-19 19:17:53 +0000112const mmap_region_t plat_arm_mmap[] = {
113 ARM_MAP_SHARED_RAM,
Manish V Badarkhe79d8be32021-06-16 16:50:43 +0100114 V2M_MAP_FLASH0_RO,
Dan Handley60eea552015-03-19 19:17:53 +0000115 V2M_MAP_IOFPGA,
Soby Mathewd0ecd972014-09-03 17:48:44 +0100116 MAP_DEVICE0,
Manish V Badarkhee0cea782021-01-23 10:55:12 +0000117#if FVP_INTERCONNECT_DRIVER == FVP_CCN
Soby Mathewd0ecd972014-09-03 17:48:44 +0100118 MAP_DEVICE1,
Manish V Badarkhee0cea782021-01-23 10:55:12 +0000119#endif
Yatharth Kochar436223d2015-10-11 14:14:55 +0100120#if TRUSTED_BOARD_BOOT
Sandrine Bailleux284c3d62017-05-26 15:48:10 +0100121 /* To access the Root of Trust Public Key registers. */
122 MAP_DEVICE2,
123 /* Map DRAM to authenticate NS_BL2U image. */
Yatharth Kochar436223d2015-10-11 14:14:55 +0100124 ARM_MAP_NS_DRAM1,
125#endif
Jon Medhurst38aa76a2014-02-26 16:27:53 +0000126 {0}
127};
Soby Mathewd0ecd972014-09-03 17:48:44 +0100128#endif
Masahiro Yamada3d8256b2016-12-25 23:36:24 +0900129#ifdef IMAGE_BL2
Dan Handley60eea552015-03-19 19:17:53 +0000130const mmap_region_t plat_arm_mmap[] = {
131 ARM_MAP_SHARED_RAM,
Juan Castillo7b4c1402015-10-06 14:01:35 +0100132 V2M_MAP_FLASH0_RW,
Dan Handley60eea552015-03-19 19:17:53 +0000133 V2M_MAP_IOFPGA,
Soby Mathewd0ecd972014-09-03 17:48:44 +0100134 MAP_DEVICE0,
Manish V Badarkhee0cea782021-01-23 10:55:12 +0000135#if FVP_INTERCONNECT_DRIVER == FVP_CCN
Soby Mathewd0ecd972014-09-03 17:48:44 +0100136 MAP_DEVICE1,
Manish V Badarkhee0cea782021-01-23 10:55:12 +0000137#endif
Dan Handley60eea552015-03-19 19:17:53 +0000138 ARM_MAP_NS_DRAM1,
Julius Werner402b3cf2019-07-09 14:02:43 -0700139#ifdef __aarch64__
Roberto Vargasb09ba052017-08-08 11:27:20 +0100140 ARM_MAP_DRAM2,
141#endif
Manish V Badarkhe39f0b862022-03-15 16:05:58 +0000142 /*
143 * Required to load HW_CONFIG, SPMC and SPs to trusted DRAM.
144 */
Achin Gupta64758c92019-10-11 15:15:19 +0100145 ARM_MAP_TRUSTED_DRAM,
Manish V Badarkhe6b2e9612022-12-12 10:14:25 +0000146
147 /*
148 * Required to load Event Log in TZC secured memory
149 */
150#if MEASURED_BOOT && (defined(SPD_tspd) || defined(SPD_opteed) || \
151defined(SPD_spmd))
152 ARM_MAP_EVENT_LOG_DRAM1,
153#endif /* MEASURED_BOOT && (SPD_tspd || SPD_opteed || SPD_spmd) */
154
Zelalem Awekec8720722021-07-12 23:41:05 -0500155#if ENABLE_RME
156 ARM_MAP_RMM_DRAM,
157 ARM_MAP_GPT_L1_DRAM,
158#endif /* ENABLE_RME */
Sandrine Bailleux3eb2d672017-08-30 10:59:22 +0100159#ifdef SPD_tspd
Dan Handley60eea552015-03-19 19:17:53 +0000160 ARM_MAP_TSP_SEC_MEM,
Sandrine Bailleux3eb2d672017-08-30 10:59:22 +0100161#endif
Sandrine Bailleux284c3d62017-05-26 15:48:10 +0100162#if TRUSTED_BOARD_BOOT
163 /* To access the Root of Trust Public Key registers. */
164 MAP_DEVICE2,
John Tsichritzisba597da2018-07-30 13:41:52 +0100165#endif /* TRUSTED_BOARD_BOOT */
Manish V Badarkhe88c51c32022-01-08 23:08:02 +0000166
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600167#if CRYPTO_SUPPORT && !RESET_TO_BL2
Manish V Badarkhe88c51c32022-01-08 23:08:02 +0000168 /*
169 * To access shared the Mbed TLS heap while booting the
170 * system with Crypto support
171 */
172 ARM_MAP_BL1_RW,
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600173#endif /* CRYPTO_SUPPORT && !RESET_TO_BL2 */
Marc Bonnici44639ab2021-11-29 16:59:02 +0000174#if SPM_MM || SPMC_AT_EL3
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000175 ARM_SP_IMAGE_MMAP,
176#endif
David Wang4518dd92016-03-07 11:02:57 +0800177#if ARM_BL31_IN_DRAM
178 ARM_MAP_BL31_SEC_DRAM,
179#endif
Jens Wiklander810d9212017-08-25 10:07:20 +0200180#ifdef SPD_opteed
Soby Mathewb3ba6fd2017-09-01 13:43:50 +0100181 ARM_MAP_OPTEE_CORE_MEM,
Jens Wiklander810d9212017-08-25 10:07:20 +0200182 ARM_OPTEE_PAGEABLE_LOAD_MEM,
183#endif
Harrison Mutaia5566f62023-12-01 15:50:00 +0000184#ifdef MAP_EL3_FW_HANDOFF
185 MAP_EL3_FW_HANDOFF,
186#endif
187 { 0 }
Soby Mathewd0ecd972014-09-03 17:48:44 +0100188};
189#endif
Masahiro Yamada3d8256b2016-12-25 23:36:24 +0900190#ifdef IMAGE_BL2U
Yatharth Kochardcda29f2015-10-14 15:28:11 +0100191const mmap_region_t plat_arm_mmap[] = {
192 MAP_DEVICE0,
193 V2M_MAP_IOFPGA,
194 {0}
195};
196#endif
Masahiro Yamada3d8256b2016-12-25 23:36:24 +0900197#ifdef IMAGE_BL31
Dan Handley60eea552015-03-19 19:17:53 +0000198const mmap_region_t plat_arm_mmap[] = {
199 ARM_MAP_SHARED_RAM,
Ambroise Vincent992f0912019-07-12 13:47:03 +0100200#if USE_DEBUGFS
201 /* Required by devfip, can be removed if devfip is not used */
202 V2M_MAP_FLASH0_RW,
203#endif /* USE_DEBUGFS */
Soby Mathewe35a3fb2017-10-11 16:08:58 +0100204 ARM_MAP_EL3_TZC_DRAM,
Dan Handley60eea552015-03-19 19:17:53 +0000205 V2M_MAP_IOFPGA,
Soby Mathewd0ecd972014-09-03 17:48:44 +0100206 MAP_DEVICE0,
Manish V Badarkhef98630f2021-01-24 03:26:50 +0000207#if FVP_GICR_REGION_PROTECTION
208 MAP_GICD_MEM,
209 MAP_GICR_MEM,
210#else
Soby Mathewd0ecd972014-09-03 17:48:44 +0100211 MAP_DEVICE1,
Manish V Badarkhef98630f2021-01-24 03:26:50 +0000212#endif /* FVP_GICR_REGION_PROTECTION */
Roberto Vargasf1454032017-08-03 09:16:43 +0100213 ARM_V2M_MAP_MEM_PROTECT,
Paul Beesley3f3c3412019-09-16 11:29:03 +0000214#if SPM_MM
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000215 ARM_SPM_BUF_EL3_MMAP,
216#endif
Zelalem Awekec8720722021-07-12 23:41:05 -0500217#if ENABLE_RME
218 ARM_MAP_GPT_L1_DRAM,
Javier Almansa Sobrino8c980a42021-11-24 18:37:37 +0000219 ARM_MAP_EL3_RMM_SHARED_MEM,
Zelalem Awekec8720722021-07-12 23:41:05 -0500220#endif
Harrison Mutai94c90ac2023-08-08 15:10:07 +0100221#ifdef MAP_FW_NS_HANDOFF
222 MAP_FW_NS_HANDOFF,
223#endif
Harrison Mutai1a0ebff2024-05-02 12:40:20 +0000224#if defined(MAP_EL3_FW_HANDOFF) && !RESET_TO_BL31
Harrison Mutaia5566f62023-12-01 15:50:00 +0000225 MAP_EL3_FW_HANDOFF,
226#endif
227 { 0 }
Soby Mathewd0ecd972014-09-03 17:48:44 +0100228};
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000229
Paul Beesley3f3c3412019-09-16 11:29:03 +0000230#if defined(IMAGE_BL31) && SPM_MM
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000231const mmap_region_t plat_arm_secure_partition_mmap[] = {
232 V2M_MAP_IOFPGA_EL0, /* for the UART */
levi.yun9fb76762024-05-16 11:18:20 +0100233 V2M_MAP_SECURE_SYSTEMREG_EL0, /* for initializing flash */
234#if PSA_FWU_SUPPORT
235 V2M_MAP_FLASH0_RW_EL0, /* for firmware update service in standalone mm */
236#endif
237 V2M_MAP_FLASH1_RW_EL0, /* for secure variable service in standalone mm */
Elyes Haouas9a90d722023-02-13 10:05:41 +0100238 MAP_REGION_FLAT(DEVICE0_BASE,
239 DEVICE0_SIZE,
Sandrine Bailleuxc4fa1732018-01-12 15:50:12 +0100240 MT_DEVICE | MT_RO | MT_SECURE | MT_USER),
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000241 ARM_SP_IMAGE_MMAP,
242 ARM_SP_IMAGE_NS_BUF_MMAP,
243 ARM_SP_IMAGE_RW_MMAP,
244 ARM_SPM_BUF_EL0_MMAP,
245 {0}
246};
247#endif
Soby Mathewd0ecd972014-09-03 17:48:44 +0100248#endif
Masahiro Yamada3d8256b2016-12-25 23:36:24 +0900249#ifdef IMAGE_BL32
Dan Handley60eea552015-03-19 19:17:53 +0000250const mmap_region_t plat_arm_mmap[] = {
Julius Werner402b3cf2019-07-09 14:02:43 -0700251#ifndef __aarch64__
Soby Mathew877cf3f2016-07-11 14:13:56 +0100252 ARM_MAP_SHARED_RAM,
Joel Hutton950c6952018-03-15 11:33:44 +0000253 ARM_V2M_MAP_MEM_PROTECT,
Soby Mathew877cf3f2016-07-11 14:13:56 +0100254#endif
Dan Handley60eea552015-03-19 19:17:53 +0000255 V2M_MAP_IOFPGA,
Soby Mathewd0ecd972014-09-03 17:48:44 +0100256 MAP_DEVICE0,
257 MAP_DEVICE1,
258 {0}
259};
260#endif
Jon Medhurst38aa76a2014-02-26 16:27:53 +0000261
Zelalem Aweke9d870b72021-07-11 18:39:39 -0500262#ifdef IMAGE_RMM
263const mmap_region_t plat_arm_mmap[] = {
264 V2M_MAP_IOFPGA,
265 MAP_DEVICE0,
266 MAP_DEVICE1,
267 {0}
268};
269#endif
270
Dan Handley60eea552015-03-19 19:17:53 +0000271ARM_CASSERT_MMAP
Soby Mathewce412502015-01-22 11:22:22 +0000272
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100273#if FVP_INTERCONNECT_DRIVER != FVP_CCN
274static const int fvp_cci400_map[] = {
275 PLAT_FVP_CCI400_CLUS0_SL_PORT,
276 PLAT_FVP_CCI400_CLUS1_SL_PORT,
277};
278
279static const int fvp_cci5xx_map[] = {
280 PLAT_FVP_CCI5XX_CLUS0_SL_PORT,
281 PLAT_FVP_CCI5XX_CLUS1_SL_PORT,
282};
283
284static unsigned int get_interconnect_master(void)
285{
286 unsigned int master;
287 u_register_t mpidr;
288
289 mpidr = read_mpidr_el1();
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000290 master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100291 MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
292
293 assert(master < FVP_CLUSTER_COUNT);
294 return master;
295}
296#endif
Dan Handley60eea552015-03-19 19:17:53 +0000297
Paul Beesley3f3c3412019-09-16 11:29:03 +0000298#if defined(IMAGE_BL31) && SPM_MM
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000299/*
300 * Boot information passed to a secure partition during initialisation. Linear
301 * indices in MP information will be filled at runtime.
302 */
Paul Beesleyaeaa2252019-10-15 10:57:42 +0000303static spm_mm_mp_info_t sp_mp_info[] = {
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000304 [0] = {0x80000000, 0},
305 [1] = {0x80000001, 0},
306 [2] = {0x80000002, 0},
307 [3] = {0x80000003, 0},
308 [4] = {0x80000100, 0},
309 [5] = {0x80000101, 0},
310 [6] = {0x80000102, 0},
311 [7] = {0x80000103, 0},
312};
313
Paul Beesleyaeaa2252019-10-15 10:57:42 +0000314const spm_mm_boot_info_t plat_arm_secure_partition_boot_info = {
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000315 .h.type = PARAM_SP_IMAGE_BOOT_INFO,
316 .h.version = VERSION_1,
Paul Beesleyaeaa2252019-10-15 10:57:42 +0000317 .h.size = sizeof(spm_mm_boot_info_t),
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000318 .h.attr = 0,
319 .sp_mem_base = ARM_SP_IMAGE_BASE,
320 .sp_mem_limit = ARM_SP_IMAGE_LIMIT,
321 .sp_image_base = ARM_SP_IMAGE_BASE,
322 .sp_stack_base = PLAT_SP_IMAGE_STACK_BASE,
323 .sp_heap_base = ARM_SP_IMAGE_HEAP_BASE,
Ard Biesheuvel0560efb2018-12-29 19:43:21 +0100324 .sp_ns_comm_buf_base = PLAT_SP_IMAGE_NS_BUF_BASE,
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000325 .sp_shared_buf_base = PLAT_SPM_BUF_BASE,
326 .sp_image_size = ARM_SP_IMAGE_SIZE,
327 .sp_pcpu_stack_size = PLAT_SP_IMAGE_STACK_PCPU_SIZE,
328 .sp_heap_size = ARM_SP_IMAGE_HEAP_SIZE,
Ard Biesheuvel0560efb2018-12-29 19:43:21 +0100329 .sp_ns_comm_buf_size = PLAT_SP_IMAGE_NS_BUF_SIZE,
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000330 .sp_shared_buf_size = PLAT_SPM_BUF_SIZE,
331 .num_sp_mem_regions = ARM_SP_IMAGE_NUM_MEM_REGIONS,
332 .num_cpus = PLATFORM_CORE_COUNT,
333 .mp_info = &sp_mp_info[0],
334};
335
336const struct mmap_region *plat_get_secure_partition_mmap(void *cookie)
337{
338 return plat_arm_secure_partition_mmap;
339}
340
Paul Beesleyaeaa2252019-10-15 10:57:42 +0000341const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000342 void *cookie)
343{
344 return &plat_arm_secure_partition_boot_info;
345}
Antonio Nino Diaze29efeb2017-11-09 11:34:09 +0000346#endif
347
Achin Gupta4f6ad662013-10-25 09:08:21 +0100348/*******************************************************************************
349 * A single boot loader stack is expected to work on both the Foundation FVP
350 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
351 * SYS_ID register provides a mechanism for detecting the differences between
352 * these platforms. This information is stored in a per-BL array to allow the
353 * code to take the correct path.Per BL platform configuration.
354 ******************************************************************************/
Daniel Boulby4d010d02018-09-18 13:26:03 +0100355void __init fvp_config_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100356{
Soby Mathewadd40352014-08-14 12:49:05 +0100357 unsigned int rev, hbi, bld, arch, sys_id;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100358
Dan Handley60eea552015-03-19 19:17:53 +0000359 sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
360 rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
361 hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
362 bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
363 arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100364
Andrew Thoelke90e31472014-06-26 14:27:26 +0100365 if (arch != ARCH_MODEL) {
366 ERROR("This firmware is for FVP models\n");
James Morrissey40a6f642014-02-10 14:24:36 +0000367 panic();
Andrew Thoelke90e31472014-06-26 14:27:26 +0100368 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100369
370 /*
371 * The build field in the SYS_ID tells which variant of the GIC
372 * memory is implemented by the model.
373 */
374 switch (bld) {
375 case BLD_GIC_VE_MMAP:
Soby Mathew21a39732016-01-13 17:06:00 +0000376 ERROR("Legacy Versatile Express memory map for GIC peripheral"
377 " is not supported\n");
Achin Gupta27573c52015-11-03 14:18:34 +0000378 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100379 break;
380 case BLD_GIC_A53A57_MMAP:
Achin Gupta4f6ad662013-10-25 09:08:21 +0100381 break;
382 default:
Andrew Thoelke90e31472014-06-26 14:27:26 +0100383 ERROR("Unsupported board build %x\n", bld);
384 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100385 }
386
387 /*
388 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
389 * for the Foundation FVP.
390 */
391 switch (hbi) {
Dan Handley60eea552015-03-19 19:17:53 +0000392 case HBI_FOUNDATION_FVP:
Dan Handley60eea552015-03-19 19:17:53 +0000393 arm_config.flags = 0;
Andrew Thoelke90e31472014-06-26 14:27:26 +0100394
395 /*
396 * Check for supported revisions of Foundation FVP
397 * Allow future revisions to run but emit warning diagnostic
398 */
399 switch (rev) {
Dan Handley60eea552015-03-19 19:17:53 +0000400 case REV_FOUNDATION_FVP_V2_0:
401 case REV_FOUNDATION_FVP_V2_1:
402 case REV_FOUNDATION_FVP_v9_1:
Sandrine Bailleux4faa4a12016-09-22 09:46:50 +0100403 case REV_FOUNDATION_FVP_v9_6:
Andrew Thoelke90e31472014-06-26 14:27:26 +0100404 break;
405 default:
406 WARN("Unrecognized Foundation FVP revision %x\n", rev);
407 break;
408 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100409 break;
Dan Handley60eea552015-03-19 19:17:53 +0000410 case HBI_BASE_FVP:
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100411 arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
Andrew Thoelke90e31472014-06-26 14:27:26 +0100412
413 /*
414 * Check for supported revisions
415 * Allow future revisions to run but emit warning diagnostic
416 */
417 switch (rev) {
Dan Handley60eea552015-03-19 19:17:53 +0000418 case REV_BASE_FVP_V0:
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100419 arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
420 break;
421 case REV_BASE_FVP_REVC:
Isla Mitchell84316352017-08-17 12:25:34 +0100422 arm_config.flags |= (ARM_CONFIG_FVP_HAS_SMMUV3 |
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100423 ARM_CONFIG_FVP_HAS_CCI5XX);
Andrew Thoelke90e31472014-06-26 14:27:26 +0100424 break;
425 default:
426 WARN("Unrecognized Base FVP revision %x\n", rev);
427 break;
428 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100429 break;
430 default:
Andrew Thoelke90e31472014-06-26 14:27:26 +0100431 ERROR("Unsupported board HBI number 0x%x\n", hbi);
432 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100433 }
Isla Mitchell84316352017-08-17 12:25:34 +0100434
435 /*
436 * We assume that the presence of MT bit, and therefore shifted
437 * affinities, is uniform across the platform: either all CPUs, or no
438 * CPUs implement it.
439 */
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000440 if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U)
Isla Mitchell84316352017-08-17 12:25:34 +0100441 arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100442}
443
Vikram Kanigiri4991ecd2015-02-26 15:25:58 +0000444
Daniel Boulby4d010d02018-09-18 13:26:03 +0100445void __init fvp_interconnect_init(void)
Vikram Kanigiridbad1ba2014-04-24 11:02:16 +0100446{
Soby Mathew71237872016-03-24 10:12:42 +0000447#if FVP_INTERCONNECT_DRIVER == FVP_CCN
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100448 if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000449 ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100450 panic();
Soby Mathew71237872016-03-24 10:12:42 +0000451 }
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100452
453 plat_arm_interconnect_init();
454#else
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000455 uintptr_t cci_base = 0U;
456 const int *cci_map = NULL;
457 unsigned int map_size = 0U;
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100458
459 /* Initialize the right interconnect */
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000460 if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100461 cci_base = PLAT_FVP_CCI5XX_BASE;
462 cci_map = fvp_cci5xx_map;
463 map_size = ARRAY_SIZE(fvp_cci5xx_map);
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000464 } else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100465 cci_base = PLAT_FVP_CCI400_BASE;
466 cci_map = fvp_cci400_map;
467 map_size = ARRAY_SIZE(fvp_cci400_map);
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000468 } else {
469 return;
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100470 }
471
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000472 assert(cci_base != 0U);
473 assert(cci_map != NULL);
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100474 cci_init(cci_base, cci_map, map_size);
475#endif
Dan Handleycae3ef92014-08-04 16:11:15 +0100476}
477
Vikram Kanigiri6355f232016-02-15 11:54:14 +0000478void fvp_interconnect_enable(void)
Dan Handleycae3ef92014-08-04 16:11:15 +0100479{
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100480#if FVP_INTERCONNECT_DRIVER == FVP_CCN
481 plat_arm_interconnect_enter_coherency();
482#else
483 unsigned int master;
484
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000485 if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
486 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100487 master = get_interconnect_master();
488 cci_enable_snoop_dvm_reqs(master);
489 }
490#endif
Vikram Kanigiri4991ecd2015-02-26 15:25:58 +0000491}
492
Vikram Kanigiri6355f232016-02-15 11:54:14 +0000493void fvp_interconnect_disable(void)
Vikram Kanigiri4991ecd2015-02-26 15:25:58 +0000494{
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100495#if FVP_INTERCONNECT_DRIVER == FVP_CCN
496 plat_arm_interconnect_exit_coherency();
497#else
498 unsigned int master;
499
Antonio Nino Diaz583e0792018-11-06 13:14:21 +0000500 if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
501 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
Jeenu Viswambharan955242d2017-07-18 15:42:50 +0100502 master = get_interconnect_master();
503 cci_disable_snoop_dvm_reqs(master);
504 }
505#endif
Vikram Kanigiridbad1ba2014-04-24 11:02:16 +0100506}
John Tsichritzisba597da2018-07-30 13:41:52 +0100507
Manish V Badarkhe88c51c32022-01-08 23:08:02 +0000508#if CRYPTO_SUPPORT
John Tsichritzisba597da2018-07-30 13:41:52 +0100509int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
510{
511 assert(heap_addr != NULL);
512 assert(heap_size != NULL);
513
514 return arm_get_mbedtls_heap(heap_addr, heap_size);
515}
Manish V Badarkhe88c51c32022-01-08 23:08:02 +0000516#endif /* CRYPTO_SUPPORT */
Alexei Fedorov1b597c22019-08-16 14:15:59 +0100517
518void fvp_timer_init(void)
519{
Madhukar Pappireddyfddfb3b2020-08-12 13:18:19 -0500520#if USE_SP804_TIMER
Alexei Fedorov1b597c22019-08-16 14:15:59 +0100521 /* Enable the clock override for SP804 timer 0, which means that no
522 * clock dividers are applied and the raw (35MHz) clock will be used.
523 */
524 mmio_write_32(V2M_SP810_BASE, FVP_SP810_CTRL_TIM0_OV);
525
526 /* Initialize delay timer driver using SP804 dual timer 0 */
527 sp804_timer_init(V2M_SP804_TIMER0_BASE,
528 SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
529#else
530 generic_delay_timer_init();
531
532 /* Enable System level generic timer */
533 mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
534 CNTCR_FCREQ(0U) | CNTCR_EN);
Madhukar Pappireddyfddfb3b2020-08-12 13:18:19 -0500535#endif /* USE_SP804_TIMER */
Alexei Fedorov1b597c22019-08-16 14:15:59 +0100536}
Manish V Badarkheed9653f2020-08-04 17:09:10 +0100537
538/*****************************************************************************
539 * plat_is_smccc_feature_available() - This function checks whether SMCCC
540 * feature is availabile for platform.
541 * @fid: SMCCC function id
542 *
543 * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
544 * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
545 *****************************************************************************/
546int32_t plat_is_smccc_feature_available(u_register_t fid)
547{
548 switch (fid) {
549 case SMCCC_ARCH_SOC_ID:
550 return SMC_ARCH_CALL_SUCCESS;
551 default:
552 return SMC_ARCH_CALL_NOT_SUPPORTED;
553 }
554}
555
556/* Get SOC version */
557int32_t plat_get_soc_version(void)
558{
559 return (int32_t)
Yann Gautierdfff4682021-05-20 14:57:34 +0200560 (SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
561 ARM_SOC_IDENTIFICATION_CODE) |
562 (FVP_SOC_ID & SOC_ID_IMPL_DEF_MASK));
Manish V Badarkheed9653f2020-08-04 17:09:10 +0100563}
564
565/* Get SOC revision */
566int32_t plat_get_soc_revision(void)
567{
568 unsigned int sys_id;
569
570 sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
Yann Gautierdfff4682021-05-20 14:57:34 +0200571 return (int32_t)(((sys_id >> V2M_SYS_ID_REV_SHIFT) &
572 V2M_SYS_ID_REV_MASK) & SOC_ID_REV_MASK);
Manish V Badarkheed9653f2020-08-04 17:09:10 +0100573}
Javier Almansa Sobrino8c980a42021-11-24 18:37:37 +0000574
575#if ENABLE_RME
AlexeiFedorov90552c62025-01-30 14:56:47 +0000576
577/* BDF mappings for RP0 RC0 */
578const struct bdf_mapping_info rc0rp0_bdf_data[] = {
579 /* BDF0 */
580 {0U, /* mapping_base */
581 0x8000U, /* mapping_top */
582 0U, /* mapping_off */
583 0U /* smmu_idx */
584 }
585};
586
587/* Root ports for RC0 */
588const struct root_port_info rc0rp_data[] = {
589 /* RP0 */
590 {0U, /* root_port_id */
591 0U, /* padding */
592 ARRAY_SIZE(rc0rp0_bdf_data), /* num_bdf_mappings */
593 (struct bdf_mapping_info *)rc0rp0_bdf_data /* bdf_mappings */
594 }
595};
596
597/* Root complexes */
598const struct root_complex_info rc_data[] = {
599 /* RC0 */
600 {PCIE_EXP_BASE, /* ecam_base */
601 0U, /* segment */
602 {0U, 0U, 0U}, /* padding */
603 ARRAY_SIZE(rc0rp_data), /* num_root_ports */
604 (struct root_port_info *)rc0rp_data /* root_ports */
605 }
606};
607
608/* Number of PCIe Root Complexes */
609#define FVP_RMM_RC_COUNT ARRAY_SIZE(rc_data)
610
Javier Almansa Sobrino8c980a42021-11-24 18:37:37 +0000611/*
612 * Get a pointer to the RMM-EL3 Shared buffer and return it
613 * through the pointer passed as parameter.
614 *
615 * This function returns the size of the shared buffer.
616 */
617size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
618{
619 *shared = (uintptr_t)RMM_SHARED_BASE;
620
621 return (size_t)RMM_SHARED_SIZE;
622}
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +0100623
AlexeiFedorovaa998812024-11-15 13:10:34 +0000624/*
625 * Calculate checksum of 64-bit words @buffer with @size length
626 */
627static uint64_t checksum_calc(uint64_t *buffer, size_t size)
628{
629 uint64_t sum = 0UL;
630
631 assert(((uintptr_t)buffer & (sizeof(uint64_t) - 1UL)) == 0UL);
632 assert((size & (sizeof(uint64_t) - 1UL)) == 0UL);
633
634 for (unsigned long i = 0UL; i < (size / sizeof(uint64_t)); i++) {
635 sum += buffer[i];
636 }
637
638 return sum;
639}
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100640/*
AlexeiFedorov90552c62025-01-30 14:56:47 +0000641 * Boot Manifest v0.5 structure illustration, with two DRAM banks,
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100642 * a single console and one device memory with two PCIe device
643 * non-coherent address ranges.
644 *
645 * +--------------------------------------------------+
646 * | offset | field | comment |
647 * +--------+--------------------+--------------------+
AlexeiFedorov90552c62025-01-30 14:56:47 +0000648 * | 0 | version | 0x00000005 |
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100649 * +--------+--------------------+--------------------+
650 * | 4 | padding | 0x00000000 |
651 * +--------+--------------------+--------------------+
652 * | 8 | plat_data | NULL |
653 * +--------+--------------------+--------------------+
654 * | 16 | num_banks | |
655 * +--------+--------------------+ |
656 * | 24 | banks | plat_dram +--+
657 * +--------+--------------------+ | |
658 * | 32 | checksum | | |
659 * +--------+--------------------+--------------------+ |
660 * | 40 | num_consoles | | |
661 * +--------+--------------------+ | |
662 * | 48 | consoles | plat_console +--|--+
663 * +--------+--------------------+ | | |
664 * | 56 | checksum | | | |
665 * +--------+--------------------+--------------------+ | |
666 * | 64 | num_banks | | | |
667 * +--------+--------------------+ | | |
668 * | 72 | banks | plat_ncoh_region +--|--|--+
669 * +--------+--------------------+ | | | |
670 * | 80 | checksum | | | | |
671 * +--------+--------------------+--------------------+ | | |
672 * | 88 | num_banks | | | | |
673 * +--------+--------------------+ | | | |
674 * | 96 | banks | plat_coh_region | | | |
675 * +--------+--------------------+ | | | |
676 * | 104 | checksum | | | | |
AlexeiFedorov90552c62025-01-30 14:56:47 +0000677 * +--------+--------------------+--------------------+ | | |
678 * | 112 | num_smmus | | | | |
679 * +--------+--------------------+ | | | |
680 * | 120 | smmus | plat_smmu +--|--|--|--+
681 * +--------+--------------------+ | | | | |
682 * | 128 | checksum | | | | | |
683 * +--------+--------------------+--------------------+ | | | |
684 * | 136 | num_root_complex | | | | | |
685 * +--------+--------------------+ | | | | |
686 * | 144 | rc_info_version | | | | | |
687 * +--------+--------------------+ | | | | |
688 * | 148 | padding | plat_root_complex +--|--|--|--|--+
689 * +--------+--------------------+ | | | | | |
690 * | 152 | root_complex | | | | | | |
691 * +--------+--------------------+ | | | | | |
692 * | 160 | checksum | | | | | | |
693 * +--------+--------------------+--------------------+<-+ | | | |
694 * | 168 | base 0 | | | | | |
695 * +--------+--------------------+ mem_bank[0] | | | | |
696 * | 176 | size 0 | | | | | |
697 * +--------+--------------------+--------------------+ | | | |
698 * | 184 | base 1 | | | | | |
699 * +--------+--------------------+ mem_bank[1] | | | | |
700 * | 192 | size 1 | | | | | |
701 * +--------+--------------------+--------------------+<----+ | | |
702 * | 200 | base | | | | |
703 * +--------+--------------------+ | | | |
704 * | 208 | map_pages | | | | |
705 * +--------+--------------------+ | | | |
706 * | 216 | name | | | | |
707 * +--------+--------------------+ consoles[0] | | | |
708 * | 224 | clk_in_hz | | | | |
709 * +--------+--------------------+ | | | |
710 * | 232 | baud_rate | | | | |
711 * +--------+--------------------+ | | | |
712 * | 240 | flags | | | | |
713 * +--------+--------------------+--------------------+<-------+ | |
714 * | 248 | base 0 | | | |
715 * +--------+--------------------+ ncoh_region[0] | | |
716 * | 256 | size 0 | | | |
717 * +--------+--------------------+--------------------+ | |
718 * | 264 | base 1 | | | |
719 * +--------+--------------------+ ncoh_region[1] | | |
720 * | 272 | size 1 | | | |
721 * +--------+--------------------+--------------------+<----------+ |
722 * | 280 | smmu_base | | |
723 * +--------+--------------------+ smmus[0] | |
724 * | 288 | smmu_r_base | | |
725 * +--------+--------------------+--------------------+<-------------+
726 * | 296 | ecam_base | |
727 * +--------+--------------------+ |
728 * | 304 | segment | |
729 * +--------+--------------------+ |
730 * | 305 | padding | root_complex[0] +--+
731 * +--------+--------------------+ | |
732 * | 308 | num_root_ports | | |
733 * +--------+--------------------+ | |
734 * | 312 | root_ports | | |
735 * +--------+--------------------+--------------------+<-+
736 * | 320 | root_port_id | |
737 * +--------+--------------------+ |
738 * | 322 | padding | |
739 * +--------+--------------------+ root_ports[0] +--+
740 * | 324 | num_bdf_mappings | | |
741 * +--------+--------------------+ | |
742 * | 328 | bdf_mappings | | |
743 * +--------+--------------------+--------------------+<-+
744 * | 336 | mapping_base | |
745 * +--------+--------------------+ |
746 * | 338 | mapping_top | |
747 * +--------+--------------------+ bdf_mappings[0] |
748 * | 340 | mapping_off | |
749 * +--------+--------------------+ |
750 * | 342 | smmu_idx | |
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100751 * +--------+--------------------+--------------------+
752 */
AlexeiFedorova97bfa52022-12-14 17:28:11 +0000753int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +0100754{
Soby Mathew32904472024-03-26 17:16:00 +0000755 uint64_t checksum, num_banks, num_consoles;
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100756 uint64_t num_ncoh_regions, num_coh_regions;
AlexeiFedorov90552c62025-01-30 14:56:47 +0000757 uint64_t num_smmus, num_root_complex;
758 unsigned int num_root_ports, num_bdf_mappings;
759 uint32_t o_realm;
760 struct memory_bank *bank_ptr, *ncoh_region_ptr, *coh_region_ptr;
Soby Mathew32904472024-03-26 17:16:00 +0000761 struct console_info *console_ptr;
AlexeiFedorov90552c62025-01-30 14:56:47 +0000762 struct smmu_info *smmu_ptr;
763 struct root_complex_info *root_complex_ptr, *rc_ptr;
764 struct root_port_info *root_port_ptr, *rp_ptr;
765 struct bdf_mapping_info *bdf_mapping_ptr, *bdf_ptr;
AlexeiFedorova97bfa52022-12-14 17:28:11 +0000766
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +0100767 assert(manifest != NULL);
768
AlexeiFedorov82685902022-12-29 15:57:40 +0000769 /* Get number of DRAM banks */
770 num_banks = FCONF_GET_PROPERTY(hw_config, dram_layout, num_banks);
771 assert(num_banks <= ARM_DRAM_NUM_BANKS);
772
Soby Mathew32904472024-03-26 17:16:00 +0000773 /* Set number of consoles */
774 num_consoles = FVP_RMM_CONSOLE_COUNT;
775
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100776 /* Set number of device non-coherent address ranges based on DT */
777 num_ncoh_regions = FCONF_GET_PROPERTY(hw_config, pci_props, num_ncoh_regions);
778
AlexeiFedorov90552c62025-01-30 14:56:47 +0000779 /* Set number of SMMUs */
780 num_smmus = FVP_RMM_SMMU_COUNT;
781
782 /* Set number of PCIe root complexes */
783 num_root_complex = FVP_RMM_RC_COUNT;
784
785 /* Calculate and set number of all PCIe root ports and BDF mappings */
786 num_root_ports = 0U;
787 num_bdf_mappings = 0U;
788
789 /* Scan all root complex entries */
790 for (unsigned long i = 0UL; i < num_root_complex; i++) {
791 num_root_ports += rc_data[i].num_root_ports;
792
793 /* Scan all root ports entries in root complex */
794 for (unsigned int j = 0U; j < rc_data[i].num_root_ports; j++) {
795 num_bdf_mappings += rc_data[i].root_ports[j].num_bdf_mappings;
796 }
797 }
798
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +0100799 manifest->version = RMMD_MANIFEST_VERSION;
Javier Almansa Sobrinodc0ca642022-12-01 17:20:45 +0000800 manifest->padding = 0U; /* RES0 */
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100801 manifest->plat_data = 0UL;
AlexeiFedorov82685902022-12-29 15:57:40 +0000802 manifest->plat_dram.num_banks = num_banks;
Soby Mathew32904472024-03-26 17:16:00 +0000803 manifest->plat_console.num_consoles = num_consoles;
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100804 manifest->plat_ncoh_region.num_banks = num_ncoh_regions;
AlexeiFedorov90552c62025-01-30 14:56:47 +0000805 manifest->plat_smmu.num_smmus = num_smmus;
806 manifest->plat_root_complex.num_root_complex = num_root_complex;
807 manifest->plat_root_complex.rc_info_version = PCIE_RC_INFO_VERSION;
808 manifest->plat_root_complex.padding = 0U; /* RES0 */
AlexeiFedorova97bfa52022-12-14 17:28:11 +0000809
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100810 /* FVP does not support device coherent address ranges */
811 num_coh_regions = 0UL;
812 manifest->plat_coh_region.num_banks = num_coh_regions;
813 manifest->plat_coh_region.banks = NULL;
814 manifest->plat_coh_region.checksum = 0UL;
Soby Mathew32904472024-03-26 17:16:00 +0000815
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100816 bank_ptr = (struct memory_bank *)
817 (((uintptr_t)manifest) + sizeof(struct rmm_manifest));
Soby Mathew32904472024-03-26 17:16:00 +0000818 console_ptr = (struct console_info *)
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100819 ((uintptr_t)bank_ptr + (num_banks *
820 sizeof(struct memory_bank)));
821 ncoh_region_ptr = (struct memory_bank *)
822 ((uintptr_t)console_ptr + (num_consoles *
823 sizeof(struct console_info)));
AlexeiFedorov90552c62025-01-30 14:56:47 +0000824 coh_region_ptr = (struct memory_bank *)
825 ((uintptr_t)ncoh_region_ptr + (num_ncoh_regions *
826 sizeof(struct memory_bank)));
827 smmu_ptr = (struct smmu_info *)
828 ((uintptr_t)coh_region_ptr + (num_coh_regions *
829 sizeof(struct memory_bank)));
830 root_complex_ptr = (struct root_complex_info *)
831 ((uintptr_t)smmu_ptr + (num_smmus *
832 sizeof(struct smmu_info)));
833 root_port_ptr = (struct root_port_info *)
834 ((uintptr_t)root_complex_ptr + (num_root_complex *
835 sizeof(struct root_complex_info)));
836 bdf_mapping_ptr = (struct bdf_mapping_info *)
837 ((uintptr_t)root_port_ptr + (num_root_ports *
838 sizeof(struct root_port_info)));
839
AlexeiFedorov82685902022-12-29 15:57:40 +0000840 manifest->plat_dram.banks = bank_ptr;
Soby Mathew32904472024-03-26 17:16:00 +0000841 manifest->plat_console.consoles = console_ptr;
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100842 manifest->plat_ncoh_region.banks = ncoh_region_ptr;
AlexeiFedorov90552c62025-01-30 14:56:47 +0000843 manifest->plat_smmu.smmus = smmu_ptr;
844 manifest->plat_root_complex.root_complex = root_complex_ptr;
Soby Mathew32904472024-03-26 17:16:00 +0000845
846 /* Ensure the manifest is not larger than the shared buffer */
847 assert((sizeof(struct rmm_manifest) +
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100848 (sizeof(struct memory_bank) *
849 manifest->plat_dram.num_banks) +
850 (sizeof(struct console_info) *
851 manifest->plat_console.num_consoles) +
852 (sizeof(struct memory_bank) *
853 manifest->plat_ncoh_region.num_banks) +
854 (sizeof(struct memory_bank) *
AlexeiFedorov90552c62025-01-30 14:56:47 +0000855 manifest->plat_coh_region.num_banks) +
856 (sizeof(struct smmu_info) *
857 manifest->plat_smmu.num_smmus) +
858 (sizeof(struct root_complex_info) *
859 manifest->plat_root_complex.num_root_complex) +
860 (sizeof(struct root_port_info) * num_root_ports) +
861 (sizeof(struct bdf_mapping_info) * num_bdf_mappings))
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100862 <= ARM_EL3_RMM_SHARED_SIZE);
AlexeiFedorova97bfa52022-12-14 17:28:11 +0000863
AlexeiFedorov82685902022-12-29 15:57:40 +0000864 /* Calculate checksum of plat_dram structure */
865 checksum = num_banks + (uint64_t)bank_ptr;
AlexeiFedorova97bfa52022-12-14 17:28:11 +0000866
AlexeiFedorov82685902022-12-29 15:57:40 +0000867 /* Store FVP DRAM banks data in Boot Manifest */
868 for (unsigned long i = 0UL; i < num_banks; i++) {
AlexeiFedorovaa998812024-11-15 13:10:34 +0000869 bank_ptr[i].base = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].base);
870 bank_ptr[i].size = FCONF_GET_PROPERTY(hw_config, dram_layout, dram_bank[i].size);
AlexeiFedorova97bfa52022-12-14 17:28:11 +0000871 }
872
AlexeiFedorovaa998812024-11-15 13:10:34 +0000873 /* Update checksum */
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100874 checksum += checksum_calc((uint64_t *)bank_ptr, sizeof(struct memory_bank) * num_banks);
AlexeiFedorovaa998812024-11-15 13:10:34 +0000875
AlexeiFedorov82685902022-12-29 15:57:40 +0000876 /* Checksum must be 0 */
877 manifest->plat_dram.checksum = ~checksum + 1UL;
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +0100878
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100879 /* Calculate the checksum of plat_consoles structure */
Soby Mathew32904472024-03-26 17:16:00 +0000880 checksum = num_consoles + (uint64_t)console_ptr;
881
882 /* Zero out the console info struct */
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100883 (void)memset((void *)console_ptr, '\0',
884 sizeof(struct console_info) * num_consoles);
Soby Mathew32904472024-03-26 17:16:00 +0000885
Soby Mathew32904472024-03-26 17:16:00 +0000886 console_ptr[0].base = FVP_RMM_CONSOLE_BASE;
AlexeiFedorovaa998812024-11-15 13:10:34 +0000887 console_ptr[0].map_pages = 1UL;
Soby Mathew32904472024-03-26 17:16:00 +0000888 console_ptr[0].clk_in_hz = FVP_RMM_CONSOLE_CLK_IN_HZ;
889 console_ptr[0].baud_rate = FVP_RMM_CONSOLE_BAUD;
890
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100891 (void)strlcpy(console_ptr[0].name, FVP_RMM_CONSOLE_NAME,
892 RMM_CONSOLE_MAX_NAME_LEN - 1UL);
Soby Mathew32904472024-03-26 17:16:00 +0000893
894 /* Update checksum */
AlexeiFedorovaa998812024-11-15 13:10:34 +0000895 checksum += checksum_calc((uint64_t *)console_ptr,
896 sizeof(struct console_info) * num_consoles);
Soby Mathew32904472024-03-26 17:16:00 +0000897 /* Checksum must be 0 */
898 manifest->plat_console.checksum = ~checksum + 1UL;
899
AlexeiFedorovbef44f62024-10-14 15:23:34 +0100900 /*
901 * Calculate the checksum of device non-coherent address ranges
902 * info structure
903 */
904 checksum = num_ncoh_regions + (uint64_t)ncoh_region_ptr;
905
906 /* Zero out the PCIe region info struct */
907 (void)memset((void *)ncoh_region_ptr, 0,
908 sizeof(struct memory_bank) * num_ncoh_regions);
909
910 for (unsigned long i = 0UL; i < num_ncoh_regions; i++) {
911 ncoh_region_ptr[i].base =
912 FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].base);
913 ncoh_region_ptr[i].size =
914 FCONF_GET_PROPERTY(hw_config, pci_props, ncoh_regions[i].size);
915 }
916
917 /* Update checksum */
918 checksum += checksum_calc((uint64_t *)ncoh_region_ptr,
919 sizeof(struct memory_bank) * num_ncoh_regions);
920
921 /* Checksum must be 0 */
922 manifest->plat_ncoh_region.checksum = ~checksum + 1UL;
923
AlexeiFedorov90552c62025-01-30 14:56:47 +0000924 /* Calculate the checksum of the plat_smmu structure */
925 checksum = num_smmus + (uint64_t)smmu_ptr;
926
927 smmu_ptr[0].smmu_base = FVP_RMM_SMMU_BASE;
928
929 /* Read SMMU_ROOT_IDR0.BA_REALM[31:22] register field */
930 o_realm = mmio_read_32(FVP_RMM_SMMU_BASE + SMMU_ROOT_IDR0) &
931 SMMU_ROOT_IDR0_BA_REALM_MASK;
932 /*
933 * Calculate the base address offset of Realm Register Page 0.
934 * O_REALM = 0x20000 + (BA_REALM * 0x10000)
935 * SMMU_REALM_BASE = SMMU_PAGE_0_BASE + O_REALM
936 */
937 o_realm = 0x20000 + (o_realm >> (SMMU_ROOT_IDR0_BA_REALM_SHIFT - 16U));
938
939 smmu_ptr[0].smmu_r_base = FVP_RMM_SMMU_BASE + o_realm;
940
941 /* Update checksum */
942 checksum += checksum_calc((uint64_t *)smmu_ptr,
943 sizeof(struct smmu_info) * num_smmus);
944 /* Checksum must be 0 */
945 manifest->plat_smmu.checksum = ~checksum + 1UL;
946
947 /* Calculate the checksum of the plat_root_complex structure */
948 checksum = num_root_complex + (uint64_t)root_complex_ptr;
949
950 /* Zero out PCIe root complex info structures */
951 (void)memset((void *)root_complex_ptr, 0,
952 sizeof(struct root_complex_info) * num_root_complex);
953
954 /* Set pointers for data in manifest */
955 rc_ptr = root_complex_ptr;
956 rp_ptr = root_port_ptr;
957 bdf_ptr = bdf_mapping_ptr;
958
959 /* Fill PCIe root complex info structures */
960 for (unsigned long i = 0U; i < num_root_complex; i++) {
961 const struct root_complex_info *rc_info = &rc_data[i];
962 const struct root_port_info *rp_info = rc_info->root_ports;
963
964 /* Copy root complex data, except root_ports pointer */
965 (void)memcpy((void *)rc_ptr, (void *)rc_info,
966 sizeof(struct root_complex_info) - sizeof(struct root_port_info *));
967
968 /* Set root_ports for root complex */
969 rc_ptr->root_ports = rp_ptr;
970
971 /* Scan root ports */
972 for (unsigned int j = 0U; j < rc_ptr->num_root_ports; j++) {
973 const struct bdf_mapping_info *bdf_info = rp_info->bdf_mappings;
974
975 /* Copy root port data, except bdf_mappings pointer */
976 (void)memcpy((void *)rp_ptr, (void *)rp_info,
977 sizeof(struct root_port_info) - sizeof(struct bdf_mapping_info *));
978
979 /* Set bdf_mappings for root port */
980 rp_ptr->bdf_mappings = bdf_ptr;
981
982 /* Copy all BDF mappings for root port */
983 (void)memcpy((void *)bdf_ptr, (void *)bdf_info,
984 sizeof(struct bdf_mapping_info) * rp_ptr->num_bdf_mappings);
985
986 bdf_ptr += rp_ptr->num_bdf_mappings;
987 rp_ptr++;
988 rp_info++;
989 }
990 rc_ptr++;
991 }
992
993 /* Check that all data are written in manifest */
994 assert(rc_ptr == (root_complex_ptr + num_root_complex));
995 assert(rp_ptr == (root_port_ptr + num_root_ports));
996 assert(bdf_ptr == (bdf_mapping_ptr + num_bdf_mappings));
997
998 /* Update checksum for all PCIe data */
999 checksum += checksum_calc((uint64_t *)root_complex_ptr,
1000 (uintptr_t)bdf_ptr - (uintptr_t)root_complex_ptr);
1001
1002 /* Checksum must be 0 */
1003 manifest->plat_root_complex.checksum = ~checksum + 1UL;
1004
Javier Almansa Sobrino1d0ca402022-04-25 17:18:15 +01001005 return 0;
1006}
Tushar Khandelwalf801fdc2024-04-22 15:35:40 +01001007
1008/*
1009 * Update encryption key associated with @mecid.
1010 */
1011int plat_rmmd_mecid_key_update(uint16_t mecid)
1012{
1013 /*
1014 * FVP does not provide an interface to change the encryption key associated
1015 * with MECID. Hence always return success.
1016 */
1017 return 0;
1018}
AlexeiFedorov90552c62025-01-30 14:56:47 +00001019#endif /* ENABLE_RME */