blob: 93f04033df7d015b7d83b7ac0cbe007180249254 [file] [log] [blame]
J-Alves9f6f0142020-06-17 15:37:59 +01001/*
Max Shvetsov103e0562021-02-04 16:58:31 +00002 * Copyright (c) 2018-2021, 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
21#define FFA_MINOR 0U
22
Daniel Boulby198deda2021-03-03 11:35:25 +000023static uint32_t spm_version;
24
Max Shvetsovc32f4782020-06-23 09:41:15 +010025static const uint32_t primary_uuid[4] = PRIMARY_UUID;
26static const uint32_t secondary_uuid[4] = SECONDARY_UUID;
Ruari Phippsd75596a2020-07-17 16:41:34 +010027static const uint32_t tertiary_uuid[4] = TERTIARY_UUID;
Max Shvetsovc32f4782020-06-23 09:41:15 +010028static const uint32_t null_uuid[4] = {0};
29
Max Shvetsov40eb6a22020-06-08 11:15:30 +010030/*
31 * Test FFA_FEATURES interface.
32 */
33static void ffa_features_test(void)
34{
35 const char *test_features = "FFA Features interface";
36 smc_ret_values ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000037 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000038 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010039 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000040 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000041 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000042
Max Shvetsov40eb6a22020-06-08 11:15:30 +010043
44 announce_test_section_start(test_features);
45
46 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000047 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010048
Daniel Boulby198deda2021-03-03 11:35:25 +000049 announce_test_start(test_target.test_name);
50
51 ffa_ret = ffa_features(test_target.feature);
52 expected_ret = FFA_VERSION_COMPILED
53 >= test_target.version_added ?
54 test_target.expected_ret : FFA_ERROR;
55
56 expect(ffa_func_id(ffa_ret), expected_ret);
57 if (expected_ret == FFA_ERROR) {
J-Alves6cb21d92021-01-07 15:18:12 +000058 expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010059 }
60
Daniel Boulby198deda2021-03-03 11:35:25 +000061 announce_test_end(test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010062 }
63
64 announce_test_section_end(test_features);
65}
66
Max Shvetsovc32f4782020-06-23 09:41:15 +010067static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4],
68 const struct ffa_partition_info *expected,
69 const uint16_t expected_size)
70{
71 smc_ret_values ret = ffa_partition_info_get(uuid);
72 unsigned int i;
J-Alves6cb21d92021-01-07 15:18:12 +000073 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
Max Shvetsovc32f4782020-06-23 09:41:15 +010074
75 struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv);
76 for (i = 0U; i < expected_size; i++) {
77 expect(info[i].id, expected[i].id);
78 expect(info[i].exec_context, expected[i].exec_context);
79 expect(info[i].properties, expected[i].properties);
80 }
81
82 ret = ffa_rx_release();
J-Alves6cb21d92021-01-07 15:18:12 +000083 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
Max Shvetsovc32f4782020-06-23 09:41:15 +010084}
85
86static void ffa_partition_info_wrong_test(void)
87{
88 const char *test_wrong_uuid = "Request wrong UUID";
89 uint32_t uuid[4] = {1};
90
91 announce_test_start(test_wrong_uuid);
92
93 smc_ret_values ret = ffa_partition_info_get(uuid);
J-Alves6cb21d92021-01-07 15:18:12 +000094 expect(ffa_func_id(ret), FFA_ERROR);
95 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +010096
97 announce_test_end(test_wrong_uuid);
98}
99
100static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
101{
102 const char *test_partition_info = "FFA Partition info interface";
103 const char *test_primary = "Get primary partition info";
104 const char *test_secondary = "Get secondary partition info";
Ruari Phippsd75596a2020-07-17 16:41:34 +0100105 const char *test_tertiary = "Get tertiary partition info";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100106 const char *test_all = "Get all partitions info";
107
108 const struct ffa_partition_info expected_info[] = {
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100109 /* Primary partition info */
110 {
111 .id = SPM_VM_ID_FIRST,
112 .exec_context = CACTUS_PRIMARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200113 /* Supports receipt of direct message requests. */
114 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100115 },
116 /* Secondary partition info */
117 {
118 .id = SPM_VM_ID_FIRST + 1U,
119 .exec_context = CACTUS_SECONDARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200120 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100121 },
122 /* Tertiary partition info */
123 {
124 .id = SPM_VM_ID_FIRST + 2U,
125 .exec_context = CACTUS_TERTIARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200126 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100127 }
Max Shvetsovc32f4782020-06-23 09:41:15 +0100128 };
129
130 announce_test_section_start(test_partition_info);
131
Ruari Phippsd75596a2020-07-17 16:41:34 +0100132 announce_test_start(test_tertiary);
133 ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1);
134 announce_test_end(test_tertiary);
135
Max Shvetsovc32f4782020-06-23 09:41:15 +0100136 announce_test_start(test_secondary);
137 ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1);
138 announce_test_end(test_secondary);
139
140 announce_test_start(test_primary);
141 ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1);
142 announce_test_end(test_primary);
143
144 announce_test_start(test_all);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100145 ffa_partition_info_helper(mb, null_uuid, expected_info, 3);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100146 announce_test_end(test_all);
147
148 ffa_partition_info_wrong_test();
149
150 announce_test_section_end(test_partition_info);
151}
152
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100153void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100154{
J-Alves9f6f0142020-06-17 15:37:59 +0100155 const char *test_ffa_version = "FFA Version interface";
156
J-Alves9f6f0142020-06-17 15:37:59 +0100157 announce_test_start(test_ffa_version);
158
159 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Daniel Boulby198deda2021-03-03 11:35:25 +0000160 spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100161
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100162 bool ffa_version_compatible =
163 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
164 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100165
166 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
167 spm_version >> FFA_VERSION_MAJOR_SHIFT,
168 spm_version & FFA_VERSION_MINOR_MASK,
169 (int)ffa_version_compatible);
170
171 expect((int)ffa_version_compatible, (int)true);
172
173 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100174}
175
Daniel Boulby198deda2021-03-03 11:35:25 +0000176void ffa_spm_id_get_test(void)
177{
178 const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function";
179
180 announce_test_start(test_spm_id_get);
181
182 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
183 smc_ret_values ret = ffa_spm_id_get();
184
185 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
186
187 ffa_id_t spm_id = ffa_endpoint_id(ret);
188
189 VERBOSE("SPM ID = 0x%x\n", spm_id);
190 /*
191 * Check the SPMC value given in the fvp_spmc_manifest
192 * is returned.
193 */
194 expect(spm_id, SPMC_ID);
195 } else {
196 NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A."
197 " Test skipped.\n");
198 }
199 announce_test_end(test_spm_id_get);
200}
201
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100202void ffa_tests(struct mailbox_buffers *mb)
203{
204 const char *test_ffa = "FFA Interfaces";
205
206 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100207
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100208 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100209 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000210 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100211 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100212
J-Alves9f6f0142020-06-17 15:37:59 +0100213 announce_test_section_end(test_ffa);
214}