summaryrefslogtreecommitdiffstats
path: root/sys/sys/cons.h
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-08-24 10:53:30 +0000
committered <ed@FreeBSD.org>2009-08-24 10:53:30 +0000
commit7669d1f2c12de4c0b0410af8a8928836498760e1 (patch)
tree277706037ddf24145cff13db7a5e4cc8a1c31a7d /sys/sys/cons.h
parent927d43d57415185dd776a3a857e6ae3d302a86ab (diff)
downloadFreeBSD-src-7669d1f2c12de4c0b0410af8a8928836498760e1.zip
FreeBSD-src-7669d1f2c12de4c0b0410af8a8928836498760e1.tar.gz
Allow multiple console devices per driver without insane code duplication.
Say, a driver wants to have multiple console devices to pick from, you would normally write down something like this: CONSOLE_DRIVER(dev1); CONSOLE_DRIVER(dev2); Unfortunately, this means that you have to declare 10 cn routines, instead of 5. It also isn't possible to initialize cn_arg on beforehand. I noticed this restriction when I was implementing some of the console bits for my vt(4) driver in my newcons branch. I have a single set of cn routines (termcn_*) which are shared by all vt(4) console devices. In order to solve this, I'm adding a separate consdev_ops structure, which contains all the function pointers. This structure is referenced through consdev's cn_ops field. While there, I'm removing CONS_DRIVER() and cn_checkc, which have been deprecated for years. They weren't used throughout the source, until the Xen console driver showed up. CONSOLE_DRIVER() has been changed to do the right thing. It now declares both the consdev and consdev_ops structure and ties them together. In other words: this change doesn't change the KPI for drivers that used the regular way of declaring console devices. If drivers want to use multiple console devices, they can do this as follows: static const struct consdev_ops mydriver_cnops = { .cn_probe = mydriver_cnprobe, ... }; static struct mydriver_softc cons0_softc = { ... }; CONSOLE_DEVICE(cons0, mydriver_cnops, &cons0_softc); static struct mydriver_softc cons1_softc = { ... }; CONSOLE_DEVICE(cons1, mydriver_cnops, &cons1_softc); Obtained from: //depot/user/ed/newcons/...
Diffstat (limited to 'sys/sys/cons.h')
-rw-r--r--sys/sys/cons.h25
1 files changed, 14 insertions, 11 deletions
diff --git a/sys/sys/cons.h b/sys/sys/cons.h
index ac97ce4..e84318f 100644
--- a/sys/sys/cons.h
+++ b/sys/sys/cons.h
@@ -45,10 +45,9 @@ 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(struct consdev *);
-typedef int cn_checkc_t(struct consdev *);
typedef void cn_putc_t(struct consdev *, int);
-struct consdev {
+struct consdev_ops {
cn_probe_t *cn_probe;
/* probe hardware and fill in consdev info */
cn_init_t *cn_init;
@@ -57,10 +56,13 @@ struct consdev {
/* turn off as console */
cn_getc_t *cn_getc;
/* kernel getchar interface */
- cn_checkc_t *cn_checkc;
- /* kernel "return char if available" interface */
cn_putc_t *cn_putc;
/* kernel putchar interface */
+};
+
+struct consdev {
+ const struct consdev_ops *cn_ops;
+ /* console device operations. */
short cn_pri; /* pecking order; the higher the better */
void *cn_arg; /* drivers method argument */
int cn_flags; /* capabilities of this console */
@@ -83,21 +85,22 @@ struct consdev {
extern struct msgbuf consmsgbuf; /* Message buffer for constty. */
extern struct tty *constty; /* Temporary virtual console. */
-#define CONS_DRIVER(name, probe, init, term, getc, checkc, putc, dbctl) \
- static struct consdev name##_consdev = { \
- probe, init, term, getc, checkc, putc \
+#define CONSOLE_DEVICE(name, ops, arg) \
+ static struct consdev name = { \
+ .cn_ops = &ops, \
+ .cn_arg = (arg), \
}; \
- DATA_SET(cons_set, name##_consdev)
+ DATA_SET(cons_set, name)
-#define CONSOLE_DRIVER(name) \
- static struct consdev name##_consdev = { \
+#define CONSOLE_DRIVER(name) \
+ static const struct consdev_ops name##_consdev_ops = { \
.cn_probe = name##_cnprobe, \
.cn_init = name##_cninit, \
.cn_term = name##_cnterm, \
.cn_getc = name##_cngetc, \
.cn_putc = name##_cnputc, \
}; \
- DATA_SET(cons_set, name##_consdev)
+ CONSOLE_DEVICE(name##_consdev, name##_consdev_ops, NULL)
/* Other kernel entry points. */
void cninit(void);
OpenPOWER on IntegriCloud