J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
| 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; |
| 15 | smc_ret_values (*fn)(const smc_ret_values *args, |
| 16 | struct mailbox_buffers *mb); |
| 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) \ |
| 28 | static smc_ret_values CACTUS_HANDLER_FN_NAME(name)( \ |
| 29 | const smc_ret_values *args, struct mailbox_buffers *mb) |
| 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 | |
| 43 | bool cactus_handle_cmd(smc_ret_values *cmd_args, smc_ret_values *ret, |
| 44 | struct mailbox_buffers *mb); |