amdtemp.c revision 1.4.2.2 1 1.4.2.2 mjf /* $NetBSD: amdtemp.c,v 1.4.2.2 2008/06/02 13:22:50 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.2 2008/06/02 13:22:50 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.2 mjf static const struct {
113 1.4.2.2 mjf const char rev[5];
114 1.4.2.2 mjf const pcireg_t cpuid[5];
115 1.4.2.2 mjf } amdtemp_core[] = {
116 1.4.2.2 mjf { "BH-F", { 0x00040FB0, 0x00040F80, 0, 0, 0 } }, /* F2 */
117 1.4.2.2 mjf { "DH-F", { 0x00040FF0, 0x00050FF0, 0x00040FC0, 0, 0 } }, /* F2, F3 */
118 1.4.2.2 mjf { "JH-F", { 0x00040F10, 0x00040F30, 0x000C0F10, 0, 0 } }, /* F2, F3 */
119 1.4.2.2 mjf { "BH-G", { 0x00060FB0, 0x00060F80, 0, 0, 0 } }, /* G1, G2 */
120 1.4.2.2 mjf { "DH-G", { 0x00070FF0, 0x00060FF0,
121 1.4.2.2 mjf 0x00060FC0, 0x00070FC0, 0 } } /* G1, G2 */
122 1.4.2.2 mjf };
123 1.4.2.2 mjf
124 1.4.2.2 mjf
125 1.4.2.2 mjf struct amdtemp_softc {
126 1.4.2.2 mjf pci_chipset_tag_t sc_pc;
127 1.4.2.2 mjf pcitag_t sc_pcitag;
128 1.4.2.2 mjf
129 1.4.2.2 mjf struct sysmon_envsys *sc_sme;
130 1.4.2.2 mjf envsys_data_t *sc_sensor;
131 1.4.2.2 mjf
132 1.4.2.2 mjf char sc_rev;
133 1.4.2.2 mjf int8_t sc_numsensors;
134 1.4.2.2 mjf uint32_t sc_family;
135 1.4.2.2 mjf };
136 1.4.2.2 mjf
137 1.4.2.2 mjf
138 1.4.2.2 mjf static int amdtemp_match(device_t, cfdata_t, void *);
139 1.4.2.2 mjf static void amdtemp_attach(device_t, device_t, void *);
140 1.4.2.2 mjf
141 1.4.2.2 mjf static void amdtemp_k8_init(struct amdtemp_softc *, pcireg_t);
142 1.4.2.2 mjf static void amdtemp_k8_setup_sensors(struct amdtemp_softc *, int);
143 1.4.2.2 mjf static void amdtemp_k8_refresh(struct sysmon_envsys *, envsys_data_t *);
144 1.4.2.2 mjf
145 1.4.2.2 mjf static void amdtemp_family10_init(struct amdtemp_softc *);
146 1.4.2.2 mjf static void amdtemp_family10_setup_sensors(struct amdtemp_softc *, int);
147 1.4.2.2 mjf static void amdtemp_family10_refresh(struct sysmon_envsys *, envsys_data_t *);
148 1.4.2.2 mjf
149 1.4.2.2 mjf CFATTACH_DECL_NEW(amdtemp, sizeof(struct amdtemp_softc),
150 1.4.2.2 mjf amdtemp_match, amdtemp_attach, NULL, NULL);
151 1.4.2.2 mjf
152 1.4.2.2 mjf static int
153 1.4.2.2 mjf amdtemp_match(device_t parent, cfdata_t match, void *aux)
154 1.4.2.2 mjf {
155 1.4.2.2 mjf struct pci_attach_args *pa = aux;
156 1.4.2.2 mjf pcireg_t cpu_signature;
157 1.4.2.2 mjf uint32_t family;
158 1.4.2.2 mjf
159 1.4.2.2 mjf if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD)
160 1.4.2.2 mjf return 0;
161 1.4.2.2 mjf
162 1.4.2.2 mjf switch (PCI_PRODUCT(pa->pa_id)) {
163 1.4.2.2 mjf case PCI_PRODUCT_AMD_AMD64_MISC:
164 1.4.2.2 mjf case PCI_PRODUCT_AMD_AMD64_F10_MISC:
165 1.4.2.2 mjf case PCI_PRODUCT_AMD_AMD64_F11_MISC:
166 1.4.2.2 mjf break;
167 1.4.2.2 mjf default:
168 1.4.2.2 mjf return 0;
169 1.4.2.2 mjf }
170 1.4.2.2 mjf
171 1.4.2.2 mjf cpu_signature = pci_conf_read(pa->pa_pc, pa->pa_tag,
172 1.4.2.2 mjf CPUID_FAMILY_MODEL_R);
173 1.4.2.2 mjf
174 1.4.2.2 mjf /* This CPUID northbridge register has been introduced
175 1.4.2.2 mjf * in Revision F */
176 1.4.2.2 mjf if (cpu_signature == 0x0)
177 1.4.2.2 mjf return 0;
178 1.4.2.2 mjf
179 1.4.2.2 mjf family = CPUID2FAMILY(cpu_signature);
180 1.4.2.2 mjf if (family == 0xf)
181 1.4.2.2 mjf family += CPUID2EXTFAMILY(cpu_signature);
182 1.4.2.2 mjf
183 1.4.2.2 mjf /* Not yet supported CPUs */
184 1.4.2.2 mjf if (family >= 0x12)
185 1.4.2.2 mjf return 0;
186 1.4.2.2 mjf
187 1.4.2.2 mjf return 2; /* supercede pchb(4) */
188 1.4.2.2 mjf }
189 1.4.2.2 mjf
190 1.4.2.2 mjf static void
191 1.4.2.2 mjf amdtemp_attach(device_t parent, device_t self, void *aux)
192 1.4.2.2 mjf {
193 1.4.2.2 mjf struct amdtemp_softc *sc = device_private(self);
194 1.4.2.2 mjf struct pci_attach_args *pa = aux;
195 1.4.2.2 mjf pcireg_t cpu_signature;
196 1.4.2.2 mjf size_t len;
197 1.4.2.2 mjf int error;
198 1.4.2.2 mjf uint8_t i;
199 1.4.2.2 mjf
200 1.4.2.2 mjf aprint_naive("\n");
201 1.4.2.2 mjf aprint_normal("\n");
202 1.4.2.2 mjf
203 1.4.2.2 mjf aprint_normal_dev(self, "AMD CPU Temperature Sensors");
204 1.4.2.2 mjf
205 1.4.2.2 mjf cpu_signature = pci_conf_read(pa->pa_pc, pa->pa_tag,
206 1.4.2.2 mjf CPUID_FAMILY_MODEL_R);
207 1.4.2.2 mjf
208 1.4.2.2 mjf /* If we hit this, then match routine is wrong. */
209 1.4.2.2 mjf KASSERT(cpu_signature != 0x0);
210 1.4.2.2 mjf
211 1.4.2.2 mjf sc->sc_family = CPUID2FAMILY(cpu_signature)
212 1.4.2.2 mjf + CPUID2EXTFAMILY(cpu_signature);
213 1.4.2.2 mjf KASSERT(sc->sc_family >= 0xf);
214 1.4.2.2 mjf
215 1.4.2.2 mjf sc->sc_pc = pa->pa_pc;
216 1.4.2.2 mjf sc->sc_pcitag = pa->pa_tag;
217 1.4.2.2 mjf
218 1.4.2.2 mjf switch (sc->sc_family) {
219 1.4.2.2 mjf case 0xf: /* AMD K8 NPT */
220 1.4.2.2 mjf amdtemp_k8_init(sc, cpu_signature);
221 1.4.2.2 mjf break;
222 1.4.2.2 mjf
223 1.4.2.2 mjf case 0x10: /* AMD Barcelona/Phenom */
224 1.4.2.2 mjf case 0x11: /* AMD Griffin */
225 1.4.2.2 mjf amdtemp_family10_init(sc);
226 1.4.2.2 mjf break;
227 1.4.2.2 mjf
228 1.4.2.2 mjf default:
229 1.4.2.2 mjf /* Not supported */
230 1.4.2.2 mjf return;
231 1.4.2.2 mjf }
232 1.4.2.2 mjf
233 1.4.2.2 mjf aprint_normal("\n");
234 1.4.2.2 mjf
235 1.4.2.2 mjf sc->sc_sme = sysmon_envsys_create();
236 1.4.2.2 mjf len = sizeof(envsys_data_t) * sc->sc_numsensors;
237 1.4.2.2 mjf sc->sc_sensor = kmem_zalloc(len, KM_NOSLEEP);
238 1.4.2.2 mjf if (!sc->sc_sensor)
239 1.4.2.2 mjf goto bad2;
240 1.4.2.2 mjf
241 1.4.2.2 mjf switch (sc->sc_family) {
242 1.4.2.2 mjf case 0xf:
243 1.4.2.2 mjf amdtemp_k8_setup_sensors(sc, device_unit(self));
244 1.4.2.2 mjf break;
245 1.4.2.2 mjf case 0x10:
246 1.4.2.2 mjf case 0x11:
247 1.4.2.2 mjf amdtemp_family10_setup_sensors(sc, device_unit(self));
248 1.4.2.2 mjf break;
249 1.4.2.2 mjf }
250 1.4.2.2 mjf
251 1.4.2.2 mjf /*
252 1.4.2.2 mjf * Set properties in sensors.
253 1.4.2.2 mjf */
254 1.4.2.2 mjf for (i = 0; i < sc->sc_numsensors; i++) {
255 1.4.2.2 mjf if (sysmon_envsys_sensor_attach(sc->sc_sme,
256 1.4.2.2 mjf &sc->sc_sensor[i]))
257 1.4.2.2 mjf goto bad;
258 1.4.2.2 mjf }
259 1.4.2.2 mjf
260 1.4.2.2 mjf /*
261 1.4.2.2 mjf * Register the sysmon_envsys device.
262 1.4.2.2 mjf */
263 1.4.2.2 mjf sc->sc_sme->sme_name = device_xname(self);
264 1.4.2.2 mjf sc->sc_sme->sme_cookie = sc;
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 sc->sc_sme->sme_refresh = amdtemp_k8_refresh;
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 sc->sc_sme->sme_refresh = amdtemp_family10_refresh;
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 error = sysmon_envsys_register(sc->sc_sme);
277 1.4.2.2 mjf if (error) {
278 1.4.2.2 mjf aprint_error_dev(self, "unable to register with sysmon "
279 1.4.2.2 mjf "(error=%d)\n", error);
280 1.4.2.2 mjf goto bad;
281 1.4.2.2 mjf }
282 1.4.2.2 mjf
283 1.4.2.2 mjf if (!pmf_device_register(self, NULL, NULL))
284 1.4.2.2 mjf aprint_error_dev(self, "couldn't establish power handler\n");
285 1.4.2.2 mjf
286 1.4.2.2 mjf return;
287 1.4.2.2 mjf
288 1.4.2.2 mjf bad:
289 1.4.2.2 mjf kmem_free(sc->sc_sensor, len);
290 1.4.2.2 mjf bad2:
291 1.4.2.2 mjf sysmon_envsys_destroy(sc->sc_sme);
292 1.4.2.2 mjf }
293 1.4.2.2 mjf
294 1.4.2.2 mjf static void
295 1.4.2.2 mjf amdtemp_k8_init(struct amdtemp_softc *sc, pcireg_t cpu_signature)
296 1.4.2.2 mjf {
297 1.4.2.2 mjf pcireg_t data;
298 1.4.2.2 mjf uint32_t cmpcap;
299 1.4.2.2 mjf uint8_t i, j;
300 1.4.2.2 mjf
301 1.4.2.2 mjf aprint_normal(" (K8");
302 1.4.2.2 mjf
303 1.4.2.2 mjf for (i = 0; i < __arraycount(amdtemp_core) && sc->sc_rev == '\0'; i++) {
304 1.4.2.2 mjf for (j = 0; amdtemp_core[i].cpuid[j] != 0; j++) {
305 1.4.2.2 mjf if ((cpu_signature & ~0xf)
306 1.4.2.2 mjf == amdtemp_core[i].cpuid[j])
307 1.4.2.2 mjf {
308 1.4.2.2 mjf sc->sc_rev = amdtemp_core[i].rev[3];
309 1.4.2.2 mjf aprint_normal(": core rev %.4s%.1x",
310 1.4.2.2 mjf amdtemp_core[i].rev,
311 1.4.2.2 mjf CPUID2STEPPING(cpu_signature));
312 1.4.2.2 mjf }
313 1.4.2.2 mjf }
314 1.4.2.2 mjf }
315 1.4.2.2 mjf
316 1.4.2.2 mjf if (sc->sc_rev == '\0') {
317 1.4.2.2 mjf /* CPUID Family Model Register was introduced in
318 1.4.2.2 mjf * Revision F */
319 1.4.2.2 mjf sc->sc_rev = 'G'; /* newer than E, assume G */
320 1.4.2.2 mjf aprint_normal(": cpuid 0x%x", cpu_signature);
321 1.4.2.2 mjf }
322 1.4.2.2 mjf
323 1.4.2.2 mjf aprint_normal(")");
324 1.4.2.2 mjf
325 1.4.2.2 mjf data = pci_conf_read(sc->sc_pc, sc->sc_pcitag, NORTHBRIDGE_CAP_R);
326 1.4.2.2 mjf cmpcap = (data >> 12) & 0x3;
327 1.4.2.2 mjf
328 1.4.2.2 mjf sc->sc_numsensors = cmpcap ? 4 : 2;
329 1.4.2.2 mjf }
330 1.4.2.2 mjf
331 1.4.2.2 mjf
332 1.4.2.2 mjf static void
333 1.4.2.2 mjf amdtemp_k8_setup_sensors(struct amdtemp_softc *sc, int dv_unit)
334 1.4.2.2 mjf {
335 1.4.2.2 mjf uint8_t i;
336 1.4.2.2 mjf
337 1.4.2.2 mjf /* There are two sensors per CPU core. So we use the
338 1.4.2.2 mjf * device unit as socket counter to correctly enumerate
339 1.4.2.2 mjf * the CPUs on multi-socket machines.
340 1.4.2.2 mjf */
341 1.4.2.2 mjf dv_unit *= (sc->sc_numsensors / 2);
342 1.4.2.2 mjf for (i = 0; i < sc->sc_numsensors; i++) {
343 1.4.2.2 mjf sc->sc_sensor[i].units = ENVSYS_STEMP;
344 1.4.2.2 mjf sc->sc_sensor[i].state = ENVSYS_SVALID;
345 1.4.2.2 mjf
346 1.4.2.2 mjf snprintf(sc->sc_sensor[i].desc, sizeof(sc->sc_sensor[i].desc),
347 1.4.2.2 mjf "CPU%u Sensor%u", dv_unit + (i / 2), i % 2);
348 1.4.2.2 mjf }
349 1.4.2.2 mjf }
350 1.4.2.2 mjf
351 1.4.2.2 mjf
352 1.4.2.2 mjf static void
353 1.4.2.2 mjf amdtemp_k8_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
354 1.4.2.2 mjf {
355 1.4.2.2 mjf struct amdtemp_softc *sc = sme->sme_cookie;
356 1.4.2.2 mjf pcireg_t status, match, tmp;
357 1.4.2.2 mjf uint32_t value;
358 1.4.2.2 mjf
359 1.4.2.2 mjf status = pci_conf_read(sc->sc_pc, sc->sc_pcitag, THERMTRIP_STAT_R);
360 1.4.2.2 mjf
361 1.4.2.2 mjf switch(edata->sensor) { /* sensor number */
362 1.4.2.2 mjf case 0: /* Core 0 Sensor 0 */
363 1.4.2.2 mjf K8_T_SEL_C0(status);
364 1.4.2.2 mjf K8_T_SEL_S0(status);
365 1.4.2.2 mjf break;
366 1.4.2.2 mjf case 1: /* Core 0 Sensor 1 */
367 1.4.2.2 mjf K8_T_SEL_C0(status);
368 1.4.2.2 mjf K8_T_SEL_S1(status);
369 1.4.2.2 mjf break;
370 1.4.2.2 mjf case 2: /* Core 1 Sensor 0 */
371 1.4.2.2 mjf K8_T_SEL_C1(status);
372 1.4.2.2 mjf K8_T_SEL_S0(status);
373 1.4.2.2 mjf break;
374 1.4.2.2 mjf case 3: /* Core 1 Sensor 1 */
375 1.4.2.2 mjf K8_T_SEL_C1(status);
376 1.4.2.2 mjf K8_T_SEL_S1(status);
377 1.4.2.2 mjf break;
378 1.4.2.2 mjf }
379 1.4.2.2 mjf
380 1.4.2.2 mjf match = status & (K8_THERM_SENSE_CORE_SEL | K8_THERM_SENSE_SEL);
381 1.4.2.2 mjf pci_conf_write(sc->sc_pc, sc->sc_pcitag, THERMTRIP_STAT_R, status);
382 1.4.2.2 mjf status = pci_conf_read(sc->sc_pc, sc->sc_pcitag, THERMTRIP_STAT_R);
383 1.4.2.2 mjf tmp = status & (K8_THERM_SENSE_CORE_SEL | K8_THERM_SENSE_SEL);
384 1.4.2.2 mjf
385 1.4.2.2 mjf value = 0x3ff & (status >> 14);
386 1.4.2.2 mjf if (sc->sc_rev != 'G')
387 1.4.2.2 mjf value &= ~0x3;
388 1.4.2.2 mjf
389 1.4.2.2 mjf edata->state = ENVSYS_SINVALID;
390 1.4.2.2 mjf if ((tmp == match) && ((value & ~0x3) != 0)) {
391 1.4.2.2 mjf edata->state = ENVSYS_SVALID;
392 1.4.2.2 mjf edata->value_cur = (value * 250000 - 49000000) + 273150000;
393 1.4.2.2 mjf }
394 1.4.2.2 mjf }
395 1.4.2.2 mjf
396 1.4.2.2 mjf
397 1.4.2.2 mjf static void
398 1.4.2.2 mjf amdtemp_family10_init(struct amdtemp_softc *sc)
399 1.4.2.2 mjf {
400 1.4.2.2 mjf aprint_normal(" (Family10h / Family11h)");
401 1.4.2.2 mjf
402 1.4.2.2 mjf sc->sc_numsensors = 1;
403 1.4.2.2 mjf }
404 1.4.2.2 mjf
405 1.4.2.2 mjf static void
406 1.4.2.2 mjf amdtemp_family10_setup_sensors(struct amdtemp_softc *sc, int dv_unit)
407 1.4.2.2 mjf {
408 1.4.2.2 mjf /* sanity check for future enhancements */
409 1.4.2.2 mjf KASSERT(sc->sc_numsensors == 1);
410 1.4.2.2 mjf
411 1.4.2.2 mjf /* There's one sensor per memory controller (= socket)
412 1.4.2.2 mjf * so we use the device unit as socket counter
413 1.4.2.2 mjf * to correctly enumerate the CPUs
414 1.4.2.2 mjf */
415 1.4.2.2 mjf sc->sc_sensor[0].units = ENVSYS_STEMP;
416 1.4.2.2 mjf sc->sc_sensor[0].state = ENVSYS_SVALID;
417 1.4.2.2 mjf
418 1.4.2.2 mjf snprintf(sc->sc_sensor[0].desc, sizeof(sc->sc_sensor[0].desc),
419 1.4.2.2 mjf "CPU%u Sensor0", dv_unit);
420 1.4.2.2 mjf }
421 1.4.2.2 mjf
422 1.4.2.2 mjf
423 1.4.2.2 mjf static void
424 1.4.2.2 mjf amdtemp_family10_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
425 1.4.2.2 mjf {
426 1.4.2.2 mjf struct amdtemp_softc *sc = sme->sme_cookie;
427 1.4.2.2 mjf pcireg_t status;
428 1.4.2.2 mjf uint32_t value;
429 1.4.2.2 mjf
430 1.4.2.2 mjf status = pci_conf_read(sc->sc_pc, sc->sc_pcitag, F10_TEMPERATURE_CTL_R);
431 1.4.2.2 mjf
432 1.4.2.2 mjf value = (status >> 21);
433 1.4.2.2 mjf
434 1.4.2.2 mjf edata->state = ENVSYS_SVALID;
435 1.4.2.2 mjf /* envsys(4) wants uK... convert from Celsius. */
436 1.4.2.2 mjf edata->value_cur = (value * 125000) + 273150000;
437 1.4.2.2 mjf }
438