Sun Jun 11 03:55:57 2017 UTC ()
New device wsbell - allows for a console beep for non pckbds (usb etc).
Works for platforms without pcppi - can work with spkr at audio and spkr
at pcppi.

To use add the following to your kernel config:
wsbell* at spkr? console?

Ok pgoyette@.


(nat)
diff -r1.1175 -r1.1176 src/sys/conf/files
diff -r1.8 -r1.9 src/sys/dev/spkr.c
diff -r1.7 -r1.8 src/sys/dev/spkrvar.h
diff -r1.32 -r1.33 src/sys/dev/pckbport/pckbd.c
diff -r1.50 -r1.51 src/sys/dev/wscons/files.wscons
diff -r0 -r1.1 src/sys/dev/wscons/wsbell.c
diff -r0 -r1.1 src/sys/dev/wscons/wsbellmux.c
diff -r0 -r1.1 src/sys/dev/wscons/wsbellmuxvar.h
diff -r0 -r1.1 src/sys/dev/wscons/wsbellvar.h
diff -r1.118 -r1.119 src/sys/dev/wscons/wsconsio.h
diff -r1.61 -r1.62 src/sys/dev/wscons/wsmux.c
diff -r1.15 -r1.16 src/sys/dev/wscons/wsmuxvar.h

cvs diff -r1.1175 -r1.1176 src/sys/conf/files (expand / switch to unified diff)

--- src/sys/conf/files 2017/06/08 21:00:43 1.1175
+++ src/sys/conf/files 2017/06/11 03:55:56 1.1176
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files,v 1.1175 2017/06/08 21:00:43 jmcneill Exp $ 1# $NetBSD: files,v 1.1176 2017/06/11 03:55:56 nat Exp $
2# @(#)files.newconf 7.5 (Berkeley) 5/10/93 2# @(#)files.newconf 7.5 (Berkeley) 5/10/93
3 3
4version 20150846 4version 20150846
5 5
6# 6#
7# device classes 7# device classes
8# 8#
9devclass disk 9devclass disk
10devclass tape 10devclass tape
11devclass ifnet 11devclass ifnet
12devclass tty 12devclass tty
13devclass audiodev 13devclass audiodev
14devclass displaydev 14devclass displaydev
@@ -334,28 +334,28 @@ define sata_pmp @@ -334,28 +334,28 @@ define sata_pmp
334define scsi_core 334define scsi_core
335define scsi {[channel = -1]}: scsi_core 335define scsi {[channel = -1]}: scsi_core
336define ata_hl {[drive = -1]} 336define ata_hl {[drive = -1]}
337define atapi { } 337define atapi { }
338define radiodev { } 338define radiodev { }
339define gpibdev {[address = -1]} 339define gpibdev {[address = -1]}
340define gpiobus { } 340define gpiobus { }
341define onewirebus { } 341define onewirebus { }
342define pckbport {[slot = -1]} 342define pckbport {[slot = -1]}
343define pckbport_machdep_cnattach 343define pckbport_machdep_cnattach
344define firmload 344define firmload
345 345
346# speaker devices, attaches to audio or pcppi drivers 346# speaker devices, attaches to audio or pcppi drivers
347device spkr 347device spkr: wsbelldev
348file dev/spkr.c spkr 348file dev/spkr.c spkr needs-flag
349 349
350include "dev/files.audio" 350include "dev/files.audio"
351 351
352# High definition audio 352# High definition audio
353include "dev/hdaudio/files.hdaudio" 353include "dev/hdaudio/files.hdaudio"
354 354
355# Base verbose vendor/product printing support 355# Base verbose vendor/product printing support
356file dev/dev_verbose.c 356file dev/dev_verbose.c
357 357
358# video devices, attaches to video hardware driver 358# video devices, attaches to video hardware driver
359# 359#
360device video 360device video
361attach video at videobus 361attach video at videobus
@@ -1175,26 +1175,27 @@ include "dev/drm/files.drm" @@ -1175,26 +1175,27 @@ include "dev/drm/files.drm"
1175include "external/bsd/common/conf/files.linux" 1175include "external/bsd/common/conf/files.linux"
1176 1176
1177# DRM/KMS - Newer direct rendering manager with kernel mode-switching 1177# DRM/KMS - Newer direct rendering manager with kernel mode-switching
1178include "external/bsd/drm2/drm/files.drmkms" 1178include "external/bsd/drm2/drm/files.drmkms"
1179 1179
1180 1180
1181# Definitions for wscons 1181# Definitions for wscons
1182# device attributes: display, display with emulator, keyboard, and mouse 1182# device attributes: display, display with emulator, keyboard, and mouse
1183# 1183#
1184define wsdisplaydev {[kbdmux = 1]} 1184define wsdisplaydev {[kbdmux = 1]}
1185define wsemuldisplaydev {[console = -1], [kbdmux = 1]} 1185define wsemuldisplaydev {[console = -1], [kbdmux = 1]}
1186define wskbddev {[console = -1], [mux = 1]} 1186define wskbddev {[console = -1], [mux = 1]}
1187define wsmousedev {[mux = 0]} 1187define wsmousedev {[mux = 0]}
 1188define wsbelldev {[console = -1], [mux = 1]}
1188define vcons 1189define vcons
1189# attribute to pull in raster support 1190# attribute to pull in raster support
1190# 1191#
1191define wsrasteremulops 1192define wsrasteremulops
1192# common PC display functions 1193# common PC display functions
1193# 1194#
1194defflag opt_pcdisplay.h PCDISPLAY_SOFTCURSOR 1195defflag opt_pcdisplay.h PCDISPLAY_SOFTCURSOR
1195define pcdisplayops 1196define pcdisplayops
1196file dev/ic/pcdisplay_subr.c pcdisplayops 1197file dev/ic/pcdisplay_subr.c pcdisplayops
1197file dev/ic/pcdisplay_chars.c pcdisplayops 1198file dev/ic/pcdisplay_chars.c pcdisplayops
1198# an attribute used by arch specific config files to include /dev/fb* (or 1199# an attribute used by arch specific config files to include /dev/fb* (or
1199# equivalent) support - on most archs this is just a NOP (untill, maybe 1200# equivalent) support - on most archs this is just a NOP (untill, maybe
1200# someday when we might make /dev/fb* support MI) 1201# someday when we might make /dev/fb* support MI)

cvs diff -r1.8 -r1.9 src/sys/dev/spkr.c (expand / switch to unified diff)

