blob: 085923a85e74fd6c4823eab30bb56b0823a88721 [file] [log] [blame]
J-Alves9f6f0142020-06-17 15:37:59 +01001/*
2 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <assert.h>
J-Alves9f6f0142020-06-17 15:37:59 +01007#include <debug.h>
Max Shvetsov40eb6a22020-06-08 11:15:30 +01008#include <errno.h>
Max Shvetsovc32f4782020-06-23 09:41:15 +01009#include <cactus_def.h>
J-Alves5aecd982020-06-11 10:25:33 +010010#include <ffa_helpers.h>
J-Alves9f6f0142020-06-17 15:37:59 +010011#include <sp_helpers.h>
12
13/* FFA version test helpers */
14#define FFA_MAJOR 1U
15#define FFA_MINOR 0U
16
Max Shvetsovc32f4782020-06-23 09:41:15 +010017static const uint32_t primary_uuid[4] = PRIMARY_UUID;
18static const uint32_t secondary_uuid[4] = SECONDARY_UUID;
Ruari Phippsd75596a2020-07-17 16:41:34 +010019static const uint32_t tertiary_uuid[4] = TERTIARY_UUID;
Max Shvetsovc32f4782020-06-23 09:41:15 +010020static const uint32_t null_uuid[4] = {0};
21
Max Shvetsov40eb6a22020-06-08 11:15:30 +010022struct feature_test {
23 const char *test_name;
24 unsigned int feature;
25 unsigned int expected_ret;
26};
27
28static const struct feature_test test_target[] = {
29 {"FFA_ERROR_32 check", FFA_ERROR, FFA_SUCCESS_SMC32},
30 {"FFA_SUCCESS_32 check", FFA_SUCCESS_SMC32, FFA_SUCCESS_SMC32},
31 {"FFA_INTERRUPT_32 check", FFA_INTERRUPT, FFA_SUCCESS_SMC32},
32 {"FFA_VERSION_32 check", FFA_VERSION, FFA_SUCCESS_SMC32},
33 {"FFA_FEATURES_32 check", FFA_FEATURES, FFA_SUCCESS_SMC32},
34 {"FFA_RX_RELEASE_32 check", FFA_RX_RELEASE, FFA_SUCCESS_SMC32},
35 {"FFA_RXTX_MAP_32 check", FFA_RXTX_MAP_SMC32, FFA_ERROR},
36 {"FFA_RXTX_MAP_64 check", FFA_RXTX_MAP_SMC64, FFA_SUCCESS_SMC32},
37 {"FFA_RXTX_UNMAP_32 check", FFA_RXTX_UNMAP, FFA_ERROR},
38 {"FFA_PARTITION_INFO_GET_32 check", FFA_PARTITION_INFO_GET, FFA_SUCCESS_SMC32},
39 {"FFA_ID_GET_32 check", FFA_ID_GET, FFA_SUCCESS_SMC32},
40 {"FFA_MSG_POLL_32 check", FFA_MSG_POLL, FFA_SUCCESS_SMC32},
41 {"FFA_MSG_WAIT_32 check", FFA_MSG_WAIT, FFA_SUCCESS_SMC32},
42 {"FFA_YIELD_32 check", FFA_MSG_YIELD, FFA_SUCCESS_SMC32},
43 {"FFA_RUN_32 check", FFA_MSG_RUN, FFA_SUCCESS_SMC32},
44 {"FFA_MSG_SEND_32 check", FFA_MSG_SEND, FFA_SUCCESS_SMC32},
45 {"FFA_MEM_DONATE_32 check", FFA_MEM_DONATE_SMC32, FFA_SUCCESS_SMC32},
46 {"FFA_MEM_LEND_32 check", FFA_MEM_LEND_SMC32, FFA_SUCCESS_SMC32},
47 {"FFA_MEM_SHARE_32 check", FFA_MEM_SHARE_SMC32, FFA_SUCCESS_SMC32},
48 {"FFA_MEM_RETRIEVE_REQ_32 check", FFA_MEM_RETRIEVE_REQ_SMC32, FFA_SUCCESS_SMC32},
49 {"FFA_MEM_RETRIEVE_RESP_32 check", FFA_MEM_RETRIEVE_RESP, FFA_SUCCESS_SMC32},
50 {"FFA_MEM_RELINQUISH_32 check", FFA_MEM_RELINQUISH, FFA_SUCCESS_SMC32},
51 {"FFA_MEM_RECLAIM_32 check", FFA_MEM_RECLAIM, FFA_SUCCESS_SMC32},
52 {"Check non-existent command", 0xFFFF, FFA_ERROR}
53};
54
55/*
56 * Test FFA_FEATURES interface.
57 */
58static void ffa_features_test(void)
59{
60 const char *test_features = "FFA Features interface";
61 smc_ret_values ffa_ret;
62 unsigned int i, test_target_size =
63 sizeof(test_target) / sizeof(struct feature_test);
64
65 announce_test_section_start(test_features);
66
67 for (i = 0U; i < test_target_size; i++) {
68 announce_test_start(test_target[i].test_name);
69
70 ffa_ret = ffa_features(test_target[i].feature);
71 expect(ffa_ret.ret0, test_target[i].expected_ret);
72 if (test_target[i].expected_ret == FFA_ERROR) {
73 expect(ffa_ret.ret2, FFA_ERROR_NOT_SUPPORTED);
74 }
75
76 announce_test_end(test_target[i].test_name);
77 }
78
79 announce_test_section_end(test_features);
80}
81
Max Shvetsovc32f4782020-06-23 09:41:15 +010082static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4],
83 const struct ffa_partition_info *expected,
84 const uint16_t expected_size)
85{
86 smc_ret_values ret = ffa_partition_info_get(uuid);
87 unsigned int i;
88 expect(ret.ret0, FFA_SUCCESS_SMC32);
89
90 struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv);
91 for (i = 0U; i < expected_size; i++) {
92 expect(info[i].id, expected[i].id);
93 expect(info[i].exec_context, expected[i].exec_context);
94 expect(info[i].properties, expected[i].properties);
95 }
96
97 ret = ffa_rx_release();
98 expect(ret.ret0, FFA_SUCCESS_SMC32);
99}
100
101static void ffa_partition_info_wrong_test(void)
102{
103 const char *test_wrong_uuid = "Request wrong UUID";
104 uint32_t uuid[4] = {1};
105
106 announce_test_start(test_wrong_uuid);
107
108 smc_ret_values ret = ffa_partition_info_get(uuid);
109 expect(ret.ret0, FFA_ERROR);
110 expect(ret.ret2, FFA_ERROR_INVALID_PARAMETER);
111
112 announce_test_end(test_wrong_uuid);
113}
114
115static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
116{
117 const char *test_partition_info = "FFA Partition info interface";
118 const char *test_primary = "Get primary partition info";
119 const char *test_secondary = "Get secondary partition info";
Ruari Phippsd75596a2020-07-17 16:41:34 +0100120 const char *test_tertiary = "Get tertiary partition info";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100121 const char *test_all = "Get all partitions info";
122
123 const struct ffa_partition_info expected_info[] = {
124 {.id = SPM_VM_ID_FIRST, .exec_context = 8, .properties = 0}, /* Primary partition info */
Ruari Phippsd75596a2020-07-17 16:41:34 +0100125 {.id = SPM_VM_ID_SECOND, .exec_context = 2, .properties = 0}, /* Secondary partition info */
126 {.id = SPM_VM_ID_THIRD, .exec_context = 2, .properties = 0} /* Tertiary partition info */
Max Shvetsovc32f4782020-06-23 09:41:15 +0100127 };
128
129 announce_test_section_start(test_partition_info);
130
Ruari Phippsd75596a2020-07-17 16:41:34 +0100131 announce_test_start(test_tertiary);
132 ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1);
133 announce_test_end(test_tertiary);
134
Max Shvetsovc32f4782020-06-23 09:41:15 +0100135 announce_test_start(test_secondary);
136 ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1);
137 announce_test_end(test_secondary);
138
139 announce_test_start(test_primary);
140 ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1);
141 announce_test_end(test_primary);
142
143 announce_test_start(test_all);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100144 ffa_partition_info_helper(mb, null_uuid, expected_info, 3);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100145 announce_test_end(test_all);
146
147 ffa_partition_info_wrong_test();
148
149 announce_test_section_end(test_partition_info);
150}
151
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100152void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100153{
J-Alves9f6f0142020-06-17 15:37:59 +0100154 const char *test_ffa_version = "FFA Version interface";
155
J-Alves9f6f0142020-06-17 15:37:59 +0100156 announce_test_start(test_ffa_version);
157
158 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100159 uint32_t spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100160
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100161 bool ffa_version_compatible =
162 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
163 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100164
165 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
166 spm_version >> FFA_VERSION_MAJOR_SHIFT,
167 spm_version & FFA_VERSION_MINOR_MASK,
168 (int)ffa_version_compatible);
169
170 expect((int)ffa_version_compatible, (int)true);
171
172 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100173}
174
175void ffa_tests(struct mailbox_buffers *mb)
176{
177 const char *test_ffa = "FFA Interfaces";
178
179 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100180
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100181 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100182 ffa_version_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100183 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100184
J-Alves9f6f0142020-06-17 15:37:59 +0100185 announce_test_section_end(test_ffa);
186}