1 /*
2  * Copyright 2021 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include "vmapi/hf/call.h"
10 
11 #include "partition_services.h"
12 #include "test/abort.h"
13 #include "test/hftest.h"
14 
15 /**
16  * Message loop to add tests to be controlled by the control partition(depends
17  * on the test set-up).
18  */
test_main_sp(bool is_boot_vcpu)19 noreturn void test_main_sp(bool is_boot_vcpu)
20 {
21 	struct ffa_value res = ffa_msg_wait();
22 
23 	while (1) {
24 		EXPECT_EQ(res.func, FFA_MSG_SEND_DIRECT_REQ_32);
25 
26 		if (is_boot_vcpu) {
27 			/* TODO: can only print from boot vCPU. */
28 			HFTEST_LOG("Received direct message request");
29 		}
30 
31 		switch (res.arg3) {
32 		case SP_ECHO_CMD:
33 			res = sp_echo_cmd(ffa_sender(res), res.arg3, res.arg4,
34 					  res.arg5, res.arg6, res.arg7);
35 			break;
36 		case SP_REQ_ECHO_CMD:
37 			res = sp_req_echo_cmd(ffa_sender(res), res.arg4,
38 					      res.arg5, res.arg6, res.arg7);
39 			break;
40 		case SP_REQ_ECHO_DENIED_CMD:
41 			res = sp_req_echo_denied_cmd(ffa_sender(res));
42 			break;
43 		case SP_NOTIF_SET_CMD:
44 			res = sp_notif_set_cmd(
45 				ffa_sender(res), sp_notif_receiver(res),
46 				sp_notif_flags(res), sp_notif_bitmap(res));
47 			break;
48 		case SP_NOTIF_GET_CMD:
49 			res = sp_notif_get_cmd(ffa_sender(res),
50 					       sp_notif_vcpu(res),
51 					       sp_notif_flags(res));
52 			break;
53 		case SP_NOTIF_BIND_CMD:
54 			res = sp_notif_bind_cmd(
55 				ffa_sender(res), sp_notif_bind_sender(res),
56 				sp_notif_flags(res), sp_notif_bitmap(res));
57 			break;
58 		case SP_NOTIF_UNBIND_CMD:
59 			res = sp_notif_unbind_cmd(ffa_sender(res),
60 						  sp_notif_bind_sender(res),
61 						  sp_notif_bitmap(res));
62 			break;
63 		case SP_CHECK_CPU_IDX_CMD:
64 			res = sp_check_cpu_idx_cmd(ffa_sender(res),
65 						   sp_check_cpu_idx(res));
66 			break;
67 		case SP_INDIR_MSG_CMD:
68 			res = sp_indirect_msg_cmd(ffa_sender(res),
69 						  sp_indirect_msg_receiver(res),
70 						  sp_indirect_msg_payload(res));
71 			break;
72 		case SP_ECHO_INDIR_MSG_CMD:
73 			res = sp_echo_indirect_msg_cmd(ffa_sender(res));
74 			break;
75 		case SP_WAIT_BUSY_LOOP_CMD:
76 			for (volatile uint64_t loop = 0; loop < res.arg4;
77 			     loop++) {
78 			}
79 			res = sp_success(ffa_receiver(res), ffa_sender(res), 0);
80 			break;
81 		case SP_CHECK_STATE_TRANSITIONS_CMD:
82 			res = sp_check_state_transitions_cmd(ffa_sender(res),
83 							     res.arg4);
84 			break;
85 		default:
86 			HFTEST_LOG_FAILURE();
87 			HFTEST_LOG(HFTEST_LOG_INDENT
88 				   "0x%x is not a valid command id\n",
89 				   res.arg3);
90 			abort();
91 		}
92 	}
93 }
94