blob: 63bf1313394dde92b2d579f8a570434dd88d336d [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 */
J-Alves2279c1d2023-05-05 17:03:28 +01006#include "ffa_helpers.h"
J-Alves9f6f0142020-06-17 15:37:59 +01007#include <assert.h>
J-Alves9f6f0142020-06-17 15:37:59 +01008#include <debug.h>
Max Shvetsov40eb6a22020-06-08 11:15:30 +01009#include <errno.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000010
Daniel Boulbyf3da5912022-04-01 12:31:52 +010011#include <sp_def.h>
J-Alves8f4a56f2020-10-28 10:29:05 +000012#include <ffa_endpoints.h>
J-Alves9f6f0142020-06-17 15:37:59 +010013#include <sp_helpers.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020014#include <spm_helpers.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000015#include <spm_common.h>
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 Boulby899dced2024-01-12 14:46:54 +000020#define FFA_MINOR 2U
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[] = {
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -070025 {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID}, {IVY_UUID}, {EL3_SPMD_LP_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),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010037 .uuid = {PRIMARY_UUID}
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),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010047 .uuid = {SECONDARY_UUID}
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),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010057 .uuid = {TERTIARY_UUID}
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),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010066 .uuid = {IVY_UUID}
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -070067 },
68 /* EL3 SPMD logical partition */
69 {
70 .id = SP_ID(0x7FC0),
71 .exec_context = EL3_SPMD_LP_EXEC_CTX_COUNT,
72 .properties = (FFA_PARTITION_AARCH64_EXEC |
73 FFA_PARTITION_DIRECT_REQ_SEND),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010074 .uuid = {EL3_SPMD_LP_UUID}
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -070075 },
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000076};
Max Shvetsovc32f4782020-06-23 09:41:15 +010077
Max Shvetsov40eb6a22020-06-08 11:15:30 +010078/*
79 * Test FFA_FEATURES interface.
80 */
81static void ffa_features_test(void)
82{
Daniel Boulbyce386b12022-03-29 18:36:36 +010083 struct ffa_value ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000084 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000085 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010086 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000087 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000088 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000089
J-Alves2279c1d2023-05-05 17:03:28 +010090 INFO("Test FFA_FEATURES.\n");
Max Shvetsov40eb6a22020-06-08 11:15:30 +010091
92 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000093 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010094
J-Alves2279c1d2023-05-05 17:03:28 +010095 ffa_ret = ffa_features_with_input_property(test_target.feature,
96 test_target.param);
Daniel Boulby198deda2021-03-03 11:35:25 +000097 expected_ret = FFA_VERSION_COMPILED
98 >= test_target.version_added ?
99 test_target.expected_ret : FFA_ERROR;
100
J-Alves2279c1d2023-05-05 17:03:28 +0100101 if (ffa_func_id(ffa_ret) != expected_ret) {
Karl Meakine3e57062024-01-18 14:28:36 +0000102 ERROR("Unexpected return: %s (expected %s)."
J-Alves2279c1d2023-05-05 17:03:28 +0100103 " FFA_FEATURES test: %s.\n",
Karl Meakine3e57062024-01-18 14:28:36 +0000104 ffa_func_name(ffa_func_id(ffa_ret)),
105 ffa_func_name(expected_ret),
J-Alves2279c1d2023-05-05 17:03:28 +0100106 test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100107 }
108
J-Alves2279c1d2023-05-05 17:03:28 +0100109 if (expected_ret == FFA_ERROR) {
110 if (ffa_error_code(ffa_ret) !=
111 FFA_ERROR_NOT_SUPPORTED) {
Karl Meakine3e57062024-01-18 14:28:36 +0000112 ERROR("Unexpected error code: %s (expected %s)."
J-Alves2279c1d2023-05-05 17:03:28 +0100113 " FFA_FEATURES test: %s.\n",
Karl Meakine3e57062024-01-18 14:28:36 +0000114 ffa_error_name(ffa_error_code(ffa_ret)),
115 ffa_error_name(expected_ret),
J-Alves2279c1d2023-05-05 17:03:28 +0100116 test_target.test_name);
117 }
118 }
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100119 }
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100120}
121
Max Shvetsovc32f4782020-06-23 09:41:15 +0100122static void ffa_partition_info_wrong_test(void)
123{
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000124 const struct ffa_uuid uuid = { .uuid = {1} };
Daniel Boulbyce386b12022-03-29 18:36:36 +0100125 struct ffa_value ret = ffa_partition_info_get(uuid);
J-Alves2279c1d2023-05-05 17:03:28 +0100126
127 VERBOSE("%s: test request wrong UUID.\n", __func__);
128
J-Alves6cb21d92021-01-07 15:18:12 +0000129 expect(ffa_func_id(ret), FFA_ERROR);
130 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100131}
132
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700133static void ffa_partition_info_get_regs_test(void)
134{
135 struct ffa_value ret = { 0 };
136
137 VERBOSE("FF-A Partition Info regs interface tests\n");
Daniel Boulby899dced2024-01-12 14:46:54 +0000138 ret = ffa_version(MAKE_FFA_VERSION(1, 2));
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700139 uint32_t version = ret.fid;
140
141 if (version == FFA_ERROR_NOT_SUPPORTED) {
Daniel Boulby899dced2024-01-12 14:46:54 +0000142 ERROR("FFA_VERSION 1.2 not supported, skipping"
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700143 " FFA_PARTITION_INFO_GET_REGS test.\n");
144 return;
145 }
146
147 ret = ffa_features(FFA_PARTITION_INFO_GET_REGS_SMC64);
148 if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
149 ERROR("FFA_PARTITION_INFO_GET_REGS not supported skipping tests.\n");
150 return;
151 }
152
153 expect(ffa_partition_info_regs_helper(sp_uuids[3],
154 &ffa_expected_partition_info[3], 1), true);
155 expect(ffa_partition_info_regs_helper(sp_uuids[2],
156 &ffa_expected_partition_info[2], 1), true);
157 expect(ffa_partition_info_regs_helper(sp_uuids[1],
158 &ffa_expected_partition_info[1], 1), true);
159 expect(ffa_partition_info_regs_helper(sp_uuids[0],
160 &ffa_expected_partition_info[0], 1), true);
161
162 /*
163 * Check partition information if there is support for SPMD EL3
164 * partitions. calling partition_info_get_regs with the SPMD EL3
165 * UUID successfully, indicates the presence of it (there is no
166 * spec defined way to discover presence of el3 spmd logical
167 * partitions). If the call fails with a not supported error,
168 * we assume they dont exist and skip further tests to avoid
169 * failures on platforms without el3 spmd logical partitions.
170 */
171 ret = ffa_partition_info_get_regs(sp_uuids[4], 0, 0);
172 if ((ffa_func_id(ret) == FFA_ERROR) &&
173 ((ffa_error_code(ret) == FFA_ERROR_NOT_SUPPORTED) ||
174 (ffa_error_code(ret) == FFA_ERROR_INVALID_PARAMETER))) {
175 INFO("Skipping register based EL3 SPMD Logical partition"
176 " discovery\n");
177 expect(ffa_partition_info_regs_helper(NULL_UUID,
178 ffa_expected_partition_info,
179 (ARRAY_SIZE(ffa_expected_partition_info) - 1)), true);
180 } else {
181 expect(ffa_partition_info_regs_helper(sp_uuids[4],
182 &ffa_expected_partition_info[4], 1), true);
183 expect(ffa_partition_info_regs_helper(NULL_UUID,
184 ffa_expected_partition_info,
185 ARRAY_SIZE(ffa_expected_partition_info)), true);
186 }
187}
188
Max Shvetsovc32f4782020-06-23 09:41:15 +0100189static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
190{
J-Alves2279c1d2023-05-05 17:03:28 +0100191 INFO("Test FFA_PARTITION_INFO_GET.\n");
Max Shvetsovc32f4782020-06-23 09:41:15 +0100192
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000193 expect(ffa_partition_info_helper(mb, sp_uuids[2],
194 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100195
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000196 expect(ffa_partition_info_helper(mb, sp_uuids[1],
197 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100198
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000199 expect(ffa_partition_info_helper(mb, sp_uuids[0],
200 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100201
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700202 /*
203 * TODO: ffa_partition_info_get_regs returns EL3 SPMD LP information
204 * but partition_info_get does not. Ignore the last entry, that is
205 * assumed to be the EL3 SPMD LP information. ffa_partition_info_get
206 * uses the rx/tx buffer and the SPMD does not support the use of
207 * rx/tx buffer to return SPMD logical partition information.
208 */
Daniel Boulby4a2888a2022-05-31 16:07:36 +0100209 expect(ffa_partition_info_helper(mb, NULL_UUID,
Varun Wadekar5c354822021-09-27 06:01:09 -0700210 ffa_expected_partition_info,
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700211 (ARRAY_SIZE(ffa_expected_partition_info) - 1)), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100212
213 ffa_partition_info_wrong_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100214}
215
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100216void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100217{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100218 struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR,
219 FFA_MINOR));
220
221 spm_version = (uint32_t)ret.fid;
J-Alves9f6f0142020-06-17 15:37:59 +0100222
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100223 bool ffa_version_compatible =
224 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
225 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100226
J-Alves2279c1d2023-05-05 17:03:28 +0100227 INFO("Test FFA_VERSION. Return %u.%u; Compatible: %i\n",
J-Alves9f6f0142020-06-17 15:37:59 +0100228 spm_version >> FFA_VERSION_MAJOR_SHIFT,
229 spm_version & FFA_VERSION_MINOR_MASK,
230 (int)ffa_version_compatible);
231
232 expect((int)ffa_version_compatible, (int)true);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100233}
234
Daniel Boulby198deda2021-03-03 11:35:25 +0000235void ffa_spm_id_get_test(void)
236{
Daniel Boulby198deda2021-03-03 11:35:25 +0000237 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
Daniel Boulbyce386b12022-03-29 18:36:36 +0100238 struct ffa_value ret = ffa_spm_id_get();
Daniel Boulby198deda2021-03-03 11:35:25 +0000239
240 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
241
242 ffa_id_t spm_id = ffa_endpoint_id(ret);
243
J-Alves2279c1d2023-05-05 17:03:28 +0100244 INFO("Test FFA_SPM_ID_GET. Return: 0x%x\n", spm_id);
245
Daniel Boulby198deda2021-03-03 11:35:25 +0000246 /*
247 * Check the SPMC value given in the fvp_spmc_manifest
248 * is returned.
249 */
250 expect(spm_id, SPMC_ID);
251 } else {
J-Alves2279c1d2023-05-05 17:03:28 +0100252 INFO("FFA_SPM_ID_GET not supported in this version of FF-A."
Daniel Boulby198deda2021-03-03 11:35:25 +0000253 " Test skipped.\n");
254 }
Daniel Boulby198deda2021-03-03 11:35:25 +0000255}
256
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100257void ffa_tests(struct mailbox_buffers *mb)
258{
J-Alves2279c1d2023-05-05 17:03:28 +0100259 const char *test_ffa = "FF-A setup and discovery";
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100260
261 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100262
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100263 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100264 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000265 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100266 ffa_partition_info_get_test(mb);
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700267 ffa_partition_info_get_regs_test();
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100268
J-Alves9f6f0142020-06-17 15:37:59 +0100269 announce_test_section_end(test_ffa);
270}