test(notifications): signaling from MP SP to UP SP

Test setting notifications from all running cores, sender being an MP
SP and the receiver an UP SP. Intent is to validate a different flow
for triggering SRI, and validate handling of per-vCPU notifications
targeting a UP SP.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I4f54ef9c4de0558dcbc3a1245cafb6da267752b7
diff --git a/spm/cactus/cactus_tests/cactus_test_notifications.c b/spm/cactus/cactus_tests/cactus_test_notifications.c
index 57375e7..bd293f9 100644
--- a/spm/cactus/cactus_tests/cactus_test_notifications.c
+++ b/spm/cactus/cactus_tests/cactus_test_notifications.c
@@ -167,7 +167,7 @@
 		}
 	}
 
-	VERBOSE("Set notifications handled!\n");
+	VERBOSE("Set notifications handled (core %u)!\n", get_current_core_id());
 
 	return cactus_response(vm_id, source, CACTUS_SUCCESS);
 }
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c b/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c
index dde8d58..7ed8f97 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c
@@ -1535,3 +1535,99 @@
 
 	return result;
 }
+
+test_result_t notifications_set_per_vcpu_on_handler(void)
+{
+	unsigned int core_pos = get_current_core_id();
+	test_result_t result = TEST_RESULT_FAIL;
+
+	if (!spm_core_sp_init(per_vcpu_sender)) {
+		goto out;
+	}
+
+	if (!notification_set(per_vcpu_receiver, per_vcpu_sender,
+			      FFA_NOTIFICATIONS_FLAG_DELAY_SRI |
+			      FFA_NOTIFICATIONS_FLAG_PER_VCPU  |
+			      FFA_NOTIFICATIONS_FLAGS_VCPU_ID(0),
+			      FFA_NOTIFICATION(core_pos))) {
+		goto out;
+	}
+
+	result = TEST_RESULT_SUCCESS;
+
+out:
+	/* Tell the lead CPU that the calling CPU has completed the test. */
+	tftf_send_event(&per_vcpu_finished[core_pos]);
+
+	return result;
+}
+
+test_result_t test_ffa_notifications_mp_sp_signals_up_sp(void)
+{
+	ffa_notification_bitmap_t to_bind = 0;
+
+	/* prepare info get variables. */
+
+	CHECK_SPMC_TESTING_SETUP(1, 1, expected_sp_uuids);
+
+	/* Setting per-vCPU sender and receiver IDs. */
+	per_vcpu_sender = SP_ID(2); /* MP SP */
+	per_vcpu_receiver = SP_ID(3); /* UP SP */
+
+	schedule_receiver_interrupt_init();
+
+	notification_pending_interrupt_sp_enable(per_vcpu_receiver, true);
+
+	/* Prepare notifications bitmap to have one bit platform core. */
+	for (uint32_t i = 0; i < PLATFORM_CORE_COUNT; i++) {
+		to_bind |= FFA_NOTIFICATION(i);
+	}
+
+	/* Request receiver to bind a set of notifications to the sender. */
+	if (!request_notification_bind(per_vcpu_receiver, per_vcpu_receiver,
+				       per_vcpu_sender, to_bind,
+				       FFA_NOTIFICATIONS_FLAG_PER_VCPU,
+				       CACTUS_SUCCESS, 0)) {
+		return TEST_RESULT_FAIL;
+	}
+
+	/*
+	 * Boot up system, and then request sender to signal notification from
+	 * every core into into receiver's only vCPU. Delayed SRI.
+	 */
+	if (!notification_set(per_vcpu_receiver, per_vcpu_sender,
+			     FFA_NOTIFICATIONS_FLAG_DELAY_SRI |
+			     FFA_NOTIFICATIONS_FLAG_PER_VCPU |
+			     FFA_NOTIFICATIONS_FLAGS_VCPU_ID(0),
+			     FFA_NOTIFICATION(0))) {
+		return TEST_RESULT_FAIL;
+	}
+
+	if (spm_run_multi_core_test(
+		(uintptr_t)notifications_set_per_vcpu_on_handler,
+		per_vcpu_finished) != TEST_RESULT_SUCCESS) {
+		return TEST_RESULT_FAIL;
+	}
+
+	if (!check_schedule_receiver_interrupt_handled()) {
+		return TEST_RESULT_FAIL;
+	}
+
+	if (!notification_get_and_validate(per_vcpu_receiver, to_bind, 0, 0,
+		FFA_NOTIFICATIONS_FLAG_BITMAP_SP, true)) {
+		return TEST_RESULT_FAIL;
+	}
+
+	/* Request unbind. */
+	if (!request_notification_unbind(per_vcpu_receiver, per_vcpu_receiver,
+					per_vcpu_sender, to_bind,
+					CACTUS_SUCCESS, 0)) {
+		return TEST_RESULT_FAIL;
+	}
+
+	schedule_receiver_interrupt_deinit();
+
+	notification_pending_interrupt_sp_enable(per_vcpu_receiver, false);
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/tests-spm.xml b/tftf/tests/tests-spm.xml
index 9603b9a..cfc7914 100644
--- a/tftf/tests/tests-spm.xml
+++ b/tftf/tests/tests-spm.xml
@@ -142,6 +142,8 @@
                function="test_ffa_notifications_sp_signals_sp_delayed_sri" />
      <testcase name="Notifications unbind while pending"
                function="test_ffa_notifications_unbind_pending" />
+     <testcase name="Notifications MP SP signals UP SP per-vCPU"
+               function="test_ffa_notifications_mp_sp_signals_up_sp" />
      <testcase name="Notifications info get no data"
                function="test_ffa_notifications_info_get_none" />
      <testcase name="Notifications VM signals SP per-vCPU"