Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Joel Hutton | 6a6f483 | 2019-04-08 15:46:36 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, 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 |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 20 | bl arch_init |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 21 | |
| 22 | /* -------------------------------------------------------------------- |
| 23 | * This code is expected to be executed only by the primary CPU. |
| 24 | * Save the mpid for the first core that executes and if a secondary |
| 25 | * CPU has lost its way make it spin forever. |
| 26 | * -------------------------------------------------------------------- |
| 27 | */ |
| 28 | bl save_primary_mpid |
| 29 | |
| 30 | /* -------------------------------------------------------------------- |
| 31 | * Zero out NOBITS sections. There are 2 of them: |
| 32 | * - the .bss section; |
| 33 | * - the coherent memory section. |
| 34 | * -------------------------------------------------------------------- |
| 35 | */ |
| 36 | ldr x0, =__BSS_START__ |
| 37 | ldr x1, =__BSS_SIZE__ |
| 38 | bl zeromem16 |
| 39 | |
| 40 | ldr x0, =__COHERENT_RAM_START__ |
| 41 | ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__ |
| 42 | bl zeromem16 |
| 43 | |
| 44 | /* -------------------------------------------------------------------- |
| 45 | * Give ourselves a small coherent stack to ease the pain of |
| 46 | * initializing the MMU |
| 47 | * -------------------------------------------------------------------- |
| 48 | */ |
| 49 | mrs x0, mpidr_el1 |
| 50 | bl platform_set_coherent_stack |
| 51 | |
| 52 | bl tftf_early_platform_setup |
| 53 | bl tftf_plat_arch_setup |
| 54 | |
| 55 | /* -------------------------------------------------------------------- |
| 56 | * Give ourselves a stack allocated in Normal -IS-WBWA memory |
| 57 | * -------------------------------------------------------------------- |
| 58 | */ |
| 59 | mrs x0, mpidr_el1 |
| 60 | bl platform_set_stack |
| 61 | |
| 62 | /* -------------------------------------------------------------------- |
| 63 | * tftf_cold_boot_main() will perform the remaining architectural and |
| 64 | * platform setup, initialise the test framework's state, then run the |
| 65 | * tests. |
| 66 | * -------------------------------------------------------------------- |
| 67 | */ |
| 68 | b tftf_cold_boot_main |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 69 | endfunc tftf_entrypoint |
| 70 | |
| 71 | /* ---------------------------------------------------------------------------- |
| 72 | * Entry point for a CPU that has just been powered up. |
| 73 | * In : x0 - context_id |
| 74 | * ---------------------------------------------------------------------------- |
| 75 | */ |
| 76 | func tftf_hotplug_entry |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 77 | /* -------------------------------------------------------------------- |
| 78 | * Preserve the context_id in a callee-saved register |
| 79 | * -------------------------------------------------------------------- |
| 80 | */ |
| 81 | mov x19, x0 |
| 82 | |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 83 | bl arch_init |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 84 | |
| 85 | /* -------------------------------------------------------------------- |
| 86 | * Give ourselves a small coherent stack to ease the pain of |
| 87 | * initializing the MMU |
| 88 | * -------------------------------------------------------------------- |
| 89 | */ |
| 90 | mrs x0, mpidr_el1 |
| 91 | bl platform_set_coherent_stack |
| 92 | |
| 93 | /* -------------------------------------------------------------------- |
| 94 | * Enable the MMU |
| 95 | * -------------------------------------------------------------------- |
| 96 | */ |
| 97 | bl tftf_plat_enable_mmu |
| 98 | |
| 99 | /* -------------------------------------------------------------------- |
| 100 | * Give ourselves a stack in normal memory. |
| 101 | * -------------------------------------------------------------------- |
| 102 | */ |
| 103 | mrs x0, mpidr_el1 |
| 104 | bl platform_set_stack |
| 105 | |
| 106 | /* -------------------------------------------------------------------- |
| 107 | * Save the context_id for later retrieval by tests |
| 108 | * -------------------------------------------------------------------- |
| 109 | */ |
| 110 | mrs x0, mpidr_el1 |
Antonio Nino Diaz | 8c0f86b | 2018-11-23 13:50:59 +0000 | [diff] [blame] | 111 | mov_imm x1, MPID_MASK |
| 112 | and x0, x0, x1 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 113 | bl platform_get_core_pos |
| 114 | |
| 115 | mov x1, x19 |
| 116 | |
| 117 | bl tftf_set_cpu_on_ctx_id |
| 118 | |
| 119 | /* -------------------------------------------------------------------- |
| 120 | * Jump to warm boot main function |
| 121 | * -------------------------------------------------------------------- |
| 122 | */ |
| 123 | b tftf_warm_boot_main |
| 124 | endfunc tftf_hotplug_entry |
| 125 | |
| 126 | /* ---------------------------------------------------------------------------- |
| 127 | * Saves the mpid of the primary core and if the primary core |
| 128 | * is already saved then it loops infinitely. |
| 129 | * ---------------------------------------------------------------------------- |
| 130 | */ |
| 131 | func save_primary_mpid |
| 132 | adrp x1, tftf_primary_core |
| 133 | ldr w0, [x1, :lo12:tftf_primary_core] |
| 134 | mov w2, #INVALID_MPID |
| 135 | cmp w0, w2 |
| 136 | b.ne panic |
Antonio Nino Diaz | 8c0f86b | 2018-11-23 13:50:59 +0000 | [diff] [blame] | 137 | mov_imm x2, MPID_MASK |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 138 | mrs x0, mpidr_el1 |
| 139 | and x0, x0, x2 |
| 140 | str w0, [x1, :lo12:tftf_primary_core] |
| 141 | ret |
| 142 | panic: |
| 143 | /* Primary core MPID already saved */ |
| 144 | b . |
| 145 | ret |
| 146 | endfunc save_primary_mpid |
Sandrine Bailleux | a1948da | 2018-12-18 10:16:25 +0100 | [diff] [blame] | 147 | |
| 148 | /* Initialize architectural state. */ |
| 149 | func arch_init |
| 150 | mrs x0, CurrentEL |
| 151 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 152 | b.eq el1_setup |
| 153 | |
| 154 | el2_setup: |
| 155 | /* Set the exception vectors. */ |
| 156 | adr x0, tftf_vector |
| 157 | msr vbar_el2, x0 |
| 158 | |
Joel Hutton | 6a6f483 | 2019-04-08 15:46:36 +0100 | [diff] [blame] | 159 | /* Enable the instruction cache and alignment checks. */ |
| 160 | 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] | 161 | msr sctlr_el2, x0 |
| 162 | |
| 163 | isb |
| 164 | ret |
| 165 | |
| 166 | el1_setup: |
| 167 | /* Set the exception vectors. */ |
| 168 | adr x0, tftf_vector |
| 169 | msr vbar_el1, x0 |
| 170 | |
| 171 | /* Enable the instruction cache and stack pointer alignment checks. */ |
Joel Hutton | 6a6f483 | 2019-04-08 15:46:36 +0100 | [diff] [blame] | 172 | 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] | 173 | msr sctlr_el1, x0 |
| 174 | |
| 175 | isb |
| 176 | ret |
| 177 | endfunc arch_init |