blob: 0db523e6bacde4ab3a0f246cb1328f7af85f51ab [file] [log] [blame]
J-Alvesd1aae292020-10-08 17:16:58 +01001/*
2 * Copyright (c) 2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef CACTUS_TEST_CMDS
8#define CACTUS_TEST_CMDS
9
10#include <debug.h>
11#include <ffa_helpers.h>
12
13/**
14 * Success and error return to be sent over a msg response.
15 */
J-Alves9b28d062020-11-30 11:42:49 +000016#define CACTUS_SUCCESS U(0)
17#define CACTUS_ERROR U(-1)
J-Alvesd1aae292020-10-08 17:16:58 +010018
19/**
20 * Get command from struct smc_ret_values.
21 */
J-Alves53392012020-11-18 14:51:57 +000022static inline uint64_t cactus_get_cmd(smc_ret_values ret)
23{
24 return (uint64_t)ret.ret3;
25}
J-Alvesd1aae292020-10-08 17:16:58 +010026
27/**
28 * Template for commands to be sent to CACTUS partitions over direct
29 * messages interfaces.
30 */
J-Alves53392012020-11-18 14:51:57 +000031static inline smc_ret_values cactus_send_cmd(
32 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t cmd, uint64_t val0,
33 uint64_t val1, uint64_t val2, uint64_t val3)
34{
35 return ffa_msg_send_direct_req64_5args(source, dest, cmd, val0, val1,
36 val2, val3);
37}
J-Alvesd1aae292020-10-08 17:16:58 +010038
39#define PRINT_CMD(smc_ret) \
40 VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \
41 smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \
42 smc_ret.ret6, smc_ret.ret7)
43
44/**
J-Alves28672f92020-11-09 15:34:31 +000045 * With this test command the sender transmits a 64-bit value that it then
46 * expects to receive on the respective command response.
47 *
48 * The id is the hex representation of the string 'echo'.
49 */
50#define CACTUS_ECHO_CMD U(0x6563686f)
51
J-Alves53392012020-11-18 14:51:57 +000052static inline smc_ret_values cactus_echo_send_cmd(
53 ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val)
54{
55 return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0,
56 0);
57}
J-Alves28672f92020-11-09 15:34:31 +000058
J-Alves53392012020-11-18 14:51:57 +000059static inline uint64_t cactus_echo_get_val(smc_ret_values ret)
60{
61 return (uint64_t)ret.ret4;
62}
J-Alves28672f92020-11-09 15:34:31 +000063
64/**
65 * Command to request a cactus secure partition to send an echo command to
66 * another partition.
67 *
68 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
69 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
70 */
71#define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1)
72
J-Alves53392012020-11-18 14:51:57 +000073static inline smc_ret_values cactus_req_echo_send_cmd(
74 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest,
75 uint64_t echo_val)
76{
77 return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val,
78 echo_dest, 0, 0);
79}
J-Alves28672f92020-11-09 15:34:31 +000080
J-Alves53392012020-11-18 14:51:57 +000081static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret)
82{
83 return (ffa_vm_id_t)ret.ret5;
84}
J-Alves28672f92020-11-09 15:34:31 +000085
86/**
J-Alves1d203f12020-11-11 11:38:49 +000087 * Command to create a cyclic dependency between SPs, which could result in
88 * a deadlock. This aims at proving such scenario cannot happen.
89 * If the deadlock happens, the system will just hang.
90 * If the deadlock is prevented, the last partition to use the command will
91 * send response CACTUS_SUCCESS.
92 *
93 * The id is the hex representation of the string 'dead'.
94 */
95#define CACTUS_DEADLOCK_CMD U(0x64656164)
96
J-Alves53392012020-11-18 14:51:57 +000097static inline smc_ret_values cactus_deadlock_send_cmd(
98 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest)
99{
100 return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0,
101 0, 0);
102}
J-Alves1d203f12020-11-11 11:38:49 +0000103
J-Alves53392012020-11-18 14:51:57 +0000104static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret)
105{
106 return (ffa_vm_id_t)ret.ret4;
107}
J-Alves1d203f12020-11-11 11:38:49 +0000108
109/**
110 * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions
111 * of specified IDs.
112 */
113#define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1)
114
J-Alves53392012020-11-18 14:51:57 +0000115static inline smc_ret_values cactus_req_deadlock_send_cmd(
116 ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1,
117 ffa_vm_id_t next_dest2)
118{
119 return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD,
120 next_dest1, next_dest2, 0, 0);
121}
J-Alves1d203f12020-11-11 11:38:49 +0000122
J-Alves53392012020-11-18 14:51:57 +0000123/* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */
124static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret)
125{
126 return (ffa_vm_id_t)ret.ret5;
127}
J-Alves1d203f12020-11-11 11:38:49 +0000128
129/**
J-Alvesd1aae292020-10-08 17:16:58 +0100130 * Command to notify cactus of a memory management operation. The cmd value
131 * should be the memory management smc function id.
J-Alvesb9085f82020-12-07 10:57:28 +0000132 *
133 * The id is the hex representation of the string "mem"
J-Alvesd1aae292020-10-08 17:16:58 +0100134 */
J-Alvesb9085f82020-12-07 10:57:28 +0000135#define CACTUS_MEM_SEND_CMD U(0x6d656d)
J-Alvesd1aae292020-10-08 17:16:58 +0100136
J-Alves53392012020-11-18 14:51:57 +0000137static inline smc_ret_values cactus_mem_send_cmd(
138 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
139 ffa_memory_handle_t handle)
140{
141 return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
142 handle, 0, 0);
143}
J-Alvesb9085f82020-12-07 10:57:28 +0000144
J-Alves53392012020-11-18 14:51:57 +0000145static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret)
146{
147 return (ffa_memory_handle_t)ret.ret5;
148}
J-Alvesd1aae292020-10-08 17:16:58 +0100149
150/**
J-Alves542d8d82020-11-18 10:34:06 +0000151 * Command to request a memory management operation. The 'mem_func' argument
152 * identifies the operation that is to be performend, and 'receiver' is the id
153 * of the partition to receive the memory region.
154 *
155 * The command id is the hex representation of the string "memory".
156 */
157#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
158
J-Alves53392012020-11-18 14:51:57 +0000159static inline smc_ret_values cactus_req_mem_send_send_cmd(
160 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
161 ffa_vm_id_t receiver)
162{
163 return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
164 receiver, 0, 0);
165}
J-Alves542d8d82020-11-18 10:34:06 +0000166
J-Alves53392012020-11-18 14:51:57 +0000167static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret)
168{
169 return (uint32_t)ret.ret4;
170}
171
172static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret)
173{
174 return (ffa_vm_id_t)ret.ret5;
175}
J-Alves542d8d82020-11-18 10:34:06 +0000176
177/**
J-Alvesd1aae292020-10-08 17:16:58 +0100178 * Template for responses to CACTUS commands.
179 */
J-Alves53392012020-11-18 14:51:57 +0000180static inline smc_ret_values cactus_response(
181 ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response)
182{
183 return ffa_msg_send_direct_resp(source, dest, response);
184}
J-Alvesd1aae292020-10-08 17:16:58 +0100185
J-Alves53392012020-11-18 14:51:57 +0000186static inline smc_ret_values cactus_success_resp(
187 ffa_vm_id_t source, ffa_vm_id_t dest)
188{
189 return cactus_response(source, dest, CACTUS_SUCCESS);
190}
J-Alvesd1aae292020-10-08 17:16:58 +0100191
J-Alves53392012020-11-18 14:51:57 +0000192static inline smc_ret_values cactus_error_resp(
193 ffa_vm_id_t source, ffa_vm_id_t dest)
194{
195 return cactus_response(source, dest, CACTUS_ERROR);
196}
J-Alvesd1aae292020-10-08 17:16:58 +0100197
J-Alves53392012020-11-18 14:51:57 +0000198static inline uint32_t cactus_get_response(smc_ret_values ret)
199{
200 return (uint32_t)ret.ret3;
201}
J-Alves542d8d82020-11-18 10:34:06 +0000202
J-Alvesd1aae292020-10-08 17:16:58 +0100203#endif