J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 1 | /* |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 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 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 10 | #include <cactus_def.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 11 | #include <cactus_platform_def.h> |
J-Alves | 8f4a56f | 2020-10-28 10:29:05 +0000 | [diff] [blame] | 12 | #include <ffa_endpoints.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 13 | #include <sp_helpers.h> |
Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame] | 14 | #include <spm_helpers.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 15 | #include <spm_common.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 16 | |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 17 | #include <lib/libc/string.h> |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 18 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 19 | /* FFA version test helpers */ |
| 20 | #define FFA_MAJOR 1U |
| 21 | #define FFA_MINOR 0U |
| 22 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 23 | static uint32_t spm_version; |
| 24 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 25 | static const uint32_t primary_uuid[4] = PRIMARY_UUID; |
| 26 | static const uint32_t secondary_uuid[4] = SECONDARY_UUID; |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 27 | static const uint32_t tertiary_uuid[4] = TERTIARY_UUID; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 28 | static const uint32_t null_uuid[4] = {0}; |
| 29 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 30 | /* |
| 31 | * Test FFA_FEATURES interface. |
| 32 | */ |
| 33 | static void ffa_features_test(void) |
| 34 | { |
| 35 | const char *test_features = "FFA Features interface"; |
| 36 | smc_ret_values ffa_ret; |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 37 | unsigned int expected_ret; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 38 | const struct ffa_features_test *ffa_feature_test_target; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 39 | unsigned int i, test_target_size = |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 40 | get_ffa_feature_test_target(&ffa_feature_test_target); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 41 | struct ffa_features_test test_target; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 42 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 43 | |
| 44 | announce_test_section_start(test_features); |
| 45 | |
| 46 | for (i = 0U; i < test_target_size; i++) { |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 47 | test_target = ffa_feature_test_target[i]; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 48 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 49 | 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-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 58 | expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 61 | announce_test_end(test_target.test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | announce_test_section_end(test_features); |
| 65 | } |
| 66 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 67 | static 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-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 73 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 74 | |
| 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-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 83 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static 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-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 94 | expect(ffa_func_id(ret), FFA_ERROR); |
| 95 | expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 96 | |
| 97 | announce_test_end(test_wrong_uuid); |
| 98 | } |
| 99 | |
| 100 | static 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 Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 105 | const char *test_tertiary = "Get tertiary partition info"; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 106 | const char *test_all = "Get all partitions info"; |
| 107 | |
| 108 | const struct ffa_partition_info expected_info[] = { |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 109 | /* Primary partition info */ |
| 110 | { |
| 111 | .id = SPM_VM_ID_FIRST, |
| 112 | .exec_context = CACTUS_PRIMARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 113 | /* Supports receipt of direct message requests. */ |
| 114 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 115 | }, |
| 116 | /* Secondary partition info */ |
| 117 | { |
| 118 | .id = SPM_VM_ID_FIRST + 1U, |
| 119 | .exec_context = CACTUS_SECONDARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 120 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 121 | }, |
| 122 | /* Tertiary partition info */ |
| 123 | { |
| 124 | .id = SPM_VM_ID_FIRST + 2U, |
| 125 | .exec_context = CACTUS_TERTIARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 126 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 127 | } |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | announce_test_section_start(test_partition_info); |
| 131 | |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 132 | 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 Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 136 | 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 Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 145 | ffa_partition_info_helper(mb, null_uuid, expected_info, 3); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 146 | announce_test_end(test_all); |
| 147 | |
| 148 | ffa_partition_info_wrong_test(); |
| 149 | |
| 150 | announce_test_section_end(test_partition_info); |
| 151 | } |
| 152 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 153 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 154 | { |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 155 | const char *test_ffa_version = "FFA Version interface"; |
| 156 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 157 | announce_test_start(test_ffa_version); |
| 158 | |
| 159 | smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR)); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 160 | spm_version = (uint32_t)ret.ret0; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 161 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 162 | bool ffa_version_compatible = |
| 163 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 164 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 165 | |
| 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 Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 176 | void 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 Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 202 | void ffa_tests(struct mailbox_buffers *mb) |
| 203 | { |
| 204 | const char *test_ffa = "FFA Interfaces"; |
| 205 | |
| 206 | announce_test_section_start(test_ffa); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 207 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 208 | ffa_features_test(); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 209 | ffa_version_test(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 210 | ffa_spm_id_get_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 211 | ffa_partition_info_get_test(mb); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 212 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 213 | announce_test_section_end(test_ffa); |
| 214 | } |