Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Dec 2013 12:29:35 +0000 (UTC)
From:      Andreas Tobler <andreast@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r259256 - stable/10/sys/powerpc/powerpc
Message-ID:  <201312121229.rBCCTZSY094367@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andreast
Date: Thu Dec 12 12:29:35 2013
New Revision: 259256
URL: http://svnweb.freebsd.org/changeset/base/259256

Log:
  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.

Modified:
  stable/10/sys/powerpc/powerpc/cpu.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/powerpc/powerpc/cpu.c
==============================================================================
--- stable/10/sys/powerpc/powerpc/cpu.c	Thu Dec 12 12:17:20 2013	(r259255)
+++ stable/10/sys/powerpc/powerpc/cpu.c	Thu Dec 12 12:29:35 2013	(r259256)
@@ -74,6 +74,8 @@
 #include <machine/smp.h>
 #include <machine/spr.h>
 
+#include <dev/ofw/openfirm.h>
+
 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 *
 {
 	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 *
 
 			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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312121229.rBCCTZSY094367>