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 | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 25 | static const struct ffa_uuid sp_uuids[] = { |
| 26 | {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID} |
| 27 | }; |
| 28 | static const struct ffa_uuid null_uuid = { .uuid = {0} }; |
| 29 | |
| 30 | static 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, |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame^] | 35 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | |
| 36 | FFA_PARTITION_DIRECT_REQ_SEND | |
| 37 | FFA_PARTITION_NOTIFICATION) |
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 | |
| 45 | FFA_PARTITION_NOTIFICATION) |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 46 | }, |
| 47 | /* Tertiary partition info */ |
| 48 | { |
| 49 | .id = SP_ID(3), |
| 50 | .exec_context = TERTIARY_EXEC_CTX_COUNT, |
| 51 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | FFA_PARTITION_DIRECT_REQ_SEND) |
| 52 | }, |
| 53 | /* Ivy partition info */ |
| 54 | { |
| 55 | .id = SP_ID(4), |
| 56 | .exec_context = IVY_EXEC_CTX_COUNT, |
| 57 | .properties = (FFA_PARTITION_DIRECT_REQ_RECV | FFA_PARTITION_DIRECT_REQ_SEND) |
| 58 | } |
| 59 | }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 60 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 61 | /* |
| 62 | * Test FFA_FEATURES interface. |
| 63 | */ |
| 64 | static void ffa_features_test(void) |
| 65 | { |
| 66 | const char *test_features = "FFA Features interface"; |
| 67 | smc_ret_values ffa_ret; |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 68 | unsigned int expected_ret; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 69 | const struct ffa_features_test *ffa_feature_test_target; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 70 | unsigned int i, test_target_size = |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 71 | get_ffa_feature_test_target(&ffa_feature_test_target); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 72 | struct ffa_features_test test_target; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 73 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 74 | |
| 75 | announce_test_section_start(test_features); |
| 76 | |
| 77 | for (i = 0U; i < test_target_size; i++) { |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 78 | test_target = ffa_feature_test_target[i]; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 79 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 80 | announce_test_start(test_target.test_name); |
| 81 | |
| 82 | ffa_ret = ffa_features(test_target.feature); |
| 83 | expected_ret = FFA_VERSION_COMPILED |
| 84 | >= test_target.version_added ? |
| 85 | test_target.expected_ret : FFA_ERROR; |
| 86 | |
| 87 | expect(ffa_func_id(ffa_ret), expected_ret); |
| 88 | if (expected_ret == FFA_ERROR) { |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 89 | expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 92 | announce_test_end(test_target.test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | announce_test_section_end(test_features); |
| 96 | } |
| 97 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 98 | static void ffa_partition_info_wrong_test(void) |
| 99 | { |
| 100 | const char *test_wrong_uuid = "Request wrong UUID"; |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 101 | const struct ffa_uuid uuid = { .uuid = {1} }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 102 | |
| 103 | announce_test_start(test_wrong_uuid); |
| 104 | |
| 105 | smc_ret_values ret = ffa_partition_info_get(uuid); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 106 | expect(ffa_func_id(ret), FFA_ERROR); |
| 107 | expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 108 | |
| 109 | announce_test_end(test_wrong_uuid); |
| 110 | } |
| 111 | |
| 112 | static void ffa_partition_info_get_test(struct mailbox_buffers *mb) |
| 113 | { |
| 114 | const char *test_partition_info = "FFA Partition info interface"; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 115 | |
| 116 | announce_test_section_start(test_partition_info); |
| 117 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 118 | expect(ffa_partition_info_helper(mb, sp_uuids[2], |
| 119 | &ffa_expected_partition_info[2], 1), true); |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 120 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 121 | expect(ffa_partition_info_helper(mb, sp_uuids[1], |
| 122 | &ffa_expected_partition_info[1], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 123 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 124 | expect(ffa_partition_info_helper(mb, sp_uuids[0], |
| 125 | &ffa_expected_partition_info[0], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 126 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 127 | expect(ffa_partition_info_helper(mb, null_uuid, |
Varun Wadekar | 5c35482 | 2021-09-27 06:01:09 -0700 | [diff] [blame] | 128 | ffa_expected_partition_info, |
| 129 | ARRAY_SIZE(ffa_expected_partition_info)), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 130 | |
| 131 | ffa_partition_info_wrong_test(); |
| 132 | |
| 133 | announce_test_section_end(test_partition_info); |
| 134 | } |
| 135 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 136 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 137 | { |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 138 | const char *test_ffa_version = "FFA Version interface"; |
| 139 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 140 | announce_test_start(test_ffa_version); |
| 141 | |
| 142 | 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] | 143 | spm_version = (uint32_t)ret.ret0; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 144 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 145 | bool ffa_version_compatible = |
| 146 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 147 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 148 | |
Olivier Deprez | 24bd170 | 2021-10-05 14:35:17 +0200 | [diff] [blame] | 149 | VERBOSE("FFA_VERSION returned %u.%u; Compatible: %i\n", |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 150 | spm_version >> FFA_VERSION_MAJOR_SHIFT, |
| 151 | spm_version & FFA_VERSION_MINOR_MASK, |
| 152 | (int)ffa_version_compatible); |
| 153 | |
| 154 | expect((int)ffa_version_compatible, (int)true); |
| 155 | |
| 156 | announce_test_end(test_ffa_version); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 159 | void ffa_spm_id_get_test(void) |
| 160 | { |
| 161 | const char *test_spm_id_get = "FFA_SPM_ID_GET SMC Function"; |
| 162 | |
| 163 | announce_test_start(test_spm_id_get); |
| 164 | |
| 165 | if (spm_version >= MAKE_FFA_VERSION(1, 1)) { |
| 166 | smc_ret_values ret = ffa_spm_id_get(); |
| 167 | |
| 168 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
| 169 | |
| 170 | ffa_id_t spm_id = ffa_endpoint_id(ret); |
| 171 | |
| 172 | VERBOSE("SPM ID = 0x%x\n", spm_id); |
| 173 | /* |
| 174 | * Check the SPMC value given in the fvp_spmc_manifest |
| 175 | * is returned. |
| 176 | */ |
| 177 | expect(spm_id, SPMC_ID); |
| 178 | } else { |
| 179 | NOTICE("FFA_SPM_ID_GET not supported in this version of FF-A." |
| 180 | " Test skipped.\n"); |
| 181 | } |
| 182 | announce_test_end(test_spm_id_get); |
| 183 | } |
| 184 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 185 | void ffa_tests(struct mailbox_buffers *mb) |
| 186 | { |
| 187 | const char *test_ffa = "FFA Interfaces"; |
| 188 | |
| 189 | announce_test_section_start(test_ffa); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 190 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 191 | ffa_features_test(); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 192 | ffa_version_test(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 193 | ffa_spm_id_get_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 194 | ffa_partition_info_get_test(mb); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 195 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 196 | announce_test_section_end(test_ffa); |
| 197 | } |