Tue Jun 13 00:54:37 2017 UTC ()
Change sc_dying from u_char to bool.


(nat)
diff -r1.6 -r1.7 src/sys/dev/wscons/wsbell.c
diff -r1.2 -r1.3 src/sys/dev/wscons/wsbellvar.h

cvs diff -r1.6 -r1.7 src/sys/dev/wscons/wsbell.c (switch to unified diff)

--- src/sys/dev/wscons/wsbell.c 2017/06/13 00:49:05 1.6
+++ src/sys/dev/wscons/wsbell.c 2017/06/13 00:54:37 1.7
@@ -1,502 +1,503 @@ @@ -1,502 +1,503 @@
1/* $NetBSD: wsbell.c,v 1.6 2017/06/13 00:49:05 nat Exp $ */ 1/* $NetBSD: wsbell.c,v 1.7 2017/06/13 00:54:37 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.6 2017/06/13 00:49:05 nat Exp $"); 110__KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.7 2017/06/13 00:54:37 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
148extern int wsmuxdebug; 148extern 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
154static void bell_thread(void *); 154static void bell_thread(void *);
155static inline void spkr_audio_play(struct wsbell_softc *, u_int, u_int, u_int); 155static inline void spkr_audio_play(struct wsbell_softc *, u_int, u_int, u_int);
156 156
157static int wsbell_match(device_t, cfdata_t, void *); 157static int wsbell_match(device_t, cfdata_t, void *);
158static void wsbell_attach(device_t, device_t, void *); 158static void wsbell_attach(device_t, device_t, void *);
159static int wsbell_detach(device_t, int); 159static int wsbell_detach(device_t, int);
160static int wsbell_activate(device_t, enum devact); 160static int wsbell_activate(device_t, enum devact);
161 161
162#if NWSMUX > 0 162#if NWSMUX > 0
163static int wsbell_mux_open(struct wsevsrc *, struct wseventvar *); 163static int wsbell_mux_open(struct wsevsrc *, struct wseventvar *);
164static int wsbell_mux_close(struct wsevsrc *); 164static int wsbell_mux_close(struct wsevsrc *);
165 165
166static int wsbelldoopen(struct wsbell_softc *, struct wseventvar *); 166static int wsbelldoopen(struct wsbell_softc *, struct wseventvar *);
167static int wsbelldoioctl(device_t, u_long, void *, int, struct lwp *); 167static int wsbelldoioctl(device_t, u_long, void *, int, struct lwp *);
168 168
169static int wsbell_do_ioctl(struct wsbell_softc *, u_long, void *, 169static 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
174CFATTACH_DECL_NEW(wsbell, sizeof (struct wsbell_softc), 174CFATTACH_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
177extern struct cfdriver wsbell_cd; 177extern struct cfdriver wsbell_cd;
178 178
179extern dev_type_open(spkropen); 179extern dev_type_open(spkropen);
180extern dev_type_close(spkrclose); 180extern dev_type_close(spkrclose);
181extern dev_type_ioctl(spkrioctl); 181extern dev_type_ioctl(spkrioctl);
182 182
183const struct cdevsw wsbell_cdevsw = { 183const 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
199struct wssrcops wsbell_srcops = { 199struct 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
205int 205int
206wsbell_match(device_t parent, cfdata_t match, void *aux) 206wsbell_match(device_t parent, cfdata_t match, void *aux)
207{ 207{
208 return (1); 208 return (1);
209} 209}
210 210
211void 211void
212wsbell_attach(device_t parent, device_t self, void *aux) 212wsbell_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_dying = false;
223 sc->sc_spkr = device_unit(parent); 224 sc->sc_spkr = device_unit(parent);
224 sc->sc_bell_data = wskbd_default_bell_data; 225 sc->sc_bell_data = wskbd_default_bell_data;
225#if NWSMUX > 0 226#if NWSMUX > 0
226 sc->sc_base.me_ops = &wsbell_srcops; 227 sc->sc_base.me_ops = &wsbell_srcops;
227 mux = device_cfdata(self)->wsbelldevcf_mux; 228 mux = device_cfdata(self)->wsbelldevcf_mux;
228 if (mux >= 0) { 229 if (mux >= 0) {
229 error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); 230 error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base);
230 if (error) 231 if (error)
231 aprint_error(" attach error=%d", error); 232 aprint_error(" attach error=%d", error);
232 else 233 else
233 aprint_normal(" mux %d", mux); 234 aprint_normal(" mux %d", mux);
234 } 235 }
235#else 236#else
236 if (device_cfdata(self)->wsbelldevcf_mux >= 0) 237 if (device_cfdata(self)->wsbelldevcf_mux >= 0)
237 aprint_normal(" (mux ignored)"); 238 aprint_normal(" (mux ignored)");
238#endif 239#endif
239 240
240 aprint_naive("\n"); 241 aprint_naive("\n");
241 aprint_normal("\n"); 242 aprint_normal("\n");
242 243
243 if (!pmf_device_register(self, NULL, NULL)) 244 if (!pmf_device_register(self, NULL, NULL))
244 aprint_error_dev(self, "couldn't establish power handler\n"); 245 aprint_error_dev(self, "couldn't establish power handler\n");
245 246
246 mutex_init(&sc->sc_bellock, MUTEX_DEFAULT, IPL_SCHED); 247 mutex_init(&sc->sc_bellock, MUTEX_DEFAULT, IPL_SCHED);
247 cv_init(&sc->sc_bellcv, "bellcv"); 248 cv_init(&sc->sc_bellcv, "bellcv");
248 249
249 kthread_create(PRI_BIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL, 250 kthread_create(PRI_BIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
250 bell_thread, sc, &sc->sc_bellthread, "%s", device_xname(self)); 251 bell_thread, sc, &sc->sc_bellthread, "%s", device_xname(self));
251} 252}
252 253
253int 254int
254wsbell_activate(device_t self, enum devact act) 255wsbell_activate(device_t self, enum devact act)
255{ 256{
256 struct wsbell_softc *sc = device_private(self); 257 struct wsbell_softc *sc = device_private(self);
257 258
258 if (act == DVACT_DEACTIVATE) 259 if (act == DVACT_DEACTIVATE)
259 sc->sc_dying = 1; 260 sc->sc_dying = true;
260 return (0); 261 return (0);
261} 262}
262 263
263int 264int
264wsbell_detach(device_t self, int flags) 265wsbell_detach(device_t self, int flags)
265{ 266{
266 struct wsbell_softc *sc = device_private(self); 267 struct wsbell_softc *sc = device_private(self);
267 struct wseventvar *evar; 268 struct wseventvar *evar;
268 int maj, mn; 269 int maj, mn;
269 int s; 270 int s;
270 271
271#if NWSMUX > 0 272#if NWSMUX > 0
272 /* Tell parent mux we're leaving. */ 273 /* Tell parent mux we're leaving. */
273 if (sc->sc_base.me_parent != NULL) { 274 if (sc->sc_base.me_parent != NULL) {
274 DPRINTF(("wsbell_detach:\n")); 275 DPRINTF(("wsbell_detach:\n"));
275 wsmux_detach_sc(&sc->sc_base); 276 wsmux_detach_sc(&sc->sc_base);
276 } 277 }
277#endif 278#endif
278 279
279 /* If we're open ... */ 280 /* If we're open ... */
280 evar = sc->sc_base.me_evp; 281 evar = sc->sc_base.me_evp;
281 if (evar != NULL && evar->io != NULL) { 282 if (evar != NULL && evar->io != NULL) {
282 s = spltty(); 283 s = spltty();
283 if (--sc->sc_refcnt >= 0) { 284 if (--sc->sc_refcnt >= 0) {
284 struct wscons_event event; 285 struct wscons_event event;
285 286
286 /* Wake everyone by generating a dummy event. */ 287 /* Wake everyone by generating a dummy event. */
287 event.type = 0; 288 event.type = 0;
288 event.value = 0; 289 event.value = 0;
289 if (wsevent_inject(evar, &event, 1) != 0) 290 if (wsevent_inject(evar, &event, 1) != 0)
290 wsevent_wakeup(evar); 291 wsevent_wakeup(evar);
291 292
292 /* Wait for processes to go away. */ 293 /* Wait for processes to go away. */
293 if (tsleep(sc, PZERO, "wsmdet", hz * 60)) 294 if (tsleep(sc, PZERO, "wsmdet", hz * 60))
294 printf("wsbell_detach: %s didn't detach\n", 295 printf("wsbell_detach: %s didn't detach\n",
295 device_xname(self)); 296 device_xname(self));
296 } 297 }
297 splx(s); 298 splx(s);
298 } 299 }
299 300
300 /* locate the major number */ 301 /* locate the major number */
301 maj = cdevsw_lookup_major(&wsbell_cdevsw); 302 maj = cdevsw_lookup_major(&wsbell_cdevsw);
302 303
303 /* Nuke the vnodes for any open instances (calls close). */ 304 /* Nuke the vnodes for any open instances (calls close). */
304 mn = device_unit(self); 305 mn = device_unit(self);
305 vdevgone(maj, mn, mn, VCHR); 306 vdevgone(maj, mn, mn, VCHR);
306 307
307 mutex_enter(&sc->sc_bellock); 308 mutex_enter(&sc->sc_bellock);
308 sc->sc_dying = 1; 309 sc->sc_dying = true;
309 310
310 cv_broadcast(&sc->sc_bellcv); 311 cv_broadcast(&sc->sc_bellcv);
311 mutex_exit(&sc->sc_bellock); 312 mutex_exit(&sc->sc_bellock);
312 313
313 kthread_join(sc->sc_bellthread); 314 kthread_join(sc->sc_bellthread);
314 cv_destroy(&sc->sc_bellcv); 315 cv_destroy(&sc->sc_bellcv);
315 mutex_destroy(&sc->sc_bellock); 316 mutex_destroy(&sc->sc_bellock);
316 317
317 return (0); 318 return (0);
318} 319}
319 320
320#if NWSMUX > 0 321#if NWSMUX > 0
321int 322int
322wsbelldoopen(struct wsbell_softc *sc, struct wseventvar *evp) 323wsbelldoopen(struct wsbell_softc *sc, struct wseventvar *evp)
323{ 324{
324 return (0); 325 return (0);
325} 326}
326 327
327/* A wrapper around the ioctl() workhorse to make reference counting easy. */ 328/* A wrapper around the ioctl() workhorse to make reference counting easy. */
328int 329int
329wsbelldoioctl(device_t dv, u_long cmd, void *data, int flag, 330wsbelldoioctl(device_t dv, u_long cmd, void *data, int flag,
330 struct lwp *l) 331 struct lwp *l)
331{ 332{
332 struct wsbell_softc *sc = device_private(dv); 333 struct wsbell_softc *sc = device_private(dv);
333 int error; 334 int error;
334 335
335 sc->sc_refcnt++; 336 sc->sc_refcnt++;
336 error = wsbell_do_ioctl(sc, cmd, data, flag, l); 337 error = wsbell_do_ioctl(sc, cmd, data, flag, l);
337 if (--sc->sc_refcnt < 0) 338 if (--sc->sc_refcnt < 0)
338 wakeup(sc); 339 wakeup(sc);
339 return (error); 340 return (error);
340} 341}
341 342
342int 343int
343wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data, 344wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data,
344 int flag, struct lwp *l) 345 int flag, struct lwp *l)
345{ 346{
346 struct wskbd_bell_data *ubdp, *kbdp; 347 struct wskbd_bell_data *ubdp, *kbdp;
347 if (sc->sc_dying) 348 if (sc->sc_dying == true)
348 return (EIO); 349 return (EIO);
349 350
350 /* 351 /*
351 * Try the wsbell specific ioctls. 352 * Try the wsbell specific ioctls.
352 */ 353 */
353 switch (cmd) { 354 switch (cmd) {
354 case WSKBDIO_SETBELL: 355 case WSKBDIO_SETBELL:
355 if ((flag & FWRITE) == 0) 356 if ((flag & FWRITE) == 0)
356 return (EACCES); 357 return (EACCES);
357 kbdp = &sc->sc_bell_data; 358 kbdp = &sc->sc_bell_data;
358 ubdp = (struct wskbd_bell_data *)data; 359 ubdp = (struct wskbd_bell_data *)data;
359 SETBELL(kbdp, ubdp, kbdp); 360 SETBELL(kbdp, ubdp, kbdp);
360 return (0); 361 return (0);
361 362
362 case WSKBDIO_GETBELL: 363 case WSKBDIO_GETBELL:
363 kbdp = &sc->sc_bell_data; 364 kbdp = &sc->sc_bell_data;
364 ubdp = (struct wskbd_bell_data *)data; 365 ubdp = (struct wskbd_bell_data *)data;
365 SETBELL(ubdp, kbdp, kbdp); 366 SETBELL(ubdp, kbdp, kbdp);
366 return (0); 367 return (0);
367 368
368 case WSKBDIO_BELL: 369 case WSKBDIO_BELL:
369 if ((flag & FWRITE) == 0) 370 if ((flag & FWRITE) == 0)
370 return (EACCES); 371 return (EACCES);
371 spkr_audio_play(sc, sc->sc_bell_data.pitch, 372 spkr_audio_play(sc, sc->sc_bell_data.pitch,
372 sc->sc_bell_data.period, sc->sc_bell_data.volume); 373 sc->sc_bell_data.period, sc->sc_bell_data.volume);
373 374
374 return 0; 375 return 0;
375 376
376 case WSKBDIO_COMPLEXBELL: 377 case WSKBDIO_COMPLEXBELL:
377 if ((flag & FWRITE) == 0) 378 if ((flag & FWRITE) == 0)
378 return (EACCES); 379 return (EACCES);
379 if (data == NULL) 380 if (data == NULL)
380 return 0; 381 return 0;
381#define d ((struct wskbd_bell_data *)data) 382#define d ((struct wskbd_bell_data *)data)
382 spkr_audio_play(sc, d->pitch, d->period, d->volume); 383 spkr_audio_play(sc, d->pitch, d->period, d->volume);
383#undef d 384#undef d
384 return 0; 385 return 0;
385 }  386 }
386 387
387 return (EPASSTHROUGH); 388 return (EPASSTHROUGH);
388} 389}
389#endif 390#endif
390 391
391static void 392static void
392bell_thread(void *arg) 393bell_thread(void *arg)
393{ 394{
394 struct wsbell_softc *sc = arg; 395 struct wsbell_softc *sc = arg;
395 struct vbell_args *vb = &sc->sc_bell_args; 396 struct vbell_args *vb = &sc->sc_bell_args;
396 tone_t tone; 397 tone_t tone;
397 u_int vol; 398 u_int vol;
398  399
399 for (;;) { 400 for (;;) {
400 mutex_enter(&sc->sc_bellock); 401 mutex_enter(&sc->sc_bellock);
401 cv_wait_sig(&sc->sc_bellcv, &sc->sc_bellock); 402 cv_wait_sig(&sc->sc_bellcv, &sc->sc_bellock);
402  403
403 if (sc->sc_dying) { 404 if (sc->sc_dying == true) {
404 mutex_exit(&sc->sc_bellock); 405 mutex_exit(&sc->sc_bellock);
405 kthread_exit(0); 406 kthread_exit(0);
406 } 407 }
407  408
408 tone.frequency = vb->pitch; 409 tone.frequency = vb->pitch;
409 tone.duration = vb->period; 410 tone.duration = vb->period;
410 vol = vb->volume; 411 vol = vb->volume;
411 mutex_exit(&sc->sc_bellock); 412 mutex_exit(&sc->sc_bellock);
412 413
413 if (spkropen(sc->sc_spkr, FWRITE, 0, NULL) != 0) 414 if (spkropen(sc->sc_spkr, FWRITE, 0, NULL) != 0)
414 continue; 415 continue;
415 spkrioctl(sc->sc_spkr, SPKRSETVOL, &vol, 0, curlwp); 416 spkrioctl(sc->sc_spkr, SPKRSETVOL, &vol, 0, curlwp);
416 spkrioctl(sc->sc_spkr, SPKRTONE, &tone, 0, curlwp); 417 spkrioctl(sc->sc_spkr, SPKRTONE, &tone, 0, curlwp);
417 spkrclose(sc->sc_spkr, FWRITE, 0, curlwp); 418 spkrclose(sc->sc_spkr, FWRITE, 0, curlwp);
418 } 419 }
419} 420}
420 421
421static inline void 422static inline void
422spkr_audio_play(struct wsbell_softc *sc, u_int pitch, u_int period, u_int volume) 423spkr_audio_play(struct wsbell_softc *sc, u_int pitch, u_int period, u_int volume)
423{ 424{
424 425
425 mutex_enter(&sc->sc_bellock); 426 mutex_enter(&sc->sc_bellock);
426 sc->sc_bell_args.pitch = pitch; 427 sc->sc_bell_args.pitch = pitch;
427 sc->sc_bell_args.period = period / 5; 428 sc->sc_bell_args.period = period / 5;
428 sc->sc_bell_args.volume = volume; 429 sc->sc_bell_args.volume = volume;
429 430
430 cv_broadcast(&sc->sc_bellcv); 431 cv_broadcast(&sc->sc_bellcv);
431 mutex_exit(&sc->sc_bellock); 432 mutex_exit(&sc->sc_bellock);
432} 433}
433 434
434#if NWSMUX > 0 435#if NWSMUX > 0
435int 436int
436wsbell_mux_open(struct wsevsrc *me, struct wseventvar *evp) 437wsbell_mux_open(struct wsevsrc *me, struct wseventvar *evp)
437{ 438{
438 struct wsbell_softc *sc = (struct wsbell_softc *)me; 439 struct wsbell_softc *sc = (struct wsbell_softc *)me;
439 440
440 if (sc->sc_base.me_evp != NULL) 441 if (sc->sc_base.me_evp != NULL)
441 return (EBUSY); 442 return (EBUSY);
442 443
443 return wsbelldoopen(sc, evp); 444 return wsbelldoopen(sc, evp);
444} 445}
445 446
446int 447int
447wsbell_mux_close(struct wsevsrc *me) 448wsbell_mux_close(struct wsevsrc *me)
448{ 449{
449 struct wsbell_softc *sc = (struct wsbell_softc *)me; 450 struct wsbell_softc *sc = (struct wsbell_softc *)me;
450 451
451 sc->sc_base.me_evp = NULL; 452 sc->sc_base.me_evp = NULL;
452 453
453 return (0); 454 return (0);
454} 455}
455#endif /* NWSMUX > 0 */ 456#endif /* NWSMUX > 0 */
456 457
457MODULE(MODULE_CLASS_DRIVER, wsbell, "spkr"); 458MODULE(MODULE_CLASS_DRIVER, wsbell, "spkr");
458 459
459#ifdef _MODULE 460#ifdef _MODULE
460int wsbell_bmajor = -1, wsbell_cmajor = -1; 461int wsbell_bmajor = -1, wsbell_cmajor = -1;
461 462
462#include "ioconf.c" 463#include "ioconf.c"
463#endif 464#endif
464 465
465static int 466static int
466wsbell_modcmd(modcmd_t cmd, void *arg) 467wsbell_modcmd(modcmd_t cmd, void *arg)
467{ 468{
468 int error = 0; 469 int error = 0;
469 470
470 switch (cmd) { 471 switch (cmd) {
471 case MODULE_CMD_INIT: 472 case MODULE_CMD_INIT:
472#ifdef _MODULE 473#ifdef _MODULE
473 error = devsw_attach("wsbell", NULL, &wsbell_bmajor, 474 error = devsw_attach("wsbell", NULL, &wsbell_bmajor,
474 &wsbell_cdevsw, &wsbell_cmajor); 475 &wsbell_cdevsw, &wsbell_cmajor);
475 if (error) 476 if (error)
476 break; 477 break;
477 478
478 error = config_init_component(cfdriver_ioconf_wsbell, 479 error = config_init_component(cfdriver_ioconf_wsbell,
479 cfattach_ioconf_wsbell, cfdata_ioconf_wsbell); 480 cfattach_ioconf_wsbell, cfdata_ioconf_wsbell);
480 if (error) 481 if (error)
481 devsw_detach(NULL, &wsbell_cdevsw); 482 devsw_detach(NULL, &wsbell_cdevsw);
482#endif 483#endif
483 break; 484 break;
484 485
485 case MODULE_CMD_FINI: 486 case MODULE_CMD_FINI:
486#ifdef _MODULE 487#ifdef _MODULE
487 devsw_detach(NULL, &wsbell_cdevsw); 488 devsw_detach(NULL, &wsbell_cdevsw);
488 error = config_fini_component(cfdriver_ioconf_wsbell, 489 error = config_fini_component(cfdriver_ioconf_wsbell,
489 cfattach_ioconf_wsbell, cfdata_ioconf_wsbell); 490 cfattach_ioconf_wsbell, cfdata_ioconf_wsbell);
490 if (error) 491 if (error)
491 devsw_attach("wsbell", NULL, &wsbell_bmajor, 492 devsw_attach("wsbell", NULL, &wsbell_bmajor,
492 &wsbell_cdevsw, &wsbell_cmajor); 493 &wsbell_cdevsw, &wsbell_cmajor);
493#endif 494#endif
494 break; 495 break;
495 496
496 default: 497 default:
497 error = ENOTTY; 498 error = ENOTTY;
498 break; 499 break;
499 } 500 }
500 501
501 return error; 502 return error;
502} 503}

