diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c index d5f8450f3..099ff3482 100644 --- a/hw/xfree86/common/xf86Bus.c +++ b/hw/xfree86/common/xf86Bus.c @@ -3030,7 +3030,7 @@ void 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; diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index ad711ef68..1a5fa4620 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -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 @@ DoConfigure() 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 @@ DoConfigure() /* 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; diff --git a/hw/xfree86/common/xf86DoProbe.c b/hw/xfree86/common/xf86DoProbe.c index eece97719..560ab2e9d 100644 --- a/hw/xfree86/common/xf86DoProbe.c +++ b/hw/xfree86/common/xf86DoProbe.c @@ -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 @@ DoProbe() { int i; Bool probeResult; - + Bool ioEnableFailed = FALSE; + #ifdef XFree86LOADER /* Find the list of video driver modules. */ char **list = xf86DriverlistFromCompile(); @@ -76,6 +78,24 @@ DoProbe() /* 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", diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index 22740047d..4b07955cb 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -1431,7 +1431,8 @@ xf86VTSwitch() xf86Screens[i]->access = NULL; xf86Screens[i]->busAccess = NULL; } - xf86DisableIO(); + if (xorgHWAccess) + xf86DisableIO(); } } else { @@ -1443,7 +1444,8 @@ xf86VTSwitch() prevSIGIO = xf86BlockSIGIO(); xf86OSPMClose = xf86OSPMOpen(); - xf86EnableIO(); + if (xorgHWAccess) + xf86EnableIO(); xf86AccessEnter(); xf86EnterServerState(SETUP); for (i = 0; i < xf86NumScreens; i++) { diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c index 6f2e9135a..bb6b9664f 100644 --- a/hw/xfree86/common/xf86Globals.c +++ b/hw/xfree86/common/xf86Globals.c @@ -238,6 +238,7 @@ Bool xf86MiscModInDevAllowNonLocal = FALSE; #endif RootWinPropPtr *xf86RegisteredPropertiesTable = NULL; Bool xf86inSuspend = FALSE; +Bool xorgHWAccess = FALSE; #ifdef DLOPEN_HACK /* diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 525f76835..61d1a1271 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -83,7 +83,12 @@ xf86AddDriver(DriverPtr driver, pointer module, int flags) 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 @@ xf86AllocateScreen(DriverPtr drv, int flags) } #endif + xf86Screens[i]->DriverFunc = drv->driverFunc; + return xf86Screens[i]; } diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index 2a251e4f6..a32536fe8 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -378,9 +378,6 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) 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 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) } /* - * 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 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) */ 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 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) 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 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) 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 @@ ddxProcessArgument(int argc, char **argv, int i) */ /* 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 @@ ddxProcessArgument(int argc, char **argv, int i) } 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 @@ ddxUseMsg() 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"); diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h index a9677bd73..8b0a4323b 100644 --- a/hw/xfree86/common/xf86Priv.h +++ b/hw/xfree86/common/xf86Priv.h @@ -112,6 +112,7 @@ extern int xf86Verbose; /* verbosity level */ extern int xf86LogVerbose; /* log file verbosity level */ extern Bool xf86ProbeOnly; extern Bool xf86DoProbe; +extern Bool xorgHWAccess; extern RootWinPropPtr *xf86RegisteredPropertiesTable; diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c index 53d381676..ba7127d75 100644 --- a/hw/xfree86/common/xf86RandR.c +++ b/hw/xfree86/common/xf86RandR.c @@ -1,4 +1,4 @@ -/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.5 2004/08/13 18:24:07 sandmann Exp $ */ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.6 2004/12/04 00:42:52 kuhn Exp $ */ /* * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.7tsi Exp $ * @@ -104,11 +104,11 @@ xf86RandRGetInfo (ScreenPtr pScreen, Rotation *rotations) } /* 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 @@ xf86RandRSetConfig (ScreenPtr pScreen, } /* 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; } diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h index 770233033..5aca02985 100644 --- a/hw/xfree86/common/xf86str.h +++ b/hw/xfree86/common/xf86str.h @@ -235,10 +235,60 @@ typedef struct x_ClockRanges { int strategy; } 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 @@ typedef struct _DriverRec { 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 @@ typedef struct { 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 @@ typedef union { /* * Driver entry point types */ -typedef struct _ScrnInfoRec *ScrnInfoPtr; typedef Bool xf86ProbeProc (DriverPtr, int); typedef Bool xf86PreInitProc (ScrnInfoPtr, int); @@ -785,8 +823,6 @@ typedef int xf86HandleMessageProc (int, const char*, const char*, char**); 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 @@ typedef struct _ScrnInfoRec { xf86DPMSSetProc *DPMSSet; xf86LoadPaletteProc *LoadPalette; xf86SetOverscanProc *SetOverscan; - xorgRRFuncProc *RRFunc; + xorgDriverFuncProc *DriverFunc; /* * This can be used when the minor ABI version is incremented. diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c index aa3313dc3..24048535d 100644 --- a/hw/xfree86/os-support/bsd/alpha_video.c +++ b/hw/xfree86/os-support/bsd/alpha_video.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c,v 1.5 2003/04/03 16:50:04 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c,v 1.6 2003/12/30 15:18:30 herrb Exp $ */ /* * Copyright 1992 by Rich Murphey * Copyright 1993 by David Wexelblat @@ -117,11 +117,13 @@ has_bwx(void) #endif } #else /* __NetBSD__ */ +static unsigned long hae_thresh = (1UL << 24); +static unsigned long hae_mask = 0xf8000000UL; /* XXX - should use xf86AXP.c */ static struct alpha_bus_window *abw; static int abw_count = -1; static void -init_abw() +init_abw(void) { if (abw_count < 0) { abw_count = alpha_bus_getwindows(ALPHA_BUS_TYPE_PCI_MEM, &abw); @@ -142,7 +144,7 @@ has_bwx(void) } static unsigned long -dense_base() +dense_base(void) { if (abw_count < 0) init_abw(); @@ -154,7 +156,7 @@ dense_base() } static unsigned long -memory_base() +memory_base(void) { if (abw_count < 0) init_abw(); @@ -284,11 +286,13 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem) xf86Msg(X_PROBED,"Machine needs sparse mapping\n"); pVidMem->mapMem = mapVidMemSparse; pVidMem->unmapMem = unmapVidMemSparse; +#ifndef __NetBSD__ if (axpSystem == -1) axpSystem = bsdGetAXP(); hae_thresh = xf86AXPParams[axpSystem].hae_thresh; hae_mask = xf86AXPParams[axpSystem].hae_mask; sparse_size = xf86AXPParams[axpSystem].size; +#endif /* __NetBSD__ */ } pVidMem->initialised = TRUE; } @@ -314,7 +318,7 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX); if (base == MAP_FAILED) { - FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n", + FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n", "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); } @@ -324,7 +328,7 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) /* else, mmap /dev/vga */ if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000) { - FatalError("%s: Address 0x%x outside allowable range\n", + FatalError("%s: Address 0x%lx outside allowable range\n", "xf86MapVidMem", Base); } base = mmap(0, Size, @@ -372,7 +376,7 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, if ((long)ptr == -1) { xf86Msg(X_WARNING, - "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n", + "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", DEV_MEM, Len, Base, Offset, strerror(errno)); return(-1); } @@ -395,11 +399,12 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, 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 @@ -412,10 +417,11 @@ xf86DisableIO() #ifdef USE_ALPHA_PIO -void +Bool xf86EnableIO() { alpha_pci_io_enable(1); + return TRUE; } void @@ -490,6 +496,7 @@ struct parms { u_int64_t hae; }; +#ifndef __NetBSD__ static int sethae(u_int64_t hae) { @@ -505,6 +512,7 @@ sethae(u_int64_t hae) return -1; #endif } +#endif /* __NetBSD__ */ static pointer mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags) @@ -553,7 +561,6 @@ readSparse8(pointer Base, register unsigned long Offset) { register unsigned long result, shift; register unsigned long msb; - mem_barrier(); Offset += (unsigned long)Base - (unsigned long)memBase; shift = (Offset & 0x3) << 3; @@ -561,11 +568,12 @@ readSparse8(pointer Base, register unsigned long Offset) msb = Offset & hae_mask; Offset -= msb; if (msb_set != msb) { +#ifndef __NetBSD__ sethae(msb); +#endif msb_set = msb; } } - result = *(vuip) ((unsigned long)memSBase + (Offset << 5)); result >>= shift; return 0xffUL & result; @@ -584,7 +592,9 @@ readSparse16(pointer Base, register unsigned long Offset) msb = Offset & hae_mask; Offset -= msb; if (msb_set != msb) { +#ifndef __NetBSD__ sethae(msb); +#endif msb_set = msb; } } @@ -612,7 +622,9 @@ writeSparse8(int Value, pointer Base, register unsigned long Offset) msb = Offset & hae_mask; Offset -= msb; if (msb_set != msb) { +#ifndef __NetBSD__ sethae(msb); +#endif msb_set = msb; } } @@ -631,7 +643,9 @@ writeSparse16(int Value, pointer Base, register unsigned long Offset) msb = Offset & hae_mask; Offset -= msb; if (msb_set != msb) { +#ifndef __NetBSD__ sethae(msb); +#endif msb_set = msb; } } @@ -659,7 +673,9 @@ writeSparseNB8(int Value, pointer Base, register unsigned long Offset) msb = Offset & hae_mask; Offset -= msb; if (msb_set != msb) { +#ifndef __NetBSD__ sethae(msb); +#endif msb_set = msb; } } @@ -677,7 +693,9 @@ writeSparseNB16(int Value, pointer Base, register unsigned long Offset) msb = Offset & hae_mask ; Offset -= msb; if (msb_set != msb) { +#ifndef __NetBSD__ sethae(msb); +#endif msb_set = msb; } } diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c index 36943add1..1a2313226 100644 --- a/hw/xfree86/os-support/bsd/arm_video.c +++ b/hw/xfree86/os-support/bsd/arm_video.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c,v 1.2 2003/03/14 13:46:03 tsi Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c,v 1.1tsi Exp $ */ /* * Copyright 1992 by Rich Murphey * Copyright 1993 by David Wexelblat @@ -449,18 +449,19 @@ armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) #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 @@ xf86DisableIO() #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 @@ xf86EnableIO() 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 ScreenEnabled[MAXSCREENS]; static Bool ExtendedEnabled = FALSE; static Bool InitDone = FALSE; -void +Bool xf86EnableIOPorts(ScreenNum) int ScreenNum; { @@ -570,7 +573,7 @@ int ScreenNum; ScreenEnabled[ScreenNum] = TRUE; if (ExtendedEnabled) - return; + return TRUE; #ifdef USE_ARC_MMAP if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { @@ -610,7 +613,7 @@ int ScreenNum; (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 @@ int ScreenNum; 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 diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c index 62d063655..abec95b91 100644 --- a/hw/xfree86/os-support/bsd/i386_video.c +++ b/hw/xfree86/os-support/bsd/i386_video.c @@ -331,25 +331,26 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, 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 @@ xf86DisableIO() 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 @@ xf86DisableIO() #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 diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c index 319bd4fb4..c98f6f0bc 100644 --- a/hw/xfree86/os-support/bus/Pci.c +++ b/hw/xfree86/os-support/bus/Pci.c @@ -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 */ @@ -833,90 +826,6 @@ pciGenFindFirst(void) 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 pciByteSwap(CARD32 u) { diff --git a/hw/xfree86/os-support/bus/ix86Pci.c b/hw/xfree86/os-support/bus/ix86Pci.c index 9437204a9..99e3ba245 100644 --- a/hw/xfree86/os-support/bus/ix86Pci.c +++ b/hw/xfree86/os-support/bus/ix86Pci.c @@ -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 @@ void ix86PciSelectCfgmech(void) #endif case PCIProbe1: + if (!xf86EnableIO()) + return; xf86MsgVerb(X_INFO, 2, "PCI: Probing config type using method 1\n"); @@ -449,6 +452,8 @@ void ix86PciSelectCfgmech(void) break; /* } */ case PCIProbe2: /* { */ + if (!xf86EnableIO()) + return; /* The scanpci-style detection method */ @@ -481,6 +486,8 @@ void ix86PciSelectCfgmech(void) break; /* } */ case PCIForceConfig1: + if (!xf86EnableIO()) + return; xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 1\n"); @@ -490,6 +497,8 @@ void ix86PciSelectCfgmech(void) return; case PCIForceConfig2: + if (!xf86EnableIO()) + return; xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 2\n"); diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c index 146dccfd3..23f85e644 100644 --- a/hw/xfree86/os-support/bus/linuxPci.c +++ b/hw/xfree86/os-support/bus/linuxPci.c @@ -99,9 +99,9 @@ linuxPciInit() } 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 @@ linuxPciOpenFile(PCITAG tag) 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 @@ linuxPciOpenFile(PCITAG tag) 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 @@ linuxPciCfgRead(PCITAG tag, int off) 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 @@ linuxPciCfgWrite(PCITAG tag, int off, CARD32 val) { 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 @@ linuxPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits) 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 @@ xf86GetPciDomain(PCITAG Tag) 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 @@ linuxMapPci(int ScreenNum, int Flags, PCITAG Tag, 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; diff --git a/hw/xfree86/os-support/bus/ppcPci.c b/hw/xfree86/os-support/bus/ppcPci.c index 2aa98355b..1be10ab9b 100644 --- a/hw/xfree86/os-support/bus/ppcPci.c +++ b/hw/xfree86/os-support/bus/ppcPci.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c,v 1.9 2002/08/27 22:07:07 tsi Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c,v 1.8 2002/07/24 19:06:52 tsi Exp $ */ /* * ppcPci.c - PowerPC PCI access functions * @@ -78,14 +78,15 @@ ppcPciInit() pmaxPciInit(); #else - - extern void motoppcPciInit(void); - + + static void motoppcPciInit(void); motoppcPciInit(); #endif } +#if defined(PowerMAX_OS) + /* * Motorola PowerPC platform support * @@ -101,6 +102,11 @@ ppcPciInit() */ 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 @@ static pciBusInfo_t motoppcPci0 = { extern volatile unsigned char *ioBase; -void +static void motoppcPciInit() { pciNumBuses = 1; @@ -134,6 +140,9 @@ motoppcPciInit() 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 @@ motoppcHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr) /*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 */ diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c index b068af2d0..4246e86eb 100644 --- a/hw/xfree86/os-support/linux/lnx_init.c +++ b/hw/xfree86/os-support/linux/lnx_init.c @@ -1,4 +1,4 @@ -/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 1.2 2004/04/23 19:54:08 eich Exp $ */ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 1.3 2005/01/14 18:42:26 eich Exp $ */ /* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 3.14 2001/10/31 22:50:30 tsi Exp $ */ /* * Copyright 1992 by Orest Zborowski @@ -84,7 +84,6 @@ void xf86OpenConsole(void) { int i, fd = -1; - int result; struct vt_mode VT; struct vt_stat vts; MessageType from = X_PROBED; @@ -95,13 +94,12 @@ xf86OpenConsole(void) 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 @@ xf86OpenConsole(void) 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 @@ xf86OpenConsole(void) 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 @@ xf86OpenConsole(void) * * 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 @@ xf86OpenConsole(void) 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 @@ xf86CloseConsole() 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 */ diff --git a/hw/xfree86/os-support/linux/lnx_kbd.c b/hw/xfree86/os-support/linux/lnx_kbd.c index 17f9e5331..48a62e215 100644 --- a/hw/xfree86/os-support/linux/lnx_kbd.c +++ b/hw/xfree86/os-support/linux/lnx_kbd.c @@ -215,6 +215,13 @@ SetKbdRepeat(InputInfoPtr pInfo, char rad) #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++) diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c index 4cd8152df..973a252dd 100644 --- a/hw/xfree86/os-support/linux/lnx_video.c +++ b/hw/xfree86/os-support/linux/lnx_video.c @@ -490,7 +490,7 @@ volatile unsigned char *ioBase = NULL; #endif -void +Bool xf86EnableIO(void) { #if defined(__powerpc__) @@ -499,7 +499,7 @@ xf86EnableIO(void) #endif if (ExtendedEnabled) - return; + return TRUE; #if defined(__powerpc__) ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); @@ -512,16 +512,20 @@ xf86EnableIO(void) /* 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 @@ xf86EnableIO(void) #endif ExtendedEnabled = TRUE; - return; + return TRUE; } void diff --git a/hw/xfree86/os-support/lynxos/lynx_video.c b/hw/xfree86/os-support/lynxos/lynx_video.c index c667994b3..5daef9922 100644 --- a/hw/xfree86/os-support/lynxos/lynx_video.c +++ b/hw/xfree86/os-support/lynxos/lynx_video.c @@ -21,7 +21,7 @@ * */ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c,v 3.18 2002/12/14 04:41:14 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c,v 3.17 2000/10/28 01:42:27 mvojkovi Exp $ */ #include "X.h" #include "input.h" @@ -297,7 +297,7 @@ removeIOSmem(void) ioBase = MAP_FAILED; } -void +Bool xf86EnableIO() { if (IOEnabled++ == 0) { @@ -305,7 +305,8 @@ xf86EnableIO() (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 @@ xf86EnableIO() atexit(removeIOSmem); } } - return; + return TRUE; } void diff --git a/hw/xfree86/os-support/sco/sco_iop.c b/hw/xfree86/os-support/sco/sco_iop.c index 85b4bbd41..52857bc71 100644 --- a/hw/xfree86/os-support/sco/sco_iop.c +++ b/hw/xfree86/os-support/sco/sco_iop.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c,v 1.1 2002/06/03 21:22:10 dawes Exp $ */ +/* $XFree86$ */ /* * Copyright 2001 by J. Kean Johnston * @@ -62,14 +62,18 @@ extern long sysi86 (int cmd, ...); 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) diff --git a/hw/xfree86/os-support/shared/ioperm_noop.c b/hw/xfree86/os-support/shared/ioperm_noop.c index c24f4f1b2..c1af992c1 100644 --- a/hw/xfree86/os-support/shared/ioperm_noop.c +++ b/hw/xfree86/os-support/shared/ioperm_noop.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c,v 3.4 2001/07/23 13:15:48 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c,v 3.3 1998/07/25 16:57:00 dawes Exp $ */ /* * Copyright 1993 by David Wexelblat * @@ -33,10 +33,10 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" -void +Bool xf86EnableIO() { - return; + return TRUE; } void diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c index 2f4b84e99..9328289e5 100644 --- a/hw/xfree86/os-support/solaris/sun_vid.c +++ b/hw/xfree86/os-support/solaris/sun_vid.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c,v 1.3 2002/10/03 02:04:19 tsi Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c,v 1.2 2001/10/28 03:34:03 tsi Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany * Copyright 1993 by David Wexelblat @@ -147,18 +147,20 @@ xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size) 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 diff --git a/hw/xfree86/os-support/sysv/sysv_video.c b/hw/xfree86/os-support/sysv/sysv_video.c index c0460f524..8f9916244 100644 --- a/hw/xfree86/os-support/sysv/sysv_video.c +++ b/hw/xfree86/os-support/sysv/sysv_video.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c,v 3.21 2003/03/14 13:46:08 tsi Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c,v 3.20tsi Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany * Copyright 1993 by David Wexelblat @@ -281,22 +281,23 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem) 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 diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h index 8b50c793a..688f647a3 100644 --- a/hw/xfree86/os-support/xf86_OSproc.h +++ b/hw/xfree86/os-support/xf86_OSproc.h @@ -125,6 +125,7 @@ extern void xf86WrapperInit(void); #define xf86FatalError(a, b) \ if (dispatchException & DE_TERMINATE) { \ ErrorF(a, b); \ + ErrorF("\n"); \ return; \ } else FatalError(a, b) @@ -144,7 +145,7 @@ extern pointer xf86MapVidMem(int, int, unsigned long, unsigned long); 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); diff --git a/hw/xfree86/utils/scanpci/scanpci.c b/hw/xfree86/utils/scanpci/scanpci.c index 5746269f5..671933a55 100644 --- a/hw/xfree86/utils/scanpci/scanpci.c +++ b/hw/xfree86/utils/scanpci/scanpci.c @@ -195,7 +195,6 @@ main(int argc, char *argv[]) break; } - xf86EnableIO(); pcrpp = xf86scanpci(0); if (!pcrpp) {