blob: 7555b8b29426ea957516d4d3d0d96e3ea53994c8 [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 */
22#define CACTUS_GET_CMD(smc_ret) smc_ret.ret3
23
24/**
25 * Template for commands to be sent to CACTUS partitions over direct
26 * messages interfaces.
27 */
28#define CACTUS_SEND_CMD(source, dest, cmd, val0, val1, val2, val3) \
29 ffa_msg_send_direct_req64_5args(source, dest, cmd, \
30 val0, val1, val2, val3)
31
32#define PRINT_CMD(smc_ret) \
33 VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \
34 smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \
35 smc_ret.ret6, smc_ret.ret7)
36
37/**
J-Alves28672f92020-11-09 15:34:31 +000038 * With this test command the sender transmits a 64-bit value that it then
39 * expects to receive on the respective command response.
40 *
41 * The id is the hex representation of the string 'echo'.
42 */
43#define CACTUS_ECHO_CMD U(0x6563686f)
44
45#define CACTUS_ECHO_SEND_CMD(source, dest, echo_val) \
46 CACTUS_SEND_CMD(source, dest, CACTUS_ECHO_CMD, echo_val,\
47 0, 0, 0)
48
49#define CACTUS_ECHO_GET_VAL(smc_ret) smc_ret.ret4
50
51/**
52 * Command to request a cactus secure partition to send an echo command to
53 * another partition.
54 *
55 * The sender of this command expects to receive CACTUS_SUCCESS if the requested
56 * echo interaction happened successfully, or CACTUS_ERROR otherwise.
57 */
58#define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1)
59
60#define CACTUS_REQ_ECHO_SEND_CMD(source, dest, echo_dest, echo_val) \
61 CACTUS_SEND_CMD(source, dest, CACTUS_REQ_ECHO_CMD, echo_val, \
62 echo_dest, 0, 0)
63
64#define CACTUS_REQ_ECHO_GET_ECHO_DEST(smc_ret) smc_ret.ret5
65
66/**
J-Alves1d203f12020-11-11 11:38:49 +000067 * Command to create a cyclic dependency between SPs, which could result in
68 * a deadlock. This aims at proving such scenario cannot happen.
69 * If the deadlock happens, the system will just hang.
70 * If the deadlock is prevented, the last partition to use the command will
71 * send response CACTUS_SUCCESS.
72 *
73 * The id is the hex representation of the string 'dead'.
74 */
75#define CACTUS_DEADLOCK_CMD U(0x64656164)
76
77#define CACTUS_DEADLOCK_SEND_CMD(source, dest, next_dest) \
78 CACTUS_SEND_CMD(source, dest, CACTUS_DEADLOCK_CMD, next_dest, \
79 0, 0, 0)
80
81#define CACTUS_DEADLOCK_GET_NEXT_DEST(smc_ret) smc_ret.ret4
82
83/**
84 * Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions
85 * of specified IDs.
86 */
87#define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1)
88
89#define CACTUS_REQ_DEADLOCK_SEND_CMD(source, dest, next_dest1, next_dest2) \
90 CACTUS_SEND_CMD(source, dest, CACTUS_REQ_DEADLOCK_CMD, \
91 next_dest1, next_dest2, 0, 0)
92
93/*To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST*/
94#define CACTUS_DEADLOCK_GET_NEXT_DEST2(smc_ret) smc_ret.ret5
95
96/**
J-Alvesd1aae292020-10-08 17:16:58 +010097 * Command to notify cactus of a memory management operation. The cmd value
98 * should be the memory management smc function id.
J-Alvesb9085f82020-12-07 10:57:28 +000099 *
100 * The id is the hex representation of the string "mem"
J-Alvesd1aae292020-10-08 17:16:58 +0100101 */
J-Alvesb9085f82020-12-07 10:57:28 +0000102#define CACTUS_MEM_SEND_CMD U(0x6d656d)
J-Alvesd1aae292020-10-08 17:16:58 +0100103
J-Alvesb9085f82020-12-07 10:57:28 +0000104#define CACTUS_MEM_SEND_CMD_SEND(source, dest, mem_func, handle) \
105 CACTUS_SEND_CMD(source, dest, CACTUS_MEM_SEND_CMD, \
106 mem_func, handle, 0, 0)
107
108#define CACTUS_MEM_SEND_GET_FUNC(smc_ret) smc_ret.ret4
109
110#define CACTUS_MEM_SEND_GET_HANDLE(smc_ret) smc_ret.ret5
J-Alvesd1aae292020-10-08 17:16:58 +0100111
112/**
J-Alves542d8d82020-11-18 10:34:06 +0000113 * Command to request a memory management operation. The 'mem_func' argument
114 * identifies the operation that is to be performend, and 'receiver' is the id
115 * of the partition to receive the memory region.
116 *
117 * The command id is the hex representation of the string "memory".
118 */
119#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
120
J-Alvesb9085f82020-12-07 10:57:28 +0000121#define CACTUS_REQ_MEM_SEND_SEND_CMD(source, dest, mem_func, receiver) \
122 CACTUS_SEND_CMD(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, \
J-Alves542d8d82020-11-18 10:34:06 +0000123 receiver, 0, 0)
124
125#define CACTUS_REQ_MEM_SEND_GET_MEM_FUNC(smc_ret) smc_ret.ret4
126#define CACTUS_REQ_MEM_SEND_GET_RECEIVER(smc_ret) smc_ret.ret5
127
128/**
J-Alvesd1aae292020-10-08 17:16:58 +0100129 * Template for responses to CACTUS commands.
130 */
J-Alves542d8d82020-11-18 10:34:06 +0000131#define CACTUS_RESPONSE(source, dest, response) \
J-Alvesd1aae292020-10-08 17:16:58 +0100132 ffa_msg_send_direct_resp(source, dest, response)
133
J-Alves542d8d82020-11-18 10:34:06 +0000134#define CACTUS_SUCCESS_RESP(source, dest) \
J-Alvesd1aae292020-10-08 17:16:58 +0100135 CACTUS_RESPONSE(source, dest, CACTUS_SUCCESS)
136
J-Alves542d8d82020-11-18 10:34:06 +0000137#define CACTUS_ERROR_RESP(source, dest) \
J-Alvesd1aae292020-10-08 17:16:58 +0100138 CACTUS_RESPONSE(source, dest, CACTUS_ERROR)
139
140#define CACTUS_GET_RESPONSE(smc_ret) smc_ret.ret3
141
J-Alves28672f92020-11-09 15:34:31 +0000142#define CACTUS_IS_SUCCESS_RESP(smc_ret) \
143 (CACTUS_GET_RESPONSE(smc_ret) == CACTUS_SUCCESS)
144
J-Alves542d8d82020-11-18 10:34:06 +0000145#define CACTUS_IS_ERROR_RESP(smc_ret) \
146 (CACTUS_GET_RESPONSE(smc_ret) == CACTUS_ERROR)
147
J-Alvesd1aae292020-10-08 17:16:58 +0100148#endif