FreeBSD/Linux Kernel Cross Reference
sys/dev/kbd/kbdreg.h
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30
31 #ifndef _DEV_KBD_KBDREG_H_
32 #define _DEV_KBD_KBDREG_H_
33
34 /* forward declarations */
35 typedef struct keyboard keyboard_t;
36 struct keymap;
37 struct accentmap;
38 struct fkeytab;
39 struct cdevsw;
40
41 /* call back funcion */
42 typedef int kbd_callback_func_t(keyboard_t *kbd, int event,
43 void *arg);
44 /* event types */
45 #define KBDIO_KEYINPUT 0
46 #define KBDIO_UNLOADING 1
47
48 typedef struct keyboard_callback {
49 kbd_callback_func_t *kc_func;
50 void *kc_arg;
51 } keyboard_callback_t;
52
53 /* keyboard */
54 struct keyboard {
55 /* the following fields are managed by kbdio */
56 int kb_index; /* kbdio index# */
57 int kb_minor; /* minor number of the sub-device */
58 int kb_flags; /* internal flags */
59 #define KB_VALID (1 << 16) /* this entry is valid */
60 #define KB_NO_DEVICE (1 << 17) /* device not present */
61 #define KB_PROBED (1 << 18) /* device probed */
62 #define KB_INITIALIZED (1 << 19) /* device initialized */
63 #define KB_REGISTERED (1 << 20) /* device registered to kbdio */
64 #define KB_BUSY (1 << 21) /* device used by a client */
65 #define KB_POLLED (1 << 22) /* device is polled */
66 int kb_active; /* 0: inactive */
67 void *kb_token; /* id of the current client */
68 keyboard_callback_t kb_callback;/* callback function */
69
70 /*
71 * Device configuration flags:
72 * The upper 16 bits are common between various keyboard devices.
73 * The lower 16 bits are device-specific.
74 */
75 int kb_config;
76 #define KB_CONF_PROBE_ONLY (1 << 16) /* probe only, don't initialize */
77
78 /* the following fields are set up by the driver */
79 char *kb_name; /* driver name */
80 int kb_unit; /* unit # */
81 int kb_type; /* KB_84, KB_101, KB_OTHER,... */
82 int kb_io_base; /* port# if any */
83 int kb_io_size; /* # of occupied port */
84 int kb_led; /* LED status */
85 struct keymap *kb_keymap; /* key map */
86 struct accentmap *kb_accentmap; /* accent map */
87 struct fkeytab *kb_fkeytab; /* function key strings */
88 int kb_fkeytab_size;/* # of function key strings */
89 void *kb_data; /* the driver's private data */
90 int kb_delay1;
91 int kb_delay2;
92 #define KB_DELAY1 500
93 #define KB_DELAY2 100
94 unsigned long kb_count; /* # of processed key strokes */
95 u_char kb_lastact[NUM_KEYS/2];
96 struct cdev *kb_dev;
97 };
98
99 #define KBD_IS_VALID(k) ((k)->kb_flags & KB_VALID)
100 #define KBD_VALID(k) ((k)->kb_flags |= KB_VALID)
101 #define KBD_INVALID(k) ((k)->kb_flags &= ~KB_VALID)
102 #define KBD_HAS_DEVICE(k) (!((k)->kb_flags & KB_NO_DEVICE))
103 #define KBD_FOUND_DEVICE(k) ((k)->kb_flags &= ~KB_NO_DEVICE)
104 #define KBD_IS_PROBED(k) ((k)->kb_flags & KB_PROBED)
105 #define KBD_PROBE_DONE(k) ((k)->kb_flags |= KB_PROBED)
106 #define KBD_IS_INITIALIZED(k) ((k)->kb_flags & KB_INITIALIZED)
107 #define KBD_INIT_DONE(k) ((k)->kb_flags |= KB_INITIALIZED)
108 #define KBD_IS_CONFIGURED(k) ((k)->kb_flags & KB_REGISTERED)
109 #define KBD_CONFIG_DONE(k) ((k)->kb_flags |= KB_REGISTERED)
110 #define KBD_IS_BUSY(k) ((k)->kb_flags & KB_BUSY)
111 #define KBD_BUSY(k) ((k)->kb_flags |= KB_BUSY)
112 #define KBD_UNBUSY(k) ((k)->kb_flags &= ~KB_BUSY)
113 #define KBD_IS_POLLED(k) ((k)->kb_flags & KB_POLLED)
114 #define KBD_POLL(k) ((k)->kb_flags |= KB_POLLED)
115 #define KBD_UNPOLL(k) ((k)->kb_flags &= ~KB_POLLED)
116 #define KBD_IS_ACTIVE(k) ((k)->kb_active)
117 #define KBD_ACTIVATE(k) (++(k)->kb_active)
118 #define KBD_DEACTIVATE(k) (--(k)->kb_active)
119 #define KBD_LED_VAL(k) ((k)->kb_led)
120
121 /* keyboard function table */
122 typedef int kbd_probe_t(int unit, void *arg, int flags);
123 typedef int kbd_init_t(int unit, keyboard_t **kbdp, void *arg,
124 int flags);
125 typedef int kbd_term_t(keyboard_t *kbd);
126 typedef int kbd_intr_t(keyboard_t *kbd, void *arg);
127 typedef int kbd_test_if_t(keyboard_t *kbd);
128 typedef int kbd_enable_t(keyboard_t *kbd);
129 typedef int kbd_disable_t(keyboard_t *kbd);
130 typedef int kbd_read_t(keyboard_t *kbd, int wait);
131 typedef int kbd_check_t(keyboard_t *kbd);
132 typedef u_int kbd_read_char_t(keyboard_t *kbd, int wait);
133 typedef int kbd_check_char_t(keyboard_t *kbd);
134 typedef int kbd_ioctl_t(keyboard_t *kbd, u_long cmd, caddr_t data);
135 typedef int kbd_lock_t(keyboard_t *kbd, int lock);
136 typedef void kbd_clear_state_t(keyboard_t *kbd);
137 typedef int kbd_get_state_t(keyboard_t *kbd, void *buf, size_t len);
138 typedef int kbd_set_state_t(keyboard_t *kbd, void *buf, size_t len);
139 typedef u_char *kbd_get_fkeystr_t(keyboard_t *kbd, int fkey,
140 size_t *len);
141 typedef int kbd_poll_mode_t(keyboard_t *kbd, int on);
142 typedef void kbd_diag_t(keyboard_t *kbd, int level);
143
144 typedef struct keyboard_switch {
145 kbd_probe_t *probe;
146 kbd_init_t *init;
147 kbd_term_t *term;
148 kbd_intr_t *intr;
149 kbd_test_if_t *test_if;
150 kbd_enable_t *enable;
151 kbd_disable_t *disable;
152 kbd_read_t *read;
153 kbd_check_t *check;
154 kbd_read_char_t *read_char;
155 kbd_check_char_t *check_char;
156 kbd_ioctl_t *ioctl;
157 kbd_lock_t *lock;
158 kbd_clear_state_t *clear_state;
159 kbd_get_state_t *get_state;
160 kbd_set_state_t *set_state;
161 kbd_get_fkeystr_t *get_fkeystr;
162 kbd_poll_mode_t *poll;
163 kbd_diag_t *diag;
164 } keyboard_switch_t;
165
166 /*
167 * Keyboard disciplines: call actual handlers via kbdsw[].
168 */
169 #define kbdd_probe(kbd, unit, arg, flags) \
170 (*kbdsw[(kbd)->kb_index]->probe)((unit), (arg), (flags))
171 #define kbdd_init(kbd, unit, kbdpp, arg, flags) \
172 (*kbdsw[(kbd)->kb_index]->init)((unit), (kbdpp), (arg), (flags))
173 #define kbdd_term(kbd) \
174 (*kbdsw[(kbd)->kb_index]->term)((kbd))
175 #define kbdd_intr(kbd, arg) \
176 (*kbdsw[(kbd)->kb_index]->intr)((kbd), (arg))
177 #define kbdd_test_if(kbd) \
178 (*kbdsw[(kbd)->kb_index]->test_if)((kbd))
179 #define kbdd_enable(kbd) \
180 (*kbdsw[(kbd)->kb_index]->enable)((kbd))
181 #define kbdd_disable(kbd) \
182 (*kbdsw[(kbd)->kb_index]->disable)((kbd))
183 #define kbdd_read(kbd, wait) \
184 (*kbdsw[(kbd)->kb_index]->read)((kbd), (wait))
185 #define kbdd_check(kbd) \
186 (*kbdsw[(kbd)->kb_index]->check)((kbd))
187 #define kbdd_read_char(kbd, wait) \
188 (*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait))
189 #define kbdd_check_char(kbd) \
190 (*kbdsw[(kbd)->kb_index]->check_char)((kbd))
191 #define kbdd_ioctl(kbd, cmd, arg) \
192 (((kbd) == NULL) ? \
193 ENODEV : \
194 (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg)))
195 #define kbdd_lock(kbd, lockf) \
196 (*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf))
197 #define kbdd_clear_state(kbd) \
198 (*kbdsw[(kbd)->kb_index]->clear_state)((kbd))
199 #define kbdd_get_state(kbd, buf, len) \
200 (*kbdsw[(kbd)->kb_index]->get_state)((kbd), (buf), (len))
201 #define kbdd_set_state(kbd, buf, len) \
202 (*kbdsw[(kbd)->kb_index]->set_state)((kbd), (buf), (len))
203 #define kbdd_get_fkeystr(kbd, fkey, len) \
204 (*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len))
205 #define kbdd_poll(kbd, on) \
206 (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
207 #define kbdd_diag(kbd, level) \
208 (*kbdsw[(kbd)->kb_index]->diag)((kbd), (level))
209
210 /*
211 * Keyboard driver definition. Some of these be immutable after definition
212 * time, e.g. one shouldn't be able to rename a driver or use a different kbdsw
213 * entirely, but patching individual methods is acceptable.
214 */
215 typedef struct keyboard_driver {
216 SLIST_ENTRY(keyboard_driver) link;
217 const char * const name;
218 keyboard_switch_t * const kbdsw;
219 /* backdoor for the console driver */
220 int (* const configure)(int);
221 } keyboard_driver_t;
222
223 #ifdef _KERNEL
224
225 #define KEYBOARD_DRIVER(name, sw, config) \
226 static struct keyboard_driver name##_kbd_driver = { \
227 { NULL }, #name, &sw, config \
228 }; \
229 DATA_SET(kbddriver_set, name##_kbd_driver);
230
231 /* global variables */
232 extern keyboard_switch_t **kbdsw;
233
234 /* functions for the keyboard driver */
235 int kbd_add_driver(keyboard_driver_t *driver);
236 int kbd_delete_driver(keyboard_driver_t *driver);
237 int kbd_register(keyboard_t *kbd);
238 int kbd_unregister(keyboard_t *kbd);
239 keyboard_switch_t *kbd_get_switch(char *driver);
240 void kbd_init_struct(keyboard_t *kbd, char *name, int type,
241 int unit, int config, int port,
242 int port_size);
243 void kbd_set_maps(keyboard_t *kbd, struct keymap *keymap,
244 struct accentmap *accmap,
245 struct fkeytab *fkeymap, int fkeymap_size);
246
247 /* functions for the keyboard client */
248 int kbd_allocate(char *driver, int unit, void *id,
249 kbd_callback_func_t *func, void *arg);
250 int kbd_release(keyboard_t *kbd, void *id);
251 int kbd_change_callback(keyboard_t *kbd, void *id,
252 kbd_callback_func_t *func, void *arg);
253 int kbd_find_keyboard(char *driver, int unit);
254 int kbd_find_keyboard2(char *driver, int unit, int index);
255 keyboard_t *kbd_get_keyboard(int index);
256
257 /* a back door for the console driver to tickle the keyboard driver XXX */
258 int kbd_configure(int flags);
259 /* see `kb_config' above for flag bit definitions */
260
261 /* evdev2kbd mappings */
262 void kbd_ev_event(keyboard_t *kbd, uint16_t type,
263 uint16_t code, int32_t value);
264
265 #ifdef KBD_INSTALL_CDEV
266
267 /* virtual keyboard cdev driver functions */
268 int kbd_attach(keyboard_t *kbd);
269 int kbd_detach(keyboard_t *kbd);
270
271 #endif /* KBD_INSTALL_CDEV */
272
273 /* generic low-level keyboard functions */
274
275 /* shift key state */
276 #define SHIFTS1 (1 << 16)
277 #define SHIFTS2 (1 << 17)
278 #define SHIFTS (SHIFTS1 | SHIFTS2)
279 #define CTLS1 (1 << 18)
280 #define CTLS2 (1 << 19)
281 #define CTLS (CTLS1 | CTLS2)
282 #define ALTS1 (1 << 20)
283 #define ALTS2 (1 << 21)
284 #define ALTS (ALTS1 | ALTS2)
285 #define AGRS1 (1 << 22)
286 #define AGRS2 (1 << 23)
287 #define AGRS (AGRS1 | AGRS2)
288 #define METAS1 (1 << 24)
289 #define METAS2 (1 << 25)
290 #define METAS (METAS1 | METAS2)
291 #define NLKDOWN (1 << 26)
292 #define SLKDOWN (1 << 27)
293 #define CLKDOWN (1 << 28)
294 #define ALKDOWN (1 << 29)
295 #define SHIFTAON (1 << 30)
296 /* lock key state (defined in sys/kbio.h) */
297 /*
298 #define CLKED LED_CAP
299 #define NLKED LED_NUM
300 #define SLKED LED_SCR
301 #define ALKED (1 << 3)
302 #define LOCK_MASK (CLKED | NLKED | SLKED | ALKED)
303 #define LED_CAP (1 << 0)
304 #define LED_NUM (1 << 1)
305 #define LED_SCR (1 << 2)
306 #define LED_MASK (LED_CAP | LED_NUM | LED_SCR)
307 */
308
309 kbd_get_fkeystr_t genkbd_get_fkeystr;
310 kbd_diag_t genkbd_diag;
311
312 int genkbd_commonioctl(keyboard_t *kbd, u_long cmd, caddr_t arg);
313 int genkbd_keyaction(keyboard_t *kbd, int keycode, int up,
314 int *shiftstate, int *accents);
315
316 #endif /* _KERNEL */
317
318 #endif /* !_DEV_KBD_KBDREG_H_ */
Cache object: e8d55e723517c81e3703d3c6298d439b
|