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