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