blob: bca3984be13f80145293b1330e0568ad6ebd0014 [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
Max Shvetsovc32f4782020-06-23 09:41:15 +010010#include <cactus_def.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000011#include <cactus_platform_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-Alves9f6f0142020-06-17 15:37:59 +010016
J-Alves63cdaa72020-10-08 17:22:45 +010017#include <lib/libc/string.h>
J-Alves63cdaa72020-10-08 17:22:45 +010018
J-Alves9f6f0142020-06-17 15:37:59 +010019/* FFA version test helpers */
20#define FFA_MAJOR 1U
Daniel Boulby8aa994c2022-01-05 19:44:30 +000021#define FFA_MINOR 1U
J-Alves9f6f0142020-06-17 15:37:59 +010022
Daniel Boulby198deda2021-03-03 11:35:25 +000023static uint32_t spm_version;
24
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000025static const struct ffa_uuid sp_uuids[] = {
Daniel Boulby8aa994c2022-01-05 19:44:30 +000026 {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID}, {IVY_UUID}
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000027 };
28static const struct ffa_uuid null_uuid = { .uuid = {0} };
29
30static const struct ffa_partition_info ffa_expected_partition_info[] = {
31 /* Primary partition info */
32 {
33 .id = SP_ID(1),
34 .exec_context = PRIMARY_EXEC_CTX_COUNT,
J-Alves4d05dec2021-11-02 11:52:27 +000035 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
36 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000037 FFA_PARTITION_NOTIFICATION),
38 .uuid = sp_uuids[0]
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,
J-Alves4d05dec2021-11-02 11:52:27 +000044 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
45 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,
J-Alvesb69c8b42021-11-04 17:03:41 +000053 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
54 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000055 FFA_PARTITION_NOTIFICATION),
56 .uuid = sp_uuids[2]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000057 },
58 /* Ivy partition info */
59 {
60 .id = SP_ID(4),
61 .exec_context = IVY_EXEC_CTX_COUNT,
Daniel Boulby8aa994c2022-01-05 19:44:30 +000062 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
63 FFA_PARTITION_DIRECT_REQ_SEND),
64 .uuid = sp_uuids[3]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000065 }
66};
Max Shvetsovc32f4782020-06-23 09:41:15 +010067
Max Shvetsov40eb6a22020-06-08 11:15:30 +010068/*
69 * Test FFA_FEATURES interface.
70 */
71static void ffa_features_test(void)
72{
73 const char *test_features = "FFA Features interface";
74 smc_ret_values ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000075 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000076 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010077 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000078 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000079 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000080
Max Shvetsov40eb6a22020-06-08 11:15:30 +010081
82 announce_test_section_start(test_features);
83
84 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000085 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010086
Daniel Boulby198deda2021-03-03 11:35:25 +000087 announce_test_start(test_target.test_name);
88
89 ffa_ret = ffa_features(test_target.feature);
90 expected_ret = FFA_VERSION_COMPILED
91 >= test_target.version_added ?
92 test_target.expected_ret : FFA_ERROR;
93
94 expect(ffa_func_id(ffa_ret), expected_ret);
95 if (expected_ret == FFA_ERROR) {
J-Alves6cb21d92021-01-07 15:18:12 +000096 expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010097 }
98
Daniel Boulby198deda2021-03-03 11:35:25 +000099 announce_test_end(test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100100 }
101
102 announce_test_section_end(test_features);
103}
104
Max Shvetsovc32f4782020-06-23 09:41:15 +0100105static void ffa_partition_info_wrong_test(void)
106{
107 const char *test_wrong_uuid = "Request wrong UUID";
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000108 const struct ffa_uuid uuid = { .uuid = {1} };
Max Shvetsovc32f4782020-06-23 09:41:15 +0100109
110 announce_test_start(test_wrong_uuid);
111
112 smc_ret_values ret = ffa_partition_info_get(uuid);
J-Alves6cb21d92021-01-07 15:18:12 +0000113 expect(ffa_func_id(ret), FFA_ERROR);
114 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100115
116 announce_test_end(test_wrong_uuid);
117}
118
119static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
120{
121 const char *test_partition_info = "FFA Partition info interface";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100122
123 announce_test_section_start(test_partition_info);
124
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000125 expect(ffa_partition_info_helper(mb, sp_uuids[2],
126 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100127
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000128 expect(ffa_partition_info_helper(mb, sp_uuids[1],
129 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100130
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000131 expect(ffa_partition_info_helper(mb, sp_uuids[0],
132 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100133
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000134 expect(ffa_partition_info_helper(mb, null_uuid,
Varun Wadekar5c354822021-09-27 06:01:09 -0700135 ffa_expected_partition_info,
136 ARRAY_SIZE(ffa_expected_partition_info)), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100137
138 ffa_partition_info_wrong_test();
139
140 announce_test_section_end(test_partition_info);
141}
142
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100143void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100144{
J-Alves9f6f0142020-06-17 15:37:59 +0100145 const char *test_ffa_version = "FFA Version interface";
146
J-Alves9f6f0142020-06-17 15:37:59 +0100147 announce_test_start(test_ffa_version);
148
149 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Daniel Boulby198deda2021-03-03 11:35:25 +0000150 spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100151
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100152 bool ffa_version_compatible =
153 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
154 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100155
Olivier Deprez24bd1702021-10-05 14:35:17 +0200156 VERBOSE("FFA_VERSION returned %u.%u; Compatible: %i\n",
J-Alves9f6f0142020-06-17 15:37:59 +0100157 spm_version >> FFA_VERSION_MAJOR_SHIFT,
158 spm_version & FFA_VERSION_MINOR_MASK,
159 (int)ffa_version_compatible);
160
161 expect((int)ffa_version_compatible, (int)true);
162
163 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100164}
165
Daniel Boulby198deda2021-03-03 11:35:25 +0000166void ffa_spm_id_get_test(void)
167{
168 const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function";
169
170 announce_test_start(test_spm_id_get);
171
172 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
173 smc_ret_values ret = ffa_spm_id_get();
174
175 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
176
177 ffa_id_t spm_id = ffa_endpoint_id(ret);
178
179 VERBOSE("SPM ID = 0x%x\n", spm_id);
180 /*
181 * Check the SPMC value given in the fvp_spmc_manifest
182 * is returned.
183 */
184 expect(spm_id, SPMC_ID);
185 } else {
186 NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A."
187 " Test skipped.\n");
188 }
189 announce_test_end(test_spm_id_get);
190}
191
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100192void 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();
Daniel Boulby198deda2021-03-03 11:35:25 +0000200 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100201 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100202
J-Alves9f6f0142020-06-17 15:37:59 +0100203 announce_test_section_end(test_ffa);
204}