1 /* $NetBSD: sysmon.c,v 1.16 2008/01/04 21:18:06 ad Exp $ */
4 * Copyright (c) 2000 Zembu Labs, Inc.
7 * Author: Jason R. Thorpe <thorpej@zembu.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Zembu Labs, Inc.
20 * 4. Neither the name of Zembu Labs nor the names of its employees may
21 * be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
26 * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
27 * CLAIMED. IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Clearing house for system monitoring hardware. We currently
38 * handle environmental sensors, watchdog timers, and power management.
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.16 2008/01/04 21:18:06 ad Exp $");
44 #include <sys/param.h>
46 #include <sys/errno.h>
47 #include <sys/fcntl.h>
48 #include <sys/callout.h>
49 #include <sys/kernel.h>
50 #include <sys/systm.h>
53 #include <dev/sysmon/sysmonvar.h>
54 #include <dev/sysmon/sysmonconf.h>
56 dev_type_open(sysmonopen
);
57 dev_type_close(sysmonclose
);
58 dev_type_ioctl(sysmonioctl
);
59 dev_type_read(sysmonread
);
60 dev_type_poll(sysmonpoll
);
61 dev_type_kqfilter(sysmonkqfilter
);
63 const struct cdevsw sysmon_cdevsw
= {
64 sysmonopen
, sysmonclose
, sysmonread
, nowrite
, sysmonioctl
,
65 nostop
, notty
, sysmonpoll
, nommap
, sysmonkqfilter
, D_OTHER
| D_MPSAFE
,
71 * Open the system monitor device.
74 sysmonopen(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
79 #if NSYSMON_ENVSYS > 0
80 case SYSMON_MINOR_ENVSYS
:
81 error
= sysmonopen_envsys(dev
, flag
, mode
, l
);
85 case SYSMON_MINOR_WDOG
:
86 error
= sysmonopen_wdog(dev
, flag
, mode
, l
);
90 case SYSMON_MINOR_POWER
:
91 error
= sysmonopen_power(dev
, flag
, mode
, l
);
104 * Close the system monitor device.
107 sysmonclose(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
111 switch (minor(dev
)) {
112 #if NSYSMON_ENVSYS > 0
113 case SYSMON_MINOR_ENVSYS
:
114 error
= sysmonclose_envsys(dev
, flag
, mode
, l
);
118 case SYSMON_MINOR_WDOG
:
119 error
= sysmonclose_wdog(dev
, flag
, mode
, l
);
122 #if NSYSMON_POWER > 0
123 case SYSMON_MINOR_POWER
:
124 error
= sysmonclose_power(dev
, flag
, mode
, l
);
137 * Perform a control request.
140 sysmonioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
144 switch (minor(dev
)) {
145 #if NSYSMON_ENVSYS > 0
146 case SYSMON_MINOR_ENVSYS
:
147 error
= sysmonioctl_envsys(dev
, cmd
, data
, flag
, l
);
151 case SYSMON_MINOR_WDOG
:
152 error
= sysmonioctl_wdog(dev
, cmd
, data
, flag
, l
);
155 #if NSYSMON_POWER > 0
156 case SYSMON_MINOR_POWER
:
157 error
= sysmonioctl_power(dev
, cmd
, data
, flag
, l
);
170 * Perform a read request.
173 sysmonread(dev_t dev
, struct uio
*uio
, int flags
)
177 switch (minor(dev
)) {
178 #if NSYSMON_POWER > 0
179 case SYSMON_MINOR_POWER
:
180 error
= sysmonread_power(dev
, uio
, flags
);
193 * Poll the system monitor device.
196 sysmonpoll(dev_t dev
, int events
, struct lwp
*l
)
200 switch (minor(dev
)) {
201 #if NSYSMON_POWER > 0
202 case SYSMON_MINOR_POWER
:
203 rv
= sysmonpoll_power(dev
, events
, l
);
216 * Kqueue filter for the system monitor device.
219 sysmonkqfilter(dev_t dev
, struct knote
*kn
)
223 switch (minor(dev
)) {
224 #if NSYSMON_POWER > 0
225 case SYSMON_MINOR_POWER
:
226 error
= sysmonkqfilter_power(dev
, kn
);