J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 1 | /* |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, Arm Limited. All rights reserved. |
J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <ffa_helpers.h> |
| 8 | #include <spm_common.h> |
| 9 | |
| 10 | /** |
| 11 | * Pairs a command id with a function call, to handle the command ID. |
| 12 | */ |
| 13 | struct cactus_cmd_handler { |
| 14 | const uint64_t id; |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 15 | struct ffa_value (*fn)(const struct ffa_value *args, |
| 16 | struct mailbox_buffers *mb); |
J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | /** |
| 20 | * Helper to create the name of a handler function. |
| 21 | */ |
| 22 | #define CACTUS_HANDLER_FN_NAME(name) cactus_##name##_handler |
| 23 | |
| 24 | /** |
| 25 | * Define handler's function signature. |
| 26 | */ |
| 27 | #define CACTUS_HANDLER_FN(name) \ |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 28 | static struct ffa_value CACTUS_HANDLER_FN_NAME(name)( \ |
| 29 | const struct ffa_value *args, struct mailbox_buffers *mb) |
J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Helper to define Cactus command handler, and pair it with a command ID. |
| 33 | * It also creates a table with this information, to be traversed by |
| 34 | * 'cactus_handle_cmd' function. |
| 35 | */ |
| 36 | #define CACTUS_CMD_HANDLER(name, ID) \ |
| 37 | CACTUS_HANDLER_FN(name); \ |
| 38 | struct cactus_cmd_handler name __section(".cactus_handler") = { \ |
| 39 | .id = ID, .fn = CACTUS_HANDLER_FN_NAME(name), \ |
| 40 | }; \ |
| 41 | CACTUS_HANDLER_FN(name) |
| 42 | |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 43 | bool cactus_handle_cmd(struct ffa_value *cmd_args, struct ffa_value *ret, |
J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 44 | struct mailbox_buffers *mb); |