blob: f08f5f326e7d714315d9280e93dc38e06a71a5bf [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-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 };
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000028
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,
Kathleen Capella7774d6e2022-11-23 19:06:21 -050034 .properties = (FFA_PARTITION_AARCH64_EXEC |
35 FFA_PARTITION_DIRECT_REQ_RECV |
J-Alves4d05dec2021-11-02 11:52:27 +000036 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,
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),
48 .uuid = sp_uuids[1]
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),
58 .uuid = sp_uuids[2]
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),
67 .uuid = sp_uuids[3]
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000068 }
69};
Max Shvetsovc32f4782020-06-23 09:41:15 +010070
Max Shvetsov40eb6a22020-06-08 11:15:30 +010071/*
72 * Test FFA_FEATURES interface.
73 */
74static void ffa_features_test(void)
75{
Daniel Boulbyce386b12022-03-29 18:36:36 +010076 struct ffa_value ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000077 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000078 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010079 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000080 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000081 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000082
J-Alves2279c1d2023-05-05 17:03:28 +010083 INFO("Test FFA_FEATURES.\n");
Max Shvetsov40eb6a22020-06-08 11:15:30 +010084
85 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000086 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010087
J-Alves2279c1d2023-05-05 17:03:28 +010088 ffa_ret = ffa_features_with_input_property(test_target.feature,
89 test_target.param);
Daniel Boulby198deda2021-03-03 11:35:25 +000090 expected_ret = FFA_VERSION_COMPILED
91 >= test_target.version_added ?
92 test_target.expected_ret : FFA_ERROR;
93
J-Alves2279c1d2023-05-05 17:03:28 +010094 if (ffa_func_id(ffa_ret) != expected_ret) {
95 ERROR("Unexpected return: %x (expected %x)."
96 " FFA_FEATURES test: %s.\n",
97 ffa_func_id(ffa_ret), expected_ret,
98 test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010099 }
100
J-Alves2279c1d2023-05-05 17:03:28 +0100101 if (expected_ret == FFA_ERROR) {
102 if (ffa_error_code(ffa_ret) !=
103 FFA_ERROR_NOT_SUPPORTED) {
104 ERROR("Unexpected error code: %x (expected %x)."
105 " FFA_FEATURES test: %s.\n",
106 ffa_error_code(ffa_ret), expected_ret,
107 test_target.test_name);
108 }
109 }
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100110 }
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100111}
112
Max Shvetsovc32f4782020-06-23 09:41:15 +0100113static void ffa_partition_info_wrong_test(void)
114{
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000115 const struct ffa_uuid uuid = { .uuid = {1} };
Daniel Boulbyce386b12022-03-29 18:36:36 +0100116 struct ffa_value ret = ffa_partition_info_get(uuid);
J-Alves2279c1d2023-05-05 17:03:28 +0100117
118 VERBOSE("%s: test request wrong UUID.\n", __func__);
119
J-Alves6cb21d92021-01-07 15:18:12 +0000120 expect(ffa_func_id(ret), FFA_ERROR);
121 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100122}
123
124static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
125{
J-Alves2279c1d2023-05-05 17:03:28 +0100126 INFO("Test FFA_PARTITION_INFO_GET.\n");
Max Shvetsovc32f4782020-06-23 09:41:15 +0100127
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000128 expect(ffa_partition_info_helper(mb, sp_uuids[2],
129 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100130
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000131 expect(ffa_partition_info_helper(mb, sp_uuids[1],
132 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100133
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000134 expect(ffa_partition_info_helper(mb, sp_uuids[0],
135 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100136
Daniel Boulby4a2888a2022-05-31 16:07:36 +0100137 expect(ffa_partition_info_helper(mb, NULL_UUID,
Varun Wadekar5c354822021-09-27 06:01:09 -0700138 ffa_expected_partition_info,
139 ARRAY_SIZE(ffa_expected_partition_info)), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100140
141 ffa_partition_info_wrong_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100142}
143
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100144void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100145{
Daniel Boulbyce386b12022-03-29 18:36:36 +0100146 struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR,
147 FFA_MINOR));
148
149 spm_version = (uint32_t)ret.fid;
J-Alves9f6f0142020-06-17 15:37:59 +0100150
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100151 bool ffa_version_compatible =
152 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
153 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100154
J-Alves2279c1d2023-05-05 17:03:28 +0100155 INFO("Test FFA_VERSION. Return %u.%u; Compatible: %i\n",
J-Alves9f6f0142020-06-17 15:37:59 +0100156 spm_version >> FFA_VERSION_MAJOR_SHIFT,
157 spm_version & FFA_VERSION_MINOR_MASK,
158 (int)ffa_version_compatible);
159
160 expect((int)ffa_version_compatible, (int)true);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100161}
162
Daniel Boulby198deda2021-03-03 11:35:25 +0000163void ffa_spm_id_get_test(void)
164{
Daniel Boulby198deda2021-03-03 11:35:25 +0000165 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
Daniel Boulbyce386b12022-03-29 18:36:36 +0100166 struct ffa_value ret = ffa_spm_id_get();
Daniel Boulby198deda2021-03-03 11:35:25 +0000167
168 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
169
170 ffa_id_t spm_id = ffa_endpoint_id(ret);
171
J-Alves2279c1d2023-05-05 17:03:28 +0100172 INFO("Test FFA_SPM_ID_GET. Return: 0x%x\n", spm_id);
173
Daniel Boulby198deda2021-03-03 11:35:25 +0000174 /*
175 * Check the SPMC value given in the fvp_spmc_manifest
176 * is returned.
177 */
178 expect(spm_id, SPMC_ID);
179 } else {
J-Alves2279c1d2023-05-05 17:03:28 +0100180 INFO("FFA_SPM_ID_GET not supported in this version of FF-A."
Daniel Boulby198deda2021-03-03 11:35:25 +0000181 " Test skipped.\n");
182 }
Daniel Boulby198deda2021-03-03 11:35:25 +0000183}
184
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100185void ffa_tests(struct mailbox_buffers *mb)
186{
J-Alves2279c1d2023-05-05 17:03:28 +0100187 const char *test_ffa = "FF-A setup and discovery";
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100188
189 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100190
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100191 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100192 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000193 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100194 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100195
J-Alves9f6f0142020-06-17 15:37:59 +0100196 announce_test_section_end(test_ffa);
197}