--- src/sys/dev/spkr.c 2017/06/11 03:33:48 1.8
+++ src/sys/dev/spkr.c 2017/06/11 03:55:56 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: spkr.c,v 1.8 2017/06/11 03:33:48 nat Exp $ */ 1/* $NetBSD: spkr.c,v 1.9 2017/06/11 03:55:56 nat Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1990 Eric S. Raymond (esr@snark.thyrsus.com) 4 * Copyright (c) 1990 Eric S. Raymond (esr@snark.thyrsus.com)
5 * Copyright (c) 1990 Andrew A. Chernov (ache@astral.msk.su) 5 * Copyright (c) 1990 Andrew A. Chernov (ache@astral.msk.su)
6 * Copyright (c) 1990 Lennart Augustsson (lennart@augustsson.net) 6 * Copyright (c) 1990 Lennart Augustsson (lennart@augustsson.net)
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -33,44 +33,49 @@ @@ -33,44 +33,49 @@
33 * POSSIBILITY OF SUCH DAMAGE. 33 * POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36/* 36/*
37 * spkr.c -- device driver for console speaker on 80386 37 * spkr.c -- device driver for console speaker on 80386
38 * 38 *
39 * v1.1 by Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990 39 * v1.1 by Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990
40 * modified for 386bsd by Andrew A. Chernov <ache@astral.msk.su> 40 * modified for 386bsd by Andrew A. Chernov <ache@astral.msk.su>
41 * 386bsd only clean version, all SYSV stuff removed 41 * 386bsd only clean version, all SYSV stuff removed
42 * use hz value from param.c 42 * use hz value from param.c
43 */ 43 */
44 44
45#include <sys/cdefs.h> 45#include <sys/cdefs.h>
46__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.8 2017/06/11 03:33:48 nat Exp $"); 46__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.9 2017/06/11 03:55:56 nat Exp $");
 47
 48#include "wsmux.h"
47 49
48#include <sys/param.h> 50#include <sys/param.h>
49#include <sys/systm.h> 51#include <sys/systm.h>
50#include <sys/kernel.h> 52#include <sys/kernel.h>
51#include <sys/errno.h> 53#include <sys/errno.h>
52#include <sys/device.h> 54#include <sys/device.h>
53#include <sys/malloc.h> 55#include <sys/malloc.h>
54#include <sys/module.h> 56#include <sys/module.h>
55#include <sys/uio.h> 57#include <sys/uio.h>
56#include <sys/proc.h> 58#include <sys/proc.h>
57#include <sys/ioctl.h> 59#include <sys/ioctl.h>
58#include <sys/conf.h> 60#include <sys/conf.h>
59 61
60#include <sys/bus.h> 62#include <sys/bus.h>
61 63
62#include <dev/spkrio.h> 64#include <dev/spkrio.h>
63#include <dev/spkrvar.h> 65#include <dev/spkrvar.h>
 66#include <dev/wscons/wsconsio.h>
 67#include <dev/wscons/wsbellvar.h>
 68#include <dev/wscons/wsbellmuxvar.h>
