blob: f81505a884a35ebdd30c8c098c084f0ebad54ad5 [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 };
27static const struct ffa_uuid null_uuid = { .uuid = {0} };
28
29static const struct ffa_partition_info ffa_expected_partition_info[] = {
30 /* Primary partition info */
31 {
32 .id = SP_ID(1),
33 .exec_context = PRIMARY_EXEC_CTX_COUNT,
J-Alves4d05dec2021-11-02 11:52:27 +000034 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
35 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,
J-Alves4d05dec2021-11-02 11:52:27 +000043 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
44 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000045 FFA_PARTITION_NOTIFICATION),
46 .uuid = sp_uuids[1]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000047 },
48 /* Tertiary partition info */
49 {
50 .id = SP_ID(3),
51 .exec_context = TERTIARY_EXEC_CTX_COUNT,
J-Alvesb69c8b42021-11-04 17:03:41 +000052 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
53 FFA_PARTITION_DIRECT_REQ_SEND |
Daniel Boulby8aa994c2022-01-05 19:44:30 +000054 FFA_PARTITION_NOTIFICATION),
55 .uuid = sp_uuids[2]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000056 },
57 /* Ivy partition info */
58 {
59 .id = SP_ID(4),
60 .exec_context = IVY_EXEC_CTX_COUNT,
Daniel Boulby8aa994c2022-01-05 19:44:30 +000061 .properties = (FFA_PARTITION_DIRECT_REQ_RECV |
62 FFA_PARTITION_DIRECT_REQ_SEND),
63 .uuid = sp_uuids[3]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000064 }
65};
Max Shvetsovc32f4782020-06-23 09:41:15 +010066
Max Shvetsov40eb6a22020-06-08 11:15:30 +010067/*
68 * Test FFA_FEATURES interface.
69 */
70static void ffa_features_test(void)
71{
72 const char *test_features = "FFA Features interface";
Daniel Boulbyce386b12022-03-29 18:36:36 +010073 struct ffa_value ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000074 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000075 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010076 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000077 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000078 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000079
Max Shvetsov40eb6a22020-06-08 11:15:30 +010080
81 announce_test_section_start(test_features);
82
83 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000084 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010085
Daniel Boulby198deda2021-03-03 11:35:25 +000086 announce_test_start(test_target.test_name);
87
88 ffa_ret = ffa_features(test_target.feature);
89 expected_ret = FFA_VERSION_COMPILED
90 >= test_target.version_added ?
91 test_target.expected_ret : FFA_ERROR;
92
93 expect(ffa_func_id(ffa_ret), expected_ret);
94 if (expected_ret == FFA_ERROR) {
J-Alves6cb21d92021-01-07 15:18:12 +000095 expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010096 }
97
Daniel Boulby198deda2021-03-03 11:35:25 +000098 announce_test_end(test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010099 }
100
101 announce_test_section_end(test_features);
102}
103
Max Shvetsovc32f4782020-06-23 09:41:15 +0100104static void ffa_partition_info_wrong_test(void)
105{
106 const char *test_wrong_uuid = "Request wrong UUID";
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000107 const struct ffa_uuid uuid = { .uuid = {1} };
Max Shvetsovc32f4782020-06-23 09:41:15 +0100108
109 announce_test_start(test_wrong_uuid);
110
Daniel Boulbyce386b12022-03-29 18:36:36 +0100111 struct ffa_value ret = ffa_partition_info_get(uuid);
J-Alves6cb21d92021-01-07 15:18:12 +0000112 expect(ffa_func_id(ret), FFA_ERROR);
113 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100114
115 announce_test_end(test_wrong_uuid);
116}
117
118static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
119{
120 const char *test_partition_info = "FFA Partition info interface";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100121
122 announce_test_section_start(test_partition_info);
123
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000124 expect(ffa_partition_info_helper(mb, sp_uuids[2],
125 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100126
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000127 expect(ffa_partition_info_helper(mb, sp_uuids[1],
128 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100129
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000130 expect(ffa_partition_info_helper(mb, sp_uuids[0],
131 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100132
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000133 expect(ffa_partition_info_helper(mb, null_uuid,
Varun Wadekar5c354822021-09-27 06:01:09 -0700134 ffa_expected_partition_info,
135 ARRAY_SIZE(ffa_expected_partition_info)), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100136
137 ffa_partition_info_wrong_test();
138
139 announce_test_section_end(test_partition_info);
140}
141
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100142void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100143{
J-Alves9f6f0142020-06-17 15:37:59 +0100144 const char *test_ffa_version = "FFA Version interface";
145
J-Alves9f6f0142020-06-17 15:37:59 +0100146 announce_test_start(test_ffa_version);
147
Daniel Boulbyce386b12022-03-29 18:36:36 +0100148 struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR,
149 FFA_MINOR));
150
151 spm_version = (uint32_t)ret.fid;
J-Alves9f6f0142020-06-17 15:37:59 +0100152
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100153 bool ffa_version_compatible =
154 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
155 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100156
Olivier Deprez24bd1702021-10-05 14:35:17 +0200157 VERBOSE("FFA_VERSION returned %u.%u; Compatible: %i\n",
J-Alves9f6f0142020-06-17 15:37:59 +0100158 spm_version >> FFA_VERSION_MAJOR_SHIFT,
159 spm_version & FFA_VERSION_MINOR_MASK,
160 (int)ffa_version_compatible);
161
162 expect((int)ffa_version_compatible, (int)true);
163
164 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100165}
166
Daniel Boulby198deda2021-03-03 11:35:25 +0000167void ffa_spm_id_get_test(void)
168{
169 const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function";
170
171 announce_test_start(test_spm_id_get);
172
173 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
Daniel Boulbyce386b12022-03-29 18:36:36 +0100174 struct ffa_value ret = ffa_spm_id_get();
Daniel Boulby198deda2021-03-03 11:35:25 +0000175
176 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
177
178 ffa_id_t spm_id = ffa_endpoint_id(ret);
179
180 VERBOSE("SPM ID = 0x%x\n", spm_id);
181 /*
182 * Check the SPMC value given in the fvp_spmc_manifest
183 * is returned.
184 */
185 expect(spm_id, SPMC_ID);
186 } else {
187 NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A."
188 " Test skipped.\n");
189 }
190 announce_test_end(test_spm_id_get);
191}
192
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100193void ffa_tests(struct mailbox_buffers *mb)
194{
195 const char *test_ffa = "FFA Interfaces";
196
197 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100198
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100199 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100200 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000201 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100202 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100203
J-Alves9f6f0142020-06-17 15:37:59 +0100204 announce_test_section_end(test_ffa);
205}