blob: 423541b9db4d10d5d1bdd7fd9b0b5d8b3ee6d849 [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,
Jelle Sels03756662021-05-20 10:41:57 +020063};
64
65const char* sp_test_str[]= {
66 "EP_TEST_SP",
67 "EP_TEST_SP_COMMUNICATION",
68 "EP_TEST_SP_INCREASE",
69 "EP_TRY_R_ACCESS",
70 "EP_TRY_W_ACCESS",
71 "EP_RETRIEVE",
72 "EP_RELINQUISH",
73 "EP_SP_MEM_SHARING",
74 "EP_SP_MEM_SHARING_MULTI",
75 "EP_SP_MEM_SHARING_EXC",
76 "EP_SP_MEM_INCORRECT_ACCESS",
Gabor Toth2a935aa2025-03-26 14:15:44 +010077 "EP_SP_NOP",
78 "EP_TEST_SP_COMMUNICATION_RESPONSE"
Jelle Sels03756662021-05-20 10:41:57 +020079};
80
81static bool test_ffa_version(void)
82{
83 sp_result result = SP_RESULT_OK;
84 uint16_t major = 0;
85 uint16_t minor = 0;
86
87 IMSG("Testing ffa_version()\n");
88
89 result = sp_discovery_ffa_version_get(&major, &minor);
90 if (result == SP_RESULT_OK) {
91 IMSG("ffa_version(): %"PRIu32".%"PRIu32"\n", major, minor);
92
93 return true;
94 } else if (result == FFA_NOT_SUPPORTED) {
95 IMSG("ffa_version(): not supported\n");
96 } else {
97 EMSG("ffa_version(): unknown error %"PRId32"\n", result);
98 }
99
100 return false;
101}
102
103static bool test_ffa_id_get(uint16_t *id)
104{
105 sp_result result = SP_RESULT_OK;
106
107 IMSG("Testing ffa_id_get()\n");
108
109 result = sp_discovery_own_id_get(id);
110 if (result == SP_RESULT_OK) {
111 IMSG("ffa_id_get(): 0x%"PRIx16"\n", *id);
112
113 return true;
114 } else if (result == FFA_NOT_SUPPORTED) {
115 IMSG("ffa_id_get(): not supported\n");
116 } else {
117 EMSG("ffa_id_get(): unknown error %"PRId32"\n", result);
118 }
119
120 return false;
121}
122
123static bool test_ffa_features(void)
124{
125 ffa_result result = FFA_OK;
126 struct ffa_interface_properties properties = {0};
127
128 IMSG("Testing ffa_features(FFA_RXTX_MAP)\n");
129
130 result = ffa_features(FFA_RXTX_MAP_32, &properties);
131 if (result == FFA_OK) {
132 static const char * const sizes[] = {
133 "4kB", "64kB", "16kB", "reserved"};
134 uint32_t buffer_size = properties.interface_properties[0] &
135 0x3U;
136
137 IMSG("ffa_features(): minimum buffer size=%s\n",
138 sizes[buffer_size]);
139 return true;
140 } else if (result == FFA_NOT_SUPPORTED) {
141 IMSG("ffa_features(): not supported\n");
142 } else {
143 EMSG("ffa_features(): unknown error %"PRId32"\n", result);
144 }
145 return false;
146}
147
148static bool test_ffa_rxtx_map(void)
149{
150 sp_result result = SP_RESULT_OK;
151
152 IMSG("Testing ffa_rxtx_map(%p %p, 1)\n", tx_buffer, rx_buffer);
153
154 result = sp_rxtx_buffer_map((void*)tx_buffer,(void*)rx_buffer,
155 sizeof(rx_buffer));
156 if (result == FFA_OK) {
157 IMSG("ffa_rxtx_map(): success\n");
158 return true;
159 } else if (result == FFA_NOT_SUPPORTED) {
160 IMSG("ffa_rxtx_map(): not supported\n");
161 } else {
162 EMSG("ffa_rxtx_map(): unknown error %"PRId32"\n", result);
163 }
164
165 return false;
166}
167
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200168static bool ffa_partition_info_get_process(sp_result result, uint32_t count,
169 struct sp_partition_info *partitions)
170{
171 uint32_t i = 0;
172
173 if (result != SP_RESULT_OK) {
174 if (result == FFA_NOT_SUPPORTED) {
175 IMSG("ffa_partition_info_get(): not supported\n");
176 return false;
177 }
178 EMSG("ffa_partition_info_get(): unknown error %"PRId32"\n", result);
179 return false;
180 }
181 IMSG("ffa_partition_info_get(): count=%"PRIu32"\n", count);
182
183 for (i = 0; i < count; i++) {
184 IMSG("partition #%u: ID=%u, execution_count=%u \
185 direct request = %c, send direcy request = %c, \
186 indirect request = %c\n",
187 i, partitions[i].partition_id,
188 partitions[i].execution_context_count,
189 partitions[i].supports_direct_requests ? '1' : '0',
190 partitions[i].can_send_direct_requests ? '1' : '0',
191 partitions[i].supports_indirect_requests ? '1' : '0'
192 );
193 }
194
195 IMSG("Testing ffa_rx_release()\n");
196
197 result = ffa_rx_release();
198 if (result == FFA_OK) {
199 IMSG("ffa_rx_release(): success\n");
200 return true;
201 } else if (result == FFA_NOT_SUPPORTED) {
202 IMSG("ffa_rx_release(): not supported\n");
203 return false;
204 }
205
206 EMSG("ffa_rx_release(): unknown error %"PRId32"\n", result);
207 return false;
208}
209
Jelle Sels03756662021-05-20 10:41:57 +0200210static bool test_ffa_partition_info_get(void)
211{
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200212 sp_result result = SP_RESULT_OK;
Jelle Sels03756662021-05-20 10:41:57 +0200213 struct sp_partition_info partitions[10] = {0};
Jelle Sels03756662021-05-20 10:41:57 +0200214 uint32_t count = 10;
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200215 struct sp_uuid uuid = {.uuid = {0x23, 0xeb, 0x01, 0x00, 0xe3, 0x2a,
216 0x44, 0x97, 0x90, 0x52, 0x2f, 0x11,
217 0xe5, 0x84, 0xaf, 0xa6}};
Jelle Sels03756662021-05-20 10:41:57 +0200218
219 IMSG("Testing ffa_partition_info_get(nil)\n");
220
221 result = sp_discovery_partition_info_get_all(partitions, &count);
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200222 if (!ffa_partition_info_get_process(result, count, partitions))
Jelle Sels03756662021-05-20 10:41:57 +0200223 return false;
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200224 result = sp_discovery_partition_info_get(&uuid,
225 partitions,
226 &count);
227
228 if (!ffa_partition_info_get_process(result, count, partitions))
229 return false;
230 if (count < 2) {
231 EMSG("ffa_partition_info_get(): Returned not enough SPs count=%"PRIu32"\n", count);
Jelle Sels03756662021-05-20 10:41:57 +0200232 return false;
233 }
Gyorgy Szing3e3db702023-07-21 14:18:19 +0200234 return true;
Jelle Sels03756662021-05-20 10:41:57 +0200235}
236
237static bool test_ffa_rxtx_unmap()
238{
239 sp_result result = SP_RESULT_OK;
240
241 result = sp_rxtx_buffer_unmap();
242 if (result == SP_RESULT_OK) {
243 IMSG("sp_rxtx_buffer_unmap(): success\n");
244 return true;
245 }
246 EMSG("sp_rxtx_buffer_unmap(): unknown error %"PRId32"\n", result);
247 return false;
248}
249
250static void return_error(uint32_t error, struct ffa_direct_msg *msg)
251{
Gabor Toth569309e2023-02-08 07:56:22 +0100252 ffa_msg_send_direct_resp_64(msg->destination_id, msg->source_id, 0xff,
Jelle Sels03756662021-05-20 10:41:57 +0200253 error, 0, 0, 0, msg);
254}
255
256static void return_ok(struct ffa_direct_msg *msg)
257{
258
Gabor Toth569309e2023-02-08 07:56:22 +0100259 ffa_msg_send_direct_resp_64(msg->destination_id,
Jelle Sels03756662021-05-20 10:41:57 +0200260 msg->source_id, SP_TEST_OK, 0, 0, 0, 0, msg);
261}
262
263static bool test_read_access(void)
264{
265 return (shared_buffer[0] != 5);
266
267}
268
269static void test_write_access(void)
270{
271 shared_buffer[0] = 0xff;
272}
273
274static void test_increase(struct ffa_direct_msg *msg)
275{
Gabor Toth569309e2023-02-08 07:56:22 +0100276 msg->args.args64[1]++;
277 msg->args.args64[2]++;
278 msg->args.args64[3]++;
279 msg->args.args64[4]++;
280 ffa_msg_send_direct_resp_64(msg->destination_id,msg->source_id,
281 SP_TEST_OK, msg->args.args64[1],
282 msg->args.args64[2],msg->args.args64[3],
283 msg->args.args64[4], msg);
Jelle Sels03756662021-05-20 10:41:57 +0200284
285}
286
287static void test_communication(struct ffa_direct_msg *msg)
288{
289 struct ffa_direct_msg sp_msg = {0};
Imre Kisbd8e04e2023-08-22 15:17:53 +0200290 uint16_t caller = msg->source_id;
291 uint16_t src = msg->destination_id;
Gabor Toth569309e2023-02-08 07:56:22 +0100292 uint16_t dst = (uint16_t)msg->args.args64[1];
Jelle Sels03756662021-05-20 10:41:57 +0200293 ffa_result res = FFA_OK;
Imre Kisbd8e04e2023-08-22 15:17:53 +0200294 struct ffa_params raw_params = { 0 };
Jelle Sels03756662021-05-20 10:41:57 +0200295
Gabor Toth569309e2023-02-08 07:56:22 +0100296 sp_msg.args.args64[1] = 0x55;
297 sp_msg.args.args64[2] = 0xAA;
298 sp_msg.args.args64[3] = 0xBB;
299 sp_msg.args.args64[4] = 0xCC;
300
Imre Kisbd8e04e2023-08-22 15:17:53 +0200301 res = ffa_msg_send_direct_req_64(src, dst,
Jelle Sels45353ba2022-09-30 14:47:56 +0200302 EP_TEST_SP_INCREASE,0x55, 0xAA, 0xBB,
303 0xCC, &sp_msg);
Jelle Sels03756662021-05-20 10:41:57 +0200304 if (res != FFA_OK) {
305 EMSG("error % in %s:%d"PRId32, res, __FILE__, __LINE__);
Imre Kisbd8e04e2023-08-22 15:17:53 +0200306 goto err;
Jelle Sels03756662021-05-20 10:41:57 +0200307 }
308
Imre Kisbd8e04e2023-08-22 15:17:53 +0200309 if (sp_msg.args.args64[1] != 0x56 || sp_msg.args.args64[2] != 0xAB ||
310 sp_msg.args.args64[3] != 0xBC || sp_msg.args.args64[4] != 0xCD) {
Imre Kis45df16f2023-03-24 13:27:10 +0100311 DMSG("Failed SP communication %lx %lx %lx %lx",
312 sp_msg.args.args64[1], sp_msg.args.args64[2],
313 sp_msg.args.args64[3], sp_msg.args.args64[4]);
Imre Kisbd8e04e2023-08-22 15:17:53 +0200314 goto err;
Jelle Sels03756662021-05-20 10:41:57 +0200315 }
Imre Kisbd8e04e2023-08-22 15:17:53 +0200316
317 /* Non-null flags (W2) register */
Balint Dobszaya28cce42024-07-09 16:03:29 +0200318 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 +0200319 &raw_params);
320 if (raw_params.a0 != FFA_ERROR || (uint32_t)raw_params.a2 != FFA_INVALID_PARAMETERS) {
321 EMSG("Unexpected error code: %d != %ld", FFA_INVALID_PARAMETERS, raw_params.a2);
322 goto err;
323 }
324
325 /* Testing non-matching source ID */
326 res = ffa_msg_send_direct_req_64(src + 1, dst, 0, 0, 0, 0, 0, &sp_msg);
327 if (res != FFA_INVALID_PARAMETERS) {
328 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
329 goto err;
330 }
331
332 /* Sending message to own ID */
333 res = ffa_msg_send_direct_req_64(src, src, 0, 0, 0, 0, 0, &sp_msg);
334 if (res != FFA_INVALID_PARAMETERS) {
335 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
336 goto err;
337 }
338
339 /* Sending message to normal world */
340 res = ffa_msg_send_direct_req_64(src, 0, 0, 0, 0, 0, 0, &sp_msg);
341 if (res != FFA_NOT_SUPPORTED) {
342 EMSG("Unexpected error code: %d != %d", FFA_NOT_SUPPORTED, res);
343 goto err;
344 }
345
346 /* Sending message for starting direct message response test */
347 if (!caller) {
348 res = ffa_msg_send_direct_req_64(src, dst, EP_TEST_SP_COMMUNICATION_RESPONSE, 0, 0,
349 0, 0, &sp_msg);
350 if (res != FFA_OK) {
351 EMSG("Unexpected error code: %d != %d", FFA_OK, res);
352 goto err;
353 }
354
355 if (sp_msg.args.args64[0] != SP_TEST_OK) {
356 EMSG("Unexpected test result: %d != %ld", SP_TEST_OK, sp_msg.args.args64[0]);
357 goto err;
358 }
359 }
360
361 return_ok(msg);
362 return;
363
364err:
365 return_error(ERR_SP_COMMUNICATION, msg);
366}
367
368static void test_communication_response(struct ffa_direct_msg *msg)
369{
370 struct ffa_direct_msg sp_msg = {0};
371 uint16_t caller = msg->source_id;
372 uint16_t src = msg->destination_id;
373 ffa_result res = FFA_OK;
374 struct ffa_params raw_params = { 0 };
375
376 /* Non-null flags (W2) register */
377 ffa_svc(FFA_MSG_SEND_DIRECT_RESP_64, (uint32_t)(src << 16 | 0x1000), 1, 0, 0, 0, 0, 1,
378 &raw_params);
379 if (raw_params.a0 != FFA_ERROR || (uint32_t)raw_params.a2 != FFA_INVALID_PARAMETERS) {
380 EMSG("Unexpected error code: %d != %ld", FFA_INVALID_PARAMETERS, raw_params.a2);
381 goto err;
382 }
383
384 /* Testing non-matching source ID */
385 res = ffa_msg_send_direct_resp_64(src + 1, caller, 0, 0, 0, 0, 2, &sp_msg);
386 if (res != FFA_INVALID_PARAMETERS) {
387 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
388 goto err;
389 }
390
391 /* Sending message to own ID */
392 res = ffa_msg_send_direct_resp_64(src, src, 0, 0, 0, 0, 3, &sp_msg);
393 if (res != FFA_INVALID_PARAMETERS) {
394 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
395 goto err;
396 }
397
398 /* Sending message request to caller SP which is busy */
399 if (caller) {
400 /* Sending message to normal world */
401 res = ffa_msg_send_direct_resp_64(src, 0, 0, 0, 0, 0, 4, &sp_msg);
402 if (res != FFA_INVALID_PARAMETERS) {
403 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
404 goto err;
405 }
406
407 /* Sending message to invalid SP */
408 res = ffa_msg_send_direct_resp_64(src, 0x1000, 0, 0, 0, 0, 5, &sp_msg);
409 if (res != FFA_INVALID_PARAMETERS) {
410 EMSG("Unexpected error code: %d != %d", FFA_INVALID_PARAMETERS, res);
411 goto err;
412 }
413
414 /* Sending message request to caller SP which is busy */
415 res = ffa_msg_send_direct_req_64(src, caller, 0, 0, 0, 0, 6, &sp_msg);
416 if (res != FFA_BUSY) {
417 EMSG("Unexpected error code: %d != %d", FFA_BUSY, res);
418 goto err;
419 }
420 }
421
422 ffa_msg_send_direct_resp_64(src, caller, SP_TEST_OK, 0, 0, 0, 0, msg);
423 return;
424
425err:
426 ffa_msg_send_direct_resp_64(src, caller, ERR_SP_COMMUNICATION, 0, 0, 0, 0, msg);
427
Jelle Sels03756662021-05-20 10:41:57 +0200428}
429
430static void test_internal_sp(struct ffa_direct_msg *msg)
431{
432 enum errors err = ERR_OK;
433 uint16_t id = 0;
434
435 if (test_ffa_version()) {
436 if (!test_ffa_id_get(&id))
437 err = ERR_ID_GET;
438
439 if (!err && !test_ffa_features())
440 err = ERR_VERSION;
441
442 if (!err && !test_ffa_rxtx_unmap(id))
443 err = ERR_RXTX_UNMAP;
444
445 if (!err && !test_ffa_rxtx_map())
446 err = ERR_RXTX_MAP;
447
448 if (!err && !test_ffa_partition_info_get())
449 err = ERR_PARTITION;
450
451 } else {
452 err = ERR_VERSION;
453 }
454
455 if (err != ERR_OK) {
456 DMSG("Failed at SP test %x", err);
457 return_error((uint32_t)err, msg);
458 }
459
460 return_ok(msg);
461}
462
463static void set_rxtx_buf(struct ffa_mem_transaction_buffer *t_buf,
464 struct ffa_mem_transaction_buffer *r_buf)
465{
466 if (t_buf) {
467 t_buf->buffer = (void*)tx_buffer;
468 t_buf->length = 4096;
469 t_buf->used = false;
470 }
471 if (r_buf) {
472 r_buf->buffer = (void*)rx_buffer;
473 r_buf->length = 4096;
474 r_buf->used = false;
475 }
476}
477
478static void test_mem_retrieve(struct ffa_direct_msg *msg)
479{
480 ffa_result res = FFA_OK;
481 struct sp_memory_descriptor descriptor = {0};
482 struct sp_memory_region regions[1] = {0};
483 struct sp_memory_access_descriptor acc_desc = {0};
484 uint64_t handle = 0;
485 uint32_t out_region_count = 1;
486 uint16_t own_id = 0;
487
488 ffa_id_get(&own_id);
489
Gabor Toth569309e2023-02-08 07:56:22 +0100490 handle = (uint64_t)msg->args.args64[1] |
491 (((uint64_t)msg->args.args64[2]) << 32);
Jelle Sels03756662021-05-20 10:41:57 +0200492 descriptor.tag = 0;
Gabor Toth569309e2023-02-08 07:56:22 +0100493 descriptor.sender_id = msg->args.args64[3] & 0xffff;
Jelle Sels03756662021-05-20 10:41:57 +0200494 acc_desc.receiver_id = own_id;
495 acc_desc.data_access = sp_data_access_read_write;
Balint Dobszay3e4f2832023-01-03 14:20:56 +0100496 res = sp_memory_retrieve(&descriptor, &acc_desc, regions, 0,
Jelle Sels03756662021-05-20 10:41:57 +0200497 &out_region_count, handle);
498
499 if (res) {
Imre Kise946d912024-04-24 13:24:47 +0200500 DMSG("Failed retrieving shared memory");
501 return_error((uint32_t)ERR_MEM_RETRIEVE, msg);
502 return;
503 }
504
505 if (descriptor.flags.transaction_type != sp_memory_transaction_type_share) {
506 EMSG("Invalid transaction type");
Jelle Sels03756662021-05-20 10:41:57 +0200507 return_error((uint32_t)ERR_MEM_RETRIEVE, msg);
508 return;
509 }
510
511 shared_buffer = regions[0].address;
512 shared_buffer_size = regions[0].page_count * 4096;
513
514 return_ok(msg);
515}
516
517static void test_mem_relinquish(struct ffa_direct_msg *msg)
518{
519 ffa_result res = FFA_OK;
Jelle Sels03756662021-05-20 10:41:57 +0200520 uint64_t handle = 0;
521 uint16_t endpoint_id = 0;
522 struct sp_memory_transaction_flags flags = {
523 .zero_memory = false,
524 .operation_time_slicing = false,
525 };
526
Gabor Toth569309e2023-02-08 07:56:22 +0100527 if (msg->args.args64[3] == 1)
Jelle Sels03756662021-05-20 10:41:57 +0200528 flags.zero_memory = true;
529
530 ffa_id_get(&endpoint_id);
Gabor Toth569309e2023-02-08 07:56:22 +0100531 handle = (uint64_t)msg->args.args64[1] |
532 (((uint64_t)msg->args.args64[2]) << 32);
Jelle Sels03756662021-05-20 10:41:57 +0200533
534 res = sp_memory_relinquish(handle, &endpoint_id, 1, &flags);
535 if (res) {
536 DMSG("Failed to relinquish share");
537 return_error((uint32_t)ERR_MEM_RELINQUISH, msg);
538 }
539
540 return_ok(msg);
541}
542
543static void test_mem_sharing(uint16_t service_ep_id, struct ffa_direct_msg *msg)
544{
545 ffa_result res = FFA_OK;
546 struct sp_memory_descriptor desc = { 0 };
547 struct sp_memory_region region = { 0 };
548 uint64_t handle = 0;
549 struct ffa_mem_transaction_buffer t_buf = {0};
550 uint16_t own_id = 0;
551 uint16_t src_id = msg->source_id;
552 struct sp_memory_access_descriptor acc_desc = { };
553
554 my_buf[0] = 0xa;
555 set_rxtx_buf(&t_buf, NULL);
556 ffa_id_get(&own_id);
557
558 region.address = (void*) my_buf;
559 region.page_count = 1;
560 desc.sender_id = own_id;
561 desc.memory_type = sp_memory_type_normal_memory;
562 desc.mem_region_attr.normal_memory.cacheability =
563 sp_cacheability_write_back;
564
565 desc.mem_region_attr.normal_memory.shareability =
566 sp_shareability_inner_shareable;
567
568 acc_desc.data_access = sp_data_access_read_write;
569 acc_desc.instruction_access = sp_instruction_access_not_executable;
570 acc_desc.receiver_id = service_ep_id;
571
572 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle);
573 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200574 EMSG("Failed to share memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200575 return_error((uint32_t)ERR_SP_SHARE, msg);
576 return;
577 }
578
Gabor Toth569309e2023-02-08 07:56:22 +0100579 res = ffa_msg_send_direct_req_64(own_id, service_ep_id,
Jelle Sels03756662021-05-20 10:41:57 +0200580 EP_RETRIEVE, handle & 0xffffffff,
581 handle >> 32, own_id, 0, msg);
582
583 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200584 EMSG("Failed to send retrieve command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200585 return_error((uint32_t)ERR_SP_SHARE, msg);
586 return;
587 }
588
Gabor Toth569309e2023-02-08 07:56:22 +0100589 res = ffa_msg_send_direct_req_64(own_id, service_ep_id,
Jelle Sels03756662021-05-20 10:41:57 +0200590 EP_TRY_W_ACCESS, 0,
591 0, 0, 0, msg);
592
593 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200594 EMSG("Failed to send TRY_W_ACCESS command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200595 return_error((uint32_t)ERR_SP_SHARE, msg);
596 return;
597 }
598
Gabor Toth569309e2023-02-08 07:56:22 +0100599 res = ffa_msg_send_direct_req_64(own_id, service_ep_id,
Jelle Sels03756662021-05-20 10:41:57 +0200600 EP_RELINQUISH, handle & 0xffffffff,
601 handle >> 32, 0, 0, msg);
602 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200603 EMSG("Failed to send relinquish command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200604 return_error((uint32_t)ERR_SP_SHARE, msg);
605 return;
606 }
607
608 res = ffa_mem_reclaim(handle, 0);
609
610 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200611 EMSG("Failed to reclaim memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200612 return_error((uint32_t)ERR_SP_SHARE, msg);
613 return;
614 }
615 msg->destination_id = own_id;
616 msg->source_id = src_id;
617
618 return_ok(msg);
619}
620
621static void test_mem_multi_sharing(struct ffa_direct_msg *msg)
622{
623 ffa_result res = FFA_OK;
624 struct sp_memory_descriptor desc = { 0 };
625 struct sp_memory_region region = { 0 };
626 uint64_t handle = 0;
627 struct ffa_mem_transaction_buffer t_buf = {0};
628 uint16_t own_id = 0;
Imre Kise946d912024-04-24 13:24:47 +0200629 uint16_t src_id = msg->source_id;
Jelle Sels03756662021-05-20 10:41:57 +0200630 struct sp_memory_access_descriptor acc_desc[2] = { };
631 uint32_t err = 0;
Gabor Toth569309e2023-02-08 07:56:22 +0100632 uint16_t endpoint2 = msg->args.args64[1];
633 uint16_t endpoint3 = msg->args.args64[2];
Jelle Sels03756662021-05-20 10:41:57 +0200634
635 my_buf[0] = 0xa;
636 set_rxtx_buf(&t_buf, NULL);
637 ffa_id_get(&own_id);
638
639 region.address = (void*) my_buf;
640 region.page_count = 1;
641 desc.sender_id = own_id;
642 desc.memory_type = sp_memory_type_normal_memory;
643 desc.mem_region_attr.normal_memory.cacheability =
644 sp_cacheability_write_back;
645
646 desc.mem_region_attr.normal_memory.shareability =
647 sp_shareability_inner_shareable;
648
649 acc_desc[0].data_access = sp_data_access_read_write;
650 acc_desc[0].instruction_access = sp_instruction_access_not_executable;
651 acc_desc[0].receiver_id = endpoint2;
652
653 acc_desc[1].data_access = sp_data_access_read_write;
654 acc_desc[1].instruction_access = sp_instruction_access_not_executable;
655 acc_desc[1].receiver_id = endpoint3;
656
657 res = sp_memory_share(&desc, acc_desc, 2, &region, 1, &handle);
658 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200659 EMSG("Failed to share memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200660 err = (uint32_t)ERR_SP_SHARE;
661 goto err;
662 }
663 /* test SP2*/
Gabor Toth569309e2023-02-08 07:56:22 +0100664 res = ffa_msg_send_direct_req_64(own_id, endpoint2,
Jelle Sels03756662021-05-20 10:41:57 +0200665 EP_RETRIEVE, handle & 0xffffffff,
666 handle >> 32, own_id, 0, msg);
667
668 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200669 EMSG("Failed to send retrieve command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200670 return_error((uint32_t)ERR_SP_SHARE, msg);
671 return;
672 }
673
Gabor Toth569309e2023-02-08 07:56:22 +0100674 res = ffa_msg_send_direct_req_64(own_id, endpoint2,
Jelle Sels03756662021-05-20 10:41:57 +0200675 EP_TRY_W_ACCESS, 0,
676 0, 0, 0, msg);
677
678 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200679 EMSG("Failed to send TRY_W_ACCESS command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200680 return_error((uint32_t)ERR_SP_SHARE, msg);
681 return;
682 }
683
684 if (my_buf[0] != 0xff) {
685 EMSG("SP2 didn't change the value of the buffer");
686 err = (uint32_t)ERR_SP_SHARE;
687 goto err;
688 }
689
Gabor Toth569309e2023-02-08 07:56:22 +0100690 res = ffa_msg_send_direct_req_64(own_id, endpoint2,
Jelle Sels03756662021-05-20 10:41:57 +0200691 EP_RELINQUISH, handle & 0xffffffff,
692 handle >> 32, 0, 0, msg);
693
694 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200695 EMSG("Failed to send relinquish command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200696 return_error((uint32_t)ERR_SP_SHARE, msg);
697 return;
698 }
699 my_buf[0] = 0xa;
700 /* test SP3*/
Gabor Toth569309e2023-02-08 07:56:22 +0100701 res = ffa_msg_send_direct_req_64(own_id, endpoint3,
Jelle Sels03756662021-05-20 10:41:57 +0200702 EP_RETRIEVE, handle & 0xffffffff,
703 handle >> 32, own_id, 0, msg);
704
705 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200706 EMSG("Failed to send retrieve command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200707 return_error((uint32_t)ERR_SP_SHARE, msg);
708 return;
709 }
710
Gabor Toth569309e2023-02-08 07:56:22 +0100711 res = ffa_msg_send_direct_req_64(own_id, endpoint3,
Jelle Sels03756662021-05-20 10:41:57 +0200712 EP_TRY_W_ACCESS, 0,
713 0, 0, 0, msg);
714
715 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200716 EMSG("Failed to send TRY_W_ACCESS command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200717 return_error((uint32_t)ERR_SP_SHARE, msg);
718 return;
719 }
720
721 if (my_buf[0] != 0xff) {
722 EMSG("SP3 didn't change the value of the buffer");
723 err = (uint32_t)ERR_SP_SHARE;
724 goto err;
725 }
726
727 if (ffa_mem_reclaim(handle, 0) == FFA_OK) {
728 EMSG("SP3 didn't relinquish memory yet!");
729 err = (uint32_t)ERR_SP_SHARE;
730 goto err;
731 }
732
Gabor Toth569309e2023-02-08 07:56:22 +0100733 res = ffa_msg_send_direct_req_64(own_id, endpoint3,
Jelle Sels03756662021-05-20 10:41:57 +0200734 EP_RELINQUISH, handle & 0xffffffff,
735 handle >> 32, 0, 0, msg);
736
737 if (res != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200738 EMSG("Failed to send relinquish command: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200739 return_error((uint32_t)ERR_SP_SHARE, msg);
740 return;
741 }
742
743 if (ffa_mem_reclaim(handle, 0) != FFA_OK) {
Imre Kise946d912024-04-24 13:24:47 +0200744 EMSG("Failed to reclaim memory: %"PRId32, res);
Jelle Sels03756662021-05-20 10:41:57 +0200745 err = (uint32_t)ERR_SP_SHARE;
746 goto err;
747 }
748
749 msg->destination_id = own_id;
750 msg->source_id = src_id;
751 return_ok(msg);
752 return;
753err:
754 msg->destination_id = own_id;
755 msg->source_id = src_id;
756 return_error(err, msg);
757}
758
Imre Kise946d912024-04-24 13:24:47 +0200759#define TEST_FFA_MEM_SHARE(len, handle, expected) \
760do { \
761 ffa_result res = FFA_OK; \
762 res = ffa_mem_share_rxtx(len, len, handle); \
763 if (res != expected) { \
764 EMSG("Invalid FFA_MEM_SHARE result: expected = %d, actual = %d", \
765 expected, res); \
766 return -1; \
767 } \
768} while (0)
769
770static int test_mem_sharing_invalid(uint16_t service_ep_id)
771{
772 uint64_t handle = 0;
773 uint16_t own_id = 0;
774 size_t len = 0;
775 struct ffa_mem_transaction_desc *transaction = NULL;
776 struct ffa_mem_access_desc *acc_desc = NULL;
777 struct ffa_composite_mem_region_desc *comp_desc = NULL;
778 struct ffa_constituent_mem_region_desc *region = NULL;
779
780 memset((void *)tx_buffer, 0x00, sizeof(tx_buffer));
781
782 transaction = (struct ffa_mem_transaction_desc *)tx_buffer;
783
784 ffa_id_get(&own_id);
785
786 transaction->sender_id = own_id;
787 transaction->mem_region_attr = 0x24;
788 transaction->flags = 0;
789 transaction->handle = 0;
790 transaction->tag = 0;
791
792 len = sizeof(*transaction);
793
794 /* Zero offset, size and count */
795 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
796
797#if CFG_FFA_VERSION >= FFA_VERSION_1_1
798 /* Zero count */
799 transaction->mem_access_desc_size = sizeof(struct ffa_mem_access_desc);
800 transaction->mem_access_desc_offset = sizeof(*transaction);
801#endif /* CFG_FFA_VERSION */
802
803 /* Too many mem access desc */
804 transaction->mem_access_desc_count = sizeof(tx_buffer);
805 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
806
807 transaction->mem_access_desc_count = 1;
808
809#if CFG_FFA_VERSION >= FFA_VERSION_1_1
810 /* Invalid offset */
811 transaction->mem_access_desc_offset = sizeof(tx_buffer);
812 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
813
814 transaction->mem_access_desc_offset = sizeof(*transaction);
815#endif /* CFG_FFA_VERSION */
816
817 acc_desc = (struct ffa_mem_access_desc *)(tx_buffer + len);
818 len += sizeof(*acc_desc);
819
820 acc_desc->mem_access_perm_desc.endpoint_id = service_ep_id;
821 acc_desc->mem_access_perm_desc.mem_access_permissions = 0x06; /* RWnX */
822
823 /* Too large memory region descriptor offset */
824 acc_desc->composite_mem_region_desc_offset = sizeof(tx_buffer);
825 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
826
827 acc_desc->composite_mem_region_desc_offset = len;
828 comp_desc = (struct ffa_composite_mem_region_desc *)(tx_buffer + len);
829 len += sizeof(*comp_desc);
830
831 /* Zero pages and address ranges */
832 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
833
834 region = (struct ffa_constituent_mem_region_desc *)(tx_buffer + len);
835 len += sizeof(*region);
836
837 /* One region with zero pages */
838 region->address = (uint64_t)shared_buffer;
839 comp_desc->address_range_count = 1;
840 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
841
842 /* One region with not matching sum pages */
843 region->address = (uint64_t)shared_buffer;
844 comp_desc->address_range_count = 1;
845 comp_desc->total_page_count = 2;
846 region->page_count = 1;
847 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
848
849 /* Too many regions */
850 comp_desc->total_page_count = sizeof(tx_buffer);
851 comp_desc->address_range_count = sizeof(tx_buffer);
852 TEST_FFA_MEM_SHARE(len, &handle, FFA_INVALID_PARAMETERS);
853
854 return 0;
855}
856
Jelle Sels03756662021-05-20 10:41:57 +0200857static void test_mem_sharing_inccorrect_access(uint16_t service_ep_id,
858 struct ffa_direct_msg *msg)
859{
860 ffa_result res = FFA_OK;
861 struct sp_memory_descriptor desc = { 0 };
862 struct sp_memory_region region = { 0 };
863 uint64_t handle = 0;
864 struct ffa_mem_transaction_buffer t_buf = {0};
865 uint16_t own_id = 0;
Imre Kise946d912024-04-24 13:24:47 +0200866 uint16_t src_id = msg->source_id;
Jelle Sels03756662021-05-20 10:41:57 +0200867 struct sp_memory_access_descriptor acc_desc = { };
868
869 set_rxtx_buf(&t_buf, NULL);
870 ffa_id_get(&own_id);
871
872 region.address = (void*) my_buf;
873 region.page_count = 1;
874 desc.sender_id = own_id;
875 desc.memory_type = sp_memory_type_normal_memory;
876 desc.mem_region_attr.normal_memory.cacheability =
877 sp_cacheability_write_back;
878
879 desc.mem_region_attr.normal_memory.shareability =
880 sp_shareability_inner_shareable;
881
882 acc_desc.data_access = sp_data_access_read_write;
883 acc_desc.instruction_access = sp_instruction_access_executable;
884 acc_desc.receiver_id = service_ep_id;
885
886 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle);
887 if (res == FFA_OK) {
888 EMSG("ffa_memory_share(): error %"PRId32, res);
889 return_error((uint32_t)ERR_SP_SHARE, msg);
890 return;
891 }
892
Imre Kise946d912024-04-24 13:24:47 +0200893 if (test_mem_sharing_invalid(service_ep_id)) {
894 return_error((uint32_t)ERR_SP_SHARE, msg);
895 return;
896 }
897
Jelle Sels03756662021-05-20 10:41:57 +0200898 msg->destination_id = own_id;
899 msg->source_id = src_id;
900 return_ok(msg);
901}
902
903static void test_mem_sharing_exc(uint16_t service_ep_id,
904 struct ffa_direct_msg *msg)
905{
906 ffa_result res = FFA_OK;
907 struct sp_memory_descriptor desc = { 0 };
908 struct sp_memory_region region = { 0 };
909 uint64_t handle = 0;
910 uint64_t handle2 = 0;
911 struct ffa_mem_transaction_buffer t_buf = {0};
912 uint16_t own_id = 0;
Imre Kise946d912024-04-24 13:24:47 +0200913 uint16_t src_id = msg->source_id;
Jelle Sels03756662021-05-20 10:41:57 +0200914 struct sp_memory_access_descriptor acc_desc = { };
915 uint32_t err = 0;
916
917 set_rxtx_buf(&t_buf, NULL);
918 ffa_id_get(&own_id);
919
920 region.address = (void*) my_buf;
921 region.page_count = 1;
922 desc.sender_id = own_id;
923 desc.memory_type = sp_memory_type_normal_memory;
924 desc.mem_region_attr.normal_memory.cacheability =
925 sp_cacheability_write_back;
926
927 desc.mem_region_attr.normal_memory.shareability =
928 sp_shareability_inner_shareable;
929
930 acc_desc.data_access = sp_data_access_read_write;
931 acc_desc.instruction_access = sp_instruction_access_not_executable;
932 acc_desc.receiver_id = service_ep_id;
933
934 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle);
935 if (res != FFA_OK) {
936 EMSG("test_mem_sharing_exc(): error %"PRId32, res);
937 err = (uint32_t)ERR_SP_SHARE_EXC;
938 goto err;
939 }
940
941 /*
942 * Try it again, it should fail as we don't have acclusive access
943 * anymore
944 */
945 res = sp_memory_share(&desc, &acc_desc, 1, &region, 1, &handle2);
946 if (res == FFA_OK) {
947 EMSG("test_mem_sharing_exc(): error %"PRId32, res);
948 err = (uint32_t)ERR_SP_SHARE_EXC;
949 goto err;
950 }
951
952 res = ffa_mem_reclaim(handle, 0);
953
954 if (res != FFA_OK) {
955 EMSG("ffa_memory_share(): error % in %s:%d"PRId32, res,
956 __FILE__,
957 __LINE__);
958 return_error((uint32_t)ERR_SP_SHARE, msg);
959 return;
960 }
961
962 msg->destination_id = own_id;
963 msg->source_id = src_id;
964 return_ok(msg);
965 return;
966err:
967 msg->destination_id = own_id;
968 msg->source_id = src_id;
969 return_error(err, msg);
970}
971
Gabor Toth983264f2024-01-23 09:16:24 +0100972void test_mem_get_set(union ffa_boot_info *boot_info)
Jelle Sels6c19b4f2022-10-18 16:40:43 +0200973{
974 void *addr = NULL;
975 ffa_result res = FFA_OK;
976 struct memory_region buffer_region = { 0 };
977 uint32_t mem_perm = 0;
978 const uint32_t original_perm = FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_NX |
979 FFA_MEM_PERM_DATA_ACCESS_PERM_RW;
980 const uint32_t ro_perm = FFA_MEM_PERM_INSTRUCTION_ACCESS_PERM_NX |
981 FFA_MEM_PERM_DATA_ACCESS_PERM_RO;
982
983 DMSG("Testing FFA_MEM_PERM_GET/SET");
984 config_ramstore_init();
985
Gabor Toth983264f2024-01-23 09:16:24 +0100986 if (!sp_config_load(boot_info)) {
Jelle Sels6c19b4f2022-10-18 16:40:43 +0200987 EMSG("Failed to load SP config");
988 goto err;
989 }
990
991 /* Only run the test if we have the test-region enabled */
992 if (!config_store_query(CONFIG_CLASSIFIER_MEMORY_REGION, "test-region",
993 0, &buffer_region, sizeof(buffer_region)))
994 return;
995
996 addr = (void *)buffer_region.base_addr;
997 /* Check original permissions */
998 res = ffa_mem_perm_get(addr, &mem_perm);
999 if (res)
1000 goto err;
1001
1002 if (mem_perm != original_perm) {
1003 EMSG("Incorrect permision got 0x%x expected 0x%x", mem_perm, original_perm);
1004 res = FFA_INVALID_PARAMETERS;
1005 goto err;
1006 }
1007
1008 /* Remove write permission */
1009 res = ffa_mem_perm_set(addr, 1, ro_perm);
1010 if (res)
1011 goto err;
1012
1013 /* Check if write permission is removed */
1014 res = ffa_mem_perm_get(addr, &mem_perm);
1015 if (res)
1016 goto err;
1017
1018 if (mem_perm != ro_perm) {
1019 EMSG("Incorrect permision got 0x%x expected 0x%x", mem_perm, original_perm);
1020 res = FFA_INVALID_PARAMETERS;
1021 goto err;
1022 }
1023 /* Set write permission back */
1024 res = ffa_mem_perm_set(addr, 1, original_perm);
1025 if (res)
1026 goto err;
1027
1028 /* Check original permissions */
1029 res = ffa_mem_perm_get(addr, &mem_perm);
1030 if (res)
1031 goto err;
1032
1033 if (mem_perm != original_perm) {
1034 EMSG("Incorrect permision got 0x%x expected 0x%x", mem_perm, original_perm);
1035 res = FFA_INVALID_PARAMETERS;
1036 goto err;
1037 }
1038
1039 return;
1040err:
1041 EMSG("GET/SET_MEM failed (0x%x)", res);
1042}
1043
Balint Dobszay4f9d8e32023-04-13 13:55:08 +02001044void __noreturn sp_main(union ffa_boot_info *boot_info) {
Jelle Sels03756662021-05-20 10:41:57 +02001045 struct ffa_direct_msg msg = {0};
1046 uint16_t own_id = 0;
1047
1048 /* Boot phase */
1049 if (sp_discovery_own_id_get(&own_id) != SP_RESULT_OK) {
1050 EMSG("Couldn't get own_id!!");
1051 }
1052
1053 test_ffa_rxtx_map();
Jelle Sels6c19b4f2022-10-18 16:40:43 +02001054 test_mem_get_set(boot_info);
Jelle Sels03756662021-05-20 10:41:57 +02001055 /* End of boot phase */
Gyorgy Szing3e3db702023-07-21 14:18:19 +02001056 test_ffa_partition_info_get();
Jelle Sels03756662021-05-20 10:41:57 +02001057 ffa_msg_wait(&msg);
1058
1059 while (1) {
Gabor Toth569309e2023-02-08 07:56:22 +01001060 enum sp_tests test_case = (enum sp_tests)msg.args.args64[0];
Jelle Sels03756662021-05-20 10:41:57 +02001061
1062 DMSG("SP:%x Starting test %s", own_id, sp_test_str[test_case]);
1063 switch (test_case) {
1064 case EP_TEST_SP:
1065 test_internal_sp(&msg);
1066 break;
1067 case EP_TEST_SP_COMMUNICATION:
1068 test_communication(&msg);
1069 break;
Imre Kisbd8e04e2023-08-22 15:17:53 +02001070 case EP_TEST_SP_COMMUNICATION_RESPONSE:
1071 test_communication_response(&msg);
1072 break;
Jelle Sels03756662021-05-20 10:41:57 +02001073 case EP_TEST_SP_INCREASE:
1074 test_increase(&msg);
1075 break;
1076 case EP_TRY_R_ACCESS:
1077 test_read_access();
1078 return_ok(&msg);
1079 break;
1080 case EP_TRY_W_ACCESS:
1081 test_write_access();
1082 return_ok(&msg);
1083 break;
1084 case EP_RETRIEVE:
1085 test_mem_retrieve(&msg);
1086 break;
1087 case EP_RELINQUISH:
1088 test_mem_relinquish(&msg);
1089 break;
1090 case EP_SP_MEM_SHARING:
Gabor Toth569309e2023-02-08 07:56:22 +01001091 test_mem_sharing((uint16_t)msg.args.args64[1], &msg);
Jelle Sels03756662021-05-20 10:41:57 +02001092 break;
1093 case EP_SP_MEM_SHARING_MULTI:
1094 test_mem_multi_sharing(&msg);
1095 break;
1096 case EP_SP_MEM_SHARING_EXC:
Gabor Toth569309e2023-02-08 07:56:22 +01001097 test_mem_sharing_exc((uint16_t)msg.args.args64[1],
Jelle Sels45353ba2022-09-30 14:47:56 +02001098 &msg);
Jelle Sels03756662021-05-20 10:41:57 +02001099 break;
1100 case EP_SP_MEM_INCORRECT_ACCESS:
1101 test_mem_sharing_inccorrect_access(
Gabor Toth569309e2023-02-08 07:56:22 +01001102 (uint16_t)msg.args.args64[1], &msg);
Jelle Sels03756662021-05-20 10:41:57 +02001103 break;
1104 case EP_SP_NOP:
1105 return_ok(&msg);
1106 break;
1107
1108 default:
1109 return_error((uint32_t)ERR_TEST_NOT_FOUND, &msg);
1110 break;
1111 }
1112 }
1113}
1114
1115void sp_interrupt_handler(uint32_t interrupt_id)
1116{
1117 (void)interrupt_id;
1118 DMSG("Got interrupt %x", interrupt_id);
1119}
Balint Dobszayac721da2024-07-02 16:33:59 +02001120
1121ffa_result ffa_vm_created_handler(uint16_t vm_id, uint64_t handle)
1122{
1123 (void)handle;
1124 DMSG("VM with ID %d created", vm_id);
1125
1126 return FFA_OK;
1127}
1128
1129ffa_result ffa_vm_destroyed_handler(uint16_t vm_id, uint64_t handle)
1130{
1131 (void)handle;
1132 DMSG("VM with ID %d destroyed", vm_id);
1133
1134 return FFA_OK;
1135}