Change behaviour of CONFIG_TIMER_EARLY
cover Change behaviour of CONFIG_TIMER_EARLY
When CONFIG_TIMER_EARLY is selected and the timer driver implements timer_early_get_count() and timer_early_get_rate() this leads to an EAGAIN error one some configurations in...
common/board_f.c:initf_dm()
initf_dm() invokes dm_timer_init(), but this function returns with an EAGAIN error in, because the DM virtual root driver isn't initialized yet in...
drivers/timer/timer-class.c:dm_timer_init()
Moved error handling to...
lib/time.c
For details you can read the description in the patches.
Affected drivers:drivers/timer/andes_plmt_timer.cdrivers/timer/sifive_clint_timer.cdrivers/timer/riscv_timer.c
I don't know who maintains these base libraries and base functions, so I used the copyright holders. For the driver I added the required maintainers to CC.
---
Johannes Krottmayer (2):
lib: time: Change behaviour of CONFIG_TIMER_EARLY
common: board_f: Fix CONFIG_TIMER_EARLY issue (EAGAIN)
common/board_f.c | 6 ------ lib/time.c | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 lib: time: Change behaviour of CONFIG_TIMER_EARLY
If CONFIG_TIMER_EARLY is selected and the timer driver implements timer_early_get_count() and timer_early_get_rate(), check first if the virtual root driver is running, when it is initialized yet use the virtual timer driver instead. When the virtual root driver doesn't exists fallback to the timer_early_get_count() and timer_early_get_rate().
--- lib/time.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-)
lib/time.c +33 -9
@@ -8,6 +8,7 @@#include <clock_legacy.h> #include <bootstage.h> #include <dm.h> +#include <dm/root.h> #include <errno.h> #include <init.h> #include <spl.h>
@@ -66,16 +67,28 @@ extern unsigned long __weak timer_read_counter(void);#if CONFIG_IS_ENABLED (TIMER ) ulong notrace get_tbclk(void) { -if (!gd->timer) { +int ret; +#ifdef CONFIG_TIMER_EARLY + +/* +* Check if the virtual root driver does not yet exist, +* if not fallback to timer_early_get_rate(). +*/ +if (gd->dm_root ==NULL )return timer_early_get_rate (); -#else -int ret; +#endif /* CONFIG_TIMER_EARLY */ + +/* +* Check if the virtual timer driver does not yet exist, +* if not initialize the driver. +*/ +if (!gd->timer) { ret =dm_timer_init (); +if (ret) -return ret; -#endif +panic ("Could not initialize timer (err %d)\n" , ret); }return timer_get_rate (gd->timer);
@@ -86,19 +99,30 @@ uint64_t notrace get_ticks(void)u64 count;int ret; -if (!gd->timer) {#ifdef CONFIG_TIMER_EARLY + +/* +* Check if the virtual root driver does not yet exist, +* if not fallback to timer_early_get_rate(). +*/ +if (gd->dm_root ==NULL )return timer_early_get_count (); -#else -int ret; +#endif /* CONFIG_TIMER_EARLY */ + +/* +* Check if the virtual timer driver does not yet exist, +* if not initialize the driver. +*/ +if (!gd->timer) { ret =dm_timer_init (); +if (ret)panic ("Could not initialize timer (err %d)\n" , ret); -#endif } ret =timer_get_count (gd->timer, &count); +if (ret) {if (spl_phase () >PHASE_TPL ) panic("Could not read count from timer (err %d)\n",
Signature · 1 line
2.34.1
Re: [PATCH 1/2] lib: time: Change behaviour of CONFIG_TIMER_EARLY
Quoted 68 lines · Johannes Krottmayer
If
CONFIG_TIMER_EARLYis selected and the timer driver implementstimer_early_get_count()andtimer_early_get_rate(), check first if the virtual root driver is running, when it is initialized yet use the virtual timer driver instead. When the virtual root driver doesn't exists fallback to thetimer_early_get_count()andtimer_early_get_rate().Signed-off-by Johannes Krottmayer <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Thomas Chou <[email protected]>Cc Rick Chen <[email protected]>Cc Leo <[email protected]>Cc Bin Meng <[email protected]>Cc Sean Anderson <[email protected]>Cc Anup Patel <[email protected]>Cc Thomas Chou <[email protected]>--- lib/time.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-)lib/time.c +18
-5@@ -8,6 +8,7 @@#include <clock_legacy.h> #include <bootstage.h> #include <dm.h> +#include <dm/root.h> #include <errno.h> #include <init.h> #include <spl.h> @@ -66,16 +67,28 @@ extern unsigned long __weak timer_read_counter(void);#if CONFIG_IS_ENABLED (TIMER ) ulong notrace get_tbclk(void) { -if (!gd->timer) { +int ret; +#ifdef CONFIG_TIMER_EARLY + +/* +* Check if the virtual root driver does not yet exist, +* if not fallback to timer_early_get_rate(). +*/ +if (gd->dm_root ==NULL )return timer_early_get_rate (); -#else -int ret; +#endif /* CONFIG_TIMER_EARLY */ + +/* +* Check if the virtual timer driver does not yet exist, +* if not initialize the driver. +*/ +if (!gd->timer) { ret =dm_timer_init (); +if (ret) -return ret; -#endif +panic ("Could not initialize timer (err %d)\n" , ret); }return timer_get_rate (gd->timer);@@ -86,19 +99,30 @@ uint64_t notrace get_ticks(void)u64 count;
lib/time.c uint64_t notrace get_ticks(void) · line 108
Quoted 10 lines
lib/time.c +6
-1int ret; -if (!gd->timer) {#ifdef CONFIG_TIMER_EARLY + +/* +* Check if the virtual root driver does not yet exist, +* if not fallback to timer_early_get_rate(). +*/ +if (gd->dm_root ==NULL )
if (!gd->dm_root)
lib/time.c uint64_t notrace get_ticks(void) · line 119
Quoted 13 lines
lib/time.c +8
-2return timer_early_get_count (); -#else -int ret; +#endif /* CONFIG_TIMER_EARLY */ + +/* +* Check if the virtual timer driver does not yet exist, +* if not initialize the driver. +*/ +if (!gd->timer) { ret =dm_timer_init (); +
Please don't insert empty lines.
lib/time.c uint64_t notrace get_ticks(void) · line 125
Quoted 7 lines
lib/time.c +1
-1if (ret)panic ("Could not initialize timer (err %d)\n" , ret); -#endif } ret =timer_get_count (gd->timer, &count); +
ditto
lib/time.c uint64_t notrace get_ticks(void) · line 128
Quoted 4 lines
lib/time.c +0
-0if (ret) {if (spl_phase () >PHASE_TPL ) panic("Could not read count from timer (err %d)\n",
OK, so as I understand it, the current logic is something like
if (!gd->timer) {
if (CONFIG_TIMER_EARLY)
return early_timer();
else
init_dm_timer();
}
return dm_timer();and this patch would change it to be
if (CONFIG_TIMER_EARLY && !gd->dm_root) return early_timer(); if (!gd->timer) init_dm_timer(); return dm_timer();
which has the consequence (with your next patch) that timer initialization is always done by the first timer API call, and not by initf_dm. However, I'm not sure why you want to change this.
--Sean
PATCH 2/2 common: board_f: Fix CONFIG_TIMER_EARLY issue (EAGAIN)
In reply to Johannes KrottmayerWhen CONFIG_TIMER_EARLY is selected and the timer driver implements timer_early_get_count() and timer_early_get_rate() this leads to an EAGAIN error one some configurations in...
common/board_f.c:initf_dm()
initf_dm() invokes dm_timer_init(), but this function returns with an EAGAIN error in, because the DM virtual root driver isn't initialized yet in...
drivers/timer/timer-class.c:dm_timer_init()
[WORKAROUND]
Move error handling to (next patch in this serie)...
lib/time.c
--- common/board_f.c | 6 ------ 1 file changed, 6 deletions(-)
common/board_f.c +0 -6
@@ -785,12 +785,6 @@ static int initf_dm(void)bootstage_accum (BOOTSTAGE_ID_ACCUM_DM_F );if (ret)return ret; - -if (IS_ENABLED (CONFIG_TIMER_EARLY )) { - ret =dm_timer_init (); -if (ret) -return ret; - }#endif return 0 ;
Signature · 1 line
2.34.1