Patch by Kevin E. Martin based off a patch from Dell, which changes the X server to use Linux native /proc based PCI interfaces by default instead of bitbanging PCI config space directly. Patch updated by Olivier Baudron to fix all occurrences of PCI config space access. This fixes a problem in Linux where other software may be probing PCI config space using the native interfaces correctly and the kernel PCI lock is held, then the X server starts up and simultaneously stomps on PCI space, generally causing the machine to hang. Fixes bugs: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=152608 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=118130 This may also fix the following bugs (unconfirmed): https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=146386 Update: This is a forward port of a patch we added to XFree86-4.3.0 for RHEL-3. The only modification is the changes to xf86Globals.c were dropped, as they're included in xorg-x11 stock code already. Mike A. Harris This bug is nominated for the 6.8.3 release as attachment 2285. https://bugs.freedesktop.org/show_bug.cgi?id=2880 --- xc/programs/Xserver/hw/xfree86/int10/helper_exec.c.use-linux-native-pciscan-by-default 2004-04-23 15:54:06.000000000 -0400 +++ xc/programs/Xserver/hw/xfree86/int10/helper_exec.c 2005-07-27 16:41:26.000000000 -0400 @@ -23,10 +23,12 @@ #include "int10Defines.h" #include "xf86int10.h" -#if !defined (_PC) && !defined (_PC_PCI) static int pciCfg1in(CARD16 addr, CARD32 *val); static int pciCfg1out(CARD16 addr, CARD32 val); -#endif +static int pciCfg1inw(CARD16 addr, CARD16 *val); +static int pciCfg1outw(CARD16 addr, CARD16 val); +static int pciCfg1inb(CARD16 addr, CARD8 *val); +static int pciCfg1outb(CARD16 addr, CARD8 val); #if defined (_PC) static void SetResetBIOSVars(xf86Int10InfoPtr pInt, Bool set); #endif @@ -321,7 +323,8 @@ } #endif /* __NOT_YET__ */ } else { - val = inb(Int10Current->ioBase + port); + if (!pciCfg1inb(port, &val)) + val = inb(Int10Current->ioBase + port); #ifdef PRINT_PORT ErrorF(" inb(%#x) = %2.2x\n", port, val); #endif @@ -343,7 +346,8 @@ (void)getsecs(&sec, &usec); val = (CARD16)(usec / 3); } else { - val = inw(Int10Current->ioBase + port); + if (!pciCfg1inw(port, &val)) + val = inw(Int10Current->ioBase + port); } #ifdef PRINT_PORT ErrorF(" inw(%#x) = %4.4x\n", port, val); @@ -380,7 +384,8 @@ #ifdef PRINT_PORT ErrorF(" outb(%#x, %2.2x)\n", port, val); #endif - outb(Int10Current->ioBase + port, val); + if (!pciCfg1outb(port, val)) + outb(Int10Current->ioBase + port, val); } } @@ -391,7 +396,8 @@ ErrorF(" outw(%#x, %4.4x)\n", port, val); #endif - outw(Int10Current->ioBase + port, val); + if (!pciCfg1outw(port, val)) + outw(Int10Current->ioBase + port, val); } CARD32 @@ -399,10 +405,8 @@ { CARD32 val; -#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1in(port, &val)) -#endif - val = inl(Int10Current->ioBase + port); + val = inl(Int10Current->ioBase + port); #ifdef PRINT_PORT ErrorF(" inl(%#x) = %8.8x\n", port, val); @@ -417,10 +421,8 @@ ErrorF(" outl(%#x, %8.8x)\n", port, val); #endif -#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1out(port, val)) -#endif - outl(Int10Current->ioBase + port, val); + outl(Int10Current->ioBase + port, val); } CARD8 @@ -459,7 +461,6 @@ (*Int10Current->mem->wl)(Int10Current, addr, val); } -#if !defined(_PC) && !defined(_PC_PCI) static CARD32 PciCfg1Addr = 0; #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00) @@ -487,12 +488,85 @@ return 1; } if (addr == 0xCFC) { - pciWriteLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr),val); + pciWriteLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr), val); + return 1; + } + return 0; +} + +static int +pciCfg1inw(CARD16 addr, CARD16 *val) +{ + int offset, shift; + + if ((addr >= 0xCF8) && (addr <= 0xCFB)) { + shift = (addr - 0xCF8) * 8; + *val = (PciCfg1Addr >> shift) & 0xffff; + return 1; + } + if ((addr >= 0xCFC) && (addr <= 0xCFF)) { + offset = addr - 0xCFC; + *val = pciReadWord(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset); + return 1; + } + return 0; +} + +static int +pciCfg1outw(CARD16 addr, CARD16 val) +{ + int offset, shift; + + if ((addr >= 0xCF8) && (addr <= 0xCFB)) { + shift = (addr - 0xCF8) * 8; + PciCfg1Addr &= ~(0xffff << shift); + PciCfg1Addr |= ((CARD32) val) << shift; + return 1; + } + if ((addr >= 0xCFC) && (addr <= 0xCFF)) { + offset = addr - 0xCFC; + pciWriteWord(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset, val); + return 1; + } + return 0; +} + +static int +pciCfg1inb(CARD16 addr, CARD8 *val) +{ + int offset, shift; + + if ((addr >= 0xCF8) && (addr <= 0xCFB)) { + shift = (addr - 0xCF8) * 8; + *val = (PciCfg1Addr >> shift) & 0xff; + return 1; + } + if ((addr >= 0xCFC) && (addr <= 0xCFF)) { + offset = addr - 0xCFC; + *val = pciReadByte(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset); + return 1; + } + return 0; +} + +static int +pciCfg1outb(CARD16 addr, CARD8 val) +{ + int offset, shift; + + if ((addr >= 0xCF8) && (addr <= 0xCFB)) { + shift = (addr - 0xCF8) * 8; + PciCfg1Addr &= ~(0xff << shift); + PciCfg1Addr |= ((CARD32) val) << shift; + return 1; + } + if ((addr >= 0xCFC) && (addr <= 0xCFF)) { + offset = addr - 0xCFC; + pciWriteByte(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset, val); return 1; } return 0; } -#endif CARD8 bios_checksum(CARD8 *start, int size)