diff options
author | Kevin Lo <kevlo@cvs.openbsd.org> | 2009-10-07 02:15:49 +0000 |
---|---|---|
committer | Kevin Lo <kevlo@cvs.openbsd.org> | 2009-10-07 02:15:49 +0000 |
commit | 913cfce4b8445d6ebee715b633da195797de6144 (patch) | |
tree | ea839ba9c84f62e265c70ae2686de60bc04948d3 | |
parent | b1852bac0a302c0bf5763ac719e7bd4bcbc02564 (diff) |
add support for the temperature sensor of VIA Nano and C7-M CPUs.
some improvements suggested by jsg@
"commit" deraadt@
-rw-r--r-- | sys/arch/amd64/amd64/identcpu.c | 30 | ||||
-rw-r--r-- | sys/arch/amd64/include/specialreg.h | 5 | ||||
-rw-r--r-- | sys/arch/i386/i386/machdep.c | 41 | ||||
-rw-r--r-- | sys/arch/i386/include/specialreg.h | 6 |
4 files changed, 77 insertions, 5 deletions
diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index 1dbdca1f8a7..90f71996406 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identcpu.c,v 1.23 2009/09/20 21:58:31 jsg Exp $ */ +/* $OpenBSD: identcpu.c,v 1.24 2009/10/07 02:15:48 kevlo Exp $ */ /* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */ /* @@ -243,6 +243,23 @@ via_nano_setup(struct cpu_info *ci) } } +#ifndef SMALL_KERNEL +void via_update_sensor(void *args); +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; +} +#endif + void identifycpu(struct cpu_info *ci) { @@ -356,8 +373,17 @@ 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; +#ifndef SMALL_KERNEL + 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); +#endif + } } void diff --git a/sys/arch/amd64/include/specialreg.h b/sys/arch/amd64/include/specialreg.h index a9151b6f4f2..9ea389d0b52 100644 --- a/sys/arch/amd64/include/specialreg.h +++ b/sys/arch/amd64/include/specialreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: specialreg.h,v 1.16 2009/09/20 21:58:31 jsg Exp $ */ +/* $OpenBSD: specialreg.h,v 1.17 2009/10/07 02:15:48 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 8fdd9528f0c..71217838978 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.461 2009/09/20 21:58:31 jsg Exp $ */ +/* $OpenBSD: machdep.c,v 1.462 2009/10/07 02:15:48 kevlo Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -1075,6 +1075,20 @@ cyrix3_cpu_setup(struct cpu_info *ci) /* * C3 Nehemiah & later: fall through. */ + + case 10: /* C7-M Type A */ + case 13: /* C7-M Type D */ + case 15: /* Nano */ +#if !defined(SMALL_KERNEL) + /* 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); +#endif + default: /* * C3 Nehemiah/Esther & later models: @@ -1168,6 +1182,31 @@ cyrix3_cpu_setup(struct cpu_info *ci) } } +#if !defined(SMALL_KERNEL) +void via_update_sensor(void *args); +void +via_update_sensor(void *args) +{ + struct cpu_info *ci = (struct cpu_info *) args; + u_int64_t msr; + + switch (ci->ci_model) { + case 0xa: + case 0xd: + msr = rdmsr(MSR_C7M_TMTEMPERATURE); + break; + case 0xf: + msr = rdmsr(MSR_CENT_TMTEMPERATURE); + break; + } + ci->ci_sensor.value = (msr & 0xffffff); + /* micro degrees */ + ci->ci_sensor.value *= 1000000; + ci->ci_sensor.value += 273150000; + ci->ci_sensor.flags &= ~SENSOR_FINVALID; +} +#endif + void cyrix6x86_cpu_setup(struct cpu_info *ci) { diff --git a/sys/arch/i386/include/specialreg.h b/sys/arch/i386/include/specialreg.h index c9d96b85368..c20cd56473c 100644 --- a/sys/arch/i386/include/specialreg.h +++ b/sys/arch/i386/include/specialreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: specialreg.h,v 1.36 2009/09/20 21:58:31 jsg Exp $ */ +/* $OpenBSD: specialreg.h,v 1.37 2009/10/07 02:15:48 kevlo Exp $ */ /* $NetBSD: specialreg.h,v 1.7 1994/10/27 04:16:26 cgd Exp $ */ /*- @@ -244,6 +244,10 @@ #define MSR_MC3_ADDR 0x412 #define MSR_MC3_MISC 0x413 +/* VIA MSRs */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ +#define MSR_C7M_TMTEMPERATURE 0x1169 + /* AMD MSRs */ #define MSR_K6_EPMR 0xc0000086 #define MSR_K7_EVNTSEL0 0xc0010000 |