sysmon.c revision 1.4.2.3 1 1.4.2.3 bouyer /* $NetBSD: sysmon.c,v 1.4.2.3 2000/11/22 16:04:53 bouyer Exp $ */
2 1.4.2.2 bouyer
3 1.4.2.2 bouyer /*-
4 1.4.2.2 bouyer * Copyright (c) 2000 Zembu Labs, Inc.
5 1.4.2.2 bouyer * All rights reserved.
6 1.4.2.2 bouyer *
7 1.4.2.2 bouyer * Author: Jason R. Thorpe <thorpej (at) zembu.com>
8 1.4.2.2 bouyer *
9 1.4.2.2 bouyer * Redistribution and use in source and binary forms, with or without
10 1.4.2.2 bouyer * modification, are permitted provided that the following conditions
11 1.4.2.2 bouyer * are met:
12 1.4.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.4.2.2 bouyer * notice, this list of conditions and the following disclaimer.
14 1.4.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.4.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.4.2.2 bouyer * documentation and/or other materials provided with the distribution.
17 1.4.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
18 1.4.2.2 bouyer * must display the following acknowledgement:
19 1.4.2.2 bouyer * This product includes software developed by Zembu Labs, Inc.
20 1.4.2.2 bouyer * 4. Neither the name of Zembu Labs nor the names of its employees may
21 1.4.2.2 bouyer * be used to endorse or promote products derived from this software
22 1.4.2.2 bouyer * without specific prior written permission.
23 1.4.2.2 bouyer *
24 1.4.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
25 1.4.2.2 bouyer * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
26 1.4.2.2 bouyer * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
27 1.4.2.2 bouyer * CLAIMED. IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.4.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.4.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.4.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.4.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.4.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.4.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.4.2.2 bouyer */
35 1.4.2.2 bouyer
36 1.4.2.2 bouyer /*
37 1.4.2.3 bouyer * Clearing house for system monitoring hardware. We currently
38 1.4.2.3 bouyer * handle environmental sensors and watchdog timers.
39 1.4.2.2 bouyer */
40 1.4.2.2 bouyer
41 1.4.2.2 bouyer #include <sys/param.h>
42 1.4.2.2 bouyer #include <sys/conf.h>
43 1.4.2.2 bouyer #include <sys/errno.h>
44 1.4.2.2 bouyer #include <sys/fcntl.h>
45 1.4.2.2 bouyer #include <sys/lock.h>
46 1.4.2.3 bouyer #include <sys/callout.h>
47 1.4.2.3 bouyer #include <sys/kernel.h>
48 1.4.2.3 bouyer #include <sys/systm.h>
49 1.4.2.3 bouyer #include <sys/proc.h>
50 1.4.2.2 bouyer
51 1.4.2.2 bouyer #include <dev/sysmon/sysmonvar.h>
52 1.4.2.3 bouyer #include <dev/sysmon/sysmonconf.h>
53 1.4.2.2 bouyer
54 1.4.2.2 bouyer cdev_decl(sysmon);
55 1.4.2.2 bouyer
56 1.4.2.2 bouyer /*
57 1.4.2.2 bouyer * sysmonopen:
58 1.4.2.2 bouyer *
59 1.4.2.2 bouyer * Open the system monitor device.
60 1.4.2.2 bouyer */
61 1.4.2.2 bouyer int
62 1.4.2.2 bouyer sysmonopen(dev_t dev, int flag, int mode, struct proc *p)
63 1.4.2.2 bouyer {
64 1.4.2.2 bouyer int error;
65 1.4.2.2 bouyer
66 1.4.2.3 bouyer switch (minor(dev)) {
67 1.4.2.3 bouyer #if NSYSMON_ENVSYS > 0
68 1.4.2.3 bouyer case SYSMON_MINOR_ENVSYS:
69 1.4.2.3 bouyer error = sysmonopen_envsys(dev, flag, mode, p);
70 1.4.2.3 bouyer break;
71 1.4.2.3 bouyer #endif
72 1.4.2.3 bouyer #if NSYSMON_WDOG > 0
73 1.4.2.3 bouyer case SYSMON_MINOR_WDOG:
74 1.4.2.3 bouyer error = sysmonopen_wdog(dev, flag, mode, p);
75 1.4.2.3 bouyer break;
76 1.4.2.3 bouyer #endif
77 1.4.2.3 bouyer default:
78 1.4.2.3 bouyer error = ENODEV;
79 1.4.2.3 bouyer }
80 1.4.2.2 bouyer
81 1.4.2.2 bouyer return (error);
82 1.4.2.2 bouyer }
83 1.4.2.2 bouyer
84 1.4.2.2 bouyer /*
85 1.4.2.2 bouyer * sysmonclose:
86 1.4.2.2 bouyer *
87 1.4.2.2 bouyer * Close the system monitor device.
88 1.4.2.2 bouyer */
89 1.4.2.2 bouyer int
90 1.4.2.2 bouyer sysmonclose(dev_t dev, int flag, int mode, struct proc *p)
91 1.4.2.2 bouyer {
92 1.4.2.3 bouyer int error;
93 1.4.2.2 bouyer
94 1.4.2.3 bouyer switch (minor(dev)) {
95 1.4.2.3 bouyer #if NSYSMON_ENVSYS > 0
96 1.4.2.3 bouyer case SYSMON_MINOR_ENVSYS:
97 1.4.2.3 bouyer error = sysmonclose_envsys(dev, flag, mode, p);
98 1.4.2.2 bouyer break;
99 1.4.2.3 bouyer #endif
100 1.4.2.3 bouyer #if NSYSMON_WDOG > 0
101 1.4.2.3 bouyer case SYSMON_MINOR_WDOG:
102 1.4.2.3 bouyer error = sysmonclose_wdog(dev, flag, mode, p);
103 1.4.2.2 bouyer break;
104 1.4.2.3 bouyer #endif
105 1.4.2.2 bouyer default:
106 1.4.2.3 bouyer error = ENODEV;
107 1.4.2.2 bouyer }
108 1.4.2.2 bouyer
109 1.4.2.2 bouyer return (error);
110 1.4.2.2 bouyer }
111 1.4.2.2 bouyer
112 1.4.2.2 bouyer /*
113 1.4.2.3 bouyer * sysmonioctl:
114 1.4.2.2 bouyer *
115 1.4.2.3 bouyer * Perform a control request.
116 1.4.2.2 bouyer */
117 1.4.2.2 bouyer int
118 1.4.2.3 bouyer sysmonioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
119 1.4.2.2 bouyer {
120 1.4.2.3 bouyer int error;
121 1.4.2.2 bouyer
122 1.4.2.3 bouyer switch (minor(dev)) {
123 1.4.2.3 bouyer #if NSYSMON_ENVSYS > 0
124 1.4.2.3 bouyer case SYSMON_MINOR_ENVSYS:
125 1.4.2.3 bouyer error = sysmonioctl_envsys(dev, cmd, data, flag, p);
126 1.4.2.3 bouyer break;
127 1.4.2.3 bouyer #endif
128 1.4.2.3 bouyer #if NSYSMON_WDOG > 0
129 1.4.2.3 bouyer case SYSMON_MINOR_WDOG:
130 1.4.2.3 bouyer error = sysmonioctl_wdog(dev, cmd, data, flag, p);
131 1.4.2.3 bouyer break;
132 1.4.2.3 bouyer #endif
133 1.4.2.3 bouyer default:
134 1.4.2.3 bouyer error = ENODEV;
135 1.4.2.2 bouyer }
136 1.4.2.2 bouyer
137 1.4.2.2 bouyer return (error);
138 1.4.2.2 bouyer }
139