blob: 2cd54c1149299671146bb70c022b2fcdec3edad5 [file] [log] [blame]
J-Alves0e1e7ca2021-01-25 14:11:06 +00001/*
Daniel Boulbyce386b12022-03-29 18:36:36 +01002 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
J-Alves0e1e7ca2021-01-25 14:11:06 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
J-Alveseeb25472021-03-11 09:54:21 +00007#include <debug.h>
8
J-Alvesf7535f42021-07-30 11:58:41 +01009#include <cactus_message_loop.h>
10#include <cactus_test_cmds.h>
11#include <ffa_helpers.h>
12#include <events.h>
13#include <platform.h>
14
15/**
16 * Counter of the number of handled requests, for each CPU. The number of
17 * requests can be accessed from another Cactus SP, or from the normal world
18 * using a special test command.
19 */
20static uint32_t requests_counter[PLATFORM_CORE_COUNT];
J-Alves0e1e7ca2021-01-25 14:11:06 +000021
22/**
23 * Begin and end of command handler table, respectively. Both symbols defined by
24 * the linker.
25 */
26extern struct cactus_cmd_handler cactus_cmd_handler_begin[];
27extern struct cactus_cmd_handler cactus_cmd_handler_end[];
28
J-Alveseeb25472021-03-11 09:54:21 +000029#define PRINT_CMD(smc_ret) \
30 VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n", \
31 smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, \
32 smc_ret.ret6, smc_ret.ret7)
33
J-Alves0e1e7ca2021-01-25 14:11:06 +000034/**
35 * Traverses command table from section ".cactus_handler", searches for a
36 * registered command and invokes the respective handler.
37 */
Daniel Boulbyce386b12022-03-29 18:36:36 +010038bool cactus_handle_cmd(struct ffa_value *cmd_args, struct ffa_value *ret,
J-Alves0e1e7ca2021-01-25 14:11:06 +000039 struct mailbox_buffers *mb)
40{
J-Alves4cb9dee2021-03-03 13:59:52 +000041 uint64_t in_cmd;
42
J-Alvesf7535f42021-07-30 11:58:41 +010043 /* Get which core it is running from. */
44 unsigned int core_pos = platform_get_core_pos(
45 read_mpidr_el1() & MPID_MASK);
46
J-Alves0e1e7ca2021-01-25 14:11:06 +000047 if (cmd_args == NULL || ret == NULL) {
Madhukar Pappireddycd183ef2021-08-05 15:34:07 -050048 ERROR("Invalid arguments passed to %s!\n", __func__);
J-Alves0e1e7ca2021-01-25 14:11:06 +000049 return false;
50 }
51
J-Alveseeb25472021-03-11 09:54:21 +000052 PRINT_CMD((*cmd_args));
53
J-Alves4cb9dee2021-03-03 13:59:52 +000054 in_cmd = cactus_get_cmd(*cmd_args);
J-Alves0e1e7ca2021-01-25 14:11:06 +000055
56 for (struct cactus_cmd_handler *it_cmd = cactus_cmd_handler_begin;
57 it_cmd < cactus_cmd_handler_end;
58 it_cmd++) {
59 if (it_cmd->id == in_cmd) {
60 *ret = it_cmd->fn(cmd_args, mb);
J-Alvesf7535f42021-07-30 11:58:41 +010061
62 /*
63 * Increment the number of requests handled in current
64 * core.
65 */
66 requests_counter[core_pos]++;
67
J-Alves0e1e7ca2021-01-25 14:11:06 +000068 return true;
69 }
70 }
71
J-Alvesf7535f42021-07-30 11:58:41 +010072 /* Handle special command. */
73 if (in_cmd == CACTUS_GET_REQ_COUNT_CMD) {
74 uint32_t requests_counter_resp;
75
76 /* Read value from array. */
77 requests_counter_resp = requests_counter[core_pos];
78 VERBOSE("Requests Counter %u, core: %u\n", requests_counter_resp,
79 core_pos);
80
81 *ret = cactus_success_resp(
82 ffa_dir_msg_dest(*cmd_args),
83 ffa_dir_msg_source(*cmd_args),
84 requests_counter_resp);
85 return true;
86 }
87
J-Alves4cb9dee2021-03-03 13:59:52 +000088 *ret = cactus_error_resp(ffa_dir_msg_dest(*cmd_args),
89 ffa_dir_msg_source(*cmd_args),
90 CACTUS_ERROR_UNHANDLED);
91 return true;
J-Alves0e1e7ca2021-01-25 14:11:06 +000092}