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 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 23 | static const uint32_t primary_uuid[4] = PRIMARY_UUID; |
| 24 | static const uint32_t secondary_uuid[4] = SECONDARY_UUID; |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 25 | static const uint32_t tertiary_uuid[4] = TERTIARY_UUID; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 26 | static const uint32_t null_uuid[4] = {0}; |
| 27 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 28 | /* |
| 29 | * Test FFA_FEATURES interface. |
| 30 | */ |
| 31 | static void ffa_features_test(void) |
| 32 | { |
| 33 | const char *test_features = "FFA Features interface"; |
| 34 | smc_ret_values ffa_ret; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 35 | const struct ffa_features_test *ffa_feature_test_target; |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 36 | unsigned int i, test_target_size = |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 37 | get_ffa_feature_test_target(&ffa_feature_test_target); |
| 38 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 39 | |
| 40 | announce_test_section_start(test_features); |
| 41 | |
| 42 | for (i = 0U; i < test_target_size; i++) { |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 43 | announce_test_start(ffa_feature_test_target[i].test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 44 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 45 | ffa_ret = ffa_features(ffa_feature_test_target[i].feature); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 46 | expect(ffa_func_id(ffa_ret), ffa_feature_test_target[i].expected_ret); |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 47 | if (ffa_feature_test_target[i].expected_ret == FFA_ERROR) { |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 48 | expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 51 | announce_test_end(ffa_feature_test_target[i].test_name); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | announce_test_section_end(test_features); |
| 55 | } |
| 56 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 57 | static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4], |
| 58 | const struct ffa_partition_info *expected, |
| 59 | const uint16_t expected_size) |
| 60 | { |
| 61 | smc_ret_values ret = ffa_partition_info_get(uuid); |
| 62 | unsigned int i; |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 63 | expect(ffa_func_id(ret), FFA_SUCCESS_SMC32); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 64 | |
| 65 | struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv); |
| 66 | for (i = 0U; i < expected_size; i++) { |
| 67 | expect(info[i].id, expected[i].id); |
| 68 | expect(info[i].exec_context, expected[i].exec_context); |
| 69 | expect(info[i].properties, expected[i].properties); |
| 70 | } |
| 71 | |
| 72 | ret = ffa_rx_release(); |
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 | |
| 76 | static void ffa_partition_info_wrong_test(void) |
| 77 | { |
| 78 | const char *test_wrong_uuid = "Request wrong UUID"; |
| 79 | uint32_t uuid[4] = {1}; |
| 80 | |
| 81 | announce_test_start(test_wrong_uuid); |
| 82 | |
| 83 | smc_ret_values ret = ffa_partition_info_get(uuid); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame] | 84 | expect(ffa_func_id(ret), FFA_ERROR); |
| 85 | expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 86 | |
| 87 | announce_test_end(test_wrong_uuid); |
| 88 | } |
| 89 | |
| 90 | static void ffa_partition_info_get_test(struct mailbox_buffers *mb) |
| 91 | { |
| 92 | const char *test_partition_info = "FFA Partition info interface"; |
| 93 | const char *test_primary = "Get primary partition info"; |
| 94 | const char *test_secondary = "Get secondary partition info"; |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 95 | const char *test_tertiary = "Get tertiary partition info"; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 96 | const char *test_all = "Get all partitions info"; |
| 97 | |
| 98 | const struct ffa_partition_info expected_info[] = { |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 99 | /* Primary partition info */ |
| 100 | { |
| 101 | .id = SPM_VM_ID_FIRST, |
| 102 | .exec_context = CACTUS_PRIMARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 103 | /* Supports receipt of direct message requests. */ |
| 104 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 105 | }, |
| 106 | /* Secondary partition info */ |
| 107 | { |
| 108 | .id = SPM_VM_ID_FIRST + 1U, |
| 109 | .exec_context = CACTUS_SECONDARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 110 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 111 | }, |
| 112 | /* Tertiary partition info */ |
| 113 | { |
| 114 | .id = SPM_VM_ID_FIRST + 2U, |
| 115 | .exec_context = CACTUS_TERTIARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 116 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 117 | } |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | announce_test_section_start(test_partition_info); |
| 121 | |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 122 | announce_test_start(test_tertiary); |
| 123 | ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1); |
| 124 | announce_test_end(test_tertiary); |
| 125 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 126 | announce_test_start(test_secondary); |
| 127 | ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1); |
| 128 | announce_test_end(test_secondary); |
| 129 | |
| 130 | announce_test_start(test_primary); |
| 131 | ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1); |
| 132 | announce_test_end(test_primary); |
| 133 | |
| 134 | announce_test_start(test_all); |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 135 | ffa_partition_info_helper(mb, null_uuid, expected_info, 3); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 136 | announce_test_end(test_all); |
| 137 | |
| 138 | ffa_partition_info_wrong_test(); |
| 139 | |
| 140 | announce_test_section_end(test_partition_info); |
| 141 | } |
| 142 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 143 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 144 | { |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 145 | const char *test_ffa_version = "FFA Version interface"; |
| 146 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 147 | announce_test_start(test_ffa_version); |
| 148 | |
| 149 | smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR)); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 150 | uint32_t spm_version = (uint32_t)ret.ret0; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 151 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 152 | bool ffa_version_compatible = |
| 153 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 154 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 155 | |
| 156 | NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n", |
| 157 | spm_version >> FFA_VERSION_MAJOR_SHIFT, |
| 158 | spm_version & FFA_VERSION_MINOR_MASK, |
| 159 | (int)ffa_version_compatible); |
| 160 | |
| 161 | expect((int)ffa_version_compatible, (int)true); |
| 162 | |
| 163 | announce_test_end(test_ffa_version); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void ffa_tests(struct mailbox_buffers *mb) |
| 167 | { |
| 168 | const char *test_ffa = "FFA Interfaces"; |
| 169 | |
| 170 | announce_test_section_start(test_ffa); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 171 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 172 | ffa_features_test(); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 173 | ffa_version_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 174 | ffa_partition_info_get_test(mb); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 175 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 176 | announce_test_section_end(test_ffa); |
| 177 | } |