arch: riscv: cpu: Add callback to init each core
Subsystems (2)
RFC PATCH 1/1 arch: riscv: cpu: Add callback to init each core
I am looking for a proper place to add some M-mode code in SPL to configure features of each core as early as possible. Try to start the discussion by sending this RFC.
I tried mach_cpu_init() as the start. And not sure whether I used it correctly, it seems executed only by the core wins lottery in ./arch/riscv/cpu/start.S.
Is there a proper place to add some inits for each core like CSR in section 7.6 in document of U74-MC Core Complex Manual[1].
There are some alternatives to do it such as
a) sending IPI to each cores
Have to wait for IPI init for each core. And the boot core have to perform the init by itself and send IPIs to other cores. It might not be straightforward.
b) hook callback, (like this patch)
c) hard code in ./arch/riscv/cpu/start.c
--- arch/riscv/cpu/start.S | 5 +++++ arch/riscv/lib/spl.c | 4 ++++ board/sifive/unmatched/spl.c | 7 +++++++ 3 files changed, 16 insertions(+)
arch/riscv/cpu/start.S +5 -0
@@ -102,6 +102,11 @@ call_board_init_f_0: mv a0, sp jal board_init_f_alloc_reserve +#if CONFIG_IS_ENABLED(RISCV_MMODE) +call_each_cpu_core: + jal mach_cpu_core_init +#endif + /* * Save global data pointer for later. We don't set it here because it * is not initialized yet.
arch/riscv/lib/spl.c +4 -0
@@ -14,6 +14,10 @@DECLARE_GLOBAL_DATA_PTR ; +__weak void mach_cpu_core_init (void ) +{ +} +__weak int spl_board_init_f (void ) {return 0 ;
board/sifive/unmatched/spl.c +7 -0
@@ -22,6 +22,13 @@#define MODE_SELECT_SD 0xb#define MODE_SELECT_MASK GENMASK(3, 0) +void mach_cpu_core_init (void ) +{ +#if CONFIG_IS_ENABLED (RISCV_MMODE ) + asmvolatile ("csrwi 0x7c1, 0" ); +#endif +} +int spl_board_init_f (void ) {int ret;
Signature · 1 line
2.31.0
RFC PATCH 1/1 arch: riscv: cpu: Add callback to init each core
Quoted 35 lines · Green Wan
I am looking for a proper place to add some M-mode code in SPL to configure features of each core as early as possible. Try to start the discussion by sending this RFC.
I tried
mach_cpu_init()as the start. And not sure whether I used it correctly, it seems executed only by the core wins lottery in./arch/riscv/cpu/start.S.Is there a proper place to add some inits for each core like CSR in section 7.6 in document of U74-MC Core Complex Manual[1].
There are some alternatives to do it such as
a) sending IPI to each cores
Have to wait for IPI init for each core. And the boot core have to perform the init by itself and send IPIs to other cores. It might not be straightforward.
b) hook callback, (like this patch)
c) hard code in./arch/riscv/cpu/start.cSigned-off-by Green Wan <[email protected]>--- arch/riscv/cpu/start.S | 5 +++++ arch/riscv/lib/spl.c | 4 ++++ board/sifive/unmatched/spl.c | 7 +++++++ 3 files changed, 16 insertions(+)arch/riscv/cpu/start.S +0
-0
arch/riscv/cpu/start.S call_board_init_f_0: · line 108
Quoted 7 lines
arch/riscv/cpu/start.S +4
-0@@ -102,6 +102,11 @@ call_board_init_f_0: mv a0, sp jal board_init_f_alloc_reserve +#if CONFIG_IS_ENABLED(RISCV_MMODE) +call_each_cpu_core: + jal mach_cpu_core_init +#endif
Inserting it here potentially corrupts the return value of board_init_f_alloc_reserve(), and you need to insert it after sp is initialized for harts other than the boot hart.
Quoted 28 lines
arch/riscv/cpu/start.S +1
-0+ /* * Save global data pointer for later. We don't set it here because it * is not initialized yet.arch/riscv/lib/spl.c +4
-0@@ -14,6 +14,10 @@DECLARE_GLOBAL_DATA_PTR ; +__weak void mach_cpu_core_init (void ) +{ +} +__weak int spl_board_init_f (void ) {return 0 ;board/sifive/unmatched/spl.c +1
-0@@ -22,6 +22,13 @@#define MODE_SELECT_SD 0xb#define MODE_SELECT_MASK GENMASK(3, 0) +void mach_cpu_core_init (void )
board/sifive/unmatched/spl.c
Quoted 10 lines
board/sifive/unmatched/spl.c +6
-1+{ +#if CONFIG_IS_ENABLED (RISCV_MMODE ) + asmvolatile ("csrwi 0x7c1, 0" ); +#endif +} +int spl_board_init_f (void ) {int ret; --
Regards,
Bin
RFC PATCH 1/1 arch: riscv: cpu: Add callback to init each core
Hi Bin,
I can move it to the place right after stacks for harts are set up and right before picking up the lottery hart. (like below) How about the function name? Do we come up with a better function name? mach_cpu_core_init() is similar to mach_cpu_init() in include/init.h. It could cause confusion.
116 /* setup stack */
117 #if CONFIG_IS_ENABLED(SMP)
118 /* tp: hart id */ 119 slli t0, tp, CONFIG_STACK_SIZE_SHIFT 120 sub sp, a0, t0
121 #else
122 mv sp, a0
123 #endif
124
move it here
125 #ifndef CONFIG_XIP
126 /*
127 * Pick hart to initialize global data and run U-Boot. The
other harts
128 * wait for initialization to complete.
129 */
130 la t0, hart_lottery 131 li t1, 1
Quoted 92 lines · Bin Meng
Quoted 14 lines · Green Wan
I am looking for a proper place to add some M-mode code in SPL to configure features of each core as early as possible. Try to start the discussion by sending this RFC.
I tried
mach_cpu_init()as the start. And not sure whether I used it correctly, it seems executed only by the core wins lottery in./arch/riscv/cpu/start.S.Is there a proper place to add some inits for each core like CSR in section 7.6 in document of U74-MC Core Complex Manual[1].
There are some alternatives to do it such as
Quoted 8 lines
a) sending IPI to each cores
Have to wait for IPI init for each core. And the boot core have to perform the init by itself and send IPIs to other cores. It might not be straightforward.
b) hook callback, (like this patch)
c) hard code in./arch/riscv/cpu/start.c[1]
Quoted 13 lines
Signed-off-by Green Wan <[email protected]>--- arch/riscv/cpu/start.S | 5 +++++ arch/riscv/lib/spl.c | 4 ++++ board/sifive/unmatched/spl.c | 7 +++++++ 3 files changed, 16 insertions(+)arch/riscv/cpu/start.S +0
-0arch/riscv/cpu/start.S call_board_init_f_0: · line 108
Quoted 7 lines
arch/riscv/cpu/start.S +4
-0@@ -102,6 +102,11 @@ call_board_init_f_0: mv a0, sp jal board_init_f_alloc_reserve +#if CONFIG_IS_ENABLED(RISCV_MMODE) +call_each_cpu_core: + jal mach_cpu_core_init +#endifInserting it here potentially corrupts the return value of
board_init_f_alloc_reserve(), and you need to insert it after sp is initialized for harts other than the boot hart.arch/riscv/cpu/start.S call_board_init_f_0:
Quoted 3 lines
arch/riscv/cpu/start.S +1
-0+ /* * Save global data pointer for later. We don't set it herebecause it
Quoted 25 lines
arch/riscv/cpu/start.S +0
-0* is not initialized yet.arch/riscv/lib/spl.c +4
-0@@ -14,6 +14,10 @@DECLARE_GLOBAL_DATA_PTR ; +__weak void mach_cpu_core_init (void ) +{ +} +__weak int spl_board_init_f (void ) {return 0 ;board/sifive/unmatched/spl.c +1
-0@@ -22,6 +22,13 @@#define MODE_SELECT_SD 0xb#define MODE_SELECT_MASK GENMASK(3, 0) +void mach_cpu_core_init (void )board/sifive/unmatched/spl.c
Quoted 10 lines
board/sifive/unmatched/spl.c +6
-1+{ +#if CONFIG_IS_ENABLED (RISCV_MMODE ) + asmvolatile ("csrwi 0x7c1, 0" ); +#endif +} +int spl_board_init_f (void ) {int ret; --Regards,
Bin
RFC PATCH 1/1 arch: riscv: cpu: Add callback to init each core
Hi Green,
Quoted 4 lines · Green Wan
Hi Bin,
I can move it to the place right after stacks for harts are set up and right before picking up the lottery hart. (like below) How about the function name? Do we come up with a better function name?
mach_cpu_core_init()is similar tomach_cpu_init()ininclude/init.h. It could cause confusion.
How about riscv_core_early_init(), or riscv_hart_early_init()?
Regards,
Bin
RFC PATCH 1/1 arch: riscv: cpu: Add callback to init each core
Quoted 6 lines · Bin Meng
Hi Green,
Quoted 3 lines · Green Wan
Hi Bin,
Quoted 8 lines
Quoted 1 line
I can move it to the place right after stacks for harts are set up and
right before picking up the lottery hart. (like below) How about the function name? Do we come up with a better function name?
mach_cpu_core_init()is similar tomach_cpu_init()ininclude/init.h. It could cause confusion.How about
riscv_core_early_init(), orriscv_hart_early_init()?
I'll vote for riscv_hart_early_init() and create the v2 patch based on it.
Thanks,
Quoted 3 lines
Regards,
Bin