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 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 31 | #include <platform.h> |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 32 | #include <arch.h> |
Vikram Kanigiri | 3ff77de | 2014-03-25 17:35:26 +0000 | [diff] [blame] | 33 | #include <console.h> |
Dan Handley | 4d2e49d | 2014-04-11 11:52:12 +0100 | [diff] [blame] | 34 | #include "drivers/pwrc/fvp_pwrc.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 35 | |
| 36 | /******************************************************************************* |
| 37 | * Declarations of linker defined symbols which will help us find the layout |
| 38 | * of trusted SRAM |
| 39 | ******************************************************************************/ |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 40 | extern unsigned long __RO_START__; |
| 41 | extern unsigned long __RO_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 42 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 43 | extern unsigned long __COHERENT_RAM_START__; |
| 44 | extern unsigned long __COHERENT_RAM_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 45 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 46 | /* |
| 47 | * The next 2 constants identify the extents of the code & RO data region. |
| 48 | * These addresses are used by the MMU setup code and therefore they must be |
| 49 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 50 | * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. |
| 51 | */ |
| 52 | #define BL31_RO_BASE (unsigned long)(&__RO_START__) |
| 53 | #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) |
| 54 | |
| 55 | /* |
| 56 | * The next 2 constants identify the extents of the coherent memory 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 | * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols |
| 60 | * refer to page-aligned addresses. |
| 61 | */ |
| 62 | #define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) |
| 63 | #define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 64 | |
| 65 | /******************************************************************************* |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 66 | * Reference to structure which holds the arguments that have been passed to |
| 67 | * BL31 from BL2. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 68 | ******************************************************************************/ |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 69 | static bl31_args *bl2_to_bl31_args; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 70 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 71 | meminfo *bl31_plat_sec_mem_layout(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 72 | { |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 73 | return &bl2_to_bl31_args->bl31_meminfo; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 76 | meminfo *bl31_plat_get_bl32_mem_layout(void) |
| 77 | { |
| 78 | return &bl2_to_bl31_args->bl32_meminfo; |
| 79 | } |
| 80 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 81 | /******************************************************************************* |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 82 | * Return a pointer to the 'el_change_info' structure of the next image for the |
| 83 | * security state specified. BL33 corresponds to the non-secure image type |
| 84 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 85 | * if the image does not exist. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 86 | ******************************************************************************/ |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 87 | el_change_info *bl31_get_next_image_info(uint32_t type) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 88 | { |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 89 | el_change_info *next_image_info; |
| 90 | |
| 91 | next_image_info = (type == NON_SECURE) ? |
| 92 | &bl2_to_bl31_args->bl33_image_info : |
| 93 | &bl2_to_bl31_args->bl32_image_info; |
| 94 | |
| 95 | /* None of the images on this platform can have 0x0 as the entrypoint */ |
| 96 | if (next_image_info->entrypoint) |
| 97 | return next_image_info; |
| 98 | else |
| 99 | return NULL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /******************************************************************************* |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 103 | * Perform any BL31 specific platform actions. Here is an opportunity to copy |
| 104 | * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they |
| 105 | * are lost (potentially). This needs to be done before the MMU is initialized |
| 106 | * so that the memory layout can be used while creating page tables. On the FVP |
| 107 | * we know that BL2 has populated the parameters in secure DRAM. So we just use |
| 108 | * the reference passed in 'from_bl2' instead of copying. The 'data' parameter |
| 109 | * is not used since all the information is contained in 'from_bl2'. Also, BL2 |
| 110 | * has flushed this information to memory, so we are guaranteed to pick up good |
| 111 | * data |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 112 | ******************************************************************************/ |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 113 | void bl31_early_platform_setup(bl31_args *from_bl2, |
Sandrine Bailleux | 93ca221 | 2013-12-02 15:57:09 +0000 | [diff] [blame] | 114 | void *data) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | { |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 116 | bl2_to_bl31_args = from_bl2; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 117 | |
| 118 | /* Initialize the platform config for future decision making */ |
| 119 | platform_config_setup(); |
Vikram Kanigiri | 3ff77de | 2014-03-25 17:35:26 +0000 | [diff] [blame] | 120 | |
| 121 | console_init(PL011_UART0_BASE); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /******************************************************************************* |
| 125 | * Initialize the gic, configure the CLCD and zero out variables needed by the |
| 126 | * secondaries to boot up correctly. |
| 127 | ******************************************************************************/ |
| 128 | void bl31_platform_setup() |
| 129 | { |
| 130 | unsigned int reg_val; |
| 131 | |
Ian Spray | 8468739 | 2014-01-02 16:57:12 +0000 | [diff] [blame] | 132 | /* Initialize the gic cpu and distributor interfaces */ |
| 133 | gic_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * TODO: Configure the CLCD before handing control to |
| 137 | * linux. Need to see if a separate driver is needed |
| 138 | * instead. |
| 139 | */ |
| 140 | mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGDATA, 0); |
| 141 | mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL, |
| 142 | (1ull << 31) | (1 << 30) | (7 << 20) | (0 << 16)); |
| 143 | |
Sandrine Bailleux | 3fa9847 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 144 | /* Enable and initialize the System level generic timer */ |
| 145 | mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_FCREQ(0) | CNTCR_EN); |
| 146 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 147 | /* Allow access to the System counter timer module */ |
| 148 | reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT); |
| 149 | reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT); |
| 150 | reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT); |
| 151 | mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(0), reg_val); |
| 152 | mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(1), reg_val); |
| 153 | |
| 154 | reg_val = (1 << CNTNSAR_NS_SHIFT(0)) | (1 << CNTNSAR_NS_SHIFT(1)); |
| 155 | mmio_write_32(SYS_TIMCTL_BASE + CNTNSAR, reg_val); |
| 156 | |
| 157 | /* Intialize the power controller */ |
| 158 | fvp_pwrc_setup(); |
| 159 | |
Ian Spray | 8468739 | 2014-01-02 16:57:12 +0000 | [diff] [blame] | 160 | /* Topologies are best known to the platform. */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 161 | plat_setup_topology(); |
| 162 | } |
| 163 | |
| 164 | /******************************************************************************* |
| 165 | * Perform the very early platform specific architectural setup here. At the |
| 166 | * moment this is only intializes the mmu in a quick and dirty way. |
| 167 | ******************************************************************************/ |
| 168 | void bl31_plat_arch_setup() |
| 169 | { |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 170 | configure_mmu(&bl2_to_bl31_args->bl31_meminfo, |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 171 | BL31_RO_BASE, |
| 172 | BL31_RO_LIMIT, |
| 173 | BL31_COHERENT_RAM_BASE, |
| 174 | BL31_COHERENT_RAM_LIMIT); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 175 | } |