diff --git a/share/man/man4/vt.4 b/share/man/man4/vt.4 index 809ca0724beb..19d60f0bc28e 100644 --- a/share/man/man4/vt.4 +++ b/share/man/man4/vt.4 @@ -43,6 +43,7 @@ In .Xr loader.conf 5 : .Cd hw.vga.textmode=1 +.Cd kern.vty=vt .Sh DESCRIPTION The .Nm @@ -171,6 +172,12 @@ prompt or in Set to 1 to use virtual terminals in text mode instead of graphics mode. Features that require graphics mode, like loadable fonts, will be disabled. +.It Va kern.vty +Set to vt to choose the +.Nm +driver for the system console, if the +.Xr syscons 4 +driver is also compiled in and is the default. .El .Sh FILES .Bl -tag -width /usr/share/syscons/keymaps/* -compact diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index 59b16af026df..6a19523ee2ea 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -266,6 +266,8 @@ static struct cdevsw consolectl_devsw = { int sc_probe_unit(int unit, int flags) { + if (!vty_enabled(VTY_SC)) + return ENXIO; if (!scvidprobe(unit, flags, FALSE)) { if (bootverbose) printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit); @@ -491,6 +493,9 @@ sc_attach_unit(int unit, int flags) struct cdev *dev; int vc; + if (!vty_enabled(VTY_SC)) + return ENXIO; + flags &= ~SC_KERNEL_CONSOLE; if (sc_console_unit == unit) { @@ -575,6 +580,8 @@ sc_attach_unit(int unit, int flags) static void scmeminit(void *arg) { + if (!vty_enabled(VTY_SC)) + return; if (sc_malloc) return; sc_malloc = TRUE; @@ -1588,7 +1595,7 @@ sc_cnprobe(struct consdev *cp) int unit; int flags; - if (getenv("hw.syscons.disable")) { + if (!vty_enabled(VTY_SC)) { cp->cn_pri = CN_DEAD; return; } diff --git a/sys/dev/syscons/sysmouse.c b/sys/dev/syscons/sysmouse.c index f2163fcb120a..e66849787929 100644 --- a/sys/dev/syscons/sysmouse.c +++ b/sys/dev/syscons/sysmouse.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -165,7 +166,7 @@ static struct ttydevsw smdev_ttydevsw = { static void sm_attach_mouse(void *unused) { - if (getenv("hw.syscons.disable")) + if (!vty_enabled(VTY_SC)) return; sysmouse_tty = tty_alloc(&smdev_ttydevsw, NULL); tty_makedev(sysmouse_tty, NULL, "sysmouse"); diff --git a/sys/dev/vt/vt_consolectl.c b/sys/dev/vt/vt_consolectl.c index be3ef7560a2e..32e3ba6a9ce5 100644 --- a/sys/dev/vt/vt_consolectl.c +++ b/sys/dev/vt/vt_consolectl.c @@ -73,7 +73,7 @@ static void consolectl_drvinit(void *unused) { - if (getenv("kern.vt.disable")) + if (!vty_enabled(VTY_VT)) return; make_dev(&consolectl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "consolectl"); diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index e0bde1f47d0c..21d530ac42c5 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -215,7 +215,7 @@ static void vt_update_static(void *dummy) { - if (getenv("kern.vt.disable")) + if (!vty_enabled(VTY_VT)) return; if (main_vd->vd_driver != NULL) printf("VT: running with driver \"%s\".\n", @@ -959,7 +959,7 @@ vtterm_cnprobe(struct terminal *tm, struct consdev *cp) struct vt_device *vd = vw->vw_device; struct winsize wsz; - if (getenv("kern.vt.disable")) + if (!vty_enabled(VTY_VT)) return; if (vd->vd_flags & VDF_INITIALIZED) @@ -1996,7 +1996,7 @@ vt_upgrade(struct vt_device *vd) struct vt_window *vw; unsigned int i; - if (getenv("kern.vt.disable")) + if (!vty_enabled(VTY_VT)) return; for (i = 0; i < VT_MAXWINDOWS; i++) { @@ -2064,7 +2064,7 @@ vt_allocate(struct vt_driver *drv, void *softc) struct vt_device *vd; struct winsize wsz; - if (getenv("kern.vt.disable")) + if (!vty_enabled(VTY_VT)) return; if (main_vd->vd_driver == NULL) { diff --git a/sys/dev/vt/vt_sysmouse.c b/sys/dev/vt/vt_sysmouse.c index 91862126596f..21b2400816f2 100644 --- a/sys/dev/vt/vt_sysmouse.c +++ b/sys/dev/vt/vt_sysmouse.c @@ -405,7 +405,7 @@ static void sysmouse_drvinit(void *unused) { - if (getenv("kern.vt.disable")) + if (!vty_enabled(VTY_VT)) return; mtx_init(&sysmouse_lock, "sysmouse", NULL, MTX_DEF); cv_init(&sysmouse_sleep, "sysmrd"); diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c index ad2ba201551c..8d23befd0577 100644 --- a/sys/kern/kern_cons.c +++ b/sys/kern/kern_cons.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include "opt_ddb.h" +#include "opt_syscons.h" #include #include @@ -648,3 +649,45 @@ sysbeep(int pitch __unused, int period __unused) #endif +/* + * Temporary support for sc(4) to vt(4) transition. + */ +static char vty_name[16] = ""; +SYSCTL_STRING(_kern, OID_AUTO, vty, CTLFLAG_RDTUN, vty_name, 0, + "Console vty driver"); + +int +vty_enabled(unsigned vty) +{ + static unsigned vty_selected = 0; + + if (vty_selected == 0) { + TUNABLE_STR_FETCH("kern.vty", vty_name, sizeof(vty_name)); + do { +#if defined(DEV_SC) + if (strcmp(vty_name, "sc") == 0) { + vty_selected = VTY_SC; + break; + } +#endif +#if defined(DEV_VT) + if (strcmp(vty_name, "vt") == 0) { + vty_selected = VTY_VT; + break; + } +#endif +#if defined(DEV_SC) + vty_selected = VTY_SC; +#elif defined(DEV_VT) + vty_selected = VTY_VT; +#endif + } while (0); + + if (vty_selected == VTY_VT) + strcpy(vty_name, "vt"); + else if (vty_selected == VTY_SC) + strcpy(vty_name, "sc"); + } + return ((vty_selected & vty) != 0); +} + diff --git a/sys/sys/cons.h b/sys/sys/cons.h index 8442bf3a76e9..485f8c06bd0d 100644 --- a/sys/sys/cons.h +++ b/sys/sys/cons.h @@ -133,6 +133,11 @@ int cnunavailable(void); void constty_set(struct tty *tp); void constty_clear(void); +/* sc(4) / vt(4) coexistence shim */ +#define VTY_SC 0x01 +#define VTY_VT 0x02 +int vty_enabled(unsigned int); + #endif /* _KERNEL */ #endif /* !_MACHINE_CONS_H_ */