blob: 593b7177fcea0d1725531266fc19d60009a141e6 [file] [log] [blame]
Abdellatif El Khlifi3d4fb572023-08-04 14:33:42 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Functional tests for UCLASS_FFA class
4 *
5 * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
6 *
7 * Authors:
8 * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
9 */
10
Abdellatif El Khlifi3d4fb572023-08-04 14:33:42 +010011#include <console.h>
12#include <dm.h>
13#include <asm/sandbox_arm_ffa.h>
14#include <asm/sandbox_arm_ffa_priv.h>
15#include <dm/test.h>
16#include <test/test.h>
17#include <test/ut.h>
18
19/* Functional tests for the UCLASS_FFA */
20
21static int check_fwk_version(struct ffa_priv *uc_priv, struct unit_test_state *uts)
22{
23 struct ffa_sandbox_data func_data;
24 u32 fwk_version = 0;
25
26 func_data.data0 = &fwk_version;
27 func_data.data0_size = sizeof(fwk_version);
28 ut_assertok(sandbox_query_ffa_emul_state(FFA_VERSION, &func_data));
29 ut_asserteq(uc_priv->fwk_version, fwk_version);
30
31 return 0;
32}
33
34static int check_endpoint_id(struct ffa_priv *uc_priv, struct unit_test_state *uts)
35{
36 ut_asserteq(0, uc_priv->id);
37
38 return 0;
39}
40
41static int check_rxtxbuf(struct ffa_priv *uc_priv, struct unit_test_state *uts)
42{
43 ut_assertnonnull(uc_priv->pair.rxbuf);
44 ut_assertnonnull(uc_priv->pair.txbuf);
45
46 return 0;
47}
48
49static int check_features(struct ffa_priv *uc_priv, struct unit_test_state *uts)
50{
51 ut_assert(uc_priv->pair.rxtx_min_pages == RXTX_4K ||
52 uc_priv->pair.rxtx_min_pages == RXTX_16K ||
53 uc_priv->pair.rxtx_min_pages == RXTX_64K);
54
55 return 0;
56}
57
58static int check_rxbuf_mapped_flag(u32 queried_func_id,
59 u8 rxbuf_mapped,
60 struct unit_test_state *uts)
61{
62 switch (queried_func_id) {
63 case FFA_RXTX_MAP:
64 ut_asserteq(1, rxbuf_mapped);
65 break;
66 case FFA_RXTX_UNMAP:
67 ut_asserteq(0, rxbuf_mapped);
68 break;
69 default:
70 ut_assert(false);
71 }
72
73 return 0;
74}
75
76static int check_rxbuf_release_flag(u8 rxbuf_owned, struct unit_test_state *uts)
77{
78 ut_asserteq(0, rxbuf_owned);
79
80 return 0;
81}
82
83static int test_ffa_msg_send_direct_req(u16 part_id, struct unit_test_state *uts)
84{
85 struct ffa_send_direct_data msg;
86 u8 cnt;
87 struct udevice *dev;
88
89 ut_assertok(uclass_first_device_err(UCLASS_FFA, &dev));
90
91 ut_assertok(ffa_sync_send_receive(dev, part_id, &msg, 1));
92
93 for (cnt = 0; cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64); cnt++)
94 ut_asserteq_64(-1UL, ((u64 *)&msg)[cnt]);
95
96 return 0;
97}
98
99static int test_partitions_and_comms(const char *service_uuid,
100 struct unit_test_state *uts)
101{
102 struct ffa_partition_desc *descs;
103 u32 count, i, j, valid_sps = 0;
104 struct udevice *dev;
105 struct ffa_sandbox_data func_data;
106 struct ffa_partitions *partitions;
107
108 ut_assertok(uclass_first_device_err(UCLASS_FFA, &dev));
109
110 /* Get from the driver the count and information of the SPs matching the UUID */
111 ut_assertok(ffa_partition_info_get(dev, service_uuid, &count, &descs));
112
113 /* Make sure the count is correct */
114 ut_asserteq(SANDBOX_SP_COUNT_PER_VALID_SERVICE, count);
115
116 /* SPs found , verify the partitions information */
117
118 func_data.data0 = &partitions;
119 func_data.data0_size = sizeof(struct ffa_partitions *);
120 ut_assertok(sandbox_query_ffa_emul_state(FFA_PARTITION_INFO_GET, &func_data));
121
122 for (i = 0; i < count ; i++) {
123 for (j = 0;
124 j < partitions->count;
125 j++) {
126 if (descs[i].info.id ==
127 partitions->descs[j].info.id) {
128 valid_sps++;
129 ut_asserteq_mem(&descs[i],
130 &partitions->descs[j],
131 sizeof(struct ffa_partition_desc));
132 /* Send and receive data from the current partition */
133 test_ffa_msg_send_direct_req(descs[i].info.id, uts);
134 }
135 }
136 }
137
138 /* Verify expected partitions found in the emulated secure world */
139 ut_asserteq(SANDBOX_SP_COUNT_PER_VALID_SERVICE, valid_sps);
140
141 return 0;
142}
143
144static int dm_test_ffa_ack(struct unit_test_state *uts)
145{
146 struct ffa_priv *uc_priv;
147 struct ffa_sandbox_data func_data;
148 u8 rxbuf_flag = 0;
149 const char *svc1_uuid = SANDBOX_SERVICE1_UUID;
150 const char *svc2_uuid = SANDBOX_SERVICE2_UUID;
151 struct udevice *dev;
152
153 /* Test probing the sandbox FF-A bus */
154 ut_assertok(uclass_first_device_err(UCLASS_FFA, &dev));
155
156 /* Get a pointer to the sandbox FF-A bus private data */
157 uc_priv = dev_get_uclass_priv(dev);
158
159 /* Make sure the private data pointer is retrieved */
160 ut_assertnonnull(uc_priv);
161
162 /* Test FFA_VERSION */
163 check_fwk_version(uc_priv, uts);
164
165 /* Test FFA_ID_GET */
166 check_endpoint_id(uc_priv, uts);
167
168 /* Test FFA_FEATURES */
169 check_features(uc_priv, uts);
170
171 /* Test RX/TX buffers */
172 check_rxtxbuf(uc_priv, uts);
173
174 /* Test FFA_RXTX_MAP */
175 func_data.data0 = &rxbuf_flag;
176 func_data.data0_size = sizeof(rxbuf_flag);
177
178 rxbuf_flag = 0;
179 sandbox_query_ffa_emul_state(FFA_RXTX_MAP, &func_data);
180 check_rxbuf_mapped_flag(FFA_RXTX_MAP, rxbuf_flag, uts);
181
182 /* FFA_PARTITION_INFO_GET / FFA_MSG_SEND_DIRECT_REQ */
183 test_partitions_and_comms(svc1_uuid, uts);
184
185 /* Test FFA_RX_RELEASE */
186 rxbuf_flag = 1;
187 sandbox_query_ffa_emul_state(FFA_RX_RELEASE, &func_data);
188 check_rxbuf_release_flag(rxbuf_flag, uts);
189
190 /* FFA_PARTITION_INFO_GET / FFA_MSG_SEND_DIRECT_REQ */
191 test_partitions_and_comms(svc2_uuid, uts);
192
193 /* Test FFA_RX_RELEASE */
194 rxbuf_flag = 1;
195 ut_assertok(sandbox_query_ffa_emul_state(FFA_RX_RELEASE, &func_data));
196 check_rxbuf_release_flag(rxbuf_flag, uts);
197
198 return 0;
199}
Simon Glass11fcfa32024-08-22 07:57:50 -0600200DM_TEST(dm_test_ffa_ack, UTF_SCAN_FDT | UTF_CONSOLE);
Abdellatif El Khlifi3d4fb572023-08-04 14:33:42 +0100201
202static int dm_test_ffa_nack(struct unit_test_state *uts)
203{
204 struct ffa_priv *uc_priv;
205 const char *valid_svc_uuid = SANDBOX_SERVICE1_UUID;
206 const char *unvalid_svc_uuid = SANDBOX_SERVICE3_UUID;
207 const char *unvalid_svc_uuid_str = SANDBOX_SERVICE4_UUID;
208 struct ffa_send_direct_data msg;
209 int ret;
210 u32 count;
211 u16 part_id = 0;
212 struct udevice *dev;
213 struct ffa_partition_desc *descs = NULL;
214
215 /* Test probing the sandbox FF-A bus */
216 ut_assertok(uclass_first_device_err(UCLASS_FFA, &dev));
217
218 /* Get a pointer to the sandbox FF-A bus private data */
219 uc_priv = dev_get_uclass_priv(dev);
220
221 /* Make sure the private data pointer is retrieved */
222 ut_assertnonnull(uc_priv);
223
224 /* Query partitions count using invalid arguments */
225 ret = ffa_partition_info_get(dev, NULL, NULL, NULL);
226 ut_asserteq(-EINVAL, ret);
227 ret = ffa_partition_info_get(dev, unvalid_svc_uuid, NULL, NULL);
228 ut_asserteq(-EINVAL, ret);
229 ret = ffa_partition_info_get(dev, unvalid_svc_uuid, &count, NULL);
230 ut_asserteq(-EINVAL, ret);
231
232 /* Query partitions count using an invalid UUID string */
233 ret = ffa_partition_info_get(dev, unvalid_svc_uuid_str, &count, &descs);
234 ut_asserteq(-EINVAL, ret);
235
236 /* Query partitions count using an invalid UUID (no matching SP) */
237 count = 0;
238 ret = ffa_partition_info_get(dev, unvalid_svc_uuid, &count, &descs);
239 ut_asserteq(0, count);
240
241 /* Query partitions data using a valid UUID */
242 count = 0;
243 ut_assertok(ffa_partition_info_get(dev, valid_svc_uuid, &count, &descs));
244 /* Make sure partitions are detected */
245 ut_asserteq(SANDBOX_SP_COUNT_PER_VALID_SERVICE, count);
246 ut_assertnonnull(descs);
247
248 /* Send data to an invalid partition */
249 ret = ffa_sync_send_receive(dev, part_id, &msg, 1);
250 ut_asserteq(-EINVAL, ret);
251
252 /* Send data to a valid partition */
253 part_id = uc_priv->partitions.descs[0].info.id;
254 ut_assertok(ffa_sync_send_receive(dev, part_id, &msg, 1));
255
256 return 0;
257}
Simon Glass11fcfa32024-08-22 07:57:50 -0600258DM_TEST(dm_test_ffa_nack, UTF_SCAN_FDT | UTF_CONSOLE);