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

Signed-off-by: Bin Meng <bmeng...@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

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to