- Add a module event function to the ukbd driver and make the ukbd KLD

module work.
- Delete unnecessary #include.
This commit is contained in:
yokota 1999-12-13 10:36:36 +00:00
parent d03d01b88b
commit f65afa425d
3 changed files with 69 additions and 6 deletions

View File

@ -53,6 +53,9 @@ typedef struct genkbd_softc {
struct selinfo gkb_rsel;
} genkbd_softc_t;
static SLIST_HEAD(, keyboard_driver) keyboard_drivers =
SLIST_HEAD_INITIALIZER(keyboard_drivers);
/* local arrays */
/*
@ -150,6 +153,24 @@ kbd_set_maps(keyboard_t *kbd, keymap_t *keymap, accentmap_t *accmap,
kbd->kb_fkeytab_size = fkeymap_size;
}
/* declare a new keyboard driver */
int
kbd_add_driver(keyboard_driver_t *driver)
{
if (SLIST_NEXT(driver, link))
return EINVAL;
SLIST_INSERT_HEAD(&keyboard_drivers, driver, link);
return 0;
}
int
kbd_delete_driver(keyboard_driver_t *driver)
{
SLIST_REMOVE(&keyboard_drivers, driver, keyboard_driver, link);
SLIST_NEXT(driver, link) = NULL;
return 0;
}
/* register a keyboard and associate it with a function table */
int
kbd_register(keyboard_t *kbd)
@ -175,6 +196,13 @@ kbd_register(keyboard_t *kbd)
kbd->kb_callback.kc_func = NULL;
kbd->kb_callback.kc_arg = NULL;
SLIST_FOREACH(p, &keyboard_drivers, link) {
if (strcmp(p->name, kbd->kb_name) == 0) {
keyboard[index] = kbd;
kbdsw[index] = p->kbdsw;
return index;
}
}
list = (const keyboard_driver_t **)kbddriver_set.ls_items;
while ((p = *list++) != NULL) {
if (strcmp(p->name, kbd->kb_name) == 0) {
@ -226,6 +254,10 @@ keyboard_switch_t
const keyboard_driver_t **list;
const keyboard_driver_t *p;
SLIST_FOREACH(p, &keyboard_drivers, link) {
if (strcmp(p->name, driver) == 0)
return p->kbdsw;
}
list = (const keyboard_driver_t **)kbddriver_set.ls_items;
while ((p = *list++) != NULL) {
if (strcmp(p->name, driver) == 0)
@ -361,6 +393,10 @@ kbd_configure(int flags)
const keyboard_driver_t **list;
const keyboard_driver_t *p;
SLIST_FOREACH(p, &keyboard_drivers, link) {
if (p->configure != NULL)
(*p->configure)(flags);
}
list = (const keyboard_driver_t **)kbddriver_set.ls_items;
while ((p = *list++) != NULL) {
if (p->configure != NULL)
@ -430,12 +466,18 @@ kbd_attach(keyboard_t *kbd)
int
kbd_detach(keyboard_t *kbd)
{
dev_t dev;
if (kbd->kb_index >= keyboards)
return EINVAL;
if (keyboard[kbd->kb_index] != kbd)
return EINVAL;
/* XXX: unmake_dev() ? */
dev = makedev(kbd_cdevsw.d_maj, kbd->kb_index);
if (dev->si_drv1)
free(dev->si_drv1, M_DEVBUF);
destroy_dev(dev);
return 0;
}

View File

@ -158,6 +158,7 @@ typedef struct keyboard_switch {
/* keyboard driver */
typedef struct keyboard_driver {
SLIST_ENTRY(keyboard_driver) link;
char *name;
keyboard_switch_t *kbdsw;
int (*configure)(int); /* backdoor for the console driver */
@ -167,7 +168,7 @@ typedef struct keyboard_driver {
#define KEYBOARD_DRIVER(name, sw, config) \
static struct keyboard_driver name##_kbd_driver = { \
#name, &sw, config \
{ NULL }, #name, &sw, config \
}; \
DATA_SET(kbddriver_set, name##_kbd_driver);
@ -176,6 +177,8 @@ extern keyboard_switch_t **kbdsw;
extern struct linker_set kbddriver_set;
/* functions for the keyboard driver */
int kbd_add_driver(keyboard_driver_t *driver);
int kbd_delete_driver(keyboard_driver_t *driver);
int kbd_register(keyboard_t *kbd);
int kbd_unregister(keyboard_t *kbd);
keyboard_switch_t *kbd_get_switch(char *driver);

View File

@ -51,12 +51,10 @@
#include <sys/module.h>
#include <sys/bus.h>
#include <machine/clock.h>
#include <sys/tty.h>
#include <sys/file.h>
#include <sys/select.h>
#include <sys/proc.h>
#include <sys/vnode.h>
#include <sys/poll.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbhid.h>
@ -66,7 +64,6 @@
#include <dev/usb/usb_quirks.h>
#include <dev/usb/hid.h>
#include <sys/conf.h>
#include <dev/kbd/kbdreg.h>
#define UKBD_EMULATE_ATSCANCODE 1
@ -115,6 +112,7 @@ typedef void usbd_intr_t(usbd_xfer_handle, usbd_private_handle, usbd_status);
typedef void usbd_disco_t(void *);
static usbd_intr_t ukbd_intr;
static int ukbd_driver_load(module_t mod, int what, void *arg);
USB_DECLARE_DRIVER(ukbd);
@ -215,7 +213,7 @@ ukbd_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
(*kbdsw[kbd->kb_index]->intr)(kbd, (void *)status);
}
DRIVER_MODULE(ukbd, uhub, ukbd_driver, ukbd_devclass, usbd_driver_load, 0);
DRIVER_MODULE(ukbd, uhub, ukbd_driver, ukbd_devclass, ukbd_driver_load, 0);
#include <machine/limits.h>
#include <machine/console.h>
@ -1227,6 +1225,12 @@ ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
default:
splx(s);
return genkbd_commonioctl(kbd, cmd, arg);
#ifdef UKBD_DEBUG
case USB_SETDEBUG:
ukbddebug = *(int *)arg;
break;
#endif
}
splx(s);
@ -1426,3 +1430,17 @@ keycode2scancode(int keycode, int shift, int up)
return (scancode | (up ? SCAN_RELEASE : SCAN_PRESS));
}
#endif /* UKBD_EMULATE_ATSCANCODE */
static int
ukbd_driver_load(module_t mod, int what, void *arg)
{
switch (what) {
case MOD_LOAD:
kbd_add_driver(&ukbd_kbd_driver);
break;
case MOD_UNLOAD:
kbd_delete_driver(&ukbd_kbd_driver);
break;
}
return usbd_driver_load(mod, what, 0);
}