git: d0ede7bd59e5 - stable/13 - riscv: reject CPUs with mmu-type "riscv,none"

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 28 Oct 2022 14:10:53 UTC
The branch stable/13 has been updated by mhorne:

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

commit d0ede7bd59e5fa2222f80a17dd759eb50d38f6c1
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-10-20 14:57:43 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-28 14:10:37 +0000

    riscv: reject CPUs with mmu-type "riscv,none"
    
    According to riscv/cpus.yaml in the device-tree docs, this property may
    exist but indicate that the CPU does not have an MMU. Detect this
    possibility.
    
    Reviewed by:    jhb
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D36980
    
    (cherry picked from commit 330acb1883242b5362bb6ccf067de253d3549832)
---
 sys/riscv/riscv/mp_machdep.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/sys/riscv/riscv/mp_machdep.c b/sys/riscv/riscv/mp_machdep.c
index 418296deee15..3fb86c5f4c28 100644
--- a/sys/riscv/riscv/mp_machdep.c
+++ b/sys/riscv/riscv/mp_machdep.c
@@ -405,6 +405,20 @@ cpu_mp_probe(void)
 }
 
 #ifdef FDT
+static boolean_t
+cpu_check_mmu(u_int id __unused, phandle_t node, u_int addr_size __unused,
+    pcell_t *reg __unused)
+{
+	char type[32];
+
+	/* Check if this hart supports MMU. */
+	if (OF_getprop(node, "mmu-type", (void *)type, sizeof(type)) == -1 ||
+	    strncmp(type, "riscv,none", 10) == 0)
+		return (0);
+
+	return (1);
+}
+
 static boolean_t
 cpu_init_fdt(u_int id, phandle_t node, u_int addr_size, pcell_t *reg)
 {
@@ -415,8 +429,7 @@ cpu_init_fdt(u_int id, phandle_t node, u_int addr_size, pcell_t *reg)
 	int naps;
 	int error;
 
-	/* Check if this hart supports MMU. */
-	if (OF_getproplen(node, "mmu-type") < 0)
+	if (!cpu_check_mmu(id, node, addr_size, reg))
 		return (0);
 
 	KASSERT(id < MAXCPU, ("Too many CPUs"));
@@ -524,17 +537,6 @@ cpu_mp_announce(void)
 {
 }
 
-static boolean_t
-cpu_check_mmu(u_int id, phandle_t node, u_int addr_size, pcell_t *reg)
-{
-
-	/* Check if this hart supports MMU. */
-	if (OF_getproplen(node, "mmu-type") < 0)
-		return (0);
-
-	return (1);
-}
-
 void
 cpu_mp_setmaxid(void)
 {