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 <assert.h> |
| 32 | #include <arch_helpers.h> |
| 33 | #include <platform.h> |
| 34 | #include <bl2.h> |
| 35 | #include <bl_common.h> |
Vikram Kanigiri | 3ff77de | 2014-03-25 17:35:26 +0000 | [diff] [blame] | 36 | #include <console.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | |
| 38 | /******************************************************************************* |
| 39 | * Declarations of linker defined symbols which will help us find the layout |
| 40 | * of trusted SRAM |
| 41 | ******************************************************************************/ |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 42 | extern unsigned long __RO_START__; |
| 43 | extern unsigned long __RO_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 44 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 45 | extern unsigned long __COHERENT_RAM_START__; |
| 46 | extern unsigned long __COHERENT_RAM_END__; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 47 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 48 | /* |
| 49 | * The next 2 constants identify the extents of the code & RO data region. |
| 50 | * These addresses are used by the MMU setup code and therefore they must be |
| 51 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 52 | * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. |
| 53 | */ |
| 54 | #define BL2_RO_BASE (unsigned long)(&__RO_START__) |
| 55 | #define BL2_RO_LIMIT (unsigned long)(&__RO_END__) |
| 56 | |
| 57 | /* |
| 58 | * The next 2 constants identify the extents of the coherent memory region. |
| 59 | * These addresses are used by the MMU setup code and therefore they must be |
| 60 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 61 | * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to |
| 62 | * page-aligned addresses. |
| 63 | */ |
| 64 | #define BL2_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) |
| 65 | #define BL2_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 66 | |
| 67 | /* Pointer to memory visible to both BL2 and BL31 for passing data */ |
| 68 | extern unsigned char **bl2_el_change_mem_ptr; |
| 69 | |
| 70 | /* Data structure which holds the extents of the trusted SRAM for BL2 */ |
| 71 | static meminfo bl2_tzram_layout |
| 72 | __attribute__ ((aligned(PLATFORM_CACHE_LINE_SIZE), |
Sandrine Bailleux | 204aa03 | 2013-10-28 15:14:00 +0000 | [diff] [blame] | 73 | section("tzfw_coherent_mem"))); |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 74 | |
| 75 | /******************************************************************************* |
| 76 | * Reference to structure which holds the arguments which need to be passed |
| 77 | * to BL31 |
| 78 | ******************************************************************************/ |
| 79 | static bl31_args *bl2_to_bl31_args; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 80 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 81 | meminfo *bl2_plat_sec_mem_layout(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 82 | { |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 83 | return &bl2_tzram_layout; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 86 | /******************************************************************************* |
| 87 | * This function returns a pointer to the memory that the platform has kept |
| 88 | * aside to pass all the information that BL31 could need. |
| 89 | ******************************************************************************/ |
| 90 | bl31_args *bl2_get_bl31_args_ptr(void) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 91 | { |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 92 | return bl2_to_bl31_args; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 95 | /******************************************************************************* |
| 96 | * BL1 has passed the extents of the trusted SRAM that should be visible to BL2 |
| 97 | * in x0. This memory layout is sitting at the base of the free trusted SRAM. |
| 98 | * Copy it to a safe loaction before its reclaimed by later BL2 functionality. |
| 99 | ******************************************************************************/ |
| 100 | void bl2_early_platform_setup(meminfo *mem_layout, |
| 101 | void *data) |
| 102 | { |
| 103 | /* Setup the BL2 memory layout */ |
| 104 | bl2_tzram_layout.total_base = mem_layout->total_base; |
| 105 | bl2_tzram_layout.total_size = mem_layout->total_size; |
| 106 | bl2_tzram_layout.free_base = mem_layout->free_base; |
| 107 | bl2_tzram_layout.free_size = mem_layout->free_size; |
| 108 | bl2_tzram_layout.attr = mem_layout->attr; |
| 109 | bl2_tzram_layout.next = 0; |
| 110 | |
| 111 | /* Initialize the platform config for future decision making */ |
| 112 | platform_config_setup(); |
| 113 | |
Vikram Kanigiri | 3ff77de | 2014-03-25 17:35:26 +0000 | [diff] [blame] | 114 | console_init(PL011_UART0_BASE); |
| 115 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
| 119 | /******************************************************************************* |
Sandrine Bailleux | 942f405 | 2013-11-19 17:14:22 +0000 | [diff] [blame] | 120 | * Perform platform specific setup. For now just initialize the memory location |
| 121 | * to use for passing arguments to BL31. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 122 | ******************************************************************************/ |
| 123 | void bl2_platform_setup() |
| 124 | { |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 125 | /* Initialise the IO layer and register platform IO devices */ |
| 126 | io_setup(); |
| 127 | |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 128 | /* |
| 129 | * Ensure that the secure DRAM memory used for passing BL31 arguments |
| 130 | * does not overlap with the BL32_BASE. |
| 131 | */ |
| 132 | assert (BL32_BASE > TZDRAM_BASE + sizeof(bl31_args)); |
| 133 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | /* Use the Trusted DRAM for passing args to BL31 */ |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 135 | bl2_to_bl31_args = (bl31_args *) TZDRAM_BASE; |
| 136 | |
| 137 | /* Populate the extents of memory available for loading BL33 */ |
| 138 | bl2_to_bl31_args->bl33_meminfo.total_base = DRAM_BASE; |
| 139 | bl2_to_bl31_args->bl33_meminfo.total_size = DRAM_SIZE; |
| 140 | bl2_to_bl31_args->bl33_meminfo.free_base = DRAM_BASE; |
| 141 | bl2_to_bl31_args->bl33_meminfo.free_size = DRAM_SIZE; |
| 142 | bl2_to_bl31_args->bl33_meminfo.attr = 0; |
| 143 | bl2_to_bl31_args->bl33_meminfo.next = 0; |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Populate the extents of memory available for loading BL32. |
| 147 | * TODO: We are temporarily executing BL2 from TZDRAM; will eventually |
| 148 | * move to Trusted SRAM |
| 149 | */ |
| 150 | bl2_to_bl31_args->bl32_meminfo.total_base = BL32_BASE; |
| 151 | bl2_to_bl31_args->bl32_meminfo.free_base = BL32_BASE; |
| 152 | |
| 153 | bl2_to_bl31_args->bl32_meminfo.total_size = |
| 154 | (TZDRAM_BASE + TZDRAM_SIZE) - BL32_BASE; |
| 155 | bl2_to_bl31_args->bl32_meminfo.free_size = |
| 156 | (TZDRAM_BASE + TZDRAM_SIZE) - BL32_BASE; |
| 157 | |
| 158 | bl2_to_bl31_args->bl32_meminfo.attr = BOT_LOAD; |
| 159 | bl2_to_bl31_args->bl32_meminfo.next = 0; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /******************************************************************************* |
| 163 | * Perform the very early platform specific architectural setup here. At the |
| 164 | * moment this is only intializes the mmu in a quick and dirty way. |
| 165 | ******************************************************************************/ |
| 166 | void bl2_plat_arch_setup() |
| 167 | { |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 168 | configure_mmu(&bl2_tzram_layout, |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 169 | BL2_RO_BASE, |
| 170 | BL2_RO_LIMIT, |
| 171 | BL2_COHERENT_RAM_BASE, |
| 172 | BL2_COHERENT_RAM_LIMIT); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 173 | } |