blob: 1e60e0e0686f4ab58b885f1a1a8d5f0688dd23cf [file] [log] [blame]
J-Alvesd1aae292020-10-08 17:16:58 +01001/*
J-Alves32ccd2b2021-12-14 14:59:51 +00002 * Copyright (c) 2021-2022, 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
J-Alvesd1aae292020-10-08 17:16:58 +010010#include <ffa_helpers.h>
Manish Pandey9ee6a8d2021-03-03 09:53:33 +000011#include <spm_common.h>
J-Alvesd1aae292020-10-08 17:16:58 +010012
13/**
14 * Success and error return to be sent over a msg response.
15 */
J-Alves0e1e7ca2021-01-25 14:11:06 +000016#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-Alves4cb9dee2021-03-03 13:59:52 +000025#define CACTUS_ERROR_UNHANDLED U(4)
J-Alvesd1aae292020-10-08 17:16:58 +010026
27/**
Daniel Boulbyce386b12022-03-29 18:36:36 +010028 * Get command from struct ffa_value.
J-Alvesd1aae292020-10-08 17:16:58 +010029 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010030static inline uint64_t cactus_get_cmd(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +000031{
Daniel Boulbyce386b12022-03-29 18:36:36 +010032 return (uint64_t)ret.arg3;
J-Alves53392012020-11-18 14:51:57 +000033}
J-Alvesd1aae292020-10-08 17:16:58 +010034
35/**
36 * Template for commands to be sent to CACTUS partitions over direct
37 * messages interfaces.
38 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010039static inline struct ffa_value cactus_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +000040 ffa_id_t source, ffa_id_t dest, uint64_t cmd, uint64_t val0,
J-Alves53392012020-11-18 14:51:57 +000041 uint64_t val1, uint64_t val2, uint64_t val3)
42{
J-Alvesecd30742021-02-19 18:31:06 +000043 return ffa_msg_send_direct_req64(source, dest, cmd, val0, val1, val2,
44 val3);
J-Alves53392012020-11-18 14:51:57 +000045}
J-Alvesd1aae292020-10-08 17:16:58 +010046
J-Alves7d28b332021-02-11 16:08:08 +000047/**
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 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010052static inline struct ffa_value cactus_send_response(
J-Alves7a595282021-03-29 15:11:11 +010053 ffa_id_t source, ffa_id_t dest, uint32_t resp, uint64_t val0,
J-Alves7d28b332021-02-11 16:08:08 +000054 uint64_t val1, uint64_t val2, uint64_t val3)
55{
J-Alvesecd30742021-02-19 18:31:06 +000056 return ffa_msg_send_direct_resp64(source, dest, resp, val0, val1,
57 val2, val3);
J-Alves7d28b332021-02-11 16:08:08 +000058}
59
60/**
61 * For responses of one value only.
62 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010063static inline struct ffa_value cactus_response(
Daniel Boulbye79d2072021-03-03 11:34:53 +000064 ffa_id_t source, ffa_id_t dest, uint32_t response)
J-Alves7d28b332021-02-11 16:08:08 +000065{
Madhukar Pappireddy3c287262021-08-05 14:39:24 -050066 return cactus_send_response(source, dest, response, 0, 0, 0, 0);
J-Alves7d28b332021-02-11 16:08:08 +000067}
68
Daniel Boulbyce386b12022-03-29 18:36:36 +010069static inline uint32_t cactus_get_response(struct ffa_value ret)
J-Alves7d28b332021-02-11 16:08:08 +000070{
Daniel Boulbyce386b12022-03-29 18:36:36 +010071 return (uint32_t)ret.arg3;
J-Alves7d28b332021-02-11 16:08:08 +000072}
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 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010080static inline struct ffa_value cactus_success_resp(
Daniel Boulbye79d2072021-03-03 11:34:53 +000081 ffa_id_t source, ffa_id_t dest, uint64_t value)
J-Alves7d28b332021-02-11 16:08:08 +000082{
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 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010092static inline struct ffa_value cactus_error_resp(
Daniel Boulbye79d2072021-03-03 11:34:53 +000093 ffa_id_t source, ffa_id_t dest, uint32_t error_code)
J-Alves7d28b332021-02-11 16:08:08 +000094{
95 return cactus_send_response(source, dest, CACTUS_ERROR, error_code,
96 0, 0, 0);
97}
98
Daniel Boulbyce386b12022-03-29 18:36:36 +010099static inline uint32_t cactus_error_code(struct ffa_value ret)
J-Alves7d28b332021-02-11 16:08:08 +0000100{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100101 return (uint32_t) ret.arg4;
J-Alves7d28b332021-02-11 16:08:08 +0000102}
103
J-Alvesd1aae292020-10-08 17:16:58 +0100104/**
J-Alves28672f92020-11-09 15:34:31 +0000105 * 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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100112static inline struct ffa_value cactus_echo_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000113 ffa_id_t source, ffa_id_t dest, uint64_t echo_val)
J-Alves53392012020-11-18 14:51:57 +0000114{
115 return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0,
116 0);
117}
J-Alves28672f92020-11-09 15:34:31 +0000118
Daniel Boulbyce386b12022-03-29 18:36:36 +0100119static inline uint64_t cactus_echo_get_val(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000120{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100121 return (uint64_t)ret.arg4;
J-Alves53392012020-11-18 14:51:57 +0000122}
J-Alves28672f92020-11-09 15:34:31 +0000123
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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100133static inline struct ffa_value cactus_req_echo_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000134 ffa_id_t source, ffa_id_t dest, ffa_id_t echo_dest,
J-Alves53392012020-11-18 14:51:57 +0000135 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-Alves28672f92020-11-09 15:34:31 +0000140
Daniel Boulbyce386b12022-03-29 18:36:36 +0100141static inline ffa_id_t cactus_req_echo_get_echo_dest(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000142{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100143 return (ffa_id_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000144}
J-Alves28672f92020-11-09 15:34:31 +0000145
146/**
J-Alves1d203f12020-11-11 11:38:49 +0000147 * 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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100157static inline struct ffa_value cactus_deadlock_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000158 ffa_id_t source, ffa_id_t dest, ffa_id_t next_dest)
J-Alves53392012020-11-18 14:51:57 +0000159{
160 return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0,
161 0, 0);
162}
J-Alves1d203f12020-11-11 11:38:49 +0000163
Daniel Boulbyce386b12022-03-29 18:36:36 +0100164static inline ffa_id_t cactus_deadlock_get_next_dest(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000165{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100166 return (ffa_id_t)ret.arg4;
J-Alves53392012020-11-18 14:51:57 +0000167}
J-Alves1d203f12020-11-11 11:38:49 +0000168
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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100175static inline struct ffa_value cactus_req_deadlock_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000176 ffa_id_t source, ffa_id_t dest, ffa_id_t next_dest1,
177 ffa_id_t next_dest2)
J-Alves53392012020-11-18 14:51:57 +0000178{
179 return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD,
180 next_dest1, next_dest2, 0, 0);
181}
J-Alves1d203f12020-11-11 11:38:49 +0000182
J-Alves53392012020-11-18 14:51:57 +0000183/* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */
Daniel Boulbyce386b12022-03-29 18:36:36 +0100184static inline ffa_id_t cactus_deadlock_get_next_dest2(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000185{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100186 return (ffa_id_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000187}
J-Alves1d203f12020-11-11 11:38:49 +0000188
189/**
J-Alvesd1aae292020-10-08 17:16:58 +0100190 * Command to notify cactus of a memory management operation. The cmd value
191 * should be the memory management smc function id.
J-Alvesb9085f82020-12-07 10:57:28 +0000192 *
193 * The id is the hex representation of the string "mem"
J-Alvesd1aae292020-10-08 17:16:58 +0100194 */
J-Alvesb9085f82020-12-07 10:57:28 +0000195#define CACTUS_MEM_SEND_CMD U(0x6d656d)
J-Alvesd1aae292020-10-08 17:16:58 +0100196
Daniel Boulbyce386b12022-03-29 18:36:36 +0100197static inline struct ffa_value cactus_mem_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000198 ffa_id_t source, ffa_id_t dest, uint32_t mem_func,
J-Alves32ccd2b2021-12-14 14:59:51 +0000199 ffa_memory_handle_t handle, ffa_memory_region_flags_t retrieve_flags,
Federico Recanati6328fb02022-01-14 15:48:16 +0100200 bool non_secure, uint16_t word_to_write)
J-Alves53392012020-11-18 14:51:57 +0000201{
Federico Recanati6328fb02022-01-14 15:48:16 +0100202 /*
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-Alves53392012020-11-18 14:51:57 +0000207 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
Federico Recanati6328fb02022-01-14 15:48:16 +0100208 handle, retrieve_flags, val3);
J-Alves53392012020-11-18 14:51:57 +0000209}
J-Alvesb9085f82020-12-07 10:57:28 +0000210
Daniel Boulbyce386b12022-03-29 18:36:36 +0100211static inline ffa_memory_handle_t cactus_mem_send_get_handle(
212 struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000213{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100214 return (ffa_memory_handle_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000215}
J-Alvesd1aae292020-10-08 17:16:58 +0100216
J-Alves32ccd2b2021-12-14 14:59:51 +0000217static inline ffa_memory_region_flags_t cactus_mem_send_get_retrv_flags(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100218 struct ffa_value ret)
J-Alves32ccd2b2021-12-14 14:59:51 +0000219{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100220 return (ffa_memory_region_flags_t)ret.arg6;
J-Alves32ccd2b2021-12-14 14:59:51 +0000221}
222
Daniel Boulbyce386b12022-03-29 18:36:36 +0100223static inline uint16_t cactus_mem_send_words_to_write(struct ffa_value ret)
J-Alves32ccd2b2021-12-14 14:59:51 +0000224{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100225 return (uint16_t)ret.arg7;
Federico Recanati6328fb02022-01-14 15:48:16 +0100226}
227
Daniel Boulbyce386b12022-03-29 18:36:36 +0100228static inline bool cactus_mem_send_get_non_secure(struct ffa_value ret)
Federico Recanati6328fb02022-01-14 15:48:16 +0100229{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100230 return (bool)(ret.arg7 >> 16);
J-Alves32ccd2b2021-12-14 14:59:51 +0000231}
232
J-Alvesd1aae292020-10-08 17:16:58 +0100233/**
J-Alves542d8d82020-11-18 10:34:06 +0000234 * Command to request a memory management operation. The 'mem_func' argument
235 * identifies the operation that is to be performend, and 'receiver' is the id
236 * of the partition to receive the memory region.
237 *
238 * The command id is the hex representation of the string "memory".
239 */
240#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
241
Daniel Boulbyce386b12022-03-29 18:36:36 +0100242static inline struct ffa_value cactus_req_mem_send_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000243 ffa_id_t source, ffa_id_t dest, uint32_t mem_func,
Federico Recanati6328fb02022-01-14 15:48:16 +0100244 ffa_id_t receiver, bool non_secure)
J-Alves53392012020-11-18 14:51:57 +0000245{
246 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
Federico Recanati6328fb02022-01-14 15:48:16 +0100247 receiver, non_secure, 0);
J-Alves53392012020-11-18 14:51:57 +0000248}
J-Alves542d8d82020-11-18 10:34:06 +0000249
Daniel Boulbyce386b12022-03-29 18:36:36 +0100250static inline uint32_t cactus_req_mem_send_get_mem_func(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000251{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100252 return (uint32_t)ret.arg4;
J-Alves53392012020-11-18 14:51:57 +0000253}
254
Daniel Boulbyce386b12022-03-29 18:36:36 +0100255static inline ffa_id_t cactus_req_mem_send_get_receiver(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000256{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100257 return (ffa_id_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000258}
J-Alves542d8d82020-11-18 10:34:06 +0000259
Daniel Boulbyce386b12022-03-29 18:36:36 +0100260static inline bool cactus_req_mem_send_get_non_secure(struct ffa_value ret)
Federico Recanati6328fb02022-01-14 15:48:16 +0100261{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100262 return (bool)ret.arg6;
Federico Recanati6328fb02022-01-14 15:48:16 +0100263}
264
J-Alves542d8d82020-11-18 10:34:06 +0000265/**
Olivier Deprez881b1992020-12-01 15:34:34 +0100266 * Request to fill SIMD vectors with dummy values with purpose to check a
267 * save/restore routine during the context switches between secure world and
268 * normal world.
269 *
270 * The command id is the hex representation of the string "SIMD"
271 */
272#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
273
Daniel Boulbyce386b12022-03-29 18:36:36 +0100274static inline struct ffa_value cactus_req_simd_fill_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000275 ffa_id_t source, ffa_id_t dest)
Olivier Deprez881b1992020-12-01 15:34:34 +0100276{
J-Alves0e1e7ca2021-01-25 14:11:06 +0000277 return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0,
278 0);
Olivier Deprez881b1992020-12-01 15:34:34 +0100279}
280
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000281/**
282 * Command to request cactus to sleep for the given time in ms
283 *
284 * The command id is the hex representation of string "sleep"
285 */
286#define CACTUS_SLEEP_CMD U(0x736c656570)
287
Daniel Boulbyce386b12022-03-29 18:36:36 +0100288static inline struct ffa_value cactus_sleep_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000289 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000290{
291 return cactus_send_cmd(source, dest, CACTUS_SLEEP_CMD, sleep_time, 0, 0,
292 0);
293}
294
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500295/**
296 * Command to request cactus to forward sleep command for the given time in ms
297 *
298 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
299 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
300 */
301#define CACTUS_FWD_SLEEP_CMD (CACTUS_SLEEP_CMD + 1)
302
Daniel Boulbyce386b12022-03-29 18:36:36 +0100303static inline struct ffa_value cactus_fwd_sleep_cmd(
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500304 ffa_id_t source, ffa_id_t dest, ffa_id_t fwd_dest,
305 uint32_t sleep_time)
306{
307 return cactus_send_cmd(source, dest, CACTUS_FWD_SLEEP_CMD, sleep_time,
308 fwd_dest, 0, 0);
309}
310
Daniel Boulbyce386b12022-03-29 18:36:36 +0100311static inline uint32_t cactus_get_sleep_time(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000312{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100313 return (uint32_t)ret.arg4;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000314}
315
Daniel Boulbyce386b12022-03-29 18:36:36 +0100316static inline ffa_id_t cactus_get_fwd_sleep_dest(struct ffa_value ret)
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500317{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100318 return (ffa_id_t)ret.arg5;
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500319}
320
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000321/**
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600322 * Command to request cactus to sleep for half the given time in ms, trigger
323 * trusted watchdog timer and then sleep again for another half the given time.
324 *
325 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
326 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
327 */
328#define CACTUS_SLEEP_TRIGGER_TWDOG_CMD (CACTUS_SLEEP_CMD + 2)
329
Daniel Boulbyce386b12022-03-29 18:36:36 +0100330static inline struct ffa_value cactus_sleep_trigger_wdog_cmd(
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600331 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time,
332 uint64_t wdog_time)
333{
334 return cactus_send_cmd(source, dest, CACTUS_SLEEP_TRIGGER_TWDOG_CMD, sleep_time,
335 wdog_time, 0, 0);
336}
337
338
Daniel Boulbyce386b12022-03-29 18:36:36 +0100339static inline uint32_t cactus_get_wdog_trigger_duration(struct ffa_value ret)
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600340{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100341 return (uint32_t)ret.arg5;
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600342}
343
344/**
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000345 * Command to request cactus to enable/disable an interrupt
346 *
347 * The command id is the hex representation of string "intr"
348 */
349#define CACTUS_INTERRUPT_CMD U(0x696e7472)
350
Daniel Boulbyce386b12022-03-29 18:36:36 +0100351static inline struct ffa_value cactus_interrupt_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000352 ffa_id_t source, ffa_id_t dest, uint32_t interrupt_id,
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000353 bool enable, uint32_t pin)
354{
355 return cactus_send_cmd(source, dest, CACTUS_INTERRUPT_CMD, interrupt_id,
356 enable, pin, 0);
357}
358
Daniel Boulbyce386b12022-03-29 18:36:36 +0100359static inline uint32_t cactus_get_interrupt_id(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000360{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100361 return (uint32_t)ret.arg4;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000362}
363
Daniel Boulbyce386b12022-03-29 18:36:36 +0100364static inline bool cactus_get_interrupt_enable(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000365{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100366 return (bool)ret.arg5;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000367}
368
Daniel Boulbyce386b12022-03-29 18:36:36 +0100369static inline enum interrupt_pin cactus_get_interrupt_pin(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000370{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100371 return (enum interrupt_pin)ret.arg6;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000372}
373
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600374/**
375 * Request to initiate DMA transaction by upstream peripheral.
376 *
377 * The command id is the hex representation of the string "SMMU"
378 */
379#define CACTUS_DMA_SMMUv3_CMD (0x534d4d55)
380
Daniel Boulbyce386b12022-03-29 18:36:36 +0100381static inline struct ffa_value cactus_send_dma_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000382 ffa_id_t source, ffa_id_t dest)
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600383{
384 return cactus_send_cmd(source, dest, CACTUS_DMA_SMMUv3_CMD, 0, 0, 0,
385 0);
386}
J-Alvesb4e89a22021-03-09 10:04:39 +0000387
388/*
389 * Request SP to bind a notification to a FF-A endpoint. In case of error
390 * when using the FFA_NOTIFICATION_BIND interface, include the error code
391 * in the response to the command's request. The receiver and sender arguments
392 * are propagated through the command's arguments, to allow the test of
393 * erroneous uses of the FFA_NOTIFICATION_BIND interface.
394 *
395 * The command id is the hex representation of the string "bind".
396 */
397#define CACTUS_NOTIFICATION_BIND_CMD U(0x62696e64)
398
Daniel Boulbyce386b12022-03-29 18:36:36 +0100399static inline struct ffa_value cactus_notification_bind_send_cmd(
J-Alvesb4e89a22021-03-09 10:04:39 +0000400 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
401 ffa_id_t sender, ffa_notification_bitmap_t notifications, uint32_t flags)
402{
403 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_BIND_CMD,
404 receiver, sender, notifications, flags);
405}
406
407/**
408 * Request to SP unbind a notification. In case of error when using the
409 * FFA_NOTIFICATION_UNBIND interface, the test includes the error code in the
410 * response. The receiver and sender arguments are propagated throught the
411 * command's arguments, to allow the test of erroneous uses of the
412 * FFA_NOTIFICATION_BIND interface.
413 *
414 * The command id is the hex representation of the string "unbind".
415 */
416#define CACTUS_NOTIFICATION_UNBIND_CMD U(0x756e62696e64)
417
Daniel Boulbyce386b12022-03-29 18:36:36 +0100418static inline struct ffa_value cactus_notification_unbind_send_cmd(
J-Alvesb4e89a22021-03-09 10:04:39 +0000419 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
420 ffa_id_t sender, ffa_notification_bitmap_t notifications)
421{
422 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_UNBIND_CMD,
423 receiver, sender, notifications, 0);
424}
425
Daniel Boulbyce386b12022-03-29 18:36:36 +0100426static inline ffa_id_t cactus_notification_get_receiver(struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000427{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100428 return (ffa_id_t)ret.arg4;
J-Alvesb4e89a22021-03-09 10:04:39 +0000429}
430
Daniel Boulbyce386b12022-03-29 18:36:36 +0100431static inline ffa_id_t cactus_notification_get_sender(struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000432{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100433 return (ffa_id_t)ret.arg5;
J-Alvesb4e89a22021-03-09 10:04:39 +0000434}
435
436static inline ffa_notification_bitmap_t cactus_notification_get_notifications(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100437 struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000438{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100439 return (uint64_t)ret.arg6;
J-Alvesb4e89a22021-03-09 10:04:39 +0000440}
441
J-Alvesab775912021-03-29 15:22:33 +0100442/**
443 * Request SP to get notifications. The arguments to use in ffa_notification_get
444 * are propagated on the command to test erroneous uses of the interface.
445 * In a successful call to the interface, the SP's response payload should
446 * include all bitmaps returned by the SPMC.
447 *
448 * The command id is the hex representation of the string "getnot".
449 */
450#define CACTUS_NOTIFICATION_GET_CMD U(0x6765746e6f74)
451
Daniel Boulbyce386b12022-03-29 18:36:36 +0100452static inline struct ffa_value cactus_notification_get_send_cmd(
J-Alvesab775912021-03-29 15:22:33 +0100453 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
J-Alvesa076d4c2021-10-19 16:06:15 +0100454 uint32_t vcpu_id, uint32_t flags, bool check_npi_handled)
J-Alvesab775912021-03-29 15:22:33 +0100455{
456 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_GET_CMD,
J-Alvesa076d4c2021-10-19 16:06:15 +0100457 receiver, vcpu_id, check_npi_handled, flags);
J-Alvesab775912021-03-29 15:22:33 +0100458}
459
Daniel Boulbyce386b12022-03-29 18:36:36 +0100460static inline uint32_t cactus_notification_get_vcpu(struct ffa_value ret)
J-Alvesab775912021-03-29 15:22:33 +0100461{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100462 return (uint32_t)ret.arg5;
J-Alvesab775912021-03-29 15:22:33 +0100463}
464
Daniel Boulbyce386b12022-03-29 18:36:36 +0100465static inline uint32_t cactus_notification_get_flags(struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000466{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100467 return (uint32_t)ret.arg7;
J-Alvesb4e89a22021-03-09 10:04:39 +0000468}
469
Daniel Boulbyce386b12022-03-29 18:36:36 +0100470static inline struct ffa_value cactus_notifications_get_success_resp(
J-Alvesab775912021-03-29 15:22:33 +0100471 ffa_id_t source, ffa_id_t dest, uint64_t from_sp,
472 uint64_t from_vm)
473{
474 return cactus_send_response(source, dest, CACTUS_SUCCESS, from_sp,
475 from_vm, 0, 0);
476}
477
Daniel Boulbyce386b12022-03-29 18:36:36 +0100478static inline uint64_t cactus_notifications_get_from_sp(struct ffa_value ret)
J-Alvesab775912021-03-29 15:22:33 +0100479{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100480 return (uint64_t)ret.arg4;
J-Alvesab775912021-03-29 15:22:33 +0100481}
482
Daniel Boulbyce386b12022-03-29 18:36:36 +0100483static inline uint64_t cactus_notifications_get_from_vm(struct ffa_value ret)
J-Alvesab775912021-03-29 15:22:33 +0100484{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100485 return (uint64_t)ret.arg5;
J-Alvesab775912021-03-29 15:22:33 +0100486}
487
Daniel Boulbyce386b12022-03-29 18:36:36 +0100488static inline bool cactus_notifications_check_npi_handled(struct ffa_value ret)
J-Alvesa076d4c2021-10-19 16:06:15 +0100489{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100490 return (bool)ret.arg6;
J-Alvesa076d4c2021-10-19 16:06:15 +0100491}
492
J-Alvesab775912021-03-29 15:22:33 +0100493/**
494 * Request SP to set notifications. The arguments to use in ffa_notification_set
495 * are propagated on the command to test erroneous uses of the interface.
496 * In case of error while calling the interface, the response should include the
J-Alvesfbbbf622021-07-30 16:43:36 +0100497 * error code. If in the flags a delay SRI is requested, cactus should
498 * send a CACTUS_ECHO_CMD to the SP specified as `echo_dest`. This should help
499 * validate that the SRI is only sent when returning execution to the NWd.
J-Alvesab775912021-03-29 15:22:33 +0100500 */
501#define CACTUS_NOTIFICATIONS_SET_CMD U(0x6e6f74736574)
502
Daniel Boulbyce386b12022-03-29 18:36:36 +0100503static inline struct ffa_value cactus_notifications_set_send_cmd(
J-Alvesab775912021-03-29 15:22:33 +0100504 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
J-Alvesfbbbf622021-07-30 16:43:36 +0100505 ffa_id_t sender, uint32_t flags, ffa_notification_bitmap_t notifications,
506 ffa_id_t echo_dest)
J-Alvesab775912021-03-29 15:22:33 +0100507{
508 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATIONS_SET_CMD,
J-Alvesfbbbf622021-07-30 16:43:36 +0100509 (uint32_t)receiver | ((uint32_t)sender << 16),
510 echo_dest,
511 notifications, flags);
512}
513
Daniel Boulbyce386b12022-03-29 18:36:36 +0100514static inline ffa_id_t cactus_notifications_set_get_receiver(
515 struct ffa_value ret)
J-Alvesfbbbf622021-07-30 16:43:36 +0100516{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100517 return (ffa_id_t)(ret.arg4 & 0xFFFFU);
J-Alvesfbbbf622021-07-30 16:43:36 +0100518}
519
Daniel Boulbyce386b12022-03-29 18:36:36 +0100520static inline ffa_id_t cactus_notifications_set_get_sender(struct ffa_value ret)
J-Alvesfbbbf622021-07-30 16:43:36 +0100521{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100522 return (ffa_id_t)((ret.arg4 >> 16U) & 0xFFFFU);
J-Alvesab775912021-03-29 15:22:33 +0100523}
524
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500525/**
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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100532static inline struct ffa_value cactus_send_twdog_cmd(
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500533 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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100539static inline uint32_t cactus_get_wdog_duration(struct ffa_value ret)
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500540{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100541 return (uint32_t)ret.arg4;
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500542}
543
J-Alvesf7535f42021-07-30 11:58:41 +0100544/**
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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100551static inline struct ffa_value cactus_get_req_count_send_cmd(
J-Alvesf7535f42021-07-30 11:58:41 +0100552 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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100558static inline uint32_t cactus_get_req_count(struct ffa_value ret)
J-Alvesf7535f42021-07-30 11:58:41 +0100559{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100560 return (uint32_t)ret.arg4;
J-Alvesf7535f42021-07-30 11:58:41 +0100561}
562
Madhukar Pappireddyf4c8e8d2022-02-15 15:52:53 -0600563/**
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
Daniel Boulbyce386b12022-03-29 18:36:36 +0100570static inline struct ffa_value cactus_get_last_interrupt_cmd(
Madhukar Pappireddyf4c8e8d2022-02-15 15:52:53 -0600571 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-Alvesd1aae292020-10-08 17:16:58 +0100576#endif