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 | */ |
| 22 | #define CACTUS_GET_CMD(smc_ret) smc_ret.ret3 |
| 23 | |
| 24 | /** |
| 25 | * Template for commands to be sent to CACTUS partitions over direct |
| 26 | * messages interfaces. |
| 27 | */ |
| 28 | #define CACTUS_SEND_CMD(source, dest, cmd, val0, val1, val2, val3) \ |
| 29 | ffa_msg_send_direct_req64_5args(source, dest, cmd, \ |
| 30 | val0, val1, val2, val3) |
| 31 | |
| 32 | #define PRINT_CMD(smc_ret) \ |
| 33 | VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \ |
| 34 | smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \ |
| 35 | smc_ret.ret6, smc_ret.ret7) |
| 36 | |
| 37 | /** |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 38 | * With this test command the sender transmits a 64-bit value that it then |
| 39 | * expects to receive on the respective command response. |
| 40 | * |
| 41 | * The id is the hex representation of the string 'echo'. |
| 42 | */ |
| 43 | #define CACTUS_ECHO_CMD U(0x6563686f) |
| 44 | |
| 45 | #define CACTUS_ECHO_SEND_CMD(source, dest, echo_val) \ |
| 46 | CACTUS_SEND_CMD(source, dest, CACTUS_ECHO_CMD, echo_val,\ |
| 47 | 0, 0, 0) |
| 48 | |
| 49 | #define CACTUS_ECHO_GET_VAL(smc_ret) smc_ret.ret4 |
| 50 | |
| 51 | /** |
| 52 | * Command to request a cactus secure partition to send an echo command to |
| 53 | * another partition. |
| 54 | * |
| 55 | * The sender of this command expects to receive CACTUS_SUCCESS if the requested |
| 56 | * echo interaction happened successfully, or CACTUS_ERROR otherwise. |
| 57 | */ |
| 58 | #define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1) |
| 59 | |
| 60 | #define CACTUS_REQ_ECHO_SEND_CMD(source, dest, echo_dest, echo_val) \ |
| 61 | CACTUS_SEND_CMD(source, dest, CACTUS_REQ_ECHO_CMD, echo_val, \ |
| 62 | echo_dest, 0, 0) |
| 63 | |
| 64 | #define CACTUS_REQ_ECHO_GET_ECHO_DEST(smc_ret) smc_ret.ret5 |
| 65 | |
| 66 | /** |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 67 | * Command to create a cyclic dependency between SPs, which could result in |
| 68 | * a deadlock. This aims at proving such scenario cannot happen. |
| 69 | * If the deadlock happens, the system will just hang. |
| 70 | * If the deadlock is prevented, the last partition to use the command will |
| 71 | * send response CACTUS_SUCCESS. |
| 72 | * |
| 73 | * The id is the hex representation of the string 'dead'. |
| 74 | */ |
| 75 | #define CACTUS_DEADLOCK_CMD U(0x64656164) |
| 76 | |
| 77 | #define CACTUS_DEADLOCK_SEND_CMD(source, dest, next_dest) \ |
| 78 | CACTUS_SEND_CMD(source, dest, CACTUS_DEADLOCK_CMD, next_dest, \ |
| 79 | 0, 0, 0) |
| 80 | |
| 81 | #define CACTUS_DEADLOCK_GET_NEXT_DEST(smc_ret) smc_ret.ret4 |
| 82 | |
| 83 | /** |
| 84 | * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions |
| 85 | * of specified IDs. |
| 86 | */ |
| 87 | #define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1) |
| 88 | |
| 89 | #define CACTUS_REQ_DEADLOCK_SEND_CMD(source, dest, next_dest1, next_dest2) \ |
| 90 | CACTUS_SEND_CMD(source, dest, CACTUS_REQ_DEADLOCK_CMD, \ |
| 91 | next_dest1, next_dest2, 0, 0) |
| 92 | |
| 93 | /*To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST*/ |
| 94 | #define CACTUS_DEADLOCK_GET_NEXT_DEST2(smc_ret) smc_ret.ret5 |
| 95 | |
| 96 | /** |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 97 | * Command to notify cactus of a memory management operation. The cmd value |
| 98 | * should be the memory management smc function id. |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame^] | 99 | * |
| 100 | * The id is the hex representation of the string "mem" |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 101 | */ |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame^] | 102 | #define CACTUS_MEM_SEND_CMD U(0x6d656d) |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 103 | |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame^] | 104 | #define CACTUS_MEM_SEND_CMD_SEND(source, dest, mem_func, handle) \ |
| 105 | CACTUS_SEND_CMD(source, dest, CACTUS_MEM_SEND_CMD, \ |
| 106 | mem_func, handle, 0, 0) |
| 107 | |
| 108 | #define CACTUS_MEM_SEND_GET_FUNC(smc_ret) smc_ret.ret4 |
| 109 | |
| 110 | #define CACTUS_MEM_SEND_GET_HANDLE(smc_ret) smc_ret.ret5 |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 111 | |
| 112 | /** |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 113 | * Command to request a memory management operation. The 'mem_func' argument |
| 114 | * identifies the operation that is to be performend, and 'receiver' is the id |
| 115 | * of the partition to receive the memory region. |
| 116 | * |
| 117 | * The command id is the hex representation of the string "memory". |
| 118 | */ |
| 119 | #define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279) |
| 120 | |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame^] | 121 | #define CACTUS_REQ_MEM_SEND_SEND_CMD(source, dest, mem_func, receiver) \ |
| 122 | CACTUS_SEND_CMD(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, \ |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 123 | receiver, 0, 0) |
| 124 | |
| 125 | #define CACTUS_REQ_MEM_SEND_GET_MEM_FUNC(smc_ret) smc_ret.ret4 |
| 126 | #define CACTUS_REQ_MEM_SEND_GET_RECEIVER(smc_ret) smc_ret.ret5 |
| 127 | |
| 128 | /** |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 129 | * Template for responses to CACTUS commands. |
| 130 | */ |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 131 | #define CACTUS_RESPONSE(source, dest, response) \ |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 132 | ffa_msg_send_direct_resp(source, dest, response) |
| 133 | |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 134 | #define CACTUS_SUCCESS_RESP(source, dest) \ |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 135 | CACTUS_RESPONSE(source, dest, CACTUS_SUCCESS) |
| 136 | |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 137 | #define CACTUS_ERROR_RESP(source, dest) \ |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 138 | CACTUS_RESPONSE(source, dest, CACTUS_ERROR) |
| 139 | |
| 140 | #define CACTUS_GET_RESPONSE(smc_ret) smc_ret.ret3 |
| 141 | |
J-Alves | 28672f9 | 2020-11-09 15:34:31 +0000 | [diff] [blame] | 142 | #define CACTUS_IS_SUCCESS_RESP(smc_ret) \ |
| 143 | (CACTUS_GET_RESPONSE(smc_ret) == CACTUS_SUCCESS) |
| 144 | |
J-Alves | 542d8d8 | 2020-11-18 10:34:06 +0000 | [diff] [blame] | 145 | #define CACTUS_IS_ERROR_RESP(smc_ret) \ |
| 146 | (CACTUS_GET_RESPONSE(smc_ret) == CACTUS_ERROR) |
| 147 | |
J-Alves | d1aae29 | 2020-10-08 17:16:58 +0100 | [diff] [blame] | 148 | #endif |