amdtemp.c revision 1.4.2.3 1 1.4.2.2 mjf /* $NetBSD: amdtemp.c,v 1.4.2.3 2009/01/17 13:28:38 mjf Exp $ */
2 1.4.2.2 mjf /* $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $ */
3 1.4.2.2 mjf
4 1.4.2.2 mjf /*
5 1.4.2.2 mjf * Copyright (c) 2008 The NetBSD Foundation, Inc.
6 1.4.2.2 mjf * All rights reserved.
7 1.4.2.2 mjf *
8 1.4.2.2 mjf * This code is derived from software contributed to The NetBSD Foundation
9 1.4.2.2 mjf * by Christoph Egger.
10 1.4.2.2 mjf *
11 1.4.2.2 mjf * Redistribution and use in source and binary forms, with or without
12 1.4.2.2 mjf * modification, are permitted provided that the following conditions
13 1.4.2.2 mjf * are met:
14 1.4.2.2 mjf * 1. Redistributions of source code must retain the above copyright
15 1.4.2.2 mjf * notice, this list of conditions and the following disclaimer.
16 1.4.2.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
17 1.4.2.2 mjf * notice, this list of conditions and the following disclaimer in the
18 1.4.2.2 mjf * documentation and/or other materials provided with the distribution.
19 1.4.2.2 mjf *
20 1.4.2.2 mjf * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.4.2.2 mjf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.4.2.2 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.4.2.2 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.4.2.2 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.4.2.2 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.4.2.2 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.4.2.2 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.4.2.2 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.4.2.2 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.4.2.2 mjf * POSSIBILITY OF SUCH DAMAGE.
31 1.4.2.2 mjf */
32 1.4.2.2 mjf
33 1.4.2.2 mjf /*
34 1.4.2.2 mjf * Copyright (c) 2008 Constantine A. Murenin <cnst+openbsd (at) bugmail.mojo.ru>
35 1.4.2.2 mjf *
36 1.4.2.2 mjf * Permission to use, copy, modify, and distribute this software for any
37 1.4.2.2 mjf * purpose with or without fee is hereby granted, provided that the above
38 1.4.2.2 mjf * copyright notice and this permission notice appear in all copies.
39 1.4.2.2 mjf *
40 1.4.2.2 mjf * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
41 1.4.2.2 mjf * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
42 1.4.2.2 mjf * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
43 1.4.2.2 mjf * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
44 1.4.2.2 mjf * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
45 1.4.2.2 mjf * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
46 1.4.2.2 mjf * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
47 1.4.2.2 mjf */
48 1.4.2.2 mjf
49 1.4.2.2 mjf
50 1.4.2.2 mjf #include <sys/cdefs.h>
51 1.4.2.2 mjf __KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.4.2.3 2009/01/17 13:28:38 mjf Exp $ ");
52 1.4.2.2 mjf
53 1.4.2.2 mjf #include <sys/param.h>
54 1.4.2.2 mjf #include <sys/systm.h>
55 1.4.2.2 mjf #include <sys/device.h>
56 1.4.2.2 mjf #include <sys/kmem.h>
57 1.4.2.2 mjf #include <dev/sysmon/sysmonvar.h>
58 1.4.2.2 mjf
59 1.4.2.2 mjf #include <machine/bus.h>
60 1.4.2.2 mjf #include <machine/cpu.h>
61 1.4.2.2 mjf #include <machine/specialreg.h>
62 1.4.2.2 mjf
63 1.4.2.2 mjf #include <dev/pci/pcireg.h>
64 1.4.2.2 mjf #include <dev/pci/pcivar.h>
65 1.4.2.2 mjf #include <dev/pci/pcidevs.h>
66 1.4.2.2 mjf
67 1.4.2.2 mjf /*
68 1.4.2.2 mjf * AMD K8:
69 1.4.2.2 mjf * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf
70 1.4.2.2 mjf * Family10h:
71 1.4.2.2 mjf * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/31116.PDF
72 1.4.2.2 mjf */
73 1.4.2.2 mjf
74 1.4.2.2 mjf /* AMD Proessors, Function 3 -- Miscellaneous Control
75 1.4.2.2 mjf */
76 1.4.2.2 mjf
77 1.4.2.2 mjf /* Function 3 Registers */
78 1.4.2.2 mjf #define THERMTRIP_STAT_R 0xe4
79 1.4.2.2 mjf #define NORTHBRIDGE_CAP_R 0xe8
80 1.4.2.2 mjf #define CPUID_FAMILY_MODEL_R 0xfc
81 1.4.2.2 mjf
82 1.4.2.2 mjf /*
83 1.4.2.2 mjf * AMD NPT Family 0Fh Processors, Function 3 -- Miscellaneous Control
84 1.4.2.2 mjf */
85 1.4.2.2 mjf
86 1.4.2.2 mjf /* Bits within Thermtrip Status Register */
87 1.4.2.2 mjf #define K8_THERM_SENSE_SEL (1 << 6)
88 1.4.2.2 mjf #define K8_THERM_SENSE_CORE_SEL (1 << 2)
89 1.4.2.2 mjf
90 1.4.2.2 mjf /* Flip core and sensor selection bits */
91 1.4.2.2 mjf #define K8_T_SEL_C0(v) (v |= K8_THERM_SENSE_CORE_SEL)
92 1.4.2.2 mjf #define K8_T_SEL_C1(v) (v &= ~(K8_THERM_SENSE_CORE_SEL))
93 1.4.2.2 mjf #define K8_T_SEL_S0(v) (v &= ~(K8_THERM_SENSE_SEL))
94 1.4.2.2 mjf #define K8_T_SEL_S1(v) (v |= K8_THERM_SENSE_SEL)
95 1.4.2.2 mjf
96 1.4.2.2 mjf
97 1.4.2.2 mjf
98 1.4.2.2 mjf /*
99 1.4.2.2 mjf * AMD Family 10h Processorcs, Function 3 -- Miscellaneous Control
100 1.4.2.2 mjf */
101 1.4.2.2 mjf
102 1.4.2.2 mjf /* Function 3 Registers */
103 1.4.2.2 mjf #define F10_TEMPERATURE_CTL_R 0xa4
104 1.4.2.2 mjf
105 1.4.2.2 mjf /* Bits within Reported Temperature Control Register */
106 1.4.2.2 mjf #define F10_TEMP_CURTEMP (1 << 21)
107 1.4.2.2 mjf
108 1.4.2.2 mjf /*
109 1.4.2.2 mjf * Revision Guide for AMD NPT Family 0Fh Processors,
110 1.4.2.2 mjf * Publication # 33610, Revision 3.30, February 2008
111 1.4.2.2 mjf */
112 1.4.2.3 mjf #define K8_SOCKET_F 1 /* Server */
113 1.4.2.3 mjf #define K8_SOCKET_AM2 2 /* Desktop */
114 1.4.2.3 mjf #define K8_SOCKET_S1 3 /* Laptop */
115 1.4.2.3 mjf
116 1.4.2.2 mjf static const struct {
117 1.4.2.2 mjf const char rev[5];
118 1.4.2.3 mjf const struct {
119 1.4.2.3 mjf const pcireg_t cpuid;
120 1.4.2.3 mjf const uint8_t socket;
121 1.4.2.3 mjf } cpu[5];
122 1.4.2.2 mjf } amdtemp_core[] = {
123 1.4.2.3 mjf { "BH-F", { { 0x00040FB0, K8_SOCKET_AM2 }, /* F2 */
124 1.4.2.3 mjf { 0x00040F80, K8_SOCKET_S1 }, /* F2 */
125 1.4.2.3 mjf { 0, 0 }, { 0, 0 }, { 0, 0 } } },
126 1.4.2.3 mjf { "DH-F", { { 0x00040FF0, K8_SOCKET_AM2 }, /* F2 */
127 1.4.2.3 mjf { 0x00040FC0, K8_SOCKET_S1 }, /* F2 */
128 1.4.2.3 mjf { 0x00050FF0, K8_SOCKET_AM2 }, /* F2, F3 */
129 1.4.2.3 mjf { 0, 0 }, { 0, 0 } } },
130 1.4.2.3 mjf { "JH-F", { { 0x00040F10, K8_SOCKET_F }, /* F2, F3 */
131 1.4.2.3 mjf { 0x00040F30, K8_SOCKET_AM2 }, /* F2, F3 */
132 1.4.2.3 mjf { 0x000C0F10, K8_SOCKET_F }, /* F3 */
133 1.4.2.3 mjf { 0, 0 }, { 0, 0 } } },
134 1.4.2.3 mjf { "BH-G", { { 0x00060FB0, K8_SOCKET_AM2 }, /* G1, G2 */
135 1.4.2.3 mjf { 0x00060F80, K8_SOCKET_S1 }, /* G1, G2 */
136 1.4.2.3 mjf { 0, 0 }, { 0, 0 }, { 0, 0 } } },
137 1.4.2.3 mjf { "DH-G", { { 0x00060FF0, K8_SOCKET_AM2 }, /* G1, G2 */
138 1.4.2.3 mjf { 0x00060FC0, K8_SOCKET_S1 }, /* G2 */
139 1.4.2.3 mjf { 0x00070FF0, K8_SOCKET_AM2 }, /* G1, G2 */
140 1.4.2.3 mjf { 0x00070FC0, K8_SOCKET_S1 }, /* G2 */
141 1.4.2.3 mjf { 0, 0 } } }
142 1.4.2.2 mjf };
143 1.4.2.2 mjf
144 1.4.2.2 mjf
145 1.4.2.2 mjf struct amdtemp_softc {
146 1.4.2.2 mjf pci_chipset_tag_t sc_pc;
147 1.4.2.2 mjf pcitag_t sc_pcitag;
148 1.4.2.2 mjf
149 1.4.2.2 mjf struct sysmon_envsys *sc_sme;
150 1.4.2.2 mjf envsys_data_t *sc_sensor;
151 1.4.2.2 mjf
152 1.4.2.2 mjf char sc_rev;
153 1.4.2.2 mjf int8_t sc_numsensors;
154 1.4.2.2 mjf uint32_t sc_family;
155 1.4.2.3 mjf int32_t sc_adjustment;
156 1.4.2.2 mjf };
157 1.4.2.2 mjf
158 1.4.2.2 mjf
159 1.4.2.2 mjf static int amdtemp_match(device_t, cfdata_t, void *);
160 1.4.2.2 mjf static void amdtemp_attach(device_t, device_t, void *);
161 1.4.2.2 mjf
162 1.4.2.2 mjf static void amdtemp_k8_init(struct amdtemp_softc *, pcireg_t);
163 1.4.2.2 mjf static void amdtemp_k8_setup_sensors(struct amdtemp_softc *, int);
164 1.4.2.2 mjf static void amdtemp_k8_refresh(struct sysmon_envsys *, envsys_data_t *);
165 1.4.2.2 mjf
166 1.4.2.2 mjf static void amdtemp_family10_init(struct amdtemp_softc *);
167 1.4.2.2 mjf static void amdtemp_family10_setup_sensors(struct amdtemp_softc *, int);
168 1.4.2.2 mjf static void amdtemp_family10_refresh(struct sysmon_envsys *, envsys_data_t *);
169 1.4.2.2 mjf
170 1.4.2.2 mjf CFATTACH_DECL_NEW(amdtemp, sizeof(struct amdtemp_softc),
171 1.4.2.2 mjf amdtemp_match, amdtemp_attach, NULL, NULL);
172 1.4.2.2 mjf
173 1.4.2.2 mjf static int
174 1.4.2.2 mjf amdtemp_match(device_t parent, cfdata_t match, void *aux)
175 1.4.2.2 mjf {
176 1.4.2.2 mjf struct pci_attach_args *pa = aux;
177 1.4.2.2 mjf pcireg_t cpu_signature;
178 1.4.2.2 mjf uint32_t family;
179 1.4.2.2 mjf
180 1.4.2.2 mjf if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD)
181 1.4.2.2 mjf return 0;
182 1.4.2.2 mjf
183 1.4.2.2 mjf switch (PCI_PRODUCT(pa->pa_id)) {
184 1.4.2.2 mjf case PCI_PRODUCT_AMD_AMD64_MISC:
185 1.4.2.2 mjf case PCI_PRODUCT_AMD_AMD64_F10_MISC:
186 1.4.2.2 mjf case PCI_PRODUCT_AMD_AMD64_F11_MISC:
187 1.4.2.2 mjf break;
188 1.4.2.2 mjf default:
189 1.4.2.2 mjf return 0;
190 1.4.2.2 mjf }
191 1.4.2.2 mjf
192 1.4.2.2 mjf cpu_signature = pci_conf_read(pa->pa_pc, pa->pa_tag,
193 1.4.2.2 mjf CPUID_FAMILY_MODEL_R);
194 1.4.2.2 mjf
195 1.4.2.2 mjf /* This CPUID northbridge register has been introduced
196 1.4.2.2 mjf * in Revision F */
197 1.4.2.2 mjf if (cpu_signature == 0x0)
198 1.4.2.2 mjf return 0;
199 1.4.2.2 mjf
200 1.4.2.2 mjf family = CPUID2FAMILY(cpu_signature);
201 1.4.2.2 mjf if (family == 0xf)
202 1.4.2.2 mjf family += CPUID2EXTFAMILY(cpu_signature);
203 1.4.2.2 mjf
204 1.4.2.2 mjf /* Not yet supported CPUs */
205 1.4.2.2 mjf if (family >= 0x12)
206 1.4.2.2 mjf return 0;
207 1.4.2.2 mjf
208 1.4.2.2 mjf return 2; /* supercede pchb(4) */
209 1.4.2.2 mjf }
210 1.4.2.2 mjf
211 1.4.2.2 mjf static void
212 1.4.2.2 mjf amdtemp_attach(device_t parent, device_t self, void *aux)
213 1.4.2.2 mjf {
214 1.4.2.2 mjf struct amdtemp_softc *sc = device_private(self);
215 1.4.2.2 mjf struct pci_attach_args *pa = aux;
216 1.4.2.2 mjf pcireg_t cpu_signature;
217 1.4.2.2 mjf size_t len;
218 1.4.2.2 mjf int error;
219 1.4.2.2 mjf uint8_t i;
220 1.4.2.2 mjf
221 1.4.2.2 mjf aprint_naive("\n");
222 1.4.2.2 mjf aprint_normal("\n");
223 1.4.2.2 mjf
224 1.4.2.2 mjf aprint_normal_dev(self, "AMD CPU Temperature Sensors");
225 1.4.2.2 mjf
226 1.4.2.2 mjf cpu_signature = pci_conf_read(pa->pa_pc, pa->pa_tag,
227 1.4.2.2 mjf CPUID_FAMILY_MODEL_R);
228 1.4.2.2 mjf
229 1.4.2.2 mjf /* If we hit this, then match routine is wrong. */
230 1.4.2.2 mjf KASSERT(cpu_signature != 0x0);
231 1.4.2.2 mjf
232 1.4.2.2 mjf sc->sc_family = CPUID2FAMILY(cpu_signature)
233 1.4.2.2 mjf + CPUID2EXTFAMILY(cpu_signature);
234 1.4.2.2 mjf KASSERT(sc->sc_family >= 0xf);
235 1.4.2.2 mjf
236 1.4.2.2 mjf sc->sc_pc = pa->pa_pc;
237 1.4.2.2 mjf sc->sc_pcitag = pa->pa_tag;
238 1.4.2.3 mjf sc->sc_adjustment = 0;
239 1.4.2.2 mjf
240 1.4.2.2 mjf switch (sc->sc_family) {
241 1.4.2.2 mjf case 0xf: /* AMD K8 NPT */
242 1.4.2.2 mjf amdtemp_k8_init(sc, cpu_signature);
243 1.4.2.2 mjf break;
244 1.4.2.2 mjf
245 1.4.2.2 mjf case 0x10: /* AMD Barcelona/Phenom */
246 1.4.2.2 mjf case 0x11: /* AMD Griffin */
247 1.4.2.2 mjf amdtemp_family10_init(sc);
248 1.4.2.2 mjf break;
249 1.4.2.2 mjf
250 1.4.2.2 mjf default:
251 1.4.2.2 mjf /* Not supported */
252 1.4.2.2 mjf return;
253 1.4.2.2 mjf }
254 1.4.2.2 mjf
255 1.4.2.2 mjf aprint_normal("\n");
256 1.4.2.2 mjf
257 1.4.2.3 mjf if (sc->sc_adjustment != 0)
258 1.4.2.3 mjf aprint_debug_dev(self, "Workaround enabled\n");
259 1.4.2.3 mjf
260 1.4.2.2 mjf sc->sc_sme = sysmon_envsys_create();
261 1.4.2.2 mjf len = sizeof(envsys_data_t) * sc->sc_numsensors;
262 1.4.2.2 mjf sc->sc_sensor = kmem_zalloc(len, KM_NOSLEEP);
263 1.4.2.2 mjf if (!sc->sc_sensor)
264 1.4.2.2 mjf goto bad2;
265 1.4.2.2 mjf
266 1.4.2.2 mjf switch (sc->sc_family) {
267 1.4.2.2 mjf case 0xf:
268 1.4.2.2 mjf amdtemp_k8_setup_sensors(sc, device_unit(self));
269 1.4.2.2 mjf break;
270 1.4.2.2 mjf case 0x10:
271 1.4.2.2 mjf case 0x11:
272 1.4.2.2 mjf amdtemp_family10_setup_sensors(sc, device_unit(self));
273 1.4.2.2 mjf break;
274 1.4.2.2 mjf }
275 1.4.2.2 mjf
276 1.4.2.2 mjf /*
277 1.4.2.2 mjf * Set properties in sensors.
278 1.4.2.2 mjf */
279 1.4.2.2 mjf for (i = 0; i < sc->sc_numsensors; i++) {
280 1.4.2.2 mjf if (sysmon_envsys_sensor_attach(sc->sc_sme,
281 1.4.2.2 mjf &sc->sc_sensor[i]))
282 1.4.2.2 mjf goto bad;
283 1.4.2.2 mjf }
284 1.4.2.2 mjf
285 1.4.2.2 mjf /*
286 1.4.2.2 mjf * Register the sysmon_envsys device.
287 1.4.2.2 mjf */
288 1.4.2.2 mjf sc->sc_sme->sme_name = device_xname(self);
289 1.4.2.2 mjf sc->sc_sme->sme_cookie = sc;
290 1.4.2.2 mjf
291 1.4.2.2 mjf switch (sc->sc_family) {
292 1.4.2.2 mjf case 0xf:
293 1.4.2.2 mjf sc->sc_sme->sme_refresh = amdtemp_k8_refresh;
294 1.4.2.2 mjf break;
295 1.4.2.2 mjf case 0x10:
296 1.4.2.2 mjf case 0x11:
297 1.4.2.2 mjf sc->sc_sme->sme_refresh = amdtemp_family10_refresh;
298 1.4.2.2 mjf break;
299 1.4.2.2 mjf }
300 1.4.2.2 mjf
301 1.4.2.2 mjf error = sysmon_envsys_register(sc->sc_sme);
302 1.4.2.2 mjf if (error) {
303 1.4.2.2 mjf aprint_error_dev(self, "unable to register with sysmon "
304 1.4.2.2 mjf "(error=%d)\n", error);
305 1.4.2.2 mjf goto bad;
306 1.4.2.2 mjf }
307 1.4.2.2 mjf
308 1.4.2.2 mjf if (!pmf_device_register(self, NULL, NULL))
309 1.4.2.2 mjf aprint_error_dev(self, "couldn't establish power handler\n");
310 1.4.2.2 mjf
311 1.4.2.2 mjf return;
312 1.4.2.2 mjf
313 1.4.2.2 mjf bad:
314 1.4.2.2 mjf kmem_free(sc->sc_sensor, len);
315 1.4.2.2 mjf bad2:
316 1.4.2.2 mjf sysmon_envsys_destroy(sc->sc_sme);
317 1.4.2.2 mjf }
318 1.4.2.2 mjf
319 1.4.2.2 mjf static void
320 1.4.2.2 mjf amdtemp_k8_init(struct amdtemp_softc *sc, pcireg_t cpu_signature)
321 1.4.2.2 mjf {
322 1.4.2.2 mjf pcireg_t data;
323 1.4.2.2 mjf uint32_t cmpcap;
324 1.4.2.2 mjf uint8_t i, j;
325 1.4.2.2 mjf
326 1.4.2.2 mjf aprint_normal(" (K8");
327 1.4.2.2 mjf
328 1.4.2.2 mjf for (i = 0; i < __arraycount(amdtemp_core) && sc->sc_rev == '\0'; i++) {
329 1.4.2.3 mjf for (j = 0; amdtemp_core[i].cpu[j].cpuid != 0; j++) {
330 1.4.2.2 mjf if ((cpu_signature & ~0xf)
331 1.4.2.3 mjf != amdtemp_core[i].cpu[j].cpuid)
332 1.4.2.3 mjf continue;
333 1.4.2.3 mjf
334 1.4.2.3 mjf sc->sc_rev = amdtemp_core[i].rev[3];
335 1.4.2.3 mjf aprint_normal(": core rev %.4s%.1x",
336 1.4.2.3 mjf amdtemp_core[i].rev,
337 1.4.2.3 mjf CPUID2STEPPING(cpu_signature));
338 1.4.2.3 mjf
339 1.4.2.3 mjf switch (amdtemp_core[i].cpu[j].socket) {
340 1.4.2.3 mjf case K8_SOCKET_AM2:
341 1.4.2.3 mjf if (sc->sc_rev == 'G')
342 1.4.2.3 mjf sc->sc_adjustment = 21000000;
343 1.4.2.3 mjf aprint_normal(", socket AM2");
344 1.4.2.3 mjf break;
345 1.4.2.3 mjf case K8_SOCKET_S1:
346 1.4.2.3 mjf aprint_normal(", socket S1");
347 1.4.2.3 mjf break;
348 1.4.2.3 mjf case K8_SOCKET_F:
349 1.4.2.3 mjf aprint_normal(", socket F");
350 1.4.2.3 mjf break;
351 1.4.2.2 mjf }
352 1.4.2.2 mjf }
353 1.4.2.2 mjf }
354 1.4.2.2 mjf
355 1.4.2.2 mjf if (sc->sc_rev == '\0') {
356 1.4.2.2 mjf /* CPUID Family Model Register was introduced in
357 1.4.2.2 mjf * Revision F */
358 1.4.2.2 mjf sc->sc_rev = 'G'; /* newer than E, assume G */
359 1.4.2.2 mjf aprint_normal(": cpuid 0x%x", cpu_signature);
360 1.4.2.2 mjf }
361 1.4.2.2 mjf
362 1.4.2.2 mjf aprint_normal(")");
363 1.4.2.2 mjf
364 1.4.2.2 mjf data = pci_conf_read(sc->sc_pc, sc->sc_pcitag, NORTHBRIDGE_CAP_R);
365 1.4.2.2 mjf cmpcap = (data >> 12) & 0x3;
366 1.4.2.2 mjf
367 1.4.2.2 mjf sc->sc_numsensors = cmpcap ? 4 : 2;
368 1.4.2.2 mjf }
369 1.4.2.2 mjf
370 1.4.2.2 mjf
371 1.4.2.2 mjf static void
372 1.4.2.2 mjf amdtemp_k8_setup_sensors(struct amdtemp_softc *sc, int dv_unit)
373 1.4.2.2 mjf {
374 1.4.2.2 mjf uint8_t i;
375 1.4.2.2 mjf
376 1.4.2.2 mjf /* There are two sensors per CPU core. So we use the
377 1.4.2.2 mjf * device unit as socket counter to correctly enumerate
378 1.4.2.2 mjf * the CPUs on multi-socket machines.
379 1.4.2.2 mjf */
380 1.4.2.2 mjf dv_unit *= (sc->sc_numsensors / 2);
381 1.4.2.2 mjf for (i = 0; i < sc->sc_numsensors; i++) {
382 1.4.2.2 mjf sc->sc_sensor[i].units = ENVSYS_STEMP;
383 1.4.2.2 mjf sc->sc_sensor[i].state = ENVSYS_SVALID;
384 1.4.2.2 mjf
385 1.4.2.2 mjf snprintf(sc->sc_sensor[i].desc, sizeof(sc->sc_sensor[i].desc),
386 1.4.2.2 mjf "CPU%u Sensor%u", dv_unit + (i / 2), i % 2);
387 1.4.2.2 mjf }
388 1.4.2.2 mjf }
389 1.4.2.2 mjf
390 1.4.2.2 mjf
391 1.4.2.2 mjf static void
392 1.4.2.2 mjf amdtemp_k8_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
393 1.4.2.2 mjf {
394 1.4.2.2 mjf struct amdtemp_softc *sc = sme->sme_cookie;
395 1.4.2.2 mjf pcireg_t status, match, tmp;
396 1.4.2.2 mjf uint32_t value;
397 1.4.2.2 mjf
398 1.4.2.2 mjf status = pci_conf_read(sc->sc_pc, sc->sc_pcitag, THERMTRIP_STAT_R);
399 1.4.2.2 mjf
400 1.4.2.2 mjf switch(edata->sensor) { /* sensor number */
401 1.4.2.2 mjf case 0: /* Core 0 Sensor 0 */
402 1.4.2.2 mjf K8_T_SEL_C0(status);
403 1.4.2.2 mjf K8_T_SEL_S0(status);
404 1.4.2.2 mjf break;
405 1.4.2.2 mjf case 1: /* Core 0 Sensor 1 */
406 1.4.2.2 mjf K8_T_SEL_C0(status);
407 1.4.2.2 mjf K8_T_SEL_S1(status);
408 1.4.2.2 mjf break;
409 1.4.2.2 mjf case 2: /* Core 1 Sensor 0 */
410 1.4.2.2 mjf K8_T_SEL_C1(status);
411 1.4.2.2 mjf K8_T_SEL_S0(status);
412 1.4.2.2 mjf break;
413 1.4.2.2 mjf case 3: /* Core 1 Sensor 1 */
414 1.4.2.2 mjf K8_T_SEL_C1(status);
415 1.4.2.2 mjf K8_T_SEL_S1(status);
416 1.4.2.2 mjf break;
417 1.4.2.2 mjf }
418 1.4.2.2 mjf
419 1.4.2.2 mjf match = status & (K8_THERM_SENSE_CORE_SEL | K8_THERM_SENSE_SEL);
420 1.4.2.2 mjf pci_conf_write(sc->sc_pc, sc->sc_pcitag, THERMTRIP_STAT_R, status);
421 1.4.2.2 mjf status = pci_conf_read(sc->sc_pc, sc->sc_pcitag, THERMTRIP_STAT_R);
422 1.4.2.2 mjf tmp = status & (K8_THERM_SENSE_CORE_SEL | K8_THERM_SENSE_SEL);
423 1.4.2.2 mjf
424 1.4.2.2 mjf value = 0x3ff & (status >> 14);
425 1.4.2.2 mjf if (sc->sc_rev != 'G')
426 1.4.2.2 mjf value &= ~0x3;
427 1.4.2.2 mjf
428 1.4.2.2 mjf edata->state = ENVSYS_SINVALID;
429 1.4.2.2 mjf if ((tmp == match) && ((value & ~0x3) != 0)) {
430 1.4.2.2 mjf edata->state = ENVSYS_SVALID;
431 1.4.2.3 mjf edata->value_cur = (value * 250000 - 49000000) + 273150000
432 1.4.2.3 mjf + sc->sc_adjustment;
433 1.4.2.2 mjf }
434 1.4.2.2 mjf }
435 1.4.2.2 mjf
436 1.4.2.2 mjf
437 1.4.2.2 mjf static void
438 1.4.2.2 mjf amdtemp_family10_init(struct amdtemp_softc *sc)
439 1.4.2.2 mjf {
440 1.4.2.2 mjf aprint_normal(" (Family10h / Family11h)");
441 1.4.2.2 mjf
442 1.4.2.2 mjf sc->sc_numsensors = 1;
443 1.4.2.2 mjf }
444 1.4.2.2 mjf
445 1.4.2.2 mjf static void
446 1.4.2.2 mjf amdtemp_family10_setup_sensors(struct amdtemp_softc *sc, int dv_unit)
447 1.4.2.2 mjf {
448 1.4.2.2 mjf /* sanity check for future enhancements */
449 1.4.2.2 mjf KASSERT(sc->sc_numsensors == 1);
450 1.4.2.2 mjf
451 1.4.2.2 mjf /* There's one sensor per memory controller (= socket)
452 1.4.2.2 mjf * so we use the device unit as socket counter
453 1.4.2.2 mjf * to correctly enumerate the CPUs
454 1.4.2.2 mjf */
455 1.4.2.2 mjf sc->sc_sensor[0].units = ENVSYS_STEMP;
456 1.4.2.2 mjf sc->sc_sensor[0].state = ENVSYS_SVALID;
457 1.4.2.2 mjf
458 1.4.2.2 mjf snprintf(sc->sc_sensor[0].desc, sizeof(sc->sc_sensor[0].desc),
459 1.4.2.2 mjf "CPU%u Sensor0", dv_unit);
460 1.4.2.2 mjf }
461 1.4.2.2 mjf
462 1.4.2.2 mjf
463 1.4.2.2 mjf static void
464 1.4.2.2 mjf amdtemp_family10_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
465 1.4.2.2 mjf {
466 1.4.2.2 mjf struct amdtemp_softc *sc = sme->sme_cookie;
467 1.4.2.2 mjf pcireg_t status;
468 1.4.2.2 mjf uint32_t value;
469 1.4.2.2 mjf
470 1.4.2.2 mjf status = pci_conf_read(sc->sc_pc, sc->sc_pcitag, F10_TEMPERATURE_CTL_R);
471 1.4.2.2 mjf
472 1.4.2.2 mjf value = (status >> 21);
473 1.4.2.2 mjf
474 1.4.2.2 mjf edata->state = ENVSYS_SVALID;
475 1.4.2.2 mjf /* envsys(4) wants uK... convert from Celsius. */
476 1.4.2.2 mjf edata->value_cur = (value * 125000) + 273150000;
477 1.4.2.2 mjf }
478