blob: 246f4f97916d676fb3e42ea7a6de0fe547f20731 [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>
11
12/**
13 * Success and error return to be sent over a msg response.
14 */
J-Alves0e1e7ca2021-01-25 14:11:06 +000015#define CACTUS_SUCCESS U(0)
16#define CACTUS_ERROR U(-1)
17
18/**
19 * Error codes.
20 */
21#define CACTUS_ERROR_INVALID U(1)
22#define CACTUS_ERROR_TEST U(2)
23#define CACTUS_ERROR_FFA_CALL U(3)
J-Alves4cb9dee2021-03-03 13:59:52 +000024#define CACTUS_ERROR_UNHANDLED U(4)
J-Alvesd1aae292020-10-08 17:16:58 +010025
26/**
27 * Get command from struct smc_ret_values.
28 */
J-Alves53392012020-11-18 14:51:57 +000029static inline uint64_t cactus_get_cmd(smc_ret_values ret)
30{
31 return (uint64_t)ret.ret3;
32}
J-Alvesd1aae292020-10-08 17:16:58 +010033
34/**
35 * Template for commands to be sent to CACTUS partitions over direct
36 * messages interfaces.
37 */
J-Alves53392012020-11-18 14:51:57 +000038static inline smc_ret_values cactus_send_cmd(
39 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t cmd, uint64_t val0,
40 uint64_t val1, uint64_t val2, uint64_t val3)
41{
J-Alvesecd30742021-02-19 18:31:06 +000042 return ffa_msg_send_direct_req64(source, dest, cmd, val0, val1, val2,
43 val3);
J-Alves53392012020-11-18 14:51:57 +000044}
J-Alvesd1aae292020-10-08 17:16:58 +010045
J-Alves7d28b332021-02-11 16:08:08 +000046/**
47 * Template for responses to Cactus commands.
48 * 'cactus_send_response' is the template for custom responses, in case there is
49 * a need to propagate more than one value in the response of a command.
50 */
51static inline smc_ret_values cactus_send_response(
52 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t resp, uint32_t val0,
53 uint64_t val1, uint64_t val2, uint64_t val3)
54{
J-Alvesecd30742021-02-19 18:31:06 +000055 return ffa_msg_send_direct_resp64(source, dest, resp, val0, val1,
56 val2, val3);
J-Alves7d28b332021-02-11 16:08:08 +000057}
58
59/**
60 * For responses of one value only.
61 */
62static inline smc_ret_values cactus_response(
63 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response)
64{
J-Alvesecd30742021-02-19 18:31:06 +000065 return ffa_msg_send_direct_resp64(source, dest, response, 0, 0, 0, 0);
J-Alves7d28b332021-02-11 16:08:08 +000066}
67
68static inline uint32_t cactus_get_response(smc_ret_values ret)
69{
70 return (uint32_t)ret.ret3;
71}
72
73/**
74 * In a successful test, in case the SP needs to propagate an extra value
75 * to conclude the test.
76 * If more arguments are needed, a custom response should be defined for the
77 * specific test.
78 */
79static inline smc_ret_values cactus_success_resp(
80 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t value)
81{
82 return cactus_send_response(source, dest, CACTUS_SUCCESS, value,
83 0, 0, 0);
84}
85
86/**
87 * In case the test fails on the SP side, the 'error_code' should help specify
88 * the reason, which can be specific to the test, or general ones as defined
89 * in the error code list.
90 */
91static inline smc_ret_values cactus_error_resp(
92 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t error_code)
93{
94 return cactus_send_response(source, dest, CACTUS_ERROR, error_code,
95 0, 0, 0);
96}
97
98static inline uint32_t cactus_error_code(smc_ret_values ret)
99{
100 return (uint32_t) ret.ret4;
101}
102
J-Alvesd1aae292020-10-08 17:16:58 +0100103/**
J-Alves28672f92020-11-09 15:34:31 +0000104 * With this test command the sender transmits a 64-bit value that it then
105 * expects to receive on the respective command response.
106 *
107 * The id is the hex representation of the string 'echo'.
108 */
109#define CACTUS_ECHO_CMD U(0x6563686f)
110
J-Alves53392012020-11-18 14:51:57 +0000111static inline smc_ret_values cactus_echo_send_cmd(
112 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val)
113{
114 return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0,
115 0);
116}
J-Alves28672f92020-11-09 15:34:31 +0000117
J-Alves53392012020-11-18 14:51:57 +0000118static inline uint64_t cactus_echo_get_val(smc_ret_values ret)
119{
120 return (uint64_t)ret.ret4;
121}
J-Alves28672f92020-11-09 15:34:31 +0000122
123/**
124 * Command to request a cactus secure partition to send an echo command to
125 * another partition.
126 *
127 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
128 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
129 */
130#define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1)
131
J-Alves53392012020-11-18 14:51:57 +0000132static inline smc_ret_values cactus_req_echo_send_cmd(
133 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest,
134 uint64_t echo_val)
135{
136 return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val,
137 echo_dest, 0, 0);
138}
J-Alves28672f92020-11-09 15:34:31 +0000139
J-Alves53392012020-11-18 14:51:57 +0000140static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret)
141{
142 return (ffa_vm_id_t)ret.ret5;
143}
J-Alves28672f92020-11-09 15:34:31 +0000144
145/**
J-Alves1d203f12020-11-11 11:38:49 +0000146 * Command to create a cyclic dependency between SPs, which could result in
147 * a deadlock. This aims at proving such scenario cannot happen.
148 * If the deadlock happens, the system will just hang.
149 * If the deadlock is prevented, the last partition to use the command will
150 * send response CACTUS_SUCCESS.
151 *
152 * The id is the hex representation of the string 'dead'.
153 */
154#define CACTUS_DEADLOCK_CMD U(0x64656164)
155
J-Alves53392012020-11-18 14:51:57 +0000156static inline smc_ret_values cactus_deadlock_send_cmd(
157 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest)
158{
159 return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0,
160 0, 0);
161}
J-Alves1d203f12020-11-11 11:38:49 +0000162
J-Alves53392012020-11-18 14:51:57 +0000163static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret)
164{
165 return (ffa_vm_id_t)ret.ret4;
166}
J-Alves1d203f12020-11-11 11:38:49 +0000167
168/**
169 * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions
170 * of specified IDs.
171 */
172#define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1)
173
J-Alves53392012020-11-18 14:51:57 +0000174static inline smc_ret_values cactus_req_deadlock_send_cmd(
175 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1,
176 ffa_vm_id_t next_dest2)
177{
178 return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD,
179 next_dest1, next_dest2, 0, 0);
180}
J-Alves1d203f12020-11-11 11:38:49 +0000181
J-Alves53392012020-11-18 14:51:57 +0000182/* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */
183static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret)
184{
185 return (ffa_vm_id_t)ret.ret5;
186}
J-Alves1d203f12020-11-11 11:38:49 +0000187
188/**
J-Alvesd1aae292020-10-08 17:16:58 +0100189 * Command to notify cactus of a memory management operation. The cmd value
190 * should be the memory management smc function id.
J-Alvesb9085f82020-12-07 10:57:28 +0000191 *
192 * The id is the hex representation of the string "mem"
J-Alvesd1aae292020-10-08 17:16:58 +0100193 */
J-Alvesb9085f82020-12-07 10:57:28 +0000194#define CACTUS_MEM_SEND_CMD U(0x6d656d)
J-Alvesd1aae292020-10-08 17:16:58 +0100195
J-Alves53392012020-11-18 14:51:57 +0000196static inline smc_ret_values cactus_mem_send_cmd(
197 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
198 ffa_memory_handle_t handle)
199{
200 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
201 handle, 0, 0);
202}
J-Alvesb9085f82020-12-07 10:57:28 +0000203
J-Alves53392012020-11-18 14:51:57 +0000204static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret)
205{
206 return (ffa_memory_handle_t)ret.ret5;
207}
J-Alvesd1aae292020-10-08 17:16:58 +0100208
209/**
J-Alves542d8d82020-11-18 10:34:06 +0000210 * Command to request a memory management operation. The 'mem_func' argument
211 * identifies the operation that is to be performend, and 'receiver' is the id
212 * of the partition to receive the memory region.
213 *
214 * The command id is the hex representation of the string "memory".
215 */
216#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
217
J-Alves53392012020-11-18 14:51:57 +0000218static inline smc_ret_values cactus_req_mem_send_send_cmd(
219 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
220 ffa_vm_id_t receiver)
221{
222 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
223 receiver, 0, 0);
224}
J-Alves542d8d82020-11-18 10:34:06 +0000225
J-Alves53392012020-11-18 14:51:57 +0000226static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret)
227{
228 return (uint32_t)ret.ret4;
229}
230
231static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret)
232{
233 return (ffa_vm_id_t)ret.ret5;
234}
J-Alves542d8d82020-11-18 10:34:06 +0000235
236/**
Olivier Deprez881b1992020-12-01 15:34:34 +0100237 * Request to fill SIMD vectors with dummy values with purpose to check a
238 * save/restore routine during the context switches between secure world and
239 * normal world.
240 *
241 * The command id is the hex representation of the string "SIMD"
242 */
243#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
244
245static inline smc_ret_values cactus_req_simd_fill_send_cmd(
246 ffa_vm_id_t source, ffa_vm_id_t dest)
247{
J-Alves0e1e7ca2021-01-25 14:11:06 +0000248 return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0,
249 0);
Olivier Deprez881b1992020-12-01 15:34:34 +0100250}
251
J-Alvesd1aae292020-10-08 17:16:58 +0100252#endif