summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2017-12-24 19:42:52 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2017-12-24 19:42:52 +0000
commit0a66ba9d82fc0d57d9a3ba69d17c65deb344ac73 (patch)
tree847f202be91e7340a18fff045c56e1b9e5085db5 /sys/arch
parent3b7398a3fbe3ec3c2e2cb47fd22cccad8b864351 (diff)
For systems where the cpu node in the device tree has a "clocks" property,
implement hw.cpuspeed using the clock framework. ok patrick@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/arm64/arm64/cpu.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/sys/arch/arm64/arm64/cpu.c b/sys/arch/arm64/arm64/cpu.c
index d48ba78b52b..169a21f25ea 100644
--- a/sys/arch/arm64/arm64/cpu.c
+++ b/sys/arch/arm64/arm64/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.7 2017/08/20 04:22:57 jsg Exp $ */
+/* $OpenBSD: cpu.c,v 1.8 2017/12/24 19:42:51 kettenis Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
@@ -20,9 +20,12 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
+#include <sys/sysctl.h>
+
#include <machine/fdt.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_clock.h>
#include <dev/ofw/fdt.h>
/* CPU Identification */
@@ -87,6 +90,7 @@ const struct implementers {
};
char cpu_model[64];
+int cpu_node;
int cpu_match(struct device *, void *, void *);
void cpu_attach(struct device *, struct device *, void *);
@@ -143,6 +147,8 @@ cpu_identify(struct cpu_info *ci)
}
}
+int cpu_clockspeed(int *);
+
int
cpu_match(struct device *parent, void *cfdata, void *aux)
{
@@ -172,9 +178,21 @@ cpu_attach(struct device *parent, struct device *dev, void *aux)
printf(":");
cpu_identify(ci);
+
+ if (OF_getproplen(faa->fa_node, "clocks") > 0) {
+ cpu_node = faa->fa_node;
+ cpu_cpuspeed = cpu_clockspeed;
+ }
} else {
printf(": not configured");
}
printf("\n");
}
+
+int
+cpu_clockspeed(int *freq)
+{
+ *freq = clock_get_frequency(cpu_node, NULL) / 1000000;
+ return 0;
+}