blob: 28555afd4726dddf04eacccc59432da88cfb24f4 [file] [log] [blame]
J-Alves9f6f0142020-06-17 15:37:59 +01001/*
2 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <assert.h>
J-Alves9f6f0142020-06-17 15:37:59 +01007#include <debug.h>
Max Shvetsov40eb6a22020-06-08 11:15:30 +01008#include <errno.h>
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +01009#include <cactus_platform_def.h>
Max Shvetsovc32f4782020-06-23 09:41:15 +010010#include <cactus_def.h>
J-Alves5aecd982020-06-11 10:25:33 +010011#include <ffa_helpers.h>
J-Alves9f6f0142020-06-17 15:37:59 +010012#include <sp_helpers.h>
13
14/* FFA version test helpers */
15#define FFA_MAJOR 1U
16#define FFA_MINOR 0U
17
Max Shvetsovc32f4782020-06-23 09:41:15 +010018static const uint32_t primary_uuid[4] = PRIMARY_UUID;
19static const uint32_t secondary_uuid[4] = SECONDARY_UUID;
Ruari Phippsd75596a2020-07-17 16:41:34 +010020static const uint32_t tertiary_uuid[4] = TERTIARY_UUID;
Max Shvetsovc32f4782020-06-23 09:41:15 +010021static const uint32_t null_uuid[4] = {0};
22
Max Shvetsov40eb6a22020-06-08 11:15:30 +010023struct feature_test {
24 const char *test_name;
25 unsigned int feature;
26 unsigned int expected_ret;
27};
28
29static const struct feature_test test_target[] = {
30 {"FFA_ERROR_32 check", FFA_ERROR, FFA_SUCCESS_SMC32},
31 {"FFA_SUCCESS_32 check", FFA_SUCCESS_SMC32, FFA_SUCCESS_SMC32},
32 {"FFA_INTERRUPT_32 check", FFA_INTERRUPT, FFA_SUCCESS_SMC32},
33 {"FFA_VERSION_32 check", FFA_VERSION, FFA_SUCCESS_SMC32},
34 {"FFA_FEATURES_32 check", FFA_FEATURES, FFA_SUCCESS_SMC32},
35 {"FFA_RX_RELEASE_32 check", FFA_RX_RELEASE, FFA_SUCCESS_SMC32},
36 {"FFA_RXTX_MAP_32 check", FFA_RXTX_MAP_SMC32, FFA_ERROR},
37 {"FFA_RXTX_MAP_64 check", FFA_RXTX_MAP_SMC64, FFA_SUCCESS_SMC32},
38 {"FFA_RXTX_UNMAP_32 check", FFA_RXTX_UNMAP, FFA_ERROR},
39 {"FFA_PARTITION_INFO_GET_32 check", FFA_PARTITION_INFO_GET, FFA_SUCCESS_SMC32},
40 {"FFA_ID_GET_32 check", FFA_ID_GET, FFA_SUCCESS_SMC32},
41 {"FFA_MSG_POLL_32 check", FFA_MSG_POLL, FFA_SUCCESS_SMC32},
42 {"FFA_MSG_WAIT_32 check", FFA_MSG_WAIT, FFA_SUCCESS_SMC32},
43 {"FFA_YIELD_32 check", FFA_MSG_YIELD, FFA_SUCCESS_SMC32},
44 {"FFA_RUN_32 check", FFA_MSG_RUN, FFA_SUCCESS_SMC32},
45 {"FFA_MSG_SEND_32 check", FFA_MSG_SEND, FFA_SUCCESS_SMC32},
46 {"FFA_MEM_DONATE_32 check", FFA_MEM_DONATE_SMC32, FFA_SUCCESS_SMC32},
47 {"FFA_MEM_LEND_32 check", FFA_MEM_LEND_SMC32, FFA_SUCCESS_SMC32},
48 {"FFA_MEM_SHARE_32 check", FFA_MEM_SHARE_SMC32, FFA_SUCCESS_SMC32},
49 {"FFA_MEM_RETRIEVE_REQ_32 check", FFA_MEM_RETRIEVE_REQ_SMC32, FFA_SUCCESS_SMC32},
50 {"FFA_MEM_RETRIEVE_RESP_32 check", FFA_MEM_RETRIEVE_RESP, FFA_SUCCESS_SMC32},
51 {"FFA_MEM_RELINQUISH_32 check", FFA_MEM_RELINQUISH, FFA_SUCCESS_SMC32},
52 {"FFA_MEM_RECLAIM_32 check", FFA_MEM_RECLAIM, FFA_SUCCESS_SMC32},
53 {"Check non-existent command", 0xFFFF, FFA_ERROR}
54};
55
56/*
57 * Test FFA_FEATURES interface.
58 */
59static void ffa_features_test(void)
60{
61 const char *test_features = "FFA Features interface";
62 smc_ret_values ffa_ret;
63 unsigned int i, test_target_size =
64 sizeof(test_target) / sizeof(struct feature_test);
65
66 announce_test_section_start(test_features);
67
68 for (i = 0U; i < test_target_size; i++) {
69 announce_test_start(test_target[i].test_name);
70
71 ffa_ret = ffa_features(test_target[i].feature);
72 expect(ffa_ret.ret0, test_target[i].expected_ret);
73 if (test_target[i].expected_ret == FFA_ERROR) {
74 expect(ffa_ret.ret2, FFA_ERROR_NOT_SUPPORTED);
75 }
76
77 announce_test_end(test_target[i].test_name);
78 }
79
80 announce_test_section_end(test_features);
81}
82
Max Shvetsovc32f4782020-06-23 09:41:15 +010083static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4],
84 const struct ffa_partition_info *expected,
85 const uint16_t expected_size)
86{
87 smc_ret_values ret = ffa_partition_info_get(uuid);
88 unsigned int i;
89 expect(ret.ret0, FFA_SUCCESS_SMC32);
90
91 struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv);
92 for (i = 0U; i < expected_size; i++) {
93 expect(info[i].id, expected[i].id);
94 expect(info[i].exec_context, expected[i].exec_context);
95 expect(info[i].properties, expected[i].properties);
96 }
97
98 ret = ffa_rx_release();
99 expect(ret.ret0, FFA_SUCCESS_SMC32);
100}
101
102static void ffa_partition_info_wrong_test(void)
103{
104 const char *test_wrong_uuid = "Request wrong UUID";
105 uint32_t uuid[4] = {1};
106
107 announce_test_start(test_wrong_uuid);
108
109 smc_ret_values ret = ffa_partition_info_get(uuid);
110 expect(ret.ret0, FFA_ERROR);
111 expect(ret.ret2, FFA_ERROR_INVALID_PARAMETER);
112
113 announce_test_end(test_wrong_uuid);
114}
115
116static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
117{
118 const char *test_partition_info = "FFA Partition info interface";
119 const char *test_primary = "Get primary partition info";
120 const char *test_secondary = "Get secondary partition info";
Ruari Phippsd75596a2020-07-17 16:41:34 +0100121 const char *test_tertiary = "Get tertiary partition info";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100122 const char *test_all = "Get all partitions info";
123
124 const struct ffa_partition_info expected_info[] = {
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100125 /* Primary partition info */
126 {
127 .id = SPM_VM_ID_FIRST,
128 .exec_context = CACTUS_PRIMARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200129 /* Supports receipt of direct message requests. */
130 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100131 },
132 /* Secondary partition info */
133 {
134 .id = SPM_VM_ID_FIRST + 1U,
135 .exec_context = CACTUS_SECONDARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200136 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100137 },
138 /* Tertiary partition info */
139 {
140 .id = SPM_VM_ID_FIRST + 2U,
141 .exec_context = CACTUS_TERTIARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200142 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100143 }
Max Shvetsovc32f4782020-06-23 09:41:15 +0100144 };
145
146 announce_test_section_start(test_partition_info);
147
Ruari Phippsd75596a2020-07-17 16:41:34 +0100148 announce_test_start(test_tertiary);
149 ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1);
150 announce_test_end(test_tertiary);
151
Max Shvetsovc32f4782020-06-23 09:41:15 +0100152 announce_test_start(test_secondary);
153 ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1);
154 announce_test_end(test_secondary);
155
156 announce_test_start(test_primary);
157 ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1);
158 announce_test_end(test_primary);
159
160 announce_test_start(test_all);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100161 ffa_partition_info_helper(mb, null_uuid, expected_info, 3);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100162 announce_test_end(test_all);
163
164 ffa_partition_info_wrong_test();
165
166 announce_test_section_end(test_partition_info);
167}
168
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100169void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100170{
J-Alves9f6f0142020-06-17 15:37:59 +0100171 const char *test_ffa_version = "FFA Version interface";
172
J-Alves9f6f0142020-06-17 15:37:59 +0100173 announce_test_start(test_ffa_version);
174
175 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100176 uint32_t spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100177
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100178 bool ffa_version_compatible =
179 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
180 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100181
182 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
183 spm_version >> FFA_VERSION_MAJOR_SHIFT,
184 spm_version & FFA_VERSION_MINOR_MASK,
185 (int)ffa_version_compatible);
186
187 expect((int)ffa_version_compatible, (int)true);
188
189 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100190}
191
192void ffa_tests(struct mailbox_buffers *mb)
193{
194 const char *test_ffa = "FFA Interfaces";
195
196 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100197
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100198 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100199 ffa_version_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100200 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100201
J-Alves9f6f0142020-06-17 15:37:59 +0100202 announce_test_section_end(test_ffa);
203}