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 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 10 | #include <ffa_helpers.h> |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 11 | #include <spm_common.h> |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Success and error return to be sent over a msg response. |
| 15 | */ |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 16 | #define CACTUS_SUCCESS U(0) |
| 17 | #define CACTUS_ERROR U(-1) |
| 18 | |
| 19 | /** |
| 20 | * Error codes. |
| 21 | */ |
| 22 | #define CACTUS_ERROR_INVALID U(1) |
| 23 | #define CACTUS_ERROR_TEST U(2) |
| 24 | #define CACTUS_ERROR_FFA_CALL U(3) |
J-Alves | 4cb9dee | 2021-03-03 13:59:52 +0000 | [diff] [blame] | 25 | #define CACTUS_ERROR_UNHANDLED U(4) |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Get command from struct smc_ret_values. |
| 29 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 30 | static inline uint64_t cactus_get_cmd(smc_ret_values ret) |
| 31 | { |
| 32 | return (uint64_t)ret.ret3; |
| 33 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Template for commands to be sent to CACTUS partitions over direct |
| 37 | * messages interfaces. |
| 38 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 39 | static inline smc_ret_values cactus_send_cmd( |
| 40 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t cmd, uint64_t val0, |
| 41 | uint64_t val1, uint64_t val2, uint64_t val3) |
| 42 | { |
J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 43 | return ffa_msg_send_direct_req64(source, dest, cmd, val0, val1, val2, |
| 44 | val3); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 45 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 46 | |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 47 | /** |
| 48 | * Template for responses to Cactus commands. |
| 49 | * 'cactus_send_response' is the template for custom responses, in case there is |
| 50 | * a need to propagate more than one value in the response of a command. |
| 51 | */ |
| 52 | static inline smc_ret_values cactus_send_response( |
| 53 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t resp, uint32_t val0, |
| 54 | uint64_t val1, uint64_t val2, uint64_t val3) |
| 55 | { |
J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 56 | return ffa_msg_send_direct_resp64(source, dest, resp, val0, val1, |
| 57 | val2, val3); |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
| 61 | * For responses of one value only. |
| 62 | */ |
| 63 | static inline smc_ret_values cactus_response( |
| 64 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response) |
| 65 | { |
J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 66 | return ffa_msg_send_direct_resp64(source, dest, response, 0, 0, 0, 0); |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static inline uint32_t cactus_get_response(smc_ret_values ret) |
| 70 | { |
| 71 | return (uint32_t)ret.ret3; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * In a successful test, in case the SP needs to propagate an extra value |
| 76 | * to conclude the test. |
| 77 | * If more arguments are needed, a custom response should be defined for the |
| 78 | * specific test. |
| 79 | */ |
| 80 | static inline smc_ret_values cactus_success_resp( |
| 81 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t value) |
| 82 | { |
| 83 | return cactus_send_response(source, dest, CACTUS_SUCCESS, value, |
| 84 | 0, 0, 0); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * In case the test fails on the SP side, the 'error_code' should help specify |
| 89 | * the reason, which can be specific to the test, or general ones as defined |
| 90 | * in the error code list. |
| 91 | */ |
| 92 | static inline smc_ret_values cactus_error_resp( |
| 93 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t error_code) |
| 94 | { |
| 95 | return cactus_send_response(source, dest, CACTUS_ERROR, error_code, |
| 96 | 0, 0, 0); |
| 97 | } |
| 98 | |
| 99 | static inline uint32_t cactus_error_code(smc_ret_values ret) |
| 100 | { |
| 101 | return (uint32_t) ret.ret4; |
| 102 | } |
| 103 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 104 | /** |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 105 | * With this test command the sender transmits a 64-bit value that it then |
| 106 | * expects to receive on the respective command response. |
| 107 | * |
| 108 | * The id is the hex representation of the string 'echo'. |
| 109 | */ |
| 110 | #define CACTUS_ECHO_CMD U(0x6563686f) |
| 111 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 112 | static inline smc_ret_values cactus_echo_send_cmd( |
| 113 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val) |
| 114 | { |
| 115 | return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0, |
| 116 | 0); |
| 117 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 118 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 119 | static inline uint64_t cactus_echo_get_val(smc_ret_values ret) |
| 120 | { |
| 121 | return (uint64_t)ret.ret4; |
| 122 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Command to request a cactus secure partition to send an echo command to |
| 126 | * another partition. |
| 127 | * |
| 128 | * The sender of this command expects to receive CACTUS_SUCCESS if the requested |
| 129 | * echo interaction happened successfully, or CACTUS_ERROR otherwise. |
| 130 | */ |
| 131 | #define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1) |
| 132 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 133 | static inline smc_ret_values cactus_req_echo_send_cmd( |
| 134 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest, |
| 135 | uint64_t echo_val) |
| 136 | { |
| 137 | return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val, |
| 138 | echo_dest, 0, 0); |
| 139 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 140 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 141 | static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret) |
| 142 | { |
| 143 | return (ffa_vm_id_t)ret.ret5; |
| 144 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 145 | |
| 146 | /** |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 147 | * Command to create a cyclic dependency between SPs, which could result in |
| 148 | * a deadlock. This aims at proving such scenario cannot happen. |
| 149 | * If the deadlock happens, the system will just hang. |
| 150 | * If the deadlock is prevented, the last partition to use the command will |
| 151 | * send response CACTUS_SUCCESS. |
| 152 | * |
| 153 | * The id is the hex representation of the string 'dead'. |
| 154 | */ |
| 155 | #define CACTUS_DEADLOCK_CMD U(0x64656164) |
| 156 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 157 | static inline smc_ret_values cactus_deadlock_send_cmd( |
| 158 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest) |
| 159 | { |
| 160 | return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0, |
| 161 | 0, 0); |
| 162 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 163 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 164 | static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret) |
| 165 | { |
| 166 | return (ffa_vm_id_t)ret.ret4; |
| 167 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions |
| 171 | * of specified IDs. |
| 172 | */ |
| 173 | #define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1) |
| 174 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 175 | static inline smc_ret_values cactus_req_deadlock_send_cmd( |
| 176 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1, |
| 177 | ffa_vm_id_t next_dest2) |
| 178 | { |
| 179 | return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD, |
| 180 | next_dest1, next_dest2, 0, 0); |
| 181 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 182 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 183 | /* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */ |
| 184 | static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret) |
| 185 | { |
| 186 | return (ffa_vm_id_t)ret.ret5; |
| 187 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 188 | |
| 189 | /** |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 190 | * Command to notify cactus of a memory management operation. The cmd value |
| 191 | * should be the memory management smc function id. |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 192 | * |
| 193 | * The id is the hex representation of the string "mem" |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 194 | */ |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 195 | #define CACTUS_MEM_SEND_CMD U(0x6d656d) |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 196 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 197 | static inline smc_ret_values cactus_mem_send_cmd( |
| 198 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func, |
| 199 | ffa_memory_handle_t handle) |
| 200 | { |
| 201 | return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func, |
| 202 | handle, 0, 0); |
| 203 | } |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 204 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 205 | static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret) |
| 206 | { |
| 207 | return (ffa_memory_handle_t)ret.ret5; |
| 208 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 209 | |
| 210 | /** |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 211 | * Command to request a memory management operation. The 'mem_func' argument |
| 212 | * identifies the operation that is to be performend, and 'receiver' is the id |
| 213 | * of the partition to receive the memory region. |
| 214 | * |
| 215 | * The command id is the hex representation of the string "memory". |
| 216 | */ |
| 217 | #define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279) |
| 218 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 219 | static inline smc_ret_values cactus_req_mem_send_send_cmd( |
| 220 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func, |
| 221 | ffa_vm_id_t receiver) |
| 222 | { |
| 223 | return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, |
| 224 | receiver, 0, 0); |
| 225 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 226 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 227 | static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret) |
| 228 | { |
| 229 | return (uint32_t)ret.ret4; |
| 230 | } |
| 231 | |
| 232 | static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret) |
| 233 | { |
| 234 | return (ffa_vm_id_t)ret.ret5; |
| 235 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 236 | |
| 237 | /** |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 238 | * Request to fill SIMD vectors with dummy values with purpose to check a |
| 239 | * save/restore routine during the context switches between secure world and |
| 240 | * normal world. |
| 241 | * |
| 242 | * The command id is the hex representation of the string "SIMD" |
| 243 | */ |
| 244 | #define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44) |
| 245 | |
| 246 | static inline smc_ret_values cactus_req_simd_fill_send_cmd( |
| 247 | ffa_vm_id_t source, ffa_vm_id_t dest) |
| 248 | { |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 249 | return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0, |
| 250 | 0); |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 251 | } |
| 252 | |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 253 | /** |
| 254 | * Command to request cactus to sleep for the given time in ms |
| 255 | * |
| 256 | * The command id is the hex representation of string "sleep" |
| 257 | */ |
| 258 | #define CACTUS_SLEEP_CMD U(0x736c656570) |
| 259 | |
| 260 | static inline smc_ret_values cactus_sleep_cmd( |
| 261 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t sleep_time) |
| 262 | { |
| 263 | return cactus_send_cmd(source, dest, CACTUS_SLEEP_CMD, sleep_time, 0, 0, |
| 264 | 0); |
| 265 | } |
| 266 | |
| 267 | static inline uint32_t cactus_get_sleep_time(smc_ret_values ret) |
| 268 | { |
| 269 | return (uint32_t)ret.ret4; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Command to request cactus to enable/disable an interrupt |
| 274 | * |
| 275 | * The command id is the hex representation of string "intr" |
| 276 | */ |
| 277 | #define CACTUS_INTERRUPT_CMD U(0x696e7472) |
| 278 | |
| 279 | static inline smc_ret_values cactus_interrupt_cmd( |
| 280 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t interrupt_id, |
| 281 | bool enable, uint32_t pin) |
| 282 | { |
| 283 | return cactus_send_cmd(source, dest, CACTUS_INTERRUPT_CMD, interrupt_id, |
| 284 | enable, pin, 0); |
| 285 | } |
| 286 | |
| 287 | static inline uint32_t cactus_get_interrupt_id(smc_ret_values ret) |
| 288 | { |
| 289 | return (uint32_t)ret.ret4; |
| 290 | } |
| 291 | |
| 292 | static inline bool cactus_get_interrupt_enable(smc_ret_values ret) |
| 293 | { |
| 294 | return (bool)ret.ret5; |
| 295 | } |
| 296 | |
| 297 | static inline enum interrupt_pin cactus_get_interrupt_pin(smc_ret_values ret) |
| 298 | { |
| 299 | return (enum interrupt_pin)ret.ret6; |
| 300 | } |
| 301 | |
Madhukar Pappireddy | 172523b | 2020-12-31 19:25:33 -0600 | [diff] [blame^] | 302 | /** |
| 303 | * Request to initiate DMA transaction by upstream peripheral. |
| 304 | * |
| 305 | * The command id is the hex representation of the string "SMMU" |
| 306 | */ |
| 307 | #define CACTUS_DMA_SMMUv3_CMD (0x534d4d55) |
| 308 | |
| 309 | static inline smc_ret_values cactus_send_dma_cmd( |
| 310 | ffa_vm_id_t source, ffa_vm_id_t dest) |
| 311 | { |
| 312 | return cactus_send_cmd(source, dest, CACTUS_DMA_SMMUv3_CMD, 0, 0, 0, |
| 313 | 0); |
| 314 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 315 | #endif |