Skip to contentSkip to conversation

event: remove CONFIG_EVENT_DYNAMIC check in event_register()

PATCH In review Ovidiu Panait 2 participants 4 messages May 15, 2022 – Jun 7, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 event: remove CONFIG_EVENT_DYNAMIC check in event_register()

The whole event_register() function is wrapped in EVENT_DYNAMIC #ifdef checks, so the inner check is not needed:

#if CONFIG_IS_ENABLED(EVENT_DYNAMIC)
...
int event_register(...)

 {
     ...
     if (!CONFIG_IS_ENABLED(EVENT_DYNAMIC))
         return -ENOSYS;

}
#endif

---

 common/event.c | 2 --
 1 file changed, 2 deletions(-)
common/event.c +0 -2
index 9d67a060a0..063647447d 100644
@@ -159,8 +159,6 @@ int event_register(const char *id, enum event_t type, event_handler_t func, void
 	struct event_state *state = gd_event_state();
 	struct event_spy *spy;
 
-	if (!CONFIG_IS_ENABLED(EVENT_DYNAMIC))
-		return -ENOSYS;
 	spy = malloc(sizeof(*spy));
 	if (!spy)
 		return log_msg_ret("alloc", -ENOMEM);
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 event: fix static events for CONFIG_NEEDS_MANUAL_RELOC

Static events do not currently work post-relocation for boards that enable CONFIG_NEEDS_MANUAL_RELOC. Relocate event handler pointers for all event spies to fix this.

Tested on Microblaze.

---

 common/board_r.c |  3 +++
 common/event.c   | 15 +++++++++++++++
 include/event.h  | 10 ++++++++++
 3 files changed, 28 insertions(+)
common/board_r.c +3 -0
index 6f4aca2077..01a1728c3f 100644
@@ -612,6 +612,9 @@ static init_fnc_t init_sequence_r[] = {
 	 */
 #endif
 	initr_reloc_global_data,
+#if CONFIG_IS_ENABLED(NEEDS_MANUAL_RELOC) && CONFIG_IS_ENABLED(EVENT)
+	event_manual_reloc,
+#endif
 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
 	initr_unlock_ram_in_cache,
 #endif
common/event.c +15 -0
index 063647447d..af1ed4121d 100644
@@ -17,6 +17,7 @@
 #include <malloc.h>
 #include <asm/global_data.h>
 #include <linux/list.h>
+#include <relocate.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -148,6 +149,20 @@ void event_show_spy_list(void)
 	}
 }
 
+#if CONFIG_IS_ENABLED(NEEDS_MANUAL_RELOC)
+int event_manual_reloc(void)
+{
+	struct evspy_info *spy, *end;
+
+	spy = ll_entry_start(struct evspy_info, evspy_info);
+	end = ll_entry_end(struct evspy_info, evspy_info);
+	for (; spy < end; spy++)
+		MANUAL_RELOC(spy->func);
+
+	return 0;
+}
+#endif
+
 #if CONFIG_IS_ENABLED(EVENT_DYNAMIC)
 static void spy_free(struct event_spy *spy)
 {
include/event.h +10 -0
index 62e72a7bd3..a8f0c3fa2b 100644
@@ -144,6 +144,16 @@ int event_register(const char *id, enum event_t type, event_handler_t func,
 /** 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);
+
 #if CONFIG_IS_ENABLED(EVENT)
 /**
  * event_notify() - notify spies about an event
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 2/2] event: fix static events for CONFIG_NEEDS_MANUAL_RELOC

Quoted 7 lines · Ovidiu Panait

Static events do not currently work post-relocation for boards that enable CONFIG_NEEDS_MANUAL_RELOC. Relocate event handler pointers for all event spies to fix this.

Tested on Microblaze.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#3 lore raw
In reply to Ovidiu Panait
Quoted 6 lines · Ovidiu Panait

The whole event_register() function is wrapped in EVENT_DYNAMIC #ifdef checks, so the inner check is not needed:

#if CONFIG_IS_ENABLED(EVENT_DYNAMIC)
...
int event_register(...)

Quoted 8 lines
 {
     ...
     if (!CONFIG_IS_ENABLED(EVENT_DYNAMIC))
         return -ENOSYS;

}
#endif

Applied to u-boot/next, thanks!

Signature · 1 line
Tom