From 6529203e90976a2462cf8f43f268993fd5571862 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 24 Dec 2017 19:43:51 +0000 Subject: [PATCH] For systems where the cpu node in the device tree has a "clocks" property, implement hw.cpuspeed using the clock framework. ok patrick@ --- sys/arch/arm/arm/cpu.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/arch/arm/arm/cpu.c b/sys/arch/arm/arm/cpu.c index 6bb0c0e617d..6ca966885f0 100644 --- a/sys/arch/arm/arm/cpu.c +++ b/sys/arch/arm/arm/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.41 2017/08/20 04:22:57 jsg Exp $ */ +/* $OpenBSD: cpu.c,v 1.42 2017/12/24 19:43:51 kettenis Exp $ */ /* $NetBSD: cpu.c,v 1.56 2004/04/14 04:01:49 bsh Exp $ */ @@ -52,7 +52,10 @@ #include #include #include +#include + #include + #include #include #include @@ -61,9 +64,11 @@ #include #include +#include #include char cpu_model[256]; +int cpu_node; int cpu_match(struct device *, void *, void *); void cpu_attach(struct device *, struct device *, void *); @@ -76,7 +81,8 @@ struct cfdriver cpu_cd = { NULL, "cpu", DV_DULL }; -void identify_arm_cpu(struct device *dv, struct cpu_info *); +void identify_arm_cpu(struct device *, struct cpu_info *); +int cpu_clockspeed(int *); int cpu_match(struct device *parent, void *cfdata, void *aux) @@ -94,6 +100,7 @@ cpu_match(struct device *parent, void *cfdata, void *aux) void cpu_attach(struct device *parent, struct device *dev, void *aux) { + struct fdt_attach_args *faa = aux; struct cpu_info *ci; if (dev->dv_unit == 0) { @@ -108,6 +115,11 @@ cpu_attach(struct device *parent, struct device *dev, void *aux) ci->ci_arm_cpuid & CPU_ID_REVISION_MASK; identify_arm_cpu(dev, ci); + + if (OF_getproplen(faa->fa_node, "clocks") > 0) { + cpu_node = faa->fa_node; + cpu_cpuspeed = cpu_clockspeed; + } } else { printf(": not configured"); } @@ -275,6 +287,13 @@ identify_arm_cpu(struct device *dv, struct cpu_info *ci) } } +int +cpu_clockspeed(int *freq) +{ + *freq = clock_get_frequency(cpu_node, NULL) / 1000000; + return 0; +} + #ifdef MULTIPROCESSOR int cpu_alloc_idle_pcb(struct cpu_info *ci) -- 2.20.1