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