xref: /titanic_52/usr/src/uts/common/sys/kbd.h (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1983-1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _SYS_KBD_H
28 #define	_SYS_KBD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS4.0 1.18 */
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Following #defines are related to the older keyboards which
38  * are no longer supported by kb module.  The #defines ane left
39  * for older programs to still compile.
40  */
41 #define	KB_KLUNK	0x00		/* Micro Switch 103SD32-2 */
42 #define	KB_VT100	0x01		/* Keytronics VT100 compatible */
43 #define	KB_SUN2		0x02		/* Sun-2 custom keyboard */
44 #define	KB_VT220	0x81		/* Emulation VT220 */
45 #define	KB_VT220I	0x82		/* International VT220 Emulation */
46 
47 #define	NOTPRESENT	0xFF		/* Keyboard is not plugged in */
48 #define	KBD_CMD_LED1	0x04		/* Turn on LED 1 for Sun-2 */
49 #define	KBD_CMD_NOLED1	0x05		/* Turn off LED 1 for Sun-2 */
50 #define	KBD_CMD_LED2	0x06		/* Turn on LED 2 for Sun-2 */
51 #define	KBD_CMD_NOLED2	0x07		/* Turn off LED 2 for Sun-2 */
52 
53 #define	CTLSMASK	0x0100		/* Set if ^S was last keyed of ^S, ^Q */
54 					/* determines which NOSCROLL sends. */
55 
56 #define	NOSCROLL	0x303	/* This key alternately sends ^S or ^Q */
57 #define	CTRLS		0x304	/* This sends ^S and lets NOSCROLL know */
58 #define	CTRLQ		0x305	/* This sends ^Q and lets NOSCROLL know */
59 
60 
61 /*
62  * Following are the only keyboard types supported by kb module.
63  * (Type 5, Hobo, US101A are also supported but they report
64  * themselves as Type 4 keyboard with a different layout id.)
65  */
66 #define	KB_SUN3		3		/* Type 3 Sun keyboard */
67 #define	KB_SUN4		4		/* Type 4 Sun keyboard */
68 #define	KB_USB		6		/* USB keyboard */
69 #define	KB_PC		101		/* Type 101 AT keyboard */
70 
71 #define	KB_ASCII	0x0F		/* Ascii terminal masquerading as kbd */
72 
73 /*
74  * This structure is used to enumerate the supported keyboard types.
75  * The array of these is terminated by an entry with a NULL table entry.
76  * The first entry is used if none match.
77  */
78 struct keyboards {
79 	int		id;	/* Keyboard type, per KIOCTYPE */
80 	struct keyboard	*table;	/* Keyboard table to use. */
81 };
82 
83 /*
84  * Various special characters that might show up on the port
85  */
86 #define	IDLEKEY		0x7F		/* Keyboard is idle; no keys down */
87 #define	ERRORKEY	0x7E		/* Keyboard detected an error */
88 #define	RESETKEY	0xFF		/* Keyboard was just reset */
89 #define	LAYOUTKEY	0xFE		/* Keyboard layout byte follows */
90 
91 #define	PRESSED		0x00		/* 0x80 bit off: key was pressed */
92 #define	RELEASED	0x80		/* 0x80 bit on : key was released */
93 
94 /*
95  * Commands to the Sun-3 keyboard.
96  */
97 #define	KBD_CMD_RESET		0x01	/* Reset keyboard as if power-up */
98 #define	KBD_CMD_BELL		0x02	/* Turn on the bell */
99 #define	KBD_CMD_NOBELL		0x03	/* Turn off the bell */
100 #define	KBD_CMD_CLICK		0x0A	/* Turn on the click annunciator */
101 #define	KBD_CMD_NOCLICK		0x0B	/* Turn off the click annunciator */
102 
103 /*
104  * Commands to the Type 4 keyboard, in addition to those above.
105  */
106 #define	KBD_CMD_AUTOTEST	0x0C	/* Initiate test sequence */
107 #define	KBD_CMD_SETLED		0x0E	/* Set keyboard LED's */
108 #define	KBD_CMD_GETLAYOUT	0x0F	/* Request that keyboard indicate */
109 					/* layout */
110 /*
111  * Type 4 keyboard LED masks (used to set LED's)
112  */
113 #define	LED_NUM_LOCK	0x1
114 #define	LED_COMPOSE	0x2
115 #define	LED_SCROLL_LOCK 0x4
116 #define	LED_CAPS_LOCK	0x8
117 #define	LED_KANA	0x10		/* Valid only on Japanese layout */
118 
119 /*
120  * Software related definitions
121  */
122 /*
123  * These are the states that the keyboard scanner can be in.
124  *
125  * It starts out in NORMAL state.
126  */
127 #define	NORMAL		0		/* The usual (ho, hum) */
128 #define	ABORT1		1		/* Got KEYABORT1 */
129 #define	COMPOSE1	2		/* Got COMPOSE */
130 #define	COMPOSE2	3		/* Got COMPOSE plus first key */
131 #define	FLTACCENT	4		/* Got floating accent key */
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 };
311 
312 /*
313  * Define the compose sequence structure.  First and second
314  * ASCII chars of 0 indicate the end of the table.
315  */
316 struct compose_sequence_t {
317 	unsigned char	first;	/* first ASCII char after COMPOSE key */
318 	unsigned char	second; /* second ASCII char after COMPOSE key */
319 	unsigned char	iso;	/* equivalent ISO code */
320 };
321 
322 /*
323  * Define the floating accent sequence structure.
324  */
325 struct fltaccent_sequence_t {
326 	unsigned short	fa_entry;	/* floating accent keymap entry */
327 	unsigned char	ascii;		/* ASCII char after FA-type key */
328 	unsigned char	iso;		/* equivalent ISO code */
329 };
330 
331 /*
332  * The "special" entries' top 4 bits are defined below.	 Generally they are
333  * used with a 4-bit parameter (such as a bit number) in the low 4 bits.
334  * The bytes whose top 4 bits are 0x0 thru 0x7 happen to be ascii
335  * characters.	They are not special cased, but just normal cased.
336  */
337 
338 #define	SHIFTKEYS	0x100	/* thru 0x10F.	This key helps to determine */
339 				/* the translation table used.	The bit */
340 				/* position of its bit in "shiftmask" */
341 				/* is added to the entry, eg */
342 				/* SHIFTKEYS+LEFTCTRL.	When this entry is */
343 				/* invoked, the bit in "shiftmask" is */
344 				/* toggled.  Depending which tables you put */
345 				/* it in, this works well for hold-down */
346 				/* keys or press-on, press-off keys.  */
347 #define	BUCKYBITS	0x200	/* thru 0x20F.	This key determines the state */
348 				/* of one of the "bucky" bits above the */
349 				/* returned ASCII character.  This is */
350 				/* basically a way to pass mode-key-up/down */
351 				/* information back to the caller with each */
352 				/* "real" key depressed.  The concept, and */
353 				/* name "bucky" (derivation unknown) comes */
354 				/* from the MIT/SAIL "TV" system...they had */
355 				/* TOP, META, CTRL, and a few other bucky */
356 				/* bits.  The bit position of its bit in */
357 				/* "buckybits", minus 7, is added to the */
358 				/* entry; eg bit 0x00000400 is BUCKYBITS+3. */
359 				/* The "-7" prevents us from messing up the */
360 				/* ASCII char, and gives us 16 useful bucky */
361 				/* bits.  When this entry is invoked, */
362 				/* the designated bit in "buckybits" is */
363 				/* toggled.  Depending which tables you put */
364 				/* it in, this works well for hold-down */
365 				/* keys or press-on, press-off keys.  */
366 #define	FUNNY		0x300	/* thru 0x30F.	This key does one of 16 funny */
367 				/* things based on the low 4 bits: */
368 #define	NOP		0x300	/* This key does nothing. */
369 #define	OOPS		0x301	/* This key exists but is undefined. */
370 #define	HOLE		0x302	/* This key does not exist on the keyboard. */
371 				/* Its position code should never be */
372 				/* generated.  This indicates a software/ */
373 				/* hardware mismatch, or bugs. */
374 #define	RESET		0x306	/* Kbd was just reset */
375 #define	ERROR		0x307	/* Kbd just detected an internal error */
376 #define	IDLE		0x308	/* Kbd is idle (no keys down) */
377 #define	COMPOSE		0x309	/* This key is the Compose key. */
378 #define	NONL		0x30A	/* This key not affected by Num Lock */
379 /* Combinations 0x30B to 0x30F are reserved for non-parameterized functions */
380 
381 #define	FA_CLASS	0x400	/* thru 0x40F.	These are for "floating */
382 				/* accent" characters.	The low-order 4 bits */
383 				/* select one of those characters. */
384 /* Definitions for the individual floating accents: */
385 #define	FA_UMLAUT	0x400	/* umlaut accent */
386 #define	FA_CFLEX	0x401	/* circumflex accent */
387 #define	FA_TILDE	0x402	/* tilde accent */
388 #define	FA_CEDILLA	0x403	/* cedilla accent */
389 #define	FA_ACUTE	0x404	/* acute accent */
390 #define	FA_GRAVE	0x405	/* grave accent */
391 
392 #define	STRING		0x500	/* thru 0x50F.	The low-order 4 bits index */
393 				/* a table select a string to be returned, */
394 				/* char by char.  Each entry the table is */
395 				/* null terminated. */
396 #define	KTAB_STRLEN	10	/* Maximum string length (including null) */
397 /* Definitions for the individual string numbers: */
398 #define	HOMEARROW	0x00
399 #define	UPARROW		0x01
400 #define	DOWNARROW	0x02
401 #define	LEFTARROW	0x03
402 #define	RIGHTARROW	0x04
403 /* string numbers 5 thru F are available to users making custom entries */
404 
405 /*
406  * In the following function key groupings, the low-order 4 bits indicate
407  * the function key number within the group, and the next 4 bits indicate
408  * the group.
409  */
410 #define	FUNCKEYS	0x600
411 #define	LEFTFUNC	0x600	/* thru 0x60F.	The "left" group. */
412 #define	RIGHTFUNC	0x610	/* thru 0x61F.	The "right" group. */
413 #define	TOPFUNC		0x620	/* thru 0x62F.	The "top" group. */
414 #define	BOTTOMFUNC	0x630	/* thru 0x63F.	The "bottom" group. */
415 #define	LF(n)		(LEFTFUNC+(n)-1)
416 #define	RF(n)		(RIGHTFUNC+(n)-1)
417 #define	TF(n)		(TOPFUNC+(n)-1)
418 #define	BF(n)		(BOTTOMFUNC+(n)-1)
419 
420 /*
421  * The actual keyboard positions may not be on the left/right/top/bottom
422  * of the physical keyboard (although they usually are).
423  * What is important is that we have reserved 64 keys for function keys.
424  *
425  * Normally, striking a function key will cause the following escape sequence
426  * to be sent through the character stream:
427  *	ESC[0..9z
428  * where ESC is a single escape character and 0..9 indicate some number of
429  * digits needed to encode the function key as a decimal number.
430  */
431 #define	PADKEYS		0x700
432 #define	PADEQUAL	0x700		/* keypad = */
433 #define	PADSLASH	0x701		/* keypad / */
434 #define	PADSTAR		0x702		/* keypad * */
435 #define	PADMINUS	0x703		/* keypad - */
436 #define	PADSEP		0x704		/* keypad,  */
437 #define	PAD7		0x705		/* keypad 7 */
438 #define	PAD8		0x706		/* keypad 8 */
439 #define	PAD9		0x707		/* keypad 9 */
440 #define	PADPLUS		0x708		/* keypad + */
441 #define	PAD4		0x709		/* keypad 4 */
442 #define	PAD5		0x70A		/* keypad 5 */
443 #define	PAD6		0x70B		/* keypad 6 */
444 #define	PAD1		0x70C		/* keypad 1 */
445 #define	PAD2		0x70D		/* keypad 2 */
446 #define	PAD3		0x70E		/* keypad 3 */
447 #define	PAD0		0x70F		/* keypad 0 */
448 #define	PADDOT		0x710		/* keypad . */
449 #define	PADENTER	0x711		/* keypad Enter */
450 
451 #ifdef	__cplusplus
452 }
453 #endif
454 
455 #endif	/* _SYS_KBD_H */
456