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