Index: programs/Xserver/hw/xfree86/common/xf86Bus.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Bus.c,v retrieving revision 1.1.1.33 diff -u -r1.1.1.33 xf86Bus.c --- programs/Xserver/hw/xfree86/common/xf86Bus.c 27 Jan 2005 15:56:54 -0000 1.1.1.33 +++ programs/Xserver/hw/xfree86/common/xf86Bus.c 28 Jan 2005 15:39:39 -0000 @@ -3030,7 +3030,7 @@ xf86FindPrimaryDevice() { /* if no VGA device is found check for primary PCI device */ - if (primaryBus.type == BUS_NONE) + if (primaryBus.type == BUS_NONE && xorgHWAccess) CheckGenericGA(); if (primaryBus.type != BUS_NONE) { char *bus; Index: programs/Xserver/hw/xfree86/common/xf86Configure.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Configure.c,v retrieving revision 1.1.1.43 diff -u -r1.1.1.43 xf86Configure.c --- programs/Xserver/hw/xfree86/common/xf86Configure.c 1 Nov 2004 16:46:34 -0000 1.1.1.43 +++ programs/Xserver/hw/xfree86/common/xf86Configure.c 28 Jan 2005 15:39:39 -0000 @@ -38,6 +38,7 @@ #endif #include "xf86.h" #include "xf86Config.h" +#include "xf86_OSlib.h" #include "xf86Priv.h" #include "xf86PciData.h" #define IN_XSERVER @@ -789,6 +790,24 @@ xfree(vlist); + for (i = 0; i < xf86NumDrivers; i++) { + xorgHWFlags flags; + if (!xf86DriverList[i]->driverFunc + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags)) { + xorgHWAccess = TRUE; + break; + } + } + /* Enable full I/O access */ + if (xorgHWAccess) { + if(!xf86EnableIO()) + /* oops, we have failed */ + xorgHWAccess = FALSE; + } + /* Disable PCI devices */ xf86ResourceBrokerInit(); xf86AccessInit(); @@ -803,6 +822,16 @@ /* Call all of the probe functions, reporting the results. */ for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) { + xorgHWFlags flags; + + if (!xorgHWAccess) { + if (!xf86DriverList[CurrentDriver]->driverFunc + || !xf86DriverList[CurrentDriver]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags)) + continue; + } if (xf86DriverList[CurrentDriver]->Probe == NULL) continue; Index: programs/Xserver/hw/xfree86/common/xf86DoProbe.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86DoProbe.c,v retrieving revision 1.1.1.8 diff -u -r1.1.1.8 xf86DoProbe.c --- programs/Xserver/hw/xfree86/common/xf86DoProbe.c 6 Jul 2004 15:12:39 -0000 1.1.1.8 +++ programs/Xserver/hw/xfree86/common/xf86DoProbe.c 28 Jan 2005 15:39:39 -0000 @@ -40,6 +40,7 @@ #include "loaderProcs.h" #include "xf86Config.h" #endif /* XFree86LOADER */ +#include "xf86_OSlib.h" #include "xf86.h" #include "xf86Priv.h" @@ -53,7 +54,8 @@ { int i; Bool probeResult; - + Bool ioEnableFailed = FALSE; + #ifdef XFree86LOADER /* Find the list of video driver modules. */ char **list = xf86DriverlistFromCompile(); @@ -76,6 +78,24 @@ /* Call all of the probe functions, reporting the results. */ for (i = 0; i < xf86NumDrivers; i++) { + + if (!xorgHWAccess) { + xorgHWFlags flags; + if (!xf86DriverList[i]->driverFunc + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags)) { + if (ioEnableFailed) + continue; + if (!xf86EnableIO()) { + ioEnableFailed = TRUE; + continue; + } + xorgHWAccess = TRUE; + } + } + if (xf86DriverList[i]->Probe == NULL) continue; xf86MsgVerb(X_INFO, 3, "Probing in driver %s\n", Index: programs/Xserver/hw/xfree86/common/xf86Events.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v retrieving revision 1.1.1.45 diff -u -r1.1.1.45 xf86Events.c --- programs/Xserver/hw/xfree86/common/xf86Events.c 1 Nov 2004 16:46:34 -0000 1.1.1.45 +++ programs/Xserver/hw/xfree86/common/xf86Events.c 28 Jan 2005 15:39:39 -0000 @@ -1431,7 +1431,8 @@ xf86Screens[i]->access = NULL; xf86Screens[i]->busAccess = NULL; } - xf86DisableIO(); + if (xorgHWAccess) + xf86DisableIO(); } } else { @@ -1443,7 +1444,8 @@ prevSIGIO = xf86BlockSIGIO(); xf86OSPMClose = xf86OSPMOpen(); - xf86EnableIO(); + if (xorgHWAccess) + xf86EnableIO(); xf86AccessEnter(); xf86EnterServerState(SETUP); for (i = 0; i < xf86NumScreens; i++) { Index: programs/Xserver/hw/xfree86/common/xf86Globals.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Globals.c,v retrieving revision 1.1.1.17 diff -u -r1.1.1.17 xf86Globals.c --- programs/Xserver/hw/xfree86/common/xf86Globals.c 6 Jul 2004 15:12:39 -0000 1.1.1.17 +++ programs/Xserver/hw/xfree86/common/xf86Globals.c 28 Jan 2005 15:39:39 -0000 @@ -238,6 +238,7 @@ #endif RootWinPropPtr *xf86RegisteredPropertiesTable = NULL; Bool xf86inSuspend = FALSE; +Bool xorgHWAccess = FALSE; #ifdef DLOPEN_HACK /* Index: programs/Xserver/hw/xfree86/common/xf86Helper.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Helper.c,v retrieving revision 1.1.1.49 diff -u -r1.1.1.49 xf86Helper.c --- programs/Xserver/hw/xfree86/common/xf86Helper.c 1 Nov 2004 16:46:35 -0000 1.1.1.49 +++ programs/Xserver/hw/xfree86/common/xf86Helper.c 28 Jan 2005 15:39:39 -0000 @@ -83,7 +83,12 @@ xf86DriverList = xnfrealloc(xf86DriverList, xf86NumDrivers * sizeof(DriverPtr)); xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec)); - *xf86DriverList[xf86NumDrivers - 1] = *driver; + if (flags & HaveDriverFuncs) + *xf86DriverList[xf86NumDrivers - 1] = *driver; + else { + memcpy(xf86DriverList[xf86NumDrivers - 1], driver, sizeof(DriverRec1)); + xf86DriverList[xf86NumDrivers - 1]->driverFunc = NULL; + } xf86DriverList[xf86NumDrivers - 1]->module = module; xf86DriverList[xf86NumDrivers - 1]->refCount = 0; } @@ -209,6 +214,8 @@ } #endif + xf86Screens[i]->DriverFunc = drv->driverFunc; + return xf86Screens[i]; } Index: programs/Xserver/hw/xfree86/common/xf86Init.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v retrieving revision 1.1.1.38 diff -u -r1.1.1.38 xf86Init.c --- programs/Xserver/hw/xfree86/common/xf86Init.c 19 Jan 2005 16:20:49 -0000 1.1.1.38 +++ programs/Xserver/hw/xfree86/common/xf86Init.c 28 Jan 2005 15:39:39 -0000 @@ -378,9 +378,6 @@ xf86OpenConsole(); - /* Enable full I/O access */ - xf86EnableIO(); - /* Do a general bus probe. This will be a PCI probe for x86 platforms */ xf86BusProbe(); @@ -446,20 +443,37 @@ } /* - * Call each of the Identify functions. The Identify functions print - * out some identifying information, and anything else that might be + * Call each of the Identify functions and call the driverFunc to check + * if HW access is required. The Identify functions print out some + * identifying information, and anything else that might be * needed at this early stage. */ - for (i = 0; i < xf86NumDrivers; i++) + for (i = 0; i < xf86NumDrivers; i++) { + xorgHWFlags flags; /* The Identify function is mandatory, but if it isn't there continue */ - if (xf86DriverList[i]->Identify != NULL) - xf86DriverList[i]->Identify(0); - else { - xf86Msg(X_WARNING, "Driver `%s' has no Identify function\n", - xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName + if (xf86DriverList[i]->Identify != NULL) + xf86DriverList[i]->Identify(0); + else { + xf86Msg(X_WARNING, "Driver `%s' has no Identify function\n", + xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName : "noname"); - } + } + if (!xorgHWAccess + && (!xf86DriverList[i]->driverFunc + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags))) + xorgHWAccess = TRUE; + } + + /* Enable full I/O access */ + if (xorgHWAccess) { + if(!xf86EnableIO()) + /* oops, we have failed */ + xorgHWAccess = FALSE; + } /* * Locate bus slot that had register IO enabled at server startup @@ -475,15 +489,25 @@ */ for (i = 0; i < xf86NumDrivers; i++) { - if (xf86DriverList[i]->Probe != NULL) - xf86DriverList[i]->Probe(xf86DriverList[i], PROBE_DEFAULT); - else { - xf86MsgVerb(X_WARNING, 0, - "Driver `%s' has no Probe function (ignoring)\n", - xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName - : "noname"); - } - xf86SetPciVideo(NULL,NONE); + xorgHWFlags flags; + if (!xorgHWAccess) { + if (!xf86DriverList[i]->driverFunc + || !xf86DriverList[i]->driverFunc(NULL, + GET_REQUIRED_HW_INTERFACES, + &flags) + || NEED_IO_ENABLED(flags)) + continue; + } + + if (xf86DriverList[i]->Probe != NULL) + xf86DriverList[i]->Probe(xf86DriverList[i], PROBE_DEFAULT); + else { + xf86MsgVerb(X_WARNING, 0, + "Driver `%s' has no Probe function (ignoring)\n", + xf86DriverList[i]->driverName + ? xf86DriverList[i]->driverName : "noname"); + } + xf86SetPciVideo(NULL,NONE); } /* @@ -814,7 +838,8 @@ xf86MsgVerb(X_INFO, 3, "APM registered successfully\n"); /* Make sure full I/O access is enabled */ - xf86EnableIO(); + if (xorgHWAccess) + xf86EnableIO(); } #if 0 @@ -896,7 +921,7 @@ xf86Screens[i]->DPMSSet = NULL; xf86Screens[i]->LoadPalette = NULL; xf86Screens[i]->SetOverscan = NULL; - xf86Screens[i]->RRFunc = NULL; + xf86Screens[i]->DriverFunc = NULL; xf86Screens[i]->pScreen = NULL; scr_index = AddScreen(xf86Screens[i]->ScreenInit, argc, argv); if (scr_index == i) { @@ -1330,7 +1355,7 @@ */ /* First the options that are only allowed for root */ - if (getuid() == 0) + if (getuid() == 0 || geteuid != 0) { if (!strcmp(argv[i], "-modulepath")) { @@ -1636,7 +1661,7 @@ } if (!strcmp(argv[i], "-configure")) { - if (getuid() != 0) { + if (getuid() != 0 && geteuid == 0) { ErrorF("The '-configure' option can only be used by root.\n"); exit(1); } @@ -1665,7 +1690,7 @@ ErrorF("\n"); ErrorF("\n"); ErrorF("Device Dependent Usage\n"); - if (getuid() == 0) + if (getuid() == 0 || geteuid() != 0) { ErrorF("-modulepath paths specify the module search path\n"); ErrorF("-logfile file specify a log file name\n"); Index: programs/Xserver/hw/xfree86/common/xf86Priv.h =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86Priv.h,v retrieving revision 1.1.1.23 diff -u -r1.1.1.23 xf86Priv.h --- programs/Xserver/hw/xfree86/common/xf86Priv.h 25 Nov 2004 16:54:17 -0000 1.1.1.23 +++ programs/Xserver/hw/xfree86/common/xf86Priv.h 28 Jan 2005 15:39:39 -0000 @@ -112,6 +112,7 @@ extern int xf86LogVerbose; /* log file verbosity level */ extern Bool xf86ProbeOnly; extern Bool xf86DoProbe; +extern Bool xorgHWAccess; extern RootWinPropPtr *xf86RegisteredPropertiesTable; Index: programs/Xserver/hw/xfree86/common/xf86RandR.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v retrieving revision 1.1.1.11 diff -u -r1.1.1.11 xf86RandR.c --- programs/Xserver/hw/xfree86/common/xf86RandR.c 19 Jan 2005 16:20:49 -0000 1.1.1.11 +++ programs/Xserver/hw/xfree86/common/xf86RandR.c 28 Jan 2005 15:39:39 -0000 @@ -104,11 +104,11 @@ } /* If there is driver support for randr, let it set our supported rotations */ - if(scrp->RRFunc) { + if(scrp->DriverFunc) { xorgRRRotation RRRotation; RRRotation.RRRotations = *rotations; - if (!(*scrp->RRFunc)(scrp, RR_GET_INFO, &RRRotation)) + if (!(*scrp->DriverFunc)(scrp, RR_GET_INFO, &RRRotation)) return FALSE; *rotations = RRRotation.RRRotations; } @@ -216,14 +216,14 @@ } /* Have the driver do its thing. */ - if (scrp->RRFunc) { + if (scrp->DriverFunc) { xorgRRRotation RRRotation; RRRotation.RRConfig.rotation = rotation; RRRotation.RRConfig.rate = rate; RRRotation.RRConfig.width = pSize->width; RRRotation.RRConfig.height = pSize->height; - if (!(*scrp->RRFunc)(scrp, RR_SET_CONFIG, &RRRotation)) + if (!(*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation)) return FALSE; } Index: programs/Xserver/hw/xfree86/common/xf86str.h =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/common/xf86str.h,v retrieving revision 1.1.1.31 diff -u -r1.1.1.31 xf86str.h --- programs/Xserver/hw/xfree86/common/xf86str.h 3 Aug 2004 10:11:05 -0000 1.1.1.31 +++ programs/Xserver/hw/xfree86/common/xf86str.h 28 Jan 2005 15:39:39 -0000 @@ -236,9 +236,59 @@ } ClockRanges, *ClockRangesPtr; /* + * The driverFunc. xorgDriverFuncOp specifies the action driver should + * perform. If requested option is not supported function should return + * FALSE. pointer can be used to pass arguments to the function or + * to return data to the caller. + */ +typedef struct _ScrnInfoRec *ScrnInfoPtr; + +/* do not change order */ +typedef enum { + RR_GET_INFO, + RR_SET_CONFIG, + GET_REQUIRED_HW_INTERFACES = 10 +} xorgDriverFuncOp; + +typedef Bool xorgDriverFuncProc (ScrnInfoPtr, xorgDriverFuncOp, + pointer); + +/* RR_GET_INFO, RR_SET_CONFIG */ +typedef struct { + int rotation; + int rate; + int width; + int height; +} xorgRRConfig; + +typedef union { + short RRRotations; + xorgRRConfig RRConfig; +} xorgRRRotation, *xorgRRRotationPtr; + +/* GET_REQUIRED_HW_INTERFACES */ +#define HW_IO 1 +#define HW_MMIO 2 +#define NEED_IO_ENABLED(x) (x & HW_IO) + +typedef CARD32 xorgHWFlags; + +/* * The driver list struct. This contains the information required for each * driver before a ScrnInfoRec has been allocated. */ +struct _DriverRec; + +typedef struct { + int driverVersion; + char * driverName; + void (*Identify)(int flags); + Bool (*Probe)(struct _DriverRec *drv, int flags); + const OptionInfoRec * (*AvailableOptions)(int chipid, int bustype); + pointer module; + int refCount; +} DriverRec1; + typedef struct _DriverRec { int driverVersion; char * driverName; @@ -247,8 +297,15 @@ const OptionInfoRec * (*AvailableOptions)(int chipid, int bustype); pointer module; int refCount; + xorgDriverFuncProc *driverFunc; } DriverRec, *DriverPtr; +/* + * AddDriver flags + */ +#define HaveDriverFuncs 1 + + #ifdef XFree86LOADER /* * The optional module list struct. This allows modules exporting helping @@ -737,24 +794,6 @@ PixmapPtr pPix; } DGADeviceRec, *DGADevicePtr; -typedef enum { - RR_GET_INFO, - RR_SET_CONFIG -} xorgRRFuncFlags; - -typedef struct { - int rotation; - int rate; - int width; - int height; -} xorgRRConfig; - -typedef union { - short RRRotations; - xorgRRConfig RRConfig; -} xorgRRRotation, *xorgRRRotationPtr; - - /* * Flags for driver Probe() functions. */ @@ -765,7 +804,6 @@ /* * Driver entry point types */ -typedef struct _ScrnInfoRec *ScrnInfoPtr; typedef Bool xf86ProbeProc (DriverPtr, int); typedef Bool xf86PreInitProc (ScrnInfoPtr, int); @@ -785,8 +823,6 @@ typedef void xf86DPMSSetProc (ScrnInfoPtr, int, int); typedef void xf86LoadPaletteProc (ScrnInfoPtr, int, int *, LOCO *, VisualPtr); typedef void xf86SetOverscanProc (ScrnInfoPtr, int); -typedef Bool xorgRRFuncProc (ScrnInfoPtr, xorgRRFuncFlags, - xorgRRRotationPtr); /* @@ -942,7 +978,7 @@ xf86DPMSSetProc *DPMSSet; xf86LoadPaletteProc *LoadPalette; xf86SetOverscanProc *SetOverscan; - xorgRRFuncProc *RRFunc; + xorgDriverFuncProc *DriverFunc; /* * This can be used when the minor ABI version is incremented. Index: programs/Xserver/hw/xfree86/drivers/dummy/dummy_driver.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/drivers/dummy/Attic/dummy_driver.c,v retrieving revision 1.1.1.9 diff -u -r1.1.1.9 dummy_driver.c --- programs/Xserver/hw/xfree86/drivers/dummy/dummy_driver.c 19 Jan 2005 16:20:35 -0000 1.1.1.9 +++ programs/Xserver/hw/xfree86/drivers/dummy/dummy_driver.c 28 Jan 2005 15:39:39 -0000 @@ -69,6 +69,9 @@ static Bool dummyModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode); static void dummySave(ScrnInfoPtr pScrn); static void dummyRestore(ScrnInfoPtr pScrn, Bool restoreText); +static Bool dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, + pointer ptr); + /* static void DUMMYDisplayPowerManagementSet(ScrnInfoPtr pScrn, */ /* int PowerManagementMode, int flags); */ @@ -103,7 +106,8 @@ DUMMYProbe, DUMMYAvailableOptions, NULL, - 0 + 0, + dummyDriverFunc }; static SymTabRec DUMMYChipsets[] = { @@ -175,7 +179,7 @@ if (!setupDone) { setupDone = TRUE; - xf86AddDriver(&DUMMY, module, 0); + xf86AddDriver(&DUMMY, module, HaveDriverFuncs); /* * Modules that this driver always requires can be loaded here @@ -816,4 +820,20 @@ return TRUE; } return TRUE; +} + + +static Bool +dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr) +{ + CARD32 *flag; + + switch (op) { + case GET_REQUIRED_HW_INTERFACES: + flag = (CARD32*)ptr; + (*flag) = 0; + return TRUE; + default: + return FALSE; + } } Index: programs/Xserver/hw/xfree86/drivers/fbdev/fbdev.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/drivers/fbdev/fbdev.c,v retrieving revision 1.1.1.26 diff -u -r1.1.1.26 fbdev.c --- programs/Xserver/hw/xfree86/drivers/fbdev/fbdev.c 19 Jan 2005 16:20:35 -0000 1.1.1.26 +++ programs/Xserver/hw/xfree86/drivers/fbdev/fbdev.c 28 Jan 2005 15:39:39 -0000 @@ -57,6 +57,8 @@ CARD32 *size, void *closure); static void FBDevPointerMoved(int index, int x, int y); static Bool FBDevDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen); +static Bool FBDevDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, + pointer ptr); enum { FBDEV_ROTATE_NONE=0, FBDEV_ROTATE_CW=270, FBDEV_ROTATE_UD=180, FBDEV_ROTATE_CCW=90 }; @@ -91,7 +93,8 @@ FBDevProbe, FBDevAvailableOptions, NULL, - 0 + 0, + FBDevDriverFunc }; /* Supported "chipsets" */ @@ -208,7 +211,7 @@ if (!setupDone) { setupDone = TRUE; - xf86AddDriver(&FBDEV, module, 0); + xf86AddDriver(&FBDEV, module, HaveDriverFuncs); LoaderRefSymLists(afbSymbols, fbSymbols, shadowSymbols, fbdevHWSymbols, NULL); return (pointer)1; @@ -1099,4 +1102,19 @@ return (DGAInit(pScreen, &FBDevDGAFunctions, fPtr->pDGAMode, fPtr->nDGAMode)); +} + +static Bool +FBDevDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr) +{ + xorgHWFlags *flag; + + switch (op) { + case GET_REQUIRED_HW_INTERFACES: + flag = (CARD32*)ptr; + (*flag) = 0; + return TRUE; + default: + return FALSE; + } } Index: programs/Xserver/hw/xfree86/etc/scanpci.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v retrieving revision 1.1.1.13 diff -u -r1.1.1.13 scanpci.c --- programs/Xserver/hw/xfree86/etc/scanpci.c 30 Apr 2003 14:14:14 -0000 1.1.1.13 +++ programs/Xserver/hw/xfree86/etc/scanpci.c 28 Jan 2005 15:39:39 -0000 @@ -195,7 +195,6 @@ break; } - xf86EnableIO(); pcrpp = xf86scanpci(0); if (!pcrpp) { Index: programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h,v retrieving revision 1.1.1.17 diff -u -r1.1.1.17 xf86_OSproc.h --- programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h 2 Dec 2003 18:49:29 -0000 1.1.1.17 +++ programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h 28 Jan 2005 15:39:39 -0000 @@ -145,7 +145,7 @@ extern void xf86UnMapVidMem(int, pointer, unsigned long); extern void xf86MapReadSideEffects(int, int, pointer, unsigned long); extern int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *, int); -extern void xf86EnableIO(void); +extern Bool xf86EnableIO(void); extern void xf86DisableIO(void); extern Bool xf86DisableInterrupts(void); extern void xf86EnableInterrupts(void); Index: programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c,v retrieving revision 1.1.1.6 diff -u -r1.1.1.6 alpha_video.c --- programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c 6 Jul 2004 15:12:46 -0000 1.1.1.6 +++ programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c 28 Jan 2005 15:39:39 -0000 @@ -399,11 +399,12 @@ extern int ioperm(unsigned long from, unsigned long num, int on); -void +Bool xf86EnableIO() { - ioperm(0, 65536, TRUE); - return; + if (!ioperm(0, 65536, TRUE)) + return TRUE; + return FALSE; } void @@ -416,10 +417,11 @@ #ifdef USE_ALPHA_PIO -void +Bool xf86EnableIO() { alpha_pci_io_enable(1); + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 arm_video.c --- programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c 30 Apr 2003 14:15:12 -0000 1.1.1.3 +++ programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c 28 Jan 2005 15:39:39 -0000 @@ -449,18 +449,19 @@ #ifdef USE_DEV_IO static int IoFd = -1; -void +Bool xf86EnableIO() { if (IoFd >= 0) - return; + return TRUE; if ((IoFd = open("/dev/io", O_RDWR)) == -1) { - FatalError("xf86EnableIO: " + xf86Msg(X_WARNING,"xf86EnableIO: " "Failed to open /dev/io for extended I/O\n"); + return FALSE; } - return; + return TRUE; } void @@ -478,14 +479,14 @@ #if defined(USE_ARC_MMAP) || defined(__arm32__) -void +Bool xf86EnableIO() { int fd; pointer base; if (ExtendedEnabled) - return; + return TRUE; if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { /* Try to map a page at the pccons I/O space */ @@ -496,18 +497,20 @@ IOPortBase = base; } else { - FatalError("EnableIO: failed to mmap %s (%s)\n", + xf86Msg(X_WARNING,"EnableIO: failed to mmap %s (%s)\n", "/dev/ttyC0", strerror(errno)); + return FALSE; } } else { - FatalError("EnableIO: failed to open %s (%s)\n", + xf86Msg("EnableIO: failed to open %s (%s)\n", "/dev/ttyC0", strerror(errno)); + return FALSE; } ExtendedEnabled = TRUE; - return; + return TRUE; } void @@ -554,7 +557,7 @@ static Bool ExtendedEnabled = FALSE; static Bool InitDone = FALSE; -void +Bool xf86EnableIOPorts(ScreenNum) int ScreenNum; { @@ -570,7 +573,7 @@ ScreenEnabled[ScreenNum] = TRUE; if (ExtendedEnabled) - return; + return TRUE; #ifdef USE_ARC_MMAP if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { @@ -610,7 +613,7 @@ (caddr_t)0x0, 0L) - memInfoP->memInfo.u.map_info_mmap.internal_offset; ExtendedEnabled = TRUE; - return; + return TRUE; } #ifdef USE_ARM32_MMAP checkDevMem(TRUE); @@ -626,19 +629,21 @@ if (IOPortBase == (unsigned int)-1) { - FatalError("xf86EnableIOPorts: failed to open mem device or map IO base. \n\ + xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\ Make sure you have the Aperture Driver installed, or a kernel built with the INSECURE option\n"); + return FALSE; } #else /* We don't have the IOBASE, so we can't map the address */ - FatalError("xf86EnableIOPorts: failed to open mem device or map IO base. \n\ + xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\ Try building the server with USE_ARM32_MMAP defined\n"); + return FALSE; #endif #endif ExtendedEnabled = TRUE; - return; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c,v retrieving revision 1.1.1.6 diff -u -r1.1.1.6 i386_video.c --- programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c 30 Jul 2004 19:25:15 -0000 1.1.1.6 +++ programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c 28 Jan 2005 15:39:39 -0000 @@ -331,25 +331,26 @@ static Bool ExtendedEnabled = FALSE; -void +Bool xf86EnableIO() { if (ExtendedEnabled) - return; + return TRUE; if (i386_iopl(TRUE) < 0) { #ifndef __OpenBSD__ - FatalError("%s: Failed to set IOPL for extended I/O", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O", "xf86EnableIO"); #else - FatalError("%s: Failed to set IOPL for extended I/O\n%s", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s", "xf86EnableIO", SYSCTL_MSG); #endif + return FALSE; } ExtendedEnabled = TRUE; - return; + return TRUE; } void @@ -373,25 +374,26 @@ static Bool ExtendedEnabled = FALSE; -void +Bool xf86EnableIO() { if (ExtendedEnabled) - return; + return TRUE; if (amd64_iopl(TRUE) < 0) { #ifndef __OpenBSD__ - FatalError("%s: Failed to set IOPL for extended I/O", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O", "xf86EnableIO"); #else - FatalError("%s: Failed to set IOPL for extended I/O\n%s", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s", "xf86EnableIO", SYSCTL_MSG); #endif + return FALSE; } ExtendedEnabled = TRUE; - return; + return TRUE; } void @@ -414,18 +416,19 @@ #ifdef USE_DEV_IO static int IoFd = -1; -void +Bool xf86EnableIO() { if (IoFd >= 0) - return; + return TRUE; if ((IoFd = open("/dev/io", O_RDWR)) == -1) { - FatalError("xf86EnableIO: " + xf86Msg(X_WARNING,"xf86EnableIO: " "Failed to open /dev/io for extended I/O"); + return FALSE; } - return; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c,v retrieving revision 1.1.1.5 diff -u -r1.1.1.5 bsdi_video.c --- programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c 3 Feb 2004 13:19:43 -0000 1.1.1.5 +++ programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c 28 Jan 2005 15:39:39 -0000 @@ -86,18 +86,20 @@ static Bool ExtendedEnabled = FALSE; -void +Bool xf86EnableIO() { if (ExtendedEnabled) - return; + return TRUE; if (ioctl(xf86Info.consoleFd, PCCONENABIOPL, 0) < 0) { - FatalError("%s: Failed to set IOPL for extended I/O\n", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n", "xf86EnableIOPorts"); + return FALSE; } ExtendedEnabled = TRUE; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/bus/Pci.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.c,v retrieving revision 1.1.1.57 diff -u -r1.1.1.57 Pci.c --- programs/Xserver/hw/xfree86/os-support/bus/Pci.c 19 Jan 2005 16:20:53 -0000 1.1.1.57 +++ programs/Xserver/hw/xfree86/os-support/bus/Pci.c 28 Jan 2005 15:39:39 -0000 @@ -208,13 +208,6 @@ #define PCI_MFDEV_SUPPORT 1 /* Include PCI multifunction device support */ #define PCI_BRIDGE_SUPPORT 1 /* Include support for PCI-to-PCI bridges */ -#ifdef PC98 -#define outb(port,data) _outb(port,data) -#define outl(port,data) _outl(port,data) -#define inb(port) _inb(port) -#define inl(port) _inl(port) -#endif - /* * Global data */ @@ -831,90 +824,6 @@ pciBusNum = -1; return pciGenFindNext(); -} - -#if defined (__powerpc__) -static int buserr_detected; - -static -void buserr(int sig) -{ - buserr_detected = 1; -} -#endif - -CARD32 -pciCfgMech1Read(PCITAG tag, int offset) -{ - unsigned long rv = 0xffffffff; -#ifdef DEBUGPCI - ErrorF("pciCfgMech1Read(tag=%08x,offset=%08x)\n", tag, offset); -#endif - -#if defined(__powerpc__) - signal(SIGBUS, buserr); - buserr_detected = 0; -#endif - - outl(0xCF8, PCI_EN | tag | (offset & 0xfc)); - rv = inl(0xCFC); - -#if defined(__powerpc__) - signal(SIGBUS, SIG_DFL); - if (buserr_detected) - { -#ifdef DEBUGPCI - ErrorF("pciCfgMech1Read() BUS ERROR\n"); -#endif - return(0xffffffff); - } - else -#endif - return(rv); -} - -void -pciCfgMech1Write(PCITAG tag, int offset, CARD32 val) -{ -#ifdef DEBUGPCI - ErrorF("pciCfgMech1Write(tag=%08x,offset=%08x,val=%08x)\n", - tag, offset,val); -#endif - -#if defined(__powerpc__) - signal(SIGBUS, SIG_IGN); -#endif - - outl(0xCF8, PCI_EN | tag | (offset & 0xfc)); -#if defined(Lynx) && defined(__powerpc__) - outb(0x80, 0x00); /* without this the next access fails - * on my Powerstack system when we use - * assembler inlines for outl */ -#endif - outl(0xCFC, val); - -#if defined(__powerpc__) - signal(SIGBUS, SIG_DFL); -#endif -} - -void -pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask, CARD32 val) -{ - unsigned long rv = 0xffffffff; - -#if defined(__powerpc__) - signal(SIGBUS, buserr); -#endif - - outl(0xCF8, PCI_EN | tag | (offset & 0xfc)); - rv = inl(0xCFC); - rv = (rv & ~mask) | val; - outl(0xCFC, rv); - -#if defined(__powerpc__) - signal(SIGBUS, SIG_DFL); -#endif } CARD32 Index: programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c,v retrieving revision 1.1.1.19 diff -u -r1.1.1.19 ix86Pci.c --- programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c 1 Nov 2004 16:46:40 -0000 1.1.1.19 +++ programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c 28 Jan 2005 15:39:39 -0000 @@ -140,6 +140,7 @@ #include "compiler.h" #include "xf86.h" #include "xf86Priv.h" +#include "xf86_OSlib.h" #include "Pci.h" #ifdef PC98 @@ -278,6 +279,8 @@ #endif case PCIProbe1: + if (!xf86EnableIO()) + return; xf86MsgVerb(X_INFO, 2, "PCI: Probing config type using method 1\n"); @@ -449,6 +452,8 @@ break; /* } */ case PCIProbe2: /* { */ + if (!xf86EnableIO()) + return; /* The scanpci-style detection method */ @@ -481,6 +486,8 @@ break; /* } */ case PCIForceConfig1: + if (!xf86EnableIO()) + return; xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 1\n"); @@ -490,6 +497,8 @@ return; case PCIForceConfig2: + if (!xf86EnableIO()) + return; xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 2\n"); Index: programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c,v retrieving revision 1.1.1.9 diff -u -r1.1.1.9 linuxPci.c --- programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c 19 Jan 2005 16:20:53 -0000 1.1.1.9 +++ programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c 28 Jan 2005 15:39:39 -0000 @@ -99,9 +99,9 @@ } static int -linuxPciOpenFile(PCITAG tag) +linuxPciOpenFile(PCITAG tag, Bool write) { - static int lbus,ldev,lfunc,fd = -1; + static int lbus,ldev,lfunc,fd = -1,is_write = 0; int bus, dev, func; char file[32]; struct stat ignored; @@ -109,7 +109,8 @@ bus = PCI_BUS_FROM_TAG(tag); dev = PCI_DEV_FROM_TAG(tag); func = PCI_FUNC_FROM_TAG(tag); - if (fd == -1 || bus != lbus || dev != ldev || func != lfunc) { + if (fd == -1 || (write && (!is_write)) + || bus != lbus || dev != ldev || func != lfunc) { if (fd != -1) close(fd); if (bus < 256) { @@ -129,7 +130,19 @@ sprintf(file, "/proc/bus/pci/%04x/%02x.%1x", bus, dev, func); } - fd = open(file,O_RDWR); + if (write) { + fd = open(file,O_RDWR); + if (fd != -1) is_write = TRUE; + } else switch (is_write) { + case TRUE: + fd = open(file,O_RDWR); + if (fd > -1) + break; + default: + fd = open(file,O_RDONLY); + is_write = FALSE; + } + lbus = bus; ldev = dev; lfunc = func; @@ -143,7 +156,7 @@ int fd; CARD32 val = 0xffffffff; - if (-1 != (fd = linuxPciOpenFile(tag))) { + if (-1 != (fd = linuxPciOpenFile(tag,FALSE))) { lseek(fd,off,SEEK_SET); read(fd,&val,4); } @@ -155,7 +168,7 @@ { int fd; - if (-1 != (fd = linuxPciOpenFile(tag))) { + if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) { lseek(fd,off,SEEK_SET); val = PCI_CPU(val); write(fd,&val,4); @@ -168,7 +181,7 @@ int fd; CARD32 val = 0xffffffff; - if (-1 != (fd = linuxPciOpenFile(tag))) { + if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) { lseek(fd,off,SEEK_SET); read(fd,&val,4); val = PCI_CPU(val); @@ -336,7 +349,7 @@ if (pPCI && (result = PCI_DOM_FROM_BUS(pPCI->busnum))) return result; - if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0)) < 0) + if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0) return 0; if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0) @@ -359,7 +372,7 @@ pPCI = xf86GetPciHostConfigFromTag(Tag); - if (((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0)) < 0) || + if (((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0) || (ioctl(fd, mmap_ioctl, 0) < 0)) break; Index: programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c,v retrieving revision 1.1.1.5 diff -u -r1.1.1.5 ppcPci.c --- programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c 16 Sep 2002 12:58:27 -0000 1.1.1.5 +++ programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c 28 Jan 2005 15:39:39 -0000 @@ -78,14 +78,15 @@ pmaxPciInit(); #else - - extern void motoppcPciInit(void); - + + static void motoppcPciInit(void); motoppcPciInit(); #endif } +#if defined(PowerMAX_OS) + /* * Motorola PowerPC platform support * @@ -101,6 +102,11 @@ */ static ADDRESS motoppcBusAddrToHostAddr(PCITAG, PciAddrType, ADDRESS); static ADDRESS motoppcHostAddrToBusAddr(PCITAG, PciAddrType, ADDRESS); +static CARD32 pciCfgMech1Read(PCITAG tag, int offset); +static void pciCfgMech1Write(PCITAG tag, int offset, CARD32 val); +static void pciCfgMech1SetBits(PCITAG tag, int offset, + CARD32 mask, CARD32 val); + static pciBusFuncs_t motoppcFuncs0 = { /* pciReadLong */ pciCfgMech1Read, @@ -126,7 +132,7 @@ extern volatile unsigned char *ioBase; -void +static void motoppcPciInit() { pciNumBuses = 1; @@ -134,6 +140,9 @@ pciFindFirstFP = pciGenFindFirst; pciFindNextFP = pciGenFindNext; + if (!xf86EnableIO()) + FatalError("motoppcPciInit: EnableIO failed\n"); + if (ioBase == MAP_FAILED) { ppcPciIoMap(0); /* Make inb/outb et al work for pci0 and its secondaries */ @@ -210,3 +219,89 @@ /*NOTREACHED*/ } + +#if defined (__powerpc__) +static int buserr_detected; + +static +void buserr(int sig) +{ + buserr_detected = 1; +} +#endif + +static CARD32 +pciCfgMech1Read(PCITAG tag, int offset) +{ + unsigned long rv = 0xffffffff; +#ifdef DEBUGPCI + ErrorF("pciCfgMech1Read(tag=%08x,offset=%08x)\n", tag, offset); +#endif + +#if defined(__powerpc__) + signal(SIGBUS, buserr); + buserr_detected = 0; +#endif + + outl(0xCF8, PCI_EN | tag | (offset & 0xfc)); + rv = inl(0xCFC); + +#if defined(__powerpc__) + signal(SIGBUS, SIG_DFL); + if (buserr_detected) + { +#ifdef DEBUGPCI + ErrorF("pciCfgMech1Read() BUS ERROR\n"); +#endif + return(0xffffffff); + } + else +#endif + return(rv); +} + +static void +pciCfgMech1Write(PCITAG tag, int offset, CARD32 val) +{ +#ifdef DEBUGPCI + ErrorF("pciCfgMech1Write(tag=%08x,offset=%08x,val=%08x)\n", + tag, offset,val); +#endif + +#if defined(__powerpc__) + signal(SIGBUS, SIG_IGN); +#endif + + outl(0xCF8, PCI_EN | tag | (offset & 0xfc)); +#if defined(Lynx) && defined(__powerpc__) + outb(0x80, 0x00); /* without this the next access fails + * on my Powerstack system when we use + * assembler inlines for outl */ +#endif + outl(0xCFC, val); + +#if defined(__powerpc__) + signal(SIGBUS, SIG_DFL); +#endif +} + +static void +pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask, CARD32 val) +{ + unsigned long rv = 0xffffffff; + +#if defined(__powerpc__) + signal(SIGBUS, buserr); +#endif + + outl(0xCF8, PCI_EN | tag | (offset & 0xfc)); + rv = inl(0xCFC); + rv = (rv & ~mask) | val; + outl(0xCFC, rv); + +#if defined(__powerpc__) + signal(SIGBUS, SIG_DFL); +#endif +} + +#endif /* PowerMAX_OS */ Index: programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 hurd_video.c --- programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c 16 Nov 2000 20:00:20 -0000 1.1.1.2 +++ programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c 28 Jan 2005 15:39:39 -0000 @@ -111,10 +111,10 @@ /************************************************************************** * I/O Permissions section ***************************************************************************/ -void +Bool xf86EnableIO() { - return; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v retrieving revision 1.1.1.6 diff -u -r1.1.1.6 lnx_init.c --- programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 19 Jan 2005 16:20:56 -0000 1.1.1.6 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 28 Jan 2005 15:39:39 -0000 @@ -84,7 +84,6 @@ xf86OpenConsole(void) { int i, fd = -1; - int result; struct vt_mode VT; struct vt_stat vts; MessageType from = X_PROBED; @@ -95,13 +94,12 @@ char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; - if (serverGeneration == 1) - { - /* check if we're run with euid==0 */ - if (geteuid() != 0) - { - FatalError("xf86OpenConsole: Server must be suid root\n"); - } + if (serverGeneration == 1) { + + /* when KeepTty check if we're run with euid==0 */ + if (KeepTty && geteuid() != 0) + FatalError("xf86OpenConsole:" + " Server must be suid root for option \"KeepTTY\"\n"); /* * setup the virtual terminal manager @@ -110,20 +108,23 @@ xf86Info.vtno = VTnum; from = X_CMDLINE; } else { + i=0; - while (tty0[i] != NULL) - { + while (tty0[i] != NULL) { if ((fd = open(tty0[i],O_WRONLY,0)) >= 0) break; i++; } + if (fd < 0) FatalError( "xf86OpenConsole: Cannot open /dev/tty0 (%s)\n", strerror(errno)); + if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || (xf86Info.vtno == -1)) { - FatalError("xf86OpenConsole: Cannot find a free VT\n"); + FatalError("xf86OpenConsole: Cannot find a free VT: %s\n", + strerror(errno)); } close(fd); } @@ -132,43 +133,61 @@ fb_dev_name=getenv("FRAMEBUFFER"); if (!fb_dev_name) fb_dev_name="/dev/fb0current"; + if ((fbfd = open(fb_dev_name, O_RDONLY)) < 0) FatalError("xf86OpenConsole: Cannot open %s (%s)\n", - fb_dev_name, strerror(errno)); - if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var)) - FatalError("xf86OpenConsole: Unable to get screen info\n"); + fb_dev_name, strerror(errno)); + + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var) < 0) + FatalError("xf86OpenConsole: Unable to get screen info %s\n", + strerror(errno)); #endif xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); if (!KeepTty) { - setpgrp(); + pid_t ppid = getppid(); + pid_t ppgid; + ppgid = getpgid(ppid); + + /* + * change to parent process group that pgid != pid so + * that setsid() doesn't fail and we become process + * group leader + */ + if (setpgid(0,ppgid) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: setpgid failed: %s\n", + strerror(errno)); + + /* become process group leader */ + if ((setsid() < 0)) + xf86Msg(X_WARNING, "xf86OpenConsole: setsid failed: %s\n", + strerror(errno)); } i=0; - while (vcs[i] != NULL) - { + while (vcs[i] != NULL) { sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) >= 0) break; i++; } - if (xf86Info.consoleFd < 0) { - FatalError("xf86OpenConsole: Cannot open virtual console %d (%s)\n", - xf86Info.vtno, strerror(errno)); - } + if (xf86Info.consoleFd < 0) + FatalError("xf86OpenConsole: Cannot open virtual console" + " %d (%s)\n", xf86Info.vtno, strerror(errno)); /* * Grab the vt ownership before we overwrite it. * Hard coded /dev/tty0 into this function as well for below. */ - if (!saveVtPerms()){ - xf86Msg(X_WARNING, - "xf86OpenConsole: Could not save ownership of VT\n"); - } + if (!saveVtPerms()) + xf86Msg(X_WARNING, + "xf86OpenConsole: Could not save ownership of VT\n"); /* change ownership of the vt */ - chown(vtname, getuid(), getgid()); + if (chown(vtname, getuid(), getgid()) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n", + vtname, strerror(errno)); /* * the current VT device we're running on is not "console", we want @@ -176,65 +195,63 @@ * * Why is this needed?? */ - chown("/dev/tty0", getuid(), getgid()); + if (chown("/dev/tty0", getuid(), getgid()) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n", + strerror(errno)); /* * Linux doesn't switch to an active vt after the last close of a vt, * so we do this ourselves by remembering which is active now. */ - if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0) - { + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: VT_GETSTATE failed: %s\n", + strerror(errno)); + else activeVT = vts.v_active; - } - if (!KeepTty) - { +#if 0 + if (!KeepTty) { /* * Detach from the controlling tty to avoid char loss */ - if ((i = open("/dev/tty",O_RDWR)) >= 0) - { + if ((i = open("/dev/tty",O_RDWR)) >= 0) { ioctl(i, TIOCNOTTY, 0); close(i); } } - +#endif + +#if defined(DO_OS_FONTRESTORE) + lnx_savefont(); +#endif /* * now get the VT */ - SYSCALL(result = ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); - } -#if defined(DO_OS_FONTRESTORE) - lnx_savefont(); -#endif - SYSCALL(result = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); - if (result < 0) - { - FatalError("xf86OpenConsole: VT_GETMODE failed\n"); - } + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_GETMODE failed %s\n", + strerror(errno)); signal(SIGUSR1, xf86VTRequest); VT.mode = VT_PROCESS; VT.relsig = SIGUSR1; VT.acqsig = SIGUSR1; + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) - { - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); - } + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n", + strerror(errno)); + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) - { - FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n"); - } + FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n", + strerror(errno)); /* we really should have a InitOSInputDevices() function instead * of Init?$#*&Device(). So I just place it here */ @@ -247,24 +264,17 @@ FatalError("Unable to set screen info\n"); close(fbfd); #endif - } - else - { - /* serverGeneration != 1 */ + } else { /* serverGeneration != 1 */ /* * now get the VT */ - SYSCALL(result = ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); - } + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n", + strerror(errno)); } return; } @@ -277,35 +287,45 @@ struct vt_stat vts; int vtno = -1; - if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0) + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETSTATE failed: %s\n", + strerror(errno)); + else vtno = vts.v_active; #endif -#if 0 - ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno); - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0); -#endif - ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */ - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) - { + /* Back to text mode ... */ + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n", + strerror(errno)); + else { + /* set dflt vt handling */ VT.mode = VT_AUTO; - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */ + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n", + strerror(errno)); } /* * Perform a switch back to the active VT when we were started */ - if (activeVT >= 0) - { - ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT); + if (activeVT >= 0) { + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n", + strerror(errno)); activeVT = -1; } + #if defined(DO_OS_FONTRESTORE) - if (xf86Info.vtno == vtno) + if (xf86Info.vtno == vtno) /* check if we are active */ lnx_restorefont(); lnx_freefontdata(); #endif - close(xf86Info.consoleFd); /* make the vt-manager happy */ + close(xf86Info.consoleFd); /* make the vt-manager happy */ restoreVtPerms(); /* restore the permissions */ Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c,v retrieving revision 1.1.1.9 diff -u -r1.1.1.9 lnx_kbd.c --- programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c 19 Jan 2005 16:20:56 -0000 1.1.1.9 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c 28 Jan 2005 15:39:39 -0000 @@ -215,6 +215,13 @@ #if defined(__alpha__) || defined (__i386__) || defined(__ia64__) + if (!xorgHWAccess) { + if (xf86EnableIO()) + xorgHWAccess = TRUE; + else + return; + } + /* The ioport way */ for (i = 0; i < RATE_COUNT; i++) Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v retrieving revision 1.1.1.36 diff -u -r1.1.1.36 lnx_video.c --- programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c 3 Aug 2004 10:11:12 -0000 1.1.1.36 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c 28 Jan 2005 15:39:39 -0000 @@ -490,7 +490,7 @@ #endif -void +Bool xf86EnableIO(void) { #if defined(__powerpc__) @@ -499,7 +499,7 @@ #endif if (ExtendedEnabled) - return; + return TRUE; #if defined(__powerpc__) ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); @@ -512,16 +512,20 @@ /* Should this be fatal or just a warning? */ #if 0 if (ioBase == MAP_FAILED) { - FatalError( + xf86Msg(X_WARNING, "xf86EnableIOPorts: Failed to map iobase (%s)\n", strerror(errno)); + return FALSE; } #endif } close(fd); #elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) - if (ioperm(0, 1024, 1) || iopl(3)) - FatalError("xf86EnableIOPorts: Failed to set IOPL for I/O\n"); + if (ioperm(0, 1024, 1) || iopl(3)) { + xf86Msg(X_WARNING, + "xf86EnableIOPorts: Failed to set IOPL for I/O\n"); + return FALSE; + } # if !defined(__alpha__) ioperm(0x40,4,0); /* trap access to the timer chip */ ioperm(0x60,4,0); /* trap access to the keyboard controller */ @@ -529,7 +533,7 @@ #endif ExtendedEnabled = TRUE; - return; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c,v retrieving revision 1.1.1.4 diff -u -r1.1.1.4 lynx_video.c --- programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c 8 Jan 2003 11:44:57 -0000 1.1.1.4 +++ programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c 28 Jan 2005 15:39:39 -0000 @@ -297,7 +297,7 @@ ioBase = MAP_FAILED; } -void +Bool xf86EnableIO() { if (IOEnabled++ == 0) { @@ -305,7 +305,8 @@ (char *)PHYS_ISA_IO_SPACE, 64*1024, SM_READ|SM_WRITE); if (ioBase == MAP_FAILED) { --IOEnabled; - FatalError("xf86EnableIO: Failed to map I/O\n"); + xf86Msg(X_WARNING,"xf86EnableIO: Failed to map I/O\n"); + return FALSE; } else { #ifdef DEBUG ErrorF("xf86EnableIO: mapped I/O at vaddr 0x%08x\n", @@ -314,7 +315,7 @@ atexit(removeIOSmem); } } - return; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 nto_ioperm.c --- programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c 30 Nov 2001 13:41:41 -0000 1.1.1.2 +++ programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c 28 Jan 2005 15:39:39 -0000 @@ -28,13 +28,14 @@ #include -void xf86EnableIO() +Bool xf86EnableIO() { ErrorF("xf86EnableIO: enabling I/O access\n"); if(ThreadCtl(_NTO_TCTL_IO, 0)) { ErrorF("xf86EnableIO: could not set I/O privilege, errno %d\n",errno); + return FALSE; } - return; + return TRUE; } void xf86DisableIO() Index: programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 os2_ioperm.c --- programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c 10 Apr 2000 13:13:37 -0000 1.1.1.1 +++ programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c 28 Jan 2005 15:39:39 -0000 @@ -48,7 +48,7 @@ USHORT callgate[3]={0,0,0}; -void xf86EnableIO() +Bool xf86EnableIO() { HFILE hfd; @@ -56,7 +56,7 @@ APIRET rc; /* no need to call multiple times */ - if (ioEnabled) return; + if (ioEnabled) return TRUE; if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action, (ULONG)0, FILE_SYSTEM, FILE_OPEN, @@ -64,7 +64,7 @@ (ULONG)0) != 0) { xf86Msg(X_ERROR,"Error opening fastio$ driver...\n"); xf86Msg(X_ERROR,"Please install xf86sup.sys in config.sys!\n"); - exit(42); + return FALSE; } callgate[0] = callgate[1] = 0; @@ -78,7 +78,7 @@ "EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n", rc,dlen); DosClose(hfd); - exit(42); + return FALSE; } /* Calling callgate with function 13 sets IOPL for the program */ @@ -90,7 +90,7 @@ ioEnabled = TRUE; DosClose(hfd); - return; + return TRUE; } void xf86DisableIO() Index: programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 sco_iop.c --- programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c 29 Jul 2002 14:46:29 -0000 1.1.1.1 +++ programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c 28 Jan 2005 15:39:39 -0000 @@ -62,14 +62,18 @@ static Bool IOEnabled = FALSE; -void xf86EnableIO(void) +Bool xf86EnableIO(void) { if (IOEnabled) - return; + return TRUE; - if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) - FatalError("Failed to set IOPL for extended I/O\n"); + if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) { + xf86Msg(X_WARNING,"Failed to set IOPL for extended I/O\n"); + return FALSE; + } + IOEnabled = TRUE; + return TRUE; } void xf86DisableIO(void) Index: programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 ioperm_noop.c --- programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c 31 Jul 2001 10:48:21 -0000 1.1.1.2 +++ programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c 28 Jan 2005 15:39:39 -0000 @@ -33,10 +33,10 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" -void +Bool xf86EnableIO() { - return; + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 sun_vid.c --- programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c 22 Nov 2002 10:38:33 -0000 1.1.1.3 +++ programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c 28 Jan 2005 15:39:39 -0000 @@ -147,18 +147,20 @@ static Bool ExtendedEnabled = FALSE; #endif -void +Bool xf86EnableIO(void) { #ifdef i386 if (ExtendedEnabled) - return; - - if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) - FatalError("xf86EnableIOPorts: Failed to set IOPL for I/O\n"); + return TRUE; + if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) { + xf86Msg(X_WARNING,"xf86EnableIOPorts: Failed to set IOPL for I/O\n"); + return FALSE; + } ExtendedEnabled = TRUE; #endif /* i386 */ + return TRUE; } void Index: programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c,v retrieving revision 1.1.1.4 diff -u -r1.1.1.4 sysv_video.c --- programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c 30 Apr 2003 14:15:22 -0000 1.1.1.4 +++ programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c 28 Jan 2005 15:39:39 -0000 @@ -281,22 +281,23 @@ static Bool ExtendedEnabled = FALSE; static Bool InitDone = FALSE; -void +Bool xf86EnableIO() { int i; if (ExtendedEnabled) - return; + return TRUE; if (SET_IOPL() < 0) { - FatalError( + xf86Msg(X_WARNING, "xf86EnableIO: Failed to set IOPL for extended I/O\n"); + return FALSE; } ExtendedEnabled = TRUE; - return; + return TRUE; } void