xref: /titanic_51/usr/src/uts/common/sys/kbd.h (revision 20c794b39650d115e17a15983b6b82e46238cf45)
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 #ifndef _SYS_KBD_H
27 #define	_SYS_KBD_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS4.0 1.18 */
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Following #defines are related to the older keyboards which
37  * are no longer supported by kb module.  The #defines ane left
38  * for older programs to still compile.
39  */
40 #define	KB_KLUNK	0x00		/* Micro Switch 103SD32-2 */
41 #define	KB_VT100	0x01		/* Keytronics VT100 compatible */
42 #define	KB_SUN2		0x02		/* Sun-2 custom keyboard */
43 #define	KB_VT220	0x81		/* Emulation VT220 */
44 #define	KB_VT220I	0x82		/* International VT220 Emulation */
45 
46 #define	NOTPRESENT	0xFF		/* Keyboard is not plugged in */
47 #define	KBD_CMD_LED1	0x04		/* Turn on LED 1 for Sun-2 */
48 #define	KBD_CMD_NOLED1	0x05		/* Turn off LED 1 for Sun-2 */
49 #define	KBD_CMD_LED2	0x06		/* Turn on LED 2 for Sun-2 */
50 #define	KBD_CMD_NOLED2	0x07		/* Turn off LED 2 for Sun-2 */
51 
52 #define	CTLSMASK	0x0100		/* Set if ^S was last keyed of ^S, ^Q */
53 					/* determines which NOSCROLL sends. */
54 
55 #define	NOSCROLL	0x303	/* This key alternately sends ^S or ^Q */
56 #define	CTRLS		0x304	/* This sends ^S and lets NOSCROLL know */
57 #define	CTRLQ		0x305	/* This sends ^Q and lets NOSCROLL know */
58 
59 
60 /*
61  * Following are the only keyboard types supported by kb module.
62  * (Type 5, Hobo, US101A are also supported but they report
63  * themselves as Type 4 keyboard with a different layout id.)
64  */
65 #define	KB_SUN3		3		/* Type 3 Sun keyboard */
66 #define	KB_SUN4		4		/* Type 4 Sun keyboard */
67 #define	KB_USB		6		/* USB keyboard */
68 #define	KB_PC		101		/* Type 101 AT keyboard */
69 
70 #define	KB_ASCII	0x0F		/* Ascii terminal masquerading as kbd */
71 
72 /*
73  * This structure is used to enumerate the supported keyboard types.
74  * The array of these is terminated by an entry with a NULL table entry.
75  * The first entry is used if none match.
76  */
77 struct keyboards {
78 	int		id;	/* Keyboard type, per KIOCTYPE */
79 	struct keyboard	*table;	/* Keyboard table to use. */
80 };
81 
82 /*
83  * Various special characters that might show up on the port
84  */
85 #define	IDLEKEY		0x7F		/* Keyboard is idle; no keys down */
86 #define	ERRORKEY	0x7E		/* Keyboard detected an error */
87 #define	RESETKEY	0xFF		/* Keyboard was just reset */
88 #define	LAYOUTKEY	0xFE		/* Keyboard layout byte follows */
89 
90 #define	PRESSED		0x00		/* 0x80 bit off: key was pressed */
91 #define	RELEASED	0x80		/* 0x80 bit on : key was released */
92 
93 /*
94  * Commands to the Sun-3 keyboard.
95  */
96 #define	KBD_CMD_RESET		0x01	/* Reset keyboard as if power-up */
97 #define	KBD_CMD_BELL		0x02	/* Turn on the bell */
98 #define	KBD_CMD_NOBELL		0x03	/* Turn off the bell */
99 #define	KBD_CMD_CLICK		0x0A	/* Turn on the click annunciator */
100 #define	KBD_CMD_NOCLICK		0x0B	/* Turn off the click annunciator */
101 
102 /*
103  * Commands to the Type 4 keyboard, in addition to those above.
104  */
105 #define	KBD_CMD_AUTOTEST	0x0C	/* Initiate test sequence */
106 #define	KBD_CMD_SETLED		0x0E	/* Set keyboard LED's */
107 #define	KBD_CMD_GETLAYOUT	0x0F	/* Request that keyboard indicate */
108 					/* layout */
109 /*
110  * Type 4 keyboard LED masks (used to set LED's)
111  */
112 #define	LED_NUM_LOCK	0x1
113 #define	LED_COMPOSE	0x2
114 #define	LED_SCROLL_LOCK 0x4
115 #define	LED_CAPS_LOCK	0x8
116 #define	LED_KANA	0x10		/* Valid only on Japanese layout */
117 
118 /*
119  * Software related definitions
120  */
121 /*
122  * These are the states that the keyboard scanner can be in.
123  *
124  * It starts out in NORMAL state.
125  */
126 #define	NORMAL		0		/* The usual (ho, hum) */
127 #define	ABORT1		1		/* Got KEYABORT1 */
128 #define	COMPOSE1	2		/* Got COMPOSE */
129 #define	COMPOSE2	3		/* Got COMPOSE plus first key */
130 #define	FLTACCENT	4		/* Got floating accent key */
131 #define	NEWABORT1	5		/* Got NEW KEYABORT1 */
132 
133 /*
134  * Size of ASCII set as used in compose handling.
135  */
136 #define	ASCII_SET_SIZE	128
137 
138 /*
139  * These are how you can have your input translated.
140  * TR_EVENT means that each keystroke is sent as a firm event.
141  * TR_UNTRANS_EVENT also sends a firm event for each up / down transition,
142  * but the value is untranslated: the event id is the key station; the
143  * value indicates whether the transition was up or down; the value of the
144  * shift-mask is undefined.
145  */
146 #define	TR_NONE		  0
147 #define	TR_ASCII	  1
148 #define	TR_EVENT	  2
149 #define	TR_UNTRANS_EVENT  3
150 
151 /*
152  * These bits can appear in the result of TR_NONE & TR_UNTRANS_EVENT getkey()s.
153  */
154 #define	BUILDKEY(key, state)	(key | state)
155 #define	STATEOF(key)	((key) & RELEASED)	/* 0 = key down, !=0 = key up */
156 #define	KEYOF(key)	((key) & ~RELEASED)	/* The key number that moved */
157 #define	NOKEY		(-1)		/* The argument was 0, and no key was */
158 					/* depressed.  They were all elated. */
159 
160 /*
161  * "Bucky" bits.  These are bits for mode keys.	 The META bit is ORed into the
162  * result of TR_ASCII getkey()s, and can be ORed into the result of TR_EVENT
163  * getkey()s for backwards compatibility.
164  * (NOKEY can also appear if no keypress was queued up.)
165  */
166 #define	METABIT		0		/* Meta key depressed with key */
167 #define	METAMASK	0x000080
168 #define	SYSTEMBIT	1		/* Upper left key was down w/key */
169 #define	SYSTEMMASK	0x000100
170 /* other "bucky" bits can be defined at will.  See "BUCKYBITS" below. */
171 
172 /*
173  * This defines the bit positions used within "shiftmask" to
174  * indicate the "pressed" (1) or "released" (0) state of shift keys.
175  * Both the bit numbers, and the aggregate masks, are defined.
176  *
177  * The "UPMASK" is a minor kludge.  Since whether the key is going
178  * up or down determines the translation table (just as the shift
179  * keys' positions do), we OR it with "shiftmask" to get "tempmask",
180  * which is the mask which is actually used to determine the
181  * translation table to use.  Don't reassign 0x0080 for anything
182  * else, or we'll have to shift and such to squeeze in UPMASK,
183  * since it comes in from the hardware as 0x80.
184  */
185 #define	CAPSLOCK	0		/* Caps Lock key */
186 #define	CAPSMASK	0x0001
187 #define	SHIFTLOCK	1		/* Shift Lock key */
188 #define	LEFTSHIFT	2		/* Left-hand shift key */
189 #define	RIGHTSHIFT	3		/* Right-hand shift key */
190 #define	SHIFTMASK	0x000E
191 #define	LEFTCTRL	4		/* Left-hand (or only) control key */
192 #define	RIGHTCTRL	5		/* Right-hand control key */
193 #define	CTRLMASK	0x0030
194 /*	META		6		Meta keys */
195 /*	META_SHIFT_MASK 0x0040		reserved */
196 /*	TOP		7		do not use! */
197 /*	TOPMASK		0x0080		UPMASK in keyboard driver */
198 /*	CMD		8		reserved */
199 /*	CMDMASK		0x0100		reserved */
200 #define	ALTGRAPH	9		/* Alt Graph key */
201 #define	ALTGRAPHMASK	0x0200
202 #define	ALT		10		/* Left (or only) Alt key */
203 #define	LEFTALT		10		/* Left Alt key */
204 #define	ALTMASK		0x1400
205 #define	NUMLOCK		11		/* Num Lock key */
206 #define	NUMLOCKMASK	0x0800
207 #define	RIGHTALT	12		/* Right Alt key */
208 #define	UPMASK		0x0080
209 
210 /*
211  * This defines the format of translation tables.
212  *
213  * A translation table is KEYMAP_SIZE "entries", each of which is 2 bytes
214  * (unsigned shorts).  The top 8 bits of each entry are decoded by
215  * a case statement in getkey.c.  If the entry is less than 0x100, it
216  * is sent out as an EUC character (possibly with bucky bits
217  * OR-ed in).  "Special" entries are 0x100 or greater, and
218  * invoke more complicated actions.
219  *
220  * The KEYMAP_SIZE is dependent upon the keyboard type.  For example, the
221  * Sun Type 4/5 keyboards have a KEYMAP_SIZE of 128 where a USB keyboard
222  * has a KEYMAP_SIZE of 255.  Instead of defining a KEYMAP_SIZE per
223  * keyboard type, a keyboard specific module/driver may supply the value
224  * at run time by defining the KEYMAP_SIZE_VARIABLE and filling in the
225  * keyboard struct appropriately.
226  */
227 
228 #ifdef KEYMAP_SIZE_VARIABLE
229 
230 typedef unsigned short keymap_entry_t;
231 
232 #else
233 #define	KEYMAP_SIZE	128
234 
235 struct keymap {
236 	unsigned short	keymap[KEYMAP_SIZE];	/* maps keycodes to actions */
237 };
238 
239 #endif
240 
241 /*
242  * This structure is used for "exception" cases for key sequences that
243  * we want to map, that should not be handled by keymap entries (For
244  * example: using Control-Shift-F1 on PC's for the compose key).
245  */
246 struct exception_map {
247 	/*
248 	 * these are the modifier keys that we "care" about
249 	 */
250 	unsigned int exc_care;
251 
252 	/*
253 	 * This is the mask of modifier keys that we want to match
254 	 */
255 	unsigned int exc_mask;
256 
257 	/*
258 	 * This is the key that we want to match.
259 	 */
260 	int exc_key;
261 
262 	/*
263 	 * This is our translated version of the matching sequence.
264 	 */
265 	unsigned short exc_entry;
266 };
267 
268 /*
269  * A keyboard is defined by its keymaps and what state it resets at idle.
270  *
271  * The masks k_idleshifts and k_idlebuckys are AND-ed with the current
272  * state of  shiftmask	and  buckybits	when a "keyboard idle" code
273  * is received.	 This ensures that where we "think" the shift & bucky
274  * keys are, more accurately reflects where they really are, since the
275  * keyboard knows better than us.  However, some keyboards don't know
276  * about shift states that should be remembered across idles.  Such
277  * shifts are described by k_toggleshifts.  k_toggleshifts are used to
278  * identify such shifts.  A toggle shift state is maintained separately
279  * from the general shift state.  The toggle shift state is OR-ed
280  * with the state general shift state when an idle is received.
281  * k_toggleshifts should not appear in the k_up table.
282  */
283 struct keyboard {
284 #ifdef KEYMAP_SIZE_VARIABLE
285 	int		k_keymap_size;	/* Number of entries in keymaps */
286 	keymap_entry_t	*k_normal;	/* Unshifted */
287 	keymap_entry_t	*k_shifted;	/* Shifted */
288 	keymap_entry_t	*k_caps;	/* Caps locked */
289 	keymap_entry_t	*k_altgraph;	/* Alt Graph down */
290 	keymap_entry_t	*k_numlock;	/* Num Lock down */
291 	keymap_entry_t	*k_control;	/* Controlled */
292 	keymap_entry_t	*k_up;		/* Key went up */
293 #else
294 	struct keymap	*k_normal;	/* Unshifted */
295 	struct keymap	*k_shifted;	/* Shifted */
296 	struct keymap	*k_caps;	/* Caps locked */
297 	struct keymap	*k_altgraph;	/* Alt Graph down */
298 	struct keymap	*k_numlock;	/* Num Lock down */
299 	struct keymap	*k_control;	/* Controlled */
300 	struct keymap	*k_up;		/* Key went up */
301 #endif
302 	int		k_idleshifts;	/* Shifts that keep across idle */
303 	int		k_idlebuckys;	/* Bucky bits that keep across idle */
304 	unsigned char	k_abort1;	/* 1st key of abort sequence */
305 	unsigned char	k_abort1a;	/* alternate 1st key */
306 	unsigned char	k_abort2;	/* 2nd key of abort sequence */
307 	int		k_toggleshifts; /* Shifts that toggle on down from */
308 					/* kbd and keep across idle */
309 	struct exception_map *k_except;	/* Oddball cases */
310 	unsigned char	k_newabort1;	/* 1st key of new abort sequence */
311 	unsigned char	k_newabort1a;	/* alternate 1st key */
312 	unsigned char	k_newabort2;	/* 2nd key of new abort sequence */
313 };
314 
315 /*
316  * Define the compose sequence structure.  First and second
317  * ASCII chars of 0 indicate the end of the table.
318  */
319 struct compose_sequence_t {
320 	unsigned char	first;	/* first ASCII char after COMPOSE key */
321 	unsigned char	second; /* second ASCII char after COMPOSE key */
322 	unsigned char	iso;	/* equivalent ISO code */
323 };
324 
325 /*
326  * Define the floating accent sequence structure.
327  */
328 struct fltaccent_sequence_t {
329 	unsigned short	fa_entry;	/* floating accent keymap entry */
330 	unsigned char	ascii;		/* ASCII char after FA-type key */
331 	unsigned char	iso;		/* equivalent ISO code */
332 };
333 
334 /*
335  * The "special" entries' top 4 bits are defined below.	 Generally they are
336  * used with a 4-bit parameter (such as a bit number) in the low 4 bits.
337  * The bytes whose top 4 bits are 0x0 thru 0x7 happen to be ascii
338  * characters.	They are not special cased, but just normal cased.
339  */
340 
341 #define	SHIFTKEYS	0x100	/* thru 0x10F.	This key helps to determine */
342 				/* the translation table used.	The bit */
343 				/* position of its bit in "shiftmask" */
344 				/* is added to the entry, eg */
345 				/* SHIFTKEYS+LEFTCTRL.	When this entry is */
346 				/* invoked, the bit in "shiftmask" is */
347 				/* toggled.  Depending which tables you put */
348 				/* it in, this works well for hold-down */
349 				/* keys or press-on, press-off keys.  */
350 #define	BUCKYBITS	0x200	/* thru 0x20F.	This key determines the state */
351 				/* of one of the "bucky" bits above the */
352 				/* returned ASCII character.  This is */
353 				/* basically a way to pass mode-key-up/down */
354 				/* information back to the caller with each */
355 				/* "real" key depressed.  The concept, and */
356 				/* name "bucky" (derivation unknown) comes */
357 				/* from the MIT/SAIL "TV" system...they had */
358 				/* TOP, META, CTRL, and a few other bucky */
359 				/* bits.  The bit position of its bit in */
360 				/* "buckybits", minus 7, is added to the */
361 				/* entry; eg bit 0x00000400 is BUCKYBITS+3. */
362 				/* The "-7" prevents us from messing up the */
363 				/* ASCII char, and gives us 16 useful bucky */
364 				/* bits.  When this entry is invoked, */
365 				/* the designated bit in "buckybits" is */
366 				/* toggled.  Depending which tables you put */
367 				/* it in, this works well for hold-down */
368 				/* keys or press-on, press-off keys.  */
369 #define	FUNNY		0x300	/* thru 0x30F.	This key does one of 16 funny */
370 				/* things based on the low 4 bits: */
371 #define	NOP		0x300	/* This key does nothing. */
372 #define	OOPS		0x301	/* This key exists but is undefined. */
373 #define	HOLE		0x302	/* This key does not exist on the keyboard. */
374 				/* Its position code should never be */
375 				/* generated.  This indicates a software/ */
376 				/* hardware mismatch, or bugs. */
377 #define	RESET		0x306	/* Kbd was just reset */
378 #define	ERROR		0x307	/* Kbd just detected an internal error */
379 #define	IDLE		0x308	/* Kbd is idle (no keys down) */
380 #define	COMPOSE		0x309	/* This key is the Compose key. */
381 #define	NONL		0x30A	/* This key not affected by Num Lock */
382 /* Combinations 0x30B to 0x30F are reserved for non-parameterized functions */
383 
384 #define	FA_CLASS	0x400	/* thru 0x40F.	These are for "floating */
385 				/* accent" characters.	The low-order 4 bits */
386 				/* select one of those characters. */
387 /* Definitions for the individual floating accents: */
388 #define	FA_UMLAUT	0x400	/* umlaut accent */
389 #define	FA_CFLEX	0x401	/* circumflex accent */
390 #define	FA_TILDE	0x402	/* tilde accent */
391 #define	FA_CEDILLA	0x403	/* cedilla accent */
392 #define	FA_ACUTE	0x404	/* acute accent */
393 #define	FA_GRAVE	0x405	/* grave accent */
394 
395 #define	STRING		0x500	/* thru 0x50F.	The low-order 4 bits index */
396 				/* a table select a string to be returned, */
397 				/* char by char.  Each entry the table is */
398 				/* null terminated. */
399 #define	KTAB_STRLEN	10	/* Maximum string length (including null) */
400 /* Definitions for the individual string numbers: */
401 #define	HOMEARROW	0x00
402 #define	UPARROW		0x01
403 #define	DOWNARROW	0x02
404 #define	LEFTARROW	0x03
405 #define	RIGHTARROW	0x04
406 /* string numbers 5 thru F are available to users making custom entries */
407 
408 /*
409  * In the following function key groupings, the low-order 4 bits indicate
410  * the function key number within the group, and the next 4 bits indicate
411  * the group.
412  */
413 #define	FUNCKEYS	0x600
414 #define	LEFTFUNC	0x600	/* thru 0x60F.	The "left" group. */
415 #define	RIGHTFUNC	0x610	/* thru 0x61F.	The "right" group. */
416 #define	TOPFUNC		0x620	/* thru 0x62F.	The "top" group. */
417 #define	BOTTOMFUNC	0x630	/* thru 0x63F.	The "bottom" group. */
418 #define	LF(n)		(LEFTFUNC+(n)-1)
419 #define	RF(n)		(RIGHTFUNC+(n)-1)
420 #define	TF(n)		(TOPFUNC+(n)-1)
421 #define	BF(n)		(BOTTOMFUNC+(n)-1)
422 
423 /*
424  * The actual keyboard positions may not be on the left/right/top/bottom
425  * of the physical keyboard (although they usually are).
426  * What is important is that we have reserved 64 keys for function keys.
427  *
428  * Normally, striking a function key will cause the following escape sequence
429  * to be sent through the character stream:
430  *	ESC[0..9z
431  * where ESC is a single escape character and 0..9 indicate some number of
432  * digits needed to encode the function key as a decimal number.
433  */
434 #define	PADKEYS		0x700
435 #define	PADEQUAL	0x700		/* keypad = */
436 #define	PADSLASH	0x701		/* keypad / */
437 #define	PADSTAR		0x702		/* keypad * */
438 #define	PADMINUS	0x703		/* keypad - */
439 #define	PADSEP		0x704		/* keypad,  */
440 #define	PAD7		0x705		/* keypad 7 */
441 #define	PAD8		0x706		/* keypad 8 */
442 #define	PAD9		0x707		/* keypad 9 */
443 #define	PADPLUS		0x708		/* keypad + */
444 #define	PAD4		0x709		/* keypad 4 */
445 #define	PAD5		0x70A		/* keypad 5 */
446 #define	PAD6		0x70B		/* keypad 6 */
447 #define	PAD1		0x70C		/* keypad 1 */
448 #define	PAD2		0x70D		/* keypad 2 */
449 #define	PAD3		0x70E		/* keypad 3 */
450 #define	PAD0		0x70F		/* keypad 0 */
451 #define	PADDOT		0x710		/* keypad . */
452 #define	PADENTER	0x711		/* keypad Enter */
453 
454 #ifdef	__cplusplus
455 }
456 #endif
457 
458 #endif	/* _SYS_KBD_H */
459