diff options
author | netchild <netchild@FreeBSD.org> | 2007-10-15 20:00:24 +0000 |
---|---|---|
committer | netchild <netchild@FreeBSD.org> | 2007-10-15 20:00:24 +0000 |
commit | 21c6e78ea76156c007b7b36f2ef60b4fffd62f50 (patch) | |
tree | f092392b1cc9ab1131c8c9929cf8ba4640ca09b3 /sys/dev/coretemp | |
parent | 4d72e12bc158aaa04ce18468c3c6286e0928dd0e (diff) | |
download | FreeBSD-src-21c6e78ea76156c007b7b36f2ef60b4fffd62f50.zip FreeBSD-src-21c6e78ea76156c007b7b36f2ef60b4fffd62f50.tar.gz |
Backout sensors framework.
Requested by: phk
Discussed on: cvs-all
Diffstat (limited to 'sys/dev/coretemp')
-rw-r--r-- | sys/dev/coretemp/coretemp.c | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/sys/dev/coretemp/coretemp.c b/sys/dev/coretemp/coretemp.c index fcc0005..61e4606 100644 --- a/sys/dev/coretemp/coretemp.c +++ b/sys/dev/coretemp/coretemp.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$"); #include <sys/module.h> #include <sys/conf.h> #include <sys/kernel.h> -#include <sys/sensors.h> +#include <sys/sysctl.h> #include <sys/proc.h> /* for curthread */ #include <sys/sched.h> @@ -50,13 +50,10 @@ __FBSDID("$FreeBSD$"); #include <machine/cpufunc.h> #include <machine/md_var.h> -extern int smp_cpus; - struct coretemp_softc { - struct ksensordev sc_sensordev; - struct ksensor sc_sensor; - device_t sc_dev; - int sc_tjmax; + device_t sc_dev; + int sc_tjmax; + struct sysctl_oid *sc_oid; }; /* @@ -68,7 +65,7 @@ static int coretemp_attach(device_t dev); static int coretemp_detach(device_t dev); static int coretemp_get_temp(device_t dev); -static void coretemp_refresh(void *arg); +static int coretemp_get_temp_sysctl(SYSCTL_HANDLER_ARGS); static device_method_t coretemp_methods[] = { /* Device interface */ @@ -177,17 +174,14 @@ coretemp_attach(device_t dev) } /* - * Add hw.sensors.cpuN.temp0 MIB. + * Add the "temperature" MIB to dev.cpu.N. */ - strlcpy(sc->sc_sensordev.xname, device_get_nameunit(pdev), - sizeof(sc->sc_sensordev.xname)); - sc->sc_sensor.type = SENSOR_TEMP; - sensor_attach(&sc->sc_sensordev, &sc->sc_sensor); - if (sensor_task_register(sc, coretemp_refresh, 2)) { - device_printf(dev, "unable to register update task\n"); - return (ENXIO); - } - sensordev_install(&sc->sc_sensordev); + sc->sc_oid = SYSCTL_ADD_PROC(device_get_sysctl_ctx(pdev), + SYSCTL_CHILDREN(device_get_sysctl_tree(pdev)), + OID_AUTO, "temperature", + CTLTYPE_INT | CTLFLAG_RD, + dev, 0, coretemp_get_temp_sysctl, "I", + "Current temperature in degC"); return (0); } @@ -197,8 +191,7 @@ coretemp_detach(device_t dev) { struct coretemp_softc *sc = device_get_softc(dev); - sensordev_deinstall(&sc->sc_sensordev); - sensor_task_unregister(sc); + sysctl_remove_oid(sc->sc_oid, 1, 0); return (0); } @@ -213,21 +206,25 @@ coretemp_get_temp(device_t dev) struct coretemp_softc *sc = device_get_softc(dev); char stemp[16]; + thread_lock(curthread); + sched_bind(curthread, cpu); + thread_unlock(curthread); + /* - * Bind to specific CPU to read the correct temperature. - * If not all CPUs are initialised, then only read from - * cpu0, returning -1 on all other CPUs. + * The digital temperature reading is located at bit 16 + * of MSR_THERM_STATUS. + * + * There is a bit on that MSR that indicates whether the + * temperature is valid or not. + * + * The temperature is computed by subtracting the temperature + * reading by Tj(max). */ - if (smp_cpus > 1) { - thread_lock(curthread); - sched_bind(curthread, cpu); - msr = rdmsr(MSR_THERM_STATUS); - sched_unbind(curthread); - thread_unlock(curthread); - } else if (cpu != 0) - return (-1); - else - msr = rdmsr(MSR_THERM_STATUS); + msr = rdmsr(MSR_THERM_STATUS); + + thread_lock(curthread); + sched_unbind(curthread); + thread_unlock(curthread); /* * Check for Thermal Status and Thermal Status Log. @@ -267,21 +264,13 @@ coretemp_get_temp(device_t dev) return (temp); } -static void -coretemp_refresh(void *arg) +static int +coretemp_get_temp_sysctl(SYSCTL_HANDLER_ARGS) { - struct coretemp_softc *sc = arg; - device_t dev = sc->sc_dev; - struct ksensor *s = &sc->sc_sensor; + device_t dev = (device_t) arg1; int temp; temp = coretemp_get_temp(dev); - if (temp == -1) { - s->flags |= SENSOR_FINVALID; - s->value = 0; - } else { - s->flags &= ~SENSOR_FINVALID; - s->value = temp * 1000000 + 273150000; - } + return (sysctl_handle_int(oidp, &temp, 0, req)); } |