$Id$ Implement IsolateDevice and SingleCard layout options for XF86Config, and -isolateDevice command-line flag for XFree86 X server. Useful for multi-card setups where different X servers run on each card. This patch by Aivils Stoss ; copyright and license as below. Minor modifications by Andreas Schuldei and Branden Robinson; documentation added by Branden Robinson. Copyright 2003 Aivils Stoss.   Permission is hereby granted, free of charge, to any person obtaining a   copy of this software and associated documentation files (the "Software"),   to deal in the Software without restriction, including without limitation   the rights to use, copy, modify, merge, publish, distribute, sublicense,   and/or sell copies of the Software, and to permit persons to whom the   Software is furnished to do so, subject to the following conditions:     The above copyright notice and this permission notice shall be included     in all copies or substantial portions of the Software.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL   THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER   DEALINGS IN THE SOFTWARE. diff -ruN xc-old/programs/Xserver/hw/xfree86/Xorg.man xc/programs/Xserver/hw/xfree86/Xorg.man --- xc-old/programs/Xserver/hw/xfree86/Xorg.man 2004-04-23 19:20:02.000000000 +0000 +++ xc/programs/Xserver/hw/xfree86/Xorg.man 2004-10-20 15:07:07.741839312 +0000 @@ -257,6 +257,19 @@ like this are downgraded from fatal errors to warnings. This option should be used with care. .TP 8 +.B \-isolateDevice \fIbus\-id\fP +Restrict device resets to the device at +.IR bus\-id . +The +.I bus\-id +string has the form +.IB bustype : bus : device : function +(e.g., \(oqPCI:1:0:0\(cq). +At present, only isolation of PCI devices is supported; i.e., this option +is ignored if +.I bustype +is anything other than \(oqPCI\(cq. +.TP 8 .B \-keeptty Prevent the server from detaching its initial controlling terminal. This option is only useful when debugging the server. Not all platforms diff -ruN xc-old/programs/Xserver/hw/xfree86/common/xf86Config.c xc/programs/Xserver/hw/xfree86/common/xf86Config.c --- xc-old/programs/Xserver/hw/xfree86/common/xf86Config.c 2004-08-16 20:17:51.000000000 +0000 +++ xc/programs/Xserver/hw/xfree86/common/xf86Config.c 2004-10-20 15:03:26.976400760 +0000 @@ -1667,6 +1667,20 @@ return TRUE; } +typedef enum { + LAYOUT_ISOLATEDEVICE, + LAYOUT_SINGLECARD +} LayoutValues; + +static OptionInfoRec LayoutOptions[] = { + { LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING, + {0}, FALSE }, + { LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN, + {0}, FALSE }, + { -1, NULL, OPTV_NONE, + {0}, FALSE }, +}; + /* * figure out which layout is active, which screens are used in that layout, * which drivers and monitors are used in these screens @@ -2546,6 +2560,8 @@ const char *filename; char *searchpath; MessageType from = X_DEFAULT; + char *scanptr; + Bool singlecard = 0; if (!autoconfig) { if (getuid() == 0) @@ -2619,6 +2636,29 @@ } } + xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions); + + if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) { + ; /* IsolateDevice specified; overrides SingleCard */ + } else { + xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard); + if (singlecard) + scanptr = xf86ConfigLayout.screens->screen->device->busID; + } + if (scanptr) { + int bus, device, func, stroffset = 0; + if (strncmp(scanptr, "PCI:", 4) != 0) { + xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n" + "\tIgnoring IsolateDevice option.\n"); + } else if (sscanf(scanptr, "PCI:%d:%d:%d", &bus, &device, &func) == 3) { + xf86IsolateDevice.bus = bus; + xf86IsolateDevice.device = device; + xf86IsolateDevice.func = func; + xf86Msg(X_INFO, + "Isolating PCI bus \"%d:%d:%d\"\n", bus, device, func); + } + } + /* Now process everything else */ if (!configFiles(xf86configptr->conf_files) || diff -ruN xc-old/programs/Xserver/hw/xfree86/common/xf86Globals.c xc/programs/Xserver/hw/xfree86/common/xf86Globals.c --- xc-old/programs/Xserver/hw/xfree86/common/xf86Globals.c 2004-07-06 14:37:47.000000000 +0000 +++ xc/programs/Xserver/hw/xfree86/common/xf86Globals.c 2004-10-20 15:03:26.977400608 +0000 @@ -238,6 +238,7 @@ #endif RootWinPropPtr *xf86RegisteredPropertiesTable = NULL; Bool xf86inSuspend = FALSE; +PciBusId xf86IsolateDevice; #ifdef DLOPEN_HACK /* diff -ruN xc-old/programs/Xserver/hw/xfree86/common/xf86Init.c xc/programs/Xserver/hw/xfree86/common/xf86Init.c --- xc-old/programs/Xserver/hw/xfree86/common/xf86Init.c 2004-10-20 15:03:24.650754000 +0000 +++ xc/programs/Xserver/hw/xfree86/common/xf86Init.c 2004-10-20 15:03:26.978400456 +0000 @@ -1697,6 +1697,25 @@ xf86AllowMouseOpenFail = TRUE; return 1; } + if (!strcmp(argv[i], "-isolateDevice")) + { + int bus, device, func; + if (++i >= argc) + return 0; + if (strncmp(argv[i], "PCI:", 4)) { + ErrorF("Bus types other than PCI not yet isolable\n"); + return 0; + } + if (sscanf(argv[i], "PCI:%d:%d:%d", &bus, &device, &func) == 3) { + xf86IsolateDevice.bus = bus; + xf86IsolateDevice.device = device; + xf86IsolateDevice.func = func; + return 2; + } else { + ErrorF("Invalid isolated device specifiation\n"); + return 0; + } + } /* OS-specific processing */ return xf86ProcessArgument(argc, argv, i); } @@ -1761,6 +1780,7 @@ #endif ErrorF("-bestRefresh choose modes with the best refresh rate\n"); ErrorF("-ignoreABI make module ABI mismatches non-fatal\n"); + ErrorF("-isolateDevice bus_id restrict device resets to bus_id (PCI only)\n"); ErrorF("-version show the server version\n"); /* OS-specific usage */ xf86UseMsg(); diff -ruN xc-old/programs/Xserver/hw/xfree86/common/xf86Priv.h xc/programs/Xserver/hw/xfree86/common/xf86Priv.h --- xc-old/programs/Xserver/hw/xfree86/common/xf86Priv.h 2004-01-29 08:08:26.000000000 +0000 +++ xc/programs/Xserver/hw/xfree86/common/xf86Priv.h 2004-10-20 15:03:26.978400456 +0000 @@ -76,6 +76,7 @@ extern Gamma xf86Gamma; extern char *xf86ServerName; extern Bool xf86ShowUnresolved; +extern PciBusId xf86IsolateDevice; /* Other parameters */ diff -ruN xc-old/programs/Xserver/hw/xfree86/common/xf86pciBus.c xc/programs/Xserver/hw/xfree86/common/xf86pciBus.c --- xc-old/programs/Xserver/hw/xfree86/common/xf86pciBus.c 2004-08-09 22:37:22.000000000 +0000 +++ xc/programs/Xserver/hw/xfree86/common/xf86pciBus.c 2004-10-20 15:03:26.980400152 +0000 @@ -180,7 +180,10 @@ int num = 0; pciVideoPtr info; Bool mem64 = FALSE; + int DoIsolateDeviceCheck = 0; + if (xf86IsolateDevice.bus || xf86IsolateDevice.device || xf86IsolateDevice.func) + DoIsolateDeviceCheck = 1; pcrpp = xf86PciInfo = xf86scanpci(0); getPciClassFlags(pcrpp); @@ -202,7 +205,11 @@ subclass = pcrp->pci_sub_class; } - if (PCIINFOCLASSES(baseclass, subclass)) { + if (PCIINFOCLASSES(baseclass, subclass) && + (DoIsolateDeviceCheck ? + (xf86IsolateDevice.bus == pcrp->busnum && + xf86IsolateDevice.device == pcrp->devnum && + xf86IsolateDevice.func == pcrp->funcnum) : 1)) { num++; xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo, sizeof(pciVideoPtr) * (num + 1)); diff -ruN xc-old/programs/Xserver/hw/xfree86/xorg.conf.man xc/programs/Xserver/hw/xfree86/xorg.conf.man --- xc-old/programs/Xserver/hw/xfree86/xorg.conf.man 2004-04-23 19:20:02.000000000 +0000 +++ xc/programs/Xserver/hw/xfree86/xorg.conf.man 2004-10-20 15:06:14.274967512 +0000 @@ -1689,7 +1689,7 @@ section provides information specific to the whole session, including session-specific .BR Options . -The +In addition to options specific to this section (described below), the .B ServerFlags options (described above) may be specified here, and ones given here override those given in the @@ -1779,12 +1779,30 @@ .RE .TP 7 .B Options -Any option permitted in the +In addition to the following, any option permitted in the .B ServerFlags section may also be specified here. When the same option appears in both places, the value given here overrides the one given in the .B ServerFlags section. +.TP 7 +.BI "Option \*qIsolateDevice\*q \*q" bus\-id \*q +Restrict device resets to the specified +.IR bus\-id . +See the +.B BusID +option (described in +.BR "DEVICE SECTION" , +above) for the format of the +.I bus\-id +parameter. This option overrides +.BR SingleCard , +if specified. At present, only PCI devices can be isolated in this manner. +.TP 7 +.BI "Option \*qSingleCard\*q \*q" boolean \*q +As +.BR IsolateDevice , +except that the bus ID of the first device in the layout is used. .PP Here is an example of a .B ServerLayout