diff options
-rw-r--r-- | zephyr/linker/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/linker/iterables-rom.ld | 3 | ||||
-rw-r--r-- | zephyr/shim/include/zephyr_host_command.h | 41 | ||||
-rw-r--r-- | zephyr/shim/src/host_command.c | 27 |
4 files changed, 14 insertions, 59 deletions
diff --git a/zephyr/linker/CMakeLists.txt b/zephyr/linker/CMakeLists.txt index 27b028d22c..316dcc71be 100644 --- a/zephyr/linker/CMakeLists.txt +++ b/zephyr/linker/CMakeLists.txt @@ -14,3 +14,5 @@ zephyr_linker_sources(RAM_SECTIONS image_size.ld) # Little FW with specific purposes used by NPCX EC zephyr_linker_sources_ifdef(CONFIG_SOC_FAMILY_NPCX ROM_START SORT_KEY 1 npcx-lfw.ld) + +zephyr_linker_sources(SECTIONS iterables-rom.ld) diff --git a/zephyr/linker/iterables-rom.ld b/zephyr/linker/iterables-rom.ld new file mode 100644 index 0000000000..dea5731465 --- /dev/null +++ b/zephyr/linker/iterables-rom.ld @@ -0,0 +1,3 @@ +#ifdef CONFIG_PLATFORM_EC_HOSTCMD +ITERABLE_SECTION_ROM(host_command, 4) +#endif diff --git a/zephyr/shim/include/zephyr_host_command.h b/zephyr/shim/include/zephyr_host_command.h index 6535bb8876..ae8e1f9ee3 100644 --- a/zephyr/shim/include/zephyr_host_command.h +++ b/zephyr/shim/include/zephyr_host_command.h @@ -14,44 +14,15 @@ #ifdef CONFIG_PLATFORM_EC_HOSTCMD -/** Node in a list of host-command handlers */ -struct zshim_host_command_node { - struct host_command *cmd; - struct zshim_host_command_node *next; -}; - -/** - * Runtime helper for DECLARE_HOST_COMMAND setup data. - * - * @param routine Handler for the host command - * @param command Command to handle (EC_CMD_...) - * @param version_mask Mask of supported versions; use EC_VER_MASK() to select - * a version - */ -void zshim_setup_host_command( - int command, - enum ec_status (*routine)(struct host_cmd_handler_args *args), - int version_mask, struct zshim_host_command_node *entry); - /** * See include/host_command.h for documentation. */ -#define DECLARE_HOST_COMMAND(command, routine, version_mask) \ - _DECLARE_HOST_COMMAND_1(command, routine, version_mask, __LINE__) -#define _DECLARE_HOST_COMMAND_1(command, routine, version_mask, line) \ - _DECLARE_HOST_COMMAND_2(command, routine, version_mask, line) -#define _DECLARE_HOST_COMMAND_2(command, routine, version_mask, line) \ - static int _setup_host_command_##line(const struct device *unused) \ - { \ - ARG_UNUSED(unused); \ - static struct host_command cmd; \ - static struct zshim_host_command_node lst; \ - lst.cmd = &cmd; \ - zshim_setup_host_command(command, routine, version_mask, \ - &lst); \ - return 0; \ - } \ - SYS_INIT(_setup_host_command_##line, APPLICATION, 1) +#define DECLARE_HOST_COMMAND(_command, _routine, _version_mask) \ + STRUCT_SECTION_ITERABLE(host_command, _cros_hcmd_##_command) = { \ + .command = _command, \ + .handler = _routine, \ + .version_mask = _version_mask, \ + } #else /* !CONFIG_PLATFORM_EC_HOSTCMD */ #ifdef __clang__ #define DECLARE_HOST_COMMAND(command, routine, version_mask) diff --git a/zephyr/shim/src/host_command.c b/zephyr/shim/src/host_command.c index 6d586f225a..bf863b48de 100644 --- a/zephyr/shim/src/host_command.c +++ b/zephyr/shim/src/host_command.c @@ -5,32 +5,11 @@ #include "host_command.h" -static struct zshim_host_command_node *host_command_head; - -void zshim_setup_host_command( - int command, - enum ec_status (*routine)(struct host_cmd_handler_args *args), - int version_mask, struct zshim_host_command_node *entry) -{ - struct zshim_host_command_node **loc = &host_command_head; - - /* Setup the entry */ - entry->cmd->handler = routine; - entry->cmd->command = command; - entry->cmd->version_mask = version_mask; - entry->next = *loc; - - /* Insert the entry */ - *loc = entry; -} - struct host_command *zephyr_find_host_command(int command) { - struct zshim_host_command_node *p; - - for (p = host_command_head; p != NULL; p = p->next) { - if (p->cmd->command == command) - return p->cmd; + STRUCT_SECTION_FOREACH(host_command, cmd) { + if (cmd->command == command) + return cmd; } return NULL; |