From d2f154c95ec08935bbf8f422afe0b3f04934d4fb Mon Sep 17 00:00:00 2001 From: Jake Burkholder Date: Tue, 11 Nov 2003 07:33:24 +0000 Subject: Add a uart attachment/syscons keyboard driver for sun keyboards. In theory this will work with any uart backend, currently supported hardware uses either ns8250 or z8530. --- sys/dev/uart/uart_kbd_sun.c | 529 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 529 insertions(+) create mode 100644 sys/dev/uart/uart_kbd_sun.c (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c new file mode 100644 index 000000000000..7b99ec298af3 --- /dev/null +++ b/sys/dev/uart/uart_kbd_sun.c @@ -0,0 +1,529 @@ +/*- + * Copyright (c) 2003 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include "opt_kbd.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include + +#include +#include + +#include "uart_if.h" + +#define SUNKBD_BUF_SIZE 128 + +#define TODO printf("%s: unimplemented", __func__) + +struct sunkbd_softc { + keyboard_t sc_kbd; + struct uart_softc *sc_uart; + struct uart_devinfo *sc_sysdev; + + struct callout sc_repeat_callout; + int sc_repeat_key; + + int sc_accents; + int sc_mode; + int sc_polling; + int sc_repeating; + int sc_state; +}; + +static int sunkbd_configure(int flags); +static int sunkbd_probe_keyboard(struct uart_devinfo *di); + +static int sunkbd_probe(int unit, void *arg, int flags); +static int sunkbd_init(int unit, keyboard_t **kbdp, void *arg, int flags); +static int sunkbd_term(keyboard_t *kbd); +static int sunkbd_intr(keyboard_t *kbd, void *arg); +static int sunkbd_test_if(keyboard_t *kbd); +static int sunkbd_enable(keyboard_t *kbd); +static int sunkbd_disable(keyboard_t *kbd); +static int sunkbd_read(keyboard_t *kbd, int wait); +static int sunkbd_check(keyboard_t *kbd); +static u_int sunkbd_read_char(keyboard_t *kbd, int wait); +static int sunkbd_check_char(keyboard_t *kbd); +static int sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data); +static int sunkbd_lock(keyboard_t *kbd, int lock); +static void sunkbd_clear_state(keyboard_t *kbd); +static int sunkbd_get_state(keyboard_t *kbd, void *buf, size_t len); +static int sunkbd_set_state(keyboard_t *kbd, void *buf, size_t len); +static int sunkbd_poll_mode(keyboard_t *kbd, int on); +static void sunkbd_diag(keyboard_t *kbd, int level); + +static void sunkbd_repeat(void *v); + +static keyboard_switch_t sunkbdsw = { + sunkbd_probe, + sunkbd_init, + sunkbd_term, + sunkbd_intr, + sunkbd_test_if, + sunkbd_enable, + sunkbd_disable, + sunkbd_read, + sunkbd_check, + sunkbd_read_char, + sunkbd_check_char, + sunkbd_ioctl, + sunkbd_lock, + sunkbd_clear_state, + sunkbd_get_state, + sunkbd_set_state, + genkbd_get_fkeystr, + sunkbd_poll_mode, + sunkbd_diag +}; + +KEYBOARD_DRIVER(sunkbd, sunkbdsw, sunkbd_configure); + +static struct sunkbd_softc sunkbd_softc; +static struct uart_devinfo uart_keyboard; + +static fkeytab_t fkey_tab[96] = { +/* 01-04 */ {"\033[M", 3}, {"\033[N", 3}, {"\033[O", 3}, {"\033[P", 3}, +/* 05-08 */ {"\033[Q", 3}, {"\033[R", 3}, {"\033[S", 3}, {"\033[T", 3}, +/* 09-12 */ {"\033[U", 3}, {"\033[V", 3}, {"\033[W", 3}, {"\033[X", 3}, +/* 13-16 */ {"\033[Y", 3}, {"\033[Z", 3}, {"\033[a", 3}, {"\033[b", 3}, +/* 17-20 */ {"\033[c", 3}, {"\033[d", 3}, {"\033[e", 3}, {"\033[f", 3}, +/* 21-24 */ {"\033[g", 3}, {"\033[h", 3}, {"\033[i", 3}, {"\033[j", 3}, +/* 25-28 */ {"\033[k", 3}, {"\033[l", 3}, {"\033[m", 3}, {"\033[n", 3}, +/* 29-32 */ {"\033[o", 3}, {"\033[p", 3}, {"\033[q", 3}, {"\033[r", 3}, +/* 33-36 */ {"\033[s", 3}, {"\033[t", 3}, {"\033[u", 3}, {"\033[v", 3}, +/* 37-40 */ {"\033[w", 3}, {"\033[x", 3}, {"\033[y", 3}, {"\033[z", 3}, +/* 41-44 */ {"\033[@", 3}, {"\033[[", 3}, {"\033[\\",3}, {"\033[]", 3}, +/* 45-48 */ {"\033[^", 3}, {"\033[_", 3}, {"\033[`", 3}, {"\033[{", 3}, +/* 49-52 */ {"\033[H", 3}, {"\033[A", 3}, {"\033[I", 3}, {"-" , 1}, +/* 53-56 */ {"\033[D", 3}, {"\033[E", 3}, {"\033[C", 3}, {"+" , 1}, +/* 57-60 */ {"\033[F", 3}, {"\033[B", 3}, {"\033[G", 3}, {"\033[L", 3}, +/* 61-64 */ {"\177", 1}, {"\033[J", 3}, {"\033[~", 3}, {"\033[}", 3}, +/* 65-68 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 69-72 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 73-76 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 77-80 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 81-84 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 85-88 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 89-92 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} , +/* 93-96 */ {"", 0} , {"", 0} , {"", 0} , {"", 0} +}; + +static int +sunkbd_probe_keyboard(struct uart_devinfo *di) +{ + int tries; + + for (tries = 5; tries != 0; tries--) { + int ltries; + + uart_putc(di, SKBD_CMD_RESET); + for (ltries = 1000; ltries != 0; ltries--) { + if (uart_poll(di) == SKBD_RSP_RESET) + break; + DELAY(1000); + } + if (ltries == 0) + continue; + for (ltries = 1000; ltries != 0; ltries--) { + if (uart_poll(di) == SKBD_RSP_IDLE) + break; + DELAY(1000); + } + if (ltries == 0) + continue; + uart_putc(di, SKBD_CMD_LAYOUT); + if (uart_getc(di) != SKBD_RSP_LAYOUT) + break; + return (uart_getc(di)); + } + return (-1); +} + +static int sunkbd_attach(struct uart_softc *sc); +static void sunkbd_uart_intr(void *arg); + +static int +sunkbd_configure(int flags) +{ + struct sunkbd_softc *sc; + + if (uart_cpu_getdev(UART_DEV_KEYBOARD, &uart_keyboard)) + return (0); + if (uart_probe(&uart_keyboard)) + return (0); + uart_init(&uart_keyboard); + if (sunkbd_probe_keyboard(&uart_keyboard) == -1) + return (0); + uart_keyboard.type = UART_DEV_KEYBOARD; + uart_keyboard.attach = sunkbd_attach; + uart_add_sysdev(&uart_keyboard); + + sc = &sunkbd_softc; + callout_init(&sc->sc_repeat_callout, 0); + sc->sc_repeat_key = -1; + sc->sc_repeating = 0; + + kbd_init_struct(&sc->sc_kbd, "sunkbd", KB_OTHER, 0, 0, 0, 0); + kbd_set_maps(&sc->sc_kbd, &keymap_sun_us_unix_kbd, + &accentmap_sun_us_unix_kbd, fkey_tab, + sizeof(fkey_tab) / sizeof(fkey_tab[0])); + sc->sc_mode = K_XLATE; + kbd_register(&sc->sc_kbd); + + sc->sc_sysdev = &uart_keyboard; + + return (0); +} + +static int +sunkbd_attach(struct uart_softc *sc) +{ + + if (sc->sc_sysdev != NULL) { + sunkbd_softc.sc_uart = sc; + + kbd_attach(&sunkbd_softc.sc_kbd); + sunkbd_enable(&sunkbd_softc.sc_kbd); + + swi_add(&tty_ithd, uart_driver_name, sunkbd_uart_intr, + &sunkbd_softc, SWI_TTY, INTR_TYPE_TTY, &sc->sc_softih); + + sc->sc_opened = 1; + } + + return (0); +} + +static void +sunkbd_uart_intr(void *arg) +{ + struct sunkbd_softc *sc = arg; + int pend; + + if (sc->sc_uart->sc_leaving) + return; + + pend = atomic_readandclear_32(&sc->sc_uart->sc_ttypend); + if (!(pend & UART_IPEND_MASK)) + return; + + if (pend & UART_IPEND_RXREADY) { + if (KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) { + sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd, + KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg); + } + } + +} + +static int +sunkbd_probe(int unit, void *arg, int flags) +{ + TODO; + return (0); +} + +static int +sunkbd_init(int unit, keyboard_t **kbdp, void *arg, int flags) +{ + TODO; + return (0); +} + +static int +sunkbd_term(keyboard_t *kbd) +{ + TODO; + return (0); +} + +static int +sunkbd_intr(keyboard_t *kbd, void *arg) +{ + TODO; + return (0); +} + +static int +sunkbd_test_if(keyboard_t *kbd) +{ + TODO; + return (0); +} + +static int +sunkbd_enable(keyboard_t *kbd) +{ + KBD_ACTIVATE(kbd); + return (0); +} + +static int +sunkbd_disable(keyboard_t *kbd) +{ + KBD_DEACTIVATE(kbd); + return (0); +} + +static int +sunkbd_read(keyboard_t *kbd, int wait) +{ + TODO; + return (0); +} + +static int +sunkbd_check(keyboard_t *kbd) +{ + TODO; + return (0); +} + +static u_int +sunkbd_read_char(keyboard_t *kbd, int wait) +{ + struct sunkbd_softc *sc; + int action; + int key; + + sc = (struct sunkbd_softc *)kbd; + if (sc->sc_repeating) { + sc->sc_repeating = 0; + callout_reset(&sc->sc_repeat_callout, hz / 10, + sunkbd_repeat, sc); + key = sc->sc_repeat_key; + if (sc->sc_mode == K_RAW) + return (key); + else + return genkbd_keyaction(kbd, key & 0x7f, key & 0x80, + &sc->sc_state, &sc->sc_accents); + } + + for (;;) { + /* XXX compose */ + + if (sc->sc_uart != NULL && !uart_rx_empty(sc->sc_uart)) { + key = uart_rx_get(sc->sc_uart); + } else if (sc->sc_polling != 0 && sc->sc_sysdev != NULL) { + if (wait) + key = uart_getc(sc->sc_sysdev); + else if ((key = uart_poll(sc->sc_sysdev)) == -1) + return (NOKEY); + } else { + return (NOKEY); + } + + switch (key) { + case SKBD_RSP_IDLE: + break; + default: + ++kbd->kb_count; + + if ((key & 0x80) == 0) { + callout_reset(&sc->sc_repeat_callout, hz / 2, + sunkbd_repeat, sc); + sc->sc_repeat_key = key; + } else { + if (sc->sc_repeat_key == (key & 0x7f)) { + callout_stop(&sc->sc_repeat_callout); + sc->sc_repeat_key = -1; + } + } + + if (sc->sc_mode == K_RAW) + return (key); + + action = genkbd_keyaction(kbd, key & 0x7f, key & 0x80, + &sc->sc_state, &sc->sc_accents); + if (action != NOKEY) + return (action); + break; + } + } + return (0); +} + +static int +sunkbd_check_char(keyboard_t *kbd) +{ + TODO; + return (0); +} + +static int +sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) +{ + struct sunkbd_softc *sc; + int error; + + sc = (struct sunkbd_softc *)kbd; + error = 0; + switch (cmd) { + case KDGKBMODE: + *(int *)data = sc->sc_mode; + break; + case KDSKBMODE: + switch (*(int *)data) { + case K_XLATE: + if (sc->sc_mode != K_XLATE) { + /* make lock key state and LED state match */ + sc->sc_state &= ~LOCK_MASK; + sc->sc_state |= KBD_LED_VAL(kbd); + } + /* FALLTHROUGH */ + case K_RAW: + case K_CODE: + if (sc->sc_mode != *(int *)data) { + sunkbd_clear_state(kbd); + sc->sc_mode = *(int *)data; + } + break; + default: + error = EINVAL; + break; + } + break; + case KDGETLED: + *(int *)data = KBD_LED_VAL(kbd); + break; + case KDSETLED: + if (*(int *)data & ~LOCK_MASK) { + error = EINVAL; + break; + } + if (sc->sc_uart == NULL) + break; + sc->sc_uart->sc_txdatasz = 2; + sc->sc_uart->sc_txbuf[0] = SKBD_CMD_SETLED; + sc->sc_uart->sc_txbuf[1] = 0; + if (*(int *)data & CLKED) + sc->sc_uart->sc_txbuf[1] |= SKBD_LED_CAPSLOCK; + if (*(int *)data & NLKED) + sc->sc_uart->sc_txbuf[1] |= SKBD_LED_NUMLOCK; + if (*(int *)data & SLKED) + sc->sc_uart->sc_txbuf[1] |= SKBD_LED_SCROLLLOCK; + UART_TRANSMIT(sc->sc_uart); + KBD_LED_VAL(kbd) = *(int *)data; + break; + case KDGKBSTATE: + *(int *)data = sc->sc_state & LOCK_MASK; + break; + case KDSKBSTATE: + if (*(int *)data & ~LOCK_MASK) { + error = EINVAL; + break; + } + sc->sc_state &= ~LOCK_MASK; + sc->sc_state |= *(int *)data; + break; + case KDSETREPEAT: + case KDSETRAD: + break; + case PIO_KEYMAP: + case PIO_KEYMAPENT: + case PIO_DEADKEYMAP: + default: + return (genkbd_commonioctl(kbd, cmd, data)); + } + return (error); +} + +static int +sunkbd_lock(keyboard_t *kbd, int lock) +{ + TODO; + return (0); +} + +static void +sunkbd_clear_state(keyboard_t *kbd) +{ + /* TODO; */ +} + +static int +sunkbd_get_state(keyboard_t *kbd, void *buf, size_t len) +{ + TODO; + return (0); +} + +static int +sunkbd_set_state(keyboard_t *kbd, void *buf, size_t len) +{ + TODO; + return (0); +} + +static int +sunkbd_poll_mode(keyboard_t *kbd, int on) +{ + struct sunkbd_softc *sc; + + sc = (struct sunkbd_softc *)kbd; + if (on) + sc->sc_polling++; + else + sc->sc_polling--; + return (0); +} + +static void +sunkbd_diag(keyboard_t *kbd, int level) +{ + TODO; +} + +static void +sunkbd_repeat(void *v) +{ + struct sunkbd_softc *sc = v; + + if (sc->sc_repeat_key != -1) { + sc->sc_repeating = 1; + sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd, + KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg); + } +} -- cgit v1.3 From af81ff3f490cce8931d10f066274f8cd451b3777 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Fri, 2 Apr 2004 05:59:06 +0000 Subject: Call kbd_attach() only when KBD_INSTALL_CDEV is enabled as the function is only defined in that case. --- sys/dev/uart/uart_kbd_sun.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index 7b99ec298af3..05254182c30c 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -224,7 +224,9 @@ sunkbd_attach(struct uart_softc *sc) if (sc->sc_sysdev != NULL) { sunkbd_softc.sc_uart = sc; +#ifdef KBD_INSTALL_CDEV kbd_attach(&sunkbd_softc.sc_kbd); +#endif sunkbd_enable(&sunkbd_softc.sc_kbd); swi_add(&tty_ithd, uart_driver_name, sunkbd_uart_intr, -- cgit v1.3 From a2e25ee10d621e4710ffe597c26aaf5328c9dc1e Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Mon, 31 Jan 2005 04:31:22 +0000 Subject: Add the keyboard system device before we probe for the keyboard. The presence or absence of a keyboard does not change whether an UART is designed as a keyboard port or not and thus whether we can use the port as a TTY or not. We now call sunkbd_attach() even when we didn't previously find a keyboard. Emit a useful message stating that no keyboard was found, but don't do anything else. MFC after: 5 days --- sys/dev/uart/uart_kbd_sun.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index 05254182c30c..034965959332 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -194,12 +194,14 @@ sunkbd_configure(int flags) if (uart_probe(&uart_keyboard)) return (0); uart_init(&uart_keyboard); - if (sunkbd_probe_keyboard(&uart_keyboard) == -1) - return (0); + uart_keyboard.type = UART_DEV_KEYBOARD; uart_keyboard.attach = sunkbd_attach; uart_add_sysdev(&uart_keyboard); + if (sunkbd_probe_keyboard(&uart_keyboard) == -1) + return (0); + sc = &sunkbd_softc; callout_init(&sc->sc_repeat_callout, 0); sc->sc_repeat_key = -1; @@ -221,6 +223,15 @@ static int sunkbd_attach(struct uart_softc *sc) { + /* + * Don't attach if we didn't probe the keyboard. Note that + * the UART is still marked as a system device in that case. + */ + if (sunkbd_softc.sc_sysdev == NULL) { + device_printf(sc->sc_dev, "keyboard not present\n"); + return (0); + } + if (sc->sc_sysdev != NULL) { sunkbd_softc.sc_uart = sc; -- cgit v1.3 From 3b8c3ece320af51df07b7d438ee281b5b9f050d0 Mon Sep 17 00:00:00 2001 From: Marius Strobl Date: Sat, 21 May 2005 20:26:30 +0000 Subject: - Sprinkle some KBD_IS_* and KBD_*_DONE macros in sunkbd_configure() as a band-aid allowing to call this function savely multiple times, e.g. during sckbdprobe() and sc_probe_unit(). Otherwise calling it a second time results in a non-working keyboard. This needs a lot of more work to actually do the right thing and work like expected. - Let sunkbd_configure() return the number of the found keyboards, i.e. 1 in case probing succeeds, as it's expected. The return values of the keyboard configure functions however currently aren't checked so this doesn't make a difference at the moment. - Use FBSDID. --- sys/dev/uart/uart_kbd_sun.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index 034965959332..97c8bc5efe31 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -22,10 +22,11 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ +#include +__FBSDID("$FreeBSD$"); + #include "opt_kbd.h" #include @@ -189,15 +190,21 @@ sunkbd_configure(int flags) { struct sunkbd_softc *sc; - if (uart_cpu_getdev(UART_DEV_KEYBOARD, &uart_keyboard)) - return (0); - if (uart_probe(&uart_keyboard)) - return (0); - uart_init(&uart_keyboard); + if (KBD_IS_CONFIGURED(&sunkbd_softc.sc_kbd)) + goto found; - uart_keyboard.type = UART_DEV_KEYBOARD; - uart_keyboard.attach = sunkbd_attach; - uart_add_sysdev(&uart_keyboard); + if (!KBD_IS_INITIALIZED(&sunkbd_softc.sc_kbd)) { + if (uart_cpu_getdev(UART_DEV_KEYBOARD, &uart_keyboard)) + return (0); + if (uart_probe(&uart_keyboard)) + return (0); + uart_init(&uart_keyboard); + + uart_keyboard.type = UART_DEV_KEYBOARD; + uart_keyboard.attach = sunkbd_attach; + uart_add_sysdev(&uart_keyboard); + KBD_INIT_DONE(&sunkbd_softc.sc_kbd); + } if (sunkbd_probe_keyboard(&uart_keyboard) == -1) return (0); @@ -215,8 +222,11 @@ sunkbd_configure(int flags) kbd_register(&sc->sc_kbd); sc->sc_sysdev = &uart_keyboard; + KBD_CONFIG_DONE(&sc->sc_kbd); - return (0); + found: + /* Return number of found keyboards. */ + return (1); } static int -- cgit v1.3 From 3a61f787fbef3a9d79c236c3ef304872c4c752c8 Mon Sep 17 00:00:00 2001 From: Marius Strobl Date: Sat, 4 Jun 2005 21:54:31 +0000 Subject: Replace the band-aid for allowing to call sunkbd_configure() multiple times which was added in the last revision with what should be a proper solution as long as keyboards that were pluggged in after the kernel has fully booted aren't supported. I.e. when sunkbd_configure() is called for the high-level console probe make sure that the keyboard is both successfully configured (i.e. also probed) and attached. The band- aid left the possibility to attach the keyboard device to the high-level console without attaching the keyboard device itself when the keyboard is plugged in after uart(4) attached but before syscons(4) does. --- sys/dev/uart/uart_kbd_sun.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index 97c8bc5efe31..4d024d2ea878 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -190,22 +190,27 @@ sunkbd_configure(int flags) { struct sunkbd_softc *sc; - if (KBD_IS_CONFIGURED(&sunkbd_softc.sc_kbd)) - goto found; - - if (!KBD_IS_INITIALIZED(&sunkbd_softc.sc_kbd)) { - if (uart_cpu_getdev(UART_DEV_KEYBOARD, &uart_keyboard)) - return (0); - if (uart_probe(&uart_keyboard)) + /* + * We are only prepared to be used for the high-level console + * when the keyboard is both configured and attached. + */ + if (!(flags & KB_CONF_PROBE_ONLY)) { + if (KBD_IS_INITIALIZED(&sunkbd_softc.sc_kbd)) + goto found; + else return (0); - uart_init(&uart_keyboard); - - uart_keyboard.type = UART_DEV_KEYBOARD; - uart_keyboard.attach = sunkbd_attach; - uart_add_sysdev(&uart_keyboard); - KBD_INIT_DONE(&sunkbd_softc.sc_kbd); } + if (uart_cpu_getdev(UART_DEV_KEYBOARD, &uart_keyboard)) + return (0); + if (uart_probe(&uart_keyboard)) + return (0); + uart_init(&uart_keyboard); + + uart_keyboard.type = UART_DEV_KEYBOARD; + uart_keyboard.attach = sunkbd_attach; + uart_add_sysdev(&uart_keyboard); + if (sunkbd_probe_keyboard(&uart_keyboard) == -1) return (0); @@ -222,7 +227,6 @@ sunkbd_configure(int flags) kbd_register(&sc->sc_kbd); sc->sc_sysdev = &uart_keyboard; - KBD_CONFIG_DONE(&sc->sc_kbd); found: /* Return number of found keyboards. */ @@ -254,6 +258,7 @@ sunkbd_attach(struct uart_softc *sc) &sunkbd_softc, SWI_TTY, INTR_TYPE_TTY, &sc->sc_softih); sc->sc_opened = 1; + KBD_INIT_DONE(&sunkbd_softc.sc_kbd); } return (0); -- cgit v1.3 From 272174a97c6ca574b8824883b21a3d2147c71e39 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Fri, 10 Mar 2006 19:37:35 +0000 Subject: MFC: Split struct ithd into struct intr_thread and intr_event and associated changes. More details below: Remove public declarations of variables that were forgotten when they were made static. Revision Changes Path 1.31 +0 -1 src/sys/sys/interrupt.h Make sure the interrupt is masked before processing it, or bad things can happen. Revision Changes Path 1.10 +3 -3 src/sys/arm/arm/intr.c Reorganize the interrupt handling code a bit to make a few things cleaner and increase flexibility to allow various different approaches to be tried in the future. - Split struct ithd up into two pieces. struct intr_event holds the list of interrupt handlers associated with interrupt sources. struct intr_thread contains the data relative to an interrupt thread. Currently we still provide a 1:1 relationship of events to threads with the exception that events only have an associated thread if there is at least one threaded interrupt handler attached to the event. This means that on x86 we no longer have 4 bazillion interrupt threads with no handlers. It also means that interrupt events with only INTR_FAST handlers no longer have an associated thread either. - Renamed struct intrhand to struct intr_handler to follow the struct intr_foo naming convention. This did require renaming the powerpc MD struct intr_handler to struct ppc_intr_handler. - INTR_FAST no longer implies INTR_EXCL on all architectures except for powerpc. This means that multiple INTR_FAST handlers can attach to the same interrupt and that INTR_FAST and non-INTR_FAST handlers can attach to the same interrupt. Sharing INTR_FAST handlers may not always be desirable, but having sio(4) and uhci(4) fight over an IRQ isn't fun either. Drivers can always still use INTR_EXCL to ask for an interrupt exclusively. The way this sharing works is that when an interrupt comes in, all the INTR_FAST handlers are executed first, and if any threaded handlers exist, the interrupt thread is scheduled afterwards. This type of layout also makes it possible to investigate using interrupt filters ala OS X where the filter determines whether or not its companion threaded handler should run. - Aside from the INTR_FAST changes above, the impact on MD interrupt code is mostly just 's/ithread/intr_event/'. - A new MI ddb command 'show intrs' walks the list of interrupt events dumping their state. It also has a '/v' verbose switch which dumps info about all of the handlers attached to each event. - We currently don't destroy an interrupt thread when the last threaded handler is removed because it would suck for things like ppbus(8)'s braindead behavior. The code is present, though, it is just under #if 0 for now. - Move the code to actually execute the threaded handlers for an interrrupt event into a separate function so that ithread_loop() becomes more readable. Previously this code was all in the middle of ithread_loop() and indented halfway across the screen. - Made struct intr_thread private to kern_intr.c and replaced td_ithd with a thread private flag TDP_ITHREAD. - In statclock, check curthread against idlethread directly rather than curthread's proc against idlethread's proc. (Not really related to intr changes) Tested on: alpha, amd64, i386, sparc64 Tested on: arm, ia64 (older version of patch by cognet and marcel) Revision Changes Path 1.88 +43 -29 src/sys/alpha/alpha/interrupt.c 1.38 +5 -5 src/sys/alpha/isa/isa.c 1.16 +58 -52 src/sys/amd64/amd64/intr_machdep.c 1.6 +1 -1 src/sys/amd64/include/intr_machdep.h 1.16 +2 -2 src/sys/amd64/isa/atpic.c 1.11 +28 -22 src/sys/arm/arm/intr.c 1.462 +2 -2 src/sys/dev/sio/sio.c 1.6 +1 -1 src/sys/dev/uart/uart_kbd_sun.c 1.24 +2 -2 src/sys/dev/uart/uart_tty.c 1.15 +58 -52 src/sys/i386/i386/intr_machdep.c 1.8 +1 -1 src/sys/i386/include/intr_machdep.h 1.21 +2 -2 src/sys/i386/isa/atpic.c 1.52 +32 -25 src/sys/ia64/ia64/interrupt.c 1.180 +3 -2 src/sys/kern/kern_clock.c 1.127 +437 -270 src/sys/kern/kern_intr.c 1.206 +0 -1 src/sys/kern/subr_witness.c 1.6 +3 -3 src/sys/powerpc/include/intr_machdep.h 1.7 +35 -32 src/sys/powerpc/powerpc/intr_machdep.c 1.14 +1 -1 src/sys/sparc64/include/intr_machdep.h 1.24 +43 -36 src/sys/sparc64/sparc64/intr_machdep.c 1.32 +36 -36 src/sys/sys/interrupt.h 1.440 +1 -3 src/sys/sys/proc.h Catch up with interrupt-thread changes. Revision Changes Path 1.32 +1 -1 src/sys/dev/zs/zs.c Catch up with new interrupt handling code. Revision Changes Path 1.16 +3 -3 src/sys/netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c Catch up with new interrupt handling code. Revision Changes Path 1.162 +2 -2 src/sys/dev/cy/cy.c 1.101 +2 -2 src/sys/dev/rc/rc.c Catch up with new interrupt handling code. Revision Changes Path 1.50 +2 -2 src/sys/dev/cx/if_cx.c 1.41 +1 -1 src/sys/dev/sab/sab.c 1.238 +2 -2 src/sys/pc98/cbus/sio.c Add a swi_remove() function to teardown software interrupt handlers. For now it just calls intr_event_remove_handler(), but at some point it might also be responsible for tearing down interrupt events created via swi_add. Revision Changes Path 1.128 +17 -0 src/sys/kern/kern_intr.c 1.33 +1 -0 src/sys/sys/interrupt.h - Use swi_remove() to teardown swi handlers rather than intr_event_remove_handler(). - Remove tty: prefix from a couple of swi handler names. Revision Changes Path 1.51 +1 -1 src/sys/dev/cx/if_cx.c 1.102 +2 -2 src/sys/dev/rc/rc.c 1.42 +1 -1 src/sys/dev/sab/sab.c 1.25 +1 -1 src/sys/dev/uart/uart_tty.c 1.33 +1 -1 src/sys/dev/zs/zs.c 1.17 +2 -2 src/sys/netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c Remove a stray return statement in the interrupt dispatch function that caused a premature exit after calling a fast interrupt handler and bypassing a much needed critical_exit() and the scheduling of the interrupt thread for non-fast handlers. In short: unbreak :-) Revision Changes Path 1.53 +0 -1 src/sys/ia64/ia64/interrupt.c If we get a stray interrupt, return after logging it. In the extremely rare case of a stray interrupt to an unregistered source (such as a stray interrupt from the 8259As when using APIC), this could result in a page fault when it tried to walk the list of interrupt handlers to execute INTR_FAST handlers. This bug was introduced with the intr_event changes, so it's not present in 5.x or 6.x. Submitted by: Mark Tinguely tinguely at casselton dot net Revision Changes Path 1.17 +1 -0 src/sys/amd64/amd64/intr_machdep.c 1.16 +1 -0 src/sys/i386/i386/intr_machdep.c Approved by: re (scottl) --- sys/alpha/alpha/interrupt.c | 72 +- sys/alpha/isa/isa.c | 10 +- sys/amd64/amd64/intr_machdep.c | 111 ++-- sys/amd64/amd64/local_apic.c | 2 - sys/amd64/include/intr_machdep.h | 2 +- sys/amd64/isa/atpic.c | 4 +- sys/arm/arm/intr.c | 52 +- sys/dev/cx/if_cx.c | 4 +- sys/dev/cy/cy.c | 4 +- sys/dev/rc/rc.c | 4 +- sys/dev/sab/sab.c | 2 +- sys/dev/sio/sio.c | 4 +- sys/dev/uart/uart_kbd_sun.c | 2 +- sys/dev/uart/uart_tty.c | 4 +- sys/dev/zs/zs.c | 2 +- sys/i386/i386/intr_machdep.c | 111 ++-- sys/i386/i386/local_apic.c | 2 - sys/i386/include/intr_machdep.h | 2 +- sys/i386/isa/atpic.c | 4 +- sys/ia64/ia64/interrupt.c | 58 +- sys/kern/kern_clock.c | 5 +- sys/kern/kern_intr.c | 730 +++++++++++++-------- sys/kern/subr_witness.c | 1 - .../bluetooth/drivers/bt3c/ng_bt3c_pccard.c | 6 +- sys/pc98/cbus/sio.c | 4 +- sys/powerpc/include/intr_machdep.h | 6 +- sys/powerpc/powerpc/intr_machdep.c | 67 +- sys/sparc64/include/intr_machdep.h | 2 +- sys/sparc64/sparc64/intr_machdep.c | 79 ++- sys/sys/interrupt.h | 79 +-- sys/sys/proc.h | 5 +- 31 files changed, 842 insertions(+), 598 deletions(-) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/alpha/alpha/interrupt.c b/sys/alpha/alpha/interrupt.c index 6f812bb43687..b4a7500c2fb8 100644 --- a/sys/alpha/alpha/interrupt.c +++ b/sys/alpha/alpha/interrupt.c @@ -325,8 +325,9 @@ LIST_HEAD(alpha_intr_list, alpha_intr); struct alpha_intr { LIST_ENTRY(alpha_intr) list; /* chain handlers in this hash bucket */ uintptr_t vector; /* vector to match */ - struct ithd *ithd; /* interrupt thread */ + struct intr_event *ie; /* interrupt event structure */ volatile long *cntp; /* interrupt counter */ + void (*disable)(uintptr_t); }; static struct mtx alpha_intr_hash_lock; @@ -338,7 +339,7 @@ static void ithds_init(void *dummy) { - mtx_init(&alpha_intr_hash_lock, "ithread table lock", NULL, MTX_SPIN); + mtx_init(&alpha_intr_hash_lock, "intr table", NULL, MTX_SPIN); } SYSINIT(ithds_init, SI_SUB_INTR, SI_ORDER_SECOND, ithds_init, NULL); @@ -371,8 +372,9 @@ alpha_setup_intr(const char *name, uintptr_t vector, driver_intr_t handler, void return ENOMEM; i->vector = vector; i->cntp = cntp; - errcode = ithread_create(&i->ithd, vector, 0, disable, enable, - "intr:"); + i->disable = disable; + errcode = intr_event_create(&i->ie, (void *)vector, 0, + (void (*)(void *))enable, "intr:"); if (errcode) { free(i, M_DEVBUF); return errcode; @@ -384,44 +386,49 @@ alpha_setup_intr(const char *name, uintptr_t vector, driver_intr_t handler, void } /* Second, add this handler. */ - return (ithread_add_handler(i->ithd, name, handler, arg, - ithread_priority(flags), flags, cookiep)); + return (intr_event_add_handler(i->ie, name, handler, arg, + intr_priority(flags), flags, cookiep)); } int alpha_teardown_intr(void *cookie) { - return (ithread_remove_handler(cookie)); + return (intr_event_remove_handler(cookie)); } +/* + * XXX: Alpha doesn't count stray interrupts like some of the other archs. + */ void alpha_dispatch_intr(void *frame, unsigned long vector) { int h = HASHVEC(vector); struct alpha_intr *i; - struct ithd *ithd; /* our interrupt thread */ - struct intrhand *ih; - int error; + struct intr_event *ie; + struct intr_handler *ih; + int error, thread; /* * Walk the hash bucket for this vector looking for this vector's - * interrupt thread. + * interrupt structure. */ for (i = LIST_FIRST(&alpha_intr_hash[h]); i && i->vector != vector; i = LIST_NEXT(i, list)) ; /* nothing */ + + /* No interrupt structure for this vector. */ if (i == NULL) - return; /* no ithread for this vector */ + return; - ithd = i->ithd; - KASSERT(ithd != NULL, ("interrupt vector without a thread")); + ie = i->ie; + KASSERT(ie != NULL, ("interrupt structure without an event")); /* - * As an optimization, if an ithread has no handlers, don't + * As an optimization, if an event has no handlers, don't * schedule it to run. */ - if (TAILQ_EMPTY(&ithd->it_handlers)) + if (TAILQ_EMPTY(&ie->ie_handlers)) return; atomic_add_long(i->cntp, 1); @@ -433,25 +440,32 @@ alpha_dispatch_intr(void *frame, unsigned long vector) */ sched_pin(); + /* Execute all fast interrupt handlers directly. */ + thread = 0; + critical_enter(); + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) { + thread = 1; + continue; + } + CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__, + ih->ih_handler, ih->ih_argument, ih->ih_name); + ih->ih_handler(ih->ih_argument); + } + critical_exit(); + /* - * Handle a fast interrupt if there is no actual thread for this - * interrupt by calling the handler directly without Giant. Note - * that this means that any fast interrupt handler must be MP safe. + * If the ithread needs to run, disable the source and schedule the + * thread. */ - ih = TAILQ_FIRST(&ithd->it_handlers); - if ((ih->ih_flags & IH_FAST) != 0) { - critical_enter(); - ih->ih_handler(ih->ih_argument); - critical_exit(); - } else { - if (ithd->it_disable) { + if (thread) { + if (i->disable) { CTR1(KTR_INTR, "alpha_dispatch_intr: disabling vector 0x%x", i->vector); - ithd->it_disable(ithd->it_vector); + i->disable(i->vector); } - - error = ithread_schedule(ithd); + error = intr_event_schedule_thread(ie); KASSERT(error == 0, ("got an impossible stray interrupt")); } sched_unpin(); diff --git a/sys/alpha/isa/isa.c b/sys/alpha/isa/isa.c index ac08c7b7e646..93ff66cfecab 100644 --- a/sys/alpha/isa/isa.c +++ b/sys/alpha/isa/isa.c @@ -390,14 +390,14 @@ isa_teardown_intr(device_t dev, device_t child, struct resource *irq, void *cookie) { struct isa_intr *ii = cookie; - struct intrhand *ih, *handler = (struct intrhand *)ii->ih; - struct ithd *ithread = handler->ih_ithread; + struct intr_handler *ih, *handler = (struct intr_handler *)ii->ih; + struct intr_event *ie = handler->ih_event; int num_handlers = 0; - mtx_lock(&ithread->it_lock); - TAILQ_FOREACH(ih, &ithread->it_handlers, ih_next) + mtx_lock(&ie->ie_lock); + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) num_handlers++; - mtx_unlock(&ithread->it_lock); + mtx_unlock(&ie->ie_lock); /* * Only disable the interrupt in hardware if there are no diff --git a/sys/amd64/amd64/intr_machdep.c b/sys/amd64/amd64/intr_machdep.c index cd439591f10c..564357824272 100644 --- a/sys/amd64/amd64/intr_machdep.c +++ b/sys/amd64/amd64/intr_machdep.c @@ -57,7 +57,7 @@ #define MAX_STRAY_LOG 5 -typedef void (*mask_fn)(uintptr_t vector); +typedef void (*mask_fn)(void *); static int intrcnt_index; static struct intsrc *interrupt_sources[NUM_IO_INTS]; @@ -87,15 +87,14 @@ intr_register_source(struct intsrc *isrc) vector = isrc->is_pic->pic_vector(isrc); if (interrupt_sources[vector] != NULL) return (EEXIST); - error = ithread_create(&isrc->is_ithread, (uintptr_t)isrc, 0, - (mask_fn)isrc->is_pic->pic_disable_source, + error = intr_event_create(&isrc->is_event, isrc, 0, (mask_fn)isrc->is_pic->pic_enable_source, "irq%d:", vector); if (error) return (error); mtx_lock_spin(&intr_table_lock); if (interrupt_sources[vector] != NULL) { mtx_unlock_spin(&intr_table_lock); - ithread_destroy(isrc->is_ithread); + intr_event_destroy(isrc->is_event); return (EEXIST); } intrcnt_register(isrc); @@ -122,8 +121,8 @@ intr_add_handler(const char *name, int vector, driver_intr_t handler, isrc = intr_lookup_source(vector); if (isrc == NULL) return (EINVAL); - error = ithread_add_handler(isrc->is_ithread, name, handler, arg, - ithread_priority(flags), flags, cookiep); + error = intr_event_add_handler(isrc->is_event, name, handler, arg, + intr_priority(flags), flags, cookiep); if (error == 0) { intrcnt_updatename(isrc); mtx_lock_spin(&intr_table_lock); @@ -147,7 +146,7 @@ intr_remove_handler(void *cookie) { int error; - error = ithread_remove_handler(cookie); + error = intr_event_remove_handler(cookie); #ifdef XXX if (error == 0) intrcnt_updatename(/* XXX */); @@ -170,12 +169,11 @@ void intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) { struct thread *td; - struct ithd *it; - struct intrhand *ih; - int error, vector; + struct intr_event *ie; + struct intr_handler *ih; + int error, vector, thread; td = curthread; - td->td_intr_nesting_level++; /* * We count software interrupts when we process them. The @@ -186,11 +184,7 @@ intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) (*isrc->is_count)++; PCPU_LAZY_INC(cnt.v_intr); - it = isrc->is_ithread; - if (it == NULL) - ih = NULL; - else - ih = TAILQ_FIRST(&it->it_handlers); + ie = isrc->is_event; /* * XXX: We assume that IRQ 0 is only used for the ISA timer @@ -200,40 +194,12 @@ intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) if (vector == 0) clkintr_pending = 1; - if (ih != NULL && ih->ih_flags & IH_FAST) { - /* - * Execute fast interrupt handlers directly. - * To support clock handlers, if a handler registers - * with a NULL argument, then we pass it a pointer to - * a trapframe as its argument. - */ - critical_enter(); - TAILQ_FOREACH(ih, &it->it_handlers, ih_next) { - MPASS(ih->ih_flags & IH_FAST); - CTR3(KTR_INTR, "%s: executing handler %p(%p)", - __func__, ih->ih_handler, - ih->ih_argument == NULL ? iframe : - ih->ih_argument); - if (ih->ih_argument == NULL) - ih->ih_handler(iframe); - else - ih->ih_handler(ih->ih_argument); - } - isrc->is_pic->pic_eoi_source(isrc); - error = 0; - critical_exit(); - } else { - /* - * For stray and threaded interrupts, we mask and EOI the - * source. - */ + /* + * For stray interrupts, mask and EOI the source, bump the + * stray count, and log the condition. + */ + if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers)) { isrc->is_pic->pic_disable_source(isrc, PIC_EOI); - if (ih == NULL) - error = EINVAL; - else - error = ithread_schedule(it); - } - if (error == EINVAL) { (*isrc->is_straycount)++; if (*isrc->is_straycount < MAX_STRAY_LOG) log(LOG_ERR, "stray irq%d\n", vector); @@ -241,6 +207,47 @@ intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) log(LOG_CRIT, "too many stray irq %d's: not logging anymore\n", vector); + return; + } + + /* + * Execute fast interrupt handlers directly. + * To support clock handlers, if a handler registers + * with a NULL argument, then we pass it a pointer to + * an intrframe as its argument. + */ + td->td_intr_nesting_level++; + thread = 0; + critical_enter(); + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) { + thread = 1; + continue; + } + CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__, + ih->ih_handler, ih->ih_argument == NULL ? iframe : + ih->ih_argument, ih->ih_name); + if (ih->ih_argument == NULL) + ih->ih_handler(iframe); + else + ih->ih_handler(ih->ih_argument); + } + + /* + * If there are any threaded handlers that need to run, + * mask the source as well as sending it an EOI. Otherwise, + * just send it an EOI but leave it unmasked. + */ + if (thread) + isrc->is_pic->pic_disable_source(isrc, PIC_EOI); + else + isrc->is_pic->pic_eoi_source(isrc); + critical_exit(); + + /* Schedule the ithread if needed. */ + if (thread) { + error = intr_event_schedule_thread(ie); + KASSERT(error == 0, ("bad stray interrupt")); } td->td_intr_nesting_level--; } @@ -283,7 +290,7 @@ static void intrcnt_updatename(struct intsrc *is) { - intrcnt_setname(is->is_ithread->it_td->td_proc->p_comm, is->is_index); + intrcnt_setname(is->is_event->ie_fullname, is->is_index); } static void @@ -292,7 +299,7 @@ intrcnt_register(struct intsrc *is) char straystr[MAXCOMLEN + 1]; /* mtx_assert(&intr_table_lock, MA_OWNED); */ - KASSERT(is->is_ithread != NULL, ("%s: isrc with no ithread", __func__)); + KASSERT(is->is_event != NULL, ("%s: isrc with no event", __func__)); is->is_index = intrcnt_index; intrcnt_index += 2; snprintf(straystr, MAXCOMLEN + 1, "stray irq%d", @@ -342,7 +349,7 @@ DB_SHOW_COMMAND(irqs, db_show_irqs) db_setup_paging(db_simple_pager, &quit, db_lines_per_page); for (i = 0; i < NUM_IO_INTS && !quit; i++, isrc++) if (*isrc != NULL) - db_dump_ithread((*isrc)->is_ithread, verbose); + db_dump_intr_event((*isrc)->is_event, verbose); } #endif diff --git a/sys/amd64/amd64/local_apic.c b/sys/amd64/amd64/local_apic.c index 33d3aa011bcd..7669b481e634 100644 --- a/sys/amd64/amd64/local_apic.c +++ b/sys/amd64/amd64/local_apic.c @@ -773,11 +773,9 @@ DB_SHOW_COMMAND(apic, db_show_apic) isrc = intr_lookup_source(irq); if (isrc == NULL || verbose == 0) db_printf("IRQ %u\n", irq); -#if 0 else db_dump_intr_event(isrc->is_event, verbose == 2); -#endif } else db_printf("IRQ %u ???\n", irq); } diff --git a/sys/amd64/include/intr_machdep.h b/sys/amd64/include/intr_machdep.h index 21fbc600b73d..370d0c95affe 100644 --- a/sys/amd64/include/intr_machdep.h +++ b/sys/amd64/include/intr_machdep.h @@ -102,7 +102,7 @@ enum { */ struct intsrc { struct pic *is_pic; - struct ithd *is_ithread; + struct intr_event *is_event; u_long *is_count; u_long *is_straycount; u_int is_index; diff --git a/sys/amd64/isa/atpic.c b/sys/amd64/isa/atpic.c index 8b2105ad4517..8aa3d015e6f1 100644 --- a/sys/amd64/isa/atpic.c +++ b/sys/amd64/isa/atpic.c @@ -499,10 +499,10 @@ atpic_handle_intr(void *cookie, struct intrframe iframe) isrc = &atintrs[vec].at_intsrc; /* - * If we don't have an ithread, see if this is a spurious + * If we don't have an event, see if this is a spurious * interrupt. */ - if (isrc->is_ithread == NULL && (vec == 7 || vec == 15)) { + if (isrc->is_event == NULL && (vec == 7 || vec == 15)) { int port, isr; /* diff --git a/sys/arm/arm/intr.c b/sys/arm/arm/intr.c index cb941f736917..5c9c5816a80b 100644 --- a/sys/arm/arm/intr.c +++ b/sys/arm/arm/intr.c @@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include -static struct ithd *ithreads[NIRQ]; +static struct intr_event *intr_events[NIRQ]; static int intrcnt_tab[NIRQ]; static int intrcnt_index = 0; static int last_printed = 0; @@ -61,18 +61,18 @@ void arm_setup_irqhandler(const char *name, void (*hand)(void*), void *arg, int irq, int flags, void **cookiep) { - struct ithd *cur_ith; + struct intr_event *event; int error; if (irq < 0 || irq >= NIRQ) return; - cur_ith = ithreads[irq]; - if (cur_ith == NULL) { - error = ithread_create(&cur_ith, irq, 0, arm_mask_irq, - arm_unmask_irq, "intr%d:", irq); + event = intr_events[irq]; + if (event == NULL) { + error = intr_event_create(&event, (void *)irq, 0, + (void (*)(void *))arm_unmask_irq, "intr%d:", irq); if (error) return; - ithreads[irq] = cur_ith; + intr_events[irq] = event; last_printed += snprintf(intrnames + last_printed, MAXCOMLEN + 1, @@ -82,14 +82,14 @@ arm_setup_irqhandler(const char *name, void (*hand)(void*), void *arg, intrcnt_index++; } - ithread_add_handler(cur_ith, name, hand, arg, - ithread_priority(flags), flags, cookiep); + intr_event_add_handler(event, name, hand, arg, + intr_priority(flags), flags, cookiep); } int arm_remove_irqhandler(void *cookie) { - return (ithread_remove_handler(cookie)); + return (intr_event_remove_handler(cookie)); } void dosoftints(void); @@ -101,28 +101,34 @@ dosoftints(void) void arm_handler_execute(void *frame, int irqnb) { - struct ithd *ithd; - int i; - struct intrhand *ih; + struct intr_event *event; + struct intr_handler *ih; struct thread *td = curthread; + int i, thread; td->td_intr_nesting_level++; while ((i = arm_get_next_irq()) != -1) { + arm_mask_irq(i); intrcnt[intrcnt_tab[i]]++; - ithd = ithreads[i]; - if (!ithd) + event = intr_events[i]; + if (!event || TAILQ_EMPTY(&event->ie_handlers)) continue; - ih = TAILQ_FIRST(&ithd->it_handlers); - if (ih && ih->ih_flags & IH_FAST) { - TAILQ_FOREACH(ih, &ithd->it_handlers, - ih_next) { + + /* Execute fast handlers. */ + thread = 0; + TAILQ_FOREACH(ih, &event->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) + thread = 1; + else ih->ih_handler(ih->ih_argument ? ih->ih_argument : frame); - } - } else if (ih) { - arm_mask_irq(i); - ithread_schedule(ithd); } + + /* Schedule thread if needed. */ + if (thread) + intr_event_schedule_thread(event); + else + arm_unmask_irq(i); } td->td_intr_nesting_level--; } diff --git a/sys/dev/cx/if_cx.c b/sys/dev/cx/if_cx.c index 2d75f97a9d5c..f052a38c27df 100644 --- a/sys/dev/cx/if_cx.c +++ b/sys/dev/cx/if_cx.c @@ -2546,7 +2546,7 @@ static int cx_modevent (module_t mod, int type, void *unused) callout_init (&timeout_handle, cx_mpsafenet?CALLOUT_MPSAFE:0); callout_reset (&timeout_handle, hz*5, cx_timeout, 0); /* Software interrupt. */ - swi_add(&tty_ithd, "cx", cx_softintr, NULL, SWI_TTY, + swi_add(&tty_intr_event, "cx", cx_softintr, NULL, SWI_TTY, (cx_mpsafenet?INTR_MPSAFE:0), &cx_fast_ih); break; case MOD_UNLOAD: @@ -2559,7 +2559,7 @@ static int cx_modevent (module_t mod, int type, void *unused) /* If we were wait it than it reasserted now, just stop it. */ if (!callout_drain (&timeout_handle)) callout_stop (&timeout_handle); - ithread_remove_handler (cx_fast_ih); + swi_remove (cx_fast_ih); --load_count; break; case MOD_SHUTDOWN: diff --git a/sys/dev/cy/cy.c b/sys/dev/cy/cy.c index d6fe330938ec..ee660090877e 100644 --- a/sys/dev/cy/cy.c +++ b/sys/dev/cy/cy.c @@ -428,9 +428,9 @@ cyattach_common(cy_addr cy_iobase, int cy_align) splx(s); if (cy_fast_ih == NULL) { - swi_add(&tty_ithd, "cy", cypoll, NULL, SWI_TTY, 0, + swi_add(&tty_intr_event, "cy", cypoll, NULL, SWI_TTY, 0, &cy_fast_ih); - swi_add(&clk_ithd, "cy", cypoll, NULL, SWI_CLOCK, 0, + swi_add(&clk_intr_event, "cy", cypoll, NULL, SWI_CLOCK, 0, &cy_slow_ih); } ttycreate(tp, NULL, 0, MINOR_CALLOUT, "c%r%r", diff --git a/sys/dev/rc/rc.c b/sys/dev/rc/rc.c index 071dbc777efc..71cc67567ddb 100644 --- a/sys/dev/rc/rc.c +++ b/sys/dev/rc/rc.c @@ -311,7 +311,7 @@ rc_attach(device_t dev) goto fail; } - swi_add(&tty_ithd, "tty:rc", rc_pollcard, sc, SWI_TTY, 0, + swi_add(&tty_intr_event, "rc", rc_pollcard, sc, SWI_TTY, 0, &sc->sc_swicookie); return (0); @@ -336,7 +336,7 @@ rc_detach(device_t dev) error = bus_teardown_intr(dev, sc->sc_irq, sc->sc_hwicookie); if (error) device_printf(dev, "failed to deregister interrupt handler\n"); - ithread_remove_handler(sc->sc_swicookie); + swi_remove(sc->sc_swicookie); rc_release_resources(dev); return (0); diff --git a/sys/dev/sab/sab.c b/sys/dev/sab/sab.c index a41d3282f9a4..20886c8e26ca 100644 --- a/sys/dev/sab/sab.c +++ b/sys/dev/sab/sab.c @@ -321,7 +321,7 @@ sab_attach(device_t dev) for (i = 0; i < SAB_NCHAN; i++) sc->sc_child[i] = device_get_softc(child[i]); - swi_add(&tty_ithd, "tty:sab", sab_softintr, sc, SWI_TTY, + swi_add(&tty_intr_event, "sab", sab_softintr, sc, SWI_TTY, INTR_TYPE_TTY, &sc->sc_softih); if (sabtty_cons != NULL) { diff --git a/sys/dev/sio/sio.c b/sys/dev/sio/sio.c index 4dfabc0c8883..0f4582f3d4d8 100644 --- a/sys/dev/sio/sio.c +++ b/sys/dev/sio/sio.c @@ -1055,9 +1055,9 @@ determined_type: ; printf("\n"); if (sio_fast_ih == NULL) { - swi_add(&tty_ithd, "sio", siopoll, NULL, SWI_TTY, 0, + swi_add(&tty_intr_event, "sio", siopoll, NULL, SWI_TTY, 0, &sio_fast_ih); - swi_add(&clk_ithd, "sio", siopoll, NULL, SWI_CLOCK, 0, + swi_add(&clk_intr_event, "sio", siopoll, NULL, SWI_CLOCK, 0, &sio_slow_ih); } diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index 4d024d2ea878..22e47fa474a5 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -254,7 +254,7 @@ sunkbd_attach(struct uart_softc *sc) #endif sunkbd_enable(&sunkbd_softc.sc_kbd); - swi_add(&tty_ithd, uart_driver_name, sunkbd_uart_intr, + swi_add(&tty_intr_event, uart_driver_name, sunkbd_uart_intr, &sunkbd_softc, SWI_TTY, INTR_TYPE_TTY, &sc->sc_softih); sc->sc_opened = 1; diff --git a/sys/dev/uart/uart_tty.c b/sys/dev/uart/uart_tty.c index 6eb573be44fb..134d80880bfa 100644 --- a/sys/dev/uart/uart_tty.c +++ b/sys/dev/uart/uart_tty.c @@ -377,7 +377,7 @@ uart_tty_attach(struct uart_softc *sc) ttyconsolemode(tp, 0); } - swi_add(&tty_ithd, uart_driver_name, uart_tty_intr, sc, SWI_TTY, + swi_add(&tty_intr_event, uart_driver_name, uart_tty_intr, sc, SWI_TTY, INTR_TYPE_TTY, &sc->sc_softih); ttycreate(tp, NULL, 0, MINOR_CALLOUT, "u%r", unit); @@ -392,7 +392,7 @@ int uart_tty_detach(struct uart_softc *sc) tp = sc->sc_u.u_tty.tp; tp->t_pps = NULL; ttygone(tp); - ithread_remove_handler(sc->sc_softih); + swi_remove(sc->sc_softih); ttyfree(tp); return (0); diff --git a/sys/dev/zs/zs.c b/sys/dev/zs/zs.c index 41c6d8662957..f67f7c584ee2 100644 --- a/sys/dev/zs/zs.c +++ b/sys/dev/zs/zs.c @@ -183,7 +183,7 @@ zs_attach(device_t dev) for (i = 0; i < ZS_NCHAN; i++) sc->sc_child[i] = device_get_softc(child[i]); - swi_add(&tty_ithd, "tty:zs", zs_softintr, sc, SWI_TTY, + swi_add(&tty_intr_event, "zs", zs_softintr, sc, SWI_TTY, INTR_TYPE_TTY, &sc->sc_softih); ZS_WRITE_REG(sc->sc_child[0], 2, sc->sc_child[0]->sc_creg[2]); diff --git a/sys/i386/i386/intr_machdep.c b/sys/i386/i386/intr_machdep.c index 871b25a4bfb6..2b5368d3bc57 100644 --- a/sys/i386/i386/intr_machdep.c +++ b/sys/i386/i386/intr_machdep.c @@ -57,7 +57,7 @@ #define MAX_STRAY_LOG 5 -typedef void (*mask_fn)(uintptr_t vector); +typedef void (*mask_fn)(void *); static int intrcnt_index; static struct intsrc *interrupt_sources[NUM_IO_INTS]; @@ -87,15 +87,14 @@ intr_register_source(struct intsrc *isrc) vector = isrc->is_pic->pic_vector(isrc); if (interrupt_sources[vector] != NULL) return (EEXIST); - error = ithread_create(&isrc->is_ithread, (uintptr_t)isrc, 0, - (mask_fn)isrc->is_pic->pic_disable_source, + error = intr_event_create(&isrc->is_event, isrc, 0, (mask_fn)isrc->is_pic->pic_enable_source, "irq%d:", vector); if (error) return (error); mtx_lock_spin(&intr_table_lock); if (interrupt_sources[vector] != NULL) { mtx_unlock_spin(&intr_table_lock); - ithread_destroy(isrc->is_ithread); + intr_event_destroy(isrc->is_event); return (EEXIST); } intrcnt_register(isrc); @@ -122,8 +121,8 @@ intr_add_handler(const char *name, int vector, driver_intr_t handler, isrc = intr_lookup_source(vector); if (isrc == NULL) return (EINVAL); - error = ithread_add_handler(isrc->is_ithread, name, handler, arg, - ithread_priority(flags), flags, cookiep); + error = intr_event_add_handler(isrc->is_event, name, handler, arg, + intr_priority(flags), flags, cookiep); if (error == 0) { intrcnt_updatename(isrc); mtx_lock_spin(&intr_table_lock); @@ -147,7 +146,7 @@ intr_remove_handler(void *cookie) { int error; - error = ithread_remove_handler(cookie); + error = intr_event_remove_handler(cookie); #ifdef XXX if (error == 0) intrcnt_updatename(/* XXX */); @@ -170,12 +169,11 @@ void intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) { struct thread *td; - struct ithd *it; - struct intrhand *ih; - int error, vector; + struct intr_event *ie; + struct intr_handler *ih; + int error, vector, thread; td = curthread; - td->td_intr_nesting_level++; /* * We count software interrupts when we process them. The @@ -186,11 +184,7 @@ intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) (*isrc->is_count)++; PCPU_LAZY_INC(cnt.v_intr); - it = isrc->is_ithread; - if (it == NULL) - ih = NULL; - else - ih = TAILQ_FIRST(&it->it_handlers); + ie = isrc->is_event; /* * XXX: We assume that IRQ 0 is only used for the ISA timer @@ -200,40 +194,12 @@ intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) if (vector == 0) clkintr_pending = 1; - if (ih != NULL && ih->ih_flags & IH_FAST) { - /* - * Execute fast interrupt handlers directly. - * To support clock handlers, if a handler registers - * with a NULL argument, then we pass it a pointer to - * a trapframe as its argument. - */ - critical_enter(); - TAILQ_FOREACH(ih, &it->it_handlers, ih_next) { - MPASS(ih->ih_flags & IH_FAST); - CTR3(KTR_INTR, "%s: executing handler %p(%p)", - __func__, ih->ih_handler, - ih->ih_argument == NULL ? iframe : - ih->ih_argument); - if (ih->ih_argument == NULL) - ih->ih_handler(iframe); - else - ih->ih_handler(ih->ih_argument); - } - isrc->is_pic->pic_eoi_source(isrc); - error = 0; - critical_exit(); - } else { - /* - * For stray and threaded interrupts, we mask and EOI the - * source. - */ + /* + * For stray interrupts, mask and EOI the source, bump the + * stray count, and log the condition. + */ + if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers)) { isrc->is_pic->pic_disable_source(isrc, PIC_EOI); - if (ih == NULL) - error = EINVAL; - else - error = ithread_schedule(it); - } - if (error == EINVAL) { (*isrc->is_straycount)++; if (*isrc->is_straycount < MAX_STRAY_LOG) log(LOG_ERR, "stray irq%d\n", vector); @@ -241,6 +207,47 @@ intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe) log(LOG_CRIT, "too many stray irq %d's: not logging anymore\n", vector); + return; + } + + /* + * Execute fast interrupt handlers directly. + * To support clock handlers, if a handler registers + * with a NULL argument, then we pass it a pointer to + * an intrframe as its argument. + */ + td->td_intr_nesting_level++; + thread = 0; + critical_enter(); + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) { + thread = 1; + continue; + } + CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__, + ih->ih_handler, ih->ih_argument == NULL ? iframe : + ih->ih_argument, ih->ih_name); + if (ih->ih_argument == NULL) + ih->ih_handler(iframe); + else + ih->ih_handler(ih->ih_argument); + } + + /* + * If there are any threaded handlers that need to run, + * mask the source as well as sending it an EOI. Otherwise, + * just send it an EOI but leave it unmasked. + */ + if (thread) + isrc->is_pic->pic_disable_source(isrc, PIC_EOI); + else + isrc->is_pic->pic_eoi_source(isrc); + critical_exit(); + + /* Schedule the ithread if needed. */ + if (thread) { + error = intr_event_schedule_thread(ie); + KASSERT(error == 0, ("bad stray interrupt")); } td->td_intr_nesting_level--; } @@ -283,7 +290,7 @@ static void intrcnt_updatename(struct intsrc *is) { - intrcnt_setname(is->is_ithread->it_td->td_proc->p_comm, is->is_index); + intrcnt_setname(is->is_event->ie_fullname, is->is_index); } static void @@ -292,7 +299,7 @@ intrcnt_register(struct intsrc *is) char straystr[MAXCOMLEN + 1]; /* mtx_assert(&intr_table_lock, MA_OWNED); */ - KASSERT(is->is_ithread != NULL, ("%s: isrc with no ithread", __func__)); + KASSERT(is->is_event != NULL, ("%s: isrc with no event", __func__)); is->is_index = intrcnt_index; intrcnt_index += 2; snprintf(straystr, MAXCOMLEN + 1, "stray irq%d", @@ -342,7 +349,7 @@ DB_SHOW_COMMAND(irqs, db_show_irqs) db_setup_paging(db_simple_pager, &quit, db_lines_per_page); for (i = 0; i < NUM_IO_INTS && !quit; i++, isrc++) if (*isrc != NULL) - db_dump_ithread((*isrc)->is_ithread, verbose); + db_dump_intr_event((*isrc)->is_event, verbose); } #endif diff --git a/sys/i386/i386/local_apic.c b/sys/i386/i386/local_apic.c index ae9f9aa62087..b226b742a710 100644 --- a/sys/i386/i386/local_apic.c +++ b/sys/i386/i386/local_apic.c @@ -774,11 +774,9 @@ DB_SHOW_COMMAND(apic, db_show_apic) isrc = intr_lookup_source(irq); if (isrc == NULL || verbose == 0) db_printf("IRQ %u\n", irq); -#if 0 else db_dump_intr_event(isrc->is_event, verbose == 2); -#endif } else db_printf("IRQ %u ???\n", irq); } diff --git a/sys/i386/include/intr_machdep.h b/sys/i386/include/intr_machdep.h index 21fbc600b73d..370d0c95affe 100644 --- a/sys/i386/include/intr_machdep.h +++ b/sys/i386/include/intr_machdep.h @@ -102,7 +102,7 @@ enum { */ struct intsrc { struct pic *is_pic; - struct ithd *is_ithread; + struct intr_event *is_event; u_long *is_count; u_long *is_straycount; u_int is_index; diff --git a/sys/i386/isa/atpic.c b/sys/i386/isa/atpic.c index 364272d1c00c..a8daa16c9e04 100644 --- a/sys/i386/isa/atpic.c +++ b/sys/i386/isa/atpic.c @@ -562,10 +562,10 @@ atpic_handle_intr(struct intrframe iframe) isrc = &atintrs[iframe.if_vec].at_intsrc; /* - * If we don't have an ithread, see if this is a spurious + * If we don't have an event, see if this is a spurious * interrupt. */ - if (isrc->is_ithread == NULL && + if (isrc->is_event == NULL && (iframe.if_vec == 7 || iframe.if_vec == 15)) { int port, isr; diff --git a/sys/ia64/ia64/interrupt.c b/sys/ia64/ia64/interrupt.c index 0c83d97117f2..1a0c3d162bba 100644 --- a/sys/ia64/ia64/interrupt.c +++ b/sys/ia64/ia64/interrupt.c @@ -254,7 +254,7 @@ stray: #define IA64_HARDWARE_IRQ_BASE 0x20 struct ia64_intr { - struct ithd *ithd; /* interrupt thread */ + struct intr_event *event; /* interrupt event */ volatile long *cntp; /* interrupt counter */ }; @@ -268,7 +268,7 @@ static void ithds_init(void *dummy) { - mtx_init(&ia64_intrs_lock, "ithread table lock", NULL, MTX_SPIN); + mtx_init(&ia64_intrs_lock, "intr table", NULL, MTX_SPIN); } SYSINIT(ithds_init, SI_SUB_INTR, SI_ORDER_SECOND, ithds_init, NULL); @@ -291,7 +291,7 @@ ia64_setup_intr(const char *name, int irq, driver_intr_t handler, void *arg, { struct ia64_intr *i; int errcode; - int vector = irq + IA64_HARDWARE_IRQ_BASE; + intptr_t vector = irq + IA64_HARDWARE_IRQ_BASE; char *intrname; /* @@ -321,8 +321,8 @@ ia64_setup_intr(const char *name, int irq, driver_intr_t handler, void *arg, memset(intrname, ' ', INTRNAME_LEN - 1); bcopy(name, intrname, strlen(name)); } - errcode = ithread_create(&i->ithd, vector, 0, 0, - ia64_send_eoi, "intr:"); + errcode = intr_event_create(&i->event, (void *)vector, 0, + (void (*)(void *))ia64_send_eoi, "intr:"); if (errcode) { free(i, M_DEVBUF); return errcode; @@ -334,8 +334,8 @@ ia64_setup_intr(const char *name, int irq, driver_intr_t handler, void *arg, } /* Second, add this handler. */ - errcode = ithread_add_handler(i->ithd, name, handler, arg, - ithread_priority(flags), flags, cookiep); + errcode = intr_event_add_handler(i->event, name, handler, arg, + intr_priority(flags), flags, cookiep); if (errcode) return errcode; @@ -346,53 +346,59 @@ int ia64_teardown_intr(void *cookie) { - return (ithread_remove_handler(cookie)); + return (intr_event_remove_handler(cookie)); } void ia64_dispatch_intr(void *frame, unsigned long vector) { struct ia64_intr *i; - struct ithd *ithd; /* our interrupt thread */ - struct intrhand *ih; - int error; + struct intr_event *ie; /* our interrupt event */ + struct intr_handler *ih; + int error, thread; /* * Find the interrupt thread for this vector. */ i = ia64_intrs[vector]; if (i == NULL) - return; /* no ithread for this vector */ + return; /* no event for this vector */ if (i->cntp) atomic_add_long(i->cntp, 1); - ithd = i->ithd; - KASSERT(ithd != NULL, ("interrupt vector without a thread")); + ie = i->event; + KASSERT(ie != NULL, ("interrupt vector without an event")); /* - * As an optimization, if an ithread has no handlers, don't + * As an optimization, if an event has no handlers, don't * schedule it to run. */ - if (TAILQ_EMPTY(&ithd->it_handlers)) + if (TAILQ_EMPTY(&ie->ie_handlers)) return; /* - * Handle a fast interrupt if there is no actual thread for this - * interrupt by calling the handler directly without Giant. Note + * Execute all fast interrupt handlers directly without Giant. Note * that this means that any fast interrupt handler must be MP safe. */ - ih = TAILQ_FIRST(&ithd->it_handlers); - if ((ih->ih_flags & IH_FAST) != 0) { - critical_enter(); + thread = 0; + critical_enter(); + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) { + thread = 1; + continue; + } + CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__, + ih->ih_handler, ih->ih_argument, ih->ih_name); ih->ih_handler(ih->ih_argument); - ia64_send_eoi(vector); - critical_exit(); - return; } + critical_exit(); - error = ithread_schedule(ithd); - KASSERT(error == 0, ("got an impossible stray interrupt")); + if (thread) { + error = intr_event_schedule_thread(ie); + KASSERT(error == 0, ("got an impossible stray interrupt")); + } else + ia64_send_eoi(vector); } #ifdef DDB diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index e2616050bffb..74862cafe54e 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -439,7 +439,8 @@ statclock(frame) * so that we know how much of its real time was spent * in ``non-process'' (i.e., interrupt) work. */ - if ((td->td_ithd != NULL) || td->td_intr_nesting_level >= 2) { + if ((td->td_pflags & TDP_ITHREAD) || + td->td_intr_nesting_level >= 2) { p->p_rux.rux_iticks++; cp_time[CP_INTR]++; } else { @@ -447,7 +448,7 @@ statclock(frame) thread_statclock(0); td->td_sticks++; p->p_rux.rux_sticks++; - if (p != PCPU_GET(idlethread)->td_proc) + if (td != PCPU_GET(idlethread)) cp_time[CP_SYS]++; else cp_time[CP_IDLE]++; diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c index ab189cfb4aa3..dd73c5b45318 100644 --- a/sys/kern/kern_intr.c +++ b/sys/kern/kern_intr.c @@ -58,13 +58,26 @@ __FBSDID("$FreeBSD$"); #include #endif -struct int_entropy { - struct proc *proc; - uintptr_t vector; +/* + * Describe an interrupt thread. There is one of these per interrupt event. + */ +struct intr_thread { + struct intr_event *it_event; + struct thread *it_thread; /* Kernel thread. */ + int it_flags; /* (j) IT_* flags. */ + int it_need; /* Needs service. */ +}; + +/* Interrupt thread flags kept in it_flags */ +#define IT_DEAD 0x000001 /* Thread is waiting to exit. */ + +struct intr_entropy { + struct thread *td; + uintptr_t event; }; -struct ithd *clk_ithd; -struct ithd *tty_ithd; +struct intr_event *clk_intr_event; +struct intr_event *tty_intr_event; void *softclock_ih; void *vm_ih; @@ -75,13 +88,21 @@ TUNABLE_INT("hw.intr_storm_threshold", &intr_storm_threshold); SYSCTL_INT(_hw, OID_AUTO, intr_storm_threshold, CTLFLAG_RW, &intr_storm_threshold, 0, "Number of consecutive interrupts before storm protection is enabled"); +static TAILQ_HEAD(, intr_event) event_list = + TAILQ_HEAD_INITIALIZER(event_list); +static void intr_event_update(struct intr_event *ie); +static struct intr_thread *ithread_create(const char *name); +#ifdef notyet +static void ithread_destroy(struct intr_thread *ithread); +#endif +static void ithread_execute_handlers(struct proc *p, struct intr_event *ie); static void ithread_loop(void *); -static void ithread_update(struct ithd *); +static void ithread_update(struct intr_thread *ithd); static void start_softintr(void *); u_char -ithread_priority(enum intr_type flags) +intr_priority(enum intr_type flags) { u_char pri; @@ -115,153 +136,206 @@ ithread_priority(enum intr_type flags) break; default: /* We didn't specify an interrupt level. */ - panic("ithread_priority: no interrupt type in flags"); + panic("intr_priority: no interrupt type in flags"); } return pri; } /* - * Regenerate the name (p_comm) and priority for a threaded interrupt thread. + * Update an ithread based on the associated intr_event. */ static void -ithread_update(struct ithd *ithd) +ithread_update(struct intr_thread *ithd) { - struct intrhand *ih; + struct intr_event *ie; struct thread *td; - struct proc *p; - int missed; + u_char pri; - mtx_assert(&ithd->it_lock, MA_OWNED); - td = ithd->it_td; - if (td == NULL) - return; - p = td->td_proc; + ie = ithd->it_event; + td = ithd->it_thread; - strlcpy(p->p_comm, ithd->it_name, sizeof(p->p_comm)); - ithd->it_flags &= ~IT_ENTROPY; + /* Determine the overall priority of this event. */ + if (TAILQ_EMPTY(&ie->ie_handlers)) + pri = PRI_MAX_ITHD; + else + pri = TAILQ_FIRST(&ie->ie_handlers)->ih_pri; - ih = TAILQ_FIRST(&ithd->it_handlers); - if (ih == NULL) { - mtx_lock_spin(&sched_lock); - sched_prio(td, PRI_MAX_ITHD); - mtx_unlock_spin(&sched_lock); - return; - } + /* Update name and priority. */ + strlcpy(td->td_proc->p_comm, ie->ie_fullname, + sizeof(td->td_proc->p_comm)); mtx_lock_spin(&sched_lock); - sched_prio(td, ih->ih_pri); + sched_prio(td, pri); mtx_unlock_spin(&sched_lock); +} + +/* + * Regenerate the full name of an interrupt event and update its priority. + */ +static void +intr_event_update(struct intr_event *ie) +{ + struct intr_handler *ih; + char *last; + int missed, space; + + /* Start off with no entropy and just the name of the event. */ + mtx_assert(&ie->ie_lock, MA_OWNED); + strlcpy(ie->ie_fullname, ie->ie_name, sizeof(ie->ie_fullname)); + ie->ie_flags &= ~IE_ENTROPY; missed = 0; - TAILQ_FOREACH(ih, &ithd->it_handlers, ih_next) { - if (strlen(p->p_comm) + strlen(ih->ih_name) + 1 < - sizeof(p->p_comm)) { - strcat(p->p_comm, " "); - strcat(p->p_comm, ih->ih_name); + space = 1; + + /* Run through all the handlers updating values. */ + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (strlen(ie->ie_fullname) + strlen(ih->ih_name) + 1 < + sizeof(ie->ie_fullname)) { + strcat(ie->ie_fullname, " "); + strcat(ie->ie_fullname, ih->ih_name); + space = 0; } else missed++; if (ih->ih_flags & IH_ENTROPY) - ithd->it_flags |= IT_ENTROPY; + ie->ie_flags |= IE_ENTROPY; } + + /* + * If the handler names were too long, add +'s to indicate missing + * names. If we run out of room and still have +'s to add, change + * the last character from a + to a *. + */ + last = &ie->ie_fullname[sizeof(ie->ie_fullname) - 2]; while (missed-- > 0) { - if (strlen(p->p_comm) + 1 == sizeof(p->p_comm)) { - if (p->p_comm[sizeof(p->p_comm) - 2] == '+') - p->p_comm[sizeof(p->p_comm) - 2] = '*'; - else - p->p_comm[sizeof(p->p_comm) - 2] = '+'; + if (strlen(ie->ie_fullname) + 1 == sizeof(ie->ie_fullname)) { + if (*last == '+') { + *last = '*'; + break; + } else + *last = '+'; + } else if (space) { + strcat(ie->ie_fullname, " +"); + space = 0; } else - strcat(p->p_comm, "+"); + strcat(ie->ie_fullname, "+"); } - CTR2(KTR_INTR, "%s: updated %s", __func__, p->p_comm); + + /* + * If this event has an ithread, update it's priority and + * name. + */ + if (ie->ie_thread != NULL) + ithread_update(ie->ie_thread); + CTR2(KTR_INTR, "%s: updated %s", __func__, ie->ie_fullname); } int -ithread_create(struct ithd **ithread, uintptr_t vector, int flags, - void (*disable)(uintptr_t), void (*enable)(uintptr_t), const char *fmt, ...) +intr_event_create(struct intr_event **event, void *source, int flags, + void (*enable)(void *), const char *fmt, ...) { - struct ithd *ithd; - struct thread *td; - struct proc *p; - int error; + struct intr_event *ie; va_list ap; - /* The only valid flag during creation is IT_SOFT. */ - if ((flags & ~IT_SOFT) != 0) + /* The only valid flag during creation is IE_SOFT. */ + if ((flags & ~IE_SOFT) != 0) return (EINVAL); - - ithd = malloc(sizeof(struct ithd), M_ITHREAD, M_WAITOK | M_ZERO); - ithd->it_vector = vector; - ithd->it_disable = disable; - ithd->it_enable = enable; - ithd->it_flags = flags; - TAILQ_INIT(&ithd->it_handlers); - mtx_init(&ithd->it_lock, "ithread", NULL, MTX_DEF); + ie = malloc(sizeof(struct intr_event), M_ITHREAD, M_WAITOK | M_ZERO); + ie->ie_source = source; + ie->ie_enable = enable; + ie->ie_flags = flags; + TAILQ_INIT(&ie->ie_handlers); + mtx_init(&ie->ie_lock, "intr event", NULL, MTX_DEF); va_start(ap, fmt); - vsnprintf(ithd->it_name, sizeof(ithd->it_name), fmt, ap); + vsnprintf(ie->ie_name, sizeof(ie->ie_name), fmt, ap); va_end(ap); + strlcpy(ie->ie_fullname, ie->ie_name, sizeof(ie->ie_fullname)); + mtx_pool_lock(mtxpool_sleep, &event_list); + TAILQ_INSERT_TAIL(&event_list, ie, ie_list); + mtx_pool_unlock(mtxpool_sleep, &event_list); + if (event != NULL) + *event = ie; + CTR2(KTR_INTR, "%s: created %s", __func__, ie->ie_name); + return (0); +} - error = kthread_create(ithread_loop, ithd, &p, RFSTOPPED | RFHIGHPID, - 0, "%s", ithd->it_name); - if (error) { - mtx_destroy(&ithd->it_lock); - free(ithd, M_ITHREAD); - return (error); +int +intr_event_destroy(struct intr_event *ie) +{ + + mtx_lock(&ie->ie_lock); + if (!TAILQ_EMPTY(&ie->ie_handlers)) { + mtx_unlock(&ie->ie_lock); + return (EBUSY); } + mtx_pool_lock(mtxpool_sleep, &event_list); + TAILQ_REMOVE(&event_list, ie, ie_list); + mtx_pool_unlock(mtxpool_sleep, &event_list); + mtx_unlock(&ie->ie_lock); + mtx_destroy(&ie->ie_lock); + free(ie, M_ITHREAD); + return (0); +} + +static struct intr_thread * +ithread_create(const char *name) +{ + struct intr_thread *ithd; + struct thread *td; + struct proc *p; + int error; + + ithd = malloc(sizeof(struct intr_thread), M_ITHREAD, M_WAITOK | M_ZERO); + + error = kthread_create(ithread_loop, ithd, &p, RFSTOPPED | RFHIGHPID, + 0, "%s", name); + if (error) + panic("kthread_create() failed with %d", error); td = FIRST_THREAD_IN_PROC(p); /* XXXKSE */ mtx_lock_spin(&sched_lock); td->td_ksegrp->kg_pri_class = PRI_ITHD; - td->td_priority = PRI_MAX_ITHD; TD_SET_IWAIT(td); mtx_unlock_spin(&sched_lock); - ithd->it_td = td; - td->td_ithd = ithd; - if (ithread != NULL) - *ithread = ithd; - CTR2(KTR_INTR, "%s: created %s", __func__, ithd->it_name); - return (0); + td->td_pflags |= TDP_ITHREAD; + ithd->it_thread = td; + CTR2(KTR_INTR, "%s: created %s", __func__, name); + return (ithd); } -int -ithread_destroy(struct ithd *ithread) +#ifdef notyet +static void +ithread_destroy(struct intr_thread *ithread) { - struct thread *td; - if (ithread == NULL) - return (EINVAL); - td = ithread->it_td; - mtx_lock(&ithread->it_lock); - if (!TAILQ_EMPTY(&ithread->it_handlers)) { - mtx_unlock(&ithread->it_lock); - return (EINVAL); - } - ithread->it_flags |= IT_DEAD; + td = ithread->it_thread; mtx_lock_spin(&sched_lock); + ithread->it_flags |= IT_DEAD; if (TD_AWAITING_INTR(td)) { TD_CLR_IWAIT(td); setrunqueue(td, SRQ_INTR); } mtx_unlock_spin(&sched_lock); - mtx_unlock(&ithread->it_lock); CTR2(KTR_INTR, "%s: killing %s", __func__, ithread->it_name); - return (0); } +#endif int -ithread_add_handler(struct ithd* ithread, const char *name, +intr_event_add_handler(struct intr_event *ie, const char *name, driver_intr_t handler, void *arg, u_char pri, enum intr_type flags, void **cookiep) { - struct intrhand *ih, *temp_ih; + struct intr_handler *ih, *temp_ih; + struct intr_thread *it; - if (ithread == NULL || name == NULL || handler == NULL) + if (ie == NULL || name == NULL || handler == NULL) return (EINVAL); - ih = malloc(sizeof(struct intrhand), M_ITHREAD, M_WAITOK | M_ZERO); + /* Allocate and populate an interrupt handler structure. */ + ih = malloc(sizeof(struct intr_handler), M_ITHREAD, M_WAITOK | M_ZERO); ih->ih_handler = handler; ih->ih_argument = arg; ih->ih_name = name; - ih->ih_ithread = ithread; + ih->ih_event = ie; ih->ih_pri = pri; if (flags & INTR_FAST) ih->ih_flags = IH_FAST; @@ -272,68 +346,96 @@ ithread_add_handler(struct ithd* ithread, const char *name, if (flags & INTR_ENTROPY) ih->ih_flags |= IH_ENTROPY; - mtx_lock(&ithread->it_lock); - if ((flags & INTR_EXCL) != 0 && !TAILQ_EMPTY(&ithread->it_handlers)) - goto fail; - if (!TAILQ_EMPTY(&ithread->it_handlers)) { - temp_ih = TAILQ_FIRST(&ithread->it_handlers); - if (temp_ih->ih_flags & IH_EXCLUSIVE) - goto fail; - if ((ih->ih_flags & IH_FAST) && !(temp_ih->ih_flags & IH_FAST)) - goto fail; - if (!(ih->ih_flags & IH_FAST) && (temp_ih->ih_flags & IH_FAST)) - goto fail; + /* We can only have one exclusive handler in a event. */ + mtx_lock(&ie->ie_lock); + if (!TAILQ_EMPTY(&ie->ie_handlers)) { + if ((flags & INTR_EXCL) || + (TAILQ_FIRST(&ie->ie_handlers)->ih_flags & IH_EXCLUSIVE)) { + mtx_unlock(&ie->ie_lock); + free(ih, M_ITHREAD); + return (EINVAL); + } } - TAILQ_FOREACH(temp_ih, &ithread->it_handlers, ih_next) - if (temp_ih->ih_pri > ih->ih_pri) - break; + /* Add the new handler to the event in priority order. */ + TAILQ_FOREACH(temp_ih, &ie->ie_handlers, ih_next) { + if (temp_ih->ih_pri > ih->ih_pri) + break; + } if (temp_ih == NULL) - TAILQ_INSERT_TAIL(&ithread->it_handlers, ih, ih_next); + TAILQ_INSERT_TAIL(&ie->ie_handlers, ih, ih_next); else TAILQ_INSERT_BEFORE(temp_ih, ih, ih_next); - ithread_update(ithread); - mtx_unlock(&ithread->it_lock); + intr_event_update(ie); + + /* Create a thread if we need one. */ + while (ie->ie_thread == NULL && !(flags & INTR_FAST)) { + if (ie->ie_flags & IE_ADDING_THREAD) + msleep(ie, &ie->ie_lock, curthread->td_priority, + "ithread", 0); + else { + ie->ie_flags |= IE_ADDING_THREAD; + mtx_unlock(&ie->ie_lock); + it = ithread_create("intr: newborn"); + mtx_lock(&ie->ie_lock); + ie->ie_flags &= ~IE_ADDING_THREAD; + ie->ie_thread = it; + it->it_event = ie; + ithread_update(it); + wakeup(ie); + } + } + CTR3(KTR_INTR, "%s: added %s to %s", __func__, ih->ih_name, + ie->ie_name); + mtx_unlock(&ie->ie_lock); if (cookiep != NULL) *cookiep = ih; - CTR3(KTR_INTR, "%s: added %s to %s", __func__, ih->ih_name, - ithread->it_name); return (0); - -fail: - mtx_unlock(&ithread->it_lock); - free(ih, M_ITHREAD); - return (EINVAL); } int -ithread_remove_handler(void *cookie) +intr_event_remove_handler(void *cookie) { - struct intrhand *handler = (struct intrhand *)cookie; - struct ithd *ithread; + struct intr_handler *handler = (struct intr_handler *)cookie; + struct intr_event *ie; #ifdef INVARIANTS - struct intrhand *ih; + struct intr_handler *ih; +#endif +#ifdef notyet + int dead; #endif if (handler == NULL) return (EINVAL); - ithread = handler->ih_ithread; - KASSERT(ithread != NULL, - ("interrupt handler \"%s\" has a NULL interrupt thread", + ie = handler->ih_event; + KASSERT(ie != NULL, + ("interrupt handler \"%s\" has a NULL interrupt event", handler->ih_name)); + mtx_lock(&ie->ie_lock); CTR3(KTR_INTR, "%s: removing %s from %s", __func__, handler->ih_name, - ithread->it_name); - mtx_lock(&ithread->it_lock); + ie->ie_name); #ifdef INVARIANTS - TAILQ_FOREACH(ih, &ithread->it_handlers, ih_next) + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) if (ih == handler) goto ok; - mtx_unlock(&ithread->it_lock); - panic("interrupt handler \"%s\" not found in interrupt thread \"%s\"", - ih->ih_name, ithread->it_name); + mtx_unlock(&ie->ie_lock); + panic("interrupt handler \"%s\" not found in interrupt event \"%s\"", + ih->ih_name, ie->ie_name); ok: #endif + /* + * If there is no ithread, then just remove the handler and return. + * XXX: Note that an INTR_FAST handler might be running on another + * CPU! + */ + if (ie->ie_thread == NULL) { + TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next); + mtx_unlock(&ie->ie_lock); + free(handler, M_ITHREAD); + return (0); + } + /* * If the interrupt thread is already running, then just mark this * handler as being dead and let the ithread do the actual removal. @@ -343,7 +445,7 @@ ok: * thread do it. */ mtx_lock_spin(&sched_lock); - if (!TD_AWAITING_INTR(ithread->it_td) && !cold) { + if (!TD_AWAITING_INTR(ie->ie_thread->it_thread) && !cold) { handler->ih_flags |= IH_DEAD; /* @@ -351,22 +453,42 @@ ok: * again and remove this handler if it has already passed * it on the list. */ - ithread->it_need = 1; - } else - TAILQ_REMOVE(&ithread->it_handlers, handler, ih_next); + ie->ie_thread->it_need = 1; + } else + TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next); mtx_unlock_spin(&sched_lock); - if ((handler->ih_flags & IH_DEAD) != 0) - msleep(handler, &ithread->it_lock, PUSER, "itrmh", 0); - ithread_update(ithread); - mtx_unlock(&ithread->it_lock); + while (handler->ih_flags & IH_DEAD) + msleep(handler, &ie->ie_lock, curthread->td_priority, "iev_rmh", + 0); + intr_event_update(ie); +#ifdef notyet + /* + * XXX: This could be bad in the case of ppbus(8). Also, I think + * this could lead to races of stale data when servicing an + * interrupt. + */ + dead = 1; + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) { + dead = 0; + break; + } + } + if (dead) { + ithread_destroy(ie->ie_thread); + ie->ie_thread = NULL; + } +#endif + mtx_unlock(&ie->ie_lock); free(handler, M_ITHREAD); return (0); } int -ithread_schedule(struct ithd *ithread) +intr_event_schedule_thread(struct intr_event *ie) { - struct int_entropy entropy; + struct intr_entropy entropy; + struct intr_thread *it; struct thread *td; struct thread *ctd; struct proc *p; @@ -374,93 +496,97 @@ ithread_schedule(struct ithd *ithread) /* * If no ithread or no handlers, then we have a stray interrupt. */ - if ((ithread == NULL) || TAILQ_EMPTY(&ithread->it_handlers)) + if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers) || + ie->ie_thread == NULL) return (EINVAL); ctd = curthread; - td = ithread->it_td; + it = ie->ie_thread; + td = it->it_thread; p = td->td_proc; + /* * If any of the handlers for this ithread claim to be good * sources of entropy, then gather some. */ - if (harvest.interrupt && ithread->it_flags & IT_ENTROPY) { + if (harvest.interrupt && ie->ie_flags & IE_ENTROPY) { CTR3(KTR_INTR, "%s: pid %d (%s) gathering entropy", __func__, p->p_pid, p->p_comm); - entropy.vector = ithread->it_vector; - entropy.proc = ctd->td_proc; + entropy.event = (uintptr_t)ie; + entropy.td = ctd; random_harvest(&entropy, sizeof(entropy), 2, 0, RANDOM_INTERRUPT); } - KASSERT(p != NULL, ("ithread %s has no process", ithread->it_name)); - CTR4(KTR_INTR, "%s: pid %d: (%s) need = %d", - __func__, p->p_pid, p->p_comm, ithread->it_need); + KASSERT(p != NULL, ("ithread %s has no process", ie->ie_name)); /* * Set it_need to tell the thread to keep running if it is already * running. Then, grab sched_lock and see if we actually need to * put this thread on the runqueue. */ - ithread->it_need = 1; + it->it_need = 1; mtx_lock_spin(&sched_lock); if (TD_AWAITING_INTR(td)) { - CTR2(KTR_INTR, "%s: setrunqueue %d", __func__, p->p_pid); + CTR3(KTR_INTR, "%s: schedule pid %d (%s)", __func__, p->p_pid, + p->p_comm); TD_CLR_IWAIT(td); setrunqueue(td, SRQ_INTR); } else { - CTR4(KTR_INTR, "%s: pid %d: it_need %d, state %d", - __func__, p->p_pid, ithread->it_need, td->td_state); + CTR5(KTR_INTR, "%s: pid %d (%s): it_need %d, state %d", + __func__, p->p_pid, p->p_comm, it->it_need, td->td_state); } mtx_unlock_spin(&sched_lock); return (0); } +/* + * Add a software interrupt handler to a specified event. If a given event + * is not specified, then a new event is created. + */ int -swi_add(struct ithd **ithdp, const char *name, driver_intr_t handler, +swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler, void *arg, int pri, enum intr_type flags, void **cookiep) { - struct ithd *ithd; + struct intr_event *ie; int error; if (flags & (INTR_FAST | INTR_ENTROPY)) return (EINVAL); - ithd = (ithdp != NULL) ? *ithdp : NULL; + ie = (eventp != NULL) ? *eventp : NULL; - if (ithd != NULL) { - if ((ithd->it_flags & IT_SOFT) == 0) - return(EINVAL); + if (ie != NULL) { + if (!(ie->ie_flags & IE_SOFT)) + return (EINVAL); } else { - error = ithread_create(&ithd, pri, IT_SOFT, NULL, NULL, + error = intr_event_create(&ie, NULL, IE_SOFT, NULL, "swi%d:", pri); if (error) return (error); - - if (ithdp != NULL) - *ithdp = ithd; + if (eventp != NULL) + *eventp = ie; } - return (ithread_add_handler(ithd, name, handler, arg, + return (intr_event_add_handler(ie, name, handler, arg, (pri * RQ_PPQ) + PI_SOFT, flags, cookiep)); /* XXKSE.. think of a better way to get separate queues */ } - /* - * Schedule a heavyweight software interrupt process. + * Schedule a software interrupt thread. */ void swi_sched(void *cookie, int flags) { - struct intrhand *ih = (struct intrhand *)cookie; - struct ithd *it = ih->ih_ithread; + struct intr_handler *ih = (struct intr_handler *)cookie; + struct intr_event *ie = ih->ih_event; int error; PCPU_LAZY_INC(cnt.v_intr); - - CTR3(KTR_INTR, "swi_sched pid %d(%s) need=%d", - it->it_td->td_proc->p_pid, it->it_td->td_proc->p_comm, it->it_need); + + CTR3(KTR_INTR, "swi_sched: %s %s need=%d", ie->ie_name, ih->ih_name, + ih->ih_need); /* * Set ih_need for this handler so that if the ithread is already @@ -469,30 +595,134 @@ swi_sched(void *cookie, int flags) */ atomic_store_rel_int(&ih->ih_need, 1); if (!(flags & SWI_DELAY)) { - error = ithread_schedule(it); + error = intr_event_schedule_thread(ie); KASSERT(error == 0, ("stray software interrupt")); } } +/* + * Remove a software interrupt handler. Currently this code does not + * remove the associated interrupt event if it becomes empty. Calling code + * may do so manually via intr_event_destroy(), but that's not really + * an optimal interface. + */ +int +swi_remove(void *cookie) +{ + + return (intr_event_remove_handler(cookie)); +} + +/* ABI compatibility shim. */ +int ithread_remove_handler(void *); + +int +ithread_remove_handler(void *cookie) +{ + + return (intr_event_remove_handler(cookie)); +} + +static void +ithread_execute_handlers(struct proc *p, struct intr_event *ie) +{ + struct intr_handler *ih, *ihn; + + /* Interrupt handlers should not sleep. */ + if (!(ie->ie_flags & IE_SOFT)) + THREAD_NO_SLEEPING(); + TAILQ_FOREACH_SAFE(ih, &ie->ie_handlers, ih_next, ihn) { + + /* + * If this handler is marked for death, remove it from + * the list of handlers and wake up the sleeper. + */ + if (ih->ih_flags & IH_DEAD) { + mtx_lock(&ie->ie_lock); + TAILQ_REMOVE(&ie->ie_handlers, ih, ih_next); + ih->ih_flags &= ~IH_DEAD; + wakeup(ih); + mtx_unlock(&ie->ie_lock); + continue; + } + + /* + * For software interrupt threads, we only execute + * handlers that have their need flag set. Hardware + * interrupt threads always invoke all of their handlers. + */ + if (ie->ie_flags & IE_SOFT) { + if (!ih->ih_need) + continue; + else + atomic_store_rel_int(&ih->ih_need, 0); + } + + /* Fast handlers are handled in primary interrupt context. */ + if (ih->ih_flags & IH_FAST) + continue; + + /* Execute this handler. */ + CTR6(KTR_INTR, "%s: pid %d exec %p(%p) for %s flg=%x", + __func__, p->p_pid, (void *)ih->ih_handler, ih->ih_argument, + ih->ih_name, ih->ih_flags); + + if (!(ih->ih_flags & IH_MPSAFE)) + mtx_lock(&Giant); + ih->ih_handler(ih->ih_argument); + if (!(ih->ih_flags & IH_MPSAFE)) + mtx_unlock(&Giant); + } + if (!(ie->ie_flags & IE_SOFT)) + THREAD_SLEEPING_OK(); + + /* + * Interrupt storm handling: + * + * If this interrupt source is currently storming, then throttle + * it to only fire the handler once per clock tick. + * + * If this interrupt source is not currently storming, but the + * number of back to back interrupts exceeds the storm threshold, + * then enter storming mode. + */ + if (intr_storm_threshold != 0 && ie->ie_count >= intr_storm_threshold) { + if (ie->ie_warned == 0) { + printf( + "Interrupt storm detected on \"%s\"; throttling interrupt source\n", + ie->ie_name); + ie->ie_warned = 1; + } + tsleep(&ie->ie_count, curthread->td_priority, "istorm", 1); + } else + ie->ie_count++; + + /* + * Now that all the handlers have had a chance to run, reenable + * the interrupt source. + */ + if (ie->ie_enable != NULL) + ie->ie_enable(ie->ie_source); +} + /* * This is the main code for interrupt threads. */ static void ithread_loop(void *arg) { - struct ithd *ithd; /* our thread context */ - struct intrhand *ih; /* and our interrupt handler chain */ + struct intr_thread *ithd; + struct intr_event *ie; struct thread *td; struct proc *p; - int count, warned; - + td = curthread; p = td->td_proc; - ithd = (struct ithd *)arg; /* point to myself */ - KASSERT(ithd->it_td == td && td->td_ithd == ithd, + ithd = (struct intr_thread *)arg; + KASSERT(ithd->it_thread == td, ("%s: ithread and proc linkage out of sync", __func__)); - count = 0; - warned = 0; + ie = ithd->it_event; + ie->ie_count = 0; /* * As long as we have interrupts outstanding, go through the @@ -503,80 +733,26 @@ ithread_loop(void *arg) * If we are an orphaned thread, then just die. */ if (ithd->it_flags & IT_DEAD) { - CTR3(KTR_INTR, "%s: pid %d: (%s) exiting", __func__, + CTR3(KTR_INTR, "%s: pid %d (%s) exiting", __func__, p->p_pid, p->p_comm); - td->td_ithd = NULL; - mtx_destroy(&ithd->it_lock); free(ithd, M_ITHREAD); kthread_exit(0); } - CTR4(KTR_INTR, "%s: pid %d: (%s) need=%d", __func__, - p->p_pid, p->p_comm, ithd->it_need); + /* + * Service interrupts. If another interrupt arrives while + * we are running, it will set it_need to note that we + * should make another pass. + */ while (ithd->it_need) { /* - * Service interrupts. If another interrupt - * arrives while we are running, they will set - * it_need to denote that we should make - * another pass. + * This might need a full read and write barrier + * to make sure that this write posts before any + * of the memory or device accesses in the + * handlers. */ atomic_store_rel_int(&ithd->it_need, 0); - if (!(ithd->it_flags & IT_SOFT)) - THREAD_NO_SLEEPING(); -restart: - TAILQ_FOREACH(ih, &ithd->it_handlers, ih_next) { - if (ithd->it_flags & IT_SOFT && !ih->ih_need) - continue; - atomic_store_rel_int(&ih->ih_need, 0); - CTR6(KTR_INTR, - "%s: pid %d ih=%p: %p(%p) flg=%x", __func__, - p->p_pid, (void *)ih, - (void *)ih->ih_handler, ih->ih_argument, - ih->ih_flags); - - if ((ih->ih_flags & IH_DEAD) != 0) { - mtx_lock(&ithd->it_lock); - TAILQ_REMOVE(&ithd->it_handlers, ih, - ih_next); - wakeup(ih); - mtx_unlock(&ithd->it_lock); - goto restart; - } - if ((ih->ih_flags & IH_MPSAFE) == 0) - mtx_lock(&Giant); - ih->ih_handler(ih->ih_argument); - if ((ih->ih_flags & IH_MPSAFE) == 0) - mtx_unlock(&Giant); - } - if (!(ithd->it_flags & IT_SOFT)) - THREAD_SLEEPING_OK(); - - /* - * Interrupt storm handling: - * - * If this interrupt source is currently storming, - * then throttle it to only fire the handler once - * per clock tick. - * - * If this interrupt source is not currently - * storming, but the number of back to back - * interrupts exceeds the storm threshold, then - * enter storming mode. - */ - if (intr_storm_threshold != 0 && - count >= intr_storm_threshold) { - if (!warned) { - printf( - "Interrupt storm detected on \"%s\"; throttling interrupt source\n", - p->p_comm); - warned = 1; - } - tsleep(&count, td->td_priority, "istorm", 1); - } else - count++; - - if (ithd->it_enable != NULL) - ithd->it_enable(ithd->it_vector); + ithread_execute_handlers(p, ie); } WITNESS_WARN(WARN_PANIC, NULL, "suspending ithread"); mtx_assert(&Giant, MA_NOTOWNED); @@ -587,12 +763,10 @@ restart: * set again, so we have to check it again. */ mtx_lock_spin(&sched_lock); - if (!ithd->it_need) { + if (!ithd->it_need && !(ithd->it_flags & IT_DEAD)) { TD_SET_IWAIT(td); - count = 0; - CTR2(KTR_INTR, "%s: pid %d: done", __func__, p->p_pid); + ie->ie_count = 0; mi_switch(SW_VOL, NULL); - CTR2(KTR_INTR, "%s: pid %d: resumed", __func__, p->p_pid); } mtx_unlock_spin(&sched_lock); } @@ -603,7 +777,7 @@ restart: * Dump details about an interrupt handler */ static void -db_dump_intrhand(struct intrhand *ih) +db_dump_intrhand(struct intr_handler *ih) { int comma; @@ -686,41 +860,42 @@ db_dump_intrhand(struct intrhand *ih) } /* - * Dump details about an ithread + * Dump details about a event. */ void -db_dump_ithread(struct ithd *ithd, int handlers) +db_dump_intr_event(struct intr_event *ie, int handlers) { - struct proc *p; - struct intrhand *ih; + struct intr_handler *ih; + struct intr_thread *it; int comma; - if (ithd->it_td != NULL) { - p = ithd->it_td->td_proc; - db_printf("%s (pid %d)", p->p_comm, p->p_pid); - } else - db_printf("%s: (no thread)", ithd->it_name); - if ((ithd->it_flags & (IT_SOFT | IT_ENTROPY | IT_DEAD)) != 0 || - ithd->it_need) { + db_printf("%s ", ie->ie_fullname); + it = ie->ie_thread; + if (it != NULL) + db_printf("(pid %d)", it->it_thread->td_proc->p_pid); + else + db_printf("(no thread)"); + if ((ie->ie_flags & (IE_SOFT | IE_ENTROPY | IE_ADDING_THREAD)) != 0 || + (it != NULL && it->it_need)) { db_printf(" {"); comma = 0; - if (ithd->it_flags & IT_SOFT) { + if (ie->ie_flags & IE_SOFT) { db_printf("SOFT"); comma = 1; } - if (ithd->it_flags & IT_ENTROPY) { + if (ie->ie_flags & IE_ENTROPY) { if (comma) db_printf(", "); db_printf("ENTROPY"); comma = 1; } - if (ithd->it_flags & IT_DEAD) { + if (ie->ie_flags & IE_ADDING_THREAD) { if (comma) db_printf(", "); - db_printf("DEAD"); + db_printf("ADDING_THREAD"); comma = 1; } - if (ithd->it_need) { + if (it != NULL && it->it_need) { if (comma) db_printf(", "); db_printf("NEED"); @@ -730,9 +905,28 @@ db_dump_ithread(struct ithd *ithd, int handlers) db_printf("\n"); if (handlers) - TAILQ_FOREACH(ih, &ithd->it_handlers, ih_next) + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) db_dump_intrhand(ih); } + +/* + * Dump data about interrupt handlers + */ +DB_SHOW_COMMAND(intr, db_show_intr) +{ + struct intr_event *ie; + int quit, all, verbose; + + quit = 0; + verbose = index(modif, 'v') != NULL; + all = index(modif, 'a') != NULL; + db_setup_paging(db_simple_pager, &quit, db_lines_per_page); + TAILQ_FOREACH(ie, &event_list, ie_list) { + if (!all && TAILQ_EMPTY(&ie->ie_handlers)) + continue; + db_dump_intr_event(ie, verbose); + } +} #endif /* DDB */ /* @@ -743,19 +937,19 @@ start_softintr(void *dummy) { struct proc *p; - if (swi_add(&clk_ithd, "clock", softclock, NULL, SWI_CLOCK, + if (swi_add(&clk_intr_event, "clock", softclock, NULL, SWI_CLOCK, INTR_MPSAFE, &softclock_ih) || swi_add(NULL, "vm", swi_vm, NULL, SWI_VM, INTR_MPSAFE, &vm_ih)) panic("died while creating standard software ithreads"); - p = clk_ithd->it_td->td_proc; + p = clk_intr_event->ie_thread->it_thread->td_proc; PROC_LOCK(p); p->p_flag |= P_NOLOAD; PROC_UNLOCK(p); } SYSINIT(start_softintr, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softintr, NULL) -/* +/* * Sysctls used by systat and others: hw.intrnames and hw.intrcnt. * The data for this machine dependent, and the declarations are in machine * dependent code. The layout of intrnames and intrcnt however is machine @@ -767,7 +961,7 @@ SYSINIT(start_softintr, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softintr, NULL) static int sysctl_intrnames(SYSCTL_HANDLER_ARGS) { - return (sysctl_handle_opaque(oidp, intrnames, eintrnames - intrnames, + return (sysctl_handle_opaque(oidp, intrnames, eintrnames - intrnames, req)); } @@ -777,7 +971,7 @@ SYSCTL_PROC(_hw, OID_AUTO, intrnames, CTLTYPE_OPAQUE | CTLFLAG_RD, static int sysctl_intrcnt(SYSCTL_HANDLER_ARGS) { - return (sysctl_handle_opaque(oidp, intrcnt, + return (sysctl_handle_opaque(oidp, intrcnt, (char *)eintrcnt - (char *)intrcnt, req)); } diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c index de5e6f51edf2..4a93f304a43e 100644 --- a/sys/kern/subr_witness.c +++ b/sys/kern/subr_witness.c @@ -374,7 +374,6 @@ static struct witness_order_list_entry order_lists[] = { { "ng_worklist", &lock_class_mtx_spin }, { "taskqueue_fast", &lock_class_mtx_spin }, { "intr table", &lock_class_mtx_spin }, - { "ithread table lock", &lock_class_mtx_spin }, { "sleepq chain", &lock_class_mtx_spin }, { "sched lock", &lock_class_mtx_spin }, { "turnstile chain", &lock_class_mtx_spin }, diff --git a/sys/netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c b/sys/netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c index 841a1b323942..172504f5fc7d 100644 --- a/sys/netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c +++ b/sys/netgraph/bluetooth/drivers/bt3c/ng_bt3c_pccard.c @@ -657,7 +657,7 @@ bt3c_pccard_attach(device_t dev) /* Attach handler to TTY SWI thread */ sc->ith = NULL; - if (swi_add(&tty_ithd, device_get_nameunit(dev), + if (swi_add(&tty_intr_event, device_get_nameunit(dev), bt3c_swi_intr, sc, SWI_TTY, 0, &sc->ith) < 0) { device_printf(dev, "Could not setup SWI ISR\n"); goto bad; @@ -694,7 +694,7 @@ bt3c_pccard_attach(device_t dev) return (0); bad: if (sc->ith != NULL) { - ithread_remove_handler(sc->ith); + swi_remove(sc->ith); sc->ith = NULL; } @@ -736,7 +736,7 @@ bt3c_pccard_detach(device_t dev) device_set_softc(dev, NULL); - ithread_remove_handler(sc->ith); + swi_remove(sc->ith); sc->ith = NULL; bus_teardown_intr(dev, sc->irq, sc->irq_cookie); diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c index b1accbf6e753..7e7ea65e7414 100644 --- a/sys/pc98/cbus/sio.c +++ b/sys/pc98/cbus/sio.c @@ -1718,9 +1718,9 @@ determined_type: ; printf("\n"); if (sio_fast_ih == NULL) { - swi_add(&tty_ithd, "sio", siopoll, NULL, SWI_TTY, 0, + swi_add(&tty_intr_event, "sio", siopoll, NULL, SWI_TTY, 0, &sio_fast_ih); - swi_add(&clk_ithd, "sio", siopoll, NULL, SWI_CLOCK, 0, + swi_add(&clk_intr_event, "sio", siopoll, NULL, SWI_CLOCK, 0, &sio_slow_ih); } diff --git a/sys/powerpc/include/intr_machdep.h b/sys/powerpc/include/intr_machdep.h index f4024d3c9b8b..3336deab9aaf 100644 --- a/sys/powerpc/include/intr_machdep.h +++ b/sys/powerpc/include/intr_machdep.h @@ -30,12 +30,12 @@ typedef void ih_func_t(void *); -struct ithd; +struct intr_event; -struct intr_handler { +struct ppc_intr_handler { ih_func_t *ih_func; void *ih_arg; - struct ithd *ih_ithd; + struct intr_event *ih_event; u_int ih_irq; u_int ih_flags; u_int ih_index; diff --git a/sys/powerpc/powerpc/intr_machdep.c b/sys/powerpc/powerpc/intr_machdep.c index 0cde8c57738b..521a25d3358f 100644 --- a/sys/powerpc/powerpc/intr_machdep.c +++ b/sys/powerpc/powerpc/intr_machdep.c @@ -85,7 +85,7 @@ MALLOC_DEFINE(M_INTR, "intr", "interrupt handler data"); static int intr_initialized = 0; static u_int intr_nirq; -static struct intr_handler *intr_handlers; +static struct ppc_intr_handler *intr_handlers; static struct mtx intr_table_lock; @@ -100,7 +100,7 @@ static void (*irq_enable)(uintptr_t); static void (*irq_disable)(uintptr_t); static void intrcnt_setname(const char *name, int index); -static void intrcnt_updatename(struct intr_handler *ih); +static void intrcnt_updatename(struct ppc_intr_handler *ih); static void intrcnt_setname(const char *name, int index) @@ -110,18 +110,18 @@ intrcnt_setname(const char *name, int index) } static void -intrcnt_updatename(struct intr_handler *ih) +intrcnt_updatename(struct ppc_intr_handler *ih) { - intrcnt_setname(ih->ih_ithd->it_td->td_proc->p_comm, ih->ih_index); + intrcnt_setname(ih->ih_event->ie_fullname, ih->ih_index); } static void -intrcnt_register(struct intr_handler *ih) +intrcnt_register(struct ppc_intr_handler *ih) { char straystr[MAXCOMLEN + 1]; - KASSERT(ih->ih_ithd != NULL, - ("%s: intr_handler with no ithread", __func__)); + KASSERT(ih->ih_event != NULL, + ("%s: ppc_intr_handler with no event", __func__)); ih->ih_index = intrcnt_index; intrcnt_index += 2; @@ -145,7 +145,7 @@ intr_init(void (*handler)(void), int nirq, void (*irq_e)(uintptr_t), intr_initialized++; intr_nirq = nirq; - intr_handlers = malloc(nirq * sizeof(struct intr_handler), M_INTR, + intr_handlers = malloc(nirq * sizeof(struct ppc_intr_handler), M_INTR, M_NOWAIT|M_ZERO); if (intr_handlers == NULL) panic("intr_init: unable to allocate interrupt handler array"); @@ -172,7 +172,7 @@ intr_init(void (*handler)(void), int nirq, void (*irq_e)(uintptr_t), irq_enable = irq_e; irq_disable = irq_d; - mtx_init(&intr_table_lock, "ithread table lock", NULL, MTX_SPIN); + mtx_init(&intr_table_lock, "intr table", NULL, MTX_SPIN); } void @@ -195,10 +195,10 @@ int inthand_add(const char *name, u_int irq, void (*handler)(void *), void *arg, int flags, void **cookiep) { - struct intr_handler *ih; - struct ithd *ithd, *orphan; + struct ppc_intr_handler *ih; + struct intr_event *event, *orphan; int error = 0; - int created_ithd = 0; + int created_event = 0; /* * Work around a race where more than one CPU may be registering @@ -206,30 +206,33 @@ inthand_add(const char *name, u_int irq, void (*handler)(void *), void *arg, */ ih = &intr_handlers[irq]; mtx_lock_spin(&intr_table_lock); - ithd = ih->ih_ithd; + event = ih->ih_event; mtx_unlock_spin(&intr_table_lock); - if (ithd == NULL) { - error = ithread_create(&ithd, irq, 0, irq_disable, - irq_enable, "irq%d:", irq); + if (event == NULL) { + error = intr_event_create(&event, (void *)irq, 0, + (void (*)(void *))irq_enable, "irq%d:", irq); if (error) return (error); mtx_lock_spin(&intr_table_lock); - if (ih->ih_ithd == NULL) { - ih->ih_ithd = ithd; - created_ithd++; + if (ih->ih_event == NULL) { + ih->ih_event = event; + created_event++; mtx_unlock_spin(&intr_table_lock); } else { - orphan = ithd; - ithd = ih->ih_ithd; + orphan = event; + event = ih->ih_event; mtx_unlock_spin(&intr_table_lock); - ithread_destroy(orphan); + intr_event_destroy(orphan); } } - error = ithread_add_handler(ithd, name, handler, arg, - ithread_priority(flags), flags, cookiep); + /* XXX: Should probably fix support for multiple FAST. */ + if (flags & INTR_FAST) + flags |= INTR_EXCL; + error = intr_event_add_handler(event, name, handler, arg, + intr_priority(flags), flags, cookiep); if ((flags & INTR_FAST) == 0 || error) { intr_setup(irq, sched_ithd, ih, flags); @@ -250,17 +253,17 @@ inthand_add(const char *name, u_int irq, void (*handler)(void *), void *arg, int inthand_remove(u_int irq, void *cookie) { - struct intr_handler *ih; + struct ppc_intr_handler *ih; int error; - error = ithread_remove_handler(cookie); + error = intr_event_remove_handler(cookie); if (error == 0) { ih = &intr_handlers[irq]; mtx_lock_spin(&intr_table_lock); - if (ih->ih_ithd == NULL) { + if (ih->ih_event == NULL) { intr_setup(irq, intr_stray_handler, ih, 0); } else { intr_setup(irq, sched_ithd, ih, 0); @@ -286,9 +289,9 @@ intr_handle(u_int irq) static void intr_stray_handler(void *cookie) { - struct intr_handler *ih; + struct ppc_intr_handler *ih; - ih = (struct intr_handler *)cookie; + ih = (struct ppc_intr_handler *)cookie; if (*intr_handlers[ih->ih_irq].ih_straycount < MAX_STRAY_LOG) { printf("stray irq %d\n", ih->ih_irq); @@ -303,12 +306,12 @@ intr_stray_handler(void *cookie) static void sched_ithd(void *cookie) { - struct intr_handler *ih; + struct ppc_intr_handler *ih; int error; - ih = (struct intr_handler *)cookie; + ih = (struct ppc_intr_handler *)cookie; - error = ithread_schedule(ih->ih_ithd); + error = intr_event_schedule_thread(ih->ih_event); if (error == EINVAL) intr_stray_handler(ih); diff --git a/sys/sparc64/include/intr_machdep.h b/sys/sparc64/include/intr_machdep.h index 9d297307625b..2604583299ba 100644 --- a/sys/sparc64/include/intr_machdep.h +++ b/sys/sparc64/include/intr_machdep.h @@ -67,7 +67,7 @@ struct intr_request { struct intr_vector { iv_func_t *iv_func; void *iv_arg; - struct ithd *iv_ithd; + struct intr_event *iv_event; u_int iv_pri; u_int iv_vec; }; diff --git a/sys/sparc64/sparc64/intr_machdep.c b/sys/sparc64/sparc64/intr_machdep.c index 24f71daa24b2..27166c430980 100644 --- a/sys/sparc64/sparc64/intr_machdep.c +++ b/sys/sparc64/sparc64/intr_machdep.c @@ -227,38 +227,44 @@ void intr_init2() { - mtx_init(&intr_table_lock, "ithread table lock", NULL, MTX_SPIN); + mtx_init(&intr_table_lock, "intr table", NULL, MTX_SPIN); } static void intr_execute_handlers(void *cookie) { struct intr_vector *iv; - struct ithd *ithd; - struct intrhand *ih; - int error; + struct intr_event *ie; + struct intr_handler *ih; + int error, thread; iv = cookie; - ithd = iv->iv_ithd; + ie = iv->iv_event; + if (ie == NULL) { + intr_stray_vector(iv); + return; + } - if (ithd == NULL) - ih = NULL; - else - ih = TAILQ_FIRST(&ithd->it_handlers); - if (ih != NULL && ih->ih_flags & IH_FAST) { - /* Execute fast interrupt handlers directly. */ - TAILQ_FOREACH(ih, &ithd->it_handlers, ih_next) { - MPASS(ih->ih_flags & IH_FAST && - ih->ih_argument != NULL); - CTR3(KTR_INTR, "%s: executing handler %p(%p)", - __func__, ih->ih_handler, ih->ih_argument); - ih->ih_handler(ih->ih_argument); + /* Execute fast interrupt handlers directly. */ + thread = 0; + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (!(ih->ih_flags & IH_FAST)) { + thread = 1; + continue; } - return; + MPASS(ih->ih_flags & IH_FAST && ih->ih_argument != NULL); + CTR3(KTR_INTR, "%s: executing handler %p(%p)", __func__, + ih->ih_handler, ih->ih_argument); + ih->ih_handler(ih->ih_argument); } /* Schedule a heavyweight interrupt process. */ - error = ithread_schedule(ithd); + if (thread) + error = intr_event_schedule_thread(ie); + else if (TAILQ_EMPTY(&ie->ie_handlers)) + error = EINVAL; + else + error = 0; if (error == EINVAL) intr_stray_vector(iv); } @@ -268,8 +274,8 @@ inthand_add(const char *name, int vec, void (*handler)(void *), void *arg, int flags, void **cookiep) { struct intr_vector *iv; - struct ithd *ithd; /* descriptor for the IRQ */ - struct ithd *orphan; + struct intr_event *ie; /* descriptor for the IRQ */ + struct intr_event *orphan; int errcode; /* @@ -278,27 +284,27 @@ inthand_add(const char *name, int vec, void (*handler)(void *), void *arg, */ iv = &intr_vectors[vec]; mtx_lock_spin(&intr_table_lock); - ithd = iv->iv_ithd; + ie = iv->iv_event; mtx_unlock_spin(&intr_table_lock); - if (ithd == NULL) { - errcode = ithread_create(&ithd, vec, 0, NULL, NULL, "vec%d:", - vec); + if (ie == NULL) { + errcode = intr_event_create(&ie, (void *)(intptr_t)vec, 0, NULL, + "vec%d:", vec); if (errcode) return (errcode); mtx_lock_spin(&intr_table_lock); - if (iv->iv_ithd == NULL) { - iv->iv_ithd = ithd; + if (iv->iv_event == NULL) { + iv->iv_event = ie; mtx_unlock_spin(&intr_table_lock); } else { - orphan = ithd; - ithd = iv->iv_ithd; + orphan = ie; + ie = iv->iv_event; mtx_unlock_spin(&intr_table_lock); - ithread_destroy(orphan); + intr_event_destroy(orphan); } } - errcode = ithread_add_handler(ithd, name, handler, arg, - ithread_priority(flags), flags, cookiep); + errcode = intr_event_add_handler(ie, name, handler, arg, + intr_priority(flags), flags, cookiep); if (errcode) return (errcode); @@ -307,7 +313,7 @@ inthand_add(const char *name, int vec, void (*handler)(void *), void *arg, intr_stray_count[vec] = 0; - intrcnt_updatename(vec, ithd->it_td->td_proc->p_comm, 0); + intrcnt_updatename(vec, ie->ie_fullname, 0); return (0); } @@ -318,15 +324,16 @@ inthand_remove(int vec, void *cookie) struct intr_vector *iv; int error; - error = ithread_remove_handler(cookie); + error = intr_event_remove_handler(cookie); if (error == 0) { /* * XXX: maybe this should be done regardless of whether - * ithread_remove_handler() succeeded? + * intr_event_remove_handler() succeeded? + * XXX: aren't the PIL's backwards below? */ iv = &intr_vectors[vec]; mtx_lock_spin(&intr_table_lock); - if (iv->iv_ithd == NULL) + if (iv->iv_event == NULL) intr_setup(PIL_ITHREAD, intr_fast, vec, intr_stray_vector, iv); else diff --git a/sys/sys/interrupt.h b/sys/sys/interrupt.h index 9833b226eb42..1626307a32f7 100644 --- a/sys/sys/interrupt.h +++ b/sys/sys/interrupt.h @@ -32,20 +32,28 @@ #include #include +/* Compatibility shims */ +#define tty_intr_event tty_ithd +#define clk_intr_event clk_ithd +#define ithd intr_event + +struct intr_event; +struct intr_thread; + /* * Describe a hardware interrupt handler. * - * Multiple interrupt handlers for a specific vector can be chained + * Multiple interrupt handlers for a specific event can be chained * together. */ -struct intrhand { +struct intr_handler { driver_intr_t *ih_handler; /* Handler function. */ void *ih_argument; /* Argument to pass to handler. */ int ih_flags; const char *ih_name; /* Name of handler. */ - struct ithd *ih_ithread; /* Ithread we are connected to. */ + struct intr_event *ih_event; /* Event we are connected to. */ int ih_need; /* Needs service. */ - TAILQ_ENTRY(intrhand) ih_next; /* Next handler for this vector. */ + TAILQ_ENTRY(intr_handler) ih_next; /* Next handler for this event. */ u_char ih_pri; /* Priority of this handler. */ }; @@ -57,29 +65,26 @@ struct intrhand { #define IH_MPSAFE 0x80000000 /* Handler does not need Giant. */ /* - * Describe an interrupt thread. There is one of these per interrupt vector. - * Note that this actually describes an interrupt source. There may or may - * not be an actual kernel thread attached to a given source. + * Describe an interrupt event. An event holds a list of handlers. */ -struct ithd { - struct mtx it_lock; - struct thread *it_td; /* Interrupt process. */ - LIST_ENTRY(ithd) it_list; /* All interrupt threads. */ - TAILQ_HEAD(, intrhand) it_handlers; /* Interrupt handlers. */ - struct ithd *it_interrupted; /* Who we interrupted. */ - void (*it_disable)(uintptr_t); /* Enable interrupt source. */ - void (*it_enable)(uintptr_t); /* Disable interrupt source. */ - void *it_md; /* Hook for MD interrupt code. */ - int it_flags; /* Interrupt-specific flags. */ - int it_need; /* Needs service. */ - uintptr_t it_vector; - char it_name[MAXCOMLEN + 1]; +struct intr_event { + TAILQ_ENTRY(intr_event) ie_list; + TAILQ_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */ + char ie_name[MAXCOMLEN]; /* Individual event name. */ + char ie_fullname[MAXCOMLEN]; + struct mtx ie_lock; + void *ie_source; /* Cookie used by MD code. */ + struct intr_thread *ie_thread; /* Thread we are connected to. */ + void (*ie_enable)(void *); + int ie_flags; + int ie_count; /* Loop counter. */ + int ie_warned; /* Warned about interrupt storm. */ }; -/* Interrupt thread flags kept in it_flags */ -#define IT_SOFT 0x000001 /* Software interrupt. */ -#define IT_ENTROPY 0x000002 /* Interrupt is an entropy source. */ -#define IT_DEAD 0x000004 /* Thread is waiting to exit. */ +/* Interrupt event flags kept in ie_flags. */ +#define IE_SOFT 0x000001 /* Software interrupt. */ +#define IE_ENTROPY 0x000002 /* Interrupt is an entropy source. */ +#define IE_ADDING_THREAD 0x000004 /* Currently building an ithread. */ /* Flags to pass to sched_swi. */ #define SWI_DELAY 0x2 @@ -97,9 +102,8 @@ struct ithd { #define SWI_TQ 6 #define SWI_TQ_GIANT 6 -extern struct ithd *tty_ithd; -extern struct ithd *clk_ithd; -extern void *net_ih; +extern struct intr_event *tty_intr_event; +extern struct intr_event *clk_intr_event; extern void *softclock_ih; extern void *vm_ih; @@ -110,21 +114,22 @@ extern u_long intrcnt[]; /* counts for for each device and stray */ extern char intrnames[]; /* string table containing device names */ #ifdef DDB -void db_dump_ithread(struct ithd *ithd, int handlers); +void db_dump_intr_event(struct intr_event *ie, int handlers); #endif -int ithread_create(struct ithd **ithread, uintptr_t vector, int flags, - void (*disable)(uintptr_t), void (*enable)(uintptr_t), - const char *fmt, ...) __printflike(6, 7); -int ithread_destroy(struct ithd *ithread); -u_char ithread_priority(enum intr_type flags); -int ithread_add_handler(struct ithd *ithread, const char *name, +u_char intr_priority(enum intr_type flags); +int intr_event_add_handler(struct intr_event *ie, const char *name, driver_intr_t handler, void *arg, u_char pri, enum intr_type flags, void **cookiep); -int ithread_remove_handler(void *cookie); -int ithread_schedule(struct ithd *ithread); -int swi_add(struct ithd **ithdp, const char *name, +int intr_event_create(struct intr_event **event, void *source, + int flags, void (*enable)(void *), const char *fmt, ...) + __printflike(5, 6); +int intr_event_destroy(struct intr_event *ie); +int intr_event_remove_handler(void *cookie); +int intr_event_schedule_thread(struct intr_event *ie); +int swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler, void *arg, int pri, enum intr_type flags, void **cookiep); void swi_sched(void *cookie, int flags); +int swi_remove(void *cookie); #endif diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 461d1167d47a..e480c76c90cb 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -149,7 +149,6 @@ struct pargs { * either lock is sufficient for read access, but both locks must be held * for write access. */ -struct ithd; struct kg_sched; struct nlminfo; struct kaioinfo; @@ -267,7 +266,7 @@ struct thread { volatile u_char td_owepreempt; /* (k*) Preempt on last critical_exit */ short td_locks; /* (k) DEBUG: lockmgr count of locks. */ struct turnstile *td_blocked; /* (j) Lock process is blocked on. */ - struct ithd *td_ithd; /* (b) For interrupt threads only. */ + void *td_ithd; /* (n) Unused, kept to preserve ABI. */ const char *td_lockname; /* (j) Name of lock blocked on. */ LIST_HEAD(, turnstile) td_contested; /* (q) Contested locks. */ struct lock_list_entry *td_sleeplocks; /* (k) Held sleep locks. */ @@ -370,7 +369,7 @@ struct thread { #define TDP_SA 0x00000080 /* A scheduler activation based thread. */ #define TDP_NOSLEEPING 0x00000100 /* Thread is not allowed to sleep on a sq. */ #define TDP_OWEUPC 0x00000200 /* Call addupc() at next AST. */ -#define TDP_UNUSED10 0x00000400 /* --available -- */ +#define TDP_ITHREAD 0x00000400 /* Thread is an interrupt thread. */ #define TDP_CAN_UNBIND 0x00000800 /* Only temporarily bound. */ #define TDP_SCHED1 0x00001000 /* Reserved for scheduler private use */ #define TDP_SCHED2 0x00002000 /* Reserved for scheduler private use */ -- cgit v1.3 From b067825826140d5f0037ad9372ced76b424bfa28 Mon Sep 17 00:00:00 2001 From: Maksim Yevmenkin Date: Mon, 25 Sep 2006 02:53:32 +0000 Subject: MFC: Do not try to call keyboard callback unless keyboard is active and busy. This should fix 'kbdcontrol -K < /dev/console' panic on sparc64 with sunkbd(4). PR: sparc64/96798 Approved by: re (hrs) --- sys/dev/uart/uart_kbd_sun.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index 22e47fa474a5..f5cd40a9b0e5 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -549,9 +549,11 @@ sunkbd_repeat(void *v) { struct sunkbd_softc *sc = v; - if (sc->sc_repeat_key != -1) { - sc->sc_repeating = 1; - sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd, - KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg); + if (KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) { + if (sc->sc_repeat_key != -1) { + sc->sc_repeating = 1; + sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd, + KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg); + } } } -- cgit v1.3 From 7fdeb89389886d8be16f14cd4a437452e5a7f422 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Wed, 4 Oct 2006 06:09:11 +0000 Subject: MFC: Fix our ioctl(2) implementation for ioctls with "int" arguments. Approved by: re (hrs, kensmith) --- contrib/telnet/telnetd/telnetd.c | 8 +++---- sys/dev/atkbdc/atkbd.c | 17 ++++++++++++++ sys/dev/digi/digi.c | 7 +++++- sys/dev/kbdmux/kbdmux.c | 18 ++++++++++++++ sys/dev/syscons/scvidctl.c | 17 ++++++++++++-- sys/dev/syscons/syscons.c | 51 ++++++++++++++++++++++++++++++++++++---- sys/dev/uart/uart_kbd_sun.c | 16 ++++++++++++- sys/dev/usb/ukbd.c | 17 ++++++++++++++ sys/dev/vkbd/vkbd.c | 17 ++++++++++++++ sys/fs/procfs/procfs_ioctl.c | 21 +++++++++++++---- sys/kern/sys_generic.c | 15 ++++++++---- sys/kern/tty_pty.c | 5 ++++ sys/net/if_tap.c | 7 +++++- sys/net/if_tap.h | 2 +- sys/pc98/cbus/pckbd.c | 13 ++++++++++ sys/sys/consio.h | 14 +++++------ sys/sys/digiio.h | 2 +- sys/sys/ioccom.h | 9 +++++-- sys/sys/kbio.h | 16 ++++++------- sys/sys/pioctl.h | 8 +++---- sys/sys/ttycom.h | 2 +- usr.sbin/vidcontrol/vidcontrol.c | 4 ++-- 22 files changed, 238 insertions(+), 48 deletions(-) (limited to 'sys/dev/uart/uart_kbd_sun.c') diff --git a/contrib/telnet/telnetd/telnetd.c b/contrib/telnet/telnetd/telnetd.c index f5000887bed1..a790c8969a80 100644 --- a/contrib/telnet/telnetd/telnetd.c +++ b/contrib/telnet/telnetd/telnetd.c @@ -1168,7 +1168,7 @@ interrupt(void) ptyflush(); /* half-hearted */ #ifdef TCSIG - (void) ioctl(pty, TCSIG, (char *)SIGINT); + (void) ioctl(pty, TCSIG, SIGINT); #else /* TCSIG */ init_termbuf(); *pfrontp++ = slctab[SLC_IP].sptr ? @@ -1186,7 +1186,7 @@ sendbrk(void) { ptyflush(); /* half-hearted */ #ifdef TCSIG - (void) ioctl(pty, TCSIG, (char *)SIGQUIT); + (void) ioctl(pty, TCSIG, SIGQUIT); #else /* TCSIG */ init_termbuf(); *pfrontp++ = slctab[SLC_ABORT].sptr ? @@ -1200,7 +1200,7 @@ sendsusp(void) #ifdef SIGTSTP ptyflush(); /* half-hearted */ # ifdef TCSIG - (void) ioctl(pty, TCSIG, (char *)SIGTSTP); + (void) ioctl(pty, TCSIG, SIGTSTP); # else /* TCSIG */ *pfrontp++ = slctab[SLC_SUSP].sptr ? (unsigned char)*slctab[SLC_SUSP].sptr : '\032'; @@ -1217,7 +1217,7 @@ recv_ayt(void) { #if defined(SIGINFO) && defined(TCSIG) if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) { - (void) ioctl(pty, TCSIG, (char *)SIGINFO); + (void) ioctl(pty, TCSIG, SIGINFO); return; } #endif diff --git a/sys/dev/atkbdc/atkbd.c b/sys/dev/atkbdc/atkbd.c index 99877874889f..c9c55d35058a 100644 --- a/sys/dev/atkbdc/atkbd.c +++ b/sys/dev/atkbdc/atkbd.c @@ -854,6 +854,7 @@ atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) int error; int s; int i; + int ival; s = spltty(); switch (cmd) { @@ -861,6 +862,10 @@ atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGKBMODE: /* get keyboard mode */ *(int *)arg = state->ks_mode; break; + case _IO('K', 7): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: @@ -886,6 +891,10 @@ atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGETLED: /* get keyboard LED */ *(int *)arg = KBD_LED_VAL(kbd); break; + case _IO('K', 66): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ if (*(int *)arg & ~LOCK_MASK) { @@ -915,6 +924,10 @@ atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGKBSTATE: /* get lock key state */ *(int *)arg = state->ks_state & LOCK_MASK; break; + case _IO('K', 20): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { splx(s); @@ -938,6 +951,10 @@ atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) } return error; + case _IO('K', 67): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETRAD: /* set keyboard repeat rate (old interface) */ splx(s); if (!KBD_HAS_DEVICE(kbd)) diff --git a/sys/dev/digi/digi.c b/sys/dev/digi/digi.c index 82b9cf119d85..66f0b96a195c 100644 --- a/sys/dev/digi/digi.c +++ b/sys/dev/digi/digi.c @@ -913,6 +913,7 @@ digiioctl(struct tty *tp, u_long cmd, void *data, int flag, struct thread *td) { struct digi_softc *sc; struct digi_p *port; + int ival; port = tp->t_sc; sc = port->sc; @@ -942,8 +943,12 @@ digiioctl(struct tty *tp, u_long cmd, void *data, int flag, struct thread *td) } } return (0); + case _IO('e', 'C'): + ival = IOCPARM_IVAL(data); + data = &ival; + /* FALLTHROUGH */ case DIGIIO_RING: - port->send_ring = *(u_char *)data; + port->send_ring = (u_char)*(int *)data; break; default: return (ENOTTY); diff --git a/sys/dev/kbdmux/kbdmux.c b/sys/dev/kbdmux/kbdmux.c index d058b8acf2ba..b9da79adc70e 100644 --- a/sys/dev/kbdmux/kbdmux.c +++ b/sys/dev/kbdmux/kbdmux.c @@ -940,6 +940,7 @@ kbdmux_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) kbdmux_kbd_t *k; keyboard_info_t *ki; int error = 0, mode; + int ival; if (state == NULL) return (ENXIO); @@ -1048,6 +1049,10 @@ kbdmux_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) KBDMUX_UNLOCK(state); break; + case _IO('K', 7): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: /* set keyboard mode */ KBDMUX_LOCK(state); @@ -1082,6 +1087,10 @@ kbdmux_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) KBDMUX_UNLOCK(state); break; + case _IO('K', 66): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: /* set keyboard LED */ KBDMUX_LOCK(state); @@ -1107,6 +1116,10 @@ kbdmux_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) KBDMUX_UNLOCK(state); break; + case _IO('K', 20): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: /* set lock key state */ KBDMUX_LOCK(state); @@ -1128,6 +1141,11 @@ kbdmux_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) return (kbdmux_ioctl(kbd, KDSETLED, arg)); /* NOT REACHED */ + case _IO('K', 67): + cmd = KDSETRAD; + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETREPEAT: /* set keyboard repeat rate (new interface) */ case KDSETRAD: /* set keyboard repeat rate (old interface) */ KBDMUX_LOCK(state); diff --git a/sys/dev/syscons/scvidctl.c b/sys/dev/syscons/scvidctl.c index f2debe35e824..82da7b1f6cf3 100644 --- a/sys/dev/syscons/scvidctl.c +++ b/sys/dev/syscons/scvidctl.c @@ -482,6 +482,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread * video_adapter_info_t adp_info; int error; int s; + int ival; scp = SC_STAT(tp->t_dev); if (scp == NULL) /* tp == SC_MOUSE */ @@ -584,6 +585,10 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread * case FBIO_FINDMODE: return fb_ioctl(adp, FBIO_FINDMODE, data); + case _IO('c', 104): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case CONS_SETWINORG: /* set frame buffer window origin */ case FBIO_SETWINORG: if (scp != scp->sc->cur_scp) @@ -675,8 +680,12 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread * return sc_set_graphics_mode(scp, tp, cmd & 0xff); #endif /* SC_NO_MODE_CHANGE */ + case _IO('K', 10): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETMODE: /* set current mode of this (virtual) console */ - switch (*(intptr_t *)data) { + switch (*(int *)data) { case KD_TEXT: /* switch to TEXT (known) mode */ /* * If scp->mode is of graphics modes, we don't know which @@ -804,8 +813,12 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread * *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT; return 0; + case _IO('K', 13): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSBORDER: /* set border color of this (virtual) console */ - scp->border = *(intptr_t *)data; + scp->border = *(int *)data; if (scp == scp->sc->cur_scp) sc_set_border(scp, scp->border); return 0; diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index 8c6da43a4cf8..8541a20eca9f 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -683,6 +683,7 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) sc_softc_t *sc; scr_stat *scp; int s; + int ival; tp = dev->si_tty; @@ -983,6 +984,10 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) bcopy(&scp->smode, data, sizeof(struct vt_mode)); return 0; + case _IO('v', 4): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case VT_RELDISP: /* screen switcher ioctl */ s = spltty(); /* @@ -999,7 +1004,7 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) return EPERM; } error = EINVAL; - switch(*(intptr_t *)data) { + switch(*(int *)data) { case VT_FALSE: /* user refuses to release screen, abort */ if ((error = finish_vt_rel(scp, FALSE, &s)) == 0) DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit)); @@ -1028,15 +1033,23 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) } return EINVAL; + case _IO('v', 5): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case VT_ACTIVATE: /* switch to screen *data */ - i = (*(intptr_t *)data == 0) ? scp->index : (*(intptr_t *)data - 1); + i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1); s = spltty(); sc_clean_up(sc->cur_scp); splx(s); return sc_switch_scr(sc, i); + case _IO('v', 6): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case VT_WAITACTIVE: /* wait for switch to occur */ - i = (*(intptr_t *)data == 0) ? scp->index : (*(intptr_t *)data - 1); + i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1); if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) return EINVAL; s = spltty(); @@ -1088,6 +1101,10 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) #endif return 0; + case _IO('K', 20): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: /* set keyboard state (locks) */ if (*(int *)data & ~LOCK_MASK) return EINVAL; @@ -1110,14 +1127,22 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) error = ENODEV; return error; + case _IO('K', 67): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETRAD: /* set keyboard repeat & delay rates (old) */ if (*(int *)data & ~0x7f) return EINVAL; - error = kbd_ioctl(sc->kbd, cmd, data); + error = kbd_ioctl(sc->kbd, KDSETRAD, data); if (error == ENOIOCTL) error = ENODEV; return error; + case _IO('K', 7): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: /* set keyboard mode */ switch (*(int *)data) { case K_XLATE: /* switch to XLT ascii mode */ @@ -1125,7 +1150,7 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) case K_CODE: /* switch to CODE mode */ scp->kbd_mode = *(int *)data; if (scp == sc->cur_scp) - kbd_ioctl(sc->kbd, cmd, data); + kbd_ioctl(sc->kbd, KDSKBMODE, data); return 0; default: return EINVAL; @@ -1142,6 +1167,10 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) error = ENODEV; return error; + case _IO('K', 8): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDMKTONE: /* sound the bell */ if (*(int*)data) sc_bell(scp, (*(int*)data)&0xffff, @@ -1150,6 +1179,10 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) sc_bell(scp, scp->bell_pitch, scp->bell_duration); return 0; + case _IO('K', 63): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KIOCSOUND: /* make tone (*data) hz */ if (scp == sc->cur_scp) { if (*(int *)data) @@ -1167,6 +1200,10 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) } return 0; + case _IO('K', 66): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: /* set keyboard LED status */ if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */ return EINVAL; @@ -1189,6 +1226,10 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) error = ENODEV; return error; + case _IO('c', 110): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case CONS_SETKBD: /* set the new keyboard */ { keyboard_t *newkbd; diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c index f5cd40a9b0e5..4cdc61e07d89 100644 --- a/sys/dev/uart/uart_kbd_sun.c +++ b/sys/dev/uart/uart_kbd_sun.c @@ -425,6 +425,7 @@ sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) { struct sunkbd_softc *sc; int error; + int ival; sc = (struct sunkbd_softc *)kbd; error = 0; @@ -432,6 +433,10 @@ sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) case KDGKBMODE: *(int *)data = sc->sc_mode; break; + case _IO('K', 7): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: switch (*(int *)data) { case K_XLATE: @@ -456,6 +461,10 @@ sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) case KDGETLED: *(int *)data = KBD_LED_VAL(kbd); break; + case _IO('K', 66): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: if (*(int *)data & ~LOCK_MASK) { error = EINVAL; @@ -478,6 +487,10 @@ sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) case KDGKBSTATE: *(int *)data = sc->sc_state & LOCK_MASK; break; + case _IO('K', 20): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: if (*(int *)data & ~LOCK_MASK) { error = EINVAL; @@ -485,7 +498,8 @@ sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) } sc->sc_state &= ~LOCK_MASK; sc->sc_state |= *(int *)data; - break; + /* set LEDs and quit */ + return (sunkbd_ioctl(kbd, KDSETLED, data)); case KDSETREPEAT: case KDSETRAD: break; diff --git a/sys/dev/usb/ukbd.c b/sys/dev/usb/ukbd.c index 4617e4fe3187..661f65329ea4 100644 --- a/sys/dev/usb/ukbd.c +++ b/sys/dev/usb/ukbd.c @@ -1159,6 +1159,7 @@ ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) ukbd_state_t *state = kbd->kb_data; int s; int i; + int ival; s = splusb(); switch (cmd) { @@ -1166,6 +1167,10 @@ ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGKBMODE: /* get keyboard mode */ *(int *)arg = state->ks_mode; break; + case _IO('K', 7): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: @@ -1191,6 +1196,10 @@ ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGETLED: /* get keyboard LED */ *(int *)arg = KBD_LED_VAL(kbd); break; + case _IO('K', 66): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ if (*(int *)arg & ~LOCK_MASK) { @@ -1215,6 +1224,10 @@ ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGKBSTATE: /* get lock key state */ *(int *)arg = state->ks_state & LOCK_MASK; break; + case _IO('K', 20): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { splx(s); @@ -1241,6 +1254,10 @@ ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) kbd->kb_delay2 = ((int *)arg)[1]; return 0; + case _IO('K', 67): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETRAD: /* set keyboard repeat rate (old interface) */ splx(s); return set_typematic(kbd, *(int *)arg); diff --git a/sys/dev/vkbd/vkbd.c b/sys/dev/vkbd/vkbd.c index 7795318b33b2..f0dfd3aeba2c 100644 --- a/sys/dev/vkbd/vkbd.c +++ b/sys/dev/vkbd/vkbd.c @@ -1092,6 +1092,7 @@ vkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) { vkbd_state_t *state = (vkbd_state_t *) kbd->kb_data; int i; + int ival; VKBD_LOCK(state); @@ -1100,6 +1101,10 @@ vkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) *(int *)arg = state->ks_mode; break; + case _IO('K', 7): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: @@ -1130,6 +1135,10 @@ vkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) *(int *)arg = KBD_LED_VAL(kbd); break; + case _IO('K', 66): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ if (*(int *)arg & ~LOCK_MASK) { @@ -1155,6 +1164,10 @@ vkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) *(int *)arg = state->ks_state & LOCK_MASK; break; + case _IO('K', 20): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { VKBD_UNLOCK(state); @@ -1174,6 +1187,10 @@ vkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) vkbd_status_changed(state); break; + case _IO('K', 67): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETRAD: /* set keyboard repeat rate (old interface) */ kbd->kb_delay1 = typematic_delay(*(int *)arg); kbd->kb_delay2 = typematic_rate(*(int *)arg); diff --git a/sys/fs/procfs/procfs_ioctl.c b/sys/fs/procfs/procfs_ioctl.c index 7acf7d25333d..8d5648f29a98 100644 --- a/sys/fs/procfs/procfs_ioctl.c +++ b/sys/fs/procfs/procfs_ioctl.c @@ -65,6 +65,7 @@ procfs_ioctl(PFS_IOCTL_ARGS) struct procfs_status32 *ps32; #endif int error, flags, sig; + int ival; PROC_LOCK(p); error = 0; @@ -72,20 +73,29 @@ procfs_ioctl(PFS_IOCTL_ARGS) #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 1, 0): #endif + case _IO('p', 1): + ival = IOCPARM_IVAL(data); + data = &ival; case PIOCBIS: - p->p_stops |= *(uintptr_t *)data; + p->p_stops |= *(unsigned int *)data; break; #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 2, 0): #endif + case _IO('p', 2): + ival = IOCPARM_IVAL(data); + data = &ival; case PIOCBIC: - p->p_stops &= ~*(uintptr_t *)data; + p->p_stops &= ~*(unsigned int *)data; break; #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 3, 0): #endif + case _IO('p', 3): + ival = IOCPARM_IVAL(data); + data = &ival; case PIOCSFL: - flags = *(uintptr_t *)data; + flags = *(unsigned int *)data; if (flags & PF_ISUGID && (error = suser(td)) != 0) break; p->p_pfsflags = flags; @@ -132,10 +142,13 @@ procfs_ioctl(PFS_IOCTL_ARGS) #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 5, 0): #endif + case _IO('p', 5): + ival = IOCPARM_IVAL(data); + data = &ival; case PIOCCONT: if (p->p_step == 0) break; - sig = *(uintptr_t *)data; + sig = *(unsigned int *)data; if (sig != 0 && !_SIG_VALID(sig)) { error = EINVAL; break; diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 3c7199a28cd7..13994b1e4e77 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -526,7 +526,7 @@ ioctl(struct thread *td, struct ioctl_args *uap) struct file *fp; struct filedesc *fdp; u_long com; - int error = 0; + int arg, error; u_int size; caddr_t data, memp; int tmp; @@ -571,14 +571,21 @@ ioctl(struct thread *td, struct ioctl_args *uap) #else ((com & (IOC_IN | IOC_OUT)) && size == 0) || #endif - ((com & IOC_VOID) && size > 0)) { + ((com & IOC_VOID) && size > 0 && size != sizeof(int))) { fdrop(fp, td); return (ENOTTY); } if (size > 0) { - memp = malloc((u_long)size, M_IOCTLOPS, M_WAITOK); - data = memp; + if (!(com & IOC_VOID)) { + memp = malloc((u_long)size, M_IOCTLOPS, M_WAITOK); + data = memp; + } else { + /* Integer argument. */ + memp = NULL; + arg = (intptr_t)uap->data; + data = (void *)&arg; + } } else { memp = NULL; data = (void *)&uap->data; diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 68b13e497bf8..e34b94cc164e 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -522,6 +522,7 @@ ptcioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td { struct tty *tp = dev->si_tty; struct ptsc *pt = dev->si_drv1; + int ival; switch (cmd) { @@ -578,6 +579,10 @@ ptcioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td ndflush(&tp->t_outq, tp->t_outq.c_cc); break; + case _IO('t', 95): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case TIOCSIG: if (*(unsigned int *)data >= NSIG || *(unsigned int *)data == 0) diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index c28a638a06ed..3c2b34976af5 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -612,6 +612,7 @@ tapioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td struct tapinfo *tapp = NULL; int s; int f; + int ival; switch (cmd) { case TAPSIFINFO: @@ -686,8 +687,12 @@ tapioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td bcopy(&ifp->if_flags, data, sizeof(ifp->if_flags)); break; + case _IO('V', 0): + ival = IOCPARM_IVAL(data); + data = (caddr_t)&ival; + /* FALLTHROUGH */ case VMIO_SIOCSIFFLAGS: /* VMware/VMnet SIOCSIFFLAGS */ - f = *(intptr_t *)data; + f = *(int *)data; f &= 0x0fff; f &= ~IFF_CANTCHANGE; f |= IFF_UP; diff --git a/sys/net/if_tap.h b/sys/net/if_tap.h index daaddf73d648..0086285e340c 100644 --- a/sys/net/if_tap.h +++ b/sys/net/if_tap.h @@ -57,7 +57,7 @@ struct tapinfo { #define TAPGIFINFO _IOR('t', 92, struct tapinfo) /* VMware ioctl's */ -#define VMIO_SIOCSIFFLAGS _IO('V', 0) +#define VMIO_SIOCSIFFLAGS _IOWINT('V', 0) #define VMIO_SIOCSKEEP _IO('V', 1) #define VMIO_SIOCSIFBR _IO('V', 2) #define VMIO_SIOCSLADRF _IO('V', 3) diff --git a/sys/pc98/cbus/pckbd.c b/sys/pc98/cbus/pckbd.c index 7eed7ca52be7..9c9e3e7853b1 100644 --- a/sys/pc98/cbus/pckbd.c +++ b/sys/pc98/cbus/pckbd.c @@ -705,6 +705,7 @@ pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) pckbd_state_t *state = kbd->kb_data; int s; int i; + int ival; s = spltty(); switch (cmd) { @@ -712,6 +713,10 @@ pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGKBMODE: /* get keyboard mode */ *(int *)arg = state->ks_mode; break; + case _IO('K', 7): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: @@ -737,6 +742,10 @@ pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGETLED: /* get keyboard LED */ *(int *)arg = KBD_LED_VAL(kbd); break; + case _IO('K', 66): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ if (*(int *)arg & ~LOCK_MASK) { @@ -757,6 +766,10 @@ pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) case KDGKBSTATE: /* get lock key state */ *(int *)arg = state->ks_state & LOCK_MASK; break; + case _IO('K', 20): + ival = IOCPARM_IVAL(arg); + arg = (caddr_t)&ival; + /* FALLTHROUGH */ case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { splx(s); diff --git a/sys/sys/consio.h b/sys/sys/consio.h index 505ef060d964..7b18ade1b541 100644 --- a/sys/sys/consio.h +++ b/sys/sys/consio.h @@ -51,10 +51,10 @@ #define KD_TEXT1 2 /* set text mode !restore fonts */ #define KD_PIXEL 3 /* set pixel mode */ #define KDGETMODE _IOR('K', 9, int) -#define KDSETMODE _IO('K', 10 /*, int */) +#define KDSETMODE _IOWINT('K', 10) /* set border color */ -#define KDSBORDER _IO('K', 13 /*, int */) +#define KDSBORDER _IOWINT('K', 13) /* set up raster(pixel) text mode */ struct _scr_size { @@ -255,10 +255,10 @@ typedef struct vid_info vid_info_t; #define CONS_FINDMODE _IOWR('c', 103, video_info_t) /* set the frame buffer window origin (equivalent to FBIO_SETWINORG) */ -#define CONS_SETWINORG _IO('c', 104 /*, u_int */) +#define CONS_SETWINORG _IOWINT('c', 104) /* use the specified keyboard */ -#define CONS_SETKBD _IO('c', 110 /*, int */) +#define CONS_SETKBD _IOWINT('c', 110) /* release the current keyboard */ #define CONS_RELKBD _IO('c', 111) @@ -320,13 +320,13 @@ typedef struct vt_mode vtmode_t; #define VT_FALSE 0 #define VT_TRUE 1 #define VT_ACKACQ 2 -#define VT_RELDISP _IO('v', 4 /*, int */) +#define VT_RELDISP _IOWINT('v', 4) /* activate the specified vty */ -#define VT_ACTIVATE _IO('v', 5 /*, int */) +#define VT_ACTIVATE _IOWINT('v', 5) /* wait until the specified vty is activate */ -#define VT_WAITACTIVE _IO('v', 6 /*, int */) +#define VT_WAITACTIVE _IOWINT('v', 6) /* get the currently active vty */ #define VT_GETACTIVE _IOR('v', 7, int) diff --git a/sys/sys/digiio.h b/sys/sys/digiio.h index 7382c0a77f77..57824dcd19a5 100644 --- a/sys/sys/digiio.h +++ b/sys/sys/digiio.h @@ -59,7 +59,7 @@ enum { #define DIGIIO_REINIT _IO('e', 'A') #define DIGIIO_DEBUG _IOW('e', 'B', int) -#define DIGIIO_RING _IO('e', 'C') +#define DIGIIO_RING _IOWINT('e', 'C') #define DIGIIO_MODEL _IOR('e', 'D', enum digi_model) #define DIGIIO_IDENT _IOW('e', 'E', char *) #define DIGIIO_SETALTPIN _IOW('e', 'F', int) diff --git a/sys/sys/ioccom.h b/sys/sys/ioccom.h index 7d25b393f3ec..4c62d48281c4 100644 --- a/sys/sys/ioccom.h +++ b/sys/sys/ioccom.h @@ -48,17 +48,22 @@ #define IOC_OUT 0x40000000 /* copy out parameters */ #define IOC_IN 0x80000000 /* copy in parameters */ #define IOC_INOUT (IOC_IN|IOC_OUT) -#define IOC_DIRMASK 0xe0000000 /* mask for IN/OUT/VOID */ +#define IOC_DIRMASK (IOC_VOID|IOC_OUT|IOC_IN) #define _IOC(inout,group,num,len) \ ((unsigned long)(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))) #define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) +#define _IOWINT(g,n) _IOC(IOC_VOID, (g), (n), sizeof(int)) #define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) #define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) /* this should be _IORW, but stdio got there first */ #define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) -#ifndef _KERNEL +#ifdef _KERNEL + +#define IOCPARM_IVAL(x) ((int)(intptr_t)(void *)*(caddr_t *)(void *)(x)) + +#else #include diff --git a/sys/sys/kbio.h b/sys/sys/kbio.h index a4b1f04b6ca3..b3b05f606872 100644 --- a/sys/sys/kbio.h +++ b/sys/sys/kbio.h @@ -15,16 +15,16 @@ #define K_XLATE 1 /* keyboard returns ascii */ #define K_CODE 2 /* keyboard returns keycodes */ #define KDGKBMODE _IOR('K', 6, int) -#define KDSKBMODE _IO('K', 7 /*, int */) +#define KDSKBMODE _IOWINT('K', 7) /* make tone */ -#define KDMKTONE _IO('K', 8 /*, int */) +#define KDMKTONE _IOWINT('K', 8) /* see console.h for the definitions of the following ioctls */ #if notdef #define KDGETMODE _IOR('K', 9, int) -#define KDSETMODE _IO('K', 10 /*, int */) -#define KDSBORDER _IO('K', 13 /*, int */) +#define KDSETMODE _IOWINT('K', 10) +#define KDSBORDER _IOWINT('K', 13) #endif /* get/set keyboard lock state */ @@ -34,14 +34,14 @@ #define ALKED 8 /* AltGr locked */ #define LOCK_MASK (CLKED | NLKED | SLKED | ALKED) #define KDGKBSTATE _IOR('K', 19, int) -#define KDSKBSTATE _IO('K', 20 /*, int */) +#define KDSKBSTATE _IOWINT('K', 20) /* enable/disable I/O access */ #define KDENABIO _IO('K', 60) #define KDDISABIO _IO('K', 61) /* make sound */ -#define KIOCSOUND _IO('K', 63 /*, int */) +#define KIOCSOUND _IOWINT('K', 63) /* get keyboard model */ #define KB_OTHER 0 /* keyboard not known */ @@ -55,10 +55,10 @@ #define LED_SCR 4 /* Scroll lock LED */ #define LED_MASK (LED_CAP | LED_NUM | LED_SCR) #define KDGETLED _IOR('K', 65, int) -#define KDSETLED _IO('K', 66 /*, int */) +#define KDSETLED _IOWINT('K', 66) /* set keyboard repeat rate (obsolete, use KDSETREPEAT below) */ -#define KDSETRAD _IO('K', 67 /*, int */) +#define KDSETRAD _IOWINT('K', 67) struct keyboard_info { int kb_index; /* kbdio index# */ diff --git a/sys/sys/pioctl.h b/sys/sys/pioctl.h index 9e3233f71221..91a3229b31c0 100644 --- a/sys/sys/pioctl.h +++ b/sys/sys/pioctl.h @@ -49,12 +49,12 @@ struct procfs_status { unsigned long val; /* Any extra data */ }; -# define PIOCBIS _IO('p', 1) /* Set event flag */ -# define PIOCBIC _IO('p', 2) /* Clear event flag */ -# define PIOCSFL _IO('p', 3) /* Set flags */ +# define PIOCBIS _IOWINT('p', 1) /* Set event flag */ +# define PIOCBIC _IOWINT('p', 2) /* Clear event flag */ +# define PIOCSFL _IOWINT('p', 3) /* Set flags */ /* wait for proc to stop */ # define PIOCWAIT _IOR('p', 4, struct procfs_status) -# define PIOCCONT _IO('p', 5) /* Continue a process */ +# define PIOCCONT _IOWINT('p', 5) /* Continue a process */ /* Get proc status */ # define PIOCSTATUS _IOR('p', 6, struct procfs_status) # define PIOCGFL _IOR('p', 7, unsigned int) /* Get flags */ diff --git a/sys/sys/ttycom.h b/sys/sys/ttycom.h index 07db4ec4a532..ecba7e9acd17 100644 --- a/sys/sys/ttycom.h +++ b/sys/sys/ttycom.h @@ -123,7 +123,7 @@ struct winsize { #define TIOCSCTTY _IO('t', 97) /* become controlling tty */ /* 97-90 tun; some conflicts */ #define TIOCEXT _IOW('t', 96, int) /* pty: external processing */ -#define TIOCSIG _IO('t', 95) /* pty: generate signal */ +#define TIOCSIG _IOWINT('t', 95) /* pty: generate signal */ #define TIOCDRAIN _IO('t', 94) /* wait till output drained */ /* 92-90 tap; some conflicts */ #define TIOCMSDTRWAIT _IOW('t', 91, int) /* modem: set wait on close */ diff --git a/usr.sbin/vidcontrol/vidcontrol.c b/usr.sbin/vidcontrol/vidcontrol.c index eb307a3fdcdd..847ff3e6e23e 100644 --- a/usr.sbin/vidcontrol/vidcontrol.c +++ b/usr.sbin/vidcontrol/vidcontrol.c @@ -147,7 +147,7 @@ revert(void) { int size[3]; - ioctl(0, VT_ACTIVATE, (caddr_t) (long) cur_info.active_vty); + ioctl(0, VT_ACTIVATE, cur_info.active_vty); fprintf(stderr, "\033[=%dA", cur_info.console_info.mv_ovscan); fprintf(stderr, "\033[=%dF", cur_info.console_info.mv_norm.fore); @@ -785,7 +785,7 @@ set_console(char *arg) if (n < 1 || n > 16) { revert(); errx(1, "console number out of range"); - } else if (ioctl(0, VT_ACTIVATE, (caddr_t) (long) n) == -1) { + } else if (ioctl(0, VT_ACTIVATE, n) == -1) { revert(); errc(1, errno, "switching vty"); } -- cgit v1.3