Change the console interface to pass a "struct consdev *" instead of a

dev_t to the method functions.

The dev_t can still be found at struct consdev *->cn_dev.

Add a void *cn_arg element to struct consdev which the drivers can use
for retrieving their softc.
This commit is contained in:
phk 2003-02-20 20:54:45 +00:00
parent 6cc306eaad
commit ece947dbac
21 changed files with 110 additions and 89 deletions

View File

@ -111,6 +111,7 @@
#include <sys/bio.h>
#include <sys/buf.h>
#include <sys/bus.h>
#include <sys/cons.h>
#include <sys/mbuf.h>
#include <sys/vmmeter.h>
#include <sys/msgbuf.h>

View File

@ -30,6 +30,7 @@
#include <sys/systm.h>
#include <sys/ktr.h>
#include <sys/proc.h>
#include <sys/cons.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>

View File

@ -129,9 +129,7 @@ static void leave_prom(critical_t);
* of the console area.
*/
void
promcnputc(dev, c)
dev_t dev;
int c;
promcnputc(struct consdev *cp, int c)
{
prom_return_t ret;
unsigned char *to = (unsigned char *)0x20000000;
@ -153,8 +151,7 @@ promcnputc(dev, c)
* Wait for the prom to get a real char and pass it back.
*/
int
promcngetc(dev)
dev_t dev;
promcngetc(struct consdev *cp)
{
prom_return_t ret;
register_t s;
@ -174,8 +171,7 @@ promcngetc(dev)
* If a char is ready, return it, otherwise return -1.
*/
int
promcncheckc(dev)
dev_t dev;
promcncheckc(struct consdev *cp)
{
prom_return_t ret;
register_t s;

View File

@ -209,7 +209,7 @@ promstart(tp)
tp->t_state |= TS_BUSY;
while (tp->t_outq.c_cc != 0)
promcnputc(tp->t_dev, getc(&tp->t_outq));
promcnputc(NULL, getc(&tp->t_outq));
tp->t_state &= ~TS_BUSY;
ttwwakeup(tp);
@ -240,7 +240,7 @@ promtimeout(v)
struct tty *tp = v;
int c;
while ((c = promcncheckc(tp->t_dev)) != -1) {
while ((c = promcncheckc(NULL)) != -1) {
if (tp->t_state & TS_ISOPEN)
(*linesw[tp->t_line].l_rint)(c, tp);
}

View File

@ -73,6 +73,7 @@
#include <sys/malloc.h>
#include <sys/bio.h>
#include <sys/buf.h>
#include <sys/cons.h>
#include <sys/mutex.h>
#include <sys/vnode.h>
#include <sys/vmmeter.h>

View File

@ -97,9 +97,9 @@ int prom_getenv(int, char *, int);
#ifdef _KERNEL
void promcnattach(int);
void promcndetach(void);
void promcnputc(dev_t, int);
int promcngetc(dev_t);
int promcncheckc(dev_t);
cn_putc_t promcnputc;
cn_getc_t promcngetc;
cn_checkc_t promcncheckc;
u_int64_t prom_dispatch(u_int64_t, u_int64_t, u_int64_t, u_int64_t,
u_int64_t);

View File

@ -34,6 +34,7 @@
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/bus.h>
#include <sys/cons.h>
#include <machine/bus.h>
#include <machine/md_var.h>
#include <sys/proc.h>

View File

@ -66,6 +66,7 @@
#include <vm/vm_pager.h>
#include <sys/user.h>
#include <sys/ptrace.h>
#include <sys/cons.h>
#include <machine/clock.h>
#include <machine/md_var.h>
#include <machine/reg.h>

View File

@ -216,9 +216,9 @@ zs_putc(caddr_t base, int chan, int c)
/*
* Console support
*/
int zs_cngetc(dev_t);
int zs_cncheckc(dev_t);
void zs_cnputc(dev_t, int);
cn_getc_t zs_cngetc;
cn_checkc_t zs_cncheckc;
cn_putc_t zs_cnputc;
static caddr_t zs_console_addr;
CONS_DRIVER(zs, NULL, NULL, NULL, zs_cngetc, zs_cncheckc, zs_cnputc, NULL);
@ -237,28 +237,28 @@ zs_cnattach(vm_offset_t base, vm_offset_t offset)
}
int
zs_cngetc(dev_t dev)
zs_cngetc(struct consdev *cp)
{
int s = spltty();
int c = zs_getc(zs_console_addr, minor(dev));
int c = zs_getc(zs_console_addr, minor(cp->cn_dev));
splx(s);
return c;
}
int
zs_cncheckc(dev_t dev)
zs_cncheckc(struct consdev *cp)
{
int s = spltty();
int c = zs_maygetc(zs_console_addr, minor(dev));
int c = zs_maygetc(zs_console_addr, minor(cp->cn_dev));
splx(s);
return c;
}
void
zs_cnputc(dev_t dev, int c)
zs_cnputc(struct consdev *cp, int c)
{
int s = spltty();
zs_putc(zs_console_addr, minor(dev), c);
zs_putc(zs_console_addr, minor(cp->cn_dev), c);
splx(s);
}

View File

@ -224,7 +224,7 @@ ofw_tty_start(struct tty *tp)
tp->t_state |= TS_BUSY;
while (tp->t_outq.c_cc != 0) {
ofw_cons_putc(tp->t_dev, getc(&tp->t_outq));
ofw_cons_putc(NULL, getc(&tp->t_outq));
}
tp->t_state &= ~TS_BUSY;
@ -250,7 +250,7 @@ ofw_timeout(void *v)
tp = (struct tty *)v;
while ((c = ofw_cons_checkc(tp->t_dev)) != -1) {
while ((c = ofw_cons_checkc(NULL)) != -1) {
if (tp->t_state & TS_ISOPEN) {
(*linesw[tp->t_line].l_rint)(c, tp);
}
@ -292,7 +292,7 @@ ofw_cons_init(struct consdev *cp)
}
static int
ofw_cons_getc(dev_t dev)
ofw_cons_getc(struct consdev *cp)
{
unsigned char ch;
int l;
@ -314,7 +314,7 @@ ofw_cons_getc(dev_t dev)
}
static int
ofw_cons_checkc(dev_t dev)
ofw_cons_checkc(struct consdev *cp)
{
unsigned char ch;
@ -330,7 +330,7 @@ ofw_cons_checkc(dev_t dev)
}
static void
ofw_cons_putc(dev_t dev, int c)
ofw_cons_putc(struct consdev *cp, int c)
{
char cbuf;

View File

@ -1132,7 +1132,7 @@ sab_cnterm(struct consdev *cn)
}
static int
sab_cngetc(dev_t dev)
sab_cngetc(struct consdev *cn)
{
struct sabtty_softc *sc = sabtty_cons;
@ -1142,7 +1142,7 @@ sab_cngetc(dev_t dev)
}
static int
sab_cncheckc(dev_t dev)
sab_cncheckc(struct consdev *cn)
{
struct sabtty_softc *sc = sabtty_cons;
@ -1152,7 +1152,7 @@ sab_cncheckc(dev_t dev)
}
static void
sab_cnputc(dev_t dev, int c)
sab_cnputc(struct consdev *cn, int c)
{
struct sabtty_softc *sc = sabtty_cons;
@ -1162,7 +1162,7 @@ sab_cnputc(dev_t dev, int c)
}
static void
sab_cndbctl(dev_t dev, int c)
sab_cndbctl(struct consdev *cn, int c)
{
}

View File

@ -2773,6 +2773,8 @@ CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc,
/* To get the GDB related variables */
#if DDB > 0
#include <ddb/ddb.h>
static struct consdev gdbconsdev;
#endif
static void
@ -2982,7 +2984,8 @@ siocnprobe(cp)
siogdbiobase = iobase;
siogdbunit = unit;
#if DDB > 0
gdb_arg = makedev(CDEV_MAJOR, unit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
#endif
@ -3003,7 +3006,8 @@ siocnprobe(cp)
printf("configuration file (currently sio only).\n");
siogdbiobase = siocniobase;
siogdbunit = siocnunit;
gdb_arg = makedev(CDEV_MAJOR, siocnunit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, siocnunit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
}
@ -3090,7 +3094,8 @@ siogdbattach(port, speed)
printf("sio%d: gdb debugging port\n", unit);
siogdbunit = unit;
#if DDB > 0
gdb_arg = makedev(CDEV_MAJOR, unit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
#endif
@ -3122,15 +3127,16 @@ siogdbattach(port, speed)
#endif
static int
siocncheckc(dev)
dev_t dev;
siocncheckc(struct consdev *cd)
{
int c;
dev_t dev;
Port_t iobase;
int s;
struct siocnstate sp;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;
@ -3151,15 +3157,16 @@ siocncheckc(dev)
static int
siocngetc(dev)
dev_t dev;
siocngetc(struct consdev *cd)
{
int c;
dev_t dev;
Port_t iobase;
int s;
struct siocnstate sp;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;
@ -3178,16 +3185,16 @@ siocngetc(dev)
}
static void
siocnputc(dev, c)
dev_t dev;
int c;
siocnputc(struct consdev *cd, int c)
{
int need_unlock;
int s;
dev_t dev;
struct siocnstate sp;
Port_t iobase;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;

View File

@ -1468,7 +1468,7 @@ sccnattach(void)
#endif /* __alpha__ */
static void
sccnputc(dev_t dev, int c)
sccnputc(struct consdev *cd, int c)
{
u_char buf[1];
scr_stat *scp = sc_console;
@ -1510,19 +1510,19 @@ sccnputc(dev_t dev, int c)
}
static int
sccngetc(dev_t dev)
sccngetc(struct consdev *cd)
{
return sccngetch(0);
}
static int
sccncheckc(dev_t dev)
sccncheckc(struct consdev *cd)
{
return sccngetch(SCGETC_NONBLOCK);
}
static void
sccndbctl(dev_t dev, int on)
sccndbctl(struct consdev *cd, int on)
{
/* assert(sc_console_unit >= 0) */
/* try to switch to the kernel console screen */

View File

@ -890,7 +890,7 @@ zs_cnterm(struct consdev *cn)
}
static int
zs_cngetc(dev_t dev)
zs_cngetc(struct consdev *cn)
{
struct zstty_softc *sc = zstty_cons;
@ -900,7 +900,7 @@ zs_cngetc(dev_t dev)
}
static int
zs_cncheckc(dev_t dev)
zs_cncheckc(struct consdev *cn)
{
struct zstty_softc *sc = zstty_cons;
@ -910,7 +910,7 @@ zs_cncheckc(dev_t dev)
}
static void
zs_cnputc(dev_t dev, int c)
zs_cnputc(struct consdev *cn, int c)
{
struct zstty_softc *sc = zstty_cons;
@ -920,7 +920,7 @@ zs_cnputc(dev_t dev, int c)
}
static void
zs_cndbctl(dev_t dev, int c)
zs_cndbctl(struct consdev *cn, int c)
{
}

View File

@ -725,7 +725,7 @@ pcvt_cn_term(struct consdev *cp)
* console put char
*---------------------------------------------------------------------------*/
static void
pcvt_cn_putc(dev_t dev, int c)
pcvt_cn_putc(struct consdev *cd, int c)
{
if (c == '\n')
sput("\r", 1, 1, 0);
@ -739,7 +739,7 @@ pcvt_cn_putc(dev_t dev, int c)
* console get char
*---------------------------------------------------------------------------*/
static int
pcvt_cn_getc(dev_t dev)
pcvt_cn_getc(struct consdev *cd)
{
register int s;
static u_char *cp, cbuf[4]; /* Temp buf for multi-char key sequence. */
@ -789,7 +789,7 @@ pcvt_cn_getc(dev_t dev)
* console check for char
*---------------------------------------------------------------------------*/
static int
pcvt_cn_checkc(dev_t dev)
pcvt_cn_checkc(struct consdev *cd)
{
char *cp;
int x;

View File

@ -116,13 +116,13 @@ ssccnattach(void *arg)
SYSINIT(ssccnattach, SI_SUB_DRIVERS, SI_ORDER_ANY, ssccnattach, 0);
static void
ssccnputc(dev_t dev, int c)
ssccnputc(struct consdev *cp, int c)
{
ssc(c, 0, 0, 0, SSC_PUTCHAR);
}
static int
ssccngetc(dev_t dev)
ssccngetc(struct consdev *cp)
{
int c;
do {
@ -133,7 +133,7 @@ ssccngetc(dev_t dev)
}
static int
ssccncheckc(dev_t dev)
ssccncheckc(struct consdev *cp)
{
int c;
c = ssc(0, 0, 0, 0, SSC_GETCHAR);
@ -242,7 +242,7 @@ sscstart(struct tty *tp)
tp->t_state |= TS_BUSY;
while (tp->t_outq.c_cc != 0)
ssccnputc(tp->t_dev, getc(&tp->t_outq));
ssccnputc(NULL, getc(&tp->t_outq));
tp->t_state &= ~TS_BUSY;
ttwwakeup(tp);
@ -270,7 +270,7 @@ ssctimeout(void *v)
struct tty *tp = v;
int c;
while ((c = ssccncheckc(tp->t_dev)) != -1) {
while ((c = ssccncheckc(NULL)) != -1) {
if (tp->t_state & TS_ISOPEN)
(*linesw[tp->t_line].l_rint)(c, tp);
}

View File

@ -529,7 +529,7 @@ cncheckc(void)
return (-1);
STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) {
cn = cnd->cnd_cn;
c = cn->cn_checkc(cn->cn_dev);
c = cn->cn_checkc(cn);
if (c != -1) {
return (c);
}
@ -549,8 +549,8 @@ cnputc(int c)
STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) {
cn = cnd->cnd_cn;
if (c == '\n')
cn->cn_putc(cn->cn_dev, '\r');
cn->cn_putc(cn->cn_dev, c);
cn->cn_putc(cn, '\r');
cn->cn_putc(cn, c);
}
#ifdef DDB
if (console_pausing && !db_active && (c == '\n')) {
@ -581,7 +581,7 @@ cndbctl(int on)
STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) {
cn = cnd->cnd_cn;
if (cn->cn_dbctl != NULL)
cn->cn_dbctl(cn->cn_dev, on);
cn->cn_dbctl(cn, on);
}
if (on)
refcount++;

View File

@ -4003,6 +4003,7 @@ CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc,
/* To get the GDB related variables */
#if DDB > 0
#include <ddb/ddb.h>
struct consdev gdbconsdev;
#endif
static void
@ -4212,7 +4213,8 @@ siocnprobe(cp)
siogdbiobase = iobase;
siogdbunit = unit;
#if DDB > 0
gdb_arg = makedev(CDEV_MAJOR, unit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
#endif
@ -4233,7 +4235,8 @@ siocnprobe(cp)
printf("configuration file (currently sio only).\n");
siogdbiobase = siocniobase;
siogdbunit = siocnunit;
gdb_arg = makedev(CDEV_MAJOR, siocnunit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, siocnunit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
}
@ -4320,7 +4323,8 @@ siogdbattach(port, speed)
printf("sio%d: gdb debugging port\n", unit);
siogdbunit = unit;
#if DDB > 0
gdb_arg = makedev(CDEV_MAJOR, unit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
#endif
@ -4352,15 +4356,16 @@ siogdbattach(port, speed)
#endif
static int
siocncheckc(dev)
dev_t dev;
siocncheckc(struct consdev *cd)
{
int c;
dev_t dev;
Port_t iobase;
int s;
struct siocnstate sp;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;
@ -4381,15 +4386,16 @@ siocncheckc(dev)
static int
siocngetc(dev)
dev_t dev;
siocngetc(struct consdev *cd)
{
int c;
dev_t dev;
Port_t iobase;
int s;
struct siocnstate sp;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;
@ -4408,16 +4414,16 @@ siocngetc(dev)
}
static void
siocnputc(dev, c)
dev_t dev;
int c;
siocnputc(struct consdev *cd, int c)
{
int need_unlock;
int s;
dev_t dev;
struct siocnstate sp;
Port_t iobase;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;

View File

@ -4003,6 +4003,7 @@ CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc,
/* To get the GDB related variables */
#if DDB > 0
#include <ddb/ddb.h>
struct consdev gdbconsdev;
#endif
static void
@ -4212,7 +4213,8 @@ siocnprobe(cp)
siogdbiobase = iobase;
siogdbunit = unit;
#if DDB > 0
gdb_arg = makedev(CDEV_MAJOR, unit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
#endif
@ -4233,7 +4235,8 @@ siocnprobe(cp)
printf("configuration file (currently sio only).\n");
siogdbiobase = siocniobase;
siogdbunit = siocnunit;
gdb_arg = makedev(CDEV_MAJOR, siocnunit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, siocnunit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
}
@ -4320,7 +4323,8 @@ siogdbattach(port, speed)
printf("sio%d: gdb debugging port\n", unit);
siogdbunit = unit;
#if DDB > 0
gdb_arg = makedev(CDEV_MAJOR, unit);
gdbconsdev.cn_dev = makedev(CDEV_MAJOR, unit);
gdb_arg = &gdbconsdev;
gdb_getc = siocngetc;
gdb_putc = siocnputc;
#endif
@ -4352,15 +4356,16 @@ siogdbattach(port, speed)
#endif
static int
siocncheckc(dev)
dev_t dev;
siocncheckc(struct consdev *cd)
{
int c;
dev_t dev;
Port_t iobase;
int s;
struct siocnstate sp;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;
@ -4381,15 +4386,16 @@ siocncheckc(dev)
static int
siocngetc(dev)
dev_t dev;
siocngetc(struct consdev *cd)
{
int c;
dev_t dev;
Port_t iobase;
int s;
struct siocnstate sp;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;
@ -4408,16 +4414,16 @@ siocngetc(dev)
}
static void
siocnputc(dev, c)
dev_t dev;
int c;
siocnputc(struct consdev *cd, int c)
{
int need_unlock;
int s;
dev_t dev;
struct siocnstate sp;
Port_t iobase;
speed_t speed;
dev = cd->cn_dev;
if (minor(dev) == siocnunit) {
iobase = siocniobase;
speed = comdefaultrate;

View File

@ -1469,7 +1469,7 @@ sccnattach(void)
#endif /* __alpha__ */
static void
sccnputc(dev_t dev, int c)
sccnputc(struct consdev *cd, int c)
{
u_char buf[1];
scr_stat *scp = sc_console;
@ -1511,19 +1511,19 @@ sccnputc(dev_t dev, int c)
}
static int
sccngetc(dev_t dev)
sccngetc(struct consdev *cd)
{
return sccngetch(0);
}
static int
sccncheckc(dev_t dev)
sccncheckc(struct consdev *cd)
{
return sccngetch(SCGETC_NONBLOCK);
}
static void
sccndbctl(dev_t dev, int on)
sccndbctl(struct consdev *cd, int on)
{
/* try to switch to the kernel console screen */
if (on && debugger == 0) {

View File

@ -46,10 +46,10 @@ struct consdev;
typedef void cn_probe_t(struct consdev *);
typedef void cn_init_t(struct consdev *);
typedef void cn_term_t(struct consdev *);
typedef int cn_getc_t(dev_t);
typedef int cn_checkc_t(dev_t);
typedef void cn_putc_t(dev_t, int);
typedef void cn_dbctl_t(dev_t, int);
typedef int cn_getc_t(struct consdev *);
typedef int cn_checkc_t(struct consdev *);
typedef void cn_putc_t(struct consdev *, int);
typedef void cn_dbctl_t(struct consdev *, int);
struct consdev {
cn_probe_t *cn_probe;
@ -69,6 +69,7 @@ struct consdev {
struct tty *cn_tp; /* tty structure for console device */
dev_t cn_dev; /* major/minor of device */
short cn_pri; /* pecking order; the higher the better */
void *cn_arg; /* drivers method argument */
};
/* values for cn_pri - reflect our policy for console selection */