diff options
author | ed <ed@FreeBSD.org> | 2008-08-20 08:31:58 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2008-08-20 08:31:58 +0000 |
commit | cc3116a9380fe32a751b584f3d8083698ccfba15 (patch) | |
tree | bd0c08a66997254385160ce71ea32029b99f99f9 /sys/dev/dcons | |
parent | b49301b5cd9ff43a7af0bd9054d9d1a328c0d212 (diff) | |
download | FreeBSD-src-cc3116a9380fe32a751b584f3d8083698ccfba15.zip FreeBSD-src-cc3116a9380fe32a751b584f3d8083698ccfba15.tar.gz |
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
Diffstat (limited to 'sys/dev/dcons')
-rw-r--r-- | sys/dev/dcons/dcons.h | 2 | ||||
-rw-r--r-- | sys/dev/dcons/dcons_os.c | 393 |
2 files changed, 49 insertions, 346 deletions
diff --git a/sys/dev/dcons/dcons.h b/sys/dev/dcons/dcons.h index 49ef869..e613f5b 100644 --- a/sys/dev/dcons/dcons.h +++ b/sys/dev/dcons/dcons.h @@ -98,7 +98,7 @@ struct dcons_softc { int brk_state; #define DC_GDB 1 int flags; - void *dev; + void *tty; }; int dcons_checkc(struct dcons_softc *); diff --git a/sys/dev/dcons/dcons_os.c b/sys/dev/dcons/dcons_os.c index a43cd28..aad9637 100644 --- a/sys/dev/dcons/dcons_os.c +++ b/sys/dev/dcons/dcons_os.c @@ -1,7 +1,7 @@ /*- * Copyright (C) 2003,2004 * Hidetoshi Shimokawa. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -18,7 +18,7 @@ * 4. Neither the name of the author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 @@ -30,15 +30,13 @@ * 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 <sys/param.h> -#if __FreeBSD_version >= 502122 #include <sys/kdb.h> #include <gdb/gdb.h> -#endif #include <sys/kernel.h> #include <sys/module.h> #include <sys/systm.h> @@ -54,13 +52,8 @@ #include <machine/bus.h> -#ifdef __DragonFly__ -#include "dcons.h" -#include "dcons_os.h" -#else #include <dev/dcons/dcons.h> #include <dev/dcons/dcons_os.h> -#endif #include <ddb/ddb.h> #include <sys/reboot.h> @@ -90,53 +83,6 @@ #define DCONS_FORCE_CONSOLE 0 /* Mostly for FreeBSD-4/DragonFly */ #endif -#ifndef DCONS_FORCE_GDB -#define DCONS_FORCE_GDB 1 -#endif - -#if __FreeBSD_version >= 500101 -#define CONS_NODEV 1 -#if __FreeBSD_version < 502122 -static struct consdev gdbconsdev; -#endif -#endif - -static d_open_t dcons_open; -static d_close_t dcons_close; -#if defined(__DragonFly__) || __FreeBSD_version < 500104 -static d_ioctl_t dcons_ioctl; -#endif - -static struct cdevsw dcons_cdevsw = { -#ifdef __DragonFly__ -#define CDEV_MAJOR 184 - "dcons", CDEV_MAJOR, D_TTY, NULL, 0, - dcons_open, dcons_close, ttyread, ttywrite, dcons_ioctl, - ttypoll, nommap, nostrategy, nodump, nopsize, -#elif __FreeBSD_version >= 500104 - .d_version = D_VERSION, - .d_open = dcons_open, - .d_close = dcons_close, - .d_name = "dcons", - .d_flags = D_TTY | D_NEEDGIANT, -#else -#define CDEV_MAJOR 184 - /* open */ dcons_open, - /* close */ dcons_close, - /* read */ ttyread, - /* write */ ttywrite, - /* ioctl */ dcons_ioctl, - /* poll */ ttypoll, - /* mmap */ nommap, - /* strategy */ nostrategy, - /* name */ "dcons", - /* major */ CDEV_MAJOR, - /* dump */ nodump, - /* psize */ nopsize, - /* flags */ D_TTY, -#endif -}; - #ifndef KLD_MODULE static char bssbuf[DCONS_BUF_SIZE]; /* buf in bss */ #endif @@ -156,20 +102,6 @@ static int drv_init = 0; static struct callout dcons_callout; struct dcons_buf *dcons_buf; /* for local dconschat */ -#ifdef __DragonFly__ -#define DEV dev_t -#define THREAD d_thread_t -#elif __FreeBSD_version < 500000 -#define DEV dev_t -#define THREAD struct proc -#else -#define DEV struct cdev * -#define THREAD struct thread -#endif - - -static void dcons_tty_start(struct tty *); -static int dcons_tty_param(struct tty *, struct termios *); static void dcons_timeout(void *); static int dcons_drv_init(int); @@ -181,12 +113,12 @@ static cn_putc_t dcons_cnputc; CONSOLE_DRIVER(dcons); -#if defined(GDB) && (__FreeBSD_version >= 502122) -static gdb_probe_f dcons_dbg_probe; -static gdb_init_f dcons_dbg_init; -static gdb_term_f dcons_dbg_term; -static gdb_getc_f dcons_dbg_getc; -static gdb_putc_f dcons_dbg_putc; +#if defined(GDB) +static gdb_probe_f dcons_dbg_probe; +static gdb_init_f dcons_dbg_init; +static gdb_term_f dcons_dbg_term; +static gdb_getc_f dcons_dbg_getc; +static gdb_putc_f dcons_dbg_putc; GDB_DBGPORT(dcons, dcons_dbg_probe, dcons_dbg_init, dcons_dbg_term, dcons_dbg_getc, dcons_dbg_putc); @@ -194,21 +126,25 @@ GDB_DBGPORT(dcons, dcons_dbg_probe, dcons_dbg_init, dcons_dbg_term, extern struct gdb_dbgport *gdb_cur; #endif +static tsw_outwakeup_t dcons_outwakeup; + +static struct ttydevsw dcons_ttydevsw = { + .tsw_flags = TF_NOPREFIX, + .tsw_outwakeup = dcons_outwakeup, +}; + #if (defined(GDB) || defined(DDB)) && defined(ALT_BREAK_TO_DEBUGGER) static int dcons_check_break(struct dcons_softc *dc, int c) { -#if __FreeBSD_version >= 502122 int kdb_brk; -#endif + if (c < 0) return (c); -#if __FreeBSD_version >= 502122 if ((kdb_brk = kdb_alt_break(c, &dc->brk_state)) != 0) { switch (kdb_brk) { case KDB_REQ_DEBUGGER: - if ((dc->flags & DC_GDB) != 0) { #ifdef GDB if (gdb_cur == &dcons_gdb_dbgport) { @@ -229,27 +165,6 @@ dcons_check_break(struct dcons_softc *dc, int c) break; } } -#else - switch (dc->brk_state) { - case STATE1: - if (c == KEY_TILDE) - dc->brk_state = STATE2; - else - dc->brk_state = STATE0; - break; - case STATE2: - dc->brk_state = STATE0; - if (c == KEY_CTRLB) { -#if DCONS_FORCE_GDB - if (dc->flags & DC_GDB) - boothowto |= RB_GDB; -#endif - breakpoint(); - } - } - if (c == KEY_CR) - dc->brk_state = STATE1; -#endif return (c); } #else @@ -263,7 +178,7 @@ dcons_os_checkc_nopoll(struct dcons_softc *dc) if (dg.dma_tag != NULL) bus_dmamap_sync(dg.dma_tag, dg.dma_map, BUS_DMASYNC_POSTREAD); - + c = dcons_check_break(dc, dcons_checkc(dc)); if (dg.dma_tag != NULL) @@ -279,18 +194,6 @@ dcons_os_checkc(struct dcons_softc *dc) return (dcons_os_checkc_nopoll(dc)); } -#if defined(GDB) || !defined(CONS_NODEV) -static int -dcons_os_getc(struct dcons_softc *dc) -{ - int c; - - while ((c = dcons_os_checkc(dc)) == -1); - - return (c & 0xff); -} -#endif - static void dcons_os_putc(struct dcons_softc *dc, int c) { @@ -302,122 +205,17 @@ dcons_os_putc(struct dcons_softc *dc, int c) if (dg.dma_tag != NULL) bus_dmamap_sync(dg.dma_tag, dg.dma_map, BUS_DMASYNC_PREWRITE); } -static int -dcons_open(DEV dev, int flag, int mode, THREAD *td) -{ - struct tty *tp; - int unit, error, s; - - unit = minor(dev); - if (unit != 0) - return (ENXIO); - - tp = dev->si_tty; - tp->t_oproc = dcons_tty_start; - tp->t_param = dcons_tty_param; - tp->t_stop = nottystop; - tp->t_dev = dev; - - error = 0; - - s = spltty(); - if ((tp->t_state & TS_ISOPEN) == 0) { - tp->t_state |= TS_CARR_ON; - ttyconsolemode(tp, 0); - } else if ((tp->t_state & TS_XCLUDE) && - priv_check(td, PRIV_TTY_EXCLUSIVE)) { - splx(s); - return (EBUSY); - } - splx(s); - -#if __FreeBSD_version < 502113 - error = (*linesw[tp->t_line].l_open)(dev, tp); -#else - error = ttyld_open(tp, dev); -#endif - - return (error); -} - -static int -dcons_close(DEV dev, int flag, int mode, THREAD *td) -{ - int unit; - struct tty *tp; - - unit = minor(dev); - if (unit != 0) - return (ENXIO); - - tp = dev->si_tty; - if (tp->t_state & TS_ISOPEN) { -#if __FreeBSD_version < 502113 - (*linesw[tp->t_line].l_close)(tp, flag); - ttyclose(tp); -#else - ttyld_close(tp, flag); - tty_close(tp); -#endif - } - - return (0); -} - -#if defined(__DragonFly__) || __FreeBSD_version < 500104 -static int -dcons_ioctl(DEV dev, u_long cmd, caddr_t data, int flag, THREAD *td) -{ - int unit; - struct tty *tp; - int error; - - unit = minor(dev); - if (unit != 0) - return (ENXIO); - - tp = dev->si_tty; - error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td); - if (error != ENOIOCTL) - return (error); - - error = ttioctl(tp, cmd, data, flag); - if (error != ENOIOCTL) - return (error); - - return (ENOTTY); -} -#endif - -static int -dcons_tty_param(struct tty *tp, struct termios *t) -{ - tp->t_ispeed = t->c_ispeed; - tp->t_ospeed = t->c_ospeed; - tp->t_cflag = t->c_cflag; - return 0; -} static void -dcons_tty_start(struct tty *tp) +dcons_outwakeup(struct tty *tp) { struct dcons_softc *dc; - int s; - - dc = (struct dcons_softc *)tp->t_dev->si_drv1; - s = spltty(); - if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { - ttwwakeup(tp); - return; - } + char ch; - tp->t_state |= TS_BUSY; - while (tp->t_outq.c_cc != 0) - dcons_os_putc(dc, getc(&tp->t_outq)); - tp->t_state &= ~TS_BUSY; + dc = tty_softc(tp); - ttwwakeup(tp); - splx(s); + while (ttydisc_getc(tp, &ch, sizeof ch) != 0) + dcons_os_putc(dc, ch); } static void @@ -429,14 +227,13 @@ dcons_timeout(void *v) for (i = 0; i < DCONS_NPORT; i ++) { dc = &sc[i]; - tp = ((DEV)dc->dev)->si_tty; + tp = dc->tty; + + tty_lock(tp); while ((c = dcons_os_checkc_nopoll(dc)) != -1) - if (tp->t_state & TS_ISOPEN) -#if __FreeBSD_version < 502113 - (*linesw[tp->t_line].l_rint)(c, tp); -#else - ttyld_rint(tp, c); -#endif + ttydisc_rint(tp, c, 0); + ttydisc_rint_done(tp); + tty_unlock(tp); } polltime = hz / poll_hz; if (polltime < 1) @@ -447,14 +244,7 @@ dcons_timeout(void *v) static void dcons_cnprobe(struct consdev *cp) { -#ifdef __DragonFly__ - cp->cn_dev = make_dev(&dcons_cdevsw, DCONS_CON, - UID_ROOT, GID_WHEEL, 0600, "dcons"); -#elif __FreeBSD_version >= 501109 sprintf(cp->cn_name, "dcons"); -#else - cp->cn_dev = makedev(CDEV_MAJOR, DCONS_CON); -#endif #if DCONS_FORCE_CONSOLE cp->cn_pri = CN_REMOTE; #else @@ -466,12 +256,7 @@ static void dcons_cninit(struct consdev *cp) { dcons_drv_init(0); -#if CONS_NODEV - cp->cn_arg -#else - cp->cn_dev->si_drv1 -#endif - = (void *)&sc[DCONS_CON]; /* share port0 with unit0 */ + cp->cn_arg = (void *)&sc[DCONS_CON]; /* share port0 with unit0 */ } static void @@ -479,39 +264,19 @@ dcons_cnterm(struct consdev *cp) { } -#if CONS_NODEV static int dcons_cngetc(struct consdev *cp) { struct dcons_softc *dc = (struct dcons_softc *)cp->cn_arg; return (dcons_os_checkc(dc)); } + static void dcons_cnputc(struct consdev *cp, int c) { struct dcons_softc *dc = (struct dcons_softc *)cp->cn_arg; dcons_os_putc(dc, c); } -#else -static int -dcons_cngetc(DEV dev) -{ - struct dcons_softc *dc = (struct dcons_softc *)dev->si_drv1; - return (dcons_os_getc(dc)); -} -static int -dcons_cncheckc(DEV dev) -{ - struct dcons_softc *dc = (struct dcons_softc *)dev->si_drv1; - return (dcons_os_checkc(dc)); -} -static void -dcons_cnputc(DEV dev, int c) -{ - struct dcons_softc *dc = (struct dcons_softc *)dev->si_drv1; - dcons_os_putc(dc, c); -} -#endif static int dcons_drv_init(int stage) @@ -577,24 +342,6 @@ dcons_drv_init(int stage) ok: dcons_buf = dg.buf; -#if __FreeBSD_version < 502122 -#if defined(DDB) && DCONS_FORCE_GDB -#if CONS_NODEV - gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB]; -#if __FreeBSD_version >= 501109 - sprintf(gdbconsdev.cn_name, "dgdb"); -#endif - gdb_arg = &gdbconsdev; -#elif defined(__DragonFly__) - gdbdev = make_dev(&dcons_cdevsw, DCONS_GDB, - UID_ROOT, GID_WHEEL, 0600, "dgdb"); -#else - gdbdev = makedev(CDEV_MAJOR, DCONS_GDB); -#endif - gdb_getc = dcons_cngetc; - gdb_putc = dcons_cnputc; -#endif -#endif drv_init = 1; return 0; @@ -606,23 +353,12 @@ dcons_attach_port(int port, char *name, int flags) { struct dcons_softc *dc; struct tty *tp; - DEV dev; dc = &sc[port]; + tp = tty_alloc(&dcons_ttydevsw, dc, NULL); dc->flags = flags; - dev = make_dev(&dcons_cdevsw, port, - UID_ROOT, GID_WHEEL, 0600, name); - dc->dev = (void *)dev; - tp = ttyalloc(); - - dev->si_drv1 = (void *)dc; - dev->si_tty = tp; - - tp->t_oproc = dcons_tty_start; - tp->t_param = dcons_tty_param; - tp->t_stop = nottystop; - tp->t_dev = dc->dev; - + dc->tty = tp; + tty_makedev(tp, NULL, "%s", name); return(0); } @@ -631,16 +367,9 @@ dcons_attach(void) { int polltime; -#ifdef __DragonFly__ - cdevsw_add(&dcons_cdevsw, -1, 0); -#endif dcons_attach_port(DCONS_CON, "dcons", 0); dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB); -#if __FreeBSD_version < 500000 - callout_init(&dcons_callout); -#else callout_init(&dcons_callout, 0); -#endif polltime = hz / poll_hz; if (polltime < 1) polltime = 1; @@ -655,37 +384,14 @@ dcons_detach(int port) struct dcons_softc *dc; dc = &sc[port]; + tp = dc->tty; - tp = ((DEV)dc->dev)->si_tty; - - if (tp->t_state & TS_ISOPEN) { - printf("dcons: still opened\n"); -#if __FreeBSD_version < 502113 - (*linesw[tp->t_line].l_close)(tp, 0); - tp->t_gen++; - ttyclose(tp); - ttwakeup(tp); - ttwwakeup(tp); -#else - ttyld_close(tp, 0); - tty_close(tp); -#endif - } - /* XXX - * must wait until all device are closed. - */ -#ifdef __DragonFly__ - tsleep((void *)dc, 0, "dcodtc", hz/4); -#else - tsleep((void *)dc, PWAIT, "dcodtc", hz/4); -#endif - destroy_dev(dc->dev); + tty_lock(tp); + tty_rel_gone(tp); return(0); } - -/* cnXXX works only for FreeBSD-5 */ static int dcons_modevent(module_t mode, int type, void *data) { @@ -695,29 +401,16 @@ dcons_modevent(module_t mode, int type, void *data) case MOD_LOAD: ret = dcons_drv_init(1); dcons_attach(); -#if __FreeBSD_version >= 500000 if (ret == 0) { dcons_cnprobe(&dcons_consdev); dcons_cninit(&dcons_consdev); cnadd(&dcons_consdev); } -#endif break; case MOD_UNLOAD: printf("dcons: unload\n"); callout_stop(&dcons_callout); -#if __FreeBSD_version < 502122 -#if defined(DDB) && DCONS_FORCE_GDB -#if CONS_NODEV - gdb_arg = NULL; -#else - gdbdev = NULL; -#endif -#endif -#endif -#if __FreeBSD_version >= 500000 cnremove(&dcons_consdev); -#endif dcons_detach(DCONS_CON); dcons_detach(DCONS_GDB); dg.buf->magic = 0; @@ -737,10 +430,20 @@ dcons_modevent(module_t mode, int type, void *data) return(err); } -#if defined(GDB) && (__FreeBSD_version >= 502122) +#if defined(GDB) /* Debugger interface */ static int +dcons_os_getc(struct dcons_softc *dc) +{ + int c; + + while ((c = dcons_os_checkc(dc)) == -1); + + return (c & 0xff); +} + +static int dcons_dbg_probe(void) { int dcons_gdb; |