Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 7 | #include <arm_config.h> |
| 8 | #include <arm_def.h> |
Soby Mathew | 7356b1e | 2016-03-24 10:12:42 +0000 | [diff] [blame] | 9 | #include <ccn.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 10 | #include <debug.h> |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 11 | #include <gicv2.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 12 | #include <mmio.h> |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 13 | #include <plat_arm.h> |
| 14 | #include <v2m_def.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 15 | #include "../fvp_def.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 16 | |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 17 | /* 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 Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 22 | /******************************************************************************* |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 23 | * 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 Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 25 | * 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 Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 28 | ******************************************************************************/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 29 | arm_config_t arm_config; |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 30 | |
| 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 Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 39 | #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \ |
| 40 | DEVICE2_SIZE, \ |
Antonio Nino Diaz | 9d602fe | 2016-05-20 14:14:16 +0100 | [diff] [blame] | 41 | MT_DEVICE | MT_RW | MT_SECURE) |
Juan Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 42 | |
| 43 | |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 44 | /* |
Sandrine Bailleux | 4a1267a | 2016-05-18 16:11:47 +0100 | [diff] [blame] | 45 | * 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 Bailleux | 889ca03 | 2016-06-14 17:01:00 +0100 | [diff] [blame] | 48 | * |
| 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 Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 51 | */ |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 52 | #ifdef IMAGE_BL1 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 53 | const mmap_region_t plat_arm_mmap[] = { |
| 54 | ARM_MAP_SHARED_RAM, |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 55 | V2M_MAP_FLASH0_RW, |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 56 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 57 | MAP_DEVICE0, |
| 58 | MAP_DEVICE1, |
Juan Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 59 | MAP_DEVICE2, |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 60 | #if TRUSTED_BOARD_BOOT |
| 61 | ARM_MAP_NS_DRAM1, |
| 62 | #endif |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 63 | {0} |
| 64 | }; |
| 65 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 66 | #ifdef IMAGE_BL2 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 67 | const mmap_region_t plat_arm_mmap[] = { |
| 68 | ARM_MAP_SHARED_RAM, |
Juan Castillo | b6132f1 | 2015-10-06 14:01:35 +0100 | [diff] [blame] | 69 | V2M_MAP_FLASH0_RW, |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 70 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 71 | MAP_DEVICE0, |
| 72 | MAP_DEVICE1, |
Juan Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 73 | MAP_DEVICE2, |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 74 | ARM_MAP_NS_DRAM1, |
| 75 | ARM_MAP_TSP_SEC_MEM, |
David Wang | 0ba499f | 2016-03-07 11:02:57 +0800 | [diff] [blame] | 76 | #if ARM_BL31_IN_DRAM |
| 77 | ARM_MAP_BL31_SEC_DRAM, |
| 78 | #endif |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 79 | {0} |
| 80 | }; |
| 81 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 82 | #ifdef IMAGE_BL2U |
Yatharth Kochar | 3a11eda | 2015-10-14 15:28:11 +0100 | [diff] [blame] | 83 | const mmap_region_t plat_arm_mmap[] = { |
| 84 | MAP_DEVICE0, |
| 85 | V2M_MAP_IOFPGA, |
| 86 | {0} |
| 87 | }; |
| 88 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 89 | #ifdef IMAGE_BL31 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 90 | const mmap_region_t plat_arm_mmap[] = { |
| 91 | ARM_MAP_SHARED_RAM, |
| 92 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 93 | MAP_DEVICE0, |
| 94 | MAP_DEVICE1, |
| 95 | {0} |
| 96 | }; |
| 97 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 98 | #ifdef IMAGE_BL32 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 99 | const mmap_region_t plat_arm_mmap[] = { |
Soby Mathew | 0d268dc | 2016-07-11 14:13:56 +0100 | [diff] [blame] | 100 | #ifdef AARCH32 |
| 101 | ARM_MAP_SHARED_RAM, |
| 102 | #endif |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 103 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 104 | MAP_DEVICE0, |
| 105 | MAP_DEVICE1, |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 106 | {0} |
| 107 | }; |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 108 | #endif |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 109 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 110 | ARM_CASSERT_MMAP |
Soby Mathew | 13ee968 | 2015-01-22 11:22:22 +0000 | [diff] [blame] | 111 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 112 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 113 | /******************************************************************************* |
| 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 Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 120 | void fvp_config_setup(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 121 | { |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 122 | unsigned int rev, hbi, bld, arch, sys_id; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 123 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 124 | 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 Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 129 | |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 130 | if (arch != ARCH_MODEL) { |
| 131 | ERROR("This firmware is for FVP models\n"); |
James Morrissey | 40a6f64 | 2014-02-10 14:24:36 +0000 | [diff] [blame] | 132 | panic(); |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 133 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | |
| 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 Mathew | cf022c5 | 2016-01-13 17:06:00 +0000 | [diff] [blame] | 141 | ERROR("Legacy Versatile Express memory map for GIC peripheral" |
| 142 | " is not supported\n"); |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 143 | panic(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 144 | break; |
| 145 | case BLD_GIC_A53A57_MMAP: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 146 | break; |
| 147 | default: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 148 | ERROR("Unsupported board build %x\n", bld); |
| 149 | panic(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 150 | } |
| 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 Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 157 | case HBI_FOUNDATION_FVP: |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 158 | arm_config.flags = 0; |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * Check for supported revisions of Foundation FVP |
| 162 | * Allow future revisions to run but emit warning diagnostic |
| 163 | */ |
| 164 | switch (rev) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 165 | case REV_FOUNDATION_FVP_V2_0: |
| 166 | case REV_FOUNDATION_FVP_V2_1: |
| 167 | case REV_FOUNDATION_FVP_v9_1: |
Sandrine Bailleux | 8b33d70 | 2016-09-22 09:46:50 +0100 | [diff] [blame] | 168 | case REV_FOUNDATION_FVP_v9_6: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 169 | break; |
| 170 | default: |
| 171 | WARN("Unrecognized Foundation FVP revision %x\n", rev); |
| 172 | break; |
| 173 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 174 | break; |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 175 | case HBI_BASE_FVP: |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 176 | arm_config.flags |= ARM_CONFIG_BASE_MMAP | |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 177 | ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC; |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Check for supported revisions |
| 181 | * Allow future revisions to run but emit warning diagnostic |
| 182 | */ |
| 183 | switch (rev) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 184 | case REV_BASE_FVP_V0: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 185 | break; |
| 186 | default: |
| 187 | WARN("Unrecognized Base FVP revision %x\n", rev); |
| 188 | break; |
| 189 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 190 | break; |
| 191 | default: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 192 | ERROR("Unsupported board HBI number 0x%x\n", hbi); |
| 193 | panic(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 194 | } |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 195 | } |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 196 | |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 197 | |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 198 | void fvp_interconnect_init(void) |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 199 | { |
Soby Mathew | 7356b1e | 2016-03-24 10:12:42 +0000 | [diff] [blame] | 200 | 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 Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 208 | plat_arm_interconnect_init(); |
Soby Mathew | 7356b1e | 2016-03-24 10:12:42 +0000 | [diff] [blame] | 209 | } |
Dan Handley | be234f9 | 2014-08-04 16:11:15 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 212 | void fvp_interconnect_enable(void) |
Dan Handley | be234f9 | 2014-08-04 16:11:15 +0100 | [diff] [blame] | 213 | { |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 214 | if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) |
| 215 | plat_arm_interconnect_enter_coherency(); |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 218 | void fvp_interconnect_disable(void) |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 219 | { |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 220 | if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) |
| 221 | plat_arm_interconnect_exit_coherency(); |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 222 | } |