Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 35b37f0 | 2018-01-08 17:33:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <assert.h> |
| 9 | #include <bl31.h> |
| 10 | #include <context_mgmt.h> |
| 11 | #include <debug.h> |
Sughosh Ganu | e77f9e8 | 2018-11-14 11:06:24 +0530 | [diff] [blame] | 12 | #include <ehf.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <platform.h> |
| 15 | #include <runtime_svc.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 16 | #include <smccc.h> |
| 17 | #include <smccc_helpers.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 18 | #include <spinlock.h> |
Antonio Nino Diaz | b5b585a | 2018-11-08 14:20:07 +0000 | [diff] [blame] | 19 | #include <string.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 20 | #include <spm_svc.h> |
Antonio Nino Diaz | 8c83ad8 | 2018-11-08 14:21:19 +0000 | [diff] [blame] | 21 | #include <sprt_svc.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 22 | #include <utils.h> |
| 23 | #include <xlat_tables_v2.h> |
| 24 | |
| 25 | #include "spm_private.h" |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 26 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 27 | /******************************************************************************* |
| 28 | * Secure Partition context information. |
| 29 | ******************************************************************************/ |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 30 | sp_context_t sp_ctx_array[PLAT_SPM_MAX_PARTITIONS]; |
| 31 | |
| 32 | /* Last Secure Partition last used by the CPU */ |
| 33 | sp_context_t *cpu_sp_ctx[PLATFORM_CORE_COUNT]; |
| 34 | |
| 35 | void spm_cpu_set_sp_ctx(unsigned int linear_id, sp_context_t *sp_ctx) |
| 36 | { |
| 37 | assert(linear_id < PLATFORM_CORE_COUNT); |
| 38 | |
| 39 | cpu_sp_ctx[linear_id] = sp_ctx; |
| 40 | } |
| 41 | |
| 42 | sp_context_t *spm_cpu_get_sp_ctx(unsigned int linear_id) |
| 43 | { |
| 44 | assert(linear_id < PLATFORM_CORE_COUNT); |
| 45 | |
| 46 | return cpu_sp_ctx[linear_id]; |
| 47 | } |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 48 | |
| 49 | /******************************************************************************* |
Antonio Nino Diaz | 44ef4eb | 2018-07-03 19:54:59 +0100 | [diff] [blame^] | 50 | * Functions to keep track of how many requests a Secure Partition has received |
| 51 | * and hasn't finished. |
| 52 | ******************************************************************************/ |
| 53 | void spm_sp_request_increase(sp_context_t *sp_ctx) |
| 54 | { |
| 55 | spin_lock(&(sp_ctx->request_count_lock)); |
| 56 | sp_ctx->request_count++; |
| 57 | spin_unlock(&(sp_ctx->request_count_lock)); |
| 58 | } |
| 59 | |
| 60 | void spm_sp_request_decrease(sp_context_t *sp_ctx) |
| 61 | { |
| 62 | spin_lock(&(sp_ctx->request_count_lock)); |
| 63 | sp_ctx->request_count--; |
| 64 | spin_unlock(&(sp_ctx->request_count_lock)); |
| 65 | } |
| 66 | |
| 67 | /* Returns 0 if it was originally 0, -1 otherwise. */ |
| 68 | int spm_sp_request_increase_if_zero(sp_context_t *sp_ctx) |
| 69 | { |
| 70 | int ret = -1; |
| 71 | |
| 72 | spin_lock(&(sp_ctx->request_count_lock)); |
| 73 | if (sp_ctx->request_count == 0U) { |
| 74 | sp_ctx->request_count++; |
| 75 | ret = 0U; |
| 76 | } |
| 77 | spin_unlock(&(sp_ctx->request_count_lock)); |
| 78 | |
| 79 | return ret; |
| 80 | } |
| 81 | |
| 82 | /******************************************************************************* |
Antonio Nino Diaz | b5b585a | 2018-11-08 14:20:07 +0000 | [diff] [blame] | 83 | * This function returns a pointer to the context of the Secure Partition that |
| 84 | * handles the service specified by an UUID. It returns NULL if the UUID wasn't |
| 85 | * found. |
| 86 | ******************************************************************************/ |
| 87 | sp_context_t *spm_sp_get_by_uuid(const uint32_t (*svc_uuid)[4]) |
| 88 | { |
| 89 | unsigned int i; |
| 90 | |
| 91 | for (i = 0U; i < PLAT_SPM_MAX_PARTITIONS; i++) { |
| 92 | |
| 93 | sp_context_t *sp_ctx = &sp_ctx_array[i]; |
| 94 | |
| 95 | if (sp_ctx->is_present == 0) { |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | struct sp_rd_sect_service *rdsvc; |
| 100 | |
| 101 | for (rdsvc = sp_ctx->rd.service; rdsvc != NULL; |
| 102 | rdsvc = rdsvc->next) { |
| 103 | uint32_t *rd_uuid = (uint32_t *)(rdsvc->uuid); |
| 104 | |
| 105 | if (memcmp(rd_uuid, svc_uuid, sizeof(rd_uuid)) == 0) { |
| 106 | return sp_ctx; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | /******************************************************************************* |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 115 | * Set state of a Secure Partition context. |
| 116 | ******************************************************************************/ |
| 117 | void sp_state_set(sp_context_t *sp_ptr, sp_state_t state) |
| 118 | { |
| 119 | spin_lock(&(sp_ptr->state_lock)); |
| 120 | sp_ptr->state = state; |
| 121 | spin_unlock(&(sp_ptr->state_lock)); |
| 122 | } |
| 123 | |
| 124 | /******************************************************************************* |
| 125 | * Wait until the state of a Secure Partition is the specified one and change it |
| 126 | * to the desired state. |
| 127 | ******************************************************************************/ |
| 128 | void sp_state_wait_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to) |
| 129 | { |
| 130 | int success = 0; |
| 131 | |
| 132 | while (success == 0) { |
| 133 | spin_lock(&(sp_ptr->state_lock)); |
| 134 | |
| 135 | if (sp_ptr->state == from) { |
| 136 | sp_ptr->state = to; |
| 137 | |
| 138 | success = 1; |
| 139 | } |
| 140 | |
| 141 | spin_unlock(&(sp_ptr->state_lock)); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /******************************************************************************* |
| 146 | * Check if the state of a Secure Partition is the specified one and, if so, |
| 147 | * change it to the desired state. Returns 0 on success, -1 on error. |
| 148 | ******************************************************************************/ |
| 149 | int sp_state_try_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to) |
| 150 | { |
| 151 | int ret = -1; |
| 152 | |
| 153 | spin_lock(&(sp_ptr->state_lock)); |
| 154 | |
| 155 | if (sp_ptr->state == from) { |
| 156 | sp_ptr->state = to; |
| 157 | |
| 158 | ret = 0; |
| 159 | } |
| 160 | |
| 161 | spin_unlock(&(sp_ptr->state_lock)); |
| 162 | |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | /******************************************************************************* |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 167 | * This function takes an SP context pointer and performs a synchronous entry |
| 168 | * into it. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 169 | ******************************************************************************/ |
Antonio Nino Diaz | 8c83ad8 | 2018-11-08 14:21:19 +0000 | [diff] [blame] | 170 | uint64_t spm_sp_synchronous_entry(sp_context_t *sp_ctx) |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 171 | { |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 172 | uint64_t rc; |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 173 | unsigned int linear_id = plat_my_core_pos(); |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 174 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 175 | assert(sp_ctx != NULL); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 176 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 177 | /* Assign the context of the SP to this CPU */ |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 178 | spm_cpu_set_sp_ctx(linear_id, sp_ctx); |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 179 | cm_set_context(&(sp_ctx->cpu_ctx), SECURE); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 180 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 181 | /* Restore the context assigned above */ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 182 | cm_el1_sysregs_context_restore(SECURE); |
| 183 | cm_set_next_eret_context(SECURE); |
| 184 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 185 | /* Invalidate TLBs at EL1. */ |
| 186 | tlbivmalle1(); |
| 187 | dsbish(); |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 188 | |
| 189 | /* Enter Secure Partition */ |
| 190 | rc = spm_secure_partition_enter(&sp_ctx->c_rt_ctx); |
| 191 | |
| 192 | /* Save secure state */ |
| 193 | cm_el1_sysregs_context_save(SECURE); |
| 194 | |
| 195 | return rc; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 198 | /******************************************************************************* |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 199 | * This function returns to the place where spm_sp_synchronous_entry() was |
| 200 | * called originally. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 201 | ******************************************************************************/ |
Antonio Nino Diaz | 8c83ad8 | 2018-11-08 14:21:19 +0000 | [diff] [blame] | 202 | __dead2 void spm_sp_synchronous_exit(uint64_t rc) |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 203 | { |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 204 | /* Get context of the SP in use by this CPU. */ |
| 205 | unsigned int linear_id = plat_my_core_pos(); |
| 206 | sp_context_t *ctx = spm_cpu_get_sp_ctx(linear_id); |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 207 | |
| 208 | /* |
| 209 | * The SPM must have initiated the original request through a |
| 210 | * synchronous entry into the secure partition. Jump back to the |
| 211 | * original C runtime context with the value of rc in x0; |
| 212 | */ |
| 213 | spm_secure_partition_exit(ctx->c_rt_ctx, rc); |
| 214 | |
| 215 | panic(); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /******************************************************************************* |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 219 | * Jump to each Secure Partition for the first time. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 220 | ******************************************************************************/ |
Antonio Nino Diaz | e881147 | 2018-04-17 15:10:18 +0100 | [diff] [blame] | 221 | static int32_t spm_init(void) |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 222 | { |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 223 | uint64_t rc = 0; |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 224 | sp_context_t *ctx; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 225 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 226 | for (unsigned int i = 0U; i < PLAT_SPM_MAX_PARTITIONS; i++) { |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 227 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 228 | ctx = &sp_ctx_array[i]; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 229 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 230 | if (ctx->is_present == 0) { |
| 231 | continue; |
| 232 | } |
| 233 | |
| 234 | INFO("Secure Partition %u init...\n", i); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 235 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 236 | ctx->state = SP_STATE_RESET; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 237 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 238 | rc = spm_sp_synchronous_entry(ctx); |
Antonio Nino Diaz | 8c83ad8 | 2018-11-08 14:21:19 +0000 | [diff] [blame] | 239 | if (rc != SPRT_YIELD_AARCH64) { |
| 240 | ERROR("Unexpected return value 0x%llx\n", rc); |
| 241 | panic(); |
| 242 | } |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 243 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 244 | ctx->state = SP_STATE_IDLE; |
| 245 | |
| 246 | INFO("Secure Partition %u initialized.\n", i); |
| 247 | } |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 248 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 249 | return rc; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /******************************************************************************* |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 253 | * Initialize contexts of all Secure Partitions. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 254 | ******************************************************************************/ |
| 255 | int32_t spm_setup(void) |
| 256 | { |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 257 | int rc; |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 258 | sp_context_t *ctx; |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 259 | void *sp_base, *rd_base; |
| 260 | size_t sp_size, rd_size; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 261 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 262 | /* Disable MMU at EL1 (initialized by BL2) */ |
| 263 | disable_mmu_icache_el1(); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 264 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 265 | unsigned int i = 0U; |
| 266 | |
| 267 | while (1) { |
| 268 | rc = plat_spm_sp_get_next_address(&sp_base, &sp_size, |
| 269 | &rd_base, &rd_size); |
| 270 | if (rc < 0) { |
| 271 | /* Reached the end of the package. */ |
| 272 | break; |
| 273 | } |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 274 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 275 | if (i >= PLAT_SPM_MAX_PARTITIONS) { |
| 276 | ERROR("Too many partitions in the package.\n"); |
| 277 | panic(); |
| 278 | } |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 279 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 280 | ctx = &sp_ctx_array[i]; |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 281 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 282 | assert(ctx->is_present == 0); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 283 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 284 | /* Initialize context of the SP */ |
| 285 | INFO("Secure Partition %u context setup start...\n", i); |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 286 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 287 | /* Assign translation tables context. */ |
| 288 | ctx->xlat_ctx_handle = spm_sp_xlat_context_alloc(); |
| 289 | |
| 290 | /* Save location of the image in physical memory */ |
| 291 | ctx->image_base = (uintptr_t)sp_base; |
| 292 | ctx->image_size = sp_size; |
| 293 | |
| 294 | rc = plat_spm_sp_rd_load(&ctx->rd, rd_base, rd_size); |
| 295 | if (rc < 0) { |
| 296 | ERROR("Error while loading RD blob.\n"); |
| 297 | panic(); |
| 298 | } |
| 299 | |
| 300 | spm_sp_setup(ctx); |
| 301 | |
| 302 | ctx->is_present = 1; |
| 303 | |
| 304 | INFO("Secure Partition %u setup done.\n", i); |
| 305 | |
| 306 | i++; |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 309 | if (i == 0U) { |
| 310 | ERROR("No present partitions in the package.\n"); |
| 311 | panic(); |
| 312 | } |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 313 | |
| 314 | /* Register init function for deferred init. */ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 315 | bl31_register_bl32_init(&spm_init); |
| 316 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 317 | return 0; |
| 318 | } |
| 319 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 320 | /******************************************************************************* |
| 321 | * Secure Partition Manager SMC handler. |
| 322 | ******************************************************************************/ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 323 | uint64_t spm_smc_handler(uint32_t smc_fid, |
| 324 | uint64_t x1, |
| 325 | uint64_t x2, |
| 326 | uint64_t x3, |
| 327 | uint64_t x4, |
| 328 | void *cookie, |
| 329 | void *handle, |
| 330 | uint64_t flags) |
| 331 | { |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 332 | unsigned int ns; |
| 333 | |
| 334 | /* Determine which security state this SMC originated from */ |
| 335 | ns = is_caller_non_secure(flags); |
| 336 | |
| 337 | if (ns == SMC_FROM_SECURE) { |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 338 | unsigned int linear_id = plat_my_core_pos(); |
| 339 | sp_context_t *sp_ctx = spm_cpu_get_sp_ctx(linear_id); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 340 | |
| 341 | /* Handle SMCs from Secure world. */ |
| 342 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 343 | assert(handle == cm_get_context(SECURE)); |
| 344 | |
| 345 | /* Make next ERET jump to S-EL0 instead of S-EL1. */ |
| 346 | cm_set_elr_spsr_el3(SECURE, read_elr_el1(), read_spsr_el1()); |
| 347 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 348 | switch (smc_fid) { |
| 349 | |
Sandrine Bailleux | 843d3f0 | 2017-12-07 09:48:56 +0000 | [diff] [blame] | 350 | case SPM_VERSION_AARCH32: |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 351 | SMC_RET1(handle, SPM_VERSION_COMPILED); |
| 352 | |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 353 | case SP_MEMORY_ATTRIBUTES_GET_AARCH64: |
| 354 | INFO("Received SP_MEMORY_ATTRIBUTES_GET_AARCH64 SMC\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 355 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 356 | if (sp_ctx->state != SP_STATE_RESET) { |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 357 | WARN("SP_MEMORY_ATTRIBUTES_GET_AARCH64 is available at boot time only\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 358 | SMC_RET1(handle, SPM_NOT_SUPPORTED); |
| 359 | } |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 360 | SMC_RET1(handle, |
| 361 | spm_memory_attributes_get_smc_handler( |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 362 | sp_ctx, x1)); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 363 | |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 364 | case SP_MEMORY_ATTRIBUTES_SET_AARCH64: |
| 365 | INFO("Received SP_MEMORY_ATTRIBUTES_SET_AARCH64 SMC\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 366 | |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 367 | if (sp_ctx->state != SP_STATE_RESET) { |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 368 | WARN("SP_MEMORY_ATTRIBUTES_SET_AARCH64 is available at boot time only\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 369 | SMC_RET1(handle, SPM_NOT_SUPPORTED); |
| 370 | } |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 371 | SMC_RET1(handle, |
| 372 | spm_memory_attributes_set_smc_handler( |
Antonio Nino Diaz | 8cc23f9 | 2018-10-30 11:35:30 +0000 | [diff] [blame] | 373 | sp_ctx, x1, x2, x3)); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 374 | default: |
| 375 | break; |
| 376 | } |
| 377 | } else { |
| 378 | |
| 379 | /* Handle SMCs from Non-secure world. */ |
| 380 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 381 | assert(handle == cm_get_context(NON_SECURE)); |
| 382 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 383 | switch (smc_fid) { |
| 384 | |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 385 | case SP_MEMORY_ATTRIBUTES_GET_AARCH64: |
| 386 | case SP_MEMORY_ATTRIBUTES_SET_AARCH64: |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 387 | /* SMC interfaces reserved for secure callers. */ |
| 388 | SMC_RET1(handle, SPM_NOT_SUPPORTED); |
| 389 | |
| 390 | default: |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | SMC_RET1(handle, SMC_UNK); |
| 396 | } |