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 | */ |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 6 | #include "ffa_helpers.h" |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 7 | #include <assert.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 8 | #include <debug.h> |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 9 | #include <errno.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 10 | |
Daniel Boulby | f3da591 | 2022-04-01 12:31:52 +0100 | [diff] [blame] | 11 | #include <sp_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 |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 21 | #define FFA_MINOR 1U |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 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[] = { |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 26 | {PRIMARY_UUID}, {SECONDARY_UUID}, {TERTIARY_UUID}, {IVY_UUID} |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 27 | }; |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 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, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 34 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 35 | FFA_PARTITION_DIRECT_REQ_RECV | |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 36 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 37 | FFA_PARTITION_NOTIFICATION), |
| 38 | .uuid = sp_uuids[0] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 39 | }, |
| 40 | /* Secondary partition info */ |
| 41 | { |
| 42 | .id = SP_ID(2), |
| 43 | .exec_context = SECONDARY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 44 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 45 | FFA_PARTITION_DIRECT_REQ_RECV | |
J-Alves | 4d05dec | 2021-11-02 11:52:27 +0000 | [diff] [blame] | 46 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 47 | FFA_PARTITION_NOTIFICATION), |
| 48 | .uuid = sp_uuids[1] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 49 | }, |
| 50 | /* Tertiary partition info */ |
| 51 | { |
| 52 | .id = SP_ID(3), |
| 53 | .exec_context = TERTIARY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 54 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 55 | FFA_PARTITION_DIRECT_REQ_RECV | |
J-Alves | b69c8b4 | 2021-11-04 17:03:41 +0000 | [diff] [blame] | 56 | FFA_PARTITION_DIRECT_REQ_SEND | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 57 | FFA_PARTITION_NOTIFICATION), |
| 58 | .uuid = sp_uuids[2] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 59 | }, |
| 60 | /* Ivy partition info */ |
| 61 | { |
| 62 | .id = SP_ID(4), |
| 63 | .exec_context = IVY_EXEC_CTX_COUNT, |
Kathleen Capella | 7774d6e | 2022-11-23 19:06:21 -0500 | [diff] [blame] | 64 | .properties = (FFA_PARTITION_AARCH64_EXEC | |
| 65 | FFA_PARTITION_DIRECT_REQ_RECV | |
Daniel Boulby | 8aa994c | 2022-01-05 19:44:30 +0000 | [diff] [blame] | 66 | FFA_PARTITION_DIRECT_REQ_SEND), |
| 67 | .uuid = sp_uuids[3] |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 68 | } |
| 69 | }; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 70 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 71 | /* |
| 72 | * Test FFA_FEATURES interface. |
| 73 | */ |
| 74 | static void ffa_features_test(void) |
| 75 | { |
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 | |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 83 | INFO("Test FFA_FEATURES.\n"); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 84 | |
| 85 | for (i = 0U; i < test_target_size; i++) { |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 86 | test_target = ffa_feature_test_target[i]; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 87 | |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 88 | ffa_ret = ffa_features_with_input_property(test_target.feature, |
| 89 | test_target.param); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 90 | expected_ret = FFA_VERSION_COMPILED |
| 91 | >= test_target.version_added ? |
| 92 | test_target.expected_ret : FFA_ERROR; |
| 93 | |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 94 | if (ffa_func_id(ffa_ret) != expected_ret) { |
| 95 | ERROR("Unexpected return: %x (expected %x)." |
| 96 | " FFA_FEATURES test: %s.\n", |
| 97 | ffa_func_id(ffa_ret), expected_ret, |
| 98 | test_target.test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 99 | } |
| 100 | |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 101 | if (expected_ret == FFA_ERROR) { |
| 102 | if (ffa_error_code(ffa_ret) != |
| 103 | FFA_ERROR_NOT_SUPPORTED) { |
| 104 | ERROR("Unexpected error code: %x (expected %x)." |
| 105 | " FFA_FEATURES test: %s.\n", |
| 106 | ffa_error_code(ffa_ret), expected_ret, |
| 107 | test_target.test_name); |
| 108 | } |
| 109 | } |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 110 | } |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 113 | static void ffa_partition_info_wrong_test(void) |
| 114 | { |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 115 | const struct ffa_uuid uuid = { .uuid = {1} }; |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 116 | struct ffa_value ret = ffa_partition_info_get(uuid); |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 117 | |
| 118 | VERBOSE("%s: test request wrong UUID.\n", __func__); |
| 119 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 120 | expect(ffa_func_id(ret), FFA_ERROR); |
| 121 | expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static void ffa_partition_info_get_test(struct mailbox_buffers *mb) |
| 125 | { |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 126 | INFO("Test FFA_PARTITION_INFO_GET.\n"); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 127 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 128 | expect(ffa_partition_info_helper(mb, sp_uuids[2], |
| 129 | &ffa_expected_partition_info[2], 1), true); |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 130 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 131 | expect(ffa_partition_info_helper(mb, sp_uuids[1], |
| 132 | &ffa_expected_partition_info[1], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 133 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 134 | expect(ffa_partition_info_helper(mb, sp_uuids[0], |
| 135 | &ffa_expected_partition_info[0], 1), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 136 | |
Daniel Boulby | 4a2888a | 2022-05-31 16:07:36 +0100 | [diff] [blame] | 137 | expect(ffa_partition_info_helper(mb, NULL_UUID, |
Varun Wadekar | 5c35482 | 2021-09-27 06:01:09 -0700 | [diff] [blame] | 138 | ffa_expected_partition_info, |
| 139 | ARRAY_SIZE(ffa_expected_partition_info)), true); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 140 | |
| 141 | ffa_partition_info_wrong_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 144 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 145 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 146 | struct ffa_value ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, |
| 147 | FFA_MINOR)); |
| 148 | |
| 149 | spm_version = (uint32_t)ret.fid; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 150 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 151 | bool ffa_version_compatible = |
| 152 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 153 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 154 | |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 155 | INFO("Test FFA_VERSION. Return %u.%u; Compatible: %i\n", |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 156 | spm_version >> FFA_VERSION_MAJOR_SHIFT, |
| 157 | spm_version & FFA_VERSION_MINOR_MASK, |
| 158 | (int)ffa_version_compatible); |
| 159 | |
| 160 | expect((int)ffa_version_compatible, (int)true); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 163 | void ffa_spm_id_get_test(void) |
| 164 | { |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 165 | if (spm_version >= MAKE_FFA_VERSION(1, 1)) { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 166 | struct ffa_value ret = ffa_spm_id_get(); |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 167 | |
| 168 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
| 169 | |
| 170 | ffa_id_t spm_id = ffa_endpoint_id(ret); |
| 171 | |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 172 | INFO("Test FFA_SPM_ID_GET. Return: 0x%x\n", spm_id); |
| 173 | |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 174 | /* |
| 175 | * Check the SPMC value given in the fvp_spmc_manifest |
| 176 | * is returned. |
| 177 | */ |
| 178 | expect(spm_id, SPMC_ID); |
| 179 | } else { |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 180 | INFO("FFA_SPM_ID_GET not supported in this version of FF-A." |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 181 | " Test skipped.\n"); |
| 182 | } |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 185 | void ffa_tests(struct mailbox_buffers *mb) |
| 186 | { |
J-Alves | 2279c1d | 2023-05-05 17:03:28 +0100 | [diff] [blame] | 187 | const char *test_ffa = "FF-A setup and discovery"; |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 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 | } |