| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: coretemp.c,v 1.10 2008/05/11 14:39:49 ad Exp $ */ | | 1 | /* $NetBSD: coretemp.c,v 1.11 2008/09/23 22:14:09 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007 Juan Romero Pardines. | | 4 | * Copyright (c) 2007 Juan Romero Pardines. |
5 | * Copyright (c) 2007 Rui Paulo <rpaulo@FreeBSD.org> | | 5 | * Copyright (c) 2007 Rui Paulo <rpaulo@FreeBSD.org> |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -26,27 +26,27 @@ | | | @@ -26,27 +26,27 @@ |
26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | * POSSIBILITY OF SUCH DAMAGE. | | 27 | * POSSIBILITY OF SUCH DAMAGE. |
28 | * | | 28 | * |
29 | * $FreeBSD: src/sys/dev/coretemp/coretemp.c,v 1.4 2007/10/15 20:00:21 netchild Exp $ | | 29 | * $FreeBSD: src/sys/dev/coretemp/coretemp.c,v 1.4 2007/10/15 20:00:21 netchild Exp $ |
30 | * | | 30 | * |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * Device driver for Intel's On Die thermal sensor via MSR. | | 34 | * Device driver for Intel's On Die thermal sensor via MSR. |
35 | * First introduced in Intel's Core line of processors. | | 35 | * First introduced in Intel's Core line of processors. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | __KERNEL_RCSID(0, "$NetBSD: coretemp.c,v 1.10 2008/05/11 14:39:49 ad Exp $"); | | 39 | __KERNEL_RCSID(0, "$NetBSD: coretemp.c,v 1.11 2008/09/23 22:14:09 christos Exp $"); |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #include <sys/kmem.h> | | 42 | #include <sys/kmem.h> |
43 | #include <sys/xcall.h> | | 43 | #include <sys/xcall.h> |
44 | #include <sys/cpu.h> | | 44 | #include <sys/cpu.h> |
45 | | | 45 | |
46 | #include <dev/sysmon/sysmonvar.h> | | 46 | #include <dev/sysmon/sysmonvar.h> |
47 | | | 47 | |
48 | #include <machine/cpuvar.h> | | 48 | #include <machine/cpuvar.h> |
49 | #include <machine/specialreg.h> | | 49 | #include <machine/specialreg.h> |
50 | #include <machine/cpufunc.h> | | 50 | #include <machine/cpufunc.h> |
51 | | | 51 | |
52 | struct coretemp_softc { | | 52 | struct coretemp_softc { |
| @@ -108,26 +108,35 @@ coretemp_register(struct cpu_info *ci) | | | @@ -108,26 +108,35 @@ coretemp_register(struct cpu_info *ci) |
108 | * On some Core 2 CPUs, there's an undocumented MSR that | | 108 | * On some Core 2 CPUs, there's an undocumented MSR that |
109 | * can tell us if Tj(max) is 100 or 85. | | 109 | * can tell us if Tj(max) is 100 or 85. |
110 | * | | 110 | * |
111 | * The if-clause for CPUs having the MSR_IA32_EXT_CONFIG was adapted | | 111 | * The if-clause for CPUs having the MSR_IA32_EXT_CONFIG was adapted |
112 | * from the Linux coretemp driver. | | 112 | * from the Linux coretemp driver. |
113 | */ | | 113 | */ |
114 | sc->sc_tjmax = 100; | | 114 | sc->sc_tjmax = 100; |
115 | if ((cpumodel == 0xf && cpumask >= 2) || cpumodel == 0xe) { | | 115 | if ((cpumodel == 0xf && cpumask >= 2) || cpumodel == 0xe) { |
116 | msr = rdmsr(MSR_IA32_EXT_CONFIG); | | 116 | msr = rdmsr(MSR_IA32_EXT_CONFIG); |
117 | if (msr & (1 << 30)) | | 117 | if (msr & (1 << 30)) |
118 | sc->sc_tjmax = 85; | | 118 | sc->sc_tjmax = 85; |
119 | } | | 119 | } |
120 | | | 120 | |
| | | 121 | /* |
| | | 122 | * Check if the MSR contains thermal reading valid bit, this |
| | | 123 | * avoid false positives on systems that fake up a compatible |
| | | 124 | * CPU that doesn't have access to these MSRs; such as VMWare. |
| | | 125 | */ |
| | | 126 | msr = rdmsr(MSR_THERM_STATUS); |
| | | 127 | if ((msr & __BIT(31)) == 0) |
| | | 128 | goto bad; |
| | | 129 | |
121 | sc->sc_ci = ci; | | 130 | sc->sc_ci = ci; |
122 | | | 131 | |
123 | /* | | 132 | /* |
124 | * Only a temperature sensor and monitor for a critical state. | | 133 | * Only a temperature sensor and monitor for a critical state. |
125 | */ | | 134 | */ |
126 | sc->sc_sensor.units = ENVSYS_STEMP; | | 135 | sc->sc_sensor.units = ENVSYS_STEMP; |
127 | sc->sc_sensor.flags = ENVSYS_FMONCRITICAL; | | 136 | sc->sc_sensor.flags = ENVSYS_FMONCRITICAL; |
128 | sc->sc_sensor.monitor = true; | | 137 | sc->sc_sensor.monitor = true; |
129 | (void)snprintf(sc->sc_sensor.desc, sizeof(sc->sc_sensor.desc), | | 138 | (void)snprintf(sc->sc_sensor.desc, sizeof(sc->sc_sensor.desc), |
130 | "%s temperature", device_xname(ci->ci_dev)); | | 139 | "%s temperature", device_xname(ci->ci_dev)); |
131 | | | 140 | |
132 | sc->sc_sme = sysmon_envsys_create(); | | 141 | sc->sc_sme = sysmon_envsys_create(); |
133 | if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) { | | 142 | if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) { |