blob: eb37f113ad35ada648155ff6127c61a722e8c4c3 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Vikram Kanigirifbb13012016-02-15 11:54:14 +00002 * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Dan Handley2b6b5742015-03-19 19:17:53 +00007#include <arm_config.h>
8#include <arm_def.h>
Soby Mathew7356b1e2016-03-24 10:12:42 +00009#include <ccn.h>
Dan Handley714a0d22014-04-09 13:13:04 +010010#include <debug.h>
Achin Gupta1fa7eb62015-11-03 14:18:34 +000011#include <gicv2.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010012#include <mmio.h>
Dan Handley2b6b5742015-03-19 19:17:53 +000013#include <plat_arm.h>
14#include <v2m_def.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010015#include "../fvp_def.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010016
Achin Gupta1fa7eb62015-11-03 14:18:34 +000017/* Defines for GIC Driver build time selection */
18#define FVP_GICV2 1
19#define FVP_GICV3 2
20#define FVP_GICV3_LEGACY 3
21
Achin Gupta4f6ad662013-10-25 09:08:21 +010022/*******************************************************************************
Dan Handley2b6b5742015-03-19 19:17:53 +000023 * arm_config holds the characteristics of the differences between the three FVP
24 * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
Vikram Kanigirifbb13012016-02-15 11:54:14 +000025 * at each boot stage by the primary before enabling the MMU (to allow
26 * interconnect configuration) & used thereafter. Each BL will have its own copy
27 * to allow independent operation.
Achin Gupta4f6ad662013-10-25 09:08:21 +010028 ******************************************************************************/
Dan Handley2b6b5742015-03-19 19:17:53 +000029arm_config_t arm_config;
Soby Mathewb08bc042014-09-03 17:48:44 +010030
31#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
32 DEVICE0_SIZE, \
33 MT_DEVICE | MT_RW | MT_SECURE)
34
35#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
36 DEVICE1_SIZE, \
37 MT_DEVICE | MT_RW | MT_SECURE)
38
Juan Castillo31a68f02015-04-14 12:49:03 +010039#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
40 DEVICE2_SIZE, \
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +010041 MT_DEVICE | MT_RW | MT_SECURE)
Juan Castillo31a68f02015-04-14 12:49:03 +010042
43
Jon Medhurstb1eb0932014-02-26 16:27:53 +000044/*
Sandrine Bailleux4a1267a2016-05-18 16:11:47 +010045 * Table of memory regions for various BL stages to map using the MMU.
46 * This doesn't include Trusted SRAM as arm_setup_page_tables() already
47 * takes care of mapping it.
Sandrine Bailleux889ca032016-06-14 17:01:00 +010048 *
49 * The flash needs to be mapped as writable in order to erase the FIP's Table of
50 * Contents in case of unrecoverable error (see plat_error_handler()).
Jon Medhurstb1eb0932014-02-26 16:27:53 +000051 */
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090052#ifdef IMAGE_BL1
Dan Handley2b6b5742015-03-19 19:17:53 +000053const mmap_region_t plat_arm_mmap[] = {
54 ARM_MAP_SHARED_RAM,
Juan Castillob6132f12015-10-06 14:01:35 +010055 V2M_MAP_FLASH0_RW,
Dan Handley2b6b5742015-03-19 19:17:53 +000056 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010057 MAP_DEVICE0,
58 MAP_DEVICE1,
Juan Castillo31a68f02015-04-14 12:49:03 +010059 MAP_DEVICE2,
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010060#if TRUSTED_BOARD_BOOT
61 ARM_MAP_NS_DRAM1,
62#endif
Soby Mathewb08bc042014-09-03 17:48:44 +010063 {0}
64};
65#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090066#ifdef IMAGE_BL2
Dan Handley2b6b5742015-03-19 19:17:53 +000067const mmap_region_t plat_arm_mmap[] = {
68 ARM_MAP_SHARED_RAM,
Juan Castillob6132f12015-10-06 14:01:35 +010069 V2M_MAP_FLASH0_RW,
Dan Handley2b6b5742015-03-19 19:17:53 +000070 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010071 MAP_DEVICE0,
72 MAP_DEVICE1,
Juan Castillo31a68f02015-04-14 12:49:03 +010073 MAP_DEVICE2,
Dan Handley2b6b5742015-03-19 19:17:53 +000074 ARM_MAP_NS_DRAM1,
75 ARM_MAP_TSP_SEC_MEM,
David Wang0ba499f2016-03-07 11:02:57 +080076#if ARM_BL31_IN_DRAM
77 ARM_MAP_BL31_SEC_DRAM,
78#endif
Soby Mathewb08bc042014-09-03 17:48:44 +010079 {0}
80};
81#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090082#ifdef IMAGE_BL2U
Yatharth Kochar3a11eda2015-10-14 15:28:11 +010083const mmap_region_t plat_arm_mmap[] = {
84 MAP_DEVICE0,
85 V2M_MAP_IOFPGA,
86 {0}
87};
88#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090089#ifdef IMAGE_BL31
Dan Handley2b6b5742015-03-19 19:17:53 +000090const mmap_region_t plat_arm_mmap[] = {
91 ARM_MAP_SHARED_RAM,
92 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010093 MAP_DEVICE0,
94 MAP_DEVICE1,
95 {0}
96};
97#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090098#ifdef IMAGE_BL32
Dan Handley2b6b5742015-03-19 19:17:53 +000099const mmap_region_t plat_arm_mmap[] = {
Soby Mathew0d268dc2016-07-11 14:13:56 +0100100#ifdef AARCH32
101 ARM_MAP_SHARED_RAM,
102#endif
Dan Handley2b6b5742015-03-19 19:17:53 +0000103 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +0100104 MAP_DEVICE0,
105 MAP_DEVICE1,
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000106 {0}
107};
Soby Mathewb08bc042014-09-03 17:48:44 +0100108#endif
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000109
Dan Handley2b6b5742015-03-19 19:17:53 +0000110ARM_CASSERT_MMAP
Soby Mathew13ee9682015-01-22 11:22:22 +0000111
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112
Achin Gupta4f6ad662013-10-25 09:08:21 +0100113/*******************************************************************************
114 * A single boot loader stack is expected to work on both the Foundation FVP
115 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
116 * SYS_ID register provides a mechanism for detecting the differences between
117 * these platforms. This information is stored in a per-BL array to allow the
118 * code to take the correct path.Per BL platform configuration.
119 ******************************************************************************/
Dan Handley2b6b5742015-03-19 19:17:53 +0000120void fvp_config_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100121{
Soby Mathew8e2f2872014-08-14 12:49:05 +0100122 unsigned int rev, hbi, bld, arch, sys_id;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100123
Dan Handley2b6b5742015-03-19 19:17:53 +0000124 sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
125 rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
126 hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
127 bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
128 arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129
Andrew Thoelke960347d2014-06-26 14:27:26 +0100130 if (arch != ARCH_MODEL) {
131 ERROR("This firmware is for FVP models\n");
James Morrissey40a6f642014-02-10 14:24:36 +0000132 panic();
Andrew Thoelke960347d2014-06-26 14:27:26 +0100133 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134
135 /*
136 * The build field in the SYS_ID tells which variant of the GIC
137 * memory is implemented by the model.
138 */
139 switch (bld) {
140 case BLD_GIC_VE_MMAP:
Soby Mathewcf022c52016-01-13 17:06:00 +0000141 ERROR("Legacy Versatile Express memory map for GIC peripheral"
142 " is not supported\n");
Achin Gupta1fa7eb62015-11-03 14:18:34 +0000143 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100144 break;
145 case BLD_GIC_A53A57_MMAP:
Achin Gupta4f6ad662013-10-25 09:08:21 +0100146 break;
147 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100148 ERROR("Unsupported board build %x\n", bld);
149 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100150 }
151
152 /*
153 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
154 * for the Foundation FVP.
155 */
156 switch (hbi) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000157 case HBI_FOUNDATION_FVP:
Dan Handley2b6b5742015-03-19 19:17:53 +0000158 arm_config.flags = 0;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100159
160 /*
161 * Check for supported revisions of Foundation FVP
162 * Allow future revisions to run but emit warning diagnostic
163 */
164 switch (rev) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000165 case REV_FOUNDATION_FVP_V2_0:
166 case REV_FOUNDATION_FVP_V2_1:
167 case REV_FOUNDATION_FVP_v9_1:
Sandrine Bailleux8b33d702016-09-22 09:46:50 +0100168 case REV_FOUNDATION_FVP_v9_6:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100169 break;
170 default:
171 WARN("Unrecognized Foundation FVP revision %x\n", rev);
172 break;
173 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100174 break;
Dan Handley2b6b5742015-03-19 19:17:53 +0000175 case HBI_BASE_FVP:
Dan Handley2b6b5742015-03-19 19:17:53 +0000176 arm_config.flags |= ARM_CONFIG_BASE_MMAP |
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000177 ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100178
179 /*
180 * Check for supported revisions
181 * Allow future revisions to run but emit warning diagnostic
182 */
183 switch (rev) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000184 case REV_BASE_FVP_V0:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100185 break;
186 default:
187 WARN("Unrecognized Base FVP revision %x\n", rev);
188 break;
189 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100190 break;
191 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100192 ERROR("Unsupported board HBI number 0x%x\n", hbi);
193 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100194 }
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100195}
Vikram Kanigiri96377452014-04-24 11:02:16 +0100196
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000197
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000198void fvp_interconnect_init(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100199{
Soby Mathew7356b1e2016-03-24 10:12:42 +0000200 if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) {
201#if FVP_INTERCONNECT_DRIVER == FVP_CCN
202 if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
203 ERROR("Unrecognized CCN variant detected. Only CCN-502"
204 " is supported");
205 panic();
206 }
207#endif
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000208 plat_arm_interconnect_init();
Soby Mathew7356b1e2016-03-24 10:12:42 +0000209 }
Dan Handleybe234f92014-08-04 16:11:15 +0100210}
211
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000212void fvp_interconnect_enable(void)
Dan Handleybe234f92014-08-04 16:11:15 +0100213{
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000214 if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
215 plat_arm_interconnect_enter_coherency();
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000216}
217
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000218void fvp_interconnect_disable(void)
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000219{
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000220 if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
221 plat_arm_interconnect_exit_coherency();
Vikram Kanigiri96377452014-04-24 11:02:16 +0100222}