Add a clearing-house pseudo-device for system monitoring devices

such as the LM78 and VT82C686A (and eventually ACPI).  Multiple
sensor devices can be hooked registered with `sysmon', and eventually
sysmon will also handle hardware (and software) watchdog timers.

Convert the `lm' and `viaenv' drivers to the new interface.
This commit is contained in:
thorpej 2000-06-24 00:37:19 +00:00
parent ee01b6fae0
commit f82e306928
9 changed files with 542 additions and 304 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lm_pnpbios.c,v 1.2 2000/03/01 20:24:53 groo Exp $ */
/* $NetBSD: lm_pnpbios.c,v 1.3 2000/06/24 00:37:20 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -51,7 +51,8 @@
#include <i386/pnpbios/pnpbiosvar.h>
#include <sys/envsys.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/ic/nslm7xvar.h>

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.374 2000/06/22 20:31:46 fvdl Exp $
# $NetBSD: files,v 1.375 2000/06/24 00:37:19 thorpej Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -189,6 +189,10 @@ file ipkdb/ipkdb_if.c ipkdb
define mii_bitbang
file dev/mii/mii_bitbang.c mii_bitbang
# Central clearing house for system monitoring.
define sysmon
file dev/sysmon/sysmon.c sysmon needs-flag
# "Chipset" drivers. These are the bus-independent routines which
# contain the cfdrivers. Attachments are provided by files.<bus>
@ -386,7 +390,7 @@ define i2c
define i2c_eeprom
# National Semiconductor LM7[89]
device lm
device lm: sysmon
file dev/ic/nslm7x.c lm needs-flag
# Essential Communications Corp. HIPPI Interface

View File

@ -1,4 +1,4 @@
/* $NetBSD: nslm7x.c,v 1.3 2000/03/09 04:20:58 groo Exp $ */
/* $NetBSD: nslm7x.c,v 1.4 2000/06/24 00:37:19 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -49,13 +49,13 @@
#include <sys/conf.h>
#include <sys/time.h>
#include <sys/envsys.h>
#include <machine/bus.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/ic/nslm7xvar.h>
#include <machine/intr.h>
@ -67,7 +67,7 @@
#define DPRINTF(x)
#endif
struct envsys_range ranges[] = { /* sc->sensors sub-intervals */
const struct envsys_range lm_ranges[] = { /* sc->sensors sub-intervals */
/* for each unit type */
{ 7, 7, ENVSYS_STEMP },
{ 8, 10, ENVSYS_SFANRPM },
@ -79,19 +79,11 @@ struct envsys_range ranges[] = { /* sc->sensors sub-intervals */
};
#define SCFLAG_OREAD 0x00000001
#define SCFLAG_OWRITE 0x00000002
#define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE)
u_int8_t lm_readreg __P((struct lm_softc *, int));
void lm_writereg __P((struct lm_softc *, int, int));
void lm_refresh_sensor_data __P((struct lm_softc *));
cdev_decl(lm);
extern struct cfdriver lm_cd;
#define LMUNIT(x) (minor(x))
int lm_gtredata __P((struct sysmon_envsys *, struct envsys_tre_data *));
int lm_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
u_int8_t
lm_readreg(sc, reg)
@ -212,99 +204,40 @@ lm_attach(lmsc)
lmsc->info[i].desc[4] = i - 7 + '0';
lmsc->info[i].desc[5] = 0;
}
/*
* Hook into the System Monitor.
*/
lmsc->sc_sysmon.sme_ranges = lm_ranges;
lmsc->sc_sysmon.sme_sensor_info = lmsc->info;
lmsc->sc_sysmon.sme_sensor_data = lmsc->sensors;
lmsc->sc_sysmon.sme_cookie = lmsc;
lmsc->sc_sysmon.sme_gtredata = lm_gtredata;
lmsc->sc_sysmon.sme_streinfo = lm_streinfo;
lmsc->sc_sysmon.sme_nsensors = LM_NUM_SENSORS;
lmsc->sc_sysmon.sme_envsys_version = 1000;
if (sysmon_envsys_register(&lmsc->sc_sysmon))
printf("%s: unable to register with sysmon\n",
lmsc->sc_dev.dv_xname);
}
int
lmopen(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
int unit = LMUNIT(dev);
struct lm_softc *sc;
if (unit >= lm_cd.cd_ndevs)
return (ENXIO);
sc = lm_cd.cd_devs[unit];
if (sc == 0)
return (ENXIO);
/* XXX - add spinlocks instead! */
if (sc->sc_flags & SCFLAG_OPEN)
return (EBUSY);
sc->sc_flags |= SCFLAG_OPEN;
return 0;
}
int
lmclose(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct lm_softc *sc = lm_cd.cd_devs[LMUNIT(dev)];
DPRINTF(("lmclose: pid %d flag %x mode %x\n", p->p_pid, flag, mode));
sc->sc_flags &= ~SCFLAG_OPEN;
return 0;
}
int
lmioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct lm_softc *sc = lm_cd.cd_devs[LMUNIT(dev)];
struct envsys_range *rng;
lm_gtredata(sme, tred)
struct sysmon_envsys *sme;
struct envsys_tre_data *tred;
struct envsys_basic_info *binfo;
struct timeval t, onepointfive = { 1, 500000 };
u_int8_t sdata;
int32_t *vers;
{
static const struct timeval onepointfive = { 1, 500000 };
struct timeval t;
struct lm_softc *sc = sme->sme_cookie;
int i, s;
int divisor;
switch (cmd) {
case ENVSYS_VERSION:
vers = (int32_t *)data;
*vers = 1000;
return (0);
case ENVSYS_GRANGE:
rng = (struct envsys_range *)data;
if ((rng->units < ENVSYS_STEMP) ||
(rng->units > ENVSYS_SAMPS) ) {
/* Return empty range for unsupp sensor types */
rng->low = 1;
rng->high = 0;
} else {
rng->low = ranges[rng->units].low;
rng->high = ranges[rng->units].high;
}
return (0);
case ENVSYS_GTREDATA:
tred = (struct envsys_tre_data *)data;
tred->validflags = 0;
if (tred->sensor < LM_NUM_SENSORS) {
/* read new values at most once every 1.5 seconds */
s = splclock();
timeradd(&sc->lastread, &onepointfive, &t);
s = splclock();
i = timercmp(&mono_time, &t, >);
if (i) {
sc->lastread.tv_sec = mono_time.tv_sec;
@ -312,33 +245,25 @@ lmioctl(dev, cmd, data, flag, p)
}
splx(s);
if (i) {
if (i)
lm_refresh_sensor_data(sc);
}
bcopy(&sc->sensors[tred->sensor], tred,
sizeof(struct envsys_tre_data));
}
*tred = sc->sensors[tred->sensor];
return (0);
}
case ENVSYS_GTREINFO:
binfo = (struct envsys_basic_info *)data;
if (binfo->sensor >= LM_NUM_SENSORS)
binfo->validflags = 0;
else
bcopy(&sc->info[binfo->sensor], binfo,
sizeof(struct envsys_basic_info));
int
lm_streinfo(sme, binfo)
struct sysmon_envsys *sme;
struct envsys_basic_info *binfo;
{
struct lm_softc *sc = sme->sme_cookie;
int divisor;
u_int8_t sdata;
return (0);
case ENVSYS_STREINFO:
binfo = (struct envsys_basic_info *)data;
if (binfo->sensor >= LM_NUM_SENSORS)
binfo->validflags = 0;
else if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
sc->info[binfo->sensor].rfact = binfo->rfact;
else {
/* FAN1 and FAN2 can have divisors set, but not FAN3 */
@ -379,17 +304,14 @@ lmioctl(dev, cmd, data, flag, p)
lm_writereg(sc, LMD_VIDFAN, sdata);
}
bcopy(binfo->desc, sc->info[binfo->sensor].desc, 33);
sc->info[binfo->sensor].desc[32] = 0;
memcpy(sc->info[binfo->sensor].desc, binfo->desc,
sizeof(sc->info[binfo->sensor].desc));
sc->info[binfo->sensor].desc[
sizeof(sc->info[binfo->sensor].desc) - 1] = '\0';
binfo->validflags = ENVSYS_FVALID;
}
return (0);
default:
return (ENOTTY);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: nslm7xvar.h,v 1.2 2000/03/07 18:39:14 groo Exp $ */
/* $NetBSD: nslm7xvar.h,v 1.3 2000/06/24 00:37:19 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -78,6 +78,8 @@ struct lm_softc {
struct timeval lastread; /* only allow reads every 1.5 seconds */
struct envsys_tre_data sensors[LM_NUM_SENSORS];
struct envsys_basic_info info[LM_NUM_SENSORS];
struct sysmon_envsys sc_sysmon;
};
void lm_attach __P((struct lm_softc *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: lm_isa.c,v 1.2 2000/03/09 04:19:03 groo Exp $ */
/* $NetBSD: lm_isa.c,v 1.3 2000/06/24 00:37:20 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -45,8 +45,6 @@
#include <sys/errno.h>
#include <sys/conf.h>
#include <sys/envsys.h>
#include <machine/bus.h>
#include <dev/isa/isareg.h>
@ -55,6 +53,8 @@
#include <machine/intr.h>
#include <machine/bus.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/ic/nslm7xvar.h>
#if defined(LMDEBUG)

View File

@ -1,4 +1,4 @@
# $NetBSD: files.pci,v 1.96 2000/06/06 03:07:39 thorpej Exp $
# $NetBSD: files.pci,v 1.97 2000/06/24 00:37:20 thorpej Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@ -331,6 +331,6 @@ attach viapm at pci
file dev/pci/viapm.c viapm
# hardware monitoring part of viapm
device viaenv
device viaenv: sysmon
attach viaenv at viapm
file dev/pci/viaenv.c viaenv needs-flag

View File

@ -1,4 +1,4 @@
/* $NetBSD: viaenv.c,v 1.2 2000/05/12 16:42:41 thorpej Exp $ */
/* $NetBSD: viaenv.c,v 1.3 2000/06/24 00:37:20 thorpej Exp $ */
/*
* Copyright (c) 2000 Johan Danielsson
@ -42,13 +42,14 @@
#include <sys/lock.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <sys/envsys.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/viapmvar.h>
#include <dev/sysmon/sysmonvar.h>
#ifdef VIAENV_DEBUG
unsigned int viaenv_debug = 0;
#define DPRINTF(X) do { if(viaenv_debug) printf X ; } while(0)
@ -62,8 +63,6 @@ struct viaenv_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
struct callout sc_callout;
unsigned int sc_flags;
int sc_fan_div[2]; /* fan RPM divisor */
@ -73,8 +72,22 @@ struct viaenv_softc {
struct proc *sc_thread;
struct lock sc_lock;
struct sysmon_envsys sc_sysmon;
};
#define SCFLAG_OPEN 1
const struct envsys_range viaenv_ranges[] = {
{ 0, 2, ENVSYS_STEMP },
{ 3, 4, ENVSYS_SFANRPM },
{ 0, 1, ENVSYS_SVOLTS_AC }, /* none */
{ 5, 11, ENVSYS_SVOLTS_DC },
{ 1, 0, ENVSYS_SOHMS }, /* none */
{ 1, 0, ENVSYS_SWATTS }, /* none */
{ 1, 0, ENVSYS_SAMPS }, /* none */
};
int viaenv_gtredata(struct sysmon_envsys *, struct envsys_tre_data *);
int viaenv_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
static int
viaenv_match(struct device * parent, struct cfdata * match, void *aux);
@ -108,7 +121,7 @@ viaenv_match(struct device * parent, struct cfdata * match, void *aux)
* haven't been able to figure out how -- it doesn't give the same values
*/
static long val_to_temp[] = {
static const long val_to_temp[] = {
20225, 20435, 20645, 20855, 21045, 21245, 21425, 21615, 21785, 21955,
22125, 22285, 22445, 22605, 22755, 22895, 23035, 23175, 23315, 23445,
23565, 23695, 23815, 23925, 24045, 24155, 24265, 24365, 24465, 24565,
@ -167,7 +180,8 @@ val_to_rpm(unsigned int val, int div)
static long
val_to_uV(unsigned int val, int index)
{
long mult[] = {1250000, 1250000, 1670000, 2600000, 6300000};
static const long mult[] =
{1250000, 1250000, 1670000, 2600000, 6300000};
assert(index >= 0 && index <= 4);
@ -282,7 +296,7 @@ viaenv_attach(struct device * parent, struct device * self, void *aux)
}
printf("\n");
lockinit(&sc->sc_lock, 0, "foo", 0, 0);
lockinit(&sc->sc_lock, 0, "viaenv", 0, 0);
/* Initialize sensors */
for (i = 0; i < VIANUMSENSORS; ++i) {
@ -316,120 +330,45 @@ viaenv_attach(struct device * parent, struct device * self, void *aux)
strcpy(sc->sc_info[8].desc, "VSENS3"); /* VSENS3 (5V) */
strcpy(sc->sc_info[9].desc, "VSENS4"); /* VSENS4 (12V) */
kthread_create(viaenv_thread_create, sc);
}
/*
* Hook into the System Monitor.
*/
sc->sc_sysmon.sme_ranges = viaenv_ranges;
sc->sc_sysmon.sme_sensor_info = sc->sc_info;
sc->sc_sysmon.sme_sensor_data = sc->sc_data;
sc->sc_sysmon.sme_cookie = sc;
extern struct cfdriver viaenv_cd;
sc->sc_sysmon.sme_gtredata = viaenv_gtredata;
sc->sc_sysmon.sme_streinfo = viaenv_streinfo;
int viaenv_open(dev_t, int, int, struct proc *);
int viaenv_close(dev_t, int, int, struct proc *);
int viaenv_ioctl(dev_t, u_long, caddr_t, int, struct proc *);
sc->sc_sysmon.sme_nsensors = VIANUMSENSORS;
sc->sc_sysmon.sme_envsys_version = 1000;
int
viaenv_open(dev_t dev, int flag, int mode, struct proc * p)
{
int unit = minor(dev);
struct viaenv_softc *sc;
if (unit >= viaenv_cd.cd_ndevs)
return ENXIO;
sc = viaenv_cd.cd_devs[unit];
if (sc == NULL)
return ENXIO;
if (sc->sc_flags & SCFLAG_OPEN)
return EBUSY;
sc->sc_flags |= SCFLAG_OPEN;
return 0;
}
int
viaenv_close(dev_t dev, int flag, int mode, struct proc * p)
{
struct viaenv_softc *sc = viaenv_cd.cd_devs[minor(dev)];
sc->sc_flags &= ~SCFLAG_OPEN;
return 0;
if (sysmon_envsys_register(&sc->sc_sysmon))
printf("%s: unable to register with sysmon\n",
sc->sc_dev.dv_xname);
}
int
viaenv_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc * p)
viaenv_gtredata(struct sysmon_envsys *sme, struct envsys_tre_data *tred)
{
struct viaenv_softc *sc = viaenv_cd.cd_devs[minor(dev)];
struct envsys_range *rng;
struct envsys_tre_data *tred;
struct envsys_basic_info *binfo;
int32_t *vers;
sc = sc;
struct viaenv_softc *sc = sme->sme_cookie;
switch (cmd) {
case ENVSYS_VERSION:
vers = (int32_t *) data;
*vers = 1000;
(void) lockmgr(&sc->sc_lock, LK_SHARED, NULL);
*tred = sc->sc_data[tred->sensor];
(void) lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
return (0);
}
int
viaenv_streinfo(struct sysmon_envsys *sme, struct envsys_basic_info *binfo)
{
/* XXX Not implemented */
binfo->validflags = 0;
return (0);
case ENVSYS_GRANGE:
rng = (struct envsys_range *) data;
switch (rng->units) {
case ENVSYS_STEMP:
rng->low = 0;
rng->high = 2;
break;
case ENVSYS_SFANRPM:
rng->low = 3;
rng->high = 4;
break;
case ENVSYS_SVOLTS_DC:
rng->low = 5;
rng->high = 11;
break;
default:
rng->low = 1;
rng->high = 0;
break;
}
return 0;
case ENVSYS_GTREDATA:
tred = (struct envsys_tre_data *) data;
tred->validflags = 0;
if (tred->sensor < VIANUMSENSORS) {
lockmgr(&sc->sc_lock, LK_SHARED, NULL);
memcpy(tred, &sc->sc_data[tred->sensor], sizeof(*tred));
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
}
return 0;
case ENVSYS_GTREINFO:
binfo = (struct envsys_basic_info *) data;
if (binfo->sensor >= VIANUMSENSORS)
binfo->validflags = 0;
else
memcpy(binfo, &sc->sc_info[binfo->sensor],
sizeof(*binfo));
return 0;
#if 0
/* not yet implemented */
case ENVSYS_STREINFO:
binfo = (struct envsys_basic_info *) data;
binfo->validflags = 0;
return 0;
#endif
default:
return ENOTTY;
}
}

305
sys/dev/sysmon/sysmon.c Normal file
View File

@ -0,0 +1,305 @@
/* $NetBSD: sysmon.c,v 1.1 2000/06/24 00:37:20 thorpej Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
* All rights reserved.
*
* Author: Jason R. Thorpe <thorpej@zembu.com>
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Zembu Labs, Inc.
* 4. Neither the name of Zembu Labs nor the names of its employees may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
* RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
* CLAIMED. IN NO EVENT SHALL ZEMBU LABS 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.
*/
/*
* Clearing house for system monitoring hardware. This pseudo-device
* is a place where hardware monitors such as the LM78 and VIA 82C686A
* (or even ACPI, eventually) can register themselves to provide
* backplane fan and temperature information, etc.
*
* Eventually, we will also provide a way for a hardware watchdog timer
* to hook itself up here (with an option to fall back on a software
* watchdog timer if hardware is not available).
*/
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/lock.h>
#include <dev/sysmon/sysmonvar.h>
/*
* We run at ENVSYS version 1.
*/
#define SYSMON_ENVSYS_VERSION (1 * 1000)
struct lock sysmon_lock;
LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
struct simplelock sysmon_envsys_list_slock = SIMPLELOCK_INITIALIZER;
u_int sysmon_envsys_next_sensor_index;
int sysmon_initialized;
struct simplelock sysmon_initialized_slock = SIMPLELOCK_INITIALIZER;
cdev_decl(sysmon);
void sysmon_init(void);
struct sysmon_envsys *sysmon_envsys_find(u_int);
void sysmon_envsys_release(struct sysmon_envsys *);
/*
* sysmon_init:
*
* Initialize the system monitor.
*/
void
sysmon_init(void)
{
lockinit(&sysmon_lock, PWAIT, "sysmon", 0, 0);
sysmon_initialized = 1;
}
/*
* sysmonopen:
*
* Open the system monitor device.
*/
int
sysmonopen(dev_t dev, int flag, int mode, struct proc *p)
{
int error;
simple_lock(&sysmon_initialized_slock);
if (sysmon_initialized == 0)
sysmon_init();
error = lockmgr(&sysmon_lock,
LK_EXCLUSIVE | LK_INTERLOCK |
((flag & O_NONBLOCK) ? LK_NOWAIT : 0), &sysmon_initialized_slock);
return (error);
}
/*
* sysmonclose:
*
* Close the system monitor device.
*/
int
sysmonclose(dev_t dev, int flag, int mode, struct proc *p)
{
(void) lockmgr(&sysmon_lock, LK_RELEASE, NULL);
return (0);
}
/*
* sysmonioctl:
*
* Perform a control request.
*/
int
sysmonioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
{
struct sysmon_envsys *sme;
int error = 0;
u_int oidx;
switch (cmd) {
/*
* For ENVSYS commands, we translate the absolute sensor index
* to a device-relative sensor index.
*/
case ENVSYS_VERSION:
*(int32_t *)data = SYSMON_ENVSYS_VERSION;
break;
case ENVSYS_GRANGE:
{
struct envsys_range *rng = (void *) data;
sme = sysmon_envsys_find(0); /* XXX */
if (sme == NULL) {
/* Return empty range for `no sensors'. */
rng->low = 1;
rng->high = 0;
break;
}
if (rng->units < ENVSYS_NSENSORS)
*rng = sme->sme_ranges[rng->units];
else {
/* Return empty range for unsupported sensor types. */
rng->low = 1;
rng->high = 0;
}
sysmon_envsys_release(sme);
break;
}
case ENVSYS_GTREDATA:
{
struct envsys_tre_data *tred = (void *) data;
sme = sysmon_envsys_find(tred->sensor);
if (sme == NULL)
break;
oidx = tred->sensor;
tred->sensor = SME_SENSOR_IDX(sme, tred->sensor);
if (tred->sensor < sme->sme_nsensors)
error = (*sme->sme_gtredata)(sme, tred);
else
tred->validflags = 0;
tred->sensor = oidx;
sysmon_envsys_release(sme);
break;
}
case ENVSYS_STREINFO:
{
struct envsys_basic_info *binfo = (void *) data;
sme = sysmon_envsys_find(binfo->sensor);
oidx = binfo->sensor;
binfo->sensor = SME_SENSOR_IDX(sme, binfo->sensor);
if (binfo->sensor < sme->sme_nsensors)
error = (*sme->sme_streinfo)(sme, binfo);
else
binfo->validflags = 0;
binfo->sensor = oidx;
sysmon_envsys_release(sme);
break;
}
case ENVSYS_GTREINFO:
{
struct envsys_basic_info *binfo = (void *) data;
sme = sysmon_envsys_find(binfo->sensor);
oidx = binfo->sensor;
binfo->sensor = SME_SENSOR_IDX(sme, binfo->sensor);
if (binfo->sensor < sme->sme_nsensors)
*binfo = sme->sme_sensor_info[binfo->sensor];
else
binfo->validflags = 0;
binfo->sensor = oidx;
sysmon_envsys_release(sme);
break;
}
default:
error = ENOTTY;
}
return (error);
}
/*
* sysmon_envsys_register:
*
* Register an ENVSYS device.
*/
int
sysmon_envsys_register(struct sysmon_envsys *sme)
{
int error = 0;
simple_lock(&sysmon_envsys_list_slock);
/* XXX Only get to register one, for now. */
if (LIST_FIRST(&sysmon_envsys_list) != NULL) {
error = EEXIST;
goto out;
}
if (sme->sme_envsys_version != SYSMON_ENVSYS_VERSION) {
error = EINVAL;
goto out;
}
sme->sme_fsensor = sysmon_envsys_next_sensor_index;
sysmon_envsys_next_sensor_index += sme->sme_nsensors;
LIST_INSERT_HEAD(&sysmon_envsys_list, sme, sme_list);
out:
simple_unlock(&sysmon_envsys_list_slock);
return (error);
}
/*
* sysmon_envsys_unregister:
*
* Unregister an ENVSYS device.
*/
void
sysmon_envsys_unregister(struct sysmon_envsys *sme)
{
simple_lock(&sysmon_envsys_list_slock);
LIST_REMOVE(sme, sme_list);
simple_unlock(&sysmon_envsys_list_slock);
}
/*
* sysmon_envsys_find:
*
* Find an ENVSYS device. The list remains locked upon
* a match.
*/
struct sysmon_envsys *
sysmon_envsys_find(u_int idx)
{
struct sysmon_envsys *sme;
simple_lock(&sysmon_envsys_list_slock);
for (sme = LIST_FIRST(&sysmon_envsys_list); sme != NULL;
sme = LIST_NEXT(sme, sme_list)) {
if (idx >= sme->sme_fsensor &&
idx < (sme->sme_fsensor + sme->sme_nsensors))
return (sme);
}
simple_unlock(&sysmon_envsys_list_slock);
return (NULL);
}
/*
* sysmon_envsys_release:
*
* Release an ENVSYS device.
*/
/* ARGSUSED */
void
sysmon_envsys_release(struct sysmon_envsys *sme)
{
simple_unlock(&sysmon_envsys_list_slock);
}

View File

@ -0,0 +1,65 @@
/* $NetBSD: sysmonvar.h,v 1.1 2000/06/24 00:37:20 thorpej Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
* All rights reserved.
*
* Author: Jason R. Thorpe <thorpej@zembu.com>
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Zembu Labs, Inc.
* 4. Neither the name of Zembu Labs nor the names of its employees may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
* RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
* CLAIMED. IN NO EVENT SHALL ZEMBU LABS 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.
*/
#ifndef _DEV_SYSMON_SYSMONVAR_H_
#define _DEV_SYSMON_SYSMONVAR_H_
#include <sys/envsys.h>
#include <sys/queue.h>
struct sysmon_envsys {
int32_t sme_envsys_version; /* ENVSYS API version */
LIST_ENTRY(sysmon_envsys) sme_list;
const struct envsys_range *sme_ranges;
struct envsys_basic_info *sme_sensor_info;
struct envsys_tre_data *sme_sensor_data;
void *sme_cookie; /* for ENVSYS back-end */
/* Callbacks */
int (*sme_gtredata)(struct sysmon_envsys *, struct envsys_tre_data *);
int (*sme_streinfo)(struct sysmon_envsys *, struct envsys_basic_info *);
u_int sme_fsensor; /* sensor index base, from sysmon */
u_int sme_nsensors; /* sensor count, from driver */
};
#define SME_SENSOR_IDX(sme, idx) ((idx) - (sme)->sme_fsensor)
int sysmon_envsys_register(struct sysmon_envsys *);
void sysmon_envsys_unregister(struct sysmon_envsys *);
#endif /* _DEV_SYSMON_SYSMONVAR_H_ */