Skip to contentSkip to conversation

lib: sbi: Introduce early hart initialization scheme

PATCH New Leo Yu-Chi Liang 2 participants 2 messages Sep 23, 2021 – Sep 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib: sbi: Introduce early hart initialization scheme

Referencing U-Boot (edd9ad81 riscv: cpu: Add callback to init each core) Introduce a callback function for each hart to do its own initialization as early as possible.

---
 firmware/fw_base.S | 6 ++++++
 lib/sbi/sbi_init.c | 4 ++++
 2 files changed, 10 insertions(+)
firmware/fw_base.S +6 -0
index 1569e60..dfbe7d7 100644
@@ -47,6 +47,12 @@
 	.globl _start
 	.globl _start_warm
 _start:
+	/* Setup temporary stack */
+	lla	s4, _fw_end
+	li	s5, (SBI_SCRATCH_SIZE * 2)
+	add	sp, s4, s5
+	/* call harts_early_init */
+	call harts_early_init
 	/* Find preferred boot HART id */
 	MOV_3R	s0, a0, s1, a1, s2, a2
 	call	fw_boot_hart
lib/sbi/sbi_init.c +4 -0
index 6ef8742..02acac0 100644
@@ -536,3 +536,7 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)
 
 	sbi_hsm_exit(scratch);
 }
+
+__attribute__((weak)) void harts_early_init(void)
+{
+}
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/2 lib: sbi: Introduce early hart initialization scheme

? 2021-09-23???? 10:28 +0800?Leo Yu-Chi Liang???

Quoted 18 lines

Referencing U-Boot (edd9ad81 riscv: cpu: Add callback to init each core)
Introduce a callback function for each hart to do its own initialization
as early as possible.

---
?firmware/fw_base.S | 6 ++++++
?lib/sbi/sbi_init.c | 4 ++++
?2 files changed, 10 insertions(+)

firmware/fw_base.S +0 -0
index 1569e60..dfbe7d7 100644
@@ -47,6 +47,12 @@

????????.globl _start

Quoted 8 lines

????????.globl _start_warm
?_start:
+???????/* Setup temporary stack */
+???????lla?????s4, _fw_end
+???????li??????s5, (SBI_SCRATCH_SIZE * 2)
+???????add?????sp, s4, s5
+???????/* call harts_early_init */
+???????call harts_early_init

This will destroy the parameters (a0/a1/a2) that the firmware passed to opensbi in the previous stage. And here, the stack pointers of multiple cores are set to the same memory address, which may cause memory conflicts.

Regards,
Xiang W

Quoted 20 lines

????????/* Find preferred boot HART id */
????????MOV_3R??s0, a0, s1, a1, s2, a2
????????call????fw_boot_hart

lib/sbi/sbi_init.c +0 -0
index 6ef8742..02acac0 100644
@@ -536,3 +536,7 @@ void __noreturn sbi_exit(struct sbi_scratch
 *scratch)

?
????????sbi_hsm_exit(scratch);
?}

lib/sbi/sbi_init.c +4 -0
+
+__attribute__((weak)) void harts_early_init(void)
+{
+}
Signature · 1 line
2.17.0