blob: 01839c58cd2ae7dd3b7e4ec0e3ff2e2fc92e7d0e [file] [log] [blame]
J-Alvesb4e89a22021-03-09 10:04:39 +00001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "cactus_message_loop.h"
8#include "cactus_test_cmds.h"
9#include "cactus_tests.h"
10#include <debug.h>
11#include <ffa_helpers.h>
12
13CACTUS_CMD_HANDLER(notifications_bind, CACTUS_NOTIFICATION_BIND_CMD)
14{
15 ffa_id_t source = ffa_dir_msg_source(*args);
16 ffa_id_t vm_id = ffa_dir_msg_dest(*args);
17 ffa_id_t receiver = cactus_notification_get_receiver(*args);
18 ffa_id_t sender = cactus_notification_get_sender(*args);
19 ffa_notification_bitmap_t notifications =
20 cactus_notification_get_notifications(*args);
21 uint32_t flags = cactus_notification_get_flags(*args);
22 smc_ret_values ret;
23
24 VERBOSE("Partition %x requested to bind notifications '%llx' to %x\n",
25 source, notifications, receiver);
26
27 ret = ffa_notification_bind(sender, receiver, flags, notifications);
28
29 if (is_ffa_call_error(ret)) {
30 return cactus_error_resp(vm_id, source, ffa_error_code(ret));
31 }
32
33 return cactus_response(vm_id, source, CACTUS_SUCCESS);
34}
35
36CACTUS_CMD_HANDLER(notifications_unbind, CACTUS_NOTIFICATION_UNBIND_CMD)
37{
38 ffa_id_t source = ffa_dir_msg_source(*args);
39 ffa_id_t vm_id = ffa_dir_msg_dest(*args);
40 ffa_id_t receiver = cactus_notification_get_receiver(*args);
41 ffa_id_t sender = cactus_notification_get_sender(*args);
42 ffa_notification_bitmap_t notifications =
43 cactus_notification_get_notifications(*args);
44 smc_ret_values ret;
45
46 VERBOSE("Partition %x requested to unbind notifications '%llx' to %x\n",
47 source, notifications, receiver);
48
49 ret = ffa_notification_unbind(sender, receiver, notifications);
50
51 if (is_ffa_call_error(ret)) {
52 return cactus_error_resp(vm_id, source, ffa_error_code(ret));
53 }
54
55 return cactus_response(vm_id, source, CACTUS_SUCCESS);
56}
J-Alvesab775912021-03-29 15:22:33 +010057
58CACTUS_CMD_HANDLER(notifications_get, CACTUS_NOTIFICATION_GET_CMD)
59{
60 ffa_id_t source = ffa_dir_msg_source(*args);
61 ffa_id_t vm_id = ffa_dir_msg_dest(*args);
62 ffa_id_t notification_receiver =
63 cactus_notification_get_receiver(*args);
64 uint32_t flags = cactus_notification_get_flags(*args);
65 uint32_t vcpu_id = cactus_notification_get_vcpu(*args);
66 smc_ret_values ret;
67
68 VERBOSE("Partition %x requested to get notifications.\n", source);
69
70 ret = ffa_notification_get(notification_receiver, vcpu_id, flags);
71
72 if (is_ffa_call_error(ret)) {
73 return cactus_error_resp(vm_id, source, ffa_error_code(ret));
74 }
75
76 VERBOSE("Notifications returned:\n"
77 " from sp: %llx\n"
78 " from vm: %llx\n",
79 ffa_notifications_get_from_sp(ret),
80 ffa_notifications_get_from_vm(ret));
81
82 return cactus_notifications_get_success_resp(
83 vm_id, source, ffa_notifications_get_from_sp(ret),
84 ffa_notifications_get_from_vm(ret));
85}
86
87CACTUS_CMD_HANDLER(notifications_set, CACTUS_NOTIFICATIONS_SET_CMD)
88{
89 ffa_id_t source = ffa_dir_msg_source(*args);
90 ffa_id_t vm_id = ffa_dir_msg_dest(*args);
J-Alvesab775912021-03-29 15:22:33 +010091 ffa_notification_bitmap_t notifications = cactus_notification_get_notifications(*args);
J-Alvesfbbbf622021-07-30 16:43:36 +010092 ffa_id_t receiver = cactus_notifications_set_get_receiver(*args);
93 ffa_id_t sender = cactus_notifications_set_get_sender(*args);
94 ffa_id_t echo_dest = cactus_req_echo_get_echo_dest(*args);
J-Alvesab775912021-03-29 15:22:33 +010095 uint32_t flags = cactus_notification_get_flags(*args);
96 smc_ret_values ret;
97
98 VERBOSE("Partition %x requested to set notifications.\n", source);
99
100 ret = ffa_notification_set(sender, receiver, flags, notifications);
101
102 if (is_ffa_call_error(ret)) {
103 return cactus_error_resp(vm_id, source, ffa_error_code(ret));
104 }
105
J-Alvesfbbbf622021-07-30 16:43:36 +0100106 /*
107 * If flag to delay notification pending interrupt, an echo test command
108 * should be sent to another SP, to validate SWd is not preempted.
109 */
110 if ((flags & FFA_NOTIFICATIONS_FLAG_DELAY_SRI) != 0 &&
111 IS_SP_ID(echo_dest)) {
112 VERBOSE("Delay SRI. Test Echo to %x.\n", echo_dest);
113 ret = cactus_echo_send_cmd(vm_id, echo_dest,
114 FFA_NOTIFICATION_SET);
115
116 if (!is_expected_cactus_response(ret, CACTUS_SUCCESS,
117 FFA_NOTIFICATION_SET)) {
118 ERROR("Echo Failed!\n");
119 return cactus_error_resp(vm_id, source,
120 CACTUS_ERROR_TEST);
121 }
122 }
123
124 VERBOSE("Set notifications handled!\n");
125
J-Alvesab775912021-03-29 15:22:33 +0100126 return cactus_response(vm_id, source, CACTUS_SUCCESS);
127}