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