Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 09ed710 | 2020-01-30 14:06:28 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | #include <tftf.h> |
| 10 | |
| 11 | .globl tftf_entrypoint |
| 12 | .globl tftf_hotplug_entry |
| 13 | |
| 14 | |
| 15 | /* ---------------------------------------------------------------------------- |
| 16 | * Cold boot entry point for the primary CPU. |
| 17 | * ---------------------------------------------------------------------------- |
| 18 | */ |
| 19 | func tftf_entrypoint |
Alexei Fedorov | 09ed710 | 2020-01-30 14:06:28 +0000 | [diff] [blame] | 20 | /* -------------------------------------------------------------------- |
| 21 | * Save arguments x0, x1 from the previous Boot loader |
| 22 | * -------------------------------------------------------------------- |
| 23 | */ |
| 24 | mov x20, x0 |
| 25 | mov x21, x1 |
| 26 | |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 27 | bl arch_init |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 28 | |
| 29 | /* -------------------------------------------------------------------- |
Alexei Fedorov | 2198e9a | 2019-12-12 14:14:55 +0000 | [diff] [blame] | 30 | * Invalidate the RW memory used by TFTF image. |
| 31 | * This is done to safeguard against possible corruption of this |
| 32 | * memory by dirty cache lines in a system cache as a result of use |
| 33 | * by an earlier boot loader stage. |
| 34 | * -------------------------------------------------------------------- |
| 35 | */ |
| 36 | adr x0, __DATA_START__ |
| 37 | adr x1, __DATA_END__ |
| 38 | sub x1, x1, x0 |
| 39 | bl inv_dcache_range |
| 40 | |
| 41 | /* -------------------------------------------------------------------- |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 42 | * This code is expected to be executed only by the primary CPU. |
| 43 | * Save the mpid for the first core that executes and if a secondary |
| 44 | * CPU has lost its way make it spin forever. |
| 45 | * -------------------------------------------------------------------- |
| 46 | */ |
| 47 | bl save_primary_mpid |
| 48 | |
| 49 | /* -------------------------------------------------------------------- |
| 50 | * Zero out NOBITS sections. There are 2 of them: |
| 51 | * - the .bss section; |
| 52 | * - the coherent memory section. |
| 53 | * -------------------------------------------------------------------- |
| 54 | */ |
| 55 | ldr x0, =__BSS_START__ |
| 56 | ldr x1, =__BSS_SIZE__ |
| 57 | bl zeromem16 |
| 58 | |
| 59 | ldr x0, =__COHERENT_RAM_START__ |
| 60 | ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__ |
| 61 | bl zeromem16 |
| 62 | |
| 63 | /* -------------------------------------------------------------------- |
| 64 | * Give ourselves a small coherent stack to ease the pain of |
| 65 | * initializing the MMU |
| 66 | * -------------------------------------------------------------------- |
| 67 | */ |
| 68 | mrs x0, mpidr_el1 |
| 69 | bl platform_set_coherent_stack |
| 70 | |
| 71 | bl tftf_early_platform_setup |
| 72 | bl tftf_plat_arch_setup |
| 73 | |
| 74 | /* -------------------------------------------------------------------- |
| 75 | * Give ourselves a stack allocated in Normal -IS-WBWA memory |
| 76 | * -------------------------------------------------------------------- |
| 77 | */ |
| 78 | mrs x0, mpidr_el1 |
| 79 | bl platform_set_stack |
| 80 | |
| 81 | /* -------------------------------------------------------------------- |
Alexei Fedorov | 09ed710 | 2020-01-30 14:06:28 +0000 | [diff] [blame] | 82 | * Save fw_config and hw_config addresses passed in x0, x1 from the |
| 83 | * previous boot loader |
| 84 | * -------------------------------------------------------------------- |
| 85 | */ |
| 86 | mov x0, x20 |
| 87 | mov x1, x21 |
| 88 | bl save_fw_hw_configs |
| 89 | |
| 90 | /* -------------------------------------------------------------------- |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 91 | * tftf_cold_boot_main() will perform the remaining architectural and |
| 92 | * platform setup, initialise the test framework's state, then run the |
| 93 | * tests. |
| 94 | * -------------------------------------------------------------------- |
| 95 | */ |
| 96 | b tftf_cold_boot_main |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 97 | endfunc tftf_entrypoint |
| 98 | |
| 99 | /* ---------------------------------------------------------------------------- |
| 100 | * Entry point for a CPU that has just been powered up. |
| 101 | * In : x0 - context_id |
| 102 | * ---------------------------------------------------------------------------- |
| 103 | */ |
| 104 | func tftf_hotplug_entry |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 105 | /* -------------------------------------------------------------------- |
| 106 | * Preserve the context_id in a callee-saved register |
| 107 | * -------------------------------------------------------------------- |
| 108 | */ |
| 109 | mov x19, x0 |
| 110 | |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 111 | bl arch_init |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 112 | |
| 113 | /* -------------------------------------------------------------------- |
| 114 | * Give ourselves a small coherent stack to ease the pain of |
| 115 | * initializing the MMU |
| 116 | * -------------------------------------------------------------------- |
| 117 | */ |
| 118 | mrs x0, mpidr_el1 |
| 119 | bl platform_set_coherent_stack |
| 120 | |
| 121 | /* -------------------------------------------------------------------- |
| 122 | * Enable the MMU |
| 123 | * -------------------------------------------------------------------- |
| 124 | */ |
| 125 | bl tftf_plat_enable_mmu |
| 126 | |
| 127 | /* -------------------------------------------------------------------- |
| 128 | * Give ourselves a stack in normal memory. |
| 129 | * -------------------------------------------------------------------- |
| 130 | */ |
| 131 | mrs x0, mpidr_el1 |
| 132 | bl platform_set_stack |
| 133 | |
| 134 | /* -------------------------------------------------------------------- |
| 135 | * Save the context_id for later retrieval by tests |
| 136 | * -------------------------------------------------------------------- |
| 137 | */ |
| 138 | mrs x0, mpidr_el1 |
Antonio Nino Diaz | 8c0f86b | 2018-11-23 13:50:59 +0000 | [diff] [blame] | 139 | mov_imm x1, MPID_MASK |
| 140 | and x0, x0, x1 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 141 | bl platform_get_core_pos |
| 142 | |
| 143 | mov x1, x19 |
| 144 | |
| 145 | bl tftf_set_cpu_on_ctx_id |
| 146 | |
| 147 | /* -------------------------------------------------------------------- |
| 148 | * Jump to warm boot main function |
| 149 | * -------------------------------------------------------------------- |
| 150 | */ |
| 151 | b tftf_warm_boot_main |
| 152 | endfunc tftf_hotplug_entry |
| 153 | |
| 154 | /* ---------------------------------------------------------------------------- |
| 155 | * Saves the mpid of the primary core and if the primary core |
| 156 | * is already saved then it loops infinitely. |
| 157 | * ---------------------------------------------------------------------------- |
| 158 | */ |
| 159 | func save_primary_mpid |
| 160 | adrp x1, tftf_primary_core |
| 161 | ldr w0, [x1, :lo12:tftf_primary_core] |
| 162 | mov w2, #INVALID_MPID |
| 163 | cmp w0, w2 |
| 164 | b.ne panic |
Antonio Nino Diaz | 8c0f86b | 2018-11-23 13:50:59 +0000 | [diff] [blame] | 165 | mov_imm x2, MPID_MASK |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 166 | mrs x0, mpidr_el1 |
| 167 | and x0, x0, x2 |
| 168 | str w0, [x1, :lo12:tftf_primary_core] |
| 169 | ret |
| 170 | panic: |
| 171 | /* Primary core MPID already saved */ |
| 172 | b . |
| 173 | ret |
| 174 | endfunc save_primary_mpid |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 175 | |
| 176 | /* Initialize architectural state. */ |
| 177 | func arch_init |
| 178 | mrs x0, CurrentEL |
| 179 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 180 | b.eq el1_setup |
| 181 | |
| 182 | el2_setup: |
| 183 | /* Set the exception vectors. */ |
| 184 | adr x0, tftf_vector |
| 185 | msr vbar_el2, x0 |
| 186 | |
Joel Hutton | 6a6f483 | 2019-04-08 15:46:36 +0100 | [diff] [blame] | 187 | /* Enable the instruction cache and alignment checks. */ |
| 188 | mov_imm x0, (SCTLR_EL2_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT) |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 189 | msr sctlr_el2, x0 |
| 190 | |
| 191 | isb |
| 192 | ret |
| 193 | |
| 194 | el1_setup: |
| 195 | /* Set the exception vectors. */ |
| 196 | adr x0, tftf_vector |
| 197 | msr vbar_el1, x0 |
| 198 | |
| 199 | /* Enable the instruction cache and stack pointer alignment checks. */ |
Joel Hutton | 6a6f483 | 2019-04-08 15:46:36 +0100 | [diff] [blame] | 200 | mov_imm x0, (SCTLR_EL1_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT) |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 201 | msr sctlr_el1, x0 |
| 202 | |
| 203 | isb |
| 204 | ret |
| 205 | endfunc arch_init |
Alexei Fedorov | 09ed710 | 2020-01-30 14:06:28 +0000 | [diff] [blame] | 206 | |
| 207 | /* Set fw_config and hw_config addresses passed in x0, x1 */ |
| 208 | func save_fw_hw_configs |
| 209 | adrp x2, fw_config_base |
| 210 | str x0, [x2, :lo12:fw_config_base] |
| 211 | str x1, [x2, :lo12:hw_config_base] |
| 212 | ret |
| 213 | endfunc save_fw_hw_configs |