Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, ARM Limited. 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 <string.h> |
| 32 | #include <assert.h> |
| 33 | #include <arch_helpers.h> |
| 34 | #include <platform.h> |
| 35 | #include <bl1.h> |
| 36 | #include <console.h> |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 37 | #include <cci400.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 38 | |
| 39 | /******************************************************************************* |
| 40 | * Declarations of linker defined symbols which will help us find the layout |
| 41 | * of trusted SRAM |
| 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__; |
| 45 | extern unsigned long __COHERENT_RAM_UNALIGNED_SIZE__; |
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 | extern unsigned long __BL1_RAM_START__; |
| 48 | extern unsigned long __BL1_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__) |
| 59 | #define BL1_COHERENT_RAM_LENGTH \ |
| 60 | (unsigned long)(&__COHERENT_RAM_UNALIGNED_SIZE__) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 61 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 62 | #define BL1_RAM_BASE (unsigned long)(&__BL1_RAM_START__) |
| 63 | #define BL1_RAM_LIMIT (unsigned long)(&__BL1_RAM_END__) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 64 | |
| 65 | |
| 66 | /* Data structure which holds the extents of the trusted SRAM for BL1*/ |
Sandrine Bailleux | 204aa03 | 2013-10-28 15:14:00 +0000 | [diff] [blame] | 67 | static meminfo bl1_tzram_layout; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 68 | |
| 69 | meminfo bl1_get_sec_mem_layout(void) |
| 70 | { |
| 71 | return bl1_tzram_layout; |
| 72 | } |
| 73 | |
| 74 | /******************************************************************************* |
| 75 | * Perform any BL1 specific platform actions. |
| 76 | ******************************************************************************/ |
| 77 | void bl1_early_platform_setup(void) |
| 78 | { |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 79 | const unsigned long bl1_ram_base = BL1_RAM_BASE; |
| 80 | const unsigned long bl1_ram_limit = BL1_RAM_LIMIT; |
| 81 | const unsigned long tzram_limit = TZRAM_BASE + TZRAM_SIZE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Calculate how much ram is BL1 using & how much remains free. |
| 85 | * This also includes a rudimentary mechanism to detect whether |
| 86 | * the BL1 data is loaded at the top or bottom of memory. |
| 87 | * TODO: add support for discontigous chunks of free ram if |
| 88 | * needed. Might need dynamic memory allocation support |
| 89 | * et al. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 90 | */ |
| 91 | bl1_tzram_layout.total_base = TZRAM_BASE; |
| 92 | bl1_tzram_layout.total_size = TZRAM_SIZE; |
| 93 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 94 | if (bl1_ram_limit == tzram_limit) { |
| 95 | /* BL1 has been loaded at the top of memory. */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 96 | bl1_tzram_layout.free_base = TZRAM_BASE; |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 97 | bl1_tzram_layout.free_size = bl1_ram_base - TZRAM_BASE; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 98 | } else { |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 99 | /* BL1 has been loaded at the bottom of memory. */ |
| 100 | bl1_tzram_layout.free_base = bl1_ram_limit; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 101 | bl1_tzram_layout.free_size = |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 102 | tzram_limit - bl1_ram_limit; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | } |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 104 | |
| 105 | /* Initialize the platform config for future decision making */ |
| 106 | platform_config_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /******************************************************************************* |
| 110 | * Function which will evaluate how much of the trusted ram has been gobbled |
| 111 | * up by BL1 and return the base and size of whats available for loading BL2. |
| 112 | * Its called after coherency and the MMU have been turned on. |
| 113 | ******************************************************************************/ |
| 114 | void bl1_platform_setup(void) |
| 115 | { |
| 116 | /* |
| 117 | * This should zero out our coherent stacks as well but we don't care |
| 118 | * as they are not being used right now. |
| 119 | */ |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 120 | memset((void *) BL1_COHERENT_RAM_BASE, 0, |
| 121 | (size_t) BL1_COHERENT_RAM_LENGTH); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 122 | |
| 123 | /* Enable and initialize the System level generic timer */ |
| 124 | mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_EN); |
| 125 | |
| 126 | /* Initialize the console */ |
| 127 | console_init(); |
| 128 | |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | /******************************************************************************* |
| 133 | * Perform the very early platform specific architecture setup here. At the |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 134 | * moment this only does basic initialization. Later architectural setup |
| 135 | * (bl1_arch_setup()) does not do anything platform specific. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 136 | ******************************************************************************/ |
| 137 | void bl1_plat_arch_setup(void) |
| 138 | { |
Harry Liebel | 30affd5 | 2013-10-30 17:41:48 +0000 | [diff] [blame] | 139 | unsigned long cci_setup; |
| 140 | |
| 141 | /* |
| 142 | * Enable CCI-400 for this cluster. No need |
| 143 | * for locks as no other cpu is active at the |
| 144 | * moment |
| 145 | */ |
| 146 | cci_setup = platform_get_cfgvar(CONFIG_HAS_CCI); |
| 147 | if (cci_setup) { |
| 148 | cci_enable_coherency(read_mpidr()); |
| 149 | } |
| 150 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 151 | configure_mmu(&bl1_tzram_layout, |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame^] | 152 | TZROM_BASE, |
| 153 | TZROM_BASE + TZROM_SIZE, |
| 154 | BL1_COHERENT_RAM_BASE, |
| 155 | BL1_COHERENT_RAM_LIMIT); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 156 | } |