J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 1 | /* |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <assert.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 7 | #include <debug.h> |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 8 | #include <errno.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 9 | |
Daniel Boulby | f3da591 | 2022-04-01 12:31:52 +0100 | [diff] [blame] | 10 | #include <sp_def.h> |
J-Alves | 8f4a56f | 2020-10-28 10:29:05 +0000 | [diff] [blame] | 11 | #include <ffa_endpoints.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 12 | #include <sp_helpers.h> |
Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame] | 13 | #include <spm_helpers.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 14 | #include <spm_common.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 15 | |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 16 | #include <lib/libc/string.h> |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 17 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 18 | /* FFA version test helpers */ |
| 19 | #define FFA_MAJOR 1U |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 20 | #define FFA_MINOR 1U |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 21 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 22 | static uint32_t spm_version; |
| 23 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 24 | static const struct ffa_uuid sp_uuids[] = { |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 25 | {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID}, {IVY_UUID} |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 26 | }; |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 27 | |
| 28 | static const struct ffa_partition_info ffa_expected_partition_info[] = { |
| 29 | /* Primary partition info */ |
| 30 | { |
| 31 | .id = SP_ID(1), |
| 32 | .exec_context = PRIMARY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame^] | 33 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 34 | FFA_PARTITION_DIRECT_REQ_RECV | |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 35 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 36 | FFA_PARTITION_NOTIFICATION), |
| 37 | .uuid = sp_uuids[0] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 38 | }, |
| 39 | /* Secondary partition info */ |
| 40 | { |
| 41 | .id = SP_ID(2), |
| 42 | .exec_context = SECONDARY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame^] | 43 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 44 | FFA_PARTITION_DIRECT_REQ_RECV | |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 45 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 46 | FFA_PARTITION_NOTIFICATION), |
| 47 | .uuid = sp_uuids[1] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 48 | }, |
| 49 | /* Tertiary partition info */ |
| 50 | { |
| 51 | .id = SP_ID(3), |
| 52 | .exec_context = TERTIARY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame^] | 53 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 54 | FFA_PARTITION_DIRECT_REQ_RECV | |
J-Alves | b69c8b4 | 2021-11-04 17:03:41 +0000 | [diff] [blame] | 55 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 56 | FFA_PARTITION_NOTIFICATION), |
| 57 | .uuid = sp_uuids[2] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 58 | }, |
| 59 | /* Ivy partition info */ |
| 60 | { |
| 61 | .id = SP_ID(4), |
| 62 | .exec_context = IVY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame^] | 63 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 64 | FFA_PARTITION_DIRECT_REQ_RECV | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 65 | FFA_PARTITION_DIRECT_REQ_SEND), |
| 66 | .uuid = sp_uuids[3] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 67 | } |
| 68 | }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 69 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 70 | /* |
| 71 | * Test FFA_FEATURES interface. |
| 72 | */ |
| 73 | static void ffa_features_test(void) |
| 74 | { |
| 75 | const char *test_features = "FFA Features interface"; |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 76 | struct ffa_value ffa_ret; |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 77 | unsigned int expected_ret; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 78 | const struct ffa_features_test *ffa_feature_test_target; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 79 | unsigned int i, test_target_size = |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 80 | get_ffa_feature_test_target(&ffa_feature_test_target); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 81 | struct ffa_features_test test_target; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 82 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 83 | |
| 84 | announce_test_section_start(test_features); |
| 85 | |
| 86 | for (i = 0U; i < test_target_size; i++) { |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 87 | test_target = ffa_feature_test_target[i]; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 88 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 89 | announce_test_start(test_target.test_name); |
| 90 | |
| 91 | ffa_ret = ffa_features(test_target.feature); |
| 92 | expected_ret = FFA_VERSION_COMPILED |
| 93 | >= test_target.version_added ? |
| 94 | test_target.expected_ret : FFA_ERROR; |
| 95 | |
| 96 | expect(ffa_func_id(ffa_ret), expected_ret); |
| 97 | if (expected_ret == FFA_ERROR) { |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 98 | expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 101 | announce_test_end(test_target.test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | announce_test_section_end(test_features); |
| 105 | } |
| 106 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 107 | static void ffa_partition_info_wrong_test(void) |
| 108 | { |
| 109 | const char *test_wrong_uuid = "Request wrong UUID"; |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 110 | const struct ffa_uuid uuid = { .uuid = {1} }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 111 | |
| 112 | announce_test_start(test_wrong_uuid); |
| 113 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 114 | struct ffa_value ret = ffa_partition_info_get(uuid); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 115 | expect(ffa_func_id(ret), FFA_ERROR); |
| 116 | expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 117 | |
| 118 | announce_test_end(test_wrong_uuid); |
| 119 | } |
| 120 | |
| 121 | static void ffa_partition_info_get_test(struct mailbox_buffers *mb) |
| 122 | { |
| 123 | const char *test_partition_info = "FFA Partition info interface"; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 124 | |
| 125 | announce_test_section_start(test_partition_info); |
| 126 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 127 | expect(ffa_partition_info_helper(mb, sp_uuids[2], |
| 128 | &ffa_expected_partition_info[2], 1), true); |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 129 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 130 | expect(ffa_partition_info_helper(mb, sp_uuids[1], |
| 131 | &ffa_expected_partition_info[1], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 132 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 133 | expect(ffa_partition_info_helper(mb, sp_uuids[0], |
| 134 | &ffa_expected_partition_info[0], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 135 | |
Daniel Boulby | 4a2888a | 2022-05-31 16:07:36 +0100 | [diff] [blame] | 136 | expect(ffa_partition_info_helper(mb, NULL_UUID, |
Varun Wadekar | 5c35482 | 2021-09-27 06:01:09 -0700 | [diff] [blame] | 137 | ffa_expected_partition_info, |
| 138 | ARRAY_SIZE(ffa_expected_partition_info)), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 139 | |
| 140 | ffa_partition_info_wrong_test(); |
| 141 | |
| 142 | announce_test_section_end(test_partition_info); |
| 143 | } |
| 144 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 145 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 146 | { |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 147 | const char *test_ffa_version = "FFA Version interface"; |
| 148 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 149 | announce_test_start(test_ffa_version); |
| 150 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 151 | struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, |
| 152 | FFA_MINOR)); |
| 153 | |
| 154 | spm_version = (uint32_t)ret.fid; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 155 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 156 | bool ffa_version_compatible = |
| 157 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 158 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 159 | |
Olivier Deprez | 24bd170 | 2021-10-05 14:35:17 +0200 | [diff] [blame] | 160 | VERBOSE("FFA_VERSION returned %u.%u; Compatible: %i\n", |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 161 | spm_version >> FFA_VERSION_MAJOR_SHIFT, |
| 162 | spm_version & FFA_VERSION_MINOR_MASK, |
| 163 | (int)ffa_version_compatible); |
| 164 | |
| 165 | expect((int)ffa_version_compatible, (int)true); |
| 166 | |
| 167 | announce_test_end(test_ffa_version); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 170 | void ffa_spm_id_get_test(void) |
| 171 | { |
| 172 | const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function"; |
| 173 | |
| 174 | announce_test_start(test_spm_id_get); |
| 175 | |
| 176 | if (spm_version >= MAKE_FFA_VERSION(1, 1)) { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 177 | struct ffa_value ret = ffa_spm_id_get(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 178 | |
| 179 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
| 180 | |
| 181 | ffa_id_t spm_id = ffa_endpoint_id(ret); |
| 182 | |
| 183 | VERBOSE("SPM ID = 0x%x\n", spm_id); |
| 184 | /* |
| 185 | * Check the SPMC value given in the fvp_spmc_manifest |
| 186 | * is returned. |
| 187 | */ |
| 188 | expect(spm_id, SPMC_ID); |
| 189 | } else { |
| 190 | NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A." |
| 191 | " Test skipped.\n"); |
| 192 | } |
| 193 | announce_test_end(test_spm_id_get); |
| 194 | } |
| 195 | |
Maksims Svecovs | 0b45223 | 2022-05-24 11:30:34 +0100 | [diff] [blame] | 196 | void ffa_console_log_test(void) |
| 197 | { |
| 198 | const char *test_name = "FFA_CONSOLE_LOG SMC Function"; |
| 199 | announce_test_start(test_name); |
| 200 | |
| 201 | const char test_string[] = "[FFA_CONSOLE_LOG]: Hello World!\n"; |
| 202 | struct ffa_value ret = ffa_console_log(test_string, sizeof(test_string)); |
| 203 | |
| 204 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
| 205 | |
| 206 | announce_test_end(test_name); |
| 207 | } |
| 208 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 209 | void ffa_tests(struct mailbox_buffers *mb) |
| 210 | { |
| 211 | const char *test_ffa = "FFA Interfaces"; |
| 212 | |
| 213 | announce_test_section_start(test_ffa); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 214 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 215 | ffa_features_test(); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 216 | ffa_version_test(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 217 | ffa_spm_id_get_test(); |
Maksims Svecovs | 0b45223 | 2022-05-24 11:30:34 +0100 | [diff] [blame] | 218 | ffa_console_log_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 219 | ffa_partition_info_get_test(mb); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 220 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 221 | announce_test_section_end(test_ffa); |
| 222 | } |