| @@ -1,503 +1,502 @@ | | | @@ -1,503 +1,502 @@ |
1 | /* $NetBSD: wsbell.c,v 1.5 2017/06/13 00:42:27 nat Exp $ */ | | 1 | /* $NetBSD: wsbell.c,v 1.6 2017/06/13 00:49:05 nat Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au> | | 4 | * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Copyright (c) 2006 The NetBSD Foundation, Inc. | | 7 | * Copyright (c) 2006 The NetBSD Foundation, Inc. |
8 | * All rights reserved. | | 8 | * All rights reserved. |
9 | * | | 9 | * |
10 | * This code is derived from software contributed to The NetBSD Foundation | | 10 | * This code is derived from software contributed to The NetBSD Foundation |
11 | * by Julio M. Merino Vidal. | | 11 | * by Julio M. Merino Vidal. |
12 | * | | 12 | * |
13 | * Redistribution and use in source and binary forms, with or without | | 13 | * Redistribution and use in source and binary forms, with or without |
14 | * modification, are permitted provided that the following conditions | | 14 | * modification, are permitted provided that the following conditions |
15 | * are met: | | 15 | * are met: |
16 | * 1. Redistributions of source code must retain the above copyright | | 16 | * 1. Redistributions of source code must retain the above copyright |
17 | * notice, this list of conditions and the following disclaimer. | | 17 | * notice, this list of conditions and the following disclaimer. |
18 | * 2. Redistributions in binary form must reproduce the above copyright | | 18 | * 2. Redistributions in binary form must reproduce the above copyright |
19 | * notice, this list of conditions and the following disclaimer in the | | 19 | * notice, this list of conditions and the following disclaimer in the |
20 | * documentation and/or other materials provided with the distribution. | | 20 | * documentation and/or other materials provided with the distribution. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 22 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
23 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 23 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
24 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 24 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 | * POSSIBILITY OF SUCH DAMAGE. | | 32 | * POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | /* | | 35 | /* |
36 | * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. | | 36 | * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. |
37 | * | | 37 | * |
38 | * Redistribution and use in source and binary forms, with or without | | 38 | * Redistribution and use in source and binary forms, with or without |
39 | * modification, are permitted provided that the following conditions | | 39 | * modification, are permitted provided that the following conditions |
40 | * are met: | | 40 | * are met: |
41 | * 1. Redistributions of source code must retain the above copyright | | 41 | * 1. Redistributions of source code must retain the above copyright |
42 | * notice, this list of conditions and the following disclaimer. | | 42 | * notice, this list of conditions and the following disclaimer. |
43 | * 2. Redistributions in binary form must reproduce the above copyright | | 43 | * 2. Redistributions in binary form must reproduce the above copyright |
44 | * notice, this list of conditions and the following disclaimer in the | | 44 | * notice, this list of conditions and the following disclaimer in the |
45 | * documentation and/or other materials provided with the distribution. | | 45 | * documentation and/or other materials provided with the distribution. |
46 | * 3. All advertising materials mentioning features or use of this software | | 46 | * 3. All advertising materials mentioning features or use of this software |
47 | * must display the following acknowledgement: | | 47 | * must display the following acknowledgement: |
48 | * This product includes software developed by Christopher G. Demetriou | | 48 | * This product includes software developed by Christopher G. Demetriou |
49 | * for the NetBSD Project. | | 49 | * for the NetBSD Project. |
50 | * 4. The name of the author may not be used to endorse or promote products | | 50 | * 4. The name of the author may not be used to endorse or promote products |
51 | * derived from this software without specific prior written permission | | 51 | * derived from this software without specific prior written permission |
52 | * | | 52 | * |
53 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 53 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
54 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 54 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
55 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 55 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
56 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 56 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
57 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 57 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
58 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 58 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
62 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 62 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
63 | */ | | 63 | */ |
64 | | | 64 | |
65 | /* | | 65 | /* |
66 | * Copyright (c) 1992, 1993 | | 66 | * Copyright (c) 1992, 1993 |
67 | * The Regents of the University of California. All rights reserved. | | 67 | * The Regents of the University of California. All rights reserved. |
68 | * | | 68 | * |
69 | * This software was developed by the Computer Systems Engineering group | | 69 | * This software was developed by the Computer Systems Engineering group |
70 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | | 70 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
71 | * contributed to Berkeley. | | 71 | * contributed to Berkeley. |
72 | * | | 72 | * |
73 | * All advertising materials mentioning features or use of this software | | 73 | * All advertising materials mentioning features or use of this software |
74 | * must display the following acknowledgement: | | 74 | * must display the following acknowledgement: |
75 | * This product includes software developed by the University of | | 75 | * This product includes software developed by the University of |
76 | * California, Lawrence Berkeley Laboratory. | | 76 | * California, Lawrence Berkeley Laboratory. |
77 | * | | 77 | * |
78 | * Redistribution and use in source and binary forms, with or without | | 78 | * Redistribution and use in source and binary forms, with or without |
79 | * modification, are permitted provided that the following conditions | | 79 | * modification, are permitted provided that the following conditions |
80 | * are met: | | 80 | * are met: |
81 | * 1. Redistributions of source code must retain the above copyright | | 81 | * 1. Redistributions of source code must retain the above copyright |
82 | * notice, this list of conditions and the following disclaimer. | | 82 | * notice, this list of conditions and the following disclaimer. |
83 | * 2. Redistributions in binary form must reproduce the above copyright | | 83 | * 2. Redistributions in binary form must reproduce the above copyright |
84 | * notice, this list of conditions and the following disclaimer in the | | 84 | * notice, this list of conditions and the following disclaimer in the |
85 | * documentation and/or other materials provided with the distribution. | | 85 | * documentation and/or other materials provided with the distribution. |
86 | * 3. Neither the name of the University nor the names of its contributors | | 86 | * 3. Neither the name of the University nor the names of its contributors |
87 | * may be used to endorse or promote products derived from this software | | 87 | * may be used to endorse or promote products derived from this software |
88 | * without specific prior written permission. | | 88 | * without specific prior written permission. |
89 | * | | 89 | * |
90 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 90 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
91 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 91 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
92 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 92 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
93 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 93 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
94 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 94 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
95 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 95 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
96 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 96 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
97 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 97 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
98 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 98 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
99 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 99 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
100 | * SUCH DAMAGE. | | 100 | * SUCH DAMAGE. |
101 | * | | 101 | * |
102 | * @(#)ms.c 8.1 (Berkeley) 6/11/93 | | 102 | * @(#)ms.c 8.1 (Berkeley) 6/11/93 |
103 | */ | | 103 | */ |
104 | | | 104 | |
105 | /* | | 105 | /* |
106 | * Keyboard Bell driver. | | 106 | * Keyboard Bell driver. |
107 | */ | | 107 | */ |
108 | | | 108 | |
109 | #include <sys/cdefs.h> | | 109 | #include <sys/cdefs.h> |
110 | __KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.5 2017/06/13 00:42:27 nat Exp $"); | | 110 | __KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.6 2017/06/13 00:49:05 nat Exp $"); |
111 | | | 111 | |
112 | #if defined(_KERNEL_OPT) | | 112 | #if defined(_KERNEL_OPT) |
113 | #include "wsmux.h" | | 113 | #include "wsmux.h" |
114 | #endif | | 114 | #endif |
115 | | | 115 | |
116 | #include <sys/param.h> | | 116 | #include <sys/param.h> |
117 | #include <sys/conf.h> | | 117 | #include <sys/conf.h> |
118 | #include <sys/ioctl.h> | | 118 | #include <sys/ioctl.h> |
119 | #include <sys/poll.h> | | 119 | #include <sys/poll.h> |
120 | #include <sys/fcntl.h> | | 120 | #include <sys/fcntl.h> |
121 | #include <sys/kernel.h> | | 121 | #include <sys/kernel.h> |
122 | #include <sys/condvar.h> | | 122 | #include <sys/condvar.h> |
123 | #include <sys/mutex.h> | | 123 | #include <sys/mutex.h> |
124 | #include <sys/kthread.h> | | 124 | #include <sys/kthread.h> |
125 | #include <sys/proc.h> | | 125 | #include <sys/proc.h> |
126 | #include <sys/syslog.h> | | 126 | #include <sys/syslog.h> |
127 | #include <sys/systm.h> | | 127 | #include <sys/systm.h> |
128 | #include <sys/tty.h> | | 128 | #include <sys/tty.h> |
129 | #include <sys/signalvar.h> | | 129 | #include <sys/signalvar.h> |
130 | #include <sys/device.h> | | 130 | #include <sys/device.h> |
131 | #include <sys/vnode.h> | | 131 | #include <sys/vnode.h> |
132 | #include <sys/callout.h> | | 132 | #include <sys/callout.h> |
133 | #include <sys/malloc.h> | | 133 | #include <sys/malloc.h> |
134 | #include <sys/module.h> | | 134 | #include <sys/module.h> |
135 | | | 135 | |
136 | #include <dev/wscons/wsconsio.h> | | 136 | #include <dev/wscons/wsconsio.h> |
137 | #include <dev/wscons/wsbellvar.h> | | 137 | #include <dev/wscons/wsbellvar.h> |
138 | #include <dev/wscons/wsbellmuxvar.h> | | 138 | #include <dev/wscons/wsbellmuxvar.h> |
139 | #include <dev/wscons/wsbelldata.h> | | 139 | #include <dev/wscons/wsbelldata.h> |
140 | | | 140 | |
141 | #include <dev/spkrio.h> | | 141 | #include <dev/spkrio.h> |
142 | | | 142 | |
143 | #include "ioconf.h" | | 143 | #include "ioconf.h" |
144 | | | 144 | |
145 | #if defined(WSMUX_DEBUG) && NWSMUX > 0 | | 145 | #if defined(WSMUX_DEBUG) && NWSMUX > 0 |
146 | #define DPRINTF(x) if (wsmuxdebug) printf x | | 146 | #define DPRINTF(x) if (wsmuxdebug) printf x |
147 | #define DPRINTFN(n,x) if (wsmuxdebug > (n)) printf x | | 147 | #define DPRINTFN(n,x) if (wsmuxdebug > (n)) printf x |
148 | extern int wsmuxdebug; | | 148 | extern int wsmuxdebug; |
149 | #else | | 149 | #else |
150 | #define DPRINTF(x) | | 150 | #define DPRINTF(x) |
151 | #define DPRINTFN(n,x) | | 151 | #define DPRINTFN(n,x) |
152 | #endif | | 152 | #endif |
153 | | | 153 | |
154 | static void bell_thread(void *); | | 154 | static void bell_thread(void *); |
155 | static inline void spkr_audio_play(struct wsbell_softc *, u_int, u_int, u_int); | | 155 | static inline void spkr_audio_play(struct wsbell_softc *, u_int, u_int, u_int); |
156 | | | 156 | |
157 | static int wsbell_match(device_t, cfdata_t, void *); | | 157 | static int wsbell_match(device_t, cfdata_t, void *); |
158 | static void wsbell_attach(device_t, device_t, void *); | | 158 | static void wsbell_attach(device_t, device_t, void *); |
159 | static int wsbell_detach(device_t, int); | | 159 | static int wsbell_detach(device_t, int); |
160 | static int wsbell_activate(device_t, enum devact); | | 160 | static int wsbell_activate(device_t, enum devact); |
161 | | | 161 | |
162 | #if NWSMUX > 0 | | 162 | #if NWSMUX > 0 |
163 | static int wsbell_mux_open(struct wsevsrc *, struct wseventvar *); | | 163 | static int wsbell_mux_open(struct wsevsrc *, struct wseventvar *); |
164 | static int wsbell_mux_close(struct wsevsrc *); | | 164 | static int wsbell_mux_close(struct wsevsrc *); |
165 | | | 165 | |
166 | static int wsbelldoopen(struct wsbell_softc *, struct wseventvar *); | | 166 | static int wsbelldoopen(struct wsbell_softc *, struct wseventvar *); |
167 | static int wsbelldoioctl(device_t, u_long, void *, int, struct lwp *); | | 167 | static int wsbelldoioctl(device_t, u_long, void *, int, struct lwp *); |
168 | | | 168 | |
169 | static int wsbell_do_ioctl(struct wsbell_softc *, u_long, void *, | | 169 | static int wsbell_do_ioctl(struct wsbell_softc *, u_long, void *, |
170 | int, struct lwp *); | | 170 | int, struct lwp *); |
171 | | | 171 | |
172 | #endif | | 172 | #endif |
173 | | | 173 | |
174 | CFATTACH_DECL_NEW(wsbell, sizeof (struct wsbell_softc), | | 174 | CFATTACH_DECL_NEW(wsbell, sizeof (struct wsbell_softc), |
175 | wsbell_match, wsbell_attach, wsbell_detach, wsbell_activate); | | 175 | wsbell_match, wsbell_attach, wsbell_detach, wsbell_activate); |
176 | | | 176 | |
177 | extern struct cfdriver wsbell_cd; | | 177 | extern struct cfdriver wsbell_cd; |
178 | | | 178 | |
179 | extern dev_type_open(spkropen); | | 179 | extern dev_type_open(spkropen); |
180 | extern dev_type_close(spkrclose); | | 180 | extern dev_type_close(spkrclose); |
181 | extern dev_type_ioctl(spkrioctl); | | 181 | extern dev_type_ioctl(spkrioctl); |
182 | | | 182 | |
183 | const struct cdevsw wsbell_cdevsw = { | | 183 | const struct cdevsw wsbell_cdevsw = { |
184 | .d_open = noopen, | | 184 | .d_open = noopen, |
185 | .d_close = noclose, | | 185 | .d_close = noclose, |
186 | .d_read = noread, | | 186 | .d_read = noread, |
187 | .d_write = nowrite, | | 187 | .d_write = nowrite, |
188 | .d_ioctl = noioctl, | | 188 | .d_ioctl = noioctl, |
189 | .d_stop = nostop, | | 189 | .d_stop = nostop, |
190 | .d_tty = notty, | | 190 | .d_tty = notty, |
191 | .d_poll = nopoll, | | 191 | .d_poll = nopoll, |
192 | .d_mmap = nommap, | | 192 | .d_mmap = nommap, |
193 | .d_kqfilter = nokqfilter, | | 193 | .d_kqfilter = nokqfilter, |
194 | .d_discard = nodiscard, | | 194 | .d_discard = nodiscard, |
195 | .d_flag = D_OTHER | | 195 | .d_flag = D_OTHER |
196 | }; | | 196 | }; |
197 | | | 197 | |
198 | #if NWSMUX > 0 | | 198 | #if NWSMUX > 0 |
199 | struct wssrcops wsbell_srcops = { | | 199 | struct wssrcops wsbell_srcops = { |
200 | WSMUX_BELL, | | 200 | WSMUX_BELL, |
201 | wsbell_mux_open, wsbell_mux_close, wsbelldoioctl, wsbelldoioctl, NULL | | 201 | wsbell_mux_open, wsbell_mux_close, wsbelldoioctl, wsbelldoioctl, NULL |
202 | }; | | 202 | }; |
203 | #endif | | 203 | #endif |
204 | | | 204 | |
205 | int | | 205 | int |
206 | wsbell_match(device_t parent, cfdata_t match, void *aux) | | 206 | wsbell_match(device_t parent, cfdata_t match, void *aux) |
207 | { | | 207 | { |
208 | return (1); | | 208 | return (1); |
209 | } | | 209 | } |
210 | | | 210 | |
211 | void | | 211 | void |
212 | wsbell_attach(device_t parent, device_t self, void *aux) | | 212 | wsbell_attach(device_t parent, device_t self, void *aux) |
213 | { | | 213 | { |
214 | struct wsbell_softc *sc = device_private(self); | | 214 | struct wsbell_softc *sc = device_private(self); |
215 | struct wsbelldev_attach_args *ap = aux; | | 215 | struct wsbelldev_attach_args *ap = aux; |
216 | #if NWSMUX > 0 | | 216 | #if NWSMUX > 0 |
217 | int mux, error; | | 217 | int mux, error; |
218 | #endif | | 218 | #endif |
219 | | | 219 | |
220 | sc->sc_base.me_dv = self; | | 220 | sc->sc_base.me_dv = self; |
221 | sc->sc_accesscookie = ap->accesscookie; | | 221 | sc->sc_accesscookie = ap->accesscookie; |
222 | | | 222 | |
223 | sc->sc_spkr = device_unit(parent); | | 223 | sc->sc_spkr = device_unit(parent); |
224 | sc->sc_bell_data = wskbd_default_bell_data; | | 224 | sc->sc_bell_data = wskbd_default_bell_data; |
225 | #if NWSMUX > 0 | | 225 | #if NWSMUX > 0 |
226 | sc->sc_base.me_ops = &wsbell_srcops; | | 226 | sc->sc_base.me_ops = &wsbell_srcops; |
227 | mux = device_cfdata(self)->wsbelldevcf_mux; | | 227 | mux = device_cfdata(self)->wsbelldevcf_mux; |
228 | if (mux >= 0) { | | 228 | if (mux >= 0) { |
229 | error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); | | 229 | error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); |
230 | if (error) | | 230 | if (error) |
231 | aprint_error(" attach error=%d", error); | | 231 | aprint_error(" attach error=%d", error); |
232 | else | | 232 | else |
233 | aprint_normal(" mux %d", mux); | | 233 | aprint_normal(" mux %d", mux); |
234 | } | | 234 | } |
235 | #else | | 235 | #else |
236 | if (device_cfdata(self)->wsbelldevcf_mux >= 0) | | 236 | if (device_cfdata(self)->wsbelldevcf_mux >= 0) |
237 | aprint_normal(" (mux ignored)"); | | 237 | aprint_normal(" (mux ignored)"); |
238 | #endif | | 238 | #endif |
239 | | | 239 | |
240 | aprint_naive("\n"); | | 240 | aprint_naive("\n"); |
241 | aprint_normal("\n"); | | 241 | aprint_normal("\n"); |
242 | | | 242 | |
243 | if (!pmf_device_register(self, NULL, NULL)) | | 243 | if (!pmf_device_register(self, NULL, NULL)) |
244 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 244 | aprint_error_dev(self, "couldn't establish power handler\n"); |
245 | | | 245 | |
246 | mutex_init(&sc->sc_bellock, MUTEX_DEFAULT, IPL_SCHED); | | 246 | mutex_init(&sc->sc_bellock, MUTEX_DEFAULT, IPL_SCHED); |
247 | cv_init(&sc->sc_bellcv, "bellcv"); | | 247 | cv_init(&sc->sc_bellcv, "bellcv"); |
248 | | | 248 | |
249 | kthread_create(PRI_BIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL, | | 249 | kthread_create(PRI_BIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL, |
250 | bell_thread, sc, &sc->sc_bellthread, "%s", device_xname(self)); | | 250 | bell_thread, sc, &sc->sc_bellthread, "%s", device_xname(self)); |
251 | } | | 251 | } |
252 | | | 252 | |
253 | int | | 253 | int |
254 | wsbell_activate(device_t self, enum devact act) | | 254 | wsbell_activate(device_t self, enum devact act) |
255 | { | | 255 | { |
256 | struct wsbell_softc *sc = device_private(self); | | 256 | struct wsbell_softc *sc = device_private(self); |
257 | | | 257 | |
258 | if (act == DVACT_DEACTIVATE) | | 258 | if (act == DVACT_DEACTIVATE) |
259 | sc->sc_dying = 1; | | 259 | sc->sc_dying = 1; |
260 | return (0); | | 260 | return (0); |
261 | } | | 261 | } |
262 | | | 262 | |
263 | int | | 263 | int |
264 | wsbell_detach(device_t self, int flags) | | 264 | wsbell_detach(device_t self, int flags) |
265 | { | | 265 | { |
266 | struct wsbell_softc *sc = device_private(self); | | 266 | struct wsbell_softc *sc = device_private(self); |
267 | struct wseventvar *evar; | | 267 | struct wseventvar *evar; |
268 | int maj, mn; | | 268 | int maj, mn; |
269 | int s; | | 269 | int s; |
270 | | | 270 | |
271 | #if NWSMUX > 0 | | 271 | #if NWSMUX > 0 |
272 | /* Tell parent mux we're leaving. */ | | 272 | /* Tell parent mux we're leaving. */ |
273 | if (sc->sc_base.me_parent != NULL) { | | 273 | if (sc->sc_base.me_parent != NULL) { |
274 | DPRINTF(("wsbell_detach:\n")); | | 274 | DPRINTF(("wsbell_detach:\n")); |
275 | wsmux_detach_sc(&sc->sc_base); | | 275 | wsmux_detach_sc(&sc->sc_base); |
276 | } | | 276 | } |
277 | #endif | | 277 | #endif |
278 | | | 278 | |
279 | /* If we're open ... */ | | 279 | /* If we're open ... */ |
280 | evar = sc->sc_base.me_evp; | | 280 | evar = sc->sc_base.me_evp; |
281 | if (evar != NULL && evar->io != NULL) { | | 281 | if (evar != NULL && evar->io != NULL) { |
282 | s = spltty(); | | 282 | s = spltty(); |
283 | if (--sc->sc_refcnt >= 0) { | | 283 | if (--sc->sc_refcnt >= 0) { |
284 | struct wscons_event event; | | 284 | struct wscons_event event; |
285 | | | 285 | |
286 | /* Wake everyone by generating a dummy event. */ | | 286 | /* Wake everyone by generating a dummy event. */ |
287 | event.type = 0; | | 287 | event.type = 0; |
288 | event.value = 0; | | 288 | event.value = 0; |
289 | if (wsevent_inject(evar, &event, 1) != 0) | | 289 | if (wsevent_inject(evar, &event, 1) != 0) |
290 | wsevent_wakeup(evar); | | 290 | wsevent_wakeup(evar); |
291 | | | 291 | |
292 | /* Wait for processes to go away. */ | | 292 | /* Wait for processes to go away. */ |
293 | if (tsleep(sc, PZERO, "wsmdet", hz * 60)) | | 293 | if (tsleep(sc, PZERO, "wsmdet", hz * 60)) |
294 | printf("wsbell_detach: %s didn't detach\n", | | 294 | printf("wsbell_detach: %s didn't detach\n", |
295 | device_xname(self)); | | 295 | device_xname(self)); |
296 | } | | 296 | } |
297 | splx(s); | | 297 | splx(s); |
298 | } | | 298 | } |
299 | | | 299 | |
300 | /* locate the major number */ | | 300 | /* locate the major number */ |
301 | maj = cdevsw_lookup_major(&wsbell_cdevsw); | | 301 | maj = cdevsw_lookup_major(&wsbell_cdevsw); |
302 | | | 302 | |
303 | /* Nuke the vnodes for any open instances (calls close). */ | | 303 | /* Nuke the vnodes for any open instances (calls close). */ |
304 | mn = device_unit(self); | | 304 | mn = device_unit(self); |
305 | vdevgone(maj, mn, mn, VCHR); | | 305 | vdevgone(maj, mn, mn, VCHR); |
306 | | | 306 | |
307 | mutex_enter(&sc->sc_bellock); | | 307 | mutex_enter(&sc->sc_bellock); |
308 | sc->sc_bell_args.dying = true; | | 308 | sc->sc_dying = 1; |
309 | | | 309 | |
310 | cv_broadcast(&sc->sc_bellcv); | | 310 | cv_broadcast(&sc->sc_bellcv); |
311 | mutex_exit(&sc->sc_bellock); | | 311 | mutex_exit(&sc->sc_bellock); |
312 | | | 312 | |
313 | kthread_join(sc->sc_bellthread); | | 313 | kthread_join(sc->sc_bellthread); |
314 | cv_destroy(&sc->sc_bellcv); | | 314 | cv_destroy(&sc->sc_bellcv); |
315 | mutex_destroy(&sc->sc_bellock); | | 315 | mutex_destroy(&sc->sc_bellock); |
316 | | | 316 | |
317 | return (0); | | 317 | return (0); |
318 | } | | 318 | } |
319 | | | 319 | |
320 | #if NWSMUX > 0 | | 320 | #if NWSMUX > 0 |
321 | int | | 321 | int |
322 | wsbelldoopen(struct wsbell_softc *sc, struct wseventvar *evp) | | 322 | wsbelldoopen(struct wsbell_softc *sc, struct wseventvar *evp) |
323 | { | | 323 | { |
324 | return (0); | | 324 | return (0); |
325 | } | | 325 | } |
326 | | | 326 | |
327 | /* A wrapper around the ioctl() workhorse to make reference counting easy. */ | | 327 | /* A wrapper around the ioctl() workhorse to make reference counting easy. */ |
328 | int | | 328 | int |
329 | wsbelldoioctl(device_t dv, u_long cmd, void *data, int flag, | | 329 | wsbelldoioctl(device_t dv, u_long cmd, void *data, int flag, |
330 | struct lwp *l) | | 330 | struct lwp *l) |
331 | { | | 331 | { |
332 | struct wsbell_softc *sc = device_private(dv); | | 332 | struct wsbell_softc *sc = device_private(dv); |
333 | int error; | | 333 | int error; |
334 | | | 334 | |
335 | sc->sc_refcnt++; | | 335 | sc->sc_refcnt++; |
336 | error = wsbell_do_ioctl(sc, cmd, data, flag, l); | | 336 | error = wsbell_do_ioctl(sc, cmd, data, flag, l); |
337 | if (--sc->sc_refcnt < 0) | | 337 | if (--sc->sc_refcnt < 0) |
338 | wakeup(sc); | | 338 | wakeup(sc); |
339 | return (error); | | 339 | return (error); |
340 | } | | 340 | } |
341 | | | 341 | |
342 | int | | 342 | int |
343 | wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data, | | 343 | wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data, |
344 | int flag, struct lwp *l) | | 344 | int flag, struct lwp *l) |
345 | { | | 345 | { |
346 | struct wskbd_bell_data *ubdp, *kbdp; | | 346 | struct wskbd_bell_data *ubdp, *kbdp; |
347 | if (sc->sc_dying) | | 347 | if (sc->sc_dying) |
348 | return (EIO); | | 348 | return (EIO); |
349 | | | 349 | |
350 | /* | | 350 | /* |
351 | * Try the wsbell specific ioctls. | | 351 | * Try the wsbell specific ioctls. |
352 | */ | | 352 | */ |
353 | switch (cmd) { | | 353 | switch (cmd) { |
354 | case WSKBDIO_SETBELL: | | 354 | case WSKBDIO_SETBELL: |
355 | if ((flag & FWRITE) == 0) | | 355 | if ((flag & FWRITE) == 0) |
356 | return (EACCES); | | 356 | return (EACCES); |
357 | kbdp = &sc->sc_bell_data; | | 357 | kbdp = &sc->sc_bell_data; |
358 | ubdp = (struct wskbd_bell_data *)data; | | 358 | ubdp = (struct wskbd_bell_data *)data; |
359 | SETBELL(kbdp, ubdp, kbdp); | | 359 | SETBELL(kbdp, ubdp, kbdp); |
360 | return (0); | | 360 | return (0); |
361 | | | 361 | |
362 | case WSKBDIO_GETBELL: | | 362 | case WSKBDIO_GETBELL: |
363 | kbdp = &sc->sc_bell_data; | | 363 | kbdp = &sc->sc_bell_data; |
364 | ubdp = (struct wskbd_bell_data *)data; | | 364 | ubdp = (struct wskbd_bell_data *)data; |
365 | SETBELL(ubdp, kbdp, kbdp); | | 365 | SETBELL(ubdp, kbdp, kbdp); |
366 | return (0); | | 366 | return (0); |
367 | | | 367 | |
368 | case WSKBDIO_BELL: | | 368 | case WSKBDIO_BELL: |
369 | if ((flag & FWRITE) == 0) | | 369 | if ((flag & FWRITE) == 0) |
370 | return (EACCES); | | 370 | return (EACCES); |
371 | spkr_audio_play(sc, sc->sc_bell_data.pitch, | | 371 | spkr_audio_play(sc, sc->sc_bell_data.pitch, |
372 | sc->sc_bell_data.period, sc->sc_bell_data.volume); | | 372 | sc->sc_bell_data.period, sc->sc_bell_data.volume); |
373 | | | 373 | |
374 | return 0; | | 374 | return 0; |
375 | | | 375 | |
376 | case WSKBDIO_COMPLEXBELL: | | 376 | case WSKBDIO_COMPLEXBELL: |
377 | if ((flag & FWRITE) == 0) | | 377 | if ((flag & FWRITE) == 0) |
378 | return (EACCES); | | 378 | return (EACCES); |
379 | if (data == NULL) | | 379 | if (data == NULL) |
380 | return 0; | | 380 | return 0; |
381 | #define d ((struct wskbd_bell_data *)data) | | 381 | #define d ((struct wskbd_bell_data *)data) |
382 | spkr_audio_play(sc, d->pitch, d->period, d->volume); | | 382 | spkr_audio_play(sc, d->pitch, d->period, d->volume); |
383 | #undef d | | 383 | #undef d |
384 | return 0; | | 384 | return 0; |
385 | } | | 385 | } |
386 | | | 386 | |
387 | return (EPASSTHROUGH); | | 387 | return (EPASSTHROUGH); |
388 | } | | 388 | } |
389 | #endif | | 389 | #endif |
390 | | | 390 | |
391 | static void | | 391 | static void |
392 | bell_thread(void *arg) | | 392 | bell_thread(void *arg) |
393 | { | | 393 | { |
394 | struct wsbell_softc *sc = arg; | | 394 | struct wsbell_softc *sc = arg; |
395 | struct vbell_args *vb = &sc->sc_bell_args; | | 395 | struct vbell_args *vb = &sc->sc_bell_args; |
396 | tone_t tone; | | 396 | tone_t tone; |
397 | u_int vol; | | 397 | u_int vol; |
398 | | | 398 | |
399 | for (;;) { | | 399 | for (;;) { |
400 | mutex_enter(&sc->sc_bellock); | | 400 | mutex_enter(&sc->sc_bellock); |
401 | cv_wait_sig(&sc->sc_bellcv, &sc->sc_bellock); | | 401 | cv_wait_sig(&sc->sc_bellcv, &sc->sc_bellock); |
402 | | | 402 | |
403 | if (vb->dying == true) { | | 403 | if (sc->sc_dying) { |
404 | mutex_exit(&sc->sc_bellock); | | 404 | mutex_exit(&sc->sc_bellock); |
405 | kthread_exit(0); | | 405 | kthread_exit(0); |
406 | } | | 406 | } |
407 | | | 407 | |
408 | tone.frequency = vb->pitch; | | 408 | tone.frequency = vb->pitch; |
409 | tone.duration = vb->period; | | 409 | tone.duration = vb->period; |
410 | vol = vb->volume; | | 410 | vol = vb->volume; |
411 | mutex_exit(&sc->sc_bellock); | | 411 | mutex_exit(&sc->sc_bellock); |
412 | | | 412 | |
413 | if (spkropen(sc->sc_spkr, FWRITE, 0, NULL) != 0) | | 413 | if (spkropen(sc->sc_spkr, FWRITE, 0, NULL) != 0) |
414 | continue; | | 414 | continue; |
415 | spkrioctl(sc->sc_spkr, SPKRSETVOL, &vol, 0, curlwp); | | 415 | spkrioctl(sc->sc_spkr, SPKRSETVOL, &vol, 0, curlwp); |
416 | spkrioctl(sc->sc_spkr, SPKRTONE, &tone, 0, curlwp); | | 416 | spkrioctl(sc->sc_spkr, SPKRTONE, &tone, 0, curlwp); |
417 | spkrclose(sc->sc_spkr, FWRITE, 0, curlwp); | | 417 | spkrclose(sc->sc_spkr, FWRITE, 0, curlwp); |
418 | } | | 418 | } |
419 | } | | 419 | } |
420 | | | 420 | |
421 | static inline void | | 421 | static inline void |
422 | spkr_audio_play(struct wsbell_softc *sc, u_int pitch, u_int period, u_int volume) | | 422 | spkr_audio_play(struct wsbell_softc *sc, u_int pitch, u_int period, u_int volume) |
423 | { | | 423 | { |
424 | | | 424 | |
425 | mutex_enter(&sc->sc_bellock); | | 425 | mutex_enter(&sc->sc_bellock); |
426 | sc->sc_bell_args.dying = false; | | | |
427 | sc->sc_bell_args.pitch = pitch; | | 426 | sc->sc_bell_args.pitch = pitch; |
428 | sc->sc_bell_args.period = period / 5; | | 427 | sc->sc_bell_args.period = period / 5; |
429 | sc->sc_bell_args.volume = volume; | | 428 | sc->sc_bell_args.volume = volume; |
430 | | | 429 | |
431 | cv_broadcast(&sc->sc_bellcv); | | 430 | cv_broadcast(&sc->sc_bellcv); |
432 | mutex_exit(&sc->sc_bellock); | | 431 | mutex_exit(&sc->sc_bellock); |
433 | } | | 432 | } |
434 | | | 433 | |
435 | #if NWSMUX > 0 | | 434 | #if NWSMUX > 0 |
436 | int | | 435 | int |
437 | wsbell_mux_open(struct wsevsrc *me, struct wseventvar *evp) | | 436 | wsbell_mux_open(struct wsevsrc *me, struct wseventvar *evp) |
438 | { | | 437 | { |
439 | struct wsbell_softc *sc = (struct wsbell_softc *)me; | | 438 | struct wsbell_softc *sc = (struct wsbell_softc *)me; |
440 | | | 439 | |
441 | if (sc->sc_base.me_evp != NULL) | | 440 | if (sc->sc_base.me_evp != NULL) |
442 | return (EBUSY); | | 441 | return (EBUSY); |
443 | | | 442 | |
444 | return wsbelldoopen(sc, evp); | | 443 | return wsbelldoopen(sc, evp); |
445 | } | | 444 | } |
446 | | | 445 | |
447 | int | | 446 | int |
448 | wsbell_mux_close(struct wsevsrc *me) | | 447 | wsbell_mux_close(struct wsevsrc *me) |
449 | { | | 448 | { |
450 | struct wsbell_softc *sc = (struct wsbell_softc *)me; | | 449 | struct wsbell_softc *sc = (struct wsbell_softc *)me; |
451 | | | 450 | |
452 | sc->sc_base.me_evp = NULL; | | 451 | sc->sc_base.me_evp = NULL; |
453 | | | 452 | |
454 | return (0); | | 453 | return (0); |
455 | } | | 454 | } |
456 | #endif /* NWSMUX > 0 */ | | 455 | #endif /* NWSMUX > 0 */ |
457 | | | 456 | |
458 | MODULE(MODULE_CLASS_DRIVER, wsbell, "spkr"); | | 457 | MODULE(MODULE_CLASS_DRIVER, wsbell, "spkr"); |
459 | | | 458 | |
460 | #ifdef _MODULE | | 459 | #ifdef _MODULE |
461 | int wsbell_bmajor = -1, wsbell_cmajor = -1; | | 460 | int wsbell_bmajor = -1, wsbell_cmajor = -1; |
462 | | | 461 | |
463 | #include "ioconf.c" | | 462 | #include "ioconf.c" |
464 | #endif | | 463 | #endif |
465 | | | 464 | |
466 | static int | | 465 | static int |
467 | wsbell_modcmd(modcmd_t cmd, void *arg) | | 466 | wsbell_modcmd(modcmd_t cmd, void *arg) |
468 | { | | 467 | { |
469 | int error = 0; | | 468 | int error = 0; |
470 | | | 469 | |
471 | switch (cmd) { | | 470 | switch (cmd) { |
472 | case MODULE_CMD_INIT: | | 471 | case MODULE_CMD_INIT: |
473 | #ifdef _MODULE | | 472 | #ifdef _MODULE |
474 | error = devsw_attach("wsbell", NULL, &wsbell_bmajor, | | 473 | error = devsw_attach("wsbell", NULL, &wsbell_bmajor, |
475 | &wsbell_cdevsw, &wsbell_cmajor); | | 474 | &wsbell_cdevsw, &wsbell_cmajor); |
476 | if (error) | | 475 | if (error) |
477 | break; | | 476 | break; |
478 | | | 477 | |
479 | error = config_init_component(cfdriver_ioconf_wsbell, | | 478 | error = config_init_component(cfdriver_ioconf_wsbell, |
480 | cfattach_ioconf_wsbell, cfdata_ioconf_wsbell); | | 479 | cfattach_ioconf_wsbell, cfdata_ioconf_wsbell); |
481 | if (error) | | 480 | if (error) |
482 | devsw_detach(NULL, &wsbell_cdevsw); | | 481 | devsw_detach(NULL, &wsbell_cdevsw); |
483 | #endif | | 482 | #endif |
484 | break; | | 483 | break; |
485 | | | 484 | |
486 | case MODULE_CMD_FINI: | | 485 | case MODULE_CMD_FINI: |
487 | #ifdef _MODULE | | 486 | #ifdef _MODULE |
488 | devsw_detach(NULL, &wsbell_cdevsw); | | 487 | devsw_detach(NULL, &wsbell_cdevsw); |
489 | error = config_fini_component(cfdriver_ioconf_wsbell, | | 488 | error = config_fini_component(cfdriver_ioconf_wsbell, |
490 | cfattach_ioconf_wsbell, cfdata_ioconf_wsbell); | | 489 | cfattach_ioconf_wsbell, cfdata_ioconf_wsbell); |
491 | if (error) | | 490 | if (error) |
492 | devsw_attach("wsbell", NULL, &wsbell_bmajor, | | 491 | devsw_attach("wsbell", NULL, &wsbell_bmajor, |
493 | &wsbell_cdevsw, &wsbell_cmajor); | | 492 | &wsbell_cdevsw, &wsbell_cmajor); |
494 | #endif | | 493 | #endif |
495 | break; | | 494 | break; |
496 | | | 495 | |
497 | default: | | 496 | default: |
498 | error = ENOTTY; | | 497 | error = ENOTTY; |
499 | break; | | 498 | break; |
500 | } | | 499 | } |
501 | | | 500 | |
502 | return error; | | 501 | return error; |
503 | } | | 502 | } |