git: bcb838d17a9b - stable/13 - riscv: Call identify_cpu() earlier for CPU 0

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 12 Jun 2023 13:50:18 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=bcb838d17a9bfdb156791ce30c64c1b18da188ef

commit bcb838d17a9bfdb156791ce30c64c1b18da188ef
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-05-22 23:50:09 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-06-12 13:49:54 +0000

    riscv: Call identify_cpu() earlier for CPU 0
    
    It is advantageous to have knowledge of ISA features as early as
    possible. For example, the presence of newer virtual memory extensions
    may be useful to pmap_bootstrap().
    
    To achieve this, split out the printf() parts of identify_cpu() into a
    separate function, printcpuinfo(). This latter function will be called
    later in boot after the console has been initialized.
    
    Reviewed by:    markj
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D39810
    
    (cherry picked from commit b0d45b023e8c9af50312c7b56c4be9c39657afcb)
---
 sys/riscv/include/cpu.h      |  1 +
 sys/riscv/riscv/identcpu.c   | 10 ++++++++--
 sys/riscv/riscv/machdep.c    |  7 ++++++-
 sys/riscv/riscv/mp_machdep.c |  1 +
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/sys/riscv/include/cpu.h b/sys/riscv/include/cpu.h
index b33e34d350fb..64e93e984a9b 100644
--- a/sys/riscv/include/cpu.h
+++ b/sys/riscv/include/cpu.h
@@ -90,6 +90,7 @@ void	cpu_halt(void) __dead2;
 void	cpu_reset(void) __dead2;
 void	fork_trampoline(void);
 void	identify_cpu(void);
+void	printcpuinfo(void);
 
 static __inline uint64_t
 get_cyclecount(void)
diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c
index 5ffa038513ae..eedddb266fe7 100644
--- a/sys/riscv/riscv/identcpu.c
+++ b/sys/riscv/riscv/identcpu.c
@@ -367,6 +367,14 @@ identify_cpu_ids(struct cpu_desc *desc)
 
 void
 identify_cpu(void)
+{
+	struct cpu_desc *desc = &cpu_desc[PCPU_GET(cpuid)];
+
+	identify_cpu_ids(desc);
+}
+
+void
+printcpuinfo(void)
 {
 	struct cpu_desc *desc;
 	u_int cpu, hart;
@@ -375,8 +383,6 @@ identify_cpu(void)
 	hart = PCPU_GET(hart);
 	desc = &cpu_desc[cpu];
 
-	identify_cpu_ids(desc);
-
 	/* Print details for boot CPU or if we want verbose output */
 	if (cpu == 0 || bootverbose) {
 		/* Summary line. */
diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c
index 6a910ad6dc1e..d9883e23ce90 100644
--- a/sys/riscv/riscv/machdep.c
+++ b/sys/riscv/riscv/machdep.c
@@ -131,7 +131,7 @@ cpu_startup(void *dummy)
 {
 
 	sbi_print_version();
-	identify_cpu();
+	printcpuinfo();
 
 	printf("real memory  = %ju (%ju MB)\n", ptoa((uintmax_t)realmem),
 	    ptoa((uintmax_t)realmem) / (1024 * 1024));
@@ -539,6 +539,11 @@ initriscv(struct riscv_bootparams *rvbp)
 	physmem_hardware_regions(mem_regions, mem_regions_sz);
 #endif
 
+	/*
+	 * Identify CPU/ISA features.
+	 */
+	identify_cpu();
+
 	/* Do basic tuning, hz etc */
 	init_param1();
 
diff --git a/sys/riscv/riscv/mp_machdep.c b/sys/riscv/riscv/mp_machdep.c
index 3fb86c5f4c28..dffadd628c46 100644
--- a/sys/riscv/riscv/mp_machdep.c
+++ b/sys/riscv/riscv/mp_machdep.c
@@ -256,6 +256,7 @@ init_secondary(uint64_t hart)
 	 * runtime chip identification.
 	 */
 	identify_cpu();
+	printcpuinfo();
 
 	/* Enable software interrupts */
 	riscv_unmask_ipi();