J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 1 | /* |
J-Alves | 32ccd2b | 2021-12-14 14:59:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 40 | ffa_id_t source, ffa_id_t dest, uint64_t cmd, uint64_t val0, |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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( |
J-Alves | 7a59528 | 2021-03-29 15:11:11 +0100 | [diff] [blame] | 53 | ffa_id_t source, ffa_id_t dest, uint32_t resp, uint64_t val0, |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 64 | ffa_id_t source, ffa_id_t dest, uint32_t response) |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 65 | { |
Madhukar Pappireddy | 3c28726 | 2021-08-05 14:39:24 -0500 | [diff] [blame] | 66 | return cactus_send_response(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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 81 | ffa_id_t source, ffa_id_t dest, uint64_t value) |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 93 | ffa_id_t source, ffa_id_t dest, uint32_t error_code) |
J-Alves | 7d28b33 | 2021-02-11 16:08:08 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 113 | ffa_id_t source, ffa_id_t dest, uint64_t echo_val) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 134 | ffa_id_t source, ffa_id_t dest, ffa_id_t echo_dest, |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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 | |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 141 | static inline ffa_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 142 | { |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 143 | return (ffa_id_t)ret.ret5; |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 158 | ffa_id_t source, ffa_id_t dest, ffa_id_t next_dest) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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 | |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 164 | static inline ffa_id_t cactus_deadlock_get_next_dest(smc_ret_values ret) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 165 | { |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 166 | return (ffa_id_t)ret.ret4; |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 176 | ffa_id_t source, ffa_id_t dest, ffa_id_t next_dest1, |
| 177 | ffa_id_t next_dest2) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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 */ |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 184 | static inline ffa_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 185 | { |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 186 | return (ffa_id_t)ret.ret5; |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 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( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 198 | ffa_id_t source, ffa_id_t dest, uint32_t mem_func, |
J-Alves | 32ccd2b | 2021-12-14 14:59:51 +0000 | [diff] [blame] | 199 | ffa_memory_handle_t handle, ffa_memory_region_flags_t retrieve_flags, |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 200 | bool non_secure, uint16_t word_to_write) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 201 | { |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 202 | /* |
| 203 | * `non_secure` and `word_to_write` are packed in the same register. |
| 204 | * Packed in a 32-bit value to support AArch32 platforms (eg Juno). |
| 205 | */ |
| 206 | uint32_t val3 = ((uint32_t)non_secure << 16) | word_to_write; |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 207 | return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func, |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 208 | handle, retrieve_flags, val3); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 209 | } |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 210 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 211 | static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret) |
| 212 | { |
| 213 | return (ffa_memory_handle_t)ret.ret5; |
| 214 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 215 | |
J-Alves | 32ccd2b | 2021-12-14 14:59:51 +0000 | [diff] [blame] | 216 | static inline ffa_memory_region_flags_t cactus_mem_send_get_retrv_flags( |
| 217 | smc_ret_values ret) |
| 218 | { |
| 219 | return (ffa_memory_region_flags_t)ret.ret6; |
| 220 | } |
| 221 | |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 222 | static inline uint16_t cactus_mem_send_words_to_write(smc_ret_values ret) |
J-Alves | 32ccd2b | 2021-12-14 14:59:51 +0000 | [diff] [blame] | 223 | { |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 224 | return (uint16_t)ret.ret7; |
| 225 | } |
| 226 | |
| 227 | static inline bool cactus_mem_send_get_non_secure(smc_ret_values ret) |
| 228 | { |
| 229 | return (bool)(ret.ret7 >> 16); |
J-Alves | 32ccd2b | 2021-12-14 14:59:51 +0000 | [diff] [blame] | 230 | } |
| 231 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 232 | /** |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 233 | * Command to request a memory management operation. The 'mem_func' argument |
| 234 | * identifies the operation that is to be performend, and 'receiver' is the id |
| 235 | * of the partition to receive the memory region. |
| 236 | * |
| 237 | * The command id is the hex representation of the string "memory". |
| 238 | */ |
| 239 | #define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279) |
| 240 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 241 | static inline smc_ret_values cactus_req_mem_send_send_cmd( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 242 | ffa_id_t source, ffa_id_t dest, uint32_t mem_func, |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 243 | ffa_id_t receiver, bool non_secure) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 244 | { |
| 245 | return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 246 | receiver, non_secure, 0); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 247 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 248 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 249 | static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret) |
| 250 | { |
| 251 | return (uint32_t)ret.ret4; |
| 252 | } |
| 253 | |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 254 | static inline ffa_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 255 | { |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 256 | return (ffa_id_t)ret.ret5; |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 257 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 258 | |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 259 | static inline bool cactus_req_mem_send_get_non_secure(smc_ret_values ret) |
| 260 | { |
| 261 | return (bool)ret.ret6; |
| 262 | } |
| 263 | |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 264 | /** |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 265 | * Request to fill SIMD vectors with dummy values with purpose to check a |
| 266 | * save/restore routine during the context switches between secure world and |
| 267 | * normal world. |
| 268 | * |
| 269 | * The command id is the hex representation of the string "SIMD" |
| 270 | */ |
| 271 | #define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44) |
| 272 | |
| 273 | static inline smc_ret_values cactus_req_simd_fill_send_cmd( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 274 | ffa_id_t source, ffa_id_t dest) |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 275 | { |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 276 | return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0, |
| 277 | 0); |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 280 | /** |
| 281 | * Command to request cactus to sleep for the given time in ms |
| 282 | * |
| 283 | * The command id is the hex representation of string "sleep" |
| 284 | */ |
| 285 | #define CACTUS_SLEEP_CMD U(0x736c656570) |
| 286 | |
| 287 | static inline smc_ret_values cactus_sleep_cmd( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 288 | ffa_id_t source, ffa_id_t dest, uint32_t sleep_time) |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 289 | { |
| 290 | return cactus_send_cmd(source, dest, CACTUS_SLEEP_CMD, sleep_time, 0, 0, |
| 291 | 0); |
| 292 | } |
| 293 | |
Madhukar Pappireddy | b640259 | 2021-08-20 13:13:49 -0500 | [diff] [blame] | 294 | /** |
| 295 | * Command to request cactus to forward sleep command for the given time in ms |
| 296 | * |
| 297 | * The sender of this command expects to receive CACTUS_SUCCESS if the requested |
| 298 | * echo interaction happened successfully, or CACTUS_ERROR otherwise. |
| 299 | */ |
| 300 | #define CACTUS_FWD_SLEEP_CMD (CACTUS_SLEEP_CMD + 1) |
| 301 | |
| 302 | static inline smc_ret_values cactus_fwd_sleep_cmd( |
| 303 | ffa_id_t source, ffa_id_t dest, ffa_id_t fwd_dest, |
| 304 | uint32_t sleep_time) |
| 305 | { |
| 306 | return cactus_send_cmd(source, dest, CACTUS_FWD_SLEEP_CMD, sleep_time, |
| 307 | fwd_dest, 0, 0); |
| 308 | } |
| 309 | |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 310 | static inline uint32_t cactus_get_sleep_time(smc_ret_values ret) |
| 311 | { |
| 312 | return (uint32_t)ret.ret4; |
| 313 | } |
| 314 | |
Madhukar Pappireddy | b640259 | 2021-08-20 13:13:49 -0500 | [diff] [blame] | 315 | static inline ffa_id_t cactus_get_fwd_sleep_dest(smc_ret_values ret) |
| 316 | { |
| 317 | return (ffa_id_t)ret.ret5; |
| 318 | } |
| 319 | |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 320 | /** |
Madhukar Pappireddy | 407befc | 2021-12-17 11:06:17 -0600 | [diff] [blame] | 321 | * Command to request cactus to sleep for half the given time in ms, trigger |
| 322 | * trusted watchdog timer and then sleep again for another half the given time. |
| 323 | * |
| 324 | * The sender of this command expects to receive CACTUS_SUCCESS if the requested |
| 325 | * echo interaction happened successfully, or CACTUS_ERROR otherwise. |
| 326 | */ |
| 327 | #define CACTUS_SLEEP_TRIGGER_TWDOG_CMD (CACTUS_SLEEP_CMD + 2) |
| 328 | |
| 329 | static inline smc_ret_values cactus_sleep_trigger_wdog_cmd( |
| 330 | ffa_id_t source, ffa_id_t dest, uint32_t sleep_time, |
| 331 | uint64_t wdog_time) |
| 332 | { |
| 333 | return cactus_send_cmd(source, dest, CACTUS_SLEEP_TRIGGER_TWDOG_CMD, sleep_time, |
| 334 | wdog_time, 0, 0); |
| 335 | } |
| 336 | |
| 337 | |
| 338 | static inline uint32_t cactus_get_wdog_trigger_duration(smc_ret_values ret) |
| 339 | { |
| 340 | return (uint32_t)ret.ret5; |
| 341 | } |
| 342 | |
| 343 | /** |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 344 | * Command to request cactus to enable/disable an interrupt |
| 345 | * |
| 346 | * The command id is the hex representation of string "intr" |
| 347 | */ |
| 348 | #define CACTUS_INTERRUPT_CMD U(0x696e7472) |
| 349 | |
| 350 | static inline smc_ret_values cactus_interrupt_cmd( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 351 | ffa_id_t source, ffa_id_t dest, uint32_t interrupt_id, |
Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 352 | bool enable, uint32_t pin) |
| 353 | { |
| 354 | return cactus_send_cmd(source, dest, CACTUS_INTERRUPT_CMD, interrupt_id, |
| 355 | enable, pin, 0); |
| 356 | } |
| 357 | |
| 358 | static inline uint32_t cactus_get_interrupt_id(smc_ret_values ret) |
| 359 | { |
| 360 | return (uint32_t)ret.ret4; |
| 361 | } |
| 362 | |
| 363 | static inline bool cactus_get_interrupt_enable(smc_ret_values ret) |
| 364 | { |
| 365 | return (bool)ret.ret5; |
| 366 | } |
| 367 | |
| 368 | static inline enum interrupt_pin cactus_get_interrupt_pin(smc_ret_values ret) |
| 369 | { |
| 370 | return (enum interrupt_pin)ret.ret6; |
| 371 | } |
| 372 | |
Madhukar Pappireddy | 172523b | 2020-12-31 19:25:33 -0600 | [diff] [blame] | 373 | /** |
| 374 | * Request to initiate DMA transaction by upstream peripheral. |
| 375 | * |
| 376 | * The command id is the hex representation of the string "SMMU" |
| 377 | */ |
| 378 | #define CACTUS_DMA_SMMUv3_CMD (0x534d4d55) |
| 379 | |
| 380 | static inline smc_ret_values cactus_send_dma_cmd( |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 381 | ffa_id_t source, ffa_id_t dest) |
Madhukar Pappireddy | 172523b | 2020-12-31 19:25:33 -0600 | [diff] [blame] | 382 | { |
| 383 | return cactus_send_cmd(source, dest, CACTUS_DMA_SMMUv3_CMD, 0, 0, 0, |
| 384 | 0); |
| 385 | } |
J-Alves | b4e89a2 | 2021-03-09 10:04:39 +0000 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * Request SP to bind a notification to a FF-A endpoint. In case of error |
| 389 | * when using the FFA_NOTIFICATION_BIND interface, include the error code |
| 390 | * in the response to the command's request. The receiver and sender arguments |
| 391 | * are propagated through the command's arguments, to allow the test of |
| 392 | * erroneous uses of the FFA_NOTIFICATION_BIND interface. |
| 393 | * |
| 394 | * The command id is the hex representation of the string "bind". |
| 395 | */ |
| 396 | #define CACTUS_NOTIFICATION_BIND_CMD U(0x62696e64) |
| 397 | |
| 398 | static inline smc_ret_values cactus_notification_bind_send_cmd( |
| 399 | ffa_id_t source, ffa_id_t dest, ffa_id_t receiver, |
| 400 | ffa_id_t sender, ffa_notification_bitmap_t notifications, uint32_t flags) |
| 401 | { |
| 402 | return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_BIND_CMD, |
| 403 | receiver, sender, notifications, flags); |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Request to SP unbind a notification. In case of error when using the |
| 408 | * FFA_NOTIFICATION_UNBIND interface, the test includes the error code in the |
| 409 | * response. The receiver and sender arguments are propagated throught the |
| 410 | * command's arguments, to allow the test of erroneous uses of the |
| 411 | * FFA_NOTIFICATION_BIND interface. |
| 412 | * |
| 413 | * The command id is the hex representation of the string "unbind". |
| 414 | */ |
| 415 | #define CACTUS_NOTIFICATION_UNBIND_CMD U(0x756e62696e64) |
| 416 | |
| 417 | static inline smc_ret_values cactus_notification_unbind_send_cmd( |
| 418 | ffa_id_t source, ffa_id_t dest, ffa_id_t receiver, |
| 419 | ffa_id_t sender, ffa_notification_bitmap_t notifications) |
| 420 | { |
| 421 | return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_UNBIND_CMD, |
| 422 | receiver, sender, notifications, 0); |
| 423 | } |
| 424 | |
| 425 | static inline ffa_id_t cactus_notification_get_receiver( |
| 426 | smc_ret_values ret) |
| 427 | { |
| 428 | return (ffa_id_t)ret.ret4; |
| 429 | } |
| 430 | |
| 431 | static inline ffa_id_t cactus_notification_get_sender( |
| 432 | smc_ret_values ret) |
| 433 | { |
| 434 | return (ffa_id_t)ret.ret5; |
| 435 | } |
| 436 | |
| 437 | static inline ffa_notification_bitmap_t cactus_notification_get_notifications( |
| 438 | smc_ret_values ret) |
| 439 | { |
| 440 | return (uint64_t)ret.ret6; |
| 441 | } |
| 442 | |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 443 | /** |
| 444 | * Request SP to get notifications. The arguments to use in ffa_notification_get |
| 445 | * are propagated on the command to test erroneous uses of the interface. |
| 446 | * In a successful call to the interface, the SP's response payload should |
| 447 | * include all bitmaps returned by the SPMC. |
| 448 | * |
| 449 | * The command id is the hex representation of the string "getnot". |
| 450 | */ |
| 451 | #define CACTUS_NOTIFICATION_GET_CMD U(0x6765746e6f74) |
| 452 | |
| 453 | static inline smc_ret_values cactus_notification_get_send_cmd( |
| 454 | ffa_id_t source, ffa_id_t dest, ffa_id_t receiver, |
J-Alves | a076d4c | 2021-10-19 16:06:15 +0100 | [diff] [blame] | 455 | uint32_t vcpu_id, uint32_t flags, bool check_npi_handled) |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 456 | { |
| 457 | return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_GET_CMD, |
J-Alves | a076d4c | 2021-10-19 16:06:15 +0100 | [diff] [blame] | 458 | receiver, vcpu_id, check_npi_handled, flags); |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static inline uint32_t cactus_notification_get_vcpu(smc_ret_values ret) |
| 462 | { |
| 463 | return (uint32_t)ret.ret5; |
| 464 | } |
| 465 | |
J-Alves | b4e89a2 | 2021-03-09 10:04:39 +0000 | [diff] [blame] | 466 | static inline uint32_t cactus_notification_get_flags(smc_ret_values ret) |
| 467 | { |
| 468 | return (uint32_t)ret.ret7; |
| 469 | } |
| 470 | |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 471 | static inline smc_ret_values cactus_notifications_get_success_resp( |
| 472 | ffa_id_t source, ffa_id_t dest, uint64_t from_sp, |
| 473 | uint64_t from_vm) |
| 474 | { |
| 475 | return cactus_send_response(source, dest, CACTUS_SUCCESS, from_sp, |
| 476 | from_vm, 0, 0); |
| 477 | } |
| 478 | |
| 479 | static inline uint64_t cactus_notifications_get_from_sp(smc_ret_values ret) |
| 480 | { |
| 481 | return (uint64_t)ret.ret4; |
| 482 | } |
| 483 | |
| 484 | static inline uint64_t cactus_notifications_get_from_vm(smc_ret_values ret) |
| 485 | { |
| 486 | return (uint64_t)ret.ret5; |
| 487 | } |
| 488 | |
J-Alves | a076d4c | 2021-10-19 16:06:15 +0100 | [diff] [blame] | 489 | static inline bool cactus_notifications_check_npi_handled(smc_ret_values ret) |
| 490 | { |
| 491 | return (bool)ret.ret6; |
| 492 | } |
| 493 | |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 494 | /** |
| 495 | * Request SP to set notifications. The arguments to use in ffa_notification_set |
| 496 | * are propagated on the command to test erroneous uses of the interface. |
| 497 | * In case of error while calling the interface, the response should include the |
J-Alves | fbbbf62 | 2021-07-30 16:43:36 +0100 | [diff] [blame] | 498 | * error code. If in the flags a delay SRI is requested, cactus should |
| 499 | * send a CACTUS_ECHO_CMD to the SP specified as `echo_dest`. This should help |
| 500 | * validate that the SRI is only sent when returning execution to the NWd. |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 501 | */ |
| 502 | #define CACTUS_NOTIFICATIONS_SET_CMD U(0x6e6f74736574) |
| 503 | |
| 504 | static inline smc_ret_values cactus_notifications_set_send_cmd( |
| 505 | ffa_id_t source, ffa_id_t dest, ffa_id_t receiver, |
J-Alves | fbbbf62 | 2021-07-30 16:43:36 +0100 | [diff] [blame] | 506 | ffa_id_t sender, uint32_t flags, ffa_notification_bitmap_t notifications, |
| 507 | ffa_id_t echo_dest) |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 508 | { |
| 509 | return cactus_send_cmd(source, dest, CACTUS_NOTIFICATIONS_SET_CMD, |
J-Alves | fbbbf62 | 2021-07-30 16:43:36 +0100 | [diff] [blame] | 510 | (uint32_t)receiver | ((uint32_t)sender << 16), |
| 511 | echo_dest, |
| 512 | notifications, flags); |
| 513 | } |
| 514 | |
| 515 | static inline ffa_id_t cactus_notifications_set_get_receiver(smc_ret_values ret) |
| 516 | { |
| 517 | return (ffa_id_t)(ret.ret4 & 0xFFFFU); |
| 518 | } |
| 519 | |
| 520 | static inline ffa_id_t cactus_notifications_set_get_sender(smc_ret_values ret) |
| 521 | { |
| 522 | return (ffa_id_t)((ret.ret4 >> 16U) & 0xFFFFU); |
J-Alves | ab77591 | 2021-03-29 15:22:33 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Madhukar Pappireddy | 3c28726 | 2021-08-05 14:39:24 -0500 | [diff] [blame] | 525 | /** |
| 526 | * Request to start trusted watchdog timer. |
| 527 | * |
| 528 | * The command id is the hex representaton of the string "WDOG" |
| 529 | */ |
| 530 | #define CACTUS_TWDOG_START_CMD U(0x57444f47) |
| 531 | |
| 532 | static inline smc_ret_values cactus_send_twdog_cmd( |
| 533 | ffa_id_t source, ffa_id_t dest, uint64_t time) |
| 534 | { |
| 535 | return cactus_send_cmd(source, dest, CACTUS_TWDOG_START_CMD, time, 0, 0, |
| 536 | 0); |
| 537 | } |
| 538 | |
| 539 | static inline uint32_t cactus_get_wdog_duration(smc_ret_values ret) |
| 540 | { |
| 541 | return (uint32_t)ret.ret4; |
| 542 | } |
| 543 | |
J-Alves | f7535f4 | 2021-07-30 11:58:41 +0100 | [diff] [blame] | 544 | /** |
| 545 | * Request SP to return the current count of handled requests. |
| 546 | * |
| 547 | * The command id is the hex representation of the string "getnot". |
| 548 | */ |
| 549 | #define CACTUS_GET_REQ_COUNT_CMD U(0x726571636f756e74) |
| 550 | |
| 551 | static inline smc_ret_values cactus_get_req_count_send_cmd( |
| 552 | ffa_id_t source, ffa_id_t dest) |
| 553 | { |
| 554 | return cactus_send_cmd(source, dest, CACTUS_GET_REQ_COUNT_CMD, 0, 0, 0, |
| 555 | 0); |
| 556 | } |
| 557 | |
| 558 | static inline uint32_t cactus_get_req_count(smc_ret_values ret) |
| 559 | { |
| 560 | return (uint32_t)ret.ret4; |
| 561 | } |
| 562 | |
Madhukar Pappireddy | f4c8e8d | 2022-02-15 15:52:53 -0600 | [diff] [blame] | 563 | /** |
| 564 | * Request SP to return the last serviced secure virtual interrupt. |
| 565 | * |
| 566 | * The command id is the hex representaton of the string "vINT" |
| 567 | */ |
| 568 | #define CACTUS_LAST_INTERRUPT_SERVICED_CMD U(0x76494e54) |
| 569 | |
| 570 | static inline smc_ret_values cactus_get_last_interrupt_cmd( |
| 571 | ffa_id_t source, ffa_id_t dest) |
| 572 | { |
| 573 | return cactus_send_cmd(source, dest, CACTUS_LAST_INTERRUPT_SERVICED_CMD, |
| 574 | 0, 0, 0, 0); |
| 575 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 576 | #endif |