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