diff options
author | Kevin Lo <kevlo@cvs.openbsd.org> | 2009-09-20 15:37:25 +0000 |
---|---|---|
committer | Kevin Lo <kevlo@cvs.openbsd.org> | 2009-09-20 15:37:25 +0000 |
commit | 28685deadaee80d11edf63ab705a896433e4f3c5 (patch) | |
tree | 8983ca91c2ec3f22ea64a775da4ee4911a70c281 /sys | |
parent | f2b7b5f2a213854221814c0276708a24c4bbf6d9 (diff) |
add support for VIA Nano cpu core temperature sensor
ok deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/amd64/identcpu.c | 27 | ||||
-rw-r--r-- | sys/arch/amd64/include/specialreg.h | 5 | ||||
-rw-r--r-- | sys/arch/i386/i386/machdep.c | 31 | ||||
-rw-r--r-- | sys/arch/i386/include/specialreg.h | 5 |
4 files changed, 63 insertions, 5 deletions
diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index 922d1c13f27..bb6e107ccfd 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identcpu.c,v 1.21 2009/07/22 20:33:12 deraadt Exp $ */ +/* $OpenBSD: identcpu.c,v 1.22 2009/09/20 15:37:23 kevlo Exp $ */ /* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */ /* @@ -155,6 +155,8 @@ void (*setperf_setup)(struct cpu_info *); void via_nano_setup(struct cpu_info *ci); +void via_update_sensor(void *args); + void via_nano_setup(struct cpu_info *ci) { @@ -244,6 +246,20 @@ via_nano_setup(struct cpu_info *ci) } void +via_update_sensor(void *args) +{ + struct cpu_info *ci = (struct cpu_info *) args; + u_int64_t msr; + + msr = rdmsr(MSR_CENT_TMTEMPERATURE); + ci->ci_sensor.value = (msr & 0xffffff); + /* micro degrees */ + ci->ci_sensor.value *= 1000000; + ci->ci_sensor.value += 273150000; + ci->ci_sensor.flags &= ~SENSOR_FINVALID; +} + +void identifycpu(struct cpu_info *ci) { u_int64_t last_tsc; @@ -356,8 +372,15 @@ identifycpu(struct cpu_info *ci) vendor[2] == 0x444d4163) /* DMAc */ amd64_errata(ci); - if (strncmp(cpu_model, "VIA Nano processor", 18) == 0) + if (strncmp(cpu_model, "VIA Nano processor", 18) == 0) { ci->cpu_setup = via_nano_setup; + strlcpy(ci->ci_sensordev.xname, ci->ci_dev->dv_xname, + sizeof(ci->ci_sensordev.xname)); + ci->ci_sensor.type = SENSOR_TEMP; + sensor_task_register(ci, via_update_sensor, 5); + sensor_attach(&ci->ci_sensordev, &ci->ci_sensor); + sensordev_install(&ci->ci_sensordev); + } } void diff --git a/sys/arch/amd64/include/specialreg.h b/sys/arch/amd64/include/specialreg.h index b825a206d9e..909f0a99d62 100644 --- a/sys/arch/amd64/include/specialreg.h +++ b/sys/arch/amd64/include/specialreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: specialreg.h,v 1.14 2009/05/31 03:20:10 matthieu Exp $ */ +/* $OpenBSD: specialreg.h,v 1.15 2009/09/20 15:37:23 kevlo Exp $ */ /* $NetBSD: specialreg.h,v 1.1 2003/04/26 18:39:48 fvdl Exp $ */ /* $NetBSD: x86/specialreg.h,v 1.2 2003/04/25 21:54:30 fvdl Exp $ */ @@ -257,6 +257,9 @@ #define MSR_MC3_ADDR 0x412 #define MSR_MC3_MISC 0x413 +/* VIA MSR */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ + /* * AMD K6/K7 MSRs. */ diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 6e0727f4fce..b30bca12551 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.459 2009/08/11 18:46:32 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.460 2009/09/20 15:37:23 kevlo Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -309,6 +309,7 @@ void amd_family6_setperf_setup(struct cpu_info *); void amd_family6_setup(struct cpu_info *); void cyrix3_setperf_setup(struct cpu_info *); void cyrix3_cpu_setup(struct cpu_info *); +void via_update_sensor(void *args); void cyrix6x86_cpu_setup(struct cpu_info *); void natsem6x86_cpu_setup(struct cpu_info *); void intel586_cpu_setup(struct cpu_info *); @@ -1164,11 +1165,39 @@ cyrix3_cpu_setup(struct cpu_info *ci) } printf("\n"); + + /* Setup the sensors structures */ + strlcpy(ci->ci_sensordev.xname, ci->ci_dev.dv_xname, + sizeof(ci->ci_sensordev.xname)); + ci->ci_sensor.type = SENSOR_TEMP; + sensor_task_register(ci, via_update_sensor, 5); + sensor_attach(&ci->ci_sensordev, &ci->ci_sensor); + sensordev_install(&ci->ci_sensordev); + break; } } void +via_update_sensor(void *args) +{ + struct cpu_info *ci = (struct cpu_info *) args; + u_int64_t msr; + + if (ci->ci_model == 0xf) { + msr = rdmsr(MSR_CENT_TMTEMPERATURE); + ci->ci_sensor.value = (msr & 0xffffff); + /* micro degrees */ + ci->ci_sensor.value *= 1000000; + ci->ci_sensor.value += 273150000; + ci->ci_sensor.flags &= ~SENSOR_FINVALID; + } else { + ci->ci_sensor.value = 0; + ci->ci_sensor.flags |= SENSOR_FINVALID; + } +} + +void cyrix6x86_cpu_setup(struct cpu_info *ci) { extern int clock_broken_latch; diff --git a/sys/arch/i386/include/specialreg.h b/sys/arch/i386/include/specialreg.h index af65c0be9ea..9ecfa024a50 100644 --- a/sys/arch/i386/include/specialreg.h +++ b/sys/arch/i386/include/specialreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: specialreg.h,v 1.34 2008/08/13 15:46:21 art Exp $ */ +/* $OpenBSD: specialreg.h,v 1.35 2009/09/20 15:37:24 kevlo Exp $ */ /* $NetBSD: specialreg.h,v 1.7 1994/10/27 04:16:26 cgd Exp $ */ /*- @@ -244,6 +244,9 @@ #define MSR_MC3_ADDR 0x412 #define MSR_MC3_MISC 0x413 +/* VIA MSR */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ + /* AMD MSRs */ #define MSR_K6_EPMR 0xc0000086 #define MSR_K7_EVNTSEL0 0xc0010000 |