blob: 93675ce77a2372c7a4e01adbd5b024651a690e03 [file] [log] [blame]
Daniel Boulby82bf3392023-07-28 18:32:27 +01001/*
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 { \
Karl Meakin1abd8df2024-07-01 10:03:18 +010017 struct ffa_value ret = ffa_version(FFA_VERSION_COMPILED); \
Karl Meakinaf77b162024-06-19 10:44:54 +010018 enum ffa_version version; \
Daniel Boulby82bf3392023-07-28 18:32:27 +010019 \
Karl Meakinaf77b162024-06-19 10:44:54 +010020 if (ret.fid == FFA_ERROR_NOT_SUPPORTED) { \
Daniel Boulby82bf3392023-07-28 18:32:27 +010021 tftf_testcase_printf("FFA_VERSION not supported.\n"); \
22 return TEST_RESULT_SKIPPED; \
23 } \
24 \
Karl Meakinaf77b162024-06-19 10:44:54 +010025 version = ret.fid; \
26 \
27 if (!ffa_version_is_valid(version)) { \
Daniel Boulby82bf3392023-07-28 18:32:27 +010028 tftf_testcase_printf("FFA_VERSION bad response: %x\n", \
29 version); \
30 return TEST_RESULT_FAIL; \
31 } \
32 \
Karl Meakin7308b122024-04-16 14:02:25 +010033 if (version < make_ffa_version(major, minor)) { \
Daniel Boulby82bf3392023-07-28 18:32:27 +010034 tftf_testcase_printf("FFA_VERSION returned %u.%u\n" \
35 "The required version is %u.%u\n", \
Karl Meakin7308b122024-04-16 14:02:25 +010036 ffa_version_get_major(version), \
37 ffa_version_get_minor(version), \
Daniel Boulby82bf3392023-07-28 18:32:27 +010038 major, minor); \
39 return TEST_RESULT_SKIPPED; \
40 } \
41 } while (0)
42
43#define SKIP_TEST_IF_FFA_ENDPOINT_NOT_DEPLOYED(mb, ffa_uuid) \
44 do { \
45 struct ffa_value sc_ret = ffa_partition_info_get(ffa_uuid); \
46 ffa_rx_release(); \
47 if (ffa_func_id(sc_ret) == FFA_ERROR && \
48 ffa_error_code(sc_ret) == FFA_ERROR_INVALID_PARAMETER) { \
49 tftf_testcase_printf("FFA endpoint not deployed!\n"); \
50 return TEST_RESULT_SKIPPED; \
51 } else if (ffa_func_id(sc_ret) != FFA_SUCCESS_SMC32) { \
52 ERROR("ffa_partition_info_get failed!\n"); \
53 return TEST_RESULT_FAIL; \
54 } \
55 } while (0)
56
57#define GET_TFTF_MAILBOX(mb) \
58 do { \
59 if (!get_tftf_mailbox(&mb)) { \
60 ERROR("Mailbox RXTX buffers not configured!\n"); \
61 return TEST_RESULT_FAIL; \
62 } \
63 } while (false);
64
65#define CHECK_SPMC_TESTING_SETUP(ffa_major, ffa_minor, expected_uuids) \
66 do { \
67 SKIP_TEST_IF_AARCH32(); \
68 const size_t expected_uuids_size = \
69 sizeof(expected_uuids) / sizeof(struct ffa_uuid); \
70 test_result_t ret = check_spmc_testing_set_up( \
71 ffa_major, ffa_minor, expected_uuids, \
72 expected_uuids_size); \
73 if (ret != TEST_RESULT_SUCCESS) { \
74 return ret; \
75 } \
76 } while (false);
77
78/*
79 * Helper function to reset TFTF global mailbox for SPM related tests.
80 * It calls the FFA_RXTX_UNMAP interface, for the SPMC to drop the current
81 * address.
82 */
83bool reset_tftf_mailbox(void);
84
85/*
86 * Helper function to get TFTF global mailbox for SPM related tests.
87 * Allocates RX/TX buffer pair and calls FFA_RXTX_MAP interface, for the SPMC
88 * to map them into its own S1 translation.
89 * If this function is called, and the buffers had been priorly mapped, it
90 * sets 'mb' with the respective addresses.
91 */
92bool get_tftf_mailbox(struct mailbox_buffers *mb);
93
94test_result_t check_spmc_testing_set_up(uint32_t ffa_version_major,
95 uint32_t ffa_version_minor, const struct ffa_uuid *ffa_uuids,
96 size_t ffa_uuids_size);
97
98/**
99 * Turn on all cpus to execute a test in all.
100 * - 'cpu_on_handler' should have the code containing the test.
101 * - 'cpu_booted' is used for notifying which cores the test has been executed.
102 * This should be used in the test executed by cpu_on_handler at the end of
103 * processing to make sure it complies with this function's implementation.
104 */
105test_result_t spm_run_multi_core_test(uintptr_t cpu_on_handler,
106 event_t *cpu_booted);
107
108/**
Daniel Boulby82bf3392023-07-28 18:32:27 +0100109 * Initializes the Mailbox for other SPM related tests that need to use
110 * RXTX buffers.
111 */
112bool mailbox_init(struct mailbox_buffers mb);
113
114#endif /* __SPM_TEST_HELPERS_H__ */