Prepare v2023.10
[platform/kernel/u-boot.git] / include / event.h
index 78a4237..f5c5d30 100644 (file)
 #ifndef __event_h
 #define __event_h
 
+#include <dm/ofnode_decl.h>
+#include <linux/types.h>
+
 /**
  * enum event_t - Types of events supported by U-Boot
  *
  * @EVT_DM_PRE_PROBE: Device is about to be probed
  */
 enum event_t {
-       EVT_NONE,
+       /**
+        * @EVT_NONE: This zero value is not used for events.
+        */
+       EVT_NONE = 0,
+
+       /**
+        * @EVT_TEST: This event is used in unit tests.
+        */
        EVT_TEST,
 
-       /* Events related to driver model */
-       EVT_DM_POST_INIT,
+       /**
+        * @EVT_DM_POST_INIT_F:
+        * This event is triggered after pre-relocation initialization of the
+        * driver model. Its parameter is NULL.
+        * A non-zero return code from the event handler let's the boot process
+        * fail.
+        */
+       EVT_DM_POST_INIT_F,
+
+       /**
+        * @EVT_DM_POST_INIT_R:
+        * This event is triggered after post-relocation initialization of the
+        * driver model. Its parameter is NULL.
+        * A non-zero return code from the event handler let's the boot process
+        * fail.
+        */
+       EVT_DM_POST_INIT_R,
+
+       /**
+        * @EVT_DM_PRE_PROBE:
+        * This event is triggered before probing a device. Its parameter is the
+        * device to be probed.
+        * A non-zero return code from the event handler lets the device not
+        * being probed.
+        */
        EVT_DM_PRE_PROBE,
+
+       /**
+        * @EVT_DM_POST_PROBE:
+        * This event is triggered after probing a device. Its parameter is the
+        * device that was probed.
+        * A non-zero return code from the event handler leaves the device in
+        * the unprobed state and therefore not usable.
+        */
        EVT_DM_POST_PROBE,
+
+       /**
+        * @EVT_DM_PRE_REMOVE:
+        * This event is triggered after removing a device. Its parameter is
+        * the device to be removed.
+        * A non-zero return code from the event handler stops the removal of
+        * the device before any changes.
+        */
        EVT_DM_PRE_REMOVE,
+
+       /**
+        * @EVT_DM_POST_REMOVE:
+        * This event is triggered before removing a device. Its parameter is
+        * the device that was removed.
+        * A non-zero return code stops from the event handler the removal of
+        * the device after all removal changes. The previous state is not
+        * restored. All children will be gone and the device may not be
+        * functional.
+        */
        EVT_DM_POST_REMOVE,
 
-       /* Init hooks */
+       /**
+        * @EVT_MISC_INIT_F:
+        * This event is triggered during the initialization sequence before
+        * relocation. Its parameter is NULL.
+        * A non-zero return code from the event handler let's the boot process
+        * fail.
+        */
        EVT_MISC_INIT_F,
 
+       /**
+        * @EVT_FPGA_LOAD:
+        * The FPGA load hook is called after loading an FPGA with a new binary.
+        * Its parameter is of type struct event_fpga_load and contains
+        * information about the loaded image.
+        */
+       EVT_FPGA_LOAD,
+
+       /**
+        * @EVT_FT_FIXUP:
+        * This event is triggered during device-tree fix up after all
+        * other device-tree fixups have been executed.
+        * Its parameter is of type struct event_ft_fixup which contains
+        * the address of the device-tree to fix up and the list of images to be
+        * booted.
+        * A non-zero return code from the event handler let's booting the
+        * images fail.
+        */
+       EVT_FT_FIXUP,
+
+       /**
+        * @EVT_MAIN_LOOP:
+        * This event is triggered immediately before calling main_loop() which
+        * is the entry point of the command line. Its parameter is NULL.
+        * A non-zero return value causes the boot to fail.
+        */
+       EVT_MAIN_LOOP,
+
+       /**
+        * @EVT_COUNT:
+        * This constants holds the maximum event number + 1 and is used when
+        * looping over all event classes.
+        */
        EVT_COUNT
 };
 
@@ -50,6 +148,30 @@ union event_data {
        struct event_dm {
                struct udevice *dev;
        } dm;
+
+       /**
+        * struct event_fpga_load - fpga load event
+        *
+        * @buf: The buffer that was loaded into the fpga
+        * @bsize: The size of the buffer that was loaded into the fpga
+        * @result: Result of the load operation
+        */
+       struct event_fpga_load {
+               const void *buf;
+               size_t bsize;
+               int result;
+       } fpga_load;
+
+       /**
+        * struct event_ft_fixup - FDT fixup before booting
+        *
+        * @tree: tree to update
+        * @images: images which are being booted
+        */
+       struct event_ft_fixup {
+               oftree tree;
+               struct bootm_headers *images;
+       } ft_fixup;
 };
 
 /**
@@ -123,11 +245,14 @@ static inline const char *event_spy_id(struct evspy_info *spy)
  * The only solution I can think of is to mark linker-list entries as 'used'
  * using an attribute. This should be safe, since we don't actually want to drop
  * any of these. However this does slightly limit LTO's optimisation choices.
+ *
+ * Another issue has come up, only with clang: using 'static' makes it throw
+ * away the linker-list entry sometimes, e.g. with the EVT_FT_FIXUP entry in
+ * vbe_simple.c - so for now, make it global.
  */
 #define EVENT_SPY(_type, _func) \
-       static __attribute__((used)) ll_entry_declare(struct evspy_info, \
-                                                     _type, evspy_info) = \
-       _ESPY_REC(_type, _func)
+       __used ll_entry_declare(struct evspy_info, _type ## _3_ ## _func, \
+               evspy_info) = _ESPY_REC(_type, _func)
 
 /**
  * event_register - register a new spy
@@ -141,7 +266,19 @@ static inline const char *event_spy_id(struct evspy_info *spy)
 int event_register(const char *id, enum event_t type, event_handler_t func,
                   void *ctx);
 
-#if CONFIG_IS_ENABLED(EVENT)
+/** event_show_spy_list( - Show a list of event spies */
+void event_show_spy_list(void);
+
+/**
+ * event_manual_reloc() - Relocate event handler pointers
+ *
+ * Relocate event handler pointers for all static event spies. It is called
+ * during the generic board init sequence, after relocation.
+ *
+ * Return: 0 if OK
+ */
+int event_manual_reloc(void);
+
 /**
  * event_notify() - notify spies about an event
  *
@@ -156,6 +293,7 @@ int event_register(const char *id, enum event_t type, event_handler_t func,
  */
 int event_notify(enum event_t type, void *data, int size);
 
+#if CONFIG_IS_ENABLED(EVENT)
 /**
  * event_notify_null() - notify spies about an event
  *
@@ -166,11 +304,6 @@ int event_notify(enum event_t type, void *data, int size);
  */
 int event_notify_null(enum event_t type);
 #else
-static inline int event_notify(enum event_t type, void *data, int size)
-{
-       return 0;
-}
-
 static inline int event_notify_null(enum event_t type)
 {
        return 0;