summaryrefslogtreecommitdiff
path: root/zephyr/shim/include/zephyr_hooks_shim.h
blob: f3949787bd025fd0691f6bd5601edc3f23354472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Copyright 2020 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#if !defined(__CROS_EC_HOOKS_H) || defined(__CROS_EC_ZEPHYR_HOOKS_SHIM_H)
#error "This file must only be included from hooks.h. Include hooks.h directly."
#endif
#define __CROS_EC_ZEPHYR_HOOKS_SHIM_H

#include <zephyr/init.h>
#include <zephyr/kernel.h>

#include "common.h"
#include "cros_version.h"

/**
 * The internal data structure stored for a deferred function.
 */
struct deferred_data {
	struct k_work_delayable *work;
};

/**
 * See include/hooks.h for documentation.
 */
int hook_call_deferred(const struct deferred_data *data, int us);

#define DECLARE_DEFERRED(routine)                                    \
	K_WORK_DELAYABLE_DEFINE(routine##_work_data,                 \
				(void (*)(struct k_work *))routine); \
	__maybe_unused const struct deferred_data routine##_data = { \
		.work = &routine##_work_data,                        \
	}

/**
 * Record describing a single hook routine.
 */
struct zephyr_shim_hook_info {
	void (*routine)(void);
	uint16_t priority; /* HOOK_PRIO_LAST = 9999 */
};

/*
 * List of hook routines.
 *
 * Values are contiguous, where *start is the first and *(end - 1) is the last.
 */
struct zephyr_shim_hook_list {
	const struct zephyr_shim_hook_info *start;
	const struct zephyr_shim_hook_info *end;
};

/**
 * See include/hooks.h for documentation.
 */
#define DECLARE_HOOK(_hooktype, _routine, _priority)                 \
	STRUCT_SECTION_ITERABLE_ALTERNATE(                           \
		zephyr_shim_hook_##_hooktype, zephyr_shim_hook_info, \
		_cros_hook_##_hooktype##_##_routine) = {             \
		.routine = _routine,                                 \
		.priority = _priority,                               \
	}