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 <arch_helpers.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 32 | #include <assert.h> |
| 33 | #include <bl_common.h> |
Sandrine Bailleux | e3060e2 | 2014-06-13 14:48:18 +0100 | [diff] [blame] | 34 | #include <debug.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 35 | #include <console.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 36 | #include <mmio.h> |
| 37 | #include <platform.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 38 | #include <platform_def.h> |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 39 | #include "../../bl1/bl1_private.h" |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 40 | #include "fvp_def.h" |
| 41 | #include "fvp_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 42 | |
| 43 | /******************************************************************************* |
| 44 | * Declarations of linker defined symbols which will help us find the layout |
| 45 | * of trusted SRAM |
| 46 | ******************************************************************************/ |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 47 | extern unsigned long __COHERENT_RAM_START__; |
| 48 | extern unsigned long __COHERENT_RAM_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 49 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 50 | /* |
| 51 | * The next 2 constants identify the extents of the coherent memory region. |
| 52 | * These addresses are used by the MMU setup code and therefore they must be |
| 53 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 54 | * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to |
| 55 | * page-aligned addresses. |
| 56 | */ |
| 57 | #define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) |
| 58 | #define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 59 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 60 | /* Data structure which holds the extents of the trusted SRAM for BL1*/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 61 | static meminfo_t bl1_tzram_layout; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 62 | |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 63 | meminfo_t *bl1_plat_sec_mem_layout(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 64 | { |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 65 | return &bl1_tzram_layout; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /******************************************************************************* |
| 69 | * Perform any BL1 specific platform actions. |
| 70 | ******************************************************************************/ |
| 71 | void bl1_early_platform_setup(void) |
| 72 | { |
Sandrine Bailleux | e3060e2 | 2014-06-13 14:48:18 +0100 | [diff] [blame] | 73 | const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 74 | |
Vikram Kanigiri | 3684abf | 2014-03-27 14:33:15 +0000 | [diff] [blame] | 75 | /* Initialize the console to provide early debug support */ |
Soby Mathew | 69817f7 | 2014-07-14 15:43:21 +0100 | [diff] [blame] | 76 | console_init(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, PL011_BAUDRATE); |
Vikram Kanigiri | 3684abf | 2014-03-27 14:33:15 +0000 | [diff] [blame] | 77 | |
Sandrine Bailleux | e3060e2 | 2014-06-13 14:48:18 +0100 | [diff] [blame] | 78 | /* Allow BL1 to see the whole Trusted RAM */ |
Juan Castillo | 0c70c57 | 2014-08-12 13:04:43 +0100 | [diff] [blame] | 79 | bl1_tzram_layout.total_base = FVP_TRUSTED_SRAM_BASE; |
| 80 | bl1_tzram_layout.total_size = FVP_TRUSTED_SRAM_SIZE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 81 | |
Sandrine Bailleux | e3060e2 | 2014-06-13 14:48:18 +0100 | [diff] [blame] | 82 | /* Calculate how much RAM BL1 is using and how much remains free */ |
Juan Castillo | 0c70c57 | 2014-08-12 13:04:43 +0100 | [diff] [blame] | 83 | bl1_tzram_layout.free_base = FVP_TRUSTED_SRAM_BASE; |
| 84 | bl1_tzram_layout.free_size = FVP_TRUSTED_SRAM_SIZE; |
Sandrine Bailleux | e3060e2 | 2014-06-13 14:48:18 +0100 | [diff] [blame] | 85 | reserve_mem(&bl1_tzram_layout.free_base, |
| 86 | &bl1_tzram_layout.free_size, |
| 87 | BL1_RAM_BASE, |
| 88 | bl1_size); |
| 89 | |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 90 | /* Initialize the platform config for future decision making */ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 91 | fvp_config_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /******************************************************************************* |
| 95 | * Function which will evaluate how much of the trusted ram has been gobbled |
| 96 | * up by BL1 and return the base and size of whats available for loading BL2. |
| 97 | * Its called after coherency and the MMU have been turned on. |
| 98 | ******************************************************************************/ |
| 99 | void bl1_platform_setup(void) |
| 100 | { |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 101 | /* Initialise the IO layer and register platform IO devices */ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 102 | fvp_io_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | } |
| 104 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 105 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 106 | /******************************************************************************* |
| 107 | * Perform the very early platform specific architecture setup here. At the |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 108 | * moment this only does basic initialization. Later architectural setup |
| 109 | * (bl1_arch_setup()) does not do anything platform specific. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 110 | ******************************************************************************/ |
| 111 | void bl1_plat_arch_setup(void) |
| 112 | { |
Dan Handley | be234f9 | 2014-08-04 16:11:15 +0100 | [diff] [blame] | 113 | fvp_cci_init(); |
| 114 | fvp_cci_enable(); |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 115 | |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 116 | fvp_configure_mmu_el3(bl1_tzram_layout.total_base, |
| 117 | bl1_tzram_layout.total_size, |
Juan Castillo | 0c70c57 | 2014-08-12 13:04:43 +0100 | [diff] [blame] | 118 | BL1_RO_BASE, |
| 119 | BL1_RO_LIMIT, |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 120 | BL1_COHERENT_RAM_BASE, |
| 121 | BL1_COHERENT_RAM_LIMIT); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 122 | } |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 123 | |
| 124 | |
| 125 | /******************************************************************************* |
| 126 | * Before calling this function BL2 is loaded in memory and its entrypoint |
| 127 | * is set by load_image. This is a placeholder for the platform to change |
| 128 | * the entrypoint of BL2 and set SPSR and security state. |
| 129 | * On FVP we are only setting the security state, entrypoint |
| 130 | ******************************************************************************/ |
| 131 | void bl1_plat_set_bl2_ep_info(image_info_t *bl2_image, |
| 132 | entry_point_info_t *bl2_ep) |
| 133 | { |
| 134 | SET_SECURITY_STATE(bl2_ep->h.attr, SECURE); |
| 135 | bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); |
| 136 | } |