blob: 94576d106ec27c172416c4a4520362431b1dc525 [file] [log] [blame]
J-Alves9f6f0142020-06-17 15:37:59 +01001/*
Olivier Deprez2661ba52024-02-19 18:50:53 +01002 * Copyright (c) 2018-2024, 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 |
J-Alvesd551d092024-10-30 11:09:47 +000036 FFA_PARTITION_INDIRECT_MSG |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000037 FFA_PARTITION_NOTIFICATION),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010038 .uuid = {PRIMARY_UUID}
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000039 },
40 /* Secondary partition info */
41 {
42 .id = SP_ID(2),
43 .exec_context = SECONDARY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050044 .properties = (FFA_PARTITION_AARCH64_EXEC |
45 FFA_PARTITION_DIRECT_REQ_RECV |
J-Alves4d05dec2021-11-02 11:52:27 +000046 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000047 FFA_PARTITION_NOTIFICATION),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010048 .uuid = {SECONDARY_UUID}
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000049 },
50 /* Tertiary partition info */
51 {
52 .id = SP_ID(3),
53 .exec_context = TERTIARY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050054 .properties = (FFA_PARTITION_AARCH64_EXEC |
55 FFA_PARTITION_DIRECT_REQ_RECV |
J-Alvesb69c8b42021-11-04 17:03:41 +000056 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000057 FFA_PARTITION_NOTIFICATION),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010058 .uuid = {TERTIARY_UUID}
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000059 },
60 /* Ivy partition info */
61 {
62 .id = SP_ID(4),
63 .exec_context = IVY_EXEC_CTX_COUNT,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050064 .properties = (FFA_PARTITION_AARCH64_EXEC |
65 FFA_PARTITION_DIRECT_REQ_RECV |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000066 FFA_PARTITION_DIRECT_REQ_SEND),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010067 .uuid = {IVY_UUID}
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -070068 },
69 /* EL3 SPMD logical partition */
70 {
71 .id = SP_ID(0x7FC0),
72 .exec_context = EL3_SPMD_LP_EXEC_CTX_COUNT,
73 .properties = (FFA_PARTITION_AARCH64_EXEC |
74 FFA_PARTITION_DIRECT_REQ_SEND),
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010075 .uuid = {EL3_SPMD_LP_UUID}
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -070076 },
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000077};
Max Shvetsovc32f4782020-06-23 09:41:15 +010078
Max Shvetsov40eb6a22020-06-08 11:15:30 +010079/*
80 * Test FFA_FEATURES interface.
81 */
J-Alves367154e2024-05-13 18:01:02 +010082static void ffa_features_test(bool el1_partition)
Max Shvetsov40eb6a22020-06-08 11:15:30 +010083{
J-Alves9668ba52024-05-13 11:49:45 +010084 const struct ffa_features_test *func_id_targets;
85 /* Get common features between tftf and cactus. */
Karl Meakin8205a642024-06-19 15:05:19 +010086 size_t test_target_size = get_ffa_feature_test_target(&func_id_targets);
J-Alvesf855e9f2024-10-30 11:11:47 +000087 struct ffa_features_test feature_id_targets[] = {
J-Alves9668ba52024-05-13 11:49:45 +010088 {"FFA_FEATURE_MEI", FFA_FEATURE_MEI, FFA_SUCCESS_SMC32, 0,
Karl Meakin7308b122024-04-16 14:02:25 +010089 FFA_VERSION_1_1},
J-Alves9668ba52024-05-13 11:49:45 +010090 {"FFA_FEATURE_SRI", FFA_FEATURE_SRI, FFA_ERROR, 0,
Karl Meakin7308b122024-04-16 14:02:25 +010091 FFA_VERSION_1_1},
J-Alves9668ba52024-05-13 11:49:45 +010092 {"FFA_FEATURE_NPI", FFA_FEATURE_NPI, FFA_SUCCESS_SMC32, 0,
Karl Meakin7308b122024-04-16 14:02:25 +010093 FFA_VERSION_1_1},
J-Alvesf855e9f2024-10-30 11:11:47 +000094 {"FFA_YIELD_32", FFA_MSG_YIELD, FFA_SUCCESS_SMC32,
95 FFA_VERSION_1_0},
J-Alves9668ba52024-05-13 11:49:45 +010096 };
Max Shvetsov103e0562021-02-04 16:58:31 +000097
J-Alves2279c1d2023-05-05 17:03:28 +010098 INFO("Test FFA_FEATURES.\n");
J-Alves9668ba52024-05-13 11:49:45 +010099 ffa_features_test_targets(func_id_targets, test_target_size);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100100
J-Alves9668ba52024-05-13 11:49:45 +0100101 /* Features are expected to be different to tftf. */
J-Alves367154e2024-05-13 18:01:02 +0100102
103 /* EL0 partitions don't support NPI. */
104 if (!el1_partition) {
105 feature_id_targets[2].expected_ret = FFA_ERROR;
106 }
107
J-Alves9668ba52024-05-13 11:49:45 +0100108 ffa_features_test_targets(feature_id_targets,
109 ARRAY_SIZE(feature_id_targets));
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100110}
111
Max Shvetsovc32f4782020-06-23 09:41:15 +0100112static void ffa_partition_info_wrong_test(void)
113{
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000114 const struct ffa_uuid uuid = { .uuid = {1} };
Daniel Boulbyce386b12022-03-29 18:36:36 +0100115 struct ffa_value ret = ffa_partition_info_get(uuid);
J-Alves2279c1d2023-05-05 17:03:28 +0100116
117 VERBOSE("%s: test request wrong UUID.\n", __func__);
118
Karl Meakinc884d6b2024-04-16 14:01:10 +0100119 EXPECT(ffa_func_id(ret), FFA_ERROR);
120 EXPECT(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100121}
122
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700123static void ffa_partition_info_get_regs_test(void)
124{
125 struct ffa_value ret = { 0 };
126
127 VERBOSE("FF-A Partition Info regs interface tests\n");
Karl Meakin7308b122024-04-16 14:02:25 +0100128 ret = ffa_version(FFA_VERSION_1_2);
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700129 uint32_t version = ret.fid;
130
131 if (version == FFA_ERROR_NOT_SUPPORTED) {
Daniel Boulby899dced2024-01-12 14:46:54 +0000132 ERROR("FFA_VERSION 1.2 not supported, skipping"
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700133 " FFA_PARTITION_INFO_GET_REGS test.\n");
134 return;
135 }
136
137 ret = ffa_features(FFA_PARTITION_INFO_GET_REGS_SMC64);
138 if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
139 ERROR("FFA_PARTITION_INFO_GET_REGS not supported skipping tests.\n");
140 return;
141 }
142
Karl Meakinc884d6b2024-04-16 14:01:10 +0100143 EXPECT(ffa_partition_info_regs_helper(sp_uuids[3],
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700144 &ffa_expected_partition_info[3], 1), true);
Karl Meakinc884d6b2024-04-16 14:01:10 +0100145 EXPECT(ffa_partition_info_regs_helper(sp_uuids[2],
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700146 &ffa_expected_partition_info[2], 1), true);
Karl Meakinc884d6b2024-04-16 14:01:10 +0100147 EXPECT(ffa_partition_info_regs_helper(sp_uuids[1],
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700148 &ffa_expected_partition_info[1], 1), true);
Karl Meakinc884d6b2024-04-16 14:01:10 +0100149 EXPECT(ffa_partition_info_regs_helper(sp_uuids[0],
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700150 &ffa_expected_partition_info[0], 1), true);
151
152 /*
153 * Check partition information if there is support for SPMD EL3
154 * partitions. calling partition_info_get_regs with the SPMD EL3
155 * UUID successfully, indicates the presence of it (there is no
156 * spec defined way to discover presence of el3 spmd logical
157 * partitions). If the call fails with a not supported error,
158 * we assume they dont exist and skip further tests to avoid
159 * failures on platforms without el3 spmd logical partitions.
160 */
161 ret = ffa_partition_info_get_regs(sp_uuids[4], 0, 0);
162 if ((ffa_func_id(ret) == FFA_ERROR) &&
163 ((ffa_error_code(ret) == FFA_ERROR_NOT_SUPPORTED) ||
164 (ffa_error_code(ret) == FFA_ERROR_INVALID_PARAMETER))) {
165 INFO("Skipping register based EL3 SPMD Logical partition"
166 " discovery\n");
Karl Meakinc884d6b2024-04-16 14:01:10 +0100167 EXPECT(ffa_partition_info_regs_helper(NULL_UUID,
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700168 ffa_expected_partition_info,
169 (ARRAY_SIZE(ffa_expected_partition_info) - 1)), true);
170 } else {
Karl Meakinc884d6b2024-04-16 14:01:10 +0100171 EXPECT(ffa_partition_info_regs_helper(sp_uuids[4],
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700172 &ffa_expected_partition_info[4], 1), true);
Karl Meakinc884d6b2024-04-16 14:01:10 +0100173 EXPECT(ffa_partition_info_regs_helper(NULL_UUID,
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700174 ffa_expected_partition_info,
175 ARRAY_SIZE(ffa_expected_partition_info)), true);
176 }
177}
178
Max Shvetsovc32f4782020-06-23 09:41:15 +0100179static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
180{
J-Alves2279c1d2023-05-05 17:03:28 +0100181 INFO("Test FFA_PARTITION_INFO_GET.\n");
Max Shvetsovc32f4782020-06-23 09:41:15 +0100182
Karl Meakinc884d6b2024-04-16 14:01:10 +0100183 EXPECT(ffa_partition_info_helper(mb, sp_uuids[2],
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000184 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100185
Karl Meakinc884d6b2024-04-16 14:01:10 +0100186 EXPECT(ffa_partition_info_helper(mb, sp_uuids[1],
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000187 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100188
Karl Meakinc884d6b2024-04-16 14:01:10 +0100189 EXPECT(ffa_partition_info_helper(mb, sp_uuids[0],
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000190 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100191
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700192 /*
193 * TODO: ffa_partition_info_get_regs returns EL3 SPMD LP information
194 * but partition_info_get does not. Ignore the last entry, that is
195 * assumed to be the EL3 SPMD LP information. ffa_partition_info_get
196 * uses the rx/tx buffer and the SPMD does not support the use of
197 * rx/tx buffer to return SPMD logical partition information.
198 */
Karl Meakinc884d6b2024-04-16 14:01:10 +0100199 EXPECT(ffa_partition_info_helper(mb, NULL_UUID,
Varun Wadekar5c354822021-09-27 06:01:09 -0700200 ffa_expected_partition_info,
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700201 (ARRAY_SIZE(ffa_expected_partition_info) - 1)), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100202
203 ffa_partition_info_wrong_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100204}
205
Olivier Deprez2661ba52024-02-19 18:50:53 +0100206static void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100207{
Karl Meakin7308b122024-04-16 14:02:25 +0100208 struct ffa_value ret = ffa_version(FFA_VERSION_COMPILED);
Daniel Boulbyce386b12022-03-29 18:36:36 +0100209
210 spm_version = (uint32_t)ret.fid;
Karl Meakin7308b122024-04-16 14:02:25 +0100211 EXPECT(spm_version, FFA_VERSION_COMPILED);
J-Alves9f6f0142020-06-17 15:37:59 +0100212
Karl Meakin7308b122024-04-16 14:02:25 +0100213 bool compatible = ffa_versions_are_compatible(spm_version, FFA_VERSION_COMPILED);
J-Alves9f6f0142020-06-17 15:37:59 +0100214
J-Alves2279c1d2023-05-05 17:03:28 +0100215 INFO("Test FFA_VERSION. Return %u.%u; Compatible: %i\n",
Karl Meakin7308b122024-04-16 14:02:25 +0100216 ffa_version_get_major(spm_version),
217 ffa_version_get_minor(spm_version),
218 (int)compatible);
J-Alves9f6f0142020-06-17 15:37:59 +0100219
Karl Meakin7308b122024-04-16 14:02:25 +0100220 EXPECT((int)compatible, (int)true);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100221}
222
Olivier Deprez2661ba52024-02-19 18:50:53 +0100223static void ffa_spm_id_get_test(void)
Daniel Boulby198deda2021-03-03 11:35:25 +0000224{
Karl Meakin7308b122024-04-16 14:02:25 +0100225 if (spm_version >= FFA_VERSION_1_1) {
Daniel Boulbyce386b12022-03-29 18:36:36 +0100226 struct ffa_value ret = ffa_spm_id_get();
Daniel Boulby198deda2021-03-03 11:35:25 +0000227
Karl Meakinc884d6b2024-04-16 14:01:10 +0100228 EXPECT(ffa_func_id(ret), FFA_SUCCESS_SMC32);
Daniel Boulby198deda2021-03-03 11:35:25 +0000229
230 ffa_id_t spm_id = ffa_endpoint_id(ret);
231
J-Alves2279c1d2023-05-05 17:03:28 +0100232 INFO("Test FFA_SPM_ID_GET. Return: 0x%x\n", spm_id);
233
Daniel Boulby198deda2021-03-03 11:35:25 +0000234 /*
235 * Check the SPMC value given in the fvp_spmc_manifest
236 * is returned.
237 */
Karl Meakinc884d6b2024-04-16 14:01:10 +0100238 EXPECT(spm_id, SPMC_ID);
Daniel Boulby198deda2021-03-03 11:35:25 +0000239 } else {
J-Alves2279c1d2023-05-05 17:03:28 +0100240 INFO("FFA_SPM_ID_GET not supported in this version of FF-A."
Daniel Boulby198deda2021-03-03 11:35:25 +0000241 " Test skipped.\n");
242 }
Daniel Boulby198deda2021-03-03 11:35:25 +0000243}
244
J-Alves367154e2024-05-13 18:01:02 +0100245void ffa_tests(struct mailbox_buffers *mb, bool el1_partition)
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100246{
Olivier Deprez2661ba52024-02-19 18:50:53 +0100247 const char *test_ffa_str = "FF-A setup and discovery";
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100248
Olivier Deprez2661ba52024-02-19 18:50:53 +0100249 announce_test_section_start(test_ffa_str);
J-Alves9f6f0142020-06-17 15:37:59 +0100250
J-Alves367154e2024-05-13 18:01:02 +0100251 ffa_features_test(el1_partition);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100252 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000253 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100254 ffa_partition_info_get_test(mb);
Raghu Krishnamurthy9f864522023-04-23 16:19:10 -0700255 ffa_partition_info_get_regs_test();
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100256
Olivier Deprez2661ba52024-02-19 18:50:53 +0100257 announce_test_section_end(test_ffa_str);
J-Alves9f6f0142020-06-17 15:37:59 +0100258}