Tue Jun 13 00:42:27 2017 UTC ()
Move duplicate definition of SETBELL macro into wsbelldata.h.


(nat)
diff -r1.4 -r1.5 src/sys/dev/wscons/wsbell.c
diff -r1.1 -r1.2 src/sys/dev/wscons/wsbelldata.h
diff -r1.139 -r1.140 src/sys/dev/wscons/wskbd.c

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

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

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

--- src/sys/dev/wscons/wsbelldata.h 2017/06/11 03:38:12 1.1
+++ src/sys/dev/wscons/wsbelldata.h 2017/06/13 00:42:27 1.2
@@ -1,43 +1,54 @@ @@ -1,43 +1,54 @@
1/* $NetBSD: wsbelldata.h,v 1.1 2017/06/11 03:38:12 nat Exp $ */ 1/* $NetBSD: wsbelldata.h,v 1.2 2017/06/13 00:42:27 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#ifndef WSKBD_DEFAULT_BELL_PITCH 28#ifndef WSKBD_DEFAULT_BELL_PITCH
29#define WSKBD_DEFAULT_BELL_PITCH 1500 /* 1500Hz */ 29#define WSKBD_DEFAULT_BELL_PITCH 1500 /* 1500Hz */
30#endif 30#endif
31#ifndef WSKBD_DEFAULT_BELL_PERIOD 31#ifndef WSKBD_DEFAULT_BELL_PERIOD
32#define WSKBD_DEFAULT_BELL_PERIOD 100 /* 100ms */ 32#define WSKBD_DEFAULT_BELL_PERIOD 100 /* 100ms */
33#endif 33#endif
34#ifndef WSKBD_DEFAULT_BELL_VOLUME 34#ifndef WSKBD_DEFAULT_BELL_VOLUME
35#define WSKBD_DEFAULT_BELL_VOLUME 50 /* 50% volume */ 35#define WSKBD_DEFAULT_BELL_VOLUME 50 /* 50% volume */
36#endif 36#endif
37 37
 38#define SETBELL(dstp, srcp, dfltp) \
 39 do { \
 40 (dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ? \
 41 (srcp)->pitch : (dfltp)->pitch; \
 42 (dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ? \
 43 (srcp)->period : (dfltp)->period; \
 44 (dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ? \
 45 (srcp)->volume : (dfltp)->volume; \
 46 (dstp)->which = WSKBD_BELL_DOALL; \
 47 } while (0)
 48
38static struct wskbd_bell_data wskbd_default_bell_data = { 49static struct wskbd_bell_data wskbd_default_bell_data = {
39 WSKBD_BELL_DOALL, 50 WSKBD_BELL_DOALL,
40 WSKBD_DEFAULT_BELL_PITCH, 51 WSKBD_DEFAULT_BELL_PITCH,
41 WSKBD_DEFAULT_BELL_PERIOD, 52 WSKBD_DEFAULT_BELL_PERIOD,
42 WSKBD_DEFAULT_BELL_VOLUME, 53 WSKBD_DEFAULT_BELL_VOLUME,
43}; 54};

cvs diff -r1.139 -r1.140 src/sys/dev/wscons/wskbd.c (switch to unified diff)

--- src/sys/dev/wscons/wskbd.c 2017/06/11 03:38:12 1.139
+++ src/sys/dev/wscons/wskbd.c 2017/06/13 00:42:27 1.140
@@ -1,1902 +1,1891 @@ @@ -1,1902 +1,1891 @@
1/* $NetBSD: wskbd.c,v 1.139 2017/06/11 03:38:12 nat Exp $ */ 1/* $NetBSD: wskbd.c,v 1.140 2017/06/13 00:42:27 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
15 * must display the following acknowledgement: 15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou 16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project. 17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products 18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission 19 * derived from this software without specific prior written permission
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Copyright (c) 1998 The NetBSD Foundation, Inc. 34 * Copyright (c) 1998 The NetBSD Foundation, Inc.
35 * All rights reserved. 35 * All rights reserved.
36 * 36 *
37 * Keysym translator contributed to The NetBSD Foundation by 37 * Keysym translator contributed to The NetBSD Foundation by
38 * Juergen Hannken-Illjes. 38 * Juergen Hannken-Illjes.
39 * 39 *
40 * Redistribution and use in source and binary forms, with or without 40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions 41 * modification, are permitted provided that the following conditions
42 * are met: 42 * are met:
43 * 1. Redistributions of source code must retain the above copyright 43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer. 44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright 45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the 46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution. 47 * documentation and/or other materials provided with the distribution.
48 * 48 *
49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGE. 59 * POSSIBILITY OF SUCH DAMAGE.
60 */ 60 */
61 61
62/* 62/*
63 * Copyright (c) 1992, 1993 63 * Copyright (c) 1992, 1993
64 * The Regents of the University of California. All rights reserved. 64 * The Regents of the University of California. All rights reserved.
65 * 65 *
66 * This software was developed by the Computer Systems Engineering group 66 * This software was developed by the Computer Systems Engineering group
67 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 67 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
68 * contributed to Berkeley. 68 * contributed to Berkeley.
69 * 69 *
70 * All advertising materials mentioning features or use of this software 70 * All advertising materials mentioning features or use of this software
71 * must display the following acknowledgement: 71 * must display the following acknowledgement:
72 * This product includes software developed by the University of 72 * This product includes software developed by the University of
73 * California, Lawrence Berkeley Laboratory. 73 * California, Lawrence Berkeley Laboratory.
74 * 74 *
75 * Redistribution and use in source and binary forms, with or without 75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions 76 * modification, are permitted provided that the following conditions
77 * are met: 77 * are met:
78 * 1. Redistributions of source code must retain the above copyright 78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer. 79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright 80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the 81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution. 82 * documentation and/or other materials provided with the distribution.
83 * 3. Neither the name of the University nor the names of its contributors 83 * 3. Neither the name of the University nor the names of its contributors
84 * may be used to endorse or promote products derived from this software 84 * may be used to endorse or promote products derived from this software
85 * without specific prior written permission. 85 * without specific prior written permission.
86 * 86 *
87 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 87 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
88 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 88 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 90 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 93 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * SUCH DAMAGE. 97 * SUCH DAMAGE.
98 * 98 *
99 * @(#)kbd.c 8.2 (Berkeley) 10/30/93 99 * @(#)kbd.c 8.2 (Berkeley) 10/30/93
100 */ 100 */
101 101
102/* 102/*
103 * Keyboard driver (/dev/wskbd*). Translates incoming bytes to ASCII or 103 * Keyboard driver (/dev/wskbd*). Translates incoming bytes to ASCII or
104 * to `wscons_events' and passes them up to the appropriate reader. 104 * to `wscons_events' and passes them up to the appropriate reader.
105 */ 105 */
106 106
107#include <sys/cdefs.h> 107#include <sys/cdefs.h>
108__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.139 2017/06/11 03:38:12 nat Exp $"); 108__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.140 2017/06/13 00:42:27 nat Exp $");
109 109
110#ifdef _KERNEL_OPT 110#ifdef _KERNEL_OPT
111#include "opt_ddb.h" 111#include "opt_ddb.h"
112#include "opt_kgdb.h" 112#include "opt_kgdb.h"
113#include "opt_wsdisplay_compat.h" 113#include "opt_wsdisplay_compat.h"
114#endif 114#endif
115 115
116#include "wsdisplay.h" 116#include "wsdisplay.h"
117#include "wskbd.h" 117#include "wskbd.h"
118#include "wsmux.h" 118#include "wsmux.h"
119 119
120#include <sys/param.h> 120#include <sys/param.h>
121#include <sys/conf.h> 121#include <sys/conf.h>
122#include <sys/device.h> 122#include <sys/device.h>
123#include <sys/ioctl.h> 123#include <sys/ioctl.h>
124#include <sys/poll.h> 124#include <sys/poll.h>
125#include <sys/kernel.h> 125#include <sys/kernel.h>
126#include <sys/proc.h> 126#include <sys/proc.h>
127#include <sys/syslog.h> 127#include <sys/syslog.h>
128#include <sys/systm.h> 128#include <sys/systm.h>
129#include <sys/callout.h> 129#include <sys/callout.h>
130#include <sys/malloc.h> 130#include <sys/malloc.h>
131#include <sys/tty.h> 131#include <sys/tty.h>
132#include <sys/signalvar.h> 132#include <sys/signalvar.h>
133#include <sys/errno.h> 133#include <sys/errno.h>
134#include <sys/fcntl.h> 134#include <sys/fcntl.h>
135#include <sys/vnode.h> 135#include <sys/vnode.h>
136#include <sys/kauth.h> 136#include <sys/kauth.h>
137 137
138#include <dev/wscons/wsconsio.h> 138#include <dev/wscons/wsconsio.h>
139#include <dev/wscons/wskbdvar.h> 139#include <dev/wscons/wskbdvar.h>
140#include <dev/wscons/wsksymdef.h> 140#include <dev/wscons/wsksymdef.h>
141#include <dev/wscons/wsksymvar.h> 141#include <dev/wscons/wsksymvar.h>
142#include <dev/wscons/wsdisplayvar.h> 142#include <dev/wscons/wsdisplayvar.h>
143#include <dev/wscons/wseventvar.h> 143#include <dev/wscons/wseventvar.h>
144#include <dev/wscons/wscons_callbacks.h> 144#include <dev/wscons/wscons_callbacks.h>
145#include <dev/wscons/wsbelldata.h> 145#include <dev/wscons/wsbelldata.h>
146 146
147#ifdef KGDB 147#ifdef KGDB
148#include <sys/kgdb.h> 148#include <sys/kgdb.h>
149#endif 149#endif
150 150
151#ifdef WSKBD_DEBUG 151#ifdef WSKBD_DEBUG
152#define DPRINTF(x) if (wskbddebug) printf x 152#define DPRINTF(x) if (wskbddebug) printf x
153int wskbddebug = 0; 153int wskbddebug = 0;
154#else 154#else
155#define DPRINTF(x) 155#define DPRINTF(x)
156#endif 156#endif
157 157
158#include <dev/wscons/wsmuxvar.h> 158#include <dev/wscons/wsmuxvar.h>
159 159
160struct wskbd_internal { 160struct wskbd_internal {
161 const struct wskbd_mapdata *t_keymap; 161 const struct wskbd_mapdata *t_keymap;
162 162
163 const struct wskbd_consops *t_consops; 163 const struct wskbd_consops *t_consops;
164 void *t_consaccesscookie; 164 void *t_consaccesscookie;
165 165
166 int t_modifiers; 166 int t_modifiers;
167 int t_composelen; /* remaining entries in t_composebuf */ 167 int t_composelen; /* remaining entries in t_composebuf */
168 keysym_t t_composebuf[2]; 168 keysym_t t_composebuf[2];
169 169
170 int t_flags; 170 int t_flags;
171#define WSKFL_METAESC 1 171#define WSKFL_METAESC 1
172 172
173#define MAXKEYSYMSPERKEY 2 /* ESC <key> at max */ 173#define MAXKEYSYMSPERKEY 2 /* ESC <key> at max */
174 keysym_t t_symbols[MAXKEYSYMSPERKEY]; 174 keysym_t t_symbols[MAXKEYSYMSPERKEY];
175 175
176 struct wskbd_softc *t_sc; /* back pointer */ 176 struct wskbd_softc *t_sc; /* back pointer */
177}; 177};
178 178
179struct wskbd_softc { 179struct wskbd_softc {
180 struct wsevsrc sc_base; 180 struct wsevsrc sc_base;
181 181
182 struct wskbd_internal *id; 182 struct wskbd_internal *id;
183 183
184 const struct wskbd_accessops *sc_accessops; 184 const struct wskbd_accessops *sc_accessops;
185 void *sc_accesscookie; 185 void *sc_accesscookie;
186 186
187 int sc_ledstate; 187 int sc_ledstate;
188 188
189 int sc_isconsole; 189 int sc_isconsole;
190 190
191 struct wskbd_bell_data sc_bell_data; 191 struct wskbd_bell_data sc_bell_data;
192 struct wskbd_keyrepeat_data sc_keyrepeat_data; 192 struct wskbd_keyrepeat_data sc_keyrepeat_data;
193#ifdef WSDISPLAY_SCROLLSUPPORT 193#ifdef WSDISPLAY_SCROLLSUPPORT
194 struct wskbd_scroll_data sc_scroll_data; 194 struct wskbd_scroll_data sc_scroll_data;
195#endif 195#endif
196 196
197 int sc_repeating; /* we've called timeout() */ 197 int sc_repeating; /* we've called timeout() */
198 callout_t sc_repeat_ch; 198 callout_t sc_repeat_ch;
199 u_int sc_repeat_type; 199 u_int sc_repeat_type;
200 int sc_repeat_value; 200 int sc_repeat_value;
201 201
202 int sc_translating; /* xlate to chars for emulation */ 202 int sc_translating; /* xlate to chars for emulation */
203 203
204 int sc_maplen; /* number of entries in sc_map */ 204 int sc_maplen; /* number of entries in sc_map */
205 struct wscons_keymap *sc_map; /* current translation map */ 205 struct wscons_keymap *sc_map; /* current translation map */
206 kbd_t sc_layout; /* current layout */ 206 kbd_t sc_layout; /* current layout */
207 207
208 int sc_refcnt; 208 int sc_refcnt;
209 u_char sc_dying; /* device is being detached */ 209 u_char sc_dying; /* device is being detached */
210 210
211 wskbd_hotkey_plugin *sc_hotkey; 211 wskbd_hotkey_plugin *sc_hotkey;
212 void *sc_hotkeycookie; 212 void *sc_hotkeycookie;
213 213
214 /* optional table to translate scancodes in event mode */ 214 /* optional table to translate scancodes in event mode */
215 int sc_evtrans_len; 215 int sc_evtrans_len;
216 keysym_t *sc_evtrans; 216 keysym_t *sc_evtrans;
217}; 217};
218 218
219#define MOD_SHIFT_L (1 << 0) 219#define MOD_SHIFT_L (1 << 0)
220#define MOD_SHIFT_R (1 << 1) 220#define MOD_SHIFT_R (1 << 1)
221#define MOD_SHIFTLOCK (1 << 2) 221#define MOD_SHIFTLOCK (1 << 2)
222#define MOD_CAPSLOCK (1 << 3) 222#define MOD_CAPSLOCK (1 << 3)
223#define MOD_CONTROL_L (1 << 4) 223#define MOD_CONTROL_L (1 << 4)
224#define MOD_CONTROL_R (1 << 5) 224#define MOD_CONTROL_R (1 << 5)
225#define MOD_META_L (1 << 6) 225#define MOD_META_L (1 << 6)
226#define MOD_META_R (1 << 7) 226#define MOD_META_R (1 << 7)
227#define MOD_MODESHIFT (1 << 8) 227#define MOD_MODESHIFT (1 << 8)
228#define MOD_NUMLOCK (1 << 9) 228#define MOD_NUMLOCK (1 << 9)
229#define MOD_COMPOSE (1 << 10) 229#define MOD_COMPOSE (1 << 10)
230#define MOD_HOLDSCREEN (1 << 11) 230#define MOD_HOLDSCREEN (1 << 11)
231#define MOD_COMMAND (1 << 12) 231#define MOD_COMMAND (1 << 12)
232#define MOD_COMMAND1 (1 << 13) 232#define MOD_COMMAND1 (1 << 13)
233#define MOD_COMMAND2 (1 << 14) 233#define MOD_COMMAND2 (1 << 14)
234 234
235#define MOD_ANYSHIFT (MOD_SHIFT_L | MOD_SHIFT_R | MOD_SHIFTLOCK) 235#define MOD_ANYSHIFT (MOD_SHIFT_L | MOD_SHIFT_R | MOD_SHIFTLOCK)
236#define MOD_ANYCONTROL (MOD_CONTROL_L | MOD_CONTROL_R) 236#define MOD_ANYCONTROL (MOD_CONTROL_L | MOD_CONTROL_R)
237#define MOD_ANYMETA (MOD_META_L | MOD_META_R) 237#define MOD_ANYMETA (MOD_META_L | MOD_META_R)
238 238
239#define MOD_ONESET(id, mask) (((id)->t_modifiers & (mask)) != 0) 239#define MOD_ONESET(id, mask) (((id)->t_modifiers & (mask)) != 0)
240#define MOD_ALLSET(id, mask) (((id)->t_modifiers & (mask)) == (mask)) 240#define MOD_ALLSET(id, mask) (((id)->t_modifiers & (mask)) == (mask))
241 241
242#define GETMODSTATE(src, dst) \ 242#define GETMODSTATE(src, dst) \
243 do { \ 243 do { \
244 dst |= (src & MOD_SHIFT_L) ? MOD_SHIFT_L : 0; \ 244 dst |= (src & MOD_SHIFT_L) ? MOD_SHIFT_L : 0; \
245 dst |= (src & MOD_SHIFT_R) ? MOD_SHIFT_R : 0; \ 245 dst |= (src & MOD_SHIFT_R) ? MOD_SHIFT_R : 0; \
246 dst |= (src & MOD_CONTROL_L) ? MOD_CONTROL_L : 0; \ 246 dst |= (src & MOD_CONTROL_L) ? MOD_CONTROL_L : 0; \
247 dst |= (src & MOD_CONTROL_R) ? MOD_CONTROL_R : 0; \ 247 dst |= (src & MOD_CONTROL_R) ? MOD_CONTROL_R : 0; \
248 dst |= (src & MOD_META_L) ? MOD_META_L : 0; \ 248 dst |= (src & MOD_META_L) ? MOD_META_L : 0; \
249 dst |= (src & MOD_META_R) ? MOD_META_R : 0; \ 249 dst |= (src & MOD_META_R) ? MOD_META_R : 0; \
250 } while (0) 250 } while (0)
251 251
252static int wskbd_match(device_t, cfdata_t, void *); 252static int wskbd_match(device_t, cfdata_t, void *);
253static void wskbd_attach(device_t, device_t, void *); 253static void wskbd_attach(device_t, device_t, void *);
254static int wskbd_detach(device_t, int); 254static int wskbd_detach(device_t, int);
255static int wskbd_activate(device_t, enum devact); 255static int wskbd_activate(device_t, enum devact);
256 256
257static int wskbd_displayioctl(device_t, u_long, void *, int, 257static int wskbd_displayioctl(device_t, u_long, void *, int,
258 struct lwp *); 258 struct lwp *);
259#if NWSDISPLAY > 0 259#if NWSDISPLAY > 0
260static int wskbd_set_display(device_t, struct wsevsrc *); 260static int wskbd_set_display(device_t, struct wsevsrc *);
261#else 261#else
262#define wskbd_set_display NULL 262#define wskbd_set_display NULL
263#endif 263#endif
264 264
265static inline void update_leds(struct wskbd_internal *); 265static inline void update_leds(struct wskbd_internal *);
266static inline void update_modifier(struct wskbd_internal *, u_int, int, int); 266static inline void update_modifier(struct wskbd_internal *, u_int, int, int);
267static int internal_command(struct wskbd_softc *, u_int *, keysym_t, keysym_t); 267static int internal_command(struct wskbd_softc *, u_int *, keysym_t, keysym_t);
268static int wskbd_translate(struct wskbd_internal *, u_int, int); 268static int wskbd_translate(struct wskbd_internal *, u_int, int);
269static int wskbd_enable(struct wskbd_softc *, int); 269static int wskbd_enable(struct wskbd_softc *, int);
270#if NWSDISPLAY > 0 270#if NWSDISPLAY > 0
271static void change_displayparam(struct wskbd_softc *, int, int, int); 271static void change_displayparam(struct wskbd_softc *, int, int, int);
272static void wskbd_holdscreen(struct wskbd_softc *, int); 272static void wskbd_holdscreen(struct wskbd_softc *, int);
273#endif 273#endif
274 274
275static int wskbd_do_ioctl_sc(struct wskbd_softc *, u_long, void *, int, 275static int wskbd_do_ioctl_sc(struct wskbd_softc *, u_long, void *, int,
276 struct lwp *); 276 struct lwp *);
277static void wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value); 277static void wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value);
278 278
279#if NWSMUX > 0 279#if NWSMUX > 0
280static int wskbd_mux_open(struct wsevsrc *, struct wseventvar *); 280static int wskbd_mux_open(struct wsevsrc *, struct wseventvar *);
281static int wskbd_mux_close(struct wsevsrc *); 281static int wskbd_mux_close(struct wsevsrc *);
282#else 282#else
283#define wskbd_mux_open NULL 283#define wskbd_mux_open NULL
284#define wskbd_mux_close NULL 284#define wskbd_mux_close NULL
285#endif 285#endif
286 286
287static int wskbd_do_open(struct wskbd_softc *, struct wseventvar *); 287static int wskbd_do_open(struct wskbd_softc *, struct wseventvar *);
288static int wskbd_do_ioctl(device_t, u_long, void *, int, struct lwp *); 288static int wskbd_do_ioctl(device_t, u_long, void *, int, struct lwp *);
289 289
290CFATTACH_DECL_NEW(wskbd, sizeof (struct wskbd_softc), 290CFATTACH_DECL_NEW(wskbd, sizeof (struct wskbd_softc),
291 wskbd_match, wskbd_attach, wskbd_detach, wskbd_activate); 291 wskbd_match, wskbd_attach, wskbd_detach, wskbd_activate);
292 292
293extern struct cfdriver wskbd_cd; 293extern struct cfdriver wskbd_cd;
294 294
295dev_type_open(wskbdopen); 295dev_type_open(wskbdopen);
296dev_type_close(wskbdclose); 296dev_type_close(wskbdclose);
297dev_type_read(wskbdread); 297dev_type_read(wskbdread);
298dev_type_ioctl(wskbdioctl); 298dev_type_ioctl(wskbdioctl);
299dev_type_poll(wskbdpoll); 299dev_type_poll(wskbdpoll);
300dev_type_kqfilter(wskbdkqfilter); 300dev_type_kqfilter(wskbdkqfilter);
301 301
302const struct cdevsw wskbd_cdevsw = { 302const struct cdevsw wskbd_cdevsw = {
303 .d_open = wskbdopen, 303 .d_open = wskbdopen,
304 .d_close = wskbdclose, 304 .d_close = wskbdclose,
305 .d_read = wskbdread, 305 .d_read = wskbdread,
306 .d_write = nowrite, 306 .d_write = nowrite,
307 .d_ioctl = wskbdioctl, 307 .d_ioctl = wskbdioctl,
308 .d_stop = nostop, 308 .d_stop = nostop,
309 .d_tty = notty, 309 .d_tty = notty,
310 .d_poll = wskbdpoll, 310 .d_poll = wskbdpoll,
311 .d_mmap = nommap, 311 .d_mmap = nommap,
312 .d_kqfilter = wskbdkqfilter, 312 .d_kqfilter = wskbdkqfilter,
313 .d_discard = nodiscard, 313 .d_discard = nodiscard,
314 .d_flag = D_OTHER 314 .d_flag = D_OTHER
315}; 315};
316 316
317#ifdef WSDISPLAY_SCROLLSUPPORT 317#ifdef WSDISPLAY_SCROLLSUPPORT
318struct wskbd_scroll_data wskbd_default_scroll_data = { 318struct wskbd_scroll_data wskbd_default_scroll_data = {
319 WSKBD_SCROLL_DOALL, 319 WSKBD_SCROLL_DOALL,
320 WSKBD_SCROLL_MODE_NORMAL, 320 WSKBD_SCROLL_MODE_NORMAL,
321#ifdef WSDISPLAY_SCROLLCOMBO 321#ifdef WSDISPLAY_SCROLLCOMBO
322 WSDISPLAY_SCROLLCOMBO, 322 WSDISPLAY_SCROLLCOMBO,
323#else 323#else
324 MOD_SHIFT_L, 324 MOD_SHIFT_L,
325#endif 325#endif
326}; 326};
327#endif 327#endif
328 328
329#ifndef WSKBD_DEFAULT_KEYREPEAT_DEL1 329#ifndef WSKBD_DEFAULT_KEYREPEAT_DEL1
330#define WSKBD_DEFAULT_KEYREPEAT_DEL1 400 /* 400ms to start repeating */ 330#define WSKBD_DEFAULT_KEYREPEAT_DEL1 400 /* 400ms to start repeating */
331#endif 331#endif
332#ifndef WSKBD_DEFAULT_KEYREPEAT_DELN 332#ifndef WSKBD_DEFAULT_KEYREPEAT_DELN
333#define WSKBD_DEFAULT_KEYREPEAT_DELN 100 /* 100ms to between repeats */ 333#define WSKBD_DEFAULT_KEYREPEAT_DELN 100 /* 100ms to between repeats */
334#endif 334#endif
335 335
336struct wskbd_keyrepeat_data wskbd_default_keyrepeat_data = { 336struct wskbd_keyrepeat_data wskbd_default_keyrepeat_data = {
337 WSKBD_KEYREPEAT_DOALL, 337 WSKBD_KEYREPEAT_DOALL,
338 WSKBD_DEFAULT_KEYREPEAT_DEL1, 338 WSKBD_DEFAULT_KEYREPEAT_DEL1,
339 WSKBD_DEFAULT_KEYREPEAT_DELN, 339 WSKBD_DEFAULT_KEYREPEAT_DELN,
340}; 340};
341 341
342#if NWSDISPLAY > 0 || NWSMUX > 0 342#if NWSDISPLAY > 0 || NWSMUX > 0
343struct wssrcops wskbd_srcops = { 343struct wssrcops wskbd_srcops = {
344 WSMUX_KBD, 344 WSMUX_KBD,
345 wskbd_mux_open, wskbd_mux_close, wskbd_do_ioctl, 345 wskbd_mux_open, wskbd_mux_close, wskbd_do_ioctl,
346 wskbd_displayioctl, wskbd_set_display 346 wskbd_displayioctl, wskbd_set_display
347}; 347};
348#endif 348#endif
349 349
350static bool wskbd_suspend(device_t dv, const pmf_qual_t *); 350static bool wskbd_suspend(device_t dv, const pmf_qual_t *);
351static void wskbd_repeat(void *v); 351static void wskbd_repeat(void *v);
352 352
353static int wskbd_console_initted; 353static int wskbd_console_initted;
354static struct wskbd_softc *wskbd_console_device; 354static struct wskbd_softc *wskbd_console_device;
355static struct wskbd_internal wskbd_console_data; 355static struct wskbd_internal wskbd_console_data;
356 356
357static void wskbd_update_layout(struct wskbd_internal *, kbd_t); 357static void wskbd_update_layout(struct wskbd_internal *, kbd_t);
358 358
359static void 359static void
360wskbd_update_layout(struct wskbd_internal *id, kbd_t enc) 360wskbd_update_layout(struct wskbd_internal *id, kbd_t enc)
361{ 361{
362 362
363 if (enc & KB_METAESC) 363 if (enc & KB_METAESC)
364 id->t_flags |= WSKFL_METAESC; 364 id->t_flags |= WSKFL_METAESC;
365 else 365 else
366 id->t_flags &= ~WSKFL_METAESC; 366 id->t_flags &= ~WSKFL_METAESC;
367} 367}
368 368
369/* 369/*
370 * Print function (for parent devices). 370 * Print function (for parent devices).
371 */ 371 */
372int 372int
373wskbddevprint(void *aux, const char *pnp) 373wskbddevprint(void *aux, const char *pnp)
374{ 374{
375#if 0 375#if 0
376 struct wskbddev_attach_args *ap = aux; 376 struct wskbddev_attach_args *ap = aux;
377#endif 377#endif
378 378
379 if (pnp) 379 if (pnp)
380 aprint_normal("wskbd at %s", pnp); 380 aprint_normal("wskbd at %s", pnp);
381#if 0 381#if 0
382 aprint_normal(" console %d", ap->console); 382 aprint_normal(" console %d", ap->console);
383#endif 383#endif
384 384
385 return (UNCONF); 385 return (UNCONF);
386} 386}
387 387
388int 388int
389wskbd_match(device_t parent, cfdata_t match, void *aux) 389wskbd_match(device_t parent, cfdata_t match, void *aux)
390{ 390{
391 struct wskbddev_attach_args *ap = aux; 391 struct wskbddev_attach_args *ap = aux;
392 392
393 if (match->wskbddevcf_console != WSKBDDEVCF_CONSOLE_UNK) { 393 if (match->wskbddevcf_console != WSKBDDEVCF_CONSOLE_UNK) {
394 /* 394 /*
395 * If console-ness of device specified, either match 395 * If console-ness of device specified, either match
396 * exactly (at high priority), or fail. 396 * exactly (at high priority), or fail.
397 */ 397 */
398 if (match->wskbddevcf_console != 0 && ap->console != 0) 398 if (match->wskbddevcf_console != 0 && ap->console != 0)
399 return (10); 399 return (10);
400 else 400 else
401 return (0); 401 return (0);
402 } 402 }
403 403
404 /* If console-ness unspecified, it wins. */ 404 /* If console-ness unspecified, it wins. */
405 return (1); 405 return (1);
406} 406}
407 407
408void 408void
409wskbd_attach(device_t parent, device_t self, void *aux) 409wskbd_attach(device_t parent, device_t self, void *aux)
410{ 410{
411 struct wskbd_softc *sc = device_private(self); 411 struct wskbd_softc *sc = device_private(self);
412 struct wskbddev_attach_args *ap = aux; 412 struct wskbddev_attach_args *ap = aux;
413#if NWSMUX > 0 413#if NWSMUX > 0
414 int mux, error; 414 int mux, error;
415#endif 415#endif
416 416
417 sc->sc_base.me_dv = self; 417 sc->sc_base.me_dv = self;
418 sc->sc_isconsole = ap->console; 418 sc->sc_isconsole = ap->console;
419 sc->sc_hotkey = NULL; 419 sc->sc_hotkey = NULL;
420 sc->sc_hotkeycookie = NULL; 420 sc->sc_hotkeycookie = NULL;
421 sc->sc_evtrans_len = 0; 421 sc->sc_evtrans_len = 0;
422 sc->sc_evtrans = NULL; 422 sc->sc_evtrans = NULL;
423 423
424#if NWSMUX > 0 || NWSDISPLAY > 0 424#if NWSMUX > 0 || NWSDISPLAY > 0
425 sc->sc_base.me_ops = &wskbd_srcops; 425 sc->sc_base.me_ops = &wskbd_srcops;
426#endif 426#endif
427#if NWSMUX > 0 427#if NWSMUX > 0
428 mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux; 428 mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux;
429 if (ap->console) { 429 if (ap->console) {
430 /* Ignore mux for console; it always goes to the console mux. */ 430 /* Ignore mux for console; it always goes to the console mux. */
431 /* printf(" (mux %d ignored for console)", mux); */ 431 /* printf(" (mux %d ignored for console)", mux); */
432 mux = -1; 432 mux = -1;
433 } 433 }
434 if (mux >= 0) 434 if (mux >= 0)
435 aprint_normal(" mux %d", mux); 435 aprint_normal(" mux %d", mux);
436#else 436#else
437 if (device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux >= 0) 437 if (device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux >= 0)
438 aprint_normal(" (mux ignored)"); 438 aprint_normal(" (mux ignored)");
439#endif 439#endif
440 440
441 if (ap->console) { 441 if (ap->console) {
442 sc->id = &wskbd_console_data; 442 sc->id = &wskbd_console_data;
443 } else { 443 } else {
444 sc->id = malloc(sizeof(struct wskbd_internal), 444 sc->id = malloc(sizeof(struct wskbd_internal),
445 M_DEVBUF, M_WAITOK|M_ZERO); 445 M_DEVBUF, M_WAITOK|M_ZERO);
446 sc->id->t_keymap = ap->keymap; 446 sc->id->t_keymap = ap->keymap;
447 wskbd_update_layout(sc->id, ap->keymap->layout); 447 wskbd_update_layout(sc->id, ap->keymap->layout);
448 } 448 }
449 449
450 callout_init(&sc->sc_repeat_ch, 0); 450 callout_init(&sc->sc_repeat_ch, 0);
451 callout_setfunc(&sc->sc_repeat_ch, wskbd_repeat, sc); 451 callout_setfunc(&sc->sc_repeat_ch, wskbd_repeat, sc);
452 452
453 sc->id->t_sc = sc; 453 sc->id->t_sc = sc;
454 454
455 sc->sc_accessops = ap->accessops; 455 sc->sc_accessops = ap->accessops;
456 sc->sc_accesscookie = ap->accesscookie; 456 sc->sc_accesscookie = ap->accesscookie;
457 sc->sc_repeating = 0; 457 sc->sc_repeating = 0;
458 sc->sc_translating = 1; 458 sc->sc_translating = 1;
459 sc->sc_ledstate = -1; /* force update */ 459 sc->sc_ledstate = -1; /* force update */
460 460
461 if (wskbd_load_keymap(sc->id->t_keymap, 461 if (wskbd_load_keymap(sc->id->t_keymap,
462 &sc->sc_map, &sc->sc_maplen) != 0) 462 &sc->sc_map, &sc->sc_maplen) != 0)
463 panic("cannot load keymap"); 463 panic("cannot load keymap");
464 464
465 sc->sc_layout = sc->id->t_keymap->layout; 465 sc->sc_layout = sc->id->t_keymap->layout;
466 466
467 /* set default bell and key repeat data */ 467 /* set default bell and key repeat data */
468 sc->sc_bell_data = wskbd_default_bell_data; 468 sc->sc_bell_data = wskbd_default_bell_data;
469 sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data; 469 sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data;
470 470
471#ifdef WSDISPLAY_SCROLLSUPPORT 471#ifdef WSDISPLAY_SCROLLSUPPORT
472 sc->sc_scroll_data = wskbd_default_scroll_data; 472 sc->sc_scroll_data = wskbd_default_scroll_data;
473#endif 473#endif
474 474
475 if (ap->console) { 475 if (ap->console) {
476 KASSERT(wskbd_console_initted); 476 KASSERT(wskbd_console_initted);
477 KASSERT(wskbd_console_device == NULL); 477 KASSERT(wskbd_console_device == NULL);
478 478
479 wskbd_console_device = sc; 479 wskbd_console_device = sc;
480 480
481 aprint_naive(": console keyboard"); 481 aprint_naive(": console keyboard");
482 aprint_normal(": console keyboard"); 482 aprint_normal(": console keyboard");
483 483
484#if NWSDISPLAY > 0 484#if NWSDISPLAY > 0
485 wsdisplay_set_console_kbd(&sc->sc_base); /* sets me_dispv */ 485 wsdisplay_set_console_kbd(&sc->sc_base); /* sets me_dispv */
486 if (sc->sc_base.me_dispdv != NULL) 486 if (sc->sc_base.me_dispdv != NULL)
487 aprint_normal(", using %s", 487 aprint_normal(", using %s",
488 device_xname(sc->sc_base.me_dispdv)); 488 device_xname(sc->sc_base.me_dispdv));
489#endif 489#endif
490 } 490 }
491 aprint_naive("\n"); 491 aprint_naive("\n");
492 aprint_normal("\n"); 492 aprint_normal("\n");
493 493
494#if NWSMUX > 0 494#if NWSMUX > 0
495 if (mux >= 0) { 495 if (mux >= 0) {
496 error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); 496 error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base);
497 if (error) 497 if (error)
498 aprint_error_dev(sc->sc_base.me_dv, 498 aprint_error_dev(sc->sc_base.me_dv,
499 "attach error=%d\n", error); 499 "attach error=%d\n", error);
500 } 500 }
501#endif 501#endif
502 502
503 if (!pmf_device_register(self, wskbd_suspend, NULL)) 503 if (!pmf_device_register(self, wskbd_suspend, NULL))
504 aprint_error_dev(self, "couldn't establish power handler\n"); 504 aprint_error_dev(self, "couldn't establish power handler\n");
505 else if (!pmf_class_input_register(self)) 505 else if (!pmf_class_input_register(self))
506 aprint_error_dev(self, "couldn't register as input device\n"); 506 aprint_error_dev(self, "couldn't register as input device\n");
507} 507}
508 508
509static bool 509static bool
510wskbd_suspend(device_t dv, const pmf_qual_t *qual) 510wskbd_suspend(device_t dv, const pmf_qual_t *qual)
511{ 511{
512 struct wskbd_softc *sc = device_private(dv); 512 struct wskbd_softc *sc = device_private(dv);
513 513
514 sc->sc_repeating = 0; 514 sc->sc_repeating = 0;
515 callout_stop(&sc->sc_repeat_ch); 515 callout_stop(&sc->sc_repeat_ch);
516 516
517 return true; 517 return true;
518} 518}
519 519
520void 520void
521wskbd_cnattach(const struct wskbd_consops *consops, void *conscookie, 521wskbd_cnattach(const struct wskbd_consops *consops, void *conscookie,
522 const struct wskbd_mapdata *mapdata) 522 const struct wskbd_mapdata *mapdata)
523{ 523{
524 KASSERT(!wskbd_console_initted); 524 KASSERT(!wskbd_console_initted);
525 525
526 wskbd_console_data.t_keymap = mapdata; 526 wskbd_console_data.t_keymap = mapdata;
527 wskbd_update_layout(&wskbd_console_data, mapdata->layout); 527 wskbd_update_layout(&wskbd_console_data, mapdata->layout);
528 528
529 wskbd_console_data.t_consops = consops; 529 wskbd_console_data.t_consops = consops;
530 wskbd_console_data.t_consaccesscookie = conscookie; 530 wskbd_console_data.t_consaccesscookie = conscookie;
531 531
532#if NWSDISPLAY > 0 532#if NWSDISPLAY > 0
533 wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell); 533 wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell);
534#endif 534#endif
535 535
536 wskbd_console_initted = 1; 536 wskbd_console_initted = 1;
537} 537}
538 538
539void 539void
540wskbd_cndetach(void) 540wskbd_cndetach(void)
541{ 541{
542 KASSERT(wskbd_console_initted); 542 KASSERT(wskbd_console_initted);
543 543
544 wskbd_console_data.t_keymap = 0; 544 wskbd_console_data.t_keymap = 0;
545 545
546 wskbd_console_data.t_consops = 0; 546 wskbd_console_data.t_consops = 0;
547 wskbd_console_data.t_consaccesscookie = 0; 547 wskbd_console_data.t_consaccesscookie = 0;
548 548
549#if NWSDISPLAY > 0 549#if NWSDISPLAY > 0
550 wsdisplay_unset_cons_kbd(); 550 wsdisplay_unset_cons_kbd();
551#endif 551#endif
552 552
553 wskbd_console_initted = 0; 553 wskbd_console_initted = 0;
554} 554}
555 555
556static void 556static void
557wskbd_repeat(void *v) 557wskbd_repeat(void *v)
558{ 558{
559 struct wskbd_softc *sc = (struct wskbd_softc *)v; 559 struct wskbd_softc *sc = (struct wskbd_softc *)v;
560 int s = spltty(); 560 int s = spltty();
561 561
562 if (!sc->sc_repeating) { 562 if (!sc->sc_repeating) {
563 /* 563 /*
564 * race condition: a "key up" event came in when wskbd_repeat() 564 * race condition: a "key up" event came in when wskbd_repeat()
565 * was already called but not yet spltty()'d 565 * was already called but not yet spltty()'d
566 */ 566 */
567 splx(s); 567 splx(s);
568 return; 568 return;
569 } 569 }
570 if (sc->sc_translating) { 570 if (sc->sc_translating) {
571 /* deliver keys */ 571 /* deliver keys */
572#if NWSDISPLAY > 0 572#if NWSDISPLAY > 0
573 if (sc->sc_base.me_dispdv != NULL) { 573 if (sc->sc_base.me_dispdv != NULL) {
574 int i; 574 int i;
575 for (i = 0; i < sc->sc_repeating; i++) 575 for (i = 0; i < sc->sc_repeating; i++)
576 wsdisplay_kbdinput(sc->sc_base.me_dispdv, 576 wsdisplay_kbdinput(sc->sc_base.me_dispdv,
577 sc->id->t_symbols[i]); 577 sc->id->t_symbols[i]);
578 } 578 }
579#endif 579#endif
580 } else { 580 } else {
581#if defined(WSKBD_EVENT_AUTOREPEAT) 581#if defined(WSKBD_EVENT_AUTOREPEAT)
582 /* queue event */ 582 /* queue event */
583 wskbd_deliver_event(sc, sc->sc_repeat_type, 583 wskbd_deliver_event(sc, sc->sc_repeat_type,
584 sc->sc_repeat_value); 584 sc->sc_repeat_value);
585#endif /* defined(WSKBD_EVENT_AUTOREPEAT) */ 585#endif /* defined(WSKBD_EVENT_AUTOREPEAT) */
586 } 586 }
587 callout_schedule(&sc->sc_repeat_ch, mstohz(sc->sc_keyrepeat_data.delN)); 587 callout_schedule(&sc->sc_repeat_ch, mstohz(sc->sc_keyrepeat_data.delN));
588 splx(s); 588 splx(s);
589} 589}
590 590
591int 591int
592wskbd_activate(device_t self, enum devact act) 592wskbd_activate(device_t self, enum devact act)
593{ 593{
594 struct wskbd_softc *sc = device_private(self); 594 struct wskbd_softc *sc = device_private(self);
595 595
596 if (act == DVACT_DEACTIVATE) 596 if (act == DVACT_DEACTIVATE)
597 sc->sc_dying = 1; 597 sc->sc_dying = 1;
598 return (0); 598 return (0);
599} 599}
600 600
601/* 601/*
602 * Detach a keyboard. To keep track of users of the softc we keep 602 * Detach a keyboard. To keep track of users of the softc we keep
603 * a reference count that's incremented while inside, e.g., read. 603 * a reference count that's incremented while inside, e.g., read.
604 * If the keyboard is active and the reference count is > 0 (0 is the 604 * If the keyboard is active and the reference count is > 0 (0 is the
605 * normal state) we post an event and then wait for the process 605 * normal state) we post an event and then wait for the process
606 * that had the reference to wake us up again. Then we blow away the 606 * that had the reference to wake us up again. Then we blow away the
607 * vnode and return (which will deallocate the softc). 607 * vnode and return (which will deallocate the softc).
608 */ 608 */
609int 609int
610wskbd_detach(device_t self, int flags) 610wskbd_detach(device_t self, int flags)
611{ 611{
612 struct wskbd_softc *sc = device_private(self); 612 struct wskbd_softc *sc = device_private(self);
613 struct wseventvar *evar; 613 struct wseventvar *evar;
614 int maj, mn; 614 int maj, mn;
615 int s; 615 int s;
616 616
617#if NWSMUX > 0 617#if NWSMUX > 0
618 /* Tell parent mux we're leaving. */ 618 /* Tell parent mux we're leaving. */
619 if (sc->sc_base.me_parent != NULL) 619 if (sc->sc_base.me_parent != NULL)
620 wsmux_detach_sc(&sc->sc_base); 620 wsmux_detach_sc(&sc->sc_base);
621#endif 621#endif
622 622
623 callout_halt(&sc->sc_repeat_ch, NULL); 623 callout_halt(&sc->sc_repeat_ch, NULL);
624 callout_destroy(&sc->sc_repeat_ch); 624 callout_destroy(&sc->sc_repeat_ch);
625 625
626 if (sc->sc_isconsole) { 626 if (sc->sc_isconsole) {
627 KASSERT(wskbd_console_device == sc); 627 KASSERT(wskbd_console_device == sc);
628 wskbd_console_device = NULL; 628 wskbd_console_device = NULL;
629 } 629 }
630 630
631 pmf_device_deregister(self); 631 pmf_device_deregister(self);
632 632
633 evar = sc->sc_base.me_evp; 633 evar = sc->sc_base.me_evp;
634 if (evar != NULL && evar->io != NULL) { 634 if (evar != NULL && evar->io != NULL) {
635 s = spltty(); 635 s = spltty();
636 if (--sc->sc_refcnt >= 0) { 636 if (--sc->sc_refcnt >= 0) {
637 struct wscons_event event; 637 struct wscons_event event;
638 638
639 /* Wake everyone by generating a dummy event. */ 639 /* Wake everyone by generating a dummy event. */
640 event.type = 0; 640 event.type = 0;
641 event.value = 0; 641 event.value = 0;
642 if (wsevent_inject(evar, &event, 1) != 0) 642 if (wsevent_inject(evar, &event, 1) != 0)
643 wsevent_wakeup(evar); 643 wsevent_wakeup(evar);
644 644
645 /* Wait for processes to go away. */ 645 /* Wait for processes to go away. */
646 if (tsleep(sc, PZERO, "wskdet", hz * 60)) 646 if (tsleep(sc, PZERO, "wskdet", hz * 60))
647 aprint_error("wskbd_detach: %s didn't detach\n", 647 aprint_error("wskbd_detach: %s didn't detach\n",
648 device_xname(self)); 648 device_xname(self));
649 } 649 }
650 splx(s); 650 splx(s);
651 } 651 }
652 652
653 /* locate the major number */ 653 /* locate the major number */
654 maj = cdevsw_lookup_major(&wskbd_cdevsw); 654 maj = cdevsw_lookup_major(&wskbd_cdevsw);
655 655
656 /* Nuke the vnodes for any open instances. */ 656 /* Nuke the vnodes for any open instances. */
657 mn = device_unit(self); 657 mn = device_unit(self);
658 vdevgone(maj, mn, mn, VCHR); 658 vdevgone(maj, mn, mn, VCHR);
659 659
660 return (0); 660 return (0);
661} 661}
662 662
663void 663void
664wskbd_input(device_t dev, u_int type, int value) 664wskbd_input(device_t dev, u_int type, int value)
665{ 665{
666 struct wskbd_softc *sc = device_private(dev); 666 struct wskbd_softc *sc = device_private(dev);
667#if NWSDISPLAY > 0 667#if NWSDISPLAY > 0
668 int num, i; 668 int num, i;
669#endif 669#endif
670 670
671 if (sc->sc_repeating) { 671 if (sc->sc_repeating) {
672 sc->sc_repeating = 0; 672 sc->sc_repeating = 0;
673 callout_stop(&sc->sc_repeat_ch); 673 callout_stop(&sc->sc_repeat_ch);
674 } 674 }
675 675
676 device_active(dev, DVA_HARDWARE); 676 device_active(dev, DVA_HARDWARE);
677 677
678#if NWSDISPLAY > 0 678#if NWSDISPLAY > 0
679 /* 679 /*
680 * If /dev/wskbdN is not connected in event mode translate and 680 * If /dev/wskbdN is not connected in event mode translate and
681 * send upstream. 681 * send upstream.
682 */ 682 */
683 if (sc->sc_translating) { 683 if (sc->sc_translating) {
684 num = wskbd_translate(sc->id, type, value); 684 num = wskbd_translate(sc->id, type, value);
685 if (num > 0) { 685 if (num > 0) {
686 if (sc->sc_base.me_dispdv != NULL) { 686 if (sc->sc_base.me_dispdv != NULL) {
687#ifdef WSDISPLAY_SCROLLSUPPORT 687#ifdef WSDISPLAY_SCROLLSUPPORT
688 if (sc->id->t_symbols [0] != KS_Print_Screen) { 688 if (sc->id->t_symbols [0] != KS_Print_Screen) {
689 wsdisplay_scroll(sc->sc_base. 689 wsdisplay_scroll(sc->sc_base.
690 me_dispdv, WSDISPLAY_SCROLL_RESET); 690 me_dispdv, WSDISPLAY_SCROLL_RESET);
691 } 691 }
692#endif 692#endif
693 for (i = 0; i < num; i++) 693 for (i = 0; i < num; i++)
694 wsdisplay_kbdinput( 694 wsdisplay_kbdinput(
695 sc->sc_base.me_dispdv, 695 sc->sc_base.me_dispdv,
696 sc->id->t_symbols[i]); 696 sc->id->t_symbols[i]);
697 } 697 }
698 698
699 if (sc->sc_keyrepeat_data.del1 != 0) { 699 if (sc->sc_keyrepeat_data.del1 != 0) {
700 sc->sc_repeating = num; 700 sc->sc_repeating = num;
701 callout_schedule(&sc->sc_repeat_ch, 701 callout_schedule(&sc->sc_repeat_ch,
702 mstohz(sc->sc_keyrepeat_data.del1)); 702 mstohz(sc->sc_keyrepeat_data.del1));
703 } 703 }
704 } 704 }
705 return; 705 return;
706 } 706 }
707#endif 707#endif
708 708
709 wskbd_deliver_event(sc, type, value); 709 wskbd_deliver_event(sc, type, value);
710 710
711#if defined(WSKBD_EVENT_AUTOREPEAT) 711#if defined(WSKBD_EVENT_AUTOREPEAT)
712 /* Repeat key presses if set. */ 712 /* Repeat key presses if set. */
713 if (type == WSCONS_EVENT_KEY_DOWN && sc->sc_keyrepeat_data.del1 != 0) { 713 if (type == WSCONS_EVENT_KEY_DOWN && sc->sc_keyrepeat_data.del1 != 0) {
714 sc->sc_repeat_type = type; 714 sc->sc_repeat_type = type;
715 sc->sc_repeat_value = value; 715 sc->sc_repeat_value = value;
716 sc->sc_repeating = 1; 716 sc->sc_repeating = 1;
717 callout_schedule(&sc->sc_repeat_ch, 717 callout_schedule(&sc->sc_repeat_ch,
718 mstohz(sc->sc_keyrepeat_data.del1)); 718 mstohz(sc->sc_keyrepeat_data.del1));
719 } 719 }
720#endif /* defined(WSKBD_EVENT_AUTOREPEAT) */ 720#endif /* defined(WSKBD_EVENT_AUTOREPEAT) */
721} 721}
722 722
723/* 723/*
724 * Keyboard is generating events. Turn this keystroke into an 724 * Keyboard is generating events. Turn this keystroke into an
725 * event and put it in the queue. If the queue is full, the 725 * event and put it in the queue. If the queue is full, the
726 * keystroke is lost (sorry!). 726 * keystroke is lost (sorry!).
727 */ 727 */
728static void 728static void
729wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value) 729wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value)
730{ 730{
731 struct wseventvar *evar; 731 struct wseventvar *evar;
732 struct wscons_event event; 732 struct wscons_event event;
733 733
734 evar = sc->sc_base.me_evp; 734 evar = sc->sc_base.me_evp;
735 735
736 if (evar == NULL) { 736 if (evar == NULL) {
737 DPRINTF(("wskbd_input: not open\n")); 737 DPRINTF(("wskbd_input: not open\n"));
738 return; 738 return;
739 } 739 }
740 740
741#ifdef DIAGNOSTIC 741#ifdef DIAGNOSTIC
742 if (evar->q == NULL) { 742 if (evar->q == NULL) {
743 printf("wskbd_input: evar->q=NULL\n"); 743 printf("wskbd_input: evar->q=NULL\n");
744 return; 744 return;
745 } 745 }
746#endif 746#endif
747 747
748 event.type = type; 748 event.type = type;
749 event.value = 0; 749 event.value = 0;
750 DPRINTF(("%d ->", value)); 750 DPRINTF(("%d ->", value));
751 if (sc->sc_evtrans_len > 0) { 751 if (sc->sc_evtrans_len > 0) {
752 if (sc->sc_evtrans_len > value) { 752 if (sc->sc_evtrans_len > value) {
753 DPRINTF(("%d", sc->sc_evtrans[value])); 753 DPRINTF(("%d", sc->sc_evtrans[value]));
754 event.value = sc->sc_evtrans[value]; 754 event.value = sc->sc_evtrans[value];
755 } 755 }
756 } else { 756 } else {
757 event.value = value; 757 event.value = value;
758 } 758 }
759 DPRINTF(("\n")); 759 DPRINTF(("\n"));
760 if (wsevent_inject(evar, &event, 1) != 0) 760 if (wsevent_inject(evar, &event, 1) != 0)
761 log(LOG_WARNING, "%s: event queue overflow\n", 761 log(LOG_WARNING, "%s: event queue overflow\n",
762 device_xname(sc->sc_base.me_dv)); 762 device_xname(sc->sc_base.me_dv));
763} 763}
764 764
765#ifdef WSDISPLAY_COMPAT_RAWKBD 765#ifdef WSDISPLAY_COMPAT_RAWKBD
766void 766void
767wskbd_rawinput(device_t dev, u_char *tbuf, int len) 767wskbd_rawinput(device_t dev, u_char *tbuf, int len)
768{ 768{
769#if NWSDISPLAY > 0 769#if NWSDISPLAY > 0
770 struct wskbd_softc *sc = device_private(dev); 770 struct wskbd_softc *sc = device_private(dev);
771 int i; 771 int i;
772 772
773 if (sc->sc_base.me_dispdv != NULL) 773 if (sc->sc_base.me_dispdv != NULL)
774 for (i = 0; i < len; i++) 774 for (i = 0; i < len; i++)
775 wsdisplay_kbdinput(sc->sc_base.me_dispdv, tbuf[i]); 775 wsdisplay_kbdinput(sc->sc_base.me_dispdv, tbuf[i]);
776 /* this is KS_GROUP_Plain */ 776 /* this is KS_GROUP_Plain */
777#endif 777#endif
778} 778}
779#endif /* WSDISPLAY_COMPAT_RAWKBD */ 779#endif /* WSDISPLAY_COMPAT_RAWKBD */
780 780
781#if NWSDISPLAY > 0 781#if NWSDISPLAY > 0
782static void 782static void
783wskbd_holdscreen(struct wskbd_softc *sc, int hold) 783wskbd_holdscreen(struct wskbd_softc *sc, int hold)
784{ 784{
785 int new_state; 785 int new_state;
786 786
787 if (sc->sc_base.me_dispdv != NULL) { 787 if (sc->sc_base.me_dispdv != NULL) {
788 wsdisplay_kbdholdscreen(sc->sc_base.me_dispdv, hold); 788 wsdisplay_kbdholdscreen(sc->sc_base.me_dispdv, hold);
789 new_state = sc->sc_ledstate; 789 new_state = sc->sc_ledstate;
790 if (hold) { 790 if (hold) {
791#ifdef WSDISPLAY_SCROLLSUPPORT 791#ifdef WSDISPLAY_SCROLLSUPPORT
792 sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_HOLD; 792 sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_HOLD;
793#endif 793#endif
794 new_state |= WSKBD_LED_SCROLL; 794 new_state |= WSKBD_LED_SCROLL;
795 } else { 795 } else {
796#ifdef WSDISPLAY_SCROLLSUPPORT 796#ifdef WSDISPLAY_SCROLLSUPPORT
797 sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_NORMAL; 797 sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_NORMAL;
798#endif 798#endif
799 new_state &= ~WSKBD_LED_SCROLL; 799 new_state &= ~WSKBD_LED_SCROLL;
800 } 800 }
801 if (new_state != sc->sc_ledstate) { 801 if (new_state != sc->sc_ledstate) {
802 (*sc->sc_accessops->set_leds)(sc->sc_accesscookie, 802 (*sc->sc_accessops->set_leds)(sc->sc_accesscookie,
803 new_state); 803 new_state);
804 sc->sc_ledstate = new_state; 804 sc->sc_ledstate = new_state;
805#ifdef WSDISPLAY_SCROLLSUPPORT 805#ifdef WSDISPLAY_SCROLLSUPPORT
806 if (!hold) 806 if (!hold)
807 wsdisplay_scroll(sc->sc_base.me_dispdv, 807 wsdisplay_scroll(sc->sc_base.me_dispdv,
808 WSDISPLAY_SCROLL_RESET); 808 WSDISPLAY_SCROLL_RESET);
809#endif 809#endif
810 } 810 }
811 } 811 }
812} 812}
813#endif 813#endif
814 814
815static int 815static int
816wskbd_enable(struct wskbd_softc *sc, int on) 816wskbd_enable(struct wskbd_softc *sc, int on)
817{ 817{
818 int error; 818 int error;
819 819
820#if 0 820#if 0
821/* I don't understand the purpose of this code. And it seems to 821/* I don't understand the purpose of this code. And it seems to
822 * break things, so it's out. -- Lennart 822 * break things, so it's out. -- Lennart
823 */ 823 */
824 if (!on && (!sc->sc_translating 824 if (!on && (!sc->sc_translating
825#if NWSDISPLAY > 0 825#if NWSDISPLAY > 0
826 || sc->sc_base.me_dispdv 826 || sc->sc_base.me_dispdv
827#endif 827#endif
828 )) 828 ))
829 return (EBUSY); 829 return (EBUSY);
830#endif 830#endif
831#if NWSDISPLAY > 0 831#if NWSDISPLAY > 0
832 if (sc->sc_base.me_dispdv != NULL) 832 if (sc->sc_base.me_dispdv != NULL)
833 return (0); 833 return (0);
834#endif 834#endif
835 835
836 /* Always cancel auto repeat when fiddling with the kbd. */ 836 /* Always cancel auto repeat when fiddling with the kbd. */
837 if (sc->sc_repeating) { 837 if (sc->sc_repeating) {
838 sc->sc_repeating = 0; 838 sc->sc_repeating = 0;
839 callout_stop(&sc->sc_repeat_ch); 839 callout_stop(&sc->sc_repeat_ch);
840 } 840 }
841 841
842 error = (*sc->sc_accessops->enable)(sc->sc_accesscookie, on); 842 error = (*sc->sc_accessops->enable)(sc->sc_accesscookie, on);
843 DPRINTF(("wskbd_enable: sc=%p on=%d res=%d\n", sc, on, error)); 843 DPRINTF(("wskbd_enable: sc=%p on=%d res=%d\n", sc, on, error));
844 return (error); 844 return (error);
845} 845}
846 846
847#if NWSMUX > 0 847#if NWSMUX > 0
848int 848int
849wskbd_mux_open(struct wsevsrc *me, struct wseventvar *evp) 849wskbd_mux_open(struct wsevsrc *me, struct wseventvar *evp)
850{ 850{
851 struct wskbd_softc *sc = (struct wskbd_softc *)me; 851 struct wskbd_softc *sc = (struct wskbd_softc *)me;
852 852
853 if (sc->sc_dying) 853 if (sc->sc_dying)
854 return (EIO); 854 return (EIO);
855 855
856 if (sc->sc_base.me_evp != NULL) 856 if (sc->sc_base.me_evp != NULL)
857 return (EBUSY); 857 return (EBUSY);
858 858
859 return (wskbd_do_open(sc, evp)); 859 return (wskbd_do_open(sc, evp));
860} 860}
861#endif 861#endif
862 862
863int 863int
864wskbdopen(dev_t dev, int flags, int mode, struct lwp *l) 864wskbdopen(dev_t dev, int flags, int mode, struct lwp *l)
865{ 865{
866 struct wskbd_softc *sc = device_lookup_private(&wskbd_cd, minor(dev)); 866 struct wskbd_softc *sc = device_lookup_private(&wskbd_cd, minor(dev));
867 struct wseventvar *evar; 867 struct wseventvar *evar;
868 int error; 868 int error;
869 869
870 if (sc == NULL) 870 if (sc == NULL)
871 return (ENXIO); 871 return (ENXIO);
872 872
873#if NWSMUX > 0 873#if NWSMUX > 0
874 DPRINTF(("wskbdopen: %s mux=%p l=%p\n", 874 DPRINTF(("wskbdopen: %s mux=%p l=%p\n",
875 device_xname(sc->sc_base.me_dv), sc->sc_base.me_parent, l)); 875 device_xname(sc->sc_base.me_dv), sc->sc_base.me_parent, l));
876#endif 876#endif
877 877
878 if (sc->sc_dying) 878 if (sc->sc_dying)
879 return (EIO); 879 return (EIO);
880 880
881 if ((flags & (FREAD | FWRITE)) == FWRITE) 881 if ((flags & (FREAD | FWRITE)) == FWRITE)
882 /* Not opening for read, only ioctl is available. */ 882 /* Not opening for read, only ioctl is available. */
883 return (0); 883 return (0);
884 884
885#if NWSMUX > 0 885#if NWSMUX > 0
886 if (sc->sc_base.me_parent != NULL) { 886 if (sc->sc_base.me_parent != NULL) {
887 /* Grab the keyboard out of the greedy hands of the mux. */ 887 /* Grab the keyboard out of the greedy hands of the mux. */
888 DPRINTF(("wskbdopen: detach\n")); 888 DPRINTF(("wskbdopen: detach\n"));
889 wsmux_detach_sc(&sc->sc_base); 889 wsmux_detach_sc(&sc->sc_base);
890 } 890 }
891#endif 891#endif
892 892
893 if (sc->sc_base.me_evp != NULL) 893 if (sc->sc_base.me_evp != NULL)
894 return (EBUSY); 894 return (EBUSY);
895 895
896 evar = &sc->sc_base.me_evar; 896 evar = &sc->sc_base.me_evar;
897 wsevent_init(evar, l->l_proc); 897 wsevent_init(evar, l->l_proc);
898 898
899 error = wskbd_do_open(sc, evar); 899 error = wskbd_do_open(sc, evar);
900 if (error) { 900 if (error) {
901 DPRINTF(("wskbdopen: %s open failed\n", 901 DPRINTF(("wskbdopen: %s open failed\n",
902 device_xname(sc->sc_base.me_dv))); 902 device_xname(sc->sc_base.me_dv)));
903 sc->sc_base.me_evp = NULL; 903 sc->sc_base.me_evp = NULL;
904 wsevent_fini(evar); 904 wsevent_fini(evar);
905 } 905 }
906 return (error); 906 return (error);
907} 907}
908 908
909int 909int
910wskbd_do_open(struct wskbd_softc *sc, struct wseventvar *evp) 910wskbd_do_open(struct wskbd_softc *sc, struct wseventvar *evp)
911{ 911{
912 sc->sc_base.me_evp = evp; 912 sc->sc_base.me_evp = evp;
913 sc->sc_translating = 0; 913 sc->sc_translating = 0;
914 914
915 return (wskbd_enable(sc, 1)); 915 return (wskbd_enable(sc, 1));
916} 916}
917 917
918int 918int
919wskbdclose(dev_t dev, int flags, int mode, 919wskbdclose(dev_t dev, int flags, int mode,
920 struct lwp *l) 920 struct lwp *l)
921{ 921{
922 struct wskbd_softc *sc = 922 struct wskbd_softc *sc =
923 device_lookup_private(&wskbd_cd, minor(dev)); 923 device_lookup_private(&wskbd_cd, minor(dev));
924 struct wseventvar *evar = sc->sc_base.me_evp; 924 struct wseventvar *evar = sc->sc_base.me_evp;
925 925
926 if (evar == NULL) 926 if (evar == NULL)
927 /* not open for read */ 927 /* not open for read */
928 return (0); 928 return (0);
929 929
930 sc->sc_base.me_evp = NULL; 930 sc->sc_base.me_evp = NULL;
931 sc->sc_translating = 1; 931 sc->sc_translating = 1;
932 (void)wskbd_enable(sc, 0); 932 (void)wskbd_enable(sc, 0);
933 wsevent_fini(evar); 933 wsevent_fini(evar);
934 934
935 return (0); 935 return (0);
936} 936}
937 937
938#if NWSMUX > 0 938#if NWSMUX > 0
939int 939int
940wskbd_mux_close(struct wsevsrc *me) 940wskbd_mux_close(struct wsevsrc *me)
941{ 941{
942 struct wskbd_softc *sc = (struct wskbd_softc *)me; 942 struct wskbd_softc *sc = (struct wskbd_softc *)me;
943 943
944 sc->sc_base.me_evp = NULL; 944 sc->sc_base.me_evp = NULL;
945 sc->sc_translating = 1; 945 sc->sc_translating = 1;
946 (void)wskbd_enable(sc, 0); 946 (void)wskbd_enable(sc, 0);
947 947
948 return (0); 948 return (0);
949} 949}
950#endif 950#endif
951 951
952int 952int
953wskbdread(dev_t dev, struct uio *uio, int flags) 953wskbdread(dev_t dev, struct uio *uio, int flags)
954{ 954{
955 struct wskbd_softc *sc = 955 struct wskbd_softc *sc =
956 device_lookup_private(&wskbd_cd, minor(dev)); 956 device_lookup_private(&wskbd_cd, minor(dev));
957 int error; 957 int error;
958 958
959 if (sc->sc_dying) 959 if (sc->sc_dying)
960 return (EIO); 960 return (EIO);
961 961
962#ifdef DIAGNOSTIC 962#ifdef DIAGNOSTIC
963 if (sc->sc_base.me_evp == NULL) { 963 if (sc->sc_base.me_evp == NULL) {
964 printf("wskbdread: evp == NULL\n"); 964 printf("wskbdread: evp == NULL\n");
965 return (EINVAL); 965 return (EINVAL);
966 } 966 }
967#endif 967#endif
968 968
969 sc->sc_refcnt++; 969 sc->sc_refcnt++;
970 error = wsevent_read(sc->sc_base.me_evp, uio, flags); 970 error = wsevent_read(sc->sc_base.me_evp, uio, flags);
971 if (--sc->sc_refcnt < 0) { 971 if (--sc->sc_refcnt < 0) {
972 wakeup(sc); 972 wakeup(sc);
973 error = EIO; 973 error = EIO;
974 } 974 }
975 return (error); 975 return (error);
976} 976}
977 977
978int 978int
979wskbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) 979wskbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
980{ 980{
981 return (wskbd_do_ioctl(device_lookup(&wskbd_cd, minor(dev)), 981 return (wskbd_do_ioctl(device_lookup(&wskbd_cd, minor(dev)),
982 cmd, data, flag,l)); 982 cmd, data, flag,l));
983} 983}
984 984
985/* A wrapper around the ioctl() workhorse to make reference counting easy. */ 985/* A wrapper around the ioctl() workhorse to make reference counting easy. */
986int 986int
987wskbd_do_ioctl(device_t dv, u_long cmd, void *data, int flag, 987wskbd_do_ioctl(device_t dv, u_long cmd, void *data, int flag,
988 struct lwp *l) 988 struct lwp *l)
989{ 989{
990 struct wskbd_softc *sc = device_private(dv); 990 struct wskbd_softc *sc = device_private(dv);
991 int error; 991 int error;
992 992
993 sc->sc_refcnt++; 993 sc->sc_refcnt++;
994 error = wskbd_do_ioctl_sc(sc, cmd, data, flag, l); 994 error = wskbd_do_ioctl_sc(sc, cmd, data, flag, l);
995 if (--sc->sc_refcnt < 0) 995 if (--sc->sc_refcnt < 0)
996 wakeup(sc); 996 wakeup(sc);
997 return (error); 997 return (error);
998} 998}
999 999
1000int 1000int
1001wskbd_do_ioctl_sc(struct wskbd_softc *sc, u_long cmd, void *data, int flag, 1001wskbd_do_ioctl_sc(struct wskbd_softc *sc, u_long cmd, void *data, int flag,
1002 struct lwp *l) 1002 struct lwp *l)
1003{ 1003{
1004 1004
1005 /* 1005 /*
1006 * Try the generic ioctls that the wskbd interface supports. 1006 * Try the generic ioctls that the wskbd interface supports.
1007 */ 1007 */
1008 switch (cmd) { 1008 switch (cmd) {
1009 case FIONBIO: /* we will remove this someday (soon???) */ 1009 case FIONBIO: /* we will remove this someday (soon???) */
1010 return (0); 1010 return (0);
1011 1011
1012 case FIOASYNC: 1012 case FIOASYNC:
1013 if (sc->sc_base.me_evp == NULL) 1013 if (sc->sc_base.me_evp == NULL)
1014 return (EINVAL); 1014 return (EINVAL);
1015 sc->sc_base.me_evp->async = *(int *)data != 0; 1015 sc->sc_base.me_evp->async = *(int *)data != 0;
1016 return (0); 1016 return (0);
1017 1017
1018 case FIOSETOWN: 1018 case FIOSETOWN:
1019 if (sc->sc_base.me_evp == NULL) 1019 if (sc->sc_base.me_evp == NULL)
1020 return (EINVAL); 1020 return (EINVAL);
1021 if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid 1021 if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid
1022 && *(int *)data != sc->sc_base.me_evp->io->p_pid) 1022 && *(int *)data != sc->sc_base.me_evp->io->p_pid)
1023 return (EPERM); 1023 return (EPERM);
1024 return (0); 1024 return (0);
1025 1025
1026 case TIOCSPGRP: 1026 case TIOCSPGRP:
1027 if (sc->sc_base.me_evp == NULL) 1027 if (sc->sc_base.me_evp == NULL)
1028 return (EINVAL); 1028 return (EINVAL);
1029 if (*(int *)data != sc->sc_base.me_evp->io->p_pgid) 1029 if (*(int *)data != sc->sc_base.me_evp->io->p_pgid)
1030 return (EPERM); 1030 return (EPERM);
1031 return (0); 1031 return (0);
1032 } 1032 }
1033 1033
1034 /* 1034 /*
1035 * Try the keyboard driver for WSKBDIO ioctls. It returns EPASSTHROUGH 1035 * Try the keyboard driver for WSKBDIO ioctls. It returns EPASSTHROUGH
1036 * if it didn't recognize the request. 1036 * if it didn't recognize the request.
1037 */ 1037 */
1038 return (wskbd_displayioctl(sc->sc_base.me_dv, cmd, data, flag, l)); 1038 return (wskbd_displayioctl(sc->sc_base.me_dv, cmd, data, flag, l));
1039} 1039}
1040 1040
1041/* 1041/*
1042 * WSKBDIO ioctls, handled in both emulation mode and in ``raw'' mode. 1042 * WSKBDIO ioctls, handled in both emulation mode and in ``raw'' mode.
1043 * Some of these have no real effect in raw mode, however. 1043 * Some of these have no real effect in raw mode, however.
1044 */ 1044 */
1045static int 1045static int
1046wskbd_displayioctl(device_t dev, u_long cmd, void *data, int flag, 1046wskbd_displayioctl(device_t dev, u_long cmd, void *data, int flag,
1047 struct lwp *l) 1047 struct lwp *l)
1048{ 1048{
1049#ifdef WSDISPLAY_SCROLLSUPPORT 1049#ifdef WSDISPLAY_SCROLLSUPPORT
1050 struct wskbd_scroll_data *usdp, *ksdp; 1050 struct wskbd_scroll_data *usdp, *ksdp;
1051#endif 1051#endif
1052 struct wskbd_softc *sc = device_private(dev); 1052 struct wskbd_softc *sc = device_private(dev);
1053 struct wskbd_bell_data *ubdp, *kbdp; 1053 struct wskbd_bell_data *ubdp, *kbdp;
1054 struct wskbd_keyrepeat_data *ukdp, *kkdp; 1054 struct wskbd_keyrepeat_data *ukdp, *kkdp;
1055 struct wskbd_map_data *umdp; 1055 struct wskbd_map_data *umdp;
1056 struct wskbd_mapdata md; 1056 struct wskbd_mapdata md;
1057 kbd_t enc; 1057 kbd_t enc;
1058 void *tbuf; 1058 void *tbuf;
1059 int len, error; 1059 int len, error;
1060 1060
1061 switch (cmd) { 1061 switch (cmd) {
1062#define SETBELL(dstp, srcp, dfltp) \ 
1063 do { \ 
1064 (dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ? \ 
1065 (srcp)->pitch : (dfltp)->pitch; \ 
1066 (dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ? \ 
1067 (srcp)->period : (dfltp)->period; \ 
1068 (dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ? \ 
1069 (srcp)->volume : (dfltp)->volume; \ 
1070 (dstp)->which = WSKBD_BELL_DOALL; \ 
1071 } while (0) 
1072 
1073 case WSKBDIO_BELL: 1062 case WSKBDIO_BELL:
1074 if ((flag & FWRITE) == 0) 1063 if ((flag & FWRITE) == 0)
1075 return (EACCES); 1064 return (EACCES);
1076 return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, 1065 return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie,
1077 WSKBDIO_COMPLEXBELL, (void *)&sc->sc_bell_data, flag, l)); 1066 WSKBDIO_COMPLEXBELL, (void *)&sc->sc_bell_data, flag, l));
1078 1067
1079 case WSKBDIO_COMPLEXBELL: 1068 case WSKBDIO_COMPLEXBELL:
1080 if ((flag & FWRITE) == 0) 1069 if ((flag & FWRITE) == 0)
1081 return (EACCES); 1070 return (EACCES);
1082 ubdp = (struct wskbd_bell_data *)data; 1071 ubdp = (struct wskbd_bell_data *)data;
1083 SETBELL(ubdp, ubdp, &sc->sc_bell_data); 1072 SETBELL(ubdp, ubdp, &sc->sc_bell_data);
1084 return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, 1073 return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie,
1085 WSKBDIO_COMPLEXBELL, (void *)ubdp, flag, l)); 1074 WSKBDIO_COMPLEXBELL, (void *)ubdp, flag, l));
1086 1075
1087 case WSKBDIO_SETBELL: 1076 case WSKBDIO_SETBELL:
1088 if ((flag & FWRITE) == 0) 1077 if ((flag & FWRITE) == 0)
1089 return (EACCES); 1078 return (EACCES);
1090 kbdp = &sc->sc_bell_data; 1079 kbdp = &sc->sc_bell_data;
1091setbell: 1080setbell:
1092 ubdp = (struct wskbd_bell_data *)data; 1081 ubdp = (struct wskbd_bell_data *)data;
1093 SETBELL(kbdp, ubdp, kbdp); 1082 SETBELL(kbdp, ubdp, kbdp);
1094 return (0); 1083 return (0);
1095 1084
1096 case WSKBDIO_GETBELL: 1085 case WSKBDIO_GETBELL:
1097 kbdp = &sc->sc_bell_data; 1086 kbdp = &sc->sc_bell_data;
1098getbell: 1087getbell:
1099 ubdp = (struct wskbd_bell_data *)data; 1088 ubdp = (struct wskbd_bell_data *)data;
1100 SETBELL(ubdp, kbdp, kbdp); 1089 SETBELL(ubdp, kbdp, kbdp);
1101 return (0); 1090 return (0);
1102 1091
1103 case WSKBDIO_SETDEFAULTBELL: 1092 case WSKBDIO_SETDEFAULTBELL:
1104 if ((error = kauth_authorize_device(l->l_cred, 1093 if ((error = kauth_authorize_device(l->l_cred,
1105 KAUTH_DEVICE_WSCONS_KEYBOARD_BELL, NULL, NULL, 1094 KAUTH_DEVICE_WSCONS_KEYBOARD_BELL, NULL, NULL,
1106 NULL, NULL)) != 0) 1095 NULL, NULL)) != 0)
1107 return (error); 1096 return (error);
1108 kbdp = &wskbd_default_bell_data; 1097 kbdp = &wskbd_default_bell_data;
1109 goto setbell; 1098 goto setbell;
1110 1099
1111 1100
1112 case WSKBDIO_GETDEFAULTBELL: 1101 case WSKBDIO_GETDEFAULTBELL:
1113 kbdp = &wskbd_default_bell_data; 1102 kbdp = &wskbd_default_bell_data;
1114 goto getbell; 1103 goto getbell;
1115 1104
1116#undef SETBELL 1105#undef SETBELL
1117 1106
1118#define SETKEYREPEAT(dstp, srcp, dfltp) \ 1107#define SETKEYREPEAT(dstp, srcp, dfltp) \
1119 do { \ 1108 do { \
1120 (dstp)->del1 = ((srcp)->which & WSKBD_KEYREPEAT_DODEL1) ? \ 1109 (dstp)->del1 = ((srcp)->which & WSKBD_KEYREPEAT_DODEL1) ? \
1121 (srcp)->del1 : (dfltp)->del1; \ 1110 (srcp)->del1 : (dfltp)->del1; \
1122 (dstp)->delN = ((srcp)->which & WSKBD_KEYREPEAT_DODELN) ? \ 1111 (dstp)->delN = ((srcp)->which & WSKBD_KEYREPEAT_DODELN) ? \
1123 (srcp)->delN : (dfltp)->delN; \ 1112 (srcp)->delN : (dfltp)->delN; \
1124 (dstp)->which = WSKBD_KEYREPEAT_DOALL; \ 1113 (dstp)->which = WSKBD_KEYREPEAT_DOALL; \
1125 } while (0) 1114 } while (0)
1126 1115
1127 case WSKBDIO_SETKEYREPEAT: 1116 case WSKBDIO_SETKEYREPEAT:
1128 if ((flag & FWRITE) == 0) 1117 if ((flag & FWRITE) == 0)
1129 return (EACCES); 1118 return (EACCES);
1130 kkdp = &sc->sc_keyrepeat_data; 1119 kkdp = &sc->sc_keyrepeat_data;
1131setkeyrepeat: 1120setkeyrepeat:
1132 ukdp = (struct wskbd_keyrepeat_data *)data; 1121 ukdp = (struct wskbd_keyrepeat_data *)data;
1133 SETKEYREPEAT(kkdp, ukdp, kkdp); 1122 SETKEYREPEAT(kkdp, ukdp, kkdp);
1134 return (0); 1123 return (0);
1135 1124
1136 case WSKBDIO_GETKEYREPEAT: 1125 case WSKBDIO_GETKEYREPEAT:
1137 kkdp = &sc->sc_keyrepeat_data; 1126 kkdp = &sc->sc_keyrepeat_data;
1138getkeyrepeat: 1127getkeyrepeat:
1139 ukdp = (struct wskbd_keyrepeat_data *)data; 1128 ukdp = (struct wskbd_keyrepeat_data *)data;
1140 SETKEYREPEAT(ukdp, kkdp, kkdp); 1129 SETKEYREPEAT(ukdp, kkdp, kkdp);
1141 return (0); 1130 return (0);
1142 1131
1143 case WSKBDIO_SETDEFAULTKEYREPEAT: 1132 case WSKBDIO_SETDEFAULTKEYREPEAT:
1144 if ((error = kauth_authorize_device(l->l_cred, 1133 if ((error = kauth_authorize_device(l->l_cred,
1145 KAUTH_DEVICE_WSCONS_KEYBOARD_KEYREPEAT, NULL, NULL, 1134 KAUTH_DEVICE_WSCONS_KEYBOARD_KEYREPEAT, NULL, NULL,
1146 NULL, NULL)) != 0) 1135 NULL, NULL)) != 0)
1147 return (error); 1136 return (error);
1148 kkdp = &wskbd_default_keyrepeat_data; 1137 kkdp = &wskbd_default_keyrepeat_data;
1149 goto setkeyrepeat; 1138 goto setkeyrepeat;
1150 1139
1151 1140
1152 case WSKBDIO_GETDEFAULTKEYREPEAT: 1141 case WSKBDIO_GETDEFAULTKEYREPEAT:
1153 kkdp = &wskbd_default_keyrepeat_data; 1142 kkdp = &wskbd_default_keyrepeat_data;
1154 goto getkeyrepeat; 1143 goto getkeyrepeat;
1155 1144
1156#ifdef WSDISPLAY_SCROLLSUPPORT 1145#ifdef WSDISPLAY_SCROLLSUPPORT
1157#define SETSCROLLMOD(dstp, srcp, dfltp) \ 1146#define SETSCROLLMOD(dstp, srcp, dfltp) \
1158 do { \ 1147 do { \
1159 (dstp)->mode = ((srcp)->which & WSKBD_SCROLL_DOMODE) ? \ 1148 (dstp)->mode = ((srcp)->which & WSKBD_SCROLL_DOMODE) ? \
1160 (srcp)->mode : (dfltp)->mode; \ 1149 (srcp)->mode : (dfltp)->mode; \
1161 (dstp)->modifier = ((srcp)->which & WSKBD_SCROLL_DOMODIFIER) ? \ 1150 (dstp)->modifier = ((srcp)->which & WSKBD_SCROLL_DOMODIFIER) ? \
1162 (srcp)->modifier : (dfltp)->modifier; \ 1151 (srcp)->modifier : (dfltp)->modifier; \
1163 (dstp)->which = WSKBD_SCROLL_DOALL; \ 1152 (dstp)->which = WSKBD_SCROLL_DOALL; \
1164 } while (0) 1153 } while (0)
1165 1154
1166 case WSKBDIO_SETSCROLL: 1155 case WSKBDIO_SETSCROLL:
1167 usdp = (struct wskbd_scroll_data *)data; 1156 usdp = (struct wskbd_scroll_data *)data;
1168 ksdp = &sc->sc_scroll_data; 1157 ksdp = &sc->sc_scroll_data;
1169 SETSCROLLMOD(ksdp, usdp, ksdp); 1158 SETSCROLLMOD(ksdp, usdp, ksdp);
1170 return (0); 1159 return (0);
1171 1160
1172 case WSKBDIO_GETSCROLL: 1161 case WSKBDIO_GETSCROLL:
1173 usdp = (struct wskbd_scroll_data *)data; 1162 usdp = (struct wskbd_scroll_data *)data;
1174 ksdp = &sc->sc_scroll_data; 1163 ksdp = &sc->sc_scroll_data;
1175 SETSCROLLMOD(usdp, ksdp, ksdp); 1164 SETSCROLLMOD(usdp, ksdp, ksdp);
1176 return (0); 1165 return (0);
1177#else 1166#else
1178 case WSKBDIO_GETSCROLL: 1167 case WSKBDIO_GETSCROLL:
1179 case WSKBDIO_SETSCROLL: 1168 case WSKBDIO_SETSCROLL:
1180 return ENODEV; 1169 return ENODEV;
1181#endif 1170#endif
1182 1171
1183#undef SETKEYREPEAT 1172#undef SETKEYREPEAT
1184 1173
1185 case WSKBDIO_SETMAP: 1174 case WSKBDIO_SETMAP:
1186 if ((flag & FWRITE) == 0) 1175 if ((flag & FWRITE) == 0)
1187 return (EACCES); 1176 return (EACCES);
1188 umdp = (struct wskbd_map_data *)data; 1177 umdp = (struct wskbd_map_data *)data;
1189 if (umdp->maplen > WSKBDIO_MAXMAPLEN) 1178 if (umdp->maplen > WSKBDIO_MAXMAPLEN)
1190 return (EINVAL); 1179 return (EINVAL);
1191 1180
1192 len = umdp->maplen*sizeof(struct wscons_keymap); 1181 len = umdp->maplen*sizeof(struct wscons_keymap);
1193 tbuf = malloc(len, M_TEMP, M_WAITOK); 1182 tbuf = malloc(len, M_TEMP, M_WAITOK);
1194 error = copyin(umdp->map, tbuf, len); 1183 error = copyin(umdp->map, tbuf, len);
1195 if (error == 0) { 1184 if (error == 0) {
1196 wskbd_init_keymap(umdp->maplen, 1185 wskbd_init_keymap(umdp->maplen,
1197 &sc->sc_map, &sc->sc_maplen); 1186 &sc->sc_map, &sc->sc_maplen);
1198 memcpy(sc->sc_map, tbuf, len); 1187 memcpy(sc->sc_map, tbuf, len);
1199 /* drop the variant bits handled by the map */ 1188 /* drop the variant bits handled by the map */
1200 sc->sc_layout = KB_USER | 1189 sc->sc_layout = KB_USER |
1201 (KB_VARIANT(sc->sc_layout) & KB_HANDLEDBYWSKBD); 1190 (KB_VARIANT(sc->sc_layout) & KB_HANDLEDBYWSKBD);
1202 wskbd_update_layout(sc->id, sc->sc_layout); 1191 wskbd_update_layout(sc->id, sc->sc_layout);
1203 } 1192 }
1204 free(tbuf, M_TEMP); 1193 free(tbuf, M_TEMP);
1205 return(error); 1194 return(error);
1206 1195
1207 case WSKBDIO_GETMAP: 1196 case WSKBDIO_GETMAP:
1208 umdp = (struct wskbd_map_data *)data; 1197 umdp = (struct wskbd_map_data *)data;
1209 if (umdp->maplen > sc->sc_maplen) 1198 if (umdp->maplen > sc->sc_maplen)
1210 umdp->maplen = sc->sc_maplen; 1199 umdp->maplen = sc->sc_maplen;
1211 error = copyout(sc->sc_map, umdp->map, 1200 error = copyout(sc->sc_map, umdp->map,
1212 umdp->maplen*sizeof(struct wscons_keymap)); 1201 umdp->maplen*sizeof(struct wscons_keymap));
1213 return(error); 1202 return(error);
1214 1203
1215 case WSKBDIO_GETENCODING: 1204 case WSKBDIO_GETENCODING:
1216 *((kbd_t *) data) = sc->sc_layout; 1205 *((kbd_t *) data) = sc->sc_layout;
1217 return(0); 1206 return(0);
1218 1207
1219 case WSKBDIO_SETENCODING: 1208 case WSKBDIO_SETENCODING:
1220 if ((flag & FWRITE) == 0) 1209 if ((flag & FWRITE) == 0)
1221 return (EACCES); 1210 return (EACCES);
1222 enc = *((kbd_t *)data); 1211 enc = *((kbd_t *)data);
1223 if (KB_ENCODING(enc) == KB_USER) { 1212 if (KB_ENCODING(enc) == KB_USER) {
1224 /* user map must already be loaded */ 1213 /* user map must already be loaded */
1225 if (KB_ENCODING(sc->sc_layout) != KB_USER) 1214 if (KB_ENCODING(sc->sc_layout) != KB_USER)
1226 return (EINVAL); 1215 return (EINVAL);
1227 /* map variants make no sense */ 1216 /* map variants make no sense */
1228 if (KB_VARIANT(enc) & ~KB_HANDLEDBYWSKBD) 1217 if (KB_VARIANT(enc) & ~KB_HANDLEDBYWSKBD)
1229 return (EINVAL); 1218 return (EINVAL);
1230 } else { 1219 } else {
1231 md = *(sc->id->t_keymap); /* structure assignment */ 1220 md = *(sc->id->t_keymap); /* structure assignment */
1232 md.layout = enc; 1221 md.layout = enc;
1233 error = wskbd_load_keymap(&md, &sc->sc_map, 1222 error = wskbd_load_keymap(&md, &sc->sc_map,
1234 &sc->sc_maplen); 1223 &sc->sc_maplen);
1235 if (error) 1224 if (error)
1236 return (error); 1225 return (error);
1237 } 1226 }
1238 sc->sc_layout = enc; 1227 sc->sc_layout = enc;
1239 wskbd_update_layout(sc->id, enc); 1228 wskbd_update_layout(sc->id, enc);
1240 return (0); 1229 return (0);
1241 1230
1242 case WSKBDIO_SETVERSION: 1231 case WSKBDIO_SETVERSION:
1243 return wsevent_setversion(sc->sc_base.me_evp, *(int *)data); 1232 return wsevent_setversion(sc->sc_base.me_evp, *(int *)data);
1244 } 1233 }
1245 1234
1246 /* 1235 /*
1247 * Try the keyboard driver for WSKBDIO ioctls. It returns -1 1236 * Try the keyboard driver for WSKBDIO ioctls. It returns -1
1248 * if it didn't recognize the request, and in turn we return 1237 * if it didn't recognize the request, and in turn we return
1249 * -1 if we didn't recognize the request. 1238 * -1 if we didn't recognize the request.
1250 */ 1239 */
1251/* printf("kbdaccess\n"); */ 1240/* printf("kbdaccess\n"); */
1252 error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd, data, 1241 error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd, data,
1253 flag, l); 1242 flag, l);
1254#ifdef WSDISPLAY_COMPAT_RAWKBD 1243#ifdef WSDISPLAY_COMPAT_RAWKBD
1255 if (!error && cmd == WSKBDIO_SETMODE && *(int *)data == WSKBD_RAW) { 1244 if (!error && cmd == WSKBDIO_SETMODE && *(int *)data == WSKBD_RAW) {
1256 int s = spltty(); 1245 int s = spltty();
1257 sc->id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R 1246 sc->id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R
1258 | MOD_CONTROL_L | MOD_CONTROL_R 1247 | MOD_CONTROL_L | MOD_CONTROL_R
1259 | MOD_META_L | MOD_META_R 1248 | MOD_META_L | MOD_META_R
1260 | MOD_COMMAND 1249 | MOD_COMMAND
1261 | MOD_COMMAND1 | MOD_COMMAND2); 1250 | MOD_COMMAND1 | MOD_COMMAND2);
1262 if (sc->sc_repeating) { 1251 if (sc->sc_repeating) {
1263 sc->sc_repeating = 0; 1252 sc->sc_repeating = 0;
1264 callout_stop(&sc->sc_repeat_ch); 1253 callout_stop(&sc->sc_repeat_ch);
1265 } 1254 }
1266 splx(s); 1255 splx(s);
1267 } 1256 }
1268#endif 1257#endif
1269 return (error); 1258 return (error);
1270} 1259}
1271 1260
1272int 1261int
1273wskbdpoll(dev_t dev, int events, struct lwp *l) 1262wskbdpoll(dev_t dev, int events, struct lwp *l)
1274{ 1263{
1275 struct wskbd_softc *sc = 1264 struct wskbd_softc *sc =
1276 device_lookup_private(&wskbd_cd, minor(dev)); 1265 device_lookup_private(&wskbd_cd, minor(dev));
1277 1266
1278 if (sc->sc_base.me_evp == NULL) 1267 if (sc->sc_base.me_evp == NULL)
1279 return (POLLERR); 1268 return (POLLERR);
1280 return (wsevent_poll(sc->sc_base.me_evp, events, l)); 1269 return (wsevent_poll(sc->sc_base.me_evp, events, l));
1281} 1270}
1282 1271
1283int 1272int
1284wskbdkqfilter(dev_t dev, struct knote *kn) 1273wskbdkqfilter(dev_t dev, struct knote *kn)
1285{ 1274{
1286 struct wskbd_softc *sc = 1275 struct wskbd_softc *sc =
1287 device_lookup_private(&wskbd_cd, minor(dev)); 1276 device_lookup_private(&wskbd_cd, minor(dev));
1288 1277
1289 if (sc->sc_base.me_evp == NULL) 1278 if (sc->sc_base.me_evp == NULL)
1290 return (1); 1279 return (1);
1291 return (wsevent_kqfilter(sc->sc_base.me_evp, kn)); 1280 return (wsevent_kqfilter(sc->sc_base.me_evp, kn));
1292} 1281}
1293 1282
1294#if NWSDISPLAY > 0 1283#if NWSDISPLAY > 0
1295 1284
1296int 1285int
1297wskbd_pickfree(void) 1286wskbd_pickfree(void)
1298{ 1287{
1299 int i; 1288 int i;
1300 struct wskbd_softc *sc; 1289 struct wskbd_softc *sc;
1301 1290
1302 for (i = 0; i < wskbd_cd.cd_ndevs; i++) { 1291 for (i = 0; i < wskbd_cd.cd_ndevs; i++) {
1303 sc = device_lookup_private(&wskbd_cd, i); 1292 sc = device_lookup_private(&wskbd_cd, i);
1304 if (sc == NULL) 1293 if (sc == NULL)
1305 continue; 1294 continue;
1306 if (sc->sc_base.me_dispdv == NULL) 1295 if (sc->sc_base.me_dispdv == NULL)
1307 return (i); 1296 return (i);
1308 } 1297 }
1309 return (-1); 1298 return (-1);
1310} 1299}
1311 1300
1312struct wsevsrc * 1301struct wsevsrc *
1313wskbd_set_console_display(device_t displaydv, struct wsevsrc *me) 1302wskbd_set_console_display(device_t displaydv, struct wsevsrc *me)
1314{ 1303{
1315 struct wskbd_softc *sc = wskbd_console_device; 1304 struct wskbd_softc *sc = wskbd_console_device;
1316 1305
1317 if (sc == NULL) 1306 if (sc == NULL)
1318 return (NULL); 1307 return (NULL);
1319 sc->sc_base.me_dispdv = displaydv; 1308 sc->sc_base.me_dispdv = displaydv;
1320#if NWSMUX > 0 1309#if NWSMUX > 0
1321 (void)wsmux_attach_sc((struct wsmux_softc *)me, &sc->sc_base); 1310 (void)wsmux_attach_sc((struct wsmux_softc *)me, &sc->sc_base);
1322#endif 1311#endif
1323 return (&sc->sc_base); 1312 return (&sc->sc_base);
1324} 1313}
1325 1314
1326int 1315int
1327wskbd_set_display(device_t dv, struct wsevsrc *me) 1316wskbd_set_display(device_t dv, struct wsevsrc *me)
1328{ 1317{
1329 struct wskbd_softc *sc = device_private(dv); 1318 struct wskbd_softc *sc = device_private(dv);
1330 device_t displaydv = me != NULL ? me->me_dispdv : NULL; 1319 device_t displaydv = me != NULL ? me->me_dispdv : NULL;
1331 device_t odisplaydv; 1320 device_t odisplaydv;
1332 int error; 1321 int error;
1333 1322
1334 DPRINTF(("wskbd_set_display: %s me=%p odisp=%p disp=%p cons=%d\n", 1323 DPRINTF(("wskbd_set_display: %s me=%p odisp=%p disp=%p cons=%d\n",
1335 device_xname(dv), me, sc->sc_base.me_dispdv, displaydv, 1324 device_xname(dv), me, sc->sc_base.me_dispdv, displaydv,
1336 sc->sc_isconsole)); 1325 sc->sc_isconsole));
1337 1326
1338 if (sc->sc_isconsole) 1327 if (sc->sc_isconsole)
1339 return (EBUSY); 1328 return (EBUSY);
1340 1329
1341 if (displaydv != NULL) { 1330 if (displaydv != NULL) {
1342 if (sc->sc_base.me_dispdv != NULL) 1331 if (sc->sc_base.me_dispdv != NULL)
1343 return (EBUSY); 1332 return (EBUSY);
1344 } else { 1333 } else {
1345 if (sc->sc_base.me_dispdv == NULL) 1334 if (sc->sc_base.me_dispdv == NULL)
1346 return (ENXIO); 1335 return (ENXIO);
1347 } 1336 }
1348 1337
1349 odisplaydv = sc->sc_base.me_dispdv; 1338 odisplaydv = sc->sc_base.me_dispdv;
1350 sc->sc_base.me_dispdv = NULL; 1339 sc->sc_base.me_dispdv = NULL;
1351 error = wskbd_enable(sc, displaydv != NULL); 1340 error = wskbd_enable(sc, displaydv != NULL);
1352 sc->sc_base.me_dispdv = displaydv; 1341 sc->sc_base.me_dispdv = displaydv;
1353 if (error) { 1342 if (error) {
1354 sc->sc_base.me_dispdv = odisplaydv; 1343 sc->sc_base.me_dispdv = odisplaydv;
1355 return (error); 1344 return (error);
1356 } 1345 }
1357 1346
1358 if (displaydv) 1347 if (displaydv)
1359 aprint_verbose_dev(sc->sc_base.me_dv, "connecting to %s\n", 1348 aprint_verbose_dev(sc->sc_base.me_dv, "connecting to %s\n",
1360 device_xname(displaydv)); 1349 device_xname(displaydv));
1361 else 1350 else
1362 aprint_verbose_dev(sc->sc_base.me_dv, "disconnecting from %s\n", 1351 aprint_verbose_dev(sc->sc_base.me_dv, "disconnecting from %s\n",
1363 device_xname(odisplaydv)); 1352 device_xname(odisplaydv));
1364 1353
1365 return (0); 1354 return (0);
1366} 1355}
1367 1356
1368#endif /* NWSDISPLAY > 0 */ 1357#endif /* NWSDISPLAY > 0 */
1369 1358
1370#if NWSMUX > 0 1359#if NWSMUX > 0
1371int 1360int
1372wskbd_add_mux(int unit, struct wsmux_softc *muxsc) 1361wskbd_add_mux(int unit, struct wsmux_softc *muxsc)
1373{ 1362{
1374 struct wskbd_softc *sc = device_lookup_private(&wskbd_cd, unit); 1363 struct wskbd_softc *sc = device_lookup_private(&wskbd_cd, unit);
1375 1364
1376 if (sc == NULL) 1365 if (sc == NULL)
1377 return (ENXIO); 1366 return (ENXIO);
1378 1367
1379 if (sc->sc_base.me_parent != NULL || sc->sc_base.me_evp != NULL) 1368 if (sc->sc_base.me_parent != NULL || sc->sc_base.me_evp != NULL)
1380 return (EBUSY); 1369 return (EBUSY);
1381 1370
1382 return (wsmux_attach_sc(muxsc, &sc->sc_base)); 1371 return (wsmux_attach_sc(muxsc, &sc->sc_base));
1383} 1372}
1384#endif 1373#endif
1385 1374
1386/* 1375/*
1387 * Console interface. 1376 * Console interface.
1388 */ 1377 */
1389int 1378int
1390wskbd_cngetc(dev_t dev) 1379wskbd_cngetc(dev_t dev)
1391{ 1380{
1392 static int num = 0; 1381 static int num = 0;
1393 static int pos; 1382 static int pos;
1394 u_int type; 1383 u_int type;
1395 int data; 1384 int data;
1396 keysym_t ks; 1385 keysym_t ks;
1397 1386
1398 if (!wskbd_console_initted) 1387 if (!wskbd_console_initted)
1399 return 0; 1388 return 0;
1400 1389
1401 if (wskbd_console_device != NULL && 1390 if (wskbd_console_device != NULL &&
1402 !wskbd_console_device->sc_translating) 1391 !wskbd_console_device->sc_translating)
1403 return 0; 1392 return 0;
1404 1393
1405 for(;;) { 1394 for(;;) {
1406 if (num-- > 0) { 1395 if (num-- > 0) {
1407 ks = wskbd_console_data.t_symbols[pos++]; 1396 ks = wskbd_console_data.t_symbols[pos++];
1408 if (KS_GROUP(ks) == KS_GROUP_Plain) 1397 if (KS_GROUP(ks) == KS_GROUP_Plain)
1409 return (KS_VALUE(ks)); 1398 return (KS_VALUE(ks));
1410 } else { 1399 } else {
1411 (*wskbd_console_data.t_consops->getc) 1400 (*wskbd_console_data.t_consops->getc)
1412 (wskbd_console_data.t_consaccesscookie, 1401 (wskbd_console_data.t_consaccesscookie,
1413 &type, &data); 1402 &type, &data);
1414 if (type == WSCONS_EVENT_ASCII) { 1403 if (type == WSCONS_EVENT_ASCII) {
1415 /* 1404 /*
1416 * We assume that when the driver falls back 1405 * We assume that when the driver falls back
1417 * to deliver pure ASCII it is in a state that 1406 * to deliver pure ASCII it is in a state that
1418 * it can not track press/release events 1407 * it can not track press/release events
1419 * reliable - so we clear all previously 1408 * reliable - so we clear all previously
1420 * accumulated modifier state. 1409 * accumulated modifier state.
1421 */ 1410 */
1422 wskbd_console_data.t_modifiers = 0; 1411 wskbd_console_data.t_modifiers = 0;
1423 return(data); 1412 return(data);
1424 } 1413 }
1425 num = wskbd_translate(&wskbd_console_data, type, data); 1414 num = wskbd_translate(&wskbd_console_data, type, data);
1426 pos = 0; 1415 pos = 0;
1427 } 1416 }
1428 } 1417 }
1429} 1418}
1430 1419
1431void 1420void
1432wskbd_cnpollc(dev_t dev, int poll) 1421wskbd_cnpollc(dev_t dev, int poll)
1433{ 1422{
1434 1423
1435 if (!wskbd_console_initted) 1424 if (!wskbd_console_initted)
1436 return; 1425 return;
1437 1426
1438 if (wskbd_console_device != NULL && 1427 if (wskbd_console_device != NULL &&
1439 !wskbd_console_device->sc_translating) 1428 !wskbd_console_device->sc_translating)
1440 return; 1429 return;
1441 1430
1442 (*wskbd_console_data.t_consops->pollc) 1431 (*wskbd_console_data.t_consops->pollc)
1443 (wskbd_console_data.t_consaccesscookie, poll); 1432 (wskbd_console_data.t_consaccesscookie, poll);
1444} 1433}
1445 1434
1446void 1435void
1447wskbd_cnbell(dev_t dev, u_int pitch, u_int period, u_int volume) 1436wskbd_cnbell(dev_t dev, u_int pitch, u_int period, u_int volume)
1448{ 1437{
1449 1438
1450 if (!wskbd_console_initted) 1439 if (!wskbd_console_initted)
1451 return; 1440 return;
1452 1441
1453 if (wskbd_console_data.t_consops->bell != NULL) 1442 if (wskbd_console_data.t_consops->bell != NULL)
1454 (*wskbd_console_data.t_consops->bell) 1443 (*wskbd_console_data.t_consops->bell)
1455 (wskbd_console_data.t_consaccesscookie, pitch, period, 1444 (wskbd_console_data.t_consaccesscookie, pitch, period,
1456 volume); 1445 volume);
1457} 1446}
1458 1447
1459static inline void 1448static inline void
1460update_leds(struct wskbd_internal *id) 1449update_leds(struct wskbd_internal *id)
1461{ 1450{
1462 int new_state; 1451 int new_state;
1463 1452
1464 new_state = 0; 1453 new_state = 0;
1465 if (id->t_modifiers & (MOD_SHIFTLOCK | MOD_CAPSLOCK)) 1454 if (id->t_modifiers & (MOD_SHIFTLOCK | MOD_CAPSLOCK))
1466 new_state |= WSKBD_LED_CAPS; 1455 new_state |= WSKBD_LED_CAPS;
1467 if (id->t_modifiers & MOD_NUMLOCK) 1456 if (id->t_modifiers & MOD_NUMLOCK)
1468 new_state |= WSKBD_LED_NUM; 1457 new_state |= WSKBD_LED_NUM;
1469 if (id->t_modifiers & MOD_COMPOSE) 1458 if (id->t_modifiers & MOD_COMPOSE)
1470 new_state |= WSKBD_LED_COMPOSE; 1459 new_state |= WSKBD_LED_COMPOSE;
1471 if (id->t_modifiers & MOD_HOLDSCREEN) 1460 if (id->t_modifiers & MOD_HOLDSCREEN)
1472 new_state |= WSKBD_LED_SCROLL; 1461 new_state |= WSKBD_LED_SCROLL;
1473 1462
1474 if (id->t_sc && new_state != id->t_sc->sc_ledstate) { 1463 if (id->t_sc && new_state != id->t_sc->sc_ledstate) {
1475 (*id->t_sc->sc_accessops->set_leds) 1464 (*id->t_sc->sc_accessops->set_leds)
1476 (id->t_sc->sc_accesscookie, new_state); 1465 (id->t_sc->sc_accesscookie, new_state);
1477 id->t_sc->sc_ledstate = new_state; 1466 id->t_sc->sc_ledstate = new_state;
1478 } 1467 }
1479} 1468}
1480 1469
1481static inline void 1470static inline void
1482update_modifier(struct wskbd_internal *id, u_int type, int toggle, int mask) 1471update_modifier(struct wskbd_internal *id, u_int type, int toggle, int mask)
1483{ 1472{
1484 if (toggle) { 1473 if (toggle) {
1485 if (type == WSCONS_EVENT_KEY_DOWN) 1474 if (type == WSCONS_EVENT_KEY_DOWN)
1486 id->t_modifiers ^= mask; 1475 id->t_modifiers ^= mask;
1487 } else { 1476 } else {
1488 if (type == WSCONS_EVENT_KEY_DOWN) 1477 if (type == WSCONS_EVENT_KEY_DOWN)
1489 id->t_modifiers |= mask; 1478 id->t_modifiers |= mask;
1490 else 1479 else
1491 id->t_modifiers &= ~mask; 1480 id->t_modifiers &= ~mask;
1492 } 1481 }
1493} 1482}
1494 1483
1495#if NWSDISPLAY > 0 1484#if NWSDISPLAY > 0
1496static void 1485static void
1497change_displayparam(struct wskbd_softc *sc, int param, int updown, 1486change_displayparam(struct wskbd_softc *sc, int param, int updown,
1498 int wraparound) 1487 int wraparound)
1499{ 1488{
1500 int res; 1489 int res;
1501 struct wsdisplay_param dp; 1490 struct wsdisplay_param dp;
1502 1491
1503 dp.param = param; 1492 dp.param = param;
1504 res = wsdisplay_param(sc->sc_base.me_dispdv, WSDISPLAYIO_GETPARAM, &dp); 1493 res = wsdisplay_param(sc->sc_base.me_dispdv, WSDISPLAYIO_GETPARAM, &dp);
1505 1494
1506 if (res == EINVAL) 1495 if (res == EINVAL)
1507 return; /* no such parameter */ 1496 return; /* no such parameter */
1508 1497
1509 dp.curval += updown; 1498 dp.curval += updown;
1510 if (dp.max < dp.curval) 1499 if (dp.max < dp.curval)
1511 dp.curval = wraparound ? dp.min : dp.max; 1500 dp.curval = wraparound ? dp.min : dp.max;
1512 else 1501 else
1513 if (dp.curval < dp.min) 1502 if (dp.curval < dp.min)
1514 dp.curval = wraparound ? dp.max : dp.min; 1503 dp.curval = wraparound ? dp.max : dp.min;
1515 wsdisplay_param(sc->sc_base.me_dispdv, WSDISPLAYIO_SETPARAM, &dp); 1504 wsdisplay_param(sc->sc_base.me_dispdv, WSDISPLAYIO_SETPARAM, &dp);
1516} 1505}
1517#endif 1506#endif
1518 1507
1519static int 1508static int
1520internal_command(struct wskbd_softc *sc, u_int *type, keysym_t ksym, 1509internal_command(struct wskbd_softc *sc, u_int *type, keysym_t ksym,
1521 keysym_t ksym2) 1510 keysym_t ksym2)
1522{ 1511{
1523#if NWSDISPLAY > 0 && defined(WSDISPLAY_SCROLLSUPPORT) 1512#if NWSDISPLAY > 0 && defined(WSDISPLAY_SCROLLSUPPORT)
1524 u_int state = 0; 1513 u_int state = 0;
1525#endif 1514#endif
1526 switch (ksym) { 1515 switch (ksym) {
1527 case KS_Cmd_VolumeToggle: 1516 case KS_Cmd_VolumeToggle:
1528 if (*type == WSCONS_EVENT_KEY_DOWN) 1517 if (*type == WSCONS_EVENT_KEY_DOWN)
1529 pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE); 1518 pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
1530 break; 1519 break;
1531 case KS_Cmd_VolumeUp: 1520 case KS_Cmd_VolumeUp:
1532 if (*type == WSCONS_EVENT_KEY_DOWN) 1521 if (*type == WSCONS_EVENT_KEY_DOWN)
1533 pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP); 1522 pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
1534 break; 1523 break;
1535 case KS_Cmd_VolumeDown: 1524 case KS_Cmd_VolumeDown:
1536 if (*type == WSCONS_EVENT_KEY_DOWN) 1525 if (*type == WSCONS_EVENT_KEY_DOWN)
1537 pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN); 1526 pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
1538 break; 1527 break;
1539#if NWSDISPLAY > 0 && defined(WSDISPLAY_SCROLLSUPPORT) 1528#if NWSDISPLAY > 0 && defined(WSDISPLAY_SCROLLSUPPORT)
1540 case KS_Cmd_ScrollFastUp: 1529 case KS_Cmd_ScrollFastUp:
1541 case KS_Cmd_ScrollFastDown: 1530 case KS_Cmd_ScrollFastDown:
1542 if (*type == WSCONS_EVENT_KEY_DOWN) { 1531 if (*type == WSCONS_EVENT_KEY_DOWN) {
1543 GETMODSTATE(sc->id->t_modifiers, state); 1532 GETMODSTATE(sc->id->t_modifiers, state);
1544 if ((sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_HOLD 1533 if ((sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_HOLD
1545 && MOD_ONESET(sc->id, MOD_HOLDSCREEN)) 1534 && MOD_ONESET(sc->id, MOD_HOLDSCREEN))
1546 || (sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_NORMAL 1535 || (sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_NORMAL
1547 && sc->sc_scroll_data.modifier == state)) { 1536 && sc->sc_scroll_data.modifier == state)) {
1548 update_modifier(sc->id, *type, 0, MOD_COMMAND); 1537 update_modifier(sc->id, *type, 0, MOD_COMMAND);
1549 wsdisplay_scroll(sc->sc_base.me_dispdv, 1538 wsdisplay_scroll(sc->sc_base.me_dispdv,
1550 (ksym == KS_Cmd_ScrollFastUp) ? 1539 (ksym == KS_Cmd_ScrollFastUp) ?
1551 WSDISPLAY_SCROLL_BACKWARD : 1540 WSDISPLAY_SCROLL_BACKWARD :
1552 WSDISPLAY_SCROLL_FORWARD); 1541 WSDISPLAY_SCROLL_FORWARD);
1553 return (1); 1542 return (1);
1554 } else { 1543 } else {
1555 return (0); 1544 return (0);
1556 } 1545 }
1557 } 1546 }
1558 1547
1559 case KS_Cmd_ScrollSlowUp: 1548 case KS_Cmd_ScrollSlowUp:
1560 case KS_Cmd_ScrollSlowDown: 1549 case KS_Cmd_ScrollSlowDown:
1561 if (*type == WSCONS_EVENT_KEY_DOWN) { 1550 if (*type == WSCONS_EVENT_KEY_DOWN) {
1562 GETMODSTATE(sc->id->t_modifiers, state); 1551 GETMODSTATE(sc->id->t_modifiers, state);
1563 if ((sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_HOLD 1552 if ((sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_HOLD
1564 && MOD_ONESET(sc->id, MOD_HOLDSCREEN)) 1553 && MOD_ONESET(sc->id, MOD_HOLDSCREEN))
1565 || (sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_NORMAL 1554 || (sc->sc_scroll_data.mode == WSKBD_SCROLL_MODE_NORMAL
1566 && sc->sc_scroll_data.modifier == state)) { 1555 && sc->sc_scroll_data.modifier == state)) {
1567 update_modifier(sc->id, *type, 0, MOD_COMMAND); 1556 update_modifier(sc->id, *type, 0, MOD_COMMAND);
1568 wsdisplay_scroll(sc->sc_base.me_dispdv, 1557 wsdisplay_scroll(sc->sc_base.me_dispdv,
1569 (ksym == KS_Cmd_ScrollSlowUp) ? 1558 (ksym == KS_Cmd_ScrollSlowUp) ?
1570 WSDISPLAY_SCROLL_BACKWARD | WSDISPLAY_SCROLL_LOW: 1559 WSDISPLAY_SCROLL_BACKWARD | WSDISPLAY_SCROLL_LOW:
1571 WSDISPLAY_SCROLL_FORWARD | WSDISPLAY_SCROLL_LOW); 1560 WSDISPLAY_SCROLL_FORWARD | WSDISPLAY_SCROLL_LOW);
1572 return (1); 1561 return (1);
1573 } else { 1562 } else {
1574 return (0); 1563 return (0);
1575 } 1564 }
1576 } 1565 }
1577#endif 1566#endif
1578 1567
1579 case KS_Cmd: 1568 case KS_Cmd:
1580 update_modifier(sc->id, *type, 0, MOD_COMMAND); 1569 update_modifier(sc->id, *type, 0, MOD_COMMAND);
1581 ksym = ksym2; 1570 ksym = ksym2;
1582 break; 1571 break;
1583 1572
1584 case KS_Cmd1: 1573 case KS_Cmd1:
1585 update_modifier(sc->id, *type, 0, MOD_COMMAND1); 1574 update_modifier(sc->id, *type, 0, MOD_COMMAND1);
1586 break; 1575 break;
1587 1576
1588 case KS_Cmd2: 1577 case KS_Cmd2:
1589 update_modifier(sc->id, *type, 0, MOD_COMMAND2); 1578 update_modifier(sc->id, *type, 0, MOD_COMMAND2);
1590 break; 1579 break;
1591 } 1580 }
1592 1581
1593 if (*type != WSCONS_EVENT_KEY_DOWN || 1582 if (*type != WSCONS_EVENT_KEY_DOWN ||
1594 (! MOD_ONESET(sc->id, MOD_COMMAND) && 1583 (! MOD_ONESET(sc->id, MOD_COMMAND) &&
1595 ! MOD_ALLSET(sc->id, MOD_COMMAND1 | MOD_COMMAND2))) 1584 ! MOD_ALLSET(sc->id, MOD_COMMAND1 | MOD_COMMAND2)))
1596 return (0); 1585 return (0);
1597 1586
1598#if defined(DDB) || defined(KGDB) 1587#if defined(DDB) || defined(KGDB)
1599 if (ksym == KS_Cmd_Debugger) { 1588 if (ksym == KS_Cmd_Debugger) {
1600 if (sc->sc_isconsole) { 1589 if (sc->sc_isconsole) {
1601#ifdef DDB 1590#ifdef DDB
1602 console_debugger(); 1591 console_debugger();
1603#endif 1592#endif
1604#ifdef KGDB 1593#ifdef KGDB
1605 kgdb_connect(1); 1594 kgdb_connect(1);
1606#endif 1595#endif
1607 } 1596 }
1608 /* discard this key (ddb discarded command modifiers) */ 1597 /* discard this key (ddb discarded command modifiers) */
1609 *type = WSCONS_EVENT_KEY_UP; 1598 *type = WSCONS_EVENT_KEY_UP;
1610 return (1); 1599 return (1);
1611 } 1600 }
1612#endif 1601#endif
1613 1602
1614#if NWSDISPLAY > 0 1603#if NWSDISPLAY > 0
1615 if (sc->sc_base.me_dispdv == NULL) 1604 if (sc->sc_base.me_dispdv == NULL)
1616 return (0); 1605 return (0);
1617 1606
1618 switch (ksym) { 1607 switch (ksym) {
1619 case KS_Cmd_Screen0: 1608 case KS_Cmd_Screen0:
1620 case KS_Cmd_Screen1: 1609 case KS_Cmd_Screen1:
1621 case KS_Cmd_Screen2: 1610 case KS_Cmd_Screen2:
1622 case KS_Cmd_Screen3: 1611 case KS_Cmd_Screen3:
1623 case KS_Cmd_Screen4: 1612 case KS_Cmd_Screen4:
1624 case KS_Cmd_Screen5: 1613 case KS_Cmd_Screen5:
1625 case KS_Cmd_Screen6: 1614 case KS_Cmd_Screen6:
1626 case KS_Cmd_Screen7: 1615 case KS_Cmd_Screen7:
1627 case KS_Cmd_Screen8: 1616 case KS_Cmd_Screen8:
1628 case KS_Cmd_Screen9: 1617 case KS_Cmd_Screen9:
1629 wsdisplay_switch(sc->sc_base.me_dispdv, ksym - KS_Cmd_Screen0, 0); 1618 wsdisplay_switch(sc->sc_base.me_dispdv, ksym - KS_Cmd_Screen0, 0);
1630 return (1); 1619 return (1);
1631 case KS_Cmd_ResetEmul: 1620 case KS_Cmd_ResetEmul:
1632 wsdisplay_reset(sc->sc_base.me_dispdv, WSDISPLAY_RESETEMUL); 1621 wsdisplay_reset(sc->sc_base.me_dispdv, WSDISPLAY_RESETEMUL);
1633 return (1); 1622 return (1);
1634 case KS_Cmd_ResetClose: 1623 case KS_Cmd_ResetClose:
1635 wsdisplay_reset(sc->sc_base.me_dispdv, WSDISPLAY_RESETCLOSE); 1624 wsdisplay_reset(sc->sc_base.me_dispdv, WSDISPLAY_RESETCLOSE);
1636 return (1); 1625 return (1);
1637 case KS_Cmd_BacklightOn: 1626 case KS_Cmd_BacklightOn:
1638 case KS_Cmd_BacklightOff: 1627 case KS_Cmd_BacklightOff:
1639 case KS_Cmd_BacklightToggle: 1628 case KS_Cmd_BacklightToggle:
1640 change_displayparam(sc, WSDISPLAYIO_PARAM_BACKLIGHT, 1629 change_displayparam(sc, WSDISPLAYIO_PARAM_BACKLIGHT,
1641 ksym == KS_Cmd_BacklightOff ? -1 : 1, 1630 ksym == KS_Cmd_BacklightOff ? -1 : 1,
1642 ksym == KS_Cmd_BacklightToggle ? 1 : 0); 1631 ksym == KS_Cmd_BacklightToggle ? 1 : 0);
1643 return (1); 1632 return (1);
1644 case KS_Cmd_BrightnessUp: 1633 case KS_Cmd_BrightnessUp:
1645 case KS_Cmd_BrightnessDown: 1634 case KS_Cmd_BrightnessDown:
1646 case KS_Cmd_BrightnessRotate: 1635 case KS_Cmd_BrightnessRotate:
1647 change_displayparam(sc, WSDISPLAYIO_PARAM_BRIGHTNESS, 1636 change_displayparam(sc, WSDISPLAYIO_PARAM_BRIGHTNESS,
1648 ksym == KS_Cmd_BrightnessDown ? -1 : 1, 1637 ksym == KS_Cmd_BrightnessDown ? -1 : 1,
1649 ksym == KS_Cmd_BrightnessRotate ? 1 : 0); 1638 ksym == KS_Cmd_BrightnessRotate ? 1 : 0);
1650 return (1); 1639 return (1);
1651 case KS_Cmd_ContrastUp: 1640 case KS_Cmd_ContrastUp:
1652 case KS_Cmd_ContrastDown: 1641 case KS_Cmd_ContrastDown:
1653 case KS_Cmd_ContrastRotate: 1642 case KS_Cmd_ContrastRotate:
1654 change_displayparam(sc, WSDISPLAYIO_PARAM_CONTRAST, 1643 change_displayparam(sc, WSDISPLAYIO_PARAM_CONTRAST,
1655 ksym == KS_Cmd_ContrastDown ? -1 : 1, 1644 ksym == KS_Cmd_ContrastDown ? -1 : 1,
1656 ksym == KS_Cmd_ContrastRotate ? 1 : 0); 1645 ksym == KS_Cmd_ContrastRotate ? 1 : 0);
1657 return (1); 1646 return (1);
1658 } 1647 }
1659#endif 1648#endif
1660 1649
1661 return (0); 1650 return (0);
1662} 1651}
1663 1652
1664device_t 1653device_t
1665wskbd_hotkey_register(device_t self, void *cookie, wskbd_hotkey_plugin *hotkey) 1654wskbd_hotkey_register(device_t self, void *cookie, wskbd_hotkey_plugin *hotkey)
1666{ 1655{
1667 struct wskbd_softc *sc = device_private(self); 1656 struct wskbd_softc *sc = device_private(self);
1668 1657
1669 KASSERT(sc != NULL); 1658 KASSERT(sc != NULL);
1670 KASSERT(hotkey != NULL); 1659 KASSERT(hotkey != NULL);
1671 1660
1672 sc->sc_hotkey = hotkey; 1661 sc->sc_hotkey = hotkey;
1673 sc->sc_hotkeycookie = cookie; 1662 sc->sc_hotkeycookie = cookie;
1674 1663
1675 return sc->sc_base.me_dv; 1664 return sc->sc_base.me_dv;
1676} 1665}
1677 1666
1678void 1667void
1679wskbd_hotkey_deregister(device_t self) 1668wskbd_hotkey_deregister(device_t self)
1680{ 1669{
1681 struct wskbd_softc *sc = device_private(self); 1670 struct wskbd_softc *sc = device_private(self);
1682 1671
1683 KASSERT(sc != NULL); 1672 KASSERT(sc != NULL);
1684 1673
1685 sc->sc_hotkey = NULL; 1674 sc->sc_hotkey = NULL;
1686 sc->sc_hotkeycookie = NULL; 1675 sc->sc_hotkeycookie = NULL;
1687} 1676}
1688 1677
1689static int 1678static int
1690wskbd_translate(struct wskbd_internal *id, u_int type, int value) 1679wskbd_translate(struct wskbd_internal *id, u_int type, int value)
1691{ 1680{
1692 struct wskbd_softc *sc = id->t_sc; 1681 struct wskbd_softc *sc = id->t_sc;
1693 keysym_t ksym, res, *group; 1682 keysym_t ksym, res, *group;
1694 struct wscons_keymap kpbuf, *kp; 1683 struct wscons_keymap kpbuf, *kp;
1695 int iscommand = 0; 1684 int iscommand = 0;
1696 int ishotkey = 0; 1685 int ishotkey = 0;
1697 1686
1698 if (type == WSCONS_EVENT_ALL_KEYS_UP) { 1687 if (type == WSCONS_EVENT_ALL_KEYS_UP) {
1699 id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R 1688 id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R
1700 | MOD_CONTROL_L | MOD_CONTROL_R 1689 | MOD_CONTROL_L | MOD_CONTROL_R
1701 | MOD_META_L | MOD_META_R 1690 | MOD_META_L | MOD_META_R
1702 | MOD_MODESHIFT 1691 | MOD_MODESHIFT
1703 | MOD_COMMAND | MOD_COMMAND1 | MOD_COMMAND2); 1692 | MOD_COMMAND | MOD_COMMAND1 | MOD_COMMAND2);
1704 update_leds(id); 1693 update_leds(id);
1705 return (0); 1694 return (0);
1706 } 1695 }
1707  1696
1708 if (sc != NULL) { 1697 if (sc != NULL) {
1709 if (sc->sc_hotkey != NULL) 1698 if (sc->sc_hotkey != NULL)
1710 ishotkey = sc->sc_hotkey(sc, sc->sc_hotkeycookie, 1699 ishotkey = sc->sc_hotkey(sc, sc->sc_hotkeycookie,
1711 type, value); 1700 type, value);
1712 if (ishotkey) 1701 if (ishotkey)
1713 return 0; 1702 return 0;
1714 1703
1715 if (value < 0 || value >= sc->sc_maplen) { 1704 if (value < 0 || value >= sc->sc_maplen) {
1716#ifdef DEBUG 1705#ifdef DEBUG
1717 printf("%s: keycode %d out of range\n", 1706 printf("%s: keycode %d out of range\n",
1718 __func__, value); 1707 __func__, value);
1719#endif 1708#endif
1720 return (0); 1709 return (0);
1721 } 1710 }
1722 kp = sc->sc_map + value; 1711 kp = sc->sc_map + value;
1723 } else { 1712 } else {
1724 kp = &kpbuf; 1713 kp = &kpbuf;
1725 wskbd_get_mapentry(id->t_keymap, value, kp); 1714 wskbd_get_mapentry(id->t_keymap, value, kp);
1726 } 1715 }
1727 1716
1728 /* if this key has a command, process it first */ 1717 /* if this key has a command, process it first */
1729 if (sc != NULL && kp->command != KS_voidSymbol) 1718 if (sc != NULL && kp->command != KS_voidSymbol)
1730 iscommand = internal_command(sc, &type, kp->command, 1719 iscommand = internal_command(sc, &type, kp->command,
1731 kp->group1[0]); 1720 kp->group1[0]);
1732 1721
1733 /* Now update modifiers */ 1722 /* Now update modifiers */
1734 switch (kp->group1[0]) { 1723 switch (kp->group1[0]) {
1735 case KS_Shift_L: 1724 case KS_Shift_L:
1736 update_modifier(id, type, 0, MOD_SHIFT_L); 1725 update_modifier(id, type, 0, MOD_SHIFT_L);
1737 break; 1726 break;
1738 1727
1739 case KS_Shift_R: 1728 case KS_Shift_R:
1740 update_modifier(id, type, 0, MOD_SHIFT_R); 1729 update_modifier(id, type, 0, MOD_SHIFT_R);
1741 break; 1730 break;
1742 1731
1743 case KS_Shift_Lock: 1732 case KS_Shift_Lock:
1744 update_modifier(id, type, 1, MOD_SHIFTLOCK); 1733 update_modifier(id, type, 1, MOD_SHIFTLOCK);
1745 break; 1734 break;
1746 1735
1747 case KS_Caps_Lock: 1736 case KS_Caps_Lock:
1748 update_modifier(id, type, 1, MOD_CAPSLOCK); 1737 update_modifier(id, type, 1, MOD_CAPSLOCK);
1749 break; 1738 break;
1750 1739
1751 case KS_Control_L: 1740 case KS_Control_L:
1752 update_modifier(id, type, 0, MOD_CONTROL_L); 1741 update_modifier(id, type, 0, MOD_CONTROL_L);
1753 break; 1742 break;
1754 1743
1755 case KS_Control_R: 1744 case KS_Control_R:
1756 update_modifier(id, type, 0, MOD_CONTROL_R); 1745 update_modifier(id, type, 0, MOD_CONTROL_R);
1757 break; 1746 break;
1758 1747
1759 case KS_Alt_L: 1748 case KS_Alt_L:
1760 update_modifier(id, type, 0, MOD_META_L); 1749 update_modifier(id, type, 0, MOD_META_L);
1761 break; 1750 break;
1762 1751
1763 case KS_Alt_R: 1752 case KS_Alt_R:
1764 update_modifier(id, type, 0, MOD_META_R); 1753 update_modifier(id, type, 0, MOD_META_R);
1765 break; 1754 break;
1766 1755
1767 case KS_Mode_switch: 1756 case KS_Mode_switch:
1768 update_modifier(id, type, 0, MOD_MODESHIFT); 1757 update_modifier(id, type, 0, MOD_MODESHIFT);
1769 break; 1758 break;
1770 1759
1771 case KS_Num_Lock: 1760 case KS_Num_Lock:
1772 update_modifier(id, type, 1, MOD_NUMLOCK); 1761 update_modifier(id, type, 1, MOD_NUMLOCK);
1773 break; 1762 break;
1774 1763
1775#if NWSDISPLAY > 0 1764#if NWSDISPLAY > 0
1776 case KS_Hold_Screen: 1765 case KS_Hold_Screen:
1777 if (sc != NULL) { 1766 if (sc != NULL) {
1778 update_modifier(id, type, 1, MOD_HOLDSCREEN); 1767 update_modifier(id, type, 1, MOD_HOLDSCREEN);
1779 wskbd_holdscreen(sc, id->t_modifiers & MOD_HOLDSCREEN); 1768 wskbd_holdscreen(sc, id->t_modifiers & MOD_HOLDSCREEN);
1780 } 1769 }
1781 break; 1770 break;
1782#endif 1771#endif
1783 } 1772 }
1784 1773
1785 /* If this is a key release or we are in command mode, we are done */ 1774 /* If this is a key release or we are in command mode, we are done */
1786 if (type != WSCONS_EVENT_KEY_DOWN || iscommand) { 1775 if (type != WSCONS_EVENT_KEY_DOWN || iscommand) {
1787 update_leds(id); 1776 update_leds(id);
1788 return (0); 1777 return (0);
1789 } 1778 }
1790 1779
1791 /* Get the keysym */ 1780 /* Get the keysym */
1792 if (id->t_modifiers & MOD_MODESHIFT) 1781 if (id->t_modifiers & MOD_MODESHIFT)
1793 group = & kp->group2[0]; 1782 group = & kp->group2[0];
1794 else 1783 else
1795 group = & kp->group1[0]; 1784 group = & kp->group1[0];
1796 1785
1797 if ((id->t_modifiers & MOD_NUMLOCK) != 0 && 1786 if ((id->t_modifiers & MOD_NUMLOCK) != 0 &&
1798 KS_GROUP(group[1]) == KS_GROUP_Keypad) { 1787 KS_GROUP(group[1]) == KS_GROUP_Keypad) {
1799 if (MOD_ONESET(id, MOD_ANYSHIFT)) 1788 if (MOD_ONESET(id, MOD_ANYSHIFT))
1800 ksym = group[0]; 1789 ksym = group[0];
1801 else 1790 else
1802 ksym = group[1]; 1791 ksym = group[1];
1803 } else if (! MOD_ONESET(id, MOD_ANYSHIFT | MOD_CAPSLOCK)) { 1792 } else if (! MOD_ONESET(id, MOD_ANYSHIFT | MOD_CAPSLOCK)) {
1804 ksym = group[0]; 1793 ksym = group[0];
1805 } else if (MOD_ONESET(id, MOD_CAPSLOCK)) { 1794 } else if (MOD_ONESET(id, MOD_CAPSLOCK)) {
1806 if (! MOD_ONESET(id, MOD_SHIFT_L | MOD_SHIFT_R)) 1795 if (! MOD_ONESET(id, MOD_SHIFT_L | MOD_SHIFT_R))
1807 ksym = group[0]; 1796 ksym = group[0];
1808 else 1797 else
1809 ksym = group[1]; 1798 ksym = group[1];
1810 if (ksym >= KS_a && ksym <= KS_z) 1799 if (ksym >= KS_a && ksym <= KS_z)
1811 ksym += KS_A - KS_a; 1800 ksym += KS_A - KS_a;
1812 else if (ksym >= KS_agrave && ksym <= KS_thorn && 1801 else if (ksym >= KS_agrave && ksym <= KS_thorn &&
1813 ksym != KS_division) 1802 ksym != KS_division)
1814 ksym += KS_Agrave - KS_agrave; 1803 ksym += KS_Agrave - KS_agrave;
1815 } else if (MOD_ONESET(id, MOD_ANYSHIFT)) { 1804 } else if (MOD_ONESET(id, MOD_ANYSHIFT)) {
1816 ksym = group[1]; 1805 ksym = group[1];
1817 } else { 1806 } else {
1818 ksym = group[0]; 1807 ksym = group[0];
1819 } 1808 }
1820 1809
1821 /* Process compose sequence and dead accents */ 1810 /* Process compose sequence and dead accents */
1822 res = KS_voidSymbol; 1811 res = KS_voidSymbol;
1823 1812
1824 switch (KS_GROUP(ksym)) { 1813 switch (KS_GROUP(ksym)) {
1825 case KS_GROUP_Plain: 1814 case KS_GROUP_Plain:
1826 case KS_GROUP_Keypad: 1815 case KS_GROUP_Keypad:
1827 case KS_GROUP_Function: 1816 case KS_GROUP_Function:
1828 res = ksym; 1817 res = ksym;
1829 break; 1818 break;
1830 1819
1831 case KS_GROUP_Mod: 1820 case KS_GROUP_Mod:
1832 if (ksym == KS_Multi_key) { 1821 if (ksym == KS_Multi_key) {
1833 update_modifier(id, 1, 0, MOD_COMPOSE); 1822 update_modifier(id, 1, 0, MOD_COMPOSE);
1834 id->t_composelen = 2; 1823 id->t_composelen = 2;
1835 } 1824 }
1836 break; 1825 break;
1837 1826
1838 case KS_GROUP_Dead: 1827 case KS_GROUP_Dead:
1839 if (id->t_composelen == 0) { 1828 if (id->t_composelen == 0) {
1840 update_modifier(id, 1, 0, MOD_COMPOSE); 1829 update_modifier(id, 1, 0, MOD_COMPOSE);
1841 id->t_composelen = 1; 1830 id->t_composelen = 1;
1842 id->t_composebuf[0] = ksym; 1831 id->t_composebuf[0] = ksym;
1843 } else 1832 } else
1844 res = ksym; 1833 res = ksym;
1845 break; 1834 break;
1846 } 1835 }
1847 1836
1848 if (res == KS_voidSymbol) { 1837 if (res == KS_voidSymbol) {
1849 update_leds(id); 1838 update_leds(id);
1850 return (0); 1839 return (0);
1851 } 1840 }
1852 1841
1853 if (id->t_composelen > 0) { 1842 if (id->t_composelen > 0) {
1854 id->t_composebuf[2 - id->t_composelen] = res; 1843 id->t_composebuf[2 - id->t_composelen] = res;
1855 if (--id->t_composelen == 0) { 1844 if (--id->t_composelen == 0) {
1856 res = wskbd_compose_value(id->t_composebuf); 1845 res = wskbd_compose_value(id->t_composebuf);
1857 update_modifier(id, 0, 0, MOD_COMPOSE); 1846 update_modifier(id, 0, 0, MOD_COMPOSE);
1858 } else { 1847 } else {
1859 return (0); 1848 return (0);
1860 } 1849 }
1861 } 1850 }
1862 1851
1863 update_leds(id); 1852 update_leds(id);
1864 1853
1865 /* We are done, return the symbol */ 1854 /* We are done, return the symbol */
1866 if (KS_GROUP(res) == KS_GROUP_Plain) { 1855 if (KS_GROUP(res) == KS_GROUP_Plain) {
1867 if (MOD_ONESET(id, MOD_ANYCONTROL)) { 1856 if (MOD_ONESET(id, MOD_ANYCONTROL)) {
1868 if ((res >= KS_at && res <= KS_z) || res == KS_space) 1857 if ((res >= KS_at && res <= KS_z) || res == KS_space)
1869 res = res & 0x1f; 1858 res = res & 0x1f;
1870 else if (res == KS_2) 1859 else if (res == KS_2)
1871 res = 0x00; 1860 res = 0x00;
1872 else if (res >= KS_3 && res <= KS_7) 1861 else if (res >= KS_3 && res <= KS_7)
1873 res = KS_Escape + (res - KS_3); 1862 res = KS_Escape + (res - KS_3);
1874 else if (res == KS_8) 1863 else if (res == KS_8)
1875 res = KS_Delete; 1864 res = KS_Delete;
1876 /* convert CTL-/ to ^_ as xterm does (undo in emacs) */ 1865 /* convert CTL-/ to ^_ as xterm does (undo in emacs) */
1877 else if (res == KS_slash) 1866 else if (res == KS_slash)
1878 res = KS_underscore & 0x1f; 1867 res = KS_underscore & 0x1f;
1879 } 1868 }
1880 if (MOD_ONESET(id, MOD_ANYMETA)) { 1869 if (MOD_ONESET(id, MOD_ANYMETA)) {
1881 if (id->t_flags & WSKFL_METAESC) { 1870 if (id->t_flags & WSKFL_METAESC) {
1882 id->t_symbols[0] = KS_Escape; 1871 id->t_symbols[0] = KS_Escape;
1883 id->t_symbols[1] = res; 1872 id->t_symbols[1] = res;
1884 return (2); 1873 return (2);
1885 } else 1874 } else
1886 res |= 0x80; 1875 res |= 0x80;
1887 } 1876 }
1888 } 1877 }
1889 1878
1890 id->t_symbols[0] = res; 1879 id->t_symbols[0] = res;
1891 return (1); 1880 return (1);
1892} 1881}
1893 1882
1894void 1883void
1895wskbd_set_evtrans(device_t dev, keysym_t *tab, int len) 1884wskbd_set_evtrans(device_t dev, keysym_t *tab, int len)
1896{ 1885{
1897 struct wskbd_softc *sc = device_private(dev); 1886 struct wskbd_softc *sc = device_private(dev);
1898 1887
1899 sc->sc_evtrans_len = len; 1888 sc->sc_evtrans_len = len;
1900 sc->sc_evtrans = tab; 1889 sc->sc_evtrans = tab;
1901} 1890}
1902 1891