64 69
65dev_type_open(spkropen); 70dev_type_open(spkropen);
66dev_type_close(spkrclose); 71dev_type_close(spkrclose);
67dev_type_write(spkrwrite); 72dev_type_write(spkrwrite);
68dev_type_ioctl(spkrioctl); 73dev_type_ioctl(spkrioctl);
69 74
70const struct cdevsw spkr_cdevsw = { 75const struct cdevsw spkr_cdevsw = {
71 .d_open = spkropen, 76 .d_open = spkropen,
72 .d_close = spkrclose, 77 .d_close = spkrclose,
73 .d_read = noread, 78 .d_read = noread,
74 .d_write = spkrwrite, 79 .d_write = spkrwrite,
75 .d_ioctl = spkrioctl, 80 .d_ioctl = spkrioctl,
76 .d_stop = nostop, 81 .d_stop = nostop,
@@ -355,26 +360,33 @@ extern struct cfdriver spkr_cd; @@ -355,26 +360,33 @@ extern struct cfdriver spkr_cd;
355void 360void
356spkr_attach(device_t self, void (*tone)(device_t, u_int, u_int), 361spkr_attach(device_t self, void (*tone)(device_t, u_int, u_int),
357 void (*rest)(device_t, int)) 362 void (*rest)(device_t, int))
358{ 363{
359 struct spkr_softc *sc = device_private(self); 364 struct spkr_softc *sc = device_private(self);
360 365
361#ifdef SPKRDEBUG 366#ifdef SPKRDEBUG
362 aprint_debug("%s: entering for unit %d\n", __func__, self->dv_unit); 367 aprint_debug("%s: entering for unit %d\n", __func__, self->dv_unit);
363#endif /* SPKRDEBUG */ 368#endif /* SPKRDEBUG */
364 sc->sc_dev = self; 369 sc->sc_dev = self;
365 sc->sc_tone = tone; 370 sc->sc_tone = tone;
366 sc->sc_rest = rest; 371 sc->sc_rest = rest;
367 sc->sc_inbuf = NULL; 372 sc->sc_inbuf = NULL;
 373
 374#if (NWSMUX > 0)
 375 struct wsbelldev_attach_args a;
 376
 377 a.accesscookie = sc;
 378 sc->sc_wsbelldev = config_found(self, &a, wsbelldevprint);
 379#endif
368} 380}
369 381
370int 382int
371spkr_detach(device_t self, int flags) 383spkr_detach(device_t self, int flags)
372{ 384{
373 struct spkr_softc *sc = device_private(self); 385 struct spkr_softc *sc = device_private(self);
374 386
375#ifdef SPKRDEBUG 387#ifdef SPKRDEBUG
376 aprint_debug("%s: entering for unit %d\n", __func__, self->dv_unit); 388 aprint_debug("%s: entering for unit %d\n", __func__, self->dv_unit);
377#endif /* SPKRDEBUG */ 389#endif /* SPKRDEBUG */
378 if (sc == NULL) 390 if (sc == NULL)
379 return ENXIO; 391 return ENXIO;
380 if (sc->sc_inbuf != NULL) 392 if (sc->sc_inbuf != NULL)

cvs diff -r1.7 -r1.8 src/sys/dev/spkrvar.h (expand / switch to unified diff)

--- src/sys/dev/spkrvar.h 2017/06/11 03:33:48 1.7
+++ src/sys/dev/spkrvar.h 2017/06/11 03:55:56 1.8
@@ -1,22 +1,23 @@ @@ -1,22 +1,23 @@
1/* $NetBSD: spkrvar.h,v 1.7 2017/06/11 03:33:48 nat Exp $ */ 1/* $NetBSD: spkrvar.h,v 1.8 2017/06/11 03:55:56 nat Exp $ */
2 2
3#ifndef _SYS_DEV_SPKRVAR_H 3#ifndef _SYS_DEV_SPKRVAR_H
4#define _SYS_DEV_SPKRVAR_H 4#define _SYS_DEV_SPKRVAR_H
5 5
6#include <sys/module.h> 6#include <sys/module.h>
7 7
8struct spkr_softc { 8struct spkr_softc {
9 device_t sc_dev; 9 device_t sc_dev;
 10 device_t sc_wsbelldev;
10 int sc_octave; /* currently selected octave */ 11 int sc_octave; /* currently selected octave */
11 int sc_whole; /* whole-note time at current tempo, in ticks */ 12 int sc_whole; /* whole-note time at current tempo, in ticks */
12 int sc_value; /* whole divisor for note time, quarter note = 1 */ 13 int sc_value; /* whole divisor for note time, quarter note = 1 */
13 int sc_fill; /* controls spacing of notes */ 14 int sc_fill; /* controls spacing of notes */
14 bool sc_octtrack; /* octave-tracking on? */ 15 bool sc_octtrack; /* octave-tracking on? */
15 bool sc_octprefix; /* override current octave-tracking state? */ 16 bool sc_octprefix; /* override current octave-tracking state? */
16 char *sc_inbuf; 17 char *sc_inbuf;
17 18
18 /* attachment-specific hooks */ 19 /* attachment-specific hooks */
19 void (*sc_tone)(device_t, u_int, u_int); 20 void (*sc_tone)(device_t, u_int, u_int);
20 void (*sc_rest)(device_t, int); 21 void (*sc_rest)(device_t, int);
21 u_int sc_vol; /* volume - only for audio skpr */ 22 u_int sc_vol; /* volume - only for audio skpr */
22}; 23};

cvs diff -r1.32 -r1.33 src/sys/dev/pckbport/pckbd.c (expand / switch to unified diff)

--- src/sys/dev/pckbport/pckbd.c 2015/07/16 15:01:04 1.32
+++ src/sys/dev/pckbport/pckbd.c 2017/06/11 03:55:56 1.33
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pckbd.c,v 1.32 2015/07/16 15:01:04 prlw1 Exp $ */ 1/* $NetBSD: pckbd.c,v 1.33 2017/06/11 03:55:56 nat Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum. 8 * by Charles M. Hannum.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -58,27 +58,27 @@ @@ -58,27 +58,27 @@
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE. 61 * SUCH DAMAGE.
62 * 62 *
63 * @(#)pccons.c 5.11 (Berkeley) 5/21/91 63 * @(#)pccons.c 5.11 (Berkeley) 5/21/91
64 */ 64 */
65 65
66/* 66/*
67 * code to work keyboard for PC-style console 67 * code to work keyboard for PC-style console
68 */ 68 */
69 69
70#include <sys/cdefs.h> 70#include <sys/cdefs.h>
71__KERNEL_RCSID(0, "$NetBSD: pckbd.c,v 1.32 2015/07/16 15:01:04 prlw1 Exp $"); 71__KERNEL_RCSID(0, "$NetBSD: pckbd.c,v 1.33 2017/06/11 03:55:56 nat Exp $");
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/systm.h> 74#include <sys/systm.h>
75#include <sys/device.h> 75#include <sys/device.h>
76#include <sys/malloc.h> 76#include <sys/malloc.h>
77#include <sys/ioctl.h> 77#include <sys/ioctl.h>
78 78
79#include <sys/bus.h> 79#include <sys/bus.h>
80 80
81#include <dev/pckbport/pckbportvar.h> 81#include <dev/pckbport/pckbportvar.h>
82 82
83#include <dev/wscons/wsconsio.h> 83#include <dev/wscons/wsconsio.h>
84#include <dev/wscons/wskbdvar.h> 84#include <dev/wscons/wskbdvar.h>
@@ -1000,35 +1000,37 @@ pckbd_ioctl(void *v, u_long cmd, void *d @@ -1000,35 +1000,37 @@ pckbd_ioctl(void *v, u_long cmd, void *d
1000 int res; 1000 int res;
1001 u_char cmdb[2]; 1001 u_char cmdb[2];
1002 1002
1003 cmdb[0] = KBC_MODEIND; 1003 cmdb[0] = KBC_MODEIND;
1004 cmdb[1] = pckbd_led_encode(*(int *)data); 1004 cmdb[1] = pckbd_led_encode(*(int *)data);
1005 sc->sc_ledstate = cmdb[1]; 1005 sc->sc_ledstate = cmdb[1];
1006 res = pckbport_enqueue_cmd(sc->id->t_kbctag, sc->id->t_kbcslot, 1006 res = pckbport_enqueue_cmd(sc->id->t_kbctag, sc->id->t_kbcslot,
1007 cmdb, 2, 0, 1, 0); 1007 cmdb, 2, 0, 1, 0);
1008 return res; 1008 return res;
1009 } 1009 }
1010 case WSKBDIO_GETLEDS: 1010 case WSKBDIO_GETLEDS:
1011 *(int *)data = pckbd_led_decode(sc->sc_ledstate); 1011 *(int *)data = pckbd_led_decode(sc->sc_ledstate);
1012 return 0; 1012 return 0;
 1013#if 0
1013 case WSKBDIO_COMPLEXBELL: 1014 case WSKBDIO_COMPLEXBELL:
1014#define d ((struct wskbd_bell_data *)data) 1015#define d ((struct wskbd_bell_data *)data)
1015 /* 1016 /*
1016 * Keyboard can't beep directly; we have an 1017 * Keyboard can't beep directly; we have an
1017 * externally-provided global hook to do this. 1018 * externally-provided global hook to do this.
1018 */ 1019 */
1019 pckbd_bell(d->pitch, d->period, d->volume, 0); 1020 pckbd_bell(d->pitch, d->period, d->volume, 0);
1020#undef d 1021#undef d
1021 return 0; 1022 return 0;
 1023#endif
1022#ifdef WSDISPLAY_COMPAT_RAWKBD 1024#ifdef WSDISPLAY_COMPAT_RAWKBD
1023 case WSKBDIO_SETMODE: 1025 case WSKBDIO_SETMODE:
1024 sc->rawkbd = (*(int *)data == WSKBD_RAW); 1026 sc->rawkbd = (*(int *)data == WSKBD_RAW);
1025 return 0; 1027 return 0;
1026#endif 1028#endif
1027 } 1029 }
1028 return EPASSTHROUGH; 1030 return EPASSTHROUGH;
1029} 1031}
1030 1032
1031void 1033void
1032pckbd_bell(u_int pitch, u_int period, u_int volume, int poll) 1034pckbd_bell(u_int pitch, u_int period, u_int volume, int poll)
1033{ 1035{
1034 1036

cvs diff -r1.50 -r1.51 src/sys/dev/wscons/files.wscons (expand / switch to unified diff)

--- src/sys/dev/wscons/files.wscons 2017/05/19 19:22:33 1.50
+++ src/sys/dev/wscons/files.wscons 2017/06/11 03:55:56 1.51
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files.wscons,v 1.50 2017/05/19 19:22:33 macallan Exp $ 1# $NetBSD: files.wscons,v 1.51 2017/06/11 03:55:56 nat Exp $
2 2
3# 3#
4# "Workstation Console" glue; attaches frame buffer to emulator & keyboard, 4# "Workstation Console" glue; attaches frame buffer to emulator & keyboard,
5# plus deals with kernel mouse drivers. 5# plus deals with kernel mouse drivers.
6# 6#
7# These files are included with strange conditions because of the hairy 7# These files are included with strange conditions because of the hairy
8# interactions between them. In particular, chunks of the glue, 8# interactions between them. In particular, chunks of the glue,
9# keyboard, and mouse code are called directly by other chunks. Also, 9# keyboard, and mouse code are called directly by other chunks. Also,
10# each hardware driver can make calls into its (child) interface driver. 10# each hardware driver can make calls into its (child) interface driver.
11# This could all be cleaned up, but it's not clear that it's worth the 11# This could all be cleaned up, but it's not clear that it's worth the
12# trouble. 12# trouble.
13# 13#
14 14
@@ -33,50 +33,54 @@ defflag opt_wsdisplay_compat.h WSDISPLAY @@ -33,50 +33,54 @@ defflag opt_wsdisplay_compat.h WSDISPLAY
33 WSKBD_EVENT_AUTOREPEAT 33 WSKBD_EVENT_AUTOREPEAT
34defparam opt_wsdisplay_compat.h WSCOMPAT_USL_SYNCTIMEOUT 34defparam opt_wsdisplay_compat.h WSCOMPAT_USL_SYNCTIMEOUT
35 WSDISPLAY_DEFAULTSCREENS 35 WSDISPLAY_DEFAULTSCREENS
36defparam opt_wsdisplay_compat.h WSDISPLAY_SCROLLBACK_LINES=100 36defparam opt_wsdisplay_compat.h WSDISPLAY_SCROLLBACK_LINES=100
37 37
38# this loses, but there's no way to define attributes which have attributes 38# this loses, but there's no way to define attributes which have attributes
39device wsdisplay #tty? 39device wsdisplay #tty?
40attach wsdisplay at wsemuldisplaydev with wsdisplay_emul 40attach wsdisplay at wsemuldisplaydev with wsdisplay_emul
41attach wsdisplay at wsdisplaydev with wsdisplay_noemul 41attach wsdisplay at wsdisplaydev with wsdisplay_noemul
42device wskbd 42device wskbd
43attach wskbd at wskbddev 43attach wskbd at wskbddev
44device wsmouse 44device wsmouse
45attach wsmouse at wsmousedev 45attach wsmouse at wsmousedev
 46device wsbell
 47attach wsbell at wsbelldev
46 48
47file dev/wscons/wsdisplay.c wsdisplay needs-flag 49file dev/wscons/wsdisplay.c wsdisplay needs-flag
48file dev/wscons/wsdisplay_compat_usl.c wsdisplay & wsdisplay_compat_usl 50file dev/wscons/wsdisplay_compat_usl.c wsdisplay & wsdisplay_compat_usl
49file dev/wscons/wsdisplay_util.c wsdisplay 51file dev/wscons/wsdisplay_util.c wsdisplay
50file dev/wscons/wsemulconf.c wsdisplay 52file dev/wscons/wsemulconf.c wsdisplay
51file dev/wscons/wsemul_dumb.c wsdisplay & !wsemul_no_dumb 53file dev/wscons/wsemul_dumb.c wsdisplay & !wsemul_no_dumb
52file dev/wscons/wsemul_sun.c wsdisplay & wsemul_sun 54file dev/wscons/wsemul_sun.c wsdisplay & wsemul_sun
53file dev/wscons/wsemul_vt100.c wsdisplay & wsemul_vt100 55file dev/wscons/wsemul_vt100.c wsdisplay & wsemul_vt100
54file dev/wscons/wsemul_vt100_subr.c wsdisplay & wsemul_vt100 56file dev/wscons/wsemul_vt100_subr.c wsdisplay & wsemul_vt100
55file dev/wscons/wsemul_vt100_chars.c wsdisplay & wsemul_vt100 57file dev/wscons/wsemul_vt100_chars.c wsdisplay & wsemul_vt100
56file dev/wscons/wsemul_vt100_keys.c wsdisplay & wsemul_vt100 58file dev/wscons/wsemul_vt100_keys.c wsdisplay & wsemul_vt100
57file dev/wscons/wsevent.c wsdisplay | wskbd | wsmouse | wsmux 59file dev/wscons/wsevent.c wsdisplay | wskbd | wsmouse | wsmux
58file dev/wscons/wskbd.c wskbd needs-flag 60file dev/wscons/wskbd.c wskbd needs-flag
59file dev/wscons/wskbdutil.c wskbd needs-flag 61file dev/wscons/wskbdutil.c wskbd needs-flag
60file dev/wscons/wsmouse.c wsmouse needs-flag 62file dev/wscons/wsmouse.c wsmouse needs-flag
 63file dev/wscons/wsbell.c wsbell needs-flag
61 64
62# rcons bit-depth options 65# rcons bit-depth options
63include "dev/rcons/files.rcons" 66include "dev/rcons/files.rcons"
64 67
65file dev/wscons/wscons_rinit.c wsrasteremulops 68file dev/wscons/wscons_rinit.c wsrasteremulops
66file dev/wscons/wscons_rops.c wsrasteremulops 69file dev/wscons/wscons_rops.c wsrasteremulops
67 70
68defpseudo wsmux 71defpseudo wsmux
69file dev/wscons/wsmux.c wsmux needs-flag 72file dev/wscons/wsmux.c wsmux needs-flag
 73file dev/wscons/wsbellmux.c wsmux needs-flag
70 74
71define tpcalib 75define tpcalib
72file dev/wscons/tpcalib.c tpcalib 76file dev/wscons/tpcalib.c tpcalib
73file dev/wscons/mra.c tpcalib 77file dev/wscons/mra.c tpcalib
74defflag opt_tpcalib.h TPCALIBDEBUG 78defflag opt_tpcalib.h TPCALIBDEBUG
75 79
76# generic virtual console support on bitmapped framebuffers 80# generic virtual console support on bitmapped framebuffers
77file dev/wscons/wsdisplay_vcons.c vcons 81file dev/wscons/wsdisplay_vcons.c vcons
78file dev/wscons/wsdisplay_vcons_util.c vcons 82file dev/wscons/wsdisplay_vcons_util.c vcons
79defflag opt_vcons.h VCONS_DRAW_INTR VCONS_INTR_DEBUG VCONS_DEBUG 83defflag opt_vcons.h VCONS_DRAW_INTR VCONS_INTR_DEBUG VCONS_DEBUG
80 84
81# generic support code for caching rendered glyphs in video memory 85# generic support code for caching rendered glyphs in video memory
82define glyphcache 86define glyphcache

File Added: src/sys/dev/wscons/wsbell.c
/* $NetBSD: wsbell.c,v 1.1 2017/06/11 03:55:56 nat Exp $ */

/*-
 * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au>
 * All rights reserved.
 *
 * Copyright (c) 2006 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Julio M. Merino Vidal.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Christopher G. Demetriou
 *	for the NetBSD Project.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This software was developed by the Computer Systems Engineering group
 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
 * contributed to Berkeley.
 *
 * All advertising materials mentioning features or use of this software
 * must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Lawrence Berkeley Laboratory.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)ms.c	8.1 (Berkeley) 6/11/93
 */

/*
 * Keyboard Bell driver.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.1 2017/06/11 03:55:56 nat Exp $");

#include "wsdisplay.h"
#include "wsmux.h"

#include <sys/param.h>
#include <sys/conf.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/condvar.h>
#include <sys/mutex.h>
#include <sys/kthread.h>
#include <sys/proc.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/signalvar.h>
#include <sys/device.h>
#include <sys/vnode.h>
#include <sys/callout.h>
#include <sys/malloc.h>

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsbellvar.h>
#include <dev/wscons/wsbellmuxvar.h>
#include <dev/wscons/wsbelldata.h>

#include <dev/spkrio.h>

#if defined(WSMUX_DEBUG) && NWSMUX > 0
#define DPRINTF(x)	if (wsmuxdebug) printf x
#define DPRINTFN(n,x)	if (wsmuxdebug > (n)) printf x
extern int wsmuxdebug;
#else
#define DPRINTF(x)
#define DPRINTFN(n,x)
#endif

static void bell_thread(void *);
static inline void spkr_audio_play(struct wsbell_softc *, u_int, u_int, u_int);

static int  wsbell_match(device_t, cfdata_t, void *);
static void wsbell_attach(device_t, device_t, void *);
static int  wsbell_detach(device_t, int);
static int  wsbell_activate(device_t, enum devact);

#if NWSMUX > 0
static int  wsbell_mux_open(struct wsevsrc *, struct wseventvar *);
static int  wsbell_mux_close(struct wsevsrc *);

static int  wsbelldoopen(struct wsbell_softc *, struct wseventvar *);
static int  wsbelldoioctl(device_t, u_long, void *, int, struct lwp *);

static int  wsbell_do_ioctl(struct wsbell_softc *, u_long, void *,
			     int, struct lwp *);

#endif

CFATTACH_DECL_NEW(wsbell, sizeof (struct wsbell_softc),
    wsbell_match, wsbell_attach, wsbell_detach, wsbell_activate);

extern struct cfdriver wsbell_cd;

extern dev_type_open(spkropen);
extern dev_type_close(spkrclose);
extern dev_type_ioctl(spkrioctl);

const struct cdevsw wsbell_cdevsw = {
	.d_open = noopen,
	.d_close = noclose,
	.d_read = noread,
	.d_write = nowrite,
	.d_ioctl = noioctl,
	.d_stop = nostop,
	.d_tty = notty,
	.d_poll = nopoll,
	.d_mmap = nommap,
	.d_kqfilter = nokqfilter,
	.d_discard = nodiscard,
	.d_flag = D_OTHER
};

#if NWSMUX > 0
struct wssrcops wsbell_srcops = {
	WSMUX_BELL,
	wsbell_mux_open, wsbell_mux_close, wsbelldoioctl, wsbelldoioctl, NULL
};
#endif

int
wsbell_match(device_t parent, cfdata_t match, void *aux)
{
	return (1);
}

void
wsbell_attach(device_t parent, device_t self, void *aux)
{
        struct wsbell_softc *sc = device_private(self);
	struct wsbelldev_attach_args *ap = aux;
#if NWSMUX > 0
	int mux, error;
#endif

	sc->sc_base.me_dv = self;
	sc->sc_accesscookie = ap->accesscookie;

	sc->sc_spkr = device_unit(parent);
	sc->sc_bell_data = wskbd_default_bell_data;
#if NWSMUX > 0
	sc->sc_base.me_ops = &wsbell_srcops;
	mux = device_cfdata(self)->wsbelldevcf_mux;
	if (mux >= 0) {
		error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base);
		if (error)
			aprint_error(" attach error=%d", error);
		else
			aprint_normal(" mux %d", mux);
	}
#else
	if (device_cfdata(self)->wsbelldevcf_mux >= 0)
		aprint_normal(" (mux ignored)");
#endif

	aprint_naive("\n");
	aprint_normal("\n");

	if (!pmf_device_register(self, NULL, NULL))
		aprint_error_dev(self, "couldn't establish power handler\n");

	mutex_init(&sc->sc_bellock, MUTEX_DEFAULT, IPL_SCHED);
	cv_init(&sc->sc_bellcv, "bellcv");

	kthread_create(PRI_BIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
	    bell_thread, sc, &sc->sc_bellthread, "%s", device_xname(self));
}

int
wsbell_activate(device_t self, enum devact act)
{
	struct wsbell_softc *sc = device_private(self);

	if (act == DVACT_DEACTIVATE)
		sc->sc_dying = 1;
	return (0);
}

int
wsbell_detach(device_t self, int flags)
{
	struct wsbell_softc *sc = device_private(self);
	struct wseventvar *evar;
	int maj, mn;
	int s;

#if NWSMUX > 0
	/* Tell parent mux we're leaving. */
	if (sc->sc_base.me_parent != NULL) {
		DPRINTF(("wsbell_detach:\n"));
		wsmux_detach_sc(&sc->sc_base);
	}
#endif

	/* If we're open ... */
	evar = sc->sc_base.me_evp;
	if (evar != NULL && evar->io != NULL) {
		s = spltty();
		if (--sc->sc_refcnt >= 0) {
			struct wscons_event event;

			/* Wake everyone by generating a dummy event. */
			event.type = 0;
			event.value = 0;
			if (wsevent_inject(evar, &event, 1) != 0)
				wsevent_wakeup(evar);

			/* Wait for processes to go away. */
			if (tsleep(sc, PZERO, "wsmdet", hz * 60))
				printf("wsbell_detach: %s didn't detach\n",
				       device_xname(self));
		}
		splx(s);
	}

	/* locate the major number */
	maj = cdevsw_lookup_major(&wsbell_cdevsw);

	/* Nuke the vnodes for any open instances (calls close). */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);

	mutex_enter(&sc->sc_bellock);
	sc->sc_bell_args.dying = true;

	cv_broadcast(&sc->sc_bellcv);
	mutex_exit(&sc->sc_bellock);

	kthread_join(sc->sc_bellthread);
	cv_destroy(&sc->sc_bellcv);
	mutex_destroy(&sc->sc_bellock);

	return (0);
}

