blob: 3938c2fce2c9fd811da16719fd544875b0715456 [file] [log] [blame]
J-Alvesd1aae292020-10-08 17:16:58 +01001/*
Madhukar Pappireddyd655d582024-01-16 14:45:39 -06002 * Copyright (c) 2021-2024, 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
Madhukar Pappireddy4d76de02022-06-22 17:38:21 -050027#define ECHO_VAL1 U(0xa0a0a0a0)
28#define ECHO_VAL2 U(0xb0b0b0b0)
29#define ECHO_VAL3 U(0xc0c0c0c0)
30
J-Alvesd1aae292020-10-08 17:16:58 +010031/**
Daniel Boulbyce386b12022-03-29 18:36:36 +010032 * Get command from struct ffa_value.
J-Alvesd1aae292020-10-08 17:16:58 +010033 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010034static inline uint64_t cactus_get_cmd(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +000035{
Daniel Boulbyce386b12022-03-29 18:36:36 +010036 return (uint64_t)ret.arg3;
J-Alves53392012020-11-18 14:51:57 +000037}
J-Alvesd1aae292020-10-08 17:16:58 +010038
39/**
40 * Template for commands to be sent to CACTUS partitions over direct
41 * messages interfaces.
42 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010043static inline struct ffa_value cactus_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +000044 ffa_id_t source, ffa_id_t dest, uint64_t cmd, uint64_t val0,
J-Alves53392012020-11-18 14:51:57 +000045 uint64_t val1, uint64_t val2, uint64_t val3)
46{
J-Alvesecd30742021-02-19 18:31:06 +000047 return ffa_msg_send_direct_req64(source, dest, cmd, val0, val1, val2,
48 val3);
J-Alves53392012020-11-18 14:51:57 +000049}
J-Alvesd1aae292020-10-08 17:16:58 +010050
J-Alves7d28b332021-02-11 16:08:08 +000051/**
52 * Template for responses to Cactus commands.
53 * 'cactus_send_response' is the template for custom responses, in case there is
54 * a need to propagate more than one value in the response of a command.
55 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010056static inline struct ffa_value cactus_send_response(
J-Alves7a595282021-03-29 15:11:11 +010057 ffa_id_t source, ffa_id_t dest, uint32_t resp, uint64_t val0,
J-Alves7d28b332021-02-11 16:08:08 +000058 uint64_t val1, uint64_t val2, uint64_t val3)
59{
J-Alvesecd30742021-02-19 18:31:06 +000060 return ffa_msg_send_direct_resp64(source, dest, resp, val0, val1,
61 val2, val3);
J-Alves7d28b332021-02-11 16:08:08 +000062}
63
64/**
65 * For responses of one value only.
66 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010067static inline struct ffa_value cactus_response(
Daniel Boulbye79d2072021-03-03 11:34:53 +000068 ffa_id_t source, ffa_id_t dest, uint32_t response)
J-Alves7d28b332021-02-11 16:08:08 +000069{
Madhukar Pappireddy3c287262021-08-05 14:39:24 -050070 return cactus_send_response(source, dest, response, 0, 0, 0, 0);
J-Alves7d28b332021-02-11 16:08:08 +000071}
72
Daniel Boulbyce386b12022-03-29 18:36:36 +010073static inline uint32_t cactus_get_response(struct ffa_value ret)
J-Alves7d28b332021-02-11 16:08:08 +000074{
Daniel Boulbyce386b12022-03-29 18:36:36 +010075 return (uint32_t)ret.arg3;
J-Alves7d28b332021-02-11 16:08:08 +000076}
77
78/**
79 * In a successful test, in case the SP needs to propagate an extra value
80 * to conclude the test.
81 * If more arguments are needed, a custom response should be defined for the
82 * specific test.
83 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010084static inline struct ffa_value cactus_success_resp(
Daniel Boulbye79d2072021-03-03 11:34:53 +000085 ffa_id_t source, ffa_id_t dest, uint64_t value)
J-Alves7d28b332021-02-11 16:08:08 +000086{
87 return cactus_send_response(source, dest, CACTUS_SUCCESS, value,
88 0, 0, 0);
89}
90
91/**
92 * In case the test fails on the SP side, the 'error_code' should help specify
93 * the reason, which can be specific to the test, or general ones as defined
94 * in the error code list.
95 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010096static inline struct ffa_value cactus_error_resp(
Daniel Boulbye79d2072021-03-03 11:34:53 +000097 ffa_id_t source, ffa_id_t dest, uint32_t error_code)
J-Alves7d28b332021-02-11 16:08:08 +000098{
99 return cactus_send_response(source, dest, CACTUS_ERROR, error_code,
100 0, 0, 0);
101}
102
Daniel Boulbyce386b12022-03-29 18:36:36 +0100103static inline uint32_t cactus_error_code(struct ffa_value ret)
J-Alves7d28b332021-02-11 16:08:08 +0000104{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100105 return (uint32_t) ret.arg4;
J-Alves7d28b332021-02-11 16:08:08 +0000106}
107
J-Alvesd1aae292020-10-08 17:16:58 +0100108/**
J-Alves28672f92020-11-09 15:34:31 +0000109 * With this test command the sender transmits a 64-bit value that it then
110 * expects to receive on the respective command response.
111 *
112 * The id is the hex representation of the string 'echo'.
113 */
114#define CACTUS_ECHO_CMD U(0x6563686f)
115
Daniel Boulbyce386b12022-03-29 18:36:36 +0100116static inline struct ffa_value cactus_echo_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000117 ffa_id_t source, ffa_id_t dest, uint64_t echo_val)
J-Alves53392012020-11-18 14:51:57 +0000118{
119 return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0,
120 0);
121}
J-Alves28672f92020-11-09 15:34:31 +0000122
Daniel Boulbyce386b12022-03-29 18:36:36 +0100123static inline uint64_t cactus_echo_get_val(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000124{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100125 return (uint64_t)ret.arg4;
J-Alves53392012020-11-18 14:51:57 +0000126}
J-Alves28672f92020-11-09 15:34:31 +0000127
128/**
129 * Command to request a cactus secure partition to send an echo command to
130 * another partition.
131 *
132 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
133 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
134 */
135#define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1)
136
Daniel Boulbyce386b12022-03-29 18:36:36 +0100137static inline struct ffa_value cactus_req_echo_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000138 ffa_id_t source, ffa_id_t dest, ffa_id_t echo_dest,
J-Alves53392012020-11-18 14:51:57 +0000139 uint64_t echo_val)
140{
141 return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val,
142 echo_dest, 0, 0);
143}
J-Alves28672f92020-11-09 15:34:31 +0000144
Daniel Boulbyce386b12022-03-29 18:36:36 +0100145static inline ffa_id_t cactus_req_echo_get_echo_dest(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000146{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100147 return (ffa_id_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000148}
J-Alves28672f92020-11-09 15:34:31 +0000149
150/**
J-Alves1d203f12020-11-11 11:38:49 +0000151 * Command to create a cyclic dependency between SPs, which could result in
152 * a deadlock. This aims at proving such scenario cannot happen.
153 * If the deadlock happens, the system will just hang.
154 * If the deadlock is prevented, the last partition to use the command will
155 * send response CACTUS_SUCCESS.
156 *
157 * The id is the hex representation of the string 'dead'.
158 */
159#define CACTUS_DEADLOCK_CMD U(0x64656164)
160
Daniel Boulbyce386b12022-03-29 18:36:36 +0100161static inline struct ffa_value cactus_deadlock_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000162 ffa_id_t source, ffa_id_t dest, ffa_id_t next_dest)
J-Alves53392012020-11-18 14:51:57 +0000163{
164 return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0,
165 0, 0);
166}
J-Alves1d203f12020-11-11 11:38:49 +0000167
Daniel Boulbyce386b12022-03-29 18:36:36 +0100168static inline ffa_id_t cactus_deadlock_get_next_dest(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000169{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100170 return (ffa_id_t)ret.arg4;
J-Alves53392012020-11-18 14:51:57 +0000171}
J-Alves1d203f12020-11-11 11:38:49 +0000172
173/**
174 * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions
175 * of specified IDs.
176 */
177#define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1)
178
Daniel Boulbyce386b12022-03-29 18:36:36 +0100179static inline struct ffa_value cactus_req_deadlock_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000180 ffa_id_t source, ffa_id_t dest, ffa_id_t next_dest1,
181 ffa_id_t next_dest2)
J-Alves53392012020-11-18 14:51:57 +0000182{
183 return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD,
184 next_dest1, next_dest2, 0, 0);
185}
J-Alves1d203f12020-11-11 11:38:49 +0000186
J-Alves53392012020-11-18 14:51:57 +0000187/* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */
Daniel Boulbyce386b12022-03-29 18:36:36 +0100188static inline ffa_id_t cactus_deadlock_get_next_dest2(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000189{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100190 return (ffa_id_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000191}
J-Alves1d203f12020-11-11 11:38:49 +0000192
193/**
J-Alvesd1aae292020-10-08 17:16:58 +0100194 * Command to notify cactus of a memory management operation. The cmd value
195 * should be the memory management smc function id.
J-Alvesb9085f82020-12-07 10:57:28 +0000196 *
197 * The id is the hex representation of the string "mem"
J-Alvesd1aae292020-10-08 17:16:58 +0100198 */
J-Alvesb9085f82020-12-07 10:57:28 +0000199#define CACTUS_MEM_SEND_CMD U(0x6d656d)
J-Alvesd1aae292020-10-08 17:16:58 +0100200
Daniel Boulbyce386b12022-03-29 18:36:36 +0100201static inline struct ffa_value cactus_mem_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000202 ffa_id_t source, ffa_id_t dest, uint32_t mem_func,
J-Alves32ccd2b2021-12-14 14:59:51 +0000203 ffa_memory_handle_t handle, ffa_memory_region_flags_t retrieve_flags,
J-Alvese742ba82024-01-11 10:38:29 +0000204 uint16_t word_to_write, bool expect_exception)
J-Alves53392012020-11-18 14:51:57 +0000205{
J-Alvese742ba82024-01-11 10:38:29 +0000206 uint64_t _expect_exception = expect_exception ? (1ULL << 32) : 0;
207 uint64_t packed = (uint64_t)word_to_write | _expect_exception;
208
J-Alves53392012020-11-18 14:51:57 +0000209 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
J-Alvese742ba82024-01-11 10:38:29 +0000210 handle, retrieve_flags, packed);
J-Alves53392012020-11-18 14:51:57 +0000211}
J-Alvesb9085f82020-12-07 10:57:28 +0000212
Daniel Boulbyce386b12022-03-29 18:36:36 +0100213static inline ffa_memory_handle_t cactus_mem_send_get_handle(
214 struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000215{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100216 return (ffa_memory_handle_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000217}
J-Alvesd1aae292020-10-08 17:16:58 +0100218
J-Alves32ccd2b2021-12-14 14:59:51 +0000219static inline ffa_memory_region_flags_t cactus_mem_send_get_retrv_flags(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100220 struct ffa_value ret)
J-Alves32ccd2b2021-12-14 14:59:51 +0000221{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100222 return (ffa_memory_region_flags_t)ret.arg6;
J-Alves32ccd2b2021-12-14 14:59:51 +0000223}
224
Daniel Boulbyce386b12022-03-29 18:36:36 +0100225static inline uint16_t cactus_mem_send_words_to_write(struct ffa_value ret)
J-Alves32ccd2b2021-12-14 14:59:51 +0000226{
J-Alvese742ba82024-01-11 10:38:29 +0000227 return (uint16_t)ret.arg7 & 0xFFFFU;
228}
229
230static inline bool cactus_mem_send_expect_exception(struct ffa_value ret)
231{
232 return (bool)(ret.arg7 >> 32);
Federico Recanati6328fb02022-01-14 15:48:16 +0100233}
234
J-Alvesd1aae292020-10-08 17:16:58 +0100235/**
J-Alves542d8d82020-11-18 10:34:06 +0000236 * Command to request a memory management operation. The 'mem_func' argument
237 * identifies the operation that is to be performend, and 'receiver' is the id
238 * of the partition to receive the memory region.
239 *
240 * The command id is the hex representation of the string "memory".
241 */
242#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
243
Daniel Boulbyce386b12022-03-29 18:36:36 +0100244static inline struct ffa_value cactus_req_mem_send_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000245 ffa_id_t source, ffa_id_t dest, uint32_t mem_func,
Federico Recanati6328fb02022-01-14 15:48:16 +0100246 ffa_id_t receiver, bool non_secure)
J-Alves53392012020-11-18 14:51:57 +0000247{
248 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
Federico Recanati6328fb02022-01-14 15:48:16 +0100249 receiver, non_secure, 0);
J-Alves53392012020-11-18 14:51:57 +0000250}
J-Alves542d8d82020-11-18 10:34:06 +0000251
Daniel Boulbyce386b12022-03-29 18:36:36 +0100252static inline uint32_t cactus_req_mem_send_get_mem_func(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000253{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100254 return (uint32_t)ret.arg4;
J-Alves53392012020-11-18 14:51:57 +0000255}
256
Daniel Boulbyce386b12022-03-29 18:36:36 +0100257static inline ffa_id_t cactus_req_mem_send_get_receiver(struct ffa_value ret)
J-Alves53392012020-11-18 14:51:57 +0000258{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100259 return (ffa_id_t)ret.arg5;
J-Alves53392012020-11-18 14:51:57 +0000260}
J-Alves542d8d82020-11-18 10:34:06 +0000261
Daniel Boulbyce386b12022-03-29 18:36:36 +0100262static inline bool cactus_req_mem_send_get_non_secure(struct ffa_value ret)
Federico Recanati6328fb02022-01-14 15:48:16 +0100263{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100264 return (bool)ret.arg6;
Federico Recanati6328fb02022-01-14 15:48:16 +0100265}
266
J-Alves542d8d82020-11-18 10:34:06 +0000267/**
Olivier Deprez881b1992020-12-01 15:34:34 +0100268 * Request to fill SIMD vectors with dummy values with purpose to check a
269 * save/restore routine during the context switches between secure world and
270 * normal world.
271 *
272 * The command id is the hex representation of the string "SIMD"
273 */
274#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
275
Daniel Boulbyce386b12022-03-29 18:36:36 +0100276static inline struct ffa_value cactus_req_simd_fill_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000277 ffa_id_t source, ffa_id_t dest)
Olivier Deprez881b1992020-12-01 15:34:34 +0100278{
J-Alves0e1e7ca2021-01-25 14:11:06 +0000279 return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0,
280 0);
Olivier Deprez881b1992020-12-01 15:34:34 +0100281}
282
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000283/**
Shruti Gupta38133fa2023-04-19 17:00:38 +0100284 * Request to compare FPU state(SIMD vectors, FPCR, FPSR) content
285 * with previous template values to check a save/restore routine during the
286 * context switches between secure world and normal world.
287 */
288#define CACTUS_CMP_SIMD_VALUE_CMD (CACTUS_REQ_SIMD_FILL_CMD + 1)
289
290static inline struct ffa_value cactus_req_simd_compare_send_cmd(
291 ffa_id_t source, ffa_id_t dest)
292{
293 return cactus_send_cmd(source, dest, CACTUS_CMP_SIMD_VALUE_CMD, 0, 0, 0,
294 0);
295}
296
297/**
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000298 * Command to request cactus to sleep for the given time in ms
299 *
300 * The command id is the hex representation of string "sleep"
301 */
302#define CACTUS_SLEEP_CMD U(0x736c656570)
303
Daniel Boulbyce386b12022-03-29 18:36:36 +0100304static inline struct ffa_value cactus_sleep_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000305 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000306{
307 return cactus_send_cmd(source, dest, CACTUS_SLEEP_CMD, sleep_time, 0, 0,
308 0);
309}
310
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500311/**
312 * Command to request cactus to forward sleep command for the given time in ms
313 *
314 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
315 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
Madhukar Pappireddy4b293412022-09-12 11:39:20 -0500316 * Moreover, the sender can send a hint to the destination SP to expect that
317 * the forwaded sleep command could be preempted by a non-secure interrupt.
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500318 */
319#define CACTUS_FWD_SLEEP_CMD (CACTUS_SLEEP_CMD + 1)
320
Daniel Boulbyce386b12022-03-29 18:36:36 +0100321static inline struct ffa_value cactus_fwd_sleep_cmd(
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500322 ffa_id_t source, ffa_id_t dest, ffa_id_t fwd_dest,
Madhukar Pappireddy4b293412022-09-12 11:39:20 -0500323 uint32_t sleep_time, bool hint_interrupted)
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500324{
325 return cactus_send_cmd(source, dest, CACTUS_FWD_SLEEP_CMD, sleep_time,
Madhukar Pappireddy4b293412022-09-12 11:39:20 -0500326 fwd_dest, hint_interrupted, 0);
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500327}
328
Daniel Boulbyce386b12022-03-29 18:36:36 +0100329static inline uint32_t cactus_get_sleep_time(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000330{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100331 return (uint32_t)ret.arg4;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000332}
333
Daniel Boulbyce386b12022-03-29 18:36:36 +0100334static inline ffa_id_t cactus_get_fwd_sleep_dest(struct ffa_value ret)
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500335{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100336 return (ffa_id_t)ret.arg5;
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500337}
338
Madhukar Pappireddy4b293412022-09-12 11:39:20 -0500339static inline bool cactus_get_fwd_sleep_interrupted_hint(struct ffa_value ret)
340{
341 return (bool)ret.arg6;
342}
343
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000344/**
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600345 * Command to request cactus to sleep for half the given time in ms, trigger
346 * trusted watchdog timer and then sleep again for another half the given time.
347 *
348 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
349 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
350 */
351#define CACTUS_SLEEP_TRIGGER_TWDOG_CMD (CACTUS_SLEEP_CMD + 2)
352
Daniel Boulbyce386b12022-03-29 18:36:36 +0100353static inline struct ffa_value cactus_sleep_trigger_wdog_cmd(
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600354 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time,
355 uint64_t wdog_time)
356{
357 return cactus_send_cmd(source, dest, CACTUS_SLEEP_TRIGGER_TWDOG_CMD, sleep_time,
358 wdog_time, 0, 0);
359}
360
361
Daniel Boulbyce386b12022-03-29 18:36:36 +0100362static inline uint32_t cactus_get_wdog_trigger_duration(struct ffa_value ret)
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600363{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100364 return (uint32_t)ret.arg5;
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600365}
366
367/**
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000368 * Command to request cactus to enable/disable an interrupt
369 *
370 * The command id is the hex representation of string "intr"
371 */
372#define CACTUS_INTERRUPT_CMD U(0x696e7472)
373
Daniel Boulbyce386b12022-03-29 18:36:36 +0100374static inline struct ffa_value cactus_interrupt_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000375 ffa_id_t source, ffa_id_t dest, uint32_t interrupt_id,
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000376 bool enable, uint32_t pin)
377{
378 return cactus_send_cmd(source, dest, CACTUS_INTERRUPT_CMD, interrupt_id,
379 enable, pin, 0);
380}
381
Daniel Boulbyce386b12022-03-29 18:36:36 +0100382static inline uint32_t cactus_get_interrupt_id(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000383{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100384 return (uint32_t)ret.arg4;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000385}
386
Daniel Boulbyce386b12022-03-29 18:36:36 +0100387static inline bool cactus_get_interrupt_enable(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000388{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100389 return (bool)ret.arg5;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000390}
391
Daniel Boulbyce386b12022-03-29 18:36:36 +0100392static inline enum interrupt_pin cactus_get_interrupt_pin(struct ffa_value ret)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000393{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100394 return (enum interrupt_pin)ret.arg6;
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000395}
396
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600397/**
398 * Request to initiate DMA transaction by upstream peripheral.
399 *
400 * The command id is the hex representation of the string "SMMU"
401 */
402#define CACTUS_DMA_SMMUv3_CMD (0x534d4d55)
403
Daniel Boulbyce386b12022-03-29 18:36:36 +0100404static inline struct ffa_value cactus_send_dma_cmd(
Olivier Depreze71ec9c2022-02-28 18:57:26 +0100405 ffa_id_t source, ffa_id_t dest, uint32_t operation,
406 uintptr_t base, size_t range, uint32_t attributes)
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600407{
Olivier Depreze71ec9c2022-02-28 18:57:26 +0100408 return cactus_send_cmd(source, dest, CACTUS_DMA_SMMUv3_CMD,
409 (uint64_t)operation, (uint64_t)base,
410 (uint64_t)range, attributes);
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600411}
J-Alvesb4e89a22021-03-09 10:04:39 +0000412
413/*
414 * Request SP to bind a notification to a FF-A endpoint. In case of error
415 * when using the FFA_NOTIFICATION_BIND interface, include the error code
416 * in the response to the command's request. The receiver and sender arguments
417 * are propagated through the command's arguments, to allow the test of
418 * erroneous uses of the FFA_NOTIFICATION_BIND interface.
419 *
420 * The command id is the hex representation of the string "bind".
421 */
422#define CACTUS_NOTIFICATION_BIND_CMD U(0x62696e64)
423
Daniel Boulbyce386b12022-03-29 18:36:36 +0100424static inline struct ffa_value cactus_notification_bind_send_cmd(
J-Alvesb4e89a22021-03-09 10:04:39 +0000425 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
426 ffa_id_t sender, ffa_notification_bitmap_t notifications, uint32_t flags)
427{
428 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_BIND_CMD,
429 receiver, sender, notifications, flags);
430}
431
432/**
433 * Request to SP unbind a notification. In case of error when using the
434 * FFA_NOTIFICATION_UNBIND interface, the test includes the error code in the
435 * response. The receiver and sender arguments are propagated throught the
436 * command's arguments, to allow the test of erroneous uses of the
437 * FFA_NOTIFICATION_BIND interface.
438 *
439 * The command id is the hex representation of the string "unbind".
440 */
441#define CACTUS_NOTIFICATION_UNBIND_CMD U(0x756e62696e64)
442
Daniel Boulbyce386b12022-03-29 18:36:36 +0100443static inline struct ffa_value cactus_notification_unbind_send_cmd(
J-Alvesb4e89a22021-03-09 10:04:39 +0000444 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
445 ffa_id_t sender, ffa_notification_bitmap_t notifications)
446{
447 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_UNBIND_CMD,
448 receiver, sender, notifications, 0);
449}
450
Daniel Boulbyce386b12022-03-29 18:36:36 +0100451static inline ffa_id_t cactus_notification_get_receiver(struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000452{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100453 return (ffa_id_t)ret.arg4;
J-Alvesb4e89a22021-03-09 10:04:39 +0000454}
455
Daniel Boulbyce386b12022-03-29 18:36:36 +0100456static inline ffa_id_t cactus_notification_get_sender(struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000457{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100458 return (ffa_id_t)ret.arg5;
J-Alvesb4e89a22021-03-09 10:04:39 +0000459}
460
461static inline ffa_notification_bitmap_t cactus_notification_get_notifications(
Daniel Boulbyce386b12022-03-29 18:36:36 +0100462 struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000463{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100464 return (uint64_t)ret.arg6;
J-Alvesb4e89a22021-03-09 10:04:39 +0000465}
466
J-Alvesab775912021-03-29 15:22:33 +0100467/**
468 * Request SP to get notifications. The arguments to use in ffa_notification_get
469 * are propagated on the command to test erroneous uses of the interface.
470 * In a successful call to the interface, the SP's response payload should
471 * include all bitmaps returned by the SPMC.
472 *
473 * The command id is the hex representation of the string "getnot".
474 */
475#define CACTUS_NOTIFICATION_GET_CMD U(0x6765746e6f74)
476
Daniel Boulbyce386b12022-03-29 18:36:36 +0100477static inline struct ffa_value cactus_notification_get_send_cmd(
J-Alvesab775912021-03-29 15:22:33 +0100478 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
J-Alvesa076d4c2021-10-19 16:06:15 +0100479 uint32_t vcpu_id, uint32_t flags, bool check_npi_handled)
J-Alvesab775912021-03-29 15:22:33 +0100480{
481 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_GET_CMD,
J-Alvesa076d4c2021-10-19 16:06:15 +0100482 receiver, vcpu_id, check_npi_handled, flags);
J-Alvesab775912021-03-29 15:22:33 +0100483}
484
Daniel Boulbyce386b12022-03-29 18:36:36 +0100485static inline uint32_t cactus_notification_get_vcpu(struct ffa_value ret)
J-Alvesab775912021-03-29 15:22:33 +0100486{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100487 return (uint32_t)ret.arg5;
J-Alvesab775912021-03-29 15:22:33 +0100488}
489
Daniel Boulbyce386b12022-03-29 18:36:36 +0100490static inline uint32_t cactus_notification_get_flags(struct ffa_value ret)
J-Alvesb4e89a22021-03-09 10:04:39 +0000491{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100492 return (uint32_t)ret.arg7;
J-Alvesb4e89a22021-03-09 10:04:39 +0000493}
494
Daniel Boulbyce386b12022-03-29 18:36:36 +0100495static inline struct ffa_value cactus_notifications_get_success_resp(
J-Alvesab775912021-03-29 15:22:33 +0100496 ffa_id_t source, ffa_id_t dest, uint64_t from_sp,
497 uint64_t from_vm)
498{
499 return cactus_send_response(source, dest, CACTUS_SUCCESS, from_sp,
500 from_vm, 0, 0);
501}
502
Daniel Boulbyce386b12022-03-29 18:36:36 +0100503static inline uint64_t cactus_notifications_get_from_sp(struct ffa_value ret)
J-Alvesab775912021-03-29 15:22:33 +0100504{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100505 return (uint64_t)ret.arg4;
J-Alvesab775912021-03-29 15:22:33 +0100506}
507
Daniel Boulbyce386b12022-03-29 18:36:36 +0100508static inline uint64_t cactus_notifications_get_from_vm(struct ffa_value ret)
J-Alvesab775912021-03-29 15:22:33 +0100509{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100510 return (uint64_t)ret.arg5;
J-Alvesab775912021-03-29 15:22:33 +0100511}
512
Daniel Boulbyce386b12022-03-29 18:36:36 +0100513static inline bool cactus_notifications_check_npi_handled(struct ffa_value ret)
J-Alvesa076d4c2021-10-19 16:06:15 +0100514{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100515 return (bool)ret.arg6;
J-Alvesa076d4c2021-10-19 16:06:15 +0100516}
517
J-Alvesab775912021-03-29 15:22:33 +0100518/**
519 * Request SP to set notifications. The arguments to use in ffa_notification_set
520 * are propagated on the command to test erroneous uses of the interface.
521 * In case of error while calling the interface, the response should include the
J-Alvesfbbbf622021-07-30 16:43:36 +0100522 * error code. If in the flags a delay SRI is requested, cactus should
523 * send a CACTUS_ECHO_CMD to the SP specified as `echo_dest`. This should help
524 * validate that the SRI is only sent when returning execution to the NWd.
J-Alvesab775912021-03-29 15:22:33 +0100525 */
526#define CACTUS_NOTIFICATIONS_SET_CMD U(0x6e6f74736574)
527
Daniel Boulbyce386b12022-03-29 18:36:36 +0100528static inline struct ffa_value cactus_notifications_set_send_cmd(
J-Alvesab775912021-03-29 15:22:33 +0100529 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
J-Alvesfbbbf622021-07-30 16:43:36 +0100530 ffa_id_t sender, uint32_t flags, ffa_notification_bitmap_t notifications,
531 ffa_id_t echo_dest)
J-Alvesab775912021-03-29 15:22:33 +0100532{
533 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATIONS_SET_CMD,
J-Alvesfbbbf622021-07-30 16:43:36 +0100534 (uint32_t)receiver | ((uint32_t)sender << 16),
535 echo_dest,
536 notifications, flags);
537}
538
Daniel Boulbyce386b12022-03-29 18:36:36 +0100539static inline ffa_id_t cactus_notifications_set_get_receiver(
540 struct ffa_value ret)
J-Alvesfbbbf622021-07-30 16:43:36 +0100541{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100542 return (ffa_id_t)(ret.arg4 & 0xFFFFU);
J-Alvesfbbbf622021-07-30 16:43:36 +0100543}
544
Daniel Boulbyce386b12022-03-29 18:36:36 +0100545static inline ffa_id_t cactus_notifications_set_get_sender(struct ffa_value ret)
J-Alvesfbbbf622021-07-30 16:43:36 +0100546{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100547 return (ffa_id_t)((ret.arg4 >> 16U) & 0xFFFFU);
J-Alvesab775912021-03-29 15:22:33 +0100548}
549
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500550/**
551 * Request to start trusted watchdog timer.
552 *
553 * The command id is the hex representaton of the string "WDOG"
554 */
555#define CACTUS_TWDOG_START_CMD U(0x57444f47)
556
Daniel Boulbyce386b12022-03-29 18:36:36 +0100557static inline struct ffa_value cactus_send_twdog_cmd(
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500558 ffa_id_t source, ffa_id_t dest, uint64_t time)
559{
560 return cactus_send_cmd(source, dest, CACTUS_TWDOG_START_CMD, time, 0, 0,
561 0);
562}
563
Daniel Boulbyce386b12022-03-29 18:36:36 +0100564static inline uint32_t cactus_get_wdog_duration(struct ffa_value ret)
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500565{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100566 return (uint32_t)ret.arg4;
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500567}
568
J-Alvesf7535f42021-07-30 11:58:41 +0100569/**
570 * Request SP to return the current count of handled requests.
571 *
572 * The command id is the hex representation of the string "getnot".
573 */
574#define CACTUS_GET_REQ_COUNT_CMD U(0x726571636f756e74)
575
Daniel Boulbyce386b12022-03-29 18:36:36 +0100576static inline struct ffa_value cactus_get_req_count_send_cmd(
J-Alvesf7535f42021-07-30 11:58:41 +0100577 ffa_id_t source, ffa_id_t dest)
578{
579 return cactus_send_cmd(source, dest, CACTUS_GET_REQ_COUNT_CMD, 0, 0, 0,
580 0);
581}
582
Daniel Boulbyce386b12022-03-29 18:36:36 +0100583static inline uint32_t cactus_get_req_count(struct ffa_value ret)
J-Alvesf7535f42021-07-30 11:58:41 +0100584{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100585 return (uint32_t)ret.arg4;
J-Alvesf7535f42021-07-30 11:58:41 +0100586}
587
Madhukar Pappireddyf4c8e8d2022-02-15 15:52:53 -0600588/**
589 * Request SP to return the last serviced secure virtual interrupt.
590 *
591 * The command id is the hex representaton of the string "vINT"
592 */
593#define CACTUS_LAST_INTERRUPT_SERVICED_CMD U(0x76494e54)
594
Daniel Boulbyce386b12022-03-29 18:36:36 +0100595static inline struct ffa_value cactus_get_last_interrupt_cmd(
Madhukar Pappireddyf4c8e8d2022-02-15 15:52:53 -0600596 ffa_id_t source, ffa_id_t dest)
597{
598 return cactus_send_cmd(source, dest, CACTUS_LAST_INTERRUPT_SERVICED_CMD,
599 0, 0, 0, 0);
600}
Madhukar Pappireddy0b0ca112022-09-19 13:39:48 -0500601
602/**
603 * Request SP to resume the task requested by current endpoint after managed
604 * exit.
605 *
606 * The command id is the hex representation of the string "RAME" which denotes
607 * (R)esume (A)fter (M)anaged (E)xit.
608 */
609#define CACTUS_RESUME_AFTER_MANAGED_EXIT U(0x52414d45)
610
611static inline struct ffa_value cactus_resume_after_managed_exit(
612 ffa_id_t source, ffa_id_t dest)
613{
614 return cactus_send_cmd(source, dest, CACTUS_RESUME_AFTER_MANAGED_EXIT,
615 0, 0, 0, 0);
616}
Raghu Krishnamurthy9e267a02022-08-11 21:25:26 -0700617
618/**
619 * Request SP to pend an interrupt in the extended SPI range.
620 *
621 * The command is the hex representation of the string "espi".
622 */
623#define CACTUS_TRIGGER_ESPI_CMD U(0x65737069)
624static inline struct ffa_value cactus_trigger_espi_cmd(
625 ffa_id_t source, ffa_id_t dest, uint32_t espi_id)
626{
627 return cactus_send_cmd(source, dest, CACTUS_TRIGGER_ESPI_CMD,
628 espi_id, 0, 0, 0);
629}
630
631static inline uint32_t cactus_get_espi_id(struct ffa_value ret)
632{
633 return (uint32_t)ret.arg4;
634}
635
Madhukar Pappireddyd655d582024-01-16 14:45:39 -0600636/*
637 * Request SP to mimic handling a RAS error delegated by an EL3 logical secure
638 * partition.
639 *
640 * The command ID is the hex representation of the string 'rase' which
641 * denotes RAS Error.
642 */
643#define CACTUS_RAS_DELEGATE_CMD U(0x72617365)
644
645static inline struct ffa_value cactus_ras_delegate_send_cmd(
646 ffa_id_t source, ffa_id_t dest, uint64_t event_id)
647{
648 return cactus_send_cmd(source, dest, CACTUS_RAS_DELEGATE_CMD, event_id, 0, 0,
649 0);
650}
651
652static inline uint64_t cactus_ras_get_event_id(struct ffa_value ret)
653{
654 return (uint64_t)ret.arg4;
655}
656
J-Alvesd1aae292020-10-08 17:16:58 +0100657#endif