blob: 80211a8d13b74e6be3624429c59c26392c4e93e5 [file] [log] [blame]
J-Alves9f6f0142020-06-17 15:37:59 +01001/*
Daniel Boulby8aa994c2022-01-05 19:44:30 +00002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
J-Alves9f6f0142020-06-17 15:37:59 +01003 *
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>
Max Shvetsov103e0562021-02-04 16:58:31 +00009
Daniel Boulbyf3da5912022-04-01 12:31:52 +010010#include <sp_def.h>
J-Alves8f4a56f2020-10-28 10:29:05 +000011#include <ffa_endpoints.h>
J-Alves9f6f0142020-06-17 15:37:59 +010012#include <sp_helpers.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020013#include <spm_helpers.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000014#include <spm_common.h>
J-Alves9f6f0142020-06-17 15:37:59 +010015
J-Alves63cdaa72020-10-08 17:22:45 +010016#include <lib/libc/string.h>
J-Alves63cdaa72020-10-08 17:22:45 +010017
J-Alves9f6f0142020-06-17 15:37:59 +010018/* FFA version test helpers */
19#define FFA_MAJOR 1U
Daniel Boulby8aa994c2022-01-05 19:44:30 +000020#define FFA_MINOR 1U
J-Alves9f6f0142020-06-17 15:37:59 +010021
Daniel Boulby198deda2021-03-03 11:35:25 +000022static uint32_t spm_version;
23
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000024static const struct ffa_uuid sp_uuids[] = {
Daniel Boulby8aa994c2022-01-05 19:44:30 +000025 {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID}, {IVY_UUID}
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000026 };
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000027
28static const struct ffa_partition_info ffa_expected_partition_info[] = {
29 /* Primary partition info */
30 {
31 .id = SP_ID(1),
32 .exec_context = PRIMARY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050033 .properties = (FFA_PARTITION_AARCH64_EXEC |
34 FFA_PARTITION_DIRECT_REQ_RECV |
J-Alves4d05dec2021-11-02 11:52:27 +000035 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000036 FFA_PARTITION_NOTIFICATION),
37 .uuid = sp_uuids[0]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000038 },
39 /* Secondary partition info */
40 {
41 .id = SP_ID(2),
42 .exec_context = SECONDARY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050043 .properties = (FFA_PARTITION_AARCH64_EXEC |
44 FFA_PARTITION_DIRECT_REQ_RECV |
J-Alves4d05dec2021-11-02 11:52:27 +000045 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000046 FFA_PARTITION_NOTIFICATION),
47 .uuid = sp_uuids[1]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000048 },
49 /* Tertiary partition info */
50 {
51 .id = SP_ID(3),
52 .exec_context = TERTIARY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050053 .properties = (FFA_PARTITION_AARCH64_EXEC |
54 FFA_PARTITION_DIRECT_REQ_RECV |
J-Alvesb69c8b42021-11-04 17:03:41 +000055 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000056 FFA_PARTITION_NOTIFICATION),
57 .uuid = sp_uuids[2]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000058 },
59 /* Ivy partition info */
60 {
61 .id = SP_ID(4),
62 .exec_context = IVY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050063 .properties = (FFA_PARTITION_AARCH64_EXEC |
64 FFA_PARTITION_DIRECT_REQ_RECV |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000065 FFA_PARTITION_DIRECT_REQ_SEND),
66 .uuid = sp_uuids[3]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000067 }
68};
Max Shvetsovc32f4782020-06-23 09:41:15 +010069
Max Shvetsov40eb6a22020-06-08 11:15:30 +010070/*
71 * Test FFA_FEATURES interface.
72 */
73static void ffa_features_test(void)
74{
75 const char *test_features = "FFA Features interface";
Daniel Boulbyce386b12022-03-29 18:36:36 +010076 struct ffa_value ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000077 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000078 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010079 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000080 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000081 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000082
Max Shvetsov40eb6a22020-06-08 11:15:30 +010083
84 announce_test_section_start(test_features);
85
86 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000087 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010088
Daniel Boulby198deda2021-03-03 11:35:25 +000089 announce_test_start(test_target.test_name);
90
91 ffa_ret = ffa_features(test_target.feature);
92 expected_ret = FFA_VERSION_COMPILED
93 >= test_target.version_added ?
94 test_target.expected_ret : FFA_ERROR;
95
96 expect(ffa_func_id(ffa_ret), expected_ret);
97 if (expected_ret == FFA_ERROR) {
J-Alves6cb21d92021-01-07 15:18:12 +000098 expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010099 }
100
Daniel Boulby198deda2021-03-03 11:35:25 +0000101 announce_test_end(test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100102 }
103
104 announce_test_section_end(test_features);
105}
106
Max Shvetsovc32f4782020-06-23 09:41:15 +0100107static void ffa_partition_info_wrong_test(void)
108{
109 const char *test_wrong_uuid = "Request wrong UUID";
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000110 const struct ffa_uuid uuid = { .uuid = {1} };
Max Shvetsovc32f4782020-06-23 09:41:15 +0100111
112 announce_test_start(test_wrong_uuid);
113
Daniel Boulbyce386b12022-03-29 18:36:36 +0100114 struct ffa_value ret = ffa_partition_info_get(uuid);
J-Alves6cb21d92021-01-07 15:18:12 +0000115 expect(ffa_func_id(ret), FFA_ERROR);
116 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100117
118 announce_test_end(test_wrong_uuid);
119}
120
121static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
122{
123 const char *test_partition_info = "FFA Partition info interface";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100124
125 announce_test_section_start(test_partition_info);
126
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000127 expect(ffa_partition_info_helper(mb, sp_uuids[2],
128 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100129
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000130 expect(ffa_partition_info_helper(mb, sp_uuids[1],
131 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100132
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000133 expect(ffa_partition_info_helper(mb, sp_uuids[0],
134 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100135
Daniel Boulby4a2888a2022-05-31 16:07:36 +0100136 expect(ffa_partition_info_helper(mb, NULL_UUID,
Varun Wadekar5c354822021-09-27 06:01:09 -0700137 ffa_expected_partition_info,
138 ARRAY_SIZE(ffa_expected_partition_info)), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100139
140 ffa_partition_info_wrong_test();
141
142 announce_test_section_end(test_partition_info);
143}
144
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100145void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100146{
J-Alves9f6f0142020-06-17 15:37:59 +0100147 const char *test_ffa_version = "FFA Version interface";
148
J-Alves9f6f0142020-06-17 15:37:59 +0100149 announce_test_start(test_ffa_version);
150
Daniel Boulbyce386b12022-03-29 18:36:36 +0100151 struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR,
152 FFA_MINOR));
153
154 spm_version = (uint32_t)ret.fid;
J-Alves9f6f0142020-06-17 15:37:59 +0100155
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100156 bool ffa_version_compatible =
157 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
158 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100159
Olivier Deprez24bd1702021-10-05 14:35:17 +0200160 VERBOSE("FFA_VERSION returned %u.%u; Compatible: %i\n",
J-Alves9f6f0142020-06-17 15:37:59 +0100161 spm_version >> FFA_VERSION_MAJOR_SHIFT,
162 spm_version & FFA_VERSION_MINOR_MASK,
163 (int)ffa_version_compatible);
164
165 expect((int)ffa_version_compatible, (int)true);
166
167 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100168}
169
Daniel Boulby198deda2021-03-03 11:35:25 +0000170void ffa_spm_id_get_test(void)
171{
172 const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function";
173
174 announce_test_start(test_spm_id_get);
175
176 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
Daniel Boulbyce386b12022-03-29 18:36:36 +0100177 struct ffa_value ret = ffa_spm_id_get();
Daniel Boulby198deda2021-03-03 11:35:25 +0000178
179 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
180
181 ffa_id_t spm_id = ffa_endpoint_id(ret);
182
183 VERBOSE("SPM ID = 0x%x\n", spm_id);
184 /*
185 * Check the SPMC value given in the fvp_spmc_manifest
186 * is returned.
187 */
188 expect(spm_id, SPMC_ID);
189 } else {
190 NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A."
191 " Test skipped.\n");
192 }
193 announce_test_end(test_spm_id_get);
194}
195
Maksims Svecovs0b452232022-05-24 11:30:34 +0100196void ffa_console_log_test(void)
197{
198 const char *test_name = "FFA_CONSOLE_LOG SMC Function";
199 announce_test_start(test_name);
200
201 const char test_string[] = "[FFA_CONSOLE_LOG]: Hello World!\n";
202 struct ffa_value ret = ffa_console_log(test_string, sizeof(test_string));
203
204 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
205
206 announce_test_end(test_name);
207}
208
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100209void ffa_tests(struct mailbox_buffers *mb)
210{
211 const char *test_ffa = "FFA Interfaces";
212
213 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100214
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100215 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100216 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000217 ffa_spm_id_get_test();
Maksims Svecovs0b452232022-05-24 11:30:34 +0100218 ffa_console_log_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100219 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100220
J-Alves9f6f0142020-06-17 15:37:59 +0100221 announce_test_section_end(test_ffa);
222}