git: 24d048be7aae - main - powerpc/mpc85xx: Set pc_hwref to the primary thread ID

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Wed, 21 Jan 2026 04:37:45 UTC
The branch main has been updated by jhibbits:

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

commit 24d048be7aae10e101596bd0d0f09a901a6f97f0
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2026-01-21 04:16:17 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2026-01-21 04:28:40 +0000

    powerpc/mpc85xx: Set pc_hwref to the primary thread ID
    
    On multithreaded cores (e6500) the CPU ID in the device tree (reg[0]) is
    the primary core, which may not match the cpuid, until Book-E threading
    is added.
---
 sys/powerpc/mpc85xx/platform_mpc85xx.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/sys/powerpc/mpc85xx/platform_mpc85xx.c b/sys/powerpc/mpc85xx/platform_mpc85xx.c
index 6653c40b01a3..cc2ad829eb05 100644
--- a/sys/powerpc/mpc85xx/platform_mpc85xx.c
+++ b/sys/powerpc/mpc85xx/platform_mpc85xx.c
@@ -302,14 +302,26 @@ mpc85xx_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
 static int
 mpc85xx_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
 {
+	phandle_t node;
+	pcell_t reg;
+	int i;
 
 	if (cpu >= maxcpu)
 		return (ENOENT);
 
 	cpuref->cr_cpuid = cpu++;
-	cpuref->cr_hwref = cpuref->cr_cpuid;
+
+	node = OF_finddevice("/cpus");
+	for (i = 0, node = OF_child(node); i < cpuref->cr_cpuid;
+	    i++, node = OF_peer(node))
+		;
+	if (OF_getencprop(node, "reg", &reg, sizeof(reg)) > 0)
+		cpuref->cr_hwref = reg;
+	else
+		cpuref->cr_hwref = cpuref->cr_cpuid;
 	if (bootverbose)
-		printf("powerpc_smp_next_cpu: cpuid %d\n", cpuref->cr_cpuid);
+		printf("powerpc_smp_next_cpu: cpuid %d, hwref %d\n",
+		    cpuref->cr_cpuid, (int)cpuref->cr_hwref);
 
 	return (0);
 }