Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
| 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 | |
| 31 | #include <arch.h> |
Juan Castillo | b3286c0 | 2014-10-20 12:29:58 +0100 | [diff] [blame] | 32 | #include <arm_gic.h> |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 33 | #include <assert.h> |
| 34 | #include <bl31.h> |
| 35 | #include <bl_common.h> |
| 36 | #include <cci400.h> |
| 37 | #include <console.h> |
| 38 | #include <mmio.h> |
| 39 | #include <platform.h> |
| 40 | #include <stddef.h> |
| 41 | #include "juno_def.h" |
| 42 | #include "juno_private.h" |
| 43 | #include "mhu.h" |
| 44 | |
| 45 | /******************************************************************************* |
| 46 | * Declarations of linker defined symbols which will help us find the layout |
| 47 | * of trusted RAM |
| 48 | ******************************************************************************/ |
| 49 | extern unsigned long __RO_START__; |
| 50 | extern unsigned long __RO_END__; |
| 51 | |
| 52 | extern unsigned long __COHERENT_RAM_START__; |
| 53 | extern unsigned long __COHERENT_RAM_END__; |
| 54 | |
| 55 | /* |
| 56 | * The next 2 constants identify the extents of the code & RO data region. |
| 57 | * These addresses are used by the MMU setup code and therefore they must be |
| 58 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 59 | * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. |
| 60 | */ |
| 61 | #define BL31_RO_BASE (unsigned long)(&__RO_START__) |
| 62 | #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) |
| 63 | |
| 64 | /* |
| 65 | * The next 2 constants identify the extents of the coherent memory region. |
| 66 | * These addresses are used by the MMU setup code and therefore they must be |
| 67 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 68 | * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols |
| 69 | * refer to page-aligned addresses. |
| 70 | */ |
| 71 | #define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) |
| 72 | #define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
| 73 | |
| 74 | /****************************************************************************** |
| 75 | * Placeholder variables for copying the arguments that have been passed to |
| 76 | * BL3-1 from BL2. |
| 77 | ******************************************************************************/ |
| 78 | static entry_point_info_t bl32_ep_info; |
| 79 | static entry_point_info_t bl33_ep_info; |
| 80 | |
| 81 | /******************************************************************************* |
| 82 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 83 | * the security state specified. BL3-3 corresponds to the non-secure image type |
| 84 | * while BL3-2 corresponds to the secure image type. A NULL pointer is returned |
| 85 | * if the image does not exist. |
| 86 | ******************************************************************************/ |
| 87 | entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) |
| 88 | { |
| 89 | entry_point_info_t *next_image_info; |
| 90 | |
| 91 | next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; |
| 92 | |
| 93 | /* None of the images on this platform can have 0x0 as the entrypoint */ |
| 94 | if (next_image_info->pc) |
| 95 | return next_image_info; |
| 96 | else |
| 97 | return NULL; |
| 98 | } |
| 99 | |
| 100 | /******************************************************************************* |
| 101 | * Perform any BL3-1 specific platform actions. Here is an opportunity to copy |
| 102 | * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they |
| 103 | * are lost (potentially). This needs to be done before the MMU is initialized |
| 104 | * so that the memory layout can be used while creating page tables. Also, BL2 |
| 105 | * has flushed this information to memory, so we are guaranteed to pick up good |
| 106 | * data |
| 107 | ******************************************************************************/ |
| 108 | void bl31_early_platform_setup(bl31_params_t *from_bl2, |
| 109 | void *plat_params_from_bl2) |
| 110 | { |
| 111 | /* Initialize the console to provide early debug support */ |
Soby Mathew | f797cea | 2014-08-21 15:20:27 +0100 | [diff] [blame] | 112 | console_init(PL011_UART2_BASE, PL011_UART2_CLK_IN_HZ, PL011_BAUDRATE); |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * Initialise the CCI-400 driver for BL31 so that it is accessible after |
| 116 | * a warm boot. BL1 should have already enabled CCI coherency for this |
| 117 | * cluster during cold boot. |
| 118 | */ |
| 119 | cci_init(CCI400_BASE, |
| 120 | CCI400_SL_IFACE3_CLUSTER_IX, |
| 121 | CCI400_SL_IFACE4_CLUSTER_IX); |
| 122 | |
| 123 | /* |
| 124 | * Check params passed from BL2 should not be NULL, |
| 125 | */ |
| 126 | assert(from_bl2 != NULL); |
| 127 | assert(from_bl2->h.type == PARAM_BL31); |
| 128 | assert(from_bl2->h.version >= VERSION_1); |
| 129 | /* |
| 130 | * In debug builds, we pass a special value in 'plat_params_from_bl2' |
| 131 | * to verify platform parameters from BL2 to BL3-1. |
| 132 | * In release builds, it's not used. |
| 133 | */ |
| 134 | assert(((unsigned long long)plat_params_from_bl2) == |
| 135 | JUNO_BL31_PLAT_PARAM_VAL); |
| 136 | |
| 137 | /* |
| 138 | * Copy BL3-2 and BL3-3 entry point information. |
| 139 | * They are stored in Secure RAM, in BL2's address space. |
| 140 | */ |
| 141 | bl32_ep_info = *from_bl2->bl32_ep_info; |
| 142 | bl33_ep_info = *from_bl2->bl33_ep_info; |
| 143 | } |
| 144 | |
| 145 | /******************************************************************************* |
| 146 | * Initialize the MHU and the GIC. |
| 147 | ******************************************************************************/ |
| 148 | void bl31_platform_setup(void) |
| 149 | { |
| 150 | unsigned int reg_val; |
| 151 | |
| 152 | mhu_secure_init(); |
| 153 | |
| 154 | /* Initialize the gic cpu and distributor interfaces */ |
Juan Castillo | b3286c0 | 2014-10-20 12:29:58 +0100 | [diff] [blame] | 155 | plat_gic_init(); |
| 156 | arm_gic_setup(); |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 157 | |
| 158 | /* Enable and initialize the System level generic timer */ |
| 159 | mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_FCREQ(0) | CNTCR_EN); |
| 160 | |
| 161 | /* Allow access to the System counter timer module */ |
| 162 | reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT); |
| 163 | reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT); |
| 164 | reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT); |
| 165 | mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(1), reg_val); |
| 166 | |
| 167 | reg_val = (1 << CNTNSAR_NS_SHIFT(1)); |
| 168 | mmio_write_32(SYS_TIMCTL_BASE + CNTNSAR, reg_val); |
| 169 | |
| 170 | /* Topologies are best known to the platform. */ |
| 171 | plat_setup_topology(); |
| 172 | } |
| 173 | |
| 174 | /******************************************************************************* |
| 175 | * Perform the very early platform specific architectural setup here. At the |
| 176 | * moment this is only intializes the mmu in a quick and dirty way. |
| 177 | ******************************************************************************/ |
| 178 | void bl31_plat_arch_setup() |
| 179 | { |
| 180 | configure_mmu_el3(BL31_RO_BASE, |
| 181 | BL31_COHERENT_RAM_LIMIT - BL31_RO_BASE, |
| 182 | BL31_RO_BASE, |
| 183 | BL31_RO_LIMIT, |
| 184 | BL31_COHERENT_RAM_BASE, |
| 185 | BL31_COHERENT_RAM_LIMIT); |
| 186 | } |