aboutsummaryrefslogtreecommitdiff
path: root/spm/cactus/cactus_test_cmds.c
diff options
context:
space:
mode:
authorJ-Alves <joao.alves@arm.com>2021-01-25 14:11:06 +0000
committerJ-Alves <joao.alves@arm.com>2021-03-12 12:56:48 +0000
commit0e1e7ca1967768891dc24ba384a0744d504a6fca (patch)
tree608cdb905f076b9894945590432eb1174be82d9e /spm/cactus/cactus_test_cmds.c
parent7d28b336e1f31afa88b6dac8ac9c5db73cdaae81 (diff)
downloadtf-a-tests-0e1e7ca1967768891dc24ba384a0744d504a6fca.tar.gz
Cactus: Refactor handling of commands
Added helper macros to define a command handler, build a command table in which each element is a pair of the handler and respective command ID. Message loop has been refactored to traverse the command table looking for the ID, and to call the respective command handler. Available tests have been moved to their own command handler. Signed-off-by: J-Alves <joao.alves@arm.com> Change-Id: I38a50a8d47b083c81c21950d98341de660891c61
Diffstat (limited to 'spm/cactus/cactus_test_cmds.c')
-rw-r--r--spm/cactus/cactus_test_cmds.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/spm/cactus/cactus_test_cmds.c b/spm/cactus/cactus_test_cmds.c
new file mode 100644
index 000000000..128f4c016
--- /dev/null
+++ b/spm/cactus/cactus_test_cmds.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "cactus_test_cmds.h"
+#include <ffa_helpers.h>
+
+/**
+ * Begin and end of command handler table, respectively. Both symbols defined by
+ * the linker.
+ */
+extern struct cactus_cmd_handler cactus_cmd_handler_begin[];
+extern struct cactus_cmd_handler cactus_cmd_handler_end[];
+
+/**
+ * Traverses command table from section ".cactus_handler", searches for a
+ * registered command and invokes the respective handler.
+ */
+bool cactus_handle_cmd(smc_ret_values *cmd_args, smc_ret_values *ret,
+ struct mailbox_buffers *mb)
+{
+ if (cmd_args == NULL || ret == NULL) {
+ ERROR("Invalid argumentos passed to %s!\n", __func__);
+ return false;
+ }
+
+ uint64_t in_cmd = cactus_get_cmd(*cmd_args);
+
+ for (struct cactus_cmd_handler *it_cmd = cactus_cmd_handler_begin;
+ it_cmd < cactus_cmd_handler_end;
+ it_cmd++) {
+ if (it_cmd->id == in_cmd) {
+ *ret = it_cmd->fn(cmd_args, mb);
+ return true;
+ }
+ }
+
+ return false;
+}