Sun Jul 31 22:04:07 2011 UTC ()
add Family14h (AMD Fusion) support


(jmcneill)
diff -r1.11 -r1.12 src/sys/arch/x86/pci/amdtemp.c

cvs diff -r1.11 -r1.12 src/sys/arch/x86/pci/amdtemp.c (expand / switch to unified diff)

--- src/sys/arch/x86/pci/amdtemp.c 2011/06/15 03:30:15 1.11
+++ src/sys/arch/x86/pci/amdtemp.c 2011/07/31 22:04:07 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: amdtemp.c,v 1.11 2011/06/15 03:30:15 jruoho Exp $ */ 1/* $NetBSD: amdtemp.c,v 1.12 2011/07/31 22:04:07 jmcneill Exp $ */
2/* $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $ */ 2/* $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 * Copyright (c) 2008 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Christoph Egger. 9 * by Christoph Egger.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -38,27 +38,27 @@ @@ -38,27 +38,27 @@
38 * copyright notice and this permission notice appear in all copies. 38 * copyright notice and this permission notice appear in all copies.
39 * 39 *
40 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 40 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
41 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 41 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 42 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
43 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 43 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
44 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 44 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
45 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 45 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
46 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 46 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
47 */ 47 */
48 48
49 49
50#include <sys/cdefs.h> 50#include <sys/cdefs.h>
51__KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.11 2011/06/15 03:30:15 jruoho Exp $ "); 51__KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.12 2011/07/31 22:04:07 jmcneill Exp $ ");
52 52
53#include <sys/param.h> 53#include <sys/param.h>
54#include <sys/bus.h> 54#include <sys/bus.h>
55#include <sys/cpu.h> 55#include <sys/cpu.h>
56#include <sys/systm.h> 56#include <sys/systm.h>
57#include <sys/device.h> 57#include <sys/device.h>
58#include <sys/kmem.h> 58#include <sys/kmem.h>
59#include <sys/module.h> 59#include <sys/module.h>
60 60
61#include <machine/specialreg.h> 61#include <machine/specialreg.h>
62 62
63#include <dev/pci/pcireg.h> 63#include <dev/pci/pcireg.h>
64#include <dev/pci/pcivar.h> 64#include <dev/pci/pcivar.h>
@@ -71,52 +71,52 @@ __KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v  @@ -71,52 +71,52 @@ __KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v
71 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf 71 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf
72 * AMD K8 Errata: #141 72 * AMD K8 Errata: #141
73 * http://support.amd.com/us/Processor_TechDocs/33610_PUB_Rev3%2042v3.pdf 73 * http://support.amd.com/us/Processor_TechDocs/33610_PUB_Rev3%2042v3.pdf
74 * 74 *
75 * Family10h: 75 * Family10h:
76 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/31116.PDF 76 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/31116.PDF
77 * Family10h Errata: #319 77 * Family10h Errata: #319
78 * http://support.amd.com/de/Processor_TechDocs/41322.pdf 78 * http://support.amd.com/de/Processor_TechDocs/41322.pdf
79 * 79 *
80 * Family11h: 80 * Family11h:
81 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/41256.pdf 81 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/41256.pdf
82 */ 82 */
83 83
84/* AMD Proessors, Function 3 -- Miscellaneous Control 84/* AMD Processors, Function 3 -- Miscellaneous Control
85 */ 85 */
86 86
87/* Function 3 Registers */ 87/* Function 3 Registers */
88#define THERMTRIP_STAT_R 0xe4 88#define THERMTRIP_STAT_R 0xe4
89#define NORTHBRIDGE_CAP_R 0xe8 89#define NORTHBRIDGE_CAP_R 0xe8
90#define CPUID_FAMILY_MODEL_R 0xfc 90#define CPUID_FAMILY_MODEL_R 0xfc
91 91
92/* 92/*
93 * AMD NPT Family 0Fh Processors, Function 3 -- Miscellaneous Control 93 * AMD NPT Family 0Fh Processors, Function 3 -- Miscellaneous Control
94 */ 94 */
95 95
96/* Bits within Thermtrip Status Register */ 96/* Bits within Thermtrip Status Register */
97#define K8_THERM_SENSE_SEL (1 << 6) 97#define K8_THERM_SENSE_SEL (1 << 6)
98#define K8_THERM_SENSE_CORE_SEL (1 << 2) 98#define K8_THERM_SENSE_CORE_SEL (1 << 2)
99 99
100/* Flip core and sensor selection bits */ 100/* Flip core and sensor selection bits */
101#define K8_T_SEL_C0(v) (v |= K8_THERM_SENSE_CORE_SEL) 101#define K8_T_SEL_C0(v) (v |= K8_THERM_SENSE_CORE_SEL)
102#define K8_T_SEL_C1(v) (v &= ~(K8_THERM_SENSE_CORE_SEL)) 102#define K8_T_SEL_C1(v) (v &= ~(K8_THERM_SENSE_CORE_SEL))
103#define K8_T_SEL_S0(v) (v &= ~(K8_THERM_SENSE_SEL)) 103#define K8_T_SEL_S0(v) (v &= ~(K8_THERM_SENSE_SEL))
104#define K8_T_SEL_S1(v) (v |= K8_THERM_SENSE_SEL) 104#define K8_T_SEL_S1(v) (v |= K8_THERM_SENSE_SEL)
105 105
106 106
107 107
108/* 108/*
109 * AMD Family 10h Processorcs, Function 3 -- Miscellaneous Control 109 * AMD Family 10h Processors, Function 3 -- Miscellaneous Control
110 */ 110 */
111 111
112/* Function 3 Registers */ 112/* Function 3 Registers */
113#define F10_TEMPERATURE_CTL_R 0xa4 113#define F10_TEMPERATURE_CTL_R 0xa4
114 114
115/* Bits within Reported Temperature Control Register */ 115/* Bits within Reported Temperature Control Register */
116#define F10_TEMP_CURTEMP (1 << 21) 116#define F10_TEMP_CURTEMP (1 << 21)
117 117
118/* 118/*
119 * Revision Guide for AMD NPT Family 0Fh Processors, 119 * Revision Guide for AMD NPT Family 0Fh Processors,
120 * Publication # 33610, Revision 3.30, February 2008 120 * Publication # 33610, Revision 3.30, February 2008
121 */ 121 */
122#define K8_SOCKET_F 1 /* Server */ 122#define K8_SOCKET_F 1 /* Server */
@@ -186,26 +186,27 @@ static int @@ -186,26 +186,27 @@ static int
186amdtemp_match(device_t parent, cfdata_t match, void *aux) 186amdtemp_match(device_t parent, cfdata_t match, void *aux)
187{ 187{
188 struct pci_attach_args *pa = aux; 188 struct pci_attach_args *pa = aux;
189 pcireg_t cpu_signature; 189 pcireg_t cpu_signature;
190 uint32_t family; 190 uint32_t family;
191 191
192 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD) 192 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD)
193 return 0; 193 return 0;
194 194
195 switch (PCI_PRODUCT(pa->pa_id)) { 195 switch (PCI_PRODUCT(pa->pa_id)) {
196 case PCI_PRODUCT_AMD_AMD64_MISC: 196 case PCI_PRODUCT_AMD_AMD64_MISC:
197 case PCI_PRODUCT_AMD_AMD64_F10_MISC: 197 case PCI_PRODUCT_AMD_AMD64_F10_MISC:
198 case PCI_PRODUCT_AMD_AMD64_F11_MISC: 198 case PCI_PRODUCT_AMD_AMD64_F11_MISC:
 199 case PCI_PRODUCT_AMD_F14_NB:
199 break; 200 break;
200 default: 201 default:
201 return 0; 202 return 0;
202 } 203 }
203 204
204 cpu_signature = pci_conf_read(pa->pa_pc, 205 cpu_signature = pci_conf_read(pa->pa_pc,
205 pa->pa_tag, CPUID_FAMILY_MODEL_R); 206 pa->pa_tag, CPUID_FAMILY_MODEL_R);
206 207
207 /* This CPUID northbridge register has been introduced 208 /* This CPUID northbridge register has been introduced
208 * in Revision F */ 209 * in Revision F */
209 if (cpu_signature == 0x0) 210 if (cpu_signature == 0x0)
210 return 0; 211 return 0;
211 212
@@ -214,27 +215,27 @@ amdtemp_match(device_t parent, cfdata_t  @@ -214,27 +215,27 @@ amdtemp_match(device_t parent, cfdata_t
214 family += CPUID2EXTFAMILY(cpu_signature); 215 family += CPUID2EXTFAMILY(cpu_signature);
215 216
216 /* Errata #319: This has been fixed in Revision C2. */ 217 /* Errata #319: This has been fixed in Revision C2. */
217 if (family == 0x10) { 218 if (family == 0x10) {
218 if (CPUID2MODEL(cpu_signature) < 4) 219 if (CPUID2MODEL(cpu_signature) < 4)
219 return 0; 220 return 0;
220 if (CPUID2MODEL(cpu_signature) == 4 221 if (CPUID2MODEL(cpu_signature) == 4
221 && CPUID2STEPPING(cpu_signature) < 2) 222 && CPUID2STEPPING(cpu_signature) < 2)
222 return 0; 223 return 0;
223 } 224 }
224 225
225 226
226 /* Not yet supported CPUs */ 227 /* Not yet supported CPUs */
227 if (family >= 0x12) 228 if (family > 0x14)
228 return 0; 229 return 0;
229 230
230 return 2; /* supercede pchb(4) */ 231 return 2; /* supercede pchb(4) */
231} 232}
232 233
233static void 234static void
234amdtemp_attach(device_t parent, device_t self, void *aux) 235amdtemp_attach(device_t parent, device_t self, void *aux)
235{ 236{
236 struct amdtemp_softc *sc = device_private(self); 237 struct amdtemp_softc *sc = device_private(self);
237 struct pci_attach_args *pa = aux; 238 struct pci_attach_args *pa = aux;
238 pcireg_t cpu_signature; 239 pcireg_t cpu_signature;
239 int error; 240 int error;
240 uint8_t i; 241 uint8_t i;
@@ -257,26 +258,27 @@ amdtemp_attach(device_t parent, device_t @@ -257,26 +258,27 @@ amdtemp_attach(device_t parent, device_t
257 sc->sc_sensor = NULL; 258 sc->sc_sensor = NULL;
258 259
259 sc->sc_pc = pa->pa_pc; 260 sc->sc_pc = pa->pa_pc;
260 sc->sc_pcitag = pa->pa_tag; 261 sc->sc_pcitag = pa->pa_tag;
261 sc->sc_adjustment = 0; 262 sc->sc_adjustment = 0;
262 263
263 switch (sc->sc_family) { 264 switch (sc->sc_family) {
264 case 0xf: /* AMD K8 NPT */ 265 case 0xf: /* AMD K8 NPT */
265 amdtemp_k8_init(sc, cpu_signature); 266 amdtemp_k8_init(sc, cpu_signature);
266 break; 267 break;
267 268
268 case 0x10: /* AMD Barcelona/Phenom */ 269 case 0x10: /* AMD Barcelona/Phenom */
269 case 0x11: /* AMD Griffin */ 270 case 0x11: /* AMD Griffin */
 271 case 0x14: /* AMD Fusion */
270 amdtemp_family10_init(sc); 272 amdtemp_family10_init(sc);
271 break; 273 break;
272 274
273 default: 275 default:
274 aprint_normal(", family 0x%x not supported\n", 276 aprint_normal(", family 0x%x not supported\n",
275 sc->sc_family); 277 sc->sc_family);
276 return; 278 return;
277 } 279 }
278 280
279 aprint_normal("\n"); 281 aprint_normal("\n");
280 282
281 if (sc->sc_adjustment != 0) 283 if (sc->sc_adjustment != 0)
282 aprint_debug_dev(self, "Workaround enabled\n"); 284 aprint_debug_dev(self, "Workaround enabled\n");
@@ -284,51 +286,53 @@ amdtemp_attach(device_t parent, device_t @@ -284,51 +286,53 @@ amdtemp_attach(device_t parent, device_t
284 sc->sc_sme = sysmon_envsys_create(); 286 sc->sc_sme = sysmon_envsys_create();
285 sc->sc_sensor_len = sizeof(envsys_data_t) * sc->sc_numsensors; 287 sc->sc_sensor_len = sizeof(envsys_data_t) * sc->sc_numsensors;
286 sc->sc_sensor = kmem_zalloc(sc->sc_sensor_len, KM_SLEEP); 288 sc->sc_sensor = kmem_zalloc(sc->sc_sensor_len, KM_SLEEP);
287 289
288 if (sc->sc_sensor == NULL) 290 if (sc->sc_sensor == NULL)
289 goto bad; 291 goto bad;
290 292
291 switch (sc->sc_family) { 293 switch (sc->sc_family) {
292 case 0xf: 294 case 0xf:
293 amdtemp_k8_setup_sensors(sc, device_unit(self)); 295 amdtemp_k8_setup_sensors(sc, device_unit(self));
294 break; 296 break;
295 case 0x10: 297 case 0x10:
296 case 0x11: 298 case 0x11:
 299 case 0x14:
297 amdtemp_family10_setup_sensors(sc, device_unit(self)); 300 amdtemp_family10_setup_sensors(sc, device_unit(self));
298 break; 301 break;
299 } 302 }
300 303
301 /* 304 /*
302 * Set properties in sensors. 305 * Set properties in sensors.
303 */ 306 */
304 for (i = 0; i < sc->sc_numsensors; i++) { 307 for (i = 0; i < sc->sc_numsensors; i++) {
305 if (sysmon_envsys_sensor_attach(sc->sc_sme, 308 if (sysmon_envsys_sensor_attach(sc->sc_sme,
306 &sc->sc_sensor[i])) 309 &sc->sc_sensor[i]))
307 goto bad; 310 goto bad;
308 } 311 }
309 312
310 /* 313 /*
311 * Register the sysmon_envsys device. 314 * Register the sysmon_envsys device.
312 */ 315 */
313 sc->sc_sme->sme_name = device_xname(self); 316 sc->sc_sme->sme_name = device_xname(self);
314 sc->sc_sme->sme_cookie = sc; 317 sc->sc_sme->sme_cookie = sc;
315 318
316 switch (sc->sc_family) { 319 switch (sc->sc_family) {
317 case 0xf: 320 case 0xf:
318 sc->sc_sme->sme_refresh = amdtemp_k8_refresh; 321 sc->sc_sme->sme_refresh = amdtemp_k8_refresh;
319 break; 322 break;
320 case 0x10: 323 case 0x10:
321 case 0x11: 324 case 0x11:
 325 case 0x14:
322 sc->sc_sme->sme_refresh = amdtemp_family10_refresh; 326 sc->sc_sme->sme_refresh = amdtemp_family10_refresh;
323 break; 327 break;
324 } 328 }
325 329
326 error = sysmon_envsys_register(sc->sc_sme); 330 error = sysmon_envsys_register(sc->sc_sme);
327 if (error) { 331 if (error) {
328 aprint_error_dev(self, "unable to register with sysmon " 332 aprint_error_dev(self, "unable to register with sysmon "
329 "(error=%d)\n", error); 333 "(error=%d)\n", error);
330 goto bad; 334 goto bad;
331 } 335 }
332 336
333 (void)pmf_device_register(self, NULL, NULL); 337 (void)pmf_device_register(self, NULL, NULL);
334 338
@@ -471,46 +475,46 @@ amdtemp_k8_refresh(struct sysmon_envsys  @@ -471,46 +475,46 @@ amdtemp_k8_refresh(struct sysmon_envsys
471 475
472 edata->state = ENVSYS_SINVALID; 476 edata->state = ENVSYS_SINVALID;
473 if ((tmp == match) && ((value & ~0x3) != 0)) { 477 if ((tmp == match) && ((value & ~0x3) != 0)) {
474 edata->state = ENVSYS_SVALID; 478 edata->state = ENVSYS_SVALID;
475 edata->value_cur = (value * 250000 - 49000000) + 273150000 479 edata->value_cur = (value * 250000 - 49000000) + 273150000
476 + sc->sc_adjustment; 480 + sc->sc_adjustment;
477 } 481 }
478} 482}
479 483
480 484
481static void 485static void
482amdtemp_family10_init(struct amdtemp_softc *sc) 486amdtemp_family10_init(struct amdtemp_softc *sc)
483{ 487{
484 aprint_normal(" (Family10h / Family11h)"); 488 aprint_normal(" (Family%02xh)", sc->sc_family);
485 489
486 sc->sc_numsensors = 1; 490 sc->sc_numsensors = 1;
487} 491}
488 492
489static void 493static void
490amdtemp_family10_setup_sensors(struct amdtemp_softc *sc, int dv_unit) 494amdtemp_family10_setup_sensors(struct amdtemp_softc *sc, int dv_unit)
491{ 495{
492 /* sanity check for future enhancements */ 496 /* sanity check for future enhancements */
493 KASSERT(sc->sc_numsensors == 1); 497 KASSERT(sc->sc_numsensors == 1);
494 498
495 /* There's one sensor per memory controller (= socket) 499 /* There's one sensor per memory controller (= socket)
496 * so we use the device unit as socket counter 500 * so we use the device unit as socket counter
497 * to correctly enumerate the CPUs 501 * to correctly enumerate the CPUs
498 */ 502 */
499 sc->sc_sensor[0].units = ENVSYS_STEMP; 503 sc->sc_sensor[0].units = ENVSYS_STEMP;
500 sc->sc_sensor[0].state = ENVSYS_SVALID; 504 sc->sc_sensor[0].state = ENVSYS_SVALID;
501 505
502 snprintf(sc->sc_sensor[0].desc, sizeof(sc->sc_sensor[0].desc), 506 snprintf(sc->sc_sensor[0].desc, sizeof(sc->sc_sensor[0].desc),
503 "CPU%u Sensor0", dv_unit); 507 "cpu%u temperature", dv_unit);
504} 508}
505 509
506 510
507static void 511static void
508amdtemp_family10_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) 512amdtemp_family10_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
509{ 513{
510 struct amdtemp_softc *sc = sme->sme_cookie; 514 struct amdtemp_softc *sc = sme->sme_cookie;
511 pcireg_t status; 515 pcireg_t status;
512 uint32_t value; 516 uint32_t value;
513 517
514 status = pci_conf_read(sc->sc_pc, 518 status = pci_conf_read(sc->sc_pc,
515 sc->sc_pcitag, F10_TEMPERATURE_CTL_R); 519 sc->sc_pcitag, F10_TEMPERATURE_CTL_R);
516 520