#if NWSMUX > 0
int
wsbelldoopen(struct wsbell_softc *sc, struct wseventvar *evp)
{
	return (0);
}

/* A wrapper around the ioctl() workhorse to make reference counting easy. */
int
wsbelldoioctl(device_t dv, u_long cmd, void *data, int flag,
	       struct lwp *l)
{
	struct wsbell_softc *sc = device_private(dv);
	int error;

	sc->sc_refcnt++;
	error = wsbell_do_ioctl(sc, cmd, data, flag, l);
	if (--sc->sc_refcnt < 0)
		wakeup(sc);
	return (error);
}

int
wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data,
		 int flag, struct lwp *l)
{
	struct wskbd_bell_data *ubdp, *kbdp;
	if (sc->sc_dying)
		return (EIO);

	/*
	 * Try the wsbell specific ioctls.
	 */
	switch (cmd) {
#define	SETBELL(dstp, srcp, dfltp)					\
    do {								\
	(dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ?		\
	    (srcp)->pitch : (dfltp)->pitch;				\
	(dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ?	\
	    (srcp)->period : (dfltp)->period;				\
	(dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ?	\
	    (srcp)->volume : (dfltp)->volume;				\
	(dstp)->which = WSKBD_BELL_DOALL;				\
    } while (0)

	case WSKBDIO_SETBELL:
		if ((flag & FWRITE) == 0)
			return (EACCES);
		kbdp = &sc->sc_bell_data;
		ubdp = (struct wskbd_bell_data *)data;
		SETBELL(kbdp, ubdp, kbdp);
		return (0);

	case WSKBDIO_GETBELL:
		kbdp = &sc->sc_bell_data;
		ubdp = (struct wskbd_bell_data *)data;
		SETBELL(ubdp, kbdp, kbdp);
		return (0);

	case WSKBDIO_BELL:
		if ((flag & FWRITE) == 0)
			return (EACCES);
		spkr_audio_play(sc, sc->sc_bell_data.pitch,
		    sc->sc_bell_data.period, sc->sc_bell_data.volume);

		return 0;

	case WSKBDIO_COMPLEXBELL:
		if ((flag & FWRITE) == 0)
			return (EACCES);
		if (data == NULL)
			return 0;
#define d ((struct wskbd_bell_data *)data)
		spkr_audio_play(sc, d->pitch, d->period, d->volume);
#undef d
		return 0;
	}	

	return (EPASSTHROUGH);
}
#endif

static void
bell_thread(void *arg)
{
	struct wsbell_softc *sc = arg;
	struct vbell_args *vb = &sc->sc_bell_args;
	tone_t tone;
	u_int vol;
	
	for (;;) {
		mutex_enter(&sc->sc_bellock);
		cv_wait_sig(&sc->sc_bellcv, &sc->sc_bellock);
		
		if (vb->dying == true) {
			mutex_exit(&sc->sc_bellock);
			kthread_exit(0);
		}
		
		tone.frequency = vb->pitch;
		tone.duration = vb->period;
		vol = vb->volume;
		mutex_exit(&sc->sc_bellock);

		if (spkropen(sc->sc_spkr, FWRITE, 0, NULL) != 0)
			continue;
		spkrioctl(sc->sc_spkr, SPKRSETVOL, &vol, 0, curlwp);
		spkrioctl(sc->sc_spkr, SPKRTONE, &tone, 0, curlwp);
		spkrclose(sc->sc_spkr, FWRITE, 0, curlwp);
	}
}

static inline void
spkr_audio_play(struct wsbell_softc *sc, u_int pitch, u_int period, u_int volume)
{

	mutex_enter(&sc->sc_bellock);
	sc->sc_bell_args.dying = false;
	sc->sc_bell_args.pitch = pitch;
	sc->sc_bell_args.period = period / 5;
	sc->sc_bell_args.volume = volume;

	cv_broadcast(&sc->sc_bellcv);
	mutex_exit(&sc->sc_bellock);
}

#if NWSMUX > 0
int
wsbell_mux_open(struct wsevsrc *me, struct wseventvar *evp)
{
	struct wsbell_softc *sc = (struct wsbell_softc *)me;

	if (sc->sc_base.me_evp != NULL)
		return (EBUSY);

	return wsbelldoopen(sc, evp);
}

int
wsbell_mux_close(struct wsevsrc *me)
{
	struct wsbell_softc *sc = (struct wsbell_softc *)me;

	sc->sc_base.me_evp = NULL;

	return (0);
}
#endif /* NWSMUX > 0 */

File Added: src/sys/dev/wscons/wsbellmux.c
/* $NetBSD: wsbellmux.c,v 1.1 2017/06/11 03:55:56 nat Exp $ */
/*-
 * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wsbellmux.c,v 1.1 2017/06/11 03:55:56 nat Exp $");

#include <sys/param.h>
#include <sys/conf.h>
#include <sys/types.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <sys/selinfo.h>

#include "wsmux.h"

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsbellvar.h>

/*
 * Print function (for parent devices).
 */
int
wsbelldevprint(void *aux, const char *pnp)
{

	if (pnp)
		aprint_normal("wsbell at %s", pnp);
	return (UNCONF);
}

#if NWSMUX > 0
int
wsbell_add_mux(int unit, struct wsmux_softc *muxsc)
{
	struct wsbell_softc *sc;
	device_t wsbelldev;
	cfdriver_t wsbellcd;

	wsbelldev = device_find_by_driver_unit("wsbell", unit);
	if (wsbelldev == NULL)
		return ENXIO;
	wsbellcd = device_cfdriver(wsbelldev);
	if (wsbellcd == NULL)
		return ENXIO;

	sc = device_lookup_private(wsbellcd, unit);
	if (sc == NULL)
		return ENXIO;

	if (sc->sc_base.me_parent != NULL || sc->sc_base.me_evp != NULL)
		return (EBUSY);

	return (wsmux_attach_sc(muxsc, &sc->sc_base));
}
#endif

File Added: src/sys/dev/wscons/wsbellmuxvar.h
/* $NetBSD: wsbellmuxvar.h,v 1.1 2017/06/11 03:55:56 nat Exp $ */
/*-
 * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

struct wsbelldev_attach_args {
	void	*accesscookie;				/* access cookie */
};


File Added: src/sys/dev/wscons/wsbellvar.h
/* $NetBSD: wsbellvar.h,v 1.1 2017/06/11 03:55:56 nat Exp $ */
/*-
 * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "locators.h"
#include <dev/wscons/wseventvar.h>
#include <dev/wscons/wsmuxvar.h>

#define	wsbelldevcf_mux	cf_loc[WSBELLDEVCF_MUX]

struct vbell_args {
	u_int pitch;
	u_int period;
	u_int volume;
	bool dying;
};

struct wsbell_softc {
	struct wsevsrc	sc_base;
	dev_t		sc_spkr;	/* our spkr device */
	struct wskbd_bell_data sc_bell_data;

	void		*sc_accesscookie;

	int		sc_refcnt;
	u_char		sc_dying;	/* device is being detached */

	lwp_t		*sc_bellthread;
	kmutex_t	sc_bellock;
	kcondvar_t	sc_bellcv;

	struct vbell_args sc_bell_args;
};

/*
 * Autoconfiguration helper functions.
 */
int	wsbelldevprint(void *, const char *);

cvs diff -r1.118 -r1.119 src/sys/dev/wscons/wsconsio.h (expand / switch to unified diff)

--- src/sys/dev/wscons/wsconsio.h 2017/06/03 14:49:42 1.118
+++ src/sys/dev/wscons/wsconsio.h 2017/06/11 03:55:56 1.119
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wsconsio.h,v 1.118 2017/06/03 14:49:42 jmcneill Exp $ */ 1/* $NetBSD: wsconsio.h,v 1.119 2017/06/11 03:55:56 nat Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. 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 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -534,26 +534,27 @@ struct wsdisplay_msgattrs { @@ -534,26 +534,27 @@ struct wsdisplay_msgattrs {
534 534
535#define WSDISPLAYIO_SETVERSION _IOW('W', 96, int) 535#define WSDISPLAYIO_SETVERSION _IOW('W', 96, int)
536#define WSDISPLAYIO_EVENT_VERSION WSEVENT_VERSION 536#define WSDISPLAYIO_EVENT_VERSION WSEVENT_VERSION
537 537
538/* 538/*
539 * Mux ioctls (97 - 127) 539 * Mux ioctls (97 - 127)
540 */ 540 */
541 541
542struct wsmux_device { 542struct wsmux_device {
543 int type; 543 int type;
544#define WSMUX_MOUSE 1 544#define WSMUX_MOUSE 1
545#define WSMUX_KBD 2 545#define WSMUX_KBD 2
546#define WSMUX_MUX 3 546#define WSMUX_MUX 3
 547#define WSMUX_BELL 4
547 int idx; 548 int idx;
548}; 549};
549#define WSMUXIO_ADD_DEVICE _IOW('W', 97, struct wsmux_device) 550#define WSMUXIO_ADD_DEVICE _IOW('W', 97, struct wsmux_device)
550#define WSMUX_ADD_DEVICE WSMUXIO_ADD_DEVICE /* XXX compat */ 551#define WSMUX_ADD_DEVICE WSMUXIO_ADD_DEVICE /* XXX compat */
551#define WSMUXIO_REMOVE_DEVICE _IOW('W', 98, struct wsmux_device) 552#define WSMUXIO_REMOVE_DEVICE _IOW('W', 98, struct wsmux_device)
552#define WSMUX_REMOVE_DEVICE WSMUXIO_REMOVE_DEVICE /* XXX compat */ 553#define WSMUX_REMOVE_DEVICE WSMUXIO_REMOVE_DEVICE /* XXX compat */
553 554
554#define WSMUX_MAXDEV 32 555#define WSMUX_MAXDEV 32
555struct wsmux_device_list { 556struct wsmux_device_list {
556 int ndevices; 557 int ndevices;
557 struct wsmux_device devices[WSMUX_MAXDEV]; 558 struct wsmux_device devices[WSMUX_MAXDEV];
558}; 559};
559#define WSMUXIO_LIST_DEVICES _IOWR('W', 99, struct wsmux_device_list) 560#define WSMUXIO_LIST_DEVICES _IOWR('W', 99, struct wsmux_device_list)

cvs diff -r1.61 -r1.62 src/sys/dev/wscons/wsmux.c (expand / switch to unified diff)

--- src/sys/dev/wscons/wsmux.c 2016/07/07 06:55:42 1.61
+++ src/sys/dev/wscons/wsmux.c 2017/06/11 03:55:56 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wsmux.c,v 1.61 2016/07/07 06:55:42 msaitoh Exp $ */ 1/* $NetBSD: wsmux.c,v 1.62 2017/06/11 03:55:56 nat Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Lennart Augustsson <lennart@augustsson.net> 7 * Author: Lennart Augustsson <lennart@augustsson.net>
8 * Carlstedt Research & Technology 8 * Carlstedt Research & Technology
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,37 +27,38 @@ @@ -27,37 +27,38 @@
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * wscons mux device. 33 * wscons mux device.
34 * 34 *
35 * The mux device is a collection of real mice and keyboards and acts as 35 * The mux device is a collection of real mice and keyboards and acts as
36 * a merge point for all the events from the different real devices. 36 * a merge point for all the events from the different real devices.
37 */ 37 */
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.61 2016/07/07 06:55:42 msaitoh Exp $"); 40__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.62 2017/06/11 03:55:56 nat Exp $");
41 41
42#ifdef _KERNEL_OPT 42#ifdef _KERNEL_OPT
43#include "opt_compat_netbsd.h" 43#include "opt_compat_netbsd.h"
44#include "opt_modular.h" 44#include "opt_modular.h"
45#endif 45#endif
46 46
47#include "wsdisplay.h" 47#include "wsdisplay.h"
48#include "wsmux.h" 48#include "wsmux.h"
49#include "wskbd.h" 49#include "wskbd.h"
50#include "wsmouse.h" 50#include "wsmouse.h"
 51#include "wsbell.h"
