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> |
| 12 | #include <errno.h> |
Antonio Nino Diaz | 35b37f0 | 2018-01-08 17:33:34 +0000 | [diff] [blame] | 13 | #include <mm_svc.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 14 | #include <platform.h> |
| 15 | #include <runtime_svc.h> |
| 16 | #include <secure_partition.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 17 | #include <smccc.h> |
| 18 | #include <smccc_helpers.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 19 | #include <spinlock.h> |
| 20 | #include <spm_svc.h> |
| 21 | #include <utils.h> |
| 22 | #include <xlat_tables_v2.h> |
| 23 | |
| 24 | #include "spm_private.h" |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 25 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 26 | /******************************************************************************* |
| 27 | * Secure Partition context information. |
| 28 | ******************************************************************************/ |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 29 | static sp_context_t sp_ctx; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 30 | |
| 31 | /******************************************************************************* |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 32 | * Set state of a Secure Partition context. |
| 33 | ******************************************************************************/ |
| 34 | void sp_state_set(sp_context_t *sp_ptr, sp_state_t state) |
| 35 | { |
| 36 | spin_lock(&(sp_ptr->state_lock)); |
| 37 | sp_ptr->state = state; |
| 38 | spin_unlock(&(sp_ptr->state_lock)); |
| 39 | } |
| 40 | |
| 41 | /******************************************************************************* |
| 42 | * Wait until the state of a Secure Partition is the specified one and change it |
| 43 | * to the desired state. |
| 44 | ******************************************************************************/ |
| 45 | void sp_state_wait_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to) |
| 46 | { |
| 47 | int success = 0; |
| 48 | |
| 49 | while (success == 0) { |
| 50 | spin_lock(&(sp_ptr->state_lock)); |
| 51 | |
| 52 | if (sp_ptr->state == from) { |
| 53 | sp_ptr->state = to; |
| 54 | |
| 55 | success = 1; |
| 56 | } |
| 57 | |
| 58 | spin_unlock(&(sp_ptr->state_lock)); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /******************************************************************************* |
| 63 | * Check if the state of a Secure Partition is the specified one and, if so, |
| 64 | * change it to the desired state. Returns 0 on success, -1 on error. |
| 65 | ******************************************************************************/ |
| 66 | int sp_state_try_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to) |
| 67 | { |
| 68 | int ret = -1; |
| 69 | |
| 70 | spin_lock(&(sp_ptr->state_lock)); |
| 71 | |
| 72 | if (sp_ptr->state == from) { |
| 73 | sp_ptr->state = to; |
| 74 | |
| 75 | ret = 0; |
| 76 | } |
| 77 | |
| 78 | spin_unlock(&(sp_ptr->state_lock)); |
| 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | /******************************************************************************* |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 84 | * This function takes an SP context pointer and performs a synchronous entry |
| 85 | * into it. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 86 | ******************************************************************************/ |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 87 | static uint64_t spm_sp_synchronous_entry(sp_context_t *sp_ctx) |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 88 | { |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 89 | uint64_t rc; |
| 90 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 91 | assert(sp_ctx != NULL); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 92 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 93 | /* Assign the context of the SP to this CPU */ |
| 94 | cm_set_context(&(sp_ctx->cpu_ctx), SECURE); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 95 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 96 | /* Restore the context assigned above */ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 97 | cm_el1_sysregs_context_restore(SECURE); |
| 98 | cm_set_next_eret_context(SECURE); |
| 99 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 100 | /* Invalidate TLBs at EL1. */ |
| 101 | tlbivmalle1(); |
| 102 | dsbish(); |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 103 | |
| 104 | /* Enter Secure Partition */ |
| 105 | rc = spm_secure_partition_enter(&sp_ctx->c_rt_ctx); |
| 106 | |
| 107 | /* Save secure state */ |
| 108 | cm_el1_sysregs_context_save(SECURE); |
| 109 | |
| 110 | return rc; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 113 | /******************************************************************************* |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 114 | * This function returns to the place where spm_sp_synchronous_entry() was |
| 115 | * called originally. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 116 | ******************************************************************************/ |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 117 | __dead2 static void spm_sp_synchronous_exit(uint64_t rc) |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 118 | { |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 119 | sp_context_t *ctx = &sp_ctx; |
| 120 | |
| 121 | /* |
| 122 | * The SPM must have initiated the original request through a |
| 123 | * synchronous entry into the secure partition. Jump back to the |
| 124 | * original C runtime context with the value of rc in x0; |
| 125 | */ |
| 126 | spm_secure_partition_exit(ctx->c_rt_ctx, rc); |
| 127 | |
| 128 | panic(); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /******************************************************************************* |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 132 | * Jump to each Secure Partition for the first time. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 133 | ******************************************************************************/ |
Antonio Nino Diaz | e881147 | 2018-04-17 15:10:18 +0100 | [diff] [blame] | 134 | static int32_t spm_init(void) |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 135 | { |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 136 | uint64_t rc; |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 137 | sp_context_t *ctx; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 138 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 139 | INFO("Secure Partition init...\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 140 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 141 | ctx = &sp_ctx; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 142 | |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 143 | ctx->state = SP_STATE_RESET; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 144 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 145 | rc = spm_sp_synchronous_entry(ctx); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 146 | assert(rc == 0); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 147 | |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 148 | ctx->state = SP_STATE_IDLE; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 149 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 150 | INFO("Secure Partition initialized.\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 151 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 152 | return rc; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /******************************************************************************* |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 156 | * Initialize contexts of all Secure Partitions. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 157 | ******************************************************************************/ |
| 158 | int32_t spm_setup(void) |
| 159 | { |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 160 | sp_context_t *ctx; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 161 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 162 | /* Disable MMU at EL1 (initialized by BL2) */ |
| 163 | disable_mmu_icache_el1(); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 164 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 165 | /* Initialize context of the SP */ |
| 166 | INFO("Secure Partition context setup start...\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 167 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 168 | ctx = &sp_ctx; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 169 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 170 | /* Assign translation tables context. */ |
| 171 | ctx->xlat_ctx_handle = spm_get_sp_xlat_context(); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 172 | |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 173 | spm_sp_setup(ctx); |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 174 | |
| 175 | /* Register init function for deferred init. */ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 176 | bl31_register_bl32_init(&spm_init); |
| 177 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 178 | INFO("Secure Partition setup done.\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 183 | /******************************************************************************* |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 184 | * MM_COMMUNICATE handler |
| 185 | ******************************************************************************/ |
| 186 | static uint64_t mm_communicate(uint32_t smc_fid, uint64_t mm_cookie, |
| 187 | uint64_t comm_buffer_address, |
| 188 | uint64_t comm_size_address, void *handle) |
| 189 | { |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 190 | uint64_t rc; |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 191 | sp_context_t *ctx = &sp_ctx; |
| 192 | |
| 193 | /* Cookie. Reserved for future use. It must be zero. */ |
| 194 | if (mm_cookie != 0U) { |
| 195 | ERROR("MM_COMMUNICATE: cookie is not zero\n"); |
| 196 | SMC_RET1(handle, SPM_INVALID_PARAMETER); |
| 197 | } |
| 198 | |
| 199 | if (comm_buffer_address == 0U) { |
| 200 | ERROR("MM_COMMUNICATE: comm_buffer_address is zero\n"); |
| 201 | SMC_RET1(handle, SPM_INVALID_PARAMETER); |
| 202 | } |
| 203 | |
| 204 | if (comm_size_address != 0U) { |
| 205 | VERBOSE("MM_COMMUNICATE: comm_size_address is not 0 as recommended.\n"); |
| 206 | } |
| 207 | |
| 208 | /* Save the Normal world context */ |
| 209 | cm_el1_sysregs_context_save(NON_SECURE); |
| 210 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 211 | /* Wait until the Secure Partition is idle and set it to busy. */ |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 212 | sp_state_wait_switch(ctx, SP_STATE_IDLE, SP_STATE_BUSY); |
| 213 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 214 | /* Set values for registers on SP entry */ |
| 215 | cpu_context_t *cpu_ctx = &(ctx->cpu_ctx); |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 216 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 217 | write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X0, smc_fid); |
| 218 | write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X1, comm_buffer_address); |
| 219 | write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X2, comm_size_address); |
| 220 | write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X3, plat_my_core_pos()); |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 221 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 222 | /* Jump to the Secure Partition. */ |
| 223 | rc = spm_sp_synchronous_entry(ctx); |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 224 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 225 | /* Flag Secure Partition as idle. */ |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 226 | assert(ctx->state == SP_STATE_BUSY); |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 227 | sp_state_set(ctx, SP_STATE_IDLE); |
| 228 | |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 229 | /* Restore non-secure state */ |
| 230 | cm_el1_sysregs_context_restore(NON_SECURE); |
| 231 | cm_set_next_eret_context(NON_SECURE); |
| 232 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 233 | SMC_RET1(handle, rc); |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /******************************************************************************* |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 237 | * Secure Partition Manager SMC handler. |
| 238 | ******************************************************************************/ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 239 | uint64_t spm_smc_handler(uint32_t smc_fid, |
| 240 | uint64_t x1, |
| 241 | uint64_t x2, |
| 242 | uint64_t x3, |
| 243 | uint64_t x4, |
| 244 | void *cookie, |
| 245 | void *handle, |
| 246 | uint64_t flags) |
| 247 | { |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 248 | unsigned int ns; |
| 249 | |
| 250 | /* Determine which security state this SMC originated from */ |
| 251 | ns = is_caller_non_secure(flags); |
| 252 | |
| 253 | if (ns == SMC_FROM_SECURE) { |
| 254 | |
| 255 | /* Handle SMCs from Secure world. */ |
| 256 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 257 | assert(handle == cm_get_context(SECURE)); |
| 258 | |
| 259 | /* Make next ERET jump to S-EL0 instead of S-EL1. */ |
| 260 | cm_set_elr_spsr_el3(SECURE, read_elr_el1(), read_spsr_el1()); |
| 261 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 262 | switch (smc_fid) { |
| 263 | |
Sandrine Bailleux | 843d3f0 | 2017-12-07 09:48:56 +0000 | [diff] [blame] | 264 | case SPM_VERSION_AARCH32: |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 265 | SMC_RET1(handle, SPM_VERSION_COMPILED); |
| 266 | |
| 267 | case SP_EVENT_COMPLETE_AARCH64: |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 268 | spm_sp_synchronous_exit(x1); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 269 | |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 270 | case SP_MEMORY_ATTRIBUTES_GET_AARCH64: |
| 271 | INFO("Received SP_MEMORY_ATTRIBUTES_GET_AARCH64 SMC\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 272 | |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 273 | if (sp_ctx.state != SP_STATE_RESET) { |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 274 | 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] | 275 | SMC_RET1(handle, SPM_NOT_SUPPORTED); |
| 276 | } |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 277 | SMC_RET1(handle, |
| 278 | spm_memory_attributes_get_smc_handler( |
| 279 | &sp_ctx, x1)); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 280 | |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 281 | case SP_MEMORY_ATTRIBUTES_SET_AARCH64: |
| 282 | INFO("Received SP_MEMORY_ATTRIBUTES_SET_AARCH64 SMC\n"); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 283 | |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 284 | if (sp_ctx.state != SP_STATE_RESET) { |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 285 | 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] | 286 | SMC_RET1(handle, SPM_NOT_SUPPORTED); |
| 287 | } |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 288 | SMC_RET1(handle, |
| 289 | spm_memory_attributes_set_smc_handler( |
| 290 | &sp_ctx, x1, x2, x3)); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | } else { |
| 295 | |
| 296 | /* Handle SMCs from Non-secure world. */ |
| 297 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 298 | assert(handle == cm_get_context(NON_SECURE)); |
| 299 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 300 | switch (smc_fid) { |
| 301 | |
Antonio Nino Diaz | 35b37f0 | 2018-01-08 17:33:34 +0000 | [diff] [blame] | 302 | case MM_VERSION_AARCH32: |
| 303 | SMC_RET1(handle, MM_VERSION_COMPILED); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 304 | |
Sandrine Bailleux | b31ee6b | 2017-12-01 09:44:21 +0000 | [diff] [blame] | 305 | case MM_COMMUNICATE_AARCH32: |
| 306 | case MM_COMMUNICATE_AARCH64: |
Antonio Nino Diaz | fbd7f50 | 2018-05-23 11:49:16 +0100 | [diff] [blame] | 307 | return mm_communicate(smc_fid, x1, x2, x3, handle); |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 308 | |
Antonio Nino Diaz | 837173f | 2017-12-01 14:12:43 +0000 | [diff] [blame] | 309 | case SP_MEMORY_ATTRIBUTES_GET_AARCH64: |
| 310 | case SP_MEMORY_ATTRIBUTES_SET_AARCH64: |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 311 | /* SMC interfaces reserved for secure callers. */ |
| 312 | SMC_RET1(handle, SPM_NOT_SUPPORTED); |
| 313 | |
| 314 | default: |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | SMC_RET1(handle, SMC_UNK); |
| 320 | } |