blob: f814ba560837ca748590deb957340836d53bd1bc [file] [log] [blame]
J-Alvesd1aae292020-10-08 17:16:58 +01001/*
J-Alves7d28b332021-02-11 16:08:08 +00002 * Copyright (c) 2021, Arm Limited. All rights reserved.
J-Alvesd1aae292020-10-08 17:16:58 +01003 *
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-Alves9b28d062020-11-30 11:42:49 +000016#define CACTUS_SUCCESS U(0)
17#define CACTUS_ERROR U(-1)
J-Alvesd1aae292020-10-08 17:16:58 +010018
19/**
20 * Get command from struct smc_ret_values.
21 */
J-Alves53392012020-11-18 14:51:57 +000022static inline uint64_t cactus_get_cmd(smc_ret_values ret)
23{
24 return (uint64_t)ret.ret3;
25}
J-Alvesd1aae292020-10-08 17:16:58 +010026
27/**
28 * Template for commands to be sent to CACTUS partitions over direct
29 * messages interfaces.
30 */
J-Alves53392012020-11-18 14:51:57 +000031static 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-Alvesd1aae292020-10-08 17:16:58 +010038
J-Alves7d28b332021-02-11 16:08:08 +000039/**
40 * Template for responses to Cactus commands.
41 * 'cactus_send_response' is the template for custom responses, in case there is
42 * a need to propagate more than one value in the response of a command.
43 */
44static inline smc_ret_values cactus_send_response(
45 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t resp, uint32_t val0,
46 uint64_t val1, uint64_t val2, uint64_t val3)
47{
48 return ffa_msg_send_direct_resp64_5args(source, dest, resp, val0, val1,
49 val2, val3);
50}
51
52/**
53 * For responses of one value only.
54 */
55static inline smc_ret_values cactus_response(
56 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response)
57{
58 return ffa_msg_send_direct_resp(source, dest, response);
59}
60
61static inline uint32_t cactus_get_response(smc_ret_values ret)
62{
63 return (uint32_t)ret.ret3;
64}
65
66/**
67 * In a successful test, in case the SP needs to propagate an extra value
68 * to conclude the test.
69 * If more arguments are needed, a custom response should be defined for the
70 * specific test.
71 */
72static inline smc_ret_values cactus_success_resp(
73 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t value)
74{
75 return cactus_send_response(source, dest, CACTUS_SUCCESS, value,
76 0, 0, 0);
77}
78
79/**
80 * In case the test fails on the SP side, the 'error_code' should help specify
81 * the reason, which can be specific to the test, or general ones as defined
82 * in the error code list.
83 */
84static inline smc_ret_values cactus_error_resp(
85 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t error_code)
86{
87 return cactus_send_response(source, dest, CACTUS_ERROR, error_code,
88 0, 0, 0);
89}
90
91static inline uint32_t cactus_error_code(smc_ret_values ret)
92{
93 return (uint32_t) ret.ret4;
94}
95
J-Alvesd1aae292020-10-08 17:16:58 +010096#define PRINT_CMD(smc_ret) \
97 VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \
98 smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \
99 smc_ret.ret6, smc_ret.ret7)
100
101/**
J-Alves28672f92020-11-09 15:34:31 +0000102 * With this test command the sender transmits a 64-bit value that it then
103 * expects to receive on the respective command response.
104 *
105 * The id is the hex representation of the string 'echo'.
106 */
107#define CACTUS_ECHO_CMD U(0x6563686f)
108
J-Alves53392012020-11-18 14:51:57 +0000109static inline smc_ret_values cactus_echo_send_cmd(
110 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val)
111{
112 return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0,
113 0);
114}
J-Alves28672f92020-11-09 15:34:31 +0000115
J-Alves53392012020-11-18 14:51:57 +0000116static inline uint64_t cactus_echo_get_val(smc_ret_values ret)
117{
118 return (uint64_t)ret.ret4;
119}
J-Alves28672f92020-11-09 15:34:31 +0000120
121/**
122 * Command to request a cactus secure partition to send an echo command to
123 * another partition.
124 *
125 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
126 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
127 */
128#define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1)
129
J-Alves53392012020-11-18 14:51:57 +0000130static inline smc_ret_values cactus_req_echo_send_cmd(
131 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest,
132 uint64_t echo_val)
133{
134 return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val,
135 echo_dest, 0, 0);
136}
J-Alves28672f92020-11-09 15:34:31 +0000137
J-Alves53392012020-11-18 14:51:57 +0000138static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret)
139{
140 return (ffa_vm_id_t)ret.ret5;
141}
J-Alves28672f92020-11-09 15:34:31 +0000142
143/**
J-Alves1d203f12020-11-11 11:38:49 +0000144 * Command to create a cyclic dependency between SPs, which could result in
145 * a deadlock. This aims at proving such scenario cannot happen.
146 * If the deadlock happens, the system will just hang.
147 * If the deadlock is prevented, the last partition to use the command will
148 * send response CACTUS_SUCCESS.
149 *
150 * The id is the hex representation of the string 'dead'.
151 */
152#define CACTUS_DEADLOCK_CMD U(0x64656164)
153
J-Alves53392012020-11-18 14:51:57 +0000154static inline smc_ret_values cactus_deadlock_send_cmd(
155 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest)
156{
157 return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0,
158 0, 0);
159}
J-Alves1d203f12020-11-11 11:38:49 +0000160
J-Alves53392012020-11-18 14:51:57 +0000161static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret)
162{
163 return (ffa_vm_id_t)ret.ret4;
164}
J-Alves1d203f12020-11-11 11:38:49 +0000165
166/**
167 * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions
168 * of specified IDs.
169 */
170#define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1)
171
J-Alves53392012020-11-18 14:51:57 +0000172static inline smc_ret_values cactus_req_deadlock_send_cmd(
173 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1,
174 ffa_vm_id_t next_dest2)
175{
176 return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD,
177 next_dest1, next_dest2, 0, 0);
178}
J-Alves1d203f12020-11-11 11:38:49 +0000179
J-Alves53392012020-11-18 14:51:57 +0000180/* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */
181static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret)
182{
183 return (ffa_vm_id_t)ret.ret5;
184}
J-Alves1d203f12020-11-11 11:38:49 +0000185
186/**
J-Alvesd1aae292020-10-08 17:16:58 +0100187 * Command to notify cactus of a memory management operation. The cmd value
188 * should be the memory management smc function id.
J-Alvesb9085f82020-12-07 10:57:28 +0000189 *
190 * The id is the hex representation of the string "mem"
J-Alvesd1aae292020-10-08 17:16:58 +0100191 */
J-Alvesb9085f82020-12-07 10:57:28 +0000192#define CACTUS_MEM_SEND_CMD U(0x6d656d)
J-Alvesd1aae292020-10-08 17:16:58 +0100193
J-Alves53392012020-11-18 14:51:57 +0000194static inline smc_ret_values cactus_mem_send_cmd(
195 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
196 ffa_memory_handle_t handle)
197{
198 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
199 handle, 0, 0);
200}
J-Alvesb9085f82020-12-07 10:57:28 +0000201
J-Alves53392012020-11-18 14:51:57 +0000202static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret)
203{
204 return (ffa_memory_handle_t)ret.ret5;
205}
J-Alvesd1aae292020-10-08 17:16:58 +0100206
207/**
J-Alves542d8d82020-11-18 10:34:06 +0000208 * Command to request a memory management operation. The 'mem_func' argument
209 * identifies the operation that is to be performend, and 'receiver' is the id
210 * of the partition to receive the memory region.
211 *
212 * The command id is the hex representation of the string "memory".
213 */
214#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
215
J-Alves53392012020-11-18 14:51:57 +0000216static inline smc_ret_values cactus_req_mem_send_send_cmd(
217 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
218 ffa_vm_id_t receiver)
219{
220 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
221 receiver, 0, 0);
222}
J-Alves542d8d82020-11-18 10:34:06 +0000223
J-Alves53392012020-11-18 14:51:57 +0000224static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret)
225{
226 return (uint32_t)ret.ret4;
227}
228
229static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret)
230{
231 return (ffa_vm_id_t)ret.ret5;
232}
J-Alves542d8d82020-11-18 10:34:06 +0000233
234/**
Olivier Deprez881b1992020-12-01 15:34:34 +0100235 * Request to fill SIMD vectors with dummy values with purpose to check a
236 * save/restore routine during the context switches between secure world and
237 * normal world.
238 *
239 * The command id is the hex representation of the string "SIMD"
240 */
241#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
242
243static inline smc_ret_values cactus_req_simd_fill_send_cmd(
244 ffa_vm_id_t source, ffa_vm_id_t dest)
245{
246 return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0, 0);
247}
248
J-Alvesd1aae292020-10-08 17:16:58 +0100249#endif