51 52
52#include <sys/param.h> 53#include <sys/param.h>
53#include <sys/conf.h> 54#include <sys/conf.h>
54#include <sys/ioctl.h> 55#include <sys/ioctl.h>
55#include <sys/poll.h> 56#include <sys/poll.h>
56#include <sys/fcntl.h> 57#include <sys/fcntl.h>
57#include <sys/kernel.h> 58#include <sys/kernel.h>
58#include <sys/malloc.h> 59#include <sys/malloc.h>
59#include <sys/proc.h> 60#include <sys/proc.h>
60#include <sys/queue.h> 61#include <sys/queue.h>
61#include <sys/syslog.h> 62#include <sys/syslog.h>
62#include <sys/systm.h> 63#include <sys/systm.h>
63#include <sys/tty.h> 64#include <sys/tty.h>
@@ -446,26 +447,28 @@ wsmux_do_ioctl(device_t dv, u_long cmd,  @@ -446,26 +447,28 @@ wsmux_do_ioctl(device_t dv, u_long cmd,
446 DPRINTF(("%s: add type=%d, no=%d\n", 447 DPRINTF(("%s: add type=%d, no=%d\n",
447 device_xname(sc->sc_base.me_dv), d->type, d->idx)); 448 device_xname(sc->sc_base.me_dv), d->type, d->idx));
448 switch (d->type) { 449 switch (d->type) {
449#if NWSMOUSE > 0 450#if NWSMOUSE > 0
450 case WSMUX_MOUSE: 451 case WSMUX_MOUSE:
451 return (wsmouse_add_mux(d->idx, sc)); 452 return (wsmouse_add_mux(d->idx, sc));
452#endif 453#endif
453#if NWSKBD > 0 454#if NWSKBD > 0
454 case WSMUX_KBD: 455 case WSMUX_KBD:
455 return (wskbd_add_mux(d->idx, sc)); 456 return (wskbd_add_mux(d->idx, sc));
456#endif 457#endif
457 case WSMUX_MUX: 458 case WSMUX_MUX:
458 return (wsmux_add_mux(d->idx, sc)); 459 return (wsmux_add_mux(d->idx, sc));
 460 case WSMUX_BELL:
 461 return (wsbell_add_mux(d->idx, sc));
459 default: 462 default:
460 return (EINVAL); 463 return (EINVAL);
461 } 464 }
462 case WSMUXIO_REMOVE_DEVICE: 465 case WSMUXIO_REMOVE_DEVICE:
463 DPRINTF(("%s: rem type=%d, no=%d\n", 466 DPRINTF(("%s: rem type=%d, no=%d\n",
464 device_xname(sc->sc_base.me_dv), d->type, d->idx)); 467 device_xname(sc->sc_base.me_dv), d->type, d->idx));
465 /* Locate the device */ 468 /* Locate the device */
466 TAILQ_FOREACH(me, &sc->sc_cld, me_next) { 469 TAILQ_FOREACH(me, &sc->sc_cld, me_next) {
467 if (me->me_ops->type == d->type && 470 if (me->me_ops->type == d->type &&
468 device_unit(me->me_dv) == d->idx) { 471 device_unit(me->me_dv) == d->idx) {
469 DPRINTF(("wsmux_do_ioctl: detach\n")); 472 DPRINTF(("wsmux_do_ioctl: detach\n"));
470 wsmux_detach_sc(me); 473 wsmux_detach_sc(me);
471 return (0); 474 return (0);

cvs diff -r1.15 -r1.16 src/sys/dev/wscons/wsmuxvar.h (expand / switch to unified diff)

--- src/sys/dev/wscons/wsmuxvar.h 2013/11/23 20:56:41 1.15
+++ src/sys/dev/wscons/wsmuxvar.h 2017/06/11 03:55:56 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wsmuxvar.h,v 1.15 2013/11/23 20:56:41 christos Exp $ */ 1/* $NetBSD: wsmuxvar.h,v 1.16 2017/06/11 03:55:56 nat Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Lennart Augustsson <augustss@carlstedt.se> 7 * Author: Lennart Augustsson <augustss@carlstedt.se>
8 * Carlstedt Research & Technology 8 * Carlstedt Research & Technology
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -79,15 +79,16 @@ struct wsmux_softc { @@ -79,15 +79,16 @@ struct wsmux_softc {
79#ifdef WSDISPLAY_COMPAT_RAWKBD 79#ifdef WSDISPLAY_COMPAT_RAWKBD
80 int sc_rawkbd; /* A hack to remember the kbd mode */ 80 int sc_rawkbd; /* A hack to remember the kbd mode */
81#endif 81#endif
82}; 82};
83 83
84struct wsmux_softc *wsmux_getmux(int); 84struct wsmux_softc *wsmux_getmux(int);
85struct wsmux_softc *wsmux_create(const char *, int); 85struct wsmux_softc *wsmux_create(const char *, int);
86int wsmux_attach_sc(struct wsmux_softc *, struct wsevsrc *); 86int wsmux_attach_sc(struct wsmux_softc *, struct wsevsrc *);
87void wsmux_detach_sc(struct wsevsrc *); 87void wsmux_detach_sc(struct wsevsrc *);
88int wsmux_set_display(struct wsmux_softc *, device_t); 88int wsmux_set_display(struct wsmux_softc *, device_t);
89 89
90int wskbd_add_mux(int, struct wsmux_softc *); 90int wskbd_add_mux(int, struct wsmux_softc *);
91int wsmouse_add_mux(int, struct wsmux_softc *); 91int wsmouse_add_mux(int, struct wsmux_softc *);
 92int wsbell_add_mux(int, struct wsmux_softc *);
92 93
93#endif /* NWSMUX > 0 */ 94#endif /* NWSMUX > 0 */