diff options
Diffstat (limited to 'hw/xfree86/os-support/bsd/bsd_init.c')
-rw-r--r-- | hw/xfree86/os-support/bsd/bsd_init.c | 354 |
1 files changed, 150 insertions, 204 deletions
diff --git a/hw/xfree86/os-support/bsd/bsd_init.c b/hw/xfree86/os-support/bsd/bsd_init.c index 961fd0eac..236b6ffbb 100644 --- a/hw/xfree86/os-support/bsd/bsd_init.c +++ b/hw/xfree86/os-support/bsd/bsd_init.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c,v 3.8.2.1 1998/02/06 22:36:49 hohndel Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c,v 3.19 2002/05/05 18:54:02 herrb Exp $ */ /* * Copyright 1992 by Rich Murphey <Rich@Rice.edu> * Copyright 1993 by David Wexelblat <dwex@goblin.org> @@ -23,24 +23,18 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: bsd_init.c,v 1.3 2000/08/17 19:51:21 cpqbld Exp $ */ +/* $XConsortium: bsd_init.c /main/8 1996/10/23 13:13:05 kaleb $ */ #include "X.h" -#include "Xmd.h" -#include "input.h" -#include "scrnintstr.h" #include "compiler.h" #include "xf86.h" -#include "xf86Procs.h" +#include "xf86Priv.h" #include "xf86_OSlib.h" -extern void xf86VTRequest( -#if NeedFunctionPrototypes - int -#endif -); +#include <sys/utsname.h> +#include <stdlib.h> static Bool KeepTty = FALSE; static int devConsoleFd = -1; @@ -58,12 +52,6 @@ static int initialVT = -1; #define PCCONS_CONSOLE_MODE O_RDWR|O_NDELAY #endif -#ifdef CODRV_SUPPORT -/* Holger Veit's codrv console driver */ -#define CODRV_CONSOLE_DEV "/dev/kbd" -#define CODRV_CONSOLE_MODE O_RDONLY|O_NDELAY -#endif - #ifdef SYSCONS_SUPPORT /* The FreeBSD 1.1 version syscons driver uses /dev/ttyv0 */ #define SYSCONS_CONSOLE_DEV1 "/dev/ttyv0" @@ -81,6 +69,11 @@ static int initialVT = -1; #define PCVT_CONSOLE_MODE O_RDWR|O_NDELAY #endif +#if defined(WSCONS_SUPPORT) && defined(__NetBSD__) +/* NetBSD's new console driver */ +#define WSCONS_PCVT_COMPAT_CONSOLE_DEV "/dev/ttyE0" +#endif + #define CHECK_DRIVER_MSG \ "Check your kernel's console driver configuration and /dev entries" @@ -88,15 +81,15 @@ static char *supported_drivers[] = { #ifdef PCCONS_SUPPORT "pccons (with X support)", #endif -#ifdef CODRV_SUPPORT - "codrv", -#endif #ifdef SYSCONS_SUPPORT "syscons", #endif #ifdef PCVT_SUPPORT "pcvt", #endif +#ifdef WSCONS_SUPPORT + "wscons", +#endif }; @@ -108,64 +101,43 @@ static char *supported_drivers[] = { * an X server. */ -typedef int (*xf86ConsOpen_t)( -#if NeedFunctionPrototypes - void -#endif -); +typedef int (*xf86ConsOpen_t)(void); #ifdef PCCONS_SUPPORT -static int xf86OpenPccons( -#if NeedFunctionPrototypes - void -#endif -); +static int xf86OpenPccons(void); #endif /* PCCONS_SUPPORT */ -#ifdef CODRV_SUPPORT -static int xf86OpenCodrv( -#if NeedFunctionPrototypes - void -#endif -); -#endif /* CODRV_SUPPORT */ - #ifdef SYSCONS_SUPPORT -static int xf86OpenSyscons( -#if NeedFunctionPrototypes - void -#endif -); +static int xf86OpenSyscons(void); #endif /* SYSCONS_SUPPORT */ #ifdef PCVT_SUPPORT -static int xf86OpenPcvt( -#if NeedFunctionPrototypes - void -#endif -); +static int xf86OpenPcvt(void); #endif /* PCVT_SUPPORT */ +#ifdef WSCONS_SUPPORT +static int xf86OpenWScons(void); +#endif + /* * The sequence of the driver probes is important; start with the * driver that is best distinguishable, and end with the most generic * driver. (Otherwise, pcvt would also probe as syscons, and either - * pcvt or syscons might succesfully probe as pccons. Only codrv is - * at its own.) + * pcvt or syscons might succesfully probe as pccons.) */ static xf86ConsOpen_t xf86ConsTab[] = { #ifdef PCVT_SUPPORT xf86OpenPcvt, #endif -#ifdef CODRV_SUPPORT - xf86OpenCodrv, -#endif #ifdef SYSCONS_SUPPORT xf86OpenSyscons, #endif #ifdef PCCONS_SUPPORT xf86OpenPccons, #endif +#ifdef WSCONS_SUPPORT + xf86OpenWScons, +#endif (xf86ConsOpen_t)NULL }; @@ -173,10 +145,9 @@ static xf86ConsOpen_t xf86ConsTab[] = { void xf86OpenConsole() { - int i, fd; -#ifdef CODRV_SUPPORT - int onoff; -#endif + int i, fd = -1; + int result; + struct utsname uts; xf86ConsOpen_t *driver; #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) vtmode_t vtmode; @@ -187,10 +158,7 @@ xf86OpenConsole() /* check if we are run with euid==0 */ if (geteuid() != 0) { - FatalError("xf86OpenConsole: Server must be running with root " - "permissions\n" - "You should be using Xwrapper to start the server or xdm.\n" - "We strongly advise against making the server SUID root!\n"); + FatalError("xf86OpenConsole: Server must be suid root\n"); } if (!KeepTty) @@ -211,7 +179,7 @@ xf86OpenConsole() /* detect which driver we are running on */ for (driver = xf86ConsTab; *driver; driver++) { - if((fd = (*driver)()) >= 0) + if ((fd = (*driver)()) >= 0) break; } @@ -231,28 +199,14 @@ xf86OpenConsole() "%s: No console driver found\n\tSupported drivers: %s\n\t%s\n", "xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG); } +#if 0 /* stdin is already closed in OsInit() */ fclose(stdin); +#endif xf86Info.consoleFd = fd; xf86Info.screenFd = fd; - xf86Config(FALSE); /* Read XF86Config */ - switch (xf86Info.consType) { -#ifdef CODRV_SUPPORT - case CODRV011: - case CODRV01X: - onoff = X_MODE_ON; - if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE, &onoff) < 0) - { - FatalError("%s: CONSOLE_X_MODE ON failed (%s)\n%s\n", - "xf86OpenConsole", strerror(errno), - CHECK_DRIVER_MSG); - } - if (xf86Info.consType == CODRV01X) - ioctl(xf86Info.consoleFd, VGATAKECTRL, 0); - break; -#endif #ifdef PCCONS_SUPPORT case PCCONS: if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0) @@ -267,13 +221,24 @@ xf86OpenConsole() */ if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0) { - ErrorF("Warning: couldn't open /dev/console (%s)\n", - strerror(errno)); + xf86Msg(X_WARNING, + "xf86OpenConsole: couldn't open /dev/console (%s)\n", + strerror(errno)); } break; #endif #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) case SYSCONS: + /* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt + * switching anymore. Here we check for FreeBSD 3.1 and up. + * Add cases for other *BSD that behave the same. + */ + uname (&uts); + if (strcmp(uts.sysname, "FreeBSD") == 0) { + i = atof(uts.release) * 100; + if (i >= 310) goto acquire_vt; + } + /* otherwise fall through */ case PCVT: /* * First activate the #1 VT. This is a hack to allow a server @@ -284,21 +249,27 @@ xf86OpenConsole() if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0) { - ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n"); + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_ACTIVATE failed\n"); } sleep(1); } - + +acquire_vt: /* * now get the VT */ - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) + SYSCALL(result = + ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); + if (result != 0) { - ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n"); + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); } - if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0) + SYSCALL(result = + ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); + if (result != 0) { - ErrorF("xf86OpenConsole: VT_WAITACTIVE failed\n"); + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); } signal(SIGUSR1, xf86VTRequest); @@ -311,17 +282,25 @@ xf86OpenConsole() { FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); } +#if !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0) { FatalError("xf86OpenConsole: KDENABIO failed (%s)\n", strerror(errno)); } +#endif if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) { FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n"); } break; #endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#ifdef WSCONS_SUPPORT + case WSCONS: + fprintf(stderr, "xf86OpenConsole\n"); + /* xf86Info.consoleFd = open("/dev/wskbd0", 0); */ + break; +#endif } } else @@ -332,7 +311,7 @@ xf86OpenConsole() { if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) { - ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n"); + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); } } #endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ @@ -363,10 +342,7 @@ xf86OpenPccons() CHECK_DRIVER_MSG); } xf86Info.consType = PCCONS; - if (xf86Verbose) - { - ErrorF("Using pccons driver with X support\n"); - } + xf86Msg(X_PROBED, "Using pccons driver with X support\n"); } return fd; } @@ -383,6 +359,7 @@ xf86OpenSyscons() char vtname[12]; struct stat status; long syscons_version; + MessageType from; /* Check for syscons */ if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0 @@ -397,6 +374,7 @@ xf86OpenSyscons() } xf86Info.vtno = VTnum; + from = X_CMDLINE; #ifdef VT_GETACTIVE if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) @@ -430,6 +408,7 @@ xf86OpenSyscons() /* * All VTs are in use. If initialVT was found, use it. * Otherwise, if stdin is a VT, use that one. + * XXX stdin is already closed, so this won't work. */ if (initialVT != -1) { @@ -458,6 +437,7 @@ xf86OpenSyscons() "or the use of the vtxx server option"); } } + from = X_PROBED; } close(fd); @@ -476,20 +456,17 @@ xf86OpenSyscons() FatalError("xf86OpenSyscons: VT_GETMODE failed\n"); } xf86Info.consType = SYSCONS; - if (xf86Verbose) + xf86Msg(X_PROBED, "Using syscons driver with X support"); + if (syscons_version >= 0x100) { - ErrorF("Using syscons driver with X support"); - if (syscons_version >= 0x100) - { - ErrorF(" (version %d.%d)\n", syscons_version >> 8, + xf86ErrorF(" (version %d.%d)\n", syscons_version >> 8, syscons_version & 0xFF); - } - else - { - ErrorF(" (version 0.x)\n"); - } - ErrorF("(using VT number %d)\n\n", xf86Info.vtno); } + else + { + xf86ErrorF(" (version 0.x)\n"); + } + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); } else { @@ -504,78 +481,6 @@ xf86OpenSyscons() #endif /* SYSCONS_SUPPORT */ -#ifdef CODRV_SUPPORT - -static int -xf86OpenCodrv() -{ - int fd = -1, onoff = X_MODE_OFF; - struct oldconsinfo ci; - - if ((fd = open(CODRV_CONSOLE_DEV, CODRV_CONSOLE_MODE, 0)) >= 0) - { - if (ioctl(fd, CONSOLE_X_MODE, &onoff) < 0) - { - FatalError("%s: CONSOLE_X_MODE on %s failed (%s)\n%s\n%s\n", - "xf86OpenCodrv", - CODRV_CONSOLE_DEV, strerror(errno), - "Was expecting codrv driver", - CHECK_DRIVER_MSG); - } - xf86Info.consType = CODRV011; - } - else - { - if (errno == EBUSY) - { - FatalError("xf86OpenCodrv: %s is already in use (codrv)\n", - CODRV_CONSOLE_DEV); - } - } - else - { - fd = -1; - } - - if(fd >= 0) - { - /* - * analyse whether this kernel has sufficient capabilities for - * this xserver, if not don't proceed: it won't work. Also - * find out which codrv version. - */ -#define NECESSARY (CONS_HASKBD|CONS_HASKEYNUM|CONS_HASPX386) - if ((ioctl(fd, OLDCONSGINFO, &ci) < 0 || - (ci.info1 & NECESSARY) != NECESSARY)) - { - FatalError("xf86OpenCodrv: %s\n%s\n%s\n", - "This Xserver has detected the codrv driver, but your", - "kernel doesn't appear to have the required facilities", - CHECK_DRIVER_MSG); - } - /* Check for codrv 0.1.2 or later */ - if (ci.info1 & CONS_CODRV2) - { - xf86Info.consType = CODRV01X; - if (xf86Verbose) - { - ErrorF("Using codrv 0.1.2 (or later)\n"); - } - } - else - { - if (xf86Verbose) - { - ErrorF("Using codrv 0.1.1\n"); - } - } -#undef NECESSARY - } - - return fd; -} -#endif /* CODRV_SUPPORT */ - #ifdef PCVT_SUPPORT static int @@ -584,11 +489,25 @@ xf86OpenPcvt() /* This looks much like syscons, since pcvt is API compatible */ int fd = -1; vtmode_t vtmode; - char vtname[12]; + char vtname[12], *vtprefix; struct stat status; struct pcvtid pcvt_version; - if ((fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0)) >= 0) +#ifndef __OpenBSD__ + vtprefix = "/dev/ttyv"; +#else + vtprefix = "/dev/ttyC"; +#endif + + fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); +#ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV + if (fd < 0) + { + fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); + vtprefix = "/dev/ttyE"; + } +#endif + if (fd >= 0) { if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0) { @@ -618,6 +537,7 @@ xf86OpenPcvt() /* * All VTs are in use. If initialVT was found, use it. * Otherwise, if stdin is a VT, use that one. + * XXX stdin is already closed, so this won't work. */ if (initialVT != -1) { @@ -639,11 +559,7 @@ xf86OpenPcvt() } close(fd); -#ifndef __OpenBSD__ - sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1); -#else - sprintf(vtname, "/dev/ttyC%01x", xf86Info.vtno - 1); -#endif + sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { FatalError("xf86OpenPcvt: Cannot open %s (%s)\n", @@ -654,11 +570,15 @@ xf86OpenPcvt() FatalError("xf86OpenPcvt: VT_GETMODE failed\n"); } xf86Info.consType = PCVT; - if (xf86Verbose) - { - ErrorF("Using pcvt driver (version %d.%d)\n", - pcvt_version.rmajor, pcvt_version.rminor); - } +#ifdef WSCONS_SUPPORT + xf86Msg(X_PROBED, + "Using wscons driver in pcvt compatibility mode " + "(version %d.%d)\n", + pcvt_version.rmajor, pcvt_version.rminor); +#else + xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n", + pcvt_version.rmajor, pcvt_version.rminor); +#endif } else { @@ -672,30 +592,49 @@ xf86OpenPcvt() #endif /* PCVT_SUPPORT */ +#ifdef WSCONS_SUPPORT + +static int +xf86OpenWScons() +{ + int fd = -1; + int mode = WSDISPLAYIO_MODE_MAPPED; + int i; + char ttyname[16]; + + /* XXX Is this ok? */ + for (i = 0; i < 8; i++) { +#if defined(__NetBSD__) + sprintf(ttyname, "/dev/ttyE%d", i); +#elif defined(__OpenBSD__) + sprintf(ttyname, "/dev/ttyC%d", i); +#endif + if ((fd = open(ttyname, 2)) != -1) + break; + } + if (fd != -1) { + if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) { + FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s\n", + "xf86OpenConsole", strerror(errno), + CHECK_DRIVER_MSG); + } + xf86Info.consType = WSCONS; + xf86Msg(X_PROBED, "Using wscons driver\n"); + } + return fd; +} + +#endif /* WSCONS_SUPPORT */ void xf86CloseConsole() { -#if defined(CODRV_SUPPORT) - int onoff; -#endif #if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) struct vt_mode VT; #endif switch (xf86Info.consType) { -#ifdef CODRV_SUPPORT - case CODRV011: - case CODRV01X: - onoff = X_MODE_OFF; - if (xf86Info.consType == CODRV01X) - { - ioctl (xf86Info.consoleFd, VGAGIVECTRL, 0); - } - ioctl (xf86Info.consoleFd, CONSOLE_X_MODE, &onoff); - break; -#endif /* CODRV_SUPPORT */ #ifdef PCCONS_SUPPORT case PCCONS: ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0); @@ -710,15 +649,25 @@ xf86CloseConsole() VT.mode = VT_AUTO; ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */ } +#if !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0) { xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)\n", strerror(errno)); } +#endif if (initialVT != -1) ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT); break; #endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#ifdef WSCONS_SUPPORT + case WSCONS: + { + int mode = WSDISPLAYIO_MODE_EMUL; + ioctl(xf86Info.screenFd, WSDISPLAYIO_SMODE, &mode); + break; + } +#endif } if (xf86Info.screenFd != xf86Info.consoleFd) @@ -738,10 +687,7 @@ xf86CloseConsole() } int -xf86ProcessArgument (argc, argv, i) -int argc; -char *argv[]; -int i; +xf86ProcessArgument(int argc, char *argv[], int i) { /* * Keep server from detaching from controlling tty. This is useful |