Add support for VIA C7 temperature sensors (options VIA_C7TEMP)diff -r1.52 -r1.53 src/sys/arch/x86/conf/files.x86
(jmcneill)
--- src/sys/arch/x86/conf/files.x86 2009/04/30 00:07:23 1.52
+++ src/sys/arch/x86/conf/files.x86 2009/10/02 18:50:03 1.53
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: files.x86,v 1.52 2009/04/30 00:07:23 rmind Exp $ | 1 | # $NetBSD: files.x86,v 1.53 2009/10/02 18:50:03 jmcneill Exp $ | |
2 | 2 | |||
3 | # options for MP configuration through the MP spec | 3 | # options for MP configuration through the MP spec | |
4 | defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI | 4 | defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI | |
5 | 5 | |||
6 | # MTRR support | 6 | # MTRR support | |
7 | defflag MTRR | 7 | defflag MTRR | |
8 | 8 | |||
9 | # Interrupt debug | 9 | # Interrupt debug | |
10 | defflag opt_intrdebug.h INTRDEBUG | 10 | defflag opt_intrdebug.h INTRDEBUG | |
11 | 11 | |||
12 | # PCI fixup options | 12 | # PCI fixup options | |
13 | defflag opt_pcifixup.h PCI_ADDR_FIXUP PCI_BUS_FIXUP | 13 | defflag opt_pcifixup.h PCI_ADDR_FIXUP PCI_BUS_FIXUP | |
14 | PCI_INTR_FIXUP PCI_INTR_FIXUP_FORCE | 14 | PCI_INTR_FIXUP PCI_INTR_FIXUP_FORCE | |
@@ -16,26 +16,29 @@ defflag opt_pcifixup.h PCI_ADDR_FIXUP PC | @@ -16,26 +16,29 @@ defflag opt_pcifixup.h PCI_ADDR_FIXUP PC | |||
16 | # Intel Enhanced Speedstep | 16 | # Intel Enhanced Speedstep | |
17 | defflag ENHANCED_SPEEDSTEP | 17 | defflag ENHANCED_SPEEDSTEP | |
18 | defflag opt_est.h EST_FREQ_USERWRITE | 18 | defflag opt_est.h EST_FREQ_USERWRITE | |
19 | 19 | |||
20 | # Intel On Die Temperature sensor | 20 | # Intel On Die Temperature sensor | |
21 | defflag opt_intel_coretemp.h INTEL_CORETEMP: sysmon_envsys | 21 | defflag opt_intel_coretemp.h INTEL_CORETEMP: sysmon_envsys | |
22 | 22 | |||
23 | # Pentium 4+ Thermal Monitor ODCM (aka On Demand Clock Modulation) | 23 | # Pentium 4+ Thermal Monitor ODCM (aka On Demand Clock Modulation) | |
24 | defflag opt_intel_odcm.h INTEL_ONDEMAND_CLOCKMOD | 24 | defflag opt_intel_odcm.h INTEL_ONDEMAND_CLOCKMOD | |
25 | 25 | |||
26 | # AMD Powernow/Cool`n'Quiet Technology | 26 | # AMD Powernow/Cool`n'Quiet Technology | |
27 | defflag opt_powernow_k8.h POWERNOW_K8 | 27 | defflag opt_powernow_k8.h POWERNOW_K8 | |
28 | 28 | |||
29 | # VIA C7 Temperature sensor | |||
30 | defflag opt_via_c7temp.h VIA_C7TEMP: sysmon_envsys | |||
31 | ||||
29 | # VIA PadLock support | 32 | # VIA PadLock support | |
30 | defflag opt_viapadlock.h VIA_PADLOCK: opencrypto | 33 | defflag opt_viapadlock.h VIA_PADLOCK: opencrypto | |
31 | file arch/x86/x86/via_padlock.c via_padlock | 34 | file arch/x86/x86/via_padlock.c via_padlock | |
32 | 35 | |||
33 | # To be able to test for NetBSD/xen in shared files | 36 | # To be able to test for NetBSD/xen in shared files | |
34 | defflag opt_xen.h DO_NOT_DEFINE | 37 | defflag opt_xen.h DO_NOT_DEFINE | |
35 | 38 | |||
36 | define cpubus { [apid = -1] } | 39 | define cpubus { [apid = -1] } | |
37 | define ioapicbus { [apid = -1] } | 40 | define ioapicbus { [apid = -1] } | |
38 | define ipmibus {} | 41 | define ipmibus {} | |
39 | 42 | |||
40 | # | 43 | # | |
41 | # CPUs | 44 | # CPUs | |
@@ -94,26 +97,29 @@ file arch/x86/isa/isa_machdep.c isa | @@ -94,26 +97,29 @@ file arch/x86/isa/isa_machdep.c isa | |||
94 | file arch/x86/x86/powernow_k8.c powernow_k8 | 97 | file arch/x86/x86/powernow_k8.c powernow_k8 | |
95 | file arch/x86/x86/powernow_common.c powernow_k8 | powernow_k7 | 98 | file arch/x86/x86/powernow_common.c powernow_k8 | powernow_k7 | |
96 | 99 | |||
97 | # Intel On Demand Clock Modulation | 100 | # Intel On Demand Clock Modulation | |
98 | file arch/x86/x86/iclockmod.c intel_ondemand_clockmod | 101 | file arch/x86/x86/iclockmod.c intel_ondemand_clockmod | |
99 | 102 | |||
100 | # Intel Enhanced Speedstep | 103 | # Intel Enhanced Speedstep | |
101 | file arch/x86/x86/est.c enhanced_speedstep | 104 | file arch/x86/x86/est.c enhanced_speedstep | |
102 | file arch/x86/x86/intel_busclock.c enhanced_speedstep | 105 | file arch/x86/x86/intel_busclock.c enhanced_speedstep | |
103 | 106 | |||
104 | # Intel On-Die Temperature sensor | 107 | # Intel On-Die Temperature sensor | |
105 | file arch/x86/x86/coretemp.c intel_coretemp | 108 | file arch/x86/x86/coretemp.c intel_coretemp | |
106 | 109 | |||
110 | # VIA C7 Temperature sensor | |||
111 | file arch/x86/x86/viac7temp.c via_c7temp | |||
112 | ||||
107 | # IPMI device | 113 | # IPMI device | |
108 | device ipmi: sysmon_envsys, sysmon_wdog | 114 | device ipmi: sysmon_envsys, sysmon_wdog | |
109 | attach ipmi at ipmibus | 115 | attach ipmi at ipmibus | |
110 | file arch/x86/x86/ipmi.c ipmi needs-flag | 116 | file arch/x86/x86/ipmi.c ipmi needs-flag | |
111 | 117 | |||
112 | file arch/x86/x86/vga_post.c vga_post | 118 | file arch/x86/x86/vga_post.c vga_post | |
113 | 119 | |||
114 | file arch/x86/x86/tprof_pmi.c tprof needs-flag | 120 | file arch/x86/x86/tprof_pmi.c tprof needs-flag | |
115 | 121 | |||
116 | file arch/x86/pci/pci_machdep.c pci | 122 | file arch/x86/pci/pci_machdep.c pci | |
117 | file arch/x86/pci/pci_intr_machdep.c pci | 123 | file arch/x86/pci/pci_intr_machdep.c pci | |
118 | 124 | |||
119 | file arch/x86/pci/pciide_machdep.c pciide_common | 125 | file arch/x86/pci/pciide_machdep.c pciide_common |
--- src/sys/arch/x86/include/cpuvar.h 2009/10/02 15:05:42 1.30
+++ src/sys/arch/x86/include/cpuvar.h 2009/10/02 18:50:03 1.31
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cpuvar.h,v 1.30 2009/10/02 15:05:42 jmcneill Exp $ */ | 1 | /* $NetBSD: cpuvar.h,v 1.31 2009/10/02 18:50:03 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by RedBack Networks Inc. | 8 | * by RedBack Networks Inc. | |
9 | * | 9 | * | |
10 | * Author: Bill Sommerfeld | 10 | * Author: Bill Sommerfeld | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -82,52 +82,57 @@ struct cpu_attach_args { | @@ -82,52 +82,57 @@ struct cpu_attach_args { | |||
82 | int cpu_number; | 82 | int cpu_number; | |
83 | int cpu_role; | 83 | int cpu_role; | |
84 | const struct cpu_functions *cpu_func; | 84 | const struct cpu_functions *cpu_func; | |
85 | }; | 85 | }; | |
86 | 86 | |||
87 | #ifdef _KERNEL | 87 | #ifdef _KERNEL | |
88 | 88 | |||
89 | #if defined(_KERNEL_OPT) | 89 | #if defined(_KERNEL_OPT) | |
90 | #include "opt_multiprocessor.h" | 90 | #include "opt_multiprocessor.h" | |
91 | #include "opt_enhanced_speedstep.h" | 91 | #include "opt_enhanced_speedstep.h" | |
92 | #ifndef XEN | 92 | #ifndef XEN | |
93 | #include "opt_intel_coretemp.h" | 93 | #include "opt_intel_coretemp.h" | |
94 | #include "opt_intel_odcm.h" | 94 | #include "opt_intel_odcm.h" | |
95 | #include "opt_via_c7temp.h" | |||
95 | #endif | 96 | #endif | |
96 | #endif /* defined(_KERNEL_OPT) */ | 97 | #endif /* defined(_KERNEL_OPT) */ | |
97 | 98 | |||
98 | #ifdef MULTIPROCESSOR | 99 | #ifdef MULTIPROCESSOR | |
99 | extern uint32_t cpus_running; | 100 | extern uint32_t cpus_running; | |
100 | #endif | 101 | #endif | |
101 | 102 | |||
102 | int x86_ipi(int, int, int); | 103 | int x86_ipi(int, int, int); | |
103 | void x86_self_ipi(int); | 104 | void x86_self_ipi(int); | |
104 | int x86_ipi_init(int); | 105 | int x86_ipi_init(int); | |
105 | int x86_ipi_startup(int, int); | 106 | int x86_ipi_startup(int, int); | |
106 | void x86_errata(void); | 107 | void x86_errata(void); | |
107 | 108 | |||
108 | void identifycpu(struct cpu_info *); | 109 | void identifycpu(struct cpu_info *); | |
109 | void identifycpu_cpuids(struct cpu_info *); | 110 | void identifycpu_cpuids(struct cpu_info *); | |
110 | void cpu_init(struct cpu_info *); | 111 | void cpu_init(struct cpu_info *); | |
111 | void cpu_init_tss(struct cpu_info *); | 112 | void cpu_init_tss(struct cpu_info *); | |
112 | void cpu_init_first(void); | 113 | void cpu_init_first(void); | |
113 | 114 | |||
114 | void x86_cpu_idle_init(void); | 115 | void x86_cpu_idle_init(void); | |
115 | void x86_cpu_idle_halt(void); | 116 | void x86_cpu_idle_halt(void); | |
116 | void x86_cpu_idle_mwait(void); | 117 | void x86_cpu_idle_mwait(void); | |
117 | #ifdef XEN | 118 | #ifdef XEN | |
118 | void x86_cpu_idle_xen(void); | 119 | void x86_cpu_idle_xen(void); | |
119 | #endif | 120 | #endif | |
120 | 121 | |||
122 | #ifdef VIA_C7TEMP | |||
123 | void viac7temp_register(struct cpu_info *); | |||
124 | #endif | |||
125 | ||||
121 | #ifdef INTEL_CORETEMP | 126 | #ifdef INTEL_CORETEMP | |
122 | void coretemp_register(struct cpu_info *); | 127 | void coretemp_register(struct cpu_info *); | |
123 | #endif | 128 | #endif | |
124 | 129 | |||
125 | #ifdef INTEL_ONDEMAND_CLOCKMOD | 130 | #ifdef INTEL_ONDEMAND_CLOCKMOD | |
126 | void clockmod_init(void); | 131 | void clockmod_init(void); | |
127 | #endif | 132 | #endif | |
128 | 133 | |||
129 | #ifdef ENHANCED_SPEEDSTEP | 134 | #ifdef ENHANCED_SPEEDSTEP | |
130 | void est_init(int); | 135 | void est_init(int); | |
131 | int via_get_bus_clock(struct cpu_info *); | 136 | int via_get_bus_clock(struct cpu_info *); | |
132 | int viac7_get_bus_clock(struct cpu_info *); | 137 | int viac7_get_bus_clock(struct cpu_info *); | |
133 | int p3_get_bus_clock(struct cpu_info *); | 138 | int p3_get_bus_clock(struct cpu_info *); |
--- src/sys/arch/x86/x86/identcpu.c 2009/04/30 00:07:23 1.16
+++ src/sys/arch/x86/x86/identcpu.c 2009/10/02 18:50:03 1.17
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: identcpu.c,v 1.16 2009/04/30 00:07:23 rmind Exp $ */ | 1 | /* $NetBSD: identcpu.c,v 1.17 2009/10/02 18:50:03 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Frank van der Linden, and by Jason R. Thorpe. | 8 | * by Frank van der Linden, and by Jason R. Thorpe. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,31 +20,32 @@ | @@ -20,31 +20,32 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.16 2009/04/30 00:07:23 rmind Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.17 2009/10/02 18:50:03 jmcneill Exp $"); | |
34 | 34 | |||
35 | #include "opt_enhanced_speedstep.h" | 35 | #include "opt_enhanced_speedstep.h" | |
36 | #include "opt_intel_odcm.h" | 36 | #include "opt_intel_odcm.h" | |
37 | #include "opt_intel_coretemp.h" | 37 | #include "opt_intel_coretemp.h" | |
38 | #include "opt_via_c7temp.h" | |||
38 | #include "opt_powernow_k8.h" | 39 | #include "opt_powernow_k8.h" | |
39 | #include "opt_xen.h" | 40 | #include "opt_xen.h" | |
40 | #ifdef i386 /* XXX */ | 41 | #ifdef i386 /* XXX */ | |
41 | #include "opt_powernow_k7.h" | 42 | #include "opt_powernow_k7.h" | |
42 | #endif | 43 | #endif | |
43 | 44 | |||
44 | #include <sys/param.h> | 45 | #include <sys/param.h> | |
45 | #include <sys/systm.h> | 46 | #include <sys/systm.h> | |
46 | #include <sys/device.h> | 47 | #include <sys/device.h> | |
47 | 48 | |||
48 | #include <uvm/uvm_extern.h> | 49 | #include <uvm/uvm_extern.h> | |
49 | 50 | |||
50 | #include <machine/specialreg.h> | 51 | #include <machine/specialreg.h> | |
@@ -741,26 +742,38 @@ cpu_identify(struct cpu_info *ci) | @@ -741,26 +742,38 @@ cpu_identify(struct cpu_info *ci) | |||
741 | 742 | |||
742 | #ifdef ENHANCED_SPEEDSTEP | 743 | #ifdef ENHANCED_SPEEDSTEP | |
743 | if (cpu_feature2 & CPUID2_EST) { | 744 | if (cpu_feature2 & CPUID2_EST) { | |
744 | if (rdmsr(MSR_MISC_ENABLE) & (1 << 16)) | 745 | if (rdmsr(MSR_MISC_ENABLE) & (1 << 16)) | |
745 | est_init(cpu_vendor); | 746 | est_init(cpu_vendor); | |
746 | } | 747 | } | |
747 | #endif /* ENHANCED_SPEEDSTEP */ | 748 | #endif /* ENHANCED_SPEEDSTEP */ | |
748 | 749 | |||
749 | #ifdef INTEL_CORETEMP | 750 | #ifdef INTEL_CORETEMP | |
750 | if (cpu_vendor == CPUVENDOR_INTEL && cpuid_level >= 0x06) | 751 | if (cpu_vendor == CPUVENDOR_INTEL && cpuid_level >= 0x06) | |
751 | coretemp_register(ci); | 752 | coretemp_register(ci); | |
752 | #endif | 753 | #endif | |
753 | 754 | |||
755 | #ifdef VIA_C7TEMP | |||
756 | if (cpu_vendor == CPUVENDOR_IDT && | |||
757 | CPUID2FAMILY(ci->ci_signature) == 6 && | |||
758 | CPUID2MODEL(ci->ci_signature) >= 0x9) { | |||
759 | uint32_t descs[4]; | |||
760 | ||||
761 | x86_cpuid(0xc0000000, descs); | |||
762 | if (descs[0] >= 0xc0000002) /* has temp sensor */ | |||
763 | viac7temp_register(ci); | |||
764 | } | |||
765 | #endif | |||
766 | ||||
754 | #if defined(POWERNOW_K7) || defined(POWERNOW_K8) | 767 | #if defined(POWERNOW_K7) || defined(POWERNOW_K8) | |
755 | if (cpu_vendor == CPUVENDOR_AMD && powernow_probe(ci)) { | 768 | if (cpu_vendor == CPUVENDOR_AMD && powernow_probe(ci)) { | |
756 | switch (CPUID2FAMILY(ci->ci_signature)) { | 769 | switch (CPUID2FAMILY(ci->ci_signature)) { | |
757 | #ifdef POWERNOW_K7 | 770 | #ifdef POWERNOW_K7 | |
758 | case 6: | 771 | case 6: | |
759 | k7_powernow_init(); | 772 | k7_powernow_init(); | |
760 | break; | 773 | break; | |
761 | #endif | 774 | #endif | |
762 | #ifdef POWERNOW_K8 | 775 | #ifdef POWERNOW_K8 | |
763 | case 15: | 776 | case 15: | |
764 | k8_powernow_init(); | 777 | k8_powernow_init(); | |
765 | break; | 778 | break; | |
766 | #endif | 779 | #endif |
/* $NetBSD: viac7temp.c,v 1.1 2009/10/02 18:50:03 jmcneill Exp $ */
/*-
* Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: viac7temp.c,v 1.1 2009/10/02 18:50:03 jmcneill Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
#include <sys/xcall.h>
#include <sys/cpu.h>
#include <sys/device.h>
#include <dev/sysmon/sysmonvar.h>
#include <machine/cpuvar.h>
#include <machine/specialreg.h>
#include <machine/cpufunc.h>
struct viac7temp_softc {
struct cpu_info *sc_ci;
struct sysmon_envsys *sc_sme;
envsys_data_t sc_sensor;
};
static void viac7temp_refresh(struct sysmon_envsys *, envsys_data_t *);
static void viac7temp_refresh_xcall(void *, void *);
void
viac7temp_register(struct cpu_info *ci)
{
struct viac7temp_softc *sc;
sc = kmem_zalloc(sizeof(struct viac7temp_softc), KM_SLEEP);
sc->sc_sensor.units = ENVSYS_STEMP;
sc->sc_sensor.flags = 0;
sc->sc_sensor.monitor = true;
strlcpy(sc->sc_sensor.desc, "temperature",
sizeof(sc->sc_sensor.desc));
sc->sc_sme = sysmon_envsys_create();
if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) {
sysmon_envsys_destroy(sc->sc_sme);
goto bad;
}
/*
* Hook into the system monitor.
*/
sc->sc_sme->sme_name = device_xname(ci->ci_dev);
sc->sc_sme->sme_cookie = sc;
sc->sc_sme->sme_refresh = viac7temp_refresh;
if (sysmon_envsys_register(sc->sc_sme)) {
aprint_error_dev(ci->ci_dev,
"unable to register with sysmon\n");
sysmon_envsys_destroy(sc->sc_sme);
goto bad;
}
return;
bad:
kmem_free(sc, sizeof(struct viac7temp_softc));
}
static void
viac7temp_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
{
struct viac7temp_softc *sc = sme->sme_cookie;
uint64_t where;
where = xc_unicast(0, viac7temp_refresh_xcall, sc, edata, sc->sc_ci);
xc_wait(where);
}
static void
viac7temp_refresh_xcall(void *arg0, void *arg1)
{
/* struct viac7temp_softc *sc = (struct viac7temp_softc *)arg0; */
envsys_data_t *edata = (envsys_data_t *)arg1;
uint32_t descs[4];
x86_cpuid(0xc0000002, descs);
edata->value_cur = descs[0] >> 8;
edata->value_cur *= 1000000;
edata->value_cur += 273150000;
edata->state = ENVSYS_SVALID;
}