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 */
38 /* Device tree fixups before booting */
41 /* To be called once, before calling main_loop() */
49 * struct event_data_test - test data
51 * @signal: A value to update the state with
53 struct event_data_test {
58 * struct event_dm - driver model event
60 * @dev: Device this event relates to
67 * struct event_fpga_load - fpga load event
69 * @buf: The buffer that was loaded into the fpga
70 * @bsize: The size of the buffer that was loaded into the fpga
71 * @result: Result of the load operation
73 struct event_fpga_load {
80 * struct event_ft_fixup - FDT fixup before booting
82 * @tree: tree to update
83 * @images: images which are being booted
85 struct event_ft_fixup {
87 struct bootm_headers *images;
92 * struct event - an event that can be sent and received
95 * @data: Data for this particular event
99 union event_data data;
102 /** Function type for event handlers */
103 typedef int (*event_handler_t)(void *ctx, struct event *event);
106 * struct evspy_info - information about an event spy
108 * @func: Function to call when the event is activated (must be first)
110 * @id: Event id string
113 event_handler_t func;
115 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
120 /* Declare a new event spy */
121 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
122 #define _ESPY_REC(_type, _func) { _func, _type, #_func, }
124 #define _ESPY_REC(_type, _func) { _func, _type, }
127 static inline const char *event_spy_id(struct evspy_info *spy)
129 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
137 * It seems that LTO will drop list entries if it decides they are not used,
138 * although the conditions that cause this are unclear.
140 * The example found is the following:
142 * static int sandbox_misc_init_f(void *ctx, struct event *event)
144 * return sandbox_early_getopt_check();
146 * EVENT_SPY(EVT_MISC_INIT_F, sandbox_misc_init_f);
148 * where EVENT_SPY uses ll_entry_declare()
150 * In this case, LTO decides to drop the sandbox_misc_init_f() function
151 * (which is fine) but then drops the linker-list entry too. This means
152 * that the code no longer works, in this case sandbox no-longer checks its
153 * command-line arguments properly.
155 * Without LTO, the KEEP() command in the .lds file is enough to keep the
156 * entry around. But with LTO it seems that the entry has already been
157 * dropped before the link script is considered.
159 * The only solution I can think of is to mark linker-list entries as 'used'
160 * using an attribute. This should be safe, since we don't actually want to drop
161 * any of these. However this does slightly limit LTO's optimisation choices.
163 * Another issue has come up, only with clang: using 'static' makes it throw
164 * away the linker-list entry sometimes, e.g. with the EVT_FT_FIXUP entry in
165 * vbe_simple.c - so for now, make it global.
167 #define EVENT_SPY(_type, _func) \
168 __used ll_entry_declare(struct evspy_info, _type ## _3_ ## _func, \
169 evspy_info) = _ESPY_REC(_type, _func)
172 * event_register - register a new spy
175 * @type: Event type to subscribe to
176 * @func: Function to call when the event is sent
177 * @ctx: Context to pass to the function
178 * @return 0 if OK, -ve on error
180 int event_register(const char *id, enum event_t type, event_handler_t func,
183 /** event_show_spy_list( - Show a list of event spies */
184 void event_show_spy_list(void);
187 * event_manual_reloc() - Relocate event handler pointers
189 * Relocate event handler pointers for all static event spies. It is called
190 * during the generic board init sequence, after relocation.
194 int event_manual_reloc(void);
197 * event_notify() - notify spies about an event
199 * It is possible to pass in union event_data here but that may not be
200 * convenient if the data is elsewhere, or is one of the members of the union.
201 * So this uses a void * for @data, with a separate @size.
204 * @data: Event data to be sent (e.g. union_event_data)
205 * @size: Size of data in bytes
206 * @return 0 if OK, -ve on error
208 int event_notify(enum event_t type, void *data, int size);
210 #if CONFIG_IS_ENABLED(EVENT)
212 * event_notify_null() - notify spies about an event
214 * Data is NULL and the size is 0
217 * @return 0 if OK, -ve on error
219 int event_notify_null(enum event_t type);
221 static inline int event_notify_null(enum event_t type)
227 #if CONFIG_IS_ENABLED(EVENT_DYNAMIC)
229 * event_uninit() - Clean up dynamic events
231 * This removes all dynamic event handlers
233 int event_uninit(void);
236 * event_uninit() - Set up dynamic events
238 * Init a list of dynamic event handlers, so that these can be added as
241 int event_init(void);
243 static inline int event_uninit(void)
248 static inline int event_init(void)