Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Javier Almansa Sobrino | 82cd82e | 2025-01-17 17:37:42 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2025, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
J-Alves | d708c03 | 2020-11-19 12:14:21 +0000 | [diff] [blame] | 7 | #ifndef TEST_HELPERS_H__ |
| 8 | #define TEST_HELPERS_H__ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 9 | |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 10 | #include <arch_features.h> |
J-Alves | f7535f4 | 2021-07-30 11:58:41 +0100 | [diff] [blame] | 11 | #include <plat_topology.h> |
J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 12 | #include <psci.h> |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 13 | #include <sme.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 14 | #include <tftf_lib.h> |
| 15 | #include <trusted_os.h> |
| 16 | #include <tsp.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 17 | #include <uuid_utils.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 18 | #include <uuid.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 19 | |
Juan Pablo Conde | dc23fcd | 2025-04-05 14:26:13 -0500 | [diff] [blame^] | 20 | #define TEST_MECID1 (unsigned short)1 |
| 21 | #define TEST_MECID2 (unsigned short)2 |
| 22 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 23 | typedef struct { |
| 24 | uintptr_t addr; |
| 25 | size_t size; |
| 26 | unsigned int attr; |
| 27 | void *arg; |
| 28 | } map_args_unmap_t; |
| 29 | |
| 30 | typedef test_result_t (*test_function_arg_t)(void *arg); |
| 31 | |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 32 | #ifndef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 33 | #define SKIP_TEST_IF_AARCH32() \ |
| 34 | do { \ |
| 35 | tftf_testcase_printf("Test not supported on aarch32\n"); \ |
| 36 | return TEST_RESULT_SKIPPED; \ |
| 37 | } while (0) |
| 38 | #else |
| 39 | #define SKIP_TEST_IF_AARCH32() |
| 40 | #endif |
| 41 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 42 | #define SKIP_TEST_IF_LESS_THAN_N_CLUSTERS(n) \ |
| 43 | do { \ |
| 44 | unsigned int clusters_cnt; \ |
| 45 | clusters_cnt = tftf_get_total_clusters_count(); \ |
| 46 | if (clusters_cnt < (n)) { \ |
| 47 | tftf_testcase_printf( \ |
| 48 | "Need at least %u clusters, only found %u\n", \ |
| 49 | (n), clusters_cnt); \ |
| 50 | return TEST_RESULT_SKIPPED; \ |
| 51 | } \ |
| 52 | } while (0) |
| 53 | |
| 54 | #define SKIP_TEST_IF_LESS_THAN_N_CPUS(n) \ |
| 55 | do { \ |
| 56 | unsigned int cpus_cnt; \ |
| 57 | cpus_cnt = tftf_get_total_cpus_count(); \ |
| 58 | if (cpus_cnt < (n)) { \ |
| 59 | tftf_testcase_printf( \ |
| 60 | "Need at least %u CPUs, only found %u\n", \ |
| 61 | (n), cpus_cnt); \ |
| 62 | return TEST_RESULT_SKIPPED; \ |
| 63 | } \ |
| 64 | } while (0) |
| 65 | |
| 66 | #define SKIP_TEST_IF_TRUSTED_OS_NOT_PRESENT() \ |
| 67 | do { \ |
| 68 | uuid_t tos_uuid; \ |
| 69 | \ |
| 70 | if (!is_trusted_os_present(&tos_uuid)) { \ |
| 71 | tftf_testcase_printf("No Trusted OS detected\n"); \ |
| 72 | return TEST_RESULT_SKIPPED; \ |
| 73 | } \ |
| 74 | } while (0) |
| 75 | |
| 76 | #define SKIP_TEST_IF_TSP_NOT_PRESENT() \ |
| 77 | do { \ |
| 78 | uuid_t tos_uuid; \ |
| 79 | char tos_uuid_str[UUID_STR_SIZE]; \ |
| 80 | \ |
| 81 | if (!is_trusted_os_present(&tos_uuid)) { \ |
| 82 | tftf_testcase_printf("No Trusted OS detected\n"); \ |
| 83 | return TEST_RESULT_SKIPPED; \ |
| 84 | } \ |
| 85 | \ |
| 86 | if (!uuid_equal(&tos_uuid, &tsp_uuid)) { \ |
| 87 | tftf_testcase_printf( \ |
| 88 | "Trusted OS is not the TSP, its UUID is: %s\n", \ |
| 89 | uuid_to_str(&tos_uuid, tos_uuid_str)); \ |
| 90 | return TEST_RESULT_SKIPPED; \ |
| 91 | } \ |
| 92 | } while (0) |
| 93 | |
Boyan Karatotev | 566f07d | 2024-10-25 13:31:48 +0100 | [diff] [blame] | 94 | #define SKIP_TEST_IF_SMCCC_VERSION_LT(major, minor) \ |
| 95 | do { \ |
| 96 | smc_args args = {0}; \ |
| 97 | smc_ret_values ret; \ |
| 98 | args.fid = SMCCC_VERSION; \ |
| 99 | ret = tftf_smc(&args); \ |
| 100 | if ((int32_t)ret.ret0 < MAKE_SMCCC_VERSION(major, minor)) { \ |
| 101 | tftf_testcase_printf( \ |
| 102 | "Unexpected SMCCC version: 0x%x\n", \ |
| 103 | (int)ret.ret0); \ |
| 104 | return TEST_RESULT_SKIPPED; \ |
| 105 | } \ |
| 106 | } while (0) |
| 107 | |
Boyan Karatotev | 7b7ca22 | 2024-10-25 13:33:18 +0100 | [diff] [blame] | 108 | #define SKIP_TEST_IF_SMCCC_FUNC_NOT_SUPPORTED(func) \ |
| 109 | do { \ |
| 110 | smc_ret_values ret; \ |
| 111 | smc_args args = {0}; \ |
| 112 | args.fid = SMCCC_ARCH_FEATURES; \ |
| 113 | args.arg1 = func; \ |
| 114 | ret = tftf_smc(&args); \ |
| 115 | if ((int)ret.ret0 == SMC_ARCH_CALL_NOT_SUPPORTED) { \ |
| 116 | tftf_testcase_printf( \ |
| 117 | #func " is not implemented\n"); \ |
| 118 | return TEST_RESULT_SKIPPED; \ |
| 119 | } \ |
| 120 | } while (0) |
| 121 | |
Daniel Boulby | 0e4629f | 2021-10-26 14:01:23 +0100 | [diff] [blame] | 122 | #define SKIP_TEST_IF_DIT_NOT_SUPPORTED() \ |
| 123 | do { \ |
| 124 | if (!is_armv8_4_dit_present()) { \ |
| 125 | tftf_testcase_printf( \ |
| 126 | "DIT not supported\n"); \ |
| 127 | return TEST_RESULT_SKIPPED; \ |
| 128 | } \ |
| 129 | } while (0) |
| 130 | |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 131 | #define SKIP_TEST_IF_PAUTH_NOT_SUPPORTED() \ |
| 132 | do { \ |
| 133 | if (!is_armv8_3_pauth_present()) { \ |
| 134 | tftf_testcase_printf( \ |
| 135 | "Pointer Authentication not supported\n"); \ |
| 136 | return TEST_RESULT_SKIPPED; \ |
| 137 | } \ |
| 138 | } while (0) |
| 139 | |
Jimmy Brisson | 90f1d5c | 2020-04-16 10:54:51 -0500 | [diff] [blame] | 140 | #define SKIP_TEST_IF_FGT_NOT_SUPPORTED() \ |
| 141 | do { \ |
| 142 | if (!is_armv8_6_fgt_present()) { \ |
| 143 | tftf_testcase_printf( \ |
| 144 | "Fine Grained Traps not supported\n"); \ |
| 145 | return TEST_RESULT_SKIPPED; \ |
| 146 | } \ |
| 147 | } while (0) |
| 148 | |
Arvind Ram Prakash | 2f2c959 | 2024-06-06 16:34:28 -0500 | [diff] [blame] | 149 | #define SKIP_TEST_IF_DEBUGV8P9_NOT_SUPPORTED() \ |
| 150 | do { \ |
| 151 | if (arch_get_debug_version() != \ |
| 152 | ID_AA64DFR0_V8_9_DEBUG_ARCH_SUPPORTED) { \ |
| 153 | tftf_testcase_printf( \ |
| 154 | "Debugv8p9 not supported\n"); \ |
| 155 | return TEST_RESULT_SKIPPED; \ |
| 156 | } \ |
| 157 | } while (0) |
| 158 | |
Arvind Ram Prakash | 94963d4 | 2024-06-13 17:19:56 -0500 | [diff] [blame] | 159 | #define SKIP_TEST_IF_FGT2_NOT_SUPPORTED() \ |
| 160 | do { \ |
| 161 | if (!is_armv8_9_fgt2_present()) { \ |
| 162 | tftf_testcase_printf( \ |
| 163 | "Fine Grained Traps 2 not supported\n"); \ |
| 164 | return TEST_RESULT_SKIPPED; \ |
| 165 | } \ |
| 166 | } while (0) |
| 167 | |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 168 | #define SKIP_TEST_IF_SVE_NOT_SUPPORTED() \ |
| 169 | do { \ |
| 170 | if (!is_armv8_2_sve_present()) { \ |
| 171 | tftf_testcase_printf("SVE not supported\n"); \ |
| 172 | return TEST_RESULT_SKIPPED; \ |
| 173 | } \ |
| 174 | } while (0) |
| 175 | |
Jimmy Brisson | 945095a | 2020-04-16 10:54:59 -0500 | [diff] [blame] | 176 | #define SKIP_TEST_IF_ECV_NOT_SELF_SYNC() \ |
| 177 | do { \ |
| 178 | if (get_armv8_6_ecv_support() != \ |
| 179 | ID_AA64MMFR0_EL1_ECV_SELF_SYNCH) { \ |
| 180 | tftf_testcase_printf("ARMv8.6-ECV not supported\n"); \ |
| 181 | return TEST_RESULT_SKIPPED; \ |
| 182 | } \ |
| 183 | } while (0) |
| 184 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 185 | #define SKIP_TEST_IF_MM_NOT_PRESENT() \ |
| 186 | do { \ |
| 187 | smc_args version_smc = { MM_VERSION_AARCH32 }; \ |
| 188 | smc_ret_values smc_ret = tftf_smc(&version_smc); \ |
| 189 | uint32_t version = smc_ret.ret0; \ |
| 190 | \ |
| 191 | if (version == (uint32_t) SMC_UNKNOWN) { \ |
| 192 | tftf_testcase_printf("SPM not detected.\n"); \ |
| 193 | return TEST_RESULT_SKIPPED; \ |
| 194 | } \ |
| 195 | } while (0) |
| 196 | |
Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 197 | #define SKIP_TEST_IF_MTE_SUPPORT_LESS_THAN(n) \ |
| 198 | do { \ |
| 199 | if (get_armv8_5_mte_support() < (n)) { \ |
| 200 | tftf_testcase_printf( \ |
| 201 | "Memory Tagging Extension not supported\n"); \ |
| 202 | return TEST_RESULT_SKIPPED; \ |
| 203 | } \ |
| 204 | } while (0) |
| 205 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 206 | #define SKIP_TEST_IF_MM_VERSION_LESS_THAN(major, minor) \ |
| 207 | do { \ |
| 208 | smc_args version_smc = { MM_VERSION_AARCH32 }; \ |
| 209 | smc_ret_values smc_ret = tftf_smc(&version_smc); \ |
| 210 | uint32_t version = smc_ret.ret0; \ |
| 211 | \ |
| 212 | if (version == (uint32_t) SMC_UNKNOWN) { \ |
| 213 | tftf_testcase_printf("SPM not detected.\n"); \ |
| 214 | return TEST_RESULT_SKIPPED; \ |
| 215 | } \ |
| 216 | \ |
| 217 | if (version < MM_VERSION_FORM(major, minor)) { \ |
J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 218 | tftf_testcase_printf("MM_VERSION returned %u.%u\n" \ |
| 219 | "The required version is %u.%u\n", \ |
| 220 | version >> MM_VERSION_MAJOR_SHIFT, \ |
| 221 | version & MM_VERSION_MINOR_MASK, \ |
| 222 | major, minor); \ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 223 | return TEST_RESULT_SKIPPED; \ |
| 224 | } \ |
| 225 | \ |
J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 226 | VERBOSE("MM_VERSION returned %u.%u\n", \ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 227 | version >> MM_VERSION_MAJOR_SHIFT, \ |
| 228 | version & MM_VERSION_MINOR_MASK); \ |
| 229 | } while (0) |
| 230 | |
Petre-Ionut Tudor | f68ebdb | 2019-09-18 16:13:00 +0100 | [diff] [blame] | 231 | #define SKIP_TEST_IF_ARCH_DEBUG_VERSION_LESS_THAN(version) \ |
| 232 | do { \ |
Petre-Ionut Tudor | f1a45f7 | 2019-10-08 16:51:45 +0100 | [diff] [blame] | 233 | uint32_t debug_ver = arch_get_debug_version(); \ |
Petre-Ionut Tudor | f68ebdb | 2019-09-18 16:13:00 +0100 | [diff] [blame] | 234 | \ |
Petre-Ionut Tudor | f1a45f7 | 2019-10-08 16:51:45 +0100 | [diff] [blame] | 235 | if (debug_ver < version) { \ |
Petre-Ionut Tudor | f68ebdb | 2019-09-18 16:13:00 +0100 | [diff] [blame] | 236 | tftf_testcase_printf("Debug version returned %d\n" \ |
| 237 | "The required version is %d\n", \ |
Petre-Ionut Tudor | f1a45f7 | 2019-10-08 16:51:45 +0100 | [diff] [blame] | 238 | debug_ver, \ |
Petre-Ionut Tudor | f68ebdb | 2019-09-18 16:13:00 +0100 | [diff] [blame] | 239 | version); \ |
| 240 | return TEST_RESULT_SKIPPED; \ |
| 241 | } \ |
| 242 | } while (0) |
| 243 | |
Manish V Badarkhe | 87c03d1 | 2021-07-06 22:57:11 +0100 | [diff] [blame] | 244 | #define SKIP_TEST_IF_TRBE_NOT_SUPPORTED() \ |
| 245 | do { \ |
Boyan Karatotev | 4e28242 | 2024-10-25 14:34:13 +0100 | [diff] [blame] | 246 | if (!is_feat_trbe_present()) { \ |
Manish V Badarkhe | 87c03d1 | 2021-07-06 22:57:11 +0100 | [diff] [blame] | 247 | tftf_testcase_printf("ARMv9-TRBE not supported\n"); \ |
| 248 | return TEST_RESULT_SKIPPED; \ |
| 249 | } \ |
| 250 | } while (false) |
| 251 | |
Manish V Badarkhe | 2c518e5 | 2021-07-08 16:36:57 +0100 | [diff] [blame] | 252 | #define SKIP_TEST_IF_TRF_NOT_SUPPORTED() \ |
| 253 | do { \ |
| 254 | if (!get_armv8_4_trf_support()) { \ |
| 255 | tftf_testcase_printf("ARMv8.4-TRF not supported\n"); \ |
| 256 | return TEST_RESULT_SKIPPED; \ |
| 257 | } \ |
| 258 | } while (false) |
| 259 | |
Manish V Badarkhe | 6d0e1b6 | 2021-07-09 13:58:28 +0100 | [diff] [blame] | 260 | #define SKIP_TEST_IF_SYS_REG_TRACE_NOT_SUPPORTED() \ |
| 261 | do { \ |
| 262 | if (!get_armv8_0_sys_reg_trace_support()) { \ |
| 263 | tftf_testcase_printf("ARMv8-system register" \ |
| 264 | "trace not supported\n"); \ |
| 265 | return TEST_RESULT_SKIPPED; \ |
| 266 | } \ |
| 267 | } while (false) |
| 268 | |
Manish V Badarkhe | 82e1a25 | 2022-01-04 13:45:31 +0000 | [diff] [blame] | 269 | #define SKIP_TEST_IF_AFP_NOT_SUPPORTED() \ |
| 270 | do { \ |
| 271 | if (!get_feat_afp_present()) { \ |
Manish V Badarkhe | b31bc75 | 2021-12-24 08:52:52 +0000 | [diff] [blame] | 272 | tftf_testcase_printf("ARMv8.7-afp not supported\n"); \ |
Manish V Badarkhe | 82e1a25 | 2022-01-04 13:45:31 +0000 | [diff] [blame] | 273 | return TEST_RESULT_SKIPPED; \ |
| 274 | } \ |
| 275 | } while (false) |
| 276 | |
Arvind Ram Prakash | 13887ac | 2024-01-04 15:22:52 -0600 | [diff] [blame] | 277 | #define SKIP_TEST_IF_MPAM_NOT_SUPPORTED() \ |
| 278 | do { \ |
| 279 | if(!is_feat_mpam_supported()){ \ |
| 280 | tftf_testcase_printf("ARMv8.4-mpam not supported\n"); \ |
| 281 | return TEST_RESULT_SKIPPED; \ |
| 282 | } \ |
| 283 | } while (false) |
| 284 | |
Andre Przywara | 2230a59 | 2025-03-10 17:19:34 +0000 | [diff] [blame] | 285 | #define SKIP_TEST_IF_RAS_NOT_SUPPORTED() \ |
| 286 | do { \ |
| 287 | if(!is_feat_ras_present()){ \ |
| 288 | tftf_testcase_printf("ARMv8.2-RAS not supported\n"); \ |
| 289 | return TEST_RESULT_SKIPPED; \ |
| 290 | } \ |
| 291 | } while (false) |
| 292 | |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 293 | #ifdef __aarch64__ |
Federico Recanati | d3749b0 | 2022-01-14 15:44:45 +0100 | [diff] [blame] | 294 | #define SKIP_TEST_IF_PA_SIZE_LESS_THAN(n) \ |
| 295 | do { \ |
| 296 | static const unsigned int pa_range_bits_arr[] = { \ |
| 297 | PARANGE_0000, PARANGE_0001, PARANGE_0010, PARANGE_0011,\ |
| 298 | PARANGE_0100, PARANGE_0101, PARANGE_0110 \ |
| 299 | }; \ |
| 300 | if (pa_range_bits_arr[get_pa_range()] < n) { \ |
| 301 | tftf_testcase_printf("PA size less than %d bit\n", n); \ |
| 302 | return TEST_RESULT_SKIPPED; \ |
| 303 | } \ |
| 304 | } while (false) |
Federico Recanati | 6328fb0 | 2022-01-14 15:48:16 +0100 | [diff] [blame] | 305 | #else |
| 306 | #define SKIP_TEST_IF_PA_SIZE_LESS_THAN(n) \ |
| 307 | do { \ |
| 308 | return TEST_RESULT_SKIPPED; \ |
| 309 | } while (false) |
| 310 | #endif |
Federico Recanati | d3749b0 | 2022-01-14 15:44:45 +0100 | [diff] [blame] | 311 | |
johpow01 | 8c3da8b | 2022-01-31 18:14:41 -0600 | [diff] [blame] | 312 | #define SKIP_TEST_IF_BRBE_NOT_SUPPORTED() \ |
| 313 | do { \ |
| 314 | if (!get_feat_brbe_support()) { \ |
| 315 | tftf_testcase_printf("FEAT_BRBE not supported\n"); \ |
| 316 | return TEST_RESULT_SKIPPED; \ |
| 317 | } \ |
| 318 | } while (false) |
| 319 | |
Manish V Badarkhe | b31bc75 | 2021-12-24 08:52:52 +0000 | [diff] [blame] | 320 | #define SKIP_TEST_IF_WFXT_NOT_SUPPORTED() \ |
| 321 | do { \ |
| 322 | if (!get_feat_wfxt_present()) { \ |
| 323 | tftf_testcase_printf("ARMv8.7-WFxT not supported\n"); \ |
| 324 | return TEST_RESULT_SKIPPED; \ |
| 325 | } \ |
| 326 | } while (false) |
| 327 | |
Juan Pablo Conde | 9303f4d | 2022-07-25 16:38:01 -0400 | [diff] [blame] | 328 | #define SKIP_TEST_IF_RNG_TRAP_NOT_SUPPORTED() \ |
| 329 | do { \ |
| 330 | if (!is_feat_rng_trap_present()) { \ |
| 331 | tftf_testcase_printf("ARMv8.5-RNG_TRAP not" \ |
| 332 | "supported\n"); \ |
| 333 | return TEST_RESULT_SKIPPED; \ |
| 334 | } \ |
| 335 | } while (false) |
| 336 | |
Boyan Karatotev | 35e3ca0 | 2022-10-10 16:39:45 +0100 | [diff] [blame] | 337 | #define SKIP_TEST_IF_PMUV3_NOT_SUPPORTED() \ |
| 338 | do { \ |
| 339 | if (!get_feat_pmuv3_supported()) { \ |
| 340 | tftf_testcase_printf("FEAT_PMUv3 not supported\n"); \ |
| 341 | return TEST_RESULT_SKIPPED; \ |
| 342 | } \ |
| 343 | } while (false) |
| 344 | |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 345 | #define SKIP_TEST_IF_SME_NOT_SUPPORTED() \ |
| 346 | do { \ |
| 347 | if(!is_feat_sme_supported()) { \ |
| 348 | tftf_testcase_printf("FEAT_SME not supported\n"); \ |
| 349 | return TEST_RESULT_SKIPPED; \ |
| 350 | } \ |
| 351 | } while (false) |
| 352 | |
Jayanth Dodderi Chidanand | 95d5d27 | 2023-01-16 17:58:47 +0000 | [diff] [blame] | 353 | #define SKIP_TEST_IF_SME2_NOT_SUPPORTED() \ |
| 354 | do { \ |
| 355 | if(!is_feat_sme2_supported()) { \ |
| 356 | tftf_testcase_printf("FEAT_SME2 not supported\n"); \ |
| 357 | return TEST_RESULT_SKIPPED; \ |
| 358 | } \ |
| 359 | } while (false) |
| 360 | |
Arvind Ram Prakash | 1ab21e5 | 2024-11-12 10:52:08 -0600 | [diff] [blame] | 361 | #define SKIP_TEST_IF_FPMR_NOT_SUPPORTED() \ |
| 362 | do { \ |
| 363 | if(!is_feat_fpmr_present()) { \ |
| 364 | tftf_testcase_printf("FEAT_FPMR not supported\n"); \ |
| 365 | return TEST_RESULT_SKIPPED; \ |
| 366 | } \ |
| 367 | } while (false) |
| 368 | |
Igor Podgainõi | d1a7f4d | 2024-11-26 12:50:47 +0100 | [diff] [blame] | 369 | #define SKIP_TEST_IF_SCTLR2_NOT_SUPPORTED() \ |
| 370 | do { \ |
| 371 | if (!is_feat_sctlr2_supported()) { \ |
| 372 | tftf_testcase_printf("FEAT_SCTLR2 not supported\n"); \ |
| 373 | return TEST_RESULT_SKIPPED; \ |
| 374 | } \ |
| 375 | } while (false) |
| 376 | |
| 377 | #define SKIP_TEST_IF_THE_NOT_SUPPORTED() \ |
| 378 | do { \ |
| 379 | if (!is_feat_the_supported()) { \ |
| 380 | tftf_testcase_printf("FEAT_THE not supported\n"); \ |
| 381 | return TEST_RESULT_SKIPPED; \ |
| 382 | } \ |
| 383 | } while (false) |
| 384 | |
| 385 | #define SKIP_TEST_IF_D128_NOT_SUPPORTED() \ |
| 386 | do { \ |
| 387 | if (!is_feat_d128_supported()) { \ |
| 388 | tftf_testcase_printf("FEAT_D128 not supported\n"); \ |
| 389 | return TEST_RESULT_SKIPPED; \ |
| 390 | } \ |
| 391 | } while (false) |
| 392 | |
Arunachalam Ganapathy | 4b22111 | 2023-04-05 14:19:03 +0100 | [diff] [blame] | 393 | #define SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP() \ |
| 394 | do { \ |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 395 | u_register_t retrmm = 0U; \ |
Arunachalam Ganapathy | 4b22111 | 2023-04-05 14:19:03 +0100 | [diff] [blame] | 396 | \ |
AlexeiFedorov | 718fd79 | 2024-11-08 14:55:20 +0000 | [diff] [blame] | 397 | if (get_armv9_2_feat_rme_support() == 0U) { \ |
Arunachalam Ganapathy | 4b22111 | 2023-04-05 14:19:03 +0100 | [diff] [blame] | 398 | tftf_testcase_printf("FEAT_RME not supported\n"); \ |
| 399 | return TEST_RESULT_SKIPPED; \ |
| 400 | } \ |
| 401 | \ |
| 402 | host_rmi_init_cmp_result(); \ |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 403 | retrmm = host_rmi_version(RMI_ABI_VERSION_VAL); \ |
Arunachalam Ganapathy | 4b22111 | 2023-04-05 14:19:03 +0100 | [diff] [blame] | 404 | \ |
| 405 | VERBOSE("RMM version is: %lu.%lu\n", \ |
| 406 | RMI_ABI_VERSION_GET_MAJOR(retrmm), \ |
| 407 | RMI_ABI_VERSION_GET_MINOR(retrmm)); \ |
| 408 | \ |
| 409 | /* \ |
| 410 | * TODO: Remove this once SMC_RMM_REALM_CREATE is implemented \ |
| 411 | * in TRP. For the moment skip the test if RMM is TRP, TRP \ |
| 412 | * version is always 0. \ |
| 413 | */ \ |
| 414 | if (retrmm == 0U) { \ |
| 415 | tftf_testcase_printf("RMM is TRP\n"); \ |
| 416 | return TEST_RESULT_SKIPPED; \ |
| 417 | } \ |
| 418 | } while (false) |
| 419 | |
Jayanth Dodderi Chidanand | cd6c94b | 2022-02-15 17:19:05 +0000 | [diff] [blame] | 420 | #define SKIP_TEST_IF_LS64_NOT_SUPPORTED() \ |
| 421 | do { \ |
| 422 | if (get_feat_ls64_support() == \ |
| 423 | ID_AA64ISAR1_LS64_NOT_SUPPORTED) { \ |
| 424 | tftf_testcase_printf("ARMv8.7-ls64 not supported"); \ |
| 425 | return TEST_RESULT_SKIPPED; \ |
| 426 | } \ |
| 427 | } while (false) |
| 428 | |
Andre Przywara | 72b7ce1 | 2024-11-04 13:44:39 +0000 | [diff] [blame] | 429 | #define SKIP_TEST_IF_LS64_ACCDATA_NOT_SUPPORTED() \ |
| 430 | do { \ |
| 431 | if (get_feat_ls64_support() < \ |
| 432 | ID_AA64ISAR1_LS64_ACCDATA_SUPPORTED) { \ |
| 433 | tftf_testcase_printf("ARMv8.7-ls64-accdata not supported"); \ |
| 434 | return TEST_RESULT_SKIPPED; \ |
| 435 | } \ |
| 436 | } while (false) |
| 437 | |
Javier Almansa Sobrino | 7c78f7b | 2024-10-25 11:44:32 +0100 | [diff] [blame] | 438 | #define SKIP_TEST_IF_DOUBLE_FAULT2_NOT_SUPPORTED() \ |
| 439 | do { \ |
| 440 | if (is_feat_double_fault2_present() == false) { \ |
| 441 | return TEST_RESULT_SKIPPED; \ |
| 442 | } \ |
| 443 | } while (false) |
| 444 | |
Javier Almansa Sobrino | 82cd82e | 2025-01-17 17:37:42 +0000 | [diff] [blame] | 445 | #define SKIP_TEST_IF_FEAT_MPAM_NOT_SUPPORTED() \ |
| 446 | do { \ |
| 447 | if (is_feat_mpam_supported() == false) { \ |
| 448 | return TEST_RESULT_SKIPPED; \ |
| 449 | } \ |
| 450 | } while (false) \ |
| 451 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 452 | /* Helper macro to verify if system suspend API is supported */ |
| 453 | #define is_psci_sys_susp_supported() \ |
J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 454 | (tftf_get_psci_feature_info(SMC_PSCI_SYSTEM_SUSPEND) \ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 455 | == PSCI_E_SUCCESS) |
| 456 | |
| 457 | /* Helper macro to verify if PSCI_STAT_COUNT API is supported */ |
| 458 | #define is_psci_stat_count_supported() \ |
J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 459 | (tftf_get_psci_feature_info(SMC_PSCI_STAT_COUNT) \ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 460 | == PSCI_E_SUCCESS) |
| 461 | |
| 462 | /* |
| 463 | * Helper function to verify the system state is ready for system |
| 464 | * suspend. i.e., a single CPU is running and all other CPUs are powered off. |
| 465 | * Returns 1 if the system is ready to suspend, 0 otherwise. |
| 466 | */ |
| 467 | int is_sys_suspend_state_ready(void); |
| 468 | |
| 469 | /* |
| 470 | * Helper function to reset the system. This function shouldn't return. |
| 471 | * It is not marked with __dead to help the test to catch some error in |
| 472 | * TF |
| 473 | */ |
| 474 | void psci_system_reset(void); |
| 475 | |
| 476 | /* |
| 477 | * Helper function that enables/disables the mem_protect mechanism |
| 478 | */ |
| 479 | int psci_mem_protect(int val); |
| 480 | |
| 481 | |
| 482 | /* |
| 483 | * Helper function to call PSCI MEM_PROTECT_CHECK |
| 484 | */ |
| 485 | int psci_mem_protect_check(uintptr_t addr, size_t size); |
| 486 | |
| 487 | |
| 488 | /* |
| 489 | * Helper function to get a sentinel address that can be used to test mem_protect |
| 490 | */ |
| 491 | unsigned char *psci_mem_prot_get_sentinel(void); |
| 492 | |
| 493 | /* |
| 494 | * Helper function to memory map and unmap a region needed by a test. |
| 495 | * |
| 496 | * Return TEST_RESULT_FAIL if the memory could not be successfully mapped or |
| 497 | * unmapped. Otherwise, return the test functions's result. |
| 498 | */ |
| 499 | test_result_t map_test_unmap(const map_args_unmap_t *args, |
| 500 | test_function_arg_t test); |
| 501 | |
J-Alves | f1126f2 | 2020-11-02 17:28:20 +0000 | [diff] [blame] | 502 | /* |
nabkah01 | 9ea1664 | 2022-03-01 19:39:59 +0000 | [diff] [blame] | 503 | * Utility function to wait for all CPUs other than the caller to be |
| 504 | * OFF. |
| 505 | */ |
| 506 | void wait_for_non_lead_cpus(void); |
| 507 | |
| 508 | /* |
| 509 | * Utility function to wait for a given CPU other than the caller to be |
| 510 | * OFF. |
| 511 | */ |
| 512 | void wait_for_core_to_turn_off(unsigned int mpidr); |
AlexeiFedorov | 2f30f10 | 2023-03-13 19:37:46 +0000 | [diff] [blame] | 513 | |
| 514 | /* Generate 64-bit random number */ |
| 515 | unsigned long long rand64(void); |
| 516 | |
Arvind Ram Prakash | 8191621 | 2024-08-15 15:08:23 -0500 | [diff] [blame] | 517 | /* TRBE Errata */ |
| 518 | #define CORTEX_A520_MIDR U(0x410FD800) |
| 519 | #define CORTEX_X4_MIDR U(0x410FD821) |
| 520 | #define RXPX_RANGE(x, y, z) (((x >= y) && (x <= z)) ? true : false) |
| 521 | bool is_trbe_errata_affected_core(void); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 522 | #endif /* __TEST_HELPERS_H__ */ |