xref: /freebsd/sys/sys/kbio.h (revision 2ff63af9)
1 /*-
2  */
3 
4 #ifndef	_SYS_KBIO_H_
5 #define	_SYS_KBIO_H_
6 
7 #ifndef _KERNEL
8 #include <sys/types.h>
9 #endif
10 #include <sys/ioccom.h>
11 
12 /* get/set keyboard I/O mode */
13 #define K_RAW		0		/* keyboard returns scancodes	*/
14 #define K_XLATE		1		/* keyboard returns ascii 	*/
15 #define K_CODE		2		/* keyboard returns keycodes 	*/
16 #define KDGKBMODE 	_IOR('K', 6, int)
17 #define KDSKBMODE 	_IOWINT('K', 7)
18 
19 /* make tone */
20 #define KDMKTONE	_IOWINT('K', 8)
21 
22 /* see console.h for the definitions of the following ioctls */
23 #ifdef notdef
24 #define KDGETMODE	_IOR('K', 9, int)
25 #define KDSETMODE	_IOWINT('K', 10)
26 #define KDSBORDER	_IOWINT('K', 13)
27 #endif
28 
29 /* get/set keyboard lock state */
30 #define CLKED		1		/* Caps locked			*/
31 #define NLKED		2		/* Num locked			*/
32 #define SLKED		4		/* Scroll locked		*/
33 #define ALKED		8		/* AltGr locked			*/
34 #define LOCK_MASK	(CLKED | NLKED | SLKED | ALKED)
35 #define KDGKBSTATE	_IOR('K', 19, int)
36 #define KDSKBSTATE	_IOWINT('K', 20)
37 
38 /* enable/disable I/O access */
39 #define KDENABIO	_IO('K', 60)
40 #define KDDISABIO	_IO('K', 61)
41 
42 /* make sound */
43 #define KIOCSOUND	_IOWINT('K', 63)
44 
45 /* get keyboard model */
46 #define KB_OTHER	0		/* keyboard not known 		*/
47 #define KB_84		1		/* 'old' 84 key AT-keyboard	*/
48 #define KB_101		2		/* MF-101 or MF-102 keyboard	*/
49 #define KDGKBTYPE	_IOR('K', 64, int)
50 
51 /* get/set keyboard LED state */
52 #define LED_CAP		1		/* Caps lock LED 		*/
53 #define LED_NUM		2		/* Num lock LED 		*/
54 #define LED_SCR		4		/* Scroll lock LED 		*/
55 #define LED_MASK	(LED_CAP | LED_NUM | LED_SCR)
56 #define KDGETLED	_IOR('K', 65, int)
57 #define KDSETLED	_IOWINT('K', 66)
58 
59 /* set keyboard repeat rate (obsolete, use KDSETREPEAT below) */
60 #define KDSETRAD	_IOWINT('K', 67)
61 
62 struct keyboard_info {
63 	int		kb_index;	/* kbdio index#			*/
64 	char		kb_name[16];	/* driver name			*/
65 	int		kb_unit;	/* unit#			*/
66 	int		kb_type;	/* KB_84, KB_101, KB_OTHER,...	*/
67 	int		kb_config;	/* device configuration flags	*/
68 	int		kb_flags;	/* internal flags		*/
69 };
70 typedef struct keyboard_info keyboard_info_t;
71 
72 /* keyboard repeat rate mapping table */
73 static const int kbdelays[]  = { 250, 500, 750, 1000 };
74 static const int kbrates[] = { 34,  38,  42,  46,  50,
75 	55,  59,  63, 68,  76,  84,  92, 100, 110, 118, 126,
76 	136, 152, 168, 184, 200, 220, 236, 252, 272, 304, 336,
77 	368, 400, 440, 472, 504 };
78 
79 /* add/remove keyboard to/from mux */
80 #define KBADDKBD	_IOW('K', 68, keyboard_info_t)	/* add keyboard */
81 #define KBRELKBD	_IOW('K', 69, keyboard_info_t)	/* release keyboard */
82 
83 /* see console.h for the definition of the following ioctl */
84 #ifdef notdef
85 #define KDRASTER	_IOW('K', 100, scr_size_t)
86 #endif
87 
88 /* get keyboard information */
89 #define KDGKBINFO	_IOR('K', 101, keyboard_info_t)
90 
91 /* set/get keyboard repeat rate (new interface) */
92 struct keyboard_repeat {
93 	int		kb_repeat[2];
94 };
95 typedef struct keyboard_repeat keyboard_repeat_t;
96 #define KDSETREPEAT	_IOW('K', 102, keyboard_repeat_t)
97 #define KDGETREPEAT	_IOR('K', 103, keyboard_repeat_t)
98 
99 /* get/set key map/accent map/function key strings */
100 
101 #define NUM_KEYS	256		/* number of keys in table	*/
102 #define NUM_STATES	8		/* states per key		*/
103 #define ALTGR_OFFSET	128		/* offset for altlock keys	*/
104 
105 #define NUM_DEADKEYS	15		/* number of accent keys	*/
106 #define NUM_ACCENTCHARS	52		/* max number of accent chars	*/
107 
108 #define NUM_FKEYS	96		/* max number of function keys	*/
109 #define MAXFK		16		/* max length of a function key str */
110 
111 #ifndef _KEYMAP_DECLARED
112 #define	_KEYMAP_DECLARED
113 
114 struct keyent_t {
115 	u_int		map[NUM_STATES];
116 	u_char		spcl;
117 	u_char		flgs;
118 #define	FLAG_LOCK_O	0
119 #define	FLAG_LOCK_C	1
120 #define FLAG_LOCK_N	2
121 };
122 
123 struct keymap {
124 	u_short		n_keys;
125 	struct keyent_t	key[NUM_KEYS];
126 };
127 typedef struct keymap keymap_t;
128 
129 #ifdef COMPAT_FREEBSD13
130 struct okeyent_t {
131 	u_char		map[NUM_STATES];
132 	u_char		spcl;
133 	u_char		flgs;
134 };
135 
136 struct okeymap {
137 	u_short		n_keys;
138 	struct okeyent_t key[NUM_KEYS];
139 };
140 typedef struct okeymap okeymap_t;
141 #endif /* COMPAT_FREEBSD13 */
142 
143 #endif /* !_KEYMAP_DECLARED */
144 
145 /* defines for "special" keys (spcl bit set in keymap) */
146 #define NOP		0x00		/* nothing (dead key)		*/
147 #define LSH		0x02		/* left shift key		*/
148 #define RSH		0x03		/* right shift key		*/
149 #define CLK		0x04		/* caps lock key		*/
150 #define NLK		0x05		/* num lock key			*/
151 #define SLK		0x06		/* scroll lock key		*/
152 #define LALT		0x07		/* left alt key			*/
153 #define BTAB		0x08		/* backwards tab		*/
154 #define LCTR		0x09		/* left control key		*/
155 #define NEXT		0x0a		/* switch to next screen 	*/
156 #define F_SCR		0x0b		/* switch to first screen 	*/
157 #define L_SCR		0x1a		/* switch to last screen 	*/
158 #define F_FN		0x1b		/* first function key 		*/
159 #define L_FN		0x7a		/* last function key 		*/
160 /*			0x7b-0x7f	   reserved do not use !	*/
161 #define RCTR		0x80		/* right control key		*/
162 #define RALT		0x81		/* right alt (altgr) key	*/
163 #define ALK		0x82		/* alt lock key			*/
164 #define ASH		0x83		/* alt shift key		*/
165 #define META		0x84		/* meta key			*/
166 #define RBT		0x85		/* boot machine			*/
167 #define DBG		0x86		/* call debugger		*/
168 #define SUSP		0x87		/* suspend power (APM)		*/
169 #define SPSC		0x88		/* toggle splash/text screen	*/
170 
171 #define F_ACC		DGRA		/* first accent key		*/
172 #define DGRA		0x89		/* grave			*/
173 #define DACU		0x8a		/* acute			*/
174 #define DCIR		0x8b		/* circumflex			*/
175 #define DTIL		0x8c		/* tilde			*/
176 #define DMAC		0x8d		/* macron			*/
177 #define DBRE		0x8e		/* breve			*/
178 #define DDOT		0x8f		/* dot				*/
179 #define DUML		0x90		/* umlaut/diaresis		*/
180 #define DDIA		0x90		/* diaresis			*/
181 #define DSLA		0x91		/* slash			*/
182 #define DRIN		0x92		/* ring				*/
183 #define DCED		0x93		/* cedilla			*/
184 #define DAPO		0x94		/* apostrophe			*/
185 #define DDAC		0x95		/* double acute			*/
186 #define DOGO		0x96		/* ogonek			*/
187 #define DCAR		0x97		/* caron			*/
188 #define L_ACC		DCAR		/* last accent key		*/
189 
190 #define STBY		0x98		/* Go into standby mode (apm)   */
191 #define PREV		0x99		/* switch to previous screen 	*/
192 #define PNC		0x9a		/* force system panic */
193 #define LSHA		0x9b		/* left shift key / alt lock	*/
194 #define RSHA		0x9c		/* right shift key / alt lock	*/
195 #define LCTRA		0x9d		/* left ctrl key / alt lock	*/
196 #define RCTRA		0x9e		/* right ctrl key / alt lock	*/
197 #define LALTA		0x9f		/* left alt key / alt lock	*/
198 #define RALTA		0xa0		/* right alt key / alt lock	*/
199 #define HALT		0xa1		/* halt machine */
200 #define PDWN		0xa2		/* halt machine and power down */
201 #define PASTE		0xa3		/* paste from cut-paste buffer */
202 
203 #define F(x)		((x)+F_FN-1)
204 #define	S(x)		((x)+F_SCR-1)
205 #define ACC(x)		((x)+F_ACC)
206 
207 struct acc_t {
208 	u_int		accchar;
209 	u_int		map[NUM_ACCENTCHARS][2];
210 };
211 
212 struct accentmap {
213 	u_short		n_accs;
214 	struct acc_t	acc[NUM_DEADKEYS];
215 };
216 typedef struct accentmap accentmap_t;
217 
218 #ifdef COMPAT_FREEBSD13
219 struct oacc_t {
220 	u_char		accchar;
221 	u_char		map[NUM_ACCENTCHARS][2];
222 };
223 
224 struct oaccentmap {
225 	u_short		n_accs;
226 	struct oacc_t	acc[NUM_DEADKEYS];
227 };
228 typedef struct oaccentmap oaccentmap_t;
229 #endif /* COMPAT_FREEBSD13 */
230 
231 struct keyarg {
232 	u_short		keynum;
233 	struct keyent_t	key;
234 };
235 typedef struct keyarg keyarg_t;
236 
237 struct fkeytab {
238 	u_char		str[MAXFK];
239 	u_char		len;
240 };
241 typedef struct fkeytab fkeytab_t;
242 
243 struct fkeyarg {
244 	u_short		keynum;
245 	char		keydef[MAXFK];
246 	char		flen;
247 };
248 typedef struct fkeyarg	fkeyarg_t;
249 
250 #define GETFKEY		_IOWR('k', 0, fkeyarg_t)
251 #define SETFKEY		_IOWR('k', 1, fkeyarg_t)
252 #ifdef notdef		/* see console.h */
253 #define GIO_SCRNMAP	_IOR('k', 2, scrmap_t)
254 #define PIO_SCRNMAP	_IOW('k', 3, scrmap_t)
255 #endif
256 /* XXX: Should have keymap_t as an argument, but that's too big for ioctl()! */
257 #define GIO_KEYMAP 	 _IO('k', 6)
258 #define PIO_KEYMAP 	 _IO('k', 7)
259 #ifdef COMPAT_FREEBSD13
260 #define OGIO_KEYMAP 	_IOR('k', 6, okeymap_t)
261 #define OPIO_KEYMAP 	_IOW('k', 7, okeymap_t)
262 #endif /* COMPAT_FREEBSD13 */
263 /* XXX: Should have accentmap_t as an argument, but that's too big for ioctl()! */
264 #define GIO_DEADKEYMAP 	 _IO('k', 8)
265 #define PIO_DEADKEYMAP 	 _IO('k', 9)
266 #ifdef COMPAT_FREEBSD13
267 #define OGIO_DEADKEYMAP	_IOR('k', 8, oaccentmap_t)
268 #define OPIO_DEADKEYMAP	_IOW('k', 9, oaccentmap_t)
269 #endif /* COMPAT_FREEBSD13 */
270 #define GIO_KEYMAPENT 	_IOWR('k', 10, keyarg_t)
271 #define PIO_KEYMAPENT 	_IOW('k', 11, keyarg_t)
272 
273 /* flags set to the return value in the KD_XLATE mode */
274 
275 #define	NOKEY		0x01000000	/* no key pressed marker 	*/
276 #define	FKEY		0x02000000	/* function key marker 		*/
277 #define	MKEY		0x04000000	/* meta key marker (prepend ESC)*/
278 #define	BKEY		0x08000000	/* backtab (ESC [ Z)		*/
279 
280 #define	SPCLKEY		0x80000000	/* special key			*/
281 #define	RELKEY		0x40000000	/* key released			*/
282 #define	ERRKEY		0x20000000	/* error			*/
283 
284 /*
285  * The top byte is used to store the flags.  This means there are 24
286  * bits left to store the actual character.  Because UTF-8 can encode
287  * 2^21 different characters, this is good enough to get Unicode
288  * working.
289  */
290 #define KEYCHAR(c)	((c) & 0x00ffffff)
291 #define KEYFLAGS(c)	((c) & ~0x00ffffff)
292 
293 #endif /* !_SYS_KBIO_H_ */
294