xref: /illumos-gate/usr/src/uts/common/io/kbtrans/usb_keytables.c (revision fc910014e8a32a65612105835a10995f2c13d942)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * This module contains the translation tables for the up-down encoded
28  * USB keyboards.
29  */
30 #include <sys/usb/usba/usbai_version.h>
31 
32 #define	KEYMAP_SIZE_VARIABLE
33 
34 #include <sys/param.h>
35 #include <sys/kbd.h>
36 #include <sys/stream.h>
37 #include <sys/consdev.h>
38 #include <sys/note.h>
39 #include <sys/usb/clients/hid/hid.h>
40 #include <sys/usb/clients/hid/hid_polled.h>
41 #include <sys/usb/clients/hidparser/hidparser.h>
42 #include <sys/kbtrans.h>
43 #include <sys/usb/clients/usbkbm/usbkbm.h>
44 #include <sys/types.h>
45 #include <sys/kmem.h>
46 #include <sys/sunddi.h>
47 
48 /* handy way to define control characters in the tables */
49 #define	c(char)(char&0x1F)
50 #define	ESC 0x1B
51 #define	DEL 0x7F
52 
53 /* Unshifted keyboard table for USB keyboard */
54 
55 static keymap_entry_t keytab_usb_lc[KEYMAP_SIZE_USB] = {
56 /*   0 */	HOLE, HOLE, HOLE, ERROR, 'a', 'b', 'c', 'd',
57 /*   8 */	'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
58 /*  16 */	'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
59 /*  24 */	'u', 'v', 'w', 'x', 'y', 'z', '1', '2',
60 /*  32 */	'3', '4', '5', '6', '7', '8', '9', '0',
61 /*  40 */	'\r', ESC, '\b', '\t', ' ', '-', '=', '[',
62 /*  48  */	']',   '\\',   HOLE,    ';',   '\'',    '`',   ',',   '.',
63 /*  56 */	'/', SHIFTKEYS+CAPSLOCK, TF(1), TF(2), TF(3),
64 		TF(4), TF(5), TF(6),
65 /*  64 */	TF(7), TF(8), TF(9), TF(10), TF(11), TF(12),
66 		RF(2), RF(3),
67 /*  72 */	RF(1), BF(8), RF(7), RF(9), DEL, RF(13), RF(15),
68 					STRING+RIGHTARROW,
69 /*  80 */	STRING+LEFTARROW, STRING+DOWNARROW, STRING+UPARROW,
70 					SHIFTKEYS+NUMLOCK, RF(5),
71 		RF(6), BF(15), BF(14),
72 /*  88 */	BF(11), RF(13), STRING+DOWNARROW, RF(15), STRING+LEFTARROW, \
73 		RF(11), STRING+RIGHTARROW, RF(7),
74 /*  96 */	STRING+UPARROW, RF(9), BF(8), BF(10), HOLE, COMPOSE,
75 		BF(13), HOLE,
76 /* 104 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
77 /* 112 */	HOLE, HOLE, HOLE, HOLE, LF(7), LF(16), LF(3), LF(5),
78 /* 120 */	BUCKYBITS+SYSTEMBIT, LF(2), LF(4), LF(10), LF(6), LF(8), \
79 		LF(9), RF(4),
80 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
81 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
82 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
83 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, '\r', HOLE,
84 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
85 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
86 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
87 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
88 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
89 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
90 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
91 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
92 /* 224 */	SHIFTKEYS+LEFTCTRL, SHIFTKEYS+LEFTSHIFT, SHIFTKEYS+ALT,
93 		BUCKYBITS+METABIT, SHIFTKEYS+RIGHTCTRL, SHIFTKEYS+RIGHTSHIFT,
94 		SHIFTKEYS+ALTGRAPH, BUCKYBITS+METABIT,
95 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
96 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
97 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
98 };
99 
100 
101 /* Shifted keyboard table for USB keyboard */
102 
103 static keymap_entry_t keytab_usb_uc[KEYMAP_SIZE_USB] = {
104 /*   0 */	HOLE, HOLE, HOLE, ERROR, 'A', 'B', 'C', 'D',
105 /*   8 */	'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
106 /*  16 */	'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
107 /*  24 */	'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@',
108 /*  32 */	'#', '$', '%', '^', '&', '*', '(', ')',
109 /*  40 */	'\r', ESC, '\b', '\t', ' ', '_', '+', '{',
110 /*  48  */	'}',   '|',   HOLE,    ':',   '"',  '~',   '<',   '>',
111 /*  56 */	'?', SHIFTKEYS+CAPSLOCK, TF(1), TF(2), TF(3),
112 		TF(4), TF(5), TF(6),
113 /*  64 */	TF(7), TF(8), TF(9), TF(10), TF(11), TF(12),
114 		RF(2), RF(3),
115 /*  72 */	RF(1), BF(8), RF(7), RF(9), DEL, RF(13), RF(15),
116 					STRING+RIGHTARROW,
117 /*  80 */	STRING+LEFTARROW, STRING+DOWNARROW, STRING+UPARROW,
118 					SHIFTKEYS+NUMLOCK, RF(5), RF(6), \
119 		BF(15), BF(14), \
120 /*  88 */	BF(11), RF(13), STRING+DOWNARROW, RF(15), \
121 		STRING+LEFTARROW, RF(11), STRING+RIGHTARROW, RF(7),
122 /*  96 */	STRING+UPARROW, RF(9), BF(8), BF(10), HOLE, COMPOSE,
123 		BF(13), HOLE,
124 /* 104 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
125 /* 112 */	HOLE, HOLE, HOLE, HOLE, LF(7), LF(16), LF(3), LF(5),
126 /* 120 */	BUCKYBITS+SYSTEMBIT, LF(2), LF(4), LF(10), LF(6), \
127 		LF(8), LF(9), RF(4),
128 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
129 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
130 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
131 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, '\r', HOLE,
132 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
133 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
134 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
135 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
136 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
137 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
138 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
139 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
140 /* 224 */	SHIFTKEYS+LEFTCTRL, SHIFTKEYS+LEFTSHIFT, SHIFTKEYS+ALT,
141 		BUCKYBITS+METABIT, SHIFTKEYS+RIGHTCTRL, SHIFTKEYS+RIGHTSHIFT,
142 		SHIFTKEYS+ALTGRAPH, BUCKYBITS+METABIT,
143 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
144 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
145 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
146 	};
147 
148 
149 /* Caps Locked keyboard table for USB keyboard */
150 
151 static keymap_entry_t keytab_usb_cl[KEYMAP_SIZE_USB] = {
152 
153 /*   0 */	HOLE, HOLE, HOLE, ERROR, 'A', 'B', 'C', 'D',
154 /*   8 */	'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
155 /*  16 */	'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
156 /*  24 */	'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2',
157 /*  32 */	'3', '4', '5', '6', '7', '8', '9', '0',
158 /*  40 */	'\r', ESC, '\b', '\t', ' ', '-', '=', '[',
159 /*  48  */	']',   '\\',   HOLE,    ';',   '\'',  '`',   ',',   '.',
160 /*  56 */	'/', SHIFTKEYS+CAPSLOCK, TF(1), TF(2), TF(3),
161 		TF(4), TF(5), TF(6),
162 /*  64 */	TF(7), TF(8), TF(9), TF(10), TF(11), TF(12),
163 		RF(2), RF(3),
164 /*  72 */	RF(1), BF(8), RF(7), RF(9), DEL, RF(13), RF(15),
165 						STRING+RIGHTARROW,
166 /*  80 */	STRING+LEFTARROW, STRING+DOWNARROW, STRING+UPARROW,
167 			SHIFTKEYS+NUMLOCK, RF(5), RF(6), BF(15), BF(14),
168 /*  88 */	BF(11), RF(13), STRING+DOWNARROW, RF(15),
169 		STRING+LEFTARROW, RF(11), STRING+RIGHTARROW, RF(7),
170 /*  96 */	STRING+UPARROW, RF(9), BF(8), BF(10), HOLE, COMPOSE,
171 		BF(13), HOLE,
172 /* 104 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
173 /* 112 */	HOLE, HOLE, HOLE, HOLE, LF(7), LF(16), LF(3), LF(5),
174 /* 120 */	BUCKYBITS+SYSTEMBIT, LF(2), LF(4), LF(10), LF(6),
175 		LF(8), LF(9), RF(4),
176 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
177 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
178 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
179 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, '\r', HOLE,
180 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
181 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
182 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
183 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
184 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
185 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
186 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
187 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
188 /* 224 */	SHIFTKEYS+LEFTCTRL, SHIFTKEYS+LEFTSHIFT,
189 		SHIFTKEYS+ALT, BUCKYBITS+METABIT, SHIFTKEYS+RIGHTCTRL,
190 		SHIFTKEYS+RIGHTSHIFT,
191 		SHIFTKEYS+ALTGRAPH, BUCKYBITS+METABIT,
192 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
193 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
194 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
195 	};
196 
197 
198 /* Alt Graph keyboard table for USB keyboard */
199 
200 static keymap_entry_t keytab_usb_ag[KEYMAP_SIZE_USB] = {
201 /*  0 */	HOLE,	HOLE, HOLE,	ERROR,	NOP,	NOP,	NOP,	NOP,
202 /*  8 */	NOP, 	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,
203 /* 16 */	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,
204 /* 24 */	NOP, 	NOP, 	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,
205 /* 32 */	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,	NOP,
206 /* 40 */	'\r',	ESC,	'\b',	'\t',	' ',	NOP,	NOP,	NOP,
207 /* 48 */	NOP,	NOP,	HOLE,	NOP,	NOP,	NOP,	NOP,	NOP,
208 /* 56 */	NOP,	SHIFTKEYS+CAPSLOCK,	TF(1), TF(2),
209 				TF(3),	TF(4),	TF(5),	TF(6),
210 /* 64 */	TF(7),	TF(8),	 TF(9),	TF(10),
211 					TF(11),	TF(12), RF(2),	RF(3),
212 /* 72 */	RF(1),	BF(8),	RF(7),	RF(9),	DEL, RF(13), RF(15),
213 					STRING+RIGHTARROW,
214 /* 80 */	STRING+LEFTARROW, STRING+DOWNARROW, STRING+UPARROW,
215 			SHIFTKEYS+NUMLOCK, RF(5), RF(6), BF(15), BF(14),
216 /* 88 */	BF(11),	RF(13),	STRING+DOWNARROW, RF(15),
217 			STRING+LEFTARROW, RF(11), STRING+RIGHTARROW, RF(7),
218 /* 96 */	STRING+UPARROW,	RF(9),	BF(8), BF(10),
219 					HOLE,	COMPOSE, BF(13), HOLE,
220 /* 104 */	HOLE,	HOLE,	HOLE,	HOLE,	HOLE,	HOLE, HOLE,	HOLE,
221 /* 112 */	HOLE,	HOLE, HOLE,	HOLE,	LF(7),	LF(16), LF(3), LF(5),
222 /* 120 */	BUCKYBITS+SYSTEMBIT, LF(2),	LF(4), LF(10), LF(6),
223 		LF(8),	LF(9),	RF(4),
224 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
225 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
226 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
227 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, '\r', HOLE,
228 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
229 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
230 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
231 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
232 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
233 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
234 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
235 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
236 /* 224 */	SHIFTKEYS+LEFTCTRL, SHIFTKEYS+LEFTSHIFT, SHIFTKEYS+ALT,
237 		BUCKYBITS+METABIT, SHIFTKEYS+RIGHTCTRL, SHIFTKEYS+RIGHTSHIFT,
238 		SHIFTKEYS+ALTGRAPH, BUCKYBITS+METABIT,
239 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
240 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
241 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
242 };
243 
244 /* Num Locked keyboard table for USB keyboard */
245 
246 static keymap_entry_t keytab_usb_nl[KEYMAP_SIZE_USB] = {
247 
248 /*   0 */	HOLE, HOLE, HOLE, NONL, NONL, NONL, NONL, NONL,
249 /*   8 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
250 /*  16 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
251 /*  24 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
252 /*  32 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
253 /*  40 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
254 /*  48 */	NONL, NONL, HOLE, NONL, NONL, NONL, NONL, NONL,
255 /*  56 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
256 /*  64 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
257 /*  72 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
258 /*  80 */	NONL, NONL, NONL, NONL, PADSLASH, PADSTAR, PADMINUS, PADPLUS,
259 /*  88 */	PADENTER, PAD1, PAD2, PAD3, PAD4, PAD5, PAD6, PAD7,
260 /*  96 */	PAD8, PAD9, PAD0, PADDOT, HOLE, NONL, NONL, HOLE,
261 /* 104 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
262 /* 112 */	HOLE, HOLE, HOLE, HOLE, NONL, NONL, NONL, NONL,
263 /* 120 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, PADEQUAL,
264 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
265 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
266 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
267 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, NONL, HOLE,
268 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
269 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
270 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
271 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
272 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
273 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
274 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
275 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
276 /* 224 */	NONL, NONL, NONL, NONL, NONL, NONL, NONL, NONL,
277 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
278 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
279 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
280 };
281 
282 /* Controlled keyboard table for USB keyboard */
283 
284 static keymap_entry_t keytab_usb_ct[KEYMAP_SIZE_USB] = {
285 /*   0 */	HOLE, HOLE, HOLE, ERROR, c('a'), c('b'), c('c'), c('d'),
286 /*   8 */	c('e'), c('f'), c('g'), c('h'), c('i'), c('j'), c('k'), c('l'),
287 /*  16 */	c('m'), c('n'), c('o'), c('p'), c('q'), c('r'), c('s'), c('t'),
288 /*  24 */	c('u'), c('v'), c('w'), c('x'), c('y'), c('z'), '1', c(' '),
289 /*  32 */	'3', '4', '5', c('^'), '7', '8', '9', '0',
290 /*  40 */	'\r', ESC, '\b', '\t', c(' '), c('_'), '=', ESC,
291 /*  48  */	c(']'),   c('\\'),   HOLE,    ';',   '\'',    c('^'),
292 		',',   '.',
293 /*  56 */	c('_'), SHIFTKEYS+CAPSLOCK, TF(1), TF(2), TF(3),
294 		TF(4), TF(5), TF(6),
295 /*  64 */	TF(7), TF(8), TF(9), TF(10), TF(11), TF(12),
296 		RF(2), RF(3),
297 /*  72 */	RF(1), BF(8), RF(7), RF(9), DEL, RF(13), RF(15),
298 						STRING+RIGHTARROW,
299 /*  80 */	STRING+LEFTARROW, STRING+DOWNARROW, STRING+UPARROW,
300 		SHIFTKEYS+NUMLOCK, RF(5), RF(6), BF(15), BF(14),
301 /*  88 */	BF(11), RF(13), STRING+DOWNARROW, RF(15),
302 		STRING+LEFTARROW, RF(11), STRING+RIGHTARROW, RF(7),
303 /*  96 */	STRING+UPARROW, RF(9), BF(8), BF(10), HOLE, COMPOSE,
304 		BF(13), HOLE,
305 /* 104 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
306 /* 112 */	HOLE, HOLE, HOLE, HOLE, LF(7), LF(16), LF(3), LF(5),
307 /* 120 */	BUCKYBITS+SYSTEMBIT, LF(2), LF(4), LF(10), LF(6),
308 		LF(8), LF(9), RF(4),
309 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
310 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
311 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
312 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, '\r', HOLE,
313 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
314 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
315 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
316 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
317 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
318 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
319 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
320 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
321 /* 224 */	SHIFTKEYS+LEFTCTRL, SHIFTKEYS+LEFTSHIFT, SHIFTKEYS+ALT,
322 		BUCKYBITS+METABIT, SHIFTKEYS+RIGHTCTRL, SHIFTKEYS+RIGHTSHIFT,
323 		SHIFTKEYS+ALTGRAPH, BUCKYBITS+METABIT,
324 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
325 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
326 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
327 
328 
329 };
330 
331 /* "Key Up" keyboard table for USB keyboard */
332 
333 static keymap_entry_t keytab_usb_up[KEYMAP_SIZE_USB] = {
334 
335 /*   0 */	HOLE, HOLE, HOLE, NOP, NOP, NOP, NOP, NOP,
336 /*   8 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
337 /*  16 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
338 /*  24 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
339 /*  32 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
340 /*  40 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
341 /*  48  */	NOP, NOP, HOLE, NOP, NOP, NOP, NOP, NOP,
342 /*  56 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
343 /*  64 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
344 /*  72 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
345 /*  80 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
346 /*  88 */	NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
347 /*  96 */	NOP, NOP, NOP, NOP, HOLE, NOP, NOP, HOLE,
348 /* 104 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
349 /* 112 */	HOLE, HOLE, HOLE, HOLE, NOP, NOP, NOP, NOP,
350 /* 120 */	BUCKYBITS+SYSTEMBIT, NOP, NOP, NOP, NOP, NOP, NOP, NOP,
351 /* 128 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
352 /* 136 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
353 /* 144 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
354 /* 152 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, NOP, HOLE,
355 /* 160 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
356 /* 168 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
357 /* 176 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
358 /* 184 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
359 /* 192 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
360 /* 200 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
361 /* 208 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
362 /* 216 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
363 /* 224 */	SHIFTKEYS+LEFTCTRL, SHIFTKEYS+LEFTSHIFT, SHIFTKEYS+ALT,
364 		BUCKYBITS+METABIT, SHIFTKEYS+RIGHTCTRL, SHIFTKEYS+RIGHTSHIFT,
365 		SHIFTKEYS+ALTGRAPH, BUCKYBITS+METABIT,
366 /* 232 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
367 /* 240 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
368 /* 248 */	HOLE, HOLE, HOLE, HOLE, HOLE, HOLE, HOLE,
369 	};
370 
371 
372 /*
373  * Index into keytab_pc_lc based on USB scancodes
374  */
375 static keymap_entry_t keytab_usb2pc[KEYMAP_SIZE_USB] = {
376 /*   0 */	0,	0,	0,	0,	31,	50,	48,	33,
377 /*   8 */	19,	34,	35,	36,	24,	37,	38,	39,
378 /*  16 */	52,	51,	25,	26,	17,	20,	32,	21,
379 /*  24 */	23,	49,	18,	47,	22,	46,	2,	3,
380 /*  32 */	4,	5,	6,	7,	8,	9,	10,	11,
381 /*  40 */	43,	110,	15,	16,	61,	12,	13,	27,
382 /*  48 */	28,	29,	0,	40,	41,	1,	53,	54,
383 /*  56 */	55,	30,	112,	113,	114,	115,	116,	117,
384 /*  64 */	118,	119,	120,	121,	122,	123,	124,	125,
385 /*  72 */	126,	75,	80,	85,	76,	81,	86,	89,
386 /*  80 */	79,	84,	83,	90,	95,	100,	105,	106,
387 /*  88 */	108,	93,	98,	103,	92,	97,	102,	91,
388 /*  96 */	96,	101,	99,	104,	0,	0,	0,	0,
389 /* 104 */	0,	0,	0,	0,	0,	0,	0,	0,
390 /* 112 */	0,	0,	0,	0,	0,	0,	0,	0,
391 /* 120 */	0,	0,	0,	0,	0,	0,	0,	0,
392 /* 128 */	0,	0,	0,	0,	0,	0,	0,	0,
393 /* 136 */	0,	0,	0,	0,	0,	0,	0,	0,
394 /* 144 */	0,	0,	0,	0,	0,	0,	0,	0,
395 /* 152 */	0,	0,	0,	0,	0,	0,	0,	0,
396 /* 160 */	0,	0,	0,	0,	0,	0,	0,	0,
397 /* 168 */	0,	0,	0,	0,	0,	0,	0,	0,
398 /* 176 */	0,	0,	0,	0,	0,	0,	0,	0,
399 /* 184 */	0,	0,	0,	0,	0,	0,	0,	0,
400 /* 192 */	0,	0,	0,	0,	0,	0,	0,	0,
401 /* 200 */	0,	0,	0,	0,	0,	0,	0,	0,
402 /* 208 */	0,	0,	0,	0,	0,	0,	0,	0,
403 /* 216 */	0,	0,	0,	0,	0,	0,	0,	0,
404 /* 224 */	58,	44,	60,	0,	64,	57,	62,	0,
405 /* 232 */	0,	0,	0,	0,	0,	0,	0,	0,
406 /* 240 */	0,	0,	0,	0,	0,	0,	0,	0,
407 /* 248 */	0,	0,	0,	0,	0,	0,	0
408 };
409 
410 /* Index to keymaps for USB keyboard */
411 static struct keyboard kbtrans_usb_keyindex = {
412 	KEYMAP_SIZE_USB,
413 	keytab_usb_lc,
414 	keytab_usb_uc,
415 	keytab_usb_cl,
416 	keytab_usb_ag,
417 	keytab_usb_nl,
418 	keytab_usb_ct,
419 	keytab_usb_up,
420 	0x0000,		/* Shift bits which stay on with idle keyboard */
421 	0x0000,		/* Bucky bits which stay on with idle keyboard */
422 	120,
423 #if defined(__sparc)
424 	0,		/* no alternate abort key F1 on sparc */
425 #else
426 	58,		/* alternate abort key F1 */
427 #endif
428 	4,
429 	CAPSMASK|NUMLOCKMASK,	/* Shift bits which toggle on down event */
430 	NULL,		/* Exception table */
431 	225,		/* new abort key Left Shift */
432 	229,		/* alternate new abort key Right Shift */
433 	72,		/* new abort key Pause */
434 };
435 
436 struct keyboard *
437 kbtrans_usbkb_maptab_init(void)
438 {
439 	struct keyboard *pkbd;
440 
441 	pkbd = (struct keyboard *)
442 	    kmem_alloc(sizeof (struct keyboard), KM_SLEEP);
443 
444 	bcopy(&kbtrans_usb_keyindex, pkbd, sizeof (*pkbd));
445 
446 	return (pkbd);
447 }
448 
449 void
450 kbtrans_usbkb_maptab_fini(struct keyboard **ppkbd)
451 {
452 	kmem_free(*ppkbd, sizeof (struct keyboard));
453 	*ppkbd = NULL;
454 }
455 
456 /*
457  * Translate USB scancodes to PC scancodes before sending it to 'kbtrans'
458  */
459 keymap_entry_t
460 kbtrans_keycode_usb2pc(int key)
461 {
462 	ASSERT(key >= 0 && key <= 255);
463 	return (keytab_usb2pc[key]);
464 }
465