blob: 25c20b0045c02117b9fb9b1cdb70c0c07c55a2d8 [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;
19static const uint32_t null_uuid[4] = {0};
20
Max Shvetsov40eb6a22020-06-08 11:15:30 +010021struct feature_test {
22 const char *test_name;
23 unsigned int feature;
24 unsigned int expected_ret;
25};
26
27static const struct feature_test test_target[] = {
28 {"FFA_ERROR_32 check", FFA_ERROR, FFA_SUCCESS_SMC32},
29 {"FFA_SUCCESS_32 check", FFA_SUCCESS_SMC32, FFA_SUCCESS_SMC32},
30 {"FFA_INTERRUPT_32 check", FFA_INTERRUPT, FFA_SUCCESS_SMC32},
31 {"FFA_VERSION_32 check", FFA_VERSION, FFA_SUCCESS_SMC32},
32 {"FFA_FEATURES_32 check", FFA_FEATURES, FFA_SUCCESS_SMC32},
33 {"FFA_RX_RELEASE_32 check", FFA_RX_RELEASE, FFA_SUCCESS_SMC32},
34 {"FFA_RXTX_MAP_32 check", FFA_RXTX_MAP_SMC32, FFA_ERROR},
35 {"FFA_RXTX_MAP_64 check", FFA_RXTX_MAP_SMC64, FFA_SUCCESS_SMC32},
36 {"FFA_RXTX_UNMAP_32 check", FFA_RXTX_UNMAP, FFA_ERROR},
37 {"FFA_PARTITION_INFO_GET_32 check", FFA_PARTITION_INFO_GET, FFA_SUCCESS_SMC32},
38 {"FFA_ID_GET_32 check", FFA_ID_GET, FFA_SUCCESS_SMC32},
39 {"FFA_MSG_POLL_32 check", FFA_MSG_POLL, FFA_SUCCESS_SMC32},
40 {"FFA_MSG_WAIT_32 check", FFA_MSG_WAIT, FFA_SUCCESS_SMC32},
41 {"FFA_YIELD_32 check", FFA_MSG_YIELD, FFA_SUCCESS_SMC32},
42 {"FFA_RUN_32 check", FFA_MSG_RUN, FFA_SUCCESS_SMC32},
43 {"FFA_MSG_SEND_32 check", FFA_MSG_SEND, FFA_SUCCESS_SMC32},
44 {"FFA_MEM_DONATE_32 check", FFA_MEM_DONATE_SMC32, FFA_SUCCESS_SMC32},
45 {"FFA_MEM_LEND_32 check", FFA_MEM_LEND_SMC32, FFA_SUCCESS_SMC32},
46 {"FFA_MEM_SHARE_32 check", FFA_MEM_SHARE_SMC32, FFA_SUCCESS_SMC32},
47 {"FFA_MEM_RETRIEVE_REQ_32 check", FFA_MEM_RETRIEVE_REQ_SMC32, FFA_SUCCESS_SMC32},
48 {"FFA_MEM_RETRIEVE_RESP_32 check", FFA_MEM_RETRIEVE_RESP, FFA_SUCCESS_SMC32},
49 {"FFA_MEM_RELINQUISH_32 check", FFA_MEM_RELINQUISH, FFA_SUCCESS_SMC32},
50 {"FFA_MEM_RECLAIM_32 check", FFA_MEM_RECLAIM, FFA_SUCCESS_SMC32},
51 {"Check non-existent command", 0xFFFF, FFA_ERROR}
52};
53
54/*
55 * Test FFA_FEATURES interface.
56 */
57static void ffa_features_test(void)
58{
59 const char *test_features = "FFA Features interface";
60 smc_ret_values ffa_ret;
61 unsigned int i, test_target_size =
62 sizeof(test_target) / sizeof(struct feature_test);
63
64 announce_test_section_start(test_features);
65
66 for (i = 0U; i < test_target_size; i++) {
67 announce_test_start(test_target[i].test_name);
68
69 ffa_ret = ffa_features(test_target[i].feature);
70 expect(ffa_ret.ret0, test_target[i].expected_ret);
71 if (test_target[i].expected_ret == FFA_ERROR) {
72 expect(ffa_ret.ret2, FFA_ERROR_NOT_SUPPORTED);
73 }
74
75 announce_test_end(test_target[i].test_name);
76 }
77
78 announce_test_section_end(test_features);
79}
80
Max Shvetsovc32f4782020-06-23 09:41:15 +010081static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4],
82 const struct ffa_partition_info *expected,
83 const uint16_t expected_size)
84{
85 smc_ret_values ret = ffa_partition_info_get(uuid);
86 unsigned int i;
87 expect(ret.ret0, FFA_SUCCESS_SMC32);
88
89 struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv);
90 for (i = 0U; i < expected_size; i++) {
91 expect(info[i].id, expected[i].id);
92 expect(info[i].exec_context, expected[i].exec_context);
93 expect(info[i].properties, expected[i].properties);
94 }
95
96 ret = ffa_rx_release();
97 expect(ret.ret0, FFA_SUCCESS_SMC32);
98}
99
100static void ffa_partition_info_wrong_test(void)
101{
102 const char *test_wrong_uuid = "Request wrong UUID";
103 uint32_t uuid[4] = {1};
104
105 announce_test_start(test_wrong_uuid);
106
107 smc_ret_values ret = ffa_partition_info_get(uuid);
108 expect(ret.ret0, FFA_ERROR);
109 expect(ret.ret2, FFA_ERROR_INVALID_PARAMETER);
110
111 announce_test_end(test_wrong_uuid);
112}
113
114static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
115{
116 const char *test_partition_info = "FFA Partition info interface";
117 const char *test_primary = "Get primary partition info";
118 const char *test_secondary = "Get secondary partition info";
119 const char *test_all = "Get all partitions info";
120
121 const struct ffa_partition_info expected_info[] = {
122 {.id = SPM_VM_ID_FIRST, .exec_context = 8, .properties = 0}, /* Primary partition info */
123 {.id = 2, .exec_context = 2, .properties = 0} /* Secondary partition info */
124 };
125
126 announce_test_section_start(test_partition_info);
127
128 announce_test_start(test_secondary);
129 ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1);
130 announce_test_end(test_secondary);
131
132 announce_test_start(test_primary);
133 ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1);
134 announce_test_end(test_primary);
135
136 announce_test_start(test_all);
137 ffa_partition_info_helper(mb, null_uuid, expected_info, 2);
138 announce_test_end(test_all);
139
140 ffa_partition_info_wrong_test();
141
142 announce_test_section_end(test_partition_info);
143}
144
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100145void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100146{
J-Alves9f6f0142020-06-17 15:37:59 +0100147 const char *test_ffa_version = "FFA Version interface";
148
J-Alves9f6f0142020-06-17 15:37:59 +0100149 announce_test_start(test_ffa_version);
150
151 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100152 uint32_t spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100153
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100154 bool ffa_version_compatible =
155 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
156 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100157
158 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
159 spm_version >> FFA_VERSION_MAJOR_SHIFT,
160 spm_version & FFA_VERSION_MINOR_MASK,
161 (int)ffa_version_compatible);
162
163 expect((int)ffa_version_compatible, (int)true);
164
165 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100166}
167
168void ffa_tests(struct mailbox_buffers *mb)
169{
170 const char *test_ffa = "FFA Interfaces";
171
172 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100173
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100174 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100175 ffa_version_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100176 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100177
J-Alves9f6f0142020-06-17 15:37:59 +0100178 announce_test_section_end(test_ffa);
179}