blob: d44ccb6ec115e77a6abc3fe6570c2ee97868bdbe [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
Achin Gupta4f6ad662013-10-25 09:08:21 +010031#include <assert.h>
32#include <arch_helpers.h>
James Morrissey40a6f642014-02-10 14:24:36 +000033#include "debug.h"
Jon Medhurstb1eb0932014-02-26 16:27:53 +000034#include <platform.h>
35#include <xlat_tables.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010036
37unsigned char platform_normal_stacks[PLATFORM_STACK_SIZE][PLATFORM_CORE_COUNT]
38__attribute__ ((aligned(PLATFORM_CACHE_LINE_SIZE),
39 section("tzfw_normal_stacks")));
40
41/*******************************************************************************
42 * This array holds the characteristics of the differences between the three
43 * FVP platforms (Base, A53_A57 & Foundation). It will be populated during cold
44 * boot at each boot stage by the primary before enabling the MMU (to allow cci
45 * configuration) & used thereafter. Each BL will have its own copy to allow
46 * independent operation.
47 ******************************************************************************/
48static unsigned long platform_config[CONFIG_LIMIT];
49
50/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010051 * Enable the MMU assuming that the pagetables have already been created
52 *******************************************************************************/
53void enable_mmu()
54{
55 unsigned long mair, tcr, ttbr, sctlr;
56 unsigned long current_el = read_current_el();
57
58 /* Set the attributes in the right indices of the MAIR */
59 mair = MAIR_ATTR_SET(ATTR_DEVICE, ATTR_DEVICE_INDEX);
60 mair |= MAIR_ATTR_SET(ATTR_IWBWA_OWBWA_NTR,
61 ATTR_IWBWA_OWBWA_NTR_INDEX);
Achin Gupta4f6ad662013-10-25 09:08:21 +010062
63 /*
64 * Set TCR bits as well. Inner & outer WBWA & shareable + T0SZ = 32
65 */
66 tcr = TCR_SH_INNER_SHAREABLE | TCR_RGN_OUTER_WBA |
67 TCR_RGN_INNER_WBA | TCR_T0SZ_4GB;
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000068
69 /* Set TTBR bits as well */
70 ttbr = (unsigned long) l1_xlation_table;
71
Achin Gupta4f6ad662013-10-25 09:08:21 +010072 if (GET_EL(current_el) == MODE_EL3) {
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000073 write_mair_el3(mair);
Achin Gupta4f6ad662013-10-25 09:08:21 +010074 tcr |= TCR_EL3_RES1;
Sandrine Bailleux295538b2013-11-15 14:46:44 +000075 /* Invalidate EL3 TLBs */
Achin Gupta4f6ad662013-10-25 09:08:21 +010076 tlbialle3();
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000077
78 write_tcr_el3(tcr);
79 write_ttbr0_el3(ttbr);
80
81 sctlr = read_sctlr_el3();
82 sctlr |= SCTLR_WXN_BIT | SCTLR_M_BIT | SCTLR_I_BIT;
83 sctlr |= SCTLR_A_BIT | SCTLR_C_BIT;
84 write_sctlr_el3(sctlr);
Achin Gupta4f6ad662013-10-25 09:08:21 +010085 } else {
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000086
87 write_mair_el1(mair);
Achin Gupta4f6ad662013-10-25 09:08:21 +010088 /* Invalidate EL1 TLBs */
89 tlbivmalle1();
Achin Gupta4f6ad662013-10-25 09:08:21 +010090
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000091 write_tcr_el1(tcr);
92 write_ttbr0_el1(ttbr);
Achin Gupta4f6ad662013-10-25 09:08:21 +010093
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +000094 sctlr = read_sctlr_el1();
95 sctlr |= SCTLR_WXN_BIT | SCTLR_M_BIT | SCTLR_I_BIT;
96 sctlr |= SCTLR_A_BIT | SCTLR_C_BIT;
97 write_sctlr_el1(sctlr);
98 }
Achin Gupta4f6ad662013-10-25 09:08:21 +010099
100 return;
101}
102
103void disable_mmu(void)
104{
Vikram Kanigirica0aeb72014-03-20 12:23:21 +0000105 unsigned long sctlr;
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +0000106 unsigned long current_el = read_current_el();
Vikram Kanigirica0aeb72014-03-20 12:23:21 +0000107
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +0000108 if (GET_EL(current_el) == MODE_EL3) {
109 sctlr = read_sctlr_el3();
110 sctlr = sctlr & ~(SCTLR_M_BIT | SCTLR_C_BIT);
111 write_sctlr_el3(sctlr);
112 } else {
113 sctlr = read_sctlr_el1();
114 sctlr = sctlr & ~(SCTLR_M_BIT | SCTLR_C_BIT);
115 write_sctlr_el1(sctlr);
116 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100117
Achin Gupta4f6ad662013-10-25 09:08:21 +0100118 /* Flush the caches */
119 dcsw_op_all(DCCISW);
120
121 return;
122}
123
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000124/*
125 * Table of regions to map using the MMU.
126 * This doesn't include TZRAM as the 'mem_layout' argument passed to to
127 * configure_mmu() will give the available subset of that,
128 */
129const mmap_region mmap[] = {
130 { TZROM_BASE, TZROM_SIZE, MT_MEMORY | MT_RO | MT_SECURE },
131 { TZDRAM_BASE, TZDRAM_SIZE, MT_MEMORY | MT_RW | MT_SECURE },
132 { FLASH0_BASE, FLASH0_SIZE, MT_MEMORY | MT_RO | MT_SECURE },
133 { FLASH1_BASE, FLASH1_SIZE, MT_MEMORY | MT_RO | MT_SECURE },
134 { VRAM_BASE, VRAM_SIZE, MT_MEMORY | MT_RW | MT_SECURE },
135 { DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
136 { NSRAM_BASE, NSRAM_SIZE, MT_MEMORY | MT_RW | MT_NS },
137 { DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
138 /* 2nd GB as device for now...*/
139 { 0x40000000, 0x40000000, MT_DEVICE | MT_RW | MT_SECURE },
140 { DRAM_BASE, DRAM_SIZE, MT_MEMORY | MT_RW | MT_NS },
141 {0}
142};
143
Achin Gupta4f6ad662013-10-25 09:08:21 +0100144/*******************************************************************************
145 * Setup the pagetables as per the platform memory map & initialize the mmu
146 *******************************************************************************/
147void configure_mmu(meminfo *mem_layout,
148 unsigned long ro_start,
149 unsigned long ro_limit,
150 unsigned long coh_start,
151 unsigned long coh_limit)
152{
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000153 mmap_add_region(mem_layout->total_base, mem_layout->total_size,
154 MT_MEMORY | MT_RW | MT_SECURE);
155 mmap_add_region(ro_start, ro_limit - ro_start,
156 MT_MEMORY | MT_RO | MT_SECURE);
157 mmap_add_region(coh_start, coh_limit - coh_start,
158 MT_DEVICE | MT_RW | MT_SECURE);
159
160 mmap_add(mmap);
161
162 init_xlat_tables();
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000163
Achin Gupta4f6ad662013-10-25 09:08:21 +0100164 enable_mmu();
165 return;
166}
167
168/* Simple routine which returns a configuration variable value */
169unsigned long platform_get_cfgvar(unsigned int var_id)
170{
171 assert(var_id < CONFIG_LIMIT);
172 return platform_config[var_id];
173}
174
175/*******************************************************************************
176 * A single boot loader stack is expected to work on both the Foundation FVP
177 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
178 * SYS_ID register provides a mechanism for detecting the differences between
179 * these platforms. This information is stored in a per-BL array to allow the
180 * code to take the correct path.Per BL platform configuration.
181 ******************************************************************************/
182int platform_config_setup(void)
183{
184 unsigned int rev, hbi, bld, arch, sys_id, midr_pn;
185
186 sys_id = mmio_read_32(VE_SYSREGS_BASE + V2M_SYS_ID);
187 rev = (sys_id >> SYS_ID_REV_SHIFT) & SYS_ID_REV_MASK;
188 hbi = (sys_id >> SYS_ID_HBI_SHIFT) & SYS_ID_HBI_MASK;
189 bld = (sys_id >> SYS_ID_BLD_SHIFT) & SYS_ID_BLD_MASK;
190 arch = (sys_id >> SYS_ID_ARCH_SHIFT) & SYS_ID_ARCH_MASK;
191
James Morrissey40a6f642014-02-10 14:24:36 +0000192 if ((rev != REV_FVP) || (arch != ARCH_MODEL))
193 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100194
195 /*
196 * The build field in the SYS_ID tells which variant of the GIC
197 * memory is implemented by the model.
198 */
199 switch (bld) {
200 case BLD_GIC_VE_MMAP:
201 platform_config[CONFIG_GICD_ADDR] = VE_GICD_BASE;
202 platform_config[CONFIG_GICC_ADDR] = VE_GICC_BASE;
203 platform_config[CONFIG_GICH_ADDR] = VE_GICH_BASE;
204 platform_config[CONFIG_GICV_ADDR] = VE_GICV_BASE;
205 break;
206 case BLD_GIC_A53A57_MMAP:
207 platform_config[CONFIG_GICD_ADDR] = BASE_GICD_BASE;
208 platform_config[CONFIG_GICC_ADDR] = BASE_GICC_BASE;
209 platform_config[CONFIG_GICH_ADDR] = BASE_GICH_BASE;
210 platform_config[CONFIG_GICV_ADDR] = BASE_GICV_BASE;
211 break;
212 default:
213 assert(0);
214 }
215
216 /*
217 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
218 * for the Foundation FVP.
219 */
220 switch (hbi) {
221 case HBI_FOUNDATION:
222 platform_config[CONFIG_MAX_AFF0] = 4;
223 platform_config[CONFIG_MAX_AFF1] = 1;
224 platform_config[CONFIG_CPU_SETUP] = 0;
225 platform_config[CONFIG_BASE_MMAP] = 0;
Harry Liebel30affd52013-10-30 17:41:48 +0000226 platform_config[CONFIG_HAS_CCI] = 0;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100227 break;
228 case HBI_FVP_BASE:
229 midr_pn = (read_midr() >> MIDR_PN_SHIFT) & MIDR_PN_MASK;
230 if ((midr_pn == MIDR_PN_A57) || (midr_pn == MIDR_PN_A53))
231 platform_config[CONFIG_CPU_SETUP] = 1;
232 else
233 platform_config[CONFIG_CPU_SETUP] = 0;
234
235 platform_config[CONFIG_MAX_AFF0] = 4;
236 platform_config[CONFIG_MAX_AFF1] = 2;
237 platform_config[CONFIG_BASE_MMAP] = 1;
Harry Liebel30affd52013-10-30 17:41:48 +0000238 platform_config[CONFIG_HAS_CCI] = 1;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100239 break;
240 default:
241 assert(0);
242 }
243
244 return 0;
245}
246
Ian Spray84687392014-01-02 16:57:12 +0000247unsigned long plat_get_ns_image_entrypoint(void)
248{
Achin Gupta4f6ad662013-10-25 09:08:21 +0100249 return NS_IMAGE_OFFSET;
250}