Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / kb8042 / at_keyprocess.c
blob3a9a9b223f89fd4e14b6e65ebb79afd3dfe149f4
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/stream.h>
28 #include <sys/kbd.h>
29 #include <sys/kbtrans.h>
30 #include <sys/sunddi.h>
31 #include <sys/consdev.h>
32 #include <sys/promif.h>
33 #include "kb8042.h"
36 * A note on the use of prom_printf here: Most of these routines can be
37 * called from "polled mode", where we're servicing I/O requests from kmdb.
38 * Normal system services are not available from polled mode; cmn_err will
39 * not work. prom_printf is the only safe output mechanism.
42 #define KEYBAD 0xff /* should generate an error */
43 #define KEYIGN 0xfe /* ignore this sequence */
45 #define KEY(code) (code)
46 #define INVALID KEYBAD
47 #define IGNORE KEYIGN
49 #define NELEM(a) (sizeof (a) / sizeof (a)[0])
52 * These are the states of our parsing machine:
54 #define STATE_IDLE 0x00000001 /* Awaiting the start of a sequence */
55 #define STATE_E0 0x00000002 /* Rec'd an E0 */
56 #define STATE_E1 0x00000004 /* Rec'd an E1 (Pause key only) */
57 #define STATE_E1_1D 0x00000008 /* Rec'd an E1 1D (Pause key only) */
58 #define STATE_E1_14 0x00000010 /* Rec'd an E1 14 (Pause key only) */
59 #define STATE_E1_14_77 0x00000020
60 #define STATE_E1_14_77_E1 0x00000040
61 #define STATE_E1_14_77_E1_F0 0x00000080
62 #define STATE_E1_14_77_E1_F0_14 0x00000100
63 #define STATE_E1_14_77_E1_F0_14_F0 0x00000200
65 static boolean_t KeyboardConvertScan_set1(struct kb8042 *, unsigned char, int *,
66 enum keystate *, boolean_t *);
67 static boolean_t KeyboardConvertScan_set2(struct kb8042 *, unsigned char, int *,
68 enum keystate *, boolean_t *);
70 static const unsigned char *keytab_base = NULL;
71 static int keytab_base_length = 0;
72 static const unsigned char *keytab_e0 = NULL;
73 static int keytab_e0_length = 0;
74 static boolean_t (*KeyboardConvertScan_fn)(struct kb8042 *, unsigned char,
75 int *, enum keystate *, boolean_t *) = NULL;
77 static const unsigned char keytab_base_set1[] = {
78 /* scan key number keycap */
79 /* 00 */ INVALID,
80 /* 01 */ KEY(110), /* Esc */
81 /* 02 */ KEY(2), /* 1 */
82 /* 03 */ KEY(3), /* 2 */
83 /* 04 */ KEY(4), /* 3 */
84 /* 05 */ KEY(5), /* 4 */
85 /* 06 */ KEY(6), /* 5 */
86 /* 07 */ KEY(7), /* 6 */
87 /* 08 */ KEY(8), /* 7 */
88 /* 09 */ KEY(9), /* 8 */
89 /* 0a */ KEY(10), /* 9 */
90 /* 0b */ KEY(11), /* 0 */
91 /* 0c */ KEY(12), /* - */
92 /* 0d */ KEY(13), /* = */
93 /* 0e */ KEY(15), /* backspace */
94 /* 0f */ KEY(16), /* tab */
96 /* 10 */ KEY(17), /* Q */
97 /* 11 */ KEY(18), /* W */
98 /* 12 */ KEY(19), /* E */
99 /* 13 */ KEY(20), /* R */
100 /* 14 */ KEY(21), /* T */
101 /* 15 */ KEY(22), /* Y */
102 /* 16 */ KEY(23), /* U */
103 /* 17 */ KEY(24), /* I */
104 /* 18 */ KEY(25), /* O */
105 /* 19 */ KEY(26), /* P */
106 /* 1a */ KEY(27), /* [ */
107 /* 1b */ KEY(28), /* ] */
108 /* 1c */ KEY(43), /* Enter (main) */
109 /* 1d */ KEY(58), /* L Ctrl */
110 /* 1e */ KEY(31), /* A */
111 /* 1f */ KEY(32), /* S */
113 /* 20 */ KEY(33), /* D */
114 /* 21 */ KEY(34), /* F */
115 /* 22 */ KEY(35), /* G */
116 /* 23 */ KEY(36), /* H */
117 /* 24 */ KEY(37), /* J */
118 /* 25 */ KEY(38), /* K */
119 /* 26 */ KEY(39), /* L */
120 /* 27 */ KEY(40), /* ; */
121 /* 28 */ KEY(41), /* ' */
122 /* 29 */ KEY(1), /* ` */
123 /* 2a */ KEY(44), /* L Shift */
124 /* 2b */ KEY(29), /* \ */
125 /* 2c */ KEY(46), /* Z */
126 /* 2d */ KEY(47), /* X */
127 /* 2e */ KEY(48), /* C */
128 /* 2f */ KEY(49), /* V */
130 /* 30 */ KEY(50), /* B */
131 /* 31 */ KEY(51), /* N */
132 /* 32 */ KEY(52), /* M */
133 /* 33 */ KEY(53), /* , */
134 /* 34 */ KEY(54), /* . */
135 /* 35 */ KEY(55), /* / */
136 /* 36 */ KEY(57), /* R Shift */
137 /* 37 */ KEY(100), /* * (num) */
138 /* 38 */ KEY(60), /* L Alt */
139 /* 39 */ KEY(61), /* Space */
140 /* 3a */ KEY(30), /* CapsLock */
141 /* 3b */ KEY(112), /* F1 */
142 /* 3c */ KEY(113), /* F2 */
143 /* 3d */ KEY(114), /* F3 */
144 /* 3e */ KEY(115), /* F4 */
145 /* 3f */ KEY(116), /* F5 */
147 /* 40 */ KEY(117), /* F6 */
148 /* 41 */ KEY(118), /* F7 */
149 /* 42 */ KEY(119), /* F8 */
150 /* 43 */ KEY(120), /* F9 */
151 /* 44 */ KEY(121), /* F10 */
152 /* 45 */ KEY(90), /* NumLock */
153 /* 46 */ KEY(125), /* Scroll Lock */
154 /* 47 */ KEY(91), /* 7 (num) */
155 /* 48 */ KEY(96), /* 8 (num) */
156 /* 49 */ KEY(101), /* 9 (num) */
157 /* 4a */ KEY(105), /* - (num) */
158 /* 4b */ KEY(92), /* 4 (num) */
159 /* 4c */ KEY(97), /* 5 (num) */
160 /* 4d */ KEY(102), /* 6 (num) */
161 /* 4e */ KEY(106), /* + (num) */
162 /* 4f */ KEY(93), /* 1 (num) */
164 /* 50 */ KEY(98), /* 2 (num) */
165 /* 51 */ KEY(103), /* 3 (num) */
166 /* 52 */ KEY(99), /* 0 (num) */
167 /* 53 */ KEY(104), /* . (num) */
168 /* 54 */ KEY(124), /* PrintScreen (with Alt) */
169 /* 55 */ INVALID,
170 /* 56 */ KEY(45), /* not labled (102-key only) */
171 /* 57 */ KEY(122), /* F11 */
172 /* 58 */ KEY(123), /* F12 */
173 /* 59 */ INVALID,
174 /* 5a */ INVALID,
175 /* 5b */ INVALID,
176 /* 5c */ INVALID,
177 /* 5d */ INVALID,
178 /* 5e */ INVALID,
179 /* 5f */ INVALID,
181 /* 60 */ INVALID,
182 /* 61 */ INVALID,
183 /* 62 */ INVALID,
184 /* 63 */ INVALID,
185 /* 64 */ INVALID,
186 /* 65 */ INVALID,
187 /* 66 */ INVALID,
188 /* 67 */ INVALID,
189 /* 68 */ INVALID,
190 /* 69 */ INVALID,
191 /* 6a */ INVALID,
192 /* 6b */ INVALID,
193 /* 6c */ INVALID,
194 /* 6d */ INVALID,
195 /* 6e */ INVALID,
196 /* 6f */ INVALID,
198 /* 70 */ KEY(133), /* Japanese 106-key keyboard */
199 /* 71 */ INVALID,
200 /* 72 */ INVALID,
201 /* 73 */ KEY(56), /* Japanese 106-key keyboard */
202 /* 74 */ INVALID,
203 /* 75 */ INVALID,
204 /* 76 */ INVALID,
205 /* 77 */ INVALID,
206 /* 78 */ INVALID,
207 /* 79 */ KEY(132), /* Japanese 106-key keyboard */
208 /* 7a */ INVALID,
209 /* 7b */ KEY(131), /* Japanese 106-key keyboard */
210 /* 7c */ INVALID,
211 /* 7d */ KEY(14), /* Japanese 106-key keyboard */
212 /* 7e */ INVALID,
213 /* 7f */ INVALID,
217 * Parse table after receiving an E0 prefix code.
219 * Generally speaking, keys that were added on the 101-key keyboard are
220 * represented as an E0 followed by the code for an 84-key key. Software
221 * ignorant of the 101-key keyboard ignores the E0 and so is handled
222 * compatibly. Many of these variants involve "fake" shift presses
223 * and releases for compatibility; these are also prefixed with E0.
224 * We ignore these fake shifts.
226 static const unsigned char keytab_e0_set1[] = {
227 /* 00 */ INVALID,
228 /* 01 */ INVALID,
229 /* 02 */ INVALID,
230 /* 03 */ INVALID,
231 /* 04 */ INVALID,
232 /* 05 */ INVALID,
233 /* 06 */ INVALID,
234 /* 07 */ INVALID,
235 /* 08 */ INVALID,
236 /* 09 */ INVALID,
237 /* 0a */ INVALID,
238 /* 0b */ INVALID,
239 /* 0c */ INVALID,
240 /* 0d */ INVALID,
241 /* 0e */ INVALID,
242 /* 0f */ INVALID,
244 /* 10 */ INVALID,
245 /* 11 */ INVALID,
246 /* 12 */ INVALID,
247 /* 13 */ INVALID,
248 /* 14 */ INVALID,
249 /* 15 */ INVALID,
250 /* 16 */ INVALID,
251 /* 17 */ INVALID,
252 /* 18 */ INVALID,
253 /* 19 */ INVALID,
254 /* 1a */ INVALID,
255 /* 1b */ INVALID,
256 /* 1c */ KEY(108), /* Enter (num) */
257 /* 1d */ KEY(64), /* R Ctrl */
258 /* 1e */ INVALID,
259 /* 1f */ INVALID,
261 /* 20 */ KEY(235), /* Mute */
262 /* 21 */ INVALID,
263 /* 22 */ INVALID,
264 /* 23 */ INVALID,
265 /* 24 */ INVALID,
266 /* 25 */ INVALID,
267 /* 26 */ INVALID,
268 /* 27 */ INVALID,
269 /* 28 */ INVALID,
270 /* 29 */ INVALID,
271 /* 2a */ INVALID,
272 /* 2b */ INVALID,
273 /* 2c */ INVALID,
274 /* 2d */ INVALID,
275 /* 2e */ KEY(234), /* Volume Down */
276 /* 2f */ INVALID,
278 /* 30 */ KEY(233), /* Volume Up */
279 /* 31 */ INVALID,
280 /* 32 */ INVALID,
281 /* 33 */ INVALID,
282 /* 34 */ INVALID,
283 /* 35 */ KEY(95), /* / (num) */
284 /* 36 */ INVALID,
285 /* 37 */ KEY(124), /* PrintScreen (no Alt) */
286 /* 38 */ KEY(62), /* R Alt */
287 /* 39 */ INVALID,
288 /* 3a */ INVALID,
289 /* 3b */ INVALID,
290 /* 3c */ INVALID,
291 /* 3d */ INVALID,
292 /* 3e */ INVALID,
293 /* 3f */ INVALID,
295 /* 40 */ INVALID,
296 /* 41 */ INVALID,
297 /* 42 */ INVALID,
298 /* 43 */ INVALID,
299 /* 44 */ INVALID,
300 /* 45 */ INVALID,
301 /* 46 */ KEY(126), /* Pause (with Cntl) */
302 /* 47 */ KEY(80), /* Home (arrow) */
303 /* 48 */ KEY(83), /* Up (arrow) */
304 /* 49 */ KEY(85), /* PgUp (arrow) */
305 /* 4a */ INVALID,
306 /* 4b */ KEY(79), /* Left (arrow) */
307 /* 4c */ INVALID,
308 /* 4d */ KEY(89), /* Right (arrow) */
309 /* 4e */ INVALID,
310 /* 4f */ KEY(81), /* End (arrow) */
312 /* 50 */ KEY(84), /* Down (arrow) */
313 /* 51 */ KEY(86), /* PgDn (arrow) */
314 /* 52 */ KEY(75), /* Insert (arrow) */
315 /* 53 */ KEY(76), /* Delete (arrow) */
316 /* 54 */ INVALID,
317 /* 55 */ INVALID,
318 /* 56 */ INVALID,
319 /* 57 */ INVALID,
320 /* 58 */ INVALID,
321 /* 59 */ INVALID,
322 /* 5a */ INVALID,
323 /* 5b */ KEY(59), /* L Window (104-key) */
324 /* 5c */ KEY(63), /* R Window (104-key) */
325 /* 5d */ KEY(65), /* Menu (104-key) */
326 /* 5e */ INVALID,
327 /* 5f */ INVALID,
329 /* 60 */ INVALID,
330 /* 61 */ INVALID,
331 /* 62 */ INVALID,
332 /* 63 */ INVALID,
333 /* 64 */ INVALID,
334 /* 65 */ INVALID,
335 /* 66 */ INVALID,
336 /* 67 */ INVALID,
337 /* 68 */ INVALID,
338 /* 69 */ INVALID,
339 /* 6a */ INVALID,
340 /* 6b */ INVALID,
341 /* 6c */ INVALID,
342 /* 6d */ INVALID,
343 /* 6e */ INVALID,
344 /* 6f */ INVALID,
346 /* 70 */ INVALID,
347 /* 71 */ INVALID,
348 /* 72 */ INVALID,
349 /* 73 */ INVALID,
350 /* 74 */ INVALID,
351 /* 75 */ INVALID,
352 /* 76 */ INVALID,
353 /* 77 */ INVALID,
354 /* 78 */ INVALID,
355 /* 79 */ INVALID,
356 /* 7a */ INVALID,
357 /* 7b */ INVALID,
358 /* 7c */ INVALID,
359 /* 7d */ INVALID,
360 /* 7e */ INVALID,
365 * Parse table for the base keyboard state. The index is the start of
366 * a new sequence.
368 * Questionable or unusual cases:
369 * 02 On some SPARC keyboards, this is the scan code for the STOP
370 * key. The KEY() value was chosen so that it maps to a
371 * HOLE entry in the keytables in kb8042_keytables.c; therefore,
372 * the STOP key code is only translated properly when kb8042
373 * is "emulating" a USB keyboard (which it is by default--
374 * see conskbd.c).
375 * 7f Old kd code says this is an 84-key SysReq. Manual says no.
376 * 87 Old kd code says 1 (num). Manual says no.
377 * 8c Old kd code says / (num). Manual says no.
378 * aa POST OK. Handled by code.
379 * e0 Extend prefix. Handled by code. (switches to E0 table)
380 * e1 Extend prefix. Handled by code. (Pause key only)
381 * f0 Break prefix. Handled by code.
382 * f1 Korean Hangul/Hanja key. Handled by code.
383 * f2 Korean Hangul key. Handled by code.
384 * ff Keyboard internal buffer overrun. Handled by code.
386 * Other values past the end of the table are treated as INVALID.
389 static const unsigned char keytab_base_set2[] = {
390 /* scan state keycap */
391 /* 00 */ INVALID,
392 /* 01 */ KEY(120), /* F9 */
393 /* 02 */ INVALID, /* F7? Old code says so but manual doesn't */
394 /* 03 */ KEY(116), /* F5 */
395 /* 04 */ KEY(114), /* F3 */
396 /* 05 */ KEY(112), /* F1 */
397 /* 06 */ KEY(113), /* F2 */
398 /* 07 */ KEY(123), /* F12 */
399 /* 08 */ INVALID,
400 /* 09 */ KEY(121), /* F10 */
401 /* 0a */ KEY(119), /* F8 */
402 /* 0b */ KEY(117), /* F6 */
403 /* 0c */ KEY(115), /* F4 */
404 /* 0d */ KEY(16), /* tab */
405 /* 0e */ KEY(1), /* ` */
406 /* 0f */ INVALID,
407 /* 10 */ INVALID,
408 /* 11 */ KEY(60), /* L Alt */
409 /* 12 */ KEY(44), /* L Shift */
410 /* 13 */ KEY(133), /* Japanese 106-key */
411 /* 14 */ KEY(58), /* L Ctrl */
412 /* 15 */ KEY(17), /* Q */
413 /* 16 */ KEY(2), /* 1 */
414 /* 17 */ INVALID,
415 /* 18 */ INVALID,
416 /* 19 */ INVALID,
417 /* 1a */ KEY(46), /* Z */
418 /* 1b */ KEY(32), /* S */
419 /* 1c */ KEY(31), /* A */
420 /* 1d */ KEY(18), /* W */
421 /* 1e */ KEY(3), /* 2 */
422 /* 1f */ INVALID,
423 /* 20 */ INVALID,
424 /* 21 */ KEY(48), /* C */
425 /* 22 */ KEY(47), /* X */
426 /* 23 */ KEY(33), /* D */
427 /* 24 */ KEY(19), /* E */
428 /* 25 */ KEY(5), /* 4 */
429 /* 26 */ KEY(4), /* 3 */
430 /* 27 */ INVALID,
431 /* 28 */ INVALID,
432 /* 29 */ KEY(61), /* Space */
433 /* 2a */ KEY(49), /* V */
434 /* 2b */ KEY(34), /* F */
435 /* 2c */ KEY(21), /* T */
436 /* 2d */ KEY(20), /* R */
437 /* 2e */ KEY(6), /* 5 */
438 /* 2f */ INVALID,
439 /* 30 */ INVALID,
440 /* 31 */ KEY(51), /* N */
441 /* 32 */ KEY(50), /* B */
442 /* 33 */ KEY(36), /* H */
443 /* 34 */ KEY(35), /* G */
444 /* 35 */ KEY(22), /* Y */
445 /* 36 */ KEY(7), /* 6 */
446 /* 37 */ INVALID,
447 /* 38 */ INVALID,
448 /* 39 */ INVALID,
449 /* 3a */ KEY(52), /* M */
450 /* 3b */ KEY(37), /* J */
451 /* 3c */ KEY(23), /* U */
452 /* 3d */ KEY(8), /* 7 */
453 /* 3e */ KEY(9), /* 8 */
454 /* 3f */ INVALID,
455 /* 40 */ INVALID,
456 /* 41 */ KEY(53), /* , */
457 /* 42 */ KEY(38), /* K */
458 /* 43 */ KEY(24), /* I */
459 /* 44 */ KEY(25), /* O */
460 /* 45 */ KEY(11), /* 0 */
461 /* 46 */ KEY(10), /* 9 */
462 /* 47 */ INVALID,
463 /* 48 */ INVALID,
464 /* 49 */ KEY(54), /* . */
465 /* 4a */ KEY(55), /* / */
466 /* 4b */ KEY(39), /* L */
467 /* 4c */ KEY(40), /* ; */
468 /* 4d */ KEY(26), /* P */
469 /* 4e */ KEY(12), /* - */
470 /* 4f */ INVALID,
471 /* 50 */ INVALID,
472 /* 51 */ KEY(56), /* Japanese 106-key */
473 /* 52 */ KEY(41), /* ' */
474 /* 53 */ INVALID,
475 /* 54 */ KEY(27), /* [ */
476 /* 55 */ KEY(13), /* = */
477 /* 56 */ INVALID,
478 /* 57 */ INVALID,
479 /* 58 */ KEY(30), /* CapsLock */
480 /* 59 */ KEY(57), /* R Shift */
481 /* 5a */ KEY(43), /* Enter (main) */
482 /* 5b */ KEY(28), /* ] */
483 /* 5c */ INVALID,
484 /* 5d */ KEY(29), /* \, key 42 for 102-key */
485 /* 5e */ INVALID,
486 /* 5f */ INVALID,
487 /* 60 */ INVALID,
488 /* 61 */ KEY(45), /* 102-key only, typically </> */
489 /* 62 */ INVALID,
490 /* 63 */ INVALID,
491 /* 64 */ KEY(132), /* Japanese 106-key */
492 /* 65 */ INVALID,
493 /* 66 */ KEY(15), /* backspace */
494 /* 67 */ KEY(131), /* Japanese 106-key */
495 /* 68 */ INVALID,
496 /* 69 */ KEY(93), /* 1 (num) */
497 /* 6a */ KEY(14), /* Japanese 106-key */
498 /* 6b */ KEY(92), /* 4 (num) */
499 /* 6c */ KEY(91), /* 7 (num) */
500 /* 6d */ INVALID,
501 /* 6e */ INVALID,
502 /* 6f */ INVALID,
503 /* 70 */ KEY(99), /* 0 (num) */
504 /* 71 */ KEY(104), /* . (num) */
505 /* 72 */ KEY(98), /* 2 (num) */
506 /* 73 */ KEY(97), /* 5 (num) */
507 /* 74 */ KEY(102), /* 6 (num) */
508 /* 75 */ KEY(96), /* 8 (num) */
509 /* 76 */ KEY(110), /* Esc */
510 /* 77 */ KEY(90), /* NumLock */
511 /* 78 */ KEY(122), /* F11 */
512 /* 79 */ KEY(106), /* + (num) */
513 /* 7a */ KEY(103), /* 3 (num) */
514 /* 7b */ KEY(105), /* - (num) */
515 /* 7c */ KEY(100), /* * (num) */
516 /* 7d */ KEY(101), /* 9 (num) */
517 /* 7e */ KEY(125), /* Scroll Lock */
518 /* 7f */ INVALID, /* 84-key SysReq? Manual says no. */
519 /* 80 */ INVALID,
520 /* 81 */ INVALID,
521 /* 82 */ INVALID,
522 /* 83 */ KEY(118), /* F7 */
523 /* 84 */ KEY(124), /* PrintScreen (w/ Alt = SysRq) */
527 * Parse table after receiving an E0 prefix code.
529 * Generally speaking, keys that were added on the 101-key keyboard are
530 * represented as an E0 followed by the code for an 84-key key. Software
531 * ignorant of the 101-key keyboard ignores the E0 and so is handled
532 * compatibly. Many of these variants involve "fake" shift presses
533 * and releases for compatibility; these are also prefixed with E0.
534 * We ignore these fake shifts.
536 static const unsigned char keytab_e0_set2[] = {
537 /* 00 */ INVALID,
538 /* 01 */ INVALID,
539 /* 02 */ INVALID,
540 /* 03 */ INVALID,
541 /* 04 */ INVALID,
542 /* 05 */ INVALID,
543 /* 06 */ INVALID,
544 /* 07 */ INVALID,
545 /* 08 */ INVALID,
546 /* 09 */ INVALID,
547 /* 0a */ INVALID,
548 /* 0b */ INVALID,
549 /* 0c */ INVALID,
550 /* 0d */ INVALID,
551 /* 0e */ INVALID,
552 /* 0f */ INVALID,
553 /* 10 */ INVALID,
554 /* 11 */ KEY(62), /* R Alt */
555 /* 12 */ IGNORE, /* Fake L Shift */
556 /* 13 */ INVALID,
557 /* 14 */ KEY(64), /* R Ctrl */
558 /* 15 */ INVALID,
559 /* 16 */ INVALID,
560 /* 17 */ INVALID,
561 /* 18 */ INVALID,
562 /* 19 */ INVALID,
563 /* 1a */ INVALID,
564 /* 1b */ INVALID,
565 /* 1c */ INVALID,
566 /* 1d */ INVALID,
567 /* 1e */ INVALID,
568 /* 1f */ KEY(59), /* L Window (104-key) */
569 /* 20 */ INVALID,
570 /* 21 */ INVALID,
571 /* 22 */ INVALID,
572 /* 23 */ INVALID,
573 /* 24 */ INVALID,
574 /* 25 */ INVALID,
575 /* 26 */ INVALID,
576 /* 27 */ KEY(63), /* R Window (104-key) */
577 /* 28 */ INVALID,
578 /* 29 */ INVALID,
579 /* 2a */ INVALID,
580 /* 2b */ INVALID,
581 /* 2c */ INVALID,
582 /* 2d */ INVALID,
583 /* 2e */ INVALID,
584 /* 2f */ KEY(65), /* Menu (104-key) */
585 /* 30 */ INVALID,
586 /* 31 */ INVALID,
587 /* 32 */ INVALID,
588 /* 33 */ INVALID,
589 /* 34 */ INVALID,
590 /* 35 */ INVALID,
591 /* 36 */ INVALID,
592 /* 37 */ INVALID,
593 /* 38 */ INVALID,
594 /* 39 */ INVALID,
595 /* 3a */ INVALID,
596 /* 3b */ INVALID,
597 /* 3c */ INVALID,
598 /* 3d */ INVALID,
599 /* 3e */ INVALID,
600 /* 3f */ INVALID,
601 /* 40 */ INVALID,
602 /* 41 */ INVALID,
603 /* 42 */ INVALID,
604 /* 43 */ INVALID,
605 /* 44 */ INVALID,
606 /* 45 */ INVALID,
607 /* 46 */ INVALID,
608 /* 47 */ INVALID,
609 /* 48 */ INVALID,
610 /* 49 */ INVALID,
611 /* 4a */ KEY(95), /* / (num) */
612 /* 4b */ INVALID,
613 /* 4c */ INVALID,
614 /* 4d */ INVALID,
615 /* 4e */ INVALID,
616 /* 4f */ INVALID,
617 /* 50 */ INVALID,
618 /* 51 */ INVALID,
619 /* 52 */ INVALID,
620 /* 53 */ INVALID,
621 /* 54 */ INVALID,
622 /* 55 */ INVALID,
623 /* 56 */ INVALID,
624 /* 57 */ INVALID,
625 /* 58 */ INVALID,
626 /* 59 */ IGNORE, /* Fake R Shift */
627 /* 5a */ KEY(108), /* Enter (num) */
628 /* 5b */ INVALID,
629 /* 5c */ INVALID,
630 /* 5d */ INVALID,
631 /* 5e */ INVALID,
632 /* 5f */ INVALID,
633 /* 60 */ INVALID,
634 /* 61 */ INVALID,
635 /* 62 */ INVALID,
636 /* 63 */ INVALID,
637 /* 64 */ INVALID,
638 /* 65 */ INVALID,
639 /* 66 */ INVALID,
640 /* 67 */ INVALID,
641 /* 68 */ INVALID,
642 /* 69 */ KEY(81), /* End (arrow) */
643 /* 6a */ INVALID,
644 /* 6b */ KEY(79), /* Left (arrow) */
645 /* 6c */ KEY(80), /* Home (arrow) */
646 /* 6d */ INVALID,
647 /* 6e */ INVALID,
648 /* 6f */ INVALID,
649 /* 70 */ KEY(75), /* Insert (arrow) */
650 /* 71 */ KEY(76), /* Delete (arrow) */
651 /* 72 */ KEY(84), /* Down (arrow) */
652 /* 73 */ INVALID,
653 /* 74 */ KEY(89), /* Right (arrow) */
654 /* 75 */ KEY(83), /* Up (arrow) */
655 /* 76 */ INVALID,
656 /* 77 */ INVALID,
657 /* 78 */ INVALID,
658 /* 79 */ INVALID,
659 /* 7a */ KEY(86), /* PgDn (arrow) */
660 /* 7b */ INVALID,
661 /* 7c */ KEY(124), /* PrintScreen (no Alt) */
662 /* 7d */ KEY(85), /* PgUp (arrow) */
663 /* 7e */ KEY(126), /* Pause (w/Ctrl = Break) */
668 * Initialize the translation state machine.
671 KeyboardConvertScan_init(struct kb8042 *kb8042, int scanset)
673 kb8042->parse_scan_state = STATE_IDLE;
674 kb8042->break_received = 0;
676 if (scanset == 1) {
677 KeyboardConvertScan_fn = &KeyboardConvertScan_set1;
678 keytab_base = keytab_base_set1;
679 keytab_base_length = NELEM(keytab_base_set1);
680 keytab_e0 = keytab_e0_set1;
681 keytab_e0_length = NELEM(keytab_e0_set1);
682 } else if (scanset == 2) {
683 KeyboardConvertScan_fn = &KeyboardConvertScan_set2;
684 keytab_base = keytab_base_set2;
685 keytab_base_length = NELEM(keytab_base_set2);
686 keytab_e0 = keytab_e0_set2;
687 keytab_e0_length = NELEM(keytab_e0_set2);
688 } else {
689 return (DDI_FAILURE);
692 return (DDI_SUCCESS);
696 * KeyboardConvertScan(*kb8042, scan, *keynum, *state
697 * *synthetic_release_needed)
699 * State machine that takes scan codes from the keyboard and resolves
700 * them to key numbers using the above tables. Returns B_TRUE if this
701 * scan code completes a scan code sequence, in which case "keynum",
702 * "state", and "synthetic_release_needed" will be filled in correctly.
704 * "synthetic_release_needed" is a hack to handle the additional two
705 * keys on a Korean keyboard. They report press only, so we tell the
706 * upper layer to synthesize the release.
708 boolean_t
709 KeyboardConvertScan(
710 struct kb8042 *kb8042,
711 unsigned char scan,
712 int *keynum,
713 enum keystate *state,
714 boolean_t *synthetic_release_needed)
716 ASSERT(KeyboardConvertScan_fn != NULL);
718 return ((*KeyboardConvertScan_fn)(kb8042, scan, keynum, state,
719 synthetic_release_needed));
722 boolean_t
723 KeyboardConvertScan_set1(
724 struct kb8042 *kb8042,
725 unsigned char scan,
726 int *keynum,
727 enum keystate *state,
728 boolean_t *synthetic_release_needed)
730 *synthetic_release_needed = B_FALSE;
731 *state = KEY_PRESSED;
733 switch (scan) {
735 * First, handle special cases.
736 * ACK has already been handled by our caller.
738 case KB_ERROR:
740 * Perhaps we should reset state here,
741 * since we no longer know what's going on.
743 return (B_FALSE);
744 case KB_POST_FAIL:
746 * Perhaps we should reset the LEDs now.
747 * If so, this check should probably be in the main line.
748 * Perhaps we should tell the higher layers that the
749 * keyboard has been reset.
752 * Reset to idle
754 kb8042->parse_scan_state = STATE_IDLE;
755 return (B_FALSE);
757 case KXT_EXTEND:
758 case KXT_EXTEND2:
759 case KXT_HANGUL_HANJA:
760 case KXT_HANGUL:
762 * Exclude these keys from the "default" test below.
764 break;
766 default:
768 * See if it was a key release.
770 if (scan > 0x80) {
771 *state = KEY_RELEASED;
772 scan -= 0x80;
774 break;
777 if (kb8042->break_received) {
778 *state = KEY_RELEASED;
779 kb8042->break_received = 0;
782 switch (kb8042->parse_scan_state) {
783 case STATE_IDLE:
784 switch (scan) {
785 case KXT_EXTEND:
786 kb8042->parse_scan_state = STATE_E0;
787 return (B_FALSE);
789 case KXT_EXTEND2:
790 kb8042->parse_scan_state = STATE_E1;
791 return (B_FALSE);
794 * We could do the next two in the table, but it would
795 * require nearly doubling the size of the table.
797 * Also, for some stupid reason these two report presses
798 * only. We tell the upper layer to synthesize a release.
800 case KXT_HANGUL_HANJA:
801 *keynum = KEY(150);
802 *synthetic_release_needed = B_TRUE;
803 break;
805 case KXT_HANGUL:
806 *keynum = KEY(151);
807 *synthetic_release_needed = B_TRUE;
808 break;
810 default:
812 * Regular scan code
814 if (scan < keytab_base_length)
815 *keynum = keytab_base[scan];
816 else
817 *keynum = INVALID;
818 break;
820 break;
822 case STATE_E0: /* Mostly 101-key additions */
823 if (scan < keytab_e0_length)
824 *keynum = keytab_e0[scan];
825 else
826 *keynum = INVALID;
827 break;
829 case STATE_E1: /* Pause key only */
830 switch (scan) {
831 case 0x1d:
832 kb8042->parse_scan_state = STATE_E1_1D;
833 return (B_FALSE);
834 default:
835 *keynum = INVALID;
836 break;
838 break;
840 case STATE_E1_1D: /* Pause key only */
841 switch (scan) {
842 case 0x45:
843 *keynum = KEY(126); /* Pause */
844 break;
845 default:
846 *keynum = INVALID;
847 break;
849 break;
853 * The results (*keynum, *state, and *synthetic_release_needed)
854 * have been filled in, but they are valid only if we return
855 * B_TRUE which is only done below. If we make it to here, we
856 * have completed a scan code sequence, so reset parse_scan_state.
859 kb8042->parse_scan_state = STATE_IDLE;
861 switch (*keynum) {
862 case KEYIGN: /* not a key, nor an error */
863 return (B_FALSE); /* also not a final keycode */
865 case KEYBAD: /* not part of a legit sequence? */
866 return (B_FALSE); /* and return not a final keycode */
868 default:
870 * If we're here, it's a valid keycode. We've already
871 * filled in the return values; return success.
873 return (B_TRUE); /* resolved to a key */
878 * KeyboardConvertScan(*kb8042, scan, *keynum, *state
879 * *synthetic_release_needed)
881 * State machine that takes scan codes from the keyboard and resolves
882 * them to key numbers using the above tables. Returns B_TRUE if this
883 * scan code completes a scan code sequence, in which case "keynum",
884 * "state", and "synthetic_release_needed" will be filled in correctly.
886 * "synthetic_release_needed" is a hack to handle the additional two
887 * keys on a Korean keyboard. They report press only, so we tell the
888 * upper layer to synthesize the release.
890 boolean_t
891 KeyboardConvertScan_set2(
892 struct kb8042 *kb8042,
893 unsigned char scan,
894 int *keynum,
895 enum keystate *state,
896 boolean_t *synthetic_release_needed)
898 *synthetic_release_needed = B_FALSE;
899 *state = KEY_PRESSED;
901 switch (scan) {
903 * First, handle special cases.
904 * ACK has already been handled by our caller.
908 * KAT_BREAK is 0xF0. It is the same as the break code for Japanese
909 * key 133.
910 * Therefore we don't treat it specially here.
912 case KAT_BREAK:
913 /* Switch states so we can recognize the code that follows */
914 kb8042->break_received = 1;
915 return (B_FALSE); /* not a final keycode */
917 case KB_ERROR:
919 * Perhaps we should reset state here,
920 * since we no longer know what's going on.
922 return (B_FALSE);
924 case KB_POST_OK:
925 case KB_POST_FAIL:
927 * Perhaps we should reset the LEDs now.
928 * If so, this check should probably be in the main line.
929 * Perhaps we should tell the higher layers that the
930 * keyboard has been reset.
933 * Reset to idle
935 kb8042->parse_scan_state = STATE_IDLE;
936 return (B_FALSE);
939 if (kb8042->break_received) {
940 *state = KEY_RELEASED;
941 kb8042->break_received = 0;
944 switch (kb8042->parse_scan_state) {
945 case STATE_IDLE:
946 switch (scan) {
947 case KXT_EXTEND:
948 kb8042->parse_scan_state = STATE_E0;
949 return (B_FALSE);
951 case KXT_EXTEND2:
952 kb8042->parse_scan_state = STATE_E1;
953 return (B_FALSE);
956 * We could do the next two in the table, but it would
957 * require nearly doubling the size of the table.
959 * Also, for some stupid reason these two report presses
960 * only. We tell the upper layer to synthesize a release.
962 case KXT_HANGUL_HANJA:
963 *keynum = KEY(150);
964 *synthetic_release_needed = B_TRUE;
965 break;
967 case KXT_HANGUL:
968 *keynum = KEY(151);
969 *synthetic_release_needed = B_TRUE;
970 break;
972 default:
974 * Regular scan code
976 if (scan < keytab_base_length)
977 *keynum = keytab_base[scan];
978 else
979 *keynum = INVALID;
980 break;
982 break;
984 case STATE_E0: /* Mostly 101-key additions */
985 if (scan < keytab_e0_length)
986 *keynum = keytab_e0[scan];
987 else
988 *keynum = INVALID;
989 break;
991 case STATE_E1: /* Pause key only */
992 switch (scan) {
993 case 0x14:
994 kb8042->parse_scan_state = STATE_E1_14;
995 return (B_FALSE);
996 default:
997 *keynum = INVALID;
998 break;
1000 break;
1002 case STATE_E1_14: /* Pause key only */
1003 if (scan == 0x77) {
1004 kb8042->parse_scan_state = STATE_E1_14_77;
1005 return (B_FALSE);
1006 } else {
1007 *keynum = INVALID;
1009 break;
1011 case STATE_E1_14_77:
1012 if (scan == 0xE1) {
1013 kb8042->parse_scan_state = STATE_E1_14_77_E1;
1014 return (B_FALSE);
1015 } else {
1016 *keynum = INVALID;
1018 break;
1020 case STATE_E1_14_77_E1:
1021 if (scan == 0xF0) {
1022 kb8042->parse_scan_state = STATE_E1_14_77_E1_F0;
1023 return (B_FALSE);
1024 } else {
1025 *keynum = INVALID;
1027 break;
1029 case STATE_E1_14_77_E1_F0:
1030 if (scan == 0x14) {
1031 kb8042->parse_scan_state = STATE_E1_14_77_E1_F0_14;
1032 return (B_FALSE);
1033 } else {
1034 *keynum = INVALID;
1036 break;
1038 case STATE_E1_14_77_E1_F0_14:
1039 if (scan == 0xF0) {
1040 kb8042->parse_scan_state = STATE_E1_14_77_E1_F0_14_F0;
1041 return (B_FALSE);
1042 } else {
1043 *keynum = INVALID;
1045 break;
1047 case STATE_E1_14_77_E1_F0_14_F0:
1048 if (scan == 0x77) {
1049 *keynum = KEY(126); /* Pause */
1050 } else {
1051 *keynum = INVALID;
1053 break;
1057 * The results (*keynum, *state, and *synthetic_release_needed)
1058 * have been filled in, but they are valid only if we return
1059 * B_TRUE which is only done below. If we make it to here, we
1060 * have completed a scan code sequence, so reset parse_scan_state.
1063 if (kb8042->break_received) {
1064 *state = KEY_RELEASED;
1065 kb8042->break_received = 0;
1068 kb8042->parse_scan_state = STATE_IDLE;
1070 switch (*keynum) {
1071 case KEYIGN: /* not a key, nor an error */
1072 return (B_FALSE); /* also not a final keycode */
1074 case KEYBAD: /* not part of a legit sequence? */
1075 return (B_FALSE); /* and return not a final keycode */
1077 default:
1079 * If we're here, it's a valid keycode. We've already
1080 * filled in the return values; return success.
1082 return (B_TRUE); /* resolved to a key */