blob: d4cf4079c0c05c0ac7163f638160ad29824ca5c4 [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
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-Alves53392012020-11-18 14:51:57 +0000199 ffa_memory_handle_t handle)
200{
201 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
202 handle, 0, 0);
203}
J-Alvesb9085f82020-12-07 10:57:28 +0000204
J-Alves53392012020-11-18 14:51:57 +0000205static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret)
206{
207 return (ffa_memory_handle_t)ret.ret5;
208}
J-Alvesd1aae292020-10-08 17:16:58 +0100209
210/**
J-Alves542d8d82020-11-18 10:34:06 +0000211 * Command to request a memory management operation. The 'mem_func' argument
212 * identifies the operation that is to be performend, and 'receiver' is the id
213 * of the partition to receive the memory region.
214 *
215 * The command id is the hex representation of the string "memory".
216 */
217#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
218
J-Alves53392012020-11-18 14:51:57 +0000219static inline smc_ret_values cactus_req_mem_send_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000220 ffa_id_t source, ffa_id_t dest, uint32_t mem_func,
221 ffa_id_t receiver)
J-Alves53392012020-11-18 14:51:57 +0000222{
223 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
224 receiver, 0, 0);
225}
J-Alves542d8d82020-11-18 10:34:06 +0000226
J-Alves53392012020-11-18 14:51:57 +0000227static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret)
228{
229 return (uint32_t)ret.ret4;
230}
231
Daniel Boulbye79d2072021-03-03 11:34:53 +0000232static inline ffa_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret)
J-Alves53392012020-11-18 14:51:57 +0000233{
Daniel Boulbye79d2072021-03-03 11:34:53 +0000234 return (ffa_id_t)ret.ret5;
J-Alves53392012020-11-18 14:51:57 +0000235}
J-Alves542d8d82020-11-18 10:34:06 +0000236
237/**
Olivier Deprez881b1992020-12-01 15:34:34 +0100238 * Request to fill SIMD vectors with dummy values with purpose to check a
239 * save/restore routine during the context switches between secure world and
240 * normal world.
241 *
242 * The command id is the hex representation of the string "SIMD"
243 */
244#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
245
246static inline smc_ret_values cactus_req_simd_fill_send_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000247 ffa_id_t source, ffa_id_t dest)
Olivier Deprez881b1992020-12-01 15:34:34 +0100248{
J-Alves0e1e7ca2021-01-25 14:11:06 +0000249 return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0,
250 0);
Olivier Deprez881b1992020-12-01 15:34:34 +0100251}
252
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000253/**
254 * Command to request cactus to sleep for the given time in ms
255 *
256 * The command id is the hex representation of string "sleep"
257 */
258#define CACTUS_SLEEP_CMD U(0x736c656570)
259
260static inline smc_ret_values cactus_sleep_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000261 ffa_id_t source, ffa_id_t dest, uint32_t sleep_time)
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000262{
263 return cactus_send_cmd(source, dest, CACTUS_SLEEP_CMD, sleep_time, 0, 0,
264 0);
265}
266
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500267/**
268 * Command to request cactus to forward sleep command for the given time in ms
269 *
270 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
271 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
272 */
273#define CACTUS_FWD_SLEEP_CMD (CACTUS_SLEEP_CMD + 1)
274
275static inline smc_ret_values cactus_fwd_sleep_cmd(
276 ffa_id_t source, ffa_id_t dest, ffa_id_t fwd_dest,
277 uint32_t sleep_time)
278{
279 return cactus_send_cmd(source, dest, CACTUS_FWD_SLEEP_CMD, sleep_time,
280 fwd_dest, 0, 0);
281}
282
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000283static inline uint32_t cactus_get_sleep_time(smc_ret_values ret)
284{
285 return (uint32_t)ret.ret4;
286}
287
Madhukar Pappireddyb6402592021-08-20 13:13:49 -0500288static inline ffa_id_t cactus_get_fwd_sleep_dest(smc_ret_values ret)
289{
290 return (ffa_id_t)ret.ret5;
291}
292
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000293/**
294 * Command to request cactus to enable/disable an interrupt
295 *
296 * The command id is the hex representation of string "intr"
297 */
298#define CACTUS_INTERRUPT_CMD U(0x696e7472)
299
300static inline smc_ret_values cactus_interrupt_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000301 ffa_id_t source, ffa_id_t dest, uint32_t interrupt_id,
Manish Pandey9ee6a8d2021-03-03 09:53:33 +0000302 bool enable, uint32_t pin)
303{
304 return cactus_send_cmd(source, dest, CACTUS_INTERRUPT_CMD, interrupt_id,
305 enable, pin, 0);
306}
307
308static inline uint32_t cactus_get_interrupt_id(smc_ret_values ret)
309{
310 return (uint32_t)ret.ret4;
311}
312
313static inline bool cactus_get_interrupt_enable(smc_ret_values ret)
314{
315 return (bool)ret.ret5;
316}
317
318static inline enum interrupt_pin cactus_get_interrupt_pin(smc_ret_values ret)
319{
320 return (enum interrupt_pin)ret.ret6;
321}
322
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600323/**
324 * Request to initiate DMA transaction by upstream peripheral.
325 *
326 * The command id is the hex representation of the string "SMMU"
327 */
328#define CACTUS_DMA_SMMUv3_CMD (0x534d4d55)
329
330static inline smc_ret_values cactus_send_dma_cmd(
Daniel Boulbye79d2072021-03-03 11:34:53 +0000331 ffa_id_t source, ffa_id_t dest)
Madhukar Pappireddy172523b2020-12-31 19:25:33 -0600332{
333 return cactus_send_cmd(source, dest, CACTUS_DMA_SMMUv3_CMD, 0, 0, 0,
334 0);
335}
J-Alvesb4e89a22021-03-09 10:04:39 +0000336
337/*
338 * Request SP to bind a notification to a FF-A endpoint. In case of error
339 * when using the FFA_NOTIFICATION_BIND interface, include the error code
340 * in the response to the command's request. The receiver and sender arguments
341 * are propagated through the command's arguments, to allow the test of
342 * erroneous uses of the FFA_NOTIFICATION_BIND interface.
343 *
344 * The command id is the hex representation of the string "bind".
345 */
346#define CACTUS_NOTIFICATION_BIND_CMD U(0x62696e64)
347
348static inline smc_ret_values cactus_notification_bind_send_cmd(
349 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
350 ffa_id_t sender, ffa_notification_bitmap_t notifications, uint32_t flags)
351{
352 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_BIND_CMD,
353 receiver, sender, notifications, flags);
354}
355
356/**
357 * Request to SP unbind a notification. In case of error when using the
358 * FFA_NOTIFICATION_UNBIND interface, the test includes the error code in the
359 * response. The receiver and sender arguments are propagated throught the
360 * command's arguments, to allow the test of erroneous uses of the
361 * FFA_NOTIFICATION_BIND interface.
362 *
363 * The command id is the hex representation of the string "unbind".
364 */
365#define CACTUS_NOTIFICATION_UNBIND_CMD U(0x756e62696e64)
366
367static inline smc_ret_values cactus_notification_unbind_send_cmd(
368 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
369 ffa_id_t sender, ffa_notification_bitmap_t notifications)
370{
371 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_UNBIND_CMD,
372 receiver, sender, notifications, 0);
373}
374
375static inline ffa_id_t cactus_notification_get_receiver(
376 smc_ret_values ret)
377{
378 return (ffa_id_t)ret.ret4;
379}
380
381static inline ffa_id_t cactus_notification_get_sender(
382 smc_ret_values ret)
383{
384 return (ffa_id_t)ret.ret5;
385}
386
387static inline ffa_notification_bitmap_t cactus_notification_get_notifications(
388 smc_ret_values ret)
389{
390 return (uint64_t)ret.ret6;
391}
392
J-Alvesab775912021-03-29 15:22:33 +0100393/**
394 * Request SP to get notifications. The arguments to use in ffa_notification_get
395 * are propagated on the command to test erroneous uses of the interface.
396 * In a successful call to the interface, the SP's response payload should
397 * include all bitmaps returned by the SPMC.
398 *
399 * The command id is the hex representation of the string "getnot".
400 */
401#define CACTUS_NOTIFICATION_GET_CMD U(0x6765746e6f74)
402
403static inline smc_ret_values cactus_notification_get_send_cmd(
404 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
405 uint32_t vcpu_id, uint32_t flags)
406{
407 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATION_GET_CMD,
408 receiver, vcpu_id, 0, flags);
409}
410
411static inline uint32_t cactus_notification_get_vcpu(smc_ret_values ret)
412{
413 return (uint32_t)ret.ret5;
414}
415
J-Alvesb4e89a22021-03-09 10:04:39 +0000416static inline uint32_t cactus_notification_get_flags(smc_ret_values ret)
417{
418 return (uint32_t)ret.ret7;
419}
420
J-Alvesab775912021-03-29 15:22:33 +0100421static inline smc_ret_values cactus_notifications_get_success_resp(
422 ffa_id_t source, ffa_id_t dest, uint64_t from_sp,
423 uint64_t from_vm)
424{
425 return cactus_send_response(source, dest, CACTUS_SUCCESS, from_sp,
426 from_vm, 0, 0);
427}
428
429static inline uint64_t cactus_notifications_get_from_sp(smc_ret_values ret)
430{
431 return (uint64_t)ret.ret4;
432}
433
434static inline uint64_t cactus_notifications_get_from_vm(smc_ret_values ret)
435{
436 return (uint64_t)ret.ret5;
437}
438
439/**
440 * Request SP to set notifications. The arguments to use in ffa_notification_set
441 * are propagated on the command to test erroneous uses of the interface.
442 * In case of error while calling the interface, the response should include the
443 * error code.
444 */
445#define CACTUS_NOTIFICATIONS_SET_CMD U(0x6e6f74736574)
446
447static inline smc_ret_values cactus_notifications_set_send_cmd(
448 ffa_id_t source, ffa_id_t dest, ffa_id_t receiver,
449 ffa_id_t sender, uint32_t flags, ffa_notification_bitmap_t notifications)
450{
451 return cactus_send_cmd(source, dest, CACTUS_NOTIFICATIONS_SET_CMD,
452 receiver, sender, notifications, flags);
453}
454
Madhukar Pappireddy3c287262021-08-05 14:39:24 -0500455/**
456 * Request to start trusted watchdog timer.
457 *
458 * The command id is the hex representaton of the string "WDOG"
459 */
460#define CACTUS_TWDOG_START_CMD U(0x57444f47)
461
462static inline smc_ret_values cactus_send_twdog_cmd(
463 ffa_id_t source, ffa_id_t dest, uint64_t time)
464{
465 return cactus_send_cmd(source, dest, CACTUS_TWDOG_START_CMD, time, 0, 0,
466 0);
467}
468
469static inline uint32_t cactus_get_wdog_duration(smc_ret_values ret)
470{
471 return (uint32_t)ret.ret4;
472}
473
J-Alvesd1aae292020-10-08 17:16:58 +0100474#endif