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 | |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 31 | #include <arch.h> |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 32 | #include <arch_helpers.h> |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 33 | #include <assert.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 34 | #include <bl_common.h> |
| 35 | #include <bl31.h> |
Vikram Kanigiri | 3ff77de | 2014-03-25 17:35:26 +0000 | [diff] [blame] | 36 | #include <console.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 37 | #include <mmio.h> |
| 38 | #include <platform.h> |
| 39 | #include <stddef.h> |
Dan Handley | 4d2e49d | 2014-04-11 11:52:12 +0100 | [diff] [blame] | 40 | #include "drivers/pwrc/fvp_pwrc.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | |
| 42 | /******************************************************************************* |
| 43 | * Declarations of linker defined symbols which will help us find the layout |
| 44 | * of trusted SRAM |
| 45 | ******************************************************************************/ |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 46 | extern unsigned long __RO_START__; |
| 47 | extern unsigned long __RO_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 48 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 49 | extern unsigned long __COHERENT_RAM_START__; |
| 50 | extern unsigned long __COHERENT_RAM_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 51 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 52 | /* |
| 53 | * The next 2 constants identify the extents of the code & RO data region. |
| 54 | * These addresses are used by the MMU setup code and therefore they must be |
| 55 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 56 | * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. |
| 57 | */ |
| 58 | #define BL31_RO_BASE (unsigned long)(&__RO_START__) |
| 59 | #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) |
| 60 | |
| 61 | /* |
| 62 | * The next 2 constants identify the extents of the coherent memory region. |
| 63 | * These addresses are used by the MMU setup code and therefore they must be |
| 64 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 65 | * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols |
| 66 | * refer to page-aligned addresses. |
| 67 | */ |
| 68 | #define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) |
| 69 | #define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 70 | |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 71 | |
| 72 | #if RESET_TO_BL31 |
| 73 | static entry_point_info_t bl32_entrypoint_info; |
| 74 | static entry_point_info_t bl33_entrypoint_info; |
| 75 | #else |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 76 | /******************************************************************************* |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 77 | * Reference to structure which holds the arguments that have been passed to |
| 78 | * BL31 from BL2. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 79 | ******************************************************************************/ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 80 | static bl31_params_t *bl2_to_bl31_params; |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 81 | #endif |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 82 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 83 | /******************************************************************************* |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 84 | * Return a pointer to the 'entry_point_info' structure of the next image for the |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 85 | * security state specified. BL33 corresponds to the non-secure image type |
| 86 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 87 | * if the image does not exist. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 88 | ******************************************************************************/ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 89 | entry_point_info_t *bl31_get_next_image_info(uint32_t type) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 90 | { |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 91 | entry_point_info_t *next_image_info; |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 92 | |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 93 | #if RESET_TO_BL31 |
| 94 | |
| 95 | if (type == NON_SECURE) |
| 96 | plat_get_entry_point_info(NON_SECURE, &bl33_entrypoint_info); |
| 97 | else |
| 98 | plat_get_entry_point_info(SECURE, &bl32_entrypoint_info); |
| 99 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 100 | next_image_info = (type == NON_SECURE) ? |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 101 | &bl33_entrypoint_info : |
| 102 | &bl32_entrypoint_info; |
| 103 | #else |
| 104 | next_image_info = (type == NON_SECURE) ? |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 105 | bl2_to_bl31_params->bl33_ep_info : |
| 106 | bl2_to_bl31_params->bl32_ep_info; |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 107 | #endif |
| 108 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 109 | |
| 110 | /* None of the images on this platform can have 0x0 as the entrypoint */ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 111 | if (next_image_info->pc) |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 112 | return next_image_info; |
| 113 | else |
| 114 | return NULL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /******************************************************************************* |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 118 | * Perform any BL31 specific platform actions. Here is an opportunity to copy |
| 119 | * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they |
| 120 | * are lost (potentially). This needs to be done before the MMU is initialized |
| 121 | * so that the memory layout can be used while creating page tables. On the FVP |
| 122 | * we know that BL2 has populated the parameters in secure DRAM. So we just use |
| 123 | * the reference passed in 'from_bl2' instead of copying. The 'data' parameter |
| 124 | * is not used since all the information is contained in 'from_bl2'. Also, BL2 |
| 125 | * has flushed this information to memory, so we are guaranteed to pick up good |
| 126 | * data |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 127 | ******************************************************************************/ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 128 | void bl31_early_platform_setup(bl31_params_t *from_bl2, |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 129 | void *plat_params_from_bl2) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 130 | { |
Vikram Kanigiri | 3684abf | 2014-03-27 14:33:15 +0000 | [diff] [blame] | 131 | /* Initialize the console to provide early debug support */ |
| 132 | console_init(PL011_UART0_BASE); |
| 133 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | /* Initialize the platform config for future decision making */ |
| 135 | platform_config_setup(); |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 136 | |
| 137 | #if RESET_TO_BL31 |
| 138 | /* There are no parameters from BL2 if BL31 is a reset vector */ |
| 139 | assert(from_bl2 == NULL); |
| 140 | assert(plat_params_from_bl2 == NULL); |
| 141 | |
| 142 | |
| 143 | /* |
| 144 | * Do initial security configuration to allow DRAM/device access. On |
| 145 | * Base FVP only DRAM security is programmable (via TrustZone), but |
| 146 | * other platforms might have more programmable security devices |
| 147 | * present. |
| 148 | */ |
| 149 | plat_security_setup(); |
| 150 | #else |
| 151 | /* Check params passed from BL2 should not be NULL, |
| 152 | * We are not checking plat_params_from_bl2 as NULL as we are not |
| 153 | * using it on FVP |
| 154 | */ |
| 155 | assert(from_bl2 != NULL); |
| 156 | assert(from_bl2->h.type == PARAM_BL31); |
| 157 | assert(from_bl2->h.version >= VERSION_1); |
| 158 | |
| 159 | bl2_to_bl31_params = from_bl2; |
| 160 | #endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /******************************************************************************* |
| 164 | * Initialize the gic, configure the CLCD and zero out variables needed by the |
| 165 | * secondaries to boot up correctly. |
| 166 | ******************************************************************************/ |
| 167 | void bl31_platform_setup() |
| 168 | { |
| 169 | unsigned int reg_val; |
| 170 | |
Ian Spray | 8468739 | 2014-01-02 16:57:12 +0000 | [diff] [blame] | 171 | /* Initialize the gic cpu and distributor interfaces */ |
| 172 | gic_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * TODO: Configure the CLCD before handing control to |
| 176 | * linux. Need to see if a separate driver is needed |
| 177 | * instead. |
| 178 | */ |
| 179 | mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGDATA, 0); |
| 180 | mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL, |
| 181 | (1ull << 31) | (1 << 30) | (7 << 20) | (0 << 16)); |
| 182 | |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 183 | /* Enable and initialize the System level generic timer */ |
| 184 | mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_FCREQ(0) | CNTCR_EN); |
| 185 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 186 | /* Allow access to the System counter timer module */ |
| 187 | reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT); |
| 188 | reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT); |
| 189 | reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT); |
| 190 | mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(0), reg_val); |
| 191 | mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(1), reg_val); |
| 192 | |
| 193 | reg_val = (1 << CNTNSAR_NS_SHIFT(0)) | (1 << CNTNSAR_NS_SHIFT(1)); |
| 194 | mmio_write_32(SYS_TIMCTL_BASE + CNTNSAR, reg_val); |
| 195 | |
| 196 | /* Intialize the power controller */ |
| 197 | fvp_pwrc_setup(); |
| 198 | |
Ian Spray | 8468739 | 2014-01-02 16:57:12 +0000 | [diff] [blame] | 199 | /* Topologies are best known to the platform. */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 200 | plat_setup_topology(); |
| 201 | } |
| 202 | |
| 203 | /******************************************************************************* |
| 204 | * Perform the very early platform specific architectural setup here. At the |
| 205 | * moment this is only intializes the mmu in a quick and dirty way. |
| 206 | ******************************************************************************/ |
| 207 | void bl31_plat_arch_setup() |
| 208 | { |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 209 | #if RESET_TO_BL31 |
| 210 | fvp_cci_setup(); |
| 211 | #endif |
| 212 | |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 213 | configure_mmu_el3(TZRAM_BASE, |
| 214 | TZRAM_SIZE, |
Sandrine Bailleux | 74a62b3 | 2014-05-09 11:35:36 +0100 | [diff] [blame] | 215 | BL31_RO_BASE, |
| 216 | BL31_RO_LIMIT, |
| 217 | BL31_COHERENT_RAM_BASE, |
| 218 | BL31_COHERENT_RAM_LIMIT); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 219 | } |
Vikram Kanigiri | 9637745 | 2014-04-24 11:02:16 +0100 | [diff] [blame] | 220 | |
| 221 | #if RESET_TO_BL31 |
| 222 | /******************************************************************************* |
| 223 | * Generate the entry point info for Non Secure and Secure images |
| 224 | * for transferring control from BL31 |
| 225 | ******************************************************************************/ |
| 226 | void plat_get_entry_point_info(unsigned long target_security, |
| 227 | entry_point_info_t *target_entry_info) |
| 228 | { |
| 229 | if (target_security == NON_SECURE) { |
| 230 | SET_PARAM_HEAD(target_entry_info, |
| 231 | PARAM_EP, |
| 232 | VERSION_1, |
| 233 | 0); |
| 234 | /* |
| 235 | * Tell BL31 where the non-trusted software image |
| 236 | * is located and the entry state information |
| 237 | */ |
| 238 | target_entry_info->pc = plat_get_ns_image_entrypoint(); |
| 239 | |
| 240 | fvp_set_bl33_ep_info(target_entry_info); |
| 241 | |
| 242 | } else { |
| 243 | SET_PARAM_HEAD(target_entry_info, |
| 244 | PARAM_EP, |
| 245 | VERSION_1, |
| 246 | 0); |
| 247 | if (BL32_BASE != 0) { |
| 248 | /* Hard coding entry point to the base of the BL32 */ |
| 249 | target_entry_info->pc = BL32_BASE; |
| 250 | fvp_set_bl32_ep_info(target_entry_info); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | #endif |