4 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
6 * This code is derived from software contributed to The DragonFly Project
7 * by Matthew Dillon <dillon@backplane.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
19 * 3. Neither the name of The DragonFly Project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific, prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
46 #include <sys/event.h>
47 #include <sys/vnode.h>
49 #include <sys/thread.h>
51 #include <machine/console.h>
56 sw_probe(keyboard_switch_t *sw, int unit, void *arg, int flags)
60 error = (*sw->probe)(unit, arg, flags);
65 sw_init(keyboard_switch_t *sw, int unit, keyboard_t **kbdpp,
70 error = (*sw->init)(unit, kbdpp, arg, flags);
75 kbd_term(keyboard_t *kbd)
80 error = (*kbdsw[kbd->kb_index]->term)(kbd);
82 KBD_ALWAYS_UNLOCK(kbd);
83 /* kbd structure is stale if error is 0 */
88 * Handle a keyboard interrupt.
90 * Be suspicious, just in case kbd_intr() is called from an interrupt
91 * before the keyboard switch is completely installed.
94 kbd_intr(keyboard_t *kbd, void *arg)
103 if (i >= 0 && i < KBD_MAXKEYBOARDS && kbdsw[i]) {
105 error = (*kbdsw[i]->intr)(kbd, arg);
112 kbd_test_if(keyboard_t *kbd)
118 error = (*kbdsw[kbd->kb_index]->test_if)(kbd);
125 kbd_enable(keyboard_t *kbd)
131 error = (*kbdsw[kbd->kb_index]->enable)(kbd);
138 kbd_disable(keyboard_t *kbd)
144 error = (*kbdsw[kbd->kb_index]->disable)(kbd);
151 kbd_read(keyboard_t *kbd, int wait)
157 error = (*kbdsw[kbd->kb_index]->read)(kbd, wait);
164 kbd_check(keyboard_t *kbd)
170 error = (*kbdsw[kbd->kb_index]->check)(kbd);
177 kbd_read_char(keyboard_t *kbd, int wait)
183 error = (*kbdsw[kbd->kb_index]->read_char)(kbd, wait);
190 kbd_check_char(keyboard_t *kbd)
196 error = (*kbdsw[kbd->kb_index]->check_char)(kbd);
203 kbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data)
210 error = (*kbdsw[kbd->kb_index]->ioctl)(kbd, cmd, data);
219 kbd_lock(keyboard_t *kbd, int xlock)
225 error = (*kbdsw[kbd->kb_index]->lock)(kbd, xlock);
232 kbd_clear_state(keyboard_t *kbd)
237 (*kbdsw[kbd->kb_index]->clear_state)(kbd);
242 kbd_get_state(keyboard_t *kbd, void *buf, size_t len)
248 error = (*kbdsw[kbd->kb_index]->get_state)(kbd, buf, len);
255 kbd_set_state(keyboard_t *kbd, void *buf, size_t len)
261 error = (*kbdsw[kbd->kb_index]->set_state)(kbd, buf, len);
268 kbd_get_fkeystr(keyboard_t *kbd, int fkey, size_t *len)
274 retstr = (*kbdsw[kbd->kb_index]->get_fkeystr)(kbd, fkey, len);
281 * Polling mode set by debugger, we cannot lock!
284 kbd_poll(keyboard_t *kbd, int on)
290 error = (*kbdsw[kbd->kb_index]->poll)(kbd, on);
298 kbd_diag(keyboard_t *kbd, int level)
303 (*kbdsw[kbd->kb_index]->diag)(kbd, level);