Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / sysmon / sysmon.c
blobec7a510ba97382f5060b978265bae7ac85b7dff9
1 /* $NetBSD: sysmon.c,v 1.16 2008/01/04 21:18:06 ad Exp $ */
3 /*-
4 * Copyright (c) 2000 Zembu Labs, Inc.
5 * All rights reserved.
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
11 * are met:
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>
45 #include <sys/conf.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>
51 #include <sys/proc.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,
69 * sysmonopen:
71 * Open the system monitor device.
73 int
74 sysmonopen(dev_t dev, int flag, int mode, struct lwp *l)
76 int error;
78 switch (minor(dev)) {
79 #if NSYSMON_ENVSYS > 0
80 case SYSMON_MINOR_ENVSYS:
81 error = sysmonopen_envsys(dev, flag, mode, l);
82 break;
83 #endif
84 #if NSYSMON_WDOG > 0
85 case SYSMON_MINOR_WDOG:
86 error = sysmonopen_wdog(dev, flag, mode, l);
87 break;
88 #endif
89 #if NSYSMON_POWER > 0
90 case SYSMON_MINOR_POWER:
91 error = sysmonopen_power(dev, flag, mode, l);
92 break;
93 #endif
94 default:
95 error = ENODEV;
98 return (error);
102 * sysmonclose:
104 * Close the system monitor device.
107 sysmonclose(dev_t dev, int flag, int mode, struct lwp *l)
109 int error;
111 switch (minor(dev)) {
112 #if NSYSMON_ENVSYS > 0
113 case SYSMON_MINOR_ENVSYS:
114 error = sysmonclose_envsys(dev, flag, mode, l);
115 break;
116 #endif
117 #if NSYSMON_WDOG > 0
118 case SYSMON_MINOR_WDOG:
119 error = sysmonclose_wdog(dev, flag, mode, l);
120 break;
121 #endif
122 #if NSYSMON_POWER > 0
123 case SYSMON_MINOR_POWER:
124 error = sysmonclose_power(dev, flag, mode, l);
125 break;
126 #endif
127 default:
128 error = ENODEV;
131 return (error);
135 * sysmonioctl:
137 * Perform a control request.
140 sysmonioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
142 int error;
144 switch (minor(dev)) {
145 #if NSYSMON_ENVSYS > 0
146 case SYSMON_MINOR_ENVSYS:
147 error = sysmonioctl_envsys(dev, cmd, data, flag, l);
148 break;
149 #endif
150 #if NSYSMON_WDOG > 0
151 case SYSMON_MINOR_WDOG:
152 error = sysmonioctl_wdog(dev, cmd, data, flag, l);
153 break;
154 #endif
155 #if NSYSMON_POWER > 0
156 case SYSMON_MINOR_POWER:
157 error = sysmonioctl_power(dev, cmd, data, flag, l);
158 break;
159 #endif
160 default:
161 error = ENODEV;
164 return (error);
168 * sysmonread:
170 * Perform a read request.
173 sysmonread(dev_t dev, struct uio *uio, int flags)
175 int error;
177 switch (minor(dev)) {
178 #if NSYSMON_POWER > 0
179 case SYSMON_MINOR_POWER:
180 error = sysmonread_power(dev, uio, flags);
181 break;
182 #endif
183 default:
184 error = ENODEV;
187 return (error);
191 * sysmonpoll:
193 * Poll the system monitor device.
196 sysmonpoll(dev_t dev, int events, struct lwp *l)
198 int rv;
200 switch (minor(dev)) {
201 #if NSYSMON_POWER > 0
202 case SYSMON_MINOR_POWER:
203 rv = sysmonpoll_power(dev, events, l);
204 break;
205 #endif
206 default:
207 rv = events;
210 return (rv);
214 * sysmonkqfilter:
216 * Kqueue filter for the system monitor device.
219 sysmonkqfilter(dev_t dev, struct knote *kn)
221 int error;
223 switch (minor(dev)) {
224 #if NSYSMON_POWER > 0
225 case SYSMON_MINOR_POWER:
226 error = sysmonkqfilter_power(dev, kn);
227 break;
228 #endif
229 default:
230 error = 1;
233 return (error);