feat(cactus): count requests received

Message loop counts the amount of requests received in each core. The
counting can be accessed through newly added test command
CACTUS_GET_REQ_COUNT_CMD.
Added such special command to be able to test delay Schedule Receiver
Interrupt, in the context of the notifications feature.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Id0a5a9cf58e10d1221a1a0f0af6264474fe7e020
diff --git a/spm/cactus/cactus_tests/cactus_message_loop.c b/spm/cactus/cactus_tests/cactus_message_loop.c
index c24f6fc..750c954 100644
--- a/spm/cactus/cactus_tests/cactus_message_loop.c
+++ b/spm/cactus/cactus_tests/cactus_message_loop.c
@@ -4,11 +4,20 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#include "cactus_message_loop.h"
-#include "cactus_test_cmds.h"
-#include <ffa_helpers.h>
 #include <debug.h>
 
+#include <cactus_message_loop.h>
+#include <cactus_test_cmds.h>
+#include <ffa_helpers.h>
+#include <events.h>
+#include <platform.h>
+
+/**
+ * Counter of the number of handled requests, for each CPU. The number of
+ * requests can be accessed from another Cactus SP, or from the normal world
+ * using a special test command.
+ */
+static uint32_t requests_counter[PLATFORM_CORE_COUNT];
 
 /**
  * Begin and end of command handler table, respectively. Both symbols defined by
@@ -31,6 +40,10 @@
 {
 	uint64_t in_cmd;
 
+	/* Get which core it is running from. */
+	unsigned int core_pos = platform_get_core_pos(
+						read_mpidr_el1() & MPID_MASK);
+
 	if (cmd_args == NULL || ret == NULL) {
 		ERROR("Invalid arguments passed to %s!\n", __func__);
 		return false;
@@ -45,10 +58,33 @@
 	     it_cmd++) {
 		if (it_cmd->id == in_cmd) {
 			*ret = it_cmd->fn(cmd_args, mb);
+
+			/*
+			 * Increment the number of requests handled in current
+			 * core.
+			 */
+			requests_counter[core_pos]++;
+
 			return true;
 		}
 	}
 
+	/* Handle special command. */
+	if (in_cmd == CACTUS_GET_REQ_COUNT_CMD) {
+		uint32_t requests_counter_resp;
+
+		/* Read value from array. */
+		requests_counter_resp = requests_counter[core_pos];
+		VERBOSE("Requests Counter %u, core: %u\n", requests_counter_resp,
+							   core_pos);
+
+		*ret = cactus_success_resp(
+			ffa_dir_msg_dest(*cmd_args),
+			ffa_dir_msg_source(*cmd_args),
+			requests_counter_resp);
+		return true;
+	}
+
 	*ret = cactus_error_resp(ffa_dir_msg_dest(*cmd_args),
 				 ffa_dir_msg_source(*cmd_args),
 				 CACTUS_ERROR_UNHANDLED);