J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
| 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> |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 9 | #include <cactus_platform_def.h> |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 10 | #include <cactus_def.h> |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 11 | #include <ffa_helpers.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 12 | #include <sp_helpers.h> |
| 13 | |
| 14 | /* FFA version test helpers */ |
| 15 | #define FFA_MAJOR 1U |
| 16 | #define FFA_MINOR 0U |
| 17 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 18 | static const uint32_t primary_uuid[4] = PRIMARY_UUID; |
| 19 | static const uint32_t secondary_uuid[4] = SECONDARY_UUID; |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 20 | static const uint32_t tertiary_uuid[4] = TERTIARY_UUID; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 21 | static const uint32_t null_uuid[4] = {0}; |
| 22 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 23 | struct feature_test { |
| 24 | const char *test_name; |
| 25 | unsigned int feature; |
| 26 | unsigned int expected_ret; |
| 27 | }; |
| 28 | |
| 29 | static const struct feature_test test_target[] = { |
| 30 | {"FFA_ERROR_32 check", FFA_ERROR, FFA_SUCCESS_SMC32}, |
| 31 | {"FFA_SUCCESS_32 check", FFA_SUCCESS_SMC32, FFA_SUCCESS_SMC32}, |
| 32 | {"FFA_INTERRUPT_32 check", FFA_INTERRUPT, FFA_SUCCESS_SMC32}, |
| 33 | {"FFA_VERSION_32 check", FFA_VERSION, FFA_SUCCESS_SMC32}, |
| 34 | {"FFA_FEATURES_32 check", FFA_FEATURES, FFA_SUCCESS_SMC32}, |
| 35 | {"FFA_RX_RELEASE_32 check", FFA_RX_RELEASE, FFA_SUCCESS_SMC32}, |
| 36 | {"FFA_RXTX_MAP_32 check", FFA_RXTX_MAP_SMC32, FFA_ERROR}, |
| 37 | {"FFA_RXTX_MAP_64 check", FFA_RXTX_MAP_SMC64, FFA_SUCCESS_SMC32}, |
| 38 | {"FFA_RXTX_UNMAP_32 check", FFA_RXTX_UNMAP, FFA_ERROR}, |
| 39 | {"FFA_PARTITION_INFO_GET_32 check", FFA_PARTITION_INFO_GET, FFA_SUCCESS_SMC32}, |
| 40 | {"FFA_ID_GET_32 check", FFA_ID_GET, FFA_SUCCESS_SMC32}, |
| 41 | {"FFA_MSG_POLL_32 check", FFA_MSG_POLL, FFA_SUCCESS_SMC32}, |
| 42 | {"FFA_MSG_WAIT_32 check", FFA_MSG_WAIT, FFA_SUCCESS_SMC32}, |
| 43 | {"FFA_YIELD_32 check", FFA_MSG_YIELD, FFA_SUCCESS_SMC32}, |
| 44 | {"FFA_RUN_32 check", FFA_MSG_RUN, FFA_SUCCESS_SMC32}, |
| 45 | {"FFA_MSG_SEND_32 check", FFA_MSG_SEND, FFA_SUCCESS_SMC32}, |
| 46 | {"FFA_MEM_DONATE_32 check", FFA_MEM_DONATE_SMC32, FFA_SUCCESS_SMC32}, |
| 47 | {"FFA_MEM_LEND_32 check", FFA_MEM_LEND_SMC32, FFA_SUCCESS_SMC32}, |
| 48 | {"FFA_MEM_SHARE_32 check", FFA_MEM_SHARE_SMC32, FFA_SUCCESS_SMC32}, |
| 49 | {"FFA_MEM_RETRIEVE_REQ_32 check", FFA_MEM_RETRIEVE_REQ_SMC32, FFA_SUCCESS_SMC32}, |
| 50 | {"FFA_MEM_RETRIEVE_RESP_32 check", FFA_MEM_RETRIEVE_RESP, FFA_SUCCESS_SMC32}, |
| 51 | {"FFA_MEM_RELINQUISH_32 check", FFA_MEM_RELINQUISH, FFA_SUCCESS_SMC32}, |
| 52 | {"FFA_MEM_RECLAIM_32 check", FFA_MEM_RECLAIM, FFA_SUCCESS_SMC32}, |
| 53 | {"Check non-existent command", 0xFFFF, FFA_ERROR} |
| 54 | }; |
| 55 | |
| 56 | /* |
| 57 | * Test FFA_FEATURES interface. |
| 58 | */ |
| 59 | static void ffa_features_test(void) |
| 60 | { |
| 61 | const char *test_features = "FFA Features interface"; |
| 62 | smc_ret_values ffa_ret; |
| 63 | unsigned int i, test_target_size = |
| 64 | sizeof(test_target) / sizeof(struct feature_test); |
| 65 | |
| 66 | announce_test_section_start(test_features); |
| 67 | |
| 68 | for (i = 0U; i < test_target_size; i++) { |
| 69 | announce_test_start(test_target[i].test_name); |
| 70 | |
| 71 | ffa_ret = ffa_features(test_target[i].feature); |
| 72 | expect(ffa_ret.ret0, test_target[i].expected_ret); |
| 73 | if (test_target[i].expected_ret == FFA_ERROR) { |
| 74 | expect(ffa_ret.ret2, FFA_ERROR_NOT_SUPPORTED); |
| 75 | } |
| 76 | |
| 77 | announce_test_end(test_target[i].test_name); |
| 78 | } |
| 79 | |
| 80 | announce_test_section_end(test_features); |
| 81 | } |
| 82 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 83 | static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4], |
| 84 | const struct ffa_partition_info *expected, |
| 85 | const uint16_t expected_size) |
| 86 | { |
| 87 | smc_ret_values ret = ffa_partition_info_get(uuid); |
| 88 | unsigned int i; |
| 89 | expect(ret.ret0, FFA_SUCCESS_SMC32); |
| 90 | |
| 91 | struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv); |
| 92 | for (i = 0U; i < expected_size; i++) { |
| 93 | expect(info[i].id, expected[i].id); |
| 94 | expect(info[i].exec_context, expected[i].exec_context); |
| 95 | expect(info[i].properties, expected[i].properties); |
| 96 | } |
| 97 | |
| 98 | ret = ffa_rx_release(); |
| 99 | expect(ret.ret0, FFA_SUCCESS_SMC32); |
| 100 | } |
| 101 | |
| 102 | static void ffa_partition_info_wrong_test(void) |
| 103 | { |
| 104 | const char *test_wrong_uuid = "Request wrong UUID"; |
| 105 | uint32_t uuid[4] = {1}; |
| 106 | |
| 107 | announce_test_start(test_wrong_uuid); |
| 108 | |
| 109 | smc_ret_values ret = ffa_partition_info_get(uuid); |
| 110 | expect(ret.ret0, FFA_ERROR); |
| 111 | expect(ret.ret2, FFA_ERROR_INVALID_PARAMETER); |
| 112 | |
| 113 | announce_test_end(test_wrong_uuid); |
| 114 | } |
| 115 | |
| 116 | static void ffa_partition_info_get_test(struct mailbox_buffers *mb) |
| 117 | { |
| 118 | const char *test_partition_info = "FFA Partition info interface"; |
| 119 | const char *test_primary = "Get primary partition info"; |
| 120 | const char *test_secondary = "Get secondary partition info"; |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 121 | const char *test_tertiary = "Get tertiary partition info"; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 122 | const char *test_all = "Get all partitions info"; |
| 123 | |
| 124 | const struct ffa_partition_info expected_info[] = { |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 125 | /* Primary partition info */ |
| 126 | { |
| 127 | .id = SPM_VM_ID_FIRST, |
| 128 | .exec_context = CACTUS_PRIMARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 129 | /* Supports receipt of direct message requests. */ |
| 130 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 131 | }, |
| 132 | /* Secondary partition info */ |
| 133 | { |
| 134 | .id = SPM_VM_ID_FIRST + 1U, |
| 135 | .exec_context = CACTUS_SECONDARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 136 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 137 | }, |
| 138 | /* Tertiary partition info */ |
| 139 | { |
| 140 | .id = SPM_VM_ID_FIRST + 2U, |
| 141 | .exec_context = CACTUS_TERTIARY_EC_COUNT, |
Olivier Deprez | 6d274a4 | 2020-10-23 09:12:27 +0200 | [diff] [blame] | 142 | .properties = 1U |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 143 | } |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | announce_test_section_start(test_partition_info); |
| 147 | |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 148 | announce_test_start(test_tertiary); |
| 149 | ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1); |
| 150 | announce_test_end(test_tertiary); |
| 151 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 152 | announce_test_start(test_secondary); |
| 153 | ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1); |
| 154 | announce_test_end(test_secondary); |
| 155 | |
| 156 | announce_test_start(test_primary); |
| 157 | ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1); |
| 158 | announce_test_end(test_primary); |
| 159 | |
| 160 | announce_test_start(test_all); |
Ruari Phipps | d75596a | 2020-07-17 16:41:34 +0100 | [diff] [blame] | 161 | ffa_partition_info_helper(mb, null_uuid, expected_info, 3); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 162 | announce_test_end(test_all); |
| 163 | |
| 164 | ffa_partition_info_wrong_test(); |
| 165 | |
| 166 | announce_test_section_end(test_partition_info); |
| 167 | } |
| 168 | |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 169 | void ffa_version_test(void) |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 170 | { |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 171 | const char *test_ffa_version = "FFA Version interface"; |
| 172 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 173 | announce_test_start(test_ffa_version); |
| 174 | |
| 175 | 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] | 176 | uint32_t spm_version = (uint32_t)ret.ret0; |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 177 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 178 | bool ffa_version_compatible = |
| 179 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 180 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 181 | |
| 182 | NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n", |
| 183 | spm_version >> FFA_VERSION_MAJOR_SHIFT, |
| 184 | spm_version & FFA_VERSION_MINOR_MASK, |
| 185 | (int)ffa_version_compatible); |
| 186 | |
| 187 | expect((int)ffa_version_compatible, (int)true); |
| 188 | |
| 189 | announce_test_end(test_ffa_version); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void ffa_tests(struct mailbox_buffers *mb) |
| 193 | { |
| 194 | const char *test_ffa = "FFA Interfaces"; |
| 195 | |
| 196 | announce_test_section_start(test_ffa); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 197 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 198 | ffa_features_test(); |
Max Shvetsov | 57c6ddb | 2020-07-01 14:09:48 +0100 | [diff] [blame] | 199 | ffa_version_test(); |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 200 | ffa_partition_info_get_test(mb); |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame] | 201 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 202 | announce_test_section_end(test_ffa); |
| 203 | } |