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 | }; |
| 27 | static const struct ffa_uuid null_uuid = { .uuid = {0} }; |
| 28 | |
| 29 | static 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-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 34 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | |
| 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, |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 43 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | |
| 44 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 45 | FFA_PARTITION_NOTIFICATION), |
| 46 | .uuid = sp_uuids[1] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 47 | }, |
| 48 | /* Tertiary partition info */ |
| 49 | { |
| 50 | .id = SP_ID(3), |
| 51 | .exec_context = TERTIARY_EXEC_CTX_COUNT, |
J-Alves | b69c8b4 | 2021-11-04 17:03:41 +0000 | [diff] [blame] | 52 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | |
| 53 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 54 | FFA_PARTITION_NOTIFICATION), |
| 55 | .uuid = sp_uuids[2] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 56 | }, |
| 57 | /* Ivy partition info */ |
| 58 | { |
| 59 | .id = SP_ID(4), |
| 60 | .exec_context = IVY_EXEC_CTX_COUNT, |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 61 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | |
| 62 | FFA_PARTITION_DIRECT_REQ_SEND), |
| 63 | .uuid = sp_uuids[3] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 64 | } |
| 65 | }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 66 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 67 | /* |
| 68 | * Test FFA_FEATURES interface. |
| 69 | */ |
| 70 | static void ffa_features_test(void) |
| 71 | { |
| 72 | const char *test_features = "FFA Features interface"; |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 73 | struct ffa_value ffa_ret; |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 74 | unsigned int expected_ret; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 75 | const struct ffa_features_test *ffa_feature_test_target; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 76 | unsigned int i, test_target_size = |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 77 | get_ffa_feature_test_target(&ffa_feature_test_target); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 78 | struct ffa_features_test test_target; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 79 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 80 | |
| 81 | announce_test_section_start(test_features); |
| 82 | |
| 83 | for (i = 0U; i < test_target_size; i++) { |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 84 | test_target = ffa_feature_test_target[i]; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 85 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 86 | 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-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 95 | expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 98 | announce_test_end(test_target.test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | announce_test_section_end(test_features); |
| 102 | } |
| 103 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 104 | static void ffa_partition_info_wrong_test(void) |
| 105 | { |
| 106 | const char *test_wrong_uuid = "Request wrong UUID"; |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 107 | const struct ffa_uuid uuid = { .uuid = {1} }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 108 | |
| 109 | announce_test_start(test_wrong_uuid); |
| 110 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 111 | struct ffa_value ret = ffa_partition_info_get(uuid); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 112 | expect(ffa_func_id(ret), FFA_ERROR); |
| 113 | expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 114 | |
| 115 | announce_test_end(test_wrong_uuid); |
| 116 | } |
| 117 | |
| 118 | static void ffa_partition_info_get_test(struct mailbox_buffers *mb) |
| 119 | { |
| 120 | const char *test_partition_info = "FFA Partition info interface"; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 121 | |
| 122 | announce_test_section_start(test_partition_info); |
| 123 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 124 | expect(ffa_partition_info_helper(mb, sp_uuids[2], |
| 125 | &ffa_expected_partition_info[2], 1), true); |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 126 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 127 | expect(ffa_partition_info_helper(mb, sp_uuids[1], |
| 128 | &ffa_expected_partition_info[1], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +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[0], |
| 131 | &ffa_expected_partition_info[0], 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, null_uuid, |
Varun Wadekar | 5c35482 | 2021-09-27 06:01:09 -0700 | [diff] [blame] | 134 | ffa_expected_partition_info, |
| 135 | ARRAY_SIZE(ffa_expected_partition_info)), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 136 | |
| 137 | ffa_partition_info_wrong_test(); |
| 138 | |
| 139 | announce_test_section_end(test_partition_info); |
| 140 | } |
| 141 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 142 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 143 | { |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 144 | const char *test_ffa_version = "FFA Version interface"; |
| 145 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 146 | announce_test_start(test_ffa_version); |
| 147 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 148 | struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, |
| 149 | FFA_MINOR)); |
| 150 | |
| 151 | spm_version = (uint32_t)ret.fid; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 152 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 153 | bool ffa_version_compatible = |
| 154 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 155 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 156 | |
Olivier Deprez | 24bd170 | 2021-10-05 14:35:17 +0200 | [diff] [blame] | 157 | VERBOSE("FFA_VERSION returned %u.%u; Compatible: %i\n", |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 158 | 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 Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 167 | void 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 Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 174 | struct ffa_value ret = ffa_spm_id_get(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 175 | |
| 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 Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 193 | void ffa_tests(struct mailbox_buffers *mb) |
| 194 | { |
| 195 | const char *test_ffa = "FFA Interfaces"; |
| 196 | |
| 197 | announce_test_section_start(test_ffa); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 198 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 199 | ffa_features_test(); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 200 | ffa_version_test(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 201 | ffa_spm_id_get_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 202 | ffa_partition_info_get_test(mb); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 203 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 204 | announce_test_section_end(test_ffa); |
| 205 | } |