Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, 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 | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 31 | #include <arch.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 32 | #include <arch_helpers.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 33 | #include <assert.h> |
| 34 | #include <bl_common.h> |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 35 | #include <cci400.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 36 | #include <debug.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 37 | #include <mmio.h> |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 38 | #include <platform.h> |
| 39 | #include <xlat_tables.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 40 | #include "../fvp_def.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 42 | /******************************************************************************* |
| 43 | * This array holds the characteristics of the differences between the three |
| 44 | * FVP platforms (Base, A53_A57 & Foundation). It will be populated during cold |
| 45 | * boot at each boot stage by the primary before enabling the MMU (to allow cci |
| 46 | * configuration) & used thereafter. Each BL will have its own copy to allow |
| 47 | * independent operation. |
| 48 | ******************************************************************************/ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 49 | static unsigned long fvp_config[CONFIG_LIMIT]; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 50 | |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 51 | /* |
| 52 | * Table of regions to map using the MMU. |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 53 | * This doesn't include TZRAM as the 'mem_layout' argument passed to |
| 54 | * configure_mmu_elx() will give the available subset of that, |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 55 | */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 56 | const mmap_region_t fvp_mmap[] = { |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 57 | { TZROM_BASE, TZROM_SIZE, MT_MEMORY | MT_RO | MT_SECURE }, |
| 58 | { TZDRAM_BASE, TZDRAM_SIZE, MT_MEMORY | MT_RW | MT_SECURE }, |
| 59 | { FLASH0_BASE, FLASH0_SIZE, MT_MEMORY | MT_RO | MT_SECURE }, |
| 60 | { FLASH1_BASE, FLASH1_SIZE, MT_MEMORY | MT_RO | MT_SECURE }, |
| 61 | { VRAM_BASE, VRAM_SIZE, MT_MEMORY | MT_RW | MT_SECURE }, |
| 62 | { DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE }, |
| 63 | { NSRAM_BASE, NSRAM_SIZE, MT_MEMORY | MT_RW | MT_NS }, |
| 64 | { DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE }, |
| 65 | /* 2nd GB as device for now...*/ |
| 66 | { 0x40000000, 0x40000000, MT_DEVICE | MT_RW | MT_SECURE }, |
Juan Castillo | 7055ca4 | 2014-05-16 15:33:15 +0100 | [diff] [blame] | 67 | { DRAM1_BASE, DRAM1_SIZE, MT_MEMORY | MT_RW | MT_NS }, |
Jon Medhurst | b1eb093 | 2014-02-26 16:27:53 +0000 | [diff] [blame] | 68 | {0} |
| 69 | }; |
| 70 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 71 | /******************************************************************************* |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 72 | * Macro generating the code for the function setting up the pagetables as per |
| 73 | * the platform memory map & initialize the mmu, for the given exception level |
| 74 | ******************************************************************************/ |
| 75 | #define DEFINE_CONFIGURE_MMU_EL(_el) \ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 76 | void fvp_configure_mmu_el##_el(unsigned long total_base, \ |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 77 | unsigned long total_size, \ |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 78 | unsigned long ro_start, \ |
| 79 | unsigned long ro_limit, \ |
| 80 | unsigned long coh_start, \ |
| 81 | unsigned long coh_limit) \ |
| 82 | { \ |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 83 | mmap_add_region(total_base, \ |
| 84 | total_size, \ |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 85 | MT_MEMORY | MT_RW | MT_SECURE); \ |
| 86 | mmap_add_region(ro_start, ro_limit - ro_start, \ |
| 87 | MT_MEMORY | MT_RO | MT_SECURE); \ |
| 88 | mmap_add_region(coh_start, coh_limit - coh_start, \ |
| 89 | MT_DEVICE | MT_RW | MT_SECURE); \ |
| 90 | mmap_add(fvp_mmap); \ |
| 91 | init_xlat_tables(); \ |
| 92 | \ |
| 93 | enable_mmu_el##_el(); \ |
| 94 | } |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 95 | |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 96 | /* Define EL1 and EL3 variants of the function initialising the MMU */ |
| 97 | DEFINE_CONFIGURE_MMU_EL(1) |
| 98 | DEFINE_CONFIGURE_MMU_EL(3) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 99 | |
| 100 | /* Simple routine which returns a configuration variable value */ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 101 | unsigned long fvp_get_cfgvar(unsigned int var_id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 102 | { |
| 103 | assert(var_id < CONFIG_LIMIT); |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 104 | return fvp_config[var_id]; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /******************************************************************************* |
| 108 | * A single boot loader stack is expected to work on both the Foundation FVP |
| 109 | * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The |
| 110 | * SYS_ID register provides a mechanism for detecting the differences between |
| 111 | * these platforms. This information is stored in a per-BL array to allow the |
| 112 | * code to take the correct path.Per BL platform configuration. |
| 113 | ******************************************************************************/ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 114 | int fvp_config_setup(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | { |
| 116 | unsigned int rev, hbi, bld, arch, sys_id, midr_pn; |
| 117 | |
| 118 | sys_id = mmio_read_32(VE_SYSREGS_BASE + V2M_SYS_ID); |
| 119 | rev = (sys_id >> SYS_ID_REV_SHIFT) & SYS_ID_REV_MASK; |
| 120 | hbi = (sys_id >> SYS_ID_HBI_SHIFT) & SYS_ID_HBI_MASK; |
| 121 | bld = (sys_id >> SYS_ID_BLD_SHIFT) & SYS_ID_BLD_MASK; |
| 122 | arch = (sys_id >> SYS_ID_ARCH_SHIFT) & SYS_ID_ARCH_MASK; |
| 123 | |
James Morrissey | 40a6f64 | 2014-02-10 14:24:36 +0000 | [diff] [blame] | 124 | if ((rev != REV_FVP) || (arch != ARCH_MODEL)) |
| 125 | panic(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * The build field in the SYS_ID tells which variant of the GIC |
| 129 | * memory is implemented by the model. |
| 130 | */ |
| 131 | switch (bld) { |
| 132 | case BLD_GIC_VE_MMAP: |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 133 | fvp_config[CONFIG_GICD_ADDR] = VE_GICD_BASE; |
| 134 | fvp_config[CONFIG_GICC_ADDR] = VE_GICC_BASE; |
| 135 | fvp_config[CONFIG_GICH_ADDR] = VE_GICH_BASE; |
| 136 | fvp_config[CONFIG_GICV_ADDR] = VE_GICV_BASE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 137 | break; |
| 138 | case BLD_GIC_A53A57_MMAP: |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 139 | fvp_config[CONFIG_GICD_ADDR] = BASE_GICD_BASE; |
| 140 | fvp_config[CONFIG_GICC_ADDR] = BASE_GICC_BASE; |
| 141 | fvp_config[CONFIG_GICH_ADDR] = BASE_GICH_BASE; |
| 142 | fvp_config[CONFIG_GICV_ADDR] = BASE_GICV_BASE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 143 | break; |
| 144 | default: |
| 145 | assert(0); |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010 |
| 150 | * for the Foundation FVP. |
| 151 | */ |
| 152 | switch (hbi) { |
| 153 | case HBI_FOUNDATION: |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 154 | fvp_config[CONFIG_MAX_AFF0] = 4; |
| 155 | fvp_config[CONFIG_MAX_AFF1] = 1; |
| 156 | fvp_config[CONFIG_CPU_SETUP] = 0; |
| 157 | fvp_config[CONFIG_BASE_MMAP] = 0; |
| 158 | fvp_config[CONFIG_HAS_CCI] = 0; |
| 159 | fvp_config[CONFIG_HAS_TZC] = 0; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | break; |
| 161 | case HBI_FVP_BASE: |
| 162 | midr_pn = (read_midr() >> MIDR_PN_SHIFT) & MIDR_PN_MASK; |
| 163 | if ((midr_pn == MIDR_PN_A57) || (midr_pn == MIDR_PN_A53)) |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 164 | fvp_config[CONFIG_CPU_SETUP] = 1; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 165 | else |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 166 | fvp_config[CONFIG_CPU_SETUP] = 0; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 167 | |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 168 | fvp_config[CONFIG_MAX_AFF0] = 4; |
| 169 | fvp_config[CONFIG_MAX_AFF1] = 2; |
| 170 | fvp_config[CONFIG_BASE_MMAP] = 1; |
| 171 | fvp_config[CONFIG_HAS_CCI] = 1; |
| 172 | fvp_config[CONFIG_HAS_TZC] = 1; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 173 | break; |
| 174 | default: |
| 175 | assert(0); |
| 176 | } |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Ian Spray | 8468739 | 2014-01-02 16:57:12 +0000 | [diff] [blame] | 181 | unsigned long plat_get_ns_image_entrypoint(void) |
| 182 | { |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 183 | return NS_IMAGE_OFFSET; |
| 184 | } |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 185 | |
| 186 | uint64_t plat_get_syscnt_freq(void) |
| 187 | { |
| 188 | uint64_t counter_base_frequency; |
| 189 | |
| 190 | /* Read the frequency from Frequency modes table */ |
| 191 | counter_base_frequency = mmio_read_32(SYS_CNTCTL_BASE + CNTFID_OFF); |
| 192 | |
| 193 | /* The first entry of the frequency modes table must not be 0 */ |
| 194 | assert(counter_base_frequency != 0); |
| 195 | |
| 196 | return counter_base_frequency; |
| 197 | } |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 198 | |
| 199 | void fvp_cci_setup(void) |
| 200 | { |
| 201 | unsigned long cci_setup; |
| 202 | |
| 203 | /* |
| 204 | * Enable CCI-400 for this cluster. No need |
| 205 | * for locks as no other cpu is active at the |
| 206 | * moment |
| 207 | */ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 208 | cci_setup = fvp_get_cfgvar(CONFIG_HAS_CCI); |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 209 | if (cci_setup) |
| 210 | cci_enable_coherency(read_mpidr()); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /******************************************************************************* |
| 215 | * Set SPSR and secure state for BL32 image |
| 216 | ******************************************************************************/ |
| 217 | void fvp_set_bl32_ep_info(entry_point_info_t *bl32_ep_info) |
| 218 | { |
| 219 | SET_SECURITY_STATE(bl32_ep_info->h.attr, SECURE); |
| 220 | /* |
| 221 | * The Secure Payload Dispatcher service is responsible for |
| 222 | * setting the SPSR prior to entry into the BL32 image. |
| 223 | */ |
| 224 | bl32_ep_info->spsr = 0; |
| 225 | } |
| 226 | |
| 227 | /******************************************************************************* |
| 228 | * Set SPSR and secure state for BL33 image |
| 229 | ******************************************************************************/ |
| 230 | void fvp_set_bl33_ep_info(entry_point_info_t *bl33_ep_info) |
| 231 | { |
| 232 | unsigned long el_status; |
| 233 | unsigned int mode; |
| 234 | |
| 235 | /* Figure out what mode we enter the non-secure world in */ |
| 236 | el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT; |
| 237 | el_status &= ID_AA64PFR0_ELX_MASK; |
| 238 | |
| 239 | if (el_status) |
| 240 | mode = MODE_EL2; |
| 241 | else |
| 242 | mode = MODE_EL1; |
| 243 | |
| 244 | /* |
| 245 | * TODO: Consider the possibility of specifying the SPSR in |
| 246 | * the FIP ToC and allowing the platform to have a say as |
| 247 | * well. |
| 248 | */ |
| 249 | bl33_ep_info->spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); |
| 250 | SET_SECURITY_STATE(bl33_ep_info->h.attr, NON_SECURE); |
| 251 | } |