blob: 2f5d7fcf5f64407ab8d13c50e695aaacfeef2d90 [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
Sandrine Bailleuxd9160a52017-05-26 15:48:10 +010039/*
40 * Need to be mapped with write permissions in order to set a new non-volatile
41 * counter value.
42 */
Juan Castillo31a68f02015-04-14 12:49:03 +010043#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
44 DEVICE2_SIZE, \
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +010045 MT_DEVICE | MT_RW | MT_SECURE)
Juan Castillo31a68f02015-04-14 12:49:03 +010046
47
Jon Medhurstb1eb0932014-02-26 16:27:53 +000048/*
Sandrine Bailleux4a1267a2016-05-18 16:11:47 +010049 * Table of memory regions for various BL stages to map using the MMU.
50 * This doesn't include Trusted SRAM as arm_setup_page_tables() already
51 * takes care of mapping it.
Sandrine Bailleux889ca032016-06-14 17:01:00 +010052 *
53 * The flash needs to be mapped as writable in order to erase the FIP's Table of
54 * Contents in case of unrecoverable error (see plat_error_handler()).
Jon Medhurstb1eb0932014-02-26 16:27:53 +000055 */
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090056#ifdef IMAGE_BL1
Dan Handley2b6b5742015-03-19 19:17:53 +000057const mmap_region_t plat_arm_mmap[] = {
58 ARM_MAP_SHARED_RAM,
Juan Castillob6132f12015-10-06 14:01:35 +010059 V2M_MAP_FLASH0_RW,
Dan Handley2b6b5742015-03-19 19:17:53 +000060 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010061 MAP_DEVICE0,
62 MAP_DEVICE1,
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010063#if TRUSTED_BOARD_BOOT
Sandrine Bailleuxd9160a52017-05-26 15:48:10 +010064 /* To access the Root of Trust Public Key registers. */
65 MAP_DEVICE2,
66 /* Map DRAM to authenticate NS_BL2U image. */
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010067 ARM_MAP_NS_DRAM1,
68#endif
Soby Mathewb08bc042014-09-03 17:48:44 +010069 {0}
70};
71#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090072#ifdef IMAGE_BL2
Dan Handley2b6b5742015-03-19 19:17:53 +000073const mmap_region_t plat_arm_mmap[] = {
74 ARM_MAP_SHARED_RAM,
Juan Castillob6132f12015-10-06 14:01:35 +010075 V2M_MAP_FLASH0_RW,
Dan Handley2b6b5742015-03-19 19:17:53 +000076 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +010077 MAP_DEVICE0,
78 MAP_DEVICE1,
Dan Handley2b6b5742015-03-19 19:17:53 +000079 ARM_MAP_NS_DRAM1,
80 ARM_MAP_TSP_SEC_MEM,
Sandrine Bailleuxd9160a52017-05-26 15:48:10 +010081#if TRUSTED_BOARD_BOOT
82 /* To access the Root of Trust Public Key registers. */
83 MAP_DEVICE2,
84#endif
David Wang0ba499f2016-03-07 11:02:57 +080085#if ARM_BL31_IN_DRAM
86 ARM_MAP_BL31_SEC_DRAM,
87#endif
Soby Mathewb08bc042014-09-03 17:48:44 +010088 {0}
89};
90#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090091#ifdef IMAGE_BL2U
Yatharth Kochar3a11eda2015-10-14 15:28:11 +010092const mmap_region_t plat_arm_mmap[] = {
93 MAP_DEVICE0,
94 V2M_MAP_IOFPGA,
95 {0}
96};
97#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090098#ifdef IMAGE_BL31
Dan Handley2b6b5742015-03-19 19:17:53 +000099const mmap_region_t plat_arm_mmap[] = {
100 ARM_MAP_SHARED_RAM,
101 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +0100102 MAP_DEVICE0,
103 MAP_DEVICE1,
104 {0}
105};
106#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900107#ifdef IMAGE_BL32
Dan Handley2b6b5742015-03-19 19:17:53 +0000108const mmap_region_t plat_arm_mmap[] = {
Soby Mathew0d268dc2016-07-11 14:13:56 +0100109#ifdef AARCH32
110 ARM_MAP_SHARED_RAM,
111#endif
Dan Handley2b6b5742015-03-19 19:17:53 +0000112 V2M_MAP_IOFPGA,
Soby Mathewb08bc042014-09-03 17:48:44 +0100113 MAP_DEVICE0,
114 MAP_DEVICE1,
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000115 {0}
116};
Soby Mathewb08bc042014-09-03 17:48:44 +0100117#endif
Jon Medhurstb1eb0932014-02-26 16:27:53 +0000118
Dan Handley2b6b5742015-03-19 19:17:53 +0000119ARM_CASSERT_MMAP
Soby Mathew13ee9682015-01-22 11:22:22 +0000120
Achin Gupta4f6ad662013-10-25 09:08:21 +0100121
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122/*******************************************************************************
123 * A single boot loader stack is expected to work on both the Foundation FVP
124 * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
125 * SYS_ID register provides a mechanism for detecting the differences between
126 * these platforms. This information is stored in a per-BL array to allow the
127 * code to take the correct path.Per BL platform configuration.
128 ******************************************************************************/
Dan Handley2b6b5742015-03-19 19:17:53 +0000129void fvp_config_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100130{
Soby Mathew8e2f2872014-08-14 12:49:05 +0100131 unsigned int rev, hbi, bld, arch, sys_id;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132
Dan Handley2b6b5742015-03-19 19:17:53 +0000133 sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
134 rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
135 hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
136 bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
137 arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
Andrew Thoelke960347d2014-06-26 14:27:26 +0100139 if (arch != ARCH_MODEL) {
140 ERROR("This firmware is for FVP models\n");
James Morrissey40a6f642014-02-10 14:24:36 +0000141 panic();
Andrew Thoelke960347d2014-06-26 14:27:26 +0100142 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100143
144 /*
145 * The build field in the SYS_ID tells which variant of the GIC
146 * memory is implemented by the model.
147 */
148 switch (bld) {
149 case BLD_GIC_VE_MMAP:
Soby Mathewcf022c52016-01-13 17:06:00 +0000150 ERROR("Legacy Versatile Express memory map for GIC peripheral"
151 " is not supported\n");
Achin Gupta1fa7eb62015-11-03 14:18:34 +0000152 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100153 break;
154 case BLD_GIC_A53A57_MMAP:
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) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000166 case HBI_FOUNDATION_FVP:
Dan Handley2b6b5742015-03-19 19:17:53 +0000167 arm_config.flags = 0;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100168
169 /*
170 * Check for supported revisions of Foundation FVP
171 * Allow future revisions to run but emit warning diagnostic
172 */
173 switch (rev) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000174 case REV_FOUNDATION_FVP_V2_0:
175 case REV_FOUNDATION_FVP_V2_1:
176 case REV_FOUNDATION_FVP_v9_1:
Sandrine Bailleux8b33d702016-09-22 09:46:50 +0100177 case REV_FOUNDATION_FVP_v9_6:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100178 break;
179 default:
180 WARN("Unrecognized Foundation FVP revision %x\n", rev);
181 break;
182 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100183 break;
Dan Handley2b6b5742015-03-19 19:17:53 +0000184 case HBI_BASE_FVP:
Dan Handley2b6b5742015-03-19 19:17:53 +0000185 arm_config.flags |= ARM_CONFIG_BASE_MMAP |
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000186 ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC;
Andrew Thoelke960347d2014-06-26 14:27:26 +0100187
188 /*
189 * Check for supported revisions
190 * Allow future revisions to run but emit warning diagnostic
191 */
192 switch (rev) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000193 case REV_BASE_FVP_V0:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100194 break;
195 default:
196 WARN("Unrecognized Base FVP revision %x\n", rev);
197 break;
198 }
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199 break;
200 default:
Andrew Thoelke960347d2014-06-26 14:27:26 +0100201 ERROR("Unsupported board HBI number 0x%x\n", hbi);
202 panic();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100203 }
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100204}
Vikram Kanigiri96377452014-04-24 11:02:16 +0100205
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000206
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000207void fvp_interconnect_init(void)
Vikram Kanigiri96377452014-04-24 11:02:16 +0100208{
Soby Mathew7356b1e2016-03-24 10:12:42 +0000209 if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) {
210#if FVP_INTERCONNECT_DRIVER == FVP_CCN
211 if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
212 ERROR("Unrecognized CCN variant detected. Only CCN-502"
213 " is supported");
214 panic();
215 }
216#endif
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000217 plat_arm_interconnect_init();
Soby Mathew7356b1e2016-03-24 10:12:42 +0000218 }
Dan Handleybe234f92014-08-04 16:11:15 +0100219}
220
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000221void fvp_interconnect_enable(void)
Dan Handleybe234f92014-08-04 16:11:15 +0100222{
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000223 if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
224 plat_arm_interconnect_enter_coherency();
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000225}
226
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000227void fvp_interconnect_disable(void)
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000228{
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000229 if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
230 plat_arm_interconnect_exit_coherency();
Vikram Kanigiri96377452014-04-24 11:02:16 +0100231}