summaryrefslogtreecommitdiff
path: root/include/hooks.h
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2020-10-27 13:14:46 -0600
committerCommit Bot <commit-bot@chromium.org>2020-11-05 23:07:36 +0000
commit9d157db4aaa9cb04f33809f170712a244b627b56 (patch)
treec3d22d52c614cd0f8d38c9cc5ba2a1f08add80ee /include/hooks.h
parent1baff54e05a5d2f9179615f717e3514d37a594cb (diff)
downloadchrome-ec-9d157db4aaa9cb04f33809f170712a244b627b56.tar.gz
zephyr: shim in hooks and deferred
Implement deferred calls using the Zephyr's delayed work queues. Implement hooks using SYS_INIT and a hooks registry created during init. BUG=b:168030971 BRANCH=none TEST=provided unit tests Build instructions for unit tests: zmake configure -B/tmp/test \ ~/trunk/src/platform/ec/zephyr/test/hooks zmake build /tmp/test Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Id019cd1fe7bb3354377773d171036767e7efa706 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2504489 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'include/hooks.h')
-rw-r--r--include/hooks.h37
1 files changed, 30 insertions, 7 deletions
diff --git a/include/hooks.h b/include/hooks.h
index 39f558fe12..400713e794 100644
--- a/include/hooks.h
+++ b/include/hooks.h
@@ -235,6 +235,22 @@ enum hook_type {
* USB PD cc connection event.
*/
HOOK_USB_PD_CONNECT,
+
+#ifdef TEST_BUILD
+ /*
+ * Special hook types to be used by unit tests of the hooks
+ * implementation only.
+ */
+ HOOK_TEST_1,
+ HOOK_TEST_2,
+ HOOK_TEST_3,
+#endif /* TEST_BUILD */
+
+ /*
+ * Not a hook type (instead the number of hooks). This should
+ * always be placed at the end of this enumeration.
+ */
+ HOOK_TYPE_COUNT,
};
struct hook_data {
@@ -258,6 +274,14 @@ struct hook_data {
*/
void hook_notify(enum hook_type type);
+/*
+ * CONFIG_PLATFORM_EC_HOOKS is enabled by default during a Zephyr
+ * build, but can be disabled via Kconfig if desired (leaving the stub
+ * implementation at the bottom of this file).
+ */
+#if defined(CONFIG_PLATFORM_EC_HOOKS)
+#include "zephyr_hooks_shim.h"
+#elif defined(CONFIG_COMMON_RUNTIME)
struct deferred_data {
/* Deferred function pointer */
void (*routine)(void);
@@ -279,12 +303,6 @@ struct deferred_data {
*/
int hook_call_deferred(const struct deferred_data *data, int us);
-/*
- * Hooks are not currently supported by the Zephyr shim.
- * TODO(b/168799177): Implement compatible DECLARE_HOOK macro for
- * Zephyr OS.
- */
-#if defined(CONFIG_COMMON_RUNTIME) && !defined(CONFIG_ZEPHYR)
/**
* Register a hook routine.
*
@@ -341,7 +359,12 @@ int hook_call_deferred(const struct deferred_data *data, int us);
CONCAT2(routine, _data) \
__attribute__((section(".rodata.deferred"))) \
= {routine}
-#else /* !defined(CONFIG_COMMON_RUNTIME) || defined(CONFIG_ZEPHYR) */
+#else
+/*
+ * Stub implementation in case hooks are disabled (neither
+ * CONFIG_COMMON_RUNTIME nor CONFIG_PLATFORM_EC_HOOKS is defined)
+ */
+#define hook_call_deferred(unused1, unused2) -1
#define DECLARE_HOOK(t, func, p) \
void CONCAT2(unused_hook_, func)(void) { func(); }
#define DECLARE_DEFERRED(func) \