J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited. All rights reserved. |
| 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 | |
| 39 | #define PRINT_CMD(smc_ret) \ |
| 40 | VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \ |
| 41 | smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \ |
| 42 | smc_ret.ret6, smc_ret.ret7) |
| 43 | |
| 44 | /** |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 45 | * With this test command the sender transmits a 64-bit value that it then |
| 46 | * expects to receive on the respective command response. |
| 47 | * |
| 48 | * The id is the hex representation of the string 'echo'. |
| 49 | */ |
| 50 | #define CACTUS_ECHO_CMD U(0x6563686f) |
| 51 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 52 | static inline smc_ret_values cactus_echo_send_cmd( |
| 53 | ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val) |
| 54 | { |
| 55 | return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0, |
| 56 | 0); |
| 57 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 58 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 59 | static inline uint64_t cactus_echo_get_val(smc_ret_values ret) |
| 60 | { |
| 61 | return (uint64_t)ret.ret4; |
| 62 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Command to request a cactus secure partition to send an echo command to |
| 66 | * another partition. |
| 67 | * |
| 68 | * The sender of this command expects to receive CACTUS_SUCCESS if the requested |
| 69 | * echo interaction happened successfully, or CACTUS_ERROR otherwise. |
| 70 | */ |
| 71 | #define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1) |
| 72 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 73 | static inline smc_ret_values cactus_req_echo_send_cmd( |
| 74 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest, |
| 75 | uint64_t echo_val) |
| 76 | { |
| 77 | return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val, |
| 78 | echo_dest, 0, 0); |
| 79 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 80 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 81 | static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret) |
| 82 | { |
| 83 | return (ffa_vm_id_t)ret.ret5; |
| 84 | } |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 85 | |
| 86 | /** |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 87 | * Command to create a cyclic dependency between SPs, which could result in |
| 88 | * a deadlock. This aims at proving such scenario cannot happen. |
| 89 | * If the deadlock happens, the system will just hang. |
| 90 | * If the deadlock is prevented, the last partition to use the command will |
| 91 | * send response CACTUS_SUCCESS. |
| 92 | * |
| 93 | * The id is the hex representation of the string 'dead'. |
| 94 | */ |
| 95 | #define CACTUS_DEADLOCK_CMD U(0x64656164) |
| 96 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 97 | static inline smc_ret_values cactus_deadlock_send_cmd( |
| 98 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest) |
| 99 | { |
| 100 | return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0, |
| 101 | 0, 0); |
| 102 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 103 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 104 | static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret) |
| 105 | { |
| 106 | return (ffa_vm_id_t)ret.ret4; |
| 107 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions |
| 111 | * of specified IDs. |
| 112 | */ |
| 113 | #define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1) |
| 114 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 115 | static inline smc_ret_values cactus_req_deadlock_send_cmd( |
| 116 | ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1, |
| 117 | ffa_vm_id_t next_dest2) |
| 118 | { |
| 119 | return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD, |
| 120 | next_dest1, next_dest2, 0, 0); |
| 121 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 122 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 123 | /* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */ |
| 124 | static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret) |
| 125 | { |
| 126 | return (ffa_vm_id_t)ret.ret5; |
| 127 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 128 | |
| 129 | /** |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 130 | * Command to notify cactus of a memory management operation. The cmd value |
| 131 | * should be the memory management smc function id. |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 132 | * |
| 133 | * The id is the hex representation of the string "mem" |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 134 | */ |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 135 | #define CACTUS_MEM_SEND_CMD U(0x6d656d) |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 136 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 137 | static inline smc_ret_values cactus_mem_send_cmd( |
| 138 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func, |
| 139 | ffa_memory_handle_t handle) |
| 140 | { |
| 141 | return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func, |
| 142 | handle, 0, 0); |
| 143 | } |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 144 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 145 | static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret) |
| 146 | { |
| 147 | return (ffa_memory_handle_t)ret.ret5; |
| 148 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 149 | |
| 150 | /** |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 151 | * Command to request a memory management operation. The 'mem_func' argument |
| 152 | * identifies the operation that is to be performend, and 'receiver' is the id |
| 153 | * of the partition to receive the memory region. |
| 154 | * |
| 155 | * The command id is the hex representation of the string "memory". |
| 156 | */ |
| 157 | #define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279) |
| 158 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 159 | static inline smc_ret_values cactus_req_mem_send_send_cmd( |
| 160 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func, |
| 161 | ffa_vm_id_t receiver) |
| 162 | { |
| 163 | return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, |
| 164 | receiver, 0, 0); |
| 165 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 166 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 167 | static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret) |
| 168 | { |
| 169 | return (uint32_t)ret.ret4; |
| 170 | } |
| 171 | |
| 172 | static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret) |
| 173 | { |
| 174 | return (ffa_vm_id_t)ret.ret5; |
| 175 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 176 | |
| 177 | /** |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 178 | * Template for responses to CACTUS commands. |
| 179 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 180 | static inline smc_ret_values cactus_response( |
| 181 | ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response) |
| 182 | { |
| 183 | return ffa_msg_send_direct_resp(source, dest, response); |
| 184 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 185 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 186 | static inline smc_ret_values cactus_success_resp( |
| 187 | ffa_vm_id_t source, ffa_vm_id_t dest) |
| 188 | { |
| 189 | return cactus_response(source, dest, CACTUS_SUCCESS); |
| 190 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 191 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 192 | static inline smc_ret_values cactus_error_resp( |
| 193 | ffa_vm_id_t source, ffa_vm_id_t dest) |
| 194 | { |
| 195 | return cactus_response(source, dest, CACTUS_ERROR); |
| 196 | } |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 197 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame^] | 198 | static inline uint32_t cactus_get_response(smc_ret_values ret) |
| 199 | { |
| 200 | return (uint32_t)ret.ret3; |
| 201 | } |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 202 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 203 | #endif |