blob: 1c1c21d8684e2763a6e21d283d7a488fecab29b9 [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/**
28 * Get command from struct smc_ret_values.
29 */
J-Alves53392012020-11-18 14:51:57 +000030static inline uint64_t cactus_get_cmd(smc_ret_values ret)
31{
32 return (uint64_t)ret.ret3;
33}
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 */
J-Alves53392012020-11-18 14:51:57 +000039static inline smc_ret_values 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 */
52static inline smc_ret_values 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 */
63static inline smc_ret_values 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
69static inline uint32_t cactus_get_response(smc_ret_values ret)
70{
71 return (uint32_t)ret.ret3;
72}
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 */
80static inline smc_ret_values 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 */
92static inline smc_ret_values 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
99static inline uint32_t cactus_error_code(smc_ret_values ret)
100{
101 return (uint32_t) ret.ret4;
102}
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
J-Alves53392012020-11-18 14:51:57 +0000112static inline smc_ret_values 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
J-Alves53392012020-11-18 14:51:57 +0000119static inline uint64_t cactus_echo_get_val(smc_ret_values ret)
120{
121 return (uint64_t)ret.ret4;
122}
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
J-Alves53392012020-11-18 14:51:57 +0000133static inline smc_ret_values 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 Boulbye79d2072021-03-03 11:34:53 +0000141static inline ffa_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret)
J-Alves53392012020-11-18 14:51:57 +0000142{
Daniel Boulbye79d2072021-03-03 11:34:53 +0000143 return (ffa_id_t)ret.ret5;
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
J-Alves53392012020-11-18 14:51:57 +0000157static inline smc_ret_values 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 Boulbye79d2072021-03-03 11:34:53 +0000164static inline ffa_id_t cactus_deadlock_get_next_dest(smc_ret_values ret)
J-Alves53392012020-11-18 14:51:57 +0000165{
Daniel Boulbye79d2072021-03-03 11:34:53 +0000166 return (ffa_id_t)ret.ret4;
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
J-Alves53392012020-11-18 14:51:57 +0000175static inline smc_ret_values 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 Boulbye79d2072021-03-03 11:34:53 +0000184static inline ffa_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret)
J-Alves53392012020-11-18 14:51:57 +0000185{
Daniel Boulbye79d2072021-03-03 11:34:53 +0000186 return (ffa_id_t)ret.ret5;
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
J-Alves53392012020-11-18 14:51:57 +0000197static inline smc_ret_values 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,
200 uint32_t word_to_write)
J-Alves53392012020-11-18 14:51:57 +0000201{
202 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
J-Alves32ccd2b2021-12-14 14:59:51 +0000203 handle, retrieve_flags, word_to_write);
J-Alves53392012020-11-18 14:51:57 +0000204}
J-Alvesb9085f82020-12-07 10:57:28 +0000205
J-Alves53392012020-11-18 14:51:57 +0000206static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret)
207{
208 return (ffa_memory_handle_t)ret.ret5;
209}
J-Alvesd1aae292020-10-08 17:16:58 +0100210
J-Alves32ccd2b2021-12-14 14:59:51 +0000211static inline ffa_memory_region_flags_t cactus_mem_send_get_retrv_flags(
212 smc_ret_values ret)
213{
214 return (ffa_memory_region_flags_t)ret.ret6;
215}
216
217static inline uint32_t cactus_mem_send_words_to_write(smc_ret_values ret)
218{
219 return (uint32_t)ret.ret7;
220}
221
J-Alvesd1aae292020-10-08 17:16:58 +0100222/**
J-Alves542d8d82020-11-18 10:34:06 +0000223 * Command to request a memory management operation. The 'mem_func' argument
224 * identifies the operation that is to be performend, and 'receiver' is the id
225 * of the partition to receive the memory region.
226 *
227 * The command id is the hex representation of the string "memory".
228 */
229#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
230
J-Alves53392012020-11-18 14:51:57 +0000231static inline smc_ret_values cactus_req_mem_send_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000232 ffa_id_t source, ffa_id_t dest, uint32_t mem_func,
233 ffa_id_t receiver)
J-Alves53392012020-11-18 14:51:57 +0000234{
235 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
236 receiver, 0, 0);
237}
J-Alves542d8d82020-11-18 10:34:06 +0000238
J-Alves53392012020-11-18 14:51:57 +0000239static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret)
240{
241 return (uint32_t)ret.ret4;
242}
243
Daniel Boulbye79d2072021-03-03 11:34:53 +0000244static inline ffa_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret)
J-Alves53392012020-11-18 14:51:57 +0000245{
Daniel Boulbye79d2072021-03-03 11:34:53 +0000246 return (ffa_id_t)ret.ret5;
J-Alves53392012020-11-18 14:51:57 +0000247}
J-Alves542d8d82020-11-18 10:34:06 +0000248
249/**
Olivier Deprez881b1992020-12-01 15:34:34 +0100250 * Request to fill SIMD vectors with dummy values with purpose to check a
251 * save/restore routine during the context switches between secure world and
252 * normal world.
253 *
254 * The command id is the hex representation of the string "SIMD"
255 */
256#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
257
258static inline smc_ret_values cactus_req_simd_fill_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000259 ffa_id_t source, ffa_id_t dest)
Olivier Deprez881b1992020-12-01 15:34:34 +0100260{
J-Alves0e1e7ca2021-01-25 14:11:06 +0000261 return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0,
262 0);
Olivier Deprez881b1992020-12-01 15:34:34 +0100263}
264
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000265/**
266 * Command to request cactus to sleep for the given time in ms
267 *
268 * The command id is the hex representation of string "sleep"
269 */
270#define CACTUS_SLEEP_CMD U(0x736c656570)
271
272static inline smc_ret_values cactus_sleep_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000273 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000274{
275 return cactus_send_cmd(source, dest, CACTUS_SLEEP_CMD, sleep_time, 0, 0,
276 0);
277}
278
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500279/**
280 * Command to request cactus to forward sleep command for the given time in ms
281 *
282 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
283 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
284 */
285#define CACTUS_FWD_SLEEP_CMD (CACTUS_SLEEP_CMD + 1)
286
287static inline smc_ret_values cactus_fwd_sleep_cmd(
288 ffa_id_t source, ffa_id_t dest, ffa_id_t fwd_dest,
289 uint32_t sleep_time)
290{
291 return cactus_send_cmd(source, dest, CACTUS_FWD_SLEEP_CMD, sleep_time,
292 fwd_dest, 0, 0);
293}
294
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000295static inline uint32_t cactus_get_sleep_time(smc_ret_values ret)
296{
297 return (uint32_t)ret.ret4;
298}
299
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500300static inline ffa_id_t cactus_get_fwd_sleep_dest(smc_ret_values ret)
301{
302 return (ffa_id_t)ret.ret5;
303}
304
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000305/**
Madhukar Pappireddy407befc2021-12-17 11:06:17 -0600306 * Command to request cactus to sleep for half the given time in ms, trigger
307 * trusted watchdog timer and then sleep again for another half the given time.
308 *
309 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
310 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
311 */
312#define CACTUS_SLEEP_TRIGGER_TWDOG_CMD (CACTUS_SLEEP_CMD + 2)
313
314static inline smc_ret_values cactus_sleep_trigger_wdog_cmd(
315 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time,
316 uint64_t wdog_time)
317{
318 return cactus_send_cmd(source, dest, CACTUS_SLEEP_TRIGGER_TWDOG_CMD, sleep_time,
319 wdog_time, 0, 0);
320}
321
322
323static inline uint32_t cactus_get_wdog_trigger_duration(smc_ret_values ret)
324{
325 return (uint32_t)ret.ret5;
326}
327
328/**
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000329 * Command to request cactus to enable/disable an interrupt
330 *
331 * The command id is the hex representation of string "intr"
332 */
333#define CACTUS_INTERRUPT_CMD U(0x696e7472)
334
335static inline smc_ret_values cactus_interrupt_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000336 ffa_id_t source, ffa_id_t dest, uint32_t interrupt_id,
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000337 bool enable, uint32_t pin)
338{
339 return cactus_send_cmd(source, dest, CACTUS_INTERRUPT_CMD, interrupt_id,
340 enable, pin, 0);
341}
342
343static inline uint32_t cactus_get_interrupt_id(smc_ret_values ret)
344{
345 return (uint32_t)ret.ret4;
346}
347
348static inline bool cactus_get_interrupt_enable(smc_ret_values ret)
349{
350 return (bool)ret.ret5;
351}
352
353static inline enum interrupt_pin cactus_get_interrupt_pin(smc_ret_values ret)
354{
355 return (enum interrupt_pin)ret.ret6;
356}
357
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600358/**
359 * Request to initiate DMA transaction by upstream peripheral.
360 *
361 * The command id is the hex representation of the string "SMMU"
362 */
363#define CACTUS_DMA_SMMUv3_CMD (0x534d4d55)
364
365static inline smc_ret_values cactus_send_dma_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000366 ffa_id_t source, ffa_id_t dest)
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600367{
368 return cactus_send_cmd(source, dest, CACTUS_DMA_SMMUv3_CMD, 0, 0, 0,
369 0);
370}
J-Alvesb4e89a22021-03-09 10:04:39 +0000371
372/*
373 * Request SP to bind a notification to a FF-A endpoint. In case of error
374 * when using the FFA_NOTIFICATION_BIND interface, include the error code
375 * in the response to the command's request. The receiver and sender arguments
376 * are propagated through the command's arguments, to allow the test of
377 * erroneous uses of the FFA_NOTIFICATION_BIND interface.
378 *
379 * The command id is the hex representation of the string "bind".
380 */
381#define CACTUS_NOTIFICATION_BIND_CMD U(0x62696e64)
382
383static inline smc_ret_values cactus_notification_bind_send_cmd(
384 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
385 ffa_id_t sender, ffa_notification_bitmap_t notifications, uint32_t flags)
386{
387 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_BIND_CMD,
388 receiver, sender, notifications, flags);
389}
390
391/**
392 * Request to SP unbind a notification. In case of error when using the
393 * FFA_NOTIFICATION_UNBIND interface, the test includes the error code in the
394 * response. The receiver and sender arguments are propagated throught the
395 * command's arguments, to allow the test of erroneous uses of the
396 * FFA_NOTIFICATION_BIND interface.
397 *
398 * The command id is the hex representation of the string "unbind".
399 */
400#define CACTUS_NOTIFICATION_UNBIND_CMD U(0x756e62696e64)
401
402static inline smc_ret_values cactus_notification_unbind_send_cmd(
403 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
404 ffa_id_t sender, ffa_notification_bitmap_t notifications)
405{
406 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_UNBIND_CMD,
407 receiver, sender, notifications, 0);
408}
409
410static inline ffa_id_t cactus_notification_get_receiver(
411 smc_ret_values ret)
412{
413 return (ffa_id_t)ret.ret4;
414}
415
416static inline ffa_id_t cactus_notification_get_sender(
417 smc_ret_values ret)
418{
419 return (ffa_id_t)ret.ret5;
420}
421
422static inline ffa_notification_bitmap_t cactus_notification_get_notifications(
423 smc_ret_values ret)
424{
425 return (uint64_t)ret.ret6;
426}
427
J-Alvesab775912021-03-29 15:22:33 +0100428/**
429 * Request SP to get notifications. The arguments to use in ffa_notification_get
430 * are propagated on the command to test erroneous uses of the interface.
431 * In a successful call to the interface, the SP's response payload should
432 * include all bitmaps returned by the SPMC.
433 *
434 * The command id is the hex representation of the string "getnot".
435 */
436#define CACTUS_NOTIFICATION_GET_CMD U(0x6765746e6f74)
437
438static inline smc_ret_values cactus_notification_get_send_cmd(
439 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
J-Alvesa076d4c2021-10-19 16:06:15 +0100440 uint32_t vcpu_id, uint32_t flags, bool check_npi_handled)
J-Alvesab775912021-03-29 15:22:33 +0100441{
442 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_GET_CMD,
J-Alvesa076d4c2021-10-19 16:06:15 +0100443 receiver, vcpu_id, check_npi_handled, flags);
J-Alvesab775912021-03-29 15:22:33 +0100444}
445
446static inline uint32_t cactus_notification_get_vcpu(smc_ret_values ret)
447{
448 return (uint32_t)ret.ret5;
449}
450
J-Alvesb4e89a22021-03-09 10:04:39 +0000451static inline uint32_t cactus_notification_get_flags(smc_ret_values ret)
452{
453 return (uint32_t)ret.ret7;
454}
455
J-Alvesab775912021-03-29 15:22:33 +0100456static inline smc_ret_values cactus_notifications_get_success_resp(
457 ffa_id_t source, ffa_id_t dest, uint64_t from_sp,
458 uint64_t from_vm)
459{
460 return cactus_send_response(source, dest, CACTUS_SUCCESS, from_sp,
461 from_vm, 0, 0);
462}
463
464static inline uint64_t cactus_notifications_get_from_sp(smc_ret_values ret)
465{
466 return (uint64_t)ret.ret4;
467}
468
469static inline uint64_t cactus_notifications_get_from_vm(smc_ret_values ret)
470{
471 return (uint64_t)ret.ret5;
472}
473
J-Alvesa076d4c2021-10-19 16:06:15 +0100474static inline bool cactus_notifications_check_npi_handled(smc_ret_values ret)
475{
476 return (bool)ret.ret6;
477}
478
J-Alvesab775912021-03-29 15:22:33 +0100479/**
480 * Request SP to set notifications. The arguments to use in ffa_notification_set
481 * are propagated on the command to test erroneous uses of the interface.
482 * In case of error while calling the interface, the response should include the
J-Alvesfbbbf622021-07-30 16:43:36 +0100483 * error code. If in the flags a delay SRI is requested, cactus should
484 * send a CACTUS_ECHO_CMD to the SP specified as `echo_dest`. This should help
485 * validate that the SRI is only sent when returning execution to the NWd.
J-Alvesab775912021-03-29 15:22:33 +0100486 */
487#define CACTUS_NOTIFICATIONS_SET_CMD U(0x6e6f74736574)
488
489static inline smc_ret_values cactus_notifications_set_send_cmd(
490 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
J-Alvesfbbbf622021-07-30 16:43:36 +0100491 ffa_id_t sender, uint32_t flags, ffa_notification_bitmap_t notifications,
492 ffa_id_t echo_dest)
J-Alvesab775912021-03-29 15:22:33 +0100493{
494 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATIONS_SET_CMD,
J-Alvesfbbbf622021-07-30 16:43:36 +0100495 (uint32_t)receiver | ((uint32_t)sender << 16),
496 echo_dest,
497 notifications, flags);
498}
499
500static inline ffa_id_t cactus_notifications_set_get_receiver(smc_ret_values ret)
501{
502 return (ffa_id_t)(ret.ret4 & 0xFFFFU);
503}
504
505static inline ffa_id_t cactus_notifications_set_get_sender(smc_ret_values ret)
506{
507 return (ffa_id_t)((ret.ret4 >> 16U) & 0xFFFFU);
J-Alvesab775912021-03-29 15:22:33 +0100508}
509
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500510/**
511 * Request to start trusted watchdog timer.
512 *
513 * The command id is the hex representaton of the string "WDOG"
514 */
515#define CACTUS_TWDOG_START_CMD U(0x57444f47)
516
517static inline smc_ret_values cactus_send_twdog_cmd(
518 ffa_id_t source, ffa_id_t dest, uint64_t time)
519{
520 return cactus_send_cmd(source, dest, CACTUS_TWDOG_START_CMD, time, 0, 0,
521 0);
522}
523
524static inline uint32_t cactus_get_wdog_duration(smc_ret_values ret)
525{
526 return (uint32_t)ret.ret4;
527}
528
J-Alvesf7535f42021-07-30 11:58:41 +0100529/**
530 * Request SP to return the current count of handled requests.
531 *
532 * The command id is the hex representation of the string "getnot".
533 */
534#define CACTUS_GET_REQ_COUNT_CMD U(0x726571636f756e74)
535
536static inline smc_ret_values cactus_get_req_count_send_cmd(
537 ffa_id_t source, ffa_id_t dest)
538{
539 return cactus_send_cmd(source, dest, CACTUS_GET_REQ_COUNT_CMD, 0, 0, 0,
540 0);
541}
542
543static inline uint32_t cactus_get_req_count(smc_ret_values ret)
544{
545 return (uint32_t)ret.ret4;
546}
547
Madhukar Pappireddyf4c8e8d2022-02-15 15:52:53 -0600548/**
549 * Request SP to return the last serviced secure virtual interrupt.
550 *
551 * The command id is the hex representaton of the string "vINT"
552 */
553#define CACTUS_LAST_INTERRUPT_SERVICED_CMD U(0x76494e54)
554
555static inline smc_ret_values cactus_get_last_interrupt_cmd(
556 ffa_id_t source, ffa_id_t dest)
557{
558 return cactus_send_cmd(source, dest, CACTUS_LAST_INTERRUPT_SERVICED_CMD,
559 0, 0, 0, 0);
560}
J-Alvesd1aae292020-10-08 17:16:58 +0100561#endif