Use a common tunable to choose between vt(4)/sc(4)

With this change and previous work from ray@ it will be possible to put
both in GENERIC, and have one enabled by default, but allow the other to
be selected via the loader.

(The previous implementation had separate kern.vt.disable and
hw.syscons.disable tunables, and would panic if both drivers were
compiled in and neither was explicitly disabled.)

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Ed Maste 2014-06-27 17:50:33 +00:00
parent 874a6e051b
commit 59644098f8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=267965
8 changed files with 71 additions and 8 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <sys/tty.h>
#include <sys/ttydefaults.h>
#include <sys/kernel.h>
#include <sys/cons.h>
#include <sys/consio.h>
#include <sys/mouse.h>
@ -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");

View File

@ -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");

View File

@ -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) {

View File

@ -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");

View File

@ -41,6 +41,7 @@
__FBSDID("$FreeBSD$");
#include "opt_ddb.h"
#include "opt_syscons.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -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);
}

View File

@ -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_ */