summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-07-08 18:07:06 +0000
committerCommit Bot <commit-bot@chromium.org>2021-08-10 21:53:32 +0000
commit64cda0a13de4056c13c8a62b756008480be6b425 (patch)
tree481f342135e489db5603903326e342ef06a2c5c8
parent2e9af0c566b905d2aa5c5d1bd7c692e549929ff1 (diff)
downloadchrome-ec-64cda0a13de4056c13c8a62b756008480be6b425.tar.gz
zephyr: shim: reimplement hooks using iterables
Reimplement the hooks shim code using Zephyr iterable sections. Keep the existing hook_registry based structure, gets rid of the per-hook init functions and instead initializes all the list nodes from a single init call. BRANCH=none BUG=b:195521227 TEST=build and run on volteer Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: Ic166d214ee1dcd1431ec484e5014cb297f7fb8c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3069399 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/linker/CMakeLists.txt1
-rw-r--r--zephyr/linker/iterables-ram.ld3
-rw-r--r--zephyr/shim/include/zephyr_hooks_shim.h32
-rw-r--r--zephyr/shim/src/hooks.c26
4 files changed, 26 insertions, 36 deletions
diff --git a/zephyr/linker/CMakeLists.txt b/zephyr/linker/CMakeLists.txt
index 316dcc71be..71955c6d9d 100644
--- a/zephyr/linker/CMakeLists.txt
+++ b/zephyr/linker/CMakeLists.txt
@@ -15,4 +15,5 @@ zephyr_linker_sources(RAM_SECTIONS image_size.ld)
zephyr_linker_sources_ifdef(CONFIG_SOC_FAMILY_NPCX ROM_START SORT_KEY 1
npcx-lfw.ld)
+zephyr_linker_sources(DATA_SECTIONS iterables-ram.ld)
zephyr_linker_sources(SECTIONS iterables-rom.ld)
diff --git a/zephyr/linker/iterables-ram.ld b/zephyr/linker/iterables-ram.ld
new file mode 100644
index 0000000000..58318a0e78
--- /dev/null
+++ b/zephyr/linker/iterables-ram.ld
@@ -0,0 +1,3 @@
+#ifdef CONFIG_PLATFORM_EC_HOOKS
+ITERABLE_SECTION_RAM(zephyr_shim_hook_list, 4)
+#endif
diff --git a/zephyr/shim/include/zephyr_hooks_shim.h b/zephyr/shim/include/zephyr_hooks_shim.h
index 6edfdfe0a9..7175b5a6af 100644
--- a/zephyr/shim/include/zephyr_hooks_shim.h
+++ b/zephyr/shim/include/zephyr_hooks_shim.h
@@ -53,33 +53,17 @@ int hook_call_deferred(const struct deferred_data *data, int us);
struct zephyr_shim_hook_list {
void (*routine)(void);
int priority;
+ enum hook_type type;
struct zephyr_shim_hook_list *next;
};
/**
- * Runtime helper for DECLARE_HOOK setup data.
- *
- * @param type The type of hook.
- * @param routine The handler for the hook.
- * @param priority The priority (smaller values are executed first).
- * @param entry A statically allocated list entry.
- */
-void zephyr_shim_setup_hook(enum hook_type type, void (*routine)(void),
- int priority, struct zephyr_shim_hook_list *entry);
-
-/**
* See include/hooks.h for documentation.
*/
-#define DECLARE_HOOK(hooktype, routine, priority) \
- _DECLARE_HOOK_1(hooktype, routine, priority, __LINE__)
-#define _DECLARE_HOOK_1(hooktype, routine, priority, line) \
- _DECLARE_HOOK_2(hooktype, routine, priority, line)
-#define _DECLARE_HOOK_2(hooktype, routine, priority, line) \
- static int _setup_hook_##line(const struct device *unused) \
- { \
- ARG_UNUSED(unused); \
- static struct zephyr_shim_hook_list lst; \
- zephyr_shim_setup_hook(hooktype, routine, priority, &lst); \
- return 0; \
- } \
- SYS_INIT(_setup_hook_##line, APPLICATION, 1)
+#define DECLARE_HOOK(_hooktype, _routine, _priority) \
+ STRUCT_SECTION_ITERABLE(zephyr_shim_hook_list, \
+ _cros_hook_##_hooktype##_##_routine) = { \
+ .type = _hooktype, \
+ .routine = _routine, \
+ .priority = _priority, \
+ }
diff --git a/zephyr/shim/src/hooks.c b/zephyr/shim/src/hooks.c
index 9d196d40ef..2ec19304d3 100644
--- a/zephyr/shim/src/hooks.c
+++ b/zephyr/shim/src/hooks.c
@@ -52,24 +52,26 @@ int hook_call_deferred(const struct deferred_data *data, int us)
static struct zephyr_shim_hook_list *hook_registry[HOOK_TYPE_COUNT];
-void zephyr_shim_setup_hook(enum hook_type type, void (*routine)(void),
- int priority, struct zephyr_shim_hook_list *entry)
+static int zephyr_shim_setup_hooks(const struct device *unused)
{
- struct zephyr_shim_hook_list **loc = &hook_registry[type];
+ STRUCT_SECTION_FOREACH(zephyr_shim_hook_list, entry) {
+ struct zephyr_shim_hook_list **loc = &hook_registry[entry->type];
- /* Find the correct place to put the entry in the registry. */
- while (*loc && (*loc)->priority < priority)
- loc = &((*loc)->next);
+ /* Find the correct place to put the entry in the registry. */
+ while (*loc && (*loc)->priority < entry->priority)
+ loc = &((*loc)->next);
- /* Setup the entry. */
- entry->routine = routine;
- entry->priority = priority;
- entry->next = *loc;
+ entry->next = *loc;
- /* Insert the entry. */
- *loc = entry;
+ /* Insert the entry. */
+ *loc = entry;
+ }
+
+ return 0;
}
+SYS_INIT(zephyr_shim_setup_hooks, APPLICATION, 1);
+
void hook_notify(enum hook_type type)
{
struct zephyr_shim_hook_list *p;