| @@ -1,1331 +1,1315 @@ | | | @@ -1,1331 +1,1315 @@ |
1 | /* $NetBSD: wskbd.c,v 1.138 2016/12/10 22:36:28 christos Exp $ */ | | 1 | /* $NetBSD: wskbd.c,v 1.139 2017/06/11 03:38:12 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.138 2016/12/10 22:36:28 christos Exp $"); | | 108 | __KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.139 2017/06/11 03:38:12 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 | | | 146 | |
146 | #ifdef KGDB | | 147 | #ifdef KGDB |
147 | #include <sys/kgdb.h> | | 148 | #include <sys/kgdb.h> |
148 | #endif | | 149 | #endif |
149 | | | 150 | |
150 | #ifdef WSKBD_DEBUG | | 151 | #ifdef WSKBD_DEBUG |
151 | #define DPRINTF(x) if (wskbddebug) printf x | | 152 | #define DPRINTF(x) if (wskbddebug) printf x |
152 | int wskbddebug = 0; | | 153 | int wskbddebug = 0; |
153 | #else | | 154 | #else |
154 | #define DPRINTF(x) | | 155 | #define DPRINTF(x) |
155 | #endif | | 156 | #endif |
156 | | | 157 | |
157 | #include <dev/wscons/wsmuxvar.h> | | 158 | #include <dev/wscons/wsmuxvar.h> |
158 | | | 159 | |
159 | struct wskbd_internal { | | 160 | struct wskbd_internal { |
160 | const struct wskbd_mapdata *t_keymap; | | 161 | const struct wskbd_mapdata *t_keymap; |
161 | | | 162 | |
162 | const struct wskbd_consops *t_consops; | | 163 | const struct wskbd_consops *t_consops; |
163 | void *t_consaccesscookie; | | 164 | void *t_consaccesscookie; |
164 | | | 165 | |
165 | int t_modifiers; | | 166 | int t_modifiers; |
166 | int t_composelen; /* remaining entries in t_composebuf */ | | 167 | int t_composelen; /* remaining entries in t_composebuf */ |
167 | keysym_t t_composebuf[2]; | | 168 | keysym_t t_composebuf[2]; |
168 | | | 169 | |
169 | int t_flags; | | 170 | int t_flags; |
170 | #define WSKFL_METAESC 1 | | 171 | #define WSKFL_METAESC 1 |
171 | | | 172 | |
172 | #define MAXKEYSYMSPERKEY 2 /* ESC <key> at max */ | | 173 | #define MAXKEYSYMSPERKEY 2 /* ESC <key> at max */ |
173 | keysym_t t_symbols[MAXKEYSYMSPERKEY]; | | 174 | keysym_t t_symbols[MAXKEYSYMSPERKEY]; |
174 | | | 175 | |
175 | struct wskbd_softc *t_sc; /* back pointer */ | | 176 | struct wskbd_softc *t_sc; /* back pointer */ |
176 | }; | | 177 | }; |
177 | | | 178 | |
178 | struct wskbd_softc { | | 179 | struct wskbd_softc { |
179 | struct wsevsrc sc_base; | | 180 | struct wsevsrc sc_base; |
180 | | | 181 | |
181 | struct wskbd_internal *id; | | 182 | struct wskbd_internal *id; |
182 | | | 183 | |
183 | const struct wskbd_accessops *sc_accessops; | | 184 | const struct wskbd_accessops *sc_accessops; |
184 | void *sc_accesscookie; | | 185 | void *sc_accesscookie; |
185 | | | 186 | |
186 | int sc_ledstate; | | 187 | int sc_ledstate; |
187 | | | 188 | |
188 | int sc_isconsole; | | 189 | int sc_isconsole; |
189 | | | 190 | |
190 | struct wskbd_bell_data sc_bell_data; | | 191 | struct wskbd_bell_data sc_bell_data; |
191 | struct wskbd_keyrepeat_data sc_keyrepeat_data; | | 192 | struct wskbd_keyrepeat_data sc_keyrepeat_data; |
192 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 193 | #ifdef WSDISPLAY_SCROLLSUPPORT |
193 | struct wskbd_scroll_data sc_scroll_data; | | 194 | struct wskbd_scroll_data sc_scroll_data; |
194 | #endif | | 195 | #endif |
195 | | | 196 | |
196 | int sc_repeating; /* we've called timeout() */ | | 197 | int sc_repeating; /* we've called timeout() */ |
197 | callout_t sc_repeat_ch; | | 198 | callout_t sc_repeat_ch; |
198 | u_int sc_repeat_type; | | 199 | u_int sc_repeat_type; |
199 | int sc_repeat_value; | | 200 | int sc_repeat_value; |
200 | | | 201 | |
201 | int sc_translating; /* xlate to chars for emulation */ | | 202 | int sc_translating; /* xlate to chars for emulation */ |
202 | | | 203 | |
203 | int sc_maplen; /* number of entries in sc_map */ | | 204 | int sc_maplen; /* number of entries in sc_map */ |
204 | struct wscons_keymap *sc_map; /* current translation map */ | | 205 | struct wscons_keymap *sc_map; /* current translation map */ |
205 | kbd_t sc_layout; /* current layout */ | | 206 | kbd_t sc_layout; /* current layout */ |
206 | | | 207 | |
207 | int sc_refcnt; | | 208 | int sc_refcnt; |
208 | u_char sc_dying; /* device is being detached */ | | 209 | u_char sc_dying; /* device is being detached */ |
209 | | | 210 | |
210 | wskbd_hotkey_plugin *sc_hotkey; | | 211 | wskbd_hotkey_plugin *sc_hotkey; |
211 | void *sc_hotkeycookie; | | 212 | void *sc_hotkeycookie; |
212 | | | 213 | |
213 | /* optional table to translate scancodes in event mode */ | | 214 | /* optional table to translate scancodes in event mode */ |
214 | int sc_evtrans_len; | | 215 | int sc_evtrans_len; |
215 | keysym_t *sc_evtrans; | | 216 | keysym_t *sc_evtrans; |
216 | }; | | 217 | }; |
217 | | | 218 | |
218 | #define MOD_SHIFT_L (1 << 0) | | 219 | #define MOD_SHIFT_L (1 << 0) |
219 | #define MOD_SHIFT_R (1 << 1) | | 220 | #define MOD_SHIFT_R (1 << 1) |
220 | #define MOD_SHIFTLOCK (1 << 2) | | 221 | #define MOD_SHIFTLOCK (1 << 2) |
221 | #define MOD_CAPSLOCK (1 << 3) | | 222 | #define MOD_CAPSLOCK (1 << 3) |
222 | #define MOD_CONTROL_L (1 << 4) | | 223 | #define MOD_CONTROL_L (1 << 4) |
223 | #define MOD_CONTROL_R (1 << 5) | | 224 | #define MOD_CONTROL_R (1 << 5) |
224 | #define MOD_META_L (1 << 6) | | 225 | #define MOD_META_L (1 << 6) |
225 | #define MOD_META_R (1 << 7) | | 226 | #define MOD_META_R (1 << 7) |
226 | #define MOD_MODESHIFT (1 << 8) | | 227 | #define MOD_MODESHIFT (1 << 8) |
227 | #define MOD_NUMLOCK (1 << 9) | | 228 | #define MOD_NUMLOCK (1 << 9) |
228 | #define MOD_COMPOSE (1 << 10) | | 229 | #define MOD_COMPOSE (1 << 10) |
229 | #define MOD_HOLDSCREEN (1 << 11) | | 230 | #define MOD_HOLDSCREEN (1 << 11) |
230 | #define MOD_COMMAND (1 << 12) | | 231 | #define MOD_COMMAND (1 << 12) |
231 | #define MOD_COMMAND1 (1 << 13) | | 232 | #define MOD_COMMAND1 (1 << 13) |
232 | #define MOD_COMMAND2 (1 << 14) | | 233 | #define MOD_COMMAND2 (1 << 14) |
233 | | | 234 | |
234 | #define MOD_ANYSHIFT (MOD_SHIFT_L | MOD_SHIFT_R | MOD_SHIFTLOCK) | | 235 | #define MOD_ANYSHIFT (MOD_SHIFT_L | MOD_SHIFT_R | MOD_SHIFTLOCK) |
235 | #define MOD_ANYCONTROL (MOD_CONTROL_L | MOD_CONTROL_R) | | 236 | #define MOD_ANYCONTROL (MOD_CONTROL_L | MOD_CONTROL_R) |
236 | #define MOD_ANYMETA (MOD_META_L | MOD_META_R) | | 237 | #define MOD_ANYMETA (MOD_META_L | MOD_META_R) |
237 | | | 238 | |
238 | #define MOD_ONESET(id, mask) (((id)->t_modifiers & (mask)) != 0) | | 239 | #define MOD_ONESET(id, mask) (((id)->t_modifiers & (mask)) != 0) |
239 | #define MOD_ALLSET(id, mask) (((id)->t_modifiers & (mask)) == (mask)) | | 240 | #define MOD_ALLSET(id, mask) (((id)->t_modifiers & (mask)) == (mask)) |
240 | | | 241 | |
241 | #define GETMODSTATE(src, dst) \ | | 242 | #define GETMODSTATE(src, dst) \ |
242 | do { \ | | 243 | do { \ |
243 | dst |= (src & MOD_SHIFT_L) ? MOD_SHIFT_L : 0; \ | | 244 | dst |= (src & MOD_SHIFT_L) ? MOD_SHIFT_L : 0; \ |
244 | dst |= (src & MOD_SHIFT_R) ? MOD_SHIFT_R : 0; \ | | 245 | dst |= (src & MOD_SHIFT_R) ? MOD_SHIFT_R : 0; \ |
245 | dst |= (src & MOD_CONTROL_L) ? MOD_CONTROL_L : 0; \ | | 246 | dst |= (src & MOD_CONTROL_L) ? MOD_CONTROL_L : 0; \ |
246 | dst |= (src & MOD_CONTROL_R) ? MOD_CONTROL_R : 0; \ | | 247 | dst |= (src & MOD_CONTROL_R) ? MOD_CONTROL_R : 0; \ |
247 | dst |= (src & MOD_META_L) ? MOD_META_L : 0; \ | | 248 | dst |= (src & MOD_META_L) ? MOD_META_L : 0; \ |
248 | dst |= (src & MOD_META_R) ? MOD_META_R : 0; \ | | 249 | dst |= (src & MOD_META_R) ? MOD_META_R : 0; \ |
249 | } while (0) | | 250 | } while (0) |
250 | | | 251 | |
251 | static int wskbd_match(device_t, cfdata_t, void *); | | 252 | static int wskbd_match(device_t, cfdata_t, void *); |
252 | static void wskbd_attach(device_t, device_t, void *); | | 253 | static void wskbd_attach(device_t, device_t, void *); |
253 | static int wskbd_detach(device_t, int); | | 254 | static int wskbd_detach(device_t, int); |
254 | static int wskbd_activate(device_t, enum devact); | | 255 | static int wskbd_activate(device_t, enum devact); |
255 | | | 256 | |
256 | static int wskbd_displayioctl(device_t, u_long, void *, int, | | 257 | static int wskbd_displayioctl(device_t, u_long, void *, int, |
257 | struct lwp *); | | 258 | struct lwp *); |
258 | #if NWSDISPLAY > 0 | | 259 | #if NWSDISPLAY > 0 |
259 | static int wskbd_set_display(device_t, struct wsevsrc *); | | 260 | static int wskbd_set_display(device_t, struct wsevsrc *); |
260 | #else | | 261 | #else |
261 | #define wskbd_set_display NULL | | 262 | #define wskbd_set_display NULL |
262 | #endif | | 263 | #endif |
263 | | | 264 | |
264 | static inline void update_leds(struct wskbd_internal *); | | 265 | static inline void update_leds(struct wskbd_internal *); |
265 | static inline void update_modifier(struct wskbd_internal *, u_int, int, int); | | 266 | static inline void update_modifier(struct wskbd_internal *, u_int, int, int); |
266 | static int internal_command(struct wskbd_softc *, u_int *, keysym_t, keysym_t); | | 267 | static int internal_command(struct wskbd_softc *, u_int *, keysym_t, keysym_t); |
267 | static int wskbd_translate(struct wskbd_internal *, u_int, int); | | 268 | static int wskbd_translate(struct wskbd_internal *, u_int, int); |
268 | static int wskbd_enable(struct wskbd_softc *, int); | | 269 | static int wskbd_enable(struct wskbd_softc *, int); |
269 | #if NWSDISPLAY > 0 | | 270 | #if NWSDISPLAY > 0 |
270 | static void change_displayparam(struct wskbd_softc *, int, int, int); | | 271 | static void change_displayparam(struct wskbd_softc *, int, int, int); |
271 | static void wskbd_holdscreen(struct wskbd_softc *, int); | | 272 | static void wskbd_holdscreen(struct wskbd_softc *, int); |
272 | #endif | | 273 | #endif |
273 | | | 274 | |
274 | static int wskbd_do_ioctl_sc(struct wskbd_softc *, u_long, void *, int, | | 275 | static int wskbd_do_ioctl_sc(struct wskbd_softc *, u_long, void *, int, |
275 | struct lwp *); | | 276 | struct lwp *); |
276 | static void wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value); | | 277 | static void wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value); |
277 | | | 278 | |
278 | #if NWSMUX > 0 | | 279 | #if NWSMUX > 0 |
279 | static int wskbd_mux_open(struct wsevsrc *, struct wseventvar *); | | 280 | static int wskbd_mux_open(struct wsevsrc *, struct wseventvar *); |
280 | static int wskbd_mux_close(struct wsevsrc *); | | 281 | static int wskbd_mux_close(struct wsevsrc *); |
281 | #else | | 282 | #else |
282 | #define wskbd_mux_open NULL | | 283 | #define wskbd_mux_open NULL |
283 | #define wskbd_mux_close NULL | | 284 | #define wskbd_mux_close NULL |
284 | #endif | | 285 | #endif |
285 | | | 286 | |
286 | static int wskbd_do_open(struct wskbd_softc *, struct wseventvar *); | | 287 | static int wskbd_do_open(struct wskbd_softc *, struct wseventvar *); |
287 | static int wskbd_do_ioctl(device_t, u_long, void *, int, struct lwp *); | | 288 | static int wskbd_do_ioctl(device_t, u_long, void *, int, struct lwp *); |
288 | | | 289 | |
289 | CFATTACH_DECL_NEW(wskbd, sizeof (struct wskbd_softc), | | 290 | CFATTACH_DECL_NEW(wskbd, sizeof (struct wskbd_softc), |
290 | wskbd_match, wskbd_attach, wskbd_detach, wskbd_activate); | | 291 | wskbd_match, wskbd_attach, wskbd_detach, wskbd_activate); |
291 | | | 292 | |
292 | extern struct cfdriver wskbd_cd; | | 293 | extern struct cfdriver wskbd_cd; |
293 | | | 294 | |
294 | dev_type_open(wskbdopen); | | 295 | dev_type_open(wskbdopen); |
295 | dev_type_close(wskbdclose); | | 296 | dev_type_close(wskbdclose); |
296 | dev_type_read(wskbdread); | | 297 | dev_type_read(wskbdread); |
297 | dev_type_ioctl(wskbdioctl); | | 298 | dev_type_ioctl(wskbdioctl); |
298 | dev_type_poll(wskbdpoll); | | 299 | dev_type_poll(wskbdpoll); |
299 | dev_type_kqfilter(wskbdkqfilter); | | 300 | dev_type_kqfilter(wskbdkqfilter); |
300 | | | 301 | |
301 | const struct cdevsw wskbd_cdevsw = { | | 302 | const struct cdevsw wskbd_cdevsw = { |
302 | .d_open = wskbdopen, | | 303 | .d_open = wskbdopen, |
303 | .d_close = wskbdclose, | | 304 | .d_close = wskbdclose, |
304 | .d_read = wskbdread, | | 305 | .d_read = wskbdread, |
305 | .d_write = nowrite, | | 306 | .d_write = nowrite, |
306 | .d_ioctl = wskbdioctl, | | 307 | .d_ioctl = wskbdioctl, |
307 | .d_stop = nostop, | | 308 | .d_stop = nostop, |
308 | .d_tty = notty, | | 309 | .d_tty = notty, |
309 | .d_poll = wskbdpoll, | | 310 | .d_poll = wskbdpoll, |
310 | .d_mmap = nommap, | | 311 | .d_mmap = nommap, |
311 | .d_kqfilter = wskbdkqfilter, | | 312 | .d_kqfilter = wskbdkqfilter, |
312 | .d_discard = nodiscard, | | 313 | .d_discard = nodiscard, |
313 | .d_flag = D_OTHER | | 314 | .d_flag = D_OTHER |
314 | }; | | 315 | }; |
315 | | | 316 | |
316 | #ifndef WSKBD_DEFAULT_BELL_PITCH | | | |
317 | #define WSKBD_DEFAULT_BELL_PITCH 1500 /* 1500Hz */ | | | |
318 | #endif | | | |
319 | #ifndef WSKBD_DEFAULT_BELL_PERIOD | | | |
320 | #define WSKBD_DEFAULT_BELL_PERIOD 100 /* 100ms */ | | | |
321 | #endif | | | |
322 | #ifndef WSKBD_DEFAULT_BELL_VOLUME | | | |
323 | #define WSKBD_DEFAULT_BELL_VOLUME 50 /* 50% volume */ | | | |
324 | #endif | | | |
325 | | | | |
326 | struct wskbd_bell_data wskbd_default_bell_data = { | | | |
327 | WSKBD_BELL_DOALL, | | | |
328 | WSKBD_DEFAULT_BELL_PITCH, | | | |
329 | WSKBD_DEFAULT_BELL_PERIOD, | | | |
330 | WSKBD_DEFAULT_BELL_VOLUME, | | | |
331 | }; | | | |
332 | | | | |
333 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 317 | #ifdef WSDISPLAY_SCROLLSUPPORT |
334 | struct wskbd_scroll_data wskbd_default_scroll_data = { | | 318 | struct wskbd_scroll_data wskbd_default_scroll_data = { |
335 | WSKBD_SCROLL_DOALL, | | 319 | WSKBD_SCROLL_DOALL, |
336 | WSKBD_SCROLL_MODE_NORMAL, | | 320 | WSKBD_SCROLL_MODE_NORMAL, |
337 | #ifdef WSDISPLAY_SCROLLCOMBO | | 321 | #ifdef WSDISPLAY_SCROLLCOMBO |
338 | WSDISPLAY_SCROLLCOMBO, | | 322 | WSDISPLAY_SCROLLCOMBO, |
339 | #else | | 323 | #else |
340 | MOD_SHIFT_L, | | 324 | MOD_SHIFT_L, |
341 | #endif | | 325 | #endif |
342 | }; | | 326 | }; |
343 | #endif | | 327 | #endif |
344 | | | 328 | |
345 | #ifndef WSKBD_DEFAULT_KEYREPEAT_DEL1 | | 329 | #ifndef WSKBD_DEFAULT_KEYREPEAT_DEL1 |
346 | #define WSKBD_DEFAULT_KEYREPEAT_DEL1 400 /* 400ms to start repeating */ | | 330 | #define WSKBD_DEFAULT_KEYREPEAT_DEL1 400 /* 400ms to start repeating */ |
347 | #endif | | 331 | #endif |
348 | #ifndef WSKBD_DEFAULT_KEYREPEAT_DELN | | 332 | #ifndef WSKBD_DEFAULT_KEYREPEAT_DELN |
349 | #define WSKBD_DEFAULT_KEYREPEAT_DELN 100 /* 100ms to between repeats */ | | 333 | #define WSKBD_DEFAULT_KEYREPEAT_DELN 100 /* 100ms to between repeats */ |
350 | #endif | | 334 | #endif |
351 | | | 335 | |
352 | struct wskbd_keyrepeat_data wskbd_default_keyrepeat_data = { | | 336 | struct wskbd_keyrepeat_data wskbd_default_keyrepeat_data = { |
353 | WSKBD_KEYREPEAT_DOALL, | | 337 | WSKBD_KEYREPEAT_DOALL, |
354 | WSKBD_DEFAULT_KEYREPEAT_DEL1, | | 338 | WSKBD_DEFAULT_KEYREPEAT_DEL1, |
355 | WSKBD_DEFAULT_KEYREPEAT_DELN, | | 339 | WSKBD_DEFAULT_KEYREPEAT_DELN, |
356 | }; | | 340 | }; |
357 | | | 341 | |
358 | #if NWSDISPLAY > 0 || NWSMUX > 0 | | 342 | #if NWSDISPLAY > 0 || NWSMUX > 0 |
359 | struct wssrcops wskbd_srcops = { | | 343 | struct wssrcops wskbd_srcops = { |
360 | WSMUX_KBD, | | 344 | WSMUX_KBD, |
361 | wskbd_mux_open, wskbd_mux_close, wskbd_do_ioctl, | | 345 | wskbd_mux_open, wskbd_mux_close, wskbd_do_ioctl, |
362 | wskbd_displayioctl, wskbd_set_display | | 346 | wskbd_displayioctl, wskbd_set_display |
363 | }; | | 347 | }; |
364 | #endif | | 348 | #endif |
365 | | | 349 | |
366 | static bool wskbd_suspend(device_t dv, const pmf_qual_t *); | | 350 | static bool wskbd_suspend(device_t dv, const pmf_qual_t *); |
367 | static void wskbd_repeat(void *v); | | 351 | static void wskbd_repeat(void *v); |
368 | | | 352 | |
369 | static int wskbd_console_initted; | | 353 | static int wskbd_console_initted; |
370 | static struct wskbd_softc *wskbd_console_device; | | 354 | static struct wskbd_softc *wskbd_console_device; |
371 | static struct wskbd_internal wskbd_console_data; | | 355 | static struct wskbd_internal wskbd_console_data; |
372 | | | 356 | |
373 | static void wskbd_update_layout(struct wskbd_internal *, kbd_t); | | 357 | static void wskbd_update_layout(struct wskbd_internal *, kbd_t); |
374 | | | 358 | |
375 | static void | | 359 | static void |
376 | wskbd_update_layout(struct wskbd_internal *id, kbd_t enc) | | 360 | wskbd_update_layout(struct wskbd_internal *id, kbd_t enc) |
377 | { | | 361 | { |
378 | | | 362 | |
379 | if (enc & KB_METAESC) | | 363 | if (enc & KB_METAESC) |
380 | id->t_flags |= WSKFL_METAESC; | | 364 | id->t_flags |= WSKFL_METAESC; |
381 | else | | 365 | else |
382 | id->t_flags &= ~WSKFL_METAESC; | | 366 | id->t_flags &= ~WSKFL_METAESC; |
383 | } | | 367 | } |
384 | | | 368 | |
385 | /* | | 369 | /* |
386 | * Print function (for parent devices). | | 370 | * Print function (for parent devices). |
387 | */ | | 371 | */ |
388 | int | | 372 | int |
389 | wskbddevprint(void *aux, const char *pnp) | | 373 | wskbddevprint(void *aux, const char *pnp) |
390 | { | | 374 | { |
391 | #if 0 | | 375 | #if 0 |
392 | struct wskbddev_attach_args *ap = aux; | | 376 | struct wskbddev_attach_args *ap = aux; |
393 | #endif | | 377 | #endif |
394 | | | 378 | |
395 | if (pnp) | | 379 | if (pnp) |
396 | aprint_normal("wskbd at %s", pnp); | | 380 | aprint_normal("wskbd at %s", pnp); |
397 | #if 0 | | 381 | #if 0 |
398 | aprint_normal(" console %d", ap->console); | | 382 | aprint_normal(" console %d", ap->console); |
399 | #endif | | 383 | #endif |
400 | | | 384 | |
401 | return (UNCONF); | | 385 | return (UNCONF); |
402 | } | | 386 | } |
403 | | | 387 | |
404 | int | | 388 | int |
405 | wskbd_match(device_t parent, cfdata_t match, void *aux) | | 389 | wskbd_match(device_t parent, cfdata_t match, void *aux) |
406 | { | | 390 | { |
407 | struct wskbddev_attach_args *ap = aux; | | 391 | struct wskbddev_attach_args *ap = aux; |
408 | | | 392 | |
409 | if (match->wskbddevcf_console != WSKBDDEVCF_CONSOLE_UNK) { | | 393 | if (match->wskbddevcf_console != WSKBDDEVCF_CONSOLE_UNK) { |
410 | /* | | 394 | /* |
411 | * If console-ness of device specified, either match | | 395 | * If console-ness of device specified, either match |
412 | * exactly (at high priority), or fail. | | 396 | * exactly (at high priority), or fail. |
413 | */ | | 397 | */ |
414 | if (match->wskbddevcf_console != 0 && ap->console != 0) | | 398 | if (match->wskbddevcf_console != 0 && ap->console != 0) |
415 | return (10); | | 399 | return (10); |
416 | else | | 400 | else |
417 | return (0); | | 401 | return (0); |
418 | } | | 402 | } |
419 | | | 403 | |
420 | /* If console-ness unspecified, it wins. */ | | 404 | /* If console-ness unspecified, it wins. */ |
421 | return (1); | | 405 | return (1); |
422 | } | | 406 | } |
423 | | | 407 | |
424 | void | | 408 | void |
425 | wskbd_attach(device_t parent, device_t self, void *aux) | | 409 | wskbd_attach(device_t parent, device_t self, void *aux) |
426 | { | | 410 | { |
427 | struct wskbd_softc *sc = device_private(self); | | 411 | struct wskbd_softc *sc = device_private(self); |
428 | struct wskbddev_attach_args *ap = aux; | | 412 | struct wskbddev_attach_args *ap = aux; |
429 | #if NWSMUX > 0 | | 413 | #if NWSMUX > 0 |
430 | int mux, error; | | 414 | int mux, error; |
431 | #endif | | 415 | #endif |
432 | | | 416 | |
433 | sc->sc_base.me_dv = self; | | 417 | sc->sc_base.me_dv = self; |
434 | sc->sc_isconsole = ap->console; | | 418 | sc->sc_isconsole = ap->console; |
435 | sc->sc_hotkey = NULL; | | 419 | sc->sc_hotkey = NULL; |
436 | sc->sc_hotkeycookie = NULL; | | 420 | sc->sc_hotkeycookie = NULL; |
437 | sc->sc_evtrans_len = 0; | | 421 | sc->sc_evtrans_len = 0; |
438 | sc->sc_evtrans = NULL; | | 422 | sc->sc_evtrans = NULL; |
439 | | | 423 | |
440 | #if NWSMUX > 0 || NWSDISPLAY > 0 | | 424 | #if NWSMUX > 0 || NWSDISPLAY > 0 |
441 | sc->sc_base.me_ops = &wskbd_srcops; | | 425 | sc->sc_base.me_ops = &wskbd_srcops; |
442 | #endif | | 426 | #endif |
443 | #if NWSMUX > 0 | | 427 | #if NWSMUX > 0 |
444 | mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux; | | 428 | mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux; |
445 | if (ap->console) { | | 429 | if (ap->console) { |
446 | /* Ignore mux for console; it always goes to the console mux. */ | | 430 | /* Ignore mux for console; it always goes to the console mux. */ |
447 | /* printf(" (mux %d ignored for console)", mux); */ | | 431 | /* printf(" (mux %d ignored for console)", mux); */ |
448 | mux = -1; | | 432 | mux = -1; |
449 | } | | 433 | } |
450 | if (mux >= 0) | | 434 | if (mux >= 0) |
451 | aprint_normal(" mux %d", mux); | | 435 | aprint_normal(" mux %d", mux); |
452 | #else | | 436 | #else |
453 | if (device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux >= 0) | | 437 | if (device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux >= 0) |
454 | aprint_normal(" (mux ignored)"); | | 438 | aprint_normal(" (mux ignored)"); |
455 | #endif | | 439 | #endif |
456 | | | 440 | |
457 | if (ap->console) { | | 441 | if (ap->console) { |
458 | sc->id = &wskbd_console_data; | | 442 | sc->id = &wskbd_console_data; |
459 | } else { | | 443 | } else { |
460 | sc->id = malloc(sizeof(struct wskbd_internal), | | 444 | sc->id = malloc(sizeof(struct wskbd_internal), |
461 | M_DEVBUF, M_WAITOK|M_ZERO); | | 445 | M_DEVBUF, M_WAITOK|M_ZERO); |
462 | sc->id->t_keymap = ap->keymap; | | 446 | sc->id->t_keymap = ap->keymap; |
463 | wskbd_update_layout(sc->id, ap->keymap->layout); | | 447 | wskbd_update_layout(sc->id, ap->keymap->layout); |
464 | } | | 448 | } |
465 | | | 449 | |
466 | callout_init(&sc->sc_repeat_ch, 0); | | 450 | callout_init(&sc->sc_repeat_ch, 0); |
467 | callout_setfunc(&sc->sc_repeat_ch, wskbd_repeat, sc); | | 451 | callout_setfunc(&sc->sc_repeat_ch, wskbd_repeat, sc); |
468 | | | 452 | |
469 | sc->id->t_sc = sc; | | 453 | sc->id->t_sc = sc; |
470 | | | 454 | |
471 | sc->sc_accessops = ap->accessops; | | 455 | sc->sc_accessops = ap->accessops; |
472 | sc->sc_accesscookie = ap->accesscookie; | | 456 | sc->sc_accesscookie = ap->accesscookie; |
473 | sc->sc_repeating = 0; | | 457 | sc->sc_repeating = 0; |
474 | sc->sc_translating = 1; | | 458 | sc->sc_translating = 1; |
475 | sc->sc_ledstate = -1; /* force update */ | | 459 | sc->sc_ledstate = -1; /* force update */ |
476 | | | 460 | |
477 | if (wskbd_load_keymap(sc->id->t_keymap, | | 461 | if (wskbd_load_keymap(sc->id->t_keymap, |
478 | &sc->sc_map, &sc->sc_maplen) != 0) | | 462 | &sc->sc_map, &sc->sc_maplen) != 0) |
479 | panic("cannot load keymap"); | | 463 | panic("cannot load keymap"); |
480 | | | 464 | |
481 | sc->sc_layout = sc->id->t_keymap->layout; | | 465 | sc->sc_layout = sc->id->t_keymap->layout; |
482 | | | 466 | |
483 | /* set default bell and key repeat data */ | | 467 | /* set default bell and key repeat data */ |
484 | sc->sc_bell_data = wskbd_default_bell_data; | | 468 | sc->sc_bell_data = wskbd_default_bell_data; |
485 | sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data; | | 469 | sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data; |
486 | | | 470 | |
487 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 471 | #ifdef WSDISPLAY_SCROLLSUPPORT |
488 | sc->sc_scroll_data = wskbd_default_scroll_data; | | 472 | sc->sc_scroll_data = wskbd_default_scroll_data; |
489 | #endif | | 473 | #endif |
490 | | | 474 | |
491 | if (ap->console) { | | 475 | if (ap->console) { |
492 | KASSERT(wskbd_console_initted); | | 476 | KASSERT(wskbd_console_initted); |
493 | KASSERT(wskbd_console_device == NULL); | | 477 | KASSERT(wskbd_console_device == NULL); |
494 | | | 478 | |
495 | wskbd_console_device = sc; | | 479 | wskbd_console_device = sc; |
496 | | | 480 | |
497 | aprint_naive(": console keyboard"); | | 481 | aprint_naive(": console keyboard"); |
498 | aprint_normal(": console keyboard"); | | 482 | aprint_normal(": console keyboard"); |
499 | | | 483 | |
500 | #if NWSDISPLAY > 0 | | 484 | #if NWSDISPLAY > 0 |
501 | wsdisplay_set_console_kbd(&sc->sc_base); /* sets me_dispv */ | | 485 | wsdisplay_set_console_kbd(&sc->sc_base); /* sets me_dispv */ |
502 | if (sc->sc_base.me_dispdv != NULL) | | 486 | if (sc->sc_base.me_dispdv != NULL) |
503 | aprint_normal(", using %s", | | 487 | aprint_normal(", using %s", |
504 | device_xname(sc->sc_base.me_dispdv)); | | 488 | device_xname(sc->sc_base.me_dispdv)); |
505 | #endif | | 489 | #endif |
506 | } | | 490 | } |
507 | aprint_naive("\n"); | | 491 | aprint_naive("\n"); |
508 | aprint_normal("\n"); | | 492 | aprint_normal("\n"); |
509 | | | 493 | |
510 | #if NWSMUX > 0 | | 494 | #if NWSMUX > 0 |
511 | if (mux >= 0) { | | 495 | if (mux >= 0) { |
512 | error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); | | 496 | error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); |
513 | if (error) | | 497 | if (error) |
514 | aprint_error_dev(sc->sc_base.me_dv, | | 498 | aprint_error_dev(sc->sc_base.me_dv, |
515 | "attach error=%d\n", error); | | 499 | "attach error=%d\n", error); |
516 | } | | 500 | } |
517 | #endif | | 501 | #endif |
518 | | | 502 | |
519 | if (!pmf_device_register(self, wskbd_suspend, NULL)) | | 503 | if (!pmf_device_register(self, wskbd_suspend, NULL)) |
520 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 504 | aprint_error_dev(self, "couldn't establish power handler\n"); |
521 | else if (!pmf_class_input_register(self)) | | 505 | else if (!pmf_class_input_register(self)) |
522 | aprint_error_dev(self, "couldn't register as input device\n"); | | 506 | aprint_error_dev(self, "couldn't register as input device\n"); |
523 | } | | 507 | } |
524 | | | 508 | |
525 | static bool | | 509 | static bool |
526 | wskbd_suspend(device_t dv, const pmf_qual_t *qual) | | 510 | wskbd_suspend(device_t dv, const pmf_qual_t *qual) |
527 | { | | 511 | { |
528 | struct wskbd_softc *sc = device_private(dv); | | 512 | struct wskbd_softc *sc = device_private(dv); |
529 | | | 513 | |
530 | sc->sc_repeating = 0; | | 514 | sc->sc_repeating = 0; |
531 | callout_stop(&sc->sc_repeat_ch); | | 515 | callout_stop(&sc->sc_repeat_ch); |
532 | | | 516 | |
533 | return true; | | 517 | return true; |
534 | } | | 518 | } |
535 | | | 519 | |
536 | void | | 520 | void |
537 | wskbd_cnattach(const struct wskbd_consops *consops, void *conscookie, | | 521 | wskbd_cnattach(const struct wskbd_consops *consops, void *conscookie, |
538 | const struct wskbd_mapdata *mapdata) | | 522 | const struct wskbd_mapdata *mapdata) |
539 | { | | 523 | { |
540 | KASSERT(!wskbd_console_initted); | | 524 | KASSERT(!wskbd_console_initted); |
541 | | | 525 | |
542 | wskbd_console_data.t_keymap = mapdata; | | 526 | wskbd_console_data.t_keymap = mapdata; |
543 | wskbd_update_layout(&wskbd_console_data, mapdata->layout); | | 527 | wskbd_update_layout(&wskbd_console_data, mapdata->layout); |
544 | | | 528 | |
545 | wskbd_console_data.t_consops = consops; | | 529 | wskbd_console_data.t_consops = consops; |
546 | wskbd_console_data.t_consaccesscookie = conscookie; | | 530 | wskbd_console_data.t_consaccesscookie = conscookie; |
547 | | | 531 | |
548 | #if NWSDISPLAY > 0 | | 532 | #if NWSDISPLAY > 0 |
549 | wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell); | | 533 | wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell); |
550 | #endif | | 534 | #endif |
551 | | | 535 | |
552 | wskbd_console_initted = 1; | | 536 | wskbd_console_initted = 1; |
553 | } | | 537 | } |
554 | | | 538 | |
555 | void | | 539 | void |
556 | wskbd_cndetach(void) | | 540 | wskbd_cndetach(void) |
557 | { | | 541 | { |
558 | KASSERT(wskbd_console_initted); | | 542 | KASSERT(wskbd_console_initted); |
559 | | | 543 | |
560 | wskbd_console_data.t_keymap = 0; | | 544 | wskbd_console_data.t_keymap = 0; |
561 | | | 545 | |
562 | wskbd_console_data.t_consops = 0; | | 546 | wskbd_console_data.t_consops = 0; |
563 | wskbd_console_data.t_consaccesscookie = 0; | | 547 | wskbd_console_data.t_consaccesscookie = 0; |
564 | | | 548 | |
565 | #if NWSDISPLAY > 0 | | 549 | #if NWSDISPLAY > 0 |
566 | wsdisplay_unset_cons_kbd(); | | 550 | wsdisplay_unset_cons_kbd(); |
567 | #endif | | 551 | #endif |
568 | | | 552 | |
569 | wskbd_console_initted = 0; | | 553 | wskbd_console_initted = 0; |
570 | } | | 554 | } |
571 | | | 555 | |
572 | static void | | 556 | static void |
573 | wskbd_repeat(void *v) | | 557 | wskbd_repeat(void *v) |
574 | { | | 558 | { |
575 | struct wskbd_softc *sc = (struct wskbd_softc *)v; | | 559 | struct wskbd_softc *sc = (struct wskbd_softc *)v; |
576 | int s = spltty(); | | 560 | int s = spltty(); |
577 | | | 561 | |
578 | if (!sc->sc_repeating) { | | 562 | if (!sc->sc_repeating) { |
579 | /* | | 563 | /* |
580 | * race condition: a "key up" event came in when wskbd_repeat() | | 564 | * race condition: a "key up" event came in when wskbd_repeat() |
581 | * was already called but not yet spltty()'d | | 565 | * was already called but not yet spltty()'d |
582 | */ | | 566 | */ |
583 | splx(s); | | 567 | splx(s); |
584 | return; | | 568 | return; |
585 | } | | 569 | } |
586 | if (sc->sc_translating) { | | 570 | if (sc->sc_translating) { |
587 | /* deliver keys */ | | 571 | /* deliver keys */ |
588 | #if NWSDISPLAY > 0 | | 572 | #if NWSDISPLAY > 0 |
589 | if (sc->sc_base.me_dispdv != NULL) { | | 573 | if (sc->sc_base.me_dispdv != NULL) { |
590 | int i; | | 574 | int i; |
591 | for (i = 0; i < sc->sc_repeating; i++) | | 575 | for (i = 0; i < sc->sc_repeating; i++) |
592 | wsdisplay_kbdinput(sc->sc_base.me_dispdv, | | 576 | wsdisplay_kbdinput(sc->sc_base.me_dispdv, |
593 | sc->id->t_symbols[i]); | | 577 | sc->id->t_symbols[i]); |
594 | } | | 578 | } |
595 | #endif | | 579 | #endif |
596 | } else { | | 580 | } else { |
597 | #if defined(WSKBD_EVENT_AUTOREPEAT) | | 581 | #if defined(WSKBD_EVENT_AUTOREPEAT) |
598 | /* queue event */ | | 582 | /* queue event */ |
599 | wskbd_deliver_event(sc, sc->sc_repeat_type, | | 583 | wskbd_deliver_event(sc, sc->sc_repeat_type, |
600 | sc->sc_repeat_value); | | 584 | sc->sc_repeat_value); |
601 | #endif /* defined(WSKBD_EVENT_AUTOREPEAT) */ | | 585 | #endif /* defined(WSKBD_EVENT_AUTOREPEAT) */ |
602 | } | | 586 | } |
603 | 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)); |
604 | splx(s); | | 588 | splx(s); |
605 | } | | 589 | } |
606 | | | 590 | |
607 | int | | 591 | int |
608 | wskbd_activate(device_t self, enum devact act) | | 592 | wskbd_activate(device_t self, enum devact act) |
609 | { | | 593 | { |
610 | struct wskbd_softc *sc = device_private(self); | | 594 | struct wskbd_softc *sc = device_private(self); |
611 | | | 595 | |
612 | if (act == DVACT_DEACTIVATE) | | 596 | if (act == DVACT_DEACTIVATE) |
613 | sc->sc_dying = 1; | | 597 | sc->sc_dying = 1; |
614 | return (0); | | 598 | return (0); |
615 | } | | 599 | } |
616 | | | 600 | |
617 | /* | | 601 | /* |
618 | * 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 |
619 | * a reference count that's incremented while inside, e.g., read. | | 603 | * a reference count that's incremented while inside, e.g., read. |
620 | * 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 |
621 | * 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 |
622 | * 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 |
623 | * vnode and return (which will deallocate the softc). | | 607 | * vnode and return (which will deallocate the softc). |
624 | */ | | 608 | */ |
625 | int | | 609 | int |
626 | wskbd_detach(device_t self, int flags) | | 610 | wskbd_detach(device_t self, int flags) |
627 | { | | 611 | { |
628 | struct wskbd_softc *sc = device_private(self); | | 612 | struct wskbd_softc *sc = device_private(self); |
629 | struct wseventvar *evar; | | 613 | struct wseventvar *evar; |
630 | int maj, mn; | | 614 | int maj, mn; |
631 | int s; | | 615 | int s; |
632 | | | 616 | |
633 | #if NWSMUX > 0 | | 617 | #if NWSMUX > 0 |
634 | /* Tell parent mux we're leaving. */ | | 618 | /* Tell parent mux we're leaving. */ |
635 | if (sc->sc_base.me_parent != NULL) | | 619 | if (sc->sc_base.me_parent != NULL) |
636 | wsmux_detach_sc(&sc->sc_base); | | 620 | wsmux_detach_sc(&sc->sc_base); |
637 | #endif | | 621 | #endif |
638 | | | 622 | |
639 | callout_halt(&sc->sc_repeat_ch, NULL); | | 623 | callout_halt(&sc->sc_repeat_ch, NULL); |
640 | callout_destroy(&sc->sc_repeat_ch); | | 624 | callout_destroy(&sc->sc_repeat_ch); |
641 | | | 625 | |
642 | if (sc->sc_isconsole) { | | 626 | if (sc->sc_isconsole) { |
643 | KASSERT(wskbd_console_device == sc); | | 627 | KASSERT(wskbd_console_device == sc); |
644 | wskbd_console_device = NULL; | | 628 | wskbd_console_device = NULL; |
645 | } | | 629 | } |
646 | | | 630 | |
647 | pmf_device_deregister(self); | | 631 | pmf_device_deregister(self); |
648 | | | 632 | |
649 | evar = sc->sc_base.me_evp; | | 633 | evar = sc->sc_base.me_evp; |
650 | if (evar != NULL && evar->io != NULL) { | | 634 | if (evar != NULL && evar->io != NULL) { |
651 | s = spltty(); | | 635 | s = spltty(); |
652 | if (--sc->sc_refcnt >= 0) { | | 636 | if (--sc->sc_refcnt >= 0) { |
653 | struct wscons_event event; | | 637 | struct wscons_event event; |
654 | | | 638 | |
655 | /* Wake everyone by generating a dummy event. */ | | 639 | /* Wake everyone by generating a dummy event. */ |
656 | event.type = 0; | | 640 | event.type = 0; |
657 | event.value = 0; | | 641 | event.value = 0; |
658 | if (wsevent_inject(evar, &event, 1) != 0) | | 642 | if (wsevent_inject(evar, &event, 1) != 0) |
659 | wsevent_wakeup(evar); | | 643 | wsevent_wakeup(evar); |
660 | | | 644 | |
661 | /* Wait for processes to go away. */ | | 645 | /* Wait for processes to go away. */ |
662 | if (tsleep(sc, PZERO, "wskdet", hz * 60)) | | 646 | if (tsleep(sc, PZERO, "wskdet", hz * 60)) |
663 | aprint_error("wskbd_detach: %s didn't detach\n", | | 647 | aprint_error("wskbd_detach: %s didn't detach\n", |
664 | device_xname(self)); | | 648 | device_xname(self)); |
665 | } | | 649 | } |
666 | splx(s); | | 650 | splx(s); |
667 | } | | 651 | } |
668 | | | 652 | |
669 | /* locate the major number */ | | 653 | /* locate the major number */ |
670 | maj = cdevsw_lookup_major(&wskbd_cdevsw); | | 654 | maj = cdevsw_lookup_major(&wskbd_cdevsw); |
671 | | | 655 | |
672 | /* Nuke the vnodes for any open instances. */ | | 656 | /* Nuke the vnodes for any open instances. */ |
673 | mn = device_unit(self); | | 657 | mn = device_unit(self); |
674 | vdevgone(maj, mn, mn, VCHR); | | 658 | vdevgone(maj, mn, mn, VCHR); |
675 | | | 659 | |
676 | return (0); | | 660 | return (0); |
677 | } | | 661 | } |
678 | | | 662 | |
679 | void | | 663 | void |
680 | wskbd_input(device_t dev, u_int type, int value) | | 664 | wskbd_input(device_t dev, u_int type, int value) |
681 | { | | 665 | { |
682 | struct wskbd_softc *sc = device_private(dev); | | 666 | struct wskbd_softc *sc = device_private(dev); |
683 | #if NWSDISPLAY > 0 | | 667 | #if NWSDISPLAY > 0 |
684 | int num, i; | | 668 | int num, i; |
685 | #endif | | 669 | #endif |
686 | | | 670 | |
687 | if (sc->sc_repeating) { | | 671 | if (sc->sc_repeating) { |
688 | sc->sc_repeating = 0; | | 672 | sc->sc_repeating = 0; |
689 | callout_stop(&sc->sc_repeat_ch); | | 673 | callout_stop(&sc->sc_repeat_ch); |
690 | } | | 674 | } |
691 | | | 675 | |
692 | device_active(dev, DVA_HARDWARE); | | 676 | device_active(dev, DVA_HARDWARE); |
693 | | | 677 | |
694 | #if NWSDISPLAY > 0 | | 678 | #if NWSDISPLAY > 0 |
695 | /* | | 679 | /* |
696 | * If /dev/wskbdN is not connected in event mode translate and | | 680 | * If /dev/wskbdN is not connected in event mode translate and |
697 | * send upstream. | | 681 | * send upstream. |
698 | */ | | 682 | */ |
699 | if (sc->sc_translating) { | | 683 | if (sc->sc_translating) { |
700 | num = wskbd_translate(sc->id, type, value); | | 684 | num = wskbd_translate(sc->id, type, value); |
701 | if (num > 0) { | | 685 | if (num > 0) { |
702 | if (sc->sc_base.me_dispdv != NULL) { | | 686 | if (sc->sc_base.me_dispdv != NULL) { |
703 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 687 | #ifdef WSDISPLAY_SCROLLSUPPORT |
704 | if (sc->id->t_symbols [0] != KS_Print_Screen) { | | 688 | if (sc->id->t_symbols [0] != KS_Print_Screen) { |
705 | wsdisplay_scroll(sc->sc_base. | | 689 | wsdisplay_scroll(sc->sc_base. |
706 | me_dispdv, WSDISPLAY_SCROLL_RESET); | | 690 | me_dispdv, WSDISPLAY_SCROLL_RESET); |
707 | } | | 691 | } |
708 | #endif | | 692 | #endif |
709 | for (i = 0; i < num; i++) | | 693 | for (i = 0; i < num; i++) |
710 | wsdisplay_kbdinput( | | 694 | wsdisplay_kbdinput( |
711 | sc->sc_base.me_dispdv, | | 695 | sc->sc_base.me_dispdv, |
712 | sc->id->t_symbols[i]); | | 696 | sc->id->t_symbols[i]); |
713 | } | | 697 | } |
714 | | | 698 | |
715 | if (sc->sc_keyrepeat_data.del1 != 0) { | | 699 | if (sc->sc_keyrepeat_data.del1 != 0) { |
716 | sc->sc_repeating = num; | | 700 | sc->sc_repeating = num; |
717 | callout_schedule(&sc->sc_repeat_ch, | | 701 | callout_schedule(&sc->sc_repeat_ch, |
718 | mstohz(sc->sc_keyrepeat_data.del1)); | | 702 | mstohz(sc->sc_keyrepeat_data.del1)); |
719 | } | | 703 | } |
720 | } | | 704 | } |
721 | return; | | 705 | return; |
722 | } | | 706 | } |
723 | #endif | | 707 | #endif |
724 | | | 708 | |
725 | wskbd_deliver_event(sc, type, value); | | 709 | wskbd_deliver_event(sc, type, value); |
726 | | | 710 | |
727 | #if defined(WSKBD_EVENT_AUTOREPEAT) | | 711 | #if defined(WSKBD_EVENT_AUTOREPEAT) |
728 | /* Repeat key presses if set. */ | | 712 | /* Repeat key presses if set. */ |
729 | 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) { |
730 | sc->sc_repeat_type = type; | | 714 | sc->sc_repeat_type = type; |
731 | sc->sc_repeat_value = value; | | 715 | sc->sc_repeat_value = value; |
732 | sc->sc_repeating = 1; | | 716 | sc->sc_repeating = 1; |
733 | callout_schedule(&sc->sc_repeat_ch, | | 717 | callout_schedule(&sc->sc_repeat_ch, |
734 | mstohz(sc->sc_keyrepeat_data.del1)); | | 718 | mstohz(sc->sc_keyrepeat_data.del1)); |
735 | } | | 719 | } |
736 | #endif /* defined(WSKBD_EVENT_AUTOREPEAT) */ | | 720 | #endif /* defined(WSKBD_EVENT_AUTOREPEAT) */ |
737 | } | | 721 | } |
738 | | | 722 | |
739 | /* | | 723 | /* |
740 | * Keyboard is generating events. Turn this keystroke into an | | 724 | * Keyboard is generating events. Turn this keystroke into an |
741 | * 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 |
742 | * keystroke is lost (sorry!). | | 726 | * keystroke is lost (sorry!). |
743 | */ | | 727 | */ |
744 | static void | | 728 | static void |
745 | wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value) | | 729 | wskbd_deliver_event(struct wskbd_softc *sc, u_int type, int value) |
746 | { | | 730 | { |
747 | struct wseventvar *evar; | | 731 | struct wseventvar *evar; |
748 | struct wscons_event event; | | 732 | struct wscons_event event; |
749 | | | 733 | |
750 | evar = sc->sc_base.me_evp; | | 734 | evar = sc->sc_base.me_evp; |
751 | | | 735 | |
752 | if (evar == NULL) { | | 736 | if (evar == NULL) { |
753 | DPRINTF(("wskbd_input: not open\n")); | | 737 | DPRINTF(("wskbd_input: not open\n")); |
754 | return; | | 738 | return; |
755 | } | | 739 | } |
756 | | | 740 | |
757 | #ifdef DIAGNOSTIC | | 741 | #ifdef DIAGNOSTIC |
758 | if (evar->q == NULL) { | | 742 | if (evar->q == NULL) { |
759 | printf("wskbd_input: evar->q=NULL\n"); | | 743 | printf("wskbd_input: evar->q=NULL\n"); |
760 | return; | | 744 | return; |
761 | } | | 745 | } |
762 | #endif | | 746 | #endif |
763 | | | 747 | |
764 | event.type = type; | | 748 | event.type = type; |
765 | event.value = 0; | | 749 | event.value = 0; |
766 | DPRINTF(("%d ->", value)); | | 750 | DPRINTF(("%d ->", value)); |
767 | if (sc->sc_evtrans_len > 0) { | | 751 | if (sc->sc_evtrans_len > 0) { |
768 | if (sc->sc_evtrans_len > value) { | | 752 | if (sc->sc_evtrans_len > value) { |
769 | DPRINTF(("%d", sc->sc_evtrans[value])); | | 753 | DPRINTF(("%d", sc->sc_evtrans[value])); |
770 | event.value = sc->sc_evtrans[value]; | | 754 | event.value = sc->sc_evtrans[value]; |
771 | } | | 755 | } |
772 | } else { | | 756 | } else { |
773 | event.value = value; | | 757 | event.value = value; |
774 | } | | 758 | } |
775 | DPRINTF(("\n")); | | 759 | DPRINTF(("\n")); |
776 | if (wsevent_inject(evar, &event, 1) != 0) | | 760 | if (wsevent_inject(evar, &event, 1) != 0) |
777 | log(LOG_WARNING, "%s: event queue overflow\n", | | 761 | log(LOG_WARNING, "%s: event queue overflow\n", |
778 | device_xname(sc->sc_base.me_dv)); | | 762 | device_xname(sc->sc_base.me_dv)); |
779 | } | | 763 | } |
780 | | | 764 | |
781 | #ifdef WSDISPLAY_COMPAT_RAWKBD | | 765 | #ifdef WSDISPLAY_COMPAT_RAWKBD |
782 | void | | 766 | void |
783 | wskbd_rawinput(device_t dev, u_char *tbuf, int len) | | 767 | wskbd_rawinput(device_t dev, u_char *tbuf, int len) |
784 | { | | 768 | { |
785 | #if NWSDISPLAY > 0 | | 769 | #if NWSDISPLAY > 0 |
786 | struct wskbd_softc *sc = device_private(dev); | | 770 | struct wskbd_softc *sc = device_private(dev); |
787 | int i; | | 771 | int i; |
788 | | | 772 | |
789 | if (sc->sc_base.me_dispdv != NULL) | | 773 | if (sc->sc_base.me_dispdv != NULL) |
790 | for (i = 0; i < len; i++) | | 774 | for (i = 0; i < len; i++) |
791 | wsdisplay_kbdinput(sc->sc_base.me_dispdv, tbuf[i]); | | 775 | wsdisplay_kbdinput(sc->sc_base.me_dispdv, tbuf[i]); |
792 | /* this is KS_GROUP_Plain */ | | 776 | /* this is KS_GROUP_Plain */ |
793 | #endif | | 777 | #endif |
794 | } | | 778 | } |
795 | #endif /* WSDISPLAY_COMPAT_RAWKBD */ | | 779 | #endif /* WSDISPLAY_COMPAT_RAWKBD */ |
796 | | | 780 | |
797 | #if NWSDISPLAY > 0 | | 781 | #if NWSDISPLAY > 0 |
798 | static void | | 782 | static void |
799 | wskbd_holdscreen(struct wskbd_softc *sc, int hold) | | 783 | wskbd_holdscreen(struct wskbd_softc *sc, int hold) |
800 | { | | 784 | { |
801 | int new_state; | | 785 | int new_state; |
802 | | | 786 | |
803 | if (sc->sc_base.me_dispdv != NULL) { | | 787 | if (sc->sc_base.me_dispdv != NULL) { |
804 | wsdisplay_kbdholdscreen(sc->sc_base.me_dispdv, hold); | | 788 | wsdisplay_kbdholdscreen(sc->sc_base.me_dispdv, hold); |
805 | new_state = sc->sc_ledstate; | | 789 | new_state = sc->sc_ledstate; |
806 | if (hold) { | | 790 | if (hold) { |
807 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 791 | #ifdef WSDISPLAY_SCROLLSUPPORT |
808 | sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_HOLD; | | 792 | sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_HOLD; |
809 | #endif | | 793 | #endif |
810 | new_state |= WSKBD_LED_SCROLL; | | 794 | new_state |= WSKBD_LED_SCROLL; |
811 | } else { | | 795 | } else { |
812 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 796 | #ifdef WSDISPLAY_SCROLLSUPPORT |
813 | sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_NORMAL; | | 797 | sc->sc_scroll_data.mode = WSKBD_SCROLL_MODE_NORMAL; |
814 | #endif | | 798 | #endif |
815 | new_state &= ~WSKBD_LED_SCROLL; | | 799 | new_state &= ~WSKBD_LED_SCROLL; |
816 | } | | 800 | } |
817 | if (new_state != sc->sc_ledstate) { | | 801 | if (new_state != sc->sc_ledstate) { |
818 | (*sc->sc_accessops->set_leds)(sc->sc_accesscookie, | | 802 | (*sc->sc_accessops->set_leds)(sc->sc_accesscookie, |
819 | new_state); | | 803 | new_state); |
820 | sc->sc_ledstate = new_state; | | 804 | sc->sc_ledstate = new_state; |
821 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 805 | #ifdef WSDISPLAY_SCROLLSUPPORT |
822 | if (!hold) | | 806 | if (!hold) |
823 | wsdisplay_scroll(sc->sc_base.me_dispdv, | | 807 | wsdisplay_scroll(sc->sc_base.me_dispdv, |
824 | WSDISPLAY_SCROLL_RESET); | | 808 | WSDISPLAY_SCROLL_RESET); |
825 | #endif | | 809 | #endif |
826 | } | | 810 | } |
827 | } | | 811 | } |
828 | } | | 812 | } |
829 | #endif | | 813 | #endif |
830 | | | 814 | |
831 | static int | | 815 | static int |
832 | wskbd_enable(struct wskbd_softc *sc, int on) | | 816 | wskbd_enable(struct wskbd_softc *sc, int on) |
833 | { | | 817 | { |
834 | int error; | | 818 | int error; |
835 | | | 819 | |
836 | #if 0 | | 820 | #if 0 |
837 | /* 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 |
838 | * break things, so it's out. -- Lennart | | 822 | * break things, so it's out. -- Lennart |
839 | */ | | 823 | */ |
840 | if (!on && (!sc->sc_translating | | 824 | if (!on && (!sc->sc_translating |
841 | #if NWSDISPLAY > 0 | | 825 | #if NWSDISPLAY > 0 |
842 | || sc->sc_base.me_dispdv | | 826 | || sc->sc_base.me_dispdv |
843 | #endif | | 827 | #endif |
844 | )) | | 828 | )) |
845 | return (EBUSY); | | 829 | return (EBUSY); |
846 | #endif | | 830 | #endif |
847 | #if NWSDISPLAY > 0 | | 831 | #if NWSDISPLAY > 0 |
848 | if (sc->sc_base.me_dispdv != NULL) | | 832 | if (sc->sc_base.me_dispdv != NULL) |
849 | return (0); | | 833 | return (0); |
850 | #endif | | 834 | #endif |
851 | | | 835 | |
852 | /* Always cancel auto repeat when fiddling with the kbd. */ | | 836 | /* Always cancel auto repeat when fiddling with the kbd. */ |
853 | if (sc->sc_repeating) { | | 837 | if (sc->sc_repeating) { |
854 | sc->sc_repeating = 0; | | 838 | sc->sc_repeating = 0; |
855 | callout_stop(&sc->sc_repeat_ch); | | 839 | callout_stop(&sc->sc_repeat_ch); |
856 | } | | 840 | } |
857 | | | 841 | |
858 | error = (*sc->sc_accessops->enable)(sc->sc_accesscookie, on); | | 842 | error = (*sc->sc_accessops->enable)(sc->sc_accesscookie, on); |
859 | 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)); |
860 | return (error); | | 844 | return (error); |
861 | } | | 845 | } |
862 | | | 846 | |
863 | #if NWSMUX > 0 | | 847 | #if NWSMUX > 0 |
864 | int | | 848 | int |
865 | wskbd_mux_open(struct wsevsrc *me, struct wseventvar *evp) | | 849 | wskbd_mux_open(struct wsevsrc *me, struct wseventvar *evp) |
866 | { | | 850 | { |
867 | struct wskbd_softc *sc = (struct wskbd_softc *)me; | | 851 | struct wskbd_softc *sc = (struct wskbd_softc *)me; |
868 | | | 852 | |
869 | if (sc->sc_dying) | | 853 | if (sc->sc_dying) |
870 | return (EIO); | | 854 | return (EIO); |
871 | | | 855 | |
872 | if (sc->sc_base.me_evp != NULL) | | 856 | if (sc->sc_base.me_evp != NULL) |
873 | return (EBUSY); | | 857 | return (EBUSY); |
874 | | | 858 | |
875 | return (wskbd_do_open(sc, evp)); | | 859 | return (wskbd_do_open(sc, evp)); |
876 | } | | 860 | } |
877 | #endif | | 861 | #endif |
878 | | | 862 | |
879 | int | | 863 | int |
880 | wskbdopen(dev_t dev, int flags, int mode, struct lwp *l) | | 864 | wskbdopen(dev_t dev, int flags, int mode, struct lwp *l) |
881 | { | | 865 | { |
882 | struct wskbd_softc *sc = device_lookup_private(&wskbd_cd, minor(dev)); | | 866 | struct wskbd_softc *sc = device_lookup_private(&wskbd_cd, minor(dev)); |
883 | struct wseventvar *evar; | | 867 | struct wseventvar *evar; |
884 | int error; | | 868 | int error; |
885 | | | 869 | |
886 | if (sc == NULL) | | 870 | if (sc == NULL) |
887 | return (ENXIO); | | 871 | return (ENXIO); |
888 | | | 872 | |
889 | #if NWSMUX > 0 | | 873 | #if NWSMUX > 0 |
890 | DPRINTF(("wskbdopen: %s mux=%p l=%p\n", | | 874 | DPRINTF(("wskbdopen: %s mux=%p l=%p\n", |
891 | 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)); |
892 | #endif | | 876 | #endif |
893 | | | 877 | |
894 | if (sc->sc_dying) | | 878 | if (sc->sc_dying) |
895 | return (EIO); | | 879 | return (EIO); |
896 | | | 880 | |
897 | if ((flags & (FREAD | FWRITE)) == FWRITE) | | 881 | if ((flags & (FREAD | FWRITE)) == FWRITE) |
898 | /* Not opening for read, only ioctl is available. */ | | 882 | /* Not opening for read, only ioctl is available. */ |
899 | return (0); | | 883 | return (0); |
900 | | | 884 | |
901 | #if NWSMUX > 0 | | 885 | #if NWSMUX > 0 |
902 | if (sc->sc_base.me_parent != NULL) { | | 886 | if (sc->sc_base.me_parent != NULL) { |
903 | /* Grab the keyboard out of the greedy hands of the mux. */ | | 887 | /* Grab the keyboard out of the greedy hands of the mux. */ |
904 | DPRINTF(("wskbdopen: detach\n")); | | 888 | DPRINTF(("wskbdopen: detach\n")); |
905 | wsmux_detach_sc(&sc->sc_base); | | 889 | wsmux_detach_sc(&sc->sc_base); |
906 | } | | 890 | } |
907 | #endif | | 891 | #endif |
908 | | | 892 | |
909 | if (sc->sc_base.me_evp != NULL) | | 893 | if (sc->sc_base.me_evp != NULL) |
910 | return (EBUSY); | | 894 | return (EBUSY); |
911 | | | 895 | |
912 | evar = &sc->sc_base.me_evar; | | 896 | evar = &sc->sc_base.me_evar; |
913 | wsevent_init(evar, l->l_proc); | | 897 | wsevent_init(evar, l->l_proc); |
914 | | | 898 | |
915 | error = wskbd_do_open(sc, evar); | | 899 | error = wskbd_do_open(sc, evar); |
916 | if (error) { | | 900 | if (error) { |
917 | DPRINTF(("wskbdopen: %s open failed\n", | | 901 | DPRINTF(("wskbdopen: %s open failed\n", |
918 | device_xname(sc->sc_base.me_dv))); | | 902 | device_xname(sc->sc_base.me_dv))); |
919 | sc->sc_base.me_evp = NULL; | | 903 | sc->sc_base.me_evp = NULL; |
920 | wsevent_fini(evar); | | 904 | wsevent_fini(evar); |
921 | } | | 905 | } |
922 | return (error); | | 906 | return (error); |
923 | } | | 907 | } |
924 | | | 908 | |
925 | int | | 909 | int |
926 | wskbd_do_open(struct wskbd_softc *sc, struct wseventvar *evp) | | 910 | wskbd_do_open(struct wskbd_softc *sc, struct wseventvar *evp) |
927 | { | | 911 | { |
928 | sc->sc_base.me_evp = evp; | | 912 | sc->sc_base.me_evp = evp; |
929 | sc->sc_translating = 0; | | 913 | sc->sc_translating = 0; |
930 | | | 914 | |
931 | return (wskbd_enable(sc, 1)); | | 915 | return (wskbd_enable(sc, 1)); |
932 | } | | 916 | } |
933 | | | 917 | |
934 | int | | 918 | int |
935 | wskbdclose(dev_t dev, int flags, int mode, | | 919 | wskbdclose(dev_t dev, int flags, int mode, |
936 | struct lwp *l) | | 920 | struct lwp *l) |
937 | { | | 921 | { |
938 | struct wskbd_softc *sc = | | 922 | struct wskbd_softc *sc = |
939 | device_lookup_private(&wskbd_cd, minor(dev)); | | 923 | device_lookup_private(&wskbd_cd, minor(dev)); |
940 | struct wseventvar *evar = sc->sc_base.me_evp; | | 924 | struct wseventvar *evar = sc->sc_base.me_evp; |
941 | | | 925 | |
942 | if (evar == NULL) | | 926 | if (evar == NULL) |
943 | /* not open for read */ | | 927 | /* not open for read */ |
944 | return (0); | | 928 | return (0); |
945 | | | 929 | |
946 | sc->sc_base.me_evp = NULL; | | 930 | sc->sc_base.me_evp = NULL; |
947 | sc->sc_translating = 1; | | 931 | sc->sc_translating = 1; |
948 | (void)wskbd_enable(sc, 0); | | 932 | (void)wskbd_enable(sc, 0); |
949 | wsevent_fini(evar); | | 933 | wsevent_fini(evar); |
950 | | | 934 | |
951 | return (0); | | 935 | return (0); |
952 | } | | 936 | } |
953 | | | 937 | |
954 | #if NWSMUX > 0 | | 938 | #if NWSMUX > 0 |
955 | int | | 939 | int |
956 | wskbd_mux_close(struct wsevsrc *me) | | 940 | wskbd_mux_close(struct wsevsrc *me) |
957 | { | | 941 | { |
958 | struct wskbd_softc *sc = (struct wskbd_softc *)me; | | 942 | struct wskbd_softc *sc = (struct wskbd_softc *)me; |
959 | | | 943 | |
960 | sc->sc_base.me_evp = NULL; | | 944 | sc->sc_base.me_evp = NULL; |
961 | sc->sc_translating = 1; | | 945 | sc->sc_translating = 1; |
962 | (void)wskbd_enable(sc, 0); | | 946 | (void)wskbd_enable(sc, 0); |
963 | | | 947 | |
964 | return (0); | | 948 | return (0); |
965 | } | | 949 | } |
966 | #endif | | 950 | #endif |
967 | | | 951 | |
968 | int | | 952 | int |
969 | wskbdread(dev_t dev, struct uio *uio, int flags) | | 953 | wskbdread(dev_t dev, struct uio *uio, int flags) |
970 | { | | 954 | { |
971 | struct wskbd_softc *sc = | | 955 | struct wskbd_softc *sc = |
972 | device_lookup_private(&wskbd_cd, minor(dev)); | | 956 | device_lookup_private(&wskbd_cd, minor(dev)); |
973 | int error; | | 957 | int error; |
974 | | | 958 | |
975 | if (sc->sc_dying) | | 959 | if (sc->sc_dying) |
976 | return (EIO); | | 960 | return (EIO); |
977 | | | 961 | |
978 | #ifdef DIAGNOSTIC | | 962 | #ifdef DIAGNOSTIC |
979 | if (sc->sc_base.me_evp == NULL) { | | 963 | if (sc->sc_base.me_evp == NULL) { |
980 | printf("wskbdread: evp == NULL\n"); | | 964 | printf("wskbdread: evp == NULL\n"); |
981 | return (EINVAL); | | 965 | return (EINVAL); |
982 | } | | 966 | } |
983 | #endif | | 967 | #endif |
984 | | | 968 | |
985 | sc->sc_refcnt++; | | 969 | sc->sc_refcnt++; |
986 | error = wsevent_read(sc->sc_base.me_evp, uio, flags); | | 970 | error = wsevent_read(sc->sc_base.me_evp, uio, flags); |
987 | if (--sc->sc_refcnt < 0) { | | 971 | if (--sc->sc_refcnt < 0) { |
988 | wakeup(sc); | | 972 | wakeup(sc); |
989 | error = EIO; | | 973 | error = EIO; |
990 | } | | 974 | } |
991 | return (error); | | 975 | return (error); |
992 | } | | 976 | } |
993 | | | 977 | |
994 | int | | 978 | int |
995 | wskbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) | | 979 | wskbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) |
996 | { | | 980 | { |
997 | return (wskbd_do_ioctl(device_lookup(&wskbd_cd, minor(dev)), | | 981 | return (wskbd_do_ioctl(device_lookup(&wskbd_cd, minor(dev)), |
998 | cmd, data, flag,l)); | | 982 | cmd, data, flag,l)); |
999 | } | | 983 | } |
1000 | | | 984 | |
1001 | /* A wrapper around the ioctl() workhorse to make reference counting easy. */ | | 985 | /* A wrapper around the ioctl() workhorse to make reference counting easy. */ |
1002 | int | | 986 | int |
1003 | wskbd_do_ioctl(device_t dv, u_long cmd, void *data, int flag, | | 987 | wskbd_do_ioctl(device_t dv, u_long cmd, void *data, int flag, |
1004 | struct lwp *l) | | 988 | struct lwp *l) |
1005 | { | | 989 | { |
1006 | struct wskbd_softc *sc = device_private(dv); | | 990 | struct wskbd_softc *sc = device_private(dv); |
1007 | int error; | | 991 | int error; |
1008 | | | 992 | |
1009 | sc->sc_refcnt++; | | 993 | sc->sc_refcnt++; |
1010 | error = wskbd_do_ioctl_sc(sc, cmd, data, flag, l); | | 994 | error = wskbd_do_ioctl_sc(sc, cmd, data, flag, l); |
1011 | if (--sc->sc_refcnt < 0) | | 995 | if (--sc->sc_refcnt < 0) |
1012 | wakeup(sc); | | 996 | wakeup(sc); |
1013 | return (error); | | 997 | return (error); |
1014 | } | | 998 | } |
1015 | | | 999 | |
1016 | int | | 1000 | int |
1017 | wskbd_do_ioctl_sc(struct wskbd_softc *sc, u_long cmd, void *data, int flag, | | 1001 | wskbd_do_ioctl_sc(struct wskbd_softc *sc, u_long cmd, void *data, int flag, |
1018 | struct lwp *l) | | 1002 | struct lwp *l) |
1019 | { | | 1003 | { |
1020 | | | 1004 | |
1021 | /* | | 1005 | /* |
1022 | * Try the generic ioctls that the wskbd interface supports. | | 1006 | * Try the generic ioctls that the wskbd interface supports. |
1023 | */ | | 1007 | */ |
1024 | switch (cmd) { | | 1008 | switch (cmd) { |
1025 | case FIONBIO: /* we will remove this someday (soon???) */ | | 1009 | case FIONBIO: /* we will remove this someday (soon???) */ |
1026 | return (0); | | 1010 | return (0); |
1027 | | | 1011 | |
1028 | case FIOASYNC: | | 1012 | case FIOASYNC: |
1029 | if (sc->sc_base.me_evp == NULL) | | 1013 | if (sc->sc_base.me_evp == NULL) |
1030 | return (EINVAL); | | 1014 | return (EINVAL); |
1031 | sc->sc_base.me_evp->async = *(int *)data != 0; | | 1015 | sc->sc_base.me_evp->async = *(int *)data != 0; |
1032 | return (0); | | 1016 | return (0); |
1033 | | | 1017 | |
1034 | case FIOSETOWN: | | 1018 | case FIOSETOWN: |
1035 | if (sc->sc_base.me_evp == NULL) | | 1019 | if (sc->sc_base.me_evp == NULL) |
1036 | return (EINVAL); | | 1020 | return (EINVAL); |
1037 | if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid | | 1021 | if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid |
1038 | && *(int *)data != sc->sc_base.me_evp->io->p_pid) | | 1022 | && *(int *)data != sc->sc_base.me_evp->io->p_pid) |
1039 | return (EPERM); | | 1023 | return (EPERM); |
1040 | return (0); | | 1024 | return (0); |
1041 | | | 1025 | |
1042 | case TIOCSPGRP: | | 1026 | case TIOCSPGRP: |
1043 | if (sc->sc_base.me_evp == NULL) | | 1027 | if (sc->sc_base.me_evp == NULL) |
1044 | return (EINVAL); | | 1028 | return (EINVAL); |
1045 | if (*(int *)data != sc->sc_base.me_evp->io->p_pgid) | | 1029 | if (*(int *)data != sc->sc_base.me_evp->io->p_pgid) |
1046 | return (EPERM); | | 1030 | return (EPERM); |
1047 | return (0); | | 1031 | return (0); |
1048 | } | | 1032 | } |
1049 | | | 1033 | |
1050 | /* | | 1034 | /* |
1051 | * Try the keyboard driver for WSKBDIO ioctls. It returns EPASSTHROUGH | | 1035 | * Try the keyboard driver for WSKBDIO ioctls. It returns EPASSTHROUGH |
1052 | * if it didn't recognize the request. | | 1036 | * if it didn't recognize the request. |
1053 | */ | | 1037 | */ |
1054 | 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)); |
1055 | } | | 1039 | } |
1056 | | | 1040 | |
1057 | /* | | 1041 | /* |
1058 | * WSKBDIO ioctls, handled in both emulation mode and in ``raw'' mode. | | 1042 | * WSKBDIO ioctls, handled in both emulation mode and in ``raw'' mode. |
1059 | * Some of these have no real effect in raw mode, however. | | 1043 | * Some of these have no real effect in raw mode, however. |
1060 | */ | | 1044 | */ |
1061 | static int | | 1045 | static int |
1062 | wskbd_displayioctl(device_t dev, u_long cmd, void *data, int flag, | | 1046 | wskbd_displayioctl(device_t dev, u_long cmd, void *data, int flag, |
1063 | struct lwp *l) | | 1047 | struct lwp *l) |
1064 | { | | 1048 | { |
1065 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 1049 | #ifdef WSDISPLAY_SCROLLSUPPORT |
1066 | struct wskbd_scroll_data *usdp, *ksdp; | | 1050 | struct wskbd_scroll_data *usdp, *ksdp; |
1067 | #endif | | 1051 | #endif |
1068 | struct wskbd_softc *sc = device_private(dev); | | 1052 | struct wskbd_softc *sc = device_private(dev); |
1069 | struct wskbd_bell_data *ubdp, *kbdp; | | 1053 | struct wskbd_bell_data *ubdp, *kbdp; |
1070 | struct wskbd_keyrepeat_data *ukdp, *kkdp; | | 1054 | struct wskbd_keyrepeat_data *ukdp, *kkdp; |
1071 | struct wskbd_map_data *umdp; | | 1055 | struct wskbd_map_data *umdp; |
1072 | struct wskbd_mapdata md; | | 1056 | struct wskbd_mapdata md; |
1073 | kbd_t enc; | | 1057 | kbd_t enc; |
1074 | void *tbuf; | | 1058 | void *tbuf; |
1075 | int len, error; | | 1059 | int len, error; |
1076 | | | 1060 | |
1077 | switch (cmd) { | | 1061 | switch (cmd) { |
1078 | #define SETBELL(dstp, srcp, dfltp) \ | | 1062 | #define SETBELL(dstp, srcp, dfltp) \ |
1079 | do { \ | | 1063 | do { \ |
1080 | (dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ? \ | | 1064 | (dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ? \ |
1081 | (srcp)->pitch : (dfltp)->pitch; \ | | 1065 | (srcp)->pitch : (dfltp)->pitch; \ |
1082 | (dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ? \ | | 1066 | (dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ? \ |
1083 | (srcp)->period : (dfltp)->period; \ | | 1067 | (srcp)->period : (dfltp)->period; \ |
1084 | (dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ? \ | | 1068 | (dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ? \ |
1085 | (srcp)->volume : (dfltp)->volume; \ | | 1069 | (srcp)->volume : (dfltp)->volume; \ |
1086 | (dstp)->which = WSKBD_BELL_DOALL; \ | | 1070 | (dstp)->which = WSKBD_BELL_DOALL; \ |
1087 | } while (0) | | 1071 | } while (0) |
1088 | | | 1072 | |
1089 | case WSKBDIO_BELL: | | 1073 | case WSKBDIO_BELL: |
1090 | if ((flag & FWRITE) == 0) | | 1074 | if ((flag & FWRITE) == 0) |
1091 | return (EACCES); | | 1075 | return (EACCES); |
1092 | return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, | | 1076 | return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, |
1093 | WSKBDIO_COMPLEXBELL, (void *)&sc->sc_bell_data, flag, l)); | | 1077 | WSKBDIO_COMPLEXBELL, (void *)&sc->sc_bell_data, flag, l)); |
1094 | | | 1078 | |
1095 | case WSKBDIO_COMPLEXBELL: | | 1079 | case WSKBDIO_COMPLEXBELL: |
1096 | if ((flag & FWRITE) == 0) | | 1080 | if ((flag & FWRITE) == 0) |
1097 | return (EACCES); | | 1081 | return (EACCES); |
1098 | ubdp = (struct wskbd_bell_data *)data; | | 1082 | ubdp = (struct wskbd_bell_data *)data; |
1099 | SETBELL(ubdp, ubdp, &sc->sc_bell_data); | | 1083 | SETBELL(ubdp, ubdp, &sc->sc_bell_data); |
1100 | return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, | | 1084 | return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, |
1101 | WSKBDIO_COMPLEXBELL, (void *)ubdp, flag, l)); | | 1085 | WSKBDIO_COMPLEXBELL, (void *)ubdp, flag, l)); |
1102 | | | 1086 | |
1103 | case WSKBDIO_SETBELL: | | 1087 | case WSKBDIO_SETBELL: |
1104 | if ((flag & FWRITE) == 0) | | 1088 | if ((flag & FWRITE) == 0) |
1105 | return (EACCES); | | 1089 | return (EACCES); |
1106 | kbdp = &sc->sc_bell_data; | | 1090 | kbdp = &sc->sc_bell_data; |
1107 | setbell: | | 1091 | setbell: |
1108 | ubdp = (struct wskbd_bell_data *)data; | | 1092 | ubdp = (struct wskbd_bell_data *)data; |
1109 | SETBELL(kbdp, ubdp, kbdp); | | 1093 | SETBELL(kbdp, ubdp, kbdp); |
1110 | return (0); | | 1094 | return (0); |
1111 | | | 1095 | |
1112 | case WSKBDIO_GETBELL: | | 1096 | case WSKBDIO_GETBELL: |
1113 | kbdp = &sc->sc_bell_data; | | 1097 | kbdp = &sc->sc_bell_data; |
1114 | getbell: | | 1098 | getbell: |
1115 | ubdp = (struct wskbd_bell_data *)data; | | 1099 | ubdp = (struct wskbd_bell_data *)data; |
1116 | SETBELL(ubdp, kbdp, kbdp); | | 1100 | SETBELL(ubdp, kbdp, kbdp); |
1117 | return (0); | | 1101 | return (0); |
1118 | | | 1102 | |
1119 | case WSKBDIO_SETDEFAULTBELL: | | 1103 | case WSKBDIO_SETDEFAULTBELL: |
1120 | if ((error = kauth_authorize_device(l->l_cred, | | 1104 | if ((error = kauth_authorize_device(l->l_cred, |
1121 | KAUTH_DEVICE_WSCONS_KEYBOARD_BELL, NULL, NULL, | | 1105 | KAUTH_DEVICE_WSCONS_KEYBOARD_BELL, NULL, NULL, |
1122 | NULL, NULL)) != 0) | | 1106 | NULL, NULL)) != 0) |
1123 | return (error); | | 1107 | return (error); |
1124 | kbdp = &wskbd_default_bell_data; | | 1108 | kbdp = &wskbd_default_bell_data; |
1125 | goto setbell; | | 1109 | goto setbell; |
1126 | | | 1110 | |
1127 | | | 1111 | |
1128 | case WSKBDIO_GETDEFAULTBELL: | | 1112 | case WSKBDIO_GETDEFAULTBELL: |
1129 | kbdp = &wskbd_default_bell_data; | | 1113 | kbdp = &wskbd_default_bell_data; |
1130 | goto getbell; | | 1114 | goto getbell; |
1131 | | | 1115 | |
1132 | #undef SETBELL | | 1116 | #undef SETBELL |
1133 | | | 1117 | |
1134 | #define SETKEYREPEAT(dstp, srcp, dfltp) \ | | 1118 | #define SETKEYREPEAT(dstp, srcp, dfltp) \ |
1135 | do { \ | | 1119 | do { \ |
1136 | (dstp)->del1 = ((srcp)->which & WSKBD_KEYREPEAT_DODEL1) ? \ | | 1120 | (dstp)->del1 = ((srcp)->which & WSKBD_KEYREPEAT_DODEL1) ? \ |
1137 | (srcp)->del1 : (dfltp)->del1; \ | | 1121 | (srcp)->del1 : (dfltp)->del1; \ |
1138 | (dstp)->delN = ((srcp)->which & WSKBD_KEYREPEAT_DODELN) ? \ | | 1122 | (dstp)->delN = ((srcp)->which & WSKBD_KEYREPEAT_DODELN) ? \ |
1139 | (srcp)->delN : (dfltp)->delN; \ | | 1123 | (srcp)->delN : (dfltp)->delN; \ |
1140 | (dstp)->which = WSKBD_KEYREPEAT_DOALL; \ | | 1124 | (dstp)->which = WSKBD_KEYREPEAT_DOALL; \ |
1141 | } while (0) | | 1125 | } while (0) |
1142 | | | 1126 | |
1143 | case WSKBDIO_SETKEYREPEAT: | | 1127 | case WSKBDIO_SETKEYREPEAT: |
1144 | if ((flag & FWRITE) == 0) | | 1128 | if ((flag & FWRITE) == 0) |
1145 | return (EACCES); | | 1129 | return (EACCES); |
1146 | kkdp = &sc->sc_keyrepeat_data; | | 1130 | kkdp = &sc->sc_keyrepeat_data; |
1147 | setkeyrepeat: | | 1131 | setkeyrepeat: |
1148 | ukdp = (struct wskbd_keyrepeat_data *)data; | | 1132 | ukdp = (struct wskbd_keyrepeat_data *)data; |
1149 | SETKEYREPEAT(kkdp, ukdp, kkdp); | | 1133 | SETKEYREPEAT(kkdp, ukdp, kkdp); |
1150 | return (0); | | 1134 | return (0); |
1151 | | | 1135 | |
1152 | case WSKBDIO_GETKEYREPEAT: | | 1136 | case WSKBDIO_GETKEYREPEAT: |
1153 | kkdp = &sc->sc_keyrepeat_data; | | 1137 | kkdp = &sc->sc_keyrepeat_data; |
1154 | getkeyrepeat: | | 1138 | getkeyrepeat: |
1155 | ukdp = (struct wskbd_keyrepeat_data *)data; | | 1139 | ukdp = (struct wskbd_keyrepeat_data *)data; |
1156 | SETKEYREPEAT(ukdp, kkdp, kkdp); | | 1140 | SETKEYREPEAT(ukdp, kkdp, kkdp); |
1157 | return (0); | | 1141 | return (0); |
1158 | | | 1142 | |
1159 | case WSKBDIO_SETDEFAULTKEYREPEAT: | | 1143 | case WSKBDIO_SETDEFAULTKEYREPEAT: |
1160 | if ((error = kauth_authorize_device(l->l_cred, | | 1144 | if ((error = kauth_authorize_device(l->l_cred, |
1161 | KAUTH_DEVICE_WSCONS_KEYBOARD_KEYREPEAT, NULL, NULL, | | 1145 | KAUTH_DEVICE_WSCONS_KEYBOARD_KEYREPEAT, NULL, NULL, |
1162 | NULL, NULL)) != 0) | | 1146 | NULL, NULL)) != 0) |
1163 | return (error); | | 1147 | return (error); |
1164 | kkdp = &wskbd_default_keyrepeat_data; | | 1148 | kkdp = &wskbd_default_keyrepeat_data; |
1165 | goto setkeyrepeat; | | 1149 | goto setkeyrepeat; |
1166 | | | 1150 | |
1167 | | | 1151 | |
1168 | case WSKBDIO_GETDEFAULTKEYREPEAT: | | 1152 | case WSKBDIO_GETDEFAULTKEYREPEAT: |
1169 | kkdp = &wskbd_default_keyrepeat_data; | | 1153 | kkdp = &wskbd_default_keyrepeat_data; |
1170 | goto getkeyrepeat; | | 1154 | goto getkeyrepeat; |
1171 | | | 1155 | |
1172 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 1156 | #ifdef WSDISPLAY_SCROLLSUPPORT |
1173 | #define SETSCROLLMOD(dstp, srcp, dfltp) \ | | 1157 | #define SETSCROLLMOD(dstp, srcp, dfltp) \ |
1174 | do { \ | | 1158 | do { \ |
1175 | (dstp)->mode = ((srcp)->which & WSKBD_SCROLL_DOMODE) ? \ | | 1159 | (dstp)->mode = ((srcp)->which & WSKBD_SCROLL_DOMODE) ? \ |
1176 | (srcp)->mode : (dfltp)->mode; \ | | 1160 | (srcp)->mode : (dfltp)->mode; \ |
1177 | (dstp)->modifier = ((srcp)->which & WSKBD_SCROLL_DOMODIFIER) ? \ | | 1161 | (dstp)->modifier = ((srcp)->which & WSKBD_SCROLL_DOMODIFIER) ? \ |
1178 | (srcp)->modifier : (dfltp)->modifier; \ | | 1162 | (srcp)->modifier : (dfltp)->modifier; \ |
1179 | (dstp)->which = WSKBD_SCROLL_DOALL; \ | | 1163 | (dstp)->which = WSKBD_SCROLL_DOALL; \ |
1180 | } while (0) | | 1164 | } while (0) |
1181 | | | 1165 | |
1182 | case WSKBDIO_SETSCROLL: | | 1166 | case WSKBDIO_SETSCROLL: |
1183 | usdp = (struct wskbd_scroll_data *)data; | | 1167 | usdp = (struct wskbd_scroll_data *)data; |
1184 | ksdp = &sc->sc_scroll_data; | | 1168 | ksdp = &sc->sc_scroll_data; |
1185 | SETSCROLLMOD(ksdp, usdp, ksdp); | | 1169 | SETSCROLLMOD(ksdp, usdp, ksdp); |
1186 | return (0); | | 1170 | return (0); |
1187 | | | 1171 | |
1188 | case WSKBDIO_GETSCROLL: | | 1172 | case WSKBDIO_GETSCROLL: |
1189 | usdp = (struct wskbd_scroll_data *)data; | | 1173 | usdp = (struct wskbd_scroll_data *)data; |
1190 | ksdp = &sc->sc_scroll_data; | | 1174 | ksdp = &sc->sc_scroll_data; |
1191 | SETSCROLLMOD(usdp, ksdp, ksdp); | | 1175 | SETSCROLLMOD(usdp, ksdp, ksdp); |
1192 | return (0); | | 1176 | return (0); |
1193 | #else | | 1177 | #else |
1194 | case WSKBDIO_GETSCROLL: | | 1178 | case WSKBDIO_GETSCROLL: |
1195 | case WSKBDIO_SETSCROLL: | | 1179 | case WSKBDIO_SETSCROLL: |
1196 | return ENODEV; | | 1180 | return ENODEV; |
1197 | #endif | | 1181 | #endif |
1198 | | | 1182 | |
1199 | #undef SETKEYREPEAT | | 1183 | #undef SETKEYREPEAT |
1200 | | | 1184 | |
1201 | case WSKBDIO_SETMAP: | | 1185 | case WSKBDIO_SETMAP: |
1202 | if ((flag & FWRITE) == 0) | | 1186 | if ((flag & FWRITE) == 0) |
1203 | return (EACCES); | | 1187 | return (EACCES); |
1204 | umdp = (struct wskbd_map_data *)data; | | 1188 | umdp = (struct wskbd_map_data *)data; |
1205 | if (umdp->maplen > WSKBDIO_MAXMAPLEN) | | 1189 | if (umdp->maplen > WSKBDIO_MAXMAPLEN) |
1206 | return (EINVAL); | | 1190 | return (EINVAL); |
1207 | | | 1191 | |
1208 | len = umdp->maplen*sizeof(struct wscons_keymap); | | 1192 | len = umdp->maplen*sizeof(struct wscons_keymap); |
1209 | tbuf = malloc(len, M_TEMP, M_WAITOK); | | 1193 | tbuf = malloc(len, M_TEMP, M_WAITOK); |
1210 | error = copyin(umdp->map, tbuf, len); | | 1194 | error = copyin(umdp->map, tbuf, len); |
1211 | if (error == 0) { | | 1195 | if (error == 0) { |
1212 | wskbd_init_keymap(umdp->maplen, | | 1196 | wskbd_init_keymap(umdp->maplen, |
1213 | &sc->sc_map, &sc->sc_maplen); | | 1197 | &sc->sc_map, &sc->sc_maplen); |
1214 | memcpy(sc->sc_map, tbuf, len); | | 1198 | memcpy(sc->sc_map, tbuf, len); |
1215 | /* drop the variant bits handled by the map */ | | 1199 | /* drop the variant bits handled by the map */ |
1216 | sc->sc_layout = KB_USER | | | 1200 | sc->sc_layout = KB_USER | |
1217 | (KB_VARIANT(sc->sc_layout) & KB_HANDLEDBYWSKBD); | | 1201 | (KB_VARIANT(sc->sc_layout) & KB_HANDLEDBYWSKBD); |
1218 | wskbd_update_layout(sc->id, sc->sc_layout); | | 1202 | wskbd_update_layout(sc->id, sc->sc_layout); |
1219 | } | | 1203 | } |
1220 | free(tbuf, M_TEMP); | | 1204 | free(tbuf, M_TEMP); |
1221 | return(error); | | 1205 | return(error); |
1222 | | | 1206 | |
1223 | case WSKBDIO_GETMAP: | | 1207 | case WSKBDIO_GETMAP: |
1224 | umdp = (struct wskbd_map_data *)data; | | 1208 | umdp = (struct wskbd_map_data *)data; |
1225 | if (umdp->maplen > sc->sc_maplen) | | 1209 | if (umdp->maplen > sc->sc_maplen) |
1226 | umdp->maplen = sc->sc_maplen; | | 1210 | umdp->maplen = sc->sc_maplen; |
1227 | error = copyout(sc->sc_map, umdp->map, | | 1211 | error = copyout(sc->sc_map, umdp->map, |
1228 | umdp->maplen*sizeof(struct wscons_keymap)); | | 1212 | umdp->maplen*sizeof(struct wscons_keymap)); |
1229 | return(error); | | 1213 | return(error); |
1230 | | | 1214 | |
1231 | case WSKBDIO_GETENCODING: | | 1215 | case WSKBDIO_GETENCODING: |
1232 | *((kbd_t *) data) = sc->sc_layout; | | 1216 | *((kbd_t *) data) = sc->sc_layout; |
1233 | return(0); | | 1217 | return(0); |
1234 | | | 1218 | |
1235 | case WSKBDIO_SETENCODING: | | 1219 | case WSKBDIO_SETENCODING: |
1236 | if ((flag & FWRITE) == 0) | | 1220 | if ((flag & FWRITE) == 0) |
1237 | return (EACCES); | | 1221 | return (EACCES); |
1238 | enc = *((kbd_t *)data); | | 1222 | enc = *((kbd_t *)data); |
1239 | if (KB_ENCODING(enc) == KB_USER) { | | 1223 | if (KB_ENCODING(enc) == KB_USER) { |
1240 | /* user map must already be loaded */ | | 1224 | /* user map must already be loaded */ |
1241 | if (KB_ENCODING(sc->sc_layout) != KB_USER) | | 1225 | if (KB_ENCODING(sc->sc_layout) != KB_USER) |
1242 | return (EINVAL); | | 1226 | return (EINVAL); |
1243 | /* map variants make no sense */ | | 1227 | /* map variants make no sense */ |
1244 | if (KB_VARIANT(enc) & ~KB_HANDLEDBYWSKBD) | | 1228 | if (KB_VARIANT(enc) & ~KB_HANDLEDBYWSKBD) |
1245 | return (EINVAL); | | 1229 | return (EINVAL); |
1246 | } else { | | 1230 | } else { |
1247 | md = *(sc->id->t_keymap); /* structure assignment */ | | 1231 | md = *(sc->id->t_keymap); /* structure assignment */ |
1248 | md.layout = enc; | | 1232 | md.layout = enc; |
1249 | error = wskbd_load_keymap(&md, &sc->sc_map, | | 1233 | error = wskbd_load_keymap(&md, &sc->sc_map, |
1250 | &sc->sc_maplen); | | 1234 | &sc->sc_maplen); |
1251 | if (error) | | 1235 | if (error) |
1252 | return (error); | | 1236 | return (error); |
1253 | } | | 1237 | } |
1254 | sc->sc_layout = enc; | | 1238 | sc->sc_layout = enc; |
1255 | wskbd_update_layout(sc->id, enc); | | 1239 | wskbd_update_layout(sc->id, enc); |
1256 | return (0); | | 1240 | return (0); |
1257 | | | 1241 | |
1258 | case WSKBDIO_SETVERSION: | | 1242 | case WSKBDIO_SETVERSION: |
1259 | return wsevent_setversion(sc->sc_base.me_evp, *(int *)data); | | 1243 | return wsevent_setversion(sc->sc_base.me_evp, *(int *)data); |
1260 | } | | 1244 | } |
1261 | | | 1245 | |
1262 | /* | | 1246 | /* |
1263 | * Try the keyboard driver for WSKBDIO ioctls. It returns -1 | | 1247 | * Try the keyboard driver for WSKBDIO ioctls. It returns -1 |
1264 | * if it didn't recognize the request, and in turn we return | | 1248 | * if it didn't recognize the request, and in turn we return |
1265 | * -1 if we didn't recognize the request. | | 1249 | * -1 if we didn't recognize the request. |
1266 | */ | | 1250 | */ |
1267 | /* printf("kbdaccess\n"); */ | | 1251 | /* printf("kbdaccess\n"); */ |
1268 | error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd, data, | | 1252 | error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd, data, |
1269 | flag, l); | | 1253 | flag, l); |
1270 | #ifdef WSDISPLAY_COMPAT_RAWKBD | | 1254 | #ifdef WSDISPLAY_COMPAT_RAWKBD |
1271 | if (!error && cmd == WSKBDIO_SETMODE && *(int *)data == WSKBD_RAW) { | | 1255 | if (!error && cmd == WSKBDIO_SETMODE && *(int *)data == WSKBD_RAW) { |
1272 | int s = spltty(); | | 1256 | int s = spltty(); |
1273 | sc->id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R | | 1257 | sc->id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R |
1274 | | MOD_CONTROL_L | MOD_CONTROL_R | | 1258 | | MOD_CONTROL_L | MOD_CONTROL_R |
1275 | | MOD_META_L | MOD_META_R | | 1259 | | MOD_META_L | MOD_META_R |
1276 | | MOD_COMMAND | | 1260 | | MOD_COMMAND |
1277 | | MOD_COMMAND1 | MOD_COMMAND2); | | 1261 | | MOD_COMMAND1 | MOD_COMMAND2); |
1278 | if (sc->sc_repeating) { | | 1262 | if (sc->sc_repeating) { |
1279 | sc->sc_repeating = 0; | | 1263 | sc->sc_repeating = 0; |
1280 | callout_stop(&sc->sc_repeat_ch); | | 1264 | callout_stop(&sc->sc_repeat_ch); |
1281 | } | | 1265 | } |
1282 | splx(s); | | 1266 | splx(s); |
1283 | } | | 1267 | } |
1284 | #endif | | 1268 | #endif |
1285 | return (error); | | 1269 | return (error); |
1286 | } | | 1270 | } |
1287 | | | 1271 | |
1288 | int | | 1272 | int |
1289 | wskbdpoll(dev_t dev, int events, struct lwp *l) | | 1273 | wskbdpoll(dev_t dev, int events, struct lwp *l) |
1290 | { | | 1274 | { |
1291 | struct wskbd_softc *sc = | | 1275 | struct wskbd_softc *sc = |
1292 | device_lookup_private(&wskbd_cd, minor(dev)); | | 1276 | device_lookup_private(&wskbd_cd, minor(dev)); |
1293 | | | 1277 | |
1294 | if (sc->sc_base.me_evp == NULL) | | 1278 | if (sc->sc_base.me_evp == NULL) |
1295 | return (POLLERR); | | 1279 | return (POLLERR); |
1296 | return (wsevent_poll(sc->sc_base.me_evp, events, l)); | | 1280 | return (wsevent_poll(sc->sc_base.me_evp, events, l)); |
1297 | } | | 1281 | } |
1298 | | | 1282 | |
1299 | int | | 1283 | int |
1300 | wskbdkqfilter(dev_t dev, struct knote *kn) | | 1284 | wskbdkqfilter(dev_t dev, struct knote *kn) |
1301 | { | | 1285 | { |
1302 | struct wskbd_softc *sc = | | 1286 | struct wskbd_softc *sc = |
1303 | device_lookup_private(&wskbd_cd, minor(dev)); | | 1287 | device_lookup_private(&wskbd_cd, minor(dev)); |
1304 | | | 1288 | |
1305 | if (sc->sc_base.me_evp == NULL) | | 1289 | if (sc->sc_base.me_evp == NULL) |
1306 | return (1); | | 1290 | return (1); |
1307 | return (wsevent_kqfilter(sc->sc_base.me_evp, kn)); | | 1291 | return (wsevent_kqfilter(sc->sc_base.me_evp, kn)); |
1308 | } | | 1292 | } |
1309 | | | 1293 | |
1310 | #if NWSDISPLAY > 0 | | 1294 | #if NWSDISPLAY > 0 |
1311 | | | 1295 | |
1312 | int | | 1296 | int |
1313 | wskbd_pickfree(void) | | 1297 | wskbd_pickfree(void) |
1314 | { | | 1298 | { |
1315 | int i; | | 1299 | int i; |
1316 | struct wskbd_softc *sc; | | 1300 | struct wskbd_softc *sc; |
1317 | | | 1301 | |
1318 | for (i = 0; i < wskbd_cd.cd_ndevs; i++) { | | 1302 | for (i = 0; i < wskbd_cd.cd_ndevs; i++) { |
1319 | sc = device_lookup_private(&wskbd_cd, i); | | 1303 | sc = device_lookup_private(&wskbd_cd, i); |
1320 | if (sc == NULL) | | 1304 | if (sc == NULL) |
1321 | continue; | | 1305 | continue; |
1322 | if (sc->sc_base.me_dispdv == NULL) | | 1306 | if (sc->sc_base.me_dispdv == NULL) |
1323 | return (i); | | 1307 | return (i); |
1324 | } | | 1308 | } |
1325 | return (-1); | | 1309 | return (-1); |
1326 | } | | 1310 | } |
1327 | | | 1311 | |
1328 | struct wsevsrc * | | 1312 | struct wsevsrc * |
1329 | wskbd_set_console_display(device_t displaydv, struct wsevsrc *me) | | 1313 | wskbd_set_console_display(device_t displaydv, struct wsevsrc *me) |
1330 | { | | 1314 | { |
1331 | struct wskbd_softc *sc = wskbd_console_device; | | 1315 | struct wskbd_softc *sc = wskbd_console_device; |