blob: 174085fb1da36ea8a5c1be53f9dab1712322ddb5 [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 Handley2bd4ef22014-04-09 13:14:54 +010033#include <assert.h>
34#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>
39#include <xlat_tables.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010040#include "../fvp_def.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
Achin Gupta4f6ad662013-10-25 09:08:21 +010042/*******************************************************************************
43 * This array holds the characteristics of the differences between the three
44 * FVP platforms (Base, A53_A57 & Foundation). It will be populated during cold
45 * boot at each boot stage by the primary before enabling the MMU (to allow cci
46 * configuration) & used thereafter. Each BL will have its own copy to allow
47 * independent operation.
48 ******************************************************************************/
Dan Handleyea451572014-05-15 14:53:30 +010049static unsigned long fvp_config[CONFIG_LIMIT];
Achin Gupta4f6ad662013-10-25 09:08:21 +010050
Jon Medhurstb1eb0932014-02-26 16:27:53 +000051/*
52 * Table of regions to map using the MMU.
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010053 * This doesn't include TZRAM as the 'mem_layout' argument passed to
54 * configure_mmu_elx() will give the available subset of that,
Jon Medhurstb1eb0932014-02-26 16:27:53 +000055 */
Dan Handleye2712bc2014-04-10 15:37:22 +010056const mmap_region_t fvp_mmap[] = {
Lin Ma13592362014-06-02 11:45:36 -070057 { TZROM_BASE, TZROM_BASE, TZROM_SIZE,
58 MT_MEMORY | MT_RO | MT_SECURE },
59 { TZDRAM_BASE, TZDRAM_BASE, TZDRAM_SIZE,
60 MT_MEMORY | MT_RW | MT_SECURE },
61 { FLASH0_BASE, FLASH0_BASE, FLASH0_SIZE,
62 MT_MEMORY | MT_RO | MT_SECURE },
63 { FLASH1_BASE, FLASH1_BASE, FLASH1_SIZE,
64 MT_MEMORY | MT_RO | MT_SECURE },
65 { VRAM_BASE, VRAM_BASE, VRAM_SIZE,
66 MT_MEMORY | MT_RW | MT_SECURE },
67 { DEVICE0_BASE, DEVICE0_BASE, DEVICE0_SIZE,
68 MT_DEVICE | MT_RW | MT_SECURE },
Lin Ma13592362014-06-02 11:45:36 -070069 { DEVICE1_BASE, DEVICE1_BASE, DEVICE1_SIZE,
70 MT_DEVICE | MT_RW | MT_SECURE },
Jon Medhurstb1eb0932014-02-26 16:27:53 +000071 /* 2nd GB as device for now...*/
Lin Ma13592362014-06-02 11:45:36 -070072 { 0x40000000, 0x40000000, 0x40000000,
73 MT_DEVICE | MT_RW | MT_SECURE },
74 { DRAM1_BASE, DRAM1_BASE, DRAM1_SIZE,
75 MT_MEMORY | MT_RW | MT_NS },
Jon Medhurstb1eb0932014-02-26 16:27:53 +000076 {0}
77};
78
Achin Gupta4f6ad662013-10-25 09:08:21 +010079/*******************************************************************************
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010080 * Macro generating the code for the function setting up the pagetables as per
81 * the platform memory map & initialize the mmu, for the given exception level
82 ******************************************************************************/
83#define DEFINE_CONFIGURE_MMU_EL(_el) \
Lin Ma13592362014-06-02 11:45:36 -070084 void fvp_configure_mmu_el##_el(unsigned long total_base, \
Vikram Kanigirid8c9d262014-05-16 18:48:12 +010085 unsigned long total_size, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010086 unsigned long ro_start, \
87 unsigned long ro_limit, \
88 unsigned long coh_start, \
89 unsigned long coh_limit) \
90 { \
Lin Ma13592362014-06-02 11:45:36 -070091 mmap_add_region(total_base, total_base, \
Vikram Kanigirid8c9d262014-05-16 18:48:12 +010092 total_size, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010093 MT_MEMORY | MT_RW | MT_SECURE); \
Lin Ma13592362014-06-02 11:45:36 -070094 mmap_add_region(ro_start, ro_start, \
95 ro_limit - ro_start, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010096 MT_MEMORY | MT_RO | MT_SECURE); \
Lin Ma13592362014-06-02 11:45:36 -070097 mmap_add_region(coh_start, coh_start, \
98 coh_limit - coh_start, \
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010099 MT_DEVICE | MT_RW | MT_SECURE); \
100 mmap_add(fvp_mmap); \
101 init_xlat_tables(); \
102 \
103 enable_mmu_el##_el(); \
104 }
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000105
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100106/* Define EL1 and EL3 variants of the function initialising the MMU */
107DEFINE_CONFIGURE_MMU_EL(1)
108DEFINE_CONFIGURE_MMU_EL(3)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100109
110/* Simple routine which returns a configuration variable value */
Dan Handleyea451572014-05-15 14:53:30 +0100111unsigned long fvp_get_cfgvar(unsigned int var_id)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112{
113 assert(var_id < CONFIG_LIMIT);
Dan Handleyea451572014-05-15 14:53:30 +0100114 return fvp_config[var_id];
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115}
116
117/*******************************************************************************
118 * A single boot loader stack is expected to work on both the Foundation FVP
119 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
120 * SYS_ID register provides a mechanism for detecting the differences between
121 * these platforms. This information is stored in a per-BL array to allow the
122 * code to take the correct path.Per BL platform configuration.
123 ******************************************************************************/
Dan Handleyea451572014-05-15 14:53:30 +0100124int fvp_config_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100125{
126 unsigned int rev, hbi, bld, arch, sys_id, midr_pn;
127
128 sys_id = mmio_read_32(VE_SYSREGS_BASE + V2M_SYS_ID);
129 rev = (sys_id >> SYS_ID_REV_SHIFT) & SYS_ID_REV_MASK;
130 hbi = (sys_id >> SYS_ID_HBI_SHIFT) & SYS_ID_HBI_MASK;
131 bld = (sys_id >> SYS_ID_BLD_SHIFT) & SYS_ID_BLD_MASK;
132 arch = (sys_id >> SYS_ID_ARCH_SHIFT) & SYS_ID_ARCH_MASK;
133
Andrew Thoelke960347d2014-06-26 14:27:26 +0100134 if (arch != ARCH_MODEL) {
135 ERROR("This firmware is for FVP models\n");
James Morrissey40a6f642014-02-10 14:24:36 +0000136 panic();
Andrew Thoelke960347d2014-06-26 14:27:26 +0100137 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
139 /*
140 * The build field in the SYS_ID tells which variant of the GIC
141 * memory is implemented by the model.
142 */
143 switch (bld) {
144 case BLD_GIC_VE_MMAP:
Dan Handleyea451572014-05-15 14:53:30 +0100145 fvp_config[CONFIG_GICD_ADDR] = VE_GICD_BASE;
146 fvp_config[CONFIG_GICC_ADDR] = VE_GICC_BASE;
147 fvp_config[CONFIG_GICH_ADDR] = VE_GICH_BASE;
148 fvp_config[CONFIG_GICV_ADDR] = VE_GICV_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100149 break;
150 case BLD_GIC_A53A57_MMAP:
Dan Handleyea451572014-05-15 14:53:30 +0100151 fvp_config[CONFIG_GICD_ADDR] = BASE_GICD_BASE;
152 fvp_config[CONFIG_GICC_ADDR] = BASE_GICC_BASE;
153 fvp_config[CONFIG_GICH_ADDR] = BASE_GICH_BASE;
154 fvp_config[CONFIG_GICV_ADDR] = BASE_GICV_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100155 break;
156 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100157 ERROR("Unsupported board build %x\n", bld);
158 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100159 }
160
161 /*
162 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
163 * for the Foundation FVP.
164 */
165 switch (hbi) {
166 case HBI_FOUNDATION:
Dan Handleyea451572014-05-15 14:53:30 +0100167 fvp_config[CONFIG_MAX_AFF0] = 4;
168 fvp_config[CONFIG_MAX_AFF1] = 1;
169 fvp_config[CONFIG_CPU_SETUP] = 0;
170 fvp_config[CONFIG_BASE_MMAP] = 0;
171 fvp_config[CONFIG_HAS_CCI] = 0;
172 fvp_config[CONFIG_HAS_TZC] = 0;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100173
174 /*
175 * Check for supported revisions of Foundation FVP
176 * Allow future revisions to run but emit warning diagnostic
177 */
178 switch (rev) {
179 case REV_FOUNDATION_V2_0:
180 case REV_FOUNDATION_V2_1:
181 break;
182 default:
183 WARN("Unrecognized Foundation FVP revision %x\n", rev);
184 break;
185 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100186 break;
187 case HBI_FVP_BASE:
188 midr_pn = (read_midr() >> MIDR_PN_SHIFT) & MIDR_PN_MASK;
189 if ((midr_pn == MIDR_PN_A57) || (midr_pn == MIDR_PN_A53))
Dan Handleyea451572014-05-15 14:53:30 +0100190 fvp_config[CONFIG_CPU_SETUP] = 1;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100191 else
Dan Handleyea451572014-05-15 14:53:30 +0100192 fvp_config[CONFIG_CPU_SETUP] = 0;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100193
Dan Handleyea451572014-05-15 14:53:30 +0100194 fvp_config[CONFIG_MAX_AFF0] = 4;
195 fvp_config[CONFIG_MAX_AFF1] = 2;
196 fvp_config[CONFIG_BASE_MMAP] = 1;
197 fvp_config[CONFIG_HAS_CCI] = 1;
198 fvp_config[CONFIG_HAS_TZC] = 1;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100199
200 /*
201 * Check for supported revisions
202 * Allow future revisions to run but emit warning diagnostic
203 */
204 switch (rev) {
205 case REV_FVP_BASE_V0:
206 break;
207 default:
208 WARN("Unrecognized Base FVP revision %x\n", rev);
209 break;
210 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100211 break;
212 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100213 ERROR("Unsupported board HBI number 0x%x\n", hbi);
214 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100215 }
216
217 return 0;
218}
219
Ian Spray84687392014-01-02 16:57:12 +0000220unsigned long plat_get_ns_image_entrypoint(void)
221{
Achin Gupta4f6ad662013-10-25 09:08:21 +0100222 return NS_IMAGE_OFFSET;
223}
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100224
225uint64_t plat_get_syscnt_freq(void)
226{
227 uint64_t counter_base_frequency;
228
229 /* Read the frequency from Frequency modes table */
230 counter_base_frequency = mmio_read_32(SYS_CNTCTL_BASE + CNTFID_OFF);
231
232 /* The first entry of the frequency modes table must not be 0 */
233 assert(counter_base_frequency != 0);
234
235 return counter_base_frequency;
236}
Vikram Kanigiri96377452014-04-24 11:02:16 +0100237
238void fvp_cci_setup(void)
239{
240 unsigned long cci_setup;
241
242 /*
243 * Enable CCI-400 for this cluster. No need
244 * for locks as no other cpu is active at the
245 * moment
246 */
Dan Handleyea451572014-05-15 14:53:30 +0100247 cci_setup = fvp_get_cfgvar(CONFIG_HAS_CCI);
Vikram Kanigiri96377452014-04-24 11:02:16 +0100248 if (cci_setup)
249 cci_enable_coherency(read_mpidr());
250}
251
252
253/*******************************************************************************
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100254 * Gets SPSR for BL32 entry
Vikram Kanigiri96377452014-04-24 11:02:16 +0100255 ******************************************************************************/
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100256uint32_t fvp_get_spsr_for_bl32_entry(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100257{
Vikram Kanigiri96377452014-04-24 11:02:16 +0100258 /*
259 * The Secure Payload Dispatcher service is responsible for
260 * setting the SPSR prior to entry into the BL32 image.
261 */
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100262 return 0;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100263}
264
265/*******************************************************************************
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100266 * Gets SPSR for BL33 entry
Vikram Kanigiri96377452014-04-24 11:02:16 +0100267 ******************************************************************************/
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100268uint32_t fvp_get_spsr_for_bl33_entry(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100269{
270 unsigned long el_status;
271 unsigned int mode;
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100272 uint32_t spsr;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100273
274 /* Figure out what mode we enter the non-secure world in */
275 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
276 el_status &= ID_AA64PFR0_ELX_MASK;
277
278 if (el_status)
279 mode = MODE_EL2;
280 else
281 mode = MODE_EL1;
282
283 /*
284 * TODO: Consider the possibility of specifying the SPSR in
285 * the FIP ToC and allowing the platform to have a say as
286 * well.
287 */
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100288 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
289 return spsr;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100290}