blob: ba069d0c62a2934f610169718ce78736de775e97 [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 Shvetsov0b7d25f2021-03-05 13:46:42 +000025static const struct ffa_uuid sp_uuids[] = {
26 {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID}
27 };
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,
35 .properties = (FFA_PARTITION_DIRECT_REQ_RECV | FFA_PARTITION_DIRECT_REQ_SEND)
36 },
37 /* Secondary partition info */
38 {
39 .id = SP_ID(2),
40 .exec_context = SECONDARY_EXEC_CTX_COUNT,
41 .properties = (FFA_PARTITION_DIRECT_REQ_RECV | FFA_PARTITION_DIRECT_REQ_SEND)
42 },
43 /* Tertiary partition info */
44 {
45 .id = SP_ID(3),
46 .exec_context = TERTIARY_EXEC_CTX_COUNT,
47 .properties = (FFA_PARTITION_DIRECT_REQ_RECV | FFA_PARTITION_DIRECT_REQ_SEND)
48 },
49 /* Ivy partition info */
50 {
51 .id = SP_ID(4),
52 .exec_context = IVY_EXEC_CTX_COUNT,
53 .properties = (FFA_PARTITION_DIRECT_REQ_RECV | FFA_PARTITION_DIRECT_REQ_SEND)
54 }
55};
Max Shvetsovc32f4782020-06-23 09:41:15 +010056
Max Shvetsov40eb6a22020-06-08 11:15:30 +010057/*
58 * Test FFA_FEATURES interface.
59 */
60static void ffa_features_test(void)
61{
62 const char *test_features = "FFA Features interface";
63 smc_ret_values ffa_ret;
Daniel Boulby198deda2021-03-03 11:35:25 +000064 unsigned int expected_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000065 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010066 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000067 get_ffa_feature_test_target(&ffa_feature_test_target);
Daniel Boulby198deda2021-03-03 11:35:25 +000068 struct ffa_features_test test_target;
Max Shvetsov103e0562021-02-04 16:58:31 +000069
Max Shvetsov40eb6a22020-06-08 11:15:30 +010070
71 announce_test_section_start(test_features);
72
73 for (i = 0U; i < test_target_size; i++) {
Daniel Boulby198deda2021-03-03 11:35:25 +000074 test_target = ffa_feature_test_target[i];
Max Shvetsov40eb6a22020-06-08 11:15:30 +010075
Daniel Boulby198deda2021-03-03 11:35:25 +000076 announce_test_start(test_target.test_name);
77
78 ffa_ret = ffa_features(test_target.feature);
79 expected_ret = FFA_VERSION_COMPILED
80 >= test_target.version_added ?
81 test_target.expected_ret : FFA_ERROR;
82
83 expect(ffa_func_id(ffa_ret), expected_ret);
84 if (expected_ret == FFA_ERROR) {
J-Alves6cb21d92021-01-07 15:18:12 +000085 expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010086 }
87
Daniel Boulby198deda2021-03-03 11:35:25 +000088 announce_test_end(test_target.test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010089 }
90
91 announce_test_section_end(test_features);
92}
93
Max Shvetsovc32f4782020-06-23 09:41:15 +010094static void ffa_partition_info_wrong_test(void)
95{
96 const char *test_wrong_uuid = "Request wrong UUID";
Max Shvetsov0b7d25f2021-03-05 13:46:42 +000097 const struct ffa_uuid uuid = { .uuid = {1} };
Max Shvetsovc32f4782020-06-23 09:41:15 +010098
99 announce_test_start(test_wrong_uuid);
100
101 smc_ret_values ret = ffa_partition_info_get(uuid);
J-Alves6cb21d92021-01-07 15:18:12 +0000102 expect(ffa_func_id(ret), FFA_ERROR);
103 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100104
105 announce_test_end(test_wrong_uuid);
106}
107
108static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
109{
110 const char *test_partition_info = "FFA Partition info interface";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100111
112 announce_test_section_start(test_partition_info);
113
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000114 expect(ffa_partition_info_helper(mb, sp_uuids[2],
115 &ffa_expected_partition_info[2], 1), true);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100116
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000117 expect(ffa_partition_info_helper(mb, sp_uuids[1],
118 &ffa_expected_partition_info[1], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100119
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000120 expect(ffa_partition_info_helper(mb, sp_uuids[0],
121 &ffa_expected_partition_info[0], 1), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100122
Max Shvetsov0b7d25f2021-03-05 13:46:42 +0000123 expect(ffa_partition_info_helper(mb, null_uuid,
124 ffa_expected_partition_info, 4), true);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100125
126 ffa_partition_info_wrong_test();
127
128 announce_test_section_end(test_partition_info);
129}
130
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100131void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100132{
J-Alves9f6f0142020-06-17 15:37:59 +0100133 const char *test_ffa_version = "FFA Version interface";
134
J-Alves9f6f0142020-06-17 15:37:59 +0100135 announce_test_start(test_ffa_version);
136
137 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Daniel Boulby198deda2021-03-03 11:35:25 +0000138 spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100139
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100140 bool ffa_version_compatible =
141 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
142 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100143
144 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
145 spm_version >> FFA_VERSION_MAJOR_SHIFT,
146 spm_version & FFA_VERSION_MINOR_MASK,
147 (int)ffa_version_compatible);
148
149 expect((int)ffa_version_compatible, (int)true);
150
151 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100152}
153
Daniel Boulby198deda2021-03-03 11:35:25 +0000154void ffa_spm_id_get_test(void)
155{
156 const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function";
157
158 announce_test_start(test_spm_id_get);
159
160 if (spm_version >= MAKE_FFA_VERSION(1, 1)) {
161 smc_ret_values ret = ffa_spm_id_get();
162
163 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
164
165 ffa_id_t spm_id = ffa_endpoint_id(ret);
166
167 VERBOSE("SPM ID = 0x%x\n", spm_id);
168 /*
169 * Check the SPMC value given in the fvp_spmc_manifest
170 * is returned.
171 */
172 expect(spm_id, SPMC_ID);
173 } else {
174 NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A."
175 " Test skipped.\n");
176 }
177 announce_test_end(test_spm_id_get);
178}
179
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100180void ffa_tests(struct mailbox_buffers *mb)
181{
182 const char *test_ffa = "FFA Interfaces";
183
184 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100185
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100186 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100187 ffa_version_test();
Daniel Boulby198deda2021-03-03 11:35:25 +0000188 ffa_spm_id_get_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100189 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100190
J-Alves9f6f0142020-06-17 15:37:59 +0100191 announce_test_section_end(test_ffa);
192}