2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2001-06-16 07:17:56 +00:00
|
|
|
* Copyright (C) 2001 Benno Rice.
|
|
|
|
* 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 Benno Rice ``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 TOOLS GMBH 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.
|
|
|
|
*/
|
|
|
|
|
2003-04-03 21:36:33 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2004-06-24 02:57:11 +00:00
|
|
|
#include "opt_ofw.h"
|
2003-02-07 16:20:09 +00:00
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
#include <sys/param.h>
|
2004-07-10 21:07:44 +00:00
|
|
|
#include <sys/kdb.h>
|
2001-06-16 07:17:56 +00:00
|
|
|
#include <sys/kernel.h>
|
2006-11-06 17:43:10 +00:00
|
|
|
#include <sys/priv.h>
|
2001-06-16 07:17:56 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/cons.h>
|
|
|
|
#include <sys/consio.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
|
2003-02-07 16:20:09 +00:00
|
|
|
#include <ddb/ddb.h>
|
|
|
|
|
2004-06-24 02:57:11 +00:00
|
|
|
#ifndef OFWCONS_POLL_HZ
|
|
|
|
#define OFWCONS_POLL_HZ 4 /* 50-100 works best on Ultra2 */
|
|
|
|
#endif
|
|
|
|
#define OFBURSTLEN 128 /* max number of bytes to write in one chunk */
|
2001-06-16 07:17:56 +00:00
|
|
|
|
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
2008-08-20 08:31:58 +00:00
|
|
|
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,
|
2001-06-16 07:17:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int polltime;
|
|
|
|
static struct callout_handle ofw_timeouthandle
|
|
|
|
= CALLOUT_HANDLE_INITIALIZER(&ofw_timeouthandle);
|
|
|
|
|
Attempt to make break-to-debugger and alternative break-to-debugger more
accessible:
(1) Always compile in support for breaking into the debugger if options
KDB is present in the kernel.
(2) Disable both by default, but allow them to be enabled via tunables
and sysctls debug.kdb.break_to_debugger and
debug.kdb.alt_break_to_debugger.
(3) options BREAK_TO_DEBUGGER and options ALT_BREAK_TO_DEBUGGER continue
to behave as before -- only now instead of compiling in
break-to-debugger support, they change the default values of the
above sysctls to enable those features by default. Current kernel
configurations should, therefore, continue to behave as expected.
(4) Migrate alternative break-to-debugger state machine logic out of
individual device drivers into centralised KDB code. This has a
number of upsides, but also one downside: it's now tricky to release
sio spin locks when entering the debugger, so we don't. However,
similar logic does not exist in other device drivers, including uart.
(5) dcons requires some special handling; unlike other console types, it
allows overriding KDB's own debugger selection, so we need a new
interface to KDB to allow that to work.
GENERIC kernels in -CURRENT will now support break-to-debugger as long as
appropriate boot/run-time options are set, which should improve the
debuggability of BETA kernels significantly.
MFC after: 3 weeks
Reviewed by: kib, nwhitehorn
Approved by: re (bz)
2011-08-26 21:46:36 +00:00
|
|
|
#if defined(KDB)
|
2003-02-07 16:20:09 +00:00
|
|
|
static int alt_break_state;
|
|
|
|
#endif
|
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
static void ofw_timeout(void *);
|
|
|
|
|
2006-05-26 18:25:34 +00:00
|
|
|
static cn_probe_t ofw_cnprobe;
|
|
|
|
static cn_init_t ofw_cninit;
|
|
|
|
static cn_term_t ofw_cnterm;
|
|
|
|
static cn_getc_t ofw_cngetc;
|
|
|
|
static cn_putc_t ofw_cnputc;
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2006-05-30 07:56:57 +00:00
|
|
|
CONSOLE_DRIVER(ofw);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2002-01-09 04:03:55 +00:00
|
|
|
static void
|
|
|
|
cn_drvinit(void *unused)
|
|
|
|
{
|
2002-11-18 06:19:12 +00:00
|
|
|
phandle_t options;
|
|
|
|
char output[32];
|
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
2008-08-20 08:31:58 +00:00
|
|
|
struct tty *tp;
|
2002-11-18 06:19:12 +00:00
|
|
|
|
2003-09-28 06:51:47 +00:00
|
|
|
if (ofw_consdev.cn_pri != CN_DEAD &&
|
|
|
|
ofw_consdev.cn_name[0] != '\0') {
|
2002-11-18 06:19:12 +00:00
|
|
|
if ((options = OF_finddevice("/options")) == -1 ||
|
|
|
|
OF_getprop(options, "output-device", output,
|
|
|
|
sizeof(output)) == -1)
|
|
|
|
return;
|
2004-10-12 21:23:33 +00:00
|
|
|
/*
|
|
|
|
* XXX: This is a hack and it may result in two /dev/ttya
|
|
|
|
* XXX: devices on platforms where the sab driver works.
|
|
|
|
*/
|
2009-05-29 06:41:23 +00:00
|
|
|
tp = tty_alloc(&ofw_ttydevsw, NULL);
|
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
2008-08-20 08:31:58 +00:00
|
|
|
tty_makedev(tp, NULL, "%s", output);
|
|
|
|
tty_makealias(tp, "ofwcons");
|
2002-11-18 06:19:12 +00:00
|
|
|
}
|
2002-01-09 04:03:55 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);
|
2002-01-09 04:03:55 +00:00
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
static int stdin;
|
|
|
|
static int stdout;
|
|
|
|
|
|
|
|
static int
|
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
2008-08-20 08:31:58 +00:00
|
|
|
ofwtty_open(struct tty *tp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
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
2008-08-20 08:31:58 +00:00
|
|
|
polltime = hz / OFWCONS_POLL_HZ;
|
|
|
|
if (polltime < 1)
|
|
|
|
polltime = 1;
|
2001-06-16 07:17:56 +00:00
|
|
|
|
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
2008-08-20 08:31:58 +00:00
|
|
|
ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
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
2008-08-20 08:31:58 +00:00
|
|
|
return (0);
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
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
2008-08-20 08:31:58 +00:00
|
|
|
static void
|
|
|
|
ofwtty_close(struct tty *tp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
|
2004-06-24 02:57:11 +00:00
|
|
|
/* XXX Should be replaced with callout_stop(9) */
|
|
|
|
untimeout(ofw_timeout, tp, ofw_timeouthandle);
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
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
2008-08-20 08:31:58 +00:00
|
|
|
ofwtty_outwakeup(struct tty *tp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
2004-06-24 02:57:11 +00:00
|
|
|
int len;
|
|
|
|
u_char buf[OFBURSTLEN];
|
|
|
|
|
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
2008-08-20 08:31:58 +00:00
|
|
|
for (;;) {
|
|
|
|
len = ttydisc_getc(tp, buf, sizeof buf);
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
OF_write(stdout, buf, len);
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ofw_timeout(void *v)
|
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
tp = (struct tty *)v;
|
|
|
|
|
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
2008-08-20 08:31:58 +00:00
|
|
|
tty_lock(tp);
|
|
|
|
while ((c = ofw_cngetc(NULL)) != -1)
|
|
|
|
ttydisc_rint(tp, c, 0);
|
|
|
|
ttydisc_rint_done(tp);
|
|
|
|
tty_unlock(tp);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-30 07:56:57 +00:00
|
|
|
ofw_cnprobe(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
int chosen;
|
|
|
|
|
|
|
|
if ((chosen = OF_finddevice("/chosen")) == -1) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-28 05:38:37 +00:00
|
|
|
cp->cn_pri = CN_LOW;
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-26 18:25:34 +00:00
|
|
|
ofw_cninit(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
|
2003-09-26 10:55:07 +00:00
|
|
|
/* XXX: This is the alias, but that should be good enough */
|
2008-10-27 11:45:31 +00:00
|
|
|
strcpy(cp->cn_name, "ofwcons");
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
2006-05-26 18:25:34 +00:00
|
|
|
static void
|
2006-05-30 07:56:57 +00:00
|
|
|
ofw_cnterm(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-05-26 18:25:34 +00:00
|
|
|
ofw_cngetc(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
|
2002-01-01 21:45:30 +00:00
|
|
|
if (OF_read(stdin, &ch, 1) > 0) {
|
Attempt to make break-to-debugger and alternative break-to-debugger more
accessible:
(1) Always compile in support for breaking into the debugger if options
KDB is present in the kernel.
(2) Disable both by default, but allow them to be enabled via tunables
and sysctls debug.kdb.break_to_debugger and
debug.kdb.alt_break_to_debugger.
(3) options BREAK_TO_DEBUGGER and options ALT_BREAK_TO_DEBUGGER continue
to behave as before -- only now instead of compiling in
break-to-debugger support, they change the default values of the
above sysctls to enable those features by default. Current kernel
configurations should, therefore, continue to behave as expected.
(4) Migrate alternative break-to-debugger state machine logic out of
individual device drivers into centralised KDB code. This has a
number of upsides, but also one downside: it's now tricky to release
sio spin locks when entering the debugger, so we don't. However,
similar logic does not exist in other device drivers, including uart.
(5) dcons requires some special handling; unlike other console types, it
allows overriding KDB's own debugger selection, so we need a new
interface to KDB to allow that to work.
GENERIC kernels in -CURRENT will now support break-to-debugger as long as
appropriate boot/run-time options are set, which should improve the
debuggability of BETA kernels significantly.
MFC after: 3 weeks
Reviewed by: kib, nwhitehorn
Approved by: re (bz)
2011-08-26 21:46:36 +00:00
|
|
|
#if defined(KDB)
|
|
|
|
kdb_alt_break(ch, &alt_break_state);
|
2003-02-07 16:20:09 +00:00
|
|
|
#endif
|
2001-06-16 07:17:56 +00:00
|
|
|
return (ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-26 18:25:34 +00:00
|
|
|
ofw_cnputc(struct consdev *cp, int c)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
char cbuf;
|
|
|
|
|
|
|
|
if (c == '\n') {
|
|
|
|
cbuf = '\r';
|
|
|
|
OF_write(stdout, &cbuf, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuf = c;
|
|
|
|
OF_write(stdout, &cbuf, 1);
|
|
|
|
}
|