blob: a8763136e2dda3fe9106b4d681aec62740a67f8f [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handley2b6b5742015-03-19 19:17:53 +00002 * Copyright (c) 2013-2015, 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 Handley2b6b5742015-03-19 19:17:53 +000031#include <arm_config.h>
32#include <arm_def.h>
Dan Handleyfb42b122014-06-20 09:43:15 +010033#include <arm_gic.h>
Vikram Kanigiri4e97e542015-02-26 15:25:58 +000034#include <cci.h>
Dan Handley714a0d22014-04-09 13:13:04 +010035#include <debug.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010036#include <mmio.h>
Dan Handley2b6b5742015-03-19 19:17:53 +000037#include <plat_arm.h>
38#include <v2m_def.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010039#include "../fvp_def.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010040
Achin Gupta4f6ad662013-10-25 09:08:21 +010041/*******************************************************************************
Dan Handley2b6b5742015-03-19 19:17:53 +000042 * arm_config holds the characteristics of the differences between the three FVP
43 * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
44 * at each boot stage by the primary before enabling the MMU (to allow cci
Achin Gupta4f6ad662013-10-25 09:08:21 +010045 * configuration) & used thereafter. Each BL will have its own copy to allow
46 * independent operation.
47 ******************************************************************************/
Dan Handley2b6b5742015-03-19 19:17:53 +000048arm_config_t arm_config;
Soby Mathewb08bc042014-09-03 17:48:44 +010049
50#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
51 DEVICE0_SIZE, \
52 MT_DEVICE | MT_RW | MT_SECURE)
53
54#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
55 DEVICE1_SIZE, \
56 MT_DEVICE | MT_RW | MT_SECURE)
57
Jon Medhurstb1eb0932014-02-26 16:27:53 +000058/*
Soby Mathewb08bc042014-09-03 17:48:44 +010059 * Table of regions for various BL stages to map using the MMU.
Sandrine Bailleux74a62b32014-05-09 11:35:36 +010060 * This doesn't include TZRAM as the 'mem_layout' argument passed to
Dan Handley2b6b5742015-03-19 19:17:53 +000061 * arm_configure_mmu_elx() will give the available subset of that,
Jon Medhurstb1eb0932014-02-26 16:27:53 +000062 */
Soby Mathewb08bc042014-09-03 17:48:44 +010063#if IMAGE_BL1
Dan Handley2b6b5742015-03-19 19:17:53 +000064const mmap_region_t plat_arm_mmap[] = {
65 ARM_MAP_SHARED_RAM,
66 V2M_MAP_FLASH0,
67 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010068 MAP_DEVICE0,
69 MAP_DEVICE1,
70 {0}
71};
72#endif
73#if IMAGE_BL2
Dan Handley2b6b5742015-03-19 19:17:53 +000074const mmap_region_t plat_arm_mmap[] = {
75 ARM_MAP_SHARED_RAM,
76 V2M_MAP_FLASH0,
77 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010078 MAP_DEVICE0,
79 MAP_DEVICE1,
Dan Handley2b6b5742015-03-19 19:17:53 +000080 ARM_MAP_NS_DRAM1,
81 ARM_MAP_TSP_SEC_MEM,
Soby Mathewb08bc042014-09-03 17:48:44 +010082 {0}
83};
84#endif
85#if IMAGE_BL31
Dan Handley2b6b5742015-03-19 19:17:53 +000086const mmap_region_t plat_arm_mmap[] = {
87 ARM_MAP_SHARED_RAM,
88 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010089 MAP_DEVICE0,
90 MAP_DEVICE1,
91 {0}
92};
93#endif
94#if IMAGE_BL32
Dan Handley2b6b5742015-03-19 19:17:53 +000095const mmap_region_t plat_arm_mmap[] = {
96 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010097 MAP_DEVICE0,
98 MAP_DEVICE1,
Jon Medhurstb1eb0932014-02-26 16:27:53 +000099 {0}
100};
Soby Mathewb08bc042014-09-03 17:48:44 +0100101#endif
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000102
Dan Handley2b6b5742015-03-19 19:17:53 +0000103ARM_CASSERT_MMAP
Soby Mathew13ee9682015-01-22 11:22:22 +0000104
Dan Handley2b6b5742015-03-19 19:17:53 +0000105
106#if IMAGE_BL31 || IMAGE_BL32
Dan Handleyfb42b122014-06-20 09:43:15 +0100107/* Array of secure interrupts to be configured by the gic driver */
108const unsigned int irq_sec_array[] = {
109 IRQ_TZ_WDOG,
Dan Handley2b6b5742015-03-19 19:17:53 +0000110 ARM_IRQ_SEC_PHY_TIMER,
111 ARM_IRQ_SEC_SGI_0,
112 ARM_IRQ_SEC_SGI_1,
113 ARM_IRQ_SEC_SGI_2,
114 ARM_IRQ_SEC_SGI_3,
115 ARM_IRQ_SEC_SGI_4,
116 ARM_IRQ_SEC_SGI_5,
117 ARM_IRQ_SEC_SGI_6,
118 ARM_IRQ_SEC_SGI_7
Dan Handleyfb42b122014-06-20 09:43:15 +0100119};
120
Dan Handley2b6b5742015-03-19 19:17:53 +0000121void plat_arm_gic_init(void)
122{
123 arm_gic_init(arm_config.gicc_base,
124 arm_config.gicd_base,
125 BASE_GICR_BASE,
126 irq_sec_array,
127 ARRAY_SIZE(irq_sec_array));
128}
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000129
Dan Handley2b6b5742015-03-19 19:17:53 +0000130#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132/*******************************************************************************
133 * A single boot loader stack is expected to work on both the Foundation FVP
134 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
135 * SYS_ID register provides a mechanism for detecting the differences between
136 * these platforms. This information is stored in a per-BL array to allow the
137 * code to take the correct path.Per BL platform configuration.
138 ******************************************************************************/
Dan Handley2b6b5742015-03-19 19:17:53 +0000139void fvp_config_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100140{
Soby Mathew8e2f2872014-08-14 12:49:05 +0100141 unsigned int rev, hbi, bld, arch, sys_id;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100142
Dan Handley2b6b5742015-03-19 19:17:53 +0000143 sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
144 rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
145 hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
146 bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
147 arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100148
Andrew Thoelke960347d2014-06-26 14:27:26 +0100149 if (arch != ARCH_MODEL) {
150 ERROR("This firmware is for FVP models\n");
James Morrissey40a6f642014-02-10 14:24:36 +0000151 panic();
Andrew Thoelke960347d2014-06-26 14:27:26 +0100152 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100153
154 /*
155 * The build field in the SYS_ID tells which variant of the GIC
156 * memory is implemented by the model.
157 */
158 switch (bld) {
159 case BLD_GIC_VE_MMAP:
Dan Handley2b6b5742015-03-19 19:17:53 +0000160 arm_config.gicd_base = VE_GICD_BASE;
161 arm_config.gicc_base = VE_GICC_BASE;
162 arm_config.gich_base = VE_GICH_BASE;
163 arm_config.gicv_base = VE_GICV_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100164 break;
165 case BLD_GIC_A53A57_MMAP:
Dan Handley2b6b5742015-03-19 19:17:53 +0000166 arm_config.gicd_base = BASE_GICD_BASE;
167 arm_config.gicc_base = BASE_GICC_BASE;
168 arm_config.gich_base = BASE_GICH_BASE;
169 arm_config.gicv_base = BASE_GICV_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100170 break;
171 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100172 ERROR("Unsupported board build %x\n", bld);
173 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100174 }
175
176 /*
177 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
178 * for the Foundation FVP.
179 */
180 switch (hbi) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000181 case HBI_FOUNDATION_FVP:
182 arm_config.max_aff0 = 4;
183 arm_config.max_aff1 = 1;
184 arm_config.flags = 0;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100185
186 /*
187 * Check for supported revisions of Foundation FVP
188 * Allow future revisions to run but emit warning diagnostic
189 */
190 switch (rev) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000191 case REV_FOUNDATION_FVP_V2_0:
192 case REV_FOUNDATION_FVP_V2_1:
193 case REV_FOUNDATION_FVP_v9_1:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100194 break;
195 default:
196 WARN("Unrecognized Foundation FVP revision %x\n", rev);
197 break;
198 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199 break;
Dan Handley2b6b5742015-03-19 19:17:53 +0000200 case HBI_BASE_FVP:
201 arm_config.max_aff0 = 4;
202 arm_config.max_aff1 = 2;
203 arm_config.flags |= ARM_CONFIG_BASE_MMAP |
204 ARM_CONFIG_HAS_CCI | ARM_CONFIG_HAS_TZC;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100205
206 /*
207 * Check for supported revisions
208 * Allow future revisions to run but emit warning diagnostic
209 */
210 switch (rev) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000211 case REV_BASE_FVP_V0:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100212 break;
213 default:
214 WARN("Unrecognized Base FVP revision %x\n", rev);
215 break;
216 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100217 break;
218 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100219 ERROR("Unsupported board HBI number 0x%x\n", hbi);
220 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100221 }
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100222}
Vikram Kanigiri96377452014-04-24 11:02:16 +0100223
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000224
Dan Handleybe234f92014-08-04 16:11:15 +0100225void fvp_cci_init(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100226{
Vikram Kanigiri96377452014-04-24 11:02:16 +0100227 /*
Dan Handleybe234f92014-08-04 16:11:15 +0100228 * Initialize CCI-400 driver
229 */
Dan Handley2b6b5742015-03-19 19:17:53 +0000230 if (arm_config.flags & ARM_CONFIG_HAS_CCI)
231 arm_cci_init();
Dan Handleybe234f92014-08-04 16:11:15 +0100232}
233
234void fvp_cci_enable(void)
235{
Dan Handley2b6b5742015-03-19 19:17:53 +0000236 if (arm_config.flags & ARM_CONFIG_HAS_CCI)
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000237 cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr()));
238}
239
240void fvp_cci_disable(void)
241{
Dan Handley2b6b5742015-03-19 19:17:53 +0000242 if (arm_config.flags & ARM_CONFIG_HAS_CCI)
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000243 cci_disable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr()));
Vikram Kanigiri96377452014-04-24 11:02:16 +0100244}