blob: 55c2cbbd3aab6e5442a081618bbc6c6d0277616a [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
Dan Handley2bd4ef22014-04-09 13:14:54 +010031#include <arch.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010032#include <arch_helpers.h>
Dan Handleyfb42b122014-06-20 09:43:15 +010033#include <arm_gic.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010034#include <bl_common.h>
Vikram Kanigiri96377452014-04-24 11:02:16 +010035#include <cci400.h>
Dan Handley714a0d22014-04-09 13:13:04 +010036#include <debug.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010037#include <mmio.h>
Jon Medhurstb1eb0932014-02-26 16:27:53 +000038#include <platform.h>
Soby Mathewb08bc042014-09-03 17:48:44 +010039#include <platform_def.h>
Dan Handley1c54d972014-06-20 12:02:01 +010040#include <plat_config.h>
Jon Medhurstb1eb0932014-02-26 16:27:53 +000041#include <xlat_tables.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010042#include "../fvp_def.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010043
Achin Gupta4f6ad662013-10-25 09:08:21 +010044/*******************************************************************************
Dan Handley1c54d972014-06-20 12:02:01 +010045 * plat_config holds the characteristics of the differences between the three
Achin Gupta4f6ad662013-10-25 09:08:21 +010046 * FVP platforms (Base, A53_A57 & Foundation). It will be populated during cold
47 * boot at each boot stage by the primary before enabling the MMU (to allow cci
48 * configuration) & used thereafter. Each BL will have its own copy to allow
49 * independent operation.
50 ******************************************************************************/
Dan Handley1c54d972014-06-20 12:02:01 +010051plat_config_t plat_config;
Achin Gupta4f6ad662013-10-25 09:08:21 +010052
Juan Castillo42a617d2014-09-24 10:00:06 +010053#define MAP_SHARED_RAM MAP_REGION_FLAT(FVP_SHARED_MEM_BASE, \
54 FVP_SHARED_MEM_SIZE, \
Soby Mathewb08bc042014-09-03 17:48:44 +010055 MT_MEMORY | MT_RW | MT_SECURE)
56
57#define MAP_FLASH0 MAP_REGION_FLAT(FLASH0_BASE, \
58 FLASH0_SIZE, \
59 MT_MEMORY | MT_RO | MT_SECURE)
60
61#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
62 DEVICE0_SIZE, \
63 MT_DEVICE | MT_RW | MT_SECURE)
64
65#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
66 DEVICE1_SIZE, \
67 MT_DEVICE | MT_RW | MT_SECURE)
68
Juan Castillof3e02182014-12-19 09:28:30 +000069#define MAP_DRAM1_NS MAP_REGION_FLAT(DRAM1_NS_BASE, \
70 DRAM1_NS_SIZE, \
Soby Mathewb08bc042014-09-03 17:48:44 +010071 MT_MEMORY | MT_RW | MT_NS)
72
73#define MAP_TSP_SEC_MEM MAP_REGION_FLAT(TSP_SEC_MEM_BASE, \
74 TSP_SEC_MEM_SIZE, \
75 MT_MEMORY | MT_RW | MT_SECURE)
76
Jon Medhurstb1eb0932014-02-26 16:27:53 +000077/*
Soby Mathewb08bc042014-09-03 17:48:44 +010078 * Table of regions for various BL stages to map using the MMU.
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010079 * This doesn't include TZRAM as the 'mem_layout' argument passed to
80 * configure_mmu_elx() will give the available subset of that,
Jon Medhurstb1eb0932014-02-26 16:27:53 +000081 */
Soby Mathewb08bc042014-09-03 17:48:44 +010082#if IMAGE_BL1
83const mmap_region_t fvp_mmap[] = {
84 MAP_SHARED_RAM,
85 MAP_FLASH0,
86 MAP_DEVICE0,
87 MAP_DEVICE1,
88 {0}
89};
90#endif
91#if IMAGE_BL2
92const mmap_region_t fvp_mmap[] = {
93 MAP_SHARED_RAM,
94 MAP_FLASH0,
95 MAP_DEVICE0,
96 MAP_DEVICE1,
Juan Castillof3e02182014-12-19 09:28:30 +000097 MAP_DRAM1_NS,
Soby Mathewb08bc042014-09-03 17:48:44 +010098 MAP_TSP_SEC_MEM,
99 {0}
100};
101#endif
102#if IMAGE_BL31
103const mmap_region_t fvp_mmap[] = {
104 MAP_SHARED_RAM,
105 MAP_DEVICE0,
106 MAP_DEVICE1,
107 {0}
108};
109#endif
110#if IMAGE_BL32
Dan Handleye2712bc2014-04-10 15:37:22 +0100111const mmap_region_t fvp_mmap[] = {
Soby Mathewb08bc042014-09-03 17:48:44 +0100112 MAP_DEVICE0,
113 MAP_DEVICE1,
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000114 {0}
115};
Soby Mathewb08bc042014-09-03 17:48:44 +0100116#endif
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000117
Dan Handleyfb42b122014-06-20 09:43:15 +0100118/* Array of secure interrupts to be configured by the gic driver */
119const unsigned int irq_sec_array[] = {
120 IRQ_TZ_WDOG,
121 IRQ_SEC_PHY_TIMER,
122 IRQ_SEC_SGI_0,
123 IRQ_SEC_SGI_1,
124 IRQ_SEC_SGI_2,
125 IRQ_SEC_SGI_3,
126 IRQ_SEC_SGI_4,
127 IRQ_SEC_SGI_5,
128 IRQ_SEC_SGI_6,
129 IRQ_SEC_SGI_7
130};
131
132const unsigned int num_sec_irqs = sizeof(irq_sec_array) /
133 sizeof(irq_sec_array[0]);
134
Achin Gupta4f6ad662013-10-25 09:08:21 +0100135/*******************************************************************************
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100136 * Macro generating the code for the function setting up the pagetables as per
137 * the platform memory map & initialize the mmu, for the given exception level
138 ******************************************************************************/
Soby Mathew2ae20432015-01-08 18:02:44 +0000139#if USE_COHERENT_MEM
140#define DEFINE_CONFIGURE_MMU_EL(_el) \
Lin Ma13592362014-06-02 11:45:36 -0700141 void fvp_configure_mmu_el##_el(unsigned long total_base, \
Vikram Kanigirid8c9d262014-05-16 18:48:12 +0100142 unsigned long total_size, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100143 unsigned long ro_start, \
144 unsigned long ro_limit, \
145 unsigned long coh_start, \
146 unsigned long coh_limit) \
147 { \
Lin Ma13592362014-06-02 11:45:36 -0700148 mmap_add_region(total_base, total_base, \
Vikram Kanigirid8c9d262014-05-16 18:48:12 +0100149 total_size, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100150 MT_MEMORY | MT_RW | MT_SECURE); \
Lin Ma13592362014-06-02 11:45:36 -0700151 mmap_add_region(ro_start, ro_start, \
152 ro_limit - ro_start, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100153 MT_MEMORY | MT_RO | MT_SECURE); \
Lin Ma13592362014-06-02 11:45:36 -0700154 mmap_add_region(coh_start, coh_start, \
155 coh_limit - coh_start, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100156 MT_DEVICE | MT_RW | MT_SECURE); \
157 mmap_add(fvp_mmap); \
158 init_xlat_tables(); \
159 \
Achin Guptae9982542014-06-26 08:59:07 +0100160 enable_mmu_el##_el(0); \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100161 }
Soby Mathew2ae20432015-01-08 18:02:44 +0000162#else
163#define DEFINE_CONFIGURE_MMU_EL(_el) \
164 void fvp_configure_mmu_el##_el(unsigned long total_base, \
165 unsigned long total_size, \
166 unsigned long ro_start, \
167 unsigned long ro_limit) \
168 { \
169 mmap_add_region(total_base, total_base, \
170 total_size, \
171 MT_MEMORY | MT_RW | MT_SECURE); \
172 mmap_add_region(ro_start, ro_start, \
173 ro_limit - ro_start, \
174 MT_MEMORY | MT_RO | MT_SECURE); \
175 mmap_add(fvp_mmap); \
176 init_xlat_tables(); \
177 \
178 enable_mmu_el##_el(0); \
179 }
180#endif
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000181
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100182/* Define EL1 and EL3 variants of the function initialising the MMU */
183DEFINE_CONFIGURE_MMU_EL(1)
184DEFINE_CONFIGURE_MMU_EL(3)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100185
Achin Gupta4f6ad662013-10-25 09:08:21 +0100186/*******************************************************************************
187 * A single boot loader stack is expected to work on both the Foundation FVP
188 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
189 * SYS_ID register provides a mechanism for detecting the differences between
190 * these platforms. This information is stored in a per-BL array to allow the
191 * code to take the correct path.Per BL platform configuration.
192 ******************************************************************************/
Dan Handleyea451572014-05-15 14:53:30 +0100193int fvp_config_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100194{
Soby Mathew8e2f2872014-08-14 12:49:05 +0100195 unsigned int rev, hbi, bld, arch, sys_id;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100196
197 sys_id = mmio_read_32(VE_SYSREGS_BASE + V2M_SYS_ID);
198 rev = (sys_id >> SYS_ID_REV_SHIFT) & SYS_ID_REV_MASK;
199 hbi = (sys_id >> SYS_ID_HBI_SHIFT) & SYS_ID_HBI_MASK;
200 bld = (sys_id >> SYS_ID_BLD_SHIFT) & SYS_ID_BLD_MASK;
201 arch = (sys_id >> SYS_ID_ARCH_SHIFT) & SYS_ID_ARCH_MASK;
202
Andrew Thoelke960347d2014-06-26 14:27:26 +0100203 if (arch != ARCH_MODEL) {
204 ERROR("This firmware is for FVP models\n");
James Morrissey40a6f642014-02-10 14:24:36 +0000205 panic();
Andrew Thoelke960347d2014-06-26 14:27:26 +0100206 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100207
208 /*
209 * The build field in the SYS_ID tells which variant of the GIC
210 * memory is implemented by the model.
211 */
212 switch (bld) {
213 case BLD_GIC_VE_MMAP:
Dan Handley1c54d972014-06-20 12:02:01 +0100214 plat_config.gicd_base = VE_GICD_BASE;
215 plat_config.gicc_base = VE_GICC_BASE;
216 plat_config.gich_base = VE_GICH_BASE;
217 plat_config.gicv_base = VE_GICV_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100218 break;
219 case BLD_GIC_A53A57_MMAP:
Dan Handley1c54d972014-06-20 12:02:01 +0100220 plat_config.gicd_base = BASE_GICD_BASE;
221 plat_config.gicc_base = BASE_GICC_BASE;
222 plat_config.gich_base = BASE_GICH_BASE;
223 plat_config.gicv_base = BASE_GICV_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100224 break;
225 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100226 ERROR("Unsupported board build %x\n", bld);
227 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100228 }
229
230 /*
231 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
232 * for the Foundation FVP.
233 */
234 switch (hbi) {
235 case HBI_FOUNDATION:
Dan Handley1c54d972014-06-20 12:02:01 +0100236 plat_config.max_aff0 = 4;
237 plat_config.max_aff1 = 1;
238 plat_config.flags = 0;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100239
240 /*
241 * Check for supported revisions of Foundation FVP
242 * Allow future revisions to run but emit warning diagnostic
243 */
244 switch (rev) {
245 case REV_FOUNDATION_V2_0:
246 case REV_FOUNDATION_V2_1:
247 break;
248 default:
249 WARN("Unrecognized Foundation FVP revision %x\n", rev);
250 break;
251 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100252 break;
253 case HBI_FVP_BASE:
Dan Handley1c54d972014-06-20 12:02:01 +0100254 plat_config.max_aff0 = 4;
255 plat_config.max_aff1 = 2;
256 plat_config.flags |= CONFIG_BASE_MMAP | CONFIG_HAS_CCI |
257 CONFIG_HAS_TZC;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100258
259 /*
260 * Check for supported revisions
261 * Allow future revisions to run but emit warning diagnostic
262 */
263 switch (rev) {
264 case REV_FVP_BASE_V0:
265 break;
266 default:
267 WARN("Unrecognized Base FVP revision %x\n", rev);
268 break;
269 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100270 break;
271 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100272 ERROR("Unsupported board HBI number 0x%x\n", hbi);
273 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100274 }
275
276 return 0;
277}
278
Ian Spray84687392014-01-02 16:57:12 +0000279unsigned long plat_get_ns_image_entrypoint(void)
280{
Achin Gupta4f6ad662013-10-25 09:08:21 +0100281 return NS_IMAGE_OFFSET;
282}
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100283
284uint64_t plat_get_syscnt_freq(void)
285{
286 uint64_t counter_base_frequency;
287
288 /* Read the frequency from Frequency modes table */
289 counter_base_frequency = mmio_read_32(SYS_CNTCTL_BASE + CNTFID_OFF);
290
291 /* The first entry of the frequency modes table must not be 0 */
Juan Castillof558cac2014-06-05 09:45:36 +0100292 if (counter_base_frequency == 0)
293 panic();
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100294
295 return counter_base_frequency;
296}
Vikram Kanigiri96377452014-04-24 11:02:16 +0100297
Dan Handleybe234f92014-08-04 16:11:15 +0100298void fvp_cci_init(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100299{
Vikram Kanigiri96377452014-04-24 11:02:16 +0100300 /*
Dan Handleybe234f92014-08-04 16:11:15 +0100301 * Initialize CCI-400 driver
302 */
303 if (plat_config.flags & CONFIG_HAS_CCI)
304 cci_init(CCI400_BASE,
305 CCI400_SL_IFACE3_CLUSTER_IX,
306 CCI400_SL_IFACE4_CLUSTER_IX);
307}
308
309void fvp_cci_enable(void)
310{
311 /*
312 * Enable CCI-400 coherency for this cluster. No need
Vikram Kanigiri96377452014-04-24 11:02:16 +0100313 * for locks as no other cpu is active at the
314 * moment
315 */
Dan Handley1c54d972014-06-20 12:02:01 +0100316 if (plat_config.flags & CONFIG_HAS_CCI)
Dan Handleybe234f92014-08-04 16:11:15 +0100317 cci_enable_cluster_coherency(read_mpidr());
Vikram Kanigiri96377452014-04-24 11:02:16 +0100318}
319
Dan Handleyfb42b122014-06-20 09:43:15 +0100320void fvp_gic_init(void)
321{
322 arm_gic_init(plat_config.gicc_base,
323 plat_config.gicd_base,
324 BASE_GICR_BASE,
325 irq_sec_array,
326 num_sec_irqs);
327}
328
Vikram Kanigiri96377452014-04-24 11:02:16 +0100329
330/*******************************************************************************
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100331 * Gets SPSR for BL32 entry
Vikram Kanigiri96377452014-04-24 11:02:16 +0100332 ******************************************************************************/
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100333uint32_t fvp_get_spsr_for_bl32_entry(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100334{
Vikram Kanigiri96377452014-04-24 11:02:16 +0100335 /*
336 * The Secure Payload Dispatcher service is responsible for
337 * setting the SPSR prior to entry into the BL32 image.
338 */
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100339 return 0;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100340}
341
342/*******************************************************************************
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100343 * Gets SPSR for BL33 entry
Vikram Kanigiri96377452014-04-24 11:02:16 +0100344 ******************************************************************************/
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100345uint32_t fvp_get_spsr_for_bl33_entry(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100346{
347 unsigned long el_status;
348 unsigned int mode;
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100349 uint32_t spsr;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100350
351 /* Figure out what mode we enter the non-secure world in */
352 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
353 el_status &= ID_AA64PFR0_ELX_MASK;
354
355 if (el_status)
356 mode = MODE_EL2;
357 else
358 mode = MODE_EL1;
359
360 /*
361 * TODO: Consider the possibility of specifying the SPSR in
362 * the FIP ToC and allowing the platform to have a say as
363 * well.
364 */
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100365 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
366 return spsr;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100367}