kern cons: introduce infrastructure for console grabbing by kernel

At the moment grab and ungrab methods of all console drivers are no-ops.

Current intended meaning of the calls is that the kernel takes control of
console input.  In the future the semantics may be extended to mean that
the calling thread takes full ownership of the console (e.g. console
output from other threads could be suspended).

Inspired by:	bde
MFC after:	2 months
This commit is contained in:
Andriy Gapon 2011-12-17 15:08:43 +00:00
parent 5dc6a81580
commit 9976156f12
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=228631
15 changed files with 192 additions and 0 deletions

View File

@ -76,6 +76,8 @@ static cn_init_t cfe_cninit;
static cn_term_t cfe_cnterm;
static cn_getc_t cfe_cngetc;
static cn_putc_t cfe_cnputc;
static cn_grab_t cfe_cngrab;
static cn_ungrab_t cfe_cnungrab;
CONSOLE_DRIVER(cfe);
@ -183,6 +185,18 @@ cfe_cnterm(struct consdev *cp)
}
static void
cfe_cngrab(struct consdev *cp)
{
}
static void
cfe_cnungrab(struct consdev *cp)
{
}
static int
cfe_cngetc(struct consdev *cp)
{

View File

@ -109,6 +109,8 @@ static cn_init_t dcons_cninit;
static cn_term_t dcons_cnterm;
static cn_getc_t dcons_cngetc;
static cn_putc_t dcons_cnputc;
static cn_grab_t dcons_cngrab;
static cn_ungrab_t dcons_cnungrab;
CONSOLE_DRIVER(dcons);
@ -246,6 +248,16 @@ dcons_cnterm(struct consdev *cp)
{
}
static void
dcons_cngrab(struct consdev *cp)
{
}
static void
dcons_cnungrab(struct consdev *cp)
{
}
static int
dcons_cngetc(struct consdev *cp)
{

View File

@ -74,6 +74,8 @@ static cn_init_t ofw_cninit;
static cn_term_t ofw_cnterm;
static cn_getc_t ofw_cngetc;
static cn_putc_t ofw_cnputc;
static cn_grab_t ofw_cngrab;
static cn_ungrab_t ofw_cnungrab;
CONSOLE_DRIVER(ofw);
@ -192,6 +194,16 @@ ofw_cnterm(struct consdev *cp)
{
}
static void
ofw_cngrab(struct consdev *cp)
{
}
static void
ofw_cnungrab(struct consdev *cp)
{
}
static int
ofw_cngetc(struct consdev *cp)
{

View File

@ -2293,6 +2293,8 @@ static cn_init_t sio_cninit;
static cn_term_t sio_cnterm;
static cn_getc_t sio_cngetc;
static cn_putc_t sio_cnputc;
static cn_grab_t sio_cngrab;
static cn_ungrab_t sio_cnungrab;
CONSOLE_DRIVER(sio);
@ -2512,6 +2514,16 @@ sio_cnterm(cp)
comconsole = -1;
}
static void
sio_cngrab(struct consdev *cp)
{
}
static void
sio_cnungrab(struct consdev *cp)
{
}
static int
sio_cngetc(struct consdev *cd)
{

View File

@ -229,6 +229,8 @@ static cn_init_t sc_cninit;
static cn_term_t sc_cnterm;
static cn_getc_t sc_cngetc;
static cn_putc_t sc_cnputc;
static cn_grab_t sc_cngrab;
static cn_ungrab_t sc_cnungrab;
CONSOLE_DRIVER(sc);
@ -1608,6 +1610,16 @@ sc_cnterm(struct consdev *cp)
sc_console = NULL;
}
static void
sc_cngrab(struct consdev *cp)
{
}
static void
sc_cnungrab(struct consdev *cp)
{
}
static void
sc_cnputc(struct consdev *cd, int c)
{

View File

@ -54,6 +54,8 @@ static cn_init_t uart_cninit;
static cn_term_t uart_cnterm;
static cn_getc_t uart_cngetc;
static cn_putc_t uart_cnputc;
static cn_grab_t uart_cngrab;
static cn_ungrab_t uart_cnungrab;
CONSOLE_DRIVER(uart);
@ -107,6 +109,16 @@ uart_cnterm(struct consdev *cp)
uart_term(cp->cn_arg);
}
static void
uart_cngrab(struct consdev *cp)
{
}
static void
uart_cnungrab(struct consdev *cp)
{
}
static void
uart_cnputc(struct consdev *cp, int c)
{

View File

@ -1308,6 +1308,8 @@ static cn_init_t ucom_cninit;
static cn_term_t ucom_cnterm;
static cn_getc_t ucom_cngetc;
static cn_putc_t ucom_cnputc;
static cn_grab_t ucom_cngrab;
static cn_ungrab_t ucom_cnungrab;
CONSOLE_DRIVER(ucom);
@ -1332,6 +1334,16 @@ ucom_cnterm(struct consdev *cp)
{
}
static void
ucom_cngrab(struct consdev *cp)
{
}
static void
ucom_cnungrab(struct consdev *cp)
{
}
static int
ucom_cngetc(struct consdev *cd)
{

View File

@ -50,6 +50,8 @@ static cn_init_t xc_cninit;
static cn_term_t xc_cnterm;
static cn_getc_t xc_cngetc;
static cn_putc_t xc_cnputc;
static cn_grab_t xc_cngrab;
static cn_ungrab_t xc_cnungrab;
#define XC_POLLTIME (hz/10)
@ -126,6 +128,16 @@ xc_cnterm(struct consdev *cp)
{
}
static void
xc_cngrab(struct consdev *cp)
{
}
static void
xc_cnungrab(struct consdev *cp)
{
}
static int
xc_cngetc(struct consdev *dev)
{

View File

@ -87,6 +87,16 @@ gdb_cnterm(struct consdev *cp)
{
}
static void
gdb_cngrab(struct consdev *cp)
{
}
static void
gdb_cnungrab(struct consdev *cp)
{
}
static int
gdb_cngetc(struct consdev *cp)
{

View File

@ -101,6 +101,16 @@ ssc_cnterm(struct consdev *cp)
{
}
static void
ssc_cngrab(struct consdev *cp)
{
}
static void
ssc_cnungrab(struct consdev *cp)
{
}
static void
ssc_cnattach(void *arg)
{

View File

@ -344,6 +344,32 @@ SYSCTL_PROC(_kern, OID_AUTO, consmute, CTLTYPE_INT|CTLFLAG_RW,
0, sizeof(cn_mute), sysctl_kern_consmute, "I",
"State of the console muting");
void
cngrab()
{
struct cn_device *cnd;
struct consdev *cn;
STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) {
cn = cnd->cnd_cn;
if (!kdb_active || !(cn->cn_flags & CN_FLAG_NODEBUG))
cn->cn_ops->cn_grab(cn);
}
}
void
cnungrab()
{
struct cn_device *cnd;
struct consdev *cn;
STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) {
cn = cnd->cnd_cn;
if (!kdb_active || !(cn->cn_flags & CN_FLAG_NODEBUG))
cn->cn_ops->cn_ungrab(cn);
}
}
/*
* Low level console routines.
*/

View File

@ -49,6 +49,8 @@ static cn_init_t uart_cninit;
static cn_term_t uart_cnterm;
static cn_getc_t uart_cngetc;
static cn_putc_t uart_cnputc;
static cn_grab_t uart_cngrab;
static cn_ungrab_t uart_cnungrab;
static void
uart_cnprobe(struct consdev *cp)
@ -90,4 +92,16 @@ uart_cnterm(struct consdev * cp)
}
static void
uart_cngrab(struct consdev *cp)
{
}
static void
uart_cnungrab(struct consdev *cp)
{
}
CONSOLE_DRIVER(uart);

View File

@ -3460,6 +3460,8 @@ static cn_init_t sio_cninit;
static cn_term_t sio_cnterm;
static cn_getc_t sio_cngetc;
static cn_putc_t sio_cnputc;
static cn_grab_t sio_cngrab;
static cn_ungrab_t sio_cnungrab;
CONSOLE_DRIVER(sio);
@ -3679,6 +3681,16 @@ sio_cnterm(cp)
comconsole = -1;
}
static void
sio_cngrab(struct consdev *cp)
{
}
static void
sio_cnungrab(struct consdev *cp)
{
}
static int
sio_cngetc(struct consdev *cd)
{

View File

@ -69,6 +69,8 @@ static cn_init_t mambo_cninit;
static cn_term_t mambo_cnterm;
static cn_getc_t mambo_cngetc;
static cn_putc_t mambo_cnputc;
static cn_grab_t mambo_cngrab;
static cn_ungrab_t mambo_cnungrab;
CONSOLE_DRIVER(mambo);
@ -146,6 +148,16 @@ mambo_cnterm(struct consdev *cp)
{
}
static void
mambo_cngrab(struct consdev *cp)
{
}
static void
mambo_cnungrab(struct consdev *cp)
{
}
static int
mambo_cngetc(struct consdev *cp)
{

View File

@ -44,6 +44,8 @@ struct tty;
typedef void cn_probe_t(struct consdev *);
typedef void cn_init_t(struct consdev *);
typedef void cn_term_t(struct consdev *);
typedef void cn_grab_t(struct consdev *);
typedef void cn_ungrab_t(struct consdev *);
typedef int cn_getc_t(struct consdev *);
typedef void cn_putc_t(struct consdev *, int);
@ -58,6 +60,10 @@ struct consdev_ops {
/* kernel getchar interface */
cn_putc_t *cn_putc;
/* kernel putchar interface */
cn_grab_t *cn_grab;
/* grab console for exclusive kernel use */
cn_ungrab_t *cn_ungrab;
/* ungrab console */
};
struct consdev {
@ -99,6 +105,8 @@ extern struct tty *constty; /* Temporary virtual console. */
.cn_term = name##_cnterm, \
.cn_getc = name##_cngetc, \
.cn_putc = name##_cnputc, \
.cn_grab = name##_cngrab, \
.cn_ungrab = name##_cnungrab, \
}; \
CONSOLE_DEVICE(name##_consdev, name##_consdev_ops, NULL)
@ -109,6 +117,8 @@ int cnadd(struct consdev *);
void cnavailable(struct consdev *, int);
void cnremove(struct consdev *);
void cnselect(struct consdev *);
void cngrab(void);
void cnungrab(void);
int cncheckc(void);
int cngetc(void);
void cnputc(int);