diff options
author | wkoszek <wkoszek@FreeBSD.org> | 2007-12-29 21:55:25 +0000 |
---|---|---|
committer | wkoszek <wkoszek@FreeBSD.org> | 2007-12-29 21:55:25 +0000 |
commit | 8a0ce839351386ec837779aa9f63b575cf8d096a (patch) | |
tree | 1c319020fe289b1aa63eb5ce1ee13396a294df02 /sys/dev/kbd | |
parent | 94cf0432f599e4d9a832f18a63279ff4e4166932 (diff) | |
download | FreeBSD-src-8a0ce839351386ec837779aa9f63b575cf8d096a.zip FreeBSD-src-8a0ce839351386ec837779aa9f63b575cf8d096a.tar.gz |
Remove explicit calls to keyboard methods with their respective variants
implemented with macros. This patch improves code readability. Reasoning
behind kbdd_* is a "keyboard discipline".
List of macros is supposed to be complete--all methods of keyboard_switch
should have their respective macros from now on.
Functionally, this code should be no-op. My intention is to leave current
behaviour of code as is.
Glanced at by: rwatson
Reviewed by: emax, marcel
Approved by: cognet
Diffstat (limited to 'sys/dev/kbd')
-rw-r--r-- | sys/dev/kbd/kbd.c | 29 | ||||
-rw-r--r-- | sys/dev/kbd/kbdreg.h | 44 |
2 files changed, 56 insertions, 17 deletions
diff --git a/sys/dev/kbd/kbd.c b/sys/dev/kbd/kbd.c index 462983f..15a3e22 100644 --- a/sys/dev/kbd/kbd.c +++ b/sys/dev/kbd/kbd.c @@ -219,8 +219,7 @@ kbd_register(keyboard_t *kbd) strcpy(ki.kb_name, kbd->kb_name); ki.kb_unit = kbd->kb_unit; - (*kbdsw[mux->kb_index]->ioctl) - (mux, KBADDKBD, (caddr_t) &ki); + kbdd_ioctl(mux, KBADDKBD, (caddr_t) &ki); } return (index); @@ -237,8 +236,7 @@ kbd_register(keyboard_t *kbd) strcpy(ki.kb_name, kbd->kb_name); ki.kb_unit = kbd->kb_unit; - (*kbdsw[mux->kb_index]->ioctl) - (mux, KBADDKBD, (caddr_t) &ki); + kbdd_ioctl(mux, KBADDKBD, (caddr_t) &ki); } return (index); @@ -363,7 +361,7 @@ kbd_allocate(char *driver, int unit, void *id, kbd_callback_func_t *func, KBD_BUSY(keyboard[index]); keyboard[index]->kb_callback.kc_func = func; keyboard[index]->kb_callback.kc_arg = arg; - (*kbdsw[index]->clear_state)(keyboard[index]); + kbdd_clear_state(keyboard[index]); } splx(s); return (index); @@ -385,7 +383,7 @@ kbd_release(keyboard_t *kbd, void *id) KBD_UNBUSY(kbd); kbd->kb_callback.kc_func = NULL; kbd->kb_callback.kc_arg = NULL; - (*kbdsw[kbd->kb_index]->clear_state)(kbd); + kbdd_clear_state(kbd); error = 0; } splx(s); @@ -664,7 +662,7 @@ genkbdioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread * kbd = kbd_get_keyboard(KBD_INDEX(dev)); if ((kbd == NULL) || !KBD_IS_VALID(kbd)) return (ENXIO); - error = (*kbdsw[kbd->kb_index]->ioctl)(kbd, cmd, arg); + error = kbdd_ioctl(kbd, cmd, arg); if (error == ENOIOCTL) error = ENODEV; return (error); @@ -723,12 +721,12 @@ genkbd_event(keyboard_t *kbd, int event, void *arg) } /* obtain the current key input mode */ - if ((*kbdsw[kbd->kb_index]->ioctl)(kbd, KDGKBMODE, (caddr_t)&mode)) + if (kbdd_ioctl(kbd, KDGKBMODE, (caddr_t)&mode)) mode = K_XLATE; /* read all pending input */ - while ((*kbdsw[kbd->kb_index]->check_char)(kbd)) { - c = (*kbdsw[kbd->kb_index]->read_char)(kbd, FALSE); + while (kbdd_check_char(kbd)) { + c = kbdd_read_char(kbd, FALSE); if (c == NOKEY) continue; if (c == ERRKEY) /* XXX: ring bell? */ @@ -771,8 +769,7 @@ genkbd_event(keyboard_t *kbd, int event, void *arg) putc(KEYCHAR(c), &sc->gkb_q); break; case FKEY | SPCLKEY: /* a function key, return string */ - cp = (*kbdsw[kbd->kb_index]->get_fkeystr)(kbd, - KEYCHAR(c), &len); + cp = kbdd_get_fkeystr(kbd, KEYCHAR(c), &len); if (cp != NULL) { while (len-- > 0) putc(*cp++, &sc->gkb_q); @@ -1110,7 +1107,7 @@ genkbd_diag(keyboard_t *kbd, int level) (s) |= l ## DOWN; \ (s) ^= l ## ED; \ i = (s) & LOCK_MASK; \ - (*kbdsw[(k)->kb_index]->ioctl)((k), KDSETLED, (caddr_t)&i); \ + kbdd_ioctl((k), KDSETLED, (caddr_t)&i); \ } static u_int @@ -1270,8 +1267,7 @@ genkbd_keyaction(keyboard_t *kbd, int keycode, int up, int *shiftstate, #else state &= ~CLKED; i = state & LOCK_MASK; - (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED, - (caddr_t)&i); + kbdd_ioctl(kbd, KDSETLED, (caddr_t)&i); #endif break; case SLK: @@ -1307,8 +1303,7 @@ genkbd_keyaction(keyboard_t *kbd, int keycode, int up, int *shiftstate, #else state |= CLKED; i = state & LOCK_MASK; - (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED, - (caddr_t)&i); + kbdd_ioctl(kbd, KDSETLED, (caddr_t)&i); #endif break; case SLK: diff --git a/sys/dev/kbd/kbdreg.h b/sys/dev/kbd/kbdreg.h index 184c607..5b81123 100644 --- a/sys/dev/kbd/kbdreg.h +++ b/sys/dev/kbd/kbdreg.h @@ -157,6 +157,50 @@ typedef struct keyboard_switch { kbd_diag_t *diag; } keyboard_switch_t; +/* + * Keyboard disciplines: call actual handlers via kbdsw[]. + */ +#define kbdd_probe(kbd, unit, arg, flags) \ + (*kbdsw[(kbd)->kb_index]->probe)((unit), (arg), (flags)) +#define kbdd_init(kbd, unit, kbdpp, arg, flags) \ + (*kbdsw[(kbd)->kb_index]->init)((unit), (kbdpp), (arg), (flags)) +#define kbdd_term(kbd) \ + (*kbdsw[(kbd)->kb_index]->term)((kbd)) +#define kbdd_intr(kbd, arg) \ + (*kbdsw[(kbd)->kb_index]->intr)((kbd), (arg)) +#define kbdd_test_if(kbd) \ + (*kbdsw[(kbd)->kb_index]->test_if)((kbd)) +#define kbdd_enable(kbd) \ + (*kbdsw[(kbd)->kb_index]->enable)((kbd)) +#define kbdd_disable(kbd) \ + (*kbdsw[(kbd)->kb_index]->disable)((kbd)) +#define kbdd_read(kbd, wait) \ + (*kbdsw[(kbd)->kb_index]->read)((kbd), (wait)) +#define kbdd_check(kbd) \ + (*kbdsw[(kbd)->kb_index]->check)((kbd)) +#define kbdd_read_char(kbd, wait) \ + (*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait)) +#define kbdd_check_char(kbd) \ + (*kbdsw[(kbd)->kb_index]->check_char)((kbd)) +#define kbdd_ioctl(kbd, cmd, arg) \ + (((kbd) == NULL) ? \ + ENODEV : \ + (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg))) +#define kbdd_lock(kbd, lockf) \ + (*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf)) +#define kbdd_clear_state(kbd) \ + (*kbdsw[(kbd)->kb_index]->clear_state)((kbd)) +#define kbdd_get_state(kbd, buf, len) \ + (*kbdsw[(kbd)->kb_index]->get_state)((kbd), (buf), (len)) +#define kbdd_set_state(kbd, buf, len) \ + (*kbdsw[(kbd)->kb_index]->set_state)((kbd), (buf), (len)) +#define kbdd_get_fkeystr(kbd, fkey, len) \ + (*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len)) +#define kbdd_poll(kbd, on) \ + (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on)) +#define kbdd_diag(kbd, level) \ + (*kbdsw[(kbd)->kb_index]->diag)((kbd), (leve)) + /* keyboard driver */ typedef struct keyboard_driver { SLIST_ENTRY(keyboard_driver) link; |