summaryrefslogtreecommitdiffstats
path: root/sys/dev/ofw
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2008-08-20 08:31:58 +0000
committered <ed@FreeBSD.org>2008-08-20 08:31:58 +0000
commitcc3116a9380fe32a751b584f3d8083698ccfba15 (patch)
treebd0c08a66997254385160ce71ea32029b99f99f9 /sys/dev/ofw
parentb49301b5cd9ff43a7af0bd9054d9d1a328c0d212 (diff)
downloadFreeBSD-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/ofw')
-rw-r--r--sys/dev/ofw/ofw_console.c143
1 files changed, 32 insertions, 111 deletions
diff --git a/sys/dev/ofw/ofw_console.c b/sys/dev/ofw/ofw_console.c
index 156f121..bec52d6 100644
--- a/sys/dev/ofw/ofw_console.c
+++ b/sys/dev/ofw/ofw_console.c
@@ -49,15 +49,15 @@ __FBSDID("$FreeBSD$");
#endif
#define OFBURSTLEN 128 /* max number of bytes to write in one chunk */
-static d_open_t ofw_dev_open;
-static d_close_t ofw_dev_close;
-
-static struct cdevsw ofw_cdevsw = {
- .d_version = D_VERSION,
- .d_open = ofw_dev_open,
- .d_close = ofw_dev_close,
- .d_name = "ofw",
- .d_flags = D_TTY | D_NEEDGIANT,
+static tsw_open_t ofwtty_open;
+static tsw_close_t ofwtty_close;
+static tsw_outwakeup_t ofwtty_outwakeup;
+
+static struct ttydevsw ofw_ttydevsw = {
+ .tsw_flags = TF_NOPREFIX,
+ .tsw_open = ofwtty_open,
+ .tsw_close = ofwtty_close,
+ .tsw_outwakeup = ofwtty_outwakeup,
};
static struct tty *ofw_tp = NULL;
@@ -69,9 +69,6 @@ static struct callout_handle ofw_timeouthandle
static int alt_break_state;
#endif
-static void ofw_tty_start(struct tty *);
-static int ofw_tty_param(struct tty *, struct termios *);
-static void ofw_tty_stop(struct tty *, int);
static void ofw_timeout(void *);
static cn_probe_t ofw_cnprobe;
@@ -87,7 +84,7 @@ cn_drvinit(void *unused)
{
phandle_t options;
char output[32];
- struct cdev *dev;
+ struct tty *tp;
if (ofw_consdev.cn_pri != CN_DEAD &&
ofw_consdev.cn_name[0] != '\0') {
@@ -99,9 +96,9 @@ cn_drvinit(void *unused)
* XXX: This is a hack and it may result in two /dev/ttya
* XXX: devices on platforms where the sab driver works.
*/
- dev = make_dev(&ofw_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "%s",
- output);
- make_dev_alias(dev, "ofwcons");
+ tp = tty_alloc(&ofw_ttydevsw, NULL, NULL);
+ tty_makedev(tp, NULL, "%s", output);
+ tty_makealias(tp, "ofwcons");
}
}
@@ -111,112 +108,36 @@ static int stdin;
static int stdout;
static int
-ofw_dev_open(struct cdev *dev, int flag, int mode, struct thread *td)
+ofwtty_open(struct tty *tp)
{
- struct tty *tp;
- int unit;
- int error, setuptimeout;
-
- error = 0;
- setuptimeout = 0;
- unit = minor(dev);
-
- /*
- * XXX: BAD, should happen at attach time
- */
- if (dev->si_tty == NULL) {
- ofw_tp = ttyalloc();
- dev->si_tty = ofw_tp;
- ofw_tp->t_dev = dev;
- }
- tp = dev->si_tty;
-
- tp->t_oproc = ofw_tty_start;
- tp->t_param = ofw_tty_param;
- tp->t_stop = ofw_tty_stop;
- tp->t_dev = dev;
-
- if ((tp->t_state & TS_ISOPEN) == 0) {
- tp->t_state |= TS_CARR_ON;
- ttyconsolemode(tp, 0);
-
- setuptimeout = 1;
- } else if ((tp->t_state & TS_XCLUDE) &&
- priv_check(td, PRIV_TTY_EXCLUSIVE)) {
- return (EBUSY);
- }
-
- error = ttyld_open(tp, dev);
+ polltime = hz / OFWCONS_POLL_HZ;
+ if (polltime < 1)
+ polltime = 1;
- if (error == 0 && setuptimeout) {
- polltime = hz / OFWCONS_POLL_HZ;
- if (polltime < 1) {
- polltime = 1;
- }
-
- ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
- }
+ ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
- return (error);
+ return (0);
}
-static int
-ofw_dev_close(struct cdev *dev, int flag, int mode, struct thread *td)
+static void
+ofwtty_close(struct tty *tp)
{
- int unit;
- struct tty *tp;
-
- unit = minor(dev);
- tp = dev->si_tty;
-
- if (unit != 0) {
- return (ENXIO);
- }
/* XXX Should be replaced with callout_stop(9) */
untimeout(ofw_timeout, tp, ofw_timeouthandle);
- ttyld_close(tp, flag);
- tty_close(tp);
-
- return (0);
-}
-
-
-static int
-ofw_tty_param(struct tty *tp, struct termios *t)
-{
-
- return (0);
}
static void
-ofw_tty_start(struct tty *tp)
+ofwtty_outwakeup(struct tty *tp)
{
- struct clist *cl;
int len;
u_char buf[OFBURSTLEN];
-
- if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
- return;
-
- tp->t_state |= TS_BUSY;
- cl = &tp->t_outq;
- len = q_to_b(cl, buf, OFBURSTLEN);
- OF_write(stdout, buf, len);
- tp->t_state &= ~TS_BUSY;
-
- ttwwakeup(tp);
-}
-
-static void
-ofw_tty_stop(struct tty *tp, int flag)
-{
-
- if (tp->t_state & TS_BUSY) {
- if ((tp->t_state & TS_TTSTOP) == 0) {
- tp->t_state |= TS_FLUSH;
- }
+ for (;;) {
+ len = ttydisc_getc(tp, buf, sizeof buf);
+ if (len == 0)
+ break;
+ OF_write(stdout, buf, len);
}
}
@@ -228,11 +149,11 @@ ofw_timeout(void *v)
tp = (struct tty *)v;
- while ((c = ofw_cngetc(NULL)) != -1) {
- if (tp->t_state & TS_ISOPEN) {
- ttyld_rint(tp, c);
- }
- }
+ tty_lock(tp);
+ while ((c = ofw_cngetc(NULL)) != -1)
+ ttydisc_rint(tp, c, 0);
+ ttydisc_rint_done(tp);
+ tty_unlock(tp);
ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
}
OpenPOWER on IntegriCloud