summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-07-08 17:36:16 +0000
committerCommit Bot <commit-bot@chromium.org>2021-08-10 21:53:27 +0000
commit2e9af0c566b905d2aa5c5d1bd7c692e549929ff1 (patch)
treea69bd06f06f5d450bb13bf11f61dd75551219855
parente3ded643c83a1fd87d800b37dc4b7a7f7f3f137f (diff)
downloadchrome-ec-2e9af0c566b905d2aa5c5d1bd7c692e549929ff1.tar.gz
zephyr: shim: reimplement mkbp_event using iterables
Rewrite the MKBP events shim using iterable sections. BRANCH=none BUG=b:195521227 TEST=build and run on volteer Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: Ia96fb9ec06b1a86b1be293209db317a361ae4741 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3069398 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/iterables-rom.ld4
-rw-r--r--zephyr/shim/include/zephyr_mkbp_event.h35
-rw-r--r--zephyr/shim/src/mkbp_event.c21
3 files changed, 12 insertions, 48 deletions
diff --git a/zephyr/linker/iterables-rom.ld b/zephyr/linker/iterables-rom.ld
index dea5731465..b8e451a085 100644
--- a/zephyr/linker/iterables-rom.ld
+++ b/zephyr/linker/iterables-rom.ld
@@ -1,3 +1,7 @@
#ifdef CONFIG_PLATFORM_EC_HOSTCMD
ITERABLE_SECTION_ROM(host_command, 4)
#endif
+
+#ifdef CONFIG_PLATFORM_EC_MKBP_EVENT
+ITERABLE_SECTION_ROM(mkbp_event_source, 4)
+#endif
diff --git a/zephyr/shim/include/zephyr_mkbp_event.h b/zephyr/shim/include/zephyr_mkbp_event.h
index b37ce0d5d3..159aebc8e1 100644
--- a/zephyr/shim/include/zephyr_mkbp_event.h
+++ b/zephyr/shim/include/zephyr_mkbp_event.h
@@ -10,39 +10,14 @@
#endif
#define __CROS_EC_ZEPHYR_MKBP_EVENT_H
-/** Node in a list of mkbp event handlers */
-struct zshim_mkbp_event_node {
- struct mkbp_event_source evtsrc;
- struct zshim_mkbp_event_node *next;
-};
-
-/**
- * Runtime helper for DECLARE_EVENT_SOURCE setup data.
- *
- * @param event_type event type (EC_MKBP_EVENT_...)
- * @param get_data event handler for the event type
- * @param entry pointer to statically allocated zshim_mkbp_event_node
- item
- */
-void zshim_setup_mkbp_event(uint8_t event_type, int (*get_data)(uint8_t *data),
- struct zshim_mkbp_event_node *entry);
-
const struct mkbp_event_source *zephyr_find_mkbp_event_source(
uint8_t event_type);
/**
* See include/mkbp_event.h for documentation.
*/
-#define DECLARE_EVENT_SOURCE(type, func) \
- _DECLARE_EVENT_SOURCE_1(type, func, __LINE__)
-#define _DECLARE_EVENT_SOURCE_1(type, func, line) \
- _DECLARE_EVENT_SOURCE_2(type, func, line)
-#define _DECLARE_EVENT_SOURCE_2(type, func, line) \
- static int _setup_mkbp_event_##line(const struct device *unused) \
- { \
- ARG_UNUSED(unused); \
- static struct zshim_mkbp_event_node mkbp_event; \
- zshim_setup_mkbp_event(type, func, &mkbp_event); \
- return 0; \
- } \
- SYS_INIT(_setup_mkbp_event_##line, APPLICATION, 1)
+#define DECLARE_EVENT_SOURCE(_type, _func) \
+ STRUCT_SECTION_ITERABLE(mkbp_event_source, _cros_evtsrc_##_func) = { \
+ .event_type = _type, \
+ .get_data = _func, \
+ }
diff --git a/zephyr/shim/src/mkbp_event.c b/zephyr/shim/src/mkbp_event.c
index fec6ef3ab3..39bcb001b8 100644
--- a/zephyr/shim/src/mkbp_event.c
+++ b/zephyr/shim/src/mkbp_event.c
@@ -5,26 +5,11 @@
#include "mkbp_event.h"
-static struct zshim_mkbp_event_node *mkbp_event_head;
-
-void zshim_setup_mkbp_event(uint8_t event_type, int (*get_data)(uint8_t *data),
- struct zshim_mkbp_event_node *entry)
-{
-
- entry->evtsrc.event_type = event_type;
- entry->evtsrc.get_data = get_data;
- entry->next = mkbp_event_head;
-
- mkbp_event_head = entry;
-}
-
const struct mkbp_event_source *zephyr_find_mkbp_event_source(uint8_t type)
{
- struct zshim_mkbp_event_node *p;
-
- for (p = mkbp_event_head; p != NULL; p = p->next) {
- if (p->evtsrc.event_type == type)
- return &p->evtsrc;
+ STRUCT_SECTION_FOREACH(mkbp_event_source, evtsrc) {
+ if (evtsrc->event_type == type)
+ return evtsrc;
}
return NULL;