Daniel Boulby | 82bf339 | 2023-07-28 18:32:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SPM_TEST_HELPERS_H__ |
| 8 | #define SPM_TEST_HELPERS_H__ |
| 9 | |
| 10 | #include <events.h> |
| 11 | #include <ffa_helpers.h> |
| 12 | #include <ffa_svc.h> |
| 13 | #include <spm_common.h> |
| 14 | |
| 15 | #define SKIP_TEST_IF_FFA_VERSION_LESS_THAN(major, minor) \ |
| 16 | do { \ |
| 17 | struct ffa_value ret = ffa_version( \ |
Karl Meakin | 7308b12 | 2024-04-16 14:02:25 +0100 | [diff] [blame] | 18 | make_ffa_version(major, minor)); \ |
| 19 | enum ffa_version version = ret.fid; \ |
Daniel Boulby | 82bf339 | 2023-07-28 18:32:27 +0100 | [diff] [blame] | 20 | \ |
| 21 | if (version == FFA_ERROR_NOT_SUPPORTED) { \ |
| 22 | tftf_testcase_printf("FFA_VERSION not supported.\n"); \ |
| 23 | return TEST_RESULT_SKIPPED; \ |
| 24 | } \ |
| 25 | \ |
Karl Meakin | 7308b12 | 2024-04-16 14:02:25 +0100 | [diff] [blame] | 26 | if (!ffa_version_is_valid(version)) { \ |
Daniel Boulby | 82bf339 | 2023-07-28 18:32:27 +0100 | [diff] [blame] | 27 | tftf_testcase_printf("FFA_VERSION bad response: %x\n", \ |
| 28 | version); \ |
| 29 | return TEST_RESULT_FAIL; \ |
| 30 | } \ |
| 31 | \ |
Karl Meakin | 7308b12 | 2024-04-16 14:02:25 +0100 | [diff] [blame] | 32 | if (version < make_ffa_version(major, minor)) { \ |
Daniel Boulby | 82bf339 | 2023-07-28 18:32:27 +0100 | [diff] [blame] | 33 | tftf_testcase_printf("FFA_VERSION returned %u.%u\n" \ |
| 34 | "The required version is %u.%u\n", \ |
Karl Meakin | 7308b12 | 2024-04-16 14:02:25 +0100 | [diff] [blame] | 35 | ffa_version_get_major(version), \ |
| 36 | ffa_version_get_minor(version), \ |
Daniel Boulby | 82bf339 | 2023-07-28 18:32:27 +0100 | [diff] [blame] | 37 | major, minor); \ |
| 38 | return TEST_RESULT_SKIPPED; \ |
| 39 | } \ |
| 40 | } while (0) |
| 41 | |
| 42 | #define SKIP_TEST_IF_FFA_ENDPOINT_NOT_DEPLOYED(mb, ffa_uuid) \ |
| 43 | do { \ |
| 44 | struct ffa_value sc_ret = ffa_partition_info_get(ffa_uuid); \ |
| 45 | ffa_rx_release(); \ |
| 46 | if (ffa_func_id(sc_ret) == FFA_ERROR && \ |
| 47 | ffa_error_code(sc_ret) == FFA_ERROR_INVALID_PARAMETER) { \ |
| 48 | tftf_testcase_printf("FFA endpoint not deployed!\n"); \ |
| 49 | return TEST_RESULT_SKIPPED; \ |
| 50 | } else if (ffa_func_id(sc_ret) != FFA_SUCCESS_SMC32) { \ |
| 51 | ERROR("ffa_partition_info_get failed!\n"); \ |
| 52 | return TEST_RESULT_FAIL; \ |
| 53 | } \ |
| 54 | } while (0) |
| 55 | |
| 56 | #define GET_TFTF_MAILBOX(mb) \ |
| 57 | do { \ |
| 58 | if (!get_tftf_mailbox(&mb)) { \ |
| 59 | ERROR("Mailbox RXTX buffers not configured!\n"); \ |
| 60 | return TEST_RESULT_FAIL; \ |
| 61 | } \ |
| 62 | } while (false); |
| 63 | |
| 64 | #define CHECK_SPMC_TESTING_SETUP(ffa_major, ffa_minor, expected_uuids) \ |
| 65 | do { \ |
| 66 | SKIP_TEST_IF_AARCH32(); \ |
| 67 | const size_t expected_uuids_size = \ |
| 68 | sizeof(expected_uuids) / sizeof(struct ffa_uuid); \ |
| 69 | test_result_t ret = check_spmc_testing_set_up( \ |
| 70 | ffa_major, ffa_minor, expected_uuids, \ |
| 71 | expected_uuids_size); \ |
| 72 | if (ret != TEST_RESULT_SUCCESS) { \ |
| 73 | return ret; \ |
| 74 | } \ |
| 75 | } while (false); |
| 76 | |
| 77 | /* |
| 78 | * Helper function to reset TFTF global mailbox for SPM related tests. |
| 79 | * It calls the FFA_RXTX_UNMAP interface, for the SPMC to drop the current |
| 80 | * address. |
| 81 | */ |
| 82 | bool reset_tftf_mailbox(void); |
| 83 | |
| 84 | /* |
| 85 | * Helper function to get TFTF global mailbox for SPM related tests. |
| 86 | * Allocates RX/TX buffer pair and calls FFA_RXTX_MAP interface, for the SPMC |
| 87 | * to map them into its own S1 translation. |
| 88 | * If this function is called, and the buffers had been priorly mapped, it |
| 89 | * sets 'mb' with the respective addresses. |
| 90 | */ |
| 91 | bool get_tftf_mailbox(struct mailbox_buffers *mb); |
| 92 | |
| 93 | test_result_t check_spmc_testing_set_up(uint32_t ffa_version_major, |
| 94 | uint32_t ffa_version_minor, const struct ffa_uuid *ffa_uuids, |
| 95 | size_t ffa_uuids_size); |
| 96 | |
| 97 | /** |
| 98 | * Turn on all cpus to execute a test in all. |
| 99 | * - 'cpu_on_handler' should have the code containing the test. |
| 100 | * - 'cpu_booted' is used for notifying which cores the test has been executed. |
| 101 | * This should be used in the test executed by cpu_on_handler at the end of |
| 102 | * processing to make sure it complies with this function's implementation. |
| 103 | */ |
| 104 | test_result_t spm_run_multi_core_test(uintptr_t cpu_on_handler, |
| 105 | event_t *cpu_booted); |
| 106 | |
| 107 | /** |
| 108 | * Call FFA_RUN in the designated SP to make it reach the message loop. |
| 109 | * Used within CPU_ON handlers, to bring up the SP in the current core. |
| 110 | */ |
| 111 | bool spm_core_sp_init(ffa_id_t sp_id); |
| 112 | |
| 113 | /** |
| 114 | * Initializes the Mailbox for other SPM related tests that need to use |
| 115 | * RXTX buffers. |
| 116 | */ |
| 117 | bool mailbox_init(struct mailbox_buffers mb); |
| 118 | |
| 119 | #endif /* __SPM_TEST_HELPERS_H__ */ |