blob: 0c6308a03f328f66ba915ecf59a8d2f545380f3e [file] [log] [blame]
Jelle Sels03756662021-05-20 10:41:57 +02001/*
Imre Kise946d912024-04-24 13:24:47 +02002 * Copyright (c) 2022-2024, Arm Limited and Contributors. All rights reserved.
Jelle Sels03756662021-05-20 10:41:57 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <ffa_api.h>
9#include <ffa_internal_api.h>
10#include <ffa_memory_descriptors.h>
11#include <sp_api.h>
12#include <sp_discovery.h>
13#include <sp_memory_management.h>
14#include <sp_rxtx.h>
15#include <string.h>
16#include <trace.h>
17
Jelle Sels6c19b4f2022-10-18 16:40:43 +020018#include "config/interface/config_store.h"
19#include "config/loader/sp/sp_config_loader.h"
20#include "config/ramstore/config_ramstore.h"
21#include "platform/interface/memory_region.h"
Jelle Sels03756662021-05-20 10:41:57 +020022#define SP_TEST_OK 0xaa
23
24static volatile uint8_t tx_buffer[4096] __aligned(4096);
25static volatile uint8_t rx_buffer[4096] __aligned(4096);
26static volatile uint8_t my_buf[4096] __aligned(4096);
27static volatile uint8_t *shared_buffer;
28static size_t shared_buffer_size;
29
30
31
32enum errors {
33 ERR_OK,
34 ERR_VERSION,
35 ERR_ID_GET,
36 ERR_FEATURES,
37 ERR_SP_COMMUNICATION,
38 ERR_RXTX_MAP,
39 ERR_PARTITION,
40 ERR_RXTX_UNMAP,
41 ERR_MEM_INCORRECT_ACCESS,
42 ERR_MEM_RETRIEVE,
43 ERR_MEM_RELINQUISH,
44 ERR_SP_SHARE,
45 ERR_SP_SHARE_EXC,
46 ERR_TEST_NOT_FOUND
47};
48
49enum sp_tests {
50 EP_TEST_SP,
51 EP_TEST_SP_COMMUNICATION,
52 EP_TEST_SP_INCREASE,
53 EP_TRY_R_ACCESS,
54 EP_TRY_W_ACCESS,
55 EP_RETRIEVE,
56 EP_RELINQUISH,
57 EP_SP_MEM_SHARING,
58 EP_SP_MEM_SHARING_MULTI,
59 EP_SP_MEM_SHARING_EXC,
60 EP_SP_MEM_INCORRECT_ACCESS,
Imre Kisbd8e04e2023-08-22 15:17:53 +020061 EP_SP_NOP,
62 EP_TEST_SP_COMMUNICATION_RESPONSE,
Gabor Tothbad63bb2025-03-26 12:43:30 +010063 EP_SP_YIELD
Jelle Sels03756662021-05-20 10:41:57 +020064};
65
66const char* sp_test_str[]= {
67 "EP_TEST_SP",
68 "EP_TEST_SP_COMMUNICATION",
69 "EP_TEST_SP_INCREASE",
70 "EP_TRY_R_ACCESS",
71 "EP_TRY_W_ACCESS",
72 "EP_RETRIEVE",
73 "EP_RELINQUISH",
74 "EP_SP_MEM_SHARING",
75 "EP_SP_MEM_SHARING_MULTI",
76 "EP_SP_MEM_SHARING_EXC",
77 "EP_SP_MEM_INCORRECT_ACCESS",
Gabor Toth2a935aa2025-03-26 14:15:44 +010078 "EP_SP_NOP",
Gabor Tothbad63bb2025-03-26 12:43:30 +010079 "EP_TEST_SP_COMMUNICATION_RESPONSE",
80 "EP_SP_YIELD"
Jelle Sels03756662021-05-20 10:41:57 +020081};
82
83static bool test_ffa_version(void)
84{
85 sp_result result = SP_RESULT_OK;
86 uint16_t major = 0;
87 uint16_t minor = 0;
88
89 IMSG("Testing ffa_version()\n");
90
91 result = sp_discovery_ffa_version_get(&major, &minor);
92 if (result == SP_RESULT_OK) {
93 IMSG("ffa_version(): %"PRIu32".%"PRIu32"\n", major, minor);
94
95 return true;
96 } else if (result == FFA_NOT_SUPPORTED) {
97 IMSG("ffa_version(): not supported\n");
98 } else {
99 EMSG("ffa_version(): unknown error %"PRId32"\n", result);
100 }
101
102 return false;
103}
104
105static bool test_ffa_id_get(uint16_t *id)
106{
107 sp_result result = SP_RESULT_OK;
108
109 IMSG("Testing ffa_id_get()\n");
110
111 result = sp_discovery_own_id_get(id);
112 if (result == SP_RESULT_OK) {
113 IMSG("ffa_id_get(): 0x%"PRIx16"\n", *id);
114
115 return true;
116 } else if (result == FFA_NOT_SUPPORTED) {
117 IMSG("ffa_id_get(): not supported\n");
118 } else {
119 EMSG("ffa_id_get(): unknown error %"PRId32"\n", result);
120 }
121
122 return false;
123}
124
125static bool test_ffa_features(void)
126{
127 ffa_result result = FFA_OK;
128 struct ffa_interface_properties properties = {0};
129
130 IMSG("Testing ffa_features(FFA_RXTX_MAP)\n");
131
132 result = ffa_features(FFA_RXTX_MAP_32, &properties);
133 if (result == FFA_OK) {
134 static const char * const sizes[] = {
135 "4kB", "64kB", "16kB", "reserved"};
136 uint32_t buffer_size = properties.interface_properties[0] &
137 0x3U;
138
139 IMSG("ffa_features(): minimum buffer size=%s\n",
140 sizes[buffer_size]);
141 return true;
142 } else if (result == FFA_NOT_SUPPORTED) {
143 IMSG("ffa_features(): not supported\n");
144 } else {
145 EMSG("ffa_features(): unknown error %"PRId32"\n", result);
146 }
147 return false;
148}
149
150static bool test_ffa_rxtx_map(void)
151{
152 sp_result result = SP_RESULT_OK;
153
154 IMSG("Testing ffa_rxtx_map(%p %p, 1)\n", tx_buffer, rx_buffer);
155
156 result = sp_rxtx_buffer_map((void*)tx_buffer,(void*)rx_buffer,
157 sizeof(rx_buffer));
158 if (result == FFA_OK) {
159 IMSG("ffa_rxtx_map(): success\n");
160 return true;
161 } else if (result == FFA_NOT_SUPPORTED) {
162 IMSG("ffa_rxtx_map(): not supported\n");
163 } else {
164 EMSG("ffa_rxtx_map(): unknown error %"PRId32"\n", result);
165 }
166
167 return false;
168}
169
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200170static bool ffa_partition_info_get_process(sp_result result, uint32_t count,
171 struct sp_partition_info *partitions)
172{
173 uint32_t i = 0;
174
175 if (result != SP_RESULT_OK) {
176 if (result == FFA_NOT_SUPPORTED) {
177 IMSG("ffa_partition_info_get(): not supported\n");
178 return false;
179 }
180 EMSG("ffa_partition_info_get(): unknown error %"PRId32"\n", result);
181 return false;
182 }
183 IMSG("ffa_partition_info_get(): count=%"PRIu32"\n", count);
184
185 for (i = 0; i < count; i++) {
186 IMSG("partition #%u: ID=%u, execution_count=%u \
187 direct request = %c, send direcy request = %c, \
188 indirect request = %c\n",
189 i, partitions[i].partition_id,
190 partitions[i].execution_context_count,
191 partitions[i].supports_direct_requests ? '1' : '0',
192 partitions[i].can_send_direct_requests ? '1' : '0',
193 partitions[i].supports_indirect_requests ? '1' : '0'
194 );
195 }
196
197 IMSG("Testing ffa_rx_release()\n");
198
199 result = ffa_rx_release();
200 if (result == FFA_OK) {
201 IMSG("ffa_rx_release(): success\n");
202 return true;
203 } else if (result == FFA_NOT_SUPPORTED) {
204 IMSG("ffa_rx_release(): not supported\n");
205 return false;
206 }
207
208 EMSG("ffa_rx_release(): unknown error %"PRId32"\n", result);
209 return false;
210}
211
Jelle Sels03756662021-05-20 10:41:57 +0200212static bool test_ffa_partition_info_get(void)
213{
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200214 sp_result result = SP_RESULT_OK;
Jelle Sels03756662021-05-20 10:41:57 +0200215 struct sp_partition_info partitions[10] = {0};
Jelle Sels03756662021-05-20 10:41:57 +0200216 uint32_t count = 10;
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200217 struct sp_uuid uuid = {.uuid = {0x23, 0xeb, 0x01, 0x00, 0xe3, 0x2a,
218 0x44, 0x97, 0x90, 0x52, 0x2f, 0x11,
219 0xe5, 0x84, 0xaf, 0xa6}};
Jelle Sels03756662021-05-20 10:41:57 +0200220
221 IMSG("Testing ffa_partition_info_get(nil)\n");
222
223 result = sp_discovery_partition_info_get_all(partitions, &count);
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200224 if (!ffa_partition_info_get_process(result, count, partitions))
Jelle Sels03756662021-05-20 10:41:57 +0200225 return false;
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200226 result = sp_discovery_partition_info_get(&uuid,
227 partitions,
228 &count);
229
230 if (!ffa_partition_info_get_process(result, count, partitions))
231 return false;
232 if (count < 2) {
233 EMSG("ffa_partition_info_get(): Returned not enough SPs count=%"PRIu32"\n", count);
Jelle Sels03756662021-05-20 10:41:57 +0200234 return false;
235 }
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200236 return true;
Jelle Sels03756662021-05-20 10:41:57 +0200237}
238
239static bool test_ffa_rxtx_unmap()
240{
241 sp_result result = SP_RESULT_OK;
242
243 result = sp_rxtx_buffer_unmap();
244 if (result == SP_RESULT_OK) {
245 IMSG("sp_rxtx_buffer_unmap(): success\n");
246 return true;
247 }
248 EMSG("sp_rxtx_buffer_unmap(): unknown error %"PRId32"\n", result);
249 return false;
250}
251
252static void return_error(uint32_t error, struct ffa_direct_msg *msg)
253{
Gabor Toth569309e2023-02-08 07:56:22 +0100254 ffa_msg_send_direct_resp_64(msg->destination_id, msg->source_id, 0xff,
Jelle Sels03756662021-05-20 10:41:57 +0200255 error, 0, 0, 0, msg);
256}
257
258static void return_ok(struct ffa_direct_msg *msg)
259{
260
Gabor Toth569309e2023-02-08 07:56:22 +0100261 ffa_msg_send_direct_resp_64(msg->destination_id,
Jelle Sels03756662021-05-20 10:41:57 +0200262 msg->source_id, SP_TEST_OK, 0, 0, 0, 0, msg);
263}
264
265static bool test_read_access(void)
266{
267 return (shared_buffer[0] != 5);
268
269}
270
271static void test_write_access(void)
272{
273 shared_buffer[0] = 0xff;
274}
275
276static void test_increase(struct ffa_direct_msg *msg)
277{
Gabor Toth569309e2023-02-08 07:56:22 +0100278 msg->args.args64[1]++;
279 msg->args.args64[2]++;
280 msg->args.args64[3]++;
281 msg->args.args64[4]++;
282 ffa_msg_send_direct_resp_64(msg->destination_id,msg->source_id,
283 SP_TEST_OK, msg->args.args64[1],
284 msg->args.args64[2],msg->args.args64[3],
285 msg->args.args64[4], msg);
Jelle Sels03756662021-05-20 10:41:57 +0200286
287}
288
289static void test_communication(struct ffa_direct_msg *msg)
290{
291 struct ffa_direct_msg sp_msg = {0};
Imre Kisbd8e04e2023-08-22 15:17:53 +0200292 uint16_t caller = msg->source_id;
293 uint16_t src = msg->destination_id;
Gabor Toth569309e2023-02-08 07:56:22 +0100294 uint16_t dst = (uint16_t)msg->args.args64[1];
Jelle Sels03756662021-05-20 10:41:57 +0200295 ffa_result res = FFA_OK;
Imre Kisbd8e04e2023-08-22 15:17:53 +0200296 struct ffa_params raw_params = { 0 };
Jelle Sels03756662021-05-20 10:41:57 +0200297
Gabor Toth569309e2023-02-08 07:56:22 +0100298 sp_msg.args.args64[1] = 0x55;
299 sp_msg.args.args64[2] = 0xAA;
300 sp_msg.args.args64[3] = 0xBB;
301 sp_msg.args.args64[4] = 0xCC;
302
Imre Kisbd8e04e2023-08-22 15:17:53 +0200303 res = ffa_msg_send_direct_req_64(src, dst,
Jelle Sels45353ba2022-09-30 14:47:56 +0200304 EP_TEST_SP_INCREASE,0x55, 0xAA, 0xBB,
305 0xCC, &sp_msg);
Jelle Sels03756662021-05-20 10:41:57 +0200306 if (res != FFA_OK) {
307 EMSG("error % in %s:%d"PRId32, res, __FILE__, __LINE__);
Imre Kisbd8e04e2023-08-22 15:17:53 +0200308 goto err;
Jelle Sels03756662021-05-20 10:41:57 +0200309 }
310
Imre Kisbd8e04e2023-08-22 15:17:53 +0200311 if (sp_msg.args.args64[1] != 0x56 || sp_msg.args.args64[2] != 0xAB ||
312 sp_msg.args.args64[3] != 0xBC || sp_msg.args.args64[4] != 0xCD) {
Imre Kis45df16f2023-03-24 13:27:10 +0100313 DMSG("Failed SP communication %lx %lx %lx %lx",
314 sp_msg.args.args64[1], sp_msg.args.args64[2],
315 sp_msg.args.args64[3], sp_msg.args.args64[4]);
Imre Kisbd8e04e2023-08-22 15:17:53 +0200316 goto err;
Jelle Sels03756662021-05-20 10:41:57 +0200317 }
Imre Kisbd8e04e2023-08-22 15:17:53 +0200318
319 /* Non-null flags (W2) register */
Balint Dobszaya28cce42024-07-09 16:03:29 +0200320 ffa_svc(FFA_MSG_SEND_DIRECT_REQ_64, (uint32_t)(src << 16 | dst), 1, 0, 0, 0, 0, 0,
Imre Kisbd8e04e2023-08-22 15:17:53 +0200321 &raw_params);
322 if (raw_params.a0 != FFA_ERROR || (uint32_t)raw_params.a2 != FFA_INVALID_PARAMETERS) {
323 EMSG("Unexpected error code: %d != %ld", FFA_INVALID_PARAMETERS, raw_params.a2);
324 goto err;
325 }
326
327 /* Testing non-matching source ID */
328 res = ffa_msg_send_direct_req_64(src + 1, dst, 0, 0, 0, 0, 0, &sp_msg);
329 if (res != FFA_INVALID_PARAMETERS) {
330 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
331 goto err;
332 }
333
334 /* Sending message to own ID */
335 res = ffa_msg_send_direct_req_64(src, src, 0, 0, 0, 0, 0, &sp_msg);
336 if (res != FFA_INVALID_PARAMETERS) {
337 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
338 goto err;
339 }
340
341 /* Sending message to normal world */
342 res = ffa_msg_send_direct_req_64(src, 0, 0, 0, 0, 0, 0, &sp_msg);
343 if (res != FFA_NOT_SUPPORTED) {
344 EMSG("Unexpected error code: %d != %d", FFA_NOT_SUPPORTED, res);
345 goto err;
346 }
347
348 /* Sending message for starting direct message response test */
349 if (!caller) {
350 res = ffa_msg_send_direct_req_64(src, dst, EP_TEST_SP_COMMUNICATION_RESPONSE, 0, 0,
351 0, 0, &sp_msg);
352 if (res != FFA_OK) {
353 EMSG("Unexpected error code: %d != %d", FFA_OK, res);
354 goto err;
355 }
356
357 if (sp_msg.args.args64[0] != SP_TEST_OK) {
358 EMSG("Unexpected test result: %d != %ld", SP_TEST_OK, sp_msg.args.args64[0]);
359 goto err;
360 }
361 }
362
363 return_ok(msg);
364 return;
365
366err:
367 return_error(ERR_SP_COMMUNICATION, msg);
368}
369
370static void test_communication_response(struct ffa_direct_msg *msg)
371{
372 struct ffa_direct_msg sp_msg = {0};
373 uint16_t caller = msg->source_id;
374 uint16_t src = msg->destination_id;
375 ffa_result res = FFA_OK;
376 struct ffa_params raw_params = { 0 };
377
378 /* Non-null flags (W2) register */
379 ffa_svc(FFA_MSG_SEND_DIRECT_RESP_64, (uint32_t)(src << 16 | 0x1000), 1, 0, 0, 0, 0, 1,
380 &raw_params);
381 if (raw_params.a0 != FFA_ERROR || (uint32_t)raw_params.a2 != FFA_INVALID_PARAMETERS) {
382 EMSG("Unexpected error code: %d != %ld", FFA_INVALID_PARAMETERS, raw_params.a2);
383 goto err;
384 }
385
386 /* Testing non-matching source ID */
387 res = ffa_msg_send_direct_resp_64(src + 1, caller, 0, 0, 0, 0, 2, &sp_msg);
388 if (res != FFA_INVALID_PARAMETERS) {
389 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
390 goto err;
391 }
392
393 /* Sending message to own ID */
394 res = ffa_msg_send_direct_resp_64(src, src, 0, 0, 0, 0, 3, &sp_msg);
395 if (res != FFA_INVALID_PARAMETERS) {
396 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
397 goto err;
398 }
399
400 /* Sending message request to caller SP which is busy */
401 if (caller) {
402 /* Sending message to normal world */
403 res = ffa_msg_send_direct_resp_64(src, 0, 0, 0, 0, 0, 4, &sp_msg);
404 if (res != FFA_INVALID_PARAMETERS) {
405 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
406 goto err;
407 }
408
409 /* Sending message to invalid SP */
410 res = ffa_msg_send_direct_resp_64(src, 0x1000, 0, 0, 0, 0, 5, &sp_msg);
411 if (res != FFA_INVALID_PARAMETERS) {
412 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
413 goto err;
414 }
415
416 /* Sending message request to caller SP which is busy */
417 res = ffa_msg_send_direct_req_64(src, caller, 0, 0, 0, 0, 6, &sp_msg);
418 if (res != FFA_BUSY) {
419 EMSG("Unexpected error code: %d != %d", FFA_BUSY, res);
420 goto err;
421 }
422 }
423
424 ffa_msg_send_direct_resp_64(src, caller, SP_TEST_OK, 0, 0, 0, 0, msg);
425 return;
426
427err:
428 ffa_msg_send_direct_resp_64(src, caller, ERR_SP_COMMUNICATION, 0, 0, 0, 0, msg);
429
Jelle Sels03756662021-05-20 10:41:57 +0200430}
431
432static void test_internal_sp(struct ffa_direct_msg *msg)
433{
434 enum errors err = ERR_OK;
435 uint16_t id = 0;
436
437 if (test_ffa_version()) {
438 if (!test_ffa_id_get(&id))
439 err = ERR_ID_GET;
440
441 if (!err && !test_ffa_features())
442 err = ERR_VERSION;
443
444 if (!err && !test_ffa_rxtx_unmap(id))
445 err = ERR_RXTX_UNMAP;
446
447 if (!err && !test_ffa_rxtx_map())
448 err = ERR_RXTX_MAP;
449
450 if (!err && !test_ffa_partition_info_get())
451 err = ERR_PARTITION;
452
453 } else {
454 err = ERR_VERSION;
455 }
456
457 if (err != ERR_OK) {
458 DMSG("Failed at SP test %x", err);
459 return_error((uint32_t)err, msg);
460 }
461
462 return_ok(msg);
463}
464
465static void set_rxtx_buf(struct ffa_mem_transaction_buffer *t_buf,
466 struct ffa_mem_transaction_buffer *r_buf)
467{
468 if (t_buf) {
469 t_buf->buffer = (void*)tx_buffer;
470 t_buf->length = 4096;
471 t_buf->used = false;
472 }
473 if (r_buf) {
474 r_buf->buffer = (void*)rx_buffer;
475 r_buf->length = 4096;
476 r_buf->used = false;
477 }
478}
479
480static void test_mem_retrieve(struct ffa_direct_msg *msg)
481{
482 ffa_result res = FFA_OK;
483 struct sp_memory_descriptor descriptor = {0};
484 struct sp_memory_region regions[1] = {0};
485 struct sp_memory_access_descriptor acc_desc = {0};
486 uint64_t handle = 0;
487 uint32_t out_region_count = 1;
488 uint16_t own_id = 0;
489
490 ffa_id_get(&own_id);
491
Gabor Toth569309e2023-02-08 07:56:22 +0100492 handle = (uint64_t)msg->args.args64[1] |
493 (((uint64_t)msg->args.args64[2]) << 32);
Jelle Sels03756662021-05-20 10:41:57 +0200494 descriptor.tag = 0;
Gabor Toth569309e2023-02-08 07:56:22 +0100495 descriptor.sender_id = msg->args.args64[3] & 0xffff;
Jelle Sels03756662021-05-20 10:41:57 +0200496 acc_desc.receiver_id = own_id;
497 acc_desc.data_access = sp_data_access_read_write;
Balint Dobszay3e4f2832023-01-03 14:20:56 +0100498 res = sp_memory_retrieve(&descriptor, &acc_desc, regions, 0,
Jelle Sels03756662021-05-20 10:41:57 +0200499 &out_region_count, handle);
500
501 if (res) {
Imre Kise946d912024-04-24 13:24:47 +0200502 DMSG("Failed retrieving shared memory");
503 return_error((uint32_t)ERR_MEM_RETRIEVE, msg);
504 return;
505 }
506
507 if (descriptor.flags.transaction_type != sp_memory_transaction_type_share) {
508 EMSG("Invalid transaction type");
Jelle Sels03756662021-05-20 10:41:57 +0200509 return_error((uint32_t)ERR_MEM_RETRIEVE, msg);
510 return;
511 }
512
513 shared_buffer = regions[0].address;
514 shared_buffer_size = regions[0].page_count * 4096;
515
516 return_ok(msg);
517}
518
519static void test_mem_relinquish(struct ffa_direct_msg *msg)
520{
521 ffa_result res = FFA_OK;
Jelle Sels03756662021-05-20 10:41:57 +0200522 uint64_t handle = 0;
523 uint16_t endpoint_id = 0;
524 struct sp_memory_transaction_flags flags = {
525 .zero_memory = false,
526 .operation_time_slicing = false,
527 };
528
Gabor Toth569309e2023-02-08 07:56:22 +0100529 if (msg->args.args64[3] == 1)
Jelle Sels03756662021-05-20 10:41:57 +0200530 flags.zero_memory = true;
531
532 ffa_id_get(&endpoint_id);
Gabor Toth569309e2023-02-08 07:56:22 +0100533 handle = (uint64_t)msg->args.args64[1] |
534 (((uint64_t)msg->args.args64[2]) << 32);
Jelle Sels03756662021-05-20 10:41:57 +0200535
536 res = sp_memory_relinquish(handle, &endpoint_id, 1, &flags);
537 if (res) {
538 DMSG("Failed to relinquish share");
539 return_error((uint32_t)ERR_MEM_RELINQUISH, msg);
540 }
541
542 return_ok(msg);
543}
544
545static void test_mem_sharing(uint16_t service_ep_id, struct ffa_direct_msg *msg)
546{
547 ffa_result res = FFA_OK;
548 struct sp_memory_descriptor desc = { 0 };
549 struct sp_memory_region region = { 0 };
550 uint64_t handle = 0;
551 struct ffa_mem_transaction_buffer t_buf = {0};
552 uint16_t own_id = 0;
553 uint16_t src_id = msg->source_id;
554 struct sp_memory_access_descriptor acc_desc = { };
555
556 my_buf[0] = 0xa;
557 set_rxtx_buf(&t_buf, NULL);
558 ffa_id_get(&own_id);
559
560 region.address = (void*) my_buf;
561 region.page_count = 1;
562 desc.sender_id = own_id;
563 desc.memory_type = sp_memory_type_normal_memory;
564 desc.mem_region_attr.normal_memory.cacheability =
565 sp_cacheability_write_back;
566
567 desc.mem_region_attr.normal_memory.shareability =
568 sp_shareability_inner_shareable;
569
570 acc_desc.data_access = sp_data_access_read_write;
571 acc_desc.instruction_access = sp_instruction_access_not_executable;
572 acc_desc.receiver_id = service_ep_id;
573
574 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle);
575 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200576 EMSG("Failed to share memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200577 return_error((uint32_t)ERR_SP_SHARE, msg);
578 return;
579 }
580
Gabor Toth569309e2023-02-08 07:56:22 +0100581 res = ffa_msg_send_direct_req_64(own_id, service_ep_id,
Jelle Sels03756662021-05-20 10:41:57 +0200582 EP_RETRIEVE, handle & 0xffffffff,
583 handle >> 32, own_id, 0, msg);
584
585 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200586 EMSG("Failed to send retrieve command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200587 return_error((uint32_t)ERR_SP_SHARE, msg);
588 return;
589 }
590
Gabor Toth569309e2023-02-08 07:56:22 +0100591 res = ffa_msg_send_direct_req_64(own_id, service_ep_id,
Jelle Sels03756662021-05-20 10:41:57 +0200592 EP_TRY_W_ACCESS, 0,
593 0, 0, 0, msg);
594
595 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200596 EMSG("Failed to send TRY_W_ACCESS command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200597 return_error((uint32_t)ERR_SP_SHARE, msg);
598 return;
599 }
600
Gabor Toth569309e2023-02-08 07:56:22 +0100601 res = ffa_msg_send_direct_req_64(own_id, service_ep_id,
Jelle Sels03756662021-05-20 10:41:57 +0200602 EP_RELINQUISH, handle & 0xffffffff,
603 handle >> 32, 0, 0, msg);
604 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200605 EMSG("Failed to send relinquish command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200606 return_error((uint32_t)ERR_SP_SHARE, msg);
607 return;
608 }
609
610 res = ffa_mem_reclaim(handle, 0);
611
612 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200613 EMSG("Failed to reclaim memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200614 return_error((uint32_t)ERR_SP_SHARE, msg);
615 return;
616 }
617 msg->destination_id = own_id;
618 msg->source_id = src_id;
619
620 return_ok(msg);
621}
622
623static void test_mem_multi_sharing(struct ffa_direct_msg *msg)
624{
625 ffa_result res = FFA_OK;
626 struct sp_memory_descriptor desc = { 0 };
627 struct sp_memory_region region = { 0 };
628 uint64_t handle = 0;
629 struct ffa_mem_transaction_buffer t_buf = {0};
630 uint16_t own_id = 0;
Imre Kise946d912024-04-24 13:24:47 +0200631 uint16_t src_id = msg->source_id;
Jelle Sels03756662021-05-20 10:41:57 +0200632 struct sp_memory_access_descriptor acc_desc[2] = { };
633 uint32_t err = 0;
Gabor Toth569309e2023-02-08 07:56:22 +0100634 uint16_t endpoint2 = msg->args.args64[1];
635 uint16_t endpoint3 = msg->args.args64[2];
Jelle Sels03756662021-05-20 10:41:57 +0200636
637 my_buf[0] = 0xa;
638 set_rxtx_buf(&t_buf, NULL);
639 ffa_id_get(&own_id);
640
641 region.address = (void*) my_buf;
642 region.page_count = 1;
643 desc.sender_id = own_id;
644 desc.memory_type = sp_memory_type_normal_memory;
645 desc.mem_region_attr.normal_memory.cacheability =
646 sp_cacheability_write_back;
647
648 desc.mem_region_attr.normal_memory.shareability =
649 sp_shareability_inner_shareable;
650
651 acc_desc[0].data_access = sp_data_access_read_write;
652 acc_desc[0].instruction_access = sp_instruction_access_not_executable;
653 acc_desc[0].receiver_id = endpoint2;
654
655 acc_desc[1].data_access = sp_data_access_read_write;
656 acc_desc[1].instruction_access = sp_instruction_access_not_executable;
657 acc_desc[1].receiver_id = endpoint3;
658
659 res = sp_memory_share(&desc, acc_desc, 2, &region, 1, &handle);
660 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200661 EMSG("Failed to share memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200662 err = (uint32_t)ERR_SP_SHARE;
663 goto err;
664 }
665 /* test SP2*/
Gabor Toth569309e2023-02-08 07:56:22 +0100666 res = ffa_msg_send_direct_req_64(own_id, endpoint2,
Jelle Sels03756662021-05-20 10:41:57 +0200667 EP_RETRIEVE, handle & 0xffffffff,
668 handle >> 32, own_id, 0, msg);
669
670 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200671 EMSG("Failed to send retrieve command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200672 return_error((uint32_t)ERR_SP_SHARE, msg);
673 return;
674 }
675
Gabor Toth569309e2023-02-08 07:56:22 +0100676 res = ffa_msg_send_direct_req_64(own_id, endpoint2,
Jelle Sels03756662021-05-20 10:41:57 +0200677 EP_TRY_W_ACCESS, 0,
678 0, 0, 0, msg);
679
680 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200681 EMSG("Failed to send TRY_W_ACCESS command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200682 return_error((uint32_t)ERR_SP_SHARE, msg);
683 return;
684 }
685
686 if (my_buf[0] != 0xff) {
687 EMSG("SP2 didn't change the value of the buffer");
688 err = (uint32_t)ERR_SP_SHARE;
689 goto err;
690 }
691
Gabor Toth569309e2023-02-08 07:56:22 +0100692 res = ffa_msg_send_direct_req_64(own_id, endpoint2,
Jelle Sels03756662021-05-20 10:41:57 +0200693 EP_RELINQUISH, handle & 0xffffffff,
694 handle >> 32, 0, 0, msg);
695
696 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200697 EMSG("Failed to send relinquish command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200698 return_error((uint32_t)ERR_SP_SHARE, msg);
699 return;
700 }
701 my_buf[0] = 0xa;
702 /* test SP3*/
Gabor Toth569309e2023-02-08 07:56:22 +0100703 res = ffa_msg_send_direct_req_64(own_id, endpoint3,
Jelle Sels03756662021-05-20 10:41:57 +0200704 EP_RETRIEVE, handle & 0xffffffff,
705 handle >> 32, own_id, 0, msg);
706
707 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200708 EMSG("Failed to send retrieve command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200709 return_error((uint32_t)ERR_SP_SHARE, msg);
710 return;
711 }
712
Gabor Toth569309e2023-02-08 07:56:22 +0100713 res = ffa_msg_send_direct_req_64(own_id, endpoint3,
Jelle Sels03756662021-05-20 10:41:57 +0200714 EP_TRY_W_ACCESS, 0,
715 0, 0, 0, msg);
716
717 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200718 EMSG("Failed to send TRY_W_ACCESS command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200719 return_error((uint32_t)ERR_SP_SHARE, msg);
720 return;
721 }
722
723 if (my_buf[0] != 0xff) {
724 EMSG("SP3 didn't change the value of the buffer");
725 err = (uint32_t)ERR_SP_SHARE;
726 goto err;
727 }
728
729 if (ffa_mem_reclaim(handle, 0) == FFA_OK) {
730 EMSG("SP3 didn't relinquish memory yet!");
731 err = (uint32_t)ERR_SP_SHARE;
732 goto err;
733 }
734
Gabor Toth569309e2023-02-08 07:56:22 +0100735 res = ffa_msg_send_direct_req_64(own_id, endpoint3,
Jelle Sels03756662021-05-20 10:41:57 +0200736 EP_RELINQUISH, handle & 0xffffffff,
737 handle >> 32, 0, 0, msg);
738
739 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200740 EMSG("Failed to send relinquish command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200741 return_error((uint32_t)ERR_SP_SHARE, msg);
742 return;
743 }
744
745 if (ffa_mem_reclaim(handle, 0) != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200746 EMSG("Failed to reclaim memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200747 err = (uint32_t)ERR_SP_SHARE;
748 goto err;
749 }
750
751 msg->destination_id = own_id;
752 msg->source_id = src_id;
753 return_ok(msg);
754 return;
755err:
756 msg->destination_id = own_id;
757 msg->source_id = src_id;
758 return_error(err, msg);
759}
760
Imre Kise946d912024-04-24 13:24:47 +0200761#define TEST_FFA_MEM_SHARE(len, handle, expected) \
762do { \
763 ffa_result res = FFA_OK; \
764 res = ffa_mem_share_rxtx(len, len, handle); \
765 if (res != expected) { \
766 EMSG("Invalid FFA_MEM_SHARE result: expected = %d, actual = %d", \
767 expected, res); \
768 return -1; \
769 } \
770} while (0)
771
772static int test_mem_sharing_invalid(uint16_t service_ep_id)
773{
774 uint64_t handle = 0;
775 uint16_t own_id = 0;
776 size_t len = 0;
777 struct ffa_mem_transaction_desc *transaction = NULL;
778 struct ffa_mem_access_desc *acc_desc = NULL;
779 struct ffa_composite_mem_region_desc *comp_desc = NULL;
780 struct ffa_constituent_mem_region_desc *region = NULL;
781
782 memset((void *)tx_buffer, 0x00, sizeof(tx_buffer));
783
784 transaction = (struct ffa_mem_transaction_desc *)tx_buffer;
785
786 ffa_id_get(&own_id);
787
788 transaction->sender_id = own_id;
789 transaction->mem_region_attr = 0x24;
790 transaction->flags = 0;
791 transaction->handle = 0;
792 transaction->tag = 0;
793
794 len = sizeof(*transaction);
795
796 /* Zero offset, size and count */
797 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
798
799#if CFG_FFA_VERSION >= FFA_VERSION_1_1
800 /* Zero count */
801 transaction->mem_access_desc_size = sizeof(struct ffa_mem_access_desc);
802 transaction->mem_access_desc_offset = sizeof(*transaction);
803#endif /* CFG_FFA_VERSION */
804
805 /* Too many mem access desc */
806 transaction->mem_access_desc_count = sizeof(tx_buffer);
807 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
808
809 transaction->mem_access_desc_count = 1;
810
811#if CFG_FFA_VERSION >= FFA_VERSION_1_1
812 /* Invalid offset */
813 transaction->mem_access_desc_offset = sizeof(tx_buffer);
814 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
815
816 transaction->mem_access_desc_offset = sizeof(*transaction);
817#endif /* CFG_FFA_VERSION */
818
819 acc_desc = (struct ffa_mem_access_desc *)(tx_buffer + len);
820 len += sizeof(*acc_desc);
821
822 acc_desc->mem_access_perm_desc.endpoint_id = service_ep_id;
823 acc_desc->mem_access_perm_desc.mem_access_permissions = 0x06; /* RWnX */
824
825 /* Too large memory region descriptor offset */
826 acc_desc->composite_mem_region_desc_offset = sizeof(tx_buffer);
827 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
828
829 acc_desc->composite_mem_region_desc_offset = len;
830 comp_desc = (struct ffa_composite_mem_region_desc *)(tx_buffer + len);
831 len += sizeof(*comp_desc);
832
833 /* Zero pages and address ranges */
834 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
835
836 region = (struct ffa_constituent_mem_region_desc *)(tx_buffer + len);
837 len += sizeof(*region);
838
839 /* One region with zero pages */
840 region->address = (uint64_t)shared_buffer;
841 comp_desc->address_range_count = 1;
842 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
843
844 /* One region with not matching sum pages */
845 region->address = (uint64_t)shared_buffer;
846 comp_desc->address_range_count = 1;
847 comp_desc->total_page_count = 2;
848 region->page_count = 1;
849 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
850
851 /* Too many regions */
852 comp_desc->total_page_count = sizeof(tx_buffer);
853 comp_desc->address_range_count = sizeof(tx_buffer);
854 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
855
856 return 0;
857}
858
Jelle Sels03756662021-05-20 10:41:57 +0200859static void test_mem_sharing_inccorrect_access(uint16_t service_ep_id,
860 struct ffa_direct_msg *msg)
861{
862 ffa_result res = FFA_OK;
863 struct sp_memory_descriptor desc = { 0 };
864 struct sp_memory_region region = { 0 };
865 uint64_t handle = 0;
866 struct ffa_mem_transaction_buffer t_buf = {0};
867 uint16_t own_id = 0;
Imre Kise946d912024-04-24 13:24:47 +0200868 uint16_t src_id = msg->source_id;
Jelle Sels03756662021-05-20 10:41:57 +0200869 struct sp_memory_access_descriptor acc_desc = { };
870
871 set_rxtx_buf(&t_buf, NULL);
872 ffa_id_get(&own_id);
873
874 region.address = (void*) my_buf;
875 region.page_count = 1;
876 desc.sender_id = own_id;
877 desc.memory_type = sp_memory_type_normal_memory;
878 desc.mem_region_attr.normal_memory.cacheability =
879 sp_cacheability_write_back;
880
881 desc.mem_region_attr.normal_memory.shareability =
882 sp_shareability_inner_shareable;
883
884 acc_desc.data_access = sp_data_access_read_write;
885 acc_desc.instruction_access = sp_instruction_access_executable;
886 acc_desc.receiver_id = service_ep_id;
887
888 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle);
889 if (res == FFA_OK) {
890 EMSG("ffa_memory_share(): error %"PRId32, res);
891 return_error((uint32_t)ERR_SP_SHARE, msg);
892 return;
893 }
894
Imre Kise946d912024-04-24 13:24:47 +0200895 if (test_mem_sharing_invalid(service_ep_id)) {
896 return_error((uint32_t)ERR_SP_SHARE, msg);
897 return;
898 }
899
Jelle Sels03756662021-05-20 10:41:57 +0200900 msg->destination_id = own_id;
901 msg->source_id = src_id;
902 return_ok(msg);
903}
904
905static void test_mem_sharing_exc(uint16_t service_ep_id,
906 struct ffa_direct_msg *msg)
907{
908 ffa_result res = FFA_OK;
909 struct sp_memory_descriptor desc = { 0 };
910 struct sp_memory_region region = { 0 };
911 uint64_t handle = 0;
912 uint64_t handle2 = 0;
913 struct ffa_mem_transaction_buffer t_buf = {0};
914 uint16_t own_id = 0;
Imre Kise946d912024-04-24 13:24:47 +0200915 uint16_t src_id = msg->source_id;
Jelle Sels03756662021-05-20 10:41:57 +0200916 struct sp_memory_access_descriptor acc_desc = { };
917 uint32_t err = 0;
918
919 set_rxtx_buf(&t_buf, NULL);
920 ffa_id_get(&own_id);
921
922 region.address = (void*) my_buf;
923 region.page_count = 1;
924 desc.sender_id = own_id;
925 desc.memory_type = sp_memory_type_normal_memory;
926 desc.mem_region_attr.normal_memory.cacheability =
927 sp_cacheability_write_back;
928
929 desc.mem_region_attr.normal_memory.shareability =
930 sp_shareability_inner_shareable;
931
932 acc_desc.data_access = sp_data_access_read_write;
933 acc_desc.instruction_access = sp_instruction_access_not_executable;
934 acc_desc.receiver_id = service_ep_id;
935
936 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle);
937 if (res != FFA_OK) {
938 EMSG("test_mem_sharing_exc(): error %"PRId32, res);
939 err = (uint32_t)ERR_SP_SHARE_EXC;
940 goto err;
941 }
942
943 /*
944 * Try it again, it should fail as we don't have acclusive access
945 * anymore
946 */
947 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle2);
948 if (res == FFA_OK) {
949 EMSG("test_mem_sharing_exc(): error %"PRId32, res);
950 err = (uint32_t)ERR_SP_SHARE_EXC;
951 goto err;
952 }
953
954 res = ffa_mem_reclaim(handle, 0);
955
956 if (res != FFA_OK) {
957 EMSG("ffa_memory_share(): error % in %s:%d"PRId32, res,
958 __FILE__,
959 __LINE__);
960 return_error((uint32_t)ERR_SP_SHARE, msg);
961 return;
962 }
963
964 msg->destination_id = own_id;
965 msg->source_id = src_id;
966 return_ok(msg);
967 return;
968err:
969 msg->destination_id = own_id;
970 msg->source_id = src_id;
971 return_error(err, msg);
972}
973
Gabor Toth983264f2024-01-23 09:16:24 +0100974void test_mem_get_set(union ffa_boot_info *boot_info)
Jelle Sels6c19b4f2022-10-18 16:40:43 +0200975{
976 void *addr = NULL;
977 ffa_result res = FFA_OK;
978 struct memory_region buffer_region = { 0 };
979 uint32_t mem_perm = 0;
980 const uint32_t original_perm = FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_NX |
981 FFA_MEM_PERM_DATA_ACCESS_PERM_RW;
982 const uint32_t ro_perm = FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_NX |
983 FFA_MEM_PERM_DATA_ACCESS_PERM_RO;
984
985 DMSG("Testing FFA_MEM_PERM_GET/SET");
986 config_ramstore_init();
987
Gabor Toth983264f2024-01-23 09:16:24 +0100988 if (!sp_config_load(boot_info)) {
Jelle Sels6c19b4f2022-10-18 16:40:43 +0200989 EMSG("Failed to load SP config");
990 goto err;
991 }
992
993 /* Only run the test if we have the test-region enabled */
994 if (!config_store_query(CONFIG_CLASSIFIER_MEMORY_REGION, "test-region",
995 0, &buffer_region, sizeof(buffer_region)))
996 return;
997
998 addr = (void *)buffer_region.base_addr;
999 /* Check original permissions */
1000 res = ffa_mem_perm_get(addr, &mem_perm);
1001 if (res)
1002 goto err;
1003
1004 if (mem_perm != original_perm) {
1005 EMSG("Incorrect permision got 0x%x expected 0x%x", mem_perm, original_perm);
1006 res = FFA_INVALID_PARAMETERS;
1007 goto err;
1008 }
1009
1010 /* Remove write permission */
1011 res = ffa_mem_perm_set(addr, 1, ro_perm);
1012 if (res)
1013 goto err;
1014
1015 /* Check if write permission is removed */
1016 res = ffa_mem_perm_get(addr, &mem_perm);
1017 if (res)
1018 goto err;
1019
1020 if (mem_perm != ro_perm) {
1021 EMSG("Incorrect permision got 0x%x expected 0x%x", mem_perm, original_perm);
1022 res = FFA_INVALID_PARAMETERS;
1023 goto err;
1024 }
1025 /* Set write permission back */
1026 res = ffa_mem_perm_set(addr, 1, original_perm);
1027 if (res)
1028 goto err;
1029
1030 /* Check original permissions */
1031 res = ffa_mem_perm_get(addr, &mem_perm);
1032 if (res)
1033 goto err;
1034
1035 if (mem_perm != original_perm) {
1036 EMSG("Incorrect permision got 0x%x expected 0x%x", mem_perm, original_perm);
1037 res = FFA_INVALID_PARAMETERS;
1038 goto err;
1039 }
1040
1041 return;
1042err:
1043 EMSG("GET/SET_MEM failed (0x%x)", res);
1044}
1045
Balint Dobszay4f9d8e32023-04-13 13:55:08 +02001046void __noreturn sp_main(union ffa_boot_info *boot_info) {
Jelle Sels03756662021-05-20 10:41:57 +02001047 struct ffa_direct_msg msg = {0};
1048 uint16_t own_id = 0;
1049
1050 /* Boot phase */
1051 if (sp_discovery_own_id_get(&own_id) != SP_RESULT_OK) {
1052 EMSG("Couldn't get own_id!!");
1053 }
1054
1055 test_ffa_rxtx_map();
Jelle Sels6c19b4f2022-10-18 16:40:43 +02001056 test_mem_get_set(boot_info);
Jelle Sels03756662021-05-20 10:41:57 +02001057 /* End of boot phase */
Gyorgy Szing3e3db702023-07-21 14:18:19 +02001058 test_ffa_partition_info_get();
Jelle Sels03756662021-05-20 10:41:57 +02001059 ffa_msg_wait(&msg);
1060
1061 while (1) {
Gabor Toth569309e2023-02-08 07:56:22 +01001062 enum sp_tests test_case = (enum sp_tests)msg.args.args64[0];
Jelle Sels03756662021-05-20 10:41:57 +02001063
1064 DMSG("SP:%x Starting test %s", own_id, sp_test_str[test_case]);
1065 switch (test_case) {
1066 case EP_TEST_SP:
1067 test_internal_sp(&msg);
1068 break;
1069 case EP_TEST_SP_COMMUNICATION:
1070 test_communication(&msg);
1071 break;
Imre Kisbd8e04e2023-08-22 15:17:53 +02001072 case EP_TEST_SP_COMMUNICATION_RESPONSE:
1073 test_communication_response(&msg);
1074 break;
Jelle Sels03756662021-05-20 10:41:57 +02001075 case EP_TEST_SP_INCREASE:
1076 test_increase(&msg);
1077 break;
1078 case EP_TRY_R_ACCESS:
1079 test_read_access();
1080 return_ok(&msg);
1081 break;
1082 case EP_TRY_W_ACCESS:
1083 test_write_access();
1084 return_ok(&msg);
1085 break;
1086 case EP_RETRIEVE:
1087 test_mem_retrieve(&msg);
1088 break;
1089 case EP_RELINQUISH:
1090 test_mem_relinquish(&msg);
1091 break;
1092 case EP_SP_MEM_SHARING:
Gabor Toth569309e2023-02-08 07:56:22 +01001093 test_mem_sharing((uint16_t)msg.args.args64[1], &msg);
Jelle Sels03756662021-05-20 10:41:57 +02001094 break;
1095 case EP_SP_MEM_SHARING_MULTI:
1096 test_mem_multi_sharing(&msg);
1097 break;
1098 case EP_SP_MEM_SHARING_EXC:
Gabor Toth569309e2023-02-08 07:56:22 +01001099 test_mem_sharing_exc((uint16_t)msg.args.args64[1],
Jelle Sels45353ba2022-09-30 14:47:56 +02001100 &msg);
Jelle Sels03756662021-05-20 10:41:57 +02001101 break;
1102 case EP_SP_MEM_INCORRECT_ACCESS:
1103 test_mem_sharing_inccorrect_access(
Gabor Toth569309e2023-02-08 07:56:22 +01001104 (uint16_t)msg.args.args64[1], &msg);
Jelle Sels03756662021-05-20 10:41:57 +02001105 break;
Gabor Tothbad63bb2025-03-26 12:43:30 +01001106 case EP_SP_YIELD:
1107 ffa_result res = ffa_yield();
1108
1109 if (res == FFA_OK)
1110 return_ok(&msg);
1111 else
1112 return_error(res, &msg);
1113 break;
Jelle Sels03756662021-05-20 10:41:57 +02001114 case EP_SP_NOP:
1115 return_ok(&msg);
1116 break;
1117
1118 default:
1119 return_error((uint32_t)ERR_TEST_NOT_FOUND, &msg);
1120 break;
1121 }
1122 }
1123}
1124
1125void sp_interrupt_handler(uint32_t interrupt_id)
1126{
1127 (void)interrupt_id;
1128 DMSG("Got interrupt %x", interrupt_id);
1129}
Balint Dobszayac721da2024-07-02 16:33:59 +02001130
1131ffa_result ffa_vm_created_handler(uint16_t vm_id, uint64_t handle)
1132{
1133 (void)handle;
1134 DMSG("VM with ID %d created", vm_id);
1135
1136 return FFA_OK;
1137}
1138
1139ffa_result ffa_vm_destroyed_handler(uint16_t vm_id, uint64_t handle)
1140{
1141 (void)handle;
1142 DMSG("VM with ID %d destroyed", vm_id);
1143
1144 return FFA_OK;
1145}