From e7f59dea880ea25078273473c575794dac08dca2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:49 -0600 Subject: Revert "initcall: Move to inline function" Somehow I do not see any inlining with initcalls now. I was sure I saw it when this commit went in, but now it seems to make things worse. This reverts commit 47870afab92fca6e672c03d0dea802a55e200675. Signed-off-by: Simon Glass --- lib/initcall.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/initcall.c (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c new file mode 100644 index 00000000000..eedb0fbf1d5 --- /dev/null +++ b/lib/initcall.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2013 The Chromium OS Authors. + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* + * To enable debugging. add #define DEBUG at the top of the including file. + * + * To find a symbol, use grep on u-boot.map + */ +int initcall_run_list(const init_fnc_t init_sequence[]) +{ + const init_fnc_t *init_fnc_ptr; + + for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { + unsigned long reloc_ofs = 0; + int ret; + + /* + * Sandbox is relocated by the OS, so symbols always appear at + * the relocated address. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) + reloc_ofs = gd->reloc_off; +#ifdef CONFIG_EFI_APP + reloc_ofs = (unsigned long)image_base; +#endif + if (reloc_ofs) + debug("initcall: %p (relocated to %p)\n", + (char *)*init_fnc_ptr - reloc_ofs, + (char *)*init_fnc_ptr); + else + debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs); + + ret = (*init_fnc_ptr)(); + if (ret) { + printf("initcall sequence %p failed at call %p (err=%d)\n", + init_sequence, + (char *)*init_fnc_ptr - reloc_ofs, ret); + return -1; + } + } + return 0; +} -- cgit v1.2.3 From 7d2e23394ffbbc1d5b5f2479e0c52db52907cc40 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:50 -0600 Subject: initcall: Factor out reloc_off calculation Move this into a function and do it once, not each time around the loop. Signed-off-by: Simon Glass --- lib/initcall.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c index eedb0fbf1d5..89a68b2444f 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -11,6 +11,20 @@ DECLARE_GLOBAL_DATA_PTR; +static ulong calc_reloc_ofs(void) +{ +#ifdef CONFIG_EFI_APP + return (ulong)image_base; +#endif + /* + * Sandbox is relocated by the OS, so symbols always appear at + * the relocated address. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) + return gd->reloc_off; + + return 0; +} /* * To enable debugging. add #define DEBUG at the top of the including file. * @@ -18,21 +32,12 @@ DECLARE_GLOBAL_DATA_PTR; */ int initcall_run_list(const init_fnc_t init_sequence[]) { + ulong reloc_ofs = calc_reloc_ofs(); const init_fnc_t *init_fnc_ptr; for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - unsigned long reloc_ofs = 0; int ret; - /* - * Sandbox is relocated by the OS, so symbols always appear at - * the relocated address. - */ - if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) - reloc_ofs = gd->reloc_off; -#ifdef CONFIG_EFI_APP - reloc_ofs = (unsigned long)image_base; -#endif if (reloc_ofs) debug("initcall: %p (relocated to %p)\n", (char *)*init_fnc_ptr - reloc_ofs, -- cgit v1.2.3 From 468e372e9ad4c551d513b2e73c1f5c1cbb2e4097 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:51 -0600 Subject: initcall: Adjust the loop logic Use a variable to hold the function, so we don't need to repeat the pointer access each time. Rename the init pointer to 'ptr' since we only refer to it in the for() statement now. Signed-off-by: Simon Glass --- lib/initcall.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c index 89a68b2444f..81c5d245073 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -33,25 +33,25 @@ static ulong calc_reloc_ofs(void) int initcall_run_list(const init_fnc_t init_sequence[]) { ulong reloc_ofs = calc_reloc_ofs(); - const init_fnc_t *init_fnc_ptr; + const init_fnc_t *ptr; + init_fnc_t func; + int ret = 0; - for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - int ret; - - if (reloc_ofs) + for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) { + if (reloc_ofs) { debug("initcall: %p (relocated to %p)\n", - (char *)*init_fnc_ptr - reloc_ofs, - (char *)*init_fnc_ptr); - else - debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs); + (char *)func - reloc_ofs, func); + } else { + debug("initcall: %p\n", (char *)func - reloc_ofs); + } - ret = (*init_fnc_ptr)(); + ret = func(); if (ret) { printf("initcall sequence %p failed at call %p (err=%d)\n", - init_sequence, - (char *)*init_fnc_ptr - reloc_ofs, ret); + init_sequence, (char *)func - reloc_ofs, ret); return -1; } } + return 0; } -- cgit v1.2.3 From 13123276806f5a2e209bd1ae16c894e0415e520d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:52 -0600 Subject: initcall: Adjust the failure message and return value Move the failure message outside the loop, so it is easier to follow the code. Avoid swallowing the error code - just pass it along. Drop the initcall-list address from the output. This is confusing since we show two addresses. Really it is only the function address which is useful, since it can be looked up in the map, e.g. with: grep -A1 -B1 serial_init u-boot.map Signed-off-by: Simon Glass --- lib/initcall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c index 81c5d245073..0f74cef32f8 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -46,11 +46,13 @@ int initcall_run_list(const init_fnc_t init_sequence[]) } ret = func(); - if (ret) { - printf("initcall sequence %p failed at call %p (err=%d)\n", - init_sequence, (char *)func - reloc_ofs, ret); - return -1; - } + } + + if (ret) { + printf("initcall failed at call %p (err=%dE)\n", + (char *)func - reloc_ofs, ret); + + return ret; } return 0; -- cgit v1.2.3 From c9eff0a6b6ea2bcd54d30f8a02281681f3730223 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:54 -0600 Subject: initcall: Support emitting events At present the initcall list consists of a list of function pointers. Over time the initcall lists will likely change to mostly emitting events, since most of the calls are board- or arch-specific. As a first step, allow an initcall to be an event type instead of a function pointer. Add the required macro and update initcall_run_list() to emit an event in that case, or ignore it if events are not enabled. The bottom 8 bits of the function pointer are used to hold the event type, with the rest being all ones. This should avoid any collision, since initcalls should not be above 0xffffff00 in memory. Convert misc_init_f over to use this mechanism. Add comments to the initcall header file while we are here. Also fix up the trace test to handle the change. Signed-off-by: Simon Glass --- lib/initcall.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c index 0f74cef32f8..33b7d761dc7 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -7,6 +7,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -25,6 +26,23 @@ static ulong calc_reloc_ofs(void) return 0; } + +/** + * initcall_is_event() - Get the event number for an initcall + * + * func: Function pointer to check + * Return: Event number, if this is an event, else 0 + */ +static int initcall_is_event(init_fnc_t func) +{ + ulong val = (ulong)func; + + if ((val & INITCALL_IS_EVENT) == INITCALL_IS_EVENT) + return val & INITCALL_EVENT_TYPE; + + return 0; +} + /* * To enable debugging. add #define DEBUG at the top of the including file. * @@ -34,23 +52,45 @@ int initcall_run_list(const init_fnc_t init_sequence[]) { ulong reloc_ofs = calc_reloc_ofs(); const init_fnc_t *ptr; + enum event_t type; init_fnc_t func; int ret = 0; for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) { - if (reloc_ofs) { + type = initcall_is_event(func); + + if (type) { + if (!CONFIG_IS_ENABLED(EVENT)) + continue; + debug("initcall: event %d/%s\n", type, + event_type_name(type)); + } else if (reloc_ofs) { debug("initcall: %p (relocated to %p)\n", - (char *)func - reloc_ofs, func); + (char *)func - reloc_ofs, (char *)func); } else { debug("initcall: %p\n", (char *)func - reloc_ofs); } - ret = func(); + ret = type ? event_notify_null(type) : func(); } if (ret) { - printf("initcall failed at call %p (err=%dE)\n", - (char *)func - reloc_ofs, ret); + if (CONFIG_IS_ENABLED(EVENT)) { + char buf[60]; + + /* don't worry about buf size as we are dying here */ + if (type) { + sprintf(buf, "event %d/%s", type, + event_type_name(type)); + } else { + sprintf(buf, "call %p", func); + } + + printf("initcall failed at %s (err=%dE)\n", buf, ret); + } else { + printf("initcall failed at call %p (err=%d)\n", + (char *)func - reloc_ofs, ret); + } return ret; } -- cgit v1.2.3 From dd802467f44b68d6ed9315ffe3002b17dc43b622 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:55 -0600 Subject: initcall: Support manual relocation Move the manual-relocation code to the initcall file. Make sure to avoid manually relocating event types. Only true function pointers should be relocated. Signed-off-by: Simon Glass --- lib/initcall.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c index 33b7d761dc7..480490ea239 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -97,3 +97,13 @@ int initcall_run_list(const init_fnc_t init_sequence[]) return 0; } + +void initcall_manual_reloc(init_fnc_t init_sequence[]) +{ + init_fnc_t *ptr; + + for (ptr = init_sequence; *ptr; ptr++) { + if (!initcall_is_event(*ptr)) + MANUAL_RELOC(*ptr); + } +} -- cgit v1.2.3 From 49c59dd5ca3078a135f85bcd1cb00e57029a1cde Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 6 Sep 2023 23:29:44 +0200 Subject: common: board_r: Remove unused NEEDS_MANUAL_RELOC code bits The last user of the NEEDS_MANUAL_RELOC has been removed in commit 26af162ac8f8 ("arch: m68k: Implement relocation") Remove now unused NEEDS_MANUAL_RELOC code. Signed-off-by: Marek Vasut --- lib/initcall.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'lib/initcall.c') diff --git a/lib/initcall.c b/lib/initcall.c index 480490ea239..33b7d761dc7 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -97,13 +97,3 @@ int initcall_run_list(const init_fnc_t init_sequence[]) return 0; } - -void initcall_manual_reloc(init_fnc_t init_sequence[]) -{ - init_fnc_t *ptr; - - for (ptr = init_sequence; *ptr; ptr++) { - if (!initcall_is_event(*ptr)) - MANUAL_RELOC(*ptr); - } -} -- cgit v1.2.3