J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 1 | /* |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef CACTUS_TEST_CMDS |
| 8 | #define CACTUS_TEST_CMDS |
| 9 | |
| 10 | #include <debug.h> |
| 11 | #include <ffa_helpers.h> |
| 12 | |
| 13 | /** |
| 14 | * Success and error return to be sent over a msg response. |
| 15 | */ |
J-Alves | 9b28d06 | 2020-11-30 11:42:49 +0000 | [diff] [blame] | 16 | #define CACTUS_SUCCESS U(0) |
| 17 | #define CACTUS_ERROR U(-1) |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Get command from struct smc_ret_values. |
| 21 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 22 | static inline uint64_t cactus_get_cmd(smc_ret_values ret) |
| 23 | { |
| 24 | return (uint64_t)ret.ret3; |
| 25 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Template for commands to be sent to CACTUS partitions over direct |
| 29 | * messages interfaces. |
| 30 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 31 | static inline smc_ret_values cactus_send_cmd( |
| 32 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t cmd, uint64_t val0, |
| 33 | uint64_t val1, uint64_t val2, uint64_t val3) |
| 34 | { |
| 35 | return ffa_msg_send_direct_req64_5args(source, dest, cmd, val0, val1, |
| 36 | val2, val3); |
| 37 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 38 | |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame^] | 39 | /** |
| 40 | * Template for responses to Cactus commands. |
| 41 | * 'cactus_send_response' is the template for custom responses, in case there is |
| 42 | * a need to propagate more than one value in the response of a command. |
| 43 | */ |
| 44 | static inline smc_ret_values cactus_send_response( |
| 45 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t resp, uint32_t val0, |
| 46 | uint64_t val1, uint64_t val2, uint64_t val3) |
| 47 | { |
| 48 | return ffa_msg_send_direct_resp64_5args(source, dest, resp, val0, val1, |
| 49 | val2, val3); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * For responses of one value only. |
| 54 | */ |
| 55 | static inline smc_ret_values cactus_response( |
| 56 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response) |
| 57 | { |
| 58 | return ffa_msg_send_direct_resp(source, dest, response); |
| 59 | } |
| 60 | |
| 61 | static inline uint32_t cactus_get_response(smc_ret_values ret) |
| 62 | { |
| 63 | return (uint32_t)ret.ret3; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * In a successful test, in case the SP needs to propagate an extra value |
| 68 | * to conclude the test. |
| 69 | * If more arguments are needed, a custom response should be defined for the |
| 70 | * specific test. |
| 71 | */ |
| 72 | static inline smc_ret_values cactus_success_resp( |
| 73 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t value) |
| 74 | { |
| 75 | return cactus_send_response(source, dest, CACTUS_SUCCESS, value, |
| 76 | 0, 0, 0); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * In case the test fails on the SP side, the 'error_code' should help specify |
| 81 | * the reason, which can be specific to the test, or general ones as defined |
| 82 | * in the error code list. |
| 83 | */ |
| 84 | static inline smc_ret_values cactus_error_resp( |
| 85 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t error_code) |
| 86 | { |
| 87 | return cactus_send_response(source, dest, CACTUS_ERROR, error_code, |
| 88 | 0, 0, 0); |
| 89 | } |
| 90 | |
| 91 | static inline uint32_t cactus_error_code(smc_ret_values ret) |
| 92 | { |
| 93 | return (uint32_t) ret.ret4; |
| 94 | } |
| 95 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 96 | #define PRINT_CMD(smc_ret) \ |
| 97 | VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \ |
| 98 | smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \ |
| 99 | smc_ret.ret6, smc_ret.ret7) |
| 100 | |
| 101 | /** |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 102 | * With this test command the sender transmits a 64-bit value that it then |
| 103 | * expects to receive on the respective command response. |
| 104 | * |
| 105 | * The id is the hex representation of the string 'echo'. |
| 106 | */ |
| 107 | #define CACTUS_ECHO_CMD U(0x6563686f) |
| 108 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 109 | static inline smc_ret_values cactus_echo_send_cmd( |
| 110 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val) |
| 111 | { |
| 112 | return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0, |
| 113 | 0); |
| 114 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 115 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 116 | static inline uint64_t cactus_echo_get_val(smc_ret_values ret) |
| 117 | { |
| 118 | return (uint64_t)ret.ret4; |
| 119 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Command to request a cactus secure partition to send an echo command to |
| 123 | * another partition. |
| 124 | * |
| 125 | * The sender of this command expects to receive CACTUS_SUCCESS if the requested |
| 126 | * echo interaction happened successfully, or CACTUS_ERROR otherwise. |
| 127 | */ |
| 128 | #define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1) |
| 129 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 130 | static inline smc_ret_values cactus_req_echo_send_cmd( |
| 131 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest, |
| 132 | uint64_t echo_val) |
| 133 | { |
| 134 | return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val, |
| 135 | echo_dest, 0, 0); |
| 136 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 137 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 138 | static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret) |
| 139 | { |
| 140 | return (ffa_vm_id_t)ret.ret5; |
| 141 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 142 | |
| 143 | /** |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 144 | * Command to create a cyclic dependency between SPs, which could result in |
| 145 | * a deadlock. This aims at proving such scenario cannot happen. |
| 146 | * If the deadlock happens, the system will just hang. |
| 147 | * If the deadlock is prevented, the last partition to use the command will |
| 148 | * send response CACTUS_SUCCESS. |
| 149 | * |
| 150 | * The id is the hex representation of the string 'dead'. |
| 151 | */ |
| 152 | #define CACTUS_DEADLOCK_CMD U(0x64656164) |
| 153 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 154 | static inline smc_ret_values cactus_deadlock_send_cmd( |
| 155 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest) |
| 156 | { |
| 157 | return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0, |
| 158 | 0, 0); |
| 159 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 160 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 161 | static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret) |
| 162 | { |
| 163 | return (ffa_vm_id_t)ret.ret4; |
| 164 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions |
| 168 | * of specified IDs. |
| 169 | */ |
| 170 | #define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1) |
| 171 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 172 | static inline smc_ret_values cactus_req_deadlock_send_cmd( |
| 173 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1, |
| 174 | ffa_vm_id_t next_dest2) |
| 175 | { |
| 176 | return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD, |
| 177 | next_dest1, next_dest2, 0, 0); |
| 178 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 179 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 180 | /* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */ |
| 181 | static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret) |
| 182 | { |
| 183 | return (ffa_vm_id_t)ret.ret5; |
| 184 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 185 | |
| 186 | /** |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 187 | * Command to notify cactus of a memory management operation. The cmd value |
| 188 | * should be the memory management smc function id. |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 189 | * |
| 190 | * The id is the hex representation of the string "mem" |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 191 | */ |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 192 | #define CACTUS_MEM_SEND_CMD U(0x6d656d) |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 193 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 194 | static inline smc_ret_values cactus_mem_send_cmd( |
| 195 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func, |
| 196 | ffa_memory_handle_t handle) |
| 197 | { |
| 198 | return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func, |
| 199 | handle, 0, 0); |
| 200 | } |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 201 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 202 | static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret) |
| 203 | { |
| 204 | return (ffa_memory_handle_t)ret.ret5; |
| 205 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 206 | |
| 207 | /** |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 208 | * Command to request a memory management operation. The 'mem_func' argument |
| 209 | * identifies the operation that is to be performend, and 'receiver' is the id |
| 210 | * of the partition to receive the memory region. |
| 211 | * |
| 212 | * The command id is the hex representation of the string "memory". |
| 213 | */ |
| 214 | #define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279) |
| 215 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 216 | static inline smc_ret_values cactus_req_mem_send_send_cmd( |
| 217 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func, |
| 218 | ffa_vm_id_t receiver) |
| 219 | { |
| 220 | return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, |
| 221 | receiver, 0, 0); |
| 222 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 223 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 224 | static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret) |
| 225 | { |
| 226 | return (uint32_t)ret.ret4; |
| 227 | } |
| 228 | |
| 229 | static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret) |
| 230 | { |
| 231 | return (ffa_vm_id_t)ret.ret5; |
| 232 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 233 | |
| 234 | /** |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 235 | * Request to fill SIMD vectors with dummy values with purpose to check a |
| 236 | * save/restore routine during the context switches between secure world and |
| 237 | * normal world. |
| 238 | * |
| 239 | * The command id is the hex representation of the string "SIMD" |
| 240 | */ |
| 241 | #define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44) |
| 242 | |
| 243 | static inline smc_ret_values cactus_req_simd_fill_send_cmd( |
| 244 | ffa_vm_id_t source, ffa_vm_id_t dest) |
| 245 | { |
| 246 | return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0, 0); |
| 247 | } |
| 248 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 249 | #endif |