Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 1 | /* |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | /******************************************************************************* |
| 33 | * This is the Secure Payload Dispatcher (SPD). The dispatcher is meant to be a |
| 34 | * plug-in component to the Secure Monitor, registered as a runtime service. The |
| 35 | * SPD is expected to be a functional extension of the Secure Payload (SP) that |
| 36 | * executes in Secure EL1. The Secure Monitor will delegate all SMCs targeting |
| 37 | * the Trusted OS/Applications range to the dispatcher. The SPD will either |
| 38 | * handle the request locally or delegate it to the Secure Payload. It is also |
| 39 | * responsible for initialising and maintaining communication with the SP. |
| 40 | ******************************************************************************/ |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 41 | #include <arch_helpers.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 42 | #include <assert.h> |
| 43 | #include <bl_common.h> |
| 44 | #include <bl31.h> |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 45 | #include <context_mgmt.h> |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 46 | #include <debug.h> |
| 47 | #include <errno.h> |
| 48 | #include <platform.h> |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 49 | #include <runtime_svc.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 50 | #include <stddef.h> |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 51 | #include <string.h> |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 52 | #include <tsp.h> |
Jeenu Viswambharan | df1ddb5 | 2014-02-28 11:23:35 +0000 | [diff] [blame] | 53 | #include <uuid.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 54 | #include "tspd_private.h" |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 55 | |
| 56 | /******************************************************************************* |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 57 | * Address of the entrypoint vector table in the Secure Payload. It is |
| 58 | * initialised once on the primary core after a cold boot. |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 59 | ******************************************************************************/ |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 60 | tsp_vectors_t *tsp_vectors; |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 61 | |
| 62 | /******************************************************************************* |
| 63 | * Array to keep track of per-cpu Secure Payload state |
| 64 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 65 | tsp_context_t tspd_sp_context[TSPD_CORE_COUNT]; |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 66 | |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 67 | |
Jeenu Viswambharan | df1ddb5 | 2014-02-28 11:23:35 +0000 | [diff] [blame] | 68 | /* TSP UID */ |
| 69 | DEFINE_SVC_UUID(tsp_uuid, |
| 70 | 0x5b3056a0, 0x3291, 0x427b, 0x98, 0x11, |
| 71 | 0x71, 0x68, 0xca, 0x50, 0xf3, 0xfa); |
| 72 | |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 73 | int32_t tspd_init(void); |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 74 | |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 75 | uint64_t tspd_handle_sp_preemption(void *handle) |
| 76 | { |
| 77 | cpu_context_t *ns_cpu_context; |
| 78 | assert(handle == cm_get_context(SECURE)); |
| 79 | cm_el1_sysregs_context_save(SECURE); |
| 80 | /* Get a reference to the non-secure context */ |
| 81 | ns_cpu_context = cm_get_context(NON_SECURE); |
| 82 | assert(ns_cpu_context); |
| 83 | |
| 84 | /* |
| 85 | * Restore non-secure state. The secure system |
| 86 | * register context will be saved when required. |
| 87 | */ |
| 88 | cm_el1_sysregs_context_restore(NON_SECURE); |
| 89 | cm_set_next_eret_context(NON_SECURE); |
| 90 | |
| 91 | SMC_RET1(ns_cpu_context, SMC_PREEMPTED); |
| 92 | } |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 93 | /******************************************************************************* |
| 94 | * This function is the handler registered for S-EL1 interrupts by the TSPD. It |
| 95 | * validates the interrupt and upon success arranges entry into the TSP at |
| 96 | * 'tsp_fiq_entry()' for handling the interrupt. |
| 97 | ******************************************************************************/ |
| 98 | static uint64_t tspd_sel1_interrupt_handler(uint32_t id, |
| 99 | uint32_t flags, |
| 100 | void *handle, |
| 101 | void *cookie) |
| 102 | { |
| 103 | uint32_t linear_id; |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 104 | tsp_context_t *tsp_ctx; |
| 105 | |
| 106 | /* Check the security state when the exception was generated */ |
| 107 | assert(get_interrupt_src_ss(flags) == NON_SECURE); |
| 108 | |
| 109 | #if IMF_READ_INTERRUPT_ID |
| 110 | /* Check the security status of the interrupt */ |
Soby Mathew | 93c89ec | 2014-05-28 17:14:36 +0100 | [diff] [blame] | 111 | assert(plat_ic_get_interrupt_type(id) == INTR_TYPE_S_EL1); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | /* Sanity check the pointer to this cpu's context */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 115 | assert(handle == cm_get_context(NON_SECURE)); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 116 | |
| 117 | /* Save the non-secure context before entering the TSP */ |
| 118 | cm_el1_sysregs_context_save(NON_SECURE); |
| 119 | |
| 120 | /* Get a reference to this cpu's TSP context */ |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 121 | linear_id = plat_my_core_pos(); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 122 | tsp_ctx = &tspd_sp_context[linear_id]; |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 123 | assert(&tsp_ctx->cpu_ctx == cm_get_context(SECURE)); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * Determine if the TSP was previously preempted. Its last known |
| 127 | * context has to be preserved in this case. |
| 128 | * The TSP should return control to the TSPD after handling this |
| 129 | * FIQ. Preserve essential EL3 context to allow entry into the |
| 130 | * TSP at the FIQ entry point using the 'cpu_context' structure. |
| 131 | * There is no need to save the secure system register context |
| 132 | * since the TSP is supposed to preserve it during S-EL1 interrupt |
| 133 | * handling. |
| 134 | */ |
| 135 | if (get_std_smc_active_flag(tsp_ctx->state)) { |
| 136 | tsp_ctx->saved_spsr_el3 = SMC_GET_EL3(&tsp_ctx->cpu_ctx, |
| 137 | CTX_SPSR_EL3); |
| 138 | tsp_ctx->saved_elr_el3 = SMC_GET_EL3(&tsp_ctx->cpu_ctx, |
| 139 | CTX_ELR_EL3); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 140 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 141 | /*Need to save the previously interrupted secure context */ |
| 142 | memcpy(&tsp_ctx->sp_ctx, &tsp_ctx->cpu_ctx, TSPD_SP_CTX_SIZE); |
| 143 | #endif |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 146 | cm_el1_sysregs_context_restore(SECURE); |
Andrew Thoelke | 4e12607 | 2014-06-04 21:10:52 +0100 | [diff] [blame] | 147 | cm_set_elr_spsr_el3(SECURE, (uint64_t) &tsp_vectors->fiq_entry, |
| 148 | SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS)); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 149 | |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 150 | cm_set_next_eret_context(SECURE); |
| 151 | |
| 152 | /* |
| 153 | * Tell the TSP that it has to handle an FIQ synchronously. Also the |
| 154 | * instruction in normal world where the interrupt was generated is |
| 155 | * passed for debugging purposes. It is safe to retrieve this address |
| 156 | * from ELR_EL3 as the secure context will not take effect until |
| 157 | * el3_exit(). |
| 158 | */ |
| 159 | SMC_RET2(&tsp_ctx->cpu_ctx, TSP_HANDLE_FIQ_AND_RETURN, read_elr_el3()); |
| 160 | } |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 161 | |
| 162 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 163 | /******************************************************************************* |
| 164 | * This function is the handler registered for S-EL1 interrupts by the TSPD. It |
| 165 | * validates the interrupt and upon success arranges entry into the TSP at |
| 166 | * 'tsp_fiq_entry()' for handling the interrupt. |
| 167 | ******************************************************************************/ |
| 168 | static uint64_t tspd_ns_interrupt_handler(uint32_t id, |
| 169 | uint32_t flags, |
| 170 | void *handle, |
| 171 | void *cookie) |
| 172 | { |
| 173 | /* Check the security state when the exception was generated */ |
| 174 | assert(get_interrupt_src_ss(flags) == SECURE); |
| 175 | |
| 176 | #if IMF_READ_INTERRUPT_ID |
| 177 | /* Check the security status of the interrupt */ |
| 178 | assert(plat_ic_get_interrupt_type(id) == INTR_TYPE_NS); |
| 179 | #endif |
| 180 | /* |
| 181 | * Disable the routing of NS interrupts from secure world to EL3 while |
| 182 | * interrupted on this core. |
| 183 | */ |
| 184 | disable_intr_rm_local(INTR_TYPE_NS, SECURE); |
| 185 | |
| 186 | return tspd_handle_sp_preemption(handle); |
| 187 | } |
| 188 | #endif |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 189 | |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 190 | /******************************************************************************* |
| 191 | * Secure Payload Dispatcher setup. The SPD finds out the SP entrypoint and type |
| 192 | * (aarch32/aarch64) if not already known and initialises the context for entry |
| 193 | * into the SP for its initialisation. |
| 194 | ******************************************************************************/ |
| 195 | int32_t tspd_setup(void) |
| 196 | { |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 197 | entry_point_info_t *tsp_ep_info; |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 198 | uint32_t linear_id; |
| 199 | |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 200 | linear_id = plat_my_core_pos(); |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * Get information about the Secure Payload (BL32) image. Its |
| 204 | * absence is a critical failure. TODO: Add support to |
| 205 | * conditionally include the SPD service |
| 206 | */ |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 207 | tsp_ep_info = bl31_plat_get_next_image_ep_info(SECURE); |
| 208 | if (!tsp_ep_info) { |
| 209 | WARN("No TSP provided by BL2 boot loader, Booting device" |
| 210 | " without TSP initialization. SMC`s destined for TSP" |
| 211 | " will return SMC_UNK\n"); |
| 212 | return 1; |
| 213 | } |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 214 | |
| 215 | /* |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 216 | * If there's no valid entry point for SP, we return a non-zero value |
| 217 | * signalling failure initializing the service. We bail out without |
| 218 | * registering any handlers |
| 219 | */ |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 220 | if (!tsp_ep_info->pc) |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 221 | return 1; |
| 222 | |
| 223 | /* |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 224 | * We could inspect the SP image and determine it's execution |
| 225 | * state i.e whether AArch32 or AArch64. Assuming it's AArch64 |
| 226 | * for the time being. |
| 227 | */ |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 228 | tspd_init_tsp_ep_state(tsp_ep_info, |
| 229 | TSP_AARCH64, |
| 230 | tsp_ep_info->pc, |
| 231 | &tspd_sp_context[linear_id]); |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 232 | |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 233 | #if TSP_INIT_ASYNC |
| 234 | bl31_set_next_image_type(SECURE); |
| 235 | #else |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 236 | /* |
| 237 | * All TSPD initialization done. Now register our init function with |
| 238 | * BL31 for deferred invocation |
| 239 | */ |
| 240 | bl31_register_bl32_init(&tspd_init); |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 241 | #endif |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 242 | return 0; |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /******************************************************************************* |
| 246 | * This function passes control to the Secure Payload image (BL32) for the first |
| 247 | * time on the primary cpu after a cold boot. It assumes that a valid secure |
| 248 | * context has already been created by tspd_setup() which can be directly used. |
| 249 | * It also assumes that a valid non-secure context has been initialised by PSCI |
| 250 | * so it does not need to save and restore any non-secure state. This function |
| 251 | * performs a synchronous entry into the Secure payload. The SP passes control |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 252 | * back to this routine through a SMC. |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 253 | ******************************************************************************/ |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 254 | int32_t tspd_init(void) |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 255 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 256 | uint32_t linear_id = plat_my_core_pos(); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 257 | tsp_context_t *tsp_ctx = &tspd_sp_context[linear_id]; |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 258 | entry_point_info_t *tsp_entry_point; |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 259 | uint64_t rc; |
Vikram Kanigiri | 9d70f0f | 2014-07-15 16:46:43 +0100 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * Get information about the Secure Payload (BL32) image. Its |
| 263 | * absence is a critical failure. |
| 264 | */ |
| 265 | tsp_entry_point = bl31_plat_get_next_image_ep_info(SECURE); |
| 266 | assert(tsp_entry_point); |
| 267 | |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 268 | cm_init_my_context(tsp_entry_point); |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 269 | |
| 270 | /* |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 271 | * Arrange for an entry into the test secure payload. It will be |
| 272 | * returned via TSP_ENTRY_DONE case |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 273 | */ |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 274 | rc = tspd_synchronous_sp_entry(tsp_ctx); |
| 275 | assert(rc != 0); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 276 | |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 277 | return rc; |
| 278 | } |
| 279 | |
Jeenu Viswambharan | 7f36660 | 2014-02-20 17:11:00 +0000 | [diff] [blame] | 280 | |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 281 | /******************************************************************************* |
| 282 | * This function is responsible for handling all SMCs in the Trusted OS/App |
| 283 | * range from the non-secure state as defined in the SMC Calling Convention |
| 284 | * Document. It is also responsible for communicating with the Secure payload |
| 285 | * to delegate work and return results back to the non-secure state. Lastly it |
| 286 | * will also return any information that the secure payload needs to do the |
| 287 | * work assigned to it. |
| 288 | ******************************************************************************/ |
| 289 | uint64_t tspd_smc_handler(uint32_t smc_fid, |
| 290 | uint64_t x1, |
| 291 | uint64_t x2, |
| 292 | uint64_t x3, |
| 293 | uint64_t x4, |
| 294 | void *cookie, |
| 295 | void *handle, |
| 296 | uint64_t flags) |
| 297 | { |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 298 | cpu_context_t *ns_cpu_context; |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 299 | uint32_t linear_id = plat_my_core_pos(), ns; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 300 | tsp_context_t *tsp_ctx = &tspd_sp_context[linear_id]; |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 301 | uint64_t rc; |
| 302 | #if TSP_INIT_ASYNC |
| 303 | entry_point_info_t *next_image_info; |
| 304 | #endif |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 305 | |
| 306 | /* Determine which security state this SMC originated from */ |
| 307 | ns = is_caller_non_secure(flags); |
| 308 | |
| 309 | switch (smc_fid) { |
| 310 | |
| 311 | /* |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 312 | * This function ID is used by TSP to indicate that it was |
| 313 | * preempted by a normal world IRQ. |
| 314 | * |
| 315 | */ |
| 316 | case TSP_PREEMPTED: |
| 317 | if (ns) |
| 318 | SMC_RET1(handle, SMC_UNK); |
| 319 | |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 320 | return tspd_handle_sp_preemption(handle); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 321 | |
| 322 | /* |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 323 | * This function ID is used only by the TSP to indicate that it has |
| 324 | * finished handling a S-EL1 FIQ interrupt. Execution should resume |
| 325 | * in the normal world. |
| 326 | */ |
| 327 | case TSP_HANDLED_S_EL1_FIQ: |
| 328 | if (ns) |
| 329 | SMC_RET1(handle, SMC_UNK); |
| 330 | |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 331 | assert(handle == cm_get_context(SECURE)); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | * Restore the relevant EL3 state which saved to service |
| 335 | * this SMC. |
| 336 | */ |
| 337 | if (get_std_smc_active_flag(tsp_ctx->state)) { |
| 338 | SMC_SET_EL3(&tsp_ctx->cpu_ctx, |
| 339 | CTX_SPSR_EL3, |
| 340 | tsp_ctx->saved_spsr_el3); |
| 341 | SMC_SET_EL3(&tsp_ctx->cpu_ctx, |
| 342 | CTX_ELR_EL3, |
| 343 | tsp_ctx->saved_elr_el3); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 344 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 345 | /* |
| 346 | * Need to restore the previously interrupted |
| 347 | * secure context. |
| 348 | */ |
| 349 | memcpy(&tsp_ctx->cpu_ctx, &tsp_ctx->sp_ctx, |
| 350 | TSPD_SP_CTX_SIZE); |
| 351 | #endif |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /* Get a reference to the non-secure context */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 355 | ns_cpu_context = cm_get_context(NON_SECURE); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 356 | assert(ns_cpu_context); |
| 357 | |
| 358 | /* |
| 359 | * Restore non-secure state. There is no need to save the |
| 360 | * secure system register context since the TSP was supposed |
| 361 | * to preserve it during S-EL1 interrupt handling. |
| 362 | */ |
| 363 | cm_el1_sysregs_context_restore(NON_SECURE); |
| 364 | cm_set_next_eret_context(NON_SECURE); |
| 365 | |
| 366 | SMC_RET0((uint64_t) ns_cpu_context); |
| 367 | |
| 368 | |
| 369 | /* |
| 370 | * This function ID is used only by the TSP to indicate that it was |
| 371 | * interrupted due to a EL3 FIQ interrupt. Execution should resume |
| 372 | * in the normal world. |
| 373 | */ |
| 374 | case TSP_EL3_FIQ: |
| 375 | if (ns) |
| 376 | SMC_RET1(handle, SMC_UNK); |
| 377 | |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 378 | assert(handle == cm_get_context(SECURE)); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 379 | |
| 380 | /* Assert that standard SMC execution has been preempted */ |
| 381 | assert(get_std_smc_active_flag(tsp_ctx->state)); |
| 382 | |
| 383 | /* Save the secure system register state */ |
| 384 | cm_el1_sysregs_context_save(SECURE); |
| 385 | |
| 386 | /* Get a reference to the non-secure context */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 387 | ns_cpu_context = cm_get_context(NON_SECURE); |
Achin Gupta | aeaab68 | 2014-05-09 13:21:31 +0100 | [diff] [blame] | 388 | assert(ns_cpu_context); |
| 389 | |
| 390 | /* Restore non-secure state */ |
| 391 | cm_el1_sysregs_context_restore(NON_SECURE); |
| 392 | cm_set_next_eret_context(NON_SECURE); |
| 393 | |
| 394 | SMC_RET1(ns_cpu_context, TSP_EL3_FIQ); |
| 395 | |
| 396 | |
| 397 | /* |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 398 | * This function ID is used only by the SP to indicate it has |
| 399 | * finished initialising itself after a cold boot |
| 400 | */ |
| 401 | case TSP_ENTRY_DONE: |
| 402 | if (ns) |
| 403 | SMC_RET1(handle, SMC_UNK); |
| 404 | |
| 405 | /* |
| 406 | * Stash the SP entry points information. This is done |
| 407 | * only once on the primary cpu |
| 408 | */ |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 409 | assert(tsp_vectors == NULL); |
| 410 | tsp_vectors = (tsp_vectors_t *) x1; |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 411 | |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 412 | if (tsp_vectors) { |
| 413 | set_tsp_pstate(tsp_ctx->state, TSP_PSTATE_ON); |
| 414 | |
| 415 | /* |
| 416 | * TSP has been successfully initialized. Register power |
| 417 | * managemnt hooks with PSCI |
| 418 | */ |
| 419 | psci_register_spd_pm_hook(&tspd_pm); |
| 420 | |
| 421 | /* |
| 422 | * Register an interrupt handler for S-EL1 interrupts |
| 423 | * when generated during code executing in the |
| 424 | * non-secure state. |
| 425 | */ |
| 426 | flags = 0; |
| 427 | set_interrupt_rm_flag(flags, NON_SECURE); |
| 428 | rc = register_interrupt_type_handler(INTR_TYPE_S_EL1, |
| 429 | tspd_sel1_interrupt_handler, |
| 430 | flags); |
| 431 | if (rc) |
| 432 | panic(); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 433 | |
| 434 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 435 | /* |
| 436 | * Register an interrupt handler for NS interrupts when |
| 437 | * generated during code executing in secure state are |
| 438 | * routed to EL3. |
| 439 | */ |
| 440 | flags = 0; |
| 441 | set_interrupt_rm_flag(flags, SECURE); |
| 442 | |
| 443 | rc = register_interrupt_type_handler(INTR_TYPE_NS, |
| 444 | tspd_ns_interrupt_handler, |
| 445 | flags); |
| 446 | if (rc) |
| 447 | panic(); |
| 448 | |
| 449 | /* |
| 450 | * Disable the interrupt NS locally since it will be enabled globally |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 451 | * within cm_init_my_context. |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 452 | */ |
| 453 | disable_intr_rm_local(INTR_TYPE_NS, SECURE); |
| 454 | #endif |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
| 458 | #if TSP_INIT_ASYNC |
| 459 | /* Save the Secure EL1 system register context */ |
| 460 | assert(cm_get_context(SECURE) == &tsp_ctx->cpu_ctx); |
| 461 | cm_el1_sysregs_context_save(SECURE); |
| 462 | |
| 463 | /* Program EL3 registers to enable entry into the next EL */ |
| 464 | next_image_info = bl31_plat_get_next_image_ep_info(NON_SECURE); |
| 465 | assert(next_image_info); |
| 466 | assert(NON_SECURE == |
| 467 | GET_SECURITY_STATE(next_image_info->h.attr)); |
| 468 | |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 469 | cm_init_my_context(next_image_info); |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 470 | cm_prepare_el3_exit(NON_SECURE); |
| 471 | SMC_RET0(cm_get_context(NON_SECURE)); |
| 472 | #else |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 473 | /* |
| 474 | * SP reports completion. The SPD must have initiated |
| 475 | * the original request through a synchronous entry |
| 476 | * into the SP. Jump back to the original C runtime |
| 477 | * context. |
| 478 | */ |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 479 | tspd_synchronous_sp_exit(tsp_ctx, x1); |
Vikram Kanigiri | 4e81341 | 2014-07-15 16:49:22 +0100 | [diff] [blame] | 480 | #endif |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 481 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 482 | /* |
| 483 | * These function IDs is used only by the SP to indicate it has |
| 484 | * finished: |
| 485 | * 1. turning itself on in response to an earlier psci |
| 486 | * cpu_on request |
| 487 | * 2. resuming itself after an earlier psci cpu_suspend |
| 488 | * request. |
| 489 | */ |
| 490 | case TSP_ON_DONE: |
| 491 | case TSP_RESUME_DONE: |
| 492 | |
| 493 | /* |
| 494 | * These function IDs is used only by the SP to indicate it has |
| 495 | * finished: |
| 496 | * 1. suspending itself after an earlier psci cpu_suspend |
| 497 | * request. |
| 498 | * 2. turning itself off in response to an earlier psci |
| 499 | * cpu_off request. |
| 500 | */ |
| 501 | case TSP_OFF_DONE: |
| 502 | case TSP_SUSPEND_DONE: |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 503 | case TSP_SYSTEM_OFF_DONE: |
| 504 | case TSP_SYSTEM_RESET_DONE: |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 505 | if (ns) |
| 506 | SMC_RET1(handle, SMC_UNK); |
| 507 | |
| 508 | /* |
| 509 | * SP reports completion. The SPD must have initiated the |
| 510 | * original request through a synchronous entry into the SP. |
| 511 | * Jump back to the original C runtime context, and pass x1 as |
| 512 | * return value to the caller |
| 513 | */ |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 514 | tspd_synchronous_sp_exit(tsp_ctx, x1); |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 515 | |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 516 | /* |
| 517 | * Request from non-secure client to perform an |
| 518 | * arithmetic operation or response from secure |
| 519 | * payload to an earlier request. |
| 520 | */ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 521 | case TSP_FAST_FID(TSP_ADD): |
| 522 | case TSP_FAST_FID(TSP_SUB): |
| 523 | case TSP_FAST_FID(TSP_MUL): |
| 524 | case TSP_FAST_FID(TSP_DIV): |
| 525 | |
| 526 | case TSP_STD_FID(TSP_ADD): |
| 527 | case TSP_STD_FID(TSP_SUB): |
| 528 | case TSP_STD_FID(TSP_MUL): |
| 529 | case TSP_STD_FID(TSP_DIV): |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 530 | if (ns) { |
| 531 | /* |
| 532 | * This is a fresh request from the non-secure client. |
| 533 | * The parameters are in x1 and x2. Figure out which |
| 534 | * registers need to be preserved, save the non-secure |
| 535 | * state and send the request to the secure payload. |
| 536 | */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 537 | assert(handle == cm_get_context(NON_SECURE)); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 538 | |
| 539 | /* Check if we are already preempted */ |
| 540 | if (get_std_smc_active_flag(tsp_ctx->state)) |
| 541 | SMC_RET1(handle, SMC_UNK); |
| 542 | |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 543 | cm_el1_sysregs_context_save(NON_SECURE); |
| 544 | |
| 545 | /* Save x1 and x2 for use by TSP_GET_ARGS call below */ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 546 | store_tsp_args(tsp_ctx, x1, x2); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * We are done stashing the non-secure context. Ask the |
| 550 | * secure payload to do the work now. |
| 551 | */ |
| 552 | |
| 553 | /* |
| 554 | * Verify if there is a valid context to use, copy the |
| 555 | * operation type and parameters to the secure context |
| 556 | * and jump to the fast smc entry point in the secure |
| 557 | * payload. Entry into S-EL1 will take place upon exit |
| 558 | * from this function. |
| 559 | */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 560 | assert(&tsp_ctx->cpu_ctx == cm_get_context(SECURE)); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 561 | |
| 562 | /* Set appropriate entry for SMC. |
| 563 | * We expect the TSP to manage the PSTATE.I and PSTATE.F |
| 564 | * flags as appropriate. |
| 565 | */ |
| 566 | if (GET_SMC_TYPE(smc_fid) == SMC_TYPE_FAST) { |
| 567 | cm_set_elr_el3(SECURE, (uint64_t) |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 568 | &tsp_vectors->fast_smc_entry); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 569 | } else { |
| 570 | set_std_smc_active_flag(tsp_ctx->state); |
| 571 | cm_set_elr_el3(SECURE, (uint64_t) |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 572 | &tsp_vectors->std_smc_entry); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 573 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 574 | /* |
| 575 | * Enable the routing of NS interrupts to EL3 |
| 576 | * during STD SMC processing on this core. |
| 577 | */ |
| 578 | enable_intr_rm_local(INTR_TYPE_NS, SECURE); |
| 579 | #endif |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 580 | } |
| 581 | |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 582 | cm_el1_sysregs_context_restore(SECURE); |
| 583 | cm_set_next_eret_context(SECURE); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 584 | SMC_RET3(&tsp_ctx->cpu_ctx, smc_fid, x1, x2); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 585 | } else { |
| 586 | /* |
| 587 | * This is the result from the secure client of an |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 588 | * earlier request. The results are in x1-x3. Copy it |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 589 | * into the non-secure context, save the secure state |
| 590 | * and return to the non-secure state. |
| 591 | */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 592 | assert(handle == cm_get_context(SECURE)); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 593 | cm_el1_sysregs_context_save(SECURE); |
| 594 | |
| 595 | /* Get a reference to the non-secure context */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 596 | ns_cpu_context = cm_get_context(NON_SECURE); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 597 | assert(ns_cpu_context); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 598 | |
| 599 | /* Restore non-secure state */ |
| 600 | cm_el1_sysregs_context_restore(NON_SECURE); |
| 601 | cm_set_next_eret_context(NON_SECURE); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 602 | if (GET_SMC_TYPE(smc_fid) == SMC_TYPE_STD) { |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 603 | clr_std_smc_active_flag(tsp_ctx->state); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 604 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 605 | /* |
| 606 | * Disable the routing of NS interrupts to EL3 |
| 607 | * after STD SMC processing is finished on this |
| 608 | * core. |
| 609 | */ |
| 610 | disable_intr_rm_local(INTR_TYPE_NS, SECURE); |
| 611 | #endif |
| 612 | } |
| 613 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 614 | SMC_RET3(ns_cpu_context, x1, x2, x3); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | break; |
| 618 | |
| 619 | /* |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 620 | * Request from non secure world to resume the preempted |
| 621 | * Standard SMC call. |
| 622 | */ |
| 623 | case TSP_FID_RESUME: |
Soby Mathew | 3d57851 | 2014-05-27 10:20:01 +0100 | [diff] [blame] | 624 | /* RESUME should be invoked only by normal world */ |
| 625 | if (!ns) { |
| 626 | assert(0); |
| 627 | break; |
| 628 | } |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 629 | |
Soby Mathew | 3d57851 | 2014-05-27 10:20:01 +0100 | [diff] [blame] | 630 | /* |
| 631 | * This is a resume request from the non-secure client. |
| 632 | * save the non-secure state and send the request to |
| 633 | * the secure payload. |
| 634 | */ |
Andrew Thoelke | a2f6553 | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 635 | assert(handle == cm_get_context(NON_SECURE)); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 636 | |
Soby Mathew | 3d57851 | 2014-05-27 10:20:01 +0100 | [diff] [blame] | 637 | /* Check if we are already preempted before resume */ |
| 638 | if (!get_std_smc_active_flag(tsp_ctx->state)) |
| 639 | SMC_RET1(handle, SMC_UNK); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 640 | |
Soby Mathew | 3d57851 | 2014-05-27 10:20:01 +0100 | [diff] [blame] | 641 | cm_el1_sysregs_context_save(NON_SECURE); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 642 | |
Soby Mathew | 3d57851 | 2014-05-27 10:20:01 +0100 | [diff] [blame] | 643 | /* |
| 644 | * We are done stashing the non-secure context. Ask the |
| 645 | * secure payload to do the work now. |
| 646 | */ |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 647 | #if TSPD_ROUTE_IRQ_TO_EL3 |
| 648 | /* |
| 649 | * Enable the routing of NS interrupts to EL3 during resumption |
| 650 | * of STD SMC call on this core. |
| 651 | */ |
| 652 | enable_intr_rm_local(INTR_TYPE_NS, SECURE); |
| 653 | #endif |
| 654 | |
| 655 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 656 | |
Soby Mathew | 3d57851 | 2014-05-27 10:20:01 +0100 | [diff] [blame] | 657 | /* We just need to return to the preempted point in |
| 658 | * TSP and the execution will resume as normal. |
| 659 | */ |
| 660 | cm_el1_sysregs_context_restore(SECURE); |
| 661 | cm_set_next_eret_context(SECURE); |
| 662 | SMC_RET0(&tsp_ctx->cpu_ctx); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 663 | |
| 664 | /* |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 665 | * This is a request from the secure payload for more arguments |
| 666 | * for an ongoing arithmetic operation requested by the |
| 667 | * non-secure world. Simply return the arguments from the non- |
| 668 | * secure client in the original call. |
| 669 | */ |
| 670 | case TSP_GET_ARGS: |
| 671 | if (ns) |
| 672 | SMC_RET1(handle, SMC_UNK); |
| 673 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 674 | get_tsp_args(tsp_ctx, x1, x2); |
| 675 | SMC_RET2(handle, x1, x2); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 676 | |
Jeenu Viswambharan | df1ddb5 | 2014-02-28 11:23:35 +0000 | [diff] [blame] | 677 | case TOS_CALL_COUNT: |
| 678 | /* |
| 679 | * Return the number of service function IDs implemented to |
| 680 | * provide service to non-secure |
| 681 | */ |
| 682 | SMC_RET1(handle, TSP_NUM_FID); |
| 683 | |
| 684 | case TOS_UID: |
| 685 | /* Return TSP UID to the caller */ |
| 686 | SMC_UUID_RET(handle, tsp_uuid); |
| 687 | |
| 688 | case TOS_CALL_VERSION: |
| 689 | /* Return the version of current implementation */ |
| 690 | SMC_RET2(handle, TSP_VERSION_MAJOR, TSP_VERSION_MINOR); |
| 691 | |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 692 | default: |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 693 | break; |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 696 | SMC_RET1(handle, SMC_UNK); |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 699 | /* Define a SPD runtime service descriptor for fast SMC calls */ |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 700 | DECLARE_RT_SVC( |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 701 | tspd_fast, |
Achin Gupta | 375f538 | 2014-02-18 18:12:48 +0000 | [diff] [blame] | 702 | |
| 703 | OEN_TOS_START, |
| 704 | OEN_TOS_END, |
| 705 | SMC_TYPE_FAST, |
| 706 | tspd_setup, |
| 707 | tspd_smc_handler |
| 708 | ); |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 709 | |
| 710 | /* Define a SPD runtime service descriptor for standard SMC calls */ |
| 711 | DECLARE_RT_SVC( |
| 712 | tspd_std, |
| 713 | |
| 714 | OEN_TOS_START, |
| 715 | OEN_TOS_END, |
| 716 | SMC_TYPE_STD, |
| 717 | NULL, |
| 718 | tspd_smc_handler |
| 719 | ); |