blob: 128f4c016f8a4e9c09dd3b9875231bdb442f6958 [file] [log] [blame]
J-Alves0e1e7ca2021-01-25 14:11:06 +00001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "cactus_test_cmds.h"
8#include <ffa_helpers.h>
9
10/**
11 * Begin and end of command handler table, respectively. Both symbols defined by
12 * the linker.
13 */
14extern struct cactus_cmd_handler cactus_cmd_handler_begin[];
15extern struct cactus_cmd_handler cactus_cmd_handler_end[];
16
17/**
18 * Traverses command table from section ".cactus_handler", searches for a
19 * registered command and invokes the respective handler.
20 */
21bool cactus_handle_cmd(smc_ret_values *cmd_args, smc_ret_values *ret,
22 struct mailbox_buffers *mb)
23{
24 if (cmd_args == NULL || ret == NULL) {
25 ERROR("Invalid argumentos passed to %s!\n", __func__);
26 return false;
27 }
28
29 uint64_t in_cmd = cactus_get_cmd(*cmd_args);
30
31 for (struct cactus_cmd_handler *it_cmd = cactus_cmd_handler_begin;
32 it_cmd < cactus_cmd_handler_end;
33 it_cmd++) {
34 if (it_cmd->id == in_cmd) {
35 *ret = it_cmd->fn(cmd_args, mb);
36 return true;
37 }
38 }
39
40 return false;
41}