cvs diff -r1.2 -r1.3 src/sys/dev/wscons/wsbellvar.h (switch to unified diff)

--- src/sys/dev/wscons/wsbellvar.h 2017/06/13 00:49:05 1.2
+++ src/sys/dev/wscons/wsbellvar.h 2017/06/13 00:54:37 1.3
@@ -1,60 +1,60 @@ @@ -1,60 +1,60 @@
1/* $NetBSD: wsbellvar.h,v 1.2 2017/06/13 00:49:05 nat Exp $ */ 1/* $NetBSD: wsbellvar.h,v 1.3 2017/06/13 00:54:37 nat Exp $ */
2/*- 2/*-
3 * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au> 3 * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include "locators.h" 28#include "locators.h"
29#include <dev/wscons/wseventvar.h> 29#include <dev/wscons/wseventvar.h>
30#include <dev/wscons/wsmuxvar.h> 30#include <dev/wscons/wsmuxvar.h>
31 31
32#define wsbelldevcf_mux cf_loc[WSBELLDEVCF_MUX] 32#define wsbelldevcf_mux cf_loc[WSBELLDEVCF_MUX]
33 33
34struct vbell_args { 34struct vbell_args {
35 u_int pitch; 35 u_int pitch;
36 u_int period; 36 u_int period;
37 u_int volume; 37 u_int volume;
38}; 38};
39 39
40struct wsbell_softc { 40struct wsbell_softc {
41 struct wsevsrc sc_base; 41 struct wsevsrc sc_base;
42 dev_t sc_spkr; /* our spkr device */ 42 dev_t sc_spkr; /* our spkr device */
43 struct wskbd_bell_data sc_bell_data; 43 struct wskbd_bell_data sc_bell_data;
44 44
45 void *sc_accesscookie; 45 void *sc_accesscookie;
46 46
47 int sc_refcnt; 47 int sc_refcnt;
48 u_char sc_dying; /* device is being detached */ 48 bool sc_dying; /* device is being detached */
49 49
50 lwp_t *sc_bellthread; 50 lwp_t *sc_bellthread;
51 kmutex_t sc_bellock; 51 kmutex_t sc_bellock;
52 kcondvar_t sc_bellcv; 52 kcondvar_t sc_bellcv;
53 53
54 struct vbell_args sc_bell_args; 54 struct vbell_args sc_bell_args;
55}; 55};
56 56
57/* 57/*
58 * Autoconfiguration helper functions. 58 * Autoconfiguration helper functions.
59 */ 59 */
60int wsbelldevprint(void *, const char *); 60int wsbelldevprint(void *, const char *);