From 0eb0385d07fef454aca38f055501e1a1d0247594 Mon Sep 17 00:00:00 2001 From: andreast Date: Thu, 12 Dec 2013 12:29:35 +0000 Subject: [PATCH] MFC: r258722, r258757 r258722: Give some output about the CPU clock on IBMPOWER machines, currently read from OF. Linux does it similar, means they also read the OF values and display them. r258757: Use the Open Firmware-based CPU frequency determination as a generic fallback if we can't measure CPU frequency. This is also useful on a variety of embedded systems using FDT. git-svn-id: svn://svn.freebsd.org/base/stable/10@259256 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/powerpc/powerpc/cpu.c | 40 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/sys/powerpc/powerpc/cpu.c b/sys/powerpc/powerpc/cpu.c index d7f8e2d4d..99c8ca11d 100644 --- a/sys/powerpc/powerpc/cpu.c +++ b/sys/powerpc/powerpc/cpu.c @@ -74,6 +74,8 @@ #include #include +#include + static void cpu_6xx_setup(int cpuid, uint16_t vers); static void cpu_970_setup(int cpuid, uint16_t vers); static void cpu_booke_setup(int cpuid, uint16_t vers); @@ -273,6 +275,9 @@ cpu_est_clockrate(int cpu_id, uint64_t *cps) { uint16_t vers; register_t msr; + phandle_t cpu, dev, root; + int res = 0; + char buf[8]; vers = mfpvr() >> 16; msr = mfmsr(); @@ -316,9 +321,40 @@ cpu_est_clockrate(int cpu_id, uint64_t *cps) mtmsr(msr); return (0); + + default: + root = OF_peer(0); + if (root == 0) + return (ENXIO); + + dev = OF_child(root); + while (dev != 0) { + res = OF_getprop(dev, "name", buf, sizeof(buf)); + if (res > 0 && strcmp(buf, "cpus") == 0) + break; + dev = OF_peer(dev); + } + cpu = OF_child(dev); + while (cpu != 0) { + res = OF_getprop(cpu, "device_type", buf, + sizeof(buf)); + if (res > 0 && strcmp(buf, "cpu") == 0) + break; + cpu = OF_peer(cpu); + } + if (cpu == 0) + return (ENOENT); + if (OF_getprop(cpu, "ibm,extended-clock-frequency", + cps, sizeof(*cps)) >= 0) { + return (0); + } else if (OF_getprop(cpu, "clock-frequency", cps, + sizeof(cell_t)) >= 0) { + *cps >>= 32; + return (0); + } else { + return (ENOENT); + } } - - return (ENXIO); } void -- 2.45.0