blob: e13e40d34cb683652c7752aa5313b51bd3eee9e1 [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{
J-Alves4cb9dee2021-03-03 13:59:52 +000024 uint64_t in_cmd;
25
J-Alves0e1e7ca2021-01-25 14:11:06 +000026 if (cmd_args == NULL || ret == NULL) {
27 ERROR("Invalid argumentos passed to %s!\n", __func__);
28 return false;
29 }
30
J-Alves4cb9dee2021-03-03 13:59:52 +000031 in_cmd = cactus_get_cmd(*cmd_args);
J-Alves0e1e7ca2021-01-25 14:11:06 +000032
33 for (struct cactus_cmd_handler *it_cmd = cactus_cmd_handler_begin;
34 it_cmd < cactus_cmd_handler_end;
35 it_cmd++) {
36 if (it_cmd->id == in_cmd) {
37 *ret = it_cmd->fn(cmd_args, mb);
38 return true;
39 }
40 }
41
J-Alves4cb9dee2021-03-03 13:59:52 +000042 *ret = cactus_error_resp(ffa_dir_msg_dest(*cmd_args),
43 ffa_dir_msg_source(*cmd_args),
44 CACTUS_ERROR_UNHANDLED);
45 return true;
J-Alves0e1e7ca2021-01-25 14:11:06 +000046}