1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Events provide a general-purpose way to react to / subscribe to changes
6 * Copyright 2021 Google LLC
13 #include <dm/ofnode_decl.h>
14 #include <linux/types.h>
17 * enum event_t - Types of events supported by U-Boot
19 * @EVT_DM_PRE_PROBE: Device is about to be probed
25 /* Events related to driver model */
39 /* Device tree fixups before booting */
42 /* To be called once, before calling main_loop() */
50 * struct event_data_test - test data
52 * @signal: A value to update the state with
54 struct event_data_test {
59 * struct event_dm - driver model event
61 * @dev: Device this event relates to
68 * struct event_fpga_load - fpga load event
70 * @buf: The buffer that was loaded into the fpga
71 * @bsize: The size of the buffer that was loaded into the fpga
72 * @result: Result of the load operation
74 struct event_fpga_load {
81 * struct event_ft_fixup - FDT fixup before booting
83 * @tree: tree to update
84 * @images: images which are being booted
86 struct event_ft_fixup {
88 struct bootm_headers *images;
93 * struct event - an event that can be sent and received
96 * @data: Data for this particular event
100 union event_data data;
103 /** Function type for event handlers */
104 typedef int (*event_handler_t)(void *ctx, struct event *event);
107 * struct evspy_info - information about an event spy
109 * @func: Function to call when the event is activated (must be first)
111 * @id: Event id string
114 event_handler_t func;
116 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
121 /* Declare a new event spy */
122 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
123 #define _ESPY_REC(_type, _func) { _func, _type, #_func, }
125 #define _ESPY_REC(_type, _func) { _func, _type, }
128 static inline const char *event_spy_id(struct evspy_info *spy)
130 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
138 * It seems that LTO will drop list entries if it decides they are not used,
139 * although the conditions that cause this are unclear.
141 * The example found is the following:
143 * static int sandbox_misc_init_f(void *ctx, struct event *event)
145 * return sandbox_early_getopt_check();
147 * EVENT_SPY(EVT_MISC_INIT_F, sandbox_misc_init_f);
149 * where EVENT_SPY uses ll_entry_declare()
151 * In this case, LTO decides to drop the sandbox_misc_init_f() function
152 * (which is fine) but then drops the linker-list entry too. This means
153 * that the code no longer works, in this case sandbox no-longer checks its
154 * command-line arguments properly.
156 * Without LTO, the KEEP() command in the .lds file is enough to keep the
157 * entry around. But with LTO it seems that the entry has already been
158 * dropped before the link script is considered.
160 * The only solution I can think of is to mark linker-list entries as 'used'
161 * using an attribute. This should be safe, since we don't actually want to drop
162 * any of these. However this does slightly limit LTO's optimisation choices.
164 * Another issue has come up, only with clang: using 'static' makes it throw
165 * away the linker-list entry sometimes, e.g. with the EVT_FT_FIXUP entry in
166 * vbe_simple.c - so for now, make it global.
168 #define EVENT_SPY(_type, _func) \
169 __used ll_entry_declare(struct evspy_info, _type ## _3_ ## _func, \
170 evspy_info) = _ESPY_REC(_type, _func)
173 * event_register - register a new spy
176 * @type: Event type to subscribe to
177 * @func: Function to call when the event is sent
178 * @ctx: Context to pass to the function
179 * @return 0 if OK, -ve on error
181 int event_register(const char *id, enum event_t type, event_handler_t func,
184 /** event_show_spy_list( - Show a list of event spies */
185 void event_show_spy_list(void);
188 * event_manual_reloc() - Relocate event handler pointers
190 * Relocate event handler pointers for all static event spies. It is called
191 * during the generic board init sequence, after relocation.
195 int event_manual_reloc(void);
198 * event_notify() - notify spies about an event
200 * It is possible to pass in union event_data here but that may not be
201 * convenient if the data is elsewhere, or is one of the members of the union.
202 * So this uses a void * for @data, with a separate @size.
205 * @data: Event data to be sent (e.g. union_event_data)
206 * @size: Size of data in bytes
207 * @return 0 if OK, -ve on error
209 int event_notify(enum event_t type, void *data, int size);
211 #if CONFIG_IS_ENABLED(EVENT)
213 * event_notify_null() - notify spies about an event
215 * Data is NULL and the size is 0
218 * @return 0 if OK, -ve on error
220 int event_notify_null(enum event_t type);
222 static inline int event_notify_null(enum event_t type)
228 #if CONFIG_IS_ENABLED(EVENT_DYNAMIC)
230 * event_uninit() - Clean up dynamic events
232 * This removes all dynamic event handlers
234 int event_uninit(void);
237 * event_uninit() - Set up dynamic events
239 * Init a list of dynamic event handlers, so that these can be added as
242 int event_init(void);
244 static inline int event_uninit(void)
249 static inline int event_init(void)