blob: bce943dad3fc95b22e0aa6a0018870986b1b77b2 [file] [log] [blame]
laurenw-arm7c7b1982020-10-21 13:34:40 -05001/*
2 * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Gary Morrison3d7f6542021-01-27 13:08:47 -06007/* This uses xlat_mpu, but tables are set up using V2 mmap_region_t */
8#define XLAT_TABLES_LIB_V2 1
laurenw-arm7c7b1982020-10-21 13:34:40 -05009
Gary Morrison3d7f6542021-01-27 13:08:47 -060010#include <assert.h>
laurenw-arm7c7b1982020-10-21 13:34:40 -050011#include <common/debug.h>
Gary Morrison3d7f6542021-01-27 13:08:47 -060012
laurenw-arm7c7b1982020-10-21 13:34:40 -050013#include <drivers/arm/cci.h>
14#include <drivers/arm/ccn.h>
15#include <drivers/arm/gicv2.h>
16#include <drivers/arm/sp804_delay_timer.h>
17#include <drivers/generic_delay_timer.h>
18#include <lib/mmio.h>
19#include <lib/smccc.h>
20#include <lib/xlat_tables/xlat_tables_compat.h>
21#include <services/arm_arch_svc.h>
22
23#include "fvp_r_private.h"
24#include <plat/arm/common/arm_config.h>
25#include <plat/arm/common/plat_arm.h>
26#include <plat/common/platform.h>
27#include <platform_def.h>
28
29
30/* Defines for GIC Driver build time selection */
31#define FVP_R_GICV3 2
32
33/*******************************************************************************
34 * arm_config holds the characteristics of the differences between the FVP_R
35 * platforms. It will be populated during cold boot at each boot stage by the
36 * primary before enabling the MPU (to allow interconnect configuration) &
37 * used thereafter. Each BL will have its own copy to allow independent
38 * operation.
39 ******************************************************************************/
40arm_config_t arm_config;
41
42#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
43 DEVICE0_SIZE, \
44 MT_DEVICE | MT_RW | MT_SECURE)
45
46#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
47 DEVICE1_SIZE, \
48 MT_DEVICE | MT_RW | MT_SECURE)
49
50/*
51 * Need to be mapped with write permissions in order to set a new non-volatile
52 * counter value.
53 */
54#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
55 DEVICE2_SIZE, \
56 MT_DEVICE | MT_RW | MT_SECURE)
57
58/*
59 * Table of memory regions for various BL stages to map using the MPU.
60 * This doesn't include Trusted SRAM as setup_page_tables() already takes care
61 * of mapping it.
62 *
63 * The flash needs to be mapped as writable in order to erase the FIP's Table of
64 * Contents in case of unrecoverable error (see plat_error_handler()).
65 */
66#ifdef IMAGE_BL1
67const mmap_region_t plat_arm_mmap[] = {
68 ARM_MAP_SHARED_RAM,
69 V2M_MAP_FLASH0_RW,
70 V2M_MAP_IOFPGA,
71 MAP_DEVICE0,
72 MAP_DEVICE1,
73#if TRUSTED_BOARD_BOOT
74 /* To access the Root of Trust Public Key registers. */
75 MAP_DEVICE2,
laurenw-arm7c7b1982020-10-21 13:34:40 -050076#endif
77 {0}
78};
79#endif
80
81ARM_CASSERT_MMAP
82
83#if FVP_R_INTERCONNECT_DRIVER != FVP_R_CCN
84static const int fvp_cci400_map[] = {
85 PLAT_FVP_R_CCI400_CLUS0_SL_PORT,
86 PLAT_FVP_R_CCI400_CLUS1_SL_PORT,
87};
88
89static const int fvp_cci5xx_map[] = {
90 PLAT_FVP_R_CCI5XX_CLUS0_SL_PORT,
91 PLAT_FVP_R_CCI5XX_CLUS1_SL_PORT,
92};
93
94static unsigned int get_interconnect_master(void)
95{
96 unsigned int master;
97 u_register_t mpidr;
98
99 mpidr = read_mpidr_el1();
100 master = ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) ?
101 MPIDR_AFFLVL2_VAL(mpidr) : MPIDR_AFFLVL1_VAL(mpidr);
102
103 assert(master < FVP_R_CLUSTER_COUNT);
104 return master;
105}
106#endif
107
108/*******************************************************************************
109 * Initialize the platform config for future decision making
110 ******************************************************************************/
111void __init fvp_config_setup(void)
112{
Gary Morrison3d7f6542021-01-27 13:08:47 -0600113 unsigned int rev, hbi, bld, arch, sys_id;
114
laurenw-arm7c7b1982020-10-21 13:34:40 -0500115 arm_config.flags |= ARM_CONFIG_BASE_MMAP;
Gary Morrison3d7f6542021-01-27 13:08:47 -0600116 sys_id = mmio_read_32(V2M_FVP_R_SYSREGS_BASE + V2M_SYS_ID);
117 rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
118 hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
119 bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
120 arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
121
122 if (arch != ARCH_MODEL) {
123 ERROR("This firmware is for FVP_R models\n");
124 panic();
125 }
126
127 /*
128 * The build field in the SYS_ID tells which variant of the GIC
129 * memory is implemented by the model.
130 */
131 switch (bld) {
132 case BLD_GIC_VE_MMAP:
133 ERROR("Legacy Versatile Express memory map for GIC %s",
134 "peripheral is not supported\n");
135 panic();
136 break;
137 case BLD_GIC_A53A57_MMAP:
138 break;
139 default:
140 ERROR("Unsupported board build %x\n", bld);
141 panic();
142 }
143
144 /*
145 * The hbi field in the SYS_ID is 0x020 for the Base FVP_R & 0x010
146 * for the Foundation FVP_R.
147 */
148 switch (hbi) {
149 case HBI_FOUNDATION_FVP_R:
150 arm_config.flags = 0;
151
152 /*
153 * Check for supported revisions of Foundation FVP_R
154 * Allow future revisions to run but emit warning diagnostic
155 */
156 switch (rev) {
157 case REV_FOUNDATION_FVP_R_V2_0:
158 case REV_FOUNDATION_FVP_R_V2_1:
159 case REV_FOUNDATION_FVP_R_v9_1:
160 case REV_FOUNDATION_FVP_R_v9_6:
161 break;
162 default:
163 WARN("Unrecognized Foundation FVP_R revision %x\n", rev);
164 break;
165 }
166 break;
167 case HBI_BASE_FVP_R:
168 arm_config.flags |= (ARM_CONFIG_BASE_MMAP | ARM_CONFIG_HAS_TZC);
169
170 /*
171 * Check for supported revisions
172 * Allow future revisions to run but emit warning diagnostic
173 */
174 switch (rev) {
175 case REV_BASE_FVP_R_V0:
176 arm_config.flags |= ARM_CONFIG_FVP_HAS_CCI400;
177 break;
178 default:
179 WARN("Unrecognized Base FVP_R revision %x\n", rev);
180 break;
181 }
182 break;
183 default:
184 ERROR("Unsupported board HBI number 0x%x\n", hbi);
185 panic();
186 }
laurenw-arm7c7b1982020-10-21 13:34:40 -0500187
188 /*
189 * We assume that the presence of MT bit, and therefore shifted
190 * affinities, is uniform across the platform: either all CPUs, or no
191 * CPUs implement it.
192 */
193 if ((read_mpidr_el1() & MPIDR_MT_MASK) != 0U) {
194 arm_config.flags |= ARM_CONFIG_FVP_SHIFTED_AFF;
195 }
196}
197
198
199void __init fvp_interconnect_init(void)
200{
201#if FVP_R_INTERCONNECT_DRIVER == FVP_R_CCN
202 if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
203 ERROR("Unrecognized CCN variant detected. Only CCN-502 is supported");
204 panic();
205 }
206
207 plat_arm_interconnect_init();
208#else
209 uintptr_t cci_base = 0U;
210 const int *cci_map = NULL;
211 unsigned int map_size = 0U;
212
213 /* Initialize the right interconnect */
214 if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI5XX) != 0U) {
215 cci_base = PLAT_FVP_R_CCI5XX_BASE;
216 cci_map = fvp_cci5xx_map;
217 map_size = ARRAY_SIZE(fvp_cci5xx_map);
218 } else if ((arm_config.flags & ARM_CONFIG_FVP_HAS_CCI400) != 0U) {
219 cci_base = PLAT_FVP_R_CCI400_BASE;
220 cci_map = fvp_cci400_map;
221 map_size = ARRAY_SIZE(fvp_cci400_map);
222 } else {
223 return;
224 }
225
226 assert(cci_base != 0U);
227 assert(cci_map != NULL);
228 cci_init(cci_base, cci_map, map_size);
229#endif
230}
231
232void fvp_interconnect_enable(void)
233{
234#if FVP_R_INTERCONNECT_DRIVER == FVP_R_CCN
235 plat_arm_interconnect_enter_coherency();
236#else
237 unsigned int master;
238
239 if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
240 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
241 master = get_interconnect_master();
242 cci_enable_snoop_dvm_reqs(master);
243 }
244#endif
245}
246
247void fvp_interconnect_disable(void)
248{
249#if FVP_R_INTERCONNECT_DRIVER == FVP_R_CCN
250 plat_arm_interconnect_exit_coherency();
251#else
252 unsigned int master;
253
254 if ((arm_config.flags & (ARM_CONFIG_FVP_HAS_CCI400 |
255 ARM_CONFIG_FVP_HAS_CCI5XX)) != 0U) {
256 master = get_interconnect_master();
257 cci_disable_snoop_dvm_reqs(master);
258 }
259#endif
260}
261
262#if TRUSTED_BOARD_BOOT
263int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
264{
265 assert(heap_addr != NULL);
266 assert(heap_size != NULL);
267
268 return arm_get_mbedtls_heap(heap_addr, heap_size);
269}
270#endif
271
272void fvp_timer_init(void)
273{
274#if USE_SP804_TIMER
275 /* Enable the clock override for SP804 timer 0, which means that no
276 * clock dividers are applied and the raw (35MHz) clock will be used.
277 */
278 mmio_write_32(V2M_SP810_BASE, FVP_R_SP810_CTRL_TIM0_OV);
279
280 /* Initialize delay timer driver using SP804 dual timer 0 */
281 sp804_timer_init(V2M_SP804_TIMER0_BASE,
282 SP804_TIMER_CLKMULT, SP804_TIMER_CLKDIV);
283#else
284 generic_delay_timer_init();
285
286 /* Enable System level generic timer */
287 mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
288 CNTCR_FCREQ(0U) | CNTCR_EN);
289#endif /* USE_SP804_TIMER */
290}
291
292/* Get SOC version */
293int32_t plat_get_soc_version(void)
294{
295 return (int32_t)
296 ((ARM_SOC_IDENTIFICATION_CODE << ARM_SOC_IDENTIFICATION_SHIFT)
297 | (ARM_SOC_CONTINUATION_CODE << ARM_SOC_CONTINUATION_SHIFT)
298 | FVP_R_SOC_ID);
299}
300
301/* Get SOC revision */
302int32_t plat_get_soc_revision(void)
303{
304 unsigned int sys_id;
305
306 sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
307 return (int32_t)((sys_id >> V2M_SYS_ID_REV_SHIFT) &
308 V2M_SYS_ID_REV_MASK);
309}