Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 1 | /* |
Douglas Raillard | 21362a9 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 7 | #include <arch.h> |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 8 | #include <asm_macros.S> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 9 | #include <tsp.h> |
Antonio Nino Diaz | 4ef91f1 | 2017-02-20 14:22:22 +0000 | [diff] [blame] | 10 | #include <xlat_tables_defs.h> |
Dan Handley | e2c27f5 | 2014-08-01 17:58:27 +0100 | [diff] [blame] | 11 | #include "../tsp_private.h" |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | .globl tsp_entrypoint |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 15 | .globl tsp_vector_table |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 16 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 17 | |
| 18 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 19 | /* --------------------------------------------- |
| 20 | * Populate the params in x0-x7 from the pointer |
| 21 | * to the smc args structure in x0. |
| 22 | * --------------------------------------------- |
| 23 | */ |
| 24 | .macro restore_args_call_smc |
| 25 | ldp x6, x7, [x0, #TSP_ARG6] |
| 26 | ldp x4, x5, [x0, #TSP_ARG4] |
| 27 | ldp x2, x3, [x0, #TSP_ARG2] |
| 28 | ldp x0, x1, [x0, #TSP_ARG0] |
| 29 | smc #0 |
| 30 | .endm |
| 31 | |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 32 | .macro save_eret_context reg1 reg2 |
| 33 | mrs \reg1, elr_el1 |
| 34 | mrs \reg2, spsr_el1 |
| 35 | stp \reg1, \reg2, [sp, #-0x10]! |
| 36 | stp x30, x18, [sp, #-0x10]! |
| 37 | .endm |
| 38 | |
| 39 | .macro restore_eret_context reg1 reg2 |
| 40 | ldp x30, x18, [sp], #0x10 |
| 41 | ldp \reg1, \reg2, [sp], #0x10 |
| 42 | msr elr_el1, \reg1 |
| 43 | msr spsr_el1, \reg2 |
| 44 | .endm |
| 45 | |
Julius Werner | b4c75e9 | 2017-08-01 15:16:36 -0700 | [diff] [blame] | 46 | func tsp_entrypoint _align=3 |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 47 | |
| 48 | /* --------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 49 | * Set the exception vector to something sane. |
| 50 | * --------------------------------------------- |
| 51 | */ |
Achin Gupta | a4f50c2 | 2014-05-09 12:17:56 +0100 | [diff] [blame] | 52 | adr x0, tsp_exceptions |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 53 | msr vbar_el1, x0 |
Achin Gupta | ed1744e | 2014-08-04 23:13:10 +0100 | [diff] [blame] | 54 | isb |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 55 | |
| 56 | /* --------------------------------------------- |
Achin Gupta | ed1744e | 2014-08-04 23:13:10 +0100 | [diff] [blame] | 57 | * Enable the SError interrupt now that the |
| 58 | * exception vectors have been setup. |
| 59 | * --------------------------------------------- |
| 60 | */ |
| 61 | msr daifclr, #DAIF_ABT_BIT |
| 62 | |
| 63 | /* --------------------------------------------- |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 64 | * Enable the instruction cache, stack pointer |
| 65 | * and data access alignment checks |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 66 | * --------------------------------------------- |
| 67 | */ |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 68 | mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT) |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 69 | mrs x0, sctlr_el1 |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 70 | orr x0, x0, x1 |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 71 | msr sctlr_el1, x0 |
| 72 | isb |
| 73 | |
| 74 | /* --------------------------------------------- |
Achin Gupta | e9c4a64 | 2015-09-11 16:03:13 +0100 | [diff] [blame] | 75 | * Invalidate the RW memory used by the BL32 |
| 76 | * image. This includes the data and NOBITS |
| 77 | * sections. This is done to safeguard against |
| 78 | * possible corruption of this memory by dirty |
| 79 | * cache lines in a system cache as a result of |
| 80 | * use by an earlier boot loader stage. |
| 81 | * --------------------------------------------- |
| 82 | */ |
| 83 | adr x0, __RW_START__ |
| 84 | adr x1, __RW_END__ |
| 85 | sub x1, x1, x0 |
| 86 | bl inv_dcache_range |
| 87 | |
| 88 | /* --------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 89 | * Zero out NOBITS sections. There are 2 of them: |
| 90 | * - the .bss section; |
| 91 | * - the coherent memory section. |
| 92 | * --------------------------------------------- |
| 93 | */ |
| 94 | ldr x0, =__BSS_START__ |
| 95 | ldr x1, =__BSS_SIZE__ |
Douglas Raillard | 21362a9 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 96 | bl zeromem |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 97 | |
Soby Mathew | 2ae2043 | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 98 | #if USE_COHERENT_MEM |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 99 | ldr x0, =__COHERENT_RAM_START__ |
| 100 | ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__ |
Douglas Raillard | 21362a9 | 2016-12-02 13:51:54 +0000 | [diff] [blame] | 101 | bl zeromem |
Soby Mathew | 2ae2043 | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 102 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 103 | |
| 104 | /* -------------------------------------------- |
Achin Gupta | f4a9709 | 2014-06-25 19:26:22 +0100 | [diff] [blame] | 105 | * Allocate a stack whose memory will be marked |
| 106 | * as Normal-IS-WBWA when the MMU is enabled. |
| 107 | * There is no risk of reading stale stack |
| 108 | * memory after enabling the MMU as only the |
| 109 | * primary cpu is running at the moment. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 110 | * -------------------------------------------- |
| 111 | */ |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 112 | bl plat_set_my_stack |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 113 | |
| 114 | /* --------------------------------------------- |
Douglas Raillard | 306593d | 2017-02-24 18:14:15 +0000 | [diff] [blame] | 115 | * Initialize the stack protector canary before |
| 116 | * any C code is called. |
| 117 | * --------------------------------------------- |
| 118 | */ |
| 119 | #if STACK_PROTECTOR_ENABLED |
| 120 | bl update_stack_protector_canary |
| 121 | #endif |
| 122 | |
| 123 | /* --------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 124 | * Perform early platform setup & platform |
| 125 | * specific early arch. setup e.g. mmu setup |
| 126 | * --------------------------------------------- |
| 127 | */ |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 128 | bl tsp_early_platform_setup |
| 129 | bl tsp_plat_arch_setup |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 130 | |
| 131 | /* --------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 132 | * Jump to main function. |
| 133 | * --------------------------------------------- |
| 134 | */ |
| 135 | bl tsp_main |
| 136 | |
| 137 | /* --------------------------------------------- |
| 138 | * Tell TSPD that we are done initialising |
| 139 | * --------------------------------------------- |
| 140 | */ |
| 141 | mov x1, x0 |
| 142 | mov x0, #TSP_ENTRY_DONE |
| 143 | smc #0 |
| 144 | |
| 145 | tsp_entrypoint_panic: |
| 146 | b tsp_entrypoint_panic |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 147 | endfunc tsp_entrypoint |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 148 | |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 149 | |
| 150 | /* ------------------------------------------- |
| 151 | * Table of entrypoint vectors provided to the |
| 152 | * TSPD for the various entrypoints |
| 153 | * ------------------------------------------- |
| 154 | */ |
| 155 | func tsp_vector_table |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 156 | b tsp_yield_smc_entry |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 157 | b tsp_fast_smc_entry |
| 158 | b tsp_cpu_on_entry |
| 159 | b tsp_cpu_off_entry |
| 160 | b tsp_cpu_resume_entry |
| 161 | b tsp_cpu_suspend_entry |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 162 | b tsp_sel1_intr_entry |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 163 | b tsp_system_off_entry |
| 164 | b tsp_system_reset_entry |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 165 | b tsp_abort_yield_smc_entry |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 166 | endfunc tsp_vector_table |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 167 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 168 | /*--------------------------------------------- |
| 169 | * This entrypoint is used by the TSPD when this |
| 170 | * cpu is to be turned off through a CPU_OFF |
| 171 | * psci call to ask the TSP to perform any |
| 172 | * bookeeping necessary. In the current |
| 173 | * implementation, the TSPD expects the TSP to |
| 174 | * re-initialise its state so nothing is done |
| 175 | * here except for acknowledging the request. |
| 176 | * --------------------------------------------- |
| 177 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 178 | func tsp_cpu_off_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 179 | bl tsp_cpu_off_main |
| 180 | restore_args_call_smc |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 181 | endfunc tsp_cpu_off_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 182 | |
| 183 | /*--------------------------------------------- |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 184 | * This entrypoint is used by the TSPD when the |
| 185 | * system is about to be switched off (through |
| 186 | * a SYSTEM_OFF psci call) to ask the TSP to |
| 187 | * perform any necessary bookkeeping. |
| 188 | * --------------------------------------------- |
| 189 | */ |
| 190 | func tsp_system_off_entry |
| 191 | bl tsp_system_off_main |
| 192 | restore_args_call_smc |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 193 | endfunc tsp_system_off_entry |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 194 | |
| 195 | /*--------------------------------------------- |
| 196 | * This entrypoint is used by the TSPD when the |
| 197 | * system is about to be reset (through a |
| 198 | * SYSTEM_RESET psci call) to ask the TSP to |
| 199 | * perform any necessary bookkeeping. |
| 200 | * --------------------------------------------- |
| 201 | */ |
| 202 | func tsp_system_reset_entry |
| 203 | bl tsp_system_reset_main |
| 204 | restore_args_call_smc |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 205 | endfunc tsp_system_reset_entry |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 206 | |
| 207 | /*--------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 208 | * This entrypoint is used by the TSPD when this |
| 209 | * cpu is turned on using a CPU_ON psci call to |
| 210 | * ask the TSP to initialise itself i.e. setup |
| 211 | * the mmu, stacks etc. Minimal architectural |
| 212 | * state will be initialised by the TSPD when |
| 213 | * this function is entered i.e. Caches and MMU |
| 214 | * will be turned off, the execution state |
| 215 | * will be aarch64 and exceptions masked. |
| 216 | * --------------------------------------------- |
| 217 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 218 | func tsp_cpu_on_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 219 | /* --------------------------------------------- |
| 220 | * Set the exception vector to something sane. |
| 221 | * --------------------------------------------- |
| 222 | */ |
Achin Gupta | a4f50c2 | 2014-05-09 12:17:56 +0100 | [diff] [blame] | 223 | adr x0, tsp_exceptions |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 224 | msr vbar_el1, x0 |
Achin Gupta | ed1744e | 2014-08-04 23:13:10 +0100 | [diff] [blame] | 225 | isb |
| 226 | |
| 227 | /* Enable the SError interrupt */ |
| 228 | msr daifclr, #DAIF_ABT_BIT |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 229 | |
| 230 | /* --------------------------------------------- |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 231 | * Enable the instruction cache, stack pointer |
| 232 | * and data access alignment checks |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 233 | * --------------------------------------------- |
| 234 | */ |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 235 | mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT) |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 236 | mrs x0, sctlr_el1 |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 237 | orr x0, x0, x1 |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 238 | msr sctlr_el1, x0 |
| 239 | isb |
| 240 | |
| 241 | /* -------------------------------------------- |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 242 | * Give ourselves a stack whose memory will be |
| 243 | * marked as Normal-IS-WBWA when the MMU is |
| 244 | * enabled. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 245 | * -------------------------------------------- |
| 246 | */ |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 247 | bl plat_set_my_stack |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 248 | |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 249 | /* -------------------------------------------- |
| 250 | * Enable the MMU with the DCache disabled. It |
| 251 | * is safe to use stacks allocated in normal |
| 252 | * memory as a result. All memory accesses are |
| 253 | * marked nGnRnE when the MMU is disabled. So |
| 254 | * all the stack writes will make it to memory. |
| 255 | * All memory accesses are marked Non-cacheable |
| 256 | * when the MMU is enabled but D$ is disabled. |
| 257 | * So used stack memory is guaranteed to be |
| 258 | * visible immediately after the MMU is enabled |
| 259 | * Enabling the DCache at the same time as the |
| 260 | * MMU can lead to speculatively fetched and |
| 261 | * possibly stale stack memory being read from |
| 262 | * other caches. This can lead to coherency |
| 263 | * issues. |
| 264 | * -------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 265 | */ |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 266 | mov x0, #DISABLE_DCACHE |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 267 | bl bl32_plat_enable_mmu |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 268 | |
| 269 | /* --------------------------------------------- |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 270 | * Enable the Data cache now that the MMU has |
| 271 | * been enabled. The stack has been unwound. It |
| 272 | * will be written first before being read. This |
| 273 | * will invalidate any stale cache lines resi- |
| 274 | * -dent in other caches. We assume that |
| 275 | * interconnect coherency has been enabled for |
| 276 | * this cluster by EL3 firmware. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 277 | * --------------------------------------------- |
| 278 | */ |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 279 | mrs x0, sctlr_el1 |
| 280 | orr x0, x0, #SCTLR_C_BIT |
| 281 | msr sctlr_el1, x0 |
| 282 | isb |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 283 | |
| 284 | /* --------------------------------------------- |
| 285 | * Enter C runtime to perform any remaining |
| 286 | * book keeping |
| 287 | * --------------------------------------------- |
| 288 | */ |
| 289 | bl tsp_cpu_on_main |
| 290 | restore_args_call_smc |
| 291 | |
| 292 | /* Should never reach here */ |
| 293 | tsp_cpu_on_entry_panic: |
| 294 | b tsp_cpu_on_entry_panic |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 295 | endfunc tsp_cpu_on_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 296 | |
| 297 | /*--------------------------------------------- |
| 298 | * This entrypoint is used by the TSPD when this |
| 299 | * cpu is to be suspended through a CPU_SUSPEND |
| 300 | * psci call to ask the TSP to perform any |
| 301 | * bookeeping necessary. In the current |
| 302 | * implementation, the TSPD saves and restores |
| 303 | * the EL1 state. |
| 304 | * --------------------------------------------- |
| 305 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 306 | func tsp_cpu_suspend_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 307 | bl tsp_cpu_suspend_main |
| 308 | restore_args_call_smc |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 309 | endfunc tsp_cpu_suspend_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 310 | |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 311 | /*------------------------------------------------- |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 312 | * This entrypoint is used by the TSPD to pass |
Soby Mathew | 7866424 | 2015-11-13 02:08:43 +0000 | [diff] [blame] | 313 | * control for `synchronously` handling a S-EL1 |
| 314 | * Interrupt which was triggered while executing |
| 315 | * in normal world. 'x0' contains a magic number |
| 316 | * which indicates this. TSPD expects control to |
| 317 | * be handed back at the end of interrupt |
| 318 | * processing. This is done through an SMC. |
| 319 | * The handover agreement is: |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 320 | * |
| 321 | * 1. PSTATE.DAIF are set upon entry. 'x1' has |
| 322 | * the ELR_EL3 from the non-secure state. |
| 323 | * 2. TSP has to preserve the callee saved |
| 324 | * general purpose registers, SP_EL1/EL0 and |
| 325 | * LR. |
| 326 | * 3. TSP has to preserve the system and vfp |
| 327 | * registers (if applicable). |
| 328 | * 4. TSP can use 'x0-x18' to enable its C |
| 329 | * runtime. |
| 330 | * 5. TSP returns to TSPD using an SMC with |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 331 | * 'x0' = TSP_HANDLED_S_EL1_INTR |
| 332 | * ------------------------------------------------ |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 333 | */ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 334 | func tsp_sel1_intr_entry |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 335 | #if DEBUG |
Soby Mathew | 7866424 | 2015-11-13 02:08:43 +0000 | [diff] [blame] | 336 | mov_imm x2, TSP_HANDLE_SEL1_INTR_AND_RETURN |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 337 | cmp x0, x2 |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 338 | b.ne tsp_sel1_int_entry_panic |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 339 | #endif |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 340 | /*------------------------------------------------- |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 341 | * Save any previous context needed to perform |
| 342 | * an exception return from S-EL1 e.g. context |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 343 | * from a previous Non secure Interrupt. |
| 344 | * Update statistics and handle the S-EL1 |
| 345 | * interrupt before returning to the TSPD. |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 346 | * IRQ/FIQs are not enabled since that will |
| 347 | * complicate the implementation. Execution |
| 348 | * will be transferred back to the normal world |
Soby Mathew | 7866424 | 2015-11-13 02:08:43 +0000 | [diff] [blame] | 349 | * in any case. The handler can return 0 |
| 350 | * if the interrupt was handled or TSP_PREEMPTED |
| 351 | * if the expected interrupt was preempted |
| 352 | * by an interrupt that should be handled in EL3 |
| 353 | * e.g. Group 0 interrupt in GICv3. In both |
| 354 | * the cases switch to EL3 using SMC with id |
| 355 | * TSP_HANDLED_S_EL1_INTR. Any other return value |
| 356 | * from the handler will result in panic. |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 357 | * ------------------------------------------------ |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 358 | */ |
| 359 | save_eret_context x2 x3 |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 360 | bl tsp_update_sync_sel1_intr_stats |
| 361 | bl tsp_common_int_handler |
Soby Mathew | 7866424 | 2015-11-13 02:08:43 +0000 | [diff] [blame] | 362 | /* Check if the S-EL1 interrupt has been handled */ |
| 363 | cbnz x0, tsp_sel1_intr_check_preemption |
| 364 | b tsp_sel1_intr_return |
| 365 | tsp_sel1_intr_check_preemption: |
| 366 | /* Check if the S-EL1 interrupt has been preempted */ |
| 367 | mov_imm x1, TSP_PREEMPTED |
| 368 | cmp x0, x1 |
| 369 | b.ne tsp_sel1_int_entry_panic |
| 370 | tsp_sel1_intr_return: |
| 371 | mov_imm x0, TSP_HANDLED_S_EL1_INTR |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 372 | restore_eret_context x2 x3 |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 373 | smc #0 |
| 374 | |
Soby Mathew | 7866424 | 2015-11-13 02:08:43 +0000 | [diff] [blame] | 375 | /* Should never reach here */ |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 376 | tsp_sel1_int_entry_panic: |
Jeenu Viswambharan | 68aef10 | 2016-11-30 15:21:11 +0000 | [diff] [blame] | 377 | no_ret plat_panic_handler |
Soby Mathew | bec9851 | 2015-09-03 18:29:38 +0100 | [diff] [blame] | 378 | endfunc tsp_sel1_intr_entry |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 379 | |
| 380 | /*--------------------------------------------- |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 381 | * This entrypoint is used by the TSPD when this |
| 382 | * cpu resumes execution after an earlier |
| 383 | * CPU_SUSPEND psci call to ask the TSP to |
| 384 | * restore its saved context. In the current |
| 385 | * implementation, the TSPD saves and restores |
| 386 | * EL1 state so nothing is done here apart from |
| 387 | * acknowledging the request. |
| 388 | * --------------------------------------------- |
| 389 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 390 | func tsp_cpu_resume_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 391 | bl tsp_cpu_resume_main |
| 392 | restore_args_call_smc |
Antonio Nino Diaz | 1f21bcf | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 393 | |
| 394 | /* Should never reach here */ |
Jeenu Viswambharan | 68aef10 | 2016-11-30 15:21:11 +0000 | [diff] [blame] | 395 | no_ret plat_panic_handler |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 396 | endfunc tsp_cpu_resume_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 397 | |
| 398 | /*--------------------------------------------- |
| 399 | * This entrypoint is used by the TSPD to ask |
| 400 | * the TSP to service a fast smc request. |
| 401 | * --------------------------------------------- |
| 402 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 403 | func tsp_fast_smc_entry |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 404 | bl tsp_smc_handler |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 405 | restore_args_call_smc |
Antonio Nino Diaz | 1f21bcf | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 406 | |
| 407 | /* Should never reach here */ |
Jeenu Viswambharan | 68aef10 | 2016-11-30 15:21:11 +0000 | [diff] [blame] | 408 | no_ret plat_panic_handler |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 409 | endfunc tsp_fast_smc_entry |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 410 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 411 | /*--------------------------------------------- |
| 412 | * This entrypoint is used by the TSPD to ask |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 413 | * the TSP to service a Yielding SMC request. |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 414 | * We will enable preemption during execution |
| 415 | * of tsp_smc_handler. |
| 416 | * --------------------------------------------- |
| 417 | */ |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 418 | func tsp_yield_smc_entry |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 419 | msr daifclr, #DAIF_FIQ_BIT | DAIF_IRQ_BIT |
| 420 | bl tsp_smc_handler |
| 421 | msr daifset, #DAIF_FIQ_BIT | DAIF_IRQ_BIT |
| 422 | restore_args_call_smc |
Antonio Nino Diaz | 1f21bcf | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 423 | |
| 424 | /* Should never reach here */ |
Jeenu Viswambharan | 68aef10 | 2016-11-30 15:21:11 +0000 | [diff] [blame] | 425 | no_ret plat_panic_handler |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 426 | endfunc tsp_yield_smc_entry |
Douglas Raillard | f212965 | 2016-11-24 15:43:19 +0000 | [diff] [blame] | 427 | |
| 428 | /*--------------------------------------------------------------------- |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 429 | * This entrypoint is used by the TSPD to abort a pre-empted Yielding |
Douglas Raillard | f212965 | 2016-11-24 15:43:19 +0000 | [diff] [blame] | 430 | * SMC. It could be on behalf of non-secure world or because a CPU |
| 431 | * suspend/CPU off request needs to abort the preempted SMC. |
| 432 | * -------------------------------------------------------------------- |
| 433 | */ |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 434 | func tsp_abort_yield_smc_entry |
Douglas Raillard | f212965 | 2016-11-24 15:43:19 +0000 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * Exceptions masking is already done by the TSPD when entering this |
| 438 | * hook so there is no need to do it here. |
| 439 | */ |
| 440 | |
| 441 | /* Reset the stack used by the pre-empted SMC */ |
| 442 | bl plat_set_my_stack |
| 443 | |
| 444 | /* |
| 445 | * Allow some cleanup such as releasing locks. |
| 446 | */ |
| 447 | bl tsp_abort_smc_handler |
| 448 | |
| 449 | restore_args_call_smc |
| 450 | |
| 451 | /* Should never reach here */ |
| 452 | bl plat_panic_handler |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 453 | endfunc tsp_abort_yield_smc_entry |