| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
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 |
| @@ -97,27 +97,27 @@ | | | @@ -97,27 +97,27 @@ |
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> |
| @@ -295,27 +295,27 @@ wsbell_detach(device_t self, int flags) | | | @@ -295,27 +295,27 @@ wsbell_detach(device_t self, int flags) |
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 |
| @@ -390,50 +390,49 @@ wsbell_do_ioctl(struct wsbell_softc *sc, | | | @@ -390,50 +390,49 @@ wsbell_do_ioctl(struct wsbell_softc *sc, |
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; |