blob: 81970f7636fca43321be523b21e78e8b9a285dfe [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>
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +01009#include <cactus_platform_def.h>
Max Shvetsovc32f4782020-06-23 09:41:15 +010010#include <cactus_def.h>
J-Alves5aecd982020-06-11 10:25:33 +010011#include <ffa_helpers.h>
J-Alves9f6f0142020-06-17 15:37:59 +010012#include <sp_helpers.h>
13
14/* FFA version test helpers */
15#define FFA_MAJOR 1U
16#define FFA_MINOR 0U
17
Max Shvetsovc32f4782020-06-23 09:41:15 +010018static const uint32_t primary_uuid[4] = PRIMARY_UUID;
19static const uint32_t secondary_uuid[4] = SECONDARY_UUID;
Ruari Phippsd75596a2020-07-17 16:41:34 +010020static const uint32_t tertiary_uuid[4] = TERTIARY_UUID;
Max Shvetsovc32f4782020-06-23 09:41:15 +010021static const uint32_t null_uuid[4] = {0};
22
Max Shvetsov40eb6a22020-06-08 11:15:30 +010023struct feature_test {
24 const char *test_name;
25 unsigned int feature;
26 unsigned int expected_ret;
27};
28
29static const struct feature_test test_target[] = {
30 {"FFA_ERROR_32 check", FFA_ERROR, FFA_SUCCESS_SMC32},
31 {"FFA_SUCCESS_32 check", FFA_SUCCESS_SMC32, FFA_SUCCESS_SMC32},
32 {"FFA_INTERRUPT_32 check", FFA_INTERRUPT, FFA_SUCCESS_SMC32},
33 {"FFA_VERSION_32 check", FFA_VERSION, FFA_SUCCESS_SMC32},
34 {"FFA_FEATURES_32 check", FFA_FEATURES, FFA_SUCCESS_SMC32},
35 {"FFA_RX_RELEASE_32 check", FFA_RX_RELEASE, FFA_SUCCESS_SMC32},
36 {"FFA_RXTX_MAP_32 check", FFA_RXTX_MAP_SMC32, FFA_ERROR},
37 {"FFA_RXTX_MAP_64 check", FFA_RXTX_MAP_SMC64, FFA_SUCCESS_SMC32},
38 {"FFA_RXTX_UNMAP_32 check", FFA_RXTX_UNMAP, FFA_ERROR},
39 {"FFA_PARTITION_INFO_GET_32 check", FFA_PARTITION_INFO_GET, FFA_SUCCESS_SMC32},
40 {"FFA_ID_GET_32 check", FFA_ID_GET, FFA_SUCCESS_SMC32},
41 {"FFA_MSG_POLL_32 check", FFA_MSG_POLL, FFA_SUCCESS_SMC32},
42 {"FFA_MSG_WAIT_32 check", FFA_MSG_WAIT, FFA_SUCCESS_SMC32},
43 {"FFA_YIELD_32 check", FFA_MSG_YIELD, FFA_SUCCESS_SMC32},
44 {"FFA_RUN_32 check", FFA_MSG_RUN, FFA_SUCCESS_SMC32},
45 {"FFA_MSG_SEND_32 check", FFA_MSG_SEND, FFA_SUCCESS_SMC32},
46 {"FFA_MEM_DONATE_32 check", FFA_MEM_DONATE_SMC32, FFA_SUCCESS_SMC32},
47 {"FFA_MEM_LEND_32 check", FFA_MEM_LEND_SMC32, FFA_SUCCESS_SMC32},
48 {"FFA_MEM_SHARE_32 check", FFA_MEM_SHARE_SMC32, FFA_SUCCESS_SMC32},
49 {"FFA_MEM_RETRIEVE_REQ_32 check", FFA_MEM_RETRIEVE_REQ_SMC32, FFA_SUCCESS_SMC32},
50 {"FFA_MEM_RETRIEVE_RESP_32 check", FFA_MEM_RETRIEVE_RESP, FFA_SUCCESS_SMC32},
51 {"FFA_MEM_RELINQUISH_32 check", FFA_MEM_RELINQUISH, FFA_SUCCESS_SMC32},
52 {"FFA_MEM_RECLAIM_32 check", FFA_MEM_RECLAIM, FFA_SUCCESS_SMC32},
53 {"Check non-existent command", 0xFFFF, FFA_ERROR}
54};
55
56/*
57 * Test FFA_FEATURES interface.
58 */
59static void ffa_features_test(void)
60{
61 const char *test_features = "FFA Features interface";
62 smc_ret_values ffa_ret;
63 unsigned int i, test_target_size =
64 sizeof(test_target) / sizeof(struct feature_test);
65
66 announce_test_section_start(test_features);
67
68 for (i = 0U; i < test_target_size; i++) {
69 announce_test_start(test_target[i].test_name);
70
71 ffa_ret = ffa_features(test_target[i].feature);
72 expect(ffa_ret.ret0, test_target[i].expected_ret);
73 if (test_target[i].expected_ret == FFA_ERROR) {
74 expect(ffa_ret.ret2, FFA_ERROR_NOT_SUPPORTED);
75 }
76
77 announce_test_end(test_target[i].test_name);
78 }
79
80 announce_test_section_end(test_features);
81}
82
Max Shvetsovc32f4782020-06-23 09:41:15 +010083static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4],
84 const struct ffa_partition_info *expected,
85 const uint16_t expected_size)
86{
87 smc_ret_values ret = ffa_partition_info_get(uuid);
88 unsigned int i;
89 expect(ret.ret0, FFA_SUCCESS_SMC32);
90
91 struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv);
92 for (i = 0U; i < expected_size; i++) {
93 expect(info[i].id, expected[i].id);
94 expect(info[i].exec_context, expected[i].exec_context);
95 expect(info[i].properties, expected[i].properties);
96 }
97
98 ret = ffa_rx_release();
99 expect(ret.ret0, FFA_SUCCESS_SMC32);
100}
101
102static void ffa_partition_info_wrong_test(void)
103{
104 const char *test_wrong_uuid = "Request wrong UUID";
105 uint32_t uuid[4] = {1};
106
107 announce_test_start(test_wrong_uuid);
108
109 smc_ret_values ret = ffa_partition_info_get(uuid);
110 expect(ret.ret0, FFA_ERROR);
111 expect(ret.ret2, FFA_ERROR_INVALID_PARAMETER);
112
113 announce_test_end(test_wrong_uuid);
114}
115
116static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
117{
118 const char *test_partition_info = "FFA Partition info interface";
119 const char *test_primary = "Get primary partition info";
120 const char *test_secondary = "Get secondary partition info";
Ruari Phippsd75596a2020-07-17 16:41:34 +0100121 const char *test_tertiary = "Get tertiary partition info";
Max Shvetsovc32f4782020-06-23 09:41:15 +0100122 const char *test_all = "Get all partitions info";
123
124 const struct ffa_partition_info expected_info[] = {
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100125 /* Primary partition info */
126 {
127 .id = SPM_VM_ID_FIRST,
128 .exec_context = CACTUS_PRIMARY_EC_COUNT,
129 .properties = 0U
130 },
131 /* Secondary partition info */
132 {
133 .id = SPM_VM_ID_FIRST + 1U,
134 .exec_context = CACTUS_SECONDARY_EC_COUNT,
135 .properties = 0U
136 },
137 /* Tertiary partition info */
138 {
139 .id = SPM_VM_ID_FIRST + 2U,
140 .exec_context = CACTUS_TERTIARY_EC_COUNT,
141 .properties = 0U
142 }
Max Shvetsovc32f4782020-06-23 09:41:15 +0100143 };
144
145 announce_test_section_start(test_partition_info);
146
Ruari Phippsd75596a2020-07-17 16:41:34 +0100147 announce_test_start(test_tertiary);
148 ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1);
149 announce_test_end(test_tertiary);
150
Max Shvetsovc32f4782020-06-23 09:41:15 +0100151 announce_test_start(test_secondary);
152 ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1);
153 announce_test_end(test_secondary);
154
155 announce_test_start(test_primary);
156 ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1);
157 announce_test_end(test_primary);
158
159 announce_test_start(test_all);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100160 ffa_partition_info_helper(mb, null_uuid, expected_info, 3);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100161 announce_test_end(test_all);
162
163 ffa_partition_info_wrong_test();
164
165 announce_test_section_end(test_partition_info);
166}
167
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100168void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100169{
J-Alves9f6f0142020-06-17 15:37:59 +0100170 const char *test_ffa_version = "FFA Version interface";
171
J-Alves9f6f0142020-06-17 15:37:59 +0100172 announce_test_start(test_ffa_version);
173
174 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100175 uint32_t spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100176
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100177 bool ffa_version_compatible =
178 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
179 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100180
181 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
182 spm_version >> FFA_VERSION_MAJOR_SHIFT,
183 spm_version & FFA_VERSION_MINOR_MASK,
184 (int)ffa_version_compatible);
185
186 expect((int)ffa_version_compatible, (int)true);
187
188 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100189}
190
191void ffa_tests(struct mailbox_buffers *mb)
192{
193 const char *test_ffa = "FFA Interfaces";
194
195 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100196
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100197 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100198 ffa_version_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100199 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100200
J-Alves9f6f0142020-06-17 15:37:59 +0100201 announce_test_section_end(test_ffa);
202}