[U-Boot] [PATCH v2 16/20] riscv: Do some basic architecture level cpu initialization

Bin Meng bmeng.cn at gmail.com
Fri Dec 7 14:14:28 UTC 2018


Implement arch_cpu_init() to do some basic architecture level cpu
initialization, like FPU enable, etc.

Signed-off-by: Bin Meng <bmeng.cn at gmail.com>

---

Changes in v2:
- use csr_set() to set MSTATUS_FS
- only enabling the cycle, time, and instret counters
- change to use satp

 arch/riscv/cpu/cpu.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
index 3858e51..194799c 100644
--- a/arch/riscv/cpu/cpu.c
+++ b/arch/riscv/cpu/cpu.c
@@ -7,6 +7,7 @@
 #include <cpu.h>
 #include <log.h>
 #include <asm/csr.h>
+#include <asm/encoding.h>
 
 /*
  * prior_stage_fdt_address must be stored in the data section since it is used
@@ -67,3 +68,21 @@ int arch_early_init_r(void)
 
 	return 0;
 }
+
+int arch_cpu_init(void)
+{
+	/* Enable FPU */
+	if (supports_extension('d') || supports_extension('f')) {
+		csr_set(MODE_PREFIX(status), MSTATUS_FS);
+		csr_write(fcsr, 0);
+	}
+
+	/* Enable perf counters for cycle, time, and instret counters only */
+	csr_write(MODE_PREFIX(counteren), GENMASK(2, 0));
+
+	/* Disable paging */
+	if (supports_extension('s'))
+		csr_write(satp, 0);
+
+	return 0;
+}
-- 
2.7.4



More information about the U-Boot mailing list