Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 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 Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 31 | #include <arm_config.h> |
| 32 | #include <arm_def.h> |
Dan Handley | fb42b12 | 2014-06-20 09:43:15 +0100 | [diff] [blame] | 33 | #include <arm_gic.h> |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 34 | #include <cci.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 35 | #include <debug.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 36 | #include <mmio.h> |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 37 | #include <plat_arm.h> |
| 38 | #include <v2m_def.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 39 | #include "../fvp_def.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 40 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | /******************************************************************************* |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 42 | * 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 Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 45 | * configuration) & used thereafter. Each BL will have its own copy to allow |
| 46 | * independent operation. |
| 47 | ******************************************************************************/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 48 | arm_config_t arm_config; |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 49 | |
| 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 | |
Juan Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 58 | #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \ |
| 59 | DEVICE2_SIZE, \ |
| 60 | MT_DEVICE | MT_RO | MT_SECURE) |
| 61 | |
| 62 | |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 63 | /* |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 64 | * Table of regions for various BL stages to map using the MMU. |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 65 | * This doesn't include TZRAM as the 'mem_layout' argument passed to |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 66 | * arm_configure_mmu_elx() will give the available subset of that, |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 67 | */ |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 68 | #if IMAGE_BL1 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 69 | const mmap_region_t plat_arm_mmap[] = { |
| 70 | ARM_MAP_SHARED_RAM, |
| 71 | V2M_MAP_FLASH0, |
| 72 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 73 | MAP_DEVICE0, |
| 74 | MAP_DEVICE1, |
Juan Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 75 | MAP_DEVICE2, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 76 | {0} |
| 77 | }; |
| 78 | #endif |
| 79 | #if IMAGE_BL2 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 80 | const mmap_region_t plat_arm_mmap[] = { |
| 81 | ARM_MAP_SHARED_RAM, |
| 82 | V2M_MAP_FLASH0, |
| 83 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 84 | MAP_DEVICE0, |
| 85 | MAP_DEVICE1, |
Juan Castillo | 31a68f0 | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 86 | MAP_DEVICE2, |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 87 | ARM_MAP_NS_DRAM1, |
| 88 | ARM_MAP_TSP_SEC_MEM, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 89 | {0} |
| 90 | }; |
| 91 | #endif |
| 92 | #if IMAGE_BL31 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 93 | const mmap_region_t plat_arm_mmap[] = { |
| 94 | ARM_MAP_SHARED_RAM, |
| 95 | V2M_MAP_IOFPGA, |
Soby Mathew | b08bc04 | 2014-09-03 17:48:44 +0100 | [diff] [blame] | 96 | MAP_DEVICE0, |
| 97 | MAP_DEVICE1, |
| 98 | {0} |
| 99 | }; |
| 100 | #endif |
| 101 | #if IMAGE_BL32 |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 102 | const mmap_region_t plat_arm_mmap[] = { |
| 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 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 112 | |
| 113 | #if IMAGE_BL31 || IMAGE_BL32 |
Dan Handley | fb42b12 | 2014-06-20 09:43:15 +0100 | [diff] [blame] | 114 | /* Array of secure interrupts to be configured by the gic driver */ |
| 115 | const unsigned int irq_sec_array[] = { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 116 | ARM_IRQ_SEC_PHY_TIMER, |
| 117 | ARM_IRQ_SEC_SGI_0, |
| 118 | ARM_IRQ_SEC_SGI_1, |
| 119 | ARM_IRQ_SEC_SGI_2, |
| 120 | ARM_IRQ_SEC_SGI_3, |
| 121 | ARM_IRQ_SEC_SGI_4, |
| 122 | ARM_IRQ_SEC_SGI_5, |
| 123 | ARM_IRQ_SEC_SGI_6, |
Vikram Kanigiri | f3bcea2 | 2015-06-24 17:51:09 +0100 | [diff] [blame] | 124 | ARM_IRQ_SEC_SGI_7, |
| 125 | FVP_IRQ_TZ_WDOG, |
| 126 | FVP_IRQ_SEC_SYS_TIMER |
Dan Handley | fb42b12 | 2014-06-20 09:43:15 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 129 | void plat_arm_gic_init(void) |
| 130 | { |
| 131 | arm_gic_init(arm_config.gicc_base, |
| 132 | arm_config.gicd_base, |
| 133 | BASE_GICR_BASE, |
| 134 | irq_sec_array, |
| 135 | ARRAY_SIZE(irq_sec_array)); |
| 136 | } |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 137 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 138 | #endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 139 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 140 | /******************************************************************************* |
| 141 | * A single boot loader stack is expected to work on both the Foundation FVP |
| 142 | * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The |
| 143 | * SYS_ID register provides a mechanism for detecting the differences between |
| 144 | * these platforms. This information is stored in a per-BL array to allow the |
| 145 | * code to take the correct path.Per BL platform configuration. |
| 146 | ******************************************************************************/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 147 | void fvp_config_setup(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 148 | { |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 149 | unsigned int rev, hbi, bld, arch, sys_id; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 150 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 151 | sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID); |
| 152 | rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK; |
| 153 | hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK; |
| 154 | bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK; |
| 155 | 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] | 156 | |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 157 | if (arch != ARCH_MODEL) { |
| 158 | ERROR("This firmware is for FVP models\n"); |
James Morrissey | 40a6f64 | 2014-02-10 14:24:36 +0000 | [diff] [blame] | 159 | panic(); |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 160 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 161 | |
| 162 | /* |
| 163 | * The build field in the SYS_ID tells which variant of the GIC |
| 164 | * memory is implemented by the model. |
| 165 | */ |
| 166 | switch (bld) { |
| 167 | case BLD_GIC_VE_MMAP: |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 168 | arm_config.gicd_base = VE_GICD_BASE; |
| 169 | arm_config.gicc_base = VE_GICC_BASE; |
| 170 | arm_config.gich_base = VE_GICH_BASE; |
| 171 | arm_config.gicv_base = VE_GICV_BASE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 172 | break; |
| 173 | case BLD_GIC_A53A57_MMAP: |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 174 | arm_config.gicd_base = BASE_GICD_BASE; |
| 175 | arm_config.gicc_base = BASE_GICC_BASE; |
| 176 | arm_config.gich_base = BASE_GICH_BASE; |
| 177 | arm_config.gicv_base = BASE_GICV_BASE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 178 | break; |
| 179 | default: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 180 | ERROR("Unsupported board build %x\n", bld); |
| 181 | panic(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* |
| 185 | * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010 |
| 186 | * for the Foundation FVP. |
| 187 | */ |
| 188 | switch (hbi) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 189 | case HBI_FOUNDATION_FVP: |
| 190 | arm_config.max_aff0 = 4; |
| 191 | arm_config.max_aff1 = 1; |
| 192 | arm_config.flags = 0; |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | * Check for supported revisions of Foundation FVP |
| 196 | * Allow future revisions to run but emit warning diagnostic |
| 197 | */ |
| 198 | switch (rev) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 199 | case REV_FOUNDATION_FVP_V2_0: |
| 200 | case REV_FOUNDATION_FVP_V2_1: |
| 201 | case REV_FOUNDATION_FVP_v9_1: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 202 | break; |
| 203 | default: |
| 204 | WARN("Unrecognized Foundation FVP revision %x\n", rev); |
| 205 | break; |
| 206 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 207 | break; |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 208 | case HBI_BASE_FVP: |
| 209 | arm_config.max_aff0 = 4; |
| 210 | arm_config.max_aff1 = 2; |
| 211 | arm_config.flags |= ARM_CONFIG_BASE_MMAP | |
| 212 | ARM_CONFIG_HAS_CCI | ARM_CONFIG_HAS_TZC; |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Check for supported revisions |
| 216 | * Allow future revisions to run but emit warning diagnostic |
| 217 | */ |
| 218 | switch (rev) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 219 | case REV_BASE_FVP_V0: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 220 | break; |
| 221 | default: |
| 222 | WARN("Unrecognized Base FVP revision %x\n", rev); |
| 223 | break; |
| 224 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 225 | break; |
| 226 | default: |
Andrew Thoelke | 960347d | 2014-06-26 14:27:26 +0100 | [diff] [blame] | 227 | ERROR("Unsupported board HBI number 0x%x\n", hbi); |
| 228 | panic(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 229 | } |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 230 | } |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 231 | |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 232 | |
Dan Handley | be234f9 | 2014-08-04 16:11:15 +0100 | [diff] [blame] | 233 | void fvp_cci_init(void) |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 234 | { |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 235 | /* |
Dan Handley | be234f9 | 2014-08-04 16:11:15 +0100 | [diff] [blame] | 236 | * Initialize CCI-400 driver |
| 237 | */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 238 | if (arm_config.flags & ARM_CONFIG_HAS_CCI) |
| 239 | arm_cci_init(); |
Dan Handley | be234f9 | 2014-08-04 16:11:15 +0100 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void fvp_cci_enable(void) |
| 243 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 244 | if (arm_config.flags & ARM_CONFIG_HAS_CCI) |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 245 | cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr())); |
| 246 | } |
| 247 | |
| 248 | void fvp_cci_disable(void) |
| 249 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 250 | if (arm_config.flags & ARM_CONFIG_HAS_CCI) |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 251 | cci_disable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr())); |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 